This is the starter kernel code for the spring 2022 offering of CSC 395: Advanced Operating Systems at Grinnell College. This project includes the basic elements required to build and run a simple kernel on an x86_64 machine emulated with QEMU.
Specifically, this starter code comes from Professor Charlie Curtsinger.
This starter code is based on the following example projects:
In addition to the above example projects, the following references were used when setting up this code:
This is an ongoing project. Be prepared for code and organization of said code to change dramatically. Below I have detailed the each implemented function, separated by which file it is. Once I have header files implemented, general function descriptions will be listed there above their specific function. Function-specific implementation comments are listed with the actual implementation itself.
All functions are implemented from descriptions given in class. To see full assignment instructions see the class website.
Does basic setup for the project and allows us to write things to the terminal.
_start_
is the equivalent tomain()
in C- Make sure the following things are called in
_start_
in this order:term_setup()
- allows you to write to the terminal, integral for printingidt_setup()
- creates an IDT and a bunch of basic handlerspic_init()
pic_unmask_irq(1)
- together withpic_init()
allows you to print characters
- These other things should also get called at some point:
idt_set_handler(0x80, syscall_entry, IDT_TYPE_TRAP)
- allow us to make system callsidt_set_handler(IRQ1_INTERRUPT, keyboard_interrupt, IDT_TYPE_TRAP)
- allow us to have keyboard presses
Functions
void idt_setup()
: create an IDT tablevoid idt_set_handler(uint8_t index, void* fn, uint8_t type)
: helper foritd_setup
which sets indvidual IDT entries
Variables
IDT_CODE_SELECTOR
IDT_TYPE_INTERRUPT
IDT_TYPE_TRAP
Structs
idt_entry_t
: an entry in the IDTinterrupt_context_t
: you need this to create an interrupt handler
Functions
-
void kprint_c(char c)
: print a single character to the terminal -
void kprint_s(const char *)
: print a string to the terminal -
void kprint_d(uint64_t value)
: print a u64 bit integer to the terminal in decimal -
void kprint_x(uint64_t value)
: print a u64 bit integer to terminal in hex (lowercase) -
void kprint_p(void* ptr)
: print the value of a pointer to the terminal in hex with leading 0x. -
void kprintf(const char* format, ...)
: print a formatted string to the terminal -
uint64_t kstrlen(const char* str)
: returns the number of characters in a string
Functions
void usable_memory(struct stivale2_struct* hdr)
: prints all usable memory to the terminal- First interval is the range of physical memory, second interval is the correspondingly mapped virtual memory
void* find_tag(struct stivale2_struct* hdr, uint64_t id)
: return an array of entries in thehdr
that have a given tagvoid memset(void *arr, uint32_t c, size_t len)
: sets an area of memory to a single valuec
Functions
This file holds a bunch of simple unit tests. Unfortunately there is nothing pretty here so far, so reference comments to make sure printed values match up!
Functions
void all_tests()
: runs all test "suites' in the filevoid kprint_tests()
: tests all functions inkprint.h