wip: kernel and virt allocator

This commit is contained in:
0x35c
2025-11-13 12:09:36 +01:00
parent d30e1e4582
commit c5f8599d90
6 changed files with 34 additions and 35 deletions

View File

@ -6,20 +6,21 @@
#include <stddef.h>
#include <stdint.h>
#define PRESENT (1 << 0)
#define RW (1 << 1)
#define SUPERVISOR (0 << 2)
#define ACCESSED (1 << 4)
#define INIT_FLAGS (PRESENT | RW | SUPERVISOR)
#define PAGE_SIZE 4096
#define PT_SIZE 1024
#define PD_SIZE 1024
#define PAGE_MASK 0xFFFFF000
#define HEAP_END 0xC0000000
#define HEAP_START ((uint32_t)&_kernel_end - HEAP_END)
#define KERNEL_START ((uint32_t)&_kernel_start)
#define KERNEL_END ((uint32_t)&_kernel_end - HEAP_END)
#define PT_START 256
#define PRESENT (1 << 0)
#define RW (1 << 1)
#define SUPERVISOR (0 << 2)
#define ACCESSED (1 << 4)
#define INIT_FLAGS (PRESENT | RW | SUPERVISOR)
#define PAGE_SIZE 4096
#define PT_SIZE 1024
#define PD_SIZE 1024
#define PAGE_MASK 0xFFFFF000
#define HEAP_END 0xC0000000
#define HEAP_START ((uint32_t)&_kernel_end - HEAP_END)
#define KERNEL_START ((uint32_t)&_kernel_start)
#define KERNEL_END ((uint32_t)&_kernel_end - HEAP_END)
#define KERNEL_PT_END 1020
#define KERNEL_PT_START 769
#define GET_PAGE_ADDR(pd_index, pt_index) \
((((uint32_t)pd_index * 1024) + (uint32_t)pt_index) * 4096)
@ -64,5 +65,5 @@ void *valloc_pages(size_t size, void **phys_addr);
int kfree_pages(void *page_ptr, size_t size);
int vfree_pages(void *page_ptr, size_t size);
void init_page_table(uint32_t page_table[1024], uint16_t start);
int16_t add_page_table(uint16_t pd_index);
int16_t add_page_table(uint16_t pd_index, uint16_t pt_start);
void switch_pd(uint32_t *pd, uint32_t *cr3);