aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Johnson <peter@tortall.net>2011-07-02 17:11:10 -0700
committerPeter Johnson <peter@tortall.net>2011-07-02 17:11:10 -0700
commit0614dede9bb5b285804882cf71479f4e9757ec2f (patch)
tree9cd21949e6821ed205887ac2aba3f3a5060f7b61
parentf12d030f908a41a70877ee84cf46da8655756f83 (diff)
downloadyasm-0614dede9bb5b285804882cf71479f4e9757ec2f.tar.gz
x86/gas: Fix no-suffix push and pop.
Previously plain "push" and "pop" would always generate a 16-bit pop (for effective address versions). Reported by: Alexei Svitkine [#212 state:resolved]
-rwxr-xr-xmodules/arch/x86/gen_x86_insn.py25
-rw-r--r--modules/arch/x86/tests/gas32/Makefile.inc2
-rw-r--r--modules/arch/x86/tests/gas32/gas-pop.asm50
-rw-r--r--modules/arch/x86/tests/gas32/gas-pop.hex456
4 files changed, 533 insertions, 0 deletions
diff --git a/modules/arch/x86/gen_x86_insn.py b/modules/arch/x86/gen_x86_insn.py
index b0c26465..b48f806e 100755
--- a/modules/arch/x86/gen_x86_insn.py
+++ b/modules/arch/x86/gen_x86_insn.py
@@ -1133,6 +1133,10 @@ add_insn("movsxd", "movsxd", parser="nasm")
# Push instructions
#
add_group("push",
+ def_opersize_64=64,
+ opcode=[0x50],
+ operands=[Operand(type="Reg", size="BITS", dest="Op0Add")])
+add_group("push",
suffix="w",
opersize=16,
def_opersize_64=64,
@@ -1146,9 +1150,16 @@ add_group("push",
operands=[Operand(type="Reg", size=32, dest="Op0Add")])
add_group("push",
suffix="q",
+ only64=True,
def_opersize_64=64,
opcode=[0x50],
operands=[Operand(type="Reg", size=64, dest="Op0Add")])
+
+add_group("push",
+ def_opersize_64=64,
+ opcode=[0xFF],
+ spare=6,
+ operands=[Operand(type="RM", size="BITS", dest="EA")])
add_group("push",
suffix="w",
opersize=16,
@@ -1165,10 +1176,12 @@ add_group("push",
operands=[Operand(type="RM", size=32, dest="EA")])
add_group("push",
suffix="q",
+ only64=True,
def_opersize_64=64,
opcode=[0xFF],
spare=6,
operands=[Operand(type="RM", size=64, dest="EA")])
+
add_group("push",
cpu=["186"],
parsers=["nasm"],
@@ -1340,6 +1353,10 @@ add_insn("pushaw", "onebyte", modifiers=[0x60, 16], cpu=["186"], not64=True)
# Pop instructions
#
add_group("pop",
+ def_opersize_64=64,
+ opcode=[0x58],
+ operands=[Operand(type="Reg", size="BITS", dest="Op0Add")])
+add_group("pop",
suffix="w",
opersize=16,
def_opersize_64=64,
@@ -1353,9 +1370,15 @@ add_group("pop",
operands=[Operand(type="Reg", size=32, dest="Op0Add")])
add_group("pop",
suffix="q",
+ only64=True,
def_opersize_64=64,
opcode=[0x58],
operands=[Operand(type="Reg", size=64, dest="Op0Add")])
+
+add_group("pop",
+ def_opersize_64=64,
+ opcode=[0x8F],
+ operands=[Operand(type="RM", size="BITS", dest="EA")])
add_group("pop",
suffix="w",
opersize=16,
@@ -1370,9 +1393,11 @@ add_group("pop",
operands=[Operand(type="RM", size=32, dest="EA")])
add_group("pop",
suffix="q",
+ only64=True,
def_opersize_64=64,
opcode=[0x8F],
operands=[Operand(type="RM", size=64, dest="EA")])
+
# POP CS is debateably valid on the 8086, if obsolete and undocumented.
# We don't include it because it's VERY unlikely it will ever be used
# anywhere. If someone really wants it they can db 0x0F it.
diff --git a/modules/arch/x86/tests/gas32/Makefile.inc b/modules/arch/x86/tests/gas32/Makefile.inc
index 282cf75f..5fc0afbf 100644
--- a/modules/arch/x86/tests/gas32/Makefile.inc
+++ b/modules/arch/x86/tests/gas32/Makefile.inc
@@ -19,6 +19,8 @@ EXTRA_DIST += modules/arch/x86/tests/gas32/gas-movdq32.asm
EXTRA_DIST += modules/arch/x86/tests/gas32/gas-movdq32.hex
EXTRA_DIST += modules/arch/x86/tests/gas32/gas-movsd.asm
EXTRA_DIST += modules/arch/x86/tests/gas32/gas-movsd.hex
+EXTRA_DIST += modules/arch/x86/tests/gas32/gas-pop.asm
+EXTRA_DIST += modules/arch/x86/tests/gas32/gas-pop.hex
EXTRA_DIST += modules/arch/x86/tests/gas32/gas32-jmpcall.asm
EXTRA_DIST += modules/arch/x86/tests/gas32/gas32-jmpcall.hex
diff --git a/modules/arch/x86/tests/gas32/gas-pop.asm b/modules/arch/x86/tests/gas32/gas-pop.asm
new file mode 100644
index 00000000..7c47ebef
--- /dev/null
+++ b/modules/arch/x86/tests/gas32/gas-pop.asm
@@ -0,0 +1,50 @@
+.code64
+push %cx # out: 66 51
+pop %cx # out: 66 59
+push %rcx # out: 51
+pop %rcx # out: 59
+pushw %cx # out: 66 51
+popw %cx # out: 66 59
+pushq %rcx # out: 51
+popq %rcx # out: 59
+
+push -24(%rcx) # out: ff 71 e8
+pop -24(%rcx) # out: 8f 41 e8
+pushw -24(%rcx) # out: 66 ff 71 e8
+popw -24(%rcx) # out: 66 8f 41 e8
+pushq -24(%rcx) # out: ff 71 e8
+popq -24(%rcx) # out: 8f 41 e8
+
+.code32
+push %cx # out: 66 51
+pop %cx # out: 66 59
+push %ecx # out: 51
+pop %ecx # out: 59
+pushw %cx # out: 66 51
+popw %cx # out: 66 59
+pushl %ecx # out: 51
+popl %ecx # out: 59
+
+push -24(%ecx) # out: ff 71 e8
+pop -24(%ecx) # out: 8f 41 e8
+pushw -24(%ecx) # out: 66 ff 71 e8
+popw -24(%ecx) # out: 66 8f 41 e8
+pushl -24(%ecx) # out: ff 71 e8
+popl -24(%ecx) # out: 8f 41 e8
+
+.code16
+push %cx # out: 51
+pop %cx # out: 59
+push %ecx # out: 66 51
+pop %ecx # out: 66 59
+pushw %cx # out: 51
+popw %cx # out: 59
+pushl %ecx # out: 66 51
+popl %ecx # out: 66 59
+
+push -24(%bp) # out: ff 76 e8
+pop -24(%bp) # out: 8f 46 e8
+pushw -24(%bp) # out: ff 76 e8
+popw -24(%bp) # out: 8f 46 e8
+pushl -24(%bp) # out: 66 ff 76 e8
+popl -24(%bp) # out: 66 8f 46 e8
diff --git a/modules/arch/x86/tests/gas32/gas-pop.hex b/modules/arch/x86/tests/gas32/gas-pop.hex
new file mode 100644
index 00000000..30744378
--- /dev/null
+++ b/modules/arch/x86/tests/gas32/gas-pop.hex
@@ -0,0 +1,456 @@
+7f
+45
+4c
+46
+01
+01
+01
+00
+00
+00
+00
+00
+00
+00
+00
+00
+01
+00
+03
+00
+01
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+01
+00
+00
+00
+00
+00
+00
+34
+00
+00
+00
+00
+00
+28
+00
+05
+00
+01
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+66
+51
+66
+59
+51
+59
+66
+51
+66
+59
+51
+59
+ff
+71
+e8
+8f
+41
+e8
+66
+ff
+71
+e8
+66
+8f
+41
+e8
+ff
+71
+e8
+8f
+41
+e8
+66
+51
+66
+59
+51
+59
+66
+51
+66
+59
+51
+59
+ff
+71
+e8
+8f
+41
+e8
+66
+ff
+71
+e8
+66
+8f
+41
+e8
+ff
+71
+e8
+8f
+41
+e8
+51
+59
+66
+51
+66
+59
+51
+59
+66
+51
+66
+59
+ff
+76
+e8
+8f
+46
+e8
+ff
+76
+e8
+8f
+46
+e8
+66
+ff
+76
+e8
+66
+8f
+46
+e8
+00
+2e
+74
+65
+78
+74
+00
+2e
+73
+74
+72
+74
+61
+62
+00
+2e
+73
+79
+6d
+74
+61
+62
+00
+2e
+73
+68
+73
+74
+72
+74
+61
+62
+00
+00
+00
+00
+00
+2d
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+01
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+04
+00
+f1
+ff
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+03
+00
+04
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+17
+00
+00
+00
+03
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+a0
+00
+00
+00
+21
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+07
+00
+00
+00
+03
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+c4
+00
+00
+00
+03
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+0f
+00
+00
+00
+02
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+c8
+00
+00
+00
+30
+00
+00
+00
+02
+00
+00
+00
+03
+00
+00
+00
+04
+00
+00
+00
+10
+00
+00
+00
+01
+00
+00
+00
+01
+00
+00
+00
+06
+00
+00
+00
+00
+00
+00
+00
+40
+00
+00
+00
+60
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+10
+00
+00
+00
+00
+00
+00
+00