diff --git a/.gitignore b/.gitignore index 7f47c0d..94d919f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .DS_Store *.code-workspace -*.bin \ No newline at end of file +bin/* +build/* \ No newline at end of file diff --git a/Makefile b/Makefile index 891f5ee..75b2fbb 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,6 @@ -FILES = ./build/kernel.asm.o +FILES = ./build/kernel.asm.o ./build/kernel.o +INCLUDES = -I./src +FLAGS = -g -ffreestanding -falign-jumps -falign-functions -falign-labels -falign-loops -fstrength-reduce -fomit-frame-pointer -finline-functions -Wno-unused-function -fno-builtin -Werror -Wno-unused-label -Wno-cpp -Wno-unused-parammeter -nostdlib -nostartfiles -nodefaultlibs -Wall -O0 -Iinc all: ./bin/boot.bin ./bin/kernel.bin rm -rf ./bin/os.bin @@ -11,11 +13,14 @@ all: ./bin/boot.bin ./bin/kernel.bin ./bin/kernel.bin: $(FILES) i686-elf-ld -g -relocatable $(FILES) -o ./build/kernelfull.o - i686-elf-gcc -T ./src/linker.ld -o ./bin/kernel.bin -ffreestanding -O0 -nostdlib ./build/kernelfull.o + i686-elf-gcc $(FLAGS) -T ./src/linker.ld -o ./bin/kernel.bin ./build/kernelfull.o ./build/kernel.asm.o: ./src/kernel.asm nasm -f elf -g ./src/kernel.asm -o ./build/kernel.asm.o +./build/kernel.o: ./src/kernel.c + i686-elf-gcc $(INCLUDES) $(FLAGS) -std=gnu99 -c ./src/kernel.c -o ./build/kernel.o + run: qemu-system-x86_64 -hda ./bin/os.bin diff --git a/doc/protected_mode_development.md b/doc/protected_mode_development.md index 6ecd1c6..43919b1 100644 --- a/doc/protected_mode_development.md +++ b/doc/protected_mode_development.md @@ -81,7 +81,7 @@ general: --- -## Notes +## References - [GDB to LLDB command map](https://lldb.llvm.org/use/map.html#examining-thread-state) - [Entering Protected Mode tutorial](http://www.osdever.net/tutorials/view/the-world-of-protected-mode) diff --git a/doc/protected_mode_development_2.md b/doc/protected_mode_development_2.md index fd3489f..9bd2456 100644 --- a/doc/protected_mode_development_2.md +++ b/doc/protected_mode_development_2.md @@ -112,3 +112,7 @@ Quick summary of how our code works with memory. - Note that aligning `boot.asm` to 512 bytes is unrelated to the memory alignment issue we talk about here. The bootloader must have the boot signature 0x55AA at 511 and 512 byte. - Make sure that `kernel.asm.o` is the first file to be linked. That ensures `kernel.asm.o` is located in the `.text` section ([`linker.ld`](../src/linker.ld)) when linked, and always starts at 0x100000. `kernel.asm.o` is 512 bytes long, so any other C object files linked after that are automatically aligned. - In other kernel assembly files, specify `.asm` section so that they are linked at the end of the object file. If the assembled code is not a multiple of 4 bytes, that's okay because those files are at the end. + +--- + +[continue](./protected_mode_development_3.md) diff --git a/doc/protected_mode_development_3.md b/doc/protected_mode_development_3.md new file mode 100644 index 0000000..b6d89fe --- /dev/null +++ b/doc/protected_mode_development_3.md @@ -0,0 +1,7 @@ +# Protected Mode Development - Part 3 + +## Writing C program in Protected Mode + +Now, we start writing our kernel in C. [commit]() + +Debugging steps are the same as what we did in the [previous note](./protected_mode_development_2.md) "5. Build, run, and debug". diff --git a/src/kernel.asm b/src/kernel.asm index 6a24986..9000cdf 100644 --- a/src/kernel.asm +++ b/src/kernel.asm @@ -2,6 +2,8 @@ global _start +extern kernel_main + CODE_SEG equ 0x08 DATA_SEG equ 0x10 @@ -20,6 +22,8 @@ _start: or al, 2 out 0x92, al ; Write to the bus line 92 + call kernel_main + cld ; Clears direction flag cli ; Disables interrupts hlt ; This hangs the computer diff --git a/src/kernel.c b/src/kernel.c new file mode 100644 index 0000000..cfe71f4 --- /dev/null +++ b/src/kernel.c @@ -0,0 +1,5 @@ +#include "kernel.h" + +void kernel_main() +{ +} \ No newline at end of file diff --git a/src/kernel.h b/src/kernel.h new file mode 100644 index 0000000..1b78527 --- /dev/null +++ b/src/kernel.h @@ -0,0 +1,6 @@ +#ifndef KERNEL_H +#define KERNEL_H + +void kernel_main(); + +#endif \ No newline at end of file