cfenollosa_os-tutorial/23-fixes
2015-08-18 11:02:06 +02:00
..
boot lesson 23, steps 1 and 2 2015-08-18 10:14:06 +02:00
cpu lesson 23, step 3 2015-08-18 10:31:28 +02:00
drivers lesson 23, step 3 2015-08-18 10:31:28 +02:00
kernel lesson 23, step 3 2015-08-18 10:31:28 +02:00
libc Lesson 23, step 4, size_t usage 2015-08-18 10:38:09 +02:00
Makefile lesson 23, steps 1 and 2 2015-08-18 10:14:06 +02:00
README.md Lesson 23, step 4 2015-08-18 11:02:06 +02:00

Concepts you may want to Google beforehand: XX

Goal: Fix miscellaneous issues with our code

The OSDev wiki has a section which describes some issues with JamesM's tutorial. 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

-nostdinc was also pased to gcc, but we will need it for step 3.

  1. 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.

  1. Reinvented datatypes

It looks like it was a bad idea to define non-standard data types like u32 and such, since C99 introduces standard fixed-width data types like uint32_t

We need to include <stdint.h> which works even in -ffreestanding (but requires stdlibs) and use those data types instead of our own, then delete them on type.h

  1. Improperly aligned kmalloc

First, since kmalloc uses a size parameter, we'll use the correct data type size_t instead of u32int_t. size_t should be used for all parameters which "count" stuff and cannot be negative. Include <stddef.h>.

We will fix our kmalloc in the future, making it a proper memory manager and aligning data types. For now, it will always return a new page-aligned memory block.

  1. Missing functions

  1. Interrupt handlers

  • also cli, sti in interrupt handlers
  1. Structs and attributes