map apic
This commit is contained in:
@@ -45,7 +45,7 @@ static KeyboardApplication kapp;
|
||||
// Main function
|
||||
extern "C" int main() {
|
||||
|
||||
//PageFrameAllocator::init();
|
||||
PageFrameAllocator::init();
|
||||
memset(&paging_tree, 0, sizeof(four_lvl_paging_t));
|
||||
create_basic_page_table((uintptr_t)&paging_tree);
|
||||
load_cr3((void*)&paging_tree.l4);
|
||||
|
||||
@@ -11,22 +11,22 @@ void create_basic_page_table(uintptr_t base){
|
||||
//pagetable_entry_t *l1 = (pagetable_entry_t *) (base + (7 * 4096));
|
||||
four_lvl_paging_t* table = (four_lvl_paging_t*)base;
|
||||
|
||||
table->l4 = {
|
||||
.present = 0,
|
||||
.write = 0,
|
||||
.user = 0,
|
||||
.address = 0, //(uintptr_t)&(table->l3) >> 12,
|
||||
table->l4.entries[0] = {
|
||||
.present = 1,
|
||||
.write = 1,
|
||||
.user = 1,
|
||||
.address = (uintptr_t)&(table->l3) >> 12,
|
||||
};
|
||||
|
||||
table->l3 = {
|
||||
table->l3.entries[0] = {
|
||||
.present = 1,
|
||||
.write = 1,
|
||||
.user = 1,
|
||||
.address = (uintptr_t)&(table->l2) >> 12,
|
||||
};
|
||||
|
||||
for(uint32_t i=0; i<sizeof(table->l2)/sizeof(table->l2[0]); i++){
|
||||
table->l2[i] = {
|
||||
for(uint32_t i=0; i<sizeof(table->l1)/sizeof(table->l1[0]); i++){
|
||||
table->l2.entries[i] = {
|
||||
.present = 1,
|
||||
.write = 1,
|
||||
.user = 1,
|
||||
@@ -35,7 +35,7 @@ void create_basic_page_table(uintptr_t base){
|
||||
}
|
||||
|
||||
//kernel memory
|
||||
for(uintptr_t i=0; i<0x40000000/4096; i++){
|
||||
for(uintptr_t i=0; i<0x4000000/4096; i++){
|
||||
table->l1[i/512].entries[i%512] = {
|
||||
.present = 1,
|
||||
.write = 1,
|
||||
@@ -44,4 +44,47 @@ void create_basic_page_table(uintptr_t base){
|
||||
};
|
||||
}
|
||||
|
||||
//add ioapic address to pagetable
|
||||
table->l3.entries[3] = {
|
||||
.present = 1,
|
||||
.write = 1,
|
||||
.user = 1,
|
||||
.address = (uintptr_t)&(table->l2_apic) >> 12,
|
||||
};
|
||||
table->l2_apic.entries[502] = {
|
||||
.present = 1,
|
||||
.write = 1,
|
||||
.user = 1,
|
||||
.address = (uintptr_t)&(table->ioapic) >> 12,
|
||||
};
|
||||
table->ioapic.entries[0] = {
|
||||
.present = 1,
|
||||
.write = 1,
|
||||
.user = 0,
|
||||
.address = 0xFEC00,
|
||||
};
|
||||
|
||||
//lapic
|
||||
table->l2_apic.entries[503] = {
|
||||
.present = 1,
|
||||
.write = 1,
|
||||
.user = 1,
|
||||
.address = (uintptr_t)&(table->lapic) >> 12,
|
||||
};
|
||||
table->lapic.entries[0] = {
|
||||
.present = 1,
|
||||
.write = 1,
|
||||
.user = 0,
|
||||
.address = 0xFEE00,
|
||||
};
|
||||
|
||||
|
||||
//unmap 0 page
|
||||
table->l1[0].entries[0].present = 0;
|
||||
|
||||
////map ioapic
|
||||
//uintptr_t ioapic_page = 0xfec00000 >> 12;
|
||||
//table->l1[ioapic_page/512].entries[ioapic_page%512].address = ioapic_page;
|
||||
//table->l1[ioapic_page/512].entries[ioapic_page%512].present = 1;
|
||||
//table->l1[ioapic_page/512].entries[ioapic_page%512].write = 1;
|
||||
}
|
||||
|
||||
@@ -22,24 +22,27 @@ 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 {
|
||||
// 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 {
|
||||
alignas(4096) pagedirectory_entry_t l4;
|
||||
alignas(4096) pagedirectory_entry_t l3;
|
||||
alignas(4096) pagedirectory_entry_t l2[32];
|
||||
alignas(4096) pagetable_t l1[32];
|
||||
alignas(4096) pagetable_t l4;
|
||||
alignas(4096) pagetable_t l3;
|
||||
alignas(4096) pagetable_t l2;
|
||||
alignas(4096) pagetable_t l1[64];
|
||||
alignas(4096) pagetable_t l2_apic;
|
||||
alignas(4096) pagetable_t ioapic;
|
||||
alignas(4096) pagetable_t lapic;
|
||||
} four_lvl_paging_t;
|
||||
|
||||
void create_basic_page_table(uintptr_t base);
|
||||
|
||||
Reference in New Issue
Block a user