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