G:/system files/ring0/boot/level_one_boot(hdd).asm
Code: Select all
use16
org 0x7C00
;setup registers
xor ax,ax
mov ds,ax
mov es,ax
cli
mov ss,ax
mov sp,0x7C00
sti
;main
call ClearScreen
mov bx,00001101b;purple on black
mov [xpos],4d;xpos
mov [ypos],2d;ypos
call SetCursorPos
mov si,bootstrapname
call PrintText
mov [xpos],4d;xpos
mov [ypos],3d;ypos
call SetCursorPos
mov si,loadingmsg
call PrintText
mov [xpos],0
mov [ypos],5
call SetCursorPos
;begin bootloader
call LoadStage2
cmp [errorflag],0
;check if we successfully loaded the second stage program
jg halt
;if successful, cache the drive number we're loading from and jump to the program
mov dl,80h
push dx
jmp 0x2000:0x0000 ;jump to loaded program
;handle boot failure
halt:
mov bx,00001111b;white on black
mov [xpos],4d;xpos
mov [ypos],5d;ypos
call SetCursorPos
mov si,haltexception
call PrintText
mov [xpos],0
mov [ypos],7
call SetCursorPos
hang:
jmp hang
;routines
ClearScreen:
pusha
mov ah,00h
mov al,03h
int 10h
popa
ret
SetCursorPos:;dl = xpos, dh = ypos
pusha
mov ah,02h
mov dl,[xpos]
mov dh,[ypos]
int 10h
popa
ret
PrintText:;si = string start position
pusha
mov ah,09h
mov bh,00h
mov cx,01h
.dochar:
lodsb
or al,al
jz .return
int 10h
add [xpos],1d
call SetCursorPos
jmp .dochar
.return:
popa
ret
LoadStage2:
pusha
mov bx,0x2000 ;segment
mov es,bx
mov bx,0x00 ;offset
mov [counter1],1
.tryread:
mov ah,02h
mov al,2d
mov ch,00h
mov cl,02h
mov dh,00h
mov dl,80h
int 13h
jc .tryagain
mov bx,00000101b;purple on black
mov [xpos],4d;xpos
mov [ypos],3d;ypos
call SetCursorPos
mov si,donemsg
jmp .fin
.tryagain:
add [counter1],1
cmp [counter1],3
jg .failed
jmp .tryread
.failed:
mov bx,00000100b;red on black
mov [xpos],4d;xpos
mov [ypos],3d;ypos
call SetCursorPos
mov si,errormsg
.fin:
call PrintText
mov [xpos],0d;xpos
mov [ypos],5d;ypos
call SetCursorPos
popa
ret
;data section
bootstrapname db "Wolf Bootloader ",0
loadingmsg db "Loading System... ",0
errormsg db "Failed to Load System",0
donemsg db "System Loaded... ",0
haltexception db "Loader Halted! ",0
xpos db 0
ypos db 0
errorflag db 0
counter1 db 0
;bootloader specifics
times 510-($-$$) db 0
dw 0xAA55
Code: Select all
use16
org 0x0000
;retrieve active drive number, assuming the first bootloader cached it for us
pop dx
mov [drivenumber],dl
xor dx,dx
;reset registers
xor ax,ax
mov ds,ax
mov es,ax
cli
mov ss,ax
mov sp,0x2000
sti
;main
call ClearScreen
mov bx,00000101b;purple on black
mov [xpos],4d;xpos
mov [ypos],2d;ypos
call SetCursorPos
mov si,loadedmsg
call PrintText
mov [xpos],0d;xpos
mov [ypos],5d;ypos
call SetCursorPos
halt:
jmp halt
ClearScreen:
pusha
mov ah,00h
mov al,03h
int 10h
popa
ret
SetCursorPos:;dl = xpos, dh = ypos
pusha
mov ah,02h
mov dl,[xpos]
mov dh,[ypos]
int 10h
popa
ret
PrintText:;si = string start position
pusha
mov ah,09h
mov bh,00h
mov cx,01h
.dochar:
lodsb
or al,al
jz .return
int 10h
add [xpos],1d
call SetCursorPos
jmp .dochar
.return:
popa
ret
loadedmsg db "System Loaded",0
xpos db 0
ypos db 0
drivenumber db 80h ;edit: was dw, should be db (an error when pasting)
times 1024-($-$$) db 0
My guess is an addressing problem but I can't find it.
As for the screenshot the characters it's printing out it's almost like the computer is showing a confused emoticon... lol
Screenshot: