From 260db9f8d7f031d16176b22f0554511ac6222afe Mon Sep 17 00:00:00 2001 From: Ain <41307858+nero@users.noreply.github.com> Date: Sat, 23 Mar 2019 20:17:47 +0000 Subject: [PATCH] Move kernel libs into subdir, create NBP-specific entrypoint --- Makefile | 8 +++++--- debug.asm => kernel/debug.asm | 0 kernel/heap.asm | 28 ++++++++++++++++++++++++++++ intr.asm => kernel/intr.asm | 0 kprintf.asm => kernel/kprintf.asm | 0 main.asm => nbp.asm | 24 ++++++++++-------------- run.sh | 4 ++-- 7 files changed, 45 insertions(+), 19 deletions(-) rename debug.asm => kernel/debug.asm (100%) create mode 100644 kernel/heap.asm rename intr.asm => kernel/intr.asm (100%) rename kprintf.asm => kernel/kprintf.asm (100%) rename main.asm => nbp.asm (72%) diff --git a/Makefile b/Makefile index 8c5399b..32e8d85 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,7 @@ -kernel.com: *.asm - nasm -s -o kernel.com main.asm +default: nbp.com + +%.com: %.asm + nasm -s -o $@ $< clean: - rm -f kernel.com + rm -f *.com diff --git a/debug.asm b/kernel/debug.asm similarity index 100% rename from debug.asm rename to kernel/debug.asm diff --git a/kernel/heap.asm b/kernel/heap.asm new file mode 100644 index 0000000..a25cdf6 --- /dev/null +++ b/kernel/heap.asm @@ -0,0 +1,28 @@ +heap_size: + dw 0x0100 + +heap_init: + push ax ; byte value (0) + push cx ; loop counter + push di ; target ptr + xor ax, ax + mov cx, [heap_size] + mov di, heap + rep stosb ; rep makes this loop cx times, incrementing di, writing al + pop di + pop cx + pop ax + ret + +; in ax number of bytes to alloc +; out ds:di +malloc: + push dx ; length of block index + or ax,0x0F + inc ax + mov dx, 0x100 + mov bp, heap + + int 0x2E + pop dx + ret diff --git a/intr.asm b/kernel/intr.asm similarity index 100% rename from intr.asm rename to kernel/intr.asm diff --git a/kprintf.asm b/kernel/kprintf.asm similarity index 100% rename from kprintf.asm rename to kernel/kprintf.asm diff --git a/main.asm b/nbp.asm similarity index 72% rename from main.asm rename to nbp.asm index c6386ce..69eca89 100644 --- a/main.asm +++ b/nbp.asm @@ -1,6 +1,6 @@ ; assumptions about the starting envionment cpu 8086 -org 0x0000 ; if we are not at CS:0000, CS adjustment will fix it for us +org 0x0000 ; dl probable drive number ; ds:si probable pointer to partition structure ; es:bx probable pxeenv+ structure @@ -42,28 +42,24 @@ _exit: main: mov ax, cs mov ds, ax + mov es, ax mov bx, 0x002E mov dx, debug_reg_ir call ivt_set - mov ax, 0 - mov bx, 0 - call cons - mov si, di - call print + call heap_init + mov ax, 18 + call malloc ret -%include "intr.asm" -%include "debug.asm" -%include "kprintf.asm" -%include "heap.asm" - -%include "cons.asm" -%include "int.asm" -%include "print.asm" +%include "kernel/heap.asm" +%include "kernel/intr.asm" +%include "kernel/debug.asm" +%include "kernel/kprintf.asm" +align 16 heap: dw 0 diff --git a/run.sh b/run.sh index 1bd108f..8d144c3 100755 --- a/run.sh +++ b/run.sh @@ -1,5 +1,5 @@ #!/bin/sh -exec qemu-system-x86_64 -boot n \ +exec qemu-system-x86_64 -boot n -fda fd0.img \ -option-rom /usr/share/qemu/pxe-rtl8139.rom \ -device e1000,netdev=mynet0,mac=52:54:00:12:34:56 \ - -netdev user,id=mynet0,net=192.168.76.0/24,dhcpstart=192.168.76.9,tftp=$PWD,bootfile=kernel.com + -netdev user,id=mynet0,net=192.168.76.0/24,dhcpstart=192.168.76.9,tftp=$PWD,bootfile=nbp.com