aboutsummaryrefslogtreecommitdiff
path: root/arch/riscv64/kernel/vmem.c
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2024-07-05 19:38:11 +0300
committerKimplul <kimi.h.kuparinen@gmail.com>2024-07-05 19:38:11 +0300
commite09edb5d54e39bd9509a1dc450df5ab320759f97 (patch)
tree78e050b0db87df3a3ddfbb6570d44513ac34e02a /arch/riscv64/kernel/vmem.c
parent98f21e694a6b0964d6d08196cb6bfbc1c2ae2ff4 (diff)
downloadkmi-e09edb5d54e39bd9509a1dc450df5ab320759f97.tar.gz
kmi-e09edb5d54e39bd9509a1dc450df5ab320759f97.zip
allow booting with Qemu's -kernel flag directly
+ Took some fairly significant changes, for one the kernel is no longer relocated at the start of a boot, instead it sits wherever the user decides the kernel should sit. Similarly, the initial kernel stack and page table are stored within the binary, slightly bloating the size but making it much safer to boot since there's really no chance of us overwriting the fdt or initrd in memory.
Diffstat (limited to 'arch/riscv64/kernel/vmem.c')
-rw-r--r--arch/riscv64/kernel/vmem.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/arch/riscv64/kernel/vmem.c b/arch/riscv64/kernel/vmem.c
index cc6f3ac..835f53d 100644
--- a/arch/riscv64/kernel/vmem.c
+++ b/arch/riscv64/kernel/vmem.c
@@ -399,13 +399,26 @@ static void __populate_dmap(struct vmem *branch)
/** How many base pages we use for the rpc stack. Used fairly often so calculate
* it at the start and then reference it. */
static size_t rpc_pages;
+long riscv_init_stack[4096 / sizeof(long)];
+__attribute__((aligned(4096))) struct vmem bootvmem;
+
+struct vmem *direct_mapping()
+{
+ rpc_pages = order_size(MM_O1) / BASE_PAGE_SIZE;
+
+ __populate_dmap(&bootvmem);
+ populate_kvmem(&bootvmem);
+ __use_vmem(&bootvmem, DEFAULT_Sv_MODE);
+
+ return &bootvmem;
+}
+
struct vmem *init_vmem(void *fdt)
{
UNUSED(fdt);
struct vmem *b = create_vmem();
__populate_dmap(b);
- rpc_pages = order_size(MM_O1) / BASE_PAGE_SIZE;
/* update which memory branch to use */
use_vmem(b);
return b;
@@ -415,14 +428,13 @@ struct vmem *create_vmem()
{
struct vmem *b = (struct vmem *)alloc_page(MM_KPAGE);
memset(b, 0, MM_KPAGE_SIZE);
-
populate_kvmem(b);
return b;
}
stat_t use_vmem(struct vmem *b)
{
- __use_vmem(b, DEFAULT_Sv_MODE);
+ __use_vmem(__pa(b), DEFAULT_Sv_MODE);
return OK;
}
@@ -457,7 +469,7 @@ vm_t setup_kernel_io(struct vmem *b, vm_t paddr)
* modifying, or during the startup stage where we don't have a tcb yet.
* I don't think checking the rpc context is necessary? */
if (!cur_tcb() || cur_tcb()->proc.vmem == b)
- flush_tlb((uintptr_t)pte_addr(b->leaf[IO_PAGE]));
+ flush_tlb_full();
return -TOP_PAGE_SIZE + paddr - addr;
}