annotate kernel/memory.c3 @ 410:6aa9743ed362 tip

Reflect change in c3 public modifier
author Windel Bouwman
date Mon, 23 Feb 2015 21:06:04 +0100
parents ad6be5454067
children
rev   line source
283
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
1 module memory;
293
6aa721e7b10b Try to improve build sequence
Windel Bouwman
parents: 283
diff changeset
2
377
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 367
diff changeset
3 import arch;
381
6df89163e114 Fix section and ldr pseudo instruction
Windel Bouwman
parents: 377
diff changeset
4 import io;
283
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
5
410
6aa9743ed362 Reflect change in c3 public modifier
Windel Bouwman
parents: 408
diff changeset
6 const int pagesize = 4096;
301
6753763d3bec merge codegen into ppci package
Windel Bouwman
parents: 296
diff changeset
7 var int ptr;
283
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
8
393
6ae782a085e0 Added init program
Windel Bouwman
parents: 389
diff changeset
9 // Let the heap grow upwards..
6ae782a085e0 Added init program
Windel Bouwman
parents: 389
diff changeset
10
410
6aa9743ed362 Reflect change in c3 public modifier
Windel Bouwman
parents: 408
diff changeset
11 public function void init()
367
577ed7fb3fe4 Try to make thumb work again
Windel Bouwman
parents: 359
diff changeset
12 {
408
ad6be5454067 Added image build task
Windel Bouwman
parents: 402
diff changeset
13 ptr = 0x60080000;
367
577ed7fb3fe4 Try to make thumb work again
Windel Bouwman
parents: 359
diff changeset
14 }
577ed7fb3fe4 Try to make thumb work again
Windel Bouwman
parents: 359
diff changeset
15
410
6aa9743ed362 Reflect change in c3 public modifier
Windel Bouwman
parents: 408
diff changeset
16 public function byte* alloc(int size)
283
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
17 {
393
6ae782a085e0 Added init program
Windel Bouwman
parents: 389
diff changeset
18 var int ptr2;
6ae782a085e0 Added init program
Windel Bouwman
parents: 389
diff changeset
19 ptr2 = ptr;
6ae782a085e0 Added init program
Windel Bouwman
parents: 389
diff changeset
20
6ae782a085e0 Added init program
Windel Bouwman
parents: 389
diff changeset
21 io.print2("alloc size ", size);
6ae782a085e0 Added init program
Windel Bouwman
parents: 389
diff changeset
22 io.print2("alloc address ", ptr);
6ae782a085e0 Added init program
Windel Bouwman
parents: 389
diff changeset
23
6ae782a085e0 Added init program
Windel Bouwman
parents: 389
diff changeset
24 // Increment new free point:
296
9417caea2eb3 Directorized some backend files
Windel Bouwman
parents: 293
diff changeset
25 ptr = ptr + size;
402
0fb6633c42f6 Moved several files to logical locations
Windel Bouwman
parents: 393
diff changeset
26 return ptr2;
283
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
27 }
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
28
410
6aa9743ed362 Reflect change in c3 public modifier
Windel Bouwman
parents: 408
diff changeset
29 function bool is_marked(int page)
6aa9743ed362 Reflect change in c3 public modifier
Windel Bouwman
parents: 408
diff changeset
30 {
6aa9743ed362 Reflect change in c3 public modifier
Windel Bouwman
parents: 408
diff changeset
31 return true;
6aa9743ed362 Reflect change in c3 public modifier
Windel Bouwman
parents: 408
diff changeset
32 }
6aa9743ed362 Reflect change in c3 public modifier
Windel Bouwman
parents: 408
diff changeset
33
6aa9743ed362 Reflect change in c3 public modifier
Windel Bouwman
parents: 408
diff changeset
34 function void set_mark(int page, bool mark)
6aa9743ed362 Reflect change in c3 public modifier
Windel Bouwman
parents: 408
diff changeset
35 {
6aa9743ed362 Reflect change in c3 public modifier
Windel Bouwman
parents: 408
diff changeset
36
6aa9743ed362 Reflect change in c3 public modifier
Windel Bouwman
parents: 408
diff changeset
37 }
6aa9743ed362 Reflect change in c3 public modifier
Windel Bouwman
parents: 408
diff changeset
38
408
ad6be5454067 Added image build task
Windel Bouwman
parents: 402
diff changeset
39 function byte* allocate_physical()
ad6be5454067 Added image build task
Windel Bouwman
parents: 402
diff changeset
40 {
410
6aa9743ed362 Reflect change in c3 public modifier
Windel Bouwman
parents: 408
diff changeset
41 var int i;
6aa9743ed362 Reflect change in c3 public modifier
Windel Bouwman
parents: 408
diff changeset
42 for (i = 0; i < 100; i += 1)
6aa9743ed362 Reflect change in c3 public modifier
Windel Bouwman
parents: 408
diff changeset
43 {
6aa9743ed362 Reflect change in c3 public modifier
Windel Bouwman
parents: 408
diff changeset
44 if (not is_marked(i))
6aa9743ed362 Reflect change in c3 public modifier
Windel Bouwman
parents: 408
diff changeset
45 {
6aa9743ed362 Reflect change in c3 public modifier
Windel Bouwman
parents: 408
diff changeset
46 return i * pagesize;
6aa9743ed362 Reflect change in c3 public modifier
Windel Bouwman
parents: 408
diff changeset
47 }
6aa9743ed362 Reflect change in c3 public modifier
Windel Bouwman
parents: 408
diff changeset
48 }
6aa9743ed362 Reflect change in c3 public modifier
Windel Bouwman
parents: 408
diff changeset
49
408
ad6be5454067 Added image build task
Windel Bouwman
parents: 402
diff changeset
50 return 0;
ad6be5454067 Added image build task
Windel Bouwman
parents: 402
diff changeset
51 }
ad6be5454067 Added image build task
Windel Bouwman
parents: 402
diff changeset
52
ad6be5454067 Added image build task
Windel Bouwman
parents: 402
diff changeset
53 function byte* allocate_virtual(byte* address)
ad6be5454067 Added image build task
Windel Bouwman
parents: 402
diff changeset
54 {
ad6be5454067 Added image build task
Windel Bouwman
parents: 402
diff changeset
55 var byte* address2;
ad6be5454067 Added image build task
Windel Bouwman
parents: 402
diff changeset
56 address2 = allocate_physical();
ad6be5454067 Added image build task
Windel Bouwman
parents: 402
diff changeset
57 return address2;
ad6be5454067 Added image build task
Windel Bouwman
parents: 402
diff changeset
58 }
ad6be5454067 Added image build task
Windel Bouwman
parents: 402
diff changeset
59
410
6aa9743ed362 Reflect change in c3 public modifier
Windel Bouwman
parents: 408
diff changeset
60 // Util function:
6aa9743ed362 Reflect change in c3 public modifier
Windel Bouwman
parents: 408
diff changeset
61 public function void memcpy(byte* dst, byte* src, int size)
393
6ae782a085e0 Added init program
Windel Bouwman
parents: 389
diff changeset
62 {
6ae782a085e0 Added init program
Windel Bouwman
parents: 389
diff changeset
63 var int i;
408
ad6be5454067 Added image build task
Windel Bouwman
parents: 402
diff changeset
64 io.print2("memcpy to ", cast<int>(dst));
ad6be5454067 Added image build task
Windel Bouwman
parents: 402
diff changeset
65 io.print2("memcpy from ", cast<int>(src));
410
6aa9743ed362 Reflect change in c3 public modifier
Windel Bouwman
parents: 408
diff changeset
66 io.print2("memcpy size ", size);
408
ad6be5454067 Added image build task
Windel Bouwman
parents: 402
diff changeset
67 for (i = 0; i < size; i += 1)
393
6ae782a085e0 Added init program
Windel Bouwman
parents: 389
diff changeset
68 {
6ae782a085e0 Added init program
Windel Bouwman
parents: 389
diff changeset
69 *(dst + i) = *(src + i);
6ae782a085e0 Added init program
Windel Bouwman
parents: 389
diff changeset
70 }
6ae782a085e0 Added init program
Windel Bouwman
parents: 389
diff changeset
71 }
283
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
72
410
6aa9743ed362 Reflect change in c3 public modifier
Windel Bouwman
parents: 408
diff changeset
73