mirror of
https://github.com/genodelabs/genode.git
synced 2025-04-08 03:45:24 +00:00
Move context area definition to native_type
This commit is contained in:
parent
62d81ae487
commit
ea38aad30e
@ -15,6 +15,7 @@
|
||||
#define _INCLUDE__BASE__NATIVE_TYPES_H_
|
||||
|
||||
#include <base/native_capability.h>
|
||||
#include <base/stdint.h>
|
||||
|
||||
namespace Codezero {
|
||||
|
||||
@ -115,6 +116,20 @@ namespace Genode {
|
||||
|
||||
typedef Native_capability_tpl<Cap_dst_policy> Native_capability;
|
||||
typedef int Native_connection_state;
|
||||
|
||||
struct Native_config
|
||||
{
|
||||
/**
|
||||
* Thread-context area configuration.
|
||||
*/
|
||||
static addr_t context_area_virtual_base() { return 0x40000000UL; }
|
||||
static addr_t context_area_virtual_size() { return 0x10000000UL; }
|
||||
|
||||
/**
|
||||
* Size of virtual address region holding the context of one thread
|
||||
*/
|
||||
static addr_t context_virtual_size() { return 0x00100000UL; }
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
@ -250,8 +250,8 @@ Platform::Platform() :
|
||||
_core_mem_alloc.virt_alloc()->remove_range(core_virt_beg, core_size);
|
||||
|
||||
/* preserve context area in core's virtual address space */
|
||||
_core_mem_alloc.virt_alloc()->raw()->remove_range(Thread_base::CONTEXT_AREA_VIRTUAL_BASE,
|
||||
Thread_base::CONTEXT_AREA_VIRTUAL_SIZE);
|
||||
_core_mem_alloc.virt_alloc()->raw()->remove_range(Native_config::context_area_virtual_base(),
|
||||
Native_config::context_area_virtual_size());
|
||||
|
||||
/* remove used core memory from physical memory allocator */
|
||||
_core_mem_alloc.phys_alloc()->remove_range(_lma_start, core_size);
|
||||
|
@ -15,6 +15,7 @@
|
||||
#define _INCLUDE__BASE__NATIVE_TYPES_H_
|
||||
|
||||
#include <base/native_capability.h>
|
||||
#include <base/stdint.h>
|
||||
|
||||
namespace Fiasco {
|
||||
#include <l4/sys/types.h>
|
||||
@ -73,6 +74,20 @@ namespace Genode {
|
||||
|
||||
typedef Native_capability_tpl<Cap_dst_policy> Native_capability;
|
||||
typedef Fiasco::l4_threadid_t Native_connection_state;
|
||||
|
||||
struct Native_config
|
||||
{
|
||||
/**
|
||||
* Thread-context area configuration.
|
||||
*/
|
||||
static addr_t context_area_virtual_base() { return 0x40000000UL; }
|
||||
static addr_t context_area_virtual_size() { return 0x10000000UL; }
|
||||
|
||||
/**
|
||||
* Size of virtual address region holding the context of one thread
|
||||
*/
|
||||
static addr_t context_virtual_size() { return 0x00100000UL; }
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* _INCLUDE__BASE__NATIVE_TYPES_H_ */
|
||||
|
@ -391,8 +391,8 @@ void Platform::_setup_basics()
|
||||
_region_alloc.add_range(_vm_start, _vm_size);
|
||||
|
||||
/* preserve context area in core's virtual address space */
|
||||
_region_alloc.remove_range(Thread_base::CONTEXT_AREA_VIRTUAL_BASE,
|
||||
Thread_base::CONTEXT_AREA_VIRTUAL_SIZE);
|
||||
_region_alloc.remove_range(Native_config::context_area_virtual_base(),
|
||||
Native_config::context_area_virtual_size());
|
||||
|
||||
/* I/O memory could be the whole user address space */
|
||||
/* FIXME if the kernel helps to find out max address - use info here */
|
||||
|
@ -2,6 +2,7 @@
|
||||
#define _INCLUDE__BASE__NATIVE_TYPES_H_
|
||||
|
||||
#include <base/cap_map.h>
|
||||
#include <base/stdint.h>
|
||||
|
||||
namespace Fiasco {
|
||||
#include <l4/sys/consts.h>
|
||||
@ -146,6 +147,20 @@ namespace Genode {
|
||||
|
||||
|
||||
typedef int Native_connection_state;
|
||||
|
||||
struct Native_config
|
||||
{
|
||||
/**
|
||||
* Thread-context area configuration.
|
||||
*/
|
||||
static addr_t context_area_virtual_base() { return 0x40000000UL; }
|
||||
static addr_t context_area_virtual_size() { return 0x10000000UL; }
|
||||
|
||||
/**
|
||||
* Size of virtual address region holding the context of one thread
|
||||
*/
|
||||
static addr_t context_virtual_size() { return 0x00100000UL; }
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* _INCLUDE__BASE__NATIVE_TYPES_H_ */
|
||||
|
@ -41,14 +41,14 @@ namespace Genode {
|
||||
|
||||
Thread_base::Context *Thread_base::Context_allocator::base_to_context(addr_t base)
|
||||
{
|
||||
addr_t result = base + CONTEXT_VIRTUAL_SIZE - sizeof(Context);
|
||||
addr_t result = base + Native_config::context_virtual_size() - sizeof(Context);
|
||||
return reinterpret_cast<Context *>(result);
|
||||
}
|
||||
|
||||
|
||||
addr_t Thread_base::Context_allocator::addr_to_base(void *addr)
|
||||
{
|
||||
return ((addr_t)addr) & CONTEXT_VIRTUAL_BASE_MASK;
|
||||
return ((addr_t)addr) & ~(Native_config::context_virtual_size() - 1);
|
||||
}
|
||||
|
||||
|
||||
@ -70,11 +70,11 @@ Thread_base::Context *Thread_base::Context_allocator::alloc(Thread_base *thread_
|
||||
/*
|
||||
* Find slot in context area for the new context
|
||||
*/
|
||||
addr_t base = CONTEXT_AREA_VIRTUAL_BASE;
|
||||
for (; _is_in_use(base); base += CONTEXT_VIRTUAL_SIZE) {
|
||||
addr_t base = Native_config::context_area_virtual_base();
|
||||
for (; _is_in_use(base); base += Native_config::context_virtual_size()) {
|
||||
|
||||
/* check upper bound of context area */
|
||||
if (base >= CONTEXT_AREA_VIRTUAL_BASE + CONTEXT_AREA_VIRTUAL_SIZE)
|
||||
if (base >= Native_config::context_area_virtual_base() + Native_config::context_area_virtual_size())
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -122,7 +122,7 @@ Thread_base::Context *Thread_base::_alloc_context(size_t stack_size)
|
||||
enum { PAGE_SIZE_LOG2 = 12 };
|
||||
size_t ds_size = align_addr(stack_size, PAGE_SIZE_LOG2);
|
||||
|
||||
if (stack_size >= CONTEXT_VIRTUAL_SIZE - sizeof(Native_utcb) - (1 << PAGE_SIZE_LOG2))
|
||||
if (stack_size >= Native_config::context_virtual_size() - sizeof(Native_utcb) - (1 << PAGE_SIZE_LOG2))
|
||||
throw Stack_too_large();
|
||||
|
||||
/*
|
||||
@ -130,7 +130,7 @@ Thread_base::Context *Thread_base::_alloc_context(size_t stack_size)
|
||||
*
|
||||
* The stack is always located at the top of the context.
|
||||
*/
|
||||
addr_t ds_addr = Context_allocator::addr_to_base(context) + CONTEXT_VIRTUAL_SIZE
|
||||
addr_t ds_addr = Context_allocator::addr_to_base(context) + Native_config::context_virtual_size()
|
||||
- ds_size;
|
||||
|
||||
/* add padding for UTCB if defined for the platform */
|
||||
@ -141,7 +141,7 @@ Thread_base::Context *Thread_base::_alloc_context(size_t stack_size)
|
||||
Ram_dataspace_capability ds_cap;
|
||||
try {
|
||||
ds_cap = env_context_area_ram_session()->alloc(ds_size);
|
||||
addr_t attach_addr = ds_addr - CONTEXT_AREA_VIRTUAL_BASE;
|
||||
addr_t attach_addr = ds_addr - Native_config::context_area_virtual_base();
|
||||
env_context_area_rm_session()->attach_at(ds_cap, attach_addr, ds_size);
|
||||
|
||||
} catch (Ram_session::Alloc_failed) {
|
||||
@ -166,7 +166,7 @@ Thread_base::Context *Thread_base::_alloc_context(size_t stack_size)
|
||||
|
||||
void Thread_base::_free_context()
|
||||
{
|
||||
addr_t ds_addr = _context->stack_base - CONTEXT_AREA_VIRTUAL_BASE;
|
||||
addr_t ds_addr = _context->stack_base - Native_config::context_area_virtual_base();
|
||||
Ram_dataspace_capability ds_cap = _context->ds_cap;
|
||||
Genode::env_context_area_rm_session()->detach((void *)ds_addr);
|
||||
Genode::env_context_area_ram_session()->free(ds_cap);
|
||||
|
@ -43,10 +43,14 @@ namespace Genode {
|
||||
enum {
|
||||
THREAD_MAX = (1 << 6),
|
||||
UTCB_AREA_SIZE = (THREAD_MAX * Fiasco::L4_UTCB_OFFSET),
|
||||
UTCB_AREA_START = (Thread_base::CONTEXT_AREA_VIRTUAL_BASE +
|
||||
THREAD_MAX * Thread_base::CONTEXT_VIRTUAL_SIZE)
|
||||
};
|
||||
|
||||
addr_t utcb_area_start()
|
||||
{
|
||||
return (Native_config::context_area_virtual_base() +
|
||||
THREAD_MAX * Native_config::context_virtual_size());
|
||||
}
|
||||
|
||||
Cap_mapping _task;
|
||||
Cap_mapping _parent;
|
||||
Platform_thread *_threads[THREAD_MAX];
|
||||
|
@ -374,8 +374,8 @@ void Platform::_setup_basics()
|
||||
_region_alloc.add_range(_vm_start, _vm_size);
|
||||
|
||||
/* preserve context area in core's virtual address space */
|
||||
_region_alloc.remove_range(Thread_base::CONTEXT_AREA_VIRTUAL_BASE,
|
||||
Thread_base::CONTEXT_AREA_VIRTUAL_SIZE);
|
||||
_region_alloc.remove_range(Native_config::context_area_virtual_base(),
|
||||
Native_config::context_area_virtual_size());
|
||||
|
||||
/* preserve utcb- area in core's virtual address space */
|
||||
_region_alloc.remove_range((addr_t)l4_utcb(), L4_PAGESIZE);
|
||||
|
@ -52,7 +52,7 @@ int Platform_pd::bind_thread(Platform_thread *thread)
|
||||
thread->_utcb = (l4_utcb_t*) (core_utcb_base() + i * L4_UTCB_OFFSET);
|
||||
else
|
||||
thread->_utcb =
|
||||
reinterpret_cast<l4_utcb_t*>(UTCB_AREA_START + i * L4_UTCB_OFFSET);
|
||||
reinterpret_cast<l4_utcb_t*>(utcb_area_start() + i * L4_UTCB_OFFSET);
|
||||
Native_thread cap_offset = THREADS_BASE_CAP + i * THREAD_CAP_SLOT;
|
||||
thread->_gate.remote = cap_offset + THREAD_GATE_CAP;
|
||||
thread->_pager.remote = cap_offset + THREAD_PAGER_CAP;
|
||||
@ -110,7 +110,7 @@ Platform_pd::Platform_pd()
|
||||
for (unsigned i = 0; i < THREAD_MAX; i++)
|
||||
_threads[i] = (Platform_thread*) 0;
|
||||
|
||||
l4_fpage_t utcb_area = l4_fpage(UTCB_AREA_START,
|
||||
l4_fpage_t utcb_area = l4_fpage(utcb_area_start(),
|
||||
log2<unsigned>(UTCB_AREA_SIZE), 0);
|
||||
l4_msgtag_t tag = l4_factory_create_task(L4_BASE_FACTORY_CAP,
|
||||
_task.local.dst(), utcb_area);
|
||||
|
@ -15,6 +15,7 @@
|
||||
#define _INCLUDE__BASE__NATIVE_TYPES_H_
|
||||
|
||||
#include <base/native_capability.h>
|
||||
#include <base/stdint.h>
|
||||
|
||||
namespace Genode {
|
||||
|
||||
@ -31,6 +32,20 @@ namespace Genode {
|
||||
typedef struct { } Native_utcb;
|
||||
typedef int Native_connection_state;
|
||||
typedef Native_capability_tpl<Cap_dst_policy> Native_capability;
|
||||
|
||||
struct Native_config
|
||||
{
|
||||
/**
|
||||
* Thread-context area configuration.
|
||||
*/
|
||||
static addr_t context_area_virtual_base() { return 0x40000000UL; }
|
||||
static addr_t context_area_virtual_size() { return 0x10000000UL; }
|
||||
|
||||
/**
|
||||
* Size of virtual address region holding the context of one thread
|
||||
*/
|
||||
static addr_t context_virtual_size() { return 0x00100000UL; }
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* _INCLUDE__BASE__NATIVE_TYPES_H_ */
|
||||
|
@ -17,6 +17,7 @@
|
||||
/* Genode includes */
|
||||
#include <kernel/syscalls.h>
|
||||
#include <base/native_capability.h>
|
||||
#include <base/stdint.h>
|
||||
|
||||
namespace Genode
|
||||
{
|
||||
@ -136,6 +137,20 @@ namespace Genode
|
||||
addr_t base;
|
||||
size_t size;
|
||||
};
|
||||
|
||||
struct Native_config
|
||||
{
|
||||
/**
|
||||
* Thread-context area configuration.
|
||||
*/
|
||||
static addr_t context_area_virtual_base() { return 0x40000000UL; }
|
||||
static addr_t context_area_virtual_size() { return 0x10000000UL; }
|
||||
|
||||
/**
|
||||
* Size of virtual address region holding the context of one thread
|
||||
*/
|
||||
static addr_t context_virtual_size() { return 0x00100000UL; }
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* _INCLUDE__BASE__NATIVE_TYPES_H_ */
|
||||
|
@ -73,7 +73,8 @@ void Thread_base::start()
|
||||
Ram_dataspace_capability ds = env()->cpu_session()->utcb(_thread_cap);
|
||||
size_t const size = sizeof(_context->utcb);
|
||||
addr_t dst = Context_allocator::addr_to_base(_context) +
|
||||
CONTEXT_VIRTUAL_SIZE - size - CONTEXT_AREA_VIRTUAL_BASE;
|
||||
Native_config::context_virtual_size() - size -
|
||||
Native_config::context_area_virtual_base();
|
||||
env_context_area_rm_session()->attach_at(ds, dst, size);
|
||||
} catch (...) {
|
||||
PERR("%s: Failed to attach UTCB", __PRETTY_FUNCTION__);
|
||||
|
@ -15,6 +15,7 @@
|
||||
#define _INCLUDE__BASE__NATIVE_TYPES_H_
|
||||
|
||||
#include <base/native_capability.h>
|
||||
#include <base/stdint.h>
|
||||
|
||||
/*
|
||||
* We cannot just include <semaphore.h> and <pthread.h> here
|
||||
@ -107,6 +108,24 @@ namespace Genode {
|
||||
|
||||
typedef Native_capability_tpl<Cap_dst_policy> Native_capability;
|
||||
typedef int Native_connection_state; /* socket descriptor */
|
||||
|
||||
struct Native_config
|
||||
{
|
||||
/**
|
||||
* Thread-context area configuration.
|
||||
*
|
||||
* Please update platform-specific files after changing these
|
||||
* values, e.g., 'base-linux/src/platform/context_area.*.ld'.
|
||||
*/
|
||||
static addr_t context_area_virtual_base() { return 0x40000000UL; }
|
||||
static addr_t context_area_virtual_size() { return 0x10000000UL; }
|
||||
|
||||
/**
|
||||
* Size of virtual address region holding the context of one thread
|
||||
*/
|
||||
static addr_t context_virtual_size() { return 0x00100000UL; }
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif /* _INCLUDE__BASE__NATIVE_TYPES_H_ */
|
||||
|
@ -46,7 +46,7 @@ class Context_area_rm_session : public Genode::Rm_session
|
||||
|
||||
/* convert context-area-relative to absolute virtual address */
|
||||
addr_t addr = local_addr;
|
||||
addr += Thread_base::CONTEXT_AREA_VIRTUAL_BASE;
|
||||
addr += Native_config::context_area_virtual_base();
|
||||
|
||||
/* use anonymous mmap for allocating stack backing store */
|
||||
int flags = MAP_FIXED | MAP_ANONYMOUS | MAP_PRIVATE;
|
||||
|
@ -30,8 +30,8 @@ static inline void main_thread_bootstrap()
|
||||
using namespace Genode;
|
||||
|
||||
/* reserve context area */
|
||||
Genode::addr_t base = Thread_base::CONTEXT_AREA_VIRTUAL_BASE;
|
||||
Genode::size_t size = Thread_base::CONTEXT_AREA_VIRTUAL_SIZE;
|
||||
Genode::addr_t base = Native_config::context_area_virtual_base();
|
||||
Genode::size_t size = Native_config::context_area_virtual_size();
|
||||
if (lx_vm_reserve(base, size) != base)
|
||||
PERR("reservation of context area [%lx,%lx) failed",
|
||||
(unsigned long) base, (unsigned long) base + size);
|
||||
|
@ -16,6 +16,7 @@
|
||||
|
||||
#include <kernel/types.h>
|
||||
#include <base/native_capability.h>
|
||||
#include <base/stdint.h>
|
||||
|
||||
namespace Genode {
|
||||
|
||||
@ -42,6 +43,20 @@ namespace Genode {
|
||||
|
||||
typedef Native_capability_tpl<Cap_dst_policy> Native_capability;
|
||||
typedef int Native_connection_state;
|
||||
|
||||
struct Native_config
|
||||
{
|
||||
/**
|
||||
* Thread-context area configuration.
|
||||
*/
|
||||
static addr_t context_area_virtual_base() { return 0x40000000UL; }
|
||||
static addr_t context_area_virtual_size() { return 0x10000000UL; }
|
||||
|
||||
/**
|
||||
* Size of virtual address region holding the context of one thread
|
||||
*/
|
||||
static addr_t context_virtual_size() { return 0x00100000UL; }
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* _INCLUDE__BASE__NATIVE_TYPES_H_ */
|
||||
|
@ -38,7 +38,7 @@ namespace Genode {
|
||||
|
||||
Thread_base::Context *Thread_base::Context_allocator::base_to_context(addr_t base)
|
||||
{
|
||||
addr_t result = base + CONTEXT_VIRTUAL_SIZE - sizeof(Context);
|
||||
addr_t result = base + Native_config::context_virtual_size() - sizeof(Context);
|
||||
return reinterpret_cast<Context *>(result);
|
||||
}
|
||||
|
||||
@ -67,11 +67,11 @@ Thread_base::Context *Thread_base::Context_allocator::alloc(Thread_base *thread_
|
||||
/*
|
||||
* Find slot in context area for the new context
|
||||
*/
|
||||
addr_t base = CONTEXT_AREA_VIRTUAL_BASE;
|
||||
for (; _is_in_use(base); base += CONTEXT_VIRTUAL_SIZE) {
|
||||
addr_t base = Native_config::context_area_virtual_base();
|
||||
for (; _is_in_use(base); base += Native_config::context_virtual_size()) {
|
||||
|
||||
/* check upper bound of context area */
|
||||
if (base >= CONTEXT_AREA_VIRTUAL_BASE + CONTEXT_AREA_VIRTUAL_SIZE)
|
||||
if (base >= Native_config::context_area_virtual_base() + Native_config::context_area_virtual_size())
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -118,7 +118,7 @@ Thread_base::Context *Thread_base::_alloc_context(size_t stack_size)
|
||||
enum { PAGE_SIZE_LOG2 = 12 };
|
||||
size_t ds_size = align_addr(stack_size, PAGE_SIZE_LOG2);
|
||||
|
||||
if (stack_size >= CONTEXT_VIRTUAL_SIZE - sizeof(Native_utcb) - (1 << PAGE_SIZE_LOG2))
|
||||
if (stack_size >= Native_config::context_virtual_size() - sizeof(Native_utcb) - (1 << PAGE_SIZE_LOG2))
|
||||
throw Stack_too_large();
|
||||
|
||||
/*
|
||||
@ -126,7 +126,7 @@ Thread_base::Context *Thread_base::_alloc_context(size_t stack_size)
|
||||
*
|
||||
* The stack is always located at the top of the context.
|
||||
*/
|
||||
addr_t ds_addr = Context_allocator::addr_to_base(context) + CONTEXT_VIRTUAL_SIZE
|
||||
addr_t ds_addr = Context_allocator::addr_to_base(context) + Native_config::context_virtual_size()
|
||||
- ds_size;
|
||||
|
||||
/* add padding for UTCB if defined for the platform */
|
||||
@ -137,7 +137,7 @@ Thread_base::Context *Thread_base::_alloc_context(size_t stack_size)
|
||||
Ram_dataspace_capability ds_cap;
|
||||
try {
|
||||
ds_cap = env_context_area_ram_session()->alloc(ds_size);
|
||||
addr_t attach_addr = ds_addr - CONTEXT_AREA_VIRTUAL_BASE;
|
||||
addr_t attach_addr = ds_addr - Native_config::context_area_virtual_base();
|
||||
env_context_area_rm_session()->attach_at(ds_cap, attach_addr, ds_size);
|
||||
|
||||
} catch (Ram_session::Alloc_failed) {
|
||||
@ -160,7 +160,7 @@ Thread_base::Context *Thread_base::_alloc_context(size_t stack_size)
|
||||
|
||||
void Thread_base::_free_context()
|
||||
{
|
||||
addr_t ds_addr = _context->stack_base - CONTEXT_AREA_VIRTUAL_BASE;
|
||||
addr_t ds_addr = _context->stack_base - Native_config::context_area_virtual_base();
|
||||
Ram_dataspace_capability ds_cap = _context->ds_cap;
|
||||
Genode::env_context_area_rm_session()->detach((void *)ds_addr);
|
||||
Genode::env_context_area_ram_session()->free(ds_cap);
|
||||
@ -183,8 +183,8 @@ Thread_base *Thread_base::myself()
|
||||
* we are the main thread because this condition can never met by any other
|
||||
* thread.
|
||||
*/
|
||||
if (sp < CONTEXT_AREA_VIRTUAL_BASE
|
||||
|| sp >= CONTEXT_AREA_VIRTUAL_BASE + CONTEXT_AREA_VIRTUAL_SIZE)
|
||||
if (sp < Native_config::context_area_virtual_base()
|
||||
|| sp >= Native_config::context_area_virtual_base() + Native_config::context_area_virtual_size())
|
||||
return 0;
|
||||
|
||||
addr_t base = Context_allocator::addr_to_base((void*)sp);
|
||||
|
@ -58,7 +58,7 @@ class Context_area_rm_session : public Rm_session
|
||||
}
|
||||
|
||||
if (!map_local(ds->phys_addr(),
|
||||
(addr_t)local_addr + Thread_base::CONTEXT_AREA_VIRTUAL_BASE,
|
||||
(addr_t)local_addr + Native_config::context_area_virtual_base(),
|
||||
ds->size() >> get_page_size_log2()))
|
||||
return 0;
|
||||
|
||||
|
@ -38,24 +38,35 @@ namespace Genode {
|
||||
|
||||
private:
|
||||
|
||||
enum{
|
||||
CONTEXT_AREA_BASE = Thread_base::CONTEXT_AREA_VIRTUAL_BASE,
|
||||
CONTEXT_AREA_SIZE = Thread_base::CONTEXT_AREA_VIRTUAL_SIZE,
|
||||
CONTEXT_AREA_TOP = CONTEXT_AREA_BASE + CONTEXT_AREA_SIZE,
|
||||
CONTEXT_SIZE = Thread_base::CONTEXT_VIRTUAL_SIZE,
|
||||
CONTEXT_BASE_MASK = Thread_base::CONTEXT_VIRTUAL_BASE_MASK,
|
||||
CONTEXT_OFFSET_MASK = ~CONTEXT_BASE_MASK,
|
||||
|
||||
MAX_CONTEXT_ID = CONTEXT_AREA_SIZE/CONTEXT_SIZE-1
|
||||
};
|
||||
addr_t context_area_base() {
|
||||
return Native_config::context_area_virtual_base();
|
||||
}
|
||||
addr_t context_area_size() {
|
||||
return Native_config::context_area_virtual_size();
|
||||
}
|
||||
addr_t context_area_top() {
|
||||
return context_area_base() + context_area_size();
|
||||
}
|
||||
addr_t context_size() {
|
||||
return Native_config::context_virtual_size();
|
||||
}
|
||||
addr_t context_base_mask() {
|
||||
return ~(Native_config::context_virtual_size() - 1);
|
||||
}
|
||||
addr_t context_offset_mask() {
|
||||
return ~context_base_mask();
|
||||
}
|
||||
addr_t max_context_id {
|
||||
return context_area_size()/context_size()-1;
|
||||
}
|
||||
|
||||
Native_process_id _pid;
|
||||
|
||||
Native_thread_id owner_tid_by_context_id[MAX_CONTEXT_ID+1];
|
||||
Native_thread_id owner_tid_by_context_id[max_context_id()+1];
|
||||
|
||||
void _free_context(Native_thread_id const & t)
|
||||
{
|
||||
for (Context_id cid = 0; cid <= MAX_CONTEXT_ID; cid++) {
|
||||
for (Context_id cid = 0; cid <= max_context_id(); cid++) {
|
||||
if (owner_tid_by_context_id[cid] == t) {
|
||||
owner_tid_by_context_id[cid] = 0;
|
||||
}
|
||||
@ -72,7 +83,7 @@ namespace Genode {
|
||||
{
|
||||
static bool const verbose = false;
|
||||
|
||||
if ((unsigned)User::MAX_THREAD_ID>(unsigned)MAX_CONTEXT_ID) {
|
||||
if ((unsigned)User::MAX_THREAD_ID>(unsigned)max_context_id()) {
|
||||
PERR("More threads allowed than context areas available");
|
||||
return;
|
||||
}
|
||||
@ -99,22 +110,22 @@ namespace Genode {
|
||||
|
||||
bool cid_if_context_address(addr_t a, Context_id* cid)
|
||||
{
|
||||
if (a < CONTEXT_AREA_BASE || a >= CONTEXT_AREA_TOP)
|
||||
if (a < context_area_base() || a >= context_area_top())
|
||||
return false;
|
||||
|
||||
addr_t context_base = a & CONTEXT_BASE_MASK;
|
||||
*cid = (Context_id)((context_base-CONTEXT_AREA_BASE) / CONTEXT_SIZE);
|
||||
addr_t context_base = a & context_base_mask();
|
||||
*cid = (Context_id)((context_base-context_area_base()) / context_size());
|
||||
return true;
|
||||
}
|
||||
|
||||
Context *context(Context_id i)
|
||||
{
|
||||
return (Context*)(CONTEXT_AREA_BASE+(i+1)*CONTEXT_SIZE-sizeof(Context));
|
||||
return (Context*)(context_area_base()+(i+1)*context_size()-sizeof(Context));
|
||||
}
|
||||
|
||||
Context *context_by_tid(Native_thread_id tid)
|
||||
{
|
||||
for (unsigned cid = 0; cid <= MAX_CONTEXT_ID; cid++)
|
||||
for (unsigned cid = 0; cid <= max_context_id(); cid++)
|
||||
if (owner_tid_by_context_id[cid] == tid)
|
||||
return context(cid);
|
||||
|
||||
@ -128,7 +139,7 @@ namespace Genode {
|
||||
if (!cid_if_context_address(a, &cid))
|
||||
return false;
|
||||
|
||||
if (cid > MAX_CONTEXT_ID) {
|
||||
if (cid > max_context_id()) {
|
||||
PERR("Context ID %i out of range", (unsigned int)cid);
|
||||
return false;
|
||||
}
|
||||
@ -142,7 +153,7 @@ namespace Genode {
|
||||
}
|
||||
|
||||
addr_t offset = a & CONTEXT_OFFSET_MASK;
|
||||
Context *context = (Context *)(CONTEXT_SIZE - sizeof(Context));
|
||||
Context *context = (Context *)(context_size() - sizeof(Context));
|
||||
|
||||
if ((void*)offset >= &context->utcb) {
|
||||
*cp = UTCB_AREA;
|
||||
@ -160,7 +171,7 @@ namespace Genode {
|
||||
{
|
||||
static bool const verbose = false;
|
||||
|
||||
if (cid > MAX_CONTEXT_ID)
|
||||
if (cid > max_context_id())
|
||||
return 0;
|
||||
|
||||
if (owner_tid_by_context_id[cid]){
|
||||
@ -182,21 +193,21 @@ namespace Genode {
|
||||
* First thread is assumed to be the main thread and gets last
|
||||
* context-area by convention
|
||||
*/
|
||||
if (!owner_tid_by_context_id[MAX_CONTEXT_ID]){
|
||||
owner_tid_by_context_id[MAX_CONTEXT_ID] = tid;
|
||||
if (!owner_tid_by_context_id[max_context_id()]){
|
||||
owner_tid_by_context_id[max_context_id()] = tid;
|
||||
if (verbose)
|
||||
PDBG("Thread %i owns Context %i (0x%p) of Protection Domain %i",
|
||||
tid, MAX_CONTEXT_ID, context(MAX_CONTEXT_ID), _pid);
|
||||
tid, max_context_id(), context(max_context_id()), _pid);
|
||||
|
||||
return context(MAX_CONTEXT_ID);
|
||||
return context(max_context_id());
|
||||
}
|
||||
|
||||
for (unsigned i = 0; i <= MAX_CONTEXT_ID - 1; i++) {
|
||||
for (unsigned i = 0; i <= max_context_id() - 1; i++) {
|
||||
if (!owner_tid_by_context_id[i]) {
|
||||
owner_tid_by_context_id[i] = tid;
|
||||
if (verbose)
|
||||
PDBG("Thread %i owns Context %i (0x%p) of Protection Domain %i",
|
||||
tid, MAX_CONTEXT_ID, context(MAX_CONTEXT_ID), _pid);
|
||||
tid, max_context_id(), context(max_context_id()), _pid);
|
||||
return context(i);
|
||||
}
|
||||
}
|
||||
@ -236,7 +247,7 @@ namespace Genode {
|
||||
*/
|
||||
void free_context(Context_id const & c)
|
||||
{
|
||||
if (c > MAX_CONTEXT_ID) { return; }
|
||||
if (c > max_context_id()) { return; }
|
||||
owner_tid_by_context_id[c] = Kernel::INVALID_THREAD_ID;
|
||||
}
|
||||
|
||||
|
@ -220,8 +220,8 @@ Genode::Platform::Platform() :
|
||||
_core_mem_alloc.remove_range(img_base, img_size);
|
||||
|
||||
/* Preserve core's context area with page-granularity from allocation */
|
||||
addr_t const ctxt_area_base = trunc_page((addr_t)Thread_base::CONTEXT_AREA_VIRTUAL_BASE);
|
||||
size_t const ctxt_area_size = round_page((addr_t)Thread_base::CONTEXT_AREA_VIRTUAL_BASE);
|
||||
addr_t const ctxt_area_base = trunc_page((addr_t)Native_config::context_area_virtual_base());
|
||||
size_t const ctxt_area_size = round_page((addr_t)Native_config::context_area_virtual_base());
|
||||
_core_mem_alloc.remove_range(ctxt_area_base, ctxt_area_size);
|
||||
|
||||
/* Preserve UART MMIO with page-granularity from allocation */
|
||||
|
@ -43,8 +43,8 @@ static void main_thread_bootstrap()
|
||||
int volatile pid;
|
||||
asm volatile ("mfs %0, rpid" : "=r"(pid) : :);
|
||||
if (pid!=Roottask::PROTECTION_ID) {
|
||||
_main_utcb_addr = (Native_utcb*)((Thread_base::CONTEXT_AREA_VIRTUAL_BASE
|
||||
+ Thread_base::CONTEXT_AREA_VIRTUAL_SIZE)
|
||||
_main_utcb_addr = (Native_utcb*)((Native_config::context_area_virtual_base()
|
||||
+ Native_config::context_area_virtual_size())
|
||||
- sizeof(Native_utcb));
|
||||
}
|
||||
|
||||
|
@ -215,6 +215,21 @@ namespace Genode {
|
||||
};
|
||||
|
||||
typedef int Native_connection_state;
|
||||
|
||||
struct Native_config
|
||||
{
|
||||
/**
|
||||
* Thread-context area configuration.
|
||||
*/
|
||||
static addr_t context_area_virtual_base() { return 0x40000000UL; }
|
||||
static addr_t context_area_virtual_size() { return 0x10000000UL; }
|
||||
|
||||
/**
|
||||
* Size of virtual address region holding the context of one thread
|
||||
*/
|
||||
static addr_t context_virtual_size() { return 0x00100000UL; }
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif /* _INCLUDE__BASE__NATIVE_TYPES_H_ */
|
||||
|
@ -218,7 +218,7 @@ Platform::Platform() :
|
||||
|
||||
/* define core's virtual address space */
|
||||
addr_t virt_beg = get_page_size();
|
||||
addr_t virt_end = Thread_base::CONTEXT_AREA_VIRTUAL_BASE;
|
||||
addr_t virt_end = Native_config::context_area_virtual_base();
|
||||
_core_mem_alloc.virt_alloc()->add_range(virt_beg,
|
||||
virt_end - virt_beg);
|
||||
|
||||
@ -229,8 +229,8 @@ Platform::Platform() :
|
||||
_core_mem_alloc.virt_alloc()->remove_range(core_virt_beg, core_size);
|
||||
|
||||
/* preserve context area in core's virtual address space */
|
||||
_core_mem_alloc.virt_alloc()->remove_range(Thread_base::CONTEXT_AREA_VIRTUAL_BASE,
|
||||
Thread_base::CONTEXT_AREA_VIRTUAL_SIZE);
|
||||
_core_mem_alloc.virt_alloc()->remove_range(Native_config::context_area_virtual_base(),
|
||||
Native_config::context_area_virtual_size());
|
||||
|
||||
/* initialize core's physical-memory and I/O memory allocator */
|
||||
_io_mem_alloc.add_range(0, ~0xfff);
|
||||
|
@ -55,7 +55,6 @@ int Platform_thread::start(void *ip, void *sp)
|
||||
return -2;
|
||||
}
|
||||
|
||||
enum { PD_UTCB = 0x6000000 };
|
||||
_pager->initial_eip((addr_t)ip);
|
||||
if (!_is_main_thread) {
|
||||
addr_t initial_sp = reinterpret_cast<addr_t>(sp);
|
||||
@ -104,7 +103,11 @@ int Platform_thread::start(void *ip, void *sp)
|
||||
* For the first thread of a new PD, use the initial stack pointer for
|
||||
* reporting the thread's UTCB address.
|
||||
*/
|
||||
_pager->initial_esp(PD_UTCB + get_page_size());
|
||||
addr_t pd_utcb = Native_config::context_area_virtual_base() +
|
||||
Native_config::context_area_virtual_size() -
|
||||
get_page_size();
|
||||
|
||||
_pager->initial_esp(pd_utcb + get_page_size());
|
||||
|
||||
_sel_exc_base = cap_selector_allocator()->alloc(NUM_INITIAL_PT_LOG2);
|
||||
|
||||
@ -180,7 +183,7 @@ int Platform_thread::start(void *ip, void *sp)
|
||||
|
||||
/* Create first thread in task */
|
||||
enum { THREAD_GLOBAL = true };
|
||||
res = create_ec(_sel_ec(), pd_sel, _cpu_no, PD_UTCB, 0, 0,
|
||||
res = create_ec(_sel_ec(), pd_sel, _cpu_no, pd_utcb, 0, 0,
|
||||
THREAD_GLOBAL);
|
||||
if (res) {
|
||||
PERR("create_ec returned %d", res);
|
||||
|
@ -15,6 +15,7 @@
|
||||
#define _INCLUDE__BASE__NATIVE_TYPES_H_
|
||||
|
||||
#include <base/native_capability.h>
|
||||
#include <base/stdint.h>
|
||||
|
||||
namespace Okl4 { extern "C" {
|
||||
#include <l4/types.h>
|
||||
@ -88,6 +89,20 @@ namespace Genode {
|
||||
|
||||
typedef Native_capability_tpl<Cap_dst_policy> Native_capability;
|
||||
typedef Okl4::L4_ThreadId_t Native_connection_state;
|
||||
|
||||
struct Native_config
|
||||
{
|
||||
/**
|
||||
* Thread-context area configuration.
|
||||
*/
|
||||
static addr_t context_area_virtual_base() { return 0x40000000UL; }
|
||||
static addr_t context_area_virtual_size() { return 0x10000000UL; }
|
||||
|
||||
/**
|
||||
* Size of virtual address region holding the context of one thread
|
||||
*/
|
||||
static addr_t context_virtual_size() { return 0x00100000UL; }
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* _INCLUDE__BASE__NATIVE_TYPES_H_ */
|
||||
|
@ -264,8 +264,8 @@ Platform::Platform() :
|
||||
_io_port_alloc.add_range(0, 0x10000);
|
||||
|
||||
/* preserve context area in core's virtual address space */
|
||||
_core_mem_alloc.virt_alloc()->remove_range(Thread_base::CONTEXT_AREA_VIRTUAL_BASE,
|
||||
Thread_base::CONTEXT_AREA_VIRTUAL_SIZE);
|
||||
_core_mem_alloc.virt_alloc()->remove_range(Native_config::context_area_virtual_base(),
|
||||
Native_config::context_area_virtual_size());
|
||||
|
||||
_vm_start = 0x1000;
|
||||
_vm_size = 0xb0000000 - 0x1000;
|
||||
|
@ -15,6 +15,7 @@
|
||||
#define _INCLUDE__BASE__NATIVE_TYPES_H_
|
||||
|
||||
#include <base/native_capability.h>
|
||||
#include <base/stdint.h>
|
||||
|
||||
namespace Pistachio {
|
||||
#include <l4/types.h>
|
||||
@ -74,6 +75,20 @@ namespace Genode {
|
||||
typedef Native_capability_tpl<Cap_dst_policy> Native_capability;
|
||||
|
||||
typedef Pistachio::L4_ThreadId_t Native_connection_state;
|
||||
|
||||
struct Native_config
|
||||
{
|
||||
/**
|
||||
* Thread-context area configuration.
|
||||
*/
|
||||
static addr_t context_area_virtual_base() { return 0x40000000UL; }
|
||||
static addr_t context_area_virtual_size() { return 0x10000000UL; }
|
||||
|
||||
/**
|
||||
* Size of virtual address region holding the context of one thread
|
||||
*/
|
||||
static addr_t context_virtual_size() { return 0x00100000UL; }
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* _INCLUDE__BASE__NATIVE_TYPES_H_ */
|
||||
|
@ -515,8 +515,8 @@ void Platform::_setup_basics()
|
||||
/* configure core's virtual memory, exclude KIP, context area */
|
||||
_region_alloc.add_range(_vm_start, _vm_size);
|
||||
_region_alloc.remove_range((addr_t)kip, kip_size);
|
||||
_region_alloc.remove_range(Thread_base::CONTEXT_AREA_VIRTUAL_BASE,
|
||||
Thread_base::CONTEXT_AREA_VIRTUAL_SIZE);
|
||||
_region_alloc.remove_range(Native_config::context_area_virtual_base(),
|
||||
Native_config::context_area_virtual_size());
|
||||
|
||||
/* remove KIP and MBI area from region and IO_MEM allocator */
|
||||
remove_region(Region((addr_t)kip, (addr_t)kip + kip_size), _region_alloc);
|
||||
|
@ -78,21 +78,6 @@ namespace Genode {
|
||||
class Stack_too_large : public Exception { };
|
||||
class Stack_alloc_failed : public Exception { };
|
||||
|
||||
/*
|
||||
* Thread-context area configuration.
|
||||
*
|
||||
* Please update platform-specific files after changing these
|
||||
* values, e.g., 'base-linux/src/platform/context_area.*.ld'.
|
||||
*/
|
||||
enum { CONTEXT_AREA_VIRTUAL_BASE = 0x40000000 };
|
||||
enum { CONTEXT_AREA_VIRTUAL_SIZE = 0x10000000 };
|
||||
|
||||
/**
|
||||
* Size of virtual address region holding the context of one thread
|
||||
*/
|
||||
enum { CONTEXT_VIRTUAL_SIZE = 0x00100000 };
|
||||
enum { CONTEXT_VIRTUAL_BASE_MASK = ~(CONTEXT_VIRTUAL_SIZE - 1) };
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
|
6
base/src/base/env/context_area.cc
vendored
6
base/src/base/env/context_area.cc
vendored
@ -19,12 +19,12 @@
|
||||
struct Context_area_rm_session : Genode::Rm_connection
|
||||
{
|
||||
Context_area_rm_session()
|
||||
: Genode::Rm_connection(0, Genode::Thread_base::CONTEXT_AREA_VIRTUAL_SIZE)
|
||||
: Genode::Rm_connection(0, Genode::Native_config::context_area_virtual_size())
|
||||
{
|
||||
using namespace Genode;
|
||||
|
||||
addr_t local_base = Thread_base::CONTEXT_AREA_VIRTUAL_BASE;
|
||||
size_t size = Thread_base::CONTEXT_AREA_VIRTUAL_SIZE;
|
||||
addr_t local_base = Native_config::context_area_virtual_base();
|
||||
size_t size = Native_config::context_area_virtual_size();
|
||||
|
||||
env()->rm_session()->attach_at(dataspace(), local_base, size);
|
||||
}
|
||||
|
@ -37,14 +37,15 @@ namespace Genode {
|
||||
|
||||
Thread_base::Context *Thread_base::Context_allocator::base_to_context(addr_t base)
|
||||
{
|
||||
addr_t result = base + CONTEXT_VIRTUAL_SIZE - sizeof(Context);
|
||||
addr_t result = base + Native_config::context_virtual_size()
|
||||
- sizeof(Context);
|
||||
return reinterpret_cast<Context *>(result);
|
||||
}
|
||||
|
||||
|
||||
addr_t Thread_base::Context_allocator::addr_to_base(void *addr)
|
||||
{
|
||||
return ((addr_t)addr) & CONTEXT_VIRTUAL_BASE_MASK;
|
||||
return ((addr_t)addr) & ~(Native_config::context_virtual_size() - 1);
|
||||
}
|
||||
|
||||
|
||||
@ -66,11 +67,12 @@ Thread_base::Context *Thread_base::Context_allocator::alloc(Thread_base *thread_
|
||||
/*
|
||||
* Find slot in context area for the new context
|
||||
*/
|
||||
addr_t base = CONTEXT_AREA_VIRTUAL_BASE;
|
||||
for (; _is_in_use(base); base += CONTEXT_VIRTUAL_SIZE) {
|
||||
addr_t base = Native_config::context_area_virtual_base();
|
||||
for (; _is_in_use(base); base += Native_config::context_virtual_size()) {
|
||||
|
||||
/* check upper bound of context area */
|
||||
if (base >= CONTEXT_AREA_VIRTUAL_BASE + CONTEXT_AREA_VIRTUAL_SIZE)
|
||||
if (base >= Native_config::context_area_virtual_base() +
|
||||
Native_config::context_area_virtual_size())
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -118,7 +120,8 @@ Thread_base::Context *Thread_base::_alloc_context(size_t stack_size)
|
||||
enum { PAGE_SIZE_LOG2 = 12 };
|
||||
size_t ds_size = align_addr(stack_size, PAGE_SIZE_LOG2);
|
||||
|
||||
if (stack_size >= CONTEXT_VIRTUAL_SIZE - sizeof(Native_utcb) - (1 << PAGE_SIZE_LOG2))
|
||||
if (stack_size >= Native_config::context_virtual_size() -
|
||||
sizeof(Native_utcb) - (1UL << PAGE_SIZE_LOG2))
|
||||
throw Stack_too_large();
|
||||
|
||||
/*
|
||||
@ -126,8 +129,9 @@ Thread_base::Context *Thread_base::_alloc_context(size_t stack_size)
|
||||
*
|
||||
* The stack is always located at the top of the context.
|
||||
*/
|
||||
addr_t ds_addr = Context_allocator::addr_to_base(context) + CONTEXT_VIRTUAL_SIZE
|
||||
- ds_size;
|
||||
addr_t ds_addr = Context_allocator::addr_to_base(context) +
|
||||
Native_config::context_virtual_size() -
|
||||
ds_size;
|
||||
|
||||
/* add padding for UTCB if defined for the platform */
|
||||
if (sizeof(Native_utcb) >= (1 << PAGE_SIZE_LOG2))
|
||||
@ -137,7 +141,7 @@ Thread_base::Context *Thread_base::_alloc_context(size_t stack_size)
|
||||
Ram_dataspace_capability ds_cap;
|
||||
try {
|
||||
ds_cap = env_context_area_ram_session()->alloc(ds_size);
|
||||
addr_t attach_addr = ds_addr - CONTEXT_AREA_VIRTUAL_BASE;
|
||||
addr_t attach_addr = ds_addr - Native_config::context_area_virtual_base();
|
||||
env_context_area_rm_session()->attach_at(ds_cap, attach_addr, ds_size);
|
||||
|
||||
} catch (Ram_session::Alloc_failed) {
|
||||
@ -158,7 +162,8 @@ Thread_base::Context *Thread_base::_alloc_context(size_t stack_size)
|
||||
|
||||
void Thread_base::_free_context()
|
||||
{
|
||||
addr_t ds_addr = _context->stack_base - CONTEXT_AREA_VIRTUAL_BASE;
|
||||
addr_t ds_addr = _context->stack_base -
|
||||
Native_config::context_area_virtual_base();
|
||||
Ram_dataspace_capability ds_cap = _context->ds_cap;
|
||||
Genode::env_context_area_rm_session()->detach((void *)ds_addr);
|
||||
Genode::env_context_area_ram_session()->free(ds_cap);
|
||||
@ -182,8 +187,9 @@ Thread_base *Thread_base::myself()
|
||||
* thread.
|
||||
*/
|
||||
addr_t sp = (addr_t)(&dummy);
|
||||
if (sp < CONTEXT_AREA_VIRTUAL_BASE
|
||||
|| sp >= CONTEXT_AREA_VIRTUAL_BASE + CONTEXT_AREA_VIRTUAL_SIZE)
|
||||
if (sp < Native_config::context_area_virtual_base() ||
|
||||
sp >= Native_config::context_area_virtual_base() +
|
||||
Native_config::context_area_virtual_size())
|
||||
return 0;
|
||||
|
||||
addr_t base = Context_allocator::addr_to_base(&dummy);
|
||||
|
@ -59,8 +59,8 @@ class Context_area_rm_session : public Rm_session
|
||||
return (addr_t)0;
|
||||
}
|
||||
|
||||
if (!map_local(ds->phys_addr(),
|
||||
(addr_t)local_addr + Thread_base::CONTEXT_AREA_VIRTUAL_BASE,
|
||||
if (!map_local(ds->phys_addr(), (addr_t)local_addr +
|
||||
Native_config::context_area_virtual_base(),
|
||||
ds->size() >> get_page_size_log2()))
|
||||
return (addr_t)0;
|
||||
|
||||
|
@ -15,6 +15,7 @@
|
||||
#include <base/elf.h>
|
||||
#include <base/env.h>
|
||||
#include <base/thread.h>
|
||||
#include <base/native_types.h>
|
||||
#include <dataspace/client.h>
|
||||
#include <rom_session/connection.h>
|
||||
#include <foc_cpu_session/connection.h>
|
||||
@ -125,8 +126,8 @@ static void register_reserved_areas()
|
||||
|
||||
size_t bin_sz = (addr_t)&_prog_img_end - (addr_t)&_prog_img_beg;
|
||||
L4lx::Env::env()->rm()->reserve_range((addr_t)&_prog_img_beg, bin_sz, "Binary");
|
||||
L4lx::Env::env()->rm()->reserve_range(Thread_base::CONTEXT_AREA_VIRTUAL_BASE,
|
||||
Thread_base::CONTEXT_AREA_VIRTUAL_SIZE,
|
||||
L4lx::Env::env()->rm()->reserve_range(Native_config::context_area_virtual_base(),
|
||||
Native_config::context_area_virtual_size(),
|
||||
"Thread Context Area");
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user