322
|
1 OS
|
|
2 ==
|
272
|
3
|
407
|
4 Implementation
|
|
5 --------------
|
|
6
|
|
7 Arm
|
|
8 ~~~
|
|
9
|
|
10 Vexpress-a9
|
|
11
|
|
12
|
|
13 For the first implementation the qemu arm system vexpress-a9 machine was
|
|
14 targeted.
|
|
15
|
|
16 To launch this machine with a kernel use:
|
|
17
|
|
18 .. code::
|
|
19
|
|
20 qemu-system-arm -M vexpress-a9 -m 128M -kernel kernel/kernel_arm.bin \
|
|
21 -serial stdio
|
|
22
|
|
23 The memory layout of this image is as follows:
|
|
24
|
|
25 - 0x00000000
|
|
26 - 0x10000000 : hardware.
|
|
27 - 0x10009000 : pl011 --> the uart peripheral
|
|
28 - 0x60000000 : bootloader of qemu itself.
|
|
29 - 0x60010000 : main memory, where kernel is loaded by the bootloader.
|
|
30
|
|
31
|
322
|
32 Design
|
|
33 ------
|
273
|
34
|
|
35 Processes / threads
|
|
36 ~~~~~~~~~~~~~~~~~~~
|
272
|
37
|
|
38 Processes are completely seperated and fully pre-emptive.
|
|
39 This means a process can be unscheduled at any moment.
|
|
40
|
|
41 Threads are co-operative. This means they yield control
|
|
42 voluntary. This means that mutexes and locks are not required.
|
|
43 This is done with the built-in language feature called tasks.
|
|
44
|
|
45 If some heavy duty task must be performed, either way spawn
|
|
46 a new process, or yield frequently from this hard labour.
|
|
47
|
273
|
48 tasks
|
|
49 ~~~~~
|
272
|
50
|
273
|
51 Consider the following:
|
|
52
|
|
53 .. code::
|
272
|
54
|
273
|
55 function int insanemath(int a)
|
272
|
56 {
|
273
|
57 while (a > 0)
|
|
58 {
|
|
59 a = a -1;
|
|
60 resume agent1;
|
|
61 }
|
|
62 return a - 1;
|
272
|
63 }
|
|
64
|
273
|
65 task agent1()
|
|
66 {
|
|
67 start agent2;
|
|
68 }
|
272
|
69
|
273
|
70 task agent2()
|
|
71 {
|
|
72 insanemath(55);
|
|
73 insanemath(44);
|
|
74 }
|
272
|
75
|
273
|
76 task main()
|
|
77 {
|
|
78 start agent1;
|
|
79 join agent1;
|
|
80 }
|
|
81
|
272
|
82
|
|
83 Say to tasks are running in concurrent / parallel.
|
|
84
|
|
85
|
|
86
|
|
87 Stack layout for tasks.
|
|
88 ||
|
|
89 ||
|
|
90 \/
|
|
91 +---------+
|
|
92 | return address
|
|
93 | locals
|
|
94 |
|
|
95 +------
|
|
96 | return address
|
|
97 | locals
|
|
98 |
|
|
99 +---
|
|
100
|
|
101 Assembly code for the functions above:
|
|
102
|
273
|
103 .. code::
|
|
104
|
|
105 .code
|
|
106 insanemath:
|
|
107 L1:
|
|
108 load r0, sp - 4
|
|
109 cmp r0, 0
|
|
110 jl L2
|
|
111 dec r0
|
|
112 store r0, sp - 4
|
|
113 jmp L1
|
|
114 L2:
|
|
115 ret
|
272
|
116
|
273
|
117 agent1:
|
|
118 hlt?
|
272
|
119
|
273
|
120 agent2:
|
|
121 hlt?
|
272
|
122
|
273
|
123 main:
|
|
124 jmp agent1
|
272
|
125
|
273
|
126 .data
|
|
127 agent1_task:
|
|
128 dd 0
|
|
129 agent2_task:
|
|
130 dd 0
|
272
|
131
|