Files
bsb2/kernel/memory/pagetable.h

67 lines
1.7 KiB
C

#ifndef _PAGETABLE_H_
#define _PAGETABLE_H_
#include "../types.h"
#define KERNEL_MEMORY_BORDER 0x4000000
typedef struct {
uint8_t present:1 = 0;
uint8_t write:1 = 0;
uint8_t user:1 = 0;
uint8_t pwt:1 = 0;
uint8_t cache_disable:1 = 0;
uint8_t accessed:1 = 0;
uint8_t dirty:1 = 0;
uint8_t pat:1 = 0;
uint8_t rsvd_0:4 = 0;
uint64_t address:39 = 0;
uint16_t rsvd_1:10 = 0;
uint8_t execute_disable:1 = 0;
} __attribute__((__packed__)) pagetable_entry_t;
typedef struct {
pagetable_entry_t entries[512];
} pagetable_t;
//typedef struct {
// uint8_t present:1 = 0;
// uint8_t write:1 = 0;
// uint8_t user:1 = 0;
// uint8_t pwt:1 = 0;
// uint8_t cache_disable:1 = 0;
// uint8_t accessed:1 = 0;
// uint8_t rsvd_0:6 = 0;
// uint64_t address:39 = 0;
// uint16_t rsvd_1:10 = 0;
// uint8_t execute_disable:1 = 0;
//} __attribute__((__packed__)) pagedirectory_entry_t;
typedef struct {
pagetable_t* l4;
pagetable_t* l3;
pagetable_t* l2;
pagetable_t* l1_kernel;
pagetable_t* l2_apic;
pagetable_t* ioapic;
pagetable_t* lapic;
} four_lvl_paging_t;
void write_identity_map(pagetable_t* identity_table, uint64_t size);
void create_basic_page_table(four_lvl_paging_t* table, pagetable_t* kernel_identity);
void load_cr3(void* cr3_value);
void setMapping(uintptr_t vaddr, void* frame, four_lvl_paging_t* flpt);
uintptr_t isMapped(uintptr_t vaddr, four_lvl_paging_t* flpt);
void* getFreeVirtSpace(four_lvl_paging_t* search_table, uint8_t num_pages);
void copy_pagetable(four_lvl_paging_t* parent_table, four_lvl_paging_t* child_table);
//typedef struct {
// same
//} pagedirectory_pointertable_entry_t;
//typedef struct {
// same
//} PML4_entry_t;
#endif