2015-02-09 09:54:08 +01:00
|
|
|
/*
|
|
|
|
* \brief Kernel backend for execution contexts in userland
|
|
|
|
* \author Martin Stein
|
|
|
|
* \author Stefan Kalkowski
|
|
|
|
* \date 2013-11-11
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2017-02-20 13:23:52 +01:00
|
|
|
* Copyright (C) 2013-2017 Genode Labs GmbH
|
2015-02-09 09:54:08 +01:00
|
|
|
*
|
|
|
|
* This file is part of the Genode OS framework, which is distributed
|
2017-02-20 13:23:52 +01:00
|
|
|
* under the terms of the GNU Affero General Public License version 3.
|
2015-02-09 09:54:08 +01:00
|
|
|
*/
|
|
|
|
|
2017-10-05 16:11:24 +02:00
|
|
|
#include <kernel/cpu.h>
|
2015-02-09 09:54:08 +01:00
|
|
|
#include <kernel/kernel.h>
|
2017-10-05 16:11:24 +02:00
|
|
|
#include <kernel/pd.h>
|
|
|
|
#include <kernel/thread.h>
|
2015-02-09 09:54:08 +01:00
|
|
|
|
|
|
|
using namespace Kernel;
|
|
|
|
|
2018-05-14 11:30:24 +02:00
|
|
|
extern "C" void kernel_to_user_context_switch(Cpu::Context*, Cpu::Fpu_context*);
|
|
|
|
|
|
|
|
|
2017-10-06 12:02:36 +02:00
|
|
|
void Thread::exception(Cpu & cpu)
|
2015-02-09 09:54:08 +01:00
|
|
|
{
|
2017-06-30 12:00:27 +02:00
|
|
|
switch (regs->cpu_exception) {
|
|
|
|
case Cpu::Context::SUPERVISOR_CALL:
|
2015-02-09 09:54:08 +01:00
|
|
|
_call();
|
|
|
|
return;
|
2017-06-30 12:00:27 +02:00
|
|
|
case Cpu::Context::PREFETCH_ABORT:
|
|
|
|
case Cpu::Context::DATA_ABORT:
|
2015-02-09 09:54:08 +01:00
|
|
|
_mmu_exception();
|
|
|
|
return;
|
2017-06-30 12:00:27 +02:00
|
|
|
case Cpu::Context::INTERRUPT_REQUEST:
|
|
|
|
case Cpu::Context::FAST_INTERRUPT_REQUEST:
|
2017-10-06 12:02:36 +02:00
|
|
|
_interrupt(cpu.id());
|
2015-02-09 09:54:08 +01:00
|
|
|
return;
|
2017-06-30 12:00:27 +02:00
|
|
|
case Cpu::Context::UNDEFINED_INSTRUCTION:
|
2019-04-05 13:50:34 +02:00
|
|
|
Genode::raw(*this, ": undefined instruction at ip=",
|
|
|
|
Genode::Hex(regs->ip));
|
hw: clean up scheduling-readiness syscalls
This cleans up the syscalls that are mainly used to control the
scheduling readiness of a thread. The different use cases and
requirements were somehow mixed together in the previous interface. The
new syscall set is:
1) pause_thread and resume_thread
They don't affect the state of the thread (IPC, signalling, etc.) but
merely decide wether the thread is allowed for scheduling or not, the
so-called pause state. The pause state is orthogonal to the thread state
and masks it when it comes to scheduling. In contrast to the stopped
state, which is described in "stop_thread and restart_thread", the
thread state and the UTCB content of a thread may change while in the
paused state. However, the register state of a thread doesn't change
while paused. The "pause" and "resume" syscalls are both core-restricted
and may target any thread. They are used as back end for the CPU session
calls "pause" and "resume". The "pause/resume" feature is made for
applications like the GDB monitor that transparently want to stop and
continue the execution of a thread no matter what state the thread is
in.
2) stop_thread and restart_thread
The stop syscall can only be used on a thread in the non-blocking
("active") thread state. The thread then switches to the "stopped"
thread state in wich it explicitely waits for a restart. The restart
syscall can only be used on a thread in the "stopped" or the "active"
thread state. The thread then switches back to the "active" thread state
and the syscall returns whether the thread was stopped. Both syscalls
are not core-restricted. "Stop" always targets the calling thread while
"restart" may target any thread in the same PD as the caller. Thread
state and UTCB content of a thread don't change while in the stopped
state. The "stop/restart" feature is used when an active thread wants to
wait for an event that is not known to the kernel. Actually the syscalls
are used when waiting for locks and on thread exit.
3) cancel_thread_blocking
Does cleanly cancel a cancelable blocking thread state (IPC, signalling,
stopped). The thread whose blocking was cancelled goes back to the
"active" thread state. It may receive a syscall return value that
reflects the cancellation. This syscall doesn't affect the pause state
of the thread which means that it may still not get scheduled. The
syscall is core-restricted and may target any thread.
4) yield_thread
Does its best that a thread is scheduled as few as possible in the
current scheduling super-period without touching the thread or pause
state. In the next superperiod, however, the thread is scheduled
"normal" again. The syscall is not core-restricted and always targets
the caller.
Fixes #2104
2016-09-15 17:23:06 +02:00
|
|
|
_die();
|
2015-02-09 09:54:08 +01:00
|
|
|
return;
|
2017-06-30 12:00:27 +02:00
|
|
|
case Cpu::Context::RESET:
|
2015-02-09 09:54:08 +01:00
|
|
|
return;
|
|
|
|
default:
|
2019-04-05 13:50:34 +02:00
|
|
|
Genode::raw(*this, ": triggered an unknown exception ",
|
|
|
|
regs->cpu_exception);
|
hw: clean up scheduling-readiness syscalls
This cleans up the syscalls that are mainly used to control the
scheduling readiness of a thread. The different use cases and
requirements were somehow mixed together in the previous interface. The
new syscall set is:
1) pause_thread and resume_thread
They don't affect the state of the thread (IPC, signalling, etc.) but
merely decide wether the thread is allowed for scheduling or not, the
so-called pause state. The pause state is orthogonal to the thread state
and masks it when it comes to scheduling. In contrast to the stopped
state, which is described in "stop_thread and restart_thread", the
thread state and the UTCB content of a thread may change while in the
paused state. However, the register state of a thread doesn't change
while paused. The "pause" and "resume" syscalls are both core-restricted
and may target any thread. They are used as back end for the CPU session
calls "pause" and "resume". The "pause/resume" feature is made for
applications like the GDB monitor that transparently want to stop and
continue the execution of a thread no matter what state the thread is
in.
2) stop_thread and restart_thread
The stop syscall can only be used on a thread in the non-blocking
("active") thread state. The thread then switches to the "stopped"
thread state in wich it explicitely waits for a restart. The restart
syscall can only be used on a thread in the "stopped" or the "active"
thread state. The thread then switches back to the "active" thread state
and the syscall returns whether the thread was stopped. Both syscalls
are not core-restricted. "Stop" always targets the calling thread while
"restart" may target any thread in the same PD as the caller. Thread
state and UTCB content of a thread don't change while in the stopped
state. The "stop/restart" feature is used when an active thread wants to
wait for an event that is not known to the kernel. Actually the syscalls
are used when waiting for locks and on thread exit.
3) cancel_thread_blocking
Does cleanly cancel a cancelable blocking thread state (IPC, signalling,
stopped). The thread whose blocking was cancelled goes back to the
"active" thread state. It may receive a syscall return value that
reflects the cancellation. This syscall doesn't affect the pause state
of the thread which means that it may still not get scheduled. The
syscall is core-restricted and may target any thread.
4) yield_thread
Does its best that a thread is scheduled as few as possible in the
current scheduling super-period without touching the thread or pause
state. In the next superperiod, however, the thread is scheduled
"normal" again. The syscall is not core-restricted and always targets
the caller.
Fixes #2104
2016-09-15 17:23:06 +02:00
|
|
|
_die();
|
2015-02-09 09:54:08 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-01-11 11:02:52 +01:00
|
|
|
void Kernel::Thread::_call_update_data_region()
|
2015-03-27 13:55:03 +01:00
|
|
|
{
|
base/core: use references instead of pointers
This patch replaces the former prominent use of pointers by references
wherever feasible. This has the following benefits:
* The contract between caller and callee becomes more obvious. When
passing a reference, the contract says that the argument cannot be
a null pointer. The caller is responsible to ensure that. Therefore,
the use of reference eliminates the need to add defensive null-pointer
checks at the callee site, which sometimes merely exist to be on the
safe side. The bottom line is that the code becomes easier to follow.
* Reference members must be initialized via an object initializer,
which promotes a programming style that avoids intermediate object-
construction states. Within core, there are still a few pointers
as member variables left though. E.g., caused by the late association
of 'Platform_thread' objects with their 'Platform_pd' objects.
* If no pointers are present as member variables, we don't need to
manually provide declarations of a private copy constructor and
an assignment operator to avoid -Weffc++ errors "class ... has
pointer data members [-Werror=effc++]".
This patch also changes a few system bindings on NOVA and Fiasco.OC,
e.g., the return value of the global 'cap_map' accessor has become a
reference. Hence, the patch touches a few places outside of core.
Fixes #3135
2019-01-24 22:00:01 +01:00
|
|
|
Cpu &cpu = cpu_pool().cpu(Cpu::executing_id());
|
2016-01-11 11:02:52 +01:00
|
|
|
|
|
|
|
auto base = (addr_t)user_arg_1();
|
|
|
|
auto const size = (size_t)user_arg_2();
|
2018-11-26 11:18:57 +01:00
|
|
|
cpu.clean_invalidate_data_cache_by_virt_region(base, size);
|
|
|
|
cpu.invalidate_instr_cache();
|
2015-03-27 13:55:03 +01:00
|
|
|
}
|
2016-01-11 11:02:52 +01:00
|
|
|
|
|
|
|
|
|
|
|
void Kernel::Thread::_call_update_instr_region()
|
|
|
|
{
|
base/core: use references instead of pointers
This patch replaces the former prominent use of pointers by references
wherever feasible. This has the following benefits:
* The contract between caller and callee becomes more obvious. When
passing a reference, the contract says that the argument cannot be
a null pointer. The caller is responsible to ensure that. Therefore,
the use of reference eliminates the need to add defensive null-pointer
checks at the callee site, which sometimes merely exist to be on the
safe side. The bottom line is that the code becomes easier to follow.
* Reference members must be initialized via an object initializer,
which promotes a programming style that avoids intermediate object-
construction states. Within core, there are still a few pointers
as member variables left though. E.g., caused by the late association
of 'Platform_thread' objects with their 'Platform_pd' objects.
* If no pointers are present as member variables, we don't need to
manually provide declarations of a private copy constructor and
an assignment operator to avoid -Weffc++ errors "class ... has
pointer data members [-Werror=effc++]".
This patch also changes a few system bindings on NOVA and Fiasco.OC,
e.g., the return value of the global 'cap_map' accessor has become a
reference. Hence, the patch touches a few places outside of core.
Fixes #3135
2019-01-24 22:00:01 +01:00
|
|
|
Cpu &cpu = cpu_pool().cpu(Cpu::executing_id());
|
2016-01-11 11:02:52 +01:00
|
|
|
|
|
|
|
auto base = (addr_t)user_arg_1();
|
|
|
|
auto const size = (size_t)user_arg_2();
|
2018-11-26 11:18:57 +01:00
|
|
|
cpu.clean_invalidate_data_cache_by_virt_region(base, size);
|
|
|
|
cpu.invalidate_instr_cache_by_virt_region(base, size);
|
2016-01-11 11:02:52 +01:00
|
|
|
}
|
2017-06-30 12:00:27 +02:00
|
|
|
|
|
|
|
|
2018-11-26 11:18:57 +01:00
|
|
|
/**
|
|
|
|
* on ARM with multiprocessing extensions, maintainance operations on TLB,
|
|
|
|
* and caches typically work coherently across CPUs when using the correct
|
|
|
|
* coprocessor registers (there might be ARM SoCs where this is not valid,
|
|
|
|
* with several shareability domains, but until now we do not support them)
|
|
|
|
*/
|
2019-06-12 22:33:02 +02:00
|
|
|
void Kernel::Thread::Tlb_invalidation::execute() { };
|
2018-11-26 11:18:57 +01:00
|
|
|
|
2017-06-30 12:00:27 +02:00
|
|
|
|
2017-10-06 12:02:36 +02:00
|
|
|
void Thread::proceed(Cpu & cpu)
|
2017-06-30 12:00:27 +02:00
|
|
|
{
|
base/core: use references instead of pointers
This patch replaces the former prominent use of pointers by references
wherever feasible. This has the following benefits:
* The contract between caller and callee becomes more obvious. When
passing a reference, the contract says that the argument cannot be
a null pointer. The caller is responsible to ensure that. Therefore,
the use of reference eliminates the need to add defensive null-pointer
checks at the callee site, which sometimes merely exist to be on the
safe side. The bottom line is that the code becomes easier to follow.
* Reference members must be initialized via an object initializer,
which promotes a programming style that avoids intermediate object-
construction states. Within core, there are still a few pointers
as member variables left though. E.g., caused by the late association
of 'Platform_thread' objects with their 'Platform_pd' objects.
* If no pointers are present as member variables, we don't need to
manually provide declarations of a private copy constructor and
an assignment operator to avoid -Weffc++ errors "class ... has
pointer data members [-Werror=effc++]".
This patch also changes a few system bindings on NOVA and Fiasco.OC,
e.g., the return value of the global 'cap_map' accessor has become a
reference. Hence, the patch touches a few places outside of core.
Fixes #3135
2019-01-24 22:00:01 +01:00
|
|
|
cpu.switch_to(*regs, pd().mmu_regs);
|
2017-10-06 12:02:36 +02:00
|
|
|
|
|
|
|
regs->cpu_exception = cpu.stack_start();
|
2018-05-14 11:30:24 +02:00
|
|
|
kernel_to_user_context_switch((static_cast<Cpu::Context*>(&*regs)),
|
|
|
|
(static_cast<Cpu::Fpu_context*>(&*regs)));
|
2017-06-30 12:00:27 +02:00
|
|
|
}
|
2017-10-06 12:02:36 +02:00
|
|
|
|
|
|
|
|
2019-02-21 17:23:10 +01:00
|
|
|
void Thread::user_ret_time(Kernel::time_t const t)
|
|
|
|
{
|
|
|
|
regs->r0 = t >> 32UL;
|
|
|
|
regs->r1 = t & ~0UL;
|
|
|
|
}
|
|
|
|
|
2017-10-06 12:02:36 +02:00
|
|
|
void Thread::user_arg_0(Kernel::Call_arg const arg) { regs->r0 = arg; }
|
|
|
|
void Thread::user_arg_1(Kernel::Call_arg const arg) { regs->r1 = arg; }
|
|
|
|
void Thread::user_arg_2(Kernel::Call_arg const arg) { regs->r2 = arg; }
|
|
|
|
void Thread::user_arg_3(Kernel::Call_arg const arg) { regs->r3 = arg; }
|
|
|
|
void Thread::user_arg_4(Kernel::Call_arg const arg) { regs->r4 = arg; }
|
2019-11-08 13:52:25 +01:00
|
|
|
void Thread::user_arg_5(Kernel::Call_arg const arg) { regs->r5 = arg; }
|
2017-10-06 12:02:36 +02:00
|
|
|
|
|
|
|
Kernel::Call_arg Thread::user_arg_0() const { return regs->r0; }
|
|
|
|
Kernel::Call_arg Thread::user_arg_1() const { return regs->r1; }
|
|
|
|
Kernel::Call_arg Thread::user_arg_2() const { return regs->r2; }
|
|
|
|
Kernel::Call_arg Thread::user_arg_3() const { return regs->r3; }
|
|
|
|
Kernel::Call_arg Thread::user_arg_4() const { return regs->r4; }
|
2019-11-08 13:52:25 +01:00
|
|
|
Kernel::Call_arg Thread::user_arg_5() const { return regs->r5; }
|