-
Notifications
You must be signed in to change notification settings - Fork 65
/
SpurSimulatedMemory.class.st
238 lines (182 loc) · 4.89 KB
/
SpurSimulatedMemory.class.st
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
Class {
#name : #SpurSimulatedMemory,
#superclass : #Object,
#instVars : [
'memoryObject',
'initialAddress'
],
#category : #'VMMaker-SpurMemoryManager'
}
{ #category : #'instance creation' }
SpurSimulatedMemory class >> new: slots [
^ self new
initializeSlots: slots;
yourself
]
{ #category : #accessing }
SpurSimulatedMemory >> at: address [
^ memoryObject
integerAt: (address - 1 * self bytesPerElement + 1) - initialAddress
size: self bytesPerElement
signed: false
]
{ #category : #accessing }
SpurSimulatedMemory >> at: address put: a32BitValue [
^ memoryObject
integerAt: (address - 1 * self bytesPerElement + 1) - initialAddress
put: a32BitValue
size: self bytesPerElement
signed: false
]
{ #category : #'as yet unclassified' }
SpurSimulatedMemory >> byteSize [
^ self size
]
{ #category : #accessing }
SpurSimulatedMemory >> bytesPerElement [
^ 4
]
{ #category : #copying }
SpurSimulatedMemory >> copyFrom: anAddress [
^ memoryObject
copyFrom: anAddress - initialAddress + 1
to: memoryObject size
]
{ #category : #accessing }
SpurSimulatedMemory >> copyFrom: start to: end [
^ memoryObject copyFrom: start - initialAddress + 1 to: end - initialAddress + 1
]
{ #category : #accessing }
SpurSimulatedMemory >> initialAddress [
^ initialAddress
]
{ #category : #accessing }
SpurSimulatedMemory >> initialAddress: anAddress [
initialAddress := anAddress
]
{ #category : #accessing }
SpurSimulatedMemory >> initialize [
super initialize.
initialAddress := 0"2*1024*1024".
]
{ #category : #initialization }
SpurSimulatedMemory >> initializeSlots: anInteger [
"Allocate a memory to hold at least `anInteger` elements of size `self bytesPerElement`.
This implementation will allocate memory in multiples of 4KB, allocating a bit more memory than required sometimes.
This is required to run on the unicorn simulator which needs memory in multiples of 4KB."
| bytesToAllocate trailingBytes |
bytesToAllocate := anInteger * self bytesPerElement.
"Calculate how many bytes to add to reach 4KB"
trailingBytes := anInteger * self bytesPerElement \\ (4 * 1024).
trailingBytes = 0 ifFalse: [ trailingBytes := (4 * 1024) - trailingBytes ].
memoryObject := ByteArray new: bytesToAllocate + trailingBytes
]
{ #category : #loading }
SpurSimulatedMemory >> loadFrom: aMultiByteFileStream size: size inPosition: startingPosition [
^ aMultiByteFileStream
readInto: memoryObject
startingAt: startingPosition - initialAddress + 1
count: size
]
{ #category : #accessing }
SpurSimulatedMemory >> long64At: address [
^ memoryObject
integerAt: address - initialAddress
size: 8
signed: true
]
{ #category : #accessing }
SpurSimulatedMemory >> long64At: address put: aValue [
^ memoryObject
integerAt: address - initialAddress
put: aValue
size: 8
signed: true
]
{ #category : #'as yet unclassified' }
SpurSimulatedMemory >> longAt: address [
^ memoryObject
integerAt: address - initialAddress
size: 4
signed: true
]
{ #category : #accessing }
SpurSimulatedMemory >> longAt: address put: aValue [
^ memoryObject
integerAt: address - initialAddress
put: aValue
size: 4
signed: true
]
{ #category : #converting }
SpurSimulatedMemory >> memoryObject [
^ memoryObject
]
{ #category : #replacing }
SpurSimulatedMemory >> replaceFrom: start to: stop with: replacement startingAt: repStart [
memoryObject replaceFrom: start to: stop with: replacement memoryObject startingAt: repStart
]
{ #category : #accessing }
SpurSimulatedMemory >> size [
^ memoryObject size
]
{ #category : #accessing }
SpurSimulatedMemory >> unsignedByteAt: anAddress [
^ memoryObject
integerAt: anAddress - initialAddress
size: 1
signed: false
]
{ #category : #accessing }
SpurSimulatedMemory >> unsignedByteAt: anAddress put: aValue [
^ memoryObject
integerAt: anAddress - initialAddress
put: aValue
size: 1
signed: false
]
{ #category : #accessing }
SpurSimulatedMemory >> unsignedLong64At: address [
^ memoryObject
integerAt: address - initialAddress
size: 8
signed: false
]
{ #category : #accessing }
SpurSimulatedMemory >> unsignedLong64At: address put: aValue [
^ memoryObject
integerAt: address - initialAddress
put: aValue
size: 8
signed: false
]
{ #category : #accessing }
SpurSimulatedMemory >> unsignedLongAt: address [
^ memoryObject
integerAt: address - initialAddress
size: 4
signed: false
]
{ #category : #accessing }
SpurSimulatedMemory >> unsignedLongAt: address put: aValue [
^ memoryObject
integerAt: address - initialAddress
put: aValue
size: 4
signed: false
]
{ #category : #accessing }
SpurSimulatedMemory >> unsignedShortAt: anAddress [
^ memoryObject
integerAt: anAddress - initialAddress
size: 2
signed: false
]
{ #category : #accessing }
SpurSimulatedMemory >> unsignedShortAt: anAddress put: aValue [
^ memoryObject
integerAt: anAddress - initialAddress
put: aValue
size: 2
signed: false
]