Skip to content

Commit 899d0b2

Browse files
committed
Add documentation for the assembly stages
1 parent e9ad711 commit 899d0b2

File tree

4 files changed

+14
-0
lines changed

4 files changed

+14
-0
lines changed

src/stage_1.s

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
.intel_syntax noprefix
44
.code16
55

6+
# This stage initializes the stack, enables the A20 line, loads the rest of
7+
# the bootloader from disk, and jumps to stage_2.
8+
69
_start:
710
# zero segment registers
811
xor ax, ax

src/stage_2.s

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
.intel_syntax noprefix
33
.code16
44

5+
# This stage sets the target operating mode, loads the kernel from disk,
6+
# creates an e820 memory map, enters protected mode, and jumps to the
7+
# third stage.
8+
59
second_stage_start_str: .asciz "Booting (second stage)..."
610
kernel_load_failed_str: .asciz "Failed to load kernel from disk"
711

src/stage_3.s

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
.intel_syntax noprefix
33
.code32
44

5+
# This stage performs some checks on the CPU (cpuid, long mode), sets up an
6+
# initial page table mapping (identity map the bootloader, map the P4
7+
# recursively, map the kernel blob to 4MB), enables paging, switches to long
8+
# mode, and jumps to stage_4.
9+
510
stage_3:
611
mov bx, 0x10
712
mov ds, bx # set data segment

src/stage_4.s

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
.intel_syntax noprefix
33
.code64
44

5+
# This stage calls into Rust code, passing various values as arguments.
6+
57
stage_4:
68
# call load_elf with kernel start address, size, and memory map as arguments
79
movabs rdi, 0x400000 # move absolute 64-bit to register

0 commit comments

Comments
 (0)