Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;; A tiny, working bootloader for x86 PCs. Has a few subroutines
- ;; so it's slightly less useless than just printing "hello world".
- ;;
- ;; writeup here: http://joebergeron.io/posts/post_two.html
- ;;
- ;; Joe Bergeron, 2016.
- ;;
- ;;
- bits 16
- mov ax, 07C0h
- mov ds, ax
- mov ax, 07E0h ; 07E0h = (07C00h+200h)/10h, beginning of stack segment.
- mov ss, ax
- mov sp, 2000h ; 8k of stack space.
- call cleanscreen
- push 0000h
- call movecursor
- push 1
- call cleanstack
- push welcome_msg
- call printmsg
- push 1
- call cleanstack
- cli
- hlt
- cleanstack:
- push bp
- mov bp, sp
- pusha
- mov bx, 2
- .clean_param:
- mov ax, [bp + 4]
- mul bx
- add bp, ax
- mov word [bp + 4], 0
- sub bp, ax
- test ax, 0
- jz .clean_last
- jmp .clean_param
- .clean_last:
- mov word [bp + 4], 0 ; clean `cleanstack` param also...
- popa
- mov sp, bp
- pop bp
- ret
- cleanscreen:
- push bp
- mov bp, sp
- pusha
- mov ah, 07h ; tells BIOS to scroll down window
- mov al, 00h ; clean entire window
- xor bh, bh ; set bh to 0: default...
- ;mov bh, 07h ; white on black
- xor cx, cx ; specifies top left of screen as (0,0)
- mov dh, 18h ; 18h = 24 rows of chars
- mov dl, 4fh ; 4fh = 79 cols of chars
- int 10h ; calls video interrupt
- popa
- mov sp, bp
- pop bp
- ret
- movecursor:
- push bp
- mov bp, sp
- pusha
- mov dx, [bp + 4] ; get the argument from the stack.
- mov ah, 02h ; set cursor position
- mov bh, 00h ; page 0 - doesn't matter, we're not using double-buffering
- int 10h
- popa
- mov sp, bp
- pop bp
- ret
- printmsg:
- push bp
- mov bp, sp
- pusha
- mov si, [bp+4] ; grab the pointer to the data
- mov bh, 00h ; page number, 0 again
- mov bl, 00h ; foreground color, irrelevant - in text mode
- mov ah, 0Eh ; print character to TTY
- .char:
- mov al, [si] ; get the current char from our pointer position
- add si, 1 ; keep incrementing si until we see a null char
- or al, 0
- je .return ; end if the string is done
- int 10h ; print the character if we're not done
- jmp .char ; keep looping
- .return:
- popa
- mov sp, bp
- pop bp
- ret
- welcome_msg:
- db "Welcome to P&D OS", 0
- booting_msg:
- db "Booting...", 0
- ; Write 0s until 512 - 2 (1st bootsector size - look forward).
- times 510-($-$$) db 0
- ; END OF BOOTLOADER (required).
- dw 0xAA55
- ; END OF BOOTLOADER
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement