283
|
1 module memory;
|
293
|
2
|
377
|
3 import arch;
|
381
|
4 import io;
|
283
|
5
|
410
|
6 const int pagesize = 4096;
|
301
|
7 var int ptr;
|
283
|
8
|
393
|
9 // Let the heap grow upwards..
|
|
10
|
410
|
11 public function void init()
|
367
|
12 {
|
408
|
13 ptr = 0x60080000;
|
367
|
14 }
|
|
15
|
410
|
16 public function byte* alloc(int size)
|
283
|
17 {
|
393
|
18 var int ptr2;
|
|
19 ptr2 = ptr;
|
|
20
|
|
21 io.print2("alloc size ", size);
|
|
22 io.print2("alloc address ", ptr);
|
|
23
|
|
24 // Increment new free point:
|
296
|
25 ptr = ptr + size;
|
402
|
26 return ptr2;
|
283
|
27 }
|
|
28
|
410
|
29 function bool is_marked(int page)
|
|
30 {
|
|
31 return true;
|
|
32 }
|
|
33
|
|
34 function void set_mark(int page, bool mark)
|
|
35 {
|
|
36
|
|
37 }
|
|
38
|
408
|
39 function byte* allocate_physical()
|
|
40 {
|
410
|
41 var int i;
|
|
42 for (i = 0; i < 100; i += 1)
|
|
43 {
|
|
44 if (not is_marked(i))
|
|
45 {
|
|
46 return i * pagesize;
|
|
47 }
|
|
48 }
|
|
49
|
408
|
50 return 0;
|
|
51 }
|
|
52
|
|
53 function byte* allocate_virtual(byte* address)
|
|
54 {
|
|
55 var byte* address2;
|
|
56 address2 = allocate_physical();
|
|
57 return address2;
|
|
58 }
|
|
59
|
410
|
60 // Util function:
|
|
61 public function void memcpy(byte* dst, byte* src, int size)
|
393
|
62 {
|
|
63 var int i;
|
408
|
64 io.print2("memcpy to ", cast<int>(dst));
|
|
65 io.print2("memcpy from ", cast<int>(src));
|
410
|
66 io.print2("memcpy size ", size);
|
408
|
67 for (i = 0; i < size; i += 1)
|
393
|
68 {
|
|
69 *(dst + i) = *(src + i);
|
|
70 }
|
|
71 }
|
283
|
72
|
410
|
73
|