2011-12-22 16:19:25 +01:00
|
|
|
/*
|
|
|
|
* \brief Support code for the thread API
|
|
|
|
* \author Norman Feske
|
|
|
|
* \date 2010-01-13
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2012-01-03 15:35:05 +01:00
|
|
|
* Copyright (C) 2010-2012 Genode Labs GmbH
|
2011-12-22 16:19:25 +01:00
|
|
|
*
|
|
|
|
* This file is part of the Genode OS framework, which is distributed
|
|
|
|
* under the terms of the GNU General Public License version 2.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Genode includes */
|
|
|
|
#include <rm_session/rm_session.h>
|
|
|
|
#include <ram_session/ram_session.h>
|
|
|
|
#include <base/printf.h>
|
|
|
|
#include <base/thread.h>
|
|
|
|
|
|
|
|
/* local includes */
|
|
|
|
#include <platform.h>
|
|
|
|
#include <map_local.h>
|
|
|
|
#include <dataspace_component.h>
|
|
|
|
|
|
|
|
using namespace Genode;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Pointer to dataspace used to hold core contexts
|
|
|
|
*/
|
|
|
|
enum { MAX_CORE_CONTEXTS = 256 };
|
|
|
|
static Dataspace_component *context_ds[MAX_CORE_CONTEXTS];
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Region-manager session for allocating thread contexts
|
|
|
|
*
|
|
|
|
* This class corresponds to the managed dataspace that is normally
|
|
|
|
* used for organizing thread contexts with the thread context area.
|
|
|
|
* It "emulates" the sub address space by adjusting the local address
|
|
|
|
* argument to 'attach' with the offset of the thread context area.
|
|
|
|
*/
|
|
|
|
class Context_area_rm_session : public Rm_session
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Attach backing store to thread-context area
|
|
|
|
*/
|
|
|
|
Local_addr attach(Dataspace_capability ds_cap,
|
|
|
|
size_t size, off_t offset,
|
2012-04-16 18:55:18 +02:00
|
|
|
bool use_local_addr, Local_addr local_addr,
|
|
|
|
bool executable)
|
2011-12-22 16:19:25 +01:00
|
|
|
{
|
2012-03-06 15:55:44 +01:00
|
|
|
Dataspace_component *ds =
|
|
|
|
dynamic_cast<Dataspace_component*>(Dataspace_capability::deref(ds_cap));
|
2011-12-22 16:19:25 +01:00
|
|
|
if (!ds) {
|
|
|
|
PERR("dataspace for core context does not exist");
|
|
|
|
return (addr_t)0;
|
|
|
|
}
|
|
|
|
|
2012-08-29 14:42:56 +02:00
|
|
|
if (!map_local(ds->phys_addr(), (addr_t)local_addr +
|
|
|
|
Native_config::context_area_virtual_base(),
|
2011-12-22 16:19:25 +01:00
|
|
|
ds->size() >> get_page_size_log2()))
|
|
|
|
return (addr_t)0;
|
|
|
|
|
|
|
|
return local_addr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void detach(Local_addr local_addr)
|
|
|
|
{
|
|
|
|
printf("context area detach from 0x%p - not implemented\n",
|
|
|
|
(void *)local_addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
Pager_capability add_client(Thread_capability) {
|
|
|
|
return Pager_capability(); }
|
|
|
|
|
|
|
|
void fault_handler(Signal_context_capability) { }
|
|
|
|
|
|
|
|
State state() { return State(); }
|
|
|
|
|
|
|
|
Dataspace_capability dataspace() { return Dataspace_capability(); }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class Context_area_ram_session : public Ram_session
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2012-06-18 15:20:31 +02:00
|
|
|
Ram_dataspace_capability alloc(size_t size, bool cached)
|
2011-12-22 16:19:25 +01:00
|
|
|
{
|
|
|
|
/* find free context */
|
|
|
|
unsigned i;
|
|
|
|
for (i = 0; i < MAX_CORE_CONTEXTS; i++)
|
|
|
|
if (!context_ds[i])
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (i == MAX_CORE_CONTEXTS) {
|
|
|
|
PERR("maximum number of core contexts (%d) reached", MAX_CORE_CONTEXTS);
|
|
|
|
return Ram_dataspace_capability();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* allocate physical memory */
|
|
|
|
size = round_page(size);
|
|
|
|
void *phys_base;
|
|
|
|
if (!platform_specific()->ram_alloc()->alloc_aligned(size, &phys_base,
|
|
|
|
get_page_size_log2())) {
|
|
|
|
PERR("could not allocate backing store for new context");
|
|
|
|
return Ram_dataspace_capability();
|
|
|
|
}
|
|
|
|
|
|
|
|
context_ds[i] = new (platform()->core_mem_alloc())
|
2012-06-18 15:20:31 +02:00
|
|
|
Dataspace_component(size, 0, (addr_t)phys_base, false, true, 0);
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2012-03-06 15:55:44 +01:00
|
|
|
Dataspace_capability cap = Dataspace_capability::local_cap(context_ds[i]);
|
|
|
|
return static_cap_cast<Ram_dataspace>(cap);
|
2011-12-22 16:19:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void free(Ram_dataspace_capability ds) { PDBG("not yet implemented"); }
|
|
|
|
|
|
|
|
int ref_account(Ram_session_capability ram_session) { return 0; }
|
|
|
|
|
|
|
|
int transfer_quota(Ram_session_capability ram_session, size_t amount) { return 0; }
|
|
|
|
|
|
|
|
size_t quota() { return 0; }
|
|
|
|
|
|
|
|
size_t used() { return 0; }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return single instance of the context-area RM and RAM session
|
|
|
|
*/
|
|
|
|
namespace Genode {
|
|
|
|
|
|
|
|
Rm_session *env_context_area_rm_session()
|
|
|
|
{
|
|
|
|
static Context_area_rm_session inst;
|
|
|
|
return &inst;
|
|
|
|
}
|
|
|
|
|
|
|
|
Ram_session *env_context_area_ram_session()
|
|
|
|
{
|
|
|
|
static Context_area_ram_session inst;
|
|
|
|
return &inst;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|