From ddd2287711c783ee3f1af84d34435c074409b403 Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Thu, 12 Aug 2021 12:19:59 +0200 Subject: [PATCH 1/6] Fixed printing --- src/bios/disk.asm | 2 +- src/bootloader.asm | 2 +- src/lib/vga.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/bios/disk.asm b/src/bios/disk.asm index 9cb7cbf..1dbc359 100644 --- a/src/bios/disk.asm +++ b/src/bios/disk.asm @@ -42,4 +42,4 @@ read_error: read_error_string: db ASCII_CARRIAGE_RETURN, ASCII_LINEBREAK, "ERROR! Disk read failed.", ASCII_END error_code_string: db "Error code: ", ASCII_END -sector_error_string: db "Invalid number of sectors read!", ASCII_END +sector_error_string: db "Invalid number of sectors read!", ASCII_END diff --git a/src/bootloader.asm b/src/bootloader.asm index c568288..a61e356 100644 --- a/src/bootloader.asm +++ b/src/bootloader.asm @@ -38,7 +38,7 @@ BEGIN_PM: load_kernel: mov bx, KERNEL_OFFSET ; Load kernel at the kernel offset - mov dh, 7 ; Read 15 sectors + mov dh, 9 ; Read 15 sectors mov dl, [BOOT_DRIVE] ; Drive index call disk_read ; Load the kernel diff --git a/src/lib/vga.c b/src/lib/vga.c index d951031..e3948e9 100644 --- a/src/lib/vga.c +++ b/src/lib/vga.c @@ -13,7 +13,7 @@ char* get_cursor_pos(unsigned int col, unsigned int row) { void print(char* str, unsigned int str_len) { for( char* c = str; *c != '\0'; c++ ) - *get_cursor_pos( GET_INDEX(str, c), cursor_y ) = 'Y'; + *get_cursor_pos( GET_INDEX(str, c), cursor_y ) = *c; } void println(char* str, unsigned int str_len) { From aa38917ca8767dd0184d6bb4207fee4e39e41cee Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Thu, 12 Aug 2021 12:34:53 +0200 Subject: [PATCH 2/6] File structure refactor --- compile.sh | 4 ++-- src/{ => bootloader}/bios.asm | 0 src/{ => bootloader}/bios/convert.asm | 0 src/{ => bootloader}/bios/disk.asm | 0 src/{ => bootloader}/bios/print.asm | 0 src/{ => bootloader}/bootloader.asm | 0 src/{ => bootloader}/equ/ascii.asm | 0 src/{ => bootloader}/equ/bios.asm | 0 src/{ => bootloader}/equ/vga.asm | 0 src/{ => bootloader}/pm.asm | 0 src/{ => bootloader}/pm/gdt.asm | 0 src/{ => bootloader}/pm/vga/print.asm | 0 src/{ => kernel}/kernel.c | 0 src/{ => kernel}/lib/vga.c | 0 14 files changed, 2 insertions(+), 2 deletions(-) rename src/{ => bootloader}/bios.asm (100%) rename src/{ => bootloader}/bios/convert.asm (100%) rename src/{ => bootloader}/bios/disk.asm (100%) rename src/{ => bootloader}/bios/print.asm (100%) rename src/{ => bootloader}/bootloader.asm (100%) rename src/{ => bootloader}/equ/ascii.asm (100%) rename src/{ => bootloader}/equ/bios.asm (100%) rename src/{ => bootloader}/equ/vga.asm (100%) rename src/{ => bootloader}/pm.asm (100%) rename src/{ => bootloader}/pm/gdt.asm (100%) rename src/{ => bootloader}/pm/vga/print.asm (100%) rename src/{ => kernel}/kernel.c (100%) rename src/{ => kernel}/lib/vga.c (100%) diff --git a/compile.sh b/compile.sh index a1a90f3..ad0984d 100755 --- a/compile.sh +++ b/compile.sh @@ -7,10 +7,10 @@ srcDir=src binDir=bin echo "Compiling bootloader... " -nasm -f bin $srcDir/bootloader.asm -i $srcDir -o $binDir/bootloader.bin +nasm -f bin $srcDir/bootloader/bootloader.asm -i $srcDir/bootloader -o $binDir/bootloader.bin echo "Compiling kernel... " -gcc -fno-pie -m32 -Os -ffreestanding -c $srcDir/kernel.c -o $binDir/kernel.o && gcc -o $binDir/kernel.bin $binDir/kernel.o -Wl,--oformat=binary -ffreestanding -nostdlib -shared -Ttext 0x1000 -m32 +gcc -fno-pie -m32 -Os -ffreestanding -c $srcDir/kernel/kernel.c -o $binDir/kernel.o && gcc -o $binDir/kernel.bin $binDir/kernel.o -Wl,--oformat=binary -ffreestanding -nostdlib -shared -Ttext 0x1000 -m32 echo "Creating OS image... " cat $binDir/bootloader.bin $binDir/kernel.bin > $binDir/os-image diff --git a/src/bios.asm b/src/bootloader/bios.asm similarity index 100% rename from src/bios.asm rename to src/bootloader/bios.asm diff --git a/src/bios/convert.asm b/src/bootloader/bios/convert.asm similarity index 100% rename from src/bios/convert.asm rename to src/bootloader/bios/convert.asm diff --git a/src/bios/disk.asm b/src/bootloader/bios/disk.asm similarity index 100% rename from src/bios/disk.asm rename to src/bootloader/bios/disk.asm diff --git a/src/bios/print.asm b/src/bootloader/bios/print.asm similarity index 100% rename from src/bios/print.asm rename to src/bootloader/bios/print.asm diff --git a/src/bootloader.asm b/src/bootloader/bootloader.asm similarity index 100% rename from src/bootloader.asm rename to src/bootloader/bootloader.asm diff --git a/src/equ/ascii.asm b/src/bootloader/equ/ascii.asm similarity index 100% rename from src/equ/ascii.asm rename to src/bootloader/equ/ascii.asm diff --git a/src/equ/bios.asm b/src/bootloader/equ/bios.asm similarity index 100% rename from src/equ/bios.asm rename to src/bootloader/equ/bios.asm diff --git a/src/equ/vga.asm b/src/bootloader/equ/vga.asm similarity index 100% rename from src/equ/vga.asm rename to src/bootloader/equ/vga.asm diff --git a/src/pm.asm b/src/bootloader/pm.asm similarity index 100% rename from src/pm.asm rename to src/bootloader/pm.asm diff --git a/src/pm/gdt.asm b/src/bootloader/pm/gdt.asm similarity index 100% rename from src/pm/gdt.asm rename to src/bootloader/pm/gdt.asm diff --git a/src/pm/vga/print.asm b/src/bootloader/pm/vga/print.asm similarity index 100% rename from src/pm/vga/print.asm rename to src/bootloader/pm/vga/print.asm diff --git a/src/kernel.c b/src/kernel/kernel.c similarity index 100% rename from src/kernel.c rename to src/kernel/kernel.c diff --git a/src/lib/vga.c b/src/kernel/lib/vga.c similarity index 100% rename from src/lib/vga.c rename to src/kernel/lib/vga.c From f5f14f28449cec7faf0599ca94afab3bd557827a Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Thu, 12 Aug 2021 12:47:49 +0200 Subject: [PATCH 3/6] compile.sh refactor --- compile.sh | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/compile.sh b/compile.sh index ad0984d..28b61b3 100755 --- a/compile.sh +++ b/compile.sh @@ -1,16 +1,27 @@ #!/usr/bin/bash -done="[OK]" -fail="[FAIL]" +option=$1 srcDir=src binDir=bin -echo "Compiling bootloader... " -nasm -f bin $srcDir/bootloader/bootloader.asm -i $srcDir/bootloader -o $binDir/bootloader.bin +compile_bootloader() { + echo "Compiling bootloader... " + nasm -f bin $srcDir/bootloader/bootloader.asm -i $srcDir/bootloader -o $binDir/bootloader.bin +} -echo "Compiling kernel... " -gcc -fno-pie -m32 -Os -ffreestanding -c $srcDir/kernel/kernel.c -o $binDir/kernel.o && gcc -o $binDir/kernel.bin $binDir/kernel.o -Wl,--oformat=binary -ffreestanding -nostdlib -shared -Ttext 0x1000 -m32 +compile_kernel() { + echo "Compiling kernel... " + gcc -fno-pie -m32 -Os -ffreestanding -c $srcDir/kernel/kernel.c -o $binDir/kernel.o && gcc -o $binDir/kernel.bin $binDir/kernel.o -Wl,--oformat=binary -ffreestanding -nostdlib -shared -Ttext 0x1000 -m32 +} -echo "Creating OS image... " -cat $binDir/bootloader.bin $binDir/kernel.bin > $binDir/os-image +create_os_image() { + echo "Creating OS image... " + cat $binDir/bootloader.bin $binDir/kernel.bin > $binDir/os-image +} + + + +compile_bootloader +compile_kernel +create_os_image From ad031119741fc625fbc605af2c140e224a4b37c9 Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Thu, 12 Aug 2021 12:48:08 +0200 Subject: [PATCH 4/6] compile.sh refactor 2 --- compile.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/compile.sh b/compile.sh index 28b61b3..9671ad1 100755 --- a/compile.sh +++ b/compile.sh @@ -1,7 +1,5 @@ #!/usr/bin/bash -option=$1 - srcDir=src binDir=bin From f9a0b07bdacaba35809fafc4557fd31d8d6edc7b Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Thu, 12 Aug 2021 12:57:30 +0200 Subject: [PATCH 5/6] GRUB & cleanup --- compile.sh | 10 +++++----- grub_compile.sh | 20 ++++++++++++++++++++ src/grub/grub.cfg | 3 +++ 3 files changed, 28 insertions(+), 5 deletions(-) create mode 100755 grub_compile.sh create mode 100644 src/grub/grub.cfg diff --git a/compile.sh b/compile.sh index 9671ad1..8360c7d 100755 --- a/compile.sh +++ b/compile.sh @@ -1,21 +1,21 @@ #!/usr/bin/bash -srcDir=src -binDir=bin +srcdir=src +bindir=bin compile_bootloader() { echo "Compiling bootloader... " - nasm -f bin $srcDir/bootloader/bootloader.asm -i $srcDir/bootloader -o $binDir/bootloader.bin + nasm -f bin $srcdir/bootloader/bootloader.asm -i $srcdir/bootloader -o $bindir/bootloader.bin } compile_kernel() { echo "Compiling kernel... " - gcc -fno-pie -m32 -Os -ffreestanding -c $srcDir/kernel/kernel.c -o $binDir/kernel.o && gcc -o $binDir/kernel.bin $binDir/kernel.o -Wl,--oformat=binary -ffreestanding -nostdlib -shared -Ttext 0x1000 -m32 + gcc -fno-pie -m32 -Os -ffreestanding -c $srcdir/kernel/kernel.c -o $bindir/kernel.o && gcc -o $bindir/kernel.bin $bindir/kernel.o -Wl,--oformat=binary -ffreestanding -nostdlib -shared -Ttext 0x1000 -m32 } create_os_image() { echo "Creating OS image... " - cat $binDir/bootloader.bin $binDir/kernel.bin > $binDir/os-image + cat $bindir/bootloader.bin $bindir/kernel.bin > $bindir/os-image } diff --git a/grub_compile.sh b/grub_compile.sh new file mode 100755 index 0000000..b360f69 --- /dev/null +++ b/grub_compile.sh @@ -0,0 +1,20 @@ +#!/usr/bin/bash + +srcdir=src +bindir=bin + +make_grub() { + echo "Making GRUB..." + mkdir -p $bindir/boot/grub + cp $bindir/kernel.bin $bindir/boot/kernel.bin + cp $srcdir/grub/grub.cfg $bindir/boot/grub/grub.cfg + grub-mkrescue -o $bindir/eOS.iso $bindir +} + +compile_kernel() { + echo "Compiling kernel... " + gcc -fno-pie -m32 -Os -ffreestanding -c $srcdir/kernel/kernel.c -o $bindir/kernel.o && gcc -o $bindir/kernel.bin $bindir/kernel.o -Wl,--oformat=binary -ffreestanding -nostdlib -shared -Ttext 0x1000 -m32 +} + +compile_kernel +make_grub diff --git a/src/grub/grub.cfg b/src/grub/grub.cfg new file mode 100644 index 0000000..c3ebe15 --- /dev/null +++ b/src/grub/grub.cfg @@ -0,0 +1,3 @@ +menuentry "eOS" { + multiboot /boot/eOS.bin +} From df314ea841a357bdade670e6049b0ecd03f07262 Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Thu, 12 Aug 2021 13:01:18 +0200 Subject: [PATCH 6/6] Stuff --- grub_compile.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grub_compile.sh b/grub_compile.sh index b360f69..5bb365d 100755 --- a/grub_compile.sh +++ b/grub_compile.sh @@ -6,7 +6,7 @@ bindir=bin make_grub() { echo "Making GRUB..." mkdir -p $bindir/boot/grub - cp $bindir/kernel.bin $bindir/boot/kernel.bin + cp $bindir/kernel.bin $bindir/boot/eOS.bin cp $srcdir/grub/grub.cfg $bindir/boot/grub/grub.cfg grub-mkrescue -o $bindir/eOS.iso $bindir }