Changed to using Boch to better handle debugging the kernel. Updated build system with a new script to handle working with the build_numbers.c file.

This commit is contained in:
2020-05-07 19:24:42 -05:00
parent 4616ce63b3
commit e1a1169240
11 changed files with 80 additions and 63 deletions
+3
View File
@@ -1,2 +1,5 @@
*.o
*.elf
*.log
*.iso
*.bin
+13 -30
View File
@@ -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
+1 -4
View File
@@ -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
+7
View File
@@ -0,0 +1,7 @@
set timeout=0
set default=0
menuentry "SDOS" {
multiboot /boot/kernel.bin
boot
}
+5
View File
@@ -0,0 +1,5 @@
void kmain()
{
asm("hlt");
}
+25
View File
@@ -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:
-17
View File
@@ -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
+9
View File
@@ -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
@@ -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
View File
+15
View File
@@ -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