2013-10-07 15:37:58 +02:00
|
|
|
/*
|
|
|
|
* \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.
|
|
|
|
*/
|
|
|
|
|
2013-10-16 13:10:54 +02:00
|
|
|
/* Genode includes */
|
|
|
|
#include <base/thread_state.h>
|
|
|
|
|
2013-11-14 12:07:07 +01:00
|
|
|
/* base-hw includes */
|
|
|
|
#include <placement_new.h>
|
|
|
|
|
2013-10-07 15:37:58 +02:00
|
|
|
/* core includes */
|
2013-10-16 13:10:54 +02:00
|
|
|
#include <kernel/kernel.h>
|
2013-10-07 15:37:58 +02:00
|
|
|
#include <kernel/thread.h>
|
2013-10-16 13:10:54 +02:00
|
|
|
#include <kernel/vm.h>
|
2013-12-17 18:10:02 +01:00
|
|
|
#include <kernel/irq.h>
|
2013-10-07 15:37:58 +02:00
|
|
|
#include <platform_pd.h>
|
2013-12-17 18:10:02 +01:00
|
|
|
#include <pic.h>
|
2013-10-07 15:37:58 +02:00
|
|
|
|
|
|
|
using namespace Kernel;
|
|
|
|
|
2013-10-16 20:53:59 +02:00
|
|
|
typedef Genode::Thread_state Thread_state;
|
|
|
|
|
2013-11-14 15:14:41 +01:00
|
|
|
unsigned Thread::pd_id() const { return _pd ? _pd->id() : 0; }
|
2013-10-16 20:53:59 +02:00
|
|
|
|
2013-11-14 15:14:41 +01:00
|
|
|
bool Thread::_core() const { return pd_id() == core_id(); }
|
2013-10-16 20:53:59 +02:00
|
|
|
|
2013-12-17 18:10:02 +01:00
|
|
|
namespace Kernel { void reset_lap_time(unsigned const processor_id); }
|
2013-10-16 20:53:59 +02:00
|
|
|
|
|
|
|
void Thread::_signal_context_kill_pending()
|
|
|
|
{
|
|
|
|
assert(_state == SCHEDULED);
|
2013-12-17 18:10:02 +01:00
|
|
|
_unschedule(AWAITS_SIGNAL_CONTEXT_KILL);
|
2013-10-16 20:53:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Thread::_signal_context_kill_done()
|
|
|
|
{
|
|
|
|
assert(_state == AWAITS_SIGNAL_CONTEXT_KILL);
|
|
|
|
user_arg_0(0);
|
|
|
|
_schedule();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-12-06 00:12:43 +01:00
|
|
|
void Thread::_signal_context_kill_failed()
|
|
|
|
{
|
|
|
|
assert(_state == AWAITS_SIGNAL_CONTEXT_KILL);
|
|
|
|
user_arg_0(-1);
|
|
|
|
_schedule();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-16 20:53:59 +02:00
|
|
|
void Thread::_await_signal(Signal_receiver * const receiver)
|
|
|
|
{
|
2013-12-17 18:10:02 +01:00
|
|
|
_unschedule(AWAITS_SIGNAL);
|
2013-10-16 20:53:59 +02:00
|
|
|
_signal_receiver = receiver;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Thread::_receive_signal(void * const base, size_t const size)
|
|
|
|
{
|
2013-11-18 12:47:14 +01:00
|
|
|
assert(_state == AWAITS_SIGNAL && size <= _utcb_phys->size());
|
|
|
|
Genode::memcpy(_utcb_phys->base(), base, size);
|
2013-10-16 20:53:59 +02:00
|
|
|
_schedule();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Thread::_received_ipc_request(size_t const s)
|
|
|
|
{
|
|
|
|
switch (_state) {
|
|
|
|
case SCHEDULED:
|
2013-11-21 12:04:21 +01:00
|
|
|
user_arg_0(0);
|
2013-10-16 20:53:59 +02:00
|
|
|
return;
|
|
|
|
default:
|
|
|
|
PERR("wrong thread state to receive IPC");
|
|
|
|
_stop();
|
|
|
|
return;
|
2013-10-07 15:37:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-16 20:53:59 +02:00
|
|
|
void Thread::_await_ipc()
|
|
|
|
{
|
|
|
|
switch (_state) {
|
|
|
|
case SCHEDULED:
|
2013-12-17 18:10:02 +01:00
|
|
|
_unschedule(AWAITS_IPC);
|
2013-10-16 20:53:59 +02:00
|
|
|
return;
|
|
|
|
default:
|
|
|
|
PERR("wrong thread state to await IPC");
|
|
|
|
_stop();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-17 13:51:17 +02:00
|
|
|
void Thread::_await_ipc_succeeded(size_t const s)
|
2013-10-16 20:53:59 +02:00
|
|
|
{
|
|
|
|
switch (_state) {
|
|
|
|
case AWAITS_IPC:
|
2013-11-21 12:04:21 +01:00
|
|
|
user_arg_0(0);
|
2013-10-17 13:51:17 +02:00
|
|
|
_schedule();
|
2013-10-16 20:53:59 +02:00
|
|
|
return;
|
|
|
|
default:
|
|
|
|
PERR("wrong thread state to receive IPC");
|
|
|
|
_stop();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-17 13:51:17 +02:00
|
|
|
void Thread::_await_ipc_failed()
|
2013-10-16 20:53:59 +02:00
|
|
|
{
|
|
|
|
switch (_state) {
|
|
|
|
case AWAITS_IPC:
|
2013-11-21 12:04:21 +01:00
|
|
|
user_arg_0(-1);
|
2013-10-17 13:51:17 +02:00
|
|
|
_schedule();
|
2013-10-16 20:53:59 +02:00
|
|
|
return;
|
|
|
|
default:
|
|
|
|
PERR("wrong thread state to cancel IPC");
|
|
|
|
_stop();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int Thread::_resume()
|
|
|
|
{
|
|
|
|
switch (_state) {
|
|
|
|
case AWAITS_RESUME:
|
|
|
|
_schedule();
|
|
|
|
return 0;
|
|
|
|
case SCHEDULED:
|
|
|
|
return 1;
|
|
|
|
case AWAITS_IPC:
|
|
|
|
Ipc_node::cancel_waiting();
|
|
|
|
return 0;
|
|
|
|
case AWAITS_SIGNAL:
|
|
|
|
Signal_handler::cancel_waiting();
|
|
|
|
return 0;
|
|
|
|
case AWAITS_SIGNAL_CONTEXT_KILL:
|
|
|
|
Signal_context_killer::cancel_waiting();
|
|
|
|
return 0;
|
|
|
|
case AWAITS_START:
|
|
|
|
case STOPPED:;
|
|
|
|
}
|
|
|
|
PERR("failed to resume thread");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Thread::_pause()
|
2013-10-07 15:37:58 +02:00
|
|
|
{
|
2013-10-16 20:53:59 +02:00
|
|
|
assert(_state == AWAITS_RESUME || _state == SCHEDULED);
|
2013-12-17 18:10:02 +01:00
|
|
|
_unschedule(AWAITS_RESUME);
|
2013-10-16 20:53:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Thread::_schedule()
|
|
|
|
{
|
2013-12-17 18:10:02 +01:00
|
|
|
if (_state == SCHEDULED) { return; }
|
2014-02-28 15:43:59 +01:00
|
|
|
Execution_context::_schedule();
|
2013-10-16 20:53:59 +02:00
|
|
|
_state = SCHEDULED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-12-17 18:10:02 +01:00
|
|
|
void Thread::_unschedule(State const s)
|
|
|
|
{
|
2014-02-28 15:43:59 +01:00
|
|
|
if (_state == SCHEDULED) { Execution_context::_unschedule(); }
|
2013-12-17 18:10:02 +01:00
|
|
|
_state = s;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-18 15:31:54 +01:00
|
|
|
Thread::Thread(unsigned const priority, char const * const label)
|
2013-10-16 20:53:59 +02:00
|
|
|
:
|
2014-02-28 15:43:59 +01:00
|
|
|
Execution_context(0, priority),
|
2013-11-14 15:14:41 +01:00
|
|
|
Thread_cpu_support(this),
|
|
|
|
_state(AWAITS_START),
|
|
|
|
_pd(0),
|
2013-11-18 12:47:14 +01:00
|
|
|
_utcb_phys(0),
|
2013-11-18 15:31:54 +01:00
|
|
|
_signal_receiver(0),
|
|
|
|
_label(label)
|
2013-12-18 16:18:16 +01:00
|
|
|
{
|
|
|
|
cpu_exception = RESET;
|
|
|
|
}
|
2013-10-07 15:37:58 +02:00
|
|
|
|
2013-12-17 18:10:02 +01:00
|
|
|
Thread::~Thread() { if (Execution_context::list()) { _unschedule(STOPPED); } }
|
|
|
|
|
2013-10-07 15:37:58 +02:00
|
|
|
|
|
|
|
void
|
2013-12-17 18:10:02 +01:00
|
|
|
Thread::init(Processor * const processor, unsigned const pd_id_arg,
|
2013-11-18 12:47:14 +01:00
|
|
|
Native_utcb * const utcb_phys, bool const start)
|
2013-10-07 15:37:58 +02:00
|
|
|
{
|
2013-10-16 13:10:54 +02:00
|
|
|
assert(_state == AWAITS_START)
|
2013-10-07 15:37:58 +02:00
|
|
|
|
|
|
|
/* store thread parameters */
|
2014-02-28 15:43:59 +01:00
|
|
|
Execution_context::_processor(processor);
|
2013-11-18 12:47:14 +01:00
|
|
|
_utcb_phys = utcb_phys;
|
2013-10-07 15:37:58 +02:00
|
|
|
|
2013-10-16 20:53:59 +02:00
|
|
|
/* join protection domain */
|
2013-11-14 15:14:41 +01:00
|
|
|
_pd = Pd::pool()->object(pd_id_arg);
|
|
|
|
assert(_pd);
|
|
|
|
addr_t const tlb = _pd->tlb()->base();
|
2013-11-18 12:47:14 +01:00
|
|
|
User_context::init_thread(tlb, pd_id());
|
2013-10-07 15:37:58 +02:00
|
|
|
|
|
|
|
/* print log message */
|
|
|
|
if (START_VERBOSE) {
|
|
|
|
PINF("in program %u '%s' start thread %u '%s'",
|
2013-11-14 15:14:41 +01:00
|
|
|
pd_id(), pd_label(), id(), label());
|
2013-10-07 15:37:58 +02:00
|
|
|
}
|
2013-10-16 20:53:59 +02:00
|
|
|
/* start execution */
|
|
|
|
if (start) { _schedule(); }
|
2013-10-07 15:37:58 +02:00
|
|
|
}
|
2013-11-11 16:55:30 +01:00
|
|
|
|
|
|
|
|
2013-12-17 18:10:02 +01:00
|
|
|
void Thread::_stop() { _unschedule(STOPPED); }
|
2013-10-16 20:53:59 +02:00
|
|
|
|
|
|
|
|
2014-02-28 15:49:24 +01:00
|
|
|
void Thread::exception(unsigned const processor_id)
|
2013-10-16 20:53:59 +02:00
|
|
|
{
|
|
|
|
switch (cpu_exception) {
|
|
|
|
case SUPERVISOR_CALL:
|
2013-12-17 18:10:02 +01:00
|
|
|
_call(processor_id);
|
2013-10-16 20:53:59 +02:00
|
|
|
return;
|
|
|
|
case PREFETCH_ABORT:
|
|
|
|
_mmu_exception();
|
|
|
|
return;
|
|
|
|
case DATA_ABORT:
|
|
|
|
_mmu_exception();
|
|
|
|
return;
|
|
|
|
case INTERRUPT_REQUEST:
|
2014-02-28 14:46:21 +01:00
|
|
|
_interrupt(processor_id);
|
2013-10-16 20:53:59 +02:00
|
|
|
return;
|
|
|
|
case FAST_INTERRUPT_REQUEST:
|
2014-02-28 14:46:21 +01:00
|
|
|
_interrupt(processor_id);
|
2013-10-16 20:53:59 +02:00
|
|
|
return;
|
2013-12-18 16:18:16 +01:00
|
|
|
case RESET:
|
|
|
|
return;
|
2013-10-16 20:53:59 +02:00
|
|
|
default:
|
|
|
|
PERR("unknown exception");
|
|
|
|
_stop();
|
2013-12-17 18:10:02 +01:00
|
|
|
reset_lap_time(processor_id);
|
2013-10-16 20:53:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Thread::_receive_yielded_cpu()
|
|
|
|
{
|
|
|
|
if (_state == AWAITS_RESUME) { _schedule(); }
|
|
|
|
else { PERR("failed to receive yielded CPU"); }
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-12-17 18:10:02 +01:00
|
|
|
void Thread::proceed(unsigned const processor_id)
|
2013-10-16 20:53:59 +02:00
|
|
|
{
|
2013-12-17 18:10:02 +01:00
|
|
|
mtc()->continue_user(this, processor_id);
|
2013-10-16 20:53:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
char const * Kernel::Thread::pd_label() const
|
|
|
|
{
|
|
|
|
if (_core()) { return "core"; }
|
2013-11-14 15:14:41 +01:00
|
|
|
if (!_pd) { return "?"; }
|
|
|
|
return _pd->platform_pd()->label();
|
2013-10-16 13:10:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-14 15:14:41 +01:00
|
|
|
void Thread::_call_new_pd()
|
2013-10-16 13:10:54 +02:00
|
|
|
{
|
|
|
|
/* check permissions */
|
2013-10-16 20:53:59 +02:00
|
|
|
if (!_core()) {
|
2013-10-16 13:10:54 +02:00
|
|
|
PERR("not entitled to create protection domain");
|
|
|
|
user_arg_0(0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* create translation lookaside buffer and protection domain */
|
|
|
|
void * p = (void *)user_arg_1();
|
|
|
|
Tlb * const tlb = new (p) Tlb();
|
|
|
|
p = (void *)((addr_t)p + sizeof(Tlb));
|
|
|
|
Pd * const pd = new (p) Pd(tlb, (Platform_pd *)user_arg_2());
|
|
|
|
user_arg_0(pd->id());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-12-05 16:12:48 +01:00
|
|
|
void Thread::_call_bin_pd()
|
2013-10-16 13:10:54 +02:00
|
|
|
{
|
|
|
|
/* check permissions */
|
2013-10-16 20:53:59 +02:00
|
|
|
if (!_core()) {
|
2013-10-16 13:10:54 +02:00
|
|
|
PERR("not entitled to destruct protection domain");
|
|
|
|
user_arg_0(-1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* lookup protection domain */
|
|
|
|
unsigned id = user_arg_1();
|
|
|
|
Pd * const pd = Pd::pool()->object(id);
|
|
|
|
if (!pd) {
|
|
|
|
PERR("unknown protection domain");
|
|
|
|
user_arg_0(-1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* destruct translation lookaside buffer and protection domain */
|
|
|
|
Tlb * const tlb = pd->tlb();
|
|
|
|
pd->~Pd();
|
|
|
|
tlb->~Tlb();
|
|
|
|
|
|
|
|
/* clean up buffers of memory management */
|
2014-03-03 00:12:53 +01:00
|
|
|
Processor::flush_tlb_by_pid(pd->id());
|
2013-10-16 13:10:54 +02:00
|
|
|
user_arg_0(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-14 15:14:41 +01:00
|
|
|
void Thread::_call_new_thread()
|
2013-10-16 13:10:54 +02:00
|
|
|
{
|
|
|
|
/* check permissions */
|
2013-11-18 15:31:54 +01:00
|
|
|
if (!_core()) {
|
|
|
|
PERR("not entitled to create thread");
|
|
|
|
user_arg_0(0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* create new thread */
|
|
|
|
void * const p = (void *)user_arg_1();
|
|
|
|
unsigned const priority = user_arg_2();
|
|
|
|
char const * const label = (char *)user_arg_3();
|
|
|
|
Thread * const t = new (p) Thread(priority, label);
|
|
|
|
user_arg_0(t->id());
|
2013-10-16 13:10:54 +02:00
|
|
|
}
|
|
|
|
|
2013-11-14 17:29:34 +01:00
|
|
|
|
2013-12-05 16:12:48 +01:00
|
|
|
void Thread::_call_bin_thread()
|
2013-10-16 13:10:54 +02:00
|
|
|
{
|
|
|
|
/* check permissions */
|
2013-10-16 20:53:59 +02:00
|
|
|
assert(_core());
|
2013-10-16 13:10:54 +02:00
|
|
|
|
|
|
|
/* get targeted thread */
|
|
|
|
unsigned thread_id = (unsigned)user_arg_1();
|
|
|
|
Thread * const thread = Thread::pool()->object(thread_id);
|
|
|
|
assert(thread);
|
|
|
|
|
|
|
|
/* destroy thread */
|
|
|
|
thread->~Thread();
|
|
|
|
}
|
|
|
|
|
2013-11-14 17:29:34 +01:00
|
|
|
|
2013-11-14 15:14:41 +01:00
|
|
|
void Thread::_call_start_thread()
|
2013-10-16 13:10:54 +02:00
|
|
|
{
|
|
|
|
/* check permissions */
|
2013-11-18 12:47:14 +01:00
|
|
|
if (!_core()) {
|
|
|
|
PERR("not entitled to start thread");
|
|
|
|
user_arg_0(0);
|
|
|
|
return;
|
|
|
|
}
|
2013-10-16 13:10:54 +02:00
|
|
|
/* dispatch arguments */
|
2013-11-18 12:47:14 +01:00
|
|
|
unsigned const thread_id = user_arg_1();
|
|
|
|
unsigned const cpu_id = user_arg_2();
|
|
|
|
unsigned const pd_id = user_arg_3();
|
|
|
|
Native_utcb * const utcb = (Native_utcb *)user_arg_4();
|
2013-10-16 13:10:54 +02:00
|
|
|
|
2013-11-18 12:47:14 +01:00
|
|
|
/* lookup targeted thread */
|
|
|
|
Thread * const t = Thread::pool()->object(thread_id);
|
|
|
|
if (!t) {
|
|
|
|
PERR("unknown thread");
|
|
|
|
user_arg_0(0);
|
|
|
|
return;
|
|
|
|
}
|
2013-12-17 18:10:02 +01:00
|
|
|
/*
|
|
|
|
* Start thread
|
|
|
|
*
|
|
|
|
* FIXME: The affinity of a thread is ignored by now.
|
|
|
|
* Instead we always assign the primary processor.
|
|
|
|
*/
|
|
|
|
if (cpu_id) { PERR("multiprocessing not supported"); }
|
|
|
|
t->init(multiprocessor()->primary(), pd_id, utcb, 1);
|
2013-11-14 17:29:34 +01:00
|
|
|
user_arg_0((Call_ret)t->_pd->tlb());
|
2013-10-16 13:10:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-14 15:14:41 +01:00
|
|
|
void Thread::_call_pause_thread()
|
2013-10-16 13:10:54 +02:00
|
|
|
{
|
|
|
|
unsigned const tid = user_arg_1();
|
|
|
|
|
|
|
|
/* shortcut for a thread to pause itself */
|
|
|
|
if (!tid) {
|
2013-10-16 20:53:59 +02:00
|
|
|
_pause();
|
2013-10-16 13:10:54 +02:00
|
|
|
user_arg_0(0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get targeted thread and check permissions */
|
|
|
|
Thread * const t = Thread::pool()->object(tid);
|
2013-10-16 20:53:59 +02:00
|
|
|
assert(t && (_core() || this == t));
|
2013-10-16 13:10:54 +02:00
|
|
|
|
|
|
|
/* pause targeted thread */
|
2013-10-16 20:53:59 +02:00
|
|
|
t->_pause();
|
2013-10-16 13:10:54 +02:00
|
|
|
user_arg_0(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-14 15:14:41 +01:00
|
|
|
void Thread::_call_resume_thread()
|
2013-10-16 13:10:54 +02:00
|
|
|
{
|
|
|
|
/* lookup thread */
|
|
|
|
Thread * const t = Thread::pool()->object(user_arg_1());
|
|
|
|
if (!t) {
|
|
|
|
PERR("unknown thread");
|
|
|
|
user_arg_0(-1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* check permissions */
|
2013-10-16 20:53:59 +02:00
|
|
|
if (!_core() && pd_id() != t->pd_id()) {
|
2013-10-16 13:10:54 +02:00
|
|
|
PERR("not entitled to resume thread");
|
|
|
|
user_arg_0(-1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* resume targeted thread */
|
2013-10-16 20:53:59 +02:00
|
|
|
user_arg_0(t->_resume());
|
2013-10-16 13:10:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-14 15:14:41 +01:00
|
|
|
void Thread_event::_signal_acknowledged()
|
2013-10-16 13:10:54 +02:00
|
|
|
{
|
2014-03-03 00:12:53 +01:00
|
|
|
Processor::tlb_insertions();
|
2013-11-14 15:14:41 +01:00
|
|
|
_thread->_resume();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Thread_event::Thread_event(Thread * const t)
|
|
|
|
:
|
|
|
|
_thread(t), _signal_context(0)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
|
|
void Thread_event::submit()
|
|
|
|
{
|
|
|
|
if (_signal_context && !_signal_context->submit(1)) { return; }
|
|
|
|
PERR("failed to communicate thread event");
|
2013-10-16 13:10:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-14 15:14:41 +01:00
|
|
|
void Thread::_call_yield_thread()
|
2013-10-16 13:10:54 +02:00
|
|
|
{
|
|
|
|
Thread * const t = Thread::pool()->object(user_arg_1());
|
2013-10-16 20:53:59 +02:00
|
|
|
if (t) { t->_receive_yielded_cpu(); }
|
2014-02-28 15:43:59 +01:00
|
|
|
Execution_context::_yield();
|
2013-10-16 13:10:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-21 11:35:33 +01:00
|
|
|
void Thread::_call_await_request_msg()
|
2013-10-16 13:10:54 +02:00
|
|
|
{
|
2013-10-18 17:01:51 +02:00
|
|
|
void * buf_base;
|
|
|
|
size_t buf_size;
|
2013-11-21 17:26:44 +01:00
|
|
|
_utcb_phys->message()->info_about_await_request(buf_base, buf_size);
|
2013-10-17 13:51:17 +02:00
|
|
|
Ipc_node::await_request(buf_base, buf_size);
|
2013-10-16 13:10:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-21 11:35:33 +01:00
|
|
|
void Thread::_call_send_request_msg()
|
2013-10-16 13:10:54 +02:00
|
|
|
{
|
2013-10-17 00:41:14 +02:00
|
|
|
Thread * const dst = Thread::pool()->object(user_arg_1());
|
|
|
|
if (!dst) {
|
2013-11-18 16:34:59 +01:00
|
|
|
PERR("unknown recipient");
|
2013-10-17 00:41:14 +02:00
|
|
|
_await_ipc();
|
|
|
|
return;
|
|
|
|
}
|
2013-10-18 17:01:51 +02:00
|
|
|
void * msg_base;
|
|
|
|
size_t msg_size;
|
|
|
|
void * buf_base;
|
|
|
|
size_t buf_size;
|
2013-11-21 17:26:44 +01:00
|
|
|
_utcb_phys->message()->info_about_send_request(msg_base, msg_size,
|
|
|
|
buf_base, buf_size);
|
2013-10-18 17:01:51 +02:00
|
|
|
Ipc_node::send_request_await_reply(dst, msg_base, msg_size,
|
|
|
|
buf_base, buf_size);
|
2013-10-16 13:10:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-21 11:35:33 +01:00
|
|
|
void Thread::_call_send_reply_msg()
|
2013-10-16 20:53:59 +02:00
|
|
|
{
|
2013-10-18 17:01:51 +02:00
|
|
|
void * msg_base;
|
|
|
|
size_t msg_size;
|
2013-11-21 17:26:44 +01:00
|
|
|
_utcb_phys->message()->info_about_send_reply(msg_base, msg_size);
|
2013-10-17 13:51:17 +02:00
|
|
|
Ipc_node::send_reply(msg_base, msg_size);
|
2013-11-21 11:35:33 +01:00
|
|
|
bool const await_request_msg = user_arg_1();
|
|
|
|
if (await_request_msg) { _call_await_request_msg(); }
|
2013-11-21 12:04:21 +01:00
|
|
|
else { user_arg_0(0); }
|
2013-11-14 15:14:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Thread::_call_route_thread_event()
|
|
|
|
{
|
|
|
|
/* check permissions */
|
|
|
|
if (!_core()) {
|
|
|
|
PERR("not entitled to route thread event");
|
|
|
|
user_arg_0(-1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* get targeted thread */
|
|
|
|
unsigned const thread_id = user_arg_1();
|
|
|
|
Thread * const t = Thread::pool()->object(thread_id);
|
|
|
|
if (!t) {
|
|
|
|
PERR("unknown thread");
|
|
|
|
user_arg_0(-1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* override event route */
|
|
|
|
unsigned const event_id = user_arg_2();
|
|
|
|
unsigned const signal_context_id = user_arg_3();
|
|
|
|
if (t->_route_event(event_id, signal_context_id)) { user_arg_0(-1); }
|
|
|
|
else { user_arg_0(0); }
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int Thread::_route_event(unsigned const event_id,
|
|
|
|
unsigned const signal_context_id)
|
|
|
|
{
|
|
|
|
/* lookup signal context */
|
|
|
|
Signal_context * c;
|
|
|
|
if (signal_context_id) {
|
|
|
|
c = Signal_context::pool()->object(signal_context_id);
|
|
|
|
if (!c) {
|
|
|
|
PERR("unknown signal context");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
} else { c = 0; }
|
|
|
|
|
|
|
|
/* lookup event and assign signal context */
|
|
|
|
Thread_event Thread::* e = _event(event_id);
|
|
|
|
if (!e) { return -1; }
|
|
|
|
(this->*e).signal_context(c);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Thread_event::signal_context(Signal_context * const c)
|
|
|
|
{
|
|
|
|
_signal_context = c;
|
|
|
|
if (_signal_context) { _signal_context->ack_handler(this); }
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
unsigned Thread_event::signal_context_id() const
|
|
|
|
{
|
|
|
|
if (_signal_context) { return _signal_context->id(); }
|
|
|
|
return 0;
|
2013-10-16 20:53:59 +02:00
|
|
|
}
|
2013-10-16 13:10:54 +02:00
|
|
|
|
|
|
|
|
2013-11-14 15:14:41 +01:00
|
|
|
void Thread::_call_access_thread_regs()
|
2013-10-16 13:10:54 +02:00
|
|
|
{
|
|
|
|
/* check permissions */
|
2013-10-16 20:53:59 +02:00
|
|
|
if (!_core()) {
|
2013-11-14 15:14:41 +01:00
|
|
|
PERR("not entitled to access thread regs");
|
|
|
|
user_arg_0(-1);
|
2013-10-16 13:10:54 +02:00
|
|
|
return;
|
|
|
|
}
|
2013-11-14 15:14:41 +01:00
|
|
|
/* get targeted thread */
|
|
|
|
unsigned const thread_id = user_arg_1();
|
|
|
|
Thread * const t = Thread::pool()->object(thread_id);
|
|
|
|
if (!t) {
|
|
|
|
PERR("unknown thread");
|
|
|
|
user_arg_0(-1);
|
2013-10-16 13:10:54 +02:00
|
|
|
return;
|
|
|
|
}
|
2013-11-14 15:14:41 +01:00
|
|
|
/* execute read operations */
|
|
|
|
unsigned const reads = user_arg_2();
|
|
|
|
unsigned const writes = user_arg_3();
|
2013-11-18 12:47:14 +01:00
|
|
|
addr_t * const utcb = (addr_t *)_utcb_phys->base();
|
2013-11-14 15:14:41 +01:00
|
|
|
addr_t * const read_ids = &utcb[0];
|
|
|
|
addr_t * const read_values = (addr_t *)user_arg_4();
|
|
|
|
for (unsigned i = 0; i < reads; i++) {
|
|
|
|
if (t->_read_reg(read_ids[i], read_values[i])) {
|
|
|
|
user_arg_0(reads + writes - i);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* execute write operations */
|
|
|
|
addr_t * const write_ids = &utcb[reads];
|
|
|
|
addr_t * const write_values = (addr_t *)user_arg_5();
|
|
|
|
for (unsigned i = 0; i < writes; i++) {
|
|
|
|
if (t->_write_reg(write_ids[i], write_values[i])) {
|
|
|
|
user_arg_0(writes - i);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
user_arg_0(0);
|
|
|
|
return;
|
2013-10-16 13:10:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-14 15:14:41 +01:00
|
|
|
void Thread::_call_update_pd()
|
2013-10-16 13:10:54 +02:00
|
|
|
{
|
2013-10-16 20:53:59 +02:00
|
|
|
assert(_core());
|
2014-03-03 00:12:53 +01:00
|
|
|
Processor::flush_tlb_by_pid(user_arg_1());
|
2013-10-16 13:10:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-14 15:14:41 +01:00
|
|
|
void Thread::_call_update_region()
|
2013-11-11 16:55:30 +01:00
|
|
|
{
|
2013-10-16 20:53:59 +02:00
|
|
|
assert(_core());
|
2013-10-16 13:10:54 +02:00
|
|
|
|
|
|
|
/* FIXME we don't handle instruction caches by now */
|
2014-03-03 00:12:53 +01:00
|
|
|
Processor::flush_data_cache_by_virt_region((addr_t)user_arg_1(),
|
|
|
|
(size_t)user_arg_2());
|
2013-10-16 13:10:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-28 00:45:48 +01:00
|
|
|
void Thread::_print_activity_table()
|
|
|
|
{
|
|
|
|
for (unsigned id = 0; id < MAX_THREADS; id++) {
|
|
|
|
Thread * const t = Thread::pool()->object(id);
|
|
|
|
if (!t) { continue; }
|
2013-12-09 16:41:23 +01:00
|
|
|
t->_print_activity(t == this);
|
2013-11-28 00:45:48 +01:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-12-09 16:41:23 +01:00
|
|
|
void Thread::_print_activity(bool const printing_thread)
|
2013-11-28 00:45:48 +01:00
|
|
|
{
|
|
|
|
Genode::printf("\033[33m[%u] %s", pd_id(), pd_label());
|
2013-12-06 19:12:06 +01:00
|
|
|
Genode::printf(" (%u) %s:\033[0m", id(), label());
|
2013-11-28 00:45:48 +01:00
|
|
|
switch (_state) {
|
|
|
|
case AWAITS_START: {
|
|
|
|
Genode::printf("\033[32m init\033[0m");
|
|
|
|
break; }
|
|
|
|
case SCHEDULED: {
|
2013-12-09 16:41:23 +01:00
|
|
|
if (!printing_thread) { Genode::printf("\033[32m run\033[0m"); }
|
|
|
|
else { Genode::printf("\033[32m debug\033[0m"); }
|
2013-11-28 00:45:48 +01:00
|
|
|
break; }
|
|
|
|
case AWAITS_IPC: {
|
|
|
|
_print_activity_when_awaits_ipc();
|
|
|
|
break; }
|
|
|
|
case AWAITS_RESUME: {
|
2013-12-06 19:12:06 +01:00
|
|
|
Genode::printf("\033[32m await RES\033[0m");
|
2013-11-28 00:45:48 +01:00
|
|
|
break; }
|
|
|
|
case AWAITS_SIGNAL: {
|
|
|
|
unsigned const receiver_id = Signal_handler::receiver()->id();
|
|
|
|
Genode::printf("\033[32m await SIG %u\033[0m", receiver_id);
|
|
|
|
break; }
|
|
|
|
case AWAITS_SIGNAL_CONTEXT_KILL: {
|
2013-12-06 12:04:48 +01:00
|
|
|
unsigned const context_id = Signal_context_killer::context()->id();
|
2013-11-28 00:45:48 +01:00
|
|
|
Genode::printf("\033[32m await SCK %u\033[0m", context_id);
|
|
|
|
break; }
|
|
|
|
case STOPPED: {
|
|
|
|
Genode::printf("\033[32m stop\033[0m");
|
|
|
|
break; }
|
|
|
|
}
|
|
|
|
_print_common_activity();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Thread::_print_common_activity()
|
|
|
|
{
|
|
|
|
Genode::printf(" ip %lx sp %lx\n", ip, sp);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Thread::_print_activity_when_awaits_ipc()
|
|
|
|
{
|
|
|
|
switch (Ipc_node::state()) {
|
|
|
|
case AWAIT_REPLY: {
|
|
|
|
Thread * const server = dynamic_cast<Thread *>(Ipc_node::outbuf_dst());
|
|
|
|
Genode::printf("\033[32m await RPL %u\033[0m", server->id());
|
|
|
|
break; }
|
|
|
|
case AWAIT_REQUEST: {
|
|
|
|
Genode::printf("\033[32m await REQ\033[0m");
|
|
|
|
break; }
|
|
|
|
case PREPARE_AND_AWAIT_REPLY: {
|
|
|
|
Thread * const server = dynamic_cast<Thread *>(Ipc_node::outbuf_dst());
|
|
|
|
Genode::printf("\033[32m prep RPL await RPL %u\033[0m", server->id());
|
|
|
|
break; }
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-14 15:14:41 +01:00
|
|
|
void Thread::_call_print_char()
|
2013-10-16 13:10:54 +02:00
|
|
|
{
|
2013-11-28 00:45:48 +01:00
|
|
|
char const c = user_arg_1();
|
|
|
|
if (!c) { _print_activity_table(); }
|
2013-10-16 13:10:54 +02:00
|
|
|
Genode::printf("%c", (char)user_arg_1());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-14 15:14:41 +01:00
|
|
|
void Thread::_call_new_signal_receiver()
|
2013-10-16 13:10:54 +02:00
|
|
|
{
|
|
|
|
/* check permissions */
|
2013-10-16 20:53:59 +02:00
|
|
|
if (!_core()) {
|
2013-10-16 13:10:54 +02:00
|
|
|
PERR("not entitled to create signal receiver");
|
|
|
|
user_arg_0(0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* create receiver */
|
2013-10-30 13:56:57 +01:00
|
|
|
void * const p = (void *)user_arg_1();
|
2013-10-16 13:10:54 +02:00
|
|
|
Signal_receiver * const r = new (p) Signal_receiver();
|
|
|
|
user_arg_0(r->id());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-14 15:14:41 +01:00
|
|
|
void Thread::_call_new_signal_context()
|
2013-10-16 13:10:54 +02:00
|
|
|
{
|
|
|
|
/* check permissions */
|
2013-10-16 20:53:59 +02:00
|
|
|
if (!_core()) {
|
2013-10-16 13:10:54 +02:00
|
|
|
PERR("not entitled to create signal context");
|
|
|
|
user_arg_0(0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* lookup receiver */
|
2013-10-30 13:56:57 +01:00
|
|
|
unsigned const id = user_arg_2();
|
2013-10-16 13:10:54 +02:00
|
|
|
Signal_receiver * const r = Signal_receiver::pool()->object(id);
|
|
|
|
if (!r) {
|
|
|
|
PERR("unknown signal receiver");
|
|
|
|
user_arg_0(0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* create and assign context*/
|
2013-10-30 13:56:57 +01:00
|
|
|
void * const p = (void *)user_arg_1();
|
|
|
|
unsigned const imprint = user_arg_3();
|
2013-12-06 11:53:08 +01:00
|
|
|
Signal_context * const c = new (p) Signal_context(r, imprint);
|
|
|
|
user_arg_0(c->id());
|
2013-10-16 13:10:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-14 15:14:41 +01:00
|
|
|
void Thread::_call_await_signal()
|
2013-10-16 13:10:54 +02:00
|
|
|
{
|
2013-10-30 13:56:57 +01:00
|
|
|
/* check wether to acknowledge a context */
|
|
|
|
unsigned const context_id = user_arg_2();
|
|
|
|
if (context_id) {
|
|
|
|
Signal_context * const c = Signal_context::pool()->object(context_id);
|
|
|
|
if (c) { c->ack(); }
|
|
|
|
else { PERR("failed to acknowledge signal context"); }
|
|
|
|
}
|
2013-10-16 13:10:54 +02:00
|
|
|
/* lookup receiver */
|
2013-10-30 13:56:57 +01:00
|
|
|
unsigned const receiver_id = user_arg_1();
|
|
|
|
Signal_receiver * const r = Signal_receiver::pool()->object(receiver_id);
|
2013-10-16 13:10:54 +02:00
|
|
|
if (!r) {
|
|
|
|
PERR("unknown signal receiver");
|
|
|
|
user_arg_0(-1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* register handler at the receiver */
|
|
|
|
if (r->add_handler(this)) {
|
|
|
|
PERR("failed to register handler at signal receiver");
|
|
|
|
user_arg_0(-1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
user_arg_0(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-14 15:14:41 +01:00
|
|
|
void Thread::_call_signal_pending()
|
2013-10-16 13:10:54 +02:00
|
|
|
{
|
|
|
|
/* lookup signal receiver */
|
2013-10-30 13:56:57 +01:00
|
|
|
unsigned const id = user_arg_1();
|
2013-10-16 13:10:54 +02:00
|
|
|
Signal_receiver * const r = Signal_receiver::pool()->object(id);
|
|
|
|
if (!r) {
|
|
|
|
PERR("unknown signal receiver");
|
|
|
|
user_arg_0(0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* get pending state */
|
|
|
|
user_arg_0(r->deliverable());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-14 15:14:41 +01:00
|
|
|
void Thread::_call_submit_signal()
|
2013-10-16 13:10:54 +02:00
|
|
|
{
|
|
|
|
/* lookup signal context */
|
|
|
|
unsigned const id = user_arg_1();
|
|
|
|
Signal_context * const c = Signal_context::pool()->object(id);
|
|
|
|
if(!c) {
|
|
|
|
PERR("unknown signal context");
|
|
|
|
user_arg_0(-1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* trigger signal context */
|
|
|
|
if (c->submit(user_arg_2())) {
|
|
|
|
PERR("failed to submit signal context");
|
|
|
|
user_arg_0(-1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
user_arg_0(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-14 15:14:41 +01:00
|
|
|
void Thread::_call_ack_signal()
|
2013-10-16 13:10:54 +02:00
|
|
|
{
|
|
|
|
/* lookup signal context */
|
2013-10-30 13:56:57 +01:00
|
|
|
unsigned const id = user_arg_1();
|
2013-10-16 13:10:54 +02:00
|
|
|
Signal_context * const c = Signal_context::pool()->object(id);
|
|
|
|
if (!c) {
|
|
|
|
PERR("unknown signal context");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* acknowledge */
|
|
|
|
c->ack();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-12-06 00:12:43 +01:00
|
|
|
void Thread::_call_kill_signal_context()
|
|
|
|
{
|
|
|
|
/* lookup signal context */
|
|
|
|
unsigned const id = user_arg_1();
|
|
|
|
Signal_context * const c = Signal_context::pool()->object(id);
|
|
|
|
if (!c) {
|
|
|
|
PERR("unknown signal context");
|
|
|
|
user_arg_0(-1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* kill signal context */
|
|
|
|
if (c->kill(this)) {
|
|
|
|
PERR("failed to kill signal context");
|
|
|
|
user_arg_0(-1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-12-05 16:12:48 +01:00
|
|
|
void Thread::_call_bin_signal_context()
|
2013-10-16 13:10:54 +02:00
|
|
|
{
|
|
|
|
/* check permissions */
|
2013-10-16 20:53:59 +02:00
|
|
|
if (!_core()) {
|
2013-10-16 13:10:54 +02:00
|
|
|
PERR("not entitled to kill signal context");
|
|
|
|
user_arg_0(-1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* lookup signal context */
|
2013-10-30 13:56:57 +01:00
|
|
|
unsigned const id = user_arg_1();
|
2013-10-16 13:10:54 +02:00
|
|
|
Signal_context * const c = Signal_context::pool()->object(id);
|
|
|
|
if (!c) {
|
|
|
|
PERR("unknown signal context");
|
|
|
|
user_arg_0(0);
|
|
|
|
return;
|
|
|
|
}
|
2013-12-06 00:12:43 +01:00
|
|
|
/* destruct signal context */
|
|
|
|
c->~Signal_context();
|
2013-10-16 13:10:54 +02:00
|
|
|
user_arg_0(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-12-05 16:12:48 +01:00
|
|
|
void Thread::_call_bin_signal_receiver()
|
2013-10-16 13:10:54 +02:00
|
|
|
{
|
|
|
|
/* check permissions */
|
2013-10-16 20:53:59 +02:00
|
|
|
if (!_core()) {
|
2013-10-16 13:10:54 +02:00
|
|
|
PERR("not entitled to kill signal receiver");
|
|
|
|
user_arg_0(-1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* lookup signal receiver */
|
2013-10-30 13:56:57 +01:00
|
|
|
unsigned const id = user_arg_1();
|
2013-10-16 13:10:54 +02:00
|
|
|
Signal_receiver * const r = Signal_receiver::pool()->object(id);
|
|
|
|
if (!r) {
|
|
|
|
PERR("unknown signal receiver");
|
|
|
|
user_arg_0(0);
|
|
|
|
return;
|
|
|
|
}
|
2013-12-06 11:53:08 +01:00
|
|
|
r->~Signal_receiver();
|
2013-10-16 13:10:54 +02:00
|
|
|
user_arg_0(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-14 15:14:41 +01:00
|
|
|
void Thread::_call_new_vm()
|
2013-10-16 13:10:54 +02:00
|
|
|
{
|
|
|
|
/* check permissions */
|
2013-10-16 20:53:59 +02:00
|
|
|
assert(_core());
|
2013-10-16 13:10:54 +02:00
|
|
|
|
|
|
|
/* dispatch arguments */
|
|
|
|
void * const allocator = (void * const)user_arg_1();
|
|
|
|
Genode::Cpu_state_modes * const state =
|
|
|
|
(Genode::Cpu_state_modes * const)user_arg_2();
|
|
|
|
Signal_context * const context =
|
|
|
|
Signal_context::pool()->object(user_arg_3());
|
|
|
|
assert(context);
|
|
|
|
|
|
|
|
/* create vm */
|
|
|
|
Vm * const vm = new (allocator) Vm(state, context);
|
|
|
|
|
|
|
|
/* return vm id */
|
2013-11-14 17:29:34 +01:00
|
|
|
user_arg_0((Call_ret)vm->id());
|
2013-10-16 13:10:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-14 15:14:41 +01:00
|
|
|
void Thread::_call_run_vm()
|
2013-10-16 13:10:54 +02:00
|
|
|
{
|
|
|
|
/* check permissions */
|
2013-10-16 20:53:59 +02:00
|
|
|
assert(_core());
|
2013-10-16 13:10:54 +02:00
|
|
|
|
|
|
|
/* get targeted vm via its id */
|
|
|
|
Vm * const vm = Vm::pool()->object(user_arg_1());
|
|
|
|
assert(vm);
|
|
|
|
|
|
|
|
/* run targeted vm */
|
|
|
|
vm->run();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-14 15:14:41 +01:00
|
|
|
void Thread::_call_pause_vm()
|
2013-10-16 13:10:54 +02:00
|
|
|
{
|
|
|
|
/* check permissions */
|
2013-10-16 20:53:59 +02:00
|
|
|
assert(_core());
|
2013-10-16 13:10:54 +02:00
|
|
|
|
|
|
|
/* get targeted vm via its id */
|
|
|
|
Vm * const vm = Vm::pool()->object(user_arg_1());
|
|
|
|
assert(vm);
|
|
|
|
|
|
|
|
/* pause targeted vm */
|
|
|
|
vm->pause();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-14 15:14:41 +01:00
|
|
|
int Thread::_read_reg(addr_t const id, addr_t & value) const
|
|
|
|
{
|
|
|
|
addr_t Thread::* const reg = _reg(id);
|
|
|
|
if (reg) {
|
|
|
|
value = this->*reg;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
PERR("unknown thread register");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int Thread::_write_reg(addr_t const id, addr_t const value)
|
|
|
|
{
|
|
|
|
addr_t Thread::* const reg = _reg(id);
|
|
|
|
if (reg) {
|
|
|
|
this->*reg = value;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
PERR("unknown thread register");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-12-17 18:10:02 +01:00
|
|
|
void Thread::_call(unsigned const processor_id)
|
2013-10-16 13:10:54 +02:00
|
|
|
{
|
2013-11-14 15:14:41 +01:00
|
|
|
switch (user_arg_0()) {
|
|
|
|
case Call_id::NEW_THREAD: _call_new_thread(); return;
|
2013-12-05 16:12:48 +01:00
|
|
|
case Call_id::BIN_THREAD: _call_bin_thread(); return;
|
2013-11-14 15:14:41 +01:00
|
|
|
case Call_id::START_THREAD: _call_start_thread(); return;
|
|
|
|
case Call_id::PAUSE_THREAD: _call_pause_thread(); return;
|
|
|
|
case Call_id::RESUME_THREAD: _call_resume_thread(); return;
|
|
|
|
case Call_id::YIELD_THREAD: _call_yield_thread(); return;
|
2013-11-21 11:35:33 +01:00
|
|
|
case Call_id::SEND_REQUEST_MSG: _call_send_request_msg(); return;
|
|
|
|
case Call_id::SEND_REPLY_MSG: _call_send_reply_msg(); return;
|
|
|
|
case Call_id::AWAIT_REQUEST_MSG: _call_await_request_msg(); return;
|
2013-11-14 15:14:41 +01:00
|
|
|
case Call_id::UPDATE_PD: _call_update_pd(); return;
|
|
|
|
case Call_id::UPDATE_REGION: _call_update_region(); return;
|
|
|
|
case Call_id::NEW_PD: _call_new_pd(); return;
|
|
|
|
case Call_id::PRINT_CHAR: _call_print_char(); return;
|
|
|
|
case Call_id::NEW_SIGNAL_RECEIVER: _call_new_signal_receiver(); return;
|
|
|
|
case Call_id::NEW_SIGNAL_CONTEXT: _call_new_signal_context(); return;
|
2013-12-06 00:12:43 +01:00
|
|
|
case Call_id::KILL_SIGNAL_CONTEXT: _call_kill_signal_context(); return;
|
2013-12-05 16:12:48 +01:00
|
|
|
case Call_id::BIN_SIGNAL_CONTEXT: _call_bin_signal_context(); return;
|
|
|
|
case Call_id::BIN_SIGNAL_RECEIVER: _call_bin_signal_receiver(); return;
|
2013-11-14 15:14:41 +01:00
|
|
|
case Call_id::AWAIT_SIGNAL: _call_await_signal(); return;
|
|
|
|
case Call_id::SUBMIT_SIGNAL: _call_submit_signal(); return;
|
|
|
|
case Call_id::SIGNAL_PENDING: _call_signal_pending(); return;
|
|
|
|
case Call_id::ACK_SIGNAL: _call_ack_signal(); return;
|
|
|
|
case Call_id::NEW_VM: _call_new_vm(); return;
|
|
|
|
case Call_id::RUN_VM: _call_run_vm(); return;
|
|
|
|
case Call_id::PAUSE_VM: _call_pause_vm(); return;
|
2013-12-05 16:12:48 +01:00
|
|
|
case Call_id::BIN_PD: _call_bin_pd(); return;
|
2013-11-14 15:14:41 +01:00
|
|
|
case Call_id::ACCESS_THREAD_REGS: _call_access_thread_regs(); return;
|
|
|
|
case Call_id::ROUTE_THREAD_EVENT: _call_route_thread_event(); return;
|
2013-10-16 13:10:54 +02:00
|
|
|
default:
|
2013-11-18 16:34:59 +01:00
|
|
|
PERR("unknown kernel call");
|
2013-10-16 20:53:59 +02:00
|
|
|
_stop();
|
2013-12-17 18:10:02 +01:00
|
|
|
reset_lap_time(processor_id);
|
2013-10-16 13:10:54 +02:00
|
|
|
}
|
2013-11-11 16:55:30 +01:00
|
|
|
}
|