[SOLVED] Bootloader - problem with reading floppy (int 13h)
Posted: Fri Jan 28, 2011 3:26 pm
Hey. I'm new to this forum so let me introduce myself I'm 17 years old student, with 7 years of experience of web developing and programming I recently got interested in low level programming and thus I started making an OS. It always fascinated me how OSs work plus I'm considering making small OS as part of my programming coursework later during the year.
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.
Memory inspection revealed:
Which is as expected.
Which means that in fact data wasn't loaded.
Floppy image shows that instruction is at correct address:
It's probably something easy but i spent last 2 days trying to find the answer, and experimenting with the code: so far without result. If you happen to know what's wrong please tell me
Thanks in advance,
Bart
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