History

fix 32bit asm

The new 16bit code was causing wrong 0x66 prefixes in 32bit code. The fix possibly breaks the feature on 16bit asm.

grischka committed 17 years ago

Commit 0a3bcb51 parent c15e37e2 files · +17 −25Browse files

Unified · Split

2 files
  1. i386-asm.c +13 −25
  2. i386-asm.h +4 −0
i386-asm.c+13−25
@@ -504,10 +504,12 @@ static void asm_opcode(TCCState *s1, int opcode) · 503 unmodified lines
504504 {
505505 const ASMInstr *pa;
506506 int i, modrm_index, reg, v, op1, is_short_jmp, seg_prefix;
507− int nb_ops, s, ss;
507+ int nb_ops, s;
508508 Operand ops[MAX_OPERANDS], *pop;
509509 int op_type[3]; /* decoded op type */
510− static int a32 = 0, o32 = 0, addr32 = 0, data32 = 0;
510+
511+ int a32, o32;
512+ static int addr32 = 0, data32 = 0;
511513
512514 /* get operands */
513515 pop = ops;
@@ -618,12 +620,12 @@ static void asm_opcode(TCCState *s1, int opcode) · 104 unmodified lines
618620 if (s1->seg_size == 32)
619621 goto bad_prefix;
620622 else
621− o32 = data32 = 1;
623+ data32 = 1;
622624 } else if (opcode == TOK_ASM_a32) {
623625 if (s1->seg_size == 32)
624626 goto bad_prefix;
625627 else
626− a32 = addr32 = 1;
628+ addr32 = 1;
627629 }
628630 if (b & 0xff00)
629631 g(b >> 8);
@@ -649,26 +651,13 @@ static void asm_opcode(TCCState *s1, int opcode) · 19 unmodified lines
649651 }
650652 }
651653
652− for(i = 0; i < nb_ops; i++) {
653− if (ops[i].type & OP_REG32) {
654− if (s1->seg_size == 16)
655− o32 = 1;
656− } else if (!(ops[i].type & OP_REG32)) {
657− if (s1->seg_size == 32)
658− o32 = 1;
659− }
660− }
661−
662− ss = s;
654+ a32 = o32 = 0;
663655 if (s == 1 || (pa->instr_type & OPC_D16)) {
664656 if (s1->seg_size == 32)
665657 o32 = 1;
666− } else if (s == 2) {
667− if (s1->seg_size == 16) {
668− if (!(pa->instr_type & OPC_D16))
669− o32 = 1;
670− }
671− s = 1;
658+ } else if (s == 2 && !(pa->instr_type & OPC_D16)) {
659+ if (s1->seg_size == 16)
660+ o32 = 1;
672661 }
673662
674663 /* generate a16/a32 prefix if needed */
@@ -721,7 +710,7 @@ static void asm_opcode(TCCState *s1, int opcode) · 46 unmodified lines
721710 v += 7;
722711 }
723712 if (pa->instr_type & OPC_B)
724− v += s;
713+ v += s >= 1;
725714 if (pa->instr_type & OPC_TEST)
726715 v += test_bits[opcode - pa->sym];
727716 if (pa->instr_type & OPC_SHORTJMP) {
@@ -824,9 +813,9 @@ static void asm_opcode(TCCState *s1, int opcode) · 96 unmodified lines
824813 at the op size */
825814 if (v == (OP_IM8 | OP_IM16 | OP_IM32) ||
826815 v == (OP_IM16 | OP_IM32)) {
827− if (ss == 0)
816+ if (s == 0)
828817 v = OP_IM8;
829− else if (ss == 1)
818+ else if (s == 1)
830819 v = OP_IM16;
831820 else
832821 v = OP_IM32;
@@ -875,7 +864,6 @@ static void asm_opcode(TCCState *s1, int opcode) · 42 unmodified lines
875864 }
876865 }
877866 }
878− a32 = o32 = 0;
879867 }
880868
881869 #define NB_SAVED_REGS 3
i386-asm.h+4−0
@@ -74,8 +74,12 @@ ALT(DEF_ASM_OP2(btcw, 0x0fbb, 0, OPC_MODRM | OPC_WL, OPT_REGW, OPT_REGW | OPT_EA · 73 unmodified lines
7474 ALT(DEF_ASM_OP2(btcw, 0x0fba, 7, OPC_MODRM | OPC_WL, OPT_IM8, OPT_REGW | OPT_EA))
7575
7676 /* prefixes */
77+ DEF_ASM_OP0(addr16, 0x67)
7778 DEF_ASM_OP0(a32, 0x67)
79+
80+ DEF_ASM_OP0(data16, 0x66)
7881 DEF_ASM_OP0(o32, 0x66)
82+
7983 DEF_ASM_OP0(lock, 0xf0)
8084 DEF_ASM_OP0(rep, 0xf3)
8185 DEF_ASM_OP0(repe, 0xf3)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t