2023-02-06 20:50:28 +00:00
|
|
|
#ifndef ARCH_PAGING_H_
|
|
|
|
|
#define ARCH_PAGING_H_
|
|
|
|
|
|
2024-11-02 11:31:51 +00:00
|
|
|
#include <mango/types.h>
|
|
|
|
|
#include <mango/compiler.h>
|
2023-02-06 20:50:28 +00:00
|
|
|
|
2023-03-20 20:41:39 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
|
extern "C" {
|
|
|
|
|
#endif
|
|
|
|
|
|
2023-02-06 20:50:28 +00:00
|
|
|
#define PTE_PRESENT 0x01ULL
|
|
|
|
|
#define PTE_RW 0x02ULL
|
|
|
|
|
#define PTE_USR 0x04ULL
|
|
|
|
|
#define PTE_WRITETHROUGH 0x08ULL
|
|
|
|
|
#define PTE_NOCACHE 0x10ULL
|
|
|
|
|
#define PTE_PAGESIZE 0x80ULL
|
|
|
|
|
#define PTE_NX 0x8000000000000000ULL
|
|
|
|
|
|
|
|
|
|
typedef phys_addr_t pml4t_ptr_t;
|
|
|
|
|
typedef uint64_t pte_t;
|
|
|
|
|
|
2023-04-12 20:17:11 +01:00
|
|
|
struct pml4t {
|
2023-02-06 20:50:28 +00:00
|
|
|
phys_addr_t p_entries[512];
|
2023-04-12 20:17:11 +01:00
|
|
|
} __packed;
|
2023-02-06 20:50:28 +00:00
|
|
|
|
2023-04-12 20:17:11 +01:00
|
|
|
struct pdpt {
|
2023-02-06 20:50:28 +00:00
|
|
|
union {
|
|
|
|
|
/* 4KiB and 2MiB pages */
|
|
|
|
|
phys_addr_t p_entries[512];
|
|
|
|
|
/* 1GiB pages */
|
|
|
|
|
pte_t p_pages[512];
|
|
|
|
|
};
|
2023-04-12 20:17:11 +01:00
|
|
|
} __packed;
|
2023-02-06 20:50:28 +00:00
|
|
|
|
2023-04-12 20:17:11 +01:00
|
|
|
struct pdir {
|
2023-02-06 20:50:28 +00:00
|
|
|
union {
|
|
|
|
|
/* 4KiB pages */
|
|
|
|
|
phys_addr_t p_entries[512];
|
|
|
|
|
/* 2MiB pages */
|
|
|
|
|
pte_t p_pages[512];
|
|
|
|
|
};
|
2023-04-12 20:17:11 +01:00
|
|
|
} __packed;
|
2023-02-06 20:50:28 +00:00
|
|
|
|
2023-04-12 20:17:11 +01:00
|
|
|
struct ptab {
|
2023-02-06 20:50:28 +00:00
|
|
|
pte_t p_pages[512];
|
2023-04-12 20:17:11 +01:00
|
|
|
} __packed;
|
2023-02-06 20:50:28 +00:00
|
|
|
|
2023-04-12 20:17:11 +01:00
|
|
|
enum page_size {
|
2023-02-06 20:50:28 +00:00
|
|
|
PS_4K,
|
|
|
|
|
PS_2M,
|
|
|
|
|
PS_1G,
|
2023-04-12 20:17:11 +01:00
|
|
|
};
|
2023-02-06 20:50:28 +00:00
|
|
|
|
|
|
|
|
/* returns 1 if gigabyte pages are supported by the CPU, 0 otherwise.
|
|
|
|
|
defined in pmap_ctrl.S */
|
|
|
|
|
extern int gigabyte_pages(void);
|
2023-02-09 21:38:06 +00:00
|
|
|
extern int enable_nx(void);
|
2023-02-06 20:50:28 +00:00
|
|
|
|
2023-03-20 20:41:39 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2023-02-06 20:50:28 +00:00
|
|
|
#endif
|