From 6dfbddb6b071625066079fdf77fa7b8482aa6da3 Mon Sep 17 00:00:00 2001 From: Victor van den Elzen Date: Wed, 29 Dec 2010 17:13:38 +0000 Subject: [PATCH] Move implicit operand size override logic to calc_size It is more logical, it cleans up the code and it makes implicit operand size override prefixes come out in the same order as explicit ones instead of after all other prefixes. Suggested-by: H. Peter Anvin --- assemble.c | 44 ++++++++++++++++++-------------------------- test/br3058845.asm | 2 +- test/prefix66.asm | 28 ++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 27 deletions(-) create mode 100644 test/prefix66.asm diff --git a/assemble.c b/assemble.c index 1a7dc8e0..a9f6eb02 100644 --- a/assemble.c +++ b/assemble.c @@ -976,12 +976,28 @@ static int64_t calcsize(int32_t segment, int64_t offset, int bits, break; case 0320: - length += (bits != 16); + { + enum prefixes pfx = ins->prefixes[PPS_OSIZE]; + if (pfx == P_O16) + break; + if (pfx != P_none) + errfunc(ERR_WARNING | ERR_PASS2, "invalid operand size prefix"); + else + ins->prefixes[PPS_OSIZE] = P_O16; break; + } case 0321: - length += (bits == 16); + { + enum prefixes pfx = ins->prefixes[PPS_OSIZE]; + if (pfx == P_O32) + break; + if (pfx != P_none) + errfunc(ERR_WARNING | ERR_PASS2, "invalid operand size prefix"); + else + ins->prefixes[PPS_OSIZE] = P_O32; break; + } case 0322: break; @@ -1636,32 +1652,8 @@ static void gencode(int32_t segment, int64_t offset, int bits, break; case 0320: - { - enum prefixes pfx = ins->prefixes[PPS_OSIZE]; - if (pfx != P_O16 && pfx != P_none) - nasm_error(ERR_WARNING, "Invalid operand size prefix"); - if (pfx != P_O16 && bits != 16) { - ins->prefixes[PPS_OSIZE] = P_O16; - *bytes = 0x66; - out(offset, segment, bytes, OUT_RAWDATA, 1, NO_SEG, NO_SEG); - offset += 1; - } - break; - } - case 0321: - { - enum prefixes pfx = ins->prefixes[PPS_OSIZE]; - if (pfx != P_O32 && pfx != P_none) - nasm_error(ERR_WARNING, "Invalid operand size prefix"); - if (pfx != P_O32 && bits == 16) { - ins->prefixes[PPS_OSIZE] = P_O32; - *bytes = 0x66; - out(offset, segment, bytes, OUT_RAWDATA, 1, NO_SEG, NO_SEG); - offset += 1; - } break; - } case 0322: case 0323: diff --git a/test/br3058845.asm b/test/br3058845.asm index b0de5607..c42f5d50 100644 --- a/test/br3058845.asm +++ b/test/br3058845.asm @@ -11,4 +11,4 @@ cmp eax, 0xFFFF_FFFF BITS 64 cmp ax, 0xFFFF -cmp eax, 0xFFFF_FFFF ; shouldn't warn, but does currently +cmp eax, 0xFFFF_FFFF diff --git a/test/prefix66.asm b/test/prefix66.asm new file mode 100644 index 00000000..4d9eb00a --- /dev/null +++ b/test/prefix66.asm @@ -0,0 +1,28 @@ +;Testname=test; Arguments=-fbin -oprefix66.bin; Files=stdout stderr prefix66.bin + +BITS 16 +cmp ax, 1 +o16 cmp ax, 1 +o32 cmp ax, 1 + +cmp eax, 1 +o16 cmp eax, 1 +o32 cmp eax, 1 + +BITS 32 +cmp ax, 1 +o16 cmp ax, 1 +o32 cmp ax, 1 + +cmp eax, 1 +o16 cmp eax, 1 +o32 cmp eax, 1 + +BITS 64 +cmp ax, 1 +o16 cmp ax, 1 +o32 cmp ax, 1 + +cmp eax, 1 +o16 cmp eax, 1 +o32 cmp eax, 1 -- 2.11.4.GIT