2011-12-22 15:19:25 +00:00
|
|
|
/*
|
|
|
|
* \brief Fiasco.OC pager support
|
|
|
|
* \author Christian Helmuth
|
|
|
|
* \author Stefan Kalkowski
|
|
|
|
* \date 2006-06-14
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2013-01-10 20:44:47 +00:00
|
|
|
* Copyright (C) 2006-2013 Genode Labs GmbH
|
2011-12-22 15:19:25 +00: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__IPC_PAGER_H_
|
|
|
|
#define _INCLUDE__BASE__IPC_PAGER_H_
|
|
|
|
|
|
|
|
/* Genode includes */
|
|
|
|
#include <base/ipc.h>
|
|
|
|
#include <base/stdint.h>
|
|
|
|
#include <base/native_types.h>
|
|
|
|
#include <base/thread_state.h>
|
|
|
|
#include <util/touch.h>
|
|
|
|
|
|
|
|
/* Fiasco includes */
|
|
|
|
namespace Fiasco {
|
|
|
|
#include <l4/sys/types.h>
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace Genode {
|
|
|
|
|
|
|
|
class Mapping
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
|
|
|
|
addr_t _dst_addr;
|
|
|
|
addr_t _src_addr;
|
|
|
|
bool _write_combined;
|
|
|
|
unsigned _log2size;
|
|
|
|
bool _rw;
|
|
|
|
bool _grant;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*/
|
|
|
|
Mapping(addr_t dst_addr, addr_t src_addr,
|
2012-11-05 15:26:36 +00:00
|
|
|
bool write_combined, bool io_mem,
|
|
|
|
unsigned l2size = L4_LOG2_PAGESIZE,
|
2011-12-22 15:19:25 +00:00
|
|
|
bool rw = true, bool grant = false)
|
|
|
|
: _dst_addr(dst_addr), _src_addr(src_addr),
|
|
|
|
_write_combined(write_combined), _log2size(l2size),
|
|
|
|
_rw(rw), _grant(grant) { }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Construct invalid flexpage
|
|
|
|
*/
|
|
|
|
Mapping() : _dst_addr(0), _src_addr(0), _write_combined(false),
|
|
|
|
_log2size(0), _rw(false), _grant(false) { }
|
|
|
|
|
|
|
|
Fiasco::l4_umword_t dst_addr() const { return _dst_addr; }
|
|
|
|
bool grant() const { return _grant; }
|
|
|
|
|
|
|
|
Fiasco::l4_fpage_t fpage() const
|
|
|
|
{
|
|
|
|
// TODO: write combined
|
|
|
|
//if (write_combined)
|
|
|
|
// _fpage.fp.cache = Fiasco::L4_FPAGE_BUFFERABLE;
|
|
|
|
|
|
|
|
unsigned char rights = _rw ? Fiasco::L4_FPAGE_RW : Fiasco::L4_FPAGE_RO;
|
|
|
|
return Fiasco::l4_fpage(_src_addr, _log2size, rights);
|
|
|
|
}
|
|
|
|
|
2012-06-18 13:20:31 +00:00
|
|
|
bool write_combined() const { return _write_combined; }
|
|
|
|
|
2011-12-22 15:19:25 +00:00
|
|
|
/**
|
2013-03-04 10:26:18 +00:00
|
|
|
* Prepare map operation is not needed on Fiasco.OC, since we clear the
|
|
|
|
* dataspace before this function is called.
|
2011-12-22 15:19:25 +00:00
|
|
|
*/
|
2013-03-04 10:26:18 +00:00
|
|
|
void prepare_map_operation() { }
|
2011-12-22 15:19:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Special paging server class
|
|
|
|
*/
|
|
|
|
class Ipc_pager : public Native_capability
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
enum Msg_type { PAGEFAULT, WAKE_UP, PAUSE, EXCEPTION };
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
Native_thread _last; /* origin of last fault */
|
|
|
|
addr_t _pf_addr; /* page-fault address */
|
|
|
|
addr_t _pf_ip; /* ip of faulter */
|
|
|
|
Mapping _reply_mapping; /* page-fault answer */
|
|
|
|
unsigned long _badge; /* badge of faulting thread */
|
|
|
|
Fiasco::l4_msgtag_t _tag; /* receive message tag */
|
|
|
|
Fiasco::l4_exc_regs_t _regs; /* exception registers */
|
|
|
|
Msg_type _type;
|
|
|
|
|
|
|
|
void _parse_msg_type(void);
|
|
|
|
void _parse_exception(void);
|
|
|
|
void _parse_pagefault(void);
|
|
|
|
void _parse(unsigned long label);
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*/
|
|
|
|
Ipc_pager();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Wait for a new page fault received as short message IPC
|
|
|
|
*/
|
|
|
|
void wait_for_fault();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reply current page-fault and wait for a new one
|
|
|
|
*
|
|
|
|
* Send short flex page and wait for next short-message (register)
|
|
|
|
* IPC -- pagefault
|
|
|
|
*/
|
|
|
|
void reply_and_wait_for_fault();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Request instruction pointer of current page fault
|
|
|
|
*/
|
|
|
|
addr_t fault_ip() { return _pf_ip; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Request fault address of current page fault
|
|
|
|
*/
|
|
|
|
addr_t fault_addr() { return _pf_addr & ~3; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set parameters for next reply
|
|
|
|
*/
|
|
|
|
void set_reply_mapping(Mapping m) { _reply_mapping = m; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set destination for next reply
|
|
|
|
*/
|
Fiasco.OC: introduce Cap_index (fixes #149, #112)
This commit introduces a Cap_index class for Fiasco.OC's capabilities.
A Cap_index is a combination of the global capability id, that is used by Genode
to correctly identify a kernel-object, and a corresponding entry in a
protection-domain's (kernel-)capability-space. The cap-indices are non-copyable,
unique objects, that are held in a Cap_map. The Cap_map is used to re-find
capabilities already present in the protection-domain, when a capability is
received via IPC. The retrieval of capabilities effectively fixes issue #112,
meaning the waste of capability-space entries.
Because Cap_index objects are non-copyable (their address indicates the position
in the capability-space of the pd), they are inappropriate to use as
Native_capability. Therefore, Native_capability is implemented as a reference
to Cap_index objects. This design seems to be a good pre-condition to implement
smart-pointers for entries in the capability-space, and thereby closing existing
leaks (please refer to issue #32).
Cap_index, Cap_map, and the allocator for Cap_index objects are designed in a way,
that it should be relatively easy to apply the same concept to NOVA also. By now,
these classes are located in the `base-foc` repository, but they intentionally
contain no Fiasco.OC specific elements.
The previously explained changes had extensive impact on the whole Fiasco.OC
platform implementation, due to various dependencies. The following things had to
be changed:
* The Thread object's startup and destruction routine is re-arranged, to
enable another thread (that calls the Thread destructor) gaining the
capability id of the thread's gate to remove it from the Cap_map, the
thread's UTCB had to be made available to the caller, because there
is the current location of that id. After having the UTCB available
in the Thread object for that reason, the whole thread bootstrapping
could be simplified.
* In the course of changing the Native_capability's semantic, a new Cap_mapping
class was introduced in core, that facilitates the establishment and
destruction of capability mappings between core and it's client's, especially
mappings related to Platform_thread and Platform_task, that are relevant to
task and thread creation and destruction. Thereby, the destruction of
threads had to be reworked, which effectively removed a bug (issue #149)
where some threads weren't destroyed properly.
* In the quick fix for issue #112, something similar to the Cap_map was
introduced available in all processes. Moreover, some kind of a capability
map already existed in core, to handle cap-session request properly. The
introduction of the Cap_map unified both structures, so that the
cap-session component code in core had to be reworked too.
* The platform initialization code had to be changed sligthly due to the
changes in Native_capability
* The vcpu initialization in the L4Linux support library had to be adapted
according to the already mentioned changes in the Thread object's bootstrap
code.
2012-03-15 11:41:24 +00:00
|
|
|
void set_reply_dst(Native_thread t) {
|
|
|
|
_last = t; }
|
2011-12-22 15:19:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Answer call without sending a flex-page mapping
|
|
|
|
*
|
|
|
|
* This function is used to acknowledge local calls from one of
|
|
|
|
* core's region-manager sessions.
|
|
|
|
*/
|
|
|
|
void acknowledge_wakeup();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return thread ID of last faulter
|
|
|
|
*/
|
|
|
|
Native_thread last() const { return _last; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return badge for faulting thread
|
|
|
|
*/
|
|
|
|
unsigned long badge() { return _badge; }
|
|
|
|
|
|
|
|
bool is_write_fault() const { return (_pf_addr & 2); }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return true if last fault was an exception
|
|
|
|
*/
|
|
|
|
bool is_exception() const
|
|
|
|
{
|
|
|
|
return _type == Ipc_pager::EXCEPTION;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the type of ipc we received at last.
|
|
|
|
*/
|
|
|
|
Msg_type msg_type() { return _type; };
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Copy the exception registers from the last exception
|
|
|
|
* to the given thread_state object.
|
|
|
|
*/
|
|
|
|
void copy_regs(Thread_state *state);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* _INCLUDE__BASE__IPC_PAGER_H_ */
|