History

segment override prefix support (Filip Navara)

bellard committed 21 years ago

Commit 3ba11901 parent 6f8b8881 file · +26 −2Browse files

Unified · Split

i386-asm.c+26−2
@@ -151,6 +151,15 @@ static const uint8_t test_bits[NB_TEST_OPCODES] = { · 150 unmodified lines
151151 0x0f, /* g */
152152 };
153153
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+
154163 static const ASMInstr asm_instrs[] = {
155164 #define ALT(x) x
156165 #define DEF_ASM_OP0(name, opcode)
@@ -410,14 +419,15 @@ static inline void asm_modrm(int reg, Operand *op) · 253 unmodified lines
410419 static void asm_opcode(TCCState *s1, int opcode)
411420 {
412421 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;
414423 int nb_ops, s, ss;
415− Operand ops[MAX_OPERANDS], *pop;
424+ Operand ops[MAX_OPERANDS], *pop, seg_prefix;
416425 int op_type[3]; /* decoded op type */
417426
418427 /* get operands */
419428 pop = ops;
420429 nb_ops = 0;
430+ has_seg_prefix = 0;
421431 for(;;) {
422432 if (tok == ';' || tok == TOK_LINEFEED)
423433 break;
@@ -425,6 +435,18 @@ static void asm_opcode(TCCState *s1, int opcode) · 1 unmodified line
425435 error("incorrect number of operands");
426436 }
427437 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+ }
428450 pop++;
429451 nb_ops++;
430452 if (tok != ',')
@@ -538,6 +560,8 @@ static void asm_opcode(TCCState *s1, int opcode) · 107 unmodified lines
538560 /* now generates the operation */
539561 if (pa->instr_type & OPC_FWAIT)
540562 g(0x9b);
563+ if (has_seg_prefix)
564+ g(segment_prefixes[seg_prefix.reg]);
541565
542566 v = pa->opcode;
543567 if (v == 0x69 || v == 0x69) {

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