1local _doc = [==[ 2 3Tutorial lua script for Ned 4=========================== 5 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. 12 13L4 Capabilities 14=============== 15 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). 21 22L4.cast(type, cap) 23 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. 28 29Generic capabilities provide the following methods: 30 31is_valid() 32 33 Returns true if the capability is not the invalid cap (L4_INVALID_CAP), and 34 false if it is the invalid cap. 35 36 37L4Re::Namespace object 38====================== 39 40There is a lua type for name spaces that has the following methods: 41 42query(name), or q(name) 43 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. 47 48 49link(name), or l(name) 50 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. 56 57 58register(name, cap), or r(name, cap) 59 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. 66 67 68L4::Factory object 69================== 70 71The factory object provides an interface to the generic create method of a 72factory. 73 74create(proto, ...) 75 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. 79 80 81Access to the L4Re Env capabilities 82=================================== 83 84The L4 module defines a table L4.Env that contains the capabilities 85of the L4Re::Env::env() environment. Namely: 86 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 93 94 95Some useful constants 96===================== 97 98L4.Proto table contains the most important protocol values for 99L4 and L4Re objects. 100 101 Namespace 102 Goos 103 Rm 104 Irq 105 Sigma0 106 Factory 107 Log 108 Scheduler 109 110The L4.Info table contains the following functions: 111 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 116 117Support for starting L4 programs 118================================ 119 120The L4 module defines two classes that are useful for starting L4 applications. 121The class L4.Loader that encapsulates a fairly high level policy 122that is useful for starting a whole set of processes. And the class L4.App_env 123that encapsulates a more fine-grained policy. 124 125L4.Loader 126--------- 127 128The class L4.Loader encapsulates the policy for starting programs with the 129basic building blocks for the application coming from a dedicated loader, 130such as Moe or a Loader instance. These building blocks are a region map (Rm), 131a scheduler, a memory allocator, and a logging facility. 132A L4.Loader object is typically used to start multiple applications. There 133is a L4.default_loader instance of L4.Loader that uses the L4.Env.mem_alloc 134factory of the current Ned instance to create the objects for a new program. 135However you may also use a more restricted factory for applications and 136instantiate a loader for them. The L4.Loader objects can already be used 137to start a program with L4.Loader:start(app_spec, cmd, ...). Where app_spec 138is a table containing parameters for the new application. cmd is the 139command to run and the remaining arguments are the command-line options for 140the application. 141 142]==] 143 144L4.default_loader:start({}, "rom/hello"); 145 146local _doc = [==[ 147 148This statement does the following: 149 1. Create a new environment for the application 150 2. Add the rom name-space into the new environment (thus shares Ned's 151 'rom' directory with the new program). 152 3. Creates all the building blocks for the new process and starts the 153 'l4re' support kernel in the new process which in turn starts 'rom/hello' 154 in the new process. 155 156Using the app_spec parameter you can modify the behavior in two ways. There are 157two supported options 'caps' for providing more capabilities for the 158application. And 'log' for modifying the logger tag and color. 159 160]==] 161 162local my_caps = { 163 fb = L4.Env.vesa; 164}; 165 166L4.default_loader:start({caps = my_caps, log = {"APP", "blue"}}, "rom/hello"); 167 168local _doc = [==[ 169 170This snippet creates a caps template (my_caps) and uses it for the 171new process and also sets user-defined log tags. The L4.Loader:start method, 172however, automatically adds the 'rom' directory to the caps environment if 173not already specified in the template. 174 175Environment variables may be given as a table in the third argument to 176start. Argument to the program are given space separated after the program 177name within a single string. 178 179]==] 180 181L4.default_loader:start({}, "rom/program arg1 " .. arg2, { LD_DEBUG = 1 }); 182 183local _doc = [==[ 184 185L4.default_loader:startv is a variant of the start function that takes the 186arguments of the program as a single argument each. If the last argument to 187startv is a table it is interpreted as environment variables for the program. 188The above example would translate to: 189 190]==] 191 192L4.default_loader:startv({}, "rom/program", "arg1", arg2, { LD_DEBUG = 1 }); 193 194local _doc = [==[ 195 196To create a new L4.Loader instance you may use a generic factory for all 197building blocks or set individual factories. 198 199]==] 200 201l = L4.Loader.new({mem = L4.Env.user_factory:create(L4.Proto.Factory, 512*1024)}) 202 203local _doc = [==[ 204 205Creates a loader instance that uses the newly created 512 Kbyte factory for 206all building blocks. To set individual factories use the options: 207 'mem' as memory allocator for the new processes and as 208 default factory for all objects not explicitely set to a 209 different factory 210 'log_fab' for creating log objects. 211 'ns_fab' for creating name-space objects. 212 'rm_fab' for creating region-map objects. 213 214 215 216L4.App_env 217---------- 218 219L4.App_env provides a more fine-grained control for a single process or for a 220limited number of processes. L4.App_env uses an L4.Loader object as basic 221facility. However you can override the memory allocator 'mem' for for the new 222process as well as the kernel factory 'factory', the log capability etc. 223 224]==] 225 226local e = L4.App_env.new({ 227 loader = l, 228 mem = L4.Env.user_factory:create(L4.Proto.Factory, 128*1024) 229}); 230 231e:start("rom/hello"); 232