2014-07-28 16:55:47 +02:00
|
|
|
/*
|
|
|
|
* \brief Kernel backend for protection domains
|
|
|
|
* \author Martin Stein
|
|
|
|
* \author Stefan Kalkowski
|
|
|
|
* \date 2012-11-30
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2012-2013 Genode Labs GmbH
|
|
|
|
*
|
|
|
|
* This file is part of the Genode OS framework, which is distributed
|
|
|
|
* under the terms of the GNU General Public License version 2.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* core includes */
|
|
|
|
#include <kernel/pd.h>
|
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 19:07:09 +02:00
|
|
|
#include <base/log.h>
|
2016-02-11 11:59:31 +01:00
|
|
|
#include <util.h>
|
2014-07-28 16:55:47 +02:00
|
|
|
|
|
|
|
/* Genode includes */
|
2015-06-16 10:59:26 +02:00
|
|
|
#include <assert.h>
|
|
|
|
#include <page_flags.h>
|
2016-01-20 18:27:18 +01:00
|
|
|
|
|
|
|
/* base-internal includes */
|
|
|
|
#include <base/internal/unmanaged_singleton.h>
|
2014-07-28 16:55:47 +02:00
|
|
|
|
|
|
|
using namespace Kernel;
|
|
|
|
|
2015-04-16 11:25:23 +02:00
|
|
|
/* structure of the mode transition */
|
|
|
|
extern int _mt_begin;
|
|
|
|
extern int _mt_end;
|
|
|
|
extern int _mt_user_entry_pic;
|
|
|
|
extern Genode::addr_t _mt_client_context_ptr;
|
|
|
|
extern Genode::addr_t _mt_master_context_begin;
|
|
|
|
extern Genode::addr_t _mt_master_context_end;
|
|
|
|
|
|
|
|
|
|
|
|
size_t Mode_transition_control::_size() {
|
|
|
|
return (addr_t)&_mt_end - (addr_t)&_mt_begin; }
|
|
|
|
|
|
|
|
|
|
|
|
size_t Mode_transition_control::_master_context_size()
|
|
|
|
{
|
|
|
|
addr_t const begin = (addr_t)&_mt_master_context_begin;
|
|
|
|
addr_t const end = (addr_t)&_mt_master_context_end;
|
|
|
|
return end - begin;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
addr_t Mode_transition_control::_virt_user_entry()
|
|
|
|
{
|
|
|
|
addr_t const phys = (addr_t)&_mt_user_entry_pic;
|
|
|
|
addr_t const phys_base = (addr_t)&_mt_begin;
|
|
|
|
return VIRT_BASE + (phys - phys_base);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Mode_transition_control::map(Genode::Translation_table * tt,
|
2015-06-16 10:59:26 +02:00
|
|
|
Genode::Translation_table_allocator * alloc)
|
2015-04-16 11:25:23 +02:00
|
|
|
{
|
|
|
|
try {
|
|
|
|
addr_t const phys_base = (addr_t)&_mt_begin;
|
2016-02-11 11:59:31 +01:00
|
|
|
tt->insert_translation(Genode::trunc_page(VIRT_BASE), phys_base, SIZE,
|
2015-06-16 10:59:26 +02:00
|
|
|
Genode::Page_flags::mode_transition(), alloc);
|
2015-04-16 11:25:23 +02:00
|
|
|
} catch(...) {
|
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 19:07:09 +02:00
|
|
|
Genode::error("inserting exception vector in page table failed!"); }
|
2015-04-16 11:25:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Mode_transition_control::switch_to(Cpu::Context * const context,
|
|
|
|
unsigned const cpu,
|
|
|
|
addr_t const entry_raw,
|
|
|
|
addr_t const context_ptr_base)
|
|
|
|
{
|
|
|
|
/* override client-context pointer of the executing CPU */
|
|
|
|
size_t const context_ptr_offset = cpu * sizeof(context);
|
|
|
|
addr_t const context_ptr = context_ptr_base + context_ptr_offset;
|
|
|
|
*(void * *)context_ptr = context;
|
|
|
|
|
|
|
|
/* call assembly code that applies the virtual-machine context */
|
|
|
|
typedef void (* Entry)();
|
|
|
|
Entry __attribute__((noreturn)) const entry = (Entry)entry_raw;
|
|
|
|
entry();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Mode_transition_control::switch_to_user(Cpu::Context * const context,
|
|
|
|
unsigned const cpu)
|
|
|
|
{
|
|
|
|
switch_to(context, cpu, _virt_user_entry(),
|
|
|
|
(addr_t)&_mt_client_context_ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-16 10:59:26 +02:00
|
|
|
Mode_transition_control::Mode_transition_control() : _master(&_table)
|
2014-07-28 16:55:47 +02:00
|
|
|
{
|
|
|
|
assert(Genode::aligned(this, ALIGN_LOG2));
|
|
|
|
assert(sizeof(_master) <= _master_context_size());
|
|
|
|
assert(_size() <= SIZE);
|
2015-06-16 10:59:26 +02:00
|
|
|
map(&_table, _alloc.alloc());
|
2014-07-28 16:55:47 +02:00
|
|
|
Genode::memcpy(&_mt_master_context_begin, &_master, sizeof(_master));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Mode_transition_control * Kernel::mtc()
|
|
|
|
{
|
|
|
|
typedef Mode_transition_control Control;
|
|
|
|
return unmanaged_singleton<Control, Control::ALIGN>();
|
|
|
|
}
|