L4Re Operating System Framework
Interface and Usage Documentation
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
tutorial.lua
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 mword_bits() Number of native machine word bits (32, 64)
116
117
118Support for starting L4 programs
119================================
120
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.
125
126L4.Loader
127---------
128
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
141the application.
142
143]==]
144
145L4.default_loader:start({}, "rom/hello");
146
147local _doc = [==[
148
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'
155 in the new process.
156
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.
160
161]==]
162
163local my_caps = {
164 fb = L4.Env.vesa;
165};
166
167L4.default_loader:start({caps = my_caps, log = {"APP", "blue"}}, "rom/hello");
168
169local _doc = [==[
170
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.
175
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.
179
180]==]
181
182L4.default_loader:start({}, "rom/program arg1 " .. arg2, { LD_DEBUG = 1 });
183
184local _doc = [==[
185
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:
190
191]==]
192
193L4.default_loader:startv({}, "rom/program", "arg1", arg2, { LD_DEBUG = 1 });
194
195local _doc = [==[
196
197To create a new L4.Loader instance you may use a generic factory for all
198building blocks or set individual factories.
199
200]==]
201
202l = L4.Loader.new({
203 mem = L4.Env.user_factory:create(L4.Proto.Factory, 512*1024):m("rs")
204});
205
206local _doc = [==[
207
208Creates a loader instance that uses the newly created 512 Kbyte 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
212 different factory
213 'log_fab' for creating log objects.
214 'ns_fab' for creating name-space objects.
215 'rm_fab' for creating region-map objects.
216
217
218
219L4.App_env
220----------
221
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.
226
227]==]
228
229local e = L4.App_env.new({
230 loader = l,
231 mem = L4.Env.user_factory:create(L4.Proto.Factory, 128*1024):m("rs")
232});
233
234e:start("rom/hello");