diff --git a/base-codezero/include/base/native_types.h b/base-codezero/include/base/native_types.h index 3506d913d8..7a5f428e13 100644 --- a/base-codezero/include/base/native_types.h +++ b/base-codezero/include/base/native_types.h @@ -15,6 +15,7 @@ #define _INCLUDE__BASE__NATIVE_TYPES_H_ #include +#include namespace Codezero { @@ -115,6 +116,20 @@ namespace Genode { typedef Native_capability_tpl 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; } + }; } diff --git a/base-codezero/src/core/platform.cc b/base-codezero/src/core/platform.cc index 0886f7c38e..960e0bac18 100644 --- a/base-codezero/src/core/platform.cc +++ b/base-codezero/src/core/platform.cc @@ -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); diff --git a/base-fiasco/include/base/native_types.h b/base-fiasco/include/base/native_types.h index 7016e90f09..26cb3232c8 100644 --- a/base-fiasco/include/base/native_types.h +++ b/base-fiasco/include/base/native_types.h @@ -15,6 +15,7 @@ #define _INCLUDE__BASE__NATIVE_TYPES_H_ #include +#include namespace Fiasco { #include @@ -73,6 +74,20 @@ namespace Genode { typedef Native_capability_tpl 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_ */ diff --git a/base-fiasco/src/core/platform.cc b/base-fiasco/src/core/platform.cc index d6bc8962fe..ac08b03050 100644 --- a/base-fiasco/src/core/platform.cc +++ b/base-fiasco/src/core/platform.cc @@ -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 */ diff --git a/base-foc/include/base/native_types.h b/base-foc/include/base/native_types.h index 2c1ae5d361..6b711dacb2 100644 --- a/base-foc/include/base/native_types.h +++ b/base-foc/include/base/native_types.h @@ -2,6 +2,7 @@ #define _INCLUDE__BASE__NATIVE_TYPES_H_ #include +#include namespace Fiasco { #include @@ -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_ */ diff --git a/base-foc/src/base/thread/thread.cc b/base-foc/src/base/thread/thread.cc index 710f08782c..dc0b20c98f 100644 --- a/base-foc/src/base/thread/thread.cc +++ b/base-foc/src/base/thread/thread.cc @@ -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(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); diff --git a/base-foc/src/core/include/platform_pd.h b/base-foc/src/core/include/platform_pd.h index d422dbc609..be35f028db 100644 --- a/base-foc/src/core/include/platform_pd.h +++ b/base-foc/src/core/include/platform_pd.h @@ -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]; diff --git a/base-foc/src/core/platform.cc b/base-foc/src/core/platform.cc index 5626abee67..ced1d3e5ff 100644 --- a/base-foc/src/core/platform.cc +++ b/base-foc/src/core/platform.cc @@ -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); diff --git a/base-foc/src/core/platform_pd.cc b/base-foc/src/core/platform_pd.cc index 5a8aa20429..f028eaef90 100644 --- a/base-foc/src/core/platform_pd.cc +++ b/base-foc/src/core/platform_pd.cc @@ -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(UTCB_AREA_START + i * L4_UTCB_OFFSET); + reinterpret_cast(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(UTCB_AREA_SIZE), 0); l4_msgtag_t tag = l4_factory_create_task(L4_BASE_FACTORY_CAP, _task.local.dst(), utcb_area); diff --git a/base-host/include/base/native_types.h b/base-host/include/base/native_types.h index 819170aa26..490501b543 100644 --- a/base-host/include/base/native_types.h +++ b/base-host/include/base/native_types.h @@ -15,6 +15,7 @@ #define _INCLUDE__BASE__NATIVE_TYPES_H_ #include +#include namespace Genode { @@ -31,6 +32,20 @@ namespace Genode { typedef struct { } Native_utcb; typedef int Native_connection_state; typedef Native_capability_tpl 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_ */ diff --git a/base-hw/include/base/native_types.h b/base-hw/include/base/native_types.h index 0a7962704d..3594c7f3e1 100644 --- a/base-hw/include/base/native_types.h +++ b/base-hw/include/base/native_types.h @@ -17,6 +17,7 @@ /* Genode includes */ #include #include +#include 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_ */ diff --git a/base-hw/src/base/thread_support.cc b/base-hw/src/base/thread_support.cc index 2d11b8ffc3..d91df41066 100644 --- a/base-hw/src/base/thread_support.cc +++ b/base-hw/src/base/thread_support.cc @@ -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__); diff --git a/base-linux/include/base/native_types.h b/base-linux/include/base/native_types.h index ace87146d4..a39746e7e8 100644 --- a/base-linux/include/base/native_types.h +++ b/base-linux/include/base/native_types.h @@ -15,6 +15,7 @@ #define _INCLUDE__BASE__NATIVE_TYPES_H_ #include +#include /* * We cannot just include and here @@ -107,6 +108,24 @@ namespace Genode { typedef Native_capability_tpl 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_ */ diff --git a/base-linux/src/core/context_area.cc b/base-linux/src/core/context_area.cc index 741e7bc5b4..894ba6ba43 100644 --- a/base-linux/src/core/context_area.cc +++ b/base-linux/src/core/context_area.cc @@ -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; diff --git a/base-linux/src/platform/_main_helper.h b/base-linux/src/platform/_main_helper.h index 0c9c8b720f..b3de48024b 100644 --- a/base-linux/src/platform/_main_helper.h +++ b/base-linux/src/platform/_main_helper.h @@ -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); diff --git a/base-mb/include/base/native_types.h b/base-mb/include/base/native_types.h index 6dbfe51b37..31460a0633 100755 --- a/base-mb/include/base/native_types.h +++ b/base-mb/include/base/native_types.h @@ -16,6 +16,7 @@ #include #include +#include namespace Genode { @@ -42,6 +43,20 @@ namespace Genode { typedef Native_capability_tpl 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_ */ diff --git a/base-mb/src/base/thread/thread.cc b/base-mb/src/base/thread/thread.cc index f06b179754..9eddac2c4f 100644 --- a/base-mb/src/base/thread/thread.cc +++ b/base-mb/src/base/thread/thread.cc @@ -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(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); diff --git a/base-mb/src/core/context_area.cc b/base-mb/src/core/context_area.cc index 48e7b7c2c7..1415a4984c 100644 --- a/base-mb/src/core/context_area.cc +++ b/base-mb/src/core/context_area.cc @@ -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; diff --git a/base-mb/src/core/include/platform_pd.h b/base-mb/src/core/include/platform_pd.h index 3fb36120a3..1de83fdbbd 100755 --- a/base-mb/src/core/include/platform_pd.h +++ b/base-mb/src/core/include/platform_pd.h @@ -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; } diff --git a/base-mb/src/core/platform.cc b/base-mb/src/core/platform.cc index de996ec271..8d38fd617b 100644 --- a/base-mb/src/core/platform.cc +++ b/base-mb/src/core/platform.cc @@ -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 */ diff --git a/base-mb/src/platform/_main_helper.h b/base-mb/src/platform/_main_helper.h index 04fe4a76e8..6d6e2c2e5a 100644 --- a/base-mb/src/platform/_main_helper.h +++ b/base-mb/src/platform/_main_helper.h @@ -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)); } diff --git a/base-nova/include/base/native_types.h b/base-nova/include/base/native_types.h index bf2dc19345..b693fe41c1 100644 --- a/base-nova/include/base/native_types.h +++ b/base-nova/include/base/native_types.h @@ -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_ */ diff --git a/base-nova/src/core/platform.cc b/base-nova/src/core/platform.cc index 3c6bfe3639..1fe7dd2abe 100644 --- a/base-nova/src/core/platform.cc +++ b/base-nova/src/core/platform.cc @@ -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); diff --git a/base-nova/src/core/platform_thread.cc b/base-nova/src/core/platform_thread.cc index 65f1837bdf..719a363a0c 100644 --- a/base-nova/src/core/platform_thread.cc +++ b/base-nova/src/core/platform_thread.cc @@ -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(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); diff --git a/base-okl4/include/base/native_types.h b/base-okl4/include/base/native_types.h index a3684c4204..46995be8da 100644 --- a/base-okl4/include/base/native_types.h +++ b/base-okl4/include/base/native_types.h @@ -15,6 +15,7 @@ #define _INCLUDE__BASE__NATIVE_TYPES_H_ #include +#include namespace Okl4 { extern "C" { #include @@ -88,6 +89,20 @@ namespace Genode { typedef Native_capability_tpl 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_ */ diff --git a/base-okl4/src/core/platform.cc b/base-okl4/src/core/platform.cc index 2ef5a20f7b..2dd13ad905 100644 --- a/base-okl4/src/core/platform.cc +++ b/base-okl4/src/core/platform.cc @@ -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; diff --git a/base-pistachio/include/base/native_types.h b/base-pistachio/include/base/native_types.h index 77e95dd4f7..cf004fbdcb 100644 --- a/base-pistachio/include/base/native_types.h +++ b/base-pistachio/include/base/native_types.h @@ -15,6 +15,7 @@ #define _INCLUDE__BASE__NATIVE_TYPES_H_ #include +#include namespace Pistachio { #include @@ -74,6 +75,20 @@ namespace Genode { typedef Native_capability_tpl 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_ */ diff --git a/base-pistachio/src/core/platform.cc b/base-pistachio/src/core/platform.cc index 37f878eb63..f48cf0cbf5 100644 --- a/base-pistachio/src/core/platform.cc +++ b/base-pistachio/src/core/platform.cc @@ -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); diff --git a/base/include/base/thread.h b/base/include/base/thread.h index b0a75c9675..0fc1780b21 100644 --- a/base/include/base/thread.h +++ b/base/include/base/thread.h @@ -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: /** diff --git a/base/src/base/env/context_area.cc b/base/src/base/env/context_area.cc index 299aa3b38f..6171c6825b 100644 --- a/base/src/base/env/context_area.cc +++ b/base/src/base/env/context_area.cc @@ -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); } diff --git a/base/src/base/thread/thread.cc b/base/src/base/thread/thread.cc index bb8896c9d0..bcb6665e86 100644 --- a/base/src/base/thread/thread.cc +++ b/base/src/base/thread/thread.cc @@ -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(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); diff --git a/base/src/core/context_area.cc b/base/src/core/context_area.cc index b73ff021d5..2128455144 100644 --- a/base/src/core/context_area.cc +++ b/base/src/core/context_area.cc @@ -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; diff --git a/ports-foc/src/lib/l4lx/startup.cc b/ports-foc/src/lib/l4lx/startup.cc index af67e67615..f6f92b9f7d 100644 --- a/ports-foc/src/lib/l4lx/startup.cc +++ b/ports-foc/src/lib/l4lx/startup.cc @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -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"); }