Stage 2 bootloader Question
Posted: Thu Jan 01, 2009 7:16 pm
I'm new to OS development. So I figured I would start out by writing a boot loader from scratch. I am attempting to write a Stage 2 boot loader. All Stage 1 does is read Stage 2 from disk and jump to it. I am using interrupts for output.
Stage 1 works fine. It outputs the string "Bootloader Initialised...", loads the second sector of the floppy disk and jumps to it.
Stage 2 does not work the way I expect it to work. For some reason I am unable to output a string the same way I output a string in stage 1. Any ideas why? Below is my code.
Here is my code for Stage 1:
--------------------------------------------------------------------------------------------------------------------------------
; bootloader
[BITS 16]
[ORG 0x7C00]
MOV si, BootLoaderWelcomeString
CALL PrintBootLoaderWelcome
ResetFloppyDrive:
MOV dl, 0 ;Drive = 0 (A drive)
MOV ah, 0
INT 0x13
JC ResetFloppyDrive
ReadFloppyDisk:
MOV ax, 0x1000
MOV es, ax ;es - extra segment. Pointer to extra data. es = 0x1000
MOV bx, 0 ;bx - Base register. Used as a pointer to data. bx = 0
MOV al, 1 ;Load just 1 disk sector
MOV ch, 0 ;Cylander = 0
MOV cl, 2 ;Sector = 2
MOV dh, 0 ;Head = 0
MOV dl, 0 ;Drive = 0 (A drive)
MOV ah, 2
INT 0x13
JC ReadFloppyDisk
JMP 0x1000:0000
PrintBootLoaderWelcome:
MOV al, [si]
OR al, al
JZ ReturnStage1
MOV ah, 0x0E
INT 0x10
INC si
JMP PrintBootLoaderWelcome
GetString:
MOV ah, 0
INT 0x16
MOV ah, 0x0E
INT 0x10
JMP GetString
ReturnStage1:
RET
BootLoaderWelcomeString DB "Bootloader Initialised...", 0x0D, 0x0A, 0
TIMES 510 - ($ - $$) DB 0 ;Fill the rest of sector with 0
DW 0xAA55 ;Add boot signature at the end of bootloader
-------------------------------------------------------------------------------------------------------------------------------------------------
Here is my code for stage 2:
-------------------------------------------------------------------------------------------------------------------------------------------------
MOV si, Stage2WelcomeString
CALL PrintStage2Welcome
JMP $
PrintStage2Welcome:
MOV al, [si]
OR al, al
JZ returnStage2
MOV ah, 0x0E
INT 0x10
INC si
JMP PrintStage2Welcome
returnStage2:
RET
Stage2WelcomeString db "Initialising Stage 2...", 0x0D, 0x0A, 0
Stage 1 works fine. It outputs the string "Bootloader Initialised...", loads the second sector of the floppy disk and jumps to it.
Stage 2 does not work the way I expect it to work. For some reason I am unable to output a string the same way I output a string in stage 1. Any ideas why? Below is my code.
Here is my code for Stage 1:
--------------------------------------------------------------------------------------------------------------------------------
; bootloader
[BITS 16]
[ORG 0x7C00]
MOV si, BootLoaderWelcomeString
CALL PrintBootLoaderWelcome
ResetFloppyDrive:
MOV dl, 0 ;Drive = 0 (A drive)
MOV ah, 0
INT 0x13
JC ResetFloppyDrive
ReadFloppyDisk:
MOV ax, 0x1000
MOV es, ax ;es - extra segment. Pointer to extra data. es = 0x1000
MOV bx, 0 ;bx - Base register. Used as a pointer to data. bx = 0
MOV al, 1 ;Load just 1 disk sector
MOV ch, 0 ;Cylander = 0
MOV cl, 2 ;Sector = 2
MOV dh, 0 ;Head = 0
MOV dl, 0 ;Drive = 0 (A drive)
MOV ah, 2
INT 0x13
JC ReadFloppyDisk
JMP 0x1000:0000
PrintBootLoaderWelcome:
MOV al, [si]
OR al, al
JZ ReturnStage1
MOV ah, 0x0E
INT 0x10
INC si
JMP PrintBootLoaderWelcome
GetString:
MOV ah, 0
INT 0x16
MOV ah, 0x0E
INT 0x10
JMP GetString
ReturnStage1:
RET
BootLoaderWelcomeString DB "Bootloader Initialised...", 0x0D, 0x0A, 0
TIMES 510 - ($ - $$) DB 0 ;Fill the rest of sector with 0
DW 0xAA55 ;Add boot signature at the end of bootloader
-------------------------------------------------------------------------------------------------------------------------------------------------
Here is my code for stage 2:
-------------------------------------------------------------------------------------------------------------------------------------------------
MOV si, Stage2WelcomeString
CALL PrintStage2Welcome
JMP $
PrintStage2Welcome:
MOV al, [si]
OR al, al
JZ returnStage2
MOV ah, 0x0E
INT 0x10
INC si
JMP PrintStage2Welcome
returnStage2:
RET
Stage2WelcomeString db "Initialising Stage 2...", 0x0D, 0x0A, 0