From 63853960825f007827a79f704d291c372c807096 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Duje=20Mihanovi=C4=87?= Date: Thu, 9 Sep 2021 11:13:53 +0200 Subject: [PATCH] Restructure the bootloader --- .gitignore | 1 - Makefile | 10 +++---- boot/x86/a20.s | 49 ++++++++++++++++++++++++++++++ boot/x86/boot | Bin 0 -> 512 bytes boot/x86/boot.s | 53 +++++++++++++++++++++++++++++++++ boot.s => boot/x86/protected.s | 52 ++------------------------------ 6 files changed, 109 insertions(+), 56 deletions(-) create mode 100644 boot/x86/a20.s create mode 100644 boot/x86/boot create mode 100644 boot/x86/boot.s rename boot.s => boot/x86/protected.s (64%) diff --git a/.gitignore b/.gitignore index 988eea0..a5ea528 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ toolchain/ -boot boot.img **/*.o **/*.bin diff --git a/Makefile b/Makefile index a4c88b3..9d1c344 100644 --- a/Makefile +++ b/Makefile @@ -6,12 +6,12 @@ KERNEL_OBJ = kernel/entry.o kernel/arch/x86/tty/tty.o kernel/kernel.o all: boot.img -boot.img: boot kernel/kernel.bin - cat boot kernel/kernel.bin > $@ +boot.img: boot/x86/boot kernel/kernel.bin + cat boot/x86/boot kernel/kernel.bin > $@ truncate -s1440K $@ -boot: boot.s - $(AS) -f bin boot.s -o $@ +boot/x86/boot: boot/x86/boot.s boot/x86/a20.s boot/x86/protected.s + $(AS) -f bin boot/x86/boot.s -o $@ kernel/kernel.bin: ${KERNEL_OBJ} $(LD) -o $@ -T kernel/linker.ld ${KERNEL_OBJ} --oformat=binary @@ -26,6 +26,6 @@ kernel/kernel.o: kernel/kernel.c $(CC) -g -o $@ -Iinclude/arch/x86 -ffreestanding -c kernel/kernel.c clean: - rm boot kernel/kernel.bin ${KERNEL_OBJ} boot.img + rm boot/x86/boot kernel/kernel.bin ${KERNEL_OBJ} boot.img .PHONY: all clean diff --git a/boot/x86/a20.s b/boot/x86/a20.s new file mode 100644 index 0000000..f6a292b --- /dev/null +++ b/boot/x86/a20.s @@ -0,0 +1,49 @@ +; Some routines for managing the A20 line + +; Check if A20 is enabled +; Based on , slightly modified +check_a20 + pushf ; save EFLAGS + ; save segment and index registers + push ds + push es + push di + push si + + cli ; disable interrupts + xor ax, ax ; ax = 0 + mov es, ax ; es = 0 + + not ax ; ax = FFFFh + mov ds, ax ; ds = FFFFh + + mov di, 500h + mov si, 510h + + mov al, [es:di] ; preserve contents of 0:500h + mov ah, [ds:si] ; preserve contents of FFFFh:510h + push ax ; push all that to stack + + mov byte [es:di], 0 ; set 0:500h to 0 + mov byte [ds:si], 0FFh ; set FFFFh:510h to FFh + + cmp byte [es:di], 0FFh ; compare 0:500h with FFh + ; if A20 is enabled, this will not be equal, but if A20 is disabled it will be + + pop ax ; pop old contents of the 2 addresses + mov [ds:si], ah ; restore contents of FFFFh:510h + mov [es:di], al ; restore contents of 0:500h + + xor ax, ax ; clear ax + je .exit ; if A20 is disabled, return 0 + mov ax, 1 ; otherwise return 1 + +.exit + pop si + pop di + pop es + pop ds + popf + sti + ret + diff --git a/boot/x86/boot b/boot/x86/boot new file mode 100644 index 0000000000000000000000000000000000000000..a70865181bef901f68adda2d1ab6a34b24541678 GIT binary patch literal 512 zcmeAWld9dzFro9!eg+1^180Scq_;3_;4*l-k;&kj;qAV|yBP$4f`T?&HN3Awb~Ehg zJFIq$)$lbpjA`_m;q|{ca%|yYzYGub9r%8s@5X)x)_nr3YF(^$T`B=U)eLsWSpKUu z*#3{O>rheaU^P5Y!n}i#AugU>e(rCe1z6cefCS2&Q?e1ef*>A