Skip to content

Startup

jmazanec15 edited this page Sep 12, 2018 · 3 revisions

Starting Up the Operating System

The process of starting up a computer to run a conventional operating system is an involved, multistep process. Generally, there is an entire set of hardware-specific steps that involve calling the general code of the operating system.

This documentation skips those steps to discuss the OS startup process (which actually concerns basekernel).

1. The Boot Block

To load the operating system, the hardware needs to be able to load an unknown amount of code, and execute it, and hand over full control of the machine. How does it do this? It loads some constant amount of data containing the code that can be used to load the rest of the OS.

The hardware reads and runs one block from the boot drive, appropriately called the boot block. The boot block can then read the rest of the OS code for execution. The boot block is always written to load the OS, but since it always fits within one block it will be able to be read by the hardware. With that complicated handoff handled, all the software ran from here on out is written for use with the OS it is executing.

2. Kernel Core

Now that the OS has been loaded, it needs to set itself up to run properly on the hardware. Every operating system needs to be able to run the computer's Central Processing Unit, Memory, and handle interupts that the hardware raises.

Basekernel can facilitate this by first executing kernelcore.s. The code contained here sets up the CPU and memory, but most importantly sets up the interrupt tables, which the hardware will use to signal events to the operating system. The interupt table will be written somewhere on hardware and the code stored in interrupt.c to initiate the appropriate response (for more on this, read the section on interrupts.

3. Main

The last thing the Kernel Core does is execute main.c, where the rest of the OS code is executed, and any other subsystems are initialized.

The operating system can now be considered "running", but we users have no means of interacting with it.

4. Terminal: kshell

To give users an interface into the OS, Basekernel executes a program called kshell. Which works like the name suggests: it is a simplified shell program.

This is not to be confused with a traditional bash shell. It's just a limited set of tools for running processes, which allows it to start a fully-featured shell program.

5. User space and the Shell

At this point we get to the domain of the OS as most users experience it. This is where transitions are made to restrict permisions. Kshell executes a more traditional shell program within the user space.