26 Home
dlack edited this page 2024-02-22 23:17:50 +01:00

How We Approached It All (in chronological steps)

A great way to learn something new is to retrace the steps taken by someone who had taken the same path before. To make this possible for future readers, below are written major ideas, proposed solutions, encountered pitfalls, and implemented fixes that have arisen along the way.

Step 0: Set up a unified development environment

Suggested reading: Operating Systems: From 0 to 1, Chapters 1-6

To safeguard against dependency hell, all the essential software needed to develop and run our OS will be provided through a set of Docker images. For more information, please refer to this section of README.

Which compiler to use: gcc or clang?

  • Compilation times are comparable
  • Clang reportedly has better error messages
  • Clang/LLVM lld links on average twice as fast as GCC ld (Up to 10 times faster, reportedly. lld uses more cores?)
  • GCC - GPL, Clang - Apache licenses
  • While the standard may move to LLVM, GCC still remains the industry standard as of now.

Decision: TL;DR - GCC.

They have many differences, above are the potentially most relevant. The GPL license seems preferable in this case, which is a point in favor of GCC. A major performance consideration comes when there are a lot of lib files as well as -debug mode (which is expected to be the case in this project). This difference will come down to the linker, and seeing as lld can be a drop-in replacement for ld, and added independently of Clang, it is not a major point in favor of Clang. We can simply install lld from the LLVM backend (Clang is just the frontend), and pass the -fuse-ld=lld flag to GCC to make it use lld instead of ld. For these reasons, I propose to start with GCC.

Step 1: Make a bootloader that prints 'dmzOS'

Suggested reading: Operating Systems: From 0 to 1, Chapter 7: Bootloader

A few dilemmas had already emerged before even having started writing any code.

Should the kernel be 32-bit or 64-bit?

  • A 32-bit kernel can provide access to 232 memory addresses. For a byte-addressable memory, that equals 232 B = 4*230 B = 4 GiB of physical memory. On the other hand, a 64-bit kernel can provide access to 264 B = 16 EiB of physical memory.
  • Having more RAM available makes heavy multitasking and memory-intensive operations perform better. On the other hand, 64-bit programs use about 50% more memory then their 32-bit counterpart; this is due to numerous reasons, one of which is that 64-bit pointers take up twice as much space as 32-bit ones.
  • The x86_64 architecture has two primary modes of operation, each having different sub-modes. A 64-bit and 32-bit kernel require the processor to operate in different modes.

Decision: In order to prevent running into chaos, we will first stick to the steps outlined in Operating Systems: From 0 to 1, which will result in our developing a 32-bit kernel stub. At that point, we will have necessary information to decide whether it aligns better with our goals to keep the kernel 32-bit or to convert it into a 64-bit version.

Intel or AT&T syntax for asm code?

  • This is simply a matter of personal preference, as both are translated into the same machine code.

Decision: Intel syntax, as it is used both in AMD and Intel architecture manuals. (...)

Step 2:

(...)

Wiki

  • OSDev Wiki: a good way to get acquainted with multiple topics at a high level, though a bit outdated.

Books

  • Operating Systems: From 0 to 1: pretty in-depth and with hands-on instructions on how to use many of the tools needed.
  • OpenCSF: an all-encompassing CS guide with a focus on many important OS-related topics.

Blogs

  • CPU Land: an avid learner's perspective on the CS fundamentals.

Repositories

  • SerenityOS: pay special attention to YouTube channels of major contributors.

YouTube

Official documentation: