I learn pure hardware (without OS) programming and have a problem with booting from flash-drive (using Kingston DT101 G2 8Gb). Initial code, which was not backed up and I can't reproduce it now exactly as it was :(, worked fine both in emulator (latest Bochs) and on a live hardware. After that more functionnality was added (dump outputing subroutines and loading sectors from flash drive using function 42h of int 13h) which worked perfectly in Bochs but not at all on the live computer - computer rebooted when trying to run it. So, I've reduced the code to a sort of a simplest form I had at the beginning and modified segment registers initialisation. Here's how it looks like now:
load_address equ 0x7c00 ;was used earlier but not now, just keeping it if anything
use16 ;we start in real mode
bootloader_start:
cli
;setting up the segments
xor ax, ax
mov ss, ax
mov sp, 0x7c00
push word 0x7c0
pop ds
push ds
push word continue
retf
continue:
sti
;copying CS into video memory to check it value (blue background)
mov ax, 0xb800
mov es, ax
mov ax, cs
push ax
mov ah, 0x17
mov [es:0], ax
pop ax
mov al, ah
mov ah, 0x17
mov [es:2], ax
;infinit loop
jmp short $
current_tty_address: ;was used earlier
dw 0
boot_drive_number: ;was used earlier
db 0
padding:
;padding to sector size - 2
times 510-($-$$) db 0
dw 0xaa55 ;mbr identifier
;if comipling for Bochs, padding to hard disk image size (flat mode, 10Mb)
%ifdef BOCHS
padding2:
times 512 * (17 * 4 * 306 - 1) db 0
%endif
But this didn't work properly. It puts a character in the first screen position (0, 0), but the next position is just black (but should have a blue background at least, no matter what the character code is). Moreover, the same code written on a flash drive of different size (Kingston DT101 G2, 32Gb) gives "Missing operating system..." message. I've tried different variations but still can't do this work and can't figure out what happens. Is this a flash drive problem? A can recall, that some months ago I tried LinuxLive with the same flash model and after 4 - 5 launchings it just stopped booting. Here what I use: Computer model: HP EliteBook 8440p; (offlease); CPU: Intel Core i5 M520 2.40GHz 2 Cores; BIOS: Hewlett-Packard 68CCU Ver. F.0D, 14/07/2010 (I don't know if it was updated); Compilator: NASM; Disk manipulation software: DiskProbe V 1.0 (R. Eugene-Baucom, Microsoft)
Please, help me to understand what happens. Thanks a lot.
This was my very stupid mistake... Because when seeing nothing in physical drive list of Disk Probe, instead of guessing run Disk Probe as administrator, I was selecting from the list of logical volumes. So, the tool wrote to the sector 0 of an active partition instead of writing to the sector 0 of an entire drive. This worked perfect with a hard disk, but with both flash drives I used something went wrong (an incompatibility between BIOS and Windows + Disk Probe in partition table treatment maybe or something like this). So, luckily the problem was very easy. Thanks to everybody for your efforts.