/*
 * @author  xamidev <xamidev@riseup.net>
 * @brief   Virtual memory manager
 * @license GPL-3.0-only
 */

#ifndef VMM_H
#define VMM_H

#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>

struct vmm_context {
    uint64_t* pml4;
};

void vmm_init(void);
void* vmm_alloc_region(uint64_t* pml4, size_t pages, uint64_t flags);
bool vmm_is_mapped(uint64_t* pml4, uint64_t virt);
void vmm_unmap(uint64_t* pml4, uint64_t virt);
void* vmm_map(uint64_t* pml4, uint64_t virt, uint64_t flags);
uint64_t* vmm_create_address_space();
uint64_t vmm_virt_to_phys(uint64_t* pml4, uint64_t virt);
uintptr_t vmm_alloc_user_stack(uint64_t* pml4);
uintptr_t vmm_alloc_user_code(uint64_t* pml4, void* code_addr, uint64_t code_size);

#define VMM_USER_SPACE_START 0x0000000000001000 
#define VMM_USER_SPACE_END   0x00007FFFFFFFF000

#endif