diff --git a/run/child.run b/run/child.run index f89c3aa..6fa68f8 100644 --- a/run/child.run +++ b/run/child.run @@ -12,7 +12,6 @@ if {[expr !$use_usb_driver && !$use_nic_driver] || set build_components { core init drivers/timer drivers/nic - lib/vfs/lwip app/child app/hello } @@ -54,15 +53,8 @@ set config { - + - - - - - - - } append_if [have_spec gpio] config " @@ -85,13 +77,6 @@ append_if $use_usb_driver config { append_platform_drv_config -append_if $use_nic_driver config { - - - - } [nic_drv_config] { - } - append config { } @@ -102,10 +87,10 @@ install_config $config # Boot image # -build_boot_image { core ld.lib.so init child hello nic_drv vfs_lwip.lib.so timer libc.lib.so vfs.lib.so } +build_boot_image { core ld.lib.so init child hello timer } append qemu_args " -nographic " -append_if [have_spec lan9118] qemu_args " -net nic,macaddr=02:00:00:00:01:03 -net nic,model=lan9118 -net tap,ifname=tap0,script=no " +#append_if [have_spec lan9119] qemu_args " -net nic,macaddr=02:00:00:00:01:03 -net nic,model=lan9118 -net tap,ifname=tap0,script=no " run_genode_until forever diff --git a/src/app/child/main.cc b/src/app/child/main.cc index ede5d6e..b280adb 100644 --- a/src/app/child/main.cc +++ b/src/app/child/main.cc @@ -1,134 +1,93 @@ #include #include -#include - -#include -#include -#include -#include -#include #include #include #include -namespace xyz { - class Parent_service : public Genode::Parent_service { - private: - Genode::Registry::Element _reg_elem; +#include - public: - Parent_service(Genode::Registry ®istry, Genode::Env &env, - Service::Name const &name) - : - Genode::Parent_service(env, name), _reg_elem(registry, *this) { } - }; +#include - class MyChild : public Genode::Child_policy { - Name const _name; +using namespace Genode; - Genode::Env &_env; +class MyChild : public Child_policy { +public: + typedef Genode::Registered Parent_service; + typedef Genode::Registry Parent_services; +private: + Env &_env; + Cap_quota const _cap_quota {50}; + Ram_quota const _ram_quota {1 * 1024 * 1024}; - Genode::Cap_quota const _cap_quota; - Genode::Ram_quota const _ram_quota; + Parent_services &_parent_services; - Genode::Registry &_parent_services; + Child _child; - Genode::Rpc_entrypoint _child_ep; + template + static Genode::Service *_find_service(Genode::Registry &services, + Genode::Service::Name const &name) + { + Genode::Service *service = nullptr; + services.for_each([&] (T &s) { + if (!service && (s.name() == name)) + service = &s; }); + return service; + } - Init::Child_policy_provide_rom_file _binary_policy; +public: + MyChild(Env &env, Parent_services &parent_services) + : + _env(env), _parent_services(parent_services), _child(_env.rm(), _env.ep().rpc_ep(), *this) + {} + ~MyChild() { }; - Genode::Child _child; + Name name() const override { return "hello"; }; - template - static Genode::Service *_find_service(Genode::Registry &services, - Genode::Service::Name const &name) - { - Genode::Service *service = nullptr; - services.for_each([&] (T &s) { - if (!service && (s.name() == name)) - service = &s; }); - return service; - } + Pd_session &ref_pd() override { return _env.pd(); } + Pd_session_capability ref_pd_cap() const override { return _env.pd_session_cap(); } - public: + void init(Pd_session &pd, Pd_session_capability pd_cap) override + { + pd.ref_account(ref_pd_cap()); + ref_pd().transfer_quota(pd_cap, _cap_quota); + ref_pd().transfer_quota(pd_cap, _ram_quota); + } - MyChild(Genode::Env &env, - Genode::Session_label const &label, - Genode::Cap_quota cap_quota, - Genode::Ram_quota ram_quota, - Genode::Registry parent_services, - Genode::Dataspace_capability binary) : - _name(label), - _env(env), - _cap_quota(Genode::Child::effective_quota(cap_quota)), - _ram_quota(Genode::Child::effective_quota(ram_quota)), - _parent_services(parent_services), - _child_ep{&_env.pd(), 12 * 1024, name().string()}, - _binary_policy(name(), binary, &_child_ep), - _child(_env.rm(), _env.ep().rpc_ep(), *this) - { }; - ~MyChild() { }; + Genode::Child_policy::Route + resolve_session_request(Genode::Service::Name const &service_name, + Genode::Session_label const &label) override + { + auto route = [&] (Genode::Service &service) { + return Genode::Child_policy::Route { .service = service, + .label = label, + .diag = Genode::Session::Diag() }; }; - Name name() const override { return _name; } + Genode::Service *service = nullptr; + service = _find_service(_parent_services, service_name); + return route(*service); + } +}; - Genode::Pd_session &ref_pd() override { return _env.pd(); } - Genode::Pd_session_capability ref_pd_cap() const override { return _env.pd_session_cap(); } - - void init(Genode::Pd_session &session, - Genode::Pd_session_capability cap) override - { - session.ref_account(_env.pd_session_cap()); - _env.pd().transfer_quota(cap, _cap_quota); - _env.pd().transfer_quota(cap, _ram_quota); - } - - Genode::Service &resolve_session_request(Genode::Service::Name const &service_name, - Genode::Session_state::Args const &args) override - { - Genode::Service *service = nullptr; - if ((service = _binary_policy.resolve_session_request(service_name.string(), args.string()))) - { - Genode::log("Service from policy: ", service_name, "/", args); - return *service; - } - - Genode::log("Service from parent: ", service_name, "/", args); - - return *_find_service(_parent_services, service_name); - } - }; -} - -void Libc::Component::construct(Libc::Env &env) +void Component::construct(Genode::Env &env) { - Libc::with_libc([&] () { - struct sockaddr_in srv_addr; - srv_addr.sin_port = htons(8080); - srv_addr.sin_family = AF_INET; - srv_addr.sin_addr.s_addr = inet_addr("127.0.0.1"); + Genode::log("Hello World from child!"); - int sd = ::socket(AF_INET, SOCK_STREAM, 0); - ::connect(sd, (struct sockaddr *)&srv_addr, sizeof(srv_addr)); + Genode::Heap _heap {env.ram(), env.rm()}; - Genode::Ram_dataspace_capability ds; - ds = env.pd().alloc(1 * 1024 * 1024); - Genode::addr_t addr = env.rm().attach(ds); + static const char *names[] = { + /* core services */ + "RM", "PD", "CPU", "IO_MEM", "IO_PORT", "IRQ", "ROM", "LOG", - ::recv(sd, (void *)addr, 16383, 0); - Genode::String<16383> s((const char *)addr); - Genode::log(s); + 0 /* null-termination */ + }; + MyChild::Parent_services _parent_services { }; + for (unsigned i = 0; names[i]; i++) + new (_heap) MyChild::Parent_service(_parent_services, env, names[i]); - Genode::Heap _heap { env.ram(), env.rm() }; + MyChild mychild(env, _parent_services); - Genode::Registry parent_services; - static const char *names[] = { "PD", "CPU", "LOG", "ROM", 0 }; - for (unsigned i = 0; names[i]; i++) - new (_heap) xyz::Parent_service(parent_services, env, names[i]); - xyz::MyChild child { env, Genode::Session_label("app"), Genode::Cap_quota{6}, Genode::Ram_quota{1 * 1024 * 1024}, parent_services, ds }; - - while(1) { - } - }); + while(1) { + } } diff --git a/src/app/child/target.mk b/src/app/child/target.mk index eb311d1..7d3c370 100644 --- a/src/app/child/target.mk +++ b/src/app/child/target.mk @@ -1,3 +1,3 @@ TARGET = child SRC_CC = main.cc -LIBS = base libc +LIBS = base diff --git a/src/app/hello/main.cc b/src/app/hello/main.cc index eb0be69..347b7cf 100644 --- a/src/app/hello/main.cc +++ b/src/app/hello/main.cc @@ -2,5 +2,5 @@ void Component::construct(Genode::Env &env) { - Genode::log("Hello World!"); + Genode::log("Hello World from hello!"); }