Genode Programming

1,113 views

Published on

The lecture by Norman Feske for Summer Systems School'12.
Genode Programming

SSS'12 - Education event, organized by ksys labs[1] in 2012, for students interested in system software development and information security.

Genode[2] - The Genode operating-system framework provides a uniform API for applications on top of 8 existing microkernels/hypervisors: Linux, L4ka::Pistachio, L4/Fiasco, OKL4, NOVA, Fiasco.OC, Codezero, and a custom kernel for the MicroBlaze architecture.

1. http://ksyslabs.org/
2. http://genode.org

Published in: Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,113
On SlideShare
0
From Embeds
0
Number of Embeds
177
Actions
Shares
0
Downloads
31
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Genode Programming

  1. 1. Genode OS Framework Programming Environment Norman Feske<norman.feske@genode-labs.com>
  2. 2. Outline1. Source tree overview2. Build system3. Run scripts4. Inter-process communication5. Client-server example Genode OS Framework Programming Environment 2
  3. 3. Outline1. Source tree overview2. Build system3. Run scripts4. Inter-process communication5. Client-server example Genode OS Framework Programming Environment 3
  4. 4. Get the source codeCode is hosted at GitHub: https://github.com/genodelabs/genodeClone the main repository: git clone https://github.com/genodelabs/genode.git Contains genuine Genode code only 3rd-party code not included, must be downloaded Genode OS Framework Programming Environment 4
  5. 5. RepositoriesFoster modular code base instead of one big treeFor a given project, only a subset of repositories is relevant→ Helps to focus attention to relevant parts→ Clean organization defeats ad-hoc solutions Genode OS Framework Programming Environment 5
  6. 6. Repository shadowingSet of used repositories defined by build directory→ Selected repositories form one logical source tree(similar to unionfs) REPOSITORIES = <list-of-repo-directories>Repositories can shadow each other target description files library description files include-search directoriesOrder is REPOSITORIES list is important Earlier entries shadow later entries Genode OS Framework Programming Environment 6
  7. 7. Repositories shadowing (II) Genode OS Framework Programming Environment 7
  8. 8. Repositories in practiceTweak existing components without breaking existing codeWant to add code? → Simply introduce a new repository Can be hosted outside the mainline Genode tree Use a revision control system of your choice Genode OS Framework Programming Environment 8
  9. 9. SpecsSource repositories → coarse grained modularityChallenges: Multiple kernels Multiple hardware platforms Different flavours of implementations ifndef-endif yields frustration, messes up test coverage Build specs → fine grained modularity Genode OS Framework Programming Environment 9
  10. 10. Specs: Build targets express their needsExamples: Specific peripheral (device driver) Particular property of CPU architecture if code is not generic only 32-bit only arm v7a Licensing conditionsExample, target.mk file REQUIRES = x86 ... Genode OS Framework Programming Environment 10
  11. 11. Specs: Build directory defines build propertiesSpec values characterize the buildExample <build-dir>/etc/specs.conf SPECS = genode foc_pandaHigh-level spec values refined to low-level spec values Genode OS Framework Programming Environment 11
  12. 12. Specs: Refinement Genode OS Framework Programming Environment 12
  13. 13. Specs: Steering the build processTraverse <repos>/mk/spec-<value>.mk files Platform-specific build settings (CFLAGS ...) Include more specialized spec-<value>.mk filesMatch target’s REQUIRES against build-dir’s SPECSPrefer specialized libraries:<repo>/lib/mk/blit.mk generic library<repo>/lib/mk/x86 32/blit.mk specialized library Genode OS Framework Programming Environment 13
  14. 14. Specs: Benefits→ No preprocessor-based configuration→ No artificial abstractions (architecture, platform, cpu, ...)→ Easy to extend→ Easy to configure Genode OS Framework Programming Environment 14
  15. 15. Anatomy of a repositoryDirectory Descriptiondoc/ Documentation, specific for the repositoryetc/ Default configuration of the build processinclude/ Globally visible header filessrc/ Source codes and target build descriptionslib/mk/ Library build descriptions Genode OS Framework Programming Environment 15
  16. 16. Repository relationships Genode OS Framework Programming Environment 16
  17. 17. Integration of 3rd-party source codeDownload and integrate a kernel: make -C <genode-dir>/base-nova prepareWorks uniformly for all kernels! Genode OS Framework Programming Environment 17
  18. 18. Integration of 3rd-party source codePorted applications and libraries reside in libports and ports.List available 3rd-party libraries: make -C libportsDownload and integrate a set of libraries: make -C libports prepare PKG=’libc freetype’...a lot to explore Genode OS Framework Programming Environment 18
  19. 19. Outline1. Source tree overview2. Build system3. Run scripts4. Inter-process communication5. Client-server example Genode OS Framework Programming Environment 19
  20. 20. Tool chainNeeded because C++ support libraries normally require a libc We need C++ support We don’t want to depend on a libc Multi-threading support is OS-specific Linux TLS Limit varienty of tool-chain related errors Compiler versions Linux distributions→ http://genode.org/download/tool-chain Genode OS Framework Programming Environment 20
  21. 21. Build directory<build-dir>/etc/build.conf Defines base/ location Defines source repositories to use REPOSITORIES = <list-of-repo-dirs> Make flags MAKE += -j4 Genode OS Framework Programming Environment 21
  22. 22. Build directory (II)<build-dir>/etc/specs.conf Included after <repos>/etc/specs.conf Define build characteristics via spec values SPECS = genode foc_panda Defaults in base-<platform>/etc/specs.conf Extend spec values SPECS += i915 Genode OS Framework Programming Environment 22
  23. 23. Build directory (III)<build-dir>/Makefile symlink to <genode-dir>/tool/builddir/build.mkFront end of the build system Genode OS Framework Programming Environment 23
  24. 24. Build directory creation tool<genode-dir>/tool/create builddirCreates templates for a variety of supported platforms: create_builddir nova_x86_32 BUILD_DIR=/tmp/buildRevisit generated build.conf: Enable repositories Add make flags as desired Genode OS Framework Programming Environment 24
  25. 25. Building targetsSingle target make <rel-dir-to-target>Example: make drivers/atapi Looks for target.mk within <repos>/src/drivers/atapi Tests REQUIRES agains SPECS Builds all libraries the target depends on Builds target Genode OS Framework Programming Environment 25
  26. 26. Building targets (II)Tree of targets make <rel-dir>Example: make driversBuilds all targets within <repos>/src/drivers. Genode OS Framework Programming Environment 26
  27. 27. Building targets (III)List of targets make <rel-dir> ...Example: make core init drivers/timerBuilds all targets found in any of the specific src/ locations Genode OS Framework Programming Environment 27
  28. 28. Outline1. Source tree overview2. Build system3. Run scripts4. Inter-process communication5. Client-server example Genode OS Framework Programming Environment 28
  29. 29. Typical work flow Genode OS Framework Programming Environment 29
  30. 30. Run scriptbuild "core init test/printf"create_boot_directoryinstall_config { <config> <parent-provides> <service name="LOG"/> </parent-provides> <default-route> <any-service> <parent/> </any-service> </default-route> <start name="test-printf"> <resource name="RAM" quantum="1M"/> </start> </config> }build_boot_image "core init test-printf"append qemu_args "-nographic -m 64"run_genode_until {-1 = -1 = -1} 10 Genode OS Framework Programming Environment 30
  31. 31. Run script (II)Located at <repos>/run/<script-name>.runExecutable from within the build directory make run/<script-name> Genode OS Framework Programming Environment 31
  32. 32. Run script (III)→ Single file describes a complete system scenario→ One run script works across different kernels→ Great for bug reports→ Run script + little work = automated test case Genode OS Framework Programming Environment 32
  33. 33. Outline1. Source tree overview2. Build system3. Run scripts4. Inter-process communication5. Client-server example Genode OS Framework Programming Environment 33
  34. 34. Remote procedure calls (RPC) Genode OS Framework Programming Environment 34
  35. 35. Remote procedure calls: Classes Genode OS Framework Programming Environment 35
  36. 36. Remote procedure calls: New RPC object Genode OS Framework Programming Environment 36
  37. 37. Remote procedure calls: Invocation Genode OS Framework Programming Environment 37
  38. 38. Shared memory Genode OS Framework Programming Environment 38
  39. 39. Asynchronous notifications Genode OS Framework Programming Environment 39
  40. 40. Asynchronous notifications (II) Genode OS Framework Programming Environment 40
  41. 41. Mechanisms combinedRPC + shared memory→ Synchronous bulk data (transaction)Signalling + dataspace→ Asynchronous bulk data (streaming) Genode OS Framework Programming Environment 41
  42. 42. Synchronous bulk data transfer Genode OS Framework Programming Environment 42
  43. 43. Asynchronous bulk data transfer Genode OS Framework Programming Environment 43
  44. 44. Packet stream example Genode OS Framework Programming Environment 44
  45. 45. Outline1. Source tree overview2. Build system3. Run scripts4. Inter-process communication5. Client-server example Genode OS Framework Programming Environment 45
  46. 46. Scenario overview Genode OS Framework Programming Environment 46
  47. 47. Classes overview Genode OS Framework Programming Environment 47
  48. 48. Create a new repositoryDesignated content: hello_tutorial hello_tutorial/include hello_tutorial/include/hello_session hello_tutorial/src hello_tutorial/src/hello hello_tutorial/src/hello/server hello_tutorial/src/hello/client Genode OS Framework Programming Environment 48
  49. 49. Server interface Genode OS Framework Programming Environment 49
  50. 50. Server interface#include <session/session.h>#include <base/rpc.h>namespace Hello { struct Session : public Genode::Session { static const char *service_name() { return "Hello"; } virtual void say_hello() = 0; virtual int add(int a, int b) = 0; GENODE_RPC(Rpc_say_hello, void, say_hello); GENODE_RPC(Rpc_add, int, add, int, int); GENODE_RPC_INTERFACE(Rpc_say_hello, Rpc_add); };} Genode OS Framework Programming Environment 50
  51. 51. Server-side interface implementation Genode OS Framework Programming Environment 51
  52. 52. Server-side interface implementation#include <base/printf.h>#include <hello_session/hello_session.h>#include <base/rpc_server.h>namespace Hello { struct Session_component : Genode::Rpc_object<Session> { void say_hello() { Genode::printf("I am here... Hello.n"); } int add(int a, int b) { return a + b; } };} Genode OS Framework Programming Environment 52
  53. 53. Server-side root interface Genode OS Framework Programming Environment 53
  54. 54. Server-side root interface#include <root/component.h>namespace Hello { struct Root_component : Genode::Root_component<Session_component> { Session_component *_create_session(const char *args) { return new (md_alloc()) Session_component(); } Root_component(Genode::Rpc_entrypoint *ep, Genode::Allocator *allocator) : Genode::Root_component<Session_component>(ep, allocator) { } };} Genode OS Framework Programming Environment 54
  55. 55. Server main program#include <base/sleep.h>#include <cap_session/connection.h>int main(void){ using namespace Genode; Cap_connection cap; Sliced_heap md_alloc(env()->ram_session(), env()->rm_session()); enum { STACK_SIZE = 4096 }; Rpc_entrypoint ep(&cap, STACK_SIZE, "hello_ep"); Hello::Root_component hello_root(&ep, &md_alloc); env()->parent()->announce(ep.manage(&hello_root)); sleep_forever(); return 0;} Genode OS Framework Programming Environment 55
  56. 56. Server build description filessrc/hello/server/target.mk TARGET = hello_server SRC_CC = main.cc LIBS = cxx env server Genode OS Framework Programming Environment 56
  57. 57. Client main program Genode OS Framework Programming Environment 57
  58. 58. Client main program#include <base/env.h>#include <base/printf.h>#include <base/rpc_client.h>#include <hello_session/hello_session.h>int main(void){ using namespace Genode; Capability<Hello::Session> hello(env()->parent()->session<Hello::Session>("ram_quota=4K")); hello.call<Hello::Session::Rpc_say_hello>(); printf("sum = %d", hello.call<Hello::Session::Rpc_add>(13, 14)); return 0;} Genode OS Framework Programming Environment 58
  59. 59. Client-side convenience wrapper Genode OS Framework Programming Environment 59
  60. 60. Client-side convenience wrapper#include <base/rpc_client.h>#include <hello_session/hello_session.h>namespace Hello { struct Session_client : Genode::Rpc_client<Session> { Session_client(Genode::Capability<Session> cap) : Genode::Rpc_client<Session>(cap) { } void say_hello() { call<Rpc_say_hello>(); } int add(int a, int b) { return call<Rpc_add>(a, b); } };} Genode OS Framework Programming Environment 60
  61. 61. Client-side connection object Genode OS Framework Programming Environment 61
  62. 62. Client-side connection object#include <hello_session/client.h>#include <base/connection.h>namespace Hello { struct Connection : Genode::Connection<Session>, Session_client { Connection() : Genode::Connection<Hello::Session>(session("ram_quota=4K")), Session_client(cap()) { } };} Genode OS Framework Programming Environment 62
  63. 63. Simplified client main program#include <base/env.h>#include <base/printf.h>#include <hello_session/connection.h>int main(void){ using namespace Genode; Hello_connection hello; hello.say_hello(); printf("sum = %d", hello.add(13, 14)); return 0;} Genode OS Framework Programming Environment 63
  64. 64. Client build description filesrc/hello/client/target.mk TARGET = hello_client SRC_CC = main.cc LIBS = cxx env Genode OS Framework Programming Environment 64
  65. 65. Run scriptbuild { core init hello }create_boot_directoryinstall_config { <config> <parent-provides> <service name="CAP"/> <service name="LOG"/> </parent-provides> <default-route> <any-service> <parent/> <any-child/> </any-service> </default-route> <start name="hello_server"> <resource name="RAM" quantum="1M"/> <provides> <service name="Hello"/> </provides> </start> <start name="hello_client"> <resource name="RAM" quantum="1M"/> </start> </config>}build_boot_image { core init hello_client hello_server }run_genode_until forever Genode OS Framework Programming Environment 65
  66. 66. Advanced featuresExtending existing RPC interfaces GENODE_RPC_INTERFACE_INHERIT(Base_interface_type, Rpc_func ...)Throwing exceptions accross process boundaries GENODE_RPC_THROW(Rpc_unlink, void, unlink, GENODE_TYPE_LIST(Permission_denied, Invalid_name, Lookup_failed), Dir_handle, Name const &); Genode OS Framework Programming Environment 66
  67. 67. ObservationsRPC stub code generated by C++ compilerNo external tools neededNo language boundary to conquerType safety Genode OS Framework Programming Environment 67
  68. 68. Thank youWhat we covered today Coming up next...Programming environment Components 1. Source tree overview 1. Classes of components 2. Build system 2. Unified configuration 3. Run scripts concept 4. Inter-process communication 3. Session routing 5. Client-server example 4. Components overview More information and resources: http://genode.org Genode OS Framework Programming Environment 68

×