2011-12-22 16:19:25 +01:00
|
|
|
/*
|
|
|
|
* \brief Thread facility
|
|
|
|
* \author Norman Feske
|
2012-08-02 12:20:00 +02:00
|
|
|
* \author Alexander Boettcher
|
2011-12-22 16:19:25 +01:00
|
|
|
* \date 2009-10-02
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2013-01-10 21:44:47 +01:00
|
|
|
* Copyright (C) 2009-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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _CORE__INCLUDE__PLATFORM_THREAD_H_
|
|
|
|
#define _CORE__INCLUDE__PLATFORM_THREAD_H_
|
|
|
|
|
|
|
|
/* Genode includes */
|
|
|
|
#include <thread/capability.h>
|
|
|
|
#include <base/thread_state.h>
|
|
|
|
#include <base/native_types.h>
|
|
|
|
#include <base/thread.h>
|
|
|
|
#include <base/pager.h>
|
|
|
|
|
2013-03-08 11:54:12 +01:00
|
|
|
/* core includes */
|
|
|
|
#include <address_space.h>
|
|
|
|
|
2011-12-22 16:19:25 +01:00
|
|
|
namespace Genode {
|
|
|
|
|
|
|
|
class Platform_pd;
|
|
|
|
class Platform_thread
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
|
|
|
|
Platform_pd *_pd;
|
|
|
|
Pager_object *_pager;
|
2012-08-08 17:12:10 +02:00
|
|
|
addr_t _id_base;
|
2012-08-02 12:20:00 +02:00
|
|
|
addr_t _sel_exc_base;
|
2012-08-08 17:12:10 +02:00
|
|
|
unsigned _cpu_no;
|
2012-08-02 12:20:00 +02:00
|
|
|
bool _is_main_thread;
|
2012-08-22 12:10:04 +02:00
|
|
|
bool _is_vcpu;
|
2013-02-19 11:14:21 +01:00
|
|
|
char _name[Thread_base::Context::NAME_LEN];
|
2012-08-08 17:12:10 +02:00
|
|
|
|
2012-08-02 12:20:00 +02:00
|
|
|
addr_t _sel_ec() { return _id_base; }
|
|
|
|
addr_t _sel_sc() { return _id_base + 1; }
|
2011-12-22 16:19:25 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
2012-08-02 12:20:00 +02:00
|
|
|
/* invalid thread number */
|
|
|
|
enum { THREAD_INVALID = -1 };
|
2011-12-22 16:19:25 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*/
|
2012-08-02 12:20:00 +02:00
|
|
|
Platform_thread(const char *name = 0,
|
|
|
|
unsigned priority = 0,
|
2012-08-08 17:12:10 +02:00
|
|
|
int thread_id = THREAD_INVALID);
|
2011-12-22 16:19:25 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Destructor
|
|
|
|
*/
|
|
|
|
~Platform_thread();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Start thread
|
|
|
|
*
|
2012-08-08 17:12:39 +02:00
|
|
|
* \param ip instruction pointer to start at
|
|
|
|
* \param sp stack pointer to use
|
2011-12-22 16:19:25 +01:00
|
|
|
*
|
|
|
|
* \retval 0 successful
|
2012-08-08 17:12:39 +02:00
|
|
|
* \retval -1 thread/vCPU could not be started
|
2011-12-22 16:19:25 +01:00
|
|
|
*/
|
2012-08-22 12:10:04 +02:00
|
|
|
int start(void *ip, void *sp);
|
2011-12-22 16:19:25 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Pause this thread
|
|
|
|
*/
|
2012-08-24 09:29:54 +02:00
|
|
|
Native_capability pause();
|
2011-12-22 16:19:25 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Resume this thread
|
|
|
|
*/
|
|
|
|
void resume();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Cancel currently blocking operation
|
|
|
|
*/
|
|
|
|
void cancel_blocking();
|
|
|
|
|
|
|
|
/**
|
2012-11-12 17:48:18 +01:00
|
|
|
* Override thread state with 's'
|
2011-12-22 16:19:25 +01:00
|
|
|
*
|
2012-11-12 17:48:18 +01:00
|
|
|
* \throw Cpu_session::State_access_failed
|
|
|
|
*/
|
|
|
|
void state(Thread_state s);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Read thread state
|
2011-12-22 16:19:25 +01:00
|
|
|
*
|
2012-11-12 17:48:18 +01:00
|
|
|
* \throw Cpu_session::State_access_failed
|
2011-12-22 16:19:25 +01:00
|
|
|
*/
|
2012-11-12 17:48:18 +01:00
|
|
|
Thread_state state();
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2013-03-08 11:54:12 +01:00
|
|
|
/**
|
|
|
|
* Return the address space to which the thread is bound
|
|
|
|
*/
|
|
|
|
Weak_ptr<Address_space> address_space();
|
|
|
|
|
2011-12-22 16:19:25 +01:00
|
|
|
|
|
|
|
/************************
|
|
|
|
** Accessor functions **
|
|
|
|
************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set pager
|
|
|
|
*/
|
|
|
|
void pager(Pager_object *pager) { _pager = pager; }
|
|
|
|
|
2012-08-02 12:20:00 +02:00
|
|
|
/**
|
|
|
|
* Return pager object
|
|
|
|
*/
|
2011-12-22 16:19:25 +01:00
|
|
|
Pager_object *pager() { return _pager; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return identification of thread when faulting
|
|
|
|
*/
|
|
|
|
unsigned long pager_object_badge() const;
|
|
|
|
|
|
|
|
/**
|
2012-09-04 17:32:55 +02:00
|
|
|
* Set the executing CPU for this thread
|
2011-12-22 16:19:25 +01:00
|
|
|
*/
|
2012-09-04 17:32:55 +02:00
|
|
|
void affinity(unsigned cpu);
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2013-07-09 15:58:06 +02:00
|
|
|
/**
|
|
|
|
* Get the executing CPU for this thread
|
|
|
|
*/
|
|
|
|
unsigned affinity();
|
|
|
|
|
2011-12-22 16:19:25 +01:00
|
|
|
/**
|
|
|
|
* Get thread name
|
|
|
|
*/
|
|
|
|
const char *name() const { return "noname"; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Associate thread with protection domain
|
|
|
|
*/
|
|
|
|
void bind_to_pd(Platform_pd *pd, bool is_main_thread)
|
|
|
|
{
|
|
|
|
_pd = pd, _is_main_thread = is_main_thread;
|
|
|
|
}
|
2012-08-08 17:12:10 +02:00
|
|
|
|
2012-08-02 12:20:00 +02:00
|
|
|
/**
|
|
|
|
* Return native EC cap with specific rights mask set.
|
|
|
|
* If the cap is mapped the kernel will demote the
|
|
|
|
* rights of the EC as specified by the rights mask.
|
|
|
|
*
|
|
|
|
* The cap is supposed to be returned to clients,
|
|
|
|
* which they have to use as argument to identify
|
|
|
|
* the thread to which they want attach portals.
|
|
|
|
*
|
|
|
|
* The demotion by the kernel during the map operation
|
|
|
|
* takes care that the EC cap itself contains
|
|
|
|
* no usable rights for the clients.
|
|
|
|
*/
|
2012-08-08 17:12:10 +02:00
|
|
|
Native_capability native_cap()
|
|
|
|
{
|
2012-07-30 11:00:43 +02:00
|
|
|
using namespace Nova;
|
|
|
|
|
|
|
|
return Native_capability(
|
|
|
|
_sel_ec(), Obj_crd::RIGHT_EC_RECALL);
|
2012-08-08 17:12:10 +02:00
|
|
|
}
|
|
|
|
|
2012-08-23 12:43:19 +02:00
|
|
|
void single_step(bool on);
|
|
|
|
|
2011-12-22 16:19:25 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* _CORE__INCLUDE__PLATFORM_THREAD_H_ */
|