From 799dcba26edfccbbb485f9dcb8b8e0e9a2cab572 Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Tue, 17 Aug 2021 17:13:45 +0200 Subject: [PATCH 1/9] Strings --- src/kernel/kernel.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c index bf1bd80..13cd450 100644 --- a/src/kernel/kernel.c +++ b/src/kernel/kernel.c @@ -1,4 +1,5 @@ #include "lib/vga.c" +#include void main() { clear_screen(); From e05eb80863e8bccf11e8c8c1503690b634904930 Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Tue, 17 Aug 2021 22:20:24 +0200 Subject: [PATCH 2/9] Removed bloat --- src/kernel/lib/string.c | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 src/kernel/lib/string.c diff --git a/src/kernel/lib/string.c b/src/kernel/lib/string.c deleted file mode 100644 index 7b9dcd4..0000000 --- a/src/kernel/lib/string.c +++ /dev/null @@ -1,8 +0,0 @@ -// Generic String Library -#define INDEX(s, c) (int)(c-s) - -unsigned int length(char* str) { - char* p; - for( p = str; *p != '\0'; p++ ) {} - return (unsigned int)(p-str); -} From d2bcea854b2279910c45407cfa94708d7749ed7a Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Tue, 17 Aug 2021 22:40:31 +0200 Subject: [PATCH 3/9] Disabling the VGA cursor --- src/kernel/kernel.c | 4 ++-- src/kernel/lib/vga.c | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c index 13cd450..6d38209 100644 --- a/src/kernel/kernel.c +++ b/src/kernel/kernel.c @@ -1,8 +1,8 @@ #include "lib/vga.c" -#include void main() { - clear_screen(); + vga_init(); + set_cursor_pos(28, 2); print("eOS Version 0.1 2021", 0xf0); } diff --git a/src/kernel/lib/vga.c b/src/kernel/lib/vga.c index c3edfb8..cde216f 100644 --- a/src/kernel/lib/vga.c +++ b/src/kernel/lib/vga.c @@ -1,4 +1,5 @@ // VGA Graphics Library +#include // VGA base address: 0xb8000 // Charpos = 0xb8000 + 2(row*80 + col) @@ -34,6 +35,11 @@ void clear_screen() { *c = 0x20; } +void disable_cursor() { + outb(0x3d4, 0x0a); + outb(0x3d5, 0x20); +} + /* General Printing Functions @@ -52,3 +58,10 @@ void println(char* str, int colorcode) { print(str, colorcode); cursor_row++; // Increment to next y-pos (newline) } + + +// VGA Initialization Function +void vga_init() { + disable_cursor(); + clear_screen(); +} From 386f1888073a2d6cf2d0df61ce6766d5040d749a Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Tue, 17 Aug 2021 22:56:23 +0200 Subject: [PATCH 4/9] Fuck you QEMU --- TODO.md | 4 +++- src/kernel/kernel.c | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/TODO.md b/TODO.md index 94694f8..94562b4 100644 --- a/TODO.md +++ b/TODO.md @@ -1,3 +1,5 @@ # TO DO - Multiboot support (for grub etc) - - Expand os-image so there is no error 0x8b00! + - VGA Library (Graphics) + - User input (Keyboard) + - File system? diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c index 6d38209..add430b 100644 --- a/src/kernel/kernel.c +++ b/src/kernel/kernel.c @@ -1,7 +1,8 @@ #include "lib/vga.c" void main() { - vga_init(); + vga_init(); // Initialize the screen first + // i.e. clear the screen et cetera. set_cursor_pos(28, 2); print("eOS Version 0.1 2021", 0xf0); From bd1d276a977818ca115e8cfd0856de53a238ef12 Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Tue, 17 Aug 2021 23:00:42 +0200 Subject: [PATCH 5/9] TODO update --- TODO.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/TODO.md b/TODO.md index 94562b4..692c607 100644 --- a/TODO.md +++ b/TODO.md @@ -1,4 +1,6 @@ # TO DO + - Refactor Makefile + - Finish the book! - Multiboot support (for grub etc) - VGA Library (Graphics) - User input (Keyboard) From c35a1bc083d7966e9d1d9e08b77c72d2131dd35f Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Wed, 18 Aug 2021 13:37:57 +0200 Subject: [PATCH 6/9] File structure fix & Makefile refactoring --- Makefile | 12 +++++++----- TODO.md | 1 + bootloader/bios.asm | 7 +++++++ {src/bootloader => bootloader}/bios/convert.asm | 0 {src/bootloader => bootloader}/bios/disk.asm | 0 {src/bootloader => bootloader}/bios/print.asm | 0 {src/bootloader => bootloader}/bootloader.asm | 6 +++--- {src/bootloader => bootloader}/equ/ascii.asm | 0 {src/bootloader => bootloader}/equ/bios.asm | 0 {src/bootloader => bootloader}/equ/vga.asm | 0 {src/bootloader => bootloader}/pm.asm | 6 +++--- {src/bootloader => bootloader}/pm/gdt.asm | 0 {src/bootloader => bootloader}/pm/vga/print.asm | 0 {src/grub => grub}/grub.cfg | 0 {src/kernel => kernel}/kernel.c | 0 {src/kernel => kernel}/kernel_entry.asm | 0 {src/kernel => kernel}/lib/vga.c | 0 src/bootloader/bios.asm | 7 ------- 18 files changed, 21 insertions(+), 18 deletions(-) create mode 100644 bootloader/bios.asm rename {src/bootloader => bootloader}/bios/convert.asm (100%) rename {src/bootloader => bootloader}/bios/disk.asm (100%) rename {src/bootloader => bootloader}/bios/print.asm (100%) rename {src/bootloader => bootloader}/bootloader.asm (89%) rename {src/bootloader => bootloader}/equ/ascii.asm (100%) rename {src/bootloader => bootloader}/equ/bios.asm (100%) rename {src/bootloader => bootloader}/equ/vga.asm (100%) rename {src/bootloader => bootloader}/pm.asm (81%) rename {src/bootloader => bootloader}/pm/gdt.asm (100%) rename {src/bootloader => bootloader}/pm/vga/print.asm (100%) rename {src/grub => grub}/grub.cfg (100%) rename {src/kernel => kernel}/kernel.c (100%) rename {src/kernel => kernel}/kernel_entry.asm (100%) rename {src/kernel => kernel}/lib/vga.c (100%) delete mode 100644 src/bootloader/bios.asm diff --git a/Makefile b/Makefile index 0eea523..d7e1e3f 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,5 @@ +C_SOURCES = $(wildcard kernel/*.c drivers/*.c) + all: os-image run: all @@ -8,10 +10,10 @@ drun: clean run grub: eOS.iso qemu-system-x86_64 eOS.iso -eOS.iso : kernel.bin src/grub/grub.cfg +eOS.iso : kernel.bin grub/grub.cfg mkdir -p boot/grub cp $< boot/eOS.bin - cp src/grub/grub.cfg boot/grub/grub.cfg + cp grub/grub.cfg boot/grub/grub.cfg grub-mkrescue -o eOS.iso ./ os-image: bootloader.bin kernel.bin @@ -20,13 +22,13 @@ os-image: bootloader.bin kernel.bin kernel.bin: kernel_entry.o kernel.o gcc -o kernel.bin $^ -Wl,--oformat=binary -ffreestanding -nostdlib -shared -Ttext 0x1000 -m32 -kernel.o : src/kernel/kernel.c +kernel.o : kernel/kernel.c gcc -fno-pie -m32 -Os -ffreestanding -c $< -o $@ -kernel_entry.o : src/kernel/kernel_entry.asm +kernel_entry.o : kernel/kernel_entry.asm nasm $< -f elf -o $@ -bootloader.bin : src/bootloader/bootloader.asm +bootloader.bin : bootloader/bootloader.asm nasm $< -f bin -o $@ clean: diff --git a/TODO.md b/TODO.md index 692c607..8520c94 100644 --- a/TODO.md +++ b/TODO.md @@ -1,5 +1,6 @@ # TO DO - Refactor Makefile + - Refactor file structure - Finish the book! - Multiboot support (for grub etc) - VGA Library (Graphics) diff --git a/bootloader/bios.asm b/bootloader/bios.asm new file mode 100644 index 0000000..339a9dc --- /dev/null +++ b/bootloader/bios.asm @@ -0,0 +1,7 @@ +; EQUs +%include "bootloader/equ/bios.asm" + +; SRs +%include "bootloader/bios/convert.asm" +%include "bootloader/bios/print.asm" +%include "bootloader/bios/disk.asm" diff --git a/src/bootloader/bios/convert.asm b/bootloader/bios/convert.asm similarity index 100% rename from src/bootloader/bios/convert.asm rename to bootloader/bios/convert.asm diff --git a/src/bootloader/bios/disk.asm b/bootloader/bios/disk.asm similarity index 100% rename from src/bootloader/bios/disk.asm rename to bootloader/bios/disk.asm diff --git a/src/bootloader/bios/print.asm b/bootloader/bios/print.asm similarity index 100% rename from src/bootloader/bios/print.asm rename to bootloader/bios/print.asm diff --git a/src/bootloader/bootloader.asm b/bootloader/bootloader.asm similarity index 89% rename from src/bootloader/bootloader.asm rename to bootloader/bootloader.asm index 64553e6..a5578fe 100644 --- a/src/bootloader/bootloader.asm +++ b/bootloader/bootloader.asm @@ -20,9 +20,9 @@ jmp $ ; inf loop -%include "src/bootloader/equ/ascii.asm" -%include "src/bootloader/bios.asm" -%include "src/bootloader/pm.asm" +%include "bootloader/equ/ascii.asm" +%include "bootloader/bios.asm" +%include "bootloader/pm.asm" BEGIN_PM: ; Inform of mode switch diff --git a/src/bootloader/equ/ascii.asm b/bootloader/equ/ascii.asm similarity index 100% rename from src/bootloader/equ/ascii.asm rename to bootloader/equ/ascii.asm diff --git a/src/bootloader/equ/bios.asm b/bootloader/equ/bios.asm similarity index 100% rename from src/bootloader/equ/bios.asm rename to bootloader/equ/bios.asm diff --git a/src/bootloader/equ/vga.asm b/bootloader/equ/vga.asm similarity index 100% rename from src/bootloader/equ/vga.asm rename to bootloader/equ/vga.asm diff --git a/src/bootloader/pm.asm b/bootloader/pm.asm similarity index 81% rename from src/bootloader/pm.asm rename to bootloader/pm.asm index 3d4cef6..1965d11 100644 --- a/src/bootloader/pm.asm +++ b/bootloader/pm.asm @@ -1,9 +1,9 @@ ; Utils -%include "src/bootloader/equ/vga.asm" -%include "src/bootloader/pm/vga/print.asm" +%include "bootloader/equ/vga.asm" +%include "bootloader/pm/vga/print.asm" ; GDT & switching to PM -%include "src/bootloader/pm/gdt.asm" ; GDT defined here +%include "bootloader/pm/gdt.asm" ; GDT defined here ; Switching to PM [bits 16] diff --git a/src/bootloader/pm/gdt.asm b/bootloader/pm/gdt.asm similarity index 100% rename from src/bootloader/pm/gdt.asm rename to bootloader/pm/gdt.asm diff --git a/src/bootloader/pm/vga/print.asm b/bootloader/pm/vga/print.asm similarity index 100% rename from src/bootloader/pm/vga/print.asm rename to bootloader/pm/vga/print.asm diff --git a/src/grub/grub.cfg b/grub/grub.cfg similarity index 100% rename from src/grub/grub.cfg rename to grub/grub.cfg diff --git a/src/kernel/kernel.c b/kernel/kernel.c similarity index 100% rename from src/kernel/kernel.c rename to kernel/kernel.c diff --git a/src/kernel/kernel_entry.asm b/kernel/kernel_entry.asm similarity index 100% rename from src/kernel/kernel_entry.asm rename to kernel/kernel_entry.asm diff --git a/src/kernel/lib/vga.c b/kernel/lib/vga.c similarity index 100% rename from src/kernel/lib/vga.c rename to kernel/lib/vga.c diff --git a/src/bootloader/bios.asm b/src/bootloader/bios.asm deleted file mode 100644 index ec08a80..0000000 --- a/src/bootloader/bios.asm +++ /dev/null @@ -1,7 +0,0 @@ -; EQUs -%include "src/bootloader/equ/bios.asm" - -; SRs -%include "src/bootloader/bios/convert.asm" -%include "src/bootloader/bios/print.asm" -%include "src/bootloader/bios/disk.asm" From cc9ff48be5b036bb5ec3c4ef1c471471a1f86738 Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Wed, 18 Aug 2021 14:13:51 +0200 Subject: [PATCH 7/9] File struc --- {kernel/lib => drivers}/vga.c | 0 kernel/kernel.c | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename {kernel/lib => drivers}/vga.c (100%) diff --git a/kernel/lib/vga.c b/drivers/vga.c similarity index 100% rename from kernel/lib/vga.c rename to drivers/vga.c diff --git a/kernel/kernel.c b/kernel/kernel.c index add430b..0ec29a5 100644 --- a/kernel/kernel.c +++ b/kernel/kernel.c @@ -1,4 +1,4 @@ -#include "lib/vga.c" +#include "../drivers/vga.c" void main() { vga_init(); // Initialize the screen first From 9674151cb4fd5ff2eaf6a6fd956290b6e4943a14 Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Wed, 18 Aug 2021 14:26:38 +0200 Subject: [PATCH 8/9] Broken Makefile --- Makefile | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index d7e1e3f..1a5eb4e 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,6 @@ C_SOURCES = $(wildcard kernel/*.c drivers/*.c) +HEADERS = $(wildcard kernel/*.h drivers/*.h) +OBJ = $(C_SOURCES:.c=.o) all: os-image @@ -19,20 +21,18 @@ eOS.iso : kernel.bin grub/grub.cfg os-image: bootloader.bin kernel.bin cat $^ > os-image -kernel.bin: kernel_entry.o kernel.o - gcc -o kernel.bin $^ -Wl,--oformat=binary -ffreestanding -nostdlib -shared -Ttext 0x1000 -m32 +kernel.bin: kernel_entry.o $(OBJ) + gcc -o $@ $^ -Wl,--oformat=binary -ffreestanding -nostdlib -shared -Ttext 0x1000 -m32 -kernel.o : kernel/kernel.c +%.o : %.c gcc -fno-pie -m32 -Os -ffreestanding -c $< -o $@ -kernel_entry.o : kernel/kernel_entry.asm +%.o : %.asm nasm $< -f elf -o $@ -bootloader.bin : bootloader/bootloader.asm +%.bin : %.asm nasm $< -f bin -o $@ clean: rm -fr *.bin *.dis *.o os-image *.map boot/ *.iso - -kernel.dis : kernel.bin - ndisasm -b 32 $< > $@ + rm -fr kernel/*.o boot/*.bin drivers/*.o From 1b8020b624171e70558edc4c9c3d93b85cdf9c0f Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Wed, 18 Aug 2021 14:29:15 +0200 Subject: [PATCH 9/9] Fixed Makefile --- Makefile | 6 +++--- kernel/kernel.c | 2 -- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 1a5eb4e..956ab1f 100644 --- a/Makefile +++ b/Makefile @@ -12,16 +12,16 @@ drun: clean run grub: eOS.iso qemu-system-x86_64 eOS.iso -eOS.iso : kernel.bin grub/grub.cfg +eOS.iso : kernel/kernel.bin grub/grub.cfg mkdir -p boot/grub cp $< boot/eOS.bin cp grub/grub.cfg boot/grub/grub.cfg grub-mkrescue -o eOS.iso ./ -os-image: bootloader.bin kernel.bin +os-image: bootloader/bootloader.bin kernel.bin cat $^ > os-image -kernel.bin: kernel_entry.o $(OBJ) +kernel.bin: kernel/kernel_entry.o $(OBJ) gcc -o $@ $^ -Wl,--oformat=binary -ffreestanding -nostdlib -shared -Ttext 0x1000 -m32 %.o : %.c diff --git a/kernel/kernel.c b/kernel/kernel.c index 0ec29a5..36b9639 100644 --- a/kernel/kernel.c +++ b/kernel/kernel.c @@ -1,5 +1,3 @@ -#include "../drivers/vga.c" - void main() { vga_init(); // Initialize the screen first // i.e. clear the screen et cetera.