SlideShare a Scribd company logo
Genode OS Framework
 Programming Environment




         Norman Feske
<norman.feske@genode-labs.com>
Outline



1. Source tree overview

2. Build system

3. Run scripts

4. Inter-process communication

5. Client-server example




                  Genode OS Framework Programming Environment   2
Outline



1. Source tree overview

2. Build system

3. Run scripts

4. Inter-process communication

5. Client-server example




                  Genode OS Framework Programming Environment   3
Get the source code



Code is hosted at GitHub:

 https://github.com/genodelabs/genode

Clone 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
Repositories




Foster modular code base instead of one big tree

For 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
Repository shadowing



Set 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 directories
Order is REPOSITORIES list is important
    Earlier entries shadow later entries



              Genode OS Framework Programming Environment   6
Repositories shadowing (II)




        Genode OS Framework Programming Environment   7
Repositories in practice




Tweak existing components without breaking existing code

Want 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
Specs




Source repositories → coarse grained modularity
Challenges:
    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
Specs: Build targets express their needs



Examples:
    Specific peripheral (device driver)
    Particular property of CPU architecture if code is not generic
        only 32-bit
        only arm v7a
    Licensing conditions
Example, target.mk file
             REQUIRES = x86
             ...




                 Genode OS Framework Programming Environment         10
Specs: Build directory defines build properties




Spec values characterize the build
Example <build-dir>/etc/specs.conf
            SPECS = genode foc_panda
High-level spec values refined to low-level spec values




                  Genode OS Framework Programming Environment   11
Specs: Refinement




       Genode OS Framework Programming Environment   12
Specs: Steering the build process



Traverse <repos>/mk/spec-<value>.mk files
    Platform-specific build settings (CFLAGS ...)
    Include more specialized spec-<value>.mk files


Match target’s REQUIRES against build-dir’s SPECS


Prefer specialized libraries:
<repo>/lib/mk/blit.mk                                         generic library
<repo>/lib/mk/x86 32/blit.mk                               specialized library



             Genode OS Framework Programming Environment                         13
Specs: Benefits




→   No preprocessor-based configuration
→   No artificial abstractions (architecture, platform, cpu, ...)
→   Easy to extend
→   Easy to configure




                    Genode OS Framework Programming Environment    14
Anatomy of a repository




Directory   Description
doc/        Documentation, specific for the repository
etc/        Default configuration of the build process
include/    Globally visible header files
src/        Source codes and target build descriptions
lib/mk/     Library build descriptions




            Genode OS Framework Programming Environment   15
Repository relationships




        Genode OS Framework Programming Environment   16
Integration of 3rd-party source code




Download and integrate a kernel:

 make -C <genode-dir>/base-nova prepare

Works uniformly for all kernels!




                   Genode OS Framework Programming Environment   17
Integration of 3rd-party source code



Ported applications and libraries reside in libports and ports.
List available 3rd-party libraries:

 make -C libports

Download and integrate a set of libraries:

 make -C libports prepare PKG=’libc freetype’

...a lot to explore




                      Genode OS Framework Programming Environment   18
Outline



1. Source tree overview

2. Build system

3. Run scripts

4. Inter-process communication

5. Client-server example




                  Genode OS Framework Programming Environment   19
Tool chain



Needed 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
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
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
Build directory (III)




<build-dir>/Makefile
          symlink to
          <genode-dir>/tool/builddir/build.mk
Front end of the build system




                  Genode OS Framework Programming Environment   23
Build directory creation tool




<genode-dir>/tool/create builddir
Creates templates for a variety of supported platforms:

 create_builddir nova_x86_32 BUILD_DIR=/tmp/build

Revisit generated build.conf:
    Enable repositories
    Add make flags as desired




                  Genode OS Framework Programming Environment   24
Building targets


Single 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
Building targets (II)



Tree of targets

 make <rel-dir>

Example:

 make drivers

Builds all targets within <repos>/src/drivers.




                  Genode OS Framework Programming Environment   26
Building targets (III)




List of targets

 make <rel-dir> ...

Example:

 make core init drivers/timer

Builds all targets found in any of the specific src/ locations




                  Genode OS Framework Programming Environment   27
Outline



1. Source tree overview

2. Build system

3. Run scripts

4. Inter-process communication

5. Client-server example




                  Genode OS Framework Programming Environment   28
Typical work flow




        Genode OS Framework Programming Environment   29
Run script

build "core init test/printf"
create_boot_directory
install_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
Run script (II)




Located at <repos>/run/<script-name>.run
Executable from within the build directory
 make run/<script-name>




           Genode OS Framework Programming Environment   31
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
Outline



1. Source tree overview

