Files
nt-lite/code/public/ntlite/memory_map.h
T

41 lines
1.6 KiB
C

// Public NTLite memory map ABI declarations shared between kernel, drivers, and user mode.
#pragma once
// memory_map.h - shared between bootx64.efi and kernel.exe
// Describes physical memory layout passed from bootloader to kernel.
#include <stddef.h>
#include <stdint.h>
#define MEMORY_MAP_MAGIC 0x4D454D4D41500000ULL // 'MEMMAP\0\0'
#define MEMORY_MAX_REGIONS 256
typedef enum MEMORY_TYPE {
MemoryUsable = 0, // free RAM, available to the PMM
MemoryReserved = 1, // firmware-reserved, do not touch
MemoryMappedIO = 2, // device MMIO regions
MemoryFramebuffer = 3, // GOP framebuffer
MemoryBootloader = 4, // bootloader code/data (reclaimable)
MemoryKernel = 5, // kernel + HAL + drivers image pages
} MEMORY_TYPE;
typedef struct MEMORY_REGION {
uint64_t Base;
uint64_t Length; // in bytes, always page-aligned
MEMORY_TYPE Type;
uint32_t _pad;
} MEMORY_REGION;
typedef struct MEMORY_MAP {
uint64_t Magic;
uint32_t RegionCount;
uint32_t _pad;
MEMORY_REGION Regions[MEMORY_MAX_REGIONS];
} MEMORY_MAP;
// The bootloader and kernel must agree on physical memory handoff layout.
_Static_assert(sizeof(MEMORY_TYPE) == 4u, "MEMORY_TYPE ABI width changed");
_Static_assert(sizeof(MEMORY_REGION) == 24u, "MEMORY_REGION ABI size changed");
_Static_assert(offsetof(MEMORY_REGION, Type) == 16u, "MEMORY_REGION Type offset changed");
_Static_assert(offsetof(MEMORY_MAP, Regions) == 16u, "MEMORY_MAP Regions offset changed");
_Static_assert(sizeof(MEMORY_MAP) == 6160u, "MEMORY_MAP ABI size changed");