Setting up second stage loader
Posted: Sat Mar 06, 2010 4:14 pm
Hey, this has likely been asked before (although I couldn't find a response) but I've started building my OS by assembling a two stage bootloader (learned from bits and pieces here and there). Now the first stage works fine (gets control, loads second stage, transfers control), but the second stage not so much. I've created a message processor to output messages corresponding to the progress of the loader, but they don't seem to appear (it's just a black screen the whole time). The code just executes and control eventually gets transferred to the kernel. Now I'm new at OSdev and I'm unsure exactly how to set up the second stage of the loader when control gets transferred there so I was wondering if anyone could offer me insight into how to set things up (memory addressing, a stack?) The second stage loader is incomplete as I'm just trying to get it set up accordingly...
boot sector/first stage
second stage loader
Thanks in advance for any help you can give
boot sector/first stage
Code: Select all
[ORG 0]
[BITS 16]
jmp 07C0h:StartBoot
StartBoot:
mov AX, CS
mov DS, AX
mov ES, AX
.reset:
mov AX, 00h
mov DL, 00h
int 13h
jc .reset
.read:
mov AX, 7E00h
mov ES, AX
mov BX, 00h
mov AH, 02h
mov AL, 04h
mov CH, 00h
mov CL, 02h
mov DH, 00h
mov DL, 00h
int 13h
jc .read
jmp 7E00h:0000h ;To second stage bootloader
times 510-($-$$) db 0
dw 0AA55h
Code: Select all
[ORG 0]
[BITS 16]
Setup:
mov AX, 7E00h ;set new location, and set screen mode
mov DS, AX
mov ES, AX
mov DL, 00h
mov AH, 00h
mov AL, 03h
int 10h
mov SI, [TITLE]
call PrintS
jmp Main
Main:
.reset: ;load kernel to physical address 10000h
mov AX, 00h
mov DL, 00h
int 13h
jc .reset
.read:
mov AX, 1000h
mov ES, AX
mov BX, 00h
mov AH, 02h ;start locations for reading
mov AL, 40h
mov CH, 00h
mov CL, 06h
mov DH, 00h
mov DL, 00h
int 13h
jc .read
mov SI, [KLOAD]
call PrintS
.pMode:
cli
mov AX, 2401h ;enable the A20 line
int 15h
jc Error
jmp Done
PrintS:
mov AH, 0Eh
.loop:
mov AL, [SI]
cmp AL, 00h
je .done
int 10h
inc SI
jmp .loop
.done:
ret
Error:
cmp AH, 86h
je .nSupport
.unknwon:
mov SI, [UNERROR]
call PrintS
hlt
.nSupport:
mov SI, [NOSUPPORT]
call PrintS
hlt
;****************
; Strings
;****************
TITLE:
db "-> BootSector found, second stage bootloader started", 0Ah, 0Dh, 00h
KLOAD:
db "-> Kernel succefully loaded, setting up protected mode", 0Ah, 0Dh, 00h
NOSUPPORT:
db "ERROR!! - A20 line function not supported, booting halted", 0Ah, 0Dh, 00h
UNERROR:
db "ERROR!! - An unknown error has occured, booting halted", 0Ah, 0Dh, 00h
Done:
jmp 1000h:0000h
times 2048-($-$$) db 0