vbos/include/kernel/mem.h
2023-04-12 13:58:22 -04:00

91 lines
1.6 KiB
C

/* SPDX-License-Identifier: GPL-2.0-only */
#ifndef _MEM_H_
#define _MEM_H_
#include <kernel/common.h>
#define HHDM_START 0xffffffff80000000
#define PAGE_XD (1 << 64)
#define PAGE_PRESENT (1 << 0)
#define PAGE_RW (1 << 1)
#define PAGE_USERMODE (1 << 2)
#ifndef __ASM__
#define ALIGN(_a) __attribute__((aligned(_a)))
struct page { /* I would rather refer to this as a struct */
union {
struct {
uint64_t present : 1;
uint64_t rw : 1;
uint64_t usermode : 1;
uint64_t pwt : 1;
uint64_t pcd : 1;
uint64_t accessed : 1;
uint64_t ignored : 1;
uint64_t zero : 1;
uint64_t ignored_2 : 4;
uint64_t addr : 36;
uint64_t reserved : 4;
uint64_t ignored_3 : 11;
uint64_t xd : 1;
};
uint64_t val;
};
};
struct cr3 {
union {
struct {
uint64_t ignored : 3;
uint64_t pwt : 1;
uint64_t pcd : 1;
uint64_t ignored_2 : 7;
uint64_t pml4_addr : 52;
};
uint64_t val;
};
};
struct mem_region {
paddr_t base;
size_t len;
};
struct mem_region_header {
paddr_t usable_base;
size_t usable_len;
struct buddy_free_list *flist;
size_t bitmap_len;
char bitmap[];
};
struct buddy_free_list {
size_t len;
size_t depth;
struct buddy_free_list *next;
struct buddy_free_list *prev;
};
extern uintptr_t __data_end;
extern uintptr_t __bss_start;
extern uintptr_t __bss_end;
extern uintptr_t hhdm_start;
extern uintptr_t data_end;
extern uintptr_t bss_start;
extern uintptr_t bss_end;
int page_map(uintptr_t virt, uintptr_t phys);
uint64_t cr3_read();
void cr3_write(uint64_t cr3);
void mem_early_init(char *mem, size_t len);
#endif /* __ASM__ */
#endif /* _MEM_H_ */