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
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* 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-01-23 14:42:55 +01:00
|
|
|
|
2013-11-14 17:29:34 +01:00
|
|
|
/* base-hw includes */
|
|
|
|
#include <kernel/interface.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.
|
|
|
|
*/
|
2015-05-19 14:18:40 +02:00
|
|
|
Native_utcb * utcb = Thread_base::myself()->utcb();
|
|
|
|
_parent_cap = utcb->cap_get(Native_utcb::PARENT);
|
|
|
|
Untyped_capability ds_cap(utcb->cap_get(Native_utcb::UTCB_DATASPACE));
|
|
|
|
_main_thread_utcb_ds = reinterpret_cap_cast<Ram_dataspace>(ds_cap);
|
|
|
|
_main_thread_cap = utcb->cap_get(Native_utcb::THREAD_MYSELF);
|
2014-01-28 14:30:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void prepare_reinit_main_thread() { prepare_init_main_thread(); }
|
|
|
|
|
|
|
|
|
|
|
|
/*****************
|
|
|
|
** Thread_base **
|
|
|
|
*****************/
|
|
|
|
|
2016-01-23 14:42:55 +01:00
|
|
|
Native_utcb *Thread_base::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
|
|
|
|
|
|
|
|
2014-04-28 21:31:57 +02:00
|
|
|
void Thread_base::_thread_start()
|
2014-01-28 14:30:36 +01:00
|
|
|
{
|
2014-04-28 21:31:57 +02:00
|
|
|
Thread_base::myself()->_thread_bootstrap();
|
|
|
|
Thread_base::myself()->entry();
|
|
|
|
Thread_base::myself()->_join_lock.unlock();
|
|
|
|
Genode::sleep_forever();
|
|
|
|
}
|
|
|
|
|
2015-05-19 14:18:40 +02:00
|
|
|
void Thread_base::_thread_bootstrap() {
|
2016-03-11 17:32:43 +01:00
|
|
|
native_thread().cap = myself()->utcb()->cap_get(Native_utcb::THREAD_MYSELF); }
|