core: simplify Rom_module and Rom_fs

* replace print_fs with Output::print equivalent
* use Avl_tree::for_each instead of own implementation
* extend constness

Ref #2159
This commit is contained in:
Stefan Kalkowski 2016-11-02 13:29:50 +01:00 committed by Christian Helmuth
parent e1ec39e476
commit f60cf697d2
9 changed files with 70 additions and 123 deletions

View File

@ -315,6 +315,10 @@ static Fiasco::l4_kernel_info_t *get_kip()
{
using namespace Fiasco;
static l4_kernel_info_t *kip = nullptr;
if (kip) return kip;
int err;
/* region allocator is not setup yet */
@ -345,7 +349,7 @@ static Fiasco::l4_kernel_info_t *get_kip()
panic("kip mapping failed");
/* store mapping base from received mapping */
l4_kernel_info_t *kip = (l4_kernel_info_t *)dw0;
kip = (l4_kernel_info_t *)dw0;
if (kip->magic != L4_KERNEL_INFO_MAGIC)
panic("Sigma0 mapped something but not the KIP");
@ -360,7 +364,6 @@ void Platform::_setup_basics()
l4_kernel_info_t * kip = get_kip();
/* add KIP as ROM module */
_kip_rom = Rom_module((addr_t)kip, L4_PAGESIZE, "l4v2_kip");
_rom_fs.insert(&_kip_rom);
/* parse memory descriptors - look for virtual memory configuration */
@ -423,7 +426,8 @@ void Platform::_setup_rom()
Platform::Platform() :
_ram_alloc(nullptr), _io_mem_alloc(core_mem_alloc()),
_io_port_alloc(core_mem_alloc()), _irq_alloc(core_mem_alloc()),
_region_alloc(core_mem_alloc())
_region_alloc(core_mem_alloc()),
_kip_rom((addr_t)get_kip(), L4_PAGESIZE, "l4v2_kip")
{
/*
* We must be single-threaded at this stage and so this is safe.
@ -445,7 +449,7 @@ Platform::Platform() :
log(":io_mem: ", _io_mem_alloc);
log(":io_port: ", _io_port_alloc);
log(":irq: ", _irq_alloc);
log(":rom_fs: "); _rom_fs.print_fs();
log(":rom_fs: ", _rom_fs);
log(":core ranges: ", _core_address_ranges);
Fiasco::l4_threadid_t myself = Fiasco::l4_myself();

View File

@ -41,8 +41,6 @@ namespace Fiasco {
#include <l4/sys/types.h>
#include <l4/sys/utcb.h>
#include <l4/sys/scheduler.h>
static l4_kernel_info_t *kip;
}
using namespace Genode;
@ -253,6 +251,10 @@ static Fiasco::l4_kernel_info_t *sigma0_map_kip()
{
using namespace Fiasco;
static l4_kernel_info_t *kip = nullptr;
if (kip) return kip;
/* signal we want to map the KIP */
l4_utcb_mr()->mr[0] = SIGMA0_REQ_KIP;
@ -273,8 +275,9 @@ static Fiasco::l4_kernel_info_t *sigma0_map_kip()
if (!ret)
panic("kip mapping failed");
return (l4_kernel_info_t*) ret;
else
kip = (l4_kernel_info_t*) ret;
return kip;
}
@ -343,7 +346,7 @@ void Platform::_setup_basics()
{
using namespace Fiasco;
kip = sigma0_map_kip();
l4_kernel_info_t * kip = sigma0_map_kip();
if (kip->magic != L4_KERNEL_INFO_MAGIC)
panic("Sigma0 mapped something but not the KIP");
@ -354,7 +357,6 @@ void Platform::_setup_basics()
log(" version: ", Hex(kip->version));
/* add KIP as ROM module */
_kip_rom = Rom_module((addr_t)kip, L4_PAGESIZE, "l4v2_kip");
_rom_fs.insert(&_kip_rom);
/* update multi-boot info pointer from KIP */
@ -418,10 +420,6 @@ void Platform::_setup_rom()
Rom_module(header->base, header->size, (const char*)header->name);
_rom_fs.insert(rom);
}
Rom_module *kip_rom = new(core_mem_alloc())
Rom_module((addr_t)Fiasco::kip, L4_PAGESIZE, "kip");
_rom_fs.insert(kip_rom);
}
@ -429,6 +427,7 @@ Platform::Platform() :
_ram_alloc(nullptr), _io_mem_alloc(core_mem_alloc()),
_io_port_alloc(core_mem_alloc()), _irq_alloc(core_mem_alloc()),
_region_alloc(core_mem_alloc()), _cap_id_alloc(core_mem_alloc()),
_kip_rom(Rom_module((addr_t)sigma0_map_kip(), L4_PAGESIZE, "l4v2_kip")),
_sigma0(cap_map()->insert(_cap_id_alloc.alloc(), Fiasco::L4_BASE_PAGER_CAP))
{
/*
@ -451,7 +450,7 @@ Platform::Platform() :
log(":io_mem: ", _io_mem_alloc);
log(":io_port: ", _io_port_alloc);
log(":irq: ", _irq_alloc);
log(":rom_fs: "); _rom_fs.print_fs();
log(":rom_fs: ", _rom_fs);
log(":core ranges: ", _core_address_ranges());
Core_cap_index* pdi =

View File

@ -152,7 +152,7 @@ Platform::Platform()
log(":io_mem_alloc: ", _io_mem_alloc);
log(":io_port_alloc: ", _io_port_alloc);
log(":irq_alloc: ", _irq_alloc);
log(":rom_fs: "); _rom_fs.print_fs();
log(":rom_fs: ", _rom_fs);
}

View File

@ -631,7 +631,7 @@ Platform::Platform() :
log(":virt_alloc: ", *_core_mem_alloc.virt_alloc());
log(":phys_alloc: ", *_core_mem_alloc.phys_alloc());
log(":io_mem_alloc: ", _io_mem_alloc);
log(":rom_fs: "); _rom_fs.print_fs();
log(":rom_fs: ", _rom_fs);
}
/* add capability selector ranges to map */

View File

@ -190,7 +190,7 @@ Platform::Platform() :
log(":io_mem: ", _io_mem_alloc);
log(":io_port: ", _io_port_alloc);
log(":irq: ", _irq_alloc);
log(":rom_fs: "); _rom_fs.print_fs();
log(":rom_fs: ", _rom_fs);
/* setup task object for core task */
_core_pd = new(core_mem_alloc()) Platform_pd(true);

View File

@ -471,20 +471,6 @@ void Platform::_setup_preemption()
}
static Pistachio::L4_KernelInterfacePage_t *init_kip()
{
using namespace Pistachio;
/* completely map program image */
addr_t beg = trunc_page((addr_t)&_prog_img_beg);
addr_t end = round_page((addr_t)&_prog_img_end);
for ( ; beg < end; beg += Pistachio::get_page_size())
L4_Sigma0_GetPage(get_sigma0(), L4_Fpage(beg, Pistachio::get_page_size()));
return get_kip();
}
void Platform::_setup_basics()
{
using namespace Pistachio;
@ -506,7 +492,6 @@ void Platform::_setup_basics()
dump_kip_memdesc(kip);
/* add KIP as ROM module */
_kip_rom = Rom_module((addr_t)kip, sizeof(L4_KernelInterfacePage_t), "pistachio_kip");
_rom_fs.insert(&_kip_rom);
// Get virtual bootinfo address.
@ -606,7 +591,9 @@ Platform_pd *Platform::core_pd()
Platform::Platform() :
_ram_alloc(nullptr), _io_mem_alloc(core_mem_alloc()),
_io_port_alloc(core_mem_alloc()), _irq_alloc(core_mem_alloc()),
_region_alloc(core_mem_alloc())
_region_alloc(core_mem_alloc()),
_kip_rom((addr_t)Pistachio::get_kip(),
sizeof(Pistachio::L4_KernelInterfacePage_t), "pistachio_kip")
{
/*
* We must be single-threaded at this stage and so this is safe.
@ -635,7 +622,7 @@ Platform::Platform() :
log(":io_mem: ", _io_mem_alloc);
log(":io_port: ", _io_port_alloc);
log(":irq: ", _irq_alloc);
log(":rom_fs: "); _rom_fs.print_fs();
log(":rom_fs: ", _rom_fs);
log(":core ranges: ", _core_address_ranges);
}

View File

@ -1,11 +1,12 @@
/**
* \brief Read-only memory modules
* \author Christian Helmuth
* \author Stefan Kalkowski
* \date 2006-05-15
*/
/*
* Copyright (C) 2006-2013 Genode Labs GmbH
* Copyright (C) 2006-2016 Genode Labs GmbH
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU General Public License version 2.
@ -14,92 +15,48 @@
#ifndef _CORE__INCLUDE__ROM_FS_H_
#define _CORE__INCLUDE__ROM_FS_H_
#include <base/stdint.h>
#include <base/log.h>
#include <util/avl_tree.h>
#include <base/output.h>
#include <util/avl_string.h>
namespace Genode {
/**
* Convert module command line to module base name
*
* The conversion is performed in place. The returned
* pointer refers to a substring of the 'name' argument.
*/
inline char *commandline_to_basename(char *name)
{
for (char *c = name; *c != 0; c++) {
if (*c == '/') name = c + 1;
if (*c == ' ') {
*c = 0;
break;
}
}
return name;
}
class Rom_module : public Avl_string_base
{
private:
/* Location of module in memory and size */
addr_t _addr;
size_t _size;
public:
/** Standard constructor creates invalid object */
Rom_module()
: Avl_string_base(0), _addr(0), _size(0) { }
Rom_module(addr_t addr, size_t size, const char *name)
: Avl_string_base(name), _addr(addr), _size(size) { }
/** Check validity */
bool valid() { return _size ? true : false; }
/** Accessor functions */
addr_t addr() const { return _addr; }
size_t size() const { return _size; }
void print(Output &out) const
{
Genode::print(out, Hex_range<addr_t>(_addr, _size), " ", name());
}
};
class Rom_fs : public Avl_tree<Avl_string_base>
{
public:
Rom_module * find(const char *name)
{
return first() ? (Rom_module *)first()->find_by_name(name) : 0;
}
/* DEBUG */
void print_fs(Rom_module *r = 0)
{
if (!r) {
Rom_module *first_module = (Rom_module *)first();
if (first_module) {
log("ROM modules:");
print_fs(first_module);
} else {
log("No modules in Rom_fs ", this);
}
} else {
log(" ROM: ", Hex_range<addr_t>(r->addr(), r->size()), " ",
r->name());
Rom_module *child;
if ((child = (Rom_module *)r->child(Rom_module::LEFT))) print_fs(child);
if ((child = (Rom_module *)r->child(Rom_module::RIGHT))) print_fs(child);
}
}
};
struct Rom_module;
struct Rom_fs;
}
struct Genode::Rom_module : Genode::Avl_string_base
{
addr_t const addr = 0;
size_t const size = 0;
Rom_module() : Avl_string_base(nullptr) { }
Rom_module(addr_t const addr, size_t const size, char const * const name)
: Avl_string_base(name), addr(addr), size(size) { }
bool valid() const { return size ? true : false; }
void print(Genode::Output & out) const {
Genode::print(out, Hex_range<addr_t>(addr, size), " ", name()); }
};
struct Genode::Rom_fs : Genode::Avl_tree<Genode::Avl_string_base>
{
Rom_module const * find(char const * const name) const
{
return first() ? (Rom_module const *)first()->find_by_name(name)
: nullptr;
}
void print(Genode::Output & out) const
{
if (!first()) Genode::print(out, "No modules in Rom_fs\n");
Genode::print(out, "ROM modules:\n");
for_each([&] (Avl_string_base const & rom) {
Genode::print(out, " ROM: ", *static_cast<Rom_module const *>(&rom), "\n"); });
}
};
#endif /* _CORE__INCLUDE__ROM_FS_H_ */

View File

@ -26,12 +26,12 @@ namespace Genode {
{
private:
Rom_module *_rom_module;
Rom_module const *_rom_module;
Dataspace_component _ds;
Rpc_entrypoint *_ds_ep;
Rom_dataspace_capability _ds_cap;
Rom_module * _find_rom(Rom_fs *rom_fs, const char *args)
Rom_module const * _find_rom(Rom_fs *rom_fs, const char *args)
{
/* extract label */
Session_label const label = label_from_args(args);

View File

@ -23,8 +23,8 @@ Rom_session_component::Rom_session_component(Rom_fs *rom_fs,
const char *args)
:
_rom_module(_find_rom(rom_fs, args)),
_ds(_rom_module ? _rom_module->size() : 0,
_rom_module ? _rom_module->addr() : 0, CACHED, false, 0),
_ds(_rom_module ? _rom_module->size : 0,
_rom_module ? _rom_module->addr : 0, CACHED, false, 0),
_ds_ep(ds_ep)
{
/* ROM module not found */