genode/repos/base-hw/src/core/spec/x86/kernel/cpu.cc

65 lines
1.5 KiB
C++

/*
* \brief Class for kernel data that is needed to manage a specific CPU
* \author Reto Buerki
* \date 2015-02-09
*/
/*
* Copyright (C) 2015 Genode Labs GmbH
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU General Public License version 2.
*/
/* core includes */
#include <kernel/cpu.h>
#include <kernel/kernel.h>
#include <kernel/pd.h>
using namespace Kernel;
Cpu_idle::Cpu_idle(Cpu * const cpu) : Cpu_job(Cpu_priority::MIN, 0)
{
Cpu_job::cpu(cpu);
ip = (addr_t)&_main;
sp = (addr_t)&_stack[stack_size];
init((addr_t)core_pd()->translation_table(), true);
}
void Cpu_idle::exception(unsigned const cpu)
{
if (trapno == RESET) {
return;
} else if (trapno >= INTERRUPTS_START && trapno <= INTERRUPTS_END) {
_interrupt(cpu);
return;
}
PWRN("Unknown exception %lu with error code %lu at ip=%p", trapno,
errcode, (void *)ip);
assert(0);
}
void Kernel::Cpu::init(Pic &pic, Kernel::Pd &core_pd)
{
Timer::disable_pit();
_init_fpu();
/*
* Please do not remove the PINF(), because the serial constructor requires
* access to the Bios Data Area, which is available in the initial
* translation table set, but not in the final tables used after
* Cr3::write().
*/
PINF("Switch to core's final translation table");
Cr3::write(Cr3::init((addr_t)core_pd.translation_table()));
/* enable timer interrupt */
unsigned const cpu = Cpu::executing_id();
pic.unmask(Timer::interrupt_id(cpu), cpu);
}