Fixed using ALIGN() instead of dceil() in vmm

This commit is contained in:
2026-03-26 21:37:32 +01:00
parent 63a238d2c4
commit 5d67cbd958
3 changed files with 22 additions and 16 deletions
+6 -2
View File
@@ -25,8 +25,12 @@
#define ALIGN_DOWN(_addr, _align) ((_addr) & ~((_align) - 1))
#define BIT(_n) (1ULL << (_n))
#define min(_a, _b) ((_a) < (_b) ? (_a) : (_b))
#define max(_a, _b) ((_a) > (_b) ? (_a) : (_b))
#define swap(_a, _b) ({ typeof(_a) _tmp = (_a); (_a) = (_b); (_b) = (_a); })
#define min(_x, _y) ({ typeof(_x) __x = (_x); typeof(_y) __y = (_y); __x < __y ? __x : __y; })
#define max(_x, _y) ({ typeof(_x) __x = (_x); typeof(_y) __y = (_y); __x > __y ? __x : __y; })
#define ceil(_x, _y) ((((_x) + (_y)) (_y)) * (_y))
#define floor(_x, _y) ((_x) - ((_x) % (_y)))
#define dceil(_x, _y) (((_x) + (_y) - 1) / (_y))
#define fence() __asm__ volatile ("" ::: "memory")
+11 -11
View File
@@ -10,14 +10,13 @@
__noreturn
void _start(void) {
int err = 0;
// Serial console for debugging
if (serial_init(COM1) < 0) panic("Failed to initialize Serial driver.");
if ((err = serial_init(COM1)) < 0) panic("Failed to initialize Serial driver. (%d)", err);
// Load structures from bootloader
if (boot_init() < 0) panic("Failed to parse bootloader structures.");
// The most important function in the world.
splash();
if ((err = boot_init()) < 0) panic("Failed to parse bootloader structures. (%d)", err);
// CPUID thingy :p
uint32_t eax = 0;
@@ -26,16 +25,17 @@ void _start(void) {
pr_info("[kernel] CPUID_GETVENDORID: %s\n", s);
// System init
if (gdt_init() < 0) panic("Failed to initalize GDT.");
if (isr_init() < 0) panic("Failed to initalize ISRs.");
if ((err = gdt_init()) < 0) panic("Failed to initalize GDT. (%d)", err);
if ((err = isr_init()) < 0) panic("Failed to initalize ISRs. (%d)", err);
// Memory management
if (pmm_init() < 0) panic("Failed to initalize Physical Memory Manager.");
if (pag_init() < 0) panic("Failed to initalize Paging.");
if ((err = pmm_init()) < 0) panic("Failed to initalize Physical Memory Manager. (%d)", err);
if ((err = pag_init()) < 0) panic("Failed to initalize Paging. (%d)", err);
panic("Yeah..");
// The most important function in the world.
splash();
// Patiently wait for things to do :)
while (1);
}
};
+5 -3
View File
@@ -11,6 +11,8 @@
// VIRTUAL address of the kernels PML4
uint64_t* pag_kernel_pml4 = NULL;
// abcabcaaabcaab
int pag_init(void) {
pag_kernel_pml4 = TO_VIRT(pmm_alloc());
if (IS_ERR(pag_kernel_pml4)) return PTR_ERR(pag_kernel_pml4);
@@ -20,14 +22,14 @@ int pag_init(void) {
pag_kernel_pml4,
(void*)bootloader.kernel_virt_base,
(void*)bootloader.kernel_phys_base,
ALIGN(bootloader.executable->size, PAGE_SIZE),
dceil(bootloader.executable->size, PAGE_SIZE),
PTE_FLAG_WRITE | PTE_FLAG_PRESENT
);
if (ret != SUCCESS) return ret;
for (size_t i = 0; i < bootloader.mm_entry_count; i++) {
struct limine_memmap_entry* entry = bootloader.mm_entries[i];
uint64_t flags = 0;
switch (entry->type) {
case LIMINE_MEMMAP_USABLE: flags = PTE_FLAG_WRITE; break;
@@ -50,7 +52,7 @@ int pag_init(void) {
ret = pag_map_region(
pag_kernel_pml4,
(void*)(entry->base + bootloader.hhdm_offset), (void*)entry->base,
ALIGN(entry->length, PAGE_SIZE),
dceil(entry->length, PAGE_SIZE),
flags | PTE_FLAG_PRESENT
);
if (ret != SUCCESS) return ret;