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