HelenOS sources
This source file includes following definitions.
- cpu_init
- cpu_list
#include <cpu.h>
#include <arch.h>
#include <arch/cpu.h>
#include <stdlib.h>
#include <mm/page.h>
#include <mm/frame.h>
#include <typedefs.h>
#include <config.h>
#include <panic.h>
#include <memw.h>
#include <adt/list.h>
#include <stdio.h>
#include <sysinfo/sysinfo.h>
#include <arch/cycle.h>
cpu_t *cpus;
void cpu_init(void)
{
#ifdef CONFIG_SMP
if (config.cpu_active == 1) {
#endif
cpus = (cpu_t *) malloc(sizeof(cpu_t) * config.cpu_count);
if (!cpus)
panic("Cannot allocate CPU structures.");
memsetb(cpus, sizeof(cpu_t) * config.cpu_count, 0);
for (size_t i = 0; i < config.cpu_count; i++) {
uintptr_t stack_phys = frame_alloc(STACK_FRAMES,
FRAME_LOWMEM | FRAME_ATOMIC, STACK_SIZE - 1);
if (!stack_phys)
panic("Cannot allocate CPU stack.");
cpus[i].local.stack = (uint8_t *) PA2KA(stack_phys);
cpus[i].id = i;
#ifdef CONFIG_FPU_LAZY
irq_spinlock_initialize(&cpus[i].fpu_lock, "cpus[].fpu_lock");
#endif
irq_spinlock_initialize(&cpus[i].tlb_lock, "cpus[].tlb_lock");
for (unsigned int j = 0; j < RQ_COUNT; j++) {
irq_spinlock_initialize(&cpus[i].rq[j].lock, "cpus[].rq[].lock");
list_initialize(&cpus[i].rq[j].rq);
}
}
#ifdef CONFIG_SMP
}
#endif
CPU = &cpus[config.cpu_active - 1];
CPU->active = true;
CPU->tlb_active = true;
CPU_LOCAL->idle = false;
CPU_LOCAL->last_cycle = get_cycle();
CPU->idle_cycles = ATOMIC_TIME_INITIALIZER();
CPU->busy_cycles = ATOMIC_TIME_INITIALIZER();
cpu_identify();
cpu_arch_init();
}
void cpu_list(void)
{
unsigned int i;
for (i = 0; i < config.cpu_count; i++) {
if (cpus[i].active)
cpu_print_report(&cpus[i]);
else
printf("cpu%u: not active\n", i);
}
}
HelenOS homepage, sources at GitHub