summaryrefslogtreecommitdiffstats
path: root/src/boot.s
diff options
context:
space:
mode:
Diffstat (limited to 'src/boot.s')
-rw-r--r--src/boot.s81
1 files changed, 81 insertions, 0 deletions
diff --git a/src/boot.s b/src/boot.s
new file mode 100644
index 0000000..28da384
--- /dev/null
+++ b/src/boot.s
@@ -0,0 +1,81 @@
+ mov ax, 0x7c0
+ mov ds, ax
+ mov ax, 0xb800 ; protected mode video memory segment (addr / 16)
+ mov es, ax
+ mov si, msg
+
+ cld
+
+ call print
+
+ cli
+
+; print using BIOS functions
+; print_loop:
+; lodsb ; load byte from DS:SI into al
+; or al, al
+; jz hang
+; mov ah, 0x0E
+; int 0x10
+; jmp print_loop
+
+; print without using BIOS functions
+print:
+ lodsb
+ cmp al, 0
+ jz exit_print
+
+ mov ah, 0x0F
+ mov cx, ax
+
+ movzx bx, byte [xpos]
+ shl bx, 1
+ movzx ax, byte [ypos]
+ mov dx, 160
+ mul dx
+
+ xor di, di
+ mov di, bx
+ add di, ax
+
+ mov ax, cx
+ stosw
+ add byte[xpos], 1
+ jmp print
+
+exit_print:
+ add byte[ypos], 1
+ mov byte[xpos], 0
+ ret
+
+hang:
+ jmp hang
+
+
+ ; vars
+ msg db 'Hello world', 13, 10, 0 ; Hello world CR LF \0
+ xpos db 0
+ ypos db 0
+
+
+ ; fill
+ times 0x1b8 -($-$$) db 0 ; fill MBR boostrap
+ dd 0 ; fill unique disk ID
+ dw 0 ; reserved
+ ; write first partition table entry CHS for start and end are set to 0
+ db 0x80 ; mark the partition as bootable
+ db 0x0 ; partition start head
+ dw 0x0 ; partition start sector and cylinder (sector = 1, cylinder = 0)
+ db 0x06 ; system ID (partition type, 07 = exFAT)
+ db 0x0 ; partition end head
+ dw 0x0 ; partition end sector and cylinder (sector = 5, cylinder = 455)
+ dd 0x1 ; partition start LBA
+ dd 0x3fff ; partition end LBA
+
+ times 0x10 db 0 ; fill second partition table entry
+ times 0x10 db 0 ; fill third partition table entry
+ times 0x10 db 0 ; fill fourth partition table entry
+ dw 0xAA55 ; valid boot sector signature
+
+ ; db 'TEST'
+ ; times 0x800000 - ($-$$) db 0