2012-08-08 12:23:13 +00:00
|
|
|
/*
|
|
|
|
* \brief Helper code used by core as base framework
|
|
|
|
* \author Alexander Boettcher
|
|
|
|
* \date 2012-08-08
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2013-01-10 20:44:47 +00:00
|
|
|
* Copyright (C) 2012-2013 Genode Labs GmbH
|
2012-08-08 12:23:13 +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 _NOVA__INCLUDE__UTIL_H_
|
|
|
|
#define _NOVA__INCLUDE__UTIL_H_
|
|
|
|
|
|
|
|
#include <base/printf.h>
|
|
|
|
#include <base/thread.h>
|
|
|
|
|
2012-08-03 08:56:08 +00:00
|
|
|
__attribute__((always_inline))
|
|
|
|
inline void nova_die(const char * text = 0)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* If thread is de-constructed the sessions are already gone.
|
|
|
|
* Be careful when enabling printf here.
|
2012-09-28 10:24:14 +00:00
|
|
|
*/
|
|
|
|
while (1)
|
2012-08-03 08:56:08 +00:00
|
|
|
asm volatile ("ud2a" : : "a"(text));
|
|
|
|
}
|
|
|
|
|
2012-11-24 17:27:03 +00:00
|
|
|
|
2013-09-25 09:53:49 +00:00
|
|
|
inline void request_event_portal(Genode::Native_capability const &cap,
|
|
|
|
Genode::addr_t sel, Genode::addr_t event,
|
2013-09-23 08:44:50 +00:00
|
|
|
unsigned short log2_count = 0)
|
2012-08-08 12:23:13 +00:00
|
|
|
{
|
2014-05-27 09:09:58 +00:00
|
|
|
Genode::Thread_base * myself = Genode::Thread_base::myself();
|
|
|
|
Nova::Utcb *utcb = reinterpret_cast<Nova::Utcb *>(myself->utcb());
|
2012-08-08 12:23:13 +00:00
|
|
|
|
|
|
|
/* save original receive window */
|
2014-05-27 09:09:58 +00:00
|
|
|
Nova::Crd orig_crd = utcb->crd_rcv;
|
2012-08-08 12:23:13 +00:00
|
|
|
|
|
|
|
/* request event-handler portal */
|
2014-05-27 09:09:58 +00:00
|
|
|
utcb->crd_rcv = Nova::Obj_crd(sel, log2_count);
|
2012-08-08 12:23:13 +00:00
|
|
|
utcb->msg[0] = event;
|
2013-09-23 08:44:50 +00:00
|
|
|
utcb->msg[1] = log2_count;
|
|
|
|
utcb->set_msg_word(2);
|
2012-08-08 12:23:13 +00:00
|
|
|
|
2014-05-27 09:09:58 +00:00
|
|
|
Genode::uint8_t res = Nova::call(cap.local_name());
|
2012-08-08 12:23:13 +00:00
|
|
|
|
|
|
|
/* restore original receive window */
|
|
|
|
utcb->crd_rcv = orig_crd;
|
2013-09-26 12:31:56 +00:00
|
|
|
|
|
|
|
if (res)
|
|
|
|
PERR("request of event (%lu) capability selector failed", event);
|
2012-08-08 12:23:13 +00:00
|
|
|
}
|
|
|
|
|
2013-09-25 09:53:49 +00:00
|
|
|
|
|
|
|
inline void request_native_ec_cap(Genode::Native_capability const &cap,
|
2014-02-12 15:22:22 +00:00
|
|
|
Genode::addr_t sel, unsigned pager_cap = 1) {
|
|
|
|
request_event_portal(cap, sel , ~0UL, pager_cap); }
|
2013-09-26 12:31:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
inline void request_signal_sm_cap(Genode::Native_capability const &cap,
|
|
|
|
Genode::addr_t sel) {
|
|
|
|
request_event_portal(cap, sel, ~0UL - 1, 0); }
|
2013-09-25 09:53:49 +00:00
|
|
|
|
2013-11-14 09:35:44 +00:00
|
|
|
|
|
|
|
inline void delegate_vcpu_portals(Genode::Native_capability const &cap,
|
|
|
|
Genode::addr_t sel)
|
|
|
|
{
|
2014-05-27 09:09:58 +00:00
|
|
|
Genode::Thread_base * myself = Genode::Thread_base::myself();
|
|
|
|
Nova::Utcb *utcb = reinterpret_cast<Nova::Utcb *>(myself->utcb());
|
2013-11-14 09:35:44 +00:00
|
|
|
|
|
|
|
/* save original receive window */
|
2014-05-27 09:09:58 +00:00
|
|
|
Nova::Crd orig_crd = utcb->crd_rcv;
|
2013-11-14 09:35:44 +00:00
|
|
|
|
2014-05-27 09:09:58 +00:00
|
|
|
Nova::Obj_crd obj_crd(sel, Nova::NUM_INITIAL_VCPU_PT_LOG2);
|
|
|
|
|
|
|
|
utcb->crd_rcv = Nova::Obj_crd();
|
2013-11-14 09:35:44 +00:00
|
|
|
utcb->set_msg_word(0);
|
2014-05-27 09:09:58 +00:00
|
|
|
Genode::uint8_t res = utcb->append_item(obj_crd, 0);
|
2013-11-14 09:35:44 +00:00
|
|
|
(void)res;
|
|
|
|
|
2014-05-27 09:09:58 +00:00
|
|
|
res = Nova::call(cap.local_name());
|
2013-11-14 09:35:44 +00:00
|
|
|
|
|
|
|
/* restore original receive window */
|
|
|
|
utcb->crd_rcv = orig_crd;
|
|
|
|
|
|
|
|
if (res)
|
|
|
|
PERR("setting exception portals for vCPU failed %u", res);
|
|
|
|
}
|
2012-08-08 12:23:13 +00:00
|
|
|
#endif /* _NOVA__INCLUDE__UTIL_H_ */
|