2013-02-25 21:18:26 +01:00
|
|
|
/*
|
2014-07-09 12:03:17 +02:00
|
|
|
* \brief Implementations for the initialization of a thread
|
2014-01-28 14:30:36 +01:00
|
|
|
* \author Martin stein
|
2014-04-28 21:31:57 +02:00
|
|
|
* \author Stefan Kalkowski
|
2013-02-25 21:18:26 +01:00
|
|
|
* \date 2013-02-15
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2017-02-20 13:23:52 +01:00
|
|
|
* Copyright (C) 2013-2017 Genode Labs GmbH
|
2013-02-25 21:18:26 +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.
|
2013-02-25 21:18:26 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* Genode includes */
|
|
|
|
#include <base/thread.h>
|
2014-01-28 14:30:36 +01:00
|
|
|
#include <base/env.h>
|
2014-04-28 21:31:57 +02:00
|
|
|
#include <base/sleep.h>
|
2013-11-14 17:29:34 +01:00
|
|
|
|
2016-01-23 14:42:55 +01:00
|
|
|
/* base-internal includes */
|
|
|
|
#include <base/internal/stack.h>
|
2016-03-08 16:59:43 +01:00
|
|
|
#include <base/internal/native_utcb.h>
|
2016-06-15 15:04:54 +02:00
|
|
|
#include <base/internal/capability_space.h>
|
2013-02-25 21:18:26 +01:00
|
|
|
|
2014-01-28 14:30:36 +01:00
|
|
|
using namespace Genode;
|
2013-02-25 21:18:26 +01:00
|
|
|
|
2015-05-19 14:18:40 +02:00
|
|
|
namespace Hw {
|
|
|
|
Ram_dataspace_capability _main_thread_utcb_ds;
|
|
|
|
Untyped_capability _main_thread_cap;
|
|
|
|
Untyped_capability _parent_cap;
|
2014-01-28 14:30:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************
|
|
|
|
** Startup library support **
|
|
|
|
*****************************/
|
|
|
|
|
|
|
|
void prepare_init_main_thread()
|
|
|
|
{
|
|
|
|
using namespace Genode;
|
2015-05-19 14:18:40 +02:00
|
|
|
using namespace Hw;
|
2014-01-28 14:30:36 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Make data from the startup info persistantly available by copying it
|
|
|
|
* before the UTCB gets polluted by the following function calls.
|
|
|
|
*/
|
2016-05-04 12:27:17 +02:00
|
|
|
Native_utcb * utcb = Thread::myself()->utcb();
|
2016-06-15 15:04:54 +02:00
|
|
|
_parent_cap = Capability_space::import(utcb->cap_get(Native_utcb::PARENT));
|
|
|
|
|
|
|
|
Untyped_capability ds_cap =
|
|
|
|
Capability_space::import(utcb->cap_get(Native_utcb::UTCB_DATASPACE));
|
2015-05-19 14:18:40 +02:00
|
|
|
_main_thread_utcb_ds = reinterpret_cap_cast<Ram_dataspace>(ds_cap);
|
2016-06-15 15:04:54 +02:00
|
|
|
|
|
|
|
_main_thread_cap = Capability_space::import(utcb->cap_get(Native_utcb::THREAD_MYSELF));
|
2014-01-28 14:30:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void prepare_reinit_main_thread() { prepare_init_main_thread(); }
|
|
|
|
|
|
|
|
|
2016-05-04 12:27:17 +02:00
|
|
|
/************
|
|
|
|
** Thread **
|
|
|
|
************/
|
2014-01-28 14:30:36 +01:00
|
|
|
|
2017-04-06 17:22:15 +02:00
|
|
|
/* prevent the compiler from optimizing out the 'this' pointer check */
|
|
|
|
__attribute__((optimize("-fno-delete-null-pointer-checks")))
|
2016-05-04 12:27:17 +02:00
|
|
|
Native_utcb *Thread::utcb()
|
2013-02-25 21:18:26 +01:00
|
|
|
{
|
2016-01-23 14:42:55 +01:00
|
|
|
if (this) { return &_stack->utcb(); }
|
2015-05-11 22:18:50 +02:00
|
|
|
return utcb_main_thread();
|
2013-02-25 21:18:26 +01:00
|
|
|
}
|
2014-01-28 14:30:36 +01:00
|
|
|
|
|
|
|
|
2016-05-04 12:27:17 +02:00
|
|
|
void Thread::_thread_start()
|
2014-01-28 14:30:36 +01:00
|
|
|
{
|
2016-05-04 12:27:17 +02:00
|
|
|
Thread::myself()->_thread_bootstrap();
|
|
|
|
Thread::myself()->entry();
|
|
|
|
Thread::myself()->_join_lock.unlock();
|
2014-04-28 21:31:57 +02:00
|
|
|
Genode::sleep_forever();
|
|
|
|
}
|
|
|
|
|
2016-06-15 15:04:54 +02:00
|
|
|
void Thread::_thread_bootstrap()
|
|
|
|
{
|
|
|
|
Kernel::capid_t capid = myself()->utcb()->cap_get(Native_utcb::THREAD_MYSELF);
|
|
|
|
native_thread().cap = Capability_space::import(capid);
|
|
|
|
}
|