started work on pmm

This commit is contained in:
2026-06-13 20:43:09 -04:00
parent 2ab98fe582
commit 4e8de774ef
5 changed files with 87 additions and 2 deletions

View File

@@ -1,4 +1,9 @@
.code32 .code32
.section .text
.global disable_interrupts
disable_interrupts:
cli
ret
.global enable_interrupts .global enable_interrupts
enable_interrupts: enable_interrupts:
@@ -8,4 +13,14 @@ enable_interrupts:
.global io_wait .global io_wait
io_wait: io_wait:
outb %al, $0x80 outb %al, $0x80
ret ret
.global load_grub_boot_struct
load_grub_boot_struct:
mov %ebx, grub_boot_struct_ptr
.section .bss
.align 4
.global grub_boot_struct_ptr
grub_boot_struct_ptr:
.int 0

View File

@@ -21,7 +21,7 @@ const char* err_messages[32] = {
[0] = "Divide by 0", [0] = "Divide by 0",
[1] = "", [1] = "",
[8] = "", [8] = "",
[13] = "General Protection Fault",a->i [13] = "General Protection Fault",
[14] = "Page Fault", [14] = "Page Fault",
}; };

View File

@@ -12,6 +12,10 @@ extern void init_pit();
extern int init_ps2(); extern int init_ps2();
extern void enable_interrupts(); extern void enable_interrupts();
extern void load_grub_boot_struct(void);
extern void* grub_boot_struct_ptr;
void kmain(void) void kmain(void)
{ {
extern print_stream_t vga_print_stream; extern print_stream_t vga_print_stream;

37
kernel/memory/mm.c Normal file
View File

@@ -0,0 +1,37 @@
#include "multiboot.h"
static uint32_t max_address = 0;
static uint32_t total_available_memory = 0;
void parse_mmap(void* base, uint32_t limit) {
multiboot_mmap_entry* entry = (multiboot_mmap_entry*)base;
void* end = (void*)((uint32_t)base + limit);
while ((void*)entry < end) {
if (entry->type == 1) {
uint32_t region_start = (uint32_t)(entry->addr);
uint32_t region_end = (uint32_t)(entry->addr + entry->len);
if (region_end > max_address) {
max_address = region_end;
}
total_available_memory += entry->len;
// start breaking up the address range
// if it's safe (not kernel, not BIOS structures, etc..), find the corresponding page in our PMM, mark it free
// need to align start and end to 4kb
if (entry->len < 4096) {
continue;
}
for (uint32_t addr = region_start; addr < region_end; addr += 4096) {
// check for physical kernel address range
// check if this address range contains our multiboot structure
// don't allow pages under 1MB
}
}
entry = (multiboot_mmap_entry*)((uint32_t)entry + entry->size + sizeof(entry->size));
}
}

29
kernel/multiboot.h Normal file
View File

@@ -0,0 +1,29 @@
#ifndef KMULTIBOOT_H
#define KMULTIBOOT_H
#include <stdint.h>
typedef struct {
uint32_t flags;
uint32_t mem_lower;
uint32_t mem_upper;
uint32_t boot_device;
uint32_t cmdline;
uint32_t mods_count;
uint32_t mods_addr;
uint32_t num;
uint32_t size;
uint32_t addr;
uint32_t shndx;
uint32_t mmap_length;
uint32_t mmap_addr;
} multiboot_info;
typedef struct __attribute__((packed)) {
uint32_t size;
uint64_t addr;
uint64_t len;
uint32_t type;
} multiboot_mmap_entry;
#endif