Skip to content

Create a basic operating system from scratch - Part 1 of Advanced Operating Systems

Notifications You must be signed in to change notification settings

athaichi/csc395_op

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Starter Kernel

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.

Acknowledgements

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:

Code Organization

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.

boot.c

Does basic setup for the project and allows us to write things to the terminal.

  • _start_ is the equivalent to main() 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 printing
    • idt_setup() - creates an IDT and a bunch of basic handlers
    • pic_init()
    • pic_unmask_irq(1) - together with pic_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 calls
    • idt_set_handler(IRQ1_INTERRUPT, keyboard_interrupt, IDT_TYPE_TRAP) - allow us to have keyboard presses

interrupts.h

Functions

  • void idt_setup(): create an IDT table
  • void idt_set_handler(uint8_t index, void* fn, uint8_t type): helper for itd_setup which sets indvidual IDT entries

Variables

  • IDT_CODE_SELECTOR
  • IDT_TYPE_INTERRUPT
  • IDT_TYPE_TRAP

Structs

  • idt_entry_t: an entry in the IDT
  • interrupt_context_t: you need this to create an interrupt handler

kprint.h

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

memory.h

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 the hdr that have a given tag
  • void memset(void *arr, uint32_t c, size_t len): sets an area of memory to a single value c

page.h

Functions

testing.h

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 file
  • void kprint_tests(): tests all functions in kprint.h

About

Create a basic operating system from scratch - Part 1 of Advanced Operating Systems

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published