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
|
|
|
|
|
|
|
/* 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
|
|
|
|
2014-01-28 14:30:36 +01:00
|
|
|
Ram_dataspace_capability _main_thread_utcb_ds;
|
2014-04-28 21:31:57 +02:00
|
|
|
Native_thread_id _main_thread_id;
|
2014-01-28 14:30:36 +01:00
|
|
|
|
|
|
|
|
|
|
|
/**************************
|
|
|
|
** Native types support **
|
|
|
|
**************************/
|
|
|
|
|
|
|
|
Native_thread_id Genode::thread_get_my_native_id()
|
|
|
|
{
|
|
|
|
Thread_base * const t = Thread_base::myself();
|
|
|
|
return t ? t->tid().thread_id : _main_thread_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************
|
|
|
|
** Startup library support **
|
|
|
|
*****************************/
|
|
|
|
|
|
|
|
void prepare_init_main_thread()
|
|
|
|
{
|
|
|
|
using namespace Genode;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Make data from the startup info persistantly available by copying it
|
|
|
|
* before the UTCB gets polluted by the following function calls.
|
|
|
|
*/
|
|
|
|
Native_utcb * const utcb = Thread_base::myself()->utcb();
|
|
|
|
_main_thread_id = utcb->start_info()->thread_id();
|
|
|
|
_main_thread_utcb_ds =
|
|
|
|
reinterpret_cap_cast<Ram_dataspace>(utcb->start_info()->utcb_ds());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void prepare_reinit_main_thread() { prepare_init_main_thread(); }
|
|
|
|
|
|
|
|
|
|
|
|
/*****************
|
|
|
|
** Thread_base **
|
|
|
|
*****************/
|
|
|
|
|
2014-04-28 21:31:57 +02:00
|
|
|
Native_utcb * Thread_base::utcb()
|
2013-02-25 21:18:26 +01:00
|
|
|
{
|
2014-04-28 21:31:57 +02:00
|
|
|
if (this) { return &_context->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();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Thread_base::_thread_bootstrap()
|
|
|
|
{
|
|
|
|
Native_utcb * const utcb = Thread_base::myself()->utcb();
|
|
|
|
_tid.thread_id = utcb->start_info()->thread_id();
|
2014-01-28 14:30:36 +01:00
|
|
|
}
|