History

Improved handling of data items.

David Boddie committed 9 years ago

Commit 0d4808d1 parent d264bdd1 file · +48 −27Browse files

Unified · Split

dis.py+48−27
@@ -177,6 +177,9 @@ class Dis: · 176 unmodified lines
177177 def read_data(self, f):
178178
179179 self.data = []
180+ addresses = []
181+ base = 0
182+ offset = 0
180183
181184 while True:
182185
@@ -186,11 +189,35 @@ class Dis: · 3 unmodified lines
186189 if code == 0:
187190 break
188191
192+ count = code & 0x0f
189193 array_type = code >> 4
194+
195+ if count == 0:
196+ count = read_OP(f)
197+
198+ offset = read_OP(f)
199+
190200 if not 1 <= array_type <= 8:
191201 raise self.error("Unknown type in data item at 0x%x" % at)
192202
193− self.data.append(Data(f, code, array_type))
203+ elif array_type == 5:
204+ # Array
205+ type_index = _read(f, ">I")
206+ length = _read(f, ">I")
207+ type_ = self.types[type_index]
208+ #print "Array", type_, type_.size, length
209+ elif array_type == 6:
210+ # Set array address
211+ index = _read(f, ">I")
212+ #print "Set array address", index, "(offset=%i)" % offset
213+ addresses.append(base)
214+ base = offset + index
215+ elif array_type == 7:
216+ # Restore load address
217+ #print "Restore load address"
218+ base = addresses.pop()
219+ else:
220+ self.data.append(Data(f, code, count, base + offset, array_type))
194221
195222 def read_link(self, f):
196223
@@ -203,7 +230,10 @@ class Dis: · 6 unmodified lines
203230
204231 def list(self):
205232
206− print "\n".join(map(str, self.code))
233+ address = 0
234+ for ins in self.code:
235+ print hex(address), str(ins)
236+ address += ins.size
207237
208238
209239 class RuntimeFlag:
@@ -225,6 +255,8 @@ class Instruction: · 15 unmodified lines
225255
226256 def __init__(self, f):
227257
258+ self.start = f.tell()
259+
228260 self.opcode = read_B(f)
229261 self.address_mode = read_B(f)
230262
@@ -236,6 +268,8 @@ class Instruction: · 5 unmodified lines
236268
237269 destination = self.address_mode & 0x07
238270 self.destination, self.destination_type = self.read_operand(destination, f)
271+
272+ self.size = f.tell() - self.start
239273
240274 def read_operand(self, operand, f):
241275
@@ -251,6 +285,9 @@ class Instruction: · 9 unmodified lines
251285 elif operand == 0x02:
252286 operand = read_OP(f)
253287 operand_type = "$OP"
288+
289+ # No operand for 0x03.
290+
254291 elif operand == 0x04:
255292 operand = (read_OP(f), read_OP(f))
256293 operand_type = "SO(SO(MP))"
@@ -297,7 +334,7 @@ class Instruction: · 40 unmodified lines
297334 (self.destination, self.destination_type):
298335
299336 if optype == "$SI":
300− operands.append("$%s" % op)
337+ operands.append("$%x" % op)
301338 elif optype == "SO(FP)":
302339 operands.append("%i(fp)" % op)
303340 elif optype == "SO(MP)":
@@ -307,7 +344,7 @@ class Instruction: · 3 unmodified lines
307344 elif optype == "LO(FP)":
308345 operands.append("%i(fp)" % op)
309346 elif optype == "$OP":
310− operands.append("$%s" % op)
347+ operands.append("$%x" % op)
311348 elif optype == "SO(SO(MP))":
312349 operands.append("%i(%i(mp))" % op)
313350 elif optype == "SO(SO(FP))":
@@ -327,6 +364,9 @@ class Type: · 13 unmodified lines
327364
328365 def is_pointer(self, address):
329366
367+ # Each bit in the array represents a word in the type. If the bit is 1
368+ # then the word contains a pointer.
369+
330370 # Convert the address of a word to a bit offset in the array.
331371 bit = address / 4
332372 # Extract the byte containing the bit we want to check.
@@ -342,21 +382,17 @@ class Data: · 9 unmodified lines
342382 "UTF-8 encoded string", "64-bit float", "Array",
343383 "Set array address", "Restore load address"]
344384
345− def __init__(self, f, code, array_type):
385+ def __init__(self, f, code, count, address, array_type):
346386
347387 self.code = code
348− self.count = code & 0x0f
349−
350− if self.count == 0:
351− self.count = read_OP(f)
352−
353− self.offset = read_OP(f)
388+ self.count = count
389+ self.address = address
354390 self.array_type = array_type
355391
356392 self.array = []
357393 base = 0
358394 i = 0
359− while i < self.count:
395+ while i < count:
360396
361397 if array_type == 1:
362398 # 8-bit byte
@@ -370,21 +406,6 @@ class Data: · 7 unmodified lines
370406 elif array_type == 4:
371407 # 64-bit float
372408 self.array.append(read_F(f))
373− elif array_type == 5:
374− # Array
375− index = _read(f, ">I")
376− length = _read(f, ">I")
377− print "Array", index, length, self.count
378− #self.array.append(read_F(f))
379− elif array_type == 6:
380− # Set array address
381− index = _read(f, ">I")
382− print "Set array address", index, self.count
383− #self.array.append(read_F(f))
384− elif array_type == 7:
385− # Restore load address
386− print "Restore load address"
387− #self.array.append(read_F(f))
388409 elif array_type == 8:
389410 # 64-bit integer
390411 self.array.append(read_L(f))