Write Your Own OS (2) — Computer Architecture Overview

Meg's tech corner
3 min readJun 24, 2020

--

Previous: Write Your Own OS(1) — Overview

Next: Write Your Own OS(3) — Bare Bone OS

Part 1 Get a bare OS up and running

In this section, we will introduce how to get a bare bone Operating System up and running. In Part 1.1, we will introduce a general computer architecture, Von Neumann architecture, and look into what happens after we press the power button. Afterwards, we will implement a bare bone OS and introduce some useful debugging skills. In part 1.2, we will extend our Operating System to write to screen and serial IO. In part 1.3, we will set up the interrupts to get input from keyboards.

Part 1.1 Bare Bone Operating System

Part 1.1.1 Von Neumann architecture

Before we dive into the Operating System, it is very useful to understand the hardware it runs on, the `runtime environment` for an Operating System. (Operating System in turn provides the runtime environment for user applications, as we will see in Part 5.) Computer architecture can be very complicated. However it can be explained with comparatively simple terminologies conceptually. We will introduce one of the most used computer architectures, called Von Neumann architecture, which forms the foundation we need to reason about the behavior or correctness of our Operating System.

Von Neumann architecture

In the Von Neumann architecture, a computer roughly consists of one or more central processing units (CPUs), main memory and many devices.

The primary job for the CPU(s) is to execute basic arithmetics, logic, controlling and input/output (I/O) instructions specified by the program. Some examples include

  • Load data from main memory to registers
  • Store data to main memory
  • Carry out arithmetic or logical operations on data
  • Send I/O instructions to devices

CPUs usually contain a few registers. They include general purpose registers which hold data for the instructions as well as some special registers. One such register is called the Program Counter register or Instructor Pointer register. It contains the address of the instructions to be executed.

Main memory, which is usually referred to as physical memory, provides storages for both data and instructions. CPUs can fetch or store instructions/ data with load or store instructions.

A computer can have many devices, such as monitors, keyboards and disks. CPUs normally fetch/send instructions or data from/to devices with some Input/Output (I/O) operations. There are some exceptions to this and we will discuss this in section 1.2.

After powering on, the computer hardware, or rather the CPU, can be thought of running an endless loop, which first reads in an instruction from main memory, then decodes and executes it. By laying out instructions in memory properly, we can achieve a huge number of tasks, from simple tasks such as printing to the screen to complex tasks such as an online multi-players game!

Endless loop inside CPU

Following this model, we will gradually explore how to load the Operating System into memory and set the IP register to the address of the first instruction of the Operating System. After our Operating System gains the control of the hardware, we will perform necessary initialization to better utilize the available hardwares. Then we will basically enter an endless loop to respond to user requests or hardware events, for example, interrupts.

Along the journey, we will include more details of the computer architectures, such as components to handle virtual memory or interrupts. Let’s now get our hands dirty and start to implement our own Operating System!

Previous: Write Your Own OS(1) — Overview

Next: Write Your Own OS(3) — Bare Bone OS

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

No responses yet

Write a response