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