Load limine module + alloc user stack
This commit is contained in:
@@ -21,6 +21,7 @@ CC_FLAGS=-Wall -Wextra -std=gnu99 -nostdlib -ffreestanding -fstack-protector -fn
|
||||
LD := x86_64-elf-ld
|
||||
|
||||
$(ELFFILE): $(BUILDDIR) $(OBJFILES)
|
||||
nasm -f bin user/hello.S -o $(BUILDDIR)/hello
|
||||
nasm -f elf64 src/arch/x86/idt.S -o $(BUILDDIR)/idt_stub.o
|
||||
$(LD) -o $(ELFFILE) -T linker.ld $(OBJFILES) $(BUILDDIR)/idt_stub.o
|
||||
# Get the symbols for debugging
|
||||
@@ -47,6 +48,7 @@ build-iso: limine/limine $(ELFFILE)
|
||||
cp -v $(ELFFILE) iso_root/boot
|
||||
mkdir -p iso_root/boot/limine
|
||||
cp -v limine.conf iso_root/boot/limine
|
||||
cp $(BUILDDIR)/hello iso_root/boot/
|
||||
mkdir -p iso_root/EFI/BOOT
|
||||
cp -v limine/limine-bios.sys limine/limine-bios-cd.bin limine/limine-uefi-cd.bin iso_root/boot/limine/
|
||||
cp -v limine/BOOTX64.EFI iso_root/EFI/BOOT/
|
||||
|
||||
@@ -40,6 +40,10 @@
|
||||
#define KERNEL_STACK_SIZE 65536
|
||||
#define KERNEL_IDT_ENTRIES 33
|
||||
|
||||
/* user */
|
||||
#define USER_STACK_TOP 0x80000000
|
||||
#define USER_STACK_PAGES 16 // 16*4096 = 64kb
|
||||
|
||||
/* paging */
|
||||
#define PAGING_MAX_PHYS 0x200000000
|
||||
|
||||
|
||||
@@ -54,6 +54,7 @@ struct boot_context {
|
||||
struct limine_hhdm_response* hhdm;
|
||||
struct limine_kernel_address_response* kaddr;
|
||||
struct limine_boot_time_response* bootdate;
|
||||
struct limine_module_response* module;
|
||||
};
|
||||
|
||||
// Are these modules initialized yet?
|
||||
|
||||
@@ -24,6 +24,7 @@ struct process {
|
||||
status_t status;
|
||||
struct cpu_status* context;
|
||||
void* root_page_table; // Process PML4 (should contain kernel PML4 in higher half [256-511]
|
||||
void* kernel_stack; // Used for interrupts (syscall: int 0x80), defines the TSS RSP0
|
||||
struct process* next;
|
||||
};
|
||||
|
||||
|
||||
@@ -6,3 +6,4 @@ interface_branding: Welcome to the PepperOS disk!
|
||||
|
||||
comment: Default configuration (warning: spicy)
|
||||
path: boot():/boot/pepperk
|
||||
module_path: boot():/boot/hello
|
||||
|
||||
+9
-2
@@ -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
@@ -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
@@ -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;
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
bits 64
|
||||
|
||||
hello:
|
||||
mov qword rax, 0xcafebabe
|
||||
jmp hello
|
||||
Reference in New Issue
Block a user