Hacking GeekOS

David H. Hovemeyer

University of Maryland

Jeffrey K. Hollingsworth

University of Maryland
This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/1.0/ or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.

Table of Contents

1. Introduction
1. Intended Audience
2. Required background
2. Kernel Hacking 101
1. Kernel Mode Restrictions
1.1. Limited Set of Library Functions
1.2. Limited Stack
1.3. Limited Memory Protection
1.4. Asynchronous Interrupts
2. Recommended Kernel Hacking Practices
2.1. Use Assertions
2.2. Use Print Statements
2.3. Test Early and Often
3. Overview of GeekOS
1. Memory
1.1. Page Allocator
1.2. Heap Allocator
2. Interrupts and Threads
2.1. Interrupts
2.2. Threads
2.3. Thread Synchronization
2.4. Interactions between Interrupts and Threads
3. Devices
3.1. Text Screen
3.2. Keyboard
3.3. System Timer
3.4. Block Devices: Floppy and IDE Disks
4. Overview of the Projects
1. Project Descriptions
2. Required Software
3. Setting Up the GeekOS Distribution
4. Starting a Project
5. Continuing to a New Project
6. Compiling a Project
7. Running GeekOS Using Bochs
8. Troubleshooting
9. Project Hints
5. Project 0: Getting Started
1. The Assignment
2. Hints
6. Project 1: Adding Processes
1. Introduction
2. Required Reading
3. Project Synopsis
4. Using Segmentation
5. Loading the Executable
6. Setting up the Process Memory
7. User Thread Creation
8. Adding System Calls
9. Spawning the Init Process
10. Testing Your Project
7. Project 2: Scheduling
1. Introduction
2. Multilevel Feedback Scheduling
3. Semaphores
4. Timing
5. Evaluating the Scheduling Policies
8. Project 3: Virtual Memory
1. Introduction
2. Changing the Project to Use Page Tables
3. Handling Page Faults
4. Paging Out Pages
5. Page Ins
6. Copying Data Between Kernel and User Memory
7. Implementation
7.1. Functions in src/geekos/paging.c
7.2. Functions in src/geekos/uservm.c
8. Extra Credit
8.1. Improving Find_Page_To_Page_Out()
8.2. Adding a User Heap
9. Project 4: A Filesystem
1. Introduction
2. GOSFS: GeekOS FileSystem
3. The Virtual Filesystem Layer (VFS)
4. VFS Data Types and Operations
4.1. Filesystem
4.2. Mount_Point
4.3. File
5. Requirements
6. GOSFS_Dir_Entry
7. The Buffer Cache
8. Getting Started
9. Issues
9.1. Concurrency
9.2. File Sharing
10. Project 5: ACLs and Inter-process Communication
11. GeekOS API Reference
1. Thread functions
1.1. Start_Kernel_Thread()
1.2. Exit()
1.3. Join()
1.4. Wait()
1.5. Wake_Up()
1.6. Wake_Up_One()

List of Figures

8.1. Virtual memory layout in GeekOS.
8.2. Actions to be taken when a page fault occurs.
9.1. Overview of the Virtual Filesystem (VFS)
9.2. Multiple File objects can refer to a common data structure