diff options
Diffstat (limited to 'src/jit/dis_mips.lua')
-rw-r--r-- | src/jit/dis_mips.lua | 79 |
1 files changed, 47 insertions, 32 deletions
diff --git a/src/jit/dis_mips.lua b/src/jit/dis_mips.lua index 02dfc172..a12b8e62 100644 --- a/src/jit/dis_mips.lua +++ b/src/jit/dis_mips.lua | |||
@@ -34,15 +34,17 @@ local map_special = { | |||
34 | "jrS", "jalrD1S", "movzDST", "movnDST", | 34 | "jrS", "jalrD1S", "movzDST", "movnDST", |
35 | "syscallY", "breakY", false, "sync", | 35 | "syscallY", "breakY", false, "sync", |
36 | "mfhiD", "mthiS", "mfloD", "mtloS", | 36 | "mfhiD", "mthiS", "mfloD", "mtloS", |
37 | false, false, false, false, | 37 | "dsllvDST", false, "dsrlvDST", "dsravDST", |
38 | "multST", "multuST", "divST", "divuST", | 38 | "multST", "multuST", "divST", "divuST", |
39 | false, false, false, false, | 39 | "dmultST", "dmultuST", "ddivST", "ddivuST", |
40 | "addDST", "addu|moveDST0", "subDST", "subu|neguDS0T", | 40 | "addDST", "addu|moveDST0", "subDST", "subu|neguDS0T", |
41 | "andDST", "orDST", "xorDST", "nor|notDST0", | 41 | "andDST", "or|moveDST0", "xorDST", "nor|notDST0", |
42 | false, false, "sltDST", "sltuDST", | 42 | false, false, "sltDST", "sltuDST", |
43 | false, false, false, false, | 43 | "daddDST", "dadduDST", "dsubDST", "dsubuDST", |
44 | "tgeSTZ", "tgeuSTZ", "tltSTZ", "tltuSTZ", | 44 | "tgeSTZ", "tgeuSTZ", "tltSTZ", "tltuSTZ", |
45 | "teqSTZ", false, "tneSTZ", | 45 | "teqSTZ", false, "tneSTZ", false, |
46 | "dsllDTA", false, "dsrlDTA", "dsraDTA", | ||
47 | "dsll32DTA", false, "dsrl32DTA", "dsra32DTA", | ||
46 | } | 48 | } |
47 | 49 | ||
48 | local map_special2 = { | 50 | local map_special2 = { |
@@ -60,11 +62,17 @@ local map_bshfl = { | |||
60 | [24] = "sehDT", | 62 | [24] = "sehDT", |
61 | } | 63 | } |
62 | 64 | ||
65 | local map_dbshfl = { | ||
66 | shift = 6, mask = 31, | ||
67 | [2] = "dsbhDT", | ||
68 | [5] = "dshdDT", | ||
69 | } | ||
70 | |||
63 | local map_special3 = { | 71 | local map_special3 = { |
64 | shift = 0, mask = 63, | 72 | shift = 0, mask = 63, |
65 | [0] = "extTSAK", [4] = "insTSAL", | 73 | [0] = "extTSAK", [1] = "dextmTSAP", [3] = "dextTSAK", |
66 | [32] = map_bshfl, | 74 | [4] = "insTSAL", [6] = "dinsuTSEQ", [7] = "dinsTSAL", |
67 | [59] = "rdhwrTD", | 75 | [32] = map_bshfl, [36] = map_dbshfl, [59] = "rdhwrTD", |
68 | } | 76 | } |
69 | 77 | ||
70 | local map_regimm = { | 78 | local map_regimm = { |
@@ -178,8 +186,8 @@ local map_cop1bc = { | |||
178 | 186 | ||
179 | local map_cop1 = { | 187 | local map_cop1 = { |
180 | shift = 21, mask = 31, | 188 | shift = 21, mask = 31, |
181 | [0] = "mfc1TG", false, "cfc1TG", "mfhc1TG", | 189 | [0] = "mfc1TG", "dmfc1TG", "cfc1TG", "mfhc1TG", |
182 | "mtc1TG", false, "ctc1TG", "mthc1TG", | 190 | "mtc1TG", "dmtc1TG", "ctc1TG", "mthc1TG", |
183 | map_cop1bc, false, false, false, | 191 | map_cop1bc, false, false, false, |
184 | false, false, false, false, | 192 | false, false, false, false, |
185 | map_cop1s, map_cop1d, false, false, | 193 | map_cop1s, map_cop1d, false, false, |
@@ -213,16 +221,16 @@ local map_pri = { | |||
213 | "andiTSU", "ori|liTS0U", "xoriTSU", "luiTU", | 221 | "andiTSU", "ori|liTS0U", "xoriTSU", "luiTU", |
214 | map_cop0, map_cop1, false, map_cop1x, | 222 | map_cop0, map_cop1, false, map_cop1x, |
215 | "beql|beqzlST0B", "bnel|bnezlST0B", "blezlSB", "bgtzlSB", | 223 | "beql|beqzlST0B", "bnel|bnezlST0B", "blezlSB", "bgtzlSB", |
216 | false, false, false, false, | 224 | "daddiTSI", "daddiuTSI", false, false, |
217 | map_special2, false, false, map_special3, | 225 | map_special2, "jalxJ", false, map_special3, |
218 | "lbTSO", "lhTSO", "lwlTSO", "lwTSO", | 226 | "lbTSO", "lhTSO", "lwlTSO", "lwTSO", |
219 | "lbuTSO", "lhuTSO", "lwrTSO", false, | 227 | "lbuTSO", "lhuTSO", "lwrTSO", false, |
220 | "sbTSO", "shTSO", "swlTSO", "swTSO", | 228 | "sbTSO", "shTSO", "swlTSO", "swTSO", |
221 | false, false, "swrTSO", "cacheNSO", | 229 | false, false, "swrTSO", "cacheNSO", |
222 | "llTSO", "lwc1HSO", "lwc2TSO", "prefNSO", | 230 | "llTSO", "lwc1HSO", "lwc2TSO", "prefNSO", |
223 | false, "ldc1HSO", "ldc2TSO", false, | 231 | false, "ldc1HSO", "ldc2TSO", "ldTSO", |
224 | "scTSO", "swc1HSO", "swc2TSO", false, | 232 | "scTSO", "swc1HSO", "swc2TSO", false, |
225 | false, "sdc1HSO", "sdc2TSO", false, | 233 | false, "sdc1HSO", "sdc2TSO", "sdTSO", |
226 | } | 234 | } |
227 | 235 | ||
228 | ------------------------------------------------------------------------------ | 236 | ------------------------------------------------------------------------------ |
@@ -306,6 +314,8 @@ local function disass_ins(ctx) | |||
306 | x = "f"..band(rshift(op, 21), 31) | 314 | x = "f"..band(rshift(op, 21), 31) |
307 | elseif p == "A" then | 315 | elseif p == "A" then |
308 | x = band(rshift(op, 6), 31) | 316 | x = band(rshift(op, 6), 31) |
317 | elseif p == "E" then | ||
318 | x = band(rshift(op, 6), 31) + 32 | ||
309 | elseif p == "M" then | 319 | elseif p == "M" then |
310 | x = band(rshift(op, 11), 31) | 320 | x = band(rshift(op, 11), 31) |
311 | elseif p == "N" then | 321 | elseif p == "N" then |
@@ -315,8 +325,12 @@ local function disass_ins(ctx) | |||
315 | if x == 0 then x = nil end | 325 | if x == 0 then x = nil end |
316 | elseif p == "K" then | 326 | elseif p == "K" then |
317 | x = band(rshift(op, 11), 31) + 1 | 327 | x = band(rshift(op, 11), 31) + 1 |
328 | elseif p == "P" then | ||
329 | x = band(rshift(op, 11), 31) + 33 | ||
318 | elseif p == "L" then | 330 | elseif p == "L" then |
319 | x = band(rshift(op, 11), 31) - last + 1 | 331 | x = band(rshift(op, 11), 31) - last + 1 |
332 | elseif p == "Q" then | ||
333 | x = band(rshift(op, 11), 31) - last + 33 | ||
320 | elseif p == "I" then | 334 | elseif p == "I" then |
321 | x = arshift(lshift(op, 16), 16) | 335 | x = arshift(lshift(op, 16), 16) |
322 | elseif p == "U" then | 336 | elseif p == "U" then |
@@ -330,11 +344,12 @@ local function disass_ins(ctx) | |||
330 | elseif p == "B" then | 344 | elseif p == "B" then |
331 | x = ctx.addr + ctx.pos + arshift(lshift(op, 16), 16)*4 + 4 | 345 | x = ctx.addr + ctx.pos + arshift(lshift(op, 16), 16)*4 + 4 |
332 | ctx.rel = x | 346 | ctx.rel = x |
333 | x = "0x"..tohex(x) | 347 | x = format("0x%08x", x) |
334 | elseif p == "J" then | 348 | elseif p == "J" then |
335 | x = band(ctx.addr + ctx.pos, 0xf0000000) + band(op, 0x03ffffff)*4 | 349 | local a = ctx.addr + ctx.pos |
350 | x = a - band(a, 0x0fffffff) + band(op, 0x03ffffff)*4 | ||
336 | ctx.rel = x | 351 | ctx.rel = x |
337 | x = "0x"..tohex(x) | 352 | x = format("0x%08x", x) |
338 | elseif p == "V" then | 353 | elseif p == "V" then |
339 | x = band(rshift(op, 8), 7) | 354 | x = band(rshift(op, 8), 7) |
340 | if x == 0 then x = nil end | 355 | if x == 0 then x = nil end |
@@ -384,7 +399,7 @@ local function disass_block(ctx, ofs, len) | |||
384 | end | 399 | end |
385 | 400 | ||
386 | -- Extended API: create a disassembler context. Then call ctx:disass(ofs, len). | 401 | -- Extended API: create a disassembler context. Then call ctx:disass(ofs, len). |
387 | local function create_(code, addr, out) | 402 | local function create(code, addr, out) |
388 | local ctx = {} | 403 | local ctx = {} |
389 | ctx.code = code | 404 | ctx.code = code |
390 | ctx.addr = addr or 0 | 405 | ctx.addr = addr or 0 |
@@ -396,33 +411,33 @@ local function create_(code, addr, out) | |||
396 | return ctx | 411 | return ctx |
397 | end | 412 | end |
398 | 413 | ||
399 | local function create_el_(code, addr, out) | 414 | local function create_el(code, addr, out) |
400 | local ctx = create_(code, addr, out) | 415 | local ctx = create(code, addr, out) |
401 | ctx.get = get_le | 416 | ctx.get = get_le |
402 | return ctx | 417 | return ctx |
403 | end | 418 | end |
404 | 419 | ||
405 | -- Simple API: disassemble code (a string) at address and output via out. | 420 | -- Simple API: disassemble code (a string) at address and output via out. |
406 | local function disass_(code, addr, out) | 421 | local function disass(code, addr, out) |
407 | create_(code, addr, out):disass() | 422 | create(code, addr, out):disass() |
408 | end | 423 | end |
409 | 424 | ||
410 | local function disass_el_(code, addr, out) | 425 | local function disass_el(code, addr, out) |
411 | create_el_(code, addr, out):disass() | 426 | create_el(code, addr, out):disass() |
412 | end | 427 | end |
413 | 428 | ||
414 | -- Return register name for RID. | 429 | -- Return register name for RID. |
415 | local function regname_(r) | 430 | local function regname(r) |
416 | if r < 32 then return map_gpr[r] end | 431 | if r < 32 then return map_gpr[r] end |
417 | return "f"..(r-32) | 432 | return "f"..(r-32) |
418 | end | 433 | end |
419 | 434 | ||
420 | -- Public module functions. | 435 | -- Public module functions. |
421 | module(...) | 436 | return { |
422 | 437 | create = create, | |
423 | create = create_ | 438 | create_el = create_el, |
424 | create_el = create_el_ | 439 | disass = disass, |
425 | disass = disass_ | 440 | disass_el = disass_el, |
426 | disass_el = disass_el_ | 441 | regname = regname |
427 | regname = regname_ | 442 | } |
428 | 443 | ||