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 <hpa@zytor.com>
This commit is contained in:
Victor van den Elzen 2010-12-29 17:13:38 +00:00
parent 47c95ceed4
commit 6dfbddb6b0
3 changed files with 47 additions and 27 deletions

View File

@ -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:

View File

@ -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

28
test/prefix66.asm Normal file
View File

@ -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