OS-Development

Operating Systems - Structure

Below are some notes on Operating Systems Structure from the book Modern Operating Systems. Different approaches suit different intended usages, below is a list of the most common structures and their explanation. Monolithic systems Layered systems Microkernels Client-server systems Virtual Machines Exokernels Monolithic Systems The entire OS runs as a single program in Kernel Mode. There is no privacy, as every procedure is visible to every other procedure.
Read more

Operating Systems - Interrupts

Once I have created a Kernel with subsequent print() methods and the GDT, my next step in creating a OS is to implement Interrupts. We are going to enable Interrupts and write a keyboard interrupt handler for my learning-purposes OS called Rose-OS. This document is a resume of this OSDEV wiki article, this osdever article and the Intel i386 processor manual. But, What are Interrupts? Interrupts are signals from a devices to the CPU.
Read more

OSTEP - Scheduling Introduction

Scheduling is the policy we use to arrange the processes the CPU has to run and when. In this post, we are going to look into some basic scheduling techniques examples. Workload assumptions We are going to set a series of assumptions about the processes running in the system: Each job runs for the same amount of time All jobs arrive at the same time Once started, each job runs to completion All jobs only run on CPU (No I/O) The runtime of each job is known Scheduling metrics We are going to use these metrics to compare the different scheduling techniques.
Read more

OSTEP - Mechanisms Limited Direct Execution

There are many problems associated with virtualizing a CPU. The most important problem we have to solve is that we need to maintain control of the processes running, so they don’t take over the system. Other problems such as the need to switch environments and resources for every different process the CPU works on, also impact CPU efficiency. Basic Technique: Limited Direct Execution Direct execution: The Operating System provides access to the CPU directly to each process.
Read more

OSTEP - Virtualization - Processes API

Unix creates a process with a pair of system calls: fork() exec() A third system call can be used by a process to wait until a process it has created to complete. wait() fork() It is used to create a new process In the following example: #include <stdio.h> #include <stdlib.h> #include <unistd.h> int main(int argc, char* argv[]) { printf("Hello world (pid:%d)\n", (int) getpid()); // rc = return code int rc = fork(); if (rc < 0) { // Fork failed fprintf(stderr, "Fork failed\n"); exit(1); } else if (rc == 0) { // Child (new process) printf("Hello, I'm a child (pid:%d)\n", (int) getpid()); } else { // Parent goes down this path printf("Hello, I am a parent of %d (pid:%d)\n", rc, (int) getpid()); } return 0; } A new child process is created when fork() is called.
Read more

OSTEP - Virtualization - Processes

This series contains my notes on the free on line book Operating Systems: Three easy pieces. As a user wants to be able to run multiple processes at once, we have to be able to create the illusion that there are as many processors as each program needs. The OS does this by virtualizing the CPU. (Executing instructions from one process and then changes to another program) This allows multiple programs to run at once.
Read more

Operating Systems - Three easy pieces - Introduction

This series contains my notes on the free on line book Operating Systems: Three easy pieces. I will create a entry on each topic or on anything I feel worth remembering/mentioning. This entry is the first one, consisting on a introduction to the book, and a few resources I found to be handy. Links and references XV6 Advanced XV6 OSTEP projects Main focus There are three main topics on operating systems development.
Read more

Rose-OS - Makefile teardown

In this post, I will be describing programs and resources used to build Rose-OS and how we combine then into a single, automated Makefile. Programs used to generate the kernel gcc nasm bochs (Emulator) ld cat rm gcc Is the compiler we use to compile our code. Normally, this command preprocesses, compiles, assembles and links our code, but we can stop it from doing this with some command-line options.
Read more

Loading a simple kernel written in C

In this post, we are describing how to write a simple C program and loading it from a 32-bit boot sector code. In this post, our kernel is as simple as it can get. It consists of a stored variable in a specific location in the code. Boot sector The code we are going to use in this section has nothing new. We are changing from 16-bit to 32-bit to be able to access more memory range.
Read more

Entering 32-bit protected mode

In this post, we will cover how to enter 32-bit protected mode. This is a requirement if we want to be able to create a OS with the features we are used to. Otherwise, we will have very little storage space allowed due to the 16-bit reference limit. Boot sector To enter 32-bit protected mode, we first have to bootstrap our code from a 16-bit sector. This is necesary because the initial code location is stored in a space-restricted zone.
Read more