代码拉取完成,页面将自动刷新
/* 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);
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。