diff --git a/.gitignore b/.gitignore index 20596b5..0dcaed2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ *.o *.elf +*.log +*.iso +*.bin diff --git a/Makefile b/Makefile index a2bbe75..7af9774 100644 --- a/Makefile +++ b/Makefile @@ -1,55 +1,38 @@ +.DELETE_ON_ERROR: + CC = gcc GCCPARAMS = -m32 -fno-pie -nostdlib -fstrength-reduce -fomit-frame-pointer -finline-functions -fno-builtin -nostdinc -fno-stack-protector ASPARAMS = -f elf32 LDPARAMS = -m elf_i386 -INCBULDNUM = sh make_buildnum.sh SRC := kernel OBJ := obj SOURCES := $(wildcard $(SRC)/*.c) -ASMSOURCES := $(wildcard $(SRC)/*.asm) +ASMSOURCES := $(wildcard $(SRC)/*.s) OBJECTS := $(patsubst $(SRC)/%.c, $(OBJ)/%.o, $(SOURCES)) -ASMOBJECTS := $(patsubst $(SRC)/%.asm, $(OBJ)/%.o, $(ASMSOURCES)) +ASMOBJECTS := $(patsubst $(SRC)/%.s, $(OBJ)/%.o, $(ASMSOURCES)) -run:kernel.iso - qemu-system-x86_64 -serial pipe:/tmp/guest -m 256M -cdrom kernel.iso & +run: kernel.iso + bochs -f support_files/boch.txt -q $(OBJ)/%.o: $(SRC)/%.c - mkdir -p $(@D) $(CC) $(GCCPARAMS) $(SRC) -c -o $@ $< -$(OBJ)/%.o: $(SRC)/%.asm - mkdir -p $(@D) +$(OBJ)/%.o: $(SRC)/%.s nasm $(ASPARAMS) -o $@ $< -kernel.bin: $(OBJECTS) $(ASMOBJECTS) - @#Crap way to increment the build number, but will do for now - @#thanks to my limited knowledge of Makefiles. - @#Sadly this number in the compiled code will always be off by one with this method.... - @sh make_buildnum.sh - mkdir -p obj/bin - ld $(LDPARAMS) -T linker.ld -o obj/bin/$@ $(OBJECTS) $(ASMOBJECTS) +kernel.o: build_numbers.c $(OBJECTS) $(ASMOBJECTS) + @sh support_files/run_linker.sh "$(LDPARAMS)" obj/bin/$@ "$(OBJECTS)" "$(ASMOBJECTS)" -kernel.iso: kernel.bin - mkdir iso - mkdir iso/boot - mkdir iso/boot/grub - cp obj/bin/kernel.bin iso/boot/kernel.bin - echo 'set timeout=0' > iso/boot/grub/grub.cfg - echo 'set default=0' >> iso/boot/grub/grub.cfg - echo '' >> iso/boot/grub/grub.cfg - echo 'menuentry "SDOS" {' >> iso/boot/grub/grub.cfg - echo ' multiboot /boot/kernel.bin' >> iso/boot/grub/grub.cfg - echo ' boot' >> iso/boot/grub/grub.cfg - echo '}' >> iso/boot/grub/grub.cfg +kernel.iso: kernel.o + cp obj/bin/kernel.o iso/boot/kernel.bin grub-mkrescue --output=kernel.iso iso - rm -rf iso - + .PHONY: clean clean: rm -rf obj/* kernel.iso .PHONY: resetbuild resetbuild: - echo 0 > build.number + @sh support_files/handle_build_numbers.sh build_numbers.c reset diff --git a/build_numbers.c b/build_numbers.c index 9e4aa14..1fc5ed0 100644 --- a/build_numbers.c +++ b/build_numbers.c @@ -1,6 +1,3 @@ #ifndef KERNEL_VERSION_NUMBER -#define KERNEL_VERSION_NUMBER "1.4.10-40" -#endif -#ifndef CONSOLE_VERSION_NUMBER -#define CONSOLE_VERSION_NUMBER "0.4.5-0" +#define KERNEL_VERSION_NUMBER "1.4.10-0" #endif diff --git a/iso/boot/grub/grub.cfg b/iso/boot/grub/grub.cfg new file mode 100644 index 0000000..66a023b --- /dev/null +++ b/iso/boot/grub/grub.cfg @@ -0,0 +1,7 @@ +set timeout=0 +set default=0 + +menuentry "SDOS" { + multiboot /boot/kernel.bin + boot +} diff --git a/kernel/kmain.c b/kernel/kmain.c new file mode 100644 index 0000000..727a947 --- /dev/null +++ b/kernel/kmain.c @@ -0,0 +1,5 @@ + +void kmain() +{ + asm("hlt"); +} diff --git a/kernel/loader.s b/kernel/loader.s new file mode 100644 index 0000000..aa9869a --- /dev/null +++ b/kernel/loader.s @@ -0,0 +1,25 @@ +global loader + +MAGIC_NUMBER equ 0x1BADB002 +FLAGS equ 0x0 +CHECKSUM equ -MAGIC_NUMBER +KERNEL_STACK_SIZE equ 4096 ; size of stack in bytes + +section .text: + align 4 + dd MAGIC_NUMBER + dd FLAGS + dd CHECKSUM + +loader: + extern kmain + call kmain + ;mov eax, 0xCAFEBABE + ;mov esp, kernel_stack + KERNEL_STACK_SIZE ; piont ESP to the start of the stack (end of memory area) +.loop: + jmp .loop + +section .bss + alignb 4 + resb KERNEL_STACK_SIZE ; reserve stack for kernel + kernel_stack: diff --git a/loader.s b/loader.s deleted file mode 100644 index dadcc86..0000000 --- a/loader.s +++ /dev/null @@ -1,17 +0,0 @@ -global loader - -MAGIC_NUMBER equ 0x1BADB002 -FLAGS equ 0x0 -CHECKSUM equ -MAGIC_NUMBER - -section .text: -align 4 - dd MAGIC_NUMBER - dd FLAGS - dd CHECKSUM - -loader: - mov eax, 0xCAFEBABE -.loop: - jmp .loop - diff --git a/support_files/boch.txt b/support_files/boch.txt new file mode 100644 index 0000000..25888cf --- /dev/null +++ b/support_files/boch.txt @@ -0,0 +1,9 @@ +megs: 32 +display_library: x +romimage: file=/usr/share/bochs/BIOS-bochs-latest +vgaromimage: file=/usr/share/bochs/VGABIOS-lgpl-latest +ata0-master: type=cdrom, path=kernel.iso, status=inserted +boot: cdrom +log: bochs.log +clock: sync=realtime, time0=local +cpu: count=1, ips=1000000 diff --git a/handle_build_numbers.sh b/support_files/handle_build_numbers.sh similarity index 87% rename from handle_build_numbers.sh rename to support_files/handle_build_numbers.sh index 2a3fccf..df0f938 100755 --- a/handle_build_numbers.sh +++ b/support_files/handle_build_numbers.sh @@ -45,23 +45,13 @@ while IFS=' ' read -ra line; do #It doesn't matter what its value is only that one is present. #If there isn't a second parameter set, then we increment the meta build #number, otherwise we decrement. - if [ "$2" == "" ] + if [ "$2" != "reset" ] then echo "Incrementing meta build number." meta=$(($i + 1)) - elif [ "$2" == "reset" ] - then + else echo "Resetting meta build number." meta=0 - else - if [ "$i" -gt 0 ] - then - echo "Decrementing meta build number." - meta=$(($i - 1)) - else - echo "Meta build number already zero, nothing to be done." - meta=0 - fi fi ;; esac diff --git a/link.ld b/support_files/link.ld similarity index 100% rename from link.ld rename to support_files/link.ld diff --git a/support_files/run_linker.sh b/support_files/run_linker.sh new file mode 100644 index 0000000..3145666 --- /dev/null +++ b/support_files/run_linker.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +#Handles the final linking of the OS binaries to build the kernel. +#This script will allow for rolling back the build number found in the +#build_numbers.c file. + +ld $1 -T support_files/link.ld -o $2 $3 $4 + +if [[ $? == 0 ]] +then + ./support_files/handle_build_numbers.sh build_numbers.c + exit 0 +else + exit 1 +fi