Unified · Split
| @@ -177,6 +177,9 @@ class Dis: · 176 unmodified lines | ||
| 177 | 177 | def read_data(self, f): |
| 178 | 178 | |
| 179 | 179 | self.data = [] |
| 180 | + addresses = [] | |
| 181 | + base = 0 | |
| 182 | + offset = 0 | |
| 180 | 183 | |
| 181 | 184 | while True: |
| 182 | 185 | |
| @@ -186,11 +189,35 @@ class Dis: · 3 unmodified lines | ||
| 186 | 189 | if code == 0: |
| 187 | 190 | break |
| 188 | 191 | |
| 192 | + count = code & 0x0f | |
| 189 | 193 | array_type = code >> 4 |
| 194 | + | |
| 195 | + if count == 0: | |
| 196 | + count = read_OP(f) | |
| 197 | + | |
| 198 | + offset = read_OP(f) | |
| 199 | + | |
| 190 | 200 | if not 1 <= array_type <= 8: |
| 191 | 201 | raise self.error("Unknown type in data item at 0x%x" % at) |
| 192 | 202 | |
| 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)) | |
| 194 | 221 | |
| 195 | 222 | def read_link(self, f): |
| 196 | 223 | |
| @@ -203,7 +230,10 @@ class Dis: · 6 unmodified lines | ||
| 203 | 230 | |
| 204 | 231 | def list(self): |
| 205 | 232 | |
| 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 | |
| 207 | 237 | |
| 208 | 238 | |
| 209 | 239 | class RuntimeFlag: |
| @@ -225,6 +255,8 @@ class Instruction: · 15 unmodified lines | ||
| 225 | 255 | |
| 226 | 256 | def __init__(self, f): |
| 227 | 257 | |
| 258 | + self.start = f.tell() | |
| 259 | + | |
| 228 | 260 | self.opcode = read_B(f) |
| 229 | 261 | self.address_mode = read_B(f) |
| 230 | 262 | |
| @@ -236,6 +268,8 @@ class Instruction: · 5 unmodified lines | ||
| 236 | 268 | |
| 237 | 269 | destination = self.address_mode & 0x07 |
| 238 | 270 | self.destination, self.destination_type = self.read_operand(destination, f) |
| 271 | + | |
| 272 | + self.size = f.tell() - self.start | |
| 239 | 273 | |
| 240 | 274 | def read_operand(self, operand, f): |
| 241 | 275 | |
| @@ -251,6 +285,9 @@ class Instruction: · 9 unmodified lines | ||
| 251 | 285 | elif operand == 0x02: |
| 252 | 286 | operand = read_OP(f) |
| 253 | 287 | operand_type = "$OP" |
| 288 | + | |
| 289 | + # No operand for 0x03. | |
| 290 | + | |
| 254 | 291 | elif operand == 0x04: |
| 255 | 292 | operand = (read_OP(f), read_OP(f)) |
| 256 | 293 | operand_type = "SO(SO(MP))" |
| @@ -297,7 +334,7 @@ class Instruction: · 40 unmodified lines | ||
| 297 | 334 | (self.destination, self.destination_type): |
| 298 | 335 | |
| 299 | 336 | if optype == "$SI": |
| 300 | − operands.append("$%s" % op) | |
| 337 | + operands.append("$%x" % op) | |
| 301 | 338 | elif optype == "SO(FP)": |
| 302 | 339 | operands.append("%i(fp)" % op) |
| 303 | 340 | elif optype == "SO(MP)": |
| @@ -307,7 +344,7 @@ class Instruction: · 3 unmodified lines | ||
| 307 | 344 | elif optype == "LO(FP)": |
| 308 | 345 | operands.append("%i(fp)" % op) |
| 309 | 346 | elif optype == "$OP": |
| 310 | − operands.append("$%s" % op) | |
| 347 | + operands.append("$%x" % op) | |
| 311 | 348 | elif optype == "SO(SO(MP))": |
| 312 | 349 | operands.append("%i(%i(mp))" % op) |
| 313 | 350 | elif optype == "SO(SO(FP))": |
| @@ -327,6 +364,9 @@ class Type: · 13 unmodified lines | ||
| 327 | 364 | |
| 328 | 365 | def is_pointer(self, address): |
| 329 | 366 | |
| 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 | + | |
| 330 | 370 | # Convert the address of a word to a bit offset in the array. |
| 331 | 371 | bit = address / 4 |
| 332 | 372 | # Extract the byte containing the bit we want to check. |
| @@ -342,21 +382,17 @@ class Data: · 9 unmodified lines | ||
| 342 | 382 | "UTF-8 encoded string", "64-bit float", "Array", |
| 343 | 383 | "Set array address", "Restore load address"] |
| 344 | 384 | |
| 345 | − def __init__(self, f, code, array_type): | |
| 385 | + def __init__(self, f, code, count, address, array_type): | |
| 346 | 386 | |
| 347 | 387 | 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 | |
| 354 | 390 | self.array_type = array_type |
| 355 | 391 | |
| 356 | 392 | self.array = [] |
| 357 | 393 | base = 0 |
| 358 | 394 | i = 0 |
| 359 | − while i < self.count: | |
| 395 | + while i < count: | |
| 360 | 396 | |
| 361 | 397 | if array_type == 1: |
| 362 | 398 | # 8-bit byte |
| @@ -370,21 +406,6 @@ class Data: · 7 unmodified lines | ||
| 370 | 406 | elif array_type == 4: |
| 371 | 407 | # 64-bit float |
| 372 | 408 | 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)) | |
| 388 | 409 | elif array_type == 8: |
| 389 | 410 | # 64-bit integer |
| 390 | 411 | self.array.append(read_L(f)) |