annotate kernel/process.c3 @ 408:ad6be5454067

Added image build task
author Windel Bouwman
date Sat, 21 Feb 2015 12:17:47 +0100
parents 9eb1fc6aad6c
children 6aa9743ed362
rev   line source
283
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
1 module process;
300
Windel Bouwman
parents: 296
diff changeset
2
283
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
3 import memory;
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
4 import kernel;
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
5
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
6 // process type definition:
296
9417caea2eb3 Directorized some backend files
Windel Bouwman
parents: 295
diff changeset
7 type struct {
283
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
8 int id;
292
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents: 283
diff changeset
9 int status;
407
9eb1fc6aad6c Minor improvements
Windel Bouwman
parents: 402
diff changeset
10 process_t* next;
9eb1fc6aad6c Minor improvements
Windel Bouwman
parents: 402
diff changeset
11 process_t* prev;
283
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
12 } process_t;
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
13
407
9eb1fc6aad6c Minor improvements
Windel Bouwman
parents: 402
diff changeset
14 var process_t* first_process;
9eb1fc6aad6c Minor improvements
Windel Bouwman
parents: 402
diff changeset
15 var process_t* last_process;
306
b145f8e6050b Start on c3 rewrite
Windel Bouwman
parents: 301
diff changeset
16 var int next_pid;
408
ad6be5454067 Added image build task
Windel Bouwman
parents: 407
diff changeset
17 var process_t* current;
283
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
18
296
9417caea2eb3 Directorized some backend files
Windel Bouwman
parents: 295
diff changeset
19 function void init()
283
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
20 {
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
21 next_pid = 0;
407
9eb1fc6aad6c Minor improvements
Windel Bouwman
parents: 402
diff changeset
22 first_process = 0;
9eb1fc6aad6c Minor improvements
Windel Bouwman
parents: 402
diff changeset
23 last_process = 0;
283
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
24 }
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
25
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
26 /*
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
27 Create a new process.
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
28 */
402
0fb6633c42f6 Moved several files to logical locations
Windel Bouwman
parents: 393
diff changeset
29 function process_t* create()
283
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
30 {
301
6753763d3bec merge codegen into ppci package
Windel Bouwman
parents: 300
diff changeset
31 var process_t* p;
389
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 359
diff changeset
32
407
9eb1fc6aad6c Minor improvements
Windel Bouwman
parents: 402
diff changeset
33 p = memory.alloc(sizeof(process_t));
283
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
34 p->id = next_pid;
393
6ae782a085e0 Added init program
Windel Bouwman
parents: 389
diff changeset
35 p->status = 0; // Ready!
407
9eb1fc6aad6c Minor improvements
Windel Bouwman
parents: 402
diff changeset
36 p->next = 0;
9eb1fc6aad6c Minor improvements
Windel Bouwman
parents: 402
diff changeset
37 p->prev = 0;
389
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 359
diff changeset
38
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 359
diff changeset
39 // Increment PID:
300
Windel Bouwman
parents: 296
diff changeset
40 next_pid = next_pid + 1;
389
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 359
diff changeset
41
407
9eb1fc6aad6c Minor improvements
Windel Bouwman
parents: 402
diff changeset
42 return p;
9eb1fc6aad6c Minor improvements
Windel Bouwman
parents: 402
diff changeset
43 }
9eb1fc6aad6c Minor improvements
Windel Bouwman
parents: 402
diff changeset
44
9eb1fc6aad6c Minor improvements
Windel Bouwman
parents: 402
diff changeset
45 function void enqueue(process_t* p)
9eb1fc6aad6c Minor improvements
Windel Bouwman
parents: 402
diff changeset
46 {
389
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 359
diff changeset
47 // Store it in the list:
407
9eb1fc6aad6c Minor improvements
Windel Bouwman
parents: 402
diff changeset
48 if (first_process == cast<process_t*>(0))
389
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 359
diff changeset
49 {
407
9eb1fc6aad6c Minor improvements
Windel Bouwman
parents: 402
diff changeset
50 first_process = p;
9eb1fc6aad6c Minor improvements
Windel Bouwman
parents: 402
diff changeset
51 last_process = p;
389
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 359
diff changeset
52 }
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 359
diff changeset
53 else
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 359
diff changeset
54 {
407
9eb1fc6aad6c Minor improvements
Windel Bouwman
parents: 402
diff changeset
55 // Update pointers:
9eb1fc6aad6c Minor improvements
Windel Bouwman
parents: 402
diff changeset
56 last_process->next = p;
9eb1fc6aad6c Minor improvements
Windel Bouwman
parents: 402
diff changeset
57 p->prev = last_process;
9eb1fc6aad6c Minor improvements
Windel Bouwman
parents: 402
diff changeset
58 last_process = p;
389
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 359
diff changeset
59 }
283
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
60 }
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
61
407
9eb1fc6aad6c Minor improvements
Windel Bouwman
parents: 402
diff changeset
62 function void kill(process_t* p)
283
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
63 {
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
64 // clean memory
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
65 }
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
66
300
Windel Bouwman
parents: 296
diff changeset
67 function process_t* byId(int id)
292
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents: 283
diff changeset
68 {
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents: 283
diff changeset
69 // Perform lookup
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents: 283
diff changeset
70 return 0;
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents: 283
diff changeset
71 }
283
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
72
408
ad6be5454067 Added image build task
Windel Bouwman
parents: 407
diff changeset
73
ad6be5454067 Added image build task
Windel Bouwman
parents: 407
diff changeset
74 function void execute_next()
ad6be5454067 Added image build task
Windel Bouwman
parents: 407
diff changeset
75 {
ad6be5454067 Added image build task
Windel Bouwman
parents: 407
diff changeset
76 var process.process_t *old;
ad6be5454067 Added image build task
Windel Bouwman
parents: 407
diff changeset
77
ad6be5454067 Added image build task
Windel Bouwman
parents: 407
diff changeset
78 old = 0;
ad6be5454067 Added image build task
Windel Bouwman
parents: 407
diff changeset
79
ad6be5454067 Added image build task
Windel Bouwman
parents: 407
diff changeset
80 if (old != current)
ad6be5454067 Added image build task
Windel Bouwman
parents: 407
diff changeset
81 {
ad6be5454067 Added image build task
Windel Bouwman
parents: 407
diff changeset
82 //execute(current);
ad6be5454067 Added image build task
Windel Bouwman
parents: 407
diff changeset
83 }
ad6be5454067 Added image build task
Windel Bouwman
parents: 407
diff changeset
84
ad6be5454067 Added image build task
Windel Bouwman
parents: 407
diff changeset
85 kernel.panic();
ad6be5454067 Added image build task
Windel Bouwman
parents: 407
diff changeset
86 }