diff --git a/Makefile b/Makefile index 0eea523..956ab1f 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,7 @@ +C_SOURCES = $(wildcard kernel/*.c drivers/*.c) +HEADERS = $(wildcard kernel/*.h drivers/*.h) +OBJ = $(C_SOURCES:.c=.o) + all: os-image run: all @@ -8,29 +12,27 @@ drun: clean run grub: eOS.iso qemu-system-x86_64 eOS.iso -eOS.iso : kernel.bin src/grub/grub.cfg +eOS.iso : kernel/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 +os-image: bootloader/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/kernel_entry.o $(OBJ) + gcc -o $@ $^ -Wl,--oformat=binary -ffreestanding -nostdlib -shared -Ttext 0x1000 -m32 -kernel.o : src/kernel/kernel.c +%.o : %.c gcc -fno-pie -m32 -Os -ffreestanding -c $< -o $@ -kernel_entry.o : src/kernel/kernel_entry.asm +%.o : %.asm nasm $< -f elf -o $@ -bootloader.bin : src/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 diff --git a/TODO.md b/TODO.md index 94694f8..8520c94 100644 --- a/TODO.md +++ b/TODO.md @@ -1,3 +1,8 @@ # TO DO + - Refactor Makefile + - Refactor file structure + - Finish the book! - 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/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/kernel/lib/vga.c b/drivers/vga.c similarity index 87% rename from src/kernel/lib/vga.c rename to drivers/vga.c index c3edfb8..cde216f 100644 --- a/src/kernel/lib/vga.c +++ b/drivers/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(); +} 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/kernel/kernel.c b/kernel/kernel.c new file mode 100644 index 0000000..36b9639 --- /dev/null +++ b/kernel/kernel.c @@ -0,0 +1,7 @@ +void main() { + 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); +} 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/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" diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c deleted file mode 100644 index bf1bd80..0000000 --- a/src/kernel/kernel.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "lib/vga.c" - -void main() { - clear_screen(); - set_cursor_pos(28, 2); - print("eOS Version 0.1 2021", 0xf0); -} 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); -}