This commit is contained in:
dzwdz 2021-08-16 19:15:38 +02:00
commit 3fe0dccba6
3 changed files with 53 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*.o
*.bin

12
Makefile Normal file
View File

@ -0,0 +1,12 @@
boot.bin: boot.o
ld -o $@ --oformat binary -Ttext 0x7c00 $<
boot.o: boot.s
as -o $@ $<
.PHONY: boot disasm
boot: boot.bin
qemu-system-i386 -drive file=$^,index=0,if=floppy,format=raw
disasm: boot.bin
objdump -D -b binary -mi8086 $^

39
boot.s Normal file
View File

@ -0,0 +1,39 @@
.code16
.global _start # the linker needs to find it
_start:
# enter mode 13h
mov $0x13, %ax
int $0x10
mov $0xA000, %ax # ES = vga memory
mov %ax, %es
mov $0x7c0, %ax # DS = the bootsector
mov %ax, %ds
# %eax - position in sector
# it has to take up all of eax because of as's lack of real support
# for 16bit
# %ebx - position in vga mem
mov $0, %eax
mov $0, %ebx
loop:
movb %ds:(%eax), %cl
movb %cl, %es:(%ebx)
inc %bx
mov $16, %cl # if we've crossed a 16 pixel boundary, skip to the next line
and %bx, %cx
jz not_eol
add $304, %bx
not_eol:
inc %ax # only iterate 512 times
cmp $512, %ax
jl loop
incb %es:319
hlt
.fill 510-(.-_start), 1, 0x90 # fill with 0x90 (NOPs)
.word 0xaa55 # boot sector magic