Load limine module + alloc user stack

This commit is contained in:
2026-04-01 15:51:04 +02:00
parent d644126901
commit 11a9dd4adb
10 changed files with 61 additions and 3 deletions
+9 -2
View File
@@ -13,6 +13,9 @@
#include <limine.h>
#include <stddef.h>
__attribute__((used, section(".limine_requests_start")))
volatile LIMINE_REQUESTS_START_MARKER;
__attribute__((used, section(".limine_requests")))
volatile struct limine_framebuffer_request framebuffer_request = {
.id = LIMINE_FRAMEBUFFER_REQUEST,
@@ -43,8 +46,11 @@ volatile struct limine_boot_time_request date_request = {
.revision = 0
};
__attribute__((used, section(".limine_requests_start")))
volatile LIMINE_REQUESTS_START_MARKER;
__attribute__((used, section(".limine_requests")))
volatile struct limine_module_request module_request = {
.id = LIMINE_MODULE_REQUEST,
.revision = 0
};
__attribute__((used, section(".limine_requests_end")))
volatile LIMINE_REQUESTS_END_MARKER;
@@ -58,4 +64,5 @@ void populate_boot_context(struct boot_context* ctx)
ctx->hhdm = hhdm_request.response ? hhdm_request.response : NULL;
ctx->kaddr = kerneladdr_request.response ? kerneladdr_request.response : NULL;
ctx->bootdate = date_request.response ? date_request.response : NULL;
ctx->module = module_request.response ? module_request.response : NULL;
}
+1 -1
View File
@@ -18,7 +18,7 @@ extern int panic_count;
*/
void read_rflags(uint64_t rflags)
{
DEBUG("\x1b[38;5;226m%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\x1b[38;5;231m",
printf("\x1b[38;5;226m%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\x1b[38;5;231m",
CHECK_BIT(rflags, 0) ? "CF " : "", /*carry flag*/
CHECK_BIT(rflags, 2) ? "PF " : "", /*parity flag*/
CHECK_BIT(rflags, 4) ? "AF " : "", /*auxiliary carry flag*/
+12
View File
@@ -62,6 +62,9 @@ extern volatile struct limine_memmap_request memmap_request;
extern volatile struct limine_hhdm_request hhdm_request;
extern volatile struct limine_kernel_address_request kerneladdr_request;
extern volatile struct limine_boot_time_request date_request;
extern volatile struct limine_module_request module_request;
struct limine_file* file;
extern struct process* processes_list;
extern struct process* current_process;
@@ -119,6 +122,15 @@ void kmain()
scheduler_init();
if (!boot_ctx.module) {
panic(NULL, "could not load 'hello' executable :(");
}
if (boot_ctx.module->module_count == 1) {
file = boot_ctx.module->modules[0];
DEBUG("file: addr=%p size=%u", file->address, file->size);
}
printf(PEPPEROS_SPLASH);
init.all = true;
+25
View File
@@ -13,6 +13,7 @@ in a specified virtual space
compared to the PMM which allocs/frees 4kb frames ("physical pages").
*/
#include "config.h"
#include <mem/vmm.h>
#include <mem/paging.h>
#include <stddef.h>
@@ -225,6 +226,30 @@ void* vmm_alloc_region(uint64_t* pml4, size_t pages, uint64_t flags)
return NULL;
}
/*
* vmm_map_user_stack - Map a user stack
* @pml4: the user process's PML4
*
* This function maps and allocates a userspace
* stack in the user @pml4 provided, according
* to constants USER_STACK_TOP and USER_STACK_PAGES.
*
* Return:
* <addr> - User stack top address
*/
uintptr_t vmm_alloc_user_stack(uint64_t* pml4)
{
uintptr_t stack_top = USER_STACK_TOP;
size_t stack_size = USER_STACK_PAGES*PAGE_SIZE;
for (size_t i=stack_top; i>stack_top-stack_size; i-=PAGE_SIZE) {
vmm_map(pml4, i, PTE_PRESENT | PTE_WRITABLE | PTE_USER);
}
return stack_top;
}
void vmm_init()
{
// NO U