about summary refs log tree commit diff stats
path: root/subx
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2019-05-11 23:10:42 -0700
committerKartik Agaram <vc@akkartik.com>2019-05-11 23:11:34 -0700
commitd5d43e044d16335a3a865a8c9f5aea5cbad73360 (patch)
tree31d52d72e2a7babf378f421a4ed85242e9d76135 /subx
parente59a74abddaf0b4f9a39432da21c6a98eae46df6 (diff)
downloadmu-d5d43e044d16335a3a865a8c9f5aea5cbad73360.tar.gz
5157
Support allocating more than 0x01000000 bytes (8MB) to a segment in the
VM.
Diffstat (limited to 'subx')
-rw-r--r--subx/012elf.cc4
-rw-r--r--subx/020syscalls.cc16
2 files changed, 10 insertions, 10 deletions
diff --git a/subx/012elf.cc b/subx/012elf.cc
index 2fea60db..0fa9d793 100644
--- a/subx/012elf.cc
+++ b/subx/012elf.cc
@@ -149,7 +149,9 @@ void load_segment_from_program_header(uint8_t* elf_contents, int segment_index,
 // Once we do, we can go up to 0xc0000000; higher addresses are reserved for
 // the Linux kernel.
 const int CODE_SEGMENT      = 0x09000000;
-const int DATA_SEGMENT =      0x0a000000;
+const int DATA_SEGMENT      = 0x0a000000;
+const int START_HEAP        = 0x0b000000;
+const int END_HEAP          = 0x7d000000;
 const int STACK_SEGMENT     = 0x7d000000;
 const int AFTER_STACK       = 0x7e000000;
 const int ARGV_DATA_SEGMENT = 0x7f000000;
diff --git a/subx/020syscalls.cc b/subx/020syscalls.cc
index 444c9fd5..eb8ebcce 100644
--- a/subx/020syscalls.cc
+++ b/subx/020syscalls.cc
@@ -111,21 +111,19 @@ void check_mode(int reg) {
 
 :(before "End Globals")
 // Very primitive/fixed/insecure mmap segments for now.
-// For now we avoid addresses with the most significant bit set; SubX doesn't
-// support unsigned comparison yet (https://github.com/akkartik/mu/issues/30)
-// Once we do, we can go up to 0xc0000000; higher addresses are reserved for
-// the Linux kernel.
-uint32_t Next_segment = 0x7c000000;
+uint32_t Segments_allocated_above = END_HEAP;
 const uint32_t SPACE_FOR_SEGMENT = 0x01000000;
 :(code)
+// always allocate multiples of the segment size
 uint32_t new_segment(uint32_t length) {
-  uint32_t result = Next_segment;
-  Mem.push_back(vma(Next_segment, Next_segment+length));
-  Next_segment -= SPACE_FOR_SEGMENT;
-  if (Next_segment <= DATA_SEGMENT) {
+  assert(length > 0);
+  uint32_t result = (Segments_allocated_above - length) & 0xff000000;
+  if (result <= START_HEAP) {
     raise << "Allocated too many segments; the VM ran out of memory. "
           << "Maybe SPACE_FOR_SEGMENT can be smaller?\n" << end();
     exit(1);
   }
+  Mem.push_back(vma(result, result+length));
+  Segments_allocated_above = result;
   return result;
 }
520' href='/akkartik/mu/commit/html/baremetal/502test.mu.html?h=hlt&id=20d6be52405130930fde9ca5bb5e95131ba4e659'>20d6be52 ^
372367f5 ^
20d6be52 ^

535fe9ac ^
82171a0f ^
535fe9ac ^

82171a0f ^
3350c34a ^








372367f5 ^
3350c34a ^


82171a0f ^
3350c34a ^

82171a0f ^
3350c34a ^




372367f5 ^
3350c34a ^


82171a0f ^
3350c34a ^

82171a0f ^
3350c34a ^


20d6be52 ^



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106