Reputation: 235
I have been writing a bootloader in NASM and have ran into a problem reading the disk: the disk times-out when I try to read more than one sector:
xor ax, ax
mov es, ax
mov ds, ax
mov ah, 0
int 0x13 ; Reset disk with int 0x13 ah 0x0
mov al, 2 ; Read 2 sectors
mov ah, 0x2 ; int 13 ah 0x2 is read disk
mov bx, 0x200 ; Load to 0x200
mov cl, 2 ; Sector 2
mov ch, 0 ; Cylinder 0
mov dl, 0 ; Floppy drive 0
mov dh, 1 ; Head 1
; LBA is block 19 (root directory of FAT12)
int 0x13
mov si, bx ; Print first filename to check success
When I use mov cl,1
, that is, read one sector instead of two (or more), the program prints the the first filename normally with no errors. Yet when I try to read multiple sector, the filename is not printed normally* and ah
contains 0x80
which corresponds to a disk timeout (that is, it is not ready) as well as setting the carry flag. I cannot figure out why this is happening. Thank you.
*string is printed in top right corner of screen--far away from the cursor position
Software: Virtual Floppy Drive + Bochs 2.6.2 (following this tutorial)
Upvotes: 1
Views: 436
Reputation: 2541
I think you're overwriting the BIOS data area in RAM, by putting your disk buffer too low, on 0000:0200. That could also explain why output goes to a wrong screen postion - the cursor position is stored in there too. All memory at and above address 0000:0500 can be used by the boot loader, so try to set the pointer a bit higher.
I notice that you're ah with 0 on line 4 while it was zeroed already on line 1. Seems unnecessary. Not that it saves a lot, but two bytes are two bytes ...
Upvotes: 2