2. Build system

3. Run scripts

4. Inter-process communication

5. Client-server example




                  Genode OS Framework Programming Environment   33
Remote procedure calls (RPC)




        Genode OS Framework Programming Environment   34
Remote procedure calls: Classes




        Genode OS Framework Programming Environment   35
Remote procedure calls: New RPC object




        Genode OS Framework Programming Environment   36
Remote procedure calls: Invocation




        Genode OS Framework Programming Environment   37
Shared memory




       Genode OS Framework Programming Environment   38
Asynchronous notifications




        Genode OS Framework Programming Environment   39
Asynchronous notifications (II)




        Genode OS Framework Programming Environment   40
Mechanisms combined




RPC + shared memory
→ Synchronous bulk data (transaction)

Signalling + dataspace
→ Asynchronous bulk data (streaming)




            Genode OS Framework Programming Environment   41
Synchronous bulk data transfer




        Genode OS Framework Programming Environment   42
Asynchronous bulk data transfer




        Genode OS Framework Programming Environment   43
Packet stream example




        Genode OS Framework Programming Environment   44
Outline



1. Source tree overview

2. Build system

3. Run scripts

4. Inter-process communication

5. Client-server example




                  Genode OS Framework Programming Environment   45
Scenario overview




        Genode OS Framework Programming Environment   46
Classes overview




        Genode OS Framework Programming Environment   47
Create a new repository



Designated 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
Server interface




         Genode OS Framework Programming Environment   49
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
Server-side interface implementation




        Genode OS Framework Programming Environment   51
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
Server-side root interface




         Genode OS Framework Programming Environment   53
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
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
Server build description files




src/hello/server/target.mk
           TARGET = hello_server
           SRC_CC = main.cc
           LIBS   = cxx env server




              Genode OS Framework Programming Environment   56
Client main program




        Genode OS Framework Programming Environment   57
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
Client-side convenience wrapper




        Genode OS Framework Programming Environment   59
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
Client-side connection object




        Genode OS Framework Programming Environment   61
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
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
Client build description file




src/hello/client/target.mk
           TARGET = hello_client
           SRC_CC = main.cc
           LIBS   = cxx env




              Genode OS Framework Programming Environment   64
Run script

build { core init hello }
create_boot_directory
install_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
Advanced features



Extending 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
Observations




RPC stub code generated by C++ compiler

No external tools needed

No language boundary to conquer

Type safety




              Genode OS Framework Programming Environment   67
Thank you



What 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

More Related Content

PPTX
Voleibol
PPTX
Badminton 1 eso.ppt
PPTX
El baloncesto aspectos técnicos
PDF
Genode Compositions
PDF
Genode Components
PDF
Introduction to Microkernels
PDF
Operating Systems Meet Fault Tolerance
PDF
Genode Architecture
Voleibol
Badminton 1 eso.ppt
El baloncesto aspectos técnicos
Genode Compositions
Genode Components
Introduction to Microkernels
Operating Systems Meet Fault Tolerance
Genode Architecture

Similar to Genode Programming (20)

PPTX
Autotools pratical training
PDF
Android Variants, Hacks, Tricks and Resources
PDF
Embedded Linux On A R M
PDF
Genode OS Framework
PDF
Embedded Linux - Building toolchain
PDF
Embedded Operating System - Linux
PDF
Android Variants, Hacks, Tricks and Resources presented at AnDevConII
ODP
Cross Platform Objective C Development Using Gn Ustep
PDF
Android Hacks, Variants, Tricks and Resources ESC SV 2012
ODP
Building Server Applications Using Objective C And Gn Ustep
ODP
Building Server Applications Using ObjectiveC And GNUstep
PDF
Leveraging Android's Linux Heritage at AnDevCon3
PDF
Introduction to OpenBricks: an Embedded Linux Framework
PDF
F-Script
ODP
Some wonderful Linux softwares for daily use
PDF
C language in our world 2019
PDF
Linux for embedded_systems
PDF
Eclipse vs Netbean vs Railo
PPT
FreeBSD Operating system overview Basics.ppt
Autotools pratical training
Android Variants, Hacks, Tricks and Resources
Embedded Linux On A R M
Genode OS Framework
Embedded Linux - Building toolchain
Embedded Operating System - Linux
Android Variants, Hacks, Tricks and Resources presented at AnDevConII
Cross Platform Objective C Development Using Gn Ustep
Android Hacks, Variants, Tricks and Resources ESC SV 2012
Building Server Applications Using Objective C And Gn Ustep
Building Server Applications Using ObjectiveC And GNUstep
Leveraging Android's Linux Heritage at AnDevCon3
Introduction to OpenBricks: an Embedded Linux Framework
F-Script
Some wonderful Linux softwares for daily use
C language in our world 2019
Linux for embedded_systems
Eclipse vs Netbean vs Railo
FreeBSD Operating system overview Basics.ppt
Ad

