diff options
| author | Mike Pall <mike> | 2026-08-03 10:44:17 +0200 |
|---|---|---|
| committer | Mike Pall <mike> | 2026-08-03 10:44:17 +0200 |
| commit | f30aabe82f61dbd6901f6a75dadde0a64dc626d2 (patch) | |
| tree | 80eda65bf087e10b2a78d9b94bcec3a04ed4d2de /src/jit/dis_mips.lua | |
| parent | 28084004ee68d576f3f0c9ea61ea448fe3e10f07 (diff) | |
| download | luajit-f30aabe82f61dbd6901f6a75dadde0a64dc626d2.tar.gz luajit-f30aabe82f61dbd6901f6a75dadde0a64dc626d2.tar.bz2 luajit-f30aabe82f61dbd6901f6a75dadde0a64dc626d2.zip | |
Modernize jit.* Lua modules.
Diffstat (limited to 'src/jit/dis_mips.lua')
| -rw-r--r-- | src/jit/dis_mips.lua | 83 |
1 files changed, 41 insertions, 42 deletions
diff --git a/src/jit/dis_mips.lua b/src/jit/dis_mips.lua index fece89370..2ff68f6be 100644 --- a/src/jit/dis_mips.lua +++ b/src/jit/dis_mips.lua | |||
| @@ -15,8 +15,7 @@ local byte, format = string.byte, string.format | |||
| 15 | local match, gmatch = string.match, string.gmatch | 15 | local match, gmatch = string.match, string.gmatch |
| 16 | local concat = table.concat | 16 | local concat = table.concat |
| 17 | local bit = require("bit") | 17 | local bit = require("bit") |
| 18 | local band, bor, tohex = bit.band, bit.bor, bit.tohex | 18 | local tohex = bit.tohex |
| 19 | local lshift, rshift, arshift = bit.lshift, bit.rshift, bit.arshift | ||
| 20 | 19 | ||
| 21 | ------------------------------------------------------------------------------ | 20 | ------------------------------------------------------------------------------ |
| 22 | -- Extended opcode maps common to all MIPS releases | 21 | -- Extended opcode maps common to all MIPS releases |
| @@ -477,13 +476,13 @@ end | |||
| 477 | local function get_be(ctx) | 476 | local function get_be(ctx) |
| 478 | local pos = ctx.pos | 477 | local pos = ctx.pos |
| 479 | local b0, b1, b2, b3 = byte(ctx.code, pos+1, pos+4) | 478 | local b0, b1, b2, b3 = byte(ctx.code, pos+1, pos+4) |
| 480 | return bor(lshift(b0, 24), lshift(b1, 16), lshift(b2, 8), b3) | 479 | return (b0 << 24) | (b1 << 16) | (b2 << 8) | b3 |
| 481 | end | 480 | end |
| 482 | 481 | ||
| 483 | local function get_le(ctx) | 482 | local function get_le(ctx) |
| 484 | local pos = ctx.pos | 483 | local pos = ctx.pos |
| 485 | local b0, b1, b2, b3 = byte(ctx.code, pos+1, pos+4) | 484 | local b0, b1, b2, b3 = byte(ctx.code, pos+1, pos+4) |
| 486 | return bor(lshift(b3, 24), lshift(b2, 16), lshift(b1, 8), b0) | 485 | return (b3 << 24) | (b2 << 16) | (b1 << 8) | b0 |
| 487 | end | 486 | end |
| 488 | 487 | ||
| 489 | -- Disassemble a single instruction. | 488 | -- Disassemble a single instruction. |
| @@ -494,13 +493,13 @@ local function disass_ins(ctx) | |||
| 494 | ctx.op = op | 493 | ctx.op = op |
| 495 | ctx.rel = nil | 494 | ctx.rel = nil |
| 496 | 495 | ||
| 497 | local opat = ctx.map_pri[rshift(op, 26)] | 496 | local opat = ctx.map_pri[op >> 26] |
| 498 | while type(opat) ~= "string" do | 497 | while type(opat) != "string" do |
| 499 | if not opat then return unknown(ctx) end | 498 | if not opat then return unknown(ctx) end |
| 500 | if opat.maprs then | 499 | if opat.maprs then |
| 501 | opat = opat[opat.maprs(band(rshift(op,21),31), band(rshift(op,16),31))] | 500 | opat = opat[opat.maprs((op >> 21) & 31, (op >> 16) & 31)] |
| 502 | else | 501 | else |
| 503 | opat = opat[band(rshift(op, opat.shift), opat.mask)] or opat._ | 502 | opat = opat[(op >> opat.shift) & opat.mask] or opat._ |
| 504 | end | 503 | end |
| 505 | end | 504 | end |
| 506 | local name, pat = match(opat, "^([a-z0-9_.]*)(.*)") | 505 | local name, pat = match(opat, "^([a-z0-9_.]*)(.*)") |
| @@ -510,82 +509,82 @@ local function disass_ins(ctx) | |||
| 510 | for p in gmatch(pat, ".") do | 509 | for p in gmatch(pat, ".") do |
| 511 | local x = nil | 510 | local x = nil |
| 512 | if p == "S" then | 511 | if p == "S" then |
| 513 | x = map_gpr[band(rshift(op, 21), 31)] | 512 | x = map_gpr[(op >> 21) & 31] |
| 514 | elseif p == "T" then | 513 | elseif p == "T" then |
| 515 | x = map_gpr[band(rshift(op, 16), 31)] | 514 | x = map_gpr[(op >> 16) & 31] |
| 516 | elseif p == "D" then | 515 | elseif p == "D" then |
| 517 | x = map_gpr[band(rshift(op, 11), 31)] | 516 | x = map_gpr[(op >> 11) & 31] |
| 518 | elseif p == "F" then | 517 | elseif p == "F" then |
| 519 | x = "f"..band(rshift(op, 6), 31) | 518 | x = "f"..((op >> 6) & 31) |
| 520 | elseif p == "G" then | 519 | elseif p == "G" then |
| 521 | x = "f"..band(rshift(op, 11), 31) | 520 | x = "f"..((op >> 11) & 31) |
| 522 | elseif p == "H" then | 521 | elseif p == "H" then |
| 523 | x = "f"..band(rshift(op, 16), 31) | 522 | x = "f"..((op >> 16) & 31) |
| 524 | elseif p == "R" then | 523 | elseif p == "R" then |
| 525 | x = "f"..band(rshift(op, 21), 31) | 524 | x = "f"..((op >> 21) & 31) |
| 526 | elseif p == "A" then | 525 | elseif p == "A" then |
| 527 | x = band(rshift(op, 6), 31) | 526 | x = (op >> 6) & 31 |
| 528 | elseif p == "a" then | 527 | elseif p == "a" then |
| 529 | x = band(rshift(op, 6), 7) | 528 | x = (op >> 6) & 7 |
| 530 | elseif p == "E" then | 529 | elseif p == "E" then |
| 531 | x = band(rshift(op, 6), 31) + 32 | 530 | x = ((op >> 6) & 31) + 32 |
| 532 | elseif p == "M" then | 531 | elseif p == "M" then |
| 533 | x = band(rshift(op, 11), 31) | 532 | x = (op >> 11) & 31 |
| 534 | elseif p == "N" then | 533 | elseif p == "N" then |
| 535 | x = band(rshift(op, 16), 31) | 534 | x = (op >> 16) & 31 |
| 536 | elseif p == "C" then | 535 | elseif p == "C" then |
| 537 | x = band(rshift(op, 18), 7) | 536 | x = (op >> 18) & 7 |
| 538 | if x == 0 then x = nil end | 537 | if x == 0 then x = nil end |
| 539 | elseif p == "K" then | 538 | elseif p == "K" then |
| 540 | x = band(rshift(op, 11), 31) + 1 | 539 | x = ((op >> 11) & 31) + 1 |
| 541 | elseif p == "P" then | 540 | elseif p == "P" then |
| 542 | x = band(rshift(op, 11), 31) + 33 | 541 | x = ((op >> 11) & 31) + 33 |
| 543 | elseif p == "L" then | 542 | elseif p == "L" then |
| 544 | x = band(rshift(op, 11), 31) - last + 1 | 543 | x = ((op >> 11) & 31) - last + 1 |
| 545 | elseif p == "Q" then | 544 | elseif p == "Q" then |
| 546 | x = band(rshift(op, 11), 31) - last + 33 | 545 | x = ((op >> 11) & 31) - last + 33 |
| 547 | elseif p == "I" then | 546 | elseif p == "I" then |
| 548 | x = arshift(lshift(op, 16), 16) | 547 | x = (op << 16) ~>> 16 |
| 549 | elseif p == "2" then | 548 | elseif p == "2" then |
| 550 | x = arshift(lshift(op, 13), 11) | 549 | x = (op << 13) ~>> 11 |
| 551 | elseif p == "3" then | 550 | elseif p == "3" then |
| 552 | x = arshift(lshift(op, 14), 11) | 551 | x = (op << 14) ~>> 11 |
| 553 | elseif p == "U" then | 552 | elseif p == "U" then |
| 554 | x = band(op, 0xffff) | 553 | x = op & 0xffff |
| 555 | elseif p == "O" then | 554 | elseif p == "O" then |
| 556 | local disp = arshift(lshift(op, 16), 16) | 555 | local disp = (op << 16) ~>> 16 |
| 557 | operands[#operands] = format("%d(%s)", disp, last) | 556 | operands[#operands] = format("%d(%s)", disp, last) |
| 558 | elseif p == "X" then | 557 | elseif p == "X" then |
| 559 | local index = map_gpr[band(rshift(op, 16), 31)] | 558 | local index = map_gpr[(op >> 16) & 31] |
| 560 | operands[#operands] = format("%s(%s)", index, last) | 559 | operands[#operands] = format("%s(%s)", index, last) |
| 561 | elseif p == "B" then | 560 | elseif p == "B" then |
| 562 | x = ctx.addr + ctx.pos + arshift(lshift(op, 16), 14) + 4 | 561 | x = ctx.addr + ctx.pos + ((op << 16) ~>> 14) + 4 |
| 563 | ctx.rel = x | 562 | ctx.rel = x |
| 564 | x = format("0x%08x", x) | 563 | x = format("0x%08x", x) |
| 565 | elseif p == "b" then | 564 | elseif p == "b" then |
| 566 | x = ctx.addr + ctx.pos + arshift(lshift(op, 11), 9) + 4 | 565 | x = ctx.addr + ctx.pos + ((op << 11) ~>> 9) + 4 |
| 567 | ctx.rel = x | 566 | ctx.rel = x |
| 568 | x = format("0x%08x", x) | 567 | x = format("0x%08x", x) |
| 569 | elseif p == "#" then | 568 | elseif p == "#" then |
| 570 | x = ctx.addr + ctx.pos + arshift(lshift(op, 6), 4) + 4 | 569 | x = ctx.addr + ctx.pos + ((op << 6) ~>> 4) + 4 |
| 571 | ctx.rel = x | 570 | ctx.rel = x |
| 572 | x = format("0x%08x", x) | 571 | x = format("0x%08x", x) |
| 573 | elseif p == "J" then | 572 | elseif p == "J" then |
| 574 | local a = ctx.addr + ctx.pos | 573 | local a = ctx.addr + ctx.pos |
| 575 | x = a - band(a, 0x0fffffff) + band(op, 0x03ffffff)*4 | 574 | x = a - (a & 0x0fffffff) + ((op & 0x03ffffff) << 2) |
| 576 | ctx.rel = x | 575 | ctx.rel = x |
| 577 | x = format("0x%08x", x) | 576 | x = format("0x%08x", x) |
| 578 | elseif p == "V" then | 577 | elseif p == "V" then |
| 579 | x = band(rshift(op, 8), 7) | 578 | x = (op >> 8) & 7 |
| 580 | if x == 0 then x = nil end | 579 | if x == 0 then x = nil end |
| 581 | elseif p == "W" then | 580 | elseif p == "W" then |
| 582 | x = band(op, 7) | 581 | x = op & 7 |
| 583 | if x == 0 then x = nil end | 582 | if x == 0 then x = nil end |
| 584 | elseif p == "Y" then | 583 | elseif p == "Y" then |
| 585 | x = band(rshift(op, 6), 0x000fffff) | 584 | x = (op >> 6) & 0x000fffff |
| 586 | if x == 0 then x = nil end | 585 | if x == 0 then x = nil end |
| 587 | elseif p == "Z" then | 586 | elseif p == "Z" then |
| 588 | x = band(rshift(op, 6), 1023) | 587 | x = (op >> 6) & 1023 |
| 589 | if x == 0 then x = nil end | 588 | if x == 0 then x = nil end |
| 590 | elseif p == "0" then | 589 | elseif p == "0" then |
| 591 | if last == "r0" or last == 0 then | 590 | if last == "r0" or last == 0 then |
| @@ -616,9 +615,9 @@ end | |||
| 616 | -- Disassemble a block of code. | 615 | -- Disassemble a block of code. |
| 617 | local function disass_block(ctx, ofs, len) | 616 | local function disass_block(ctx, ofs, len) |
| 618 | if not ofs then ofs = 0 end | 617 | if not ofs then ofs = 0 end |
| 619 | local stop = len and ofs+len or #ctx.code | 618 | local stop = len ? ofs+len : #ctx.code |
| 620 | stop = stop - stop % 4 | 619 | stop &= -4 |
| 621 | ctx.pos = ofs - ofs % 4 | 620 | ctx.pos = ofs & -4 |
| 622 | ctx.rel = nil | 621 | ctx.rel = nil |
| 623 | while ctx.pos < stop do disass_ins(ctx) end | 622 | while ctx.pos < stop do disass_ins(ctx) end |
| 624 | end | 623 | end |
