summaryrefslogtreecommitdiff
path: root/doc/develop/file_summary.md
blob: de7df15a07f8e45ae825429680b2a725f8654eee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
Makefile - Top-level Makefile, deligates to boot/ and kernel/ Makefiles with ARCH=x86_64 or ARCH=aarch64. Provides make all, make disk-aarch64, make run-x86_64 and other
config.mk - Shared toolchain config - defines Clang/LLD paths, per-arch target triples and flags, common c++20 freestanding flags (-fno-exception, -fno-rtti, -nostlib and other)

include/boot_info.h - The loader <-> kernel boot_info struct.

boot/Makefile - Builds .efi binary via ELF->PE32+ objcopy. Compiles c++ with --target=x86_64-unknown-windows (or aarch64), links with lld-link to produce a PE32+ .efi binary directly
boot/common/efi.h - Standalone UEFI types (without gnu-efi or EDK2 dependency). It defines EFI_SYSTEM_TABLE, EFI_BOOT_SERVICE, GOP, FIle Protocol, Loaded Image Protocol, GUIDs, status codes.
boot/common/elf.h - ELF64 format definitions. It defines Elf64_Ehdr, Elf64_Phdr, segment types(PT_LOAD), machine types(EM_X86_64, EM_AARCH64), and the ElfLoadResult struct.
boot/common/elf_parser.cpp - Reads ELF64 bin from memory, validates headers, calculates virtual address span, allocates phisycal pages via UEFI AllocatePages, copies PT_LOAD segments, zeroes BSS. Returns entry point and load addresses.
boot/common/efi_loader.cpp - Main boot logic: load ELF, GOP, memory map, ExitBootService. Opens the ESP filesystem, reads bastion.elf, calls the ELF parser, locates GOF framebuffer, finds ACPI/FDT config tables, does GetMemoryMap -> ExitBootServices, converts UEFI memory map to our format, populates BootInfo.
boot/x86_64/entry.cpp - efi_main() -> common loader -> jump to kernel. Calls efi_loader_main(), then computes the physical entry address from the ELF virtual entry and jumps to the kernel with BootInfo* in RDI register.
boot/x86_64/linker.ld - PE32+ layout for x86_64 loader. Linker script for this loader - section layout for text/rodata/data/bss.
boot/aarch64/entry.cpp - efi_main() -> common loader -> jump to kernel but for aarch64. Instead of RDI uses X0(AAPCS64)
boot/aarch64/linkel.ld - PE32+ layout for aarch64 loader

kernel/Makefile - Builds kernel.elf - auto-discovers .cpp asd .S sources via wildcard, compiles as freestanding ELF, links with the arch-specifc linker script
kernel/arch/x86_64/entry.S - Assembly entry: set stack, call kernel_main. Sets up a 16KiB stack, calls ```kernel_main(BootInfo*)``` . Written in AT&T syntax for Clang's integrated assembler.
kernel/arch/x86_64/linker.ld - Places kernel at phiscal 0x100000 (1MiB). Defines .text, .rodata .data .bss sections with section boundary symbols (__bss_start, __kernel_end)
kernel/arch/aarch64/entry.S - Same for AArch64. Masks interrupts, sets stack from _stack_top, calls kernel_main.
kernel/arch/aarch64/linkel.ld - Same, but at 0x40100000 (QEMU virt machine convention)
kernel/core/kernel_main.cpp - First c++ code: init console, dump memory map, halt. Validate BootInfo magic, init the framebuffer console, prints a banner with arch name, dumps framebuffer info, firmware table addresses, memory map with region types and total usable RAM, then halts.
kernel/lib/kprint.cpp - Framebuffer console with 8x16 VGA bitmap font (ASCII 32-126).
kernel/lib/string.cpp - Freestanding memcpy/memset/strlet and other
kernel/lib/cxxabi.cpp - C++ ABI stubs(```__ctx_atexit``` and other). Has placeholder for new/delete operators. Needed because the compiler emits references to these symbols even in freestanding mode.
kernel/include/kernel/kprint.h - Console API header
kernel/include/kernel/types.h - PhysAddr, VirtAddr, aligment helpers
scripts/create_disk.sh - Creates 64 MiB GPT + FAT32 ESP disp image. Copies BOOTX64.efi to EFI/BOOT/ and bastion.elf to the root. Uses sgdisk + mkfs.vfat + mtools
scripts/run_qemu.sh - Finds OVMF/AAVMF firmware on the system and launches QEMU with the disk image, serial on stdio, interrupt logging enabled.