An X86 lightweight OS I am building as a hobby project in Nasm
, C
and C++
, more details about the OS to follow as we build.
To run the code ensure you have QEMU-KVM
installed and run on Linux: After that run:
make # Run make to build the proceed to the virtualization command
./run.sh
The general agreeable process is:-
-
BIOS copied from ROM into RAM
-
BIOS executes code: (Involves initializing Hardware and running some tests such as Power-on self test (POST))
-
BIOS searches for an OS to start.
-
BIOS loads and starts the OS
-
OS boots up
- Legacy Booting
- BIOS loads the first sector of each bootable device into memory (at location 0x7C00). We use the
ORG
command in Assembly to tell the Assembler where we expect our code to be loaded. The Assembler uses this info to calculate the label address. - BIOS checks for 0xAA55 signature.
- If found, the code execution begins.
- BIOS looks into special EFI partitions
- OS must be compiled as an EFI program.
Directives | Instructions |
---|---|
1. Gives a clue to the assembler | 1. Translated to machine code, |
that affects how the program | instructions that CPU executes. |
compiles. | |
2. Not translated to machine | |
code. | |
3. Assembler specific - different | |
assemblers have different | |
directives. |
-
The BIOS expects the last two bytes of the first sector to be 8855. We will assume our program can be booted from a 1.44MB Floppy Disk where one sector is 512 bytes. Meaning the last bytes of the first sector need to be 8855. We can ask Nasm to emit the bytes directly by using
DB
directive, which stands for declare constant bytes, while theTIMES
directive repeats an instruction a number of times. -
In NASM the
$
can be used to obtain an Assembly position of the beginning of the current line, while the$$
gives us the beginning of the current section. Meaning$-$$
gives the size of the program in bytes -
After that we declare our signature using the
DW
directive