Bootloader not handing off execution
Posted: Sun Feb 10, 2013 10:20 am
So, I'm quite sure I'm not doing anything wrong. Even looked at some other people's code in case my registers were wrong or something, but no.
This is just a simple bootloader I whipped up which will load the next sector on the disk (2nd sector) into memory, then jump to there and continue execution of what was just loaded. (Don't have a file system). The data is loaded using INT 0x13, which loads the sector into ES:BX (0x1000:0) in this case. Then my loaded program should be in memory, the bootloader jumps to where it was loaded and should continue execution. But it doesn't work for some reason.
I'm quite sure the offending code is here, because this is where all my diskette functions are. But I'm not sure what it is because I even checked other people's code so I'm sure I'm doing something fine.
And my data I'm trying to load is just a simple
I know it's not loading because bochs says nothing about being halted.
Any help would be appreciated
This is just a simple bootloader I whipped up which will load the next sector on the disk (2nd sector) into memory, then jump to there and continue execution of what was just loaded. (Don't have a file system). The data is loaded using INT 0x13, which loads the sector into ES:BX (0x1000:0) in this case. Then my loaded program should be in memory, the bootloader jumps to where it was loaded and should continue execution. But it doesn't work for some reason.
I'm quite sure the offending code is here, because this is where all my diskette functions are. But I'm not sure what it is because I even checked other people's code so I'm sure I'm doing something fine.
Code: Select all
;--------------Reset diskette--------------------------
;will reset drive 0 and if fails tries again
resetDiskFail:
mov si, msg_resetDiskFail
call write ;will fall down to reset disk again
resetDisk:
mov si, msg_resetDisk
call write
mov ah, 00 ;reset disk
mov dl, 00 ;Disk 0 is the default drive
int 0x13 ;call bios and reset
jc resetDiskFail;if carry flag is set error occured so try again
jmp loadSector ;jump to load sectors instead if passed
;---------------Load Sectors------------------------------
;Will load the next sector on the disk into 0x1000:0
loadSectorFail:
mov si, msg_loadSectorFail
call write
loadSector:
mov si, msg_loadSector
call write
mov ah, 00
int 0x16 ;wait for keypress incase data on another disk
mov ax, 0x1000 ;read into address 0x1000:0
mov es, ax ;sector data is loaded into es:bx, so 0x1000:0
xor bx, bx
mov ah, 0x02 ;read disk sector
mov al, 01 ;read 1 sector
mov ch, 01 ;reading from track 1
mov cl, 02 ;second sector (next one)
mov dh, 00 ;head 0
mov dl, 00 ;drive 0 (default)
int 0x13 ;call bios and load sector
jc loadSectorFail; carry will be 1 on error, so if error try again
mov si, msg_loadSectorOK
call write
jmp lastStep
;-----------End of the Boot loader--------------------
;Jumps to where we loaded the data into
;and passes off control to whatever lies in the clutches
;of the second sector :)
;execution will be taken off from there!!
lastStep:
mov ax, 0x1000 ;set data segment register
mov ds, ax
jmp 0x1000:0x0000 ;JUMP AND EXECUTE!!!!!
Code: Select all
org 0x1000 ;Because this is where we loaded to, so this is where we start, correct?
cli
hlt
Any help would be appreciated