diff options
Diffstat (limited to 'src/jit/dis_x86.lua')
-rw-r--r-- | src/jit/dis_x86.lua | 38 |
1 files changed, 20 insertions, 18 deletions
diff --git a/src/jit/dis_x86.lua b/src/jit/dis_x86.lua index c442a176..14b0fd61 100644 --- a/src/jit/dis_x86.lua +++ b/src/jit/dis_x86.lua | |||
@@ -28,6 +28,8 @@ local type = type | |||
28 | local sub, byte, format = string.sub, string.byte, string.format | 28 | local sub, byte, format = string.sub, string.byte, string.format |
29 | local match, gmatch, gsub = string.match, string.gmatch, string.gsub | 29 | local match, gmatch, gsub = string.match, string.gmatch, string.gsub |
30 | local lower, rep = string.lower, string.rep | 30 | local lower, rep = string.lower, string.rep |
31 | local bit = require("bit") | ||
32 | local tohex = bit.tohex | ||
31 | 33 | ||
32 | -- Map for 1st opcode byte in 32 bit mode. Ugly? Well ... read on. | 34 | -- Map for 1st opcode byte in 32 bit mode. Ugly? Well ... read on. |
33 | local map_opc1_32 = { | 35 | local map_opc1_32 = { |
@@ -532,7 +534,7 @@ local function putpat(ctx, name, pat) | |||
532 | local lo = imm % 0x1000000 | 534 | local lo = imm % 0x1000000 |
533 | x = format("0x%02x%06x", (imm-lo) / 0x1000000, lo) | 535 | x = format("0x%02x%06x", (imm-lo) / 0x1000000, lo) |
534 | else | 536 | else |
535 | x = format("0x%08x", imm) | 537 | x = "0x"..tohex(imm) |
536 | end | 538 | end |
537 | elseif p == "R" then | 539 | elseif p == "R" then |
538 | local r = byte(code, pos-1, pos-1)%8 | 540 | local r = byte(code, pos-1, pos-1)%8 |
@@ -782,7 +784,7 @@ local function disass_block(ctx, ofs, len) | |||
782 | end | 784 | end |
783 | 785 | ||
784 | -- Extended API: create a disassembler context. Then call ctx:disass(ofs, len). | 786 | -- Extended API: create a disassembler context. Then call ctx:disass(ofs, len). |
785 | local function create_(code, addr, out) | 787 | local function create(code, addr, out) |
786 | local ctx = {} | 788 | local ctx = {} |
787 | ctx.code = code | 789 | ctx.code = code |
788 | ctx.addr = (addr or 0) - 1 | 790 | ctx.addr = (addr or 0) - 1 |
@@ -796,8 +798,8 @@ local function create_(code, addr, out) | |||
796 | return ctx | 798 | return ctx |
797 | end | 799 | end |
798 | 800 | ||
799 | local function create64_(code, addr, out) | 801 | local function create64(code, addr, out) |
800 | local ctx = create_(code, addr, out) | 802 | local ctx = create(code, addr, out) |
801 | ctx.x64 = true | 803 | ctx.x64 = true |
802 | ctx.map1 = map_opc1_64 | 804 | ctx.map1 = map_opc1_64 |
803 | ctx.aregs = map_regs.Q | 805 | ctx.aregs = map_regs.Q |
@@ -805,32 +807,32 @@ local function create64_(code, addr, out) | |||
805 | end | 807 | end |
806 | 808 | ||
807 | -- Simple API: disassemble code (a string) at address and output via out. | 809 | -- Simple API: disassemble code (a string) at address and output via out. |
808 | local function disass_(code, addr, out) | 810 | local function disass(code, addr, out) |
809 | create_(code, addr, out):disass() | 811 | create(code, addr, out):disass() |
810 | end | 812 | end |
811 | 813 | ||
812 | local function disass64_(code, addr, out) | 814 | local function disass64(code, addr, out) |
813 | create64_(code, addr, out):disass() | 815 | create64(code, addr, out):disass() |
814 | end | 816 | end |
815 | 817 | ||
816 | -- Return register name for RID. | 818 | -- Return register name for RID. |
817 | local function regname_(r) | 819 | local function regname(r) |
818 | if r < 8 then return map_regs.D[r+1] end | 820 | if r < 8 then return map_regs.D[r+1] end |
819 | return map_regs.X[r-7] | 821 | return map_regs.X[r-7] |
820 | end | 822 | end |
821 | 823 | ||
822 | local function regname64_(r) | 824 | local function regname64(r) |
823 | if r < 16 then return map_regs.Q[r+1] end | 825 | if r < 16 then return map_regs.Q[r+1] end |
824 | return map_regs.X[r-15] | 826 | return map_regs.X[r-15] |
825 | end | 827 | end |
826 | 828 | ||
827 | -- Public module functions. | 829 | -- Public module functions. |
828 | module(...) | 830 | return { |
829 | 831 | create = create, | |
830 | create = create_ | 832 | create64 = create64, |
831 | create64 = create64_ | 833 | disass = disass, |
832 | disass = disass_ | 834 | disass64 = disass64, |
833 | disass64 = disass64_ | 835 | regname = regname, |
834 | regname = regname_ | 836 | regname64 = regname64 |
835 | regname64 = regname64_ | 837 | } |
836 | 838 | ||