More from Vasily Sartakov (17)

PDF
Мейнстрим технологии шифрованной памяти
PDF
RnD Collaborations in Asia-Pacific Region
PDF
Сетевая подсистема в L4Re и Genode
PDF
Защита памяти при помощи NX-bit в среде L4Re
PDF
Hardware Errors and the OS
PDF
PDF
Operating Systems Hardening
PDF
Особенности Национального RnD
PDF
Trusted Computing Base
PDF
System Integrity
PDF
PDF
Memory, IPC and L4Re
PDF
Advanced Components on Top of L4Re
PDF
Применение Fiasco.OC
PDF
Прикладная Информатика 6 (36) 2011
PDF
Разработка встраиваемой операционной системы на базе микроядерной архитектуры...
PPT
Образование, наука, бизнес. Сегодня, завтра, послезавтра
Мейнстрим технологии шифрованной памяти
RnD Collaborations in Asia-Pacific Region
Сетевая подсистема в L4Re и Genode
Защита памяти при помощи NX-bit в среде L4Re
Hardware Errors and the OS
Operating Systems Hardening
Особенности Национального RnD
Trusted Computing Base
System Integrity
Memory, IPC and L4Re
Advanced Components on Top of L4Re
Применение Fiasco.OC
Прикладная Информатика 6 (36) 2011
Разработка встраиваемой операционной системы на базе микроядерной архитектуры...
Образование, наука, бизнес. Сегодня, завтра, послезавтра
Ad

Recently uploaded (20)

PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PPTX
Institutional Correction lecture only . . .
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PDF
Pre independence Education in Inndia.pdf
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
01-Introduction-to-Information-Management.pdf
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PPTX
GDM (1) (1).pptx small presentation for students
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PPTX
Lesson notes of climatology university.
PPTX
PPH.pptx obstetrics and gynecology in nursing
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
Sports Quiz easy sports quiz sports quiz
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Renaissance Architecture: A Journey from Faith to Humanism
Institutional Correction lecture only . . .
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
Pre independence Education in Inndia.pdf
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
01-Introduction-to-Information-Management.pdf
human mycosis Human fungal infections are called human mycosis..pptx
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
GDM (1) (1).pptx small presentation for students
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
VCE English Exam - Section C Student Revision Booklet
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Lesson notes of climatology university.
PPH.pptx obstetrics and gynecology in nursing
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Sports Quiz easy sports quiz sports quiz

