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.
|
|
|
|
*/
|
|
|
|
|
2016-01-20 19:52:51 +00:00
|
|
|
#ifndef _INCLUDE__NOVA__UTIL_H_
|
|
|
|
#define _INCLUDE__NOVA__UTIL_H_
|
2012-08-08 12:23:13 +00:00
|
|
|
|
base: avoid use of deprecated base/printf.h
Besides adapting the components to the use of base/log.h, the patch
cleans up a few base headers, i.e., it removes unused includes from
root/component.h, specifically base/heap.h and
ram_session/ram_session.h. Hence, components that relied on the implicit
inclusion of those headers have to manually include those headers now.
While adjusting the log messages, I repeatedly stumbled over the problem
that printing char * arguments is ambiguous. It is unclear whether to
print the argument as pointer or null-terminated string. To overcome
this problem, the patch introduces a new type 'Cstring' that allows the
caller to express that the argument should be handled as null-terminated
string. As a nice side effect, with this type in place, the optional len
argument of the 'String' class could be removed. Instead of supplying a
pair of (char const *, size_t), the constructor accepts a 'Cstring'.
This, in turn, clears the way let the 'String' constructor use the new
output mechanism to assemble a string from multiple arguments (and
thereby getting rid of snprintf within Genode in the near future).
To enforce the explicit resolution of the char * ambiguity, the 'char *'
overload of the 'print' function is marked as deleted.
Issue #1987
2016-07-13 17:07:09 +00:00
|
|
|
#include <base/log.h>
|
2012-08-08 12:23:13 +00:00
|
|
|
#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
|
|
|
|
2016-11-30 18:36:32 +00:00
|
|
|
inline void request_event_portal(Genode::addr_t const cap,
|
|
|
|
Genode::addr_t const sel, Genode::addr_t event)
|
2012-08-08 12:23:13 +00:00
|
|
|
{
|
2016-05-04 10:27:17 +00:00
|
|
|
Genode::Thread * myself = Genode::Thread::myself();
|
2014-05-27 09:09:58 +00:00
|
|
|
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 */
|
2016-11-30 18:36:32 +00:00
|
|
|
utcb->crd_rcv = Nova::Obj_crd(sel, 0);
|
2012-08-08 12:23:13 +00:00
|
|
|
utcb->msg[0] = event;
|
2016-11-30 18:36:32 +00:00
|
|
|
utcb->set_msg_word(1);
|
2012-08-08 12:23:13 +00:00
|
|
|
|
2016-11-30 18:36:32 +00:00
|
|
|
Genode::uint8_t res = Nova::call(cap);
|
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)
|
2016-11-30 18:36:32 +00:00
|
|
|
Genode::error("request of event (", Genode::Hex(event), ") ",
|
base: avoid use of deprecated base/printf.h
Besides adapting the components to the use of base/log.h, the patch
cleans up a few base headers, i.e., it removes unused includes from
root/component.h, specifically base/heap.h and
ram_session/ram_session.h. Hence, components that relied on the implicit
inclusion of those headers have to manually include those headers now.
While adjusting the log messages, I repeatedly stumbled over the problem
that printing char * arguments is ambiguous. It is unclear whether to
print the argument as pointer or null-terminated string. To overcome
this problem, the patch introduces a new type 'Cstring' that allows the
caller to express that the argument should be handled as null-terminated
string. As a nice side effect, with this type in place, the optional len
argument of the 'String' class could be removed. Instead of supplying a
pair of (char const *, size_t), the constructor accepts a 'Cstring'.
This, in turn, clears the way let the 'String' constructor use the new
output mechanism to assemble a string from multiple arguments (and
thereby getting rid of snprintf within Genode in the near future).
To enforce the explicit resolution of the char * ambiguity, the 'char *'
overload of the 'print' function is marked as deleted.
Issue #1987
2016-07-13 17:07:09 +00:00
|
|
|
"capability selector failed (res=", res, ")");
|
2012-08-08 12:23:13 +00:00
|
|
|
}
|
|
|
|
|
2013-09-25 09:53:49 +00:00
|
|
|
|
2016-11-30 18:36:32 +00:00
|
|
|
inline void request_native_ec_cap(Genode::addr_t const cap,
|
|
|
|
Genode::addr_t const sel)
|
2014-09-05 15:00:31 +00:00
|
|
|
{
|
2016-11-30 18:36:32 +00:00
|
|
|
request_event_portal(cap, sel , ~0UL);
|
2014-09-05 15:00:31 +00:00
|
|
|
}
|
2013-09-26 12:31:56 +00:00
|
|
|
|
|
|
|
|
2016-11-30 18:36:32 +00:00
|
|
|
inline void request_signal_sm_cap(Genode::addr_t const cap,
|
2014-09-05 15:00:31 +00:00
|
|
|
Genode::addr_t const sel)
|
|
|
|
{
|
2016-11-30 18:36:32 +00:00
|
|
|
request_event_portal(cap, sel, ~0UL - 1);
|
2014-09-05 15:00:31 +00:00
|
|
|
}
|
2013-09-25 09:53:49 +00:00
|
|
|
|
2013-11-14 09:35:44 +00:00
|
|
|
|
2016-11-30 18:36:32 +00:00
|
|
|
inline void translate_remote_pager(Genode::addr_t const cap,
|
2016-11-24 20:57:33 +00:00
|
|
|
Genode::addr_t const sel)
|
2013-11-14 09:35:44 +00:00
|
|
|
{
|
2016-05-04 10:27:17 +00:00
|
|
|
Genode::Thread * myself = Genode::Thread::myself();
|
2014-05-27 09:09:58 +00:00
|
|
|
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
|
|
|
utcb->crd_rcv = Nova::Obj_crd();
|
2013-11-14 09:35:44 +00:00
|
|
|
|
2014-09-05 15:00:31 +00:00
|
|
|
Genode::uint8_t res = Nova::NOVA_OK;
|
|
|
|
enum {
|
2016-11-24 20:57:33 +00:00
|
|
|
TRANSLATE = true, THIS_PD = false, NON_GUEST = false, HOTSPOT = 0
|
2014-09-05 15:00:31 +00:00
|
|
|
};
|
|
|
|
|
2016-11-24 20:57:33 +00:00
|
|
|
/* translate one item */
|
|
|
|
utcb->msg[0] = 0xaffe;
|
|
|
|
utcb->set_msg_word(1);
|
2014-09-05 15:00:31 +00:00
|
|
|
|
2016-11-24 20:57:33 +00:00
|
|
|
Nova::Obj_crd obj_crd(sel, 0);
|
|
|
|
if (utcb->append_item(obj_crd, HOTSPOT, THIS_PD, NON_GUEST, TRANSLATE))
|
2014-09-05 15:00:31 +00:00
|
|
|
/* trigger the translation */
|
2016-11-30 18:36:32 +00:00
|
|
|
res = Nova::call(cap);
|
2013-11-14 09:35:44 +00:00
|
|
|
|
|
|
|
/* restore original receive window */
|
|
|
|
utcb->crd_rcv = orig_crd;
|
|
|
|
|
2016-11-24 20:57:33 +00:00
|
|
|
if (res != Nova::NOVA_OK)
|
base: avoid use of deprecated base/printf.h
Besides adapting the components to the use of base/log.h, the patch
cleans up a few base headers, i.e., it removes unused includes from
root/component.h, specifically base/heap.h and
ram_session/ram_session.h. Hence, components that relied on the implicit
inclusion of those headers have to manually include those headers now.
While adjusting the log messages, I repeatedly stumbled over the problem
that printing char * arguments is ambiguous. It is unclear whether to
print the argument as pointer or null-terminated string. To overcome
this problem, the patch introduces a new type 'Cstring' that allows the
caller to express that the argument should be handled as null-terminated
string. As a nice side effect, with this type in place, the optional len
argument of the 'String' class could be removed. Instead of supplying a
pair of (char const *, size_t), the constructor accepts a 'Cstring'.
This, in turn, clears the way let the 'String' constructor use the new
output mechanism to assemble a string from multiple arguments (and
thereby getting rid of snprintf within Genode in the near future).
To enforce the explicit resolution of the char * ambiguity, the 'char *'
overload of the 'print' function is marked as deleted.
Issue #1987
2016-07-13 17:07:09 +00:00
|
|
|
Genode::error("setting exception portals for vCPU failed res=", res);
|
2013-11-14 09:35:44 +00:00
|
|
|
}
|
2016-01-20 19:52:51 +00:00
|
|
|
#endif /* _INCLUDE__NOVA__UTIL_H_ */
|