annotate doc/design.rst @ 275:6f2423df0675

Fixed serve arm-as
author Windel Bouwman
date Sat, 14 Sep 2013 17:29:10 +0200
parents ea93e0a7a31e
children
rev   line source
273
6b3a874edd6e Added some docs
Windel Bouwman
parents: 272
diff changeset
1 Design
6b3a874edd6e Added some docs
Windel Bouwman
parents: 272
diff changeset
2 ======
272
e64bae57cda8 refactor ir
Windel Bouwman
parents:
diff changeset
3
273
6b3a874edd6e Added some docs
Windel Bouwman
parents: 272
diff changeset
4 OS
6b3a874edd6e Added some docs
Windel Bouwman
parents: 272
diff changeset
5 --
6b3a874edd6e Added some docs
Windel Bouwman
parents: 272
diff changeset
6
6b3a874edd6e Added some docs
Windel Bouwman
parents: 272
diff changeset
7 Processes / threads
6b3a874edd6e Added some docs
Windel Bouwman
parents: 272
diff changeset
8 ~~~~~~~~~~~~~~~~~~~
272
e64bae57cda8 refactor ir
Windel Bouwman
parents:
diff changeset
9
e64bae57cda8 refactor ir
Windel Bouwman
parents:
diff changeset
10 Processes are completely seperated and fully pre-emptive.
e64bae57cda8 refactor ir
Windel Bouwman
parents:
diff changeset
11 This means a process can be unscheduled at any moment.
e64bae57cda8 refactor ir
Windel Bouwman
parents:
diff changeset
12
e64bae57cda8 refactor ir
Windel Bouwman
parents:
diff changeset
13 Threads are co-operative. This means they yield control
e64bae57cda8 refactor ir
Windel Bouwman
parents:
diff changeset
14 voluntary. This means that mutexes and locks are not required.
e64bae57cda8 refactor ir
Windel Bouwman
parents:
diff changeset
15 This is done with the built-in language feature called tasks.
e64bae57cda8 refactor ir
Windel Bouwman
parents:
diff changeset
16
e64bae57cda8 refactor ir
Windel Bouwman
parents:
diff changeset
17 If some heavy duty task must be performed, either way spawn
e64bae57cda8 refactor ir
Windel Bouwman
parents:
diff changeset
18 a new process, or yield frequently from this hard labour.
e64bae57cda8 refactor ir
Windel Bouwman
parents:
diff changeset
19
273
6b3a874edd6e Added some docs
Windel Bouwman
parents: 272
diff changeset
20 tasks
6b3a874edd6e Added some docs
Windel Bouwman
parents: 272
diff changeset
21 ~~~~~
272
e64bae57cda8 refactor ir
Windel Bouwman
parents:
diff changeset
22
273
6b3a874edd6e Added some docs
Windel Bouwman
parents: 272
diff changeset
23 Consider the following:
6b3a874edd6e Added some docs
Windel Bouwman
parents: 272
diff changeset
24
6b3a874edd6e Added some docs
Windel Bouwman
parents: 272
diff changeset
25 .. code::
272
e64bae57cda8 refactor ir
Windel Bouwman
parents:
diff changeset
26
273
6b3a874edd6e Added some docs
Windel Bouwman
parents: 272
diff changeset
27 function int insanemath(int a)
272
e64bae57cda8 refactor ir
Windel Bouwman
parents:
diff changeset
28 {
273
6b3a874edd6e Added some docs
Windel Bouwman
parents: 272
diff changeset
29 while (a > 0)
6b3a874edd6e Added some docs
Windel Bouwman
parents: 272
diff changeset
30 {
6b3a874edd6e Added some docs
Windel Bouwman
parents: 272
diff changeset
31 a = a -1;
6b3a874edd6e Added some docs
Windel Bouwman
parents: 272
diff changeset
32 resume agent1;
6b3a874edd6e Added some docs
Windel Bouwman
parents: 272
diff changeset
33 }
6b3a874edd6e Added some docs
Windel Bouwman
parents: 272
diff changeset
34 return a - 1;
272
e64bae57cda8 refactor ir
Windel Bouwman
parents:
diff changeset
35 }
e64bae57cda8 refactor ir
Windel Bouwman
parents:
diff changeset
36
273
6b3a874edd6e Added some docs
Windel Bouwman
parents: 272
diff changeset
37 task agent1()
6b3a874edd6e Added some docs
Windel Bouwman
parents: 272
diff changeset
38 {
6b3a874edd6e Added some docs
Windel Bouwman
parents: 272
diff changeset
39 start agent2;
6b3a874edd6e Added some docs
Windel Bouwman
parents: 272
diff changeset
40 }
272
e64bae57cda8 refactor ir
Windel Bouwman
parents:
diff changeset
41
273
6b3a874edd6e Added some docs
Windel Bouwman
parents: 272
diff changeset
42 task agent2()
6b3a874edd6e Added some docs
Windel Bouwman
parents: 272
diff changeset
43 {
6b3a874edd6e Added some docs
Windel Bouwman
parents: 272
diff changeset
44 insanemath(55);
6b3a874edd6e Added some docs
Windel Bouwman
parents: 272
diff changeset
45 insanemath(44);
6b3a874edd6e Added some docs
Windel Bouwman
parents: 272
diff changeset
46 }
272
e64bae57cda8 refactor ir
Windel Bouwman
parents:
diff changeset
47
273
6b3a874edd6e Added some docs
Windel Bouwman
parents: 272
diff changeset
48 task main()
6b3a874edd6e Added some docs
Windel Bouwman
parents: 272
diff changeset
49 {
6b3a874edd6e Added some docs
Windel Bouwman
parents: 272
diff changeset
50 start agent1;
6b3a874edd6e Added some docs
Windel Bouwman
parents: 272
diff changeset
51 join agent1;
6b3a874edd6e Added some docs
Windel Bouwman
parents: 272
diff changeset
52 }
6b3a874edd6e Added some docs
Windel Bouwman
parents: 272
diff changeset
53
272
e64bae57cda8 refactor ir
Windel Bouwman
parents:
diff changeset
54
e64bae57cda8 refactor ir
Windel Bouwman
parents:
diff changeset
55 Say to tasks are running in concurrent / parallel.
e64bae57cda8 refactor ir
Windel Bouwman
parents:
diff changeset
56
e64bae57cda8 refactor ir
Windel Bouwman
parents:
diff changeset
57
e64bae57cda8 refactor ir
Windel Bouwman
parents:
diff changeset
58
e64bae57cda8 refactor ir
Windel Bouwman
parents:
diff changeset
59 Stack layout for tasks.
e64bae57cda8 refactor ir
Windel Bouwman
parents:
diff changeset
60 ||
e64bae57cda8 refactor ir
Windel Bouwman
parents:
diff changeset
61 ||
e64bae57cda8 refactor ir
Windel Bouwman
parents:
diff changeset
62 \/
e64bae57cda8 refactor ir
Windel Bouwman
parents:
diff changeset
63 +---------+
e64bae57cda8 refactor ir
Windel Bouwman
parents:
diff changeset
64 | return address
e64bae57cda8 refactor ir
Windel Bouwman
parents:
diff changeset
65 | locals
e64bae57cda8 refactor ir
Windel Bouwman
parents:
diff changeset
66 |
e64bae57cda8 refactor ir
Windel Bouwman
parents:
diff changeset
67 +------
e64bae57cda8 refactor ir
Windel Bouwman
parents:
diff changeset
68 | return address
e64bae57cda8 refactor ir
Windel Bouwman
parents:
diff changeset
69 | locals
e64bae57cda8 refactor ir
Windel Bouwman
parents:
diff changeset
70 |
e64bae57cda8 refactor ir
Windel Bouwman
parents:
diff changeset
71 +---
e64bae57cda8 refactor ir
Windel Bouwman
parents:
diff changeset
72
e64bae57cda8 refactor ir
Windel Bouwman
parents:
diff changeset
73 Assembly code for the functions above:
e64bae57cda8 refactor ir
Windel Bouwman
parents:
diff changeset
74
273
6b3a874edd6e Added some docs
Windel Bouwman
parents: 272
diff changeset
75 .. code::
6b3a874edd6e Added some docs
Windel Bouwman
parents: 272
diff changeset
76
6b3a874edd6e Added some docs
Windel Bouwman
parents: 272
diff changeset
77 .code
6b3a874edd6e Added some docs
Windel Bouwman
parents: 272
diff changeset
78 insanemath:
6b3a874edd6e Added some docs
Windel Bouwman
parents: 272
diff changeset
79 L1:
6b3a874edd6e Added some docs
Windel Bouwman
parents: 272
diff changeset
80 load r0, sp - 4
6b3a874edd6e Added some docs
Windel Bouwman
parents: 272
diff changeset
81 cmp r0, 0
6b3a874edd6e Added some docs
Windel Bouwman
parents: 272
diff changeset
82 jl L2
6b3a874edd6e Added some docs
Windel Bouwman
parents: 272
diff changeset
83 dec r0
6b3a874edd6e Added some docs
Windel Bouwman
parents: 272
diff changeset
84 store r0, sp - 4
6b3a874edd6e Added some docs
Windel Bouwman
parents: 272
diff changeset
85 jmp L1
6b3a874edd6e Added some docs
Windel Bouwman
parents: 272
diff changeset
86 L2:
6b3a874edd6e Added some docs
Windel Bouwman
parents: 272
diff changeset
87 ret
272
e64bae57cda8 refactor ir
Windel Bouwman
parents:
diff changeset
88
273
6b3a874edd6e Added some docs
Windel Bouwman
parents: 272
diff changeset
89 agent1:
6b3a874edd6e Added some docs
Windel Bouwman
parents: 272
diff changeset
90 hlt?
272
e64bae57cda8 refactor ir
Windel Bouwman
parents:
diff changeset
91
273
6b3a874edd6e Added some docs
Windel Bouwman
parents: 272
diff changeset
92 agent2:
6b3a874edd6e Added some docs
Windel Bouwman
parents: 272
diff changeset
93 hlt?
272
e64bae57cda8 refactor ir
Windel Bouwman
parents:
diff changeset
94
273
6b3a874edd6e Added some docs
Windel Bouwman
parents: 272
diff changeset
95 main:
6b3a874edd6e Added some docs
Windel Bouwman
parents: 272
diff changeset
96 jmp agent1
272
e64bae57cda8 refactor ir
Windel Bouwman
parents:
diff changeset
97
273
6b3a874edd6e Added some docs
Windel Bouwman
parents: 272
diff changeset
98 .data
6b3a874edd6e Added some docs
Windel Bouwman
parents: 272
diff changeset
99 agent1_task:
6b3a874edd6e Added some docs
Windel Bouwman
parents: 272
diff changeset
100 dd 0
6b3a874edd6e Added some docs
Windel Bouwman
parents: 272
diff changeset
101 agent2_task:
6b3a874edd6e Added some docs
Windel Bouwman
parents: 272
diff changeset
102 dd 0
272
e64bae57cda8 refactor ir
Windel Bouwman
parents:
diff changeset
103