Genode Programming

  • 1. Genode OS Framework Programming Environment Norman Feske <norman.feske@genode-labs.com>
  • 2. Outline 1. Source tree overview 2. Build system 3. Run scripts 4. Inter-process communication 5. Client-server example Genode OS Framework Programming Environment 2
  • 3. Outline 1. Source tree overview 2. Build system 3. Run scripts 4. Inter-process communication 5. Client-server example Genode OS Framework Programming Environment 3
  • 4. Get the source code Code is hosted at GitHub: https://github.com/genodelabs/genode Clone 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. Repositories Foster modular code base instead of one big tree For 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. Repository shadowing Set 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 directories Order is REPOSITORIES list is important Earlier entries shadow later entries Genode OS Framework Programming Environment 6
  • 7. Repositories shadowing (II) Genode OS Framework Programming Environment 7
  • 8. Repositories in practice Tweak existing components without breaking existing code Want 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. Specs Source repositories → coarse grained modularity Challenges: 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. Specs: Build targets express their needs Examples: Specific peripheral (device driver) Particular property of CPU architecture if code is not generic only 32-bit only arm v7a Licensing conditions Example, target.mk file REQUIRES = x86 ... Genode OS Framework Programming Environment 10
  • 11. Specs: Build directory defines build properties Spec values characterize the build Example <build-dir>/etc/specs.conf SPECS = genode foc_panda High-level spec values refined to low-level spec values Genode OS Framework Programming Environment 11
  • 12. Specs: Refinement Genode OS Framework Programming Environment 12
  • 13. Specs: Steering the build process Traverse <repos>/mk/spec-<value>.mk files Platform-specific build settings (CFLAGS ...) Include more specialized spec-<value>.mk files Match target’s REQUIRES against build-dir’s SPECS Prefer 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. 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. Anatomy of a repository Directory Description doc/ Documentation, specific for the repository etc/ Default configuration of the build process include/ Globally visible header files src/ Source codes and target build descriptions lib/mk/ Library build descriptions Genode OS Framework Programming Environment 15
  • 16. Repository relationships Genode OS Framework Programming Environment 16
  • 17. Integration of 3rd-party source code Download and integrate a kernel: make -C <genode-dir>/base-nova prepare Works uniformly for all kernels! Genode OS Framework Programming Environment 17
  • 18. Integration of 3rd-party source code Ported applications and libraries reside in libports and ports. List available 3rd-party libraries: make -C libports Download and integrate a set of libraries: make -C libports prepare PKG=’libc freetype’ ...a lot to explore Genode OS Framework Programming Environment 18
  • 19. Outline 1. Source tree overview 2. Build system 3. Run scripts 4. Inter-process communication 5. Client-server example Genode OS Framework Programming Environment 19
  • 20. Tool chain Needed 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. 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. 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. Build directory (III) <build-dir>/Makefile symlink to <genode-dir>/tool/builddir/build.mk Front end of the build system Genode OS Framework Programming Environment 23
  • 24. Build directory creation tool <genode-dir>/tool/create builddir Creates templates for a variety of supported platforms: create_builddir nova_x86_32 BUILD_DIR=/tmp/build Revisit generated build.conf: Enable repositories Add make flags as desired Genode OS Framework Programming Environment 24
  • 25. Building targets Single 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. Building targets (II) Tree of targets make <rel-dir> Example: make drivers Builds all targets within <repos>/src/drivers. Genode OS Framework Programming Environment 26
  • 27. Building targets (III) List of targets make <rel-dir> ... Example: make core init drivers/timer Builds all targets found in any of the specific src/ locations Genode OS Framework Programming Environment 27
  • 28. Outline 1. Source tree overview 2. Build system 3. Run scripts 4. Inter-process communication 5. Client-server example Genode OS Framework Programming Environment 28
  • 29. Typical work flow Genode OS Framework Programming Environment 29
  • 30. Run script build "core init test/printf" create_boot_directory install_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. Run script (II) Located at <repos>/run/<script-name>.run Executable from within the build directory make run/<script-name> Genode OS Framework Programming Environment 31
  • 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. Outline 1. Source tree overview 2. Build system 3. Run scripts 4. Inter-process communication 5. Client-server example Genode OS Framework Programming Environment 33
  • 34. Remote procedure calls (RPC) Genode OS Framework Programming Environment 34
  • 35. Remote procedure calls: Classes Genode OS Framework Programming Environment 35
  • 36. Remote procedure calls: New RPC object Genode OS Framework Programming Environment 36
  • 37. Remote procedure calls: Invocation Genode OS Framework Programming Environment 37
  • 38. Shared memory Genode OS Framework Programming Environment 38
  • 39. Asynchronous notifications Genode OS Framework Programming Environment 39
  • 40. Asynchronous notifications (II) Genode OS Framework Programming Environment 40
  • 41. Mechanisms combined RPC + shared memory → Synchronous bulk data (transaction) Signalling + dataspace → Asynchronous bulk data (streaming) Genode OS Framework Programming Environment 41
  • 42. Synchronous bulk data transfer Genode OS Framework Programming Environment 42
  • 43. Asynchronous bulk data transfer Genode OS Framework Programming Environment 43
  • 44. Packet stream example Genode OS Framework Programming Environment 44
  • 45. Outline 1. Source tree overview 2. Build system 3. Run scripts 4. Inter-process communication 5. Client-server example Genode OS Framework Programming Environment 45
  • 46. Scenario overview Genode OS Framework Programming Environment 46
  • 47. Classes overview Genode OS Framework Programming Environment 47
  • 48. Create a new repository Designated 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. Server interface Genode OS Framework Programming Environment 49
  • 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. Server-side interface implementation Genode OS Framework Programming Environment 51
  • 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. Server-side root interface Genode OS Framework Programming Environment 53
  • 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. 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. Server build description files src/hello/server/target.mk TARGET = hello_server SRC_CC = main.cc LIBS = cxx env server Genode OS Framework Programming Environment 56
  • 57. Client main program Genode OS Framework Programming Environment 57
  • 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. Client-side convenience wrapper Genode OS Framework Programming Environment 59
  • 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. Client-side connection object Genode OS Framework Programming Environment 61
  • 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. 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. Client build description file src/hello/client/target.mk TARGET = hello_client SRC_CC = main.cc LIBS = cxx env Genode OS Framework Programming Environment 64
  • 65. Run script build { core init hello } create_boot_directory install_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. Advanced features Extending 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. Observations RPC stub code generated by C++ compiler No external tools needed No language boundary to conquer Type safety Genode OS Framework Programming Environment 67
  • 68. Thank you What 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