tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Tinycc-devel] [patch] support segment prefixes


From: Filip Navara
Subject: [Tinycc-devel] [patch] support segment prefixes
Date: Tue, 05 Jul 2005 02:14:32 +0200
User-agent: Mozilla Thunderbird 0.9 (Windows/20041103)

Support the "movl %fs:0x18, %eax" assembler syntax...
--- i386-asm.c  Sat Jun 18 00:09:15 2005
+++ i386-asm.c  Sun Jul  3 17:01:28 2005
@@ -151,6 +151,15 @@
  0x0f, /* g */
 };
 
+static const uint8_t segment_prefixes[] = {
+ 0x26, /* es */
+ 0x2e, /* cs */
+ 0x36, /* ss */
+ 0x3e, /* ds */
+ 0x64, /* fs */
+ 0x65  /* gs */
+};
+
 static const ASMInstr asm_instrs[] = {
 #define ALT(x) x
 #define DEF_ASM_OP0(name, opcode)
@@ -410,14 +419,15 @@
 static void asm_opcode(TCCState *s1, int opcode)
 {
     const ASMInstr *pa;
-    int i, modrm_index, reg, v, op1, is_short_jmp;
+    int i, modrm_index, reg, v, op1, is_short_jmp, has_seg_prefix;
     int nb_ops, s, ss;
-    Operand ops[MAX_OPERANDS], *pop;
+    Operand ops[MAX_OPERANDS], *pop, seg_prefix;
     int op_type[3]; /* decoded op type */
 
     /* get operands */
     pop = ops;
     nb_ops = 0;
+    has_seg_prefix = 0;
     for(;;) {
         if (tok == ';' || tok == TOK_LINEFEED)
             break;
@@ -425,6 +435,18 @@
             error("incorrect number of operands");
         }
         parse_operand(s1, pop);
+        if (tok == ':') {
+           if (pop->type != OP_SEG || has_seg_prefix) {
+               error("incorrect prefix");
+           }
+           seg_prefix = *pop;
+           has_seg_prefix = 1;
+           next();
+           parse_operand(s1, pop);
+           if (!(pop->type & (OP_IM8 | OP_IM16 | OP_IM32 | OP_IM8S | 
OP_ADDR))) {
+               error("segment prefix must be followed by immediate operand");
+           }
+        }
         pop++;
         nb_ops++;
         if (tok != ',')
@@ -538,6 +560,8 @@
     /* now generates the operation */
     if (pa->instr_type & OPC_FWAIT)
         g(0x9b);
+    if (has_seg_prefix)
+        g(segment_prefixes[seg_prefix.reg]);
 
     v = pa->opcode;
     if (v == 0x69 || v == 0x69) {

reply via email to

[Prev in Thread] Current Thread [Next in Thread]