genode/repos/base-nova/src/core/thread_start.cc
Norman Feske b49e588c1c Assign threads to PD at its creation time
This patch replaces the former 'Pd_session::bind_thread' function by a
PD-capability argument of the 'Cpu_session::create_thread' function, and
removes the ancient thread-start protocol via 'Rm_session::add_client' and
'Cpu_session::set_pager'. Threads are now bound to PDs at their creation
time and implicitly paged according to the address space of the PD.

Note the API change:

This patch changes the signature of the 'Child' and 'Process' constructors.
There is a new 'address_space' argument, which represents the region map
representing the child's address space. It is supplied separately to the
PD session capability (which principally can be invoked to obtain the
PD's address space) to allow the population of the address space
without relying on an 'Pd_session::address_space' RPC call.
Furthermore, a new (optional) env_pd argument allows the explicit
overriding of the PD capability handed out to the child as part of its
environment. It can be used to intercept the interaction of the child
with its PD session at core. This is used by Noux.

Issue #1938
2016-05-09 13:10:52 +02:00

132 lines
3.5 KiB
C++

/*
* \brief NOVA-specific implementation of the Thread API for core
* \author Norman Feske
* \author Sebastian Sumpf
* \author Alexander Boettcher
* \date 2010-01-19
*/
/*
* Copyright (C) 2010-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.
*/
/* Genode includes */
#include <base/thread.h>
#include <base/printf.h>
/* base-internal includes */
#include <base/internal/stack.h>
/* NOVA includes */
#include <nova/syscalls.h>
/* core includes */
#include <nova_util.h>
#include <platform_pd.h>
using namespace Genode;
void Thread_base::_init_platform_thread(size_t, Type type)
{
/*
* This function is called for constructing server activations and pager
* objects. It allocates capability selectors for the thread's execution
* context and a synchronization-helper semaphore needed for 'Lock'.
*/
using namespace Nova;
if (type == MAIN)
{
/* set EC selector according to NOVA spec */
native_thread().ec_sel = Platform_pd::pd_core_sel() + 1;
/*
* Exception base of first thread in core is 0. We have to set
* it here so that Thread_base code finds the semaphore of the
* main thread.
*/
native_thread().exc_pt_sel = 0;
return;
}
native_thread().ec_sel = cap_map()->insert(1);
native_thread().exc_pt_sel = cap_map()->insert(NUM_INITIAL_PT_LOG2);
addr_t pd_sel = Platform_pd::pd_core_sel();
/* create running semaphore required for locking */
addr_t rs_sel =native_thread().exc_pt_sel + SM_SEL_EC;
uint8_t res = create_sm(rs_sel, pd_sel, 0);
if (res != NOVA_OK) {
PERR("create_sm returned %u", res);
throw Cpu_session::Thread_creation_failed();
}
}
void Thread_base::_deinit_platform_thread()
{
unmap_local(Nova::Obj_crd(native_thread().ec_sel, 1));
unmap_local(Nova::Obj_crd(native_thread().exc_pt_sel, Nova::NUM_INITIAL_PT_LOG2));
cap_map()->remove(native_thread().ec_sel, 1, false);
cap_map()->remove(native_thread().exc_pt_sel, Nova::NUM_INITIAL_PT_LOG2, false);
/* revoke utcb */
Nova::Rights rwx(true, true, true);
addr_t utcb = reinterpret_cast<addr_t>(&_stack->utcb());
Nova::revoke(Nova::Mem_crd(utcb >> 12, 0, rwx));
}
void Thread_base::start()
{
/*
* On NOVA, core almost never starts regular threads. This simply creates a
* local EC
*/
using namespace Nova;
addr_t sp = _stack->top();
addr_t utcb = reinterpret_cast<addr_t>(&_stack->utcb());
Utcb * utcb_obj = reinterpret_cast<Utcb *>(&_stack->utcb());
addr_t pd_sel = Platform_pd::pd_core_sel();
Affinity::Location location = _affinity;
if (!location.valid())
location = Affinity::Location(boot_cpu(), 0);
/* create local EC */
enum { LOCAL_THREAD = false };
uint8_t res = create_ec(native_thread().ec_sel, pd_sel, location.xpos(),
utcb, sp, native_thread().exc_pt_sel, LOCAL_THREAD);
if (res != NOVA_OK) {
PERR("create_ec returned %d cpu=%u", res, location.xpos());
throw Cpu_session::Thread_creation_failed();
}
/* default: we don't accept any mappings or translations */
utcb_obj->crd_rcv = Obj_crd();
utcb_obj->crd_xlt = Obj_crd();
if (map_local(reinterpret_cast<Nova::Utcb *>(Thread_base::myself()->utcb()),
Obj_crd(PT_SEL_PAGE_FAULT, 0),
Obj_crd(native_thread().exc_pt_sel + PT_SEL_PAGE_FAULT, 0))) {
PERR("could not create page fault portal");
throw Cpu_session::Thread_creation_failed();
}
}
void Thread_base::cancel_blocking()
{
using namespace Nova;
if (sm_ctrl(native_thread().exc_pt_sel + SM_SEL_EC, SEMAPHORE_UP))
nova_die();
}