home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.2 (Developer) / NS_dev_3.2.iso / NextDeveloper / Source / GNU / cctools / as / i386-check.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-09-09  |  5.9 KB  |  221 lines

  1. #include "as.h"
  2. #include "flonum.h"
  3. #include "frags.h"
  4. #include "struc-symbol.h"
  5. #include "expr.h"
  6. #include "i386.h"
  7. #include "i386-opcode.h"
  8.  
  9. static char **get_operand(
  10.     unsigned long type);
  11. static char *get_suffix(
  12.     unsigned long type);
  13.  
  14. void
  15. main(void)
  16. {
  17.     template *t;
  18.     prefix_entry *p;
  19.     long prefix;
  20.  
  21.     unsigned long i, j, type0, type1;
  22.     char **op0, **op1;
  23.     char *suffix;
  24.  
  25.     for(t = i386_optab; t < i386_optab_end; t++){
  26.         /*
  27.          * Don't use the table entries that are prefixes and not
  28.          * instructions.
  29.          */
  30.         prefix = 0;
  31.         for(p = i386_prefixtab; p < i386_prefixtab_end; p++){
  32.         prefix = (p->prefix_code == t->base_opcode);
  33.         if(prefix)
  34.             break;
  35.         }
  36.         if(prefix)
  37.         continue;
  38.         /*
  39.          * The string instructions with operands take only specific
  40.          * operands and are not checked here.
  41.          */
  42.         if(t->operands != 0 && IS_STRING_INSTRUCTION(t->base_opcode))
  43.         continue;
  44.        
  45.         if(t->operands == 0){
  46.         if((t->opcode_modifier & W) == 0) {
  47.             printf("\t%s\n", t->name);
  48.         }
  49.         else{
  50.             printf("\t%sb\n", t->name);
  51.             printf("\t%sw\n", t->name);
  52.             printf("\t%sl\n", t->name);
  53.         }
  54.         }
  55.  
  56.         if(t->operands == 1){
  57.         for(i = 0; i < 32; i++){
  58.             type0 = 1 << i;
  59.             if((type0 & t->operand_types[0]) == 0)
  60.             continue;
  61.  
  62.             /* These only take byte displacement */
  63.             if(IS_LOOP_ECX_TIMES(t->base_opcode) &&
  64.                (type0 == Disp16 || type0 == Disp32))
  65.             continue;
  66.  
  67.             /* These only take byte displacement */
  68.             if((strcmp(t->name, "jcxz") == 0 ||
  69.                 strcmp(t->name, "jecxz") == 0) &&
  70.                (type0 == Disp16 || type0 == Disp32))
  71.             continue;
  72.  
  73.             if(type0 == Disp8 &&
  74.                ((t->operand_types[0] & (Disp16 | Disp32)) != 0))
  75.             continue;
  76.  
  77.             suffix = "";
  78.             if((type0 & Mem) != 0)
  79.             suffix = get_suffix(type0);
  80.  
  81.             /* fwait prefixed instructions */
  82.             if((t->base_opcode & 0xff00) == 0x9b00 &&
  83.                strcmp(suffix, "w") == 0)
  84.             continue;
  85.  
  86.             op0 = get_operand(type0);
  87.             for( ; *op0; op0++){
  88.             printf("\t%s%s\t%s\n", t->name, suffix, *op0);
  89.             }
  90.         }
  91.         }
  92.  
  93.         if(t->operands == 2){
  94.         for(i = 0; i < 32; i++){
  95.             type0 = 1 << i;
  96.             if((type0 & t->operand_types[0]) == 0)
  97.             continue;
  98.             for(j = 0; j < 32; j++){
  99.             type1 = 1 << j;
  100.             if((type1 & t->operand_types[1]) == 0)
  101.                 continue;
  102.             if((type0 & Reg) != 0 && (type1 & Reg) != 0)
  103.                 if(type0 != type1)
  104.                 continue;
  105.  
  106.             suffix = "";
  107.             if((type0 & (Imm|Imm1)) != 0 && (type1 & Mem) != 0)
  108.                 suffix = get_suffix(type0);
  109.             if((type0 & Mem) != 0 && (type1 & (Imm|Imm1)) != 0)
  110.                 suffix = get_suffix(type1);
  111.  
  112.             op0 = get_operand(type0);
  113.             op1 = get_operand(type1);
  114.             for( ; *op0; op0++){
  115.                 for( ; *op1; op1++){
  116.                 printf("\t%s%s\t%s,%s\n", t->name, suffix,
  117.                        *op0, *op1);
  118.                 if(t->opcode_modifier & D){
  119.                     printf("\t%s%s\t%s,%s\n", t->name, suffix,
  120.                        *op1, *op0);
  121.                 }
  122.                 }
  123.             }
  124.             }
  125.         }
  126.         }
  127.     }
  128. }
  129.  
  130. static
  131. char *
  132. get_suffix(
  133. unsigned long type)
  134. {
  135.     switch(type){
  136.     case Imm8:    return("b");
  137.     case Imm8S:    return("b");
  138.     case Imm16:    return("w");
  139.     case Imm32:    return("l");
  140.     case Imm1:    return("l"); /* all */
  141.     case Disp8:    return("b");
  142.     case Disp16:    return("w");
  143.     case Disp32:    return("l");
  144.     case Mem8:    return("b");
  145.     case Mem16:    return("w");
  146.     case Mem32:    return("l");
  147.     case BaseIndex:    return("l"); /* all */
  148.     default:    return("");
  149.     }
  150. }
  151.  
  152. static char *Reg8_table[] = { "%bl", NULL };
  153. static char *Reg16_table[] = { "%bx", NULL };
  154. static char *Reg32_table[] = { "%ebx", NULL };
  155. static char *Imm8_table[] = { "$0x7f", NULL };
  156. static char *Imm8S_table[] = { "$0xfe", NULL };
  157. static char *Imm16_table[] = { "$0xface", NULL };
  158. static char *Imm32_table[] = { "$0xcafebabe", NULL };
  159. static char *Imm1_table[] = { "$0", "$1", NULL };
  160. static char *Disp8_table[] = { "0x45", NULL };
  161. static char *Disp16_table[] = { "0xfeed", NULL };
  162. static char *Disp32_table[] = { "0xbabecafe", NULL };
  163. static char *Mem8_table[] = { "0x88888888", NULL };
  164. static char *Mem16_table[] = { "0x16161616", NULL };
  165. static char *Mem32_table[] = { "0x32323232", NULL };
  166. static char *BaseIndex_table[] = { "0xdeadbeef(%ebx,%ecx,8)", NULL };
  167. static char *InOutPortReg_table[] = { "%dx", NULL };
  168. static char *ShiftCount_table[] = { "%cl", NULL };
  169. static char *Control_table[] = { "%cr0", NULL };
  170. static char *Debug_table[] = { "%db0", NULL };
  171. static char *Test_table[] = { "%tr3", NULL };
  172. static char *FloatReg_table[] = { "%st(1)", NULL };
  173. static char *FloatAcc_table[] = { "%st", NULL };
  174. static char *SReg2_table[] = { "%ds", NULL };
  175. static char *SReg3_table[] = { "%fs", NULL };
  176. static char *Acc_table[] = { "%eax", NULL };
  177. static char *JumpAbsolute_table[] = { "*0xbadeface", NULL };
  178. static char *Abs8_table[] = { "0xab", NULL };
  179. static char *Abs16_table[] = { "0xabcd", NULL };
  180. static char *Abs32_table[] = { "0xabcdef01", NULL };
  181. static char *hosed_table[] = { "hosed", NULL };
  182.  
  183. static
  184. char **
  185. get_operand(
  186. unsigned long type)
  187. {
  188.     switch(type){
  189.     case Reg8:    return(Reg8_table);
  190.     case Reg16:    return(Reg16_table);
  191.     case Reg32:    return(Reg32_table);
  192.     case Imm8:    return(Imm8_table);
  193.     case Imm8S:    return(Imm8S_table);
  194.     case Imm16:    return(Imm16_table);
  195.     case Imm32:    return(Imm32_table);
  196.     case Imm1:    return(Imm1_table);
  197.     case Disp8:    return(Disp8_table);
  198.     case Disp16:    return(Disp16_table);
  199.     case Disp32:    return(Disp32_table);
  200.     case Mem8:    return(Mem8_table);
  201.     case Mem16:    return(Mem16_table);
  202.     case Mem32:    return(Mem32_table);
  203.     case BaseIndex:    return(BaseIndex_table);
  204.     case InOutPortReg:    return(InOutPortReg_table);
  205.     case ShiftCount:    return(ShiftCount_table);
  206.     case Control:    return(Control_table);
  207.     case Debug:    return(Debug_table);
  208.     case Test:    return(Test_table);
  209.     case FloatReg:    return(FloatReg_table);
  210.     case FloatAcc:    return(FloatAcc_table);
  211.     case SReg2:    return(SReg2_table);
  212.     case SReg3:    return(SReg3_table);
  213.     case Acc:    return(Acc_table);
  214.     case JumpAbsolute:    return(JumpAbsolute_table);
  215.     case Abs8:    return(Abs8_table);
  216.     case Abs16:    return(Abs16_table);
  217.     case Abs32:    return(Abs32_table);
  218.     default:    return(hosed_table);
  219.     }
  220. }
  221.