"Boot from 1st hard disk"
Initially, I could fit my bootloader in 512 bytes. I had a small function (_load) to read (INT 13h, AH=02h) the boot-sector from the HD into 7C00h, and was relocating this function to 7E00h at runtime. This was working fine, no problems there.
Now, I am extending my bootloader, and this functionality needs to be in the second stage. I am loading this second stage into 7E00h from the second sector of a FAT12 floppy. Since the second stage is in 7E00h, there is no need to relocate the _load function, so I should be able to load the target boot-sector straight into 7C00h.
The second stage appears to be loading correctly, since the menu is displaying, and the other two options (install, shutdown; both in second stage as well) are also executing without problems. However, booting from the first HD is no longer working, and I can't for the life of me work out why.
Here's the function in question:
Code: Select all
_load:
MOV AH, 02h ; Read sectors from disk
MOV AL, 1h ; Read 1 sector
MOV CH, 0h ; First cylinder
MOV CL, 1h ; First sector
MOV DH, 0h ; First head
MOV DL, 80h ; First hard drive
MOV BX, 07C0h ; Target is 07C0h:0000h (ES:BX)
MOV ES, BX
MOV BX, 0h
INT 13h ; Execute read
JC .read_err ; Check for errors
JMP 07C0h:0000h ; Transfer execution to boot sector
.read_err:
MOV SI, .str_err_read
CALL printstr
JMP $
; Strings used by _load
.str_err_read db 'Error reading from first HD'
; _load end
Is there any reason why loading code from disk into memory would be any different than dynamically relocating it?
Any advice would be greatly appreciated.
Cheers.