#ifndef MM_H #define MM_H MM_H #include "hos_types.h" #include "hos_defines.h" #include "multiboot.h" #define KERNEL_CODE_SEGMENT 0x08 #define KERNEL_DATA_SEGMENT 0x10 typedef u32_t pagedirectory_entry_t; #define NUM_PAGETABLE_ENTRIES (PAGE_SIZE / sizeof(pagedirectory_entry_t)) typedef pagedirectory_entry_t pagedirectory_t[NUM_PAGETABLE_ENTRIES]; typedef struct { u64_t base; u64_t length; } mm_mem_range_t; /* http://courses.ece.illinois.edu/ece391/references/descriptors.pdf */ /* granularity: 0: limit in bytes; 1: limit in pages */ /* dpl: 0: system mode; 3: user mode */ /* normal: 0: TSS/LDT/call gate; 1: code/data segment */ /* code_seg: 0: data segment; 1: code segment */ #define MAKE_DESCRIPTOR(base, limit, granularity, dpl, normal, code_seg) \ (u64_t) ( ( (((u64_t) base) & 0xFF000000ull) << 32 ) /* base 31:24 */ \ | ( (((u64_t) granularity) & 0x1ull) << 55 ) /* granularity */ \ | ( ( (u64_t) 0x1ull) << 54 ) /* 32-bit */ \ | ( (((u64_t) limit) & 0xF0000ull) << 32 ) /* limit 19:16 */ \ | ( ( (u64_t) 0x1ull) << 47 ) /* present */ \ | ( (((u64_t) dpl) & 0x3ull) << 45 ) /* dpl */ \ | ( (((u64_t) normal) & 0x1ull) << 44 ) /* normal */ \ | ( (((u64_t) code_seg) & 0x1ull) << 43 ) /* code seg */ \ | ( ( (u64_t) 0x2ull) << 40 ) /* ? */ \ | ( (((u64_t) base) & 0x00FFFFFFull) << 16) /* base 23:00 */ \ | ( (((u64_t) limit) & 0x0000FFFFull) ) ) /* limit 15:00 */ typedef u64_t descriptor_t; void mm_record_mmap_entry(mb_mmap_t * mmap); void mm_bootstrap(); int mm_early_map(u32_t virtual_address, u32_t physical_address, u32_t user_mode, u32_t writable); int mm_map(u32_t virtual_address, u32_t physical_address, u32_t user_mode, u32_t writable); u32_t mm_early_page_alloc(); u32_t mm_page_alloc(); void mm_print_memory_map(); #endif