From 3fe0dccba6a36462dff8e870b0441bf4a09c409e Mon Sep 17 00:00:00 2001 From: dzwdz Date: Mon, 16 Aug 2021 19:15:38 +0200 Subject: [PATCH] poc --- .gitignore | 2 ++ Makefile | 12 ++++++++++++ boot.s | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+) create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 boot.s diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8deeab7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.o +*.bin diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..6a5b710 --- /dev/null +++ b/Makefile @@ -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 $^ diff --git a/boot.s b/boot.s new file mode 100644 index 0000000..df6f49c --- /dev/null +++ b/boot.s @@ -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