
First thing main does is call pagingInit(0x10000 * 4) then pml4[0] = (uint64_t)&page_dir_ptr_tab | 3 runs. All I did was make sure i was in protected mode and set up the stack and now I can't set variables.
this runs:
Code: Select all
_start:
cli
mov rax, cr0
or eax, 1
mov cr0, rax
mov esp, stack_top
extern svmain
push rbx
call svmain
Code: Select all
extern "C" void svmain (multiboot_info_t* mbinfo) {
pagingInit(0x1000000 * 4);
Code: Select all
uint64_t pml4[4] __attribute__((aligned(0x20)));
uint64_t page_dir_ptr_tab[4] __attribute__((aligned(0x20)));
uint64_t page_dir[512] __attribute__((aligned(0x1000)));
uint64_t page_tab[512] __attribute__((aligned(0x1000)));
uint64_t page_tab_2[512] __attribute__((aligned(0x1000)));
void pagingInit(uintptr_t start) {
pml4[0] = (uint64_t)&page_dir_ptr_tab | 3; // this doesn't work
Code: Select all
typedef struct page {
uint32_t present : 1;
uint32_t rw : 1;
uint32_t user : 1;
uint32_t write_through : 1;
uint32_t cache_disable : 1;
uint32_t accessed : 1;
uint32_t dirty : 1;
uint32_t zero : 1;
uint32_t global : 1;
uint32_t gp : 3;
uint64_t addr : 52;
} __attribute__ ((packed)) page_t;
void pagingInit(uintptr_t start) {
uintptr_t address = 0;
uintptr_t pt_start = start & 0xFFFFF000
page_t *page_table = (page_t *)pt_start
for (int i = 0; i < 512 * 512; i++) {
page_table[i].present = 1;
page_table[i].rw = 1;
page_table[i].addr = address; // crashes here
Code: Select all
G++:
-nostdlib -ffreestanding -g -Wall -Wextra -mno-80387 -masm=intel -fno-pie -fno-pic -static -fno-exceptions -fno-non-call-exceptions -mno-red-zone -mno-mmx -mno-sse -mno-sse2 -std=gnu++1z -fno-exceptions -fno-rtti -fno-common -O0 -IT8/include
NASM:
-felf64
