/** * @file * http://www.brokenthorn.com/Resources/OSDev18.html * https://wiki.osdev.org/Memory_Map_(x86) * * Paging * ====== * * The Smallest Managable Unit is a Page containing 4096 (0x1000) bytes. * * A Page Directory holds 1024 tables each mapping 1024 pages, totaling * in 0x100000000 bytes of addressable space (4gigs). * * The first 32megs will get ALWAYS identity mapped (hold kernel code/kernel stack etc) * This are the first 8 page-tables * * Layout * ====== * * We are aiming for the following layout: * * 0xFFFFFFFF * 0xC0000000 RESERVED * * 0xB0000000 User Stack TOP (Grows down) | * env, argc, argv ... | * | alltogether ~2.5gigs * .......... User Heap (brk()) | * 0x08000000 User Code | * | * | almost 100 megs (in kernel alloc/free private-cpu and shared) * | * 0x02000000 FoolOS TSS Stack TOP (max ~8mb) GROWS DOWN * leave few empty pages under stack as guard. * * 0x01800000 FoolOS Stack TOP (max ~8mb) GROWS DOWN * leave few empty pages under stack as guard. * * 0x01000000 * 0x00EFFFFF RESERVED * 0x00100000 FoolOS Kernel (max ~14mb) * 0x00007BFF RESERVED * 0x00007000 16-bit SMP entry (max ~3kb) * 0x00000500 * 0x00000000 RESERVED * */ //! i86 architecture defines 1024 entries per table--do not change #define PAGES_PER_TABLE 1024 #define PAGES_PER_DIR 1024 #define PAGE_DIRECTORY_INDEX(x) (((x) >> 22) & 0x3ff) #define PAGE_TABLE_INDEX(x) (((x) >> 12) & 0x3ff) #define PAGE_GET_PHYSICAL_ADDRESS(x) (*x & ~0xfff) //! page table represents 4mb address space #define PTABLE_ADDR_SPACE_SIZE 0x400000 //! directory table represents 4gb address space #define DTABLE_ADDR_SPACE_SIZE 0x100000000 //! page sizes are 4kb #define PAGE_SIZE 4096 //! page table entry typedef uint32_t pt_entry; //! a page directery entry typedef uint32_t pd_entry; //! page table typedef struct ptable_struct { pt_entry m_entries[PAGES_PER_TABLE]; }ptable ; //! page directory typedef struct pdirectory_struct { pd_entry m_entries[PAGES_PER_DIR]; }pdirectory; pdirectory* vmem_init(uint32_t kernel_blocks,uint32_t fb_addr);