diff options
author | Mike Pall <mike> | 2009-12-13 19:11:11 +0100 |
---|---|---|
committer | Mike Pall <mike> | 2009-12-13 19:11:11 +0100 |
commit | ef885f476e63d1ccb3ba33d175a9dc1e1822e803 (patch) | |
tree | 3b26a70668df0b9480f4f8a7f3a639d6f78dffab | |
parent | d12d036023bc7c50443bb6dbf4743c23a6783244 (diff) | |
download | luajit-ef885f476e63d1ccb3ba33d175a9dc1e1822e803.tar.gz luajit-ef885f476e63d1ccb3ba33d175a9dc1e1822e803.tar.bz2 luajit-ef885f476e63d1ccb3ba33d175a9dc1e1822e803.zip |
Add support for 64 bit immediates/displacements to DynASM x64.
-rw-r--r-- | dynasm/dasm_x86.lua | 54 |
1 files changed, 47 insertions, 7 deletions
diff --git a/dynasm/dasm_x86.lua b/dynasm/dasm_x86.lua index af5bd111..d7789ced 100644 --- a/dynasm/dasm_x86.lua +++ b/dynasm/dasm_x86.lua | |||
@@ -13,7 +13,7 @@ local _info = { | |||
13 | description = "DynASM x86/x64 module", | 13 | description = "DynASM x86/x64 module", |
14 | version = "1.2.1", | 14 | version = "1.2.1", |
15 | vernum = 10201, | 15 | vernum = 10201, |
16 | release = "2009-12-09", | 16 | release = "2009-12-13", |
17 | author = "Mike Pall", | 17 | author = "Mike Pall", |
18 | license = "MIT", | 18 | license = "MIT", |
19 | } | 19 | } |
@@ -40,7 +40,7 @@ local action_names = { | |||
40 | -- int arg, 1 buffer pos: | 40 | -- int arg, 1 buffer pos: |
41 | "DISP", "IMM_S", "IMM_B", "IMM_W", "IMM_D", "IMM_WB", "IMM_DB", | 41 | "DISP", "IMM_S", "IMM_B", "IMM_W", "IMM_D", "IMM_WB", "IMM_DB", |
42 | -- action arg (1 byte), int arg, 1 buffer pos (reg/num): | 42 | -- action arg (1 byte), int arg, 1 buffer pos (reg/num): |
43 | "VREG", "SPACE", | 43 | "VREG", "SPACE", -- !x64: VREG support NYI. |
44 | -- ptrdiff_t arg, 1 buffer pos (address): !x64 | 44 | -- ptrdiff_t arg, 1 buffer pos (address): !x64 |
45 | "SETLABEL", "REL_A", | 45 | "SETLABEL", "REL_A", |
46 | -- action arg (1 byte) or int arg, 2 buffer pos (link, offset): | 46 | -- action arg (1 byte) or int arg, 2 buffer pos (link, offset): |
@@ -518,8 +518,13 @@ local function wputmrmsib(t, imark, s, vsreg) | |||
518 | wputmodrm(t.xsc, xreg, 5) | 518 | wputmodrm(t.xsc, xreg, 5) |
519 | if vxreg then waction("VREG", vxreg); wputxb(3) end | 519 | if vxreg then waction("VREG", vxreg); wputxb(3) end |
520 | else | 520 | else |
521 | -- Pure displacement. | 521 | -- Pure 32 bit displacement. |
522 | wputmodrm(0, s, 5) -- [disp] -> (0, s, ebp) | 522 | if x64 then |
523 | wputmodrm(0, s, 4) -- [disp] -> (0, s, esp) (0, esp, ebp) | ||
524 | wputmodrm(0, 4, 5) | ||
525 | else | ||
526 | wputmodrm(0, s, 5) -- [disp] -> (0, s, ebp) | ||
527 | end | ||
523 | if imark then waction("MARK") end | 528 | if imark then waction("MARK") end |
524 | if vsreg then waction("VREG", vsreg); wputxb(2) end | 529 | if vsreg then waction("VREG", vsreg); wputxb(2) end |
525 | end | 530 | end |
@@ -676,7 +681,7 @@ local function parseoperand(param) | |||
676 | -- [disp] | 681 | -- [disp] |
677 | t.disp = toint(br) | 682 | t.disp = toint(br) |
678 | if t.disp then | 683 | if t.disp then |
679 | t.mode = "xmO" | 684 | t.mode = x64 and "xm" or "xmO" |
680 | break | 685 | break |
681 | end | 686 | end |
682 | 687 | ||
@@ -686,7 +691,7 @@ local function parseoperand(param) | |||
686 | reg, t.reg, tp = rtexpr(reg) | 691 | reg, t.reg, tp = rtexpr(reg) |
687 | if not t.reg then | 692 | if not t.reg then |
688 | -- [expr] | 693 | -- [expr] |
689 | t.mode = "xmO" | 694 | t.mode = x64 and "xm" or "xmO" |
690 | t.disp = dispexpr("+"..br) | 695 | t.disp = dispexpr("+"..br) |
691 | break | 696 | break |
692 | end | 697 | end |
@@ -955,7 +960,6 @@ local map_op = { | |||
955 | popfd_0 = "9D", | 960 | popfd_0 = "9D", |
956 | sahf_0 = "9E", | 961 | sahf_0 = "9E", |
957 | lahf_0 = "9F", | 962 | lahf_0 = "9F", |
958 | -- !x64: mov with 64 bit immediate | ||
959 | mov_2 = "OR:A3o|RO:A1O|mr:89Rm|rm:8BrM|rib:nB0ri|ridw:B8ri|mi:C70mi", | 963 | mov_2 = "OR:A3o|RO:A1O|mr:89Rm|rm:8BrM|rib:nB0ri|ridw:B8ri|mi:C70mi", |
960 | movsb_0 = "A4", | 964 | movsb_0 = "A4", |
961 | movsw_0 = "66A5", | 965 | movsw_0 = "66A5", |
@@ -1641,6 +1645,42 @@ end | |||
1641 | 1645 | ||
1642 | ------------------------------------------------------------------------------ | 1646 | ------------------------------------------------------------------------------ |
1643 | 1647 | ||
1648 | -- x64-specific opcode for 64 bit immediates and displacements. | ||
1649 | if x64 then | ||
1650 | function map_op.mov64_2(params) | ||
1651 | local opcode, op64, sz, rex | ||
1652 | local op64 = match(params[1], "^%[%s*(.-)%s*%]$") | ||
1653 | if op64 then | ||
1654 | local a = parseoperand(params[2]) | ||
1655 | if a.mode ~= "rmR" then werror("bad operand mode") end | ||
1656 | sz = a.opsize | ||
1657 | rex = sz == "q" and 8 or 0 | ||
1658 | opcode = 0xa3 | ||
1659 | else | ||
1660 | op64 = match(params[2], "^%[%s*(.-)%s*%]$") | ||
1661 | local a = parseoperand(params[1]) | ||
1662 | if op64 then | ||
1663 | if a.mode ~= "rmR" then werror("bad operand mode") end | ||
1664 | sz = a.opsize | ||
1665 | rex = sz == "q" and 8 or 0 | ||
1666 | opcode = 0xa1 | ||
1667 | else | ||
1668 | if sub(a.mode, 1, 1) ~= "r" or a.opsize ~= "q" then | ||
1669 | werror("bad operand mode") | ||
1670 | end | ||
1671 | op64 = params[2] | ||
1672 | opcode = 0xb8 + (a.reg%8) -- !x64: no VREG support. | ||
1673 | rex = a.reg > 7 and 9 or 8 | ||
1674 | end | ||
1675 | end | ||
1676 | wputop(sz, opcode, rex) | ||
1677 | waction("IMM_D", format("(unsigned int)(%s)", op64)) | ||
1678 | waction("IMM_D", format("(unsigned int)((%s)>>32)", op64)) | ||
1679 | end | ||
1680 | end | ||
1681 | |||
1682 | ------------------------------------------------------------------------------ | ||
1683 | |||
1644 | -- Pseudo-opcodes for data storage. | 1684 | -- Pseudo-opcodes for data storage. |
1645 | local function op_data(params) | 1685 | local function op_data(params) |
1646 | if not params then return "imm..." end | 1686 | if not params then return "imm..." end |