From 928bf3f29d7a8b2163a3c1d5c15554d5b42c606b Mon Sep 17 00:00:00 2001
From: Marvin Borner
Date: Sat, 1 Aug 2020 17:30:42 +0200
Subject: Some entry position optimizations

---
 src/Makefile             | 4 ++--
 src/drivers/interrupts.c | 3 ++-
 src/features/load.c      | 4 +++-
 src/inc/load.h           | 2 --
 src/main.c               | 2 +-
 5 files changed, 8 insertions(+), 7 deletions(-)

(limited to 'src')

diff --git a/src/Makefile b/src/Makefile
index 475d792..37ad049 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -27,7 +27,7 @@ AS = nasm
 CSFLAGS = -mpreferred-stack-boundary=2 -fno-asynchronous-unwind-tables -Os
 
 # TODO: Use lib as external library
-CFLAGS = $(CSFLAGS) -Wall -Wextra -nostdlib -nostdinc -ffreestanding -fno-builtin -mgeneral-regs-only -std=c99 -m32 -pedantic-errors -Ilib/inc/ -Iinc/
+CFLAGS = $(CSFLAGS) -Wall -Wextra -nostdlib -nostdinc -ffreestanding -fno-builtin -mgeneral-regs-only -std=c99 -m32 -pedantic-errors -Wl,-ekernel_main -Ilib/inc/ -Iinc/
 
 ASFLAGS = -f elf32 -O3
 
@@ -42,5 +42,5 @@ all: compile
 compile: $(COBJS)
 	@mkdir -p ../build/
 	@$(AS) -f bin entry.asm -o ../build/boot.bin
-	@$(LD) -N -emain -Ttext 0x00050000 -o ../build/kernel.bin $(COBJS) --oformat binary
+	@$(LD) -N -ekernel_main -Ttext 0x00050000 -o ../build/kernel.bin $(COBJS) --oformat binary
 	@$(CC) $(CFLAGS) -o ../build/debug.o $(COBJS)
diff --git a/src/drivers/interrupts.c b/src/drivers/interrupts.c
index dc031e0..1bd0b44 100644
--- a/src/drivers/interrupts.c
+++ b/src/drivers/interrupts.c
@@ -5,6 +5,7 @@
 #include <def.h>
 #include <interrupts.h>
 #include <mem.h>
+#include <print.h>
 #include <serial.h>
 
 /**
@@ -136,7 +137,7 @@ void isr_handler(struct regs *r)
 	if (handler) {
 		handler(r);
 	} else if (r->int_no <= 32) {
-		serial_print("Exception, halting!\n");
+		printf("#%d Exception, halting!\n", r->int_no);
 		__asm__("cli");
 		while (1) {
 		};
diff --git a/src/features/load.c b/src/features/load.c
index 47beb9b..958acd7 100644
--- a/src/features/load.c
+++ b/src/features/load.c
@@ -1,3 +1,5 @@
+// MIT License, Copyright (c) 2020 Marvin Borner
+
 #include <def.h>
 #include <fs.h>
 #include <load.h>
@@ -8,7 +10,7 @@ void bin_load(char *path)
 	char *data = read_file(path);
 
 	void (*entry)();
-	*(void **)(&entry) = data + MAIN_OFFSET;
+	*(void **)(&entry) = data;
 
 	entry();
 }
diff --git a/src/inc/load.h b/src/inc/load.h
index 8ba026b..a02afc0 100644
--- a/src/inc/load.h
+++ b/src/inc/load.h
@@ -3,8 +3,6 @@
 #ifndef LOAD_H
 #define LOAD_H
 
-#define MAIN_OFFSET 0xfe
-
 void bin_load(char *path);
 
 #endif
diff --git a/src/main.c b/src/main.c
index 68993ba..ba390fa 100644
--- a/src/main.c
+++ b/src/main.c
@@ -15,7 +15,7 @@
 u32 HEAP = 0x00200000;
 u32 HEAP_START;
 
-void main(struct mem_info *mem_info, struct vid_info *vid_info)
+void kernel_main(struct mem_info *mem_info, struct vid_info *vid_info)
 {
 	HEAP_START = HEAP; // For malloc function
 
-- 
cgit v1.2.3