Unified · Split
| @@ -151,6 +151,15 @@ static const uint8_t test_bits[NB_TEST_OPCODES] = { · 150 unmodified lines | |||
| 151 | 0x0f, /* g */ | 151 | 0x0f, /* g */ |
| 152 | }; | 152 | }; |
| 153 | 153 | ||
| 154 | static const uint8_t segment_prefixes[] = { | ||
| 155 | 0x26, /* es */ | ||
| 156 | 0x2e, /* cs */ | ||
| 157 | 0x36, /* ss */ | ||
| 158 | 0x3e, /* ds */ | ||
| 159 | 0x64, /* fs */ | ||
| 160 | 0x65 /* gs */ | ||
| 161 | }; | ||
| 162 | |||
| 154 | static const ASMInstr asm_instrs[] = { | 163 | static const ASMInstr asm_instrs[] = { |
| 155 | #define ALT(x) x | 164 | #define ALT(x) x |
| 156 | #define DEF_ASM_OP0(name, opcode) | 165 | #define DEF_ASM_OP0(name, opcode) |
| @@ -410,14 +419,15 @@ static inline void asm_modrm(int reg, Operand *op) · 253 unmodified lines | |||
| 410 | static void asm_opcode(TCCState *s1, int opcode) | 419 | static void asm_opcode(TCCState *s1, int opcode) |
| 411 | { | 420 | { |
| 412 | const ASMInstr *pa; | 421 | const ASMInstr *pa; |
| 413 | int i, modrm_index, reg, v, op1, is_short_jmp; | 422 | int i, modrm_index, reg, v, op1, is_short_jmp, has_seg_prefix; |
| 414 | int nb_ops, s, ss; | 423 | int nb_ops, s, ss; |
| 415 | Operand ops[MAX_OPERANDS], *pop; | 424 | Operand ops[MAX_OPERANDS], *pop, seg_prefix; |
| 416 | int op_type[3]; /* decoded op type */ | 425 | int op_type[3]; /* decoded op type */ |
| 417 | 426 | ||
| 418 | /* get operands */ | 427 | /* get operands */ |
| 419 | pop = ops; | 428 | pop = ops; |
| 420 | nb_ops = 0; | 429 | nb_ops = 0; |
| 430 | has_seg_prefix = 0; | ||
| 421 | for(;;) { | 431 | for(;;) { |
| 422 | if (tok == ';' || tok == TOK_LINEFEED) | 432 | if (tok == ';' || tok == TOK_LINEFEED) |
| 423 | break; | 433 | break; |
| @@ -425,6 +435,18 @@ static void asm_opcode(TCCState *s1, int opcode) · 1 unmodified line | |||
| 425 | error("incorrect number of operands"); | 435 | error("incorrect number of operands"); |
| 426 | } | 436 | } |
| 427 | parse_operand(s1, pop); | 437 | parse_operand(s1, pop); |
| 438 | if (tok == ':') { | ||
| 439 | if (pop->type != OP_SEG || has_seg_prefix) { | ||
| 440 | error("incorrect prefix"); | ||
| 441 | } | ||
| 442 | seg_prefix = *pop; | ||
| 443 | has_seg_prefix = 1; | ||
| 444 | next(); | ||
| 445 | parse_operand(s1, pop); | ||
| 446 | if (!(pop->type & OP_EA)) { | ||
| 447 | error("segment prefix must be followed by memory reference"); | ||
| 448 | } | ||
| 449 | } | ||
| 428 | pop++; | 450 | pop++; |
| 429 | nb_ops++; | 451 | nb_ops++; |
| 430 | if (tok != ',') | 452 | if (tok != ',') |
| @@ -538,6 +560,8 @@ static void asm_opcode(TCCState *s1, int opcode) · 107 unmodified lines | |||
| 538 | /* now generates the operation */ | 560 | /* now generates the operation */ |
| 539 | if (pa->instr_type & OPC_FWAIT) | 561 | if (pa->instr_type & OPC_FWAIT) |
| 540 | g(0x9b); | 562 | g(0x9b); |
| 563 | if (has_seg_prefix) | ||
| 564 | g(segment_prefixes[seg_prefix.reg]); | ||
| 541 | 565 | ||
| 542 | v = pa->opcode; | 566 | v = pa->opcode; |
| 543 | if (v == 0x69 || v == 0x69) { | 567 | if (v == 0x69 || v == 0x69) { |