generate_m88k_bcnd.c Source File

Back to the index.

generate_m88k_bcnd.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2007-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 #include <string.h>
30 
31 
32 void print_function_name(int samepage, int n_bit, int m5)
33 {
34  printf("bcnd_");
35 
36  if (n_bit)
37  printf("n_");
38 
39  if (samepage)
40  printf("samepage_");
41 
42  switch (m5) {
43  case 0x1: printf("gt0"); break;
44  case 0x2: printf("eq0"); break;
45  case 0x3: printf("ge0"); break;
46  case 0x7: printf("not_maxneg"); break;
47  case 0x8: printf("maxneg"); break;
48  case 0xc: printf("lt0"); break;
49  case 0xd: printf("ne0"); break;
50  case 0xe: printf("le0"); break;
51  }
52 }
53 
54 
55 void print_operator(int m5)
56 {
57  switch (m5) {
58  case 0x1: printf("> 0"); break;
59  case 0x2: printf("== 0"); break;
60  case 0x3: printf(">= 0"); break;
61  case 0x7: printf("!= 0x80000000UL"); break;
62  case 0x8: printf("== 0x80000000UL"); break;
63  case 0xc: printf("< 0"); break;
64  case 0xd: printf("!= 0"); break;
65  case 0xe: printf("<= 0"); break;
66  }
67 }
68 
69 
70 void bcnd(int samepage, int n_bit, int m5)
71 {
72  if (samepage && n_bit)
73  return;
74 
75  printf("\nX(");
76  print_function_name(samepage, n_bit, m5);
77  printf(")\n{\n");
78 
79  /* Easiest case is without the n_bit: */
80  if (!n_bit) {
81  printf("\tif ((%sint32_t)reg(ic->arg[0]) ",
82  (m5 == 7 || m5 == 8)? "u" : "");
83  print_operator(m5);
84  printf(") {\n");
85 
86  if (samepage)
87  printf("\t\tcpu->cd.m88k.next_ic = (struct m88k_"
88  "instr_call *) ic->arg[2];\n");
89  else
90  printf("\t\tcpu->pc = (cpu->pc & 0xfffff000) + "
91  "(int32_t)ic->arg[2];\n\t\tquick_pc_to_"
92  "pointers(cpu);\n");
93 
94  printf("\t}\n");
95  } else {
96  /* n_bit, i.e. delay slot: */
97  printf("\tint cond = (%sint32_t)reg(ic->arg[0]) ",
98  (m5 == 7 || m5 == 8)? "u" : "");
99  print_operator(m5);
100  printf(";\n");
101 
102  printf("\tSYNCH_PC;\n");
103 
104  printf("\tif (cond)\n");
105  printf("\t\tcpu->cd.m88k.delay_target = (cpu->pc\n");
106  printf("\t\t\t& ~((M88K_IC_ENTRIES_PER_PAGE-1)"
107  " << M88K_INSTR_ALIGNMENT_SHIFT))\n");
108  printf("\t\t\t+ ic->arg[2];\n");
109  printf("\telse\n");
110  printf("\t\tcpu->cd.m88k.delay_target = cpu->pc + 8;\n");
111 
112  printf("\tcpu->delay_slot = TO_BE_DELAYED;\n");
113  printf("\tic[1].f(cpu, ic+1);\n");
114  printf("\tcpu->n_translated_instrs ++;\n");
115 
116  printf("\tif (!(cpu->delay_slot & EXCEPTION_IN_"
117  "DELAY_SLOT)) {\n");
118  printf("\t\tcpu->delay_slot = NOT_DELAYED;\n");
119  printf("\t\tif (cond) {\n");
120 
121  printf("\t\t\tcpu->pc = cpu->cd.m88k.delay_target;\n");
122  printf("\t\t\tquick_pc_to_pointers(cpu);\n");
123 
124  printf("\t\t} else\n");
125  printf("\t\t\tcpu->cd.m88k.next_ic ++;\n");
126  printf("\t} else\n");
127  printf("\t\tcpu->delay_slot = NOT_DELAYED;\n");
128 
129  }
130 
131  printf("}\n\n");
132 }
133 
134 
135 int main(int argc, char *argv[])
136 {
137  int samepage, n_bit, m5;
138 
139  printf("\n/* AUTOMATICALLY GENERATED! Do not edit. */\n\n");
140 
141  for (samepage=0; samepage<=1; samepage++)
142  for (n_bit=0; n_bit<=1; n_bit++)
143  for (m5=0; m5<=31; m5++) {
144  if (m5 == 1 || m5 == 2 || m5 == 3 || m5 == 7 || m5 == 8 ||
145  m5 == 0xc || m5 == 0xd || m5 == 0xe)
146  bcnd(samepage, n_bit, m5);
147  }
148 
149  /* Array of pointers to all the functions: */
150  printf("\n\nvoid (*m88k_bcnd[32 * 2 * 2])(struct cpu *, struct "
151  "m88k_instr_call *) = {\n");
152  for (samepage=0; samepage<=1; samepage++)
153  for (n_bit=0; n_bit<=1; n_bit++)
154  for (m5=0; m5<=31; m5++) {
155  if (m5 || n_bit || samepage)
156  printf(",\n");
157 
158  if (m5 == 1 || m5 == 2 || m5 == 3 || m5 == 7 || m5 == 8 ||
159  m5 == 0xc || m5 == 0xd || m5 == 0xe) {
160  if (samepage && n_bit)
161  printf("NULL");
162  else {
163  printf("m88k_instr_");
165  samepage, n_bit, m5);
166  }
167  } else
168  printf("NULL");
169  }
170  printf(" };\n");
171 
172  return 0;
173 }
174 
void print_operator(int m5)
int main(int argc, char *argv[])
void print_function_name(int samepage, int n_bit, int m5)
void bcnd(int samepage, int n_bit, int m5)

Generated on Fri Dec 7 2018 19:52:23 for GXemul by doxygen 1.8.13