summaryrefslogtreecommitdiff
path: root/include/boot/boot_info.h
blob: 3c1e45f47d5478161265778793fe1233a0e1fe0e (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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#pragma once
// ============================================================================
// boot_info.h - Boot handoff struct
// Shared between the UEFI loader and the kernel.
// The loader fills it, the kernel consumes it. Simple.
// In future i will expand this struct
// ============================================================================

#include <stdint.h>

// ── Boot Magic Number───────────────────────────────────────────────────────
inline constexpr uint64_t BOOT_INFO_MAGIC = 0xDEADDEADDEADDEADULL;

// ── Framebuffer (GOP) ───────────────────────────────────────────────────────
// TODO: remove Framebuffer to driver
enum class PixelFormat : uint32_t {
    RGB  = 0,  // PixelRedGreenBlueReserved8BitPerColor
    BGR  = 1,  // PixelBlueGreenRedReserved8BitPerColor
    Mask = 2,  // PixelBitMask — need to check masks
};

struct FramebufferInfo {
    uint64_t    base;          // Physical address of framebuffer
    uint32_t    width;         // Horizontal resolution in pixels
    uint32_t    height;        // Vertical resolution in pixels
    uint32_t    pitch;         // Bytes per scanline (>= width * 4)
    PixelFormat format;
};

// ── Memory map ─────────────────────────────────────────────────────────────
//TODO: remove FrameBuffer
enum class MemoryRegionType : uint32_t {
    Usable                = 0,  // Free RAM - kernel can use
    Reserved              = 1,  // Firmware/hardware reserved
    AcpiReclaimable       = 2,  // ACPI tables - free after parsing
    AcpiNvs               = 3,  // ACPI non-volatile storage
    BootloaderReclaimable = 4,  // Loader code/data - free after kernel init
    KernelAndModules      = 5,  // Kernel image + any loaded modules
    Framebuffer           = 6,  // Framebuffer memory - do not use as RAM
};

struct MemoryRegion {
    uint64_t         base;
    uint64_t         length;
    MemoryRegionType type;
    uint32_t         _reserved;  // Padding to 24 bytes
};

// ── Boot info structure ────────────────────────────────────────────────────

struct BootInfo {
    uint64_t        magic;               // Must be BOOT_INFO_MAGIC

    // Framebuffer
    // Todo: remove
    FramebufferInfo framebuffer;

    // Memory map (array of MemoryRegion)
    MemoryRegion*   memory_map;
    uint64_t        memory_map_count;

    // Platform-specific firmware tables (both always present to keep layout uniform)
    uint64_t        rsdp_address;        // ACPI RSDP (x86_64), 0 if absent
    uint64_t        fdt_address;         // Flattened Device Tree (aarch64), 0 if absent

    // Kernel load info
    uint64_t        kernel_phys_base;    // Where the kernel was loaded physically
    uint64_t        kernel_virt_base;    // Kernel's virtual base (from ELF)
    uint64_t        kernel_size;         // Total size of kernel in memory

    // Kernel entry point (virtual address from ELF e_entry)
    uint64_t        kernel_entry_point;

    // Higher-half direct map base (if set up by loader)
    uint64_t        hhdm_base;           // e.g., 0xFFFF800000000000

    // Kernel command line (null-terminated string, or nullptr if none)
    // The loader can read this from a config file on the ESP.
    const char*     cmdline;             // e.g., "verbose nosmp mem=256M"
};