build: add a "user" arch to allow the kernel to run as a program on the host machine
This commit is contained in:
68
arch/user/init.c
Normal file
68
arch/user/init.c
Normal file
@@ -0,0 +1,68 @@
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <socks/init.h>
|
||||
#include <socks/memblock.h>
|
||||
#include <socks/vm.h>
|
||||
#include <socks/object.h>
|
||||
#include <socks/printk.h>
|
||||
#include <arch/stdcon.h>
|
||||
#include <sys/mman.h>
|
||||
|
||||
#define PMEM_SIZE 0x2000000
|
||||
|
||||
extern void kernel_init(uintptr_t arg);
|
||||
|
||||
static void *pmem = NULL;
|
||||
|
||||
static void early_vm_init(void)
|
||||
{
|
||||
pmem = mmap(NULL, PMEM_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
|
||||
if (pmem == MAP_FAILED) {
|
||||
fprintf(stderr, "arch: cannot map physical memory buffer.");
|
||||
abort();
|
||||
}
|
||||
|
||||
uintptr_t alloc_start = (uintptr_t)pmem + VM_PAGE_SIZE;
|
||||
uintptr_t alloc_end = alloc_start + PMEM_SIZE;
|
||||
|
||||
memblock_init(alloc_start, alloc_end, (uintptr_t)pmem);
|
||||
printk("memblock: allocating from [0x%llx-0x%llx]", alloc_start, alloc_end);
|
||||
}
|
||||
|
||||
uintptr_t __pagemap_base(void)
|
||||
{
|
||||
return (uintptr_t)pmem;
|
||||
}
|
||||
|
||||
uintptr_t __pagemap_limit(void)
|
||||
{
|
||||
return (uintptr_t)pmem + PMEM_SIZE - 1;
|
||||
}
|
||||
|
||||
int ml_init(uintptr_t arg)
|
||||
{
|
||||
stdcon_init();
|
||||
print_kernel_banner();
|
||||
early_vm_init();
|
||||
|
||||
memblock_add(0, PMEM_SIZE);
|
||||
|
||||
vm_zone_descriptor_t vm_zones[] = {
|
||||
{ .zd_id = VM_ZONE_DMA, .zd_node = 0, .zd_name = "dma", .zd_base = 0x00, .zd_limit = 0xffffff },
|
||||
{ .zd_id = VM_ZONE_NORMAL, .zd_node = 0, .zd_name = "normal", .zd_base = 0x1000000, .zd_limit = UINTPTR_MAX },
|
||||
};
|
||||
|
||||
vm_bootstrap(vm_zones, sizeof vm_zones / sizeof vm_zones[0]);
|
||||
|
||||
object_bootstrap();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, const char **argv)
|
||||
{
|
||||
kernel_init(0);
|
||||
|
||||
munmap(pmem, PMEM_SIZE);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user