feat: handing over the handover
This commit is contained in:
parent
e45cc2aff3
commit
6d143cccf1
|
@ -26,7 +26,8 @@
|
||||||
"-mno-mmx",
|
"-mno-mmx",
|
||||||
"-mno-3dnow",
|
"-mno-3dnow",
|
||||||
"-mno-sse",
|
"-mno-sse",
|
||||||
"-mno-sse2"
|
"-mno-sse2",
|
||||||
|
"-g"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"cxx": {
|
"cxx": {
|
||||||
|
|
|
@ -6,7 +6,12 @@
|
||||||
|
|
||||||
#define STACK_SIZE (kib$(4))
|
#define STACK_SIZE (kib$(4))
|
||||||
#define KERNEL_STACK_SIZE (0x1000)
|
#define KERNEL_STACK_SIZE (0x1000)
|
||||||
#define USER_STACK_BASE (0xff0000000)
|
#define USER_STACK_TOP (0x7fffffffe000)
|
||||||
|
#define USER_STACK_SIZE (mib$(2))
|
||||||
|
#define USER_STACK_BASE (USER_STACK_TOP - USER_STACK_SIZE)
|
||||||
|
#define USER_HEAP_BASE (0x80000000000)
|
||||||
|
#define USER_HEAP_SIZE (gib$(4))
|
||||||
|
#define USER_HEAP_TOP (USER_HEAP_BASE + USER_HEAP_SIZE)
|
||||||
|
|
||||||
struct _HalContext
|
struct _HalContext
|
||||||
{
|
{
|
||||||
|
|
|
@ -15,6 +15,8 @@ _Noreturn int _start()
|
||||||
hal_panic();
|
hal_panic();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vmem_bootstrap();
|
||||||
|
|
||||||
Res hal = hal_setup();
|
Res hal = hal_setup();
|
||||||
if (hal.type != RES_OK)
|
if (hal.type != RES_OK)
|
||||||
{
|
{
|
||||||
|
|
|
@ -7,7 +7,8 @@
|
||||||
"dbg",
|
"dbg",
|
||||||
"stdc-shim",
|
"stdc-shim",
|
||||||
"loader",
|
"loader",
|
||||||
"kmalloc"
|
"kmalloc",
|
||||||
|
"tinyvmem"
|
||||||
],
|
],
|
||||||
"tools": {
|
"tools": {
|
||||||
"cc": {
|
"cc": {
|
||||||
|
|
|
@ -1,7 +1,11 @@
|
||||||
#include <dbg/log.h>
|
#include <dbg/log.h>
|
||||||
|
#include <hal.h>
|
||||||
#include <handover.h>
|
#include <handover.h>
|
||||||
|
#include <kmalloc/kmalloc.h>
|
||||||
|
#include <math.h>
|
||||||
#include <specs/elf.h>
|
#include <specs/elf.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <tinyvmem/tinyvmem.h>
|
||||||
|
|
||||||
#include "hal.h"
|
#include "hal.h"
|
||||||
#include "pmm.h"
|
#include "pmm.h"
|
||||||
|
@ -19,6 +23,7 @@
|
||||||
|
|
||||||
static HalPage *sched_vspace;
|
static HalPage *sched_vspace;
|
||||||
static HalContext *sched_ctx;
|
static HalContext *sched_ctx;
|
||||||
|
static Vmem sched_vmem;
|
||||||
|
|
||||||
static HalContext *kernel_ctx;
|
static HalContext *kernel_ctx;
|
||||||
static bool need_switch = false;
|
static bool need_switch = false;
|
||||||
|
@ -33,6 +38,8 @@ Res load_scheduler(void)
|
||||||
|
|
||||||
try$(hal_space_create(&sched_vspace));
|
try$(hal_space_create(&sched_vspace));
|
||||||
|
|
||||||
|
vmem_init(&sched_vmem, "procman", (void *)USER_HEAP_BASE, USER_HEAP_SIZE, PMM_PAGE_SIZE, 0, 0, 0, 0, 0);
|
||||||
|
|
||||||
Elf_Ehdr *hdr = (Elf_Ehdr *)sched.start;
|
Elf_Ehdr *hdr = (Elf_Ehdr *)sched.start;
|
||||||
if (memcmp(hdr->e_ident, ELFMAG, SELFMAG) != 0)
|
if (memcmp(hdr->e_ident, ELFMAG, SELFMAG) != 0)
|
||||||
{
|
{
|
||||||
|
@ -76,9 +83,24 @@ Res load_scheduler(void)
|
||||||
return err$(RES_NOMEM);
|
return err$(RES_NOMEM);
|
||||||
}
|
}
|
||||||
|
|
||||||
hal_space_map(sched_vspace, USER_STACK_BASE, sched_stack_obj.base, STACK_SIZE, HAL_MEM_READ | HAL_MEM_WRITE | HAL_MEM_USER);
|
HandoverBuilder builder;
|
||||||
|
PmmObj handover_obj = pmm_alloc(align_up$(kib$(16), PMM_PAGE_SIZE) / PMM_PAGE_SIZE);
|
||||||
|
if (handover_obj.len == 0)
|
||||||
|
{
|
||||||
|
return err$(RES_NOMEM);
|
||||||
|
}
|
||||||
|
|
||||||
hal_context_start(sched_ctx, hdr->e_entry, USER_STACK_BASE, (SysArgs){0, 0, 0, 0, 0, 0});
|
handover_builder_init(&builder, (void *)hal_mmap_l2h(handover_obj.base), kib$(16));
|
||||||
|
handover_parse_module(&builder);
|
||||||
|
|
||||||
|
builder.payload->magic = HANDOVER_MAGIC;
|
||||||
|
|
||||||
|
uintptr_t handover_addr = (uintptr_t)vmem_alloc(&sched_vmem, kib$(16), VM_INSTANTFIT);
|
||||||
|
|
||||||
|
try$(hal_space_map(sched_vspace, align_down$(handover_addr, PMM_PAGE_SIZE), align_down$((uintptr_t)handover_obj.base, PMM_PAGE_SIZE),
|
||||||
|
align_up$(builder.size, PMM_PAGE_SIZE), HAL_MEM_READ | HAL_MEM_USER));
|
||||||
|
try$(hal_space_map(sched_vspace, USER_STACK_BASE, sched_stack_obj.base, STACK_SIZE, HAL_MEM_READ | HAL_MEM_WRITE | HAL_MEM_USER));
|
||||||
|
hal_context_start(sched_ctx, hdr->e_entry, USER_STACK_BASE, (SysArgs){handover_addr, 0, 0, 0, 0, 0});
|
||||||
need_switch = true;
|
need_switch = true;
|
||||||
|
|
||||||
return ok$();
|
return ok$();
|
||||||
|
|
|
@ -55,7 +55,7 @@ void handover_parse_mmap(HandoverBuilder *self)
|
||||||
error$("Couldn't retrieve memory map from Limine");
|
error$("Couldn't retrieve memory map from Limine");
|
||||||
hal_panic();
|
hal_panic();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (kernel_addr_req.response == NULL)
|
if (kernel_addr_req.response == NULL)
|
||||||
{
|
{
|
||||||
error$("Couldn't retrieve kernel address from Limine");
|
error$("Couldn't retrieve kernel address from Limine");
|
||||||
|
@ -215,7 +215,6 @@ HandoverPayload *handover(void)
|
||||||
handover_parse_mmap(&builder);
|
handover_parse_mmap(&builder);
|
||||||
|
|
||||||
is_handover_init = true;
|
is_handover_init = true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return builder.payload;
|
return builder.payload;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"$schema": "https://schemas.cute.engineering/stable/cutekit.manifest.component.v1",
|
"$schema": "https://schemas.cute.engineering/stable/cutekit.manifest.component.v1",
|
||||||
"type": "lib",
|
"type": "lib",
|
||||||
"id": "mem",
|
"id": "tinyvmem",
|
||||||
"requires": [
|
"requires": [
|
||||||
"dbg",
|
"dbg",
|
||||||
"stdc-shim"
|
"stdc-shim"
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <sync/spinlock.h>
|
||||||
#include <sys/queue.h>
|
#include <sys/queue.h>
|
||||||
|
|
||||||
#include "tinyvmem.h"
|
#include "tinyvmem.h"
|
||||||
|
@ -21,6 +22,7 @@
|
||||||
#else
|
#else
|
||||||
# include <dbg/log.h>
|
# include <dbg/log.h>
|
||||||
# include <hal.h>
|
# include <hal.h>
|
||||||
|
|
||||||
# include "../../core/pmm.h"
|
# include "../../core/pmm.h"
|
||||||
# define vmem_printf(...) ((void)0)
|
# define vmem_printf(...) ((void)0)
|
||||||
# define ASSERT(x) (x ? (void)0 : _ASSERT(__FILE__, __LINE__, #x))
|
# define ASSERT(x) (x ? (void)0 : _ASSERT(__FILE__, __LINE__, #x))
|
||||||
|
@ -74,8 +76,17 @@ static int nfreesegs = 0;
|
||||||
|
|
||||||
#ifdef __ck_sys_kernel__
|
#ifdef __ck_sys_kernel__
|
||||||
|
|
||||||
void vmem_lock(void);
|
static Spinlock lock = SPINLOCK_INIT;
|
||||||
void vmem_unlock(void);
|
|
||||||
|
void vmem_lock(void)
|
||||||
|
{
|
||||||
|
spinlock_acquire(&lock);
|
||||||
|
}
|
||||||
|
|
||||||
|
void vmem_unlock(void)
|
||||||
|
{
|
||||||
|
spinlock_release(&lock);
|
||||||
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
# define vmem_lock()
|
# define vmem_lock()
|
||||||
|
|
|
@ -1,7 +1,17 @@
|
||||||
#include <dbg/log.h>
|
#include <dbg/log.h>
|
||||||
|
#include <handover/handover.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
_Noreturn int _start()
|
_Noreturn int _start(uintptr_t handover_addr)
|
||||||
{
|
{
|
||||||
|
HandoverPayload *handover = (HandoverPayload *)handover_addr;
|
||||||
|
|
||||||
|
if (handover->magic != HANDOVER_MAGIC)
|
||||||
|
{
|
||||||
|
error$("Invalid handover magic");
|
||||||
|
for (;;);
|
||||||
|
}
|
||||||
|
|
||||||
log$("Hello, world!");
|
log$("Hello, world!");
|
||||||
for (;;)
|
for (;;)
|
||||||
;
|
;
|
||||||
|
|
Loading…
Reference in a new issue