diff --git a/repos/os/src/app/rom_logger/README b/repos/os/src/app/rom_logger/README index 587f625233..f1b75e62ed 100644 --- a/repos/os/src/app/rom_logger/README +++ b/repos/os/src/app/rom_logger/README @@ -3,3 +3,6 @@ ROM dataspace to the LOG. It responds to configuration and ROM-module updates. The name of the ROM module must be specified via the 'rom' attribute of the components '' node. For example: ''. + +The output format may be also be specified via a 'format' attribute. The options are +'text'and 'hexdump', with the former as a default. diff --git a/repos/os/src/app/rom_logger/main.cc b/repos/os/src/app/rom_logger/main.cc index 98a91b0258..89d242c558 100644 --- a/repos/os/src/app/rom_logger/main.cc +++ b/repos/os/src/app/rom_logger/main.cc @@ -12,12 +12,10 @@ */ /* Genode includes */ -#include #include -#include -#include +#include #include -#include +#include #include namespace Rom_logger { struct Main; } @@ -25,7 +23,9 @@ namespace Rom_logger { struct Main; } struct Rom_logger::Main { - Server::Entrypoint &_ep; + Genode::Env &_env; + + Genode::Attached_rom_dataspace _config_rom { _env, "config" }; Genode::Lazy_volatile_object _rom_ds; @@ -42,72 +42,84 @@ struct Rom_logger::Main * Signal handler that is invoked when the configuration or the ROM module * changes. */ - void _handle_update(unsigned); + void _handle_update(); - Genode::Signal_rpc_member
_update_dispatcher = - { _ep, *this, &Main::_handle_update }; + Genode::Signal_handler
_update_handler { + _env.ep(), *this, &Main::_handle_update }; - Main(Server::Entrypoint &ep) : _ep(ep) + Main(Genode::Env &env) : _env(env) { - Genode::config()->sigh(_update_dispatcher); - _handle_update(0); + _config_rom.sigh(_update_handler); + _handle_update(); } }; -void Rom_logger::Main::_handle_update(unsigned) -{ - using Genode::config; +template +inline Genode::Hex mkhex(T value) { + return Genode::Hex(value, Genode::Hex::OMIT_PREFIX, Genode::Hex::PAD); } - config()->reload(); + +void Rom_logger::Main::_handle_update() +{ + _config_rom.update(); /* * Query name of ROM module from config */ Rom_name rom_name; try { - rom_name = config()->xml_node().attribute_value("rom", rom_name); - + _config_rom.xml().attribute("rom").value(&rom_name); } catch (...) { Genode::warning("could not determine ROM name from config"); return; } + typedef Genode::String<8> Format_string; + Format_string format = + _config_rom.xml().attribute_value("format", Format_string("text")); + /* * If ROM name changed, reconstruct '_rom_ds' */ if (rom_name != _rom_name) { _rom_ds.construct(rom_name.string()); - _rom_ds->sigh(_update_dispatcher); + _rom_ds->sigh(_update_handler); _rom_name = rom_name; } + if (!_rom_ds.constructed()) + return; + /* * Update ROM module and print content to LOG */ - if (_rom_ds.constructed()) { - _rom_ds->update(); + _rom_ds->update(); - if (_rom_ds->valid()) { - log("ROM '", _rom_name, "':"); + if (!_rom_ds->valid()) { + Genode::log("ROM '", _rom_name, "' is invalid"); + return; + } - Genode::print_lines<200>(_rom_ds->local_addr(), _rom_ds->size(), - [&] (char const *line) { Genode::log(" ", line); }); - } else { - Genode::log("ROM '", _rom_name, "' is invalid"); - } + log("ROM '", _rom_name, "':"); + + if (format == "text") { + Genode::print_lines<200>(_rom_ds->local_addr(), _rom_ds->size(), + [&] (char const *line) { Genode::log(" ", line); }); + } else if (format == "hexdump") { + short const *data = _rom_ds->local_addr(); + /* dataspaces are always page aligned, therefore multiples of 2*8 bytes */ + Genode::uint32_t const data_len = _rom_ds->size() / sizeof(short); + for (Genode::uint32_t i = 0; i < data_len; i += 8) + log(mkhex(i)," ",mkhex(data[i+0])," ",mkhex(data[i+1]), + " ",mkhex(data[i+2])," ",mkhex(data[i+3]), + " ",mkhex(data[i+4])," ",mkhex(data[i+5]), + " ",mkhex(data[i+6])," ",mkhex(data[i+7])); + } else { + error("unknown format specified by '", _config_rom.xml(),"'"); } } -namespace Server { - - char const *name() { return "ep"; } - - size_t stack_size() { return 4*1024*sizeof(long); } - - void construct(Entrypoint &ep) - { - static Rom_logger::Main main(ep); - } -} +Genode::size_t Component::stack_size() { return 4*1024*sizeof(long); } +void Component::construct(Genode::Env &env) { static Rom_logger::Main main(env); } diff --git a/repos/os/src/app/rom_logger/target.mk b/repos/os/src/app/rom_logger/target.mk index d70ed00854..717ccc85f9 100644 --- a/repos/os/src/app/rom_logger/target.mk +++ b/repos/os/src/app/rom_logger/target.mk @@ -1,3 +1,3 @@ TARGET = rom_logger SRC_CC = main.cc -LIBS = base config server +LIBS = base