2011-12-22 15:19:25 +00:00
|
|
|
/*
|
|
|
|
* \brief Pager framework
|
|
|
|
* \author Norman Feske
|
|
|
|
* \author Sebastian Sumpf
|
2012-08-01 14:16:51 +00:00
|
|
|
* \author Alexander Boettcher
|
2011-12-22 15:19:25 +00:00
|
|
|
* \date 2010-01-25
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2013-01-10 20:44:47 +00:00
|
|
|
* Copyright (C) 2010-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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Genode includes */
|
|
|
|
#include <base/pager.h>
|
|
|
|
#include <base/sleep.h>
|
|
|
|
|
|
|
|
/* NOVA includes */
|
|
|
|
#include <nova/syscalls.h>
|
|
|
|
|
|
|
|
using namespace Genode;
|
|
|
|
using namespace Nova;
|
|
|
|
|
2013-11-26 14:35:53 +00:00
|
|
|
enum { PF_HANDLER_STACK_SIZE = 2 * sizeof(addr_t) * 1024 };
|
2012-08-01 15:04:43 +00:00
|
|
|
extern Genode::addr_t __core_pd_sel;
|
2011-12-22 15:19:25 +00:00
|
|
|
|
2013-01-11 22:10:21 +00:00
|
|
|
|
2012-08-23 09:02:31 +00:00
|
|
|
Utcb * Pager_object::_check_handler(Thread_base *&myself, Pager_object *&obj)
|
|
|
|
{
|
|
|
|
Utcb * utcb;
|
|
|
|
myself = Thread_base::myself();
|
|
|
|
obj = static_cast<Pager_object *>(myself);
|
|
|
|
|
|
|
|
if (!myself || !obj) goto dead;
|
|
|
|
|
|
|
|
utcb = reinterpret_cast<Utcb *>(myself->utcb());
|
|
|
|
if (!utcb) goto dead;
|
|
|
|
|
|
|
|
return utcb;
|
|
|
|
|
|
|
|
dead:
|
|
|
|
|
|
|
|
PERR("unexpected exception-fault for non-existing pager object,"
|
|
|
|
" going to sleep forever");
|
|
|
|
|
2013-09-26 13:16:01 +00:00
|
|
|
if (obj) obj->_state.mark_dead();
|
2012-08-23 09:02:31 +00:00
|
|
|
sleep_forever();
|
|
|
|
}
|
|
|
|
|
2013-01-11 22:10:21 +00:00
|
|
|
|
2011-12-22 15:19:25 +00:00
|
|
|
void Pager_object::_page_fault_handler()
|
|
|
|
{
|
|
|
|
Ipc_pager ipc_pager;
|
|
|
|
ipc_pager.wait_for_fault();
|
|
|
|
|
2012-08-23 09:02:31 +00:00
|
|
|
Thread_base *myself;
|
|
|
|
Pager_object *obj;
|
|
|
|
Utcb *utcb = _check_handler(myself, obj);
|
2011-12-22 15:19:25 +00:00
|
|
|
|
|
|
|
int ret = obj->pager(ipc_pager);
|
|
|
|
|
|
|
|
if (ret) {
|
2013-01-31 10:59:38 +00:00
|
|
|
if (obj->client_recall() != Nova::NOVA_OK) {
|
2013-02-19 10:14:21 +00:00
|
|
|
char client_name[Context::NAME_LEN];
|
|
|
|
myself->name(client_name, sizeof(client_name));
|
|
|
|
|
2013-02-27 10:32:49 +00:00
|
|
|
PWRN("unresolvable page fault since recall failed, '%s' "
|
|
|
|
"address=0x%lx ip=0x%lx", client_name, ipc_pager.fault_addr(),
|
|
|
|
ipc_pager.fault_ip());
|
2013-01-31 10:59:38 +00:00
|
|
|
|
|
|
|
Native_capability pager_obj = obj->Object_pool<Pager_object>::Entry::cap();
|
|
|
|
revoke(pager_obj.dst(), true);
|
|
|
|
|
2013-09-23 07:07:33 +00:00
|
|
|
revoke(Obj_crd(obj->exc_pt_sel_client(), NUM_INITIAL_PT_LOG2), false);
|
2013-01-31 10:59:38 +00:00
|
|
|
|
2013-09-26 13:16:01 +00:00
|
|
|
obj->_state.mark_dead();
|
2013-01-31 10:59:38 +00:00
|
|
|
}
|
2013-02-27 10:32:49 +00:00
|
|
|
|
2013-06-25 08:02:17 +00:00
|
|
|
if (ret == 1) {
|
|
|
|
char client_name[Context::NAME_LEN];
|
|
|
|
myself->name(client_name, sizeof(client_name));
|
|
|
|
|
|
|
|
PDBG("unhandled page fault, '%s' address=0x%lx ip=0x%lx",
|
2013-09-26 12:31:56 +00:00
|
|
|
client_name, ipc_pager.fault_addr(), ipc_pager.fault_ip());
|
2013-06-25 08:02:17 +00:00
|
|
|
}
|
2013-02-27 10:32:49 +00:00
|
|
|
|
2012-06-26 11:43:30 +00:00
|
|
|
utcb->set_msg_word(0);
|
2012-08-22 10:10:04 +00:00
|
|
|
utcb->mtd = 0;
|
2011-12-22 15:19:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ipc_pager.reply_and_wait_for_fault();
|
|
|
|
}
|
|
|
|
|
2013-01-11 22:10:21 +00:00
|
|
|
|
2012-08-23 09:02:31 +00:00
|
|
|
void Pager_object::_exception_handler(addr_t portal_id)
|
|
|
|
{
|
|
|
|
Thread_base *myself;
|
|
|
|
Pager_object *obj;
|
|
|
|
Utcb *utcb = _check_handler(myself, obj);
|
2013-01-16 15:07:04 +00:00
|
|
|
addr_t fault_ip = utcb->ip;
|
2013-11-04 10:05:10 +00:00
|
|
|
uint8_t res = 0xFF;
|
2012-08-23 09:02:31 +00:00
|
|
|
|
2013-09-26 12:31:56 +00:00
|
|
|
if (obj->submit_exception_signal())
|
|
|
|
res = obj->client_recall();
|
|
|
|
|
|
|
|
if (res != NOVA_OK) {
|
2013-02-19 10:14:21 +00:00
|
|
|
char client_name[Context::NAME_LEN];
|
|
|
|
myself->name(client_name, sizeof(client_name));
|
|
|
|
|
2013-09-26 12:31:56 +00:00
|
|
|
PWRN("unresolvable exception at ip 0x%lx, exception portal 0x%lx, %s, "
|
2013-11-04 10:05:10 +00:00
|
|
|
"'%s'", fault_ip,
|
|
|
|
portal_id, res == 0xFF ? "no signal handler" :
|
|
|
|
res == NOVA_OK ? "" : "recall failed",
|
2013-09-26 12:31:56 +00:00
|
|
|
client_name);
|
2013-01-16 15:07:04 +00:00
|
|
|
|
2012-08-23 09:02:31 +00:00
|
|
|
Nova::revoke(Obj_crd(portal_id, 0));
|
2013-09-26 13:16:01 +00:00
|
|
|
obj->_state.mark_dead();
|
2012-08-23 09:02:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
utcb->set_msg_word(0);
|
|
|
|
utcb->mtd = 0;
|
|
|
|
|
|
|
|
reply(myself->stack_top());
|
|
|
|
}
|
|
|
|
|
2013-01-11 22:10:21 +00:00
|
|
|
|
2012-08-24 08:25:24 +00:00
|
|
|
void Pager_object::_recall_handler()
|
|
|
|
{
|
2012-08-23 09:02:31 +00:00
|
|
|
Thread_base *myself;
|
|
|
|
Pager_object *obj;
|
|
|
|
Utcb *utcb = _check_handler(myself, obj);
|
2012-08-24 08:25:24 +00:00
|
|
|
|
|
|
|
obj->_copy_state(utcb);
|
|
|
|
|
|
|
|
obj->_state.thread.ip = utcb->ip;
|
|
|
|
obj->_state.thread.sp = utcb->sp;
|
|
|
|
|
|
|
|
obj->_state.thread.eflags = utcb->flags;
|
|
|
|
obj->_state.thread.trapno = PT_SEL_RECALL;
|
|
|
|
|
2013-09-26 13:16:01 +00:00
|
|
|
obj->_state.mark_valid();
|
2012-08-24 08:25:24 +00:00
|
|
|
|
2013-09-26 13:16:01 +00:00
|
|
|
if (obj->_state.is_client_cancel())
|
|
|
|
if (sm_ctrl(obj->sm_state_notify(), SEMAPHORE_UP) != NOVA_OK)
|
|
|
|
PWRN("notify failed");
|
2012-08-24 08:25:24 +00:00
|
|
|
|
2013-09-26 13:16:01 +00:00
|
|
|
do {
|
|
|
|
if (sm_ctrl(obj->exc_pt_sel() + SM_SEL_EC, SEMAPHORE_DOWNZERO) != NOVA_OK)
|
|
|
|
PWRN("blocking recall handler failed");
|
|
|
|
} while (obj->_state.is_client_cancel());
|
2012-08-24 08:25:24 +00:00
|
|
|
|
2013-09-26 13:16:01 +00:00
|
|
|
obj->_state.mark_invalid();
|
2012-08-24 08:25:24 +00:00
|
|
|
|
2012-08-23 10:43:19 +00:00
|
|
|
bool singlestep_state = obj->_state.thread.eflags & 0x100UL;
|
2013-09-26 13:16:01 +00:00
|
|
|
if (obj->_state.singlestep() && !singlestep_state) {
|
2012-08-23 10:43:19 +00:00
|
|
|
utcb->flags = obj->_state.thread.eflags | 0x100UL;
|
|
|
|
utcb->mtd = Nova::Mtd(Mtd::EFL).value();
|
|
|
|
} else
|
2013-09-26 13:16:01 +00:00
|
|
|
if (!obj->_state.singlestep() && singlestep_state) {
|
2012-12-04 08:49:01 +00:00
|
|
|
utcb->flags = obj->_state.thread.eflags & ~0x100UL;
|
|
|
|
utcb->mtd = Nova::Mtd(Mtd::EFL).value();
|
|
|
|
} else
|
|
|
|
utcb->mtd = 0;
|
2013-09-26 13:16:01 +00:00
|
|
|
|
2012-08-24 08:25:24 +00:00
|
|
|
utcb->set_msg_word(0);
|
2012-12-04 08:49:01 +00:00
|
|
|
|
2012-08-23 09:02:31 +00:00
|
|
|
reply(myself->stack_top());
|
2012-08-24 08:25:24 +00:00
|
|
|
}
|
2011-12-22 15:19:25 +00:00
|
|
|
|
2013-01-11 22:10:21 +00:00
|
|
|
|
2011-12-22 15:19:25 +00:00
|
|
|
void Pager_object::_startup_handler()
|
|
|
|
{
|
2012-08-23 09:02:31 +00:00
|
|
|
Thread_base *myself;
|
|
|
|
Pager_object *obj;
|
|
|
|
Utcb *utcb = _check_handler(myself, obj);
|
2011-12-22 15:19:25 +00:00
|
|
|
|
2012-08-24 08:25:24 +00:00
|
|
|
utcb->ip = obj->_initial_eip;
|
|
|
|
utcb->sp = obj->_initial_esp;
|
2012-08-23 09:02:31 +00:00
|
|
|
|
2011-12-22 15:19:25 +00:00
|
|
|
utcb->mtd = Mtd::EIP | Mtd::ESP;
|
2012-06-26 11:43:30 +00:00
|
|
|
utcb->set_msg_word(0);
|
2012-08-23 09:02:31 +00:00
|
|
|
|
|
|
|
reply(myself->stack_top());
|
2011-12-22 15:19:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Pager_object::_invoke_handler()
|
|
|
|
{
|
2012-08-23 09:02:31 +00:00
|
|
|
Thread_base *myself;
|
|
|
|
Pager_object *obj;
|
|
|
|
Utcb *utcb = _check_handler(myself, obj);
|
2011-12-22 15:19:25 +00:00
|
|
|
|
2013-11-14 09:35:44 +00:00
|
|
|
/* if protocol is violated ignore request and close receive window */
|
|
|
|
if (utcb->msg_words() != 2) {
|
|
|
|
utcb->crd_rcv = Obj_crd();
|
|
|
|
reply(myself->stack_top());
|
|
|
|
}
|
|
|
|
|
2011-12-22 15:19:25 +00:00
|
|
|
/* send single portal as reply */
|
2013-09-23 08:44:50 +00:00
|
|
|
addr_t const event = utcb->msg[0];
|
|
|
|
addr_t const logcount = utcb->msg[1];
|
2013-09-25 09:53:49 +00:00
|
|
|
|
2011-12-22 15:19:25 +00:00
|
|
|
utcb->mtd = 0;
|
2012-06-26 11:43:30 +00:00
|
|
|
utcb->set_msg_word(0);
|
2011-12-22 15:19:25 +00:00
|
|
|
|
2013-09-26 12:31:56 +00:00
|
|
|
/* native ec cap requested */
|
2013-09-25 09:53:49 +00:00
|
|
|
if (event == ~0UL) {
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
bool res = utcb->append_item(Obj_crd(obj->_state.sel_client_ec, 0,
|
|
|
|
Obj_crd::RIGHT_EC_RECALL), 0);
|
2014-02-12 15:22:22 +00:00
|
|
|
/* if logcount > 0 then the pager cap should also be mapped */
|
|
|
|
if (logcount)
|
|
|
|
res = utcb->append_item(Obj_crd(obj->Object_pool<Pager_object>::Entry::cap().local_name(), 0), 1);
|
2013-09-25 09:53:49 +00:00
|
|
|
(void)res;
|
2013-09-26 12:31:56 +00:00
|
|
|
|
2013-09-25 09:53:49 +00:00
|
|
|
reply(myself->stack_top());
|
|
|
|
}
|
|
|
|
|
2013-09-26 12:31:56 +00:00
|
|
|
/* semaphore for signaling thread is requested, reuse PT_SEL_STARTUP. */
|
|
|
|
if (event == ~0UL - 1) {
|
|
|
|
/* create semaphore only once */
|
|
|
|
if (!obj->_state.has_signal_sm()) {
|
|
|
|
|
|
|
|
revoke(Obj_crd(obj->exc_pt_sel_client() + PT_SEL_STARTUP, 0));
|
|
|
|
|
|
|
|
bool res = Nova::create_sm(obj->exc_pt_sel_client() + PT_SEL_STARTUP,
|
|
|
|
__core_pd_sel, 0);
|
|
|
|
if (res != Nova::NOVA_OK)
|
|
|
|
reply(myself->stack_top());
|
|
|
|
|
|
|
|
obj->_state.mark_signal_sm();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool res = utcb->append_item(Obj_crd(obj->exc_pt_sel_client() +
|
|
|
|
PT_SEL_STARTUP, 0), 0);
|
|
|
|
(void)res;
|
|
|
|
|
|
|
|
reply(myself->stack_top());
|
|
|
|
}
|
|
|
|
|
|
|
|
/* sanity check, if event is not valid return nothing */
|
2013-09-23 08:44:50 +00:00
|
|
|
if (logcount > NUM_INITIAL_PT_LOG2 || event > 1UL << NUM_INITIAL_PT_LOG2 ||
|
|
|
|
event + (1UL << logcount) > (1UL << NUM_INITIAL_PT_LOG2))
|
|
|
|
reply(myself->stack_top());
|
2012-08-24 08:25:24 +00:00
|
|
|
|
2013-09-26 12:31:56 +00:00
|
|
|
/* valid event portal is requested, delegate it to caller */
|
2013-09-25 09:53:49 +00:00
|
|
|
bool res = utcb->append_item(Obj_crd(obj->exc_pt_sel_client() + event,
|
|
|
|
logcount), 0);
|
2013-09-23 08:44:50 +00:00
|
|
|
(void)res;
|
2011-12-22 15:19:25 +00:00
|
|
|
|
2012-08-23 09:02:31 +00:00
|
|
|
reply(myself->stack_top());
|
2011-12-22 15:19:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-26 13:16:01 +00:00
|
|
|
void Pager_object::wake_up()
|
|
|
|
{
|
|
|
|
_state.unmark_client_cancel();
|
|
|
|
|
|
|
|
cancel_blocking();
|
|
|
|
}
|
2011-12-22 15:19:25 +00:00
|
|
|
|
2012-08-22 10:10:04 +00:00
|
|
|
|
2013-01-11 22:10:21 +00:00
|
|
|
void Pager_object::client_cancel_blocking()
|
|
|
|
{
|
2013-09-26 13:16:01 +00:00
|
|
|
if (_state.is_client_cancel())
|
|
|
|
return;
|
|
|
|
|
|
|
|
_state.mark_client_cancel();
|
|
|
|
|
2013-09-23 07:07:33 +00:00
|
|
|
uint8_t res = sm_ctrl(exc_pt_sel_client() + SM_SEL_EC, SEMAPHORE_UP);
|
2012-08-24 08:25:24 +00:00
|
|
|
if (res != NOVA_OK)
|
2013-09-26 12:31:56 +00:00
|
|
|
PWRN("canceling blocked client failed (thread sm)");
|
|
|
|
|
|
|
|
if (!_state.has_signal_sm())
|
|
|
|
return;
|
|
|
|
|
|
|
|
res = sm_ctrl(exc_pt_sel_client() + PT_SEL_STARTUP, SEMAPHORE_UP);
|
|
|
|
if (res != NOVA_OK)
|
|
|
|
PWRN("canceling blocked client failed (signal sm)");
|
2012-08-24 08:25:24 +00:00
|
|
|
}
|
2011-12-22 15:19:25 +00:00
|
|
|
|
2012-08-22 10:10:04 +00:00
|
|
|
|
2013-01-11 22:10:21 +00:00
|
|
|
uint8_t Pager_object::client_recall()
|
|
|
|
{
|
2014-01-30 09:19:17 +00:00
|
|
|
return ec_ctrl(EC_RECALL, _state.sel_client_ec);
|
2012-08-22 10:10:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-12-04 08:49:01 +00:00
|
|
|
void Pager_object::cleanup_call()
|
|
|
|
{
|
2013-09-23 07:07:33 +00:00
|
|
|
/* revoke all portals handling the client. */
|
|
|
|
revoke(Obj_crd(exc_pt_sel_client(), NUM_INITIAL_PT_LOG2));
|
2012-12-04 08:49:01 +00:00
|
|
|
|
|
|
|
Utcb *utcb = (Utcb *)Thread_base::myself()->utcb();
|
|
|
|
if (reinterpret_cast<Utcb *>(this->utcb()) == utcb) return;
|
|
|
|
|
|
|
|
/* if pager is blocked wake him up */
|
|
|
|
wake_up();
|
|
|
|
|
|
|
|
utcb->set_msg_word(0);
|
|
|
|
if (uint8_t res = call(_pt_cleanup))
|
|
|
|
PERR("%8p - cleanup call to pager (%8p) failed res=%d",
|
|
|
|
utcb, this->utcb(), res);
|
|
|
|
}
|
|
|
|
|
2013-09-26 12:31:56 +00:00
|
|
|
|
2013-02-22 14:26:43 +00:00
|
|
|
static uint8_t create_portal(addr_t pt, addr_t pd, addr_t ec, Mtd mtd,
|
2013-09-26 12:31:56 +00:00
|
|
|
addr_t eip)
|
2013-02-22 14:26:43 +00:00
|
|
|
{
|
|
|
|
uint8_t res = create_pt(pt, pd, ec, mtd, eip);
|
|
|
|
|
|
|
|
if (res == NOVA_OK)
|
|
|
|
revoke(Obj_crd(pt, 0, Obj_crd::RIGHT_PT_CTRL));
|
|
|
|
|
2013-09-26 12:31:56 +00:00
|
|
|
return res;
|
2013-02-22 14:26:43 +00:00
|
|
|
}
|
2012-12-04 08:49:01 +00:00
|
|
|
|
2013-09-26 12:31:56 +00:00
|
|
|
|
2013-08-07 20:16:58 +00:00
|
|
|
Pager_object::Pager_object(unsigned long badge, Affinity::Location location)
|
2013-11-14 09:35:44 +00:00
|
|
|
:
|
2014-10-16 09:15:46 +00:00
|
|
|
Thread_base(0, "pager:", PF_HANDLER_STACK_SIZE),
|
2013-11-14 09:35:44 +00:00
|
|
|
_badge(reinterpret_cast<unsigned long>(_context->name + 6)),
|
|
|
|
_client_exc_vcpu(Native_thread::INVALID_INDEX)
|
2011-12-22 15:19:25 +00:00
|
|
|
{
|
2012-08-23 09:02:31 +00:00
|
|
|
class Create_exception_pt_failed { };
|
|
|
|
uint8_t res;
|
|
|
|
|
2013-02-19 10:14:21 +00:00
|
|
|
/* construct pager name out of client name */
|
|
|
|
strncpy(_context->name + 6, reinterpret_cast<char const *>(badge),
|
|
|
|
sizeof(_context->name) - 6);
|
|
|
|
|
2012-08-23 09:02:31 +00:00
|
|
|
addr_t pd_sel = __core_pd_sel;
|
2013-09-11 08:45:23 +00:00
|
|
|
_pt_cleanup = cap_map()->insert(1);
|
|
|
|
_client_exc_pt_sel = cap_map()->insert(NUM_INITIAL_PT_LOG2);
|
2013-09-26 13:16:01 +00:00
|
|
|
_state._status = 0;
|
2012-08-23 09:02:31 +00:00
|
|
|
_state.sel_client_ec = Native_thread::INVALID_INDEX;
|
|
|
|
|
2013-09-23 07:07:33 +00:00
|
|
|
if (_pt_cleanup == Native_thread::INVALID_INDEX ||
|
|
|
|
_client_exc_pt_sel == Native_thread::INVALID_INDEX)
|
|
|
|
throw Create_exception_pt_failed();
|
|
|
|
|
2013-07-08 07:06:26 +00:00
|
|
|
/* tell thread starting code on which CPU to let run the pager */
|
2014-01-17 16:22:32 +00:00
|
|
|
reinterpret_cast<Affinity::Location *>(stack_base())[0] = location;
|
2013-08-07 20:16:58 +00:00
|
|
|
|
2012-10-05 12:46:16 +00:00
|
|
|
/* creates local EC */
|
|
|
|
Thread_base::start();
|
|
|
|
|
2013-01-11 22:10:21 +00:00
|
|
|
/* create portal for exception handlers 0x0 - 0xd */
|
2012-08-23 09:02:31 +00:00
|
|
|
for (unsigned i = 0; i < PT_SEL_PAGE_FAULT; i++) {
|
2013-09-23 07:07:33 +00:00
|
|
|
res = create_portal(exc_pt_sel_client() + i, pd_sel, _tid.ec_sel,
|
|
|
|
Mtd(Mtd::EIP), (addr_t)_exception_handler);
|
2012-08-23 09:02:31 +00:00
|
|
|
if (res) {
|
|
|
|
PERR("could not create exception portal, error = %u\n", res);
|
|
|
|
throw Create_exception_pt_failed();
|
|
|
|
}
|
|
|
|
}
|
2011-12-22 15:19:25 +00:00
|
|
|
|
|
|
|
/* create portal for page-fault handler */
|
2013-09-23 07:07:33 +00:00
|
|
|
res = create_portal(exc_pt_sel_client() + PT_SEL_PAGE_FAULT, pd_sel, _tid.ec_sel,
|
2013-02-22 14:26:43 +00:00
|
|
|
Mtd(Mtd::QUAL | Mtd::EIP), (mword_t)_page_fault_handler);
|
2011-12-22 15:19:25 +00:00
|
|
|
if (res) {
|
2012-11-30 15:18:55 +00:00
|
|
|
PERR("could not create page-fault portal, error = %u\n", res);
|
2011-12-22 15:19:25 +00:00
|
|
|
class Create_page_fault_pt_failed { };
|
|
|
|
throw Create_page_fault_pt_failed();
|
|
|
|
}
|
|
|
|
|
2013-01-11 22:10:21 +00:00
|
|
|
/* create portal for exception handlers 0xf - 0x19 */
|
2012-08-23 09:02:31 +00:00
|
|
|
for (unsigned i = PT_SEL_PAGE_FAULT + 1; i < PT_SEL_PARENT; i++) {
|
2013-09-23 07:07:33 +00:00
|
|
|
res = create_portal(exc_pt_sel_client() + i, pd_sel, _tid.ec_sel,
|
|
|
|
Mtd(Mtd::EIP), (addr_t)_exception_handler);
|
2012-08-23 09:02:31 +00:00
|
|
|
if (res) {
|
|
|
|
PERR("could not create exception portal, error = %u\n", res);
|
|
|
|
throw Create_exception_pt_failed();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-22 15:19:25 +00:00
|
|
|
/* create portal for startup handler */
|
2013-09-23 07:07:33 +00:00
|
|
|
res = create_portal(exc_pt_sel_client() + PT_SEL_STARTUP, pd_sel, _tid.ec_sel,
|
2013-02-22 14:26:43 +00:00
|
|
|
Mtd(Mtd::ESP | Mtd::EIP), (mword_t)_startup_handler);
|
2011-12-22 15:19:25 +00:00
|
|
|
if (res) {
|
2012-08-08 12:23:13 +00:00
|
|
|
PERR("could not create startup portal, error = %u\n",
|
2011-12-22 15:19:25 +00:00
|
|
|
res);
|
|
|
|
class Create_startup_pt_failed { };
|
|
|
|
throw Create_startup_pt_failed();
|
|
|
|
}
|
|
|
|
|
2013-01-11 22:10:21 +00:00
|
|
|
/* create portal for recall handler */
|
2012-08-24 08:25:24 +00:00
|
|
|
Mtd mtd(Mtd::ESP | Mtd::EIP | Mtd::ACDB | Mtd::EFL | Mtd::EBSD | Mtd::FSGS);
|
2013-09-23 07:07:33 +00:00
|
|
|
res = create_portal(exc_pt_sel_client() + PT_SEL_RECALL, pd_sel, _tid.ec_sel,
|
2013-02-22 14:26:43 +00:00
|
|
|
mtd, (addr_t)_recall_handler);
|
2012-08-24 08:25:24 +00:00
|
|
|
if (res) {
|
|
|
|
PERR("could not create recall portal, error = %u\n", res);
|
|
|
|
class Create_recall_pt_failed { };
|
|
|
|
throw Create_recall_pt_failed();
|
|
|
|
}
|
|
|
|
|
2013-09-23 07:07:33 +00:00
|
|
|
/*
|
|
|
|
* Create semaphore required for Genode locking. It can be later on
|
|
|
|
* requested by the thread the same way as all exception portals.
|
|
|
|
*/
|
|
|
|
res = Nova::create_sm(exc_pt_sel_client() + SM_SEL_EC, pd_sel, 0);
|
|
|
|
if (res != Nova::NOVA_OK) {
|
|
|
|
class Create_state_notifiy_sm_failed { };
|
|
|
|
throw Create_state_notifiy_sm_failed();
|
|
|
|
}
|
|
|
|
|
2013-01-11 22:10:21 +00:00
|
|
|
/* create portal for final cleanup call used during destruction */
|
2013-02-22 14:26:43 +00:00
|
|
|
res = create_portal(_pt_cleanup, pd_sel, _tid.ec_sel, Mtd(0),
|
|
|
|
reinterpret_cast<addr_t>(_invoke_handler));
|
2012-08-24 08:25:24 +00:00
|
|
|
if (res) {
|
|
|
|
PERR("could not create pager cleanup portal, error = %u\n", res);
|
|
|
|
class Create_cleanup_pt_failed { };
|
|
|
|
throw Create_cleanup_pt_failed();
|
|
|
|
}
|
|
|
|
|
2013-09-23 07:07:33 +00:00
|
|
|
res = Nova::create_sm(sm_state_notify(), pd_sel, 0);
|
2012-08-24 08:25:24 +00:00
|
|
|
if (res != Nova::NOVA_OK) {
|
|
|
|
class Create_state_notifiy_sm_failed { };
|
|
|
|
throw Create_state_notifiy_sm_failed();
|
|
|
|
}
|
2012-06-19 13:54:41 +00:00
|
|
|
}
|
2011-12-22 15:19:25 +00:00
|
|
|
|
2013-01-11 22:10:21 +00:00
|
|
|
|
2011-12-22 15:19:25 +00:00
|
|
|
Pager_object::~Pager_object()
|
|
|
|
{
|
2013-01-16 15:07:04 +00:00
|
|
|
/* if pager is blocked wake him up */
|
2013-09-23 07:07:33 +00:00
|
|
|
sm_ctrl(sm_state_notify(), SEMAPHORE_UP);
|
|
|
|
revoke(Obj_crd(sm_state_notify(), 0));
|
2013-01-16 15:07:04 +00:00
|
|
|
|
2012-12-04 08:49:01 +00:00
|
|
|
/* take care nobody is handled anymore by this object */
|
|
|
|
cleanup_call();
|
2012-06-19 13:54:41 +00:00
|
|
|
|
2013-01-11 22:10:21 +00:00
|
|
|
/* revoke portal used for the cleanup call */
|
2012-08-23 09:02:31 +00:00
|
|
|
revoke(Obj_crd(_pt_cleanup, 0));
|
2012-12-04 08:49:01 +00:00
|
|
|
|
2013-09-11 08:45:23 +00:00
|
|
|
cap_map()->remove(_pt_cleanup, 1, false);
|
|
|
|
cap_map()->remove(exc_pt_sel_client(), NUM_INITIAL_PT_LOG2, false);
|
2013-11-14 09:35:44 +00:00
|
|
|
|
|
|
|
if (_client_exc_vcpu == Native_thread::INVALID_INDEX)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* revoke vCPU exception portals */
|
|
|
|
revoke(Obj_crd(_client_exc_vcpu, NUM_INITIAL_VCPU_PT_LOG2));
|
|
|
|
cap_map()->remove(_client_exc_vcpu, NUM_INITIAL_VCPU_PT_LOG2, false);
|
2011-12-22 15:19:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Pager_capability Pager_entrypoint::manage(Pager_object *obj)
|
|
|
|
{
|
2012-08-08 12:23:13 +00:00
|
|
|
/* request creation of portal bind to pager thread */
|
2012-07-30 08:56:07 +00:00
|
|
|
Native_capability pager_thread_cap(obj->ec_sel());
|
|
|
|
Native_capability cap_session =
|
|
|
|
_cap_session->alloc(pager_thread_cap, obj->handler_address());
|
2011-12-22 15:19:25 +00:00
|
|
|
|
|
|
|
/* add server object to object pool */
|
2012-07-12 07:35:37 +00:00
|
|
|
obj->Object_pool<Pager_object>::Entry::cap(cap_session);
|
2011-12-22 15:19:25 +00:00
|
|
|
insert(obj);
|
|
|
|
|
|
|
|
/* return capability that uses the object id as badge */
|
2012-08-08 12:23:13 +00:00
|
|
|
return reinterpret_cap_cast<Pager_object>(
|
|
|
|
obj->Object_pool<Pager_object>::Entry::cap());
|
2011-12-22 15:19:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Pager_entrypoint::dissolve(Pager_object *obj)
|
|
|
|
{
|
2012-12-04 08:49:01 +00:00
|
|
|
Native_capability pager_obj = obj->Object_pool<Pager_object>::Entry::cap();
|
|
|
|
|
2012-08-08 12:23:13 +00:00
|
|
|
/* cleanup at cap session */
|
2012-12-04 08:49:01 +00:00
|
|
|
_cap_session->free(pager_obj);
|
2012-08-08 12:23:13 +00:00
|
|
|
|
|
|
|
/* cleanup locally */
|
2012-12-04 08:49:01 +00:00
|
|
|
revoke(pager_obj.dst(), true);
|
2012-06-19 13:54:41 +00:00
|
|
|
|
2012-12-14 09:03:55 +00:00
|
|
|
remove_locked(obj);
|
2012-12-04 08:49:01 +00:00
|
|
|
obj->cleanup_call();
|
2011-12-22 15:19:25 +00:00
|
|
|
}
|
|
|
|
|