2023-02-25 17:58:23 +00:00
|
|
|
#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>
|
|
|
|
|
|
2023-02-26 10:05:39 +00:00
|
|
|
#define PMEM_SIZE 0x4000000
|
2023-02-25 17:58:23 +00:00
|
|
|
|
|
|
|
|
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]);
|
2023-02-26 10:05:39 +00:00
|
|
|
|
2023-02-25 17:58:23 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int main(int argc, const char **argv)
|
|
|
|
|
{
|
|
|
|
|
kernel_init(0);
|
|
|
|
|
|
|
|
|
|
munmap(pmem, PMEM_SIZE);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|