加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
setup.c 3.04 KB
一键复制 编辑 原始数据 按行查看 历史
/* SPDX-License-Identifier: Apache-2.0
* Copyright 2024 The TenonOS Authors
*/
#include <libfdt.h>
#include <stdio.h>
#include <uk/intctlr.h>
#include <uk/plat/common/bootinfo.h>
#include <uk/plat/memory.h>
#include <arm/psci.h>
#include <arm/cpu.h>
#include <d9/console.h>
#if CONFIG_ENFORCE_W_XOR_X && CONFIG_PAGING
#include <uk/plat/common/w_xor_x.h>
#endif /* CONFIG_ENFORCE_W_XOR_X && CONFIG_PAGING */
static char *cmdline;
static __sz cmdline_len;
static inline int cmdline_init(struct ukplat_bootinfo *bi)
{
char *cmdl;
if (bi->cmdline_len) {
cmdl = (char *)bi->cmdline;
cmdline_len = bi->cmdline_len;
} else {
cmdl = CONFIG_UK_NAME;
cmdline_len = sizeof(CONFIG_UK_NAME) - 1;
}
/* TODO: Only extract what we need before passing to application. */
/* This is not the original command-line, but one that will be thrashed
* by `ukplat_entry_argp` to obtain argc/argv. So mark it as a kernel
* resource instead.
*/
cmdline = ukplat_memregion_alloc(cmdline_len + 1, UKPLAT_MEMRT_KERNEL,
UKPLAT_MEMRF_READ | UKPLAT_MEMRF_WRITE |
UKPLAT_MEMRF_MAP);
if (unlikely(!cmdline))
return -ENOMEM;
memcpy(cmdline, cmdl, cmdline_len);
cmdline[cmdline_len] = 0;
return 0;
}
static void __noreturn _ukplat_entry2(void)
{
ukplat_entry_argp(NULL, cmdline, cmdline_len);
ukplat_lcpu_halt();
}
void _libd9plat_entry(void *fdtp)
{
int rc;
void *bstack;
struct ukplat_bootinfo *bi;
ukplat_bootinfo_fdt_setup(fdtp);
_libd9plat_init_console(fdtp);
bi = ukplat_bootinfo_get();
if (unlikely(!bi))
UK_CRASH("Invalid bootinfo");
rc = cmdline_init(bi);
if (unlikely(rc < 0))
UK_CRASH("Failed to initialize command-line\n");
/* Allocate boot stack */
bstack = ukplat_memregion_alloc(__STACK_SIZE, UKPLAT_MEMRT_STACK,
UKPLAT_MEMRF_READ | UKPLAT_MEMRF_WRITE |
UKPLAT_MEMRF_MAP);
if (unlikely(!bstack))
UK_CRASH("Boot stack alloc failed\n");
bstack = (void *)((__uptr)bstack + __STACK_SIZE);
/* Initialize paging */
rc = ukplat_mem_init();
if (unlikely(rc))
UK_CRASH("Could not initialize paging (%d)\n", rc);
#if defined(CONFIG_ENFORCE_W_XOR_X) && defined(CONFIG_PAGING)
/* Print boot information */
ukplat_bootinfo_print();
enforce_w_xor_x();
#endif /* CONFIG_ENFORCE_W_XOR_X && CONFIG_PAGING */
/* Initialize logical boot CPU */
rc = lcpu_init(lcpu_alloc(get_bootstrap_cpu_physical_id()));
if (unlikely(rc))
UK_CRASH("Failed to initialize bootstrapping CPU: %d\n", rc);
/* Initialize interrupt controller */
rc = uk_intctlr_probe();
if (unlikely(rc))
UK_CRASH("Could not initialize the IRQ controller: %d\n", rc);
/* Initialize PSCI */
rc = get_psci_method(bi);
if (unlikely(rc < 0))
UK_CRASH("Failed to get PSCI method: %d.\n", rc);
/*
* Switch away from the bootstrap stack as early as possible.
*/
uk_pr_info("Switch from bootstrap stack to stack @%p\n", bstack);
/* Print boot information */
uk_pr_info("Print bootinfo before jump to entry:\n");
ukplat_bootinfo_print();
/*
* Enter Unikraft with new allocated stack.
*/
lcpu_arch_jump_to(bstack, _ukplat_entry2);
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化