2011-12-22 16:19:25 +01:00
|
|
|
/*
|
|
|
|
* \brief NOVA-specific implementation of the Thread API
|
|
|
|
* \author Norman Feske
|
|
|
|
* \date 2010-01-19
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2013-01-10 21:44:47 +01:00
|
|
|
* Copyright (C) 2010-2013 Genode Labs GmbH
|
2011-12-22 16:19:25 +01:00
|
|
|
*
|
|
|
|
* 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>
|
|
|
|
#include <base/sleep.h>
|
|
|
|
#include <base/env.h>
|
|
|
|
|
2016-01-23 14:42:55 +01:00
|
|
|
/* base-internal includes */
|
|
|
|
#include <base/internal/stack.h>
|
|
|
|
|
2011-12-22 16:19:25 +01:00
|
|
|
using namespace Genode;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Entry point entered by new threads
|
|
|
|
*/
|
|
|
|
void Thread_base::_thread_start()
|
|
|
|
{
|
|
|
|
Thread_base::myself()->_thread_bootstrap();
|
|
|
|
Thread_base::myself()->entry();
|
2012-11-16 13:53:37 +01:00
|
|
|
Thread_base::myself()->_join_lock.unlock();
|
2011-12-22 16:19:25 +01:00
|
|
|
Genode::sleep_forever();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*****************
|
|
|
|
** Thread base **
|
|
|
|
*****************/
|
|
|
|
|
|
|
|
void Thread_base::_deinit_platform_thread()
|
|
|
|
{
|
2014-04-29 09:45:47 +02:00
|
|
|
if (!_cpu_session)
|
|
|
|
_cpu_session = env()->cpu_session();
|
|
|
|
|
2014-04-03 14:18:52 +02:00
|
|
|
_cpu_session->kill_thread(_thread_cap);
|
2011-12-22 16:19:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Thread_base::start()
|
|
|
|
{
|
2014-04-03 14:18:52 +02:00
|
|
|
/* if no cpu session is given, use it from the environment */
|
|
|
|
if (!_cpu_session)
|
|
|
|
_cpu_session = env()->cpu_session();
|
|
|
|
|
2011-12-22 16:19:25 +01:00
|
|
|
/* create thread at core */
|
|
|
|
char buf[48];
|
|
|
|
name(buf, sizeof(buf));
|
2015-03-27 14:05:55 +01:00
|
|
|
enum { WEIGHT = Cpu_session::DEFAULT_WEIGHT };
|
2016-01-23 14:42:55 +01:00
|
|
|
addr_t const utcb = (addr_t)&_stack->utcb();
|
2015-03-27 14:05:55 +01:00
|
|
|
_thread_cap = _cpu_session->create_thread(WEIGHT, buf, utcb);
|
2015-03-13 11:20:44 +01:00
|
|
|
if (!_thread_cap.valid())
|
|
|
|
throw Cpu_session::Thread_creation_failed();
|
2011-12-22 16:19:25 +01:00
|
|
|
|
|
|
|
/* assign thread to protection domain */
|
2015-03-13 11:20:44 +01:00
|
|
|
if (env()->pd_session()->bind_thread(_thread_cap))
|
|
|
|
throw Cpu_session::Thread_creation_failed();
|
2011-12-22 16:19:25 +01:00
|
|
|
|
|
|
|
/* create new pager object and assign it to the new thread */
|
|
|
|
Pager_capability pager_cap = env()->rm_session()->add_client(_thread_cap);
|
2015-03-13 11:20:44 +01:00
|
|
|
if (!pager_cap.valid())
|
|
|
|
throw Cpu_session::Thread_creation_failed();
|
|
|
|
|
2014-04-03 14:18:52 +02:00
|
|
|
_cpu_session->set_pager(_thread_cap, pager_cap);
|
2011-12-22 16:19:25 +01:00
|
|
|
|
|
|
|
/* register initial IP and SP at core */
|
2016-01-23 14:42:55 +01:00
|
|
|
_cpu_session->start(_thread_cap, (addr_t)_thread_start, _stack->top());
|
2011-12-22 16:19:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Thread_base::cancel_blocking()
|
|
|
|
{
|
2014-04-03 14:18:52 +02:00
|
|
|
_cpu_session->cancel_blocking(_thread_cap);
|
2011-12-22 16:19:25 +01:00
|
|
|
}
|