#ifndef KMM_H
#define KMM_H

#include <stdint.h>

#define PAGE_PRESENT  (1 << 0)
#define PAGE_WRITABLE (1 << 1)
#define PAGE_USER     (1 << 2)
#define PAGE_COW      (1 << 9)

#define TEMP_KERNPD_VADDR   0xDFF90000
#define TEMP_TASKPD_VADDR   0xDFFA0000
#define TEMP_PT_SRC         0xDFFB0000
#define TEMP_PT_DST         0xDFFC0000

#define PAGE_SIZE 4096

#define MAX_RAM   0xFFFFFFFF // 4GB
#define BITMAP_SIZE ((MAX_RAM / PAGE_SIZE) / 8)

#define CUR_PAGE_DIRECTORY  0xFFFFF000
#define CUR_PAGE_TABLES  0xFFC00000

typedef struct __attribute__((packed)) {
    uint32_t addr;
} mem_page_t;

void init_pmm(void* mmap_base, uint32_t mmap_limit);
void init_page_tables();

void* p_alloc_frame();

uint32_t total_free_memory();

void* create_new_pd();
void* clone_current_pd();
void clear_current_pd();

int is_cow(uint32_t vaddr);

void map_page(uint32_t vaddr, uint32_t paddr, uint32_t flags);
void unmap_page(uint32_t vaddr);

void load_pd(void* paddr);

void flush_tlb();
void disable_pae();

#endif 
