Unified · Split
| @@ -151,6 +151,15 @@ static const uint8_t test_bits[NB_TEST_OPCODES] = { · 150 unmodified lines | ||
| 151 | 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 | 163 | static const ASMInstr asm_instrs[] = { |
| 155 | 164 | #define ALT(x) x |
| 156 | 165 | #define DEF_ASM_OP0(name, opcode) |
| @@ -410,14 +419,15 @@ static inline void asm_modrm(int reg, Operand *op) · 253 unmodified lines | ||
| 410 | 419 | static void asm_opcode(TCCState *s1, int opcode) |
| 411 | 420 | { |
| 412 | 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 | 423 | int nb_ops, s, ss; |
| 415 | − Operand ops[MAX_OPERANDS], *pop; | |
| 424 | + Operand ops[MAX_OPERANDS], *pop, seg_prefix; | |
| 416 | 425 | int op_type[3]; /* decoded op type */ |
| 417 | 426 | |
| 418 | 427 | /* get operands */ |
| 419 | 428 | pop = ops; |
| 420 | 429 | nb_ops = 0; |
| 430 | + has_seg_prefix = 0; | |
| 421 | 431 | for(;;) { |
| 422 | 432 | if (tok == ';' || tok == TOK_LINEFEED) |
| 423 | 433 | break; |
| @@ -425,6 +435,18 @@ static void asm_opcode(TCCState *s1, int opcode) · 1 unmodified line | ||
| 425 | 435 | error("incorrect number of operands"); |
| 426 | 436 | } |
| 427 | 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 | 450 | pop++; |
| 429 | 451 | nb_ops++; |
| 430 | 452 | if (tok != ',') |
| @@ -538,6 +560,8 @@ static void asm_opcode(TCCState *s1, int opcode) · 107 unmodified lines | ||
| 538 | 560 | /* now generates the operation */ |
| 539 | 561 | if (pa->instr_type & OPC_FWAIT) |
| 540 | 562 | g(0x9b); |
| 563 | + if (has_seg_prefix) | |
| 564 | + g(segment_prefixes[seg_prefix.reg]); | |
| 541 | 565 | |
| 542 | 566 | v = pa->opcode; |
| 543 | 567 | if (v == 0x69 || v == 0x69) { |