2011-12-22 16:19:25 +01:00
|
|
|
/*
|
|
|
|
* \brief Platform-specific type definitions
|
|
|
|
* \author Norman Feske
|
2012-08-01 16:16:51 +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 _INCLUDE__BASE__NATIVE_TYPES_H_
|
|
|
|
#define _INCLUDE__BASE__NATIVE_TYPES_H_
|
|
|
|
|
2012-03-08 12:45:18 +01:00
|
|
|
#include <base/native_capability.h>
|
2012-08-08 13:07:21 +02:00
|
|
|
#include <base/stdint.h>
|
2012-03-07 11:58:40 +01:00
|
|
|
|
2012-07-30 10:56:07 +02:00
|
|
|
#include <nova/syscalls.h>
|
|
|
|
|
2013-08-30 15:25:53 +02:00
|
|
|
#include <base/cap_map.h>
|
|
|
|
|
2011-12-22 16:19:25 +01:00
|
|
|
namespace Genode {
|
|
|
|
|
|
|
|
struct Native_thread
|
|
|
|
{
|
2012-08-02 10:10:48 +02:00
|
|
|
enum { INVALID_INDEX = ~0UL };
|
|
|
|
|
2012-08-01 17:04:43 +02:00
|
|
|
addr_t ec_sel; /* NOVA cap selector for execution context */
|
|
|
|
addr_t exc_pt_sel; /* base of event portal window */
|
2012-08-07 11:41:03 +02:00
|
|
|
bool is_vcpu;
|
2012-08-02 10:10:48 +02:00
|
|
|
|
|
|
|
Native_thread() : ec_sel(INVALID_INDEX),
|
2012-08-07 11:41:03 +02:00
|
|
|
exc_pt_sel (INVALID_INDEX), is_vcpu(false) {}
|
2011-12-22 16:19:25 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef Native_thread Native_thread_id;
|
|
|
|
|
2012-08-08 13:07:21 +02:00
|
|
|
inline bool operator == (Native_thread_id t1, Native_thread_id t2)
|
|
|
|
{
|
2012-08-01 17:04:43 +02:00
|
|
|
return (t1.ec_sel == t2.ec_sel) &&
|
|
|
|
(t1.exc_pt_sel == t2.exc_pt_sel);
|
2012-08-01 16:16:51 +02:00
|
|
|
}
|
2012-08-08 13:07:21 +02:00
|
|
|
inline bool operator != (Native_thread_id t1, Native_thread_id t2)
|
|
|
|
{
|
2012-08-01 17:04:43 +02:00
|
|
|
return (t1.ec_sel != t2.ec_sel) &&
|
|
|
|
(t1.exc_pt_sel != t2.exc_pt_sel);
|
2012-08-08 13:07:21 +02:00
|
|
|
}
|
2011-12-22 16:19:25 +01:00
|
|
|
|
|
|
|
class Native_utcb
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
|
|
|
|
/**
|
2012-08-01 17:04:43 +02:00
|
|
|
* Size of the NOVA-specific user-level thread-control
|
|
|
|
* block
|
2011-12-22 16:19:25 +01:00
|
|
|
*/
|
|
|
|
enum { UTCB_SIZE = 4096 };
|
|
|
|
|
|
|
|
/**
|
|
|
|
* User-level thread control block
|
|
|
|
*
|
2012-08-01 17:04:43 +02:00
|
|
|
* The UTCB is one 4K page, shared between the kernel
|
|
|
|
* and the user process. It is not backed by a
|
|
|
|
* dataspace but provided by the kernel.
|
2011-12-22 16:19:25 +01:00
|
|
|
*/
|
2012-07-30 10:56:07 +02:00
|
|
|
addr_t _utcb[UTCB_SIZE/sizeof(addr_t)];
|
2011-12-22 16:19:25 +01:00
|
|
|
};
|
|
|
|
|
2012-07-30 10:56:07 +02:00
|
|
|
class Native_capability
|
2011-12-22 16:19:25 +01:00
|
|
|
{
|
2012-07-30 10:56:07 +02:00
|
|
|
public:
|
2012-08-10 10:09:42 +02:00
|
|
|
|
2012-07-30 10:56:07 +02:00
|
|
|
typedef Nova::Obj_crd Dst;
|
|
|
|
|
|
|
|
struct Raw
|
|
|
|
{
|
2013-01-11 23:10:21 +01:00
|
|
|
Dst dst;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* It is obsolete and unused in NOVA, however still used by
|
|
|
|
* generic base part
|
2012-07-30 10:56:07 +02:00
|
|
|
*/
|
|
|
|
addr_t local_name;
|
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
2012-08-10 10:09:42 +02:00
|
|
|
|
2012-07-30 10:56:07 +02:00
|
|
|
struct _Raw
|
|
|
|
{
|
|
|
|
Dst dst;
|
|
|
|
|
|
|
|
_Raw() : dst() { }
|
|
|
|
|
|
|
|
_Raw(addr_t sel, unsigned rights)
|
|
|
|
: dst(sel, 0, rights) { }
|
|
|
|
} _cap;
|
|
|
|
|
|
|
|
bool _trans_map;
|
|
|
|
void * _ptr;
|
2012-08-07 11:41:03 +02:00
|
|
|
addr_t _rcv_window;
|
2012-07-30 10:56:07 +02:00
|
|
|
|
2012-08-02 10:10:48 +02:00
|
|
|
enum { INVALID_INDEX = ~0UL };
|
2012-08-10 10:09:42 +02:00
|
|
|
|
2012-07-30 10:56:07 +02:00
|
|
|
protected:
|
|
|
|
|
|
|
|
explicit
|
2012-08-07 11:41:03 +02:00
|
|
|
Native_capability(void* ptr)
|
|
|
|
: _cap(), _trans_map(true), _ptr(ptr),
|
|
|
|
_rcv_window(INVALID_INDEX) {}
|
2012-07-30 10:56:07 +02:00
|
|
|
|
2013-08-30 15:25:53 +02:00
|
|
|
inline void _inc(bool inc_if_one = false) const
|
|
|
|
{
|
|
|
|
Cap_index idx(cap_map()->find(local_name()));
|
|
|
|
idx.inc(inc_if_one);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void _dec() const
|
|
|
|
{
|
|
|
|
Cap_index idx(cap_map()->find(local_name()));
|
|
|
|
idx.dec();
|
|
|
|
}
|
|
|
|
|
2012-07-30 10:56:07 +02:00
|
|
|
public:
|
2012-08-10 10:09:42 +02:00
|
|
|
|
2012-08-07 11:41:03 +02:00
|
|
|
/**
|
|
|
|
* Constructors
|
|
|
|
*/
|
2012-08-10 10:09:42 +02:00
|
|
|
|
2012-08-07 11:41:03 +02:00
|
|
|
Native_capability()
|
2012-08-10 10:09:42 +02:00
|
|
|
: _cap(), _trans_map(true), _ptr(0), _rcv_window(INVALID_INDEX) {}
|
2012-07-30 10:56:07 +02:00
|
|
|
|
|
|
|
explicit
|
|
|
|
Native_capability(addr_t sel, unsigned rights = 0x1f)
|
2012-08-10 10:09:42 +02:00
|
|
|
{
|
|
|
|
if (sel == INVALID_INDEX)
|
|
|
|
_cap = _Raw();
|
2013-08-30 15:25:53 +02:00
|
|
|
else {
|
2012-08-10 10:09:42 +02:00
|
|
|
_cap = _Raw(sel, rights);
|
2013-08-30 15:25:53 +02:00
|
|
|
_inc();
|
|
|
|
}
|
2012-08-10 10:09:42 +02:00
|
|
|
|
|
|
|
_trans_map = true;
|
|
|
|
_ptr = 0;
|
|
|
|
_rcv_window = INVALID_INDEX;
|
|
|
|
}
|
2012-07-30 10:56:07 +02:00
|
|
|
|
|
|
|
Native_capability(const Native_capability &o)
|
2012-08-07 11:41:03 +02:00
|
|
|
: _cap(o._cap), _trans_map(o._trans_map), _ptr(o._ptr),
|
2013-08-30 15:25:53 +02:00
|
|
|
_rcv_window(o._rcv_window) { if (valid()) _inc(); }
|
|
|
|
|
|
|
|
~Native_capability() { if (valid()) _dec(); }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Overloaded comparison operator
|
|
|
|
*/
|
|
|
|
bool operator==(const Native_capability &o) const {
|
|
|
|
return (_ptr) ? _ptr == o._ptr : local_name() == o.local_name(); }
|
|
|
|
|
|
|
|
Native_capability operator+ () const
|
|
|
|
{
|
|
|
|
if (valid()) _inc(true);
|
|
|
|
return *this;
|
|
|
|
}
|
2012-07-30 10:56:07 +02:00
|
|
|
|
2012-08-07 11:41:03 +02:00
|
|
|
/**
|
|
|
|
* Copy constructor
|
|
|
|
*/
|
|
|
|
Native_capability& operator=
|
|
|
|
(const Native_capability &o)
|
|
|
|
{
|
2012-07-30 10:56:07 +02:00
|
|
|
if (this == &o)
|
|
|
|
return *this;
|
|
|
|
|
2013-08-30 15:25:53 +02:00
|
|
|
if (valid()) _dec();
|
|
|
|
|
2012-07-30 10:56:07 +02:00
|
|
|
_cap = o._cap;
|
|
|
|
_trans_map = o._trans_map;
|
|
|
|
_ptr = o._ptr;
|
2012-08-07 11:41:03 +02:00
|
|
|
_rcv_window = o._rcv_window;
|
2013-08-30 15:25:53 +02:00
|
|
|
|
|
|
|
if (valid()) _inc();
|
|
|
|
|
2012-07-30 10:56:07 +02:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2012-08-07 11:41:03 +02:00
|
|
|
/**
|
|
|
|
* Check whether the selector of the Native_cap and
|
|
|
|
* the capability type is valid.
|
|
|
|
*/
|
2012-08-10 10:09:42 +02:00
|
|
|
bool valid() const { return !_cap.dst.is_null(); }
|
2012-07-30 10:56:07 +02:00
|
|
|
|
|
|
|
Dst dst() const { return _cap.dst; }
|
2012-08-07 11:41:03 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return pointer to the server object identified by
|
|
|
|
* this cap
|
|
|
|
*/
|
2012-07-30 10:56:07 +02:00
|
|
|
void * local() const { return _ptr; }
|
2012-08-02 10:10:48 +02:00
|
|
|
|
2012-08-07 11:41:03 +02:00
|
|
|
/**
|
|
|
|
* Return the local_name. On NOVA it is the same as the
|
|
|
|
* destination value.
|
|
|
|
*/
|
|
|
|
addr_t local_name() const
|
|
|
|
{
|
2012-08-02 10:10:48 +02:00
|
|
|
if (valid())
|
|
|
|
return _cap.dst.base();
|
|
|
|
else
|
|
|
|
return INVALID_INDEX;
|
|
|
|
}
|
2012-07-30 10:56:07 +02:00
|
|
|
|
2012-08-07 11:41:03 +02:00
|
|
|
/**
|
|
|
|
* Set one specific cap selector index as receive
|
|
|
|
* window for the next IPC. This can be used to make
|
|
|
|
* sure that the to be received mapped capability will
|
|
|
|
* be placed at a specific index.
|
|
|
|
*/
|
|
|
|
void rcv_window(addr_t rcv) { _rcv_window = rcv; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the selector of the rcv_window.
|
|
|
|
*/
|
|
|
|
addr_t rcv_window() const { return _rcv_window; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return an invalid Dst object
|
|
|
|
*/
|
2012-07-30 10:56:07 +02:00
|
|
|
static Dst invalid() { return Dst(); }
|
|
|
|
|
2012-08-07 11:41:03 +02:00
|
|
|
/**
|
|
|
|
* Return a invalid Native_capability
|
|
|
|
*/
|
2012-07-30 10:56:07 +02:00
|
|
|
static Native_capability invalid_cap()
|
|
|
|
{
|
2012-08-10 10:09:42 +02:00
|
|
|
return Native_capability();
|
2012-07-30 10:56:07 +02:00
|
|
|
}
|
|
|
|
|
2012-08-07 11:41:03 +02:00
|
|
|
/**
|
|
|
|
* Invoke map syscall instead of translate_map call
|
|
|
|
*/
|
2012-07-30 10:56:07 +02:00
|
|
|
void solely_map() { _trans_map = false; }
|
2012-08-07 11:41:03 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return true if the cap should be tried first to
|
|
|
|
* be translated and if this fails it should be mapped.
|
|
|
|
*/
|
2012-07-30 10:56:07 +02:00
|
|
|
bool trans_map() const { return _trans_map; }
|
2011-12-22 16:19:25 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef int Native_connection_state;
|
2012-08-29 14:42:56 +02:00
|
|
|
|
|
|
|
struct Native_config
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Thread-context area configuration.
|
|
|
|
*/
|
2012-09-04 12:57:09 +02:00
|
|
|
static addr_t context_area_virtual_base() { return 0xa0000000UL; }
|
2012-08-29 14:42:56 +02:00
|
|
|
static addr_t context_area_virtual_size() { return 0x10000000UL; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Size of virtual address region holding the context of one thread
|
|
|
|
*/
|
|
|
|
static addr_t context_virtual_size() { return 0x00100000UL; }
|
|
|
|
};
|
|
|
|
|
2012-11-21 15:20:21 +01:00
|
|
|
struct Native_pd_args { };
|
2011-12-22 16:19:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* _INCLUDE__BASE__NATIVE_TYPES_H_ */
|