From 92ff191c3dfc8fac74a88f6dc24ce345dce54f4e Mon Sep 17 00:00:00 2001 From: Carlos Date: Tue, 18 Aug 2015 10:14:06 +0200 Subject: [PATCH] lesson 23, steps 1 and 2 --- 23-fixes/Makefile | 3 +-- 23-fixes/README.md | 46 ++++++++++++++++++++++++++++++++++ 23-fixes/boot/kernel_entry.asm | 9 ++++--- 23-fixes/kernel/kernel.c | 2 +- 4 files changed, 54 insertions(+), 6 deletions(-) diff --git a/23-fixes/Makefile b/23-fixes/Makefile index 1478294..6b679a7 100644 --- a/23-fixes/Makefile +++ b/23-fixes/Makefile @@ -7,8 +7,7 @@ OBJ = ${C_SOURCES:.c=.o cpu/interrupt.o} CC = /usr/local/i386elfgcc/bin/i386-elf-gcc GDB = /usr/local/i386elfgcc/bin/i386-elf-gdb # -g: Use debugging symbols in gcc -CFLAGS = -g -m32 -nostdlib -nostdinc -fno-builtin -fno-stack-protector -nostartfiles -nodefaultlibs \ - -Wall -Wextra -Werror +CFLAGS = -g -ffreestanding -Wall -Wextra -fno-exceptions # First rule is run by default os-image.bin: boot/bootsect.bin kernel.bin diff --git a/23-fixes/README.md b/23-fixes/README.md index 4c29f36..c27f74d 100644 --- a/23-fixes/README.md +++ b/23-fixes/README.md @@ -7,4 +7,50 @@ JamesM's tutorial](http://wiki.osdev.org/James_Molloy%27s_Tutorial_Known_Bugs). Since we followed his tutorial for lessons 18-22 (interrupts through malloc), we'll need to make sure we fix any of the issues before moving on. +1. Wrong CFLAGS +--------------- + +We add `-ffreestanding` when compiling `.o` files, which includes `kernel_entry.o` and thus +`kernel.bin` and `os-image.bin`. + +Before, we disabled libgcc (not libc) through the use of `-nostdlib` and we didn't re-enable +it for linking. Since this is tricky, we'll delete `-nostdlib` + + +2. Not setting a stack +---------------------- + + + +3. kernel.c `main()` function +----------------------------- + +Modify `kernel/kernel.c` and change `main()` to `kernel_main()` since gcc recognizes "main" as +a special keyword and we don't want to mess with that. + +Change `boot/kernel_entry.asm` to point to the new name accordingly. + +To fix the `i386-elf-ld: warning: cannot find entry symbol _start; defaulting to 0000000000001000` +warning message, add a `global _start;` and define the `_start:` label in `boot/kernel_entry.asm`. + +4. Reinvented datatypes +----------------------- + to provide size\_t + + + +5. Missing functions +-------------------- + +6. Interrupt handlers +--------------------- +- also cli, sti in interrupt handlers + + +7. Structs and attributes +------------------------- + +8. Improperly aligned `kmalloc` +------------------------------- + diff --git a/23-fixes/boot/kernel_entry.asm b/23-fixes/boot/kernel_entry.asm index 6728303..4148566 100644 --- a/23-fixes/boot/kernel_entry.asm +++ b/23-fixes/boot/kernel_entry.asm @@ -1,4 +1,7 @@ +global _start; [bits 32] -[extern main] ; Define calling point. Must have same name as kernel.c 'main' function -call main ; Calls the C function. The linker will know where it is placed in memory -jmp $ + +_start: + [extern kernel_main] ; Define calling point. Must have same name as kernel.c 'main' function + call kernel_main ; Calls the C function. The linker will know where it is placed in memory + jmp $ diff --git a/23-fixes/kernel/kernel.c b/23-fixes/kernel/kernel.c index ecd034c..064b87a 100644 --- a/23-fixes/kernel/kernel.c +++ b/23-fixes/kernel/kernel.c @@ -4,7 +4,7 @@ #include "../libc/string.h" #include "../libc/mem.h" -void main() { +void kernel_main() { isr_install(); irq_install();