3Tutorial lua script for Ned
 
    4===========================
 
    6Firstly we have a set of definitions available. Some come from 'ned.lua'
 
    7embedded script and others from the C++ bindings within Ned. The whole L4
 
    8functionality is in the lua module "L4" (use 'local L4 = require("L4");').
 
    9The L4 module classes and functions cope with L4 capabilities and
 
   10their invocations, provide a set of constants and access to the L4Re environment of
 
   11the running program.  Finally, of course it can also start L4 applications.
 
   16The L4 module defines a user data type for capabilities.  A capability in lua
 
   17carries a typed L4 capability and is accompanied with a set of type specific
 
   18methods that may be called on the object behind the capability.  There also
 
   19exists a way to cast a capability to a capability to a different type of
 
   20object using L4.cast(type, cap).
 
   24Returns a cap transformed to a capability of the given type, whereas type
 
   25is either the fully qualified C++ name of the class encapsulating the object
 
   26or the L4 protocol ID assigned to all L4Re and L4 system objects.
 
   27If the type is unknown then nil is returned.
 
   29Generic capabilities provide the following methods:
 
   33  Returns true if the capability is not the invalid cap (L4_INVALID_CAP), and
 
   34  false if it is the invalid cap.
 
   40There is a lua type for name spaces that has the following methods:
 
   42query(name), or q(name)
 
   44  Returns a closure (function) that initiates a query for the given name
 
   45  within the name space.  The function takes no arguments and returns
 
   46  a capability if successful or nil if name is not found.
 
   51  Returns a function that can create a link to the given object in the name
 
   52  space if put into another name space. The function takes two parameters
 
   53  the target name space and the name in the target name space.
 
   54  Loader:create_namespace and Loader.fill_namespace calls this function
 
   55  when things are really put into an L4Re::Namespace.
 
   58register(name, cap), or r(name, cap)
 
   60  Registers the given object capability under the given name. cap can
 
   61  be either a real capability (note query returns a function), a string, or
 
   62  nil.  If it is a capability it is just put into the name space.
 
   63  In the case cap is a string a placeholder will be put into the name space
 
   64  that will be replaced with a real capability later by some program.
 
   65  And if nil is use the name will be deleted from the name space.
 
   71The factory object provides an interface to the generic create method of a
 
   76  This method calls the factory to create an object of the given type,
 
   77  via the L4 protocol number (see L4.Proto table for more) all further
 
   78  arguments are passed to the factory.
 
   81Access to the L4Re Env capabilities
 
   82===================================
 
   84The L4 module defines a table L4.Env that contains the capabilities
 
   85of the L4Re::Env::env() environment. Namely:
 
   87factory      The kernel factory of Ned
 
   88log          The log object of Ned
 
   89user_factory The factory provided to Ned, including memory
 
   90parent       The parent of Ned
 
   91rm           The region map of Ned
 
   92scheduler    The scheduler of Ned
 
   98L4.Proto table contains the most important protocol values for
 
  110The L4.Info table contains the following functions:
 
  112  Kip.str()    The banner string found in the kernel info page
 
  113  arch()       Architecture name, such as: x86, amd64, arm, ppc32
 
  114  platform()   Platform name, such as: pc, ux, realview, beagleboard
 
  115  mword_bits() Number of native machine word bits (32, 64)
 
  118Support for starting L4 programs
 
  119================================
 
  121The L4 module defines two classes that are useful for starting L4 applications.
 
  122The class L4.Loader that encapsulates a fairly high level policy
 
  123that is useful for starting a whole set of processes. And the class L4.App_env
 
  124that encapsulates a more fine-grained policy.
 
  129The class L4.Loader encapsulates the policy for starting programs with the
 
  130basic building blocks for the application coming from a dedicated loader,
 
  131such as Moe or a Loader instance. These building blocks are a region map (Rm),
 
  132a scheduler, a memory allocator, and a logging facility.
 
  133A L4.Loader object is typically used to start multiple applications. There
 
  134is a L4.default_loader instance of L4.Loader that uses the L4.Env.mem_alloc
 
  135factory of the current Ned instance to create the objects for a new program.
 
  136However you may also use a more restricted factory for applications and
 
  137instantiate a loader for them.  The L4.Loader objects can already be used
 
  138to start a program with L4.Loader:start(app_spec, cmd, ...). Where app_spec
 
  139is a table containing parameters for the new application. cmd is the
 
  140command to run and the remaining arguments are the command-line options for
 
  145L4.default_loader:start({}, "rom/hello");
 
  149This statement does the following:
 
  150 1. Create a new environment for the application
 
  151 2. Add the rom name-space into the new environment (thus shares Ned's
 
  152    'rom' directory with the new program).
 
  153 3. Creates all the building blocks for the new process and starts the
 
  154    'l4re' support kernel in the new process which in turn starts 'rom/hello'
 
  157Using the app_spec parameter you can modify the behavior in two ways. There are
 
  158two supported options 'caps' for providing more capabilities for the
 
  159application. And 'log' for modifying the logger tag and color.
 
  167L4.default_loader:start({caps = my_caps, log = {"APP", "blue"}}, "rom/hello");
 
  171This snippet creates a caps template (my_caps) and uses it for the
 
  172new process and also sets user-defined log tags.  The L4.Loader:start method,
 
  173however, automatically adds the 'rom' directory to the caps environment if
 
  174not already specified in the template.
 
  176Environment variables may be given as a table in the third argument to
 
  177start. Argument to the program are given space separated after the program
 
  178name within a single string.
 
  182L4.default_loader:start({}, "rom/program arg1 " .. arg2, { LD_DEBUG = 1 });
 
  186L4.default_loader:startv is a variant of the start function that takes the
 
  187arguments of the program as a single argument each. If the last argument to
 
  188startv is a table it is interpreted as environment variables for the program.
 
  189The above example would translate to:
 
  193L4.default_loader:startv({}, "rom/program", "arg1", arg2, { LD_DEBUG = 1 });
 
  197To create a new L4.Loader instance you may use a generic factory for all
 
  198building blocks or set individual factories.
 
  203  mem = L4.Env.user_factory:create(L4.Proto.Factory, 512*1024):m("rs")
 
  208Creates a loader instance that uses the newly created 512 KB factory for
 
  209all building blocks. To set individual factories use the options:
 
  210  'mem'       as memory allocator for the new processes and as
 
  211              default factory for all objects not explicitely set to a
 
  213  'log_fab'   for creating log objects.
 
  214  'ns_fab'    for creating name-space objects.
 
  215  'rm_fab'    for creating region-map objects.
 
  222L4.App_env provides a more fine-grained control for a single process or for a
 
  223limited number of processes. L4.App_env uses an L4.Loader object as basic
 
  224facility. However you can override the memory allocator 'mem' for for the new
 
  225process as well as the kernel factory 'factory', the log capability etc.
 
  229local e = L4.App_env.new({
 
  231  mem = L4.Env.user_factory:create(L4.Proto.Factory, 128*1024):m("rs")