diff options
author | Marvin Borner | 2020-08-01 17:30:42 +0200 |
---|---|---|
committer | Marvin Borner | 2020-08-01 17:30:42 +0200 |
commit | 928bf3f29d7a8b2163a3c1d5c15554d5b42c606b (patch) | |
tree | 16924d82ad79f609ee5966b165050bbcace90b9e | |
parent | 9a146c325ac0538be807e904d7c35d0a73f9fc5e (diff) |
Some entry position optimizations
-rw-r--r-- | apps/Makefile | 5 | ||||
-rw-r--r-- | apps/link.ld | 3 | ||||
-rw-r--r-- | apps/test.c | 46 | ||||
-rw-r--r-- | src/Makefile | 4 | ||||
-rw-r--r-- | src/drivers/interrupts.c | 3 | ||||
-rw-r--r-- | src/features/load.c | 4 | ||||
-rw-r--r-- | src/inc/load.h | 2 | ||||
-rw-r--r-- | src/main.c | 2 |
8 files changed, 13 insertions, 56 deletions
diff --git a/apps/Makefile b/apps/Makefile index 16f108a..574f135 100644 --- a/apps/Makefile +++ b/apps/Makefile @@ -5,10 +5,7 @@ CC = ../cross/opt/bin/i686-elf-gcc LD = ../cross/opt/bin/i686-elf-ld OC = ../cross/opt/bin/i686-elf-objcopy -# TODO: Fix crash without optimizations -CSFLAGS = -mpreferred-stack-boundary=2 -fno-asynchronous-unwind-tables -Os - -CFLAGS = $(CSFLAGS) -Wall -Wextra -nostdlib -nostdinc -ffreestanding -fno-builtin -mgeneral-regs-only -std=c99 -m32 -pedantic-errors -I../src/lib/inc/ -fPIE -Os +CFLAGS = $(CSFLAGS) -Wall -Wextra -nostdlib -nostdinc -ffreestanding -ffunction-sections -fno-builtin -std=c99 -m32 -pedantic-errors -I../src/lib/inc/ -fPIE all: $(COBJS) diff --git a/apps/link.ld b/apps/link.ld index d977c19..84b2e2f 100644 --- a/apps/link.ld +++ b/apps/link.ld @@ -7,7 +7,8 @@ SECTIONS . = 0x00000000; .text : { - *(.text) + *(.text.main) + *(.text*) } .rodata : { diff --git a/apps/test.c b/apps/test.c index c5e6468..ad84996 100644 --- a/apps/test.c +++ b/apps/test.c @@ -1,3 +1,5 @@ +// MIT License, Copyright (c) 2020 Marvin Borner + #include <def.h> u32 strlen(const char *s) @@ -15,54 +17,11 @@ u8 inb(u16 port) return value; } -u16 inw(u16 port) -{ - u16 value; - __asm__ volatile("inw %1, %0" : "=a"(value) : "Nd"(port)); - return value; -} - -u32 inl(u16 port) -{ - u32 value; - __asm__ volatile("inl %1, %0" : "=a"(value) : "Nd"(port)); - return value; -} - -void insl(u16 port, void *addr, int n) -{ - __asm__ volatile("cld; rep insl" - : "=D"(addr), "=c"(n) - : "d"(port), "0"(addr), "1"(n) - : "memory", "cc"); -} - void outb(u16 port, u8 data) { __asm__ volatile("outb %0, %1" ::"a"(data), "Nd"(port)); } -void outw(u16 port, u16 data) -{ - __asm__ volatile("outw %0, %1" ::"a"(data), "Nd"(port)); -} - -void outl(u16 port, u32 data) -{ - __asm__ volatile("outl %0, %1" ::"a"(data), "Nd"(port)); -} - -void serial_install() -{ - outb(0x3f8 + 1, 0x00); - outb(0x3f8 + 3, 0x80); - outb(0x3f8 + 0, 0x03); - outb(0x3f8 + 1, 0x00); - outb(0x3f8 + 3, 0x03); - outb(0x3f8 + 2, 0xC7); - outb(0x3f8 + 4, 0x0B); -} - int is_transmit_empty() { return inb(0x3f8 + 5) & 0x20; @@ -83,6 +42,5 @@ void serial_print(const char *data) void main() { - serial_install(); serial_print("Follow the white rabbit."); } 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 @@ -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 |