generate_mips_loadstore_multi.c Source File

Back to the index.

generate_mips_loadstore_multi.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2007-2019 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 #include <string.h>
30 
31 
32 void generate_multi(int store, int endianness, int n, int sixtyfourbit)
33 {
34  int i, nr;
35 
36  printf("X(multi_%cw_%i_%ce)\n{\n",
37  store? 's' : 'l', n, endianness? 'b' : 'l');
38 
39  printf("\tuint32_t *page;\n"
40  "\tMODE_uint_t rX = reg(ic[0].arg[1])");
41  for (i=0; i<n; i++)
42  printf(", r%i", i);
43  printf(";\n");
44 
45  for (i=0; i<n; i++)
46  printf("\tMODE_uint_t addr%i = rX + (int32_t)ic[%i].arg[2];\n",
47  i, i);
48 
49  if (sixtyfourbit) {
50  printf("\tconst uint32_t mask1 = (1 << DYNTRANS_L1N) - 1;\n");
51  printf("\tconst uint32_t mask2 = (1 << DYNTRANS_L2N) - 1;\n");
52  printf("\tconst uint32_t mask3 = (1 << DYNTRANS_L3N) - 1;\n");
53  printf("\tuint32_t x1, x2, x3;\n");
54  printf("\tstruct DYNTRANS_L2_64_TABLE *l2;\n");
55  printf("\tstruct DYNTRANS_L3_64_TABLE *l3;\n");
56  printf("\tx1 = (addr0 >> (64-DYNTRANS_L1N)) & mask1;\n");
57  printf("\tx2 = (addr0 >> (64-DYNTRANS_L1N-DYNTRANS_L2N)) & mask2;\n");
58  printf("\tx3 = (addr0 >> (64-DYNTRANS_L1N-DYNTRANS_L2N-DYNTRANS_L3N)) & mask3;\n");
59  printf("\tl2 = cpu->cd.DYNTRANS_ARCH.l1_64[x1];\n");
60  printf("\tl3 = l2->l3[x2];\n");
61  printf("\tpage = (uint32_t *) l3->host_%s[x3];\n",
62  store? "store" : "load");
63  } else {
64  printf("\tuint32_t index%i = addr%i >> 12;\n", 0, 0);
65  printf("\tpage = (uint32_t *) cpu->cd.mips.host_%s[index0];\n",
66  store? "store" : "load");
67  }
68 
69  printf("\tif (cpu->delay_slot ||\n"
70  "\t page == NULL");
71  for (i=0; i<n; i++)
72  printf(" || (addr%i & 3)", i);
73  printf("\n\t ");
74  for (i=1; i<n; i++)
75  printf(" || ((addr%i ^ addr0) & ~0xfff)", i);
76  printf(") {\n");
77 
78  nr = 2*2;
79  if (store)
80  nr += 8;
81  else
82  nr += 1;
83  if (endianness)
84  nr += 16;
85  printf("\t\tmips%s_loadstore[%i](cpu, ic);\n", sixtyfourbit ? "" : "32", nr);
86 
87  printf("\t\treturn;\n\t}\n");
88 
89  for (i=0; i<n; i++)
90  printf("\taddr%i = (addr%i >> 2) & 0x3ff;\n", i, i);
91 
92  if (store) {
93  for (i=0; i<n; i++)
94  printf("\tr%i = reg(ic[%i].arg[0]);\n", i, i);
95  for (i=0; i<n; i++)
96  printf("\tr%i = %cE32_TO_HOST(r%i);\n", i,
97  endianness? 'B' : 'L', i);
98  for (i=0; i<n; i++)
99  printf("\tpage[addr%i] = r%i;\n", i, i);
100  } else {
101  for (i=0; i<n; i++)
102  printf("\tr%i = page[addr%i];\n", i, i);
103  for (i=0; i<n; i++)
104  printf("\tr%i = %cE32_TO_HOST(r%i);\n", i,
105  endianness? 'B' : 'L', i);
106  for (i=0; i<n; i++)
107  printf("\treg(ic[%i].arg[0]) = (MODE_int_t)(int32_t)r%i;\n", i, i);
108  }
109 
110  printf("\tcpu->n_translated_instrs += %i;\n", n - 1);
111  printf("\tcpu->cd.mips.next_ic += %i;\n", n - 1);
112 
113  printf("}\n");
114 }
115 
116 
117 int main(int argc, char *argv[])
118 {
119  int store, endianness, n;
120 
121  printf("\n/* AUTOMATICALLY GENERATED! Do not edit. */\n\n");
122 
123  for (endianness=0; endianness<=1; endianness++)
124  for (store=0; store<=1; store++)
125  for (n=2; n<=5; n++) {
126  printf("#ifdef MODE32\n");
127  generate_multi(store, endianness, n, 0);
128  printf("#else\n");
129  generate_multi(store, endianness, n, 1);
130  printf("#endif\n\n");
131  }
132 
133  return 0;
134 }
135 
main
int main(int argc, char *argv[])
Definition: generate_mips_loadstore_multi.c:117
generate_multi
void generate_multi(int store, int endianness, int n, int sixtyfourbit)
Definition: generate_mips_loadstore_multi.c:32

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