I have looked into making a small OS for the sake of learning, and am on the bootloader right now. I want to be able to use int 0x13
to read sectors from a floppy drive, put them into memory, then jump to that code. Here is what I have so far:
org 0x7c00
bits 16
main:
call setup_segments
mov ah, 2 ; function
mov al, 1 ; num of sectors
mov ch, 1 ; cylinder
mov cl, 2 ; sector
mov dh, 0 ; head
mov dl, 0 ; drive
mov bx, 0x1000 ;
mov es, bx ; dest (segment)
mov bx, 0 ; dest (offset)
int 0x13 ; BIOS Drive Interrupt
jmp 0x1000:0 ; jump to loaded code
times 510 - ($-$$) db 0 ; fluff up program to 510 B
dw 0xAA55 ; boot loader signature
LoadTarget: ; Print Message, Get Key Press, Reboot
jmp new_main
Greeting: db "Hello, welcome to the bestest bootloader there ever was!", 0
Prompt: db "Press any key to reboot...", 0
Println:
lodsb ; al <-- [ds:si], si++
or al, al ; needed for jump ?
jz PrintNwl ; if null is found print '\r\n'
mov ah, 0x0e ; function
mov bh, 0 ; page number ?
mov bl, 7 ; text attribute ?
int 0x10 ; BIOS Interrupt
jmp Println
PrintNwl: ; print \r\n
; print \r
mov ah, 0x0e ; function
mov al, 13 ; char (carriage return)
mov bh, 0 ; page number ?
mov bl, 7 ; text attribute ?
int 0x10
; print \n
mov ah, 0x0e ; function
mov al, 20 ; char (line feed)
mov bh, 0 ; page number ?
mov bl, 7 ; text attribute ?
int 0x10
ret ; return
GetKeyPress:
mov si, Prompt ; load prompt
call Println ; print prompt
xor ah, ah ; clear ah
int 0x16 ; BIOS Keyboard Service
ret ; return
setup_segments:
cli ;Clear interrupts
;Setup stack segments
mov ax,cs
mov ds,ax
mov es,ax
mov ss,ax
sti ;Enable interrupts
ret
new_main:
call setup_segments
mov si, Greeting ; load greeting
call Println ; print greeting
call GetKeyPress ; wait for key press
jmp 0xffff:0 ; jump to reboot address
times 1024 - ($-$$) db 0 ; fluff up sector
I want to load the sector after LoadTarget
into the address 0x1000:0
, then jump to it. So far I just get a blank screen. I feel like the bug is somewhere between main
and the line times 510 - ($-$$) db 0
. Maybe I'm just not getting the values of the register right? Please help! Thanks