generate_arm_dpi.c Source File

Back to the index.

generate_arm_dpi.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2009 Anders Gavare. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  * 1. Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * 3. The name of the author may not be used to endorse or promote products
13  * derived from this software without specific prior written permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  * SUCH DAMAGE.
26  */
27 
28 #include <stdio.h>
29 
30 char *cond[16] = {
31  "eq", "ne", "cs", "cc", "mi", "pl", "vs", "vc",
32  "hi", "ls", "ge", "lt", "gt", "le", "", "" };
33 
34 char *op[16] = {
35  "and", "eor", "sub", "rsb", "add", "adc", "sbc", "rsc",
36  "tst", "teq", "cmp", "cmn", "orr", "mov", "bic", "mvn" };
37 
38 
39 static char *uppercase(char *l)
40 {
41  static char staticbuf[1000];
42  size_t i = 0;
43 
44  while (*l && i < sizeof(staticbuf)) {
45  char u = *l++;
46  if (u >= 'a' && u <= 'z')
47  u -= 32;
48  staticbuf[i++] = u;
49  }
50  if (i == sizeof(staticbuf))
51  i--;
52  staticbuf[i] = 0;
53  return staticbuf;
54 }
55 
56 
57 int main(int argc, char *argv[])
58 {
59  int n, a, reg, pc, s, c;
60 
61  printf("\n/* AUTOMATICALLY GENERATED! Do not edit. */\n\n");
62  printf("#include <stdio.h>\n#include <stdlib.h>\n"
63  "#include \"cpu.h\"\n"
64  "#include \"misc.h\"\n"
65  "#define DYNTRANS_PC_TO_POINTERS arm_pc_to_pointers\n"
66  "#include \"quick_pc_to_pointers.h\"\n"
67  "#define reg(x) (*((uint32_t *)(x)))\n");
68  printf("extern void arm_instr_nop(struct cpu *, "
69  "struct arm_instr_call *);\n");
70  printf("extern void arm_instr_invalid(struct cpu *, "
71  "struct arm_instr_call *);\n");
72  printf("extern void arm_pc_to_pointers(struct cpu *);\n");
73 
74  for (reg=0; reg<=2; reg++)
75  for (pc=0; pc<=1; pc++)
76  for (s=0; s<=1; s++)
77  for (a=0; a<16; a++) {
78  if (a >= 8 && a <= 11 && s == 0)
79  continue;
80  if (reg == 2 && pc)
81  continue;
82  printf("#define A__NAME arm_instr_%s%s%s%s\n",
83  op[a], s? "s" : "", pc? "_pc" : "", reg?
84  (reg==2? "_regshort" : "_reg") : "");
85 
86  for (c=0; c<14; c++)
87  printf("#define A__NAME__%s arm_instr_%s%s%s%s__%s\n",
88  cond[c], op[a], s? "s" : "", pc? "_pc" : "",
89  reg? (reg==2? "_regshort" : "_reg") : "", cond[c]);
90  if (s) printf("#define A__S\n");
91  switch (reg) {
92  case 1: printf("#define A__REG\n"); break;
93  case 2: printf("#define A__REGSHORT\n"); break;
94  }
95  if (pc) printf("#define A__PC\n");
96  printf("#define A__%s\n", uppercase(op[a]));
97  printf("#include \"cpu_arm_instr_dpi.cc\"\n");
98  printf("#undef A__%s\n", uppercase(op[a]));
99  if (s) printf("#undef A__S\n");
100  switch (reg) {
101  case 1: printf("#undef A__REG\n"); break;
102  case 2: printf("#undef A__REGSHORT\n"); break;
103  }
104  if (pc) printf("#undef A__PC\n");
105  for (c=0; c<14; c++)
106  printf("#undef A__NAME__%s\n", cond[c]);
107  printf("#undef A__NAME\n");
108  }
109 
110  printf("\n\tvoid (*arm_dpi_instr[2 * 2 * 2 * 16 * 16])(struct cpu *,\n"
111  "\t\tstruct arm_instr_call *) = {\n");
112  n = 0;
113  for (reg=0; reg<=1; reg++)
114  for (pc=0; pc<=1; pc++)
115  for (s=0; s<=1; s++)
116  for (a=0; a<16; a++)
117  for (c=0; c<16; c++) {
118  if (c == 15)
119  printf("\tarm_instr_nop");
120  else if (a >= 8 && a <= 11 && s == 0)
121  printf("\tarm_instr_invalid");
122  else
123  printf("\tarm_instr_%s%s%s%s%s%s",
124  op[a], s? "s" : "", pc? "_pc" : "",
125  reg? "_reg" : "",
126  c!=14? "__" : "", cond[c]);
127  n++;
128  if (n != 2 * 2 * 2 * 16 * 16)
129  printf(",");
130  printf("\n");
131  }
132 
133  printf("};\n\n");
134 
135  printf("\n\tvoid (*arm_dpi_instr_regshort[2 * 16 * 16])(struct cpu *,\n"
136  "\t\tstruct arm_instr_call *) = {\n");
137  n = 0;
138  for (s=0; s<=1; s++)
139  for (a=0; a<16; a++)
140  for (c=0; c<16; c++) {
141  if (c == 15)
142  printf("\tarm_instr_nop");
143  else if (a >= 8 && a <= 11 && s == 0)
144  printf("\tarm_instr_invalid");
145  else
146  printf("\tarm_instr_%s%s_regshort%s%s",
147  op[a], s? "s" : "",
148  c!=14? "__" : "", cond[c]);
149  n++;
150  if (n != 2 * 16 * 16)
151  printf(",");
152  printf("\n");
153  }
154 
155  printf("};\n\n");
156 
157  return 0;
158 }
159 
main
int main(int argc, char *argv[])
Definition: generate_arm_dpi.c:57
op
char * op[16]
Definition: generate_arm_dpi.c:34
cond
char * cond[16]
Definition: generate_arm_dpi.c:30
reg
#define reg(x)
Definition: tmp_alpha_tail.cc:53

Generated on Tue Aug 25 2020 19:25:06 for GXemul by doxygen 1.8.18