genode/ports/src/app/gdb_monitor/rom.h

127 lines
2.7 KiB
C
Raw Normal View History

2011-12-22 16:19:25 +01:00
/*
* \brief ROM service
* \author Christian Helmuth
* \date 2011-09-16
*/
/*
2013-01-10 21:44:47 +01:00
* Copyright (C) 2011-2013 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.
*/
#ifndef _ROM_H_
#define _ROM_H_
/* Genode includes */
#include <base/service.h>
#include <root/component.h>
#include <rom_session/client.h>
#include <util/arg_string.h>
namespace Gdb_monitor {
using namespace Genode;
/**
* Clone a ROM dataspace in RAM
*/
Capability<Ram_dataspace> clone_rom(Capability<Rom_dataspace> rom_cap)
{
Genode::size_t rom_size = Dataspace_client(rom_cap).size();
Capability<Ram_dataspace> clone_cap = env()->ram_session()->alloc(rom_size);
if (!clone_cap.valid()) {
PERR("%s: memory allocation for cloned dataspace failed", __func__);
return Capability<Ram_dataspace>();
}
void *rom = env()->rm_session()->attach(rom_cap);
void *clone = env()->rm_session()->attach(clone_cap);
memcpy(clone, rom, rom_size);
env()->rm_session()->detach(rom);
env()->rm_session()->detach(clone);
return clone_cap;
}
/**
* ROM session backed by RAM dataspace copy of original ROM
*/
class Rom_session_component : public Rpc_object<Rom_session>
{
private:
Capability<Ram_dataspace> _clone_cap;
public:
Rom_session_component(char const *filename)
: _clone_cap(clone_rom(Rom_connection(filename).dataspace()))
{ }
~Rom_session_component() { env()->ram_session()->free(_clone_cap); }
Capability<Rom_dataspace> dataspace()
{
return static_cap_cast<Rom_dataspace>(
static_cap_cast<Dataspace>(_clone_cap));
}
Support for dynamic ROM sessions, fix #170 This patch introduces support for ROM sessions that update their provided data during the lifetime of the session. The 'Rom_session' interface had been extended with the new 'release()' and 'sigh()' functions, which are needed to support the new protocol. All ROM services have been updated to the new interface. Furthermore, the patch changes the child policy of init with regard to the handling of configuration files. The 'Init::Child' used to always provide the ROM dataspace with the child's config file via a locally implemented ROM service. However, for dynamic ROM sessions, we need to establish a session to the real supplier of the ROM data. This is achieved by using a new 'Child_policy_redirect_rom_file' policy to handle the 'configfile' rather than handling the 'configfile' case entirely within 'Child_config'. To see the new facility in action, the new 'os/run/dynamic_config.run' script provides a simple scenario. The config file of the test program is provided by a service, which generates and updates the config data at regular intervals. In addition, new support has been added to let slaves use dynamic reconfiguration. By using the new 'Child_policy_dynamic_rom_file', the configuration of a slave can be changed dynamically at runtime via the new 'configure()' function. The config is provided as plain null-terminated string (instead of a dataspace capability) because we need to buffer the config data anyway. So there is no benefit of using a dataspace. For buffering configuration data, a 'Ram_session' must be supplied. If no 'Ram_session' is specified at construction time of a 'Slave_policy', no config is supplied to the slave (which is still a common case). An example for dynamically reconfiguring a slave is provided by 'os/run/dynamic_config_slave.run'.
2012-04-04 17:07:19 +02:00
void release() { }
void sigh(Genode::Signal_context_capability) { }
2011-12-22 16:19:25 +01:00
};
class Rom_root : public Root_component<Rom_session_component>
{
protected:
Rom_session_component *_create_session(char const *args)
{
enum { FILENAME_MAX_LEN = 128 };
char filename[FILENAME_MAX_LEN];
Arg_string::find_arg(args, "filename").string(filename, sizeof(filename), "");
return new (md_alloc()) Rom_session_component(filename);
}
public:
Rom_root(Rpc_entrypoint *session_ep,
Allocator *md_alloc)
: Root_component<Rom_session_component>(session_ep, md_alloc)
{ }
};
class Rom_service : public Service
{
private:
Rom_root _root;
public:
Rom_service(Rpc_entrypoint *entrypoint,
Allocator *md_alloc)
: Service("ROM"), _root(entrypoint, md_alloc)
{ }
Capability<Session> session(char const *args, Affinity const &affinity) {
return _root.session(args, affinity); }
2011-12-22 16:19:25 +01:00
void upgrade(Capability<Session>, char const *) { }
void close(Capability<Session> cap) { _root.close(cap); }
};
}
#endif /* _ROM_H_ */