I found myself in a bit of a trouble. Trying to implement multi-stage bootloader, I developed code to read root directory, FATs, locate file etc. It didn't work however. I started experimenting and came to the conclusion that it's reading floppy thats failing. I developed a small bootloader that is just meant to read sector onto 0x1000 and execute it (pretty much like one from tutorial). It also didn't work. Using GDB i determined that BIOS reported that operation was successful (CF flag clear, AL as expected) but the buffer address remained clear.
Code: Select all
[bits 16]
[org 0x0]
start: jmp loader
times 0x0b-$+start db 0
bpbBytesPerSector: dw 512
bpbSectorsPerCluster: db 1
bpbReservedSectors: dw 1 ;bootsector
bpbNumberOfFats: db 2 ;FAT12 has 2 fats
bpbRootEntries: dw 224 ;224 root directories is max for floppy
bpbTotalSectors: dw 2880 ;max 2880 sectors per floppy
bpbMedia: db 0xf0 ;singled sided,9 sectors per fat, 80 tracks, movable
bpbSectorsPerFat: dw 9
bpbSectorsPerTrack: dw 18
bpbHeadsPerCylinder: dw 2
bpbHiddenSectors: dd 0
bpbTotalSectorsBig: dd 0
bsDriveNumber: db 0
bsUnused: db 0
bsExtBootSignature: db 0x29 ;MS/PC-DOS version 4.0 Bios Parameter Block (BPB)
bsSerialNumber: dd 0x74fe574
bsVolumeLable: db "TestOS "
bsFileSystem: db "FAT12 "
;*****************************
;******** ENTRY POINT ********
;*****************************
loader:
;****** RESET FLOPPY *********
ResetLoop:
mov ah,0x00 ;function 0 - reset
mov dl,0x00 ;drive number
int 0x13
jc ResetLoop ;error - try again
mov ax, 0x1000 ;setup buffer address
mov es, ax
xor bx, bx
mov ah, 0x02 ;read floppy sector function
mov al, 0x01 ;number of sectors to read
mov ch, 0x01 ;track
mov cl, 0x02 ;start sector
mov dh, 0x00 ;head number
mov dl, 0x00 ;drive number
mov byte[0x7c00],0x00 ;clear space used for debug (ensure no random vals)
mov byte[0x7c01],0x00
int 0x13
jc carry
jmp end
carry: ;there was an error -> set data in RAM for debug
mov byte[0x7c00],0xAA
end:
mov byte[0x7c01],al ;save number of readed sectors to RAM for debug
jmp 0x1000:0x00 ;jump to new sector
;**** REST OF THE SECTOR *****
times 510-($-$$) db 0
dw 0xAA55
int 0x18 ;this should be read by bootloader
Code: Select all
0x7c00: 0x00 0x01 0x00 0x00 0x00 0x00 0x00 0x00
Code: Select all
0x1000: 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
Which means that in fact data wasn't loaded.
Floppy image shows that instruction is at correct address:
Code: Select all
0x200: 0xCD 0x18 0xFF 0x00 0x00 0x00 0x00 0x00
Thanks in advance,
Bart