HelenOS sources
This source file includes following definitions.
- main_bsp
- main_bsp_separated_stack
- main_ap
- main_ap_separated_stack
#include <arch/asm.h>
#include <debug.h>
#include <context.h>
#include <stdio.h>
#include <panic.h>
#include <assert.h>
#include <config.h>
#include <time/clock.h>
#include <time/timeout.h>
#include <proc/scheduler.h>
#include <proc/thread.h>
#include <proc/task.h>
#include <main/kinit.h>
#include <main/version.h>
#include <console/kconsole.h>
#include <console/console.h>
#include <log.h>
#include <cpu.h>
#include <align.h>
#include <interrupt.h>
#include <str.h>
#include <mm/frame.h>
#include <mm/page.h>
#include <genarch/mm/page_pt.h>
#include <mm/km.h>
#include <mm/tlb.h>
#include <mm/as.h>
#include <mm/slab.h>
#include <mm/reserve.h>
#include <synch/waitq.h>
#include <synch/syswaitq.h>
#include <arch/arch.h>
#include <arch.h>
#include <ipc/ipc.h>
#include <macros.h>
#include <smp/smp.h>
#include <ddi/ddi.h>
#include <main/main.h>
#include <ipc/event.h>
#include <sysinfo/sysinfo.h>
#include <sysinfo/stats.h>
#include <lib/ra.h>
#include <cap/cap.h>
#define CHECK_INT_TYPE_(signness, size) \
static_assert(sizeof(signness##size##_t) * 8 == size, \
#signness #size "_t does not have " #size " bits");
#define CHECK_INT_TYPE(size) \
CHECK_INT_TYPE_(int, size); \
CHECK_INT_TYPE_(uint, size)
CHECK_INT_TYPE(8);
CHECK_INT_TYPE(16);
CHECK_INT_TYPE(32);
CHECK_INT_TYPE(64);
config_t config = {
.identity_configured = false,
.non_identity_configured = false,
.physmem_end = 0
};
char bargs[CONFIG_BOOT_ARGUMENTS_BUFLEN] = { };
init_t init = {
.cnt = 0
};
ballocs_t ballocs = {
.base = (uintptr_t) NULL,
.size = 0
};
static context_t ctx;
static const size_t bootstrap_stack_size = STACK_SIZE;
static _Alignas(STACK_SIZE) uint8_t bootstrap_stack[STACK_SIZE];
uint8_t *const bootstrap_stack_top = bootstrap_stack + STACK_SIZE;
static void main_bsp_separated_stack(void);
#ifdef CONFIG_SMP
static void main_ap_separated_stack(void);
#endif
_NO_TRACE void main_bsp(void)
{
config.cpu_count = 1;
config.cpu_active = 1;
config.base = (uintptr_t) kernel_load_address;
config.kernel_size =
ALIGN_UP((uintptr_t) kdata_end - config.base, PAGE_SIZE);
context_create(&ctx, main_bsp_separated_stack,
bootstrap_stack, bootstrap_stack_size);
context_restore(&ctx);
}
void main_bsp_separated_stack(void)
{
current_initialize(CURRENT);
version_print();
LOG("\nconfig.base=%p config.kernel_size=%zu",
(void *) config.base, config.kernel_size);
#ifdef CONFIG_KCONSOLE
kconsole_init();
#endif
exc_init();
ARCH_OP(pre_mm_init);
km_identity_init();
frame_init();
slab_cache_init();
malloc_init();
ra_init();
sysinfo_init();
as_init();
page_init();
tlb_init();
km_non_identity_init();
ddi_init();
ARCH_OP(post_mm_init);
reserve_init();
ARCH_OP(pre_smp_init);
smp_init();
slab_enable_cpucache();
uint64_t size;
const char *size_suffix;
bin_order_suffix(zones_total_size(), &size, &size_suffix, false);
printf("Detected %u CPU(s), %" PRIu64 " %s free memory\n",
config.cpu_count, size, size_suffix);
cpu_init();
calibrate_delay_loop();
ARCH_OP(post_cpu_init);
clock_counter_init();
timeout_init();
scheduler_init();
caps_init();
task_init();
thread_init();
sys_waitq_init();
sysinfo_set_item_data("boot_args", NULL, bargs, str_size(bargs) + 1);
if (init.cnt > 0) {
size_t i;
for (i = 0; i < init.cnt; i++)
LOG("init[%zu].addr=%p, init[%zu].size=%zu",
i, (void *) init.tasks[i].paddr, i, init.tasks[i].size);
} else
printf("No init binaries found.\n");
ipc_init();
event_init();
kio_init();
log_init();
stats_init();
task_t *kernel = task_create(AS_KERNEL, "kernel");
if (!kernel)
panic("Cannot create kernel task.");
thread_t *kinit_thread = thread_create(kinit, NULL, kernel,
THREAD_FLAG_UNCOUNTED, "kinit");
if (!kinit_thread)
panic("Cannot create kinit thread.");
thread_start(kinit_thread);
thread_detach(kinit_thread);
current_copy(CURRENT, (current_t *) CPU_LOCAL->stack);
context_replace(scheduler_run, CPU_LOCAL->stack, STACK_SIZE);
}
#ifdef CONFIG_SMP
void main_ap(void)
{
config.cpu_active++;
current_initialize(CURRENT);
ARCH_OP(pre_mm_init);
frame_init();
page_init();
tlb_init();
ARCH_OP(post_mm_init);
cpu_init();
calibrate_delay_loop();
ARCH_OP(post_cpu_init);
current_copy(CURRENT, (current_t *) CPU_LOCAL->stack);
context_replace(main_ap_separated_stack, CPU_LOCAL->stack, STACK_SIZE);
}
void main_ap_separated_stack(void)
{
timeout_init();
semaphore_up(&ap_completion_semaphore);
scheduler_run();
}
#endif
HelenOS homepage, sources at GitHub