annotate doc/os.rst @ 410:6aa9743ed362 tip

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