parent
d961b9ae1e
commit
b85126a638
77
base-hw/src/core/kernel/thread.cc
Normal file
77
base-hw/src/core/kernel/thread.cc
Normal file
|
@ -0,0 +1,77 @@
|
||||||
|
/*
|
||||||
|
* \brief Kernel backend for execution contexts in userland
|
||||||
|
* \author Martin Stein
|
||||||
|
* \date 2013-09-15
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2013 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/thread.h>
|
||||||
|
#include <kernel/pd.h>
|
||||||
|
#include <platform_thread.h>
|
||||||
|
#include <platform_pd.h>
|
||||||
|
|
||||||
|
using namespace Kernel;
|
||||||
|
|
||||||
|
|
||||||
|
char const * Kernel::Thread::label()
|
||||||
|
{
|
||||||
|
if (!platform_thread()) {
|
||||||
|
if (!phys_utcb()) { return "idle"; }
|
||||||
|
return "core";
|
||||||
|
}
|
||||||
|
return platform_thread()->name();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
char const * Kernel::Thread::pd_label()
|
||||||
|
{
|
||||||
|
if (core()) { return "core"; }
|
||||||
|
if (!pd()) { return "?"; }
|
||||||
|
return pd()->platform_pd()->label();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
Kernel::Thread::prepare_to_start(void * const ip,
|
||||||
|
void * const sp,
|
||||||
|
unsigned const cpu_id,
|
||||||
|
unsigned const pd_id,
|
||||||
|
Native_utcb * const utcb_phys,
|
||||||
|
Native_utcb * const utcb_virt,
|
||||||
|
bool const main)
|
||||||
|
{
|
||||||
|
assert(_state == AWAIT_START)
|
||||||
|
|
||||||
|
/* FIXME: support SMP */
|
||||||
|
if (cpu_id) { PERR("multicore processing not supported"); }
|
||||||
|
|
||||||
|
/* store thread parameters */
|
||||||
|
_phys_utcb = utcb_phys;
|
||||||
|
_virt_utcb = utcb_virt;
|
||||||
|
_pd_id = pd_id;
|
||||||
|
|
||||||
|
/* join a protection domain */
|
||||||
|
Pd * const pd = Pd::pool()->object(_pd_id);
|
||||||
|
assert(pd);
|
||||||
|
addr_t const tlb = pd->tlb()->base();
|
||||||
|
|
||||||
|
/* initialize CPU context */
|
||||||
|
User_context * const c = static_cast<User_context *>(this);
|
||||||
|
bool const core = (_pd_id == core_id());
|
||||||
|
if (!main) { c->init_thread(ip, sp, tlb, pd_id); }
|
||||||
|
else if (!core) { c->init_main_thread(ip, utcb_virt, tlb, pd_id); }
|
||||||
|
else { c->init_core_main_thread(ip, sp, tlb, pd_id); }
|
||||||
|
|
||||||
|
/* print log message */
|
||||||
|
if (START_VERBOSE) {
|
||||||
|
PINF("in program %u '%s' start thread %u '%s'",
|
||||||
|
this->pd_id(), pd_label(), id(), label());
|
||||||
|
}
|
||||||
|
}
|
|
@ -101,6 +101,8 @@ class Kernel::Thread
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
enum { START_VERBOSE = 0 };
|
||||||
|
|
||||||
enum State
|
enum State
|
||||||
{
|
{
|
||||||
SCHEDULED = 1,
|
SCHEDULED = 1,
|
||||||
|
@ -301,6 +303,26 @@ class Kernel::Thread
|
||||||
_signal_receiver(0)
|
_signal_receiver(0)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return wether the thread is a core thread
|
||||||
|
*/
|
||||||
|
bool core() { return pd_id() == core_id(); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return kernel backend of protection domain the thread is in
|
||||||
|
*/
|
||||||
|
Pd * pd() { return Pd::pool()->object(pd_id()); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return user label of the thread
|
||||||
|
*/
|
||||||
|
char const * label();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* return user label of the protection domain the thread is in
|
||||||
|
*/
|
||||||
|
char const * pd_label();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Suspend the thread unrecoverably
|
* Suspend the thread unrecoverably
|
||||||
*/
|
*/
|
||||||
|
@ -327,30 +349,7 @@ class Kernel::Thread
|
||||||
unsigned const pd_id,
|
unsigned const pd_id,
|
||||||
Native_utcb * const utcb_phys,
|
Native_utcb * const utcb_phys,
|
||||||
Native_utcb * const utcb_virt,
|
Native_utcb * const utcb_virt,
|
||||||
bool const main)
|
bool const main);
|
||||||
{
|
|
||||||
assert(_state == AWAIT_START)
|
|
||||||
|
|
||||||
/* FIXME: support SMP */
|
|
||||||
if (cpu_id) { PERR("multicore processing not supported"); }
|
|
||||||
|
|
||||||
/* store thread parameters */
|
|
||||||
_phys_utcb = utcb_phys;
|
|
||||||
_virt_utcb = utcb_virt;
|
|
||||||
_pd_id = pd_id;
|
|
||||||
|
|
||||||
/* join a protection domain */
|
|
||||||
Pd * const pd = Pd::pool()->object(_pd_id);
|
|
||||||
assert(pd);
|
|
||||||
addr_t const tlb = pd->tlb()->base();
|
|
||||||
|
|
||||||
/* initialize CPU context */
|
|
||||||
User_context * const c = static_cast<User_context *>(this);
|
|
||||||
bool const core = (_pd_id == core_id());
|
|
||||||
if (!main) { c->init_thread(ip, sp, tlb, pd_id); }
|
|
||||||
else if (!core) { c->init_main_thread(ip, utcb_virt, tlb, pd_id); }
|
|
||||||
else { c->init_core_main_thread(ip, sp, tlb, pd_id); }
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Start this thread
|
* Start this thread
|
||||||
|
|
|
@ -47,6 +47,7 @@ SRC_CC += console.cc \
|
||||||
trace_session_component.cc \
|
trace_session_component.cc \
|
||||||
thread.cc \
|
thread.cc \
|
||||||
kernel.cc \
|
kernel.cc \
|
||||||
|
kernel/thread.cc \
|
||||||
kernel/signal_receiver.cc \
|
kernel/signal_receiver.cc \
|
||||||
rm_session_support.cc \
|
rm_session_support.cc \
|
||||||
kernel_support.cc \
|
kernel_support.cc \
|
||||||
|
|
Loading…
Reference in New Issue
Block a user