1 /*
2 * MIPS emulation for qemu: CPU initialisation routines.
3 *
4 * Copyright (c) 2004-2005 Jocelyn Mayer
5 * Copyright (c) 2007 Herve Poussineau
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
19 */
20
21 /* CPU / CPU family specific config register values. */
22
23 /* Have config1, uncached coherency */
24 #define MIPS_CONFIG0 \
25 ((1U << CP0C0_M) | (0x2 << CP0C0_K0))
26
27 /* Have config2, no coprocessor2 attached, no MDMX support attached,
28 no performance counters, watch registers present,
29 no code compression, EJTAG present, no FPU */
30 #define MIPS_CONFIG1 \
31 ((1U << CP0C1_M) | \
32 (0 << CP0C1_C2) | (0 << CP0C1_MD) | (0 << CP0C1_PC) | \
33 (1 << CP0C1_WR) | (0 << CP0C1_CA) | (1 << CP0C1_EP) | \
34 (0 << CP0C1_FP))
35
36 /* Have config3, no tertiary/secondary caches implemented */
37 #define MIPS_CONFIG2 \
38 ((1U << CP0C2_M))
39
40 /* No config4, no DSP ASE, no large physaddr (PABITS),
41 no external interrupt controller, no vectored interrupts,
42 no 1kb pages, no SmartMIPS ASE, no trace logic */
43 #define MIPS_CONFIG3 \
44 ((0 << CP0C3_M) | (0 << CP0C3_DSPP) | (0 << CP0C3_LPA) | \
45 (0 << CP0C3_VEIC) | (0 << CP0C3_VInt) | (0 << CP0C3_SP) | \
46 (0 << CP0C3_SM) | (0 << CP0C3_TL))
47
48 #define MIPS_CONFIG4 \
49 ((0 << CP0C4_M))
50
51 #define MIPS_CONFIG5 \
52 ((0 << CP0C5_M))
53
54 /*****************************************************************************/
55 /* MIPS CPU definitions */
56 const mips_def_t mips_defs[] =
57 {
58 {
59 .name = "4Kc",
60 .CP0_PRid = 0x00018000,
61 .CP0_Config0 = MIPS_CONFIG0 | (MMU_TYPE_R4000 << CP0C0_MT),
62 .CP0_Config1 = MIPS_CONFIG1 | (15 << CP0C1_MMU) |
63 (0 << CP0C1_IS) | (3 << CP0C1_IL) | (1 << CP0C1_IA) |
64 (0 << CP0C1_DS) | (3 << CP0C1_DL) | (1 << CP0C1_DA) |
65 (0 << CP0C1_CA),
66 .CP0_Config2 = MIPS_CONFIG2,
67 .CP0_Config3 = MIPS_CONFIG3,
68 .CP0_LLAddr_rw_bitmask = 0,
69 .CP0_LLAddr_shift = 4,
70 .SYNCI_Step = 32,
71 .CCRes = 2,
72 .CP0_Status_rw_bitmask = 0x1278FF17,
73 .SEGBITS = 32,
74 .PABITS = 32,
75 .insn_flags = CPU_MIPS32,
76 .mmu_type = MMU_TYPE_R4000,
77 },
78 {
79 .name = "4Km",
80 .CP0_PRid = 0x00018300,
81 /* Config1 implemented, fixed mapping MMU,
82 no virtual icache, uncached coherency. */
83 .CP0_Config0 = MIPS_CONFIG0 | (MMU_TYPE_FMT << CP0C0_MT),
84 .CP0_Config1 = MIPS_CONFIG1 |
85 (0 << CP0C1_IS) | (3 << CP0C1_IL) | (1 << CP0C1_IA) |
86 (0 << CP0C1_DS) | (3 << CP0C1_DL) | (1 << CP0C1_DA) |
87 (1 << CP0C1_CA),
88 .CP0_Config2 = MIPS_CONFIG2,
89 .CP0_Config3 = MIPS_CONFIG3,
90 .CP0_LLAddr_rw_bitmask = 0,
91 .CP0_LLAddr_shift = 4,
92 .SYNCI_Step = 32,
93 .CCRes = 2,
94 .CP0_Status_rw_bitmask = 0x1258FF17,
95 .SEGBITS = 32,
96 .PABITS = 32,
97 .insn_flags = CPU_MIPS32 | ASE_MIPS16,
98 .mmu_type = MMU_TYPE_FMT,
99 },
100 {
101 .name = "4KEcR1",
102 .CP0_PRid = 0x00018400,
103 .CP0_Config0 = MIPS_CONFIG0 | (MMU_TYPE_R4000 << CP0C0_MT),
104 .CP0_Config1 = MIPS_CONFIG1 | (15 << CP0C1_MMU) |
105 (0 << CP0C1_IS) | (3 << CP0C1_IL) | (1 << CP0C1_IA) |
106 (0 << CP0C1_DS) | (3 << CP0C1_DL) | (1 << CP0C1_DA) |
107 (0 << CP0C1_CA),
108 .CP0_Config2 = MIPS_CONFIG2,
109 .CP0_Config3 = MIPS_CONFIG3,
110 .CP0_LLAddr_rw_bitmask = 0,
111 .CP0_LLAddr_shift = 4,
112 .SYNCI_Step = 32,
113 .CCRes = 2,
114 .CP0_Status_rw_bitmask = 0x1278FF17,
115 .SEGBITS = 32,
116 .PABITS = 32,
117 .insn_flags = CPU_MIPS32,
118 .mmu_type = MMU_TYPE_R4000,
119 },
120 {
121 .name = "4KEmR1",
122 .CP0_PRid = 0x00018500,
123 .CP0_Config0 = MIPS_CONFIG0 | (MMU_TYPE_FMT << CP0C0_MT),
124 .CP0_Config1 = MIPS_CONFIG1 |
125 (0 << CP0C1_IS) | (3 << CP0C1_IL) | (1 << CP0C1_IA) |
126 (0 << CP0C1_DS) | (3 << CP0C1_DL) | (1 << CP0C1_DA) |
127 (1 << CP0C1_CA),
128 .CP0_Config2 = MIPS_CONFIG2,
129 .CP0_Config3 = MIPS_CONFIG3,
130 .CP0_LLAddr_rw_bitmask = 0,
131 .CP0_LLAddr_shift = 4,
132 .SYNCI_Step = 32,
133 .CCRes = 2,
134 .CP0_Status_rw_bitmask = 0x1258FF17,
135 .SEGBITS = 32,
136 .PABITS = 32,
137 .insn_flags = CPU_MIPS32 | ASE_MIPS16,
138 .mmu_type = MMU_TYPE_FMT,
139 },
140 {
141 .name = "4KEc",
142 .CP0_PRid = 0x00019000,
143 .CP0_Config0 = MIPS_CONFIG0 | (0x1 << CP0C0_AR) |
144 (MMU_TYPE_R4000 << CP0C0_MT),
145 .CP0_Config1 = MIPS_CONFIG1 | (15 << CP0C1_MMU) |
146 (0 << CP0C1_IS) | (3 << CP0C1_IL) | (1 << CP0C1_IA) |
147 (0 << CP0C1_DS) | (3 << CP0C1_DL) | (1 << CP0C1_DA) |
148 (0 << CP0C1_CA),
149 .CP0_Config2 = MIPS_CONFIG2,
150 .CP0_Config3 = MIPS_CONFIG3 | (0 << CP0C3_VInt),
151 .CP0_LLAddr_rw_bitmask = 0,
152 .CP0_LLAddr_shift = 4,
153 .SYNCI_Step = 32,
154 .CCRes = 2,
155 .CP0_Status_rw_bitmask = 0x1278FF17,
156 .SEGBITS = 32,
157 .PABITS = 32,
158 .insn_flags = CPU_MIPS32R2,
159 .mmu_type = MMU_TYPE_R4000,
160 },
161 {
162 .name = "4KEm",
163 .CP0_PRid = 0x00019100,
164 .CP0_Config0 = MIPS_CONFIG0 | (0x1 << CP0C0_AR) |
165 (MMU_TYPE_FMT << CP0C0_MT),
166 .CP0_Config1 = MIPS_CONFIG1 |
167 (0 << CP0C1_IS) | (3 << CP0C1_IL) | (1 << CP0C1_IA) |
168 (0 << CP0C1_DS) | (3 << CP0C1_DL) | (1 << CP0C1_DA) |
169 (1 << CP0C1_CA),
170 .CP0_Config2 = MIPS_CONFIG2,
171 .CP0_Config3 = MIPS_CONFIG3,
172 .CP0_LLAddr_rw_bitmask = 0,
173 .CP0_LLAddr_shift = 4,
174 .SYNCI_Step = 32,
175 .CCRes = 2,
176 .CP0_Status_rw_bitmask = 0x1258FF17,
177 .SEGBITS = 32,
178 .PABITS = 32,
179 .insn_flags = CPU_MIPS32R2 | ASE_MIPS16,
180 .mmu_type = MMU_TYPE_FMT,
181 },
182 {
183 .name = "24Kc",
184 .CP0_PRid = 0x00019300,
185 .CP0_Config0 = MIPS_CONFIG0 | (0x1 << CP0C0_AR) |
186 (MMU_TYPE_R4000 << CP0C0_MT),
187 .CP0_Config1 = MIPS_CONFIG1 | (15 << CP0C1_MMU) |
188 (0 << CP0C1_IS) | (3 << CP0C1_IL) | (1 << CP0C1_IA) |
189 (0 << CP0C1_DS) | (3 << CP0C1_DL) | (1 << CP0C1_DA) |
190 (1 << CP0C1_CA),
191 .CP0_Config2 = MIPS_CONFIG2,
192 .CP0_Config3 = MIPS_CONFIG3 | (0 << CP0C3_VInt),
193 .CP0_LLAddr_rw_bitmask = 0,
194 .CP0_LLAddr_shift = 4,
195 .SYNCI_Step = 32,
196 .CCRes = 2,
197 /* No DSP implemented. */
198 .CP0_Status_rw_bitmask = 0x1278FF1F,
199 .SEGBITS = 32,
200 .PABITS = 32,
201 .insn_flags = CPU_MIPS32R2 | ASE_MIPS16,
202 .mmu_type = MMU_TYPE_R4000,
203 },
204 {
205 .name = "24KEc",
206 .CP0_PRid = 0x00019600,
207 .CP0_Config0 = MIPS_CONFIG0 | (0x1 << CP0C0_AR) |
208 (MMU_TYPE_R4000 << CP0C0_MT),
209 .CP0_Config1 = MIPS_CONFIG1 | (15 << CP0C1_MMU) |
210 (0 << CP0C1_IS) | (3 << CP0C1_IL) | (1 << CP0C1_IA) |
211 (0 << CP0C1_DS) | (3 << CP0C1_DL) | (1 << CP0C1_DA) |
212 (1 << CP0C1_CA),
213 .CP0_Config2 = MIPS_CONFIG2,
214 .CP0_Config3 = MIPS_CONFIG3 | (1 << CP0C3_DSPP) | (0 << CP0C3_VInt),
215 .CP0_LLAddr_rw_bitmask = 0,
216 .CP0_LLAddr_shift = 4,
217 .SYNCI_Step = 32,
218 .CCRes = 2,
219 /* we have a DSP, but no FPU */
220 .CP0_Status_rw_bitmask = 0x1378FF1F,
221 .SEGBITS = 32,
222 .PABITS = 32,
223 .insn_flags = CPU_MIPS32R2 | ASE_MIPS16 | ASE_DSP,
224 .mmu_type = MMU_TYPE_R4000,
225 },
226 {
227 .name = "24Kf",
228 .CP0_PRid = 0x00019300,
229 .CP0_Config0 = MIPS_CONFIG0 | (0x1 << CP0C0_AR) |
230 (MMU_TYPE_R4000 << CP0C0_MT),
231 .CP0_Config1 = MIPS_CONFIG1 | (1 << CP0C1_FP) | (15 << CP0C1_MMU) |
232 (0 << CP0C1_IS) | (3 << CP0C1_IL) | (1 << CP0C1_IA) |
233 (0 << CP0C1_DS) | (3 << CP0C1_DL) | (1 << CP0C1_DA) |
234 (1 << CP0C1_CA),
235 .CP0_Config2 = MIPS_CONFIG2,
236 .CP0_Config3 = MIPS_CONFIG3 | (0 << CP0C3_VInt),
237 .CP0_LLAddr_rw_bitmask = 0,
238 .CP0_LLAddr_shift = 4,
239 .SYNCI_Step = 32,
240 .CCRes = 2,
241 /* No DSP implemented. */
242 .CP0_Status_rw_bitmask = 0x3678FF1F,
243 .CP1_fcr0 = (1 << FCR0_F64) | (1 << FCR0_L) | (1 << FCR0_W) |
244 (1 << FCR0_D) | (1 << FCR0_S) | (0x93 << FCR0_PRID),
245 .CP1_fcr31 = 0,
246 .CP1_fcr31_rw_bitmask = 0xFF83FFFF,
247 .SEGBITS = 32,
248 .PABITS = 32,
249 .insn_flags = CPU_MIPS32R2 | ASE_MIPS16,
250 .mmu_type = MMU_TYPE_R4000,
251 },
252 {
253 .name = "34Kf",
254 .CP0_PRid = 0x00019500,
255 .CP0_Config0 = MIPS_CONFIG0 | (0x1 << CP0C0_AR) |
256 (MMU_TYPE_R4000 << CP0C0_MT),
257 .CP0_Config1 = MIPS_CONFIG1 | (1 << CP0C1_FP) | (15 << CP0C1_MMU) |
258 (0 << CP0C1_IS) | (3 << CP0C1_IL) | (1 << CP0C1_IA) |
259 (0 << CP0C1_DS) | (3 << CP0C1_DL) | (1 << CP0C1_DA) |
260 (1 << CP0C1_CA),
261 .CP0_Config2 = MIPS_CONFIG2,
262 .CP0_Config3 = MIPS_CONFIG3 | (1 << CP0C3_VInt) | (1 << CP0C3_MT) |
263 (1 << CP0C3_DSPP),
264 .CP0_LLAddr_rw_bitmask = 0,
265 .CP0_LLAddr_shift = 0,
266 .SYNCI_Step = 32,
267 .CCRes = 2,
268 .CP0_Status_rw_bitmask = 0x3778FF1F,
269 .CP0_TCStatus_rw_bitmask = (0 << CP0TCSt_TCU3) | (0 << CP0TCSt_TCU2) |
270 (1 << CP0TCSt_TCU1) | (1 << CP0TCSt_TCU0) |
271 (0 << CP0TCSt_TMX) | (1 << CP0TCSt_DT) |
272 (1 << CP0TCSt_DA) | (1 << CP0TCSt_A) |
273 (0x3 << CP0TCSt_TKSU) | (1 << CP0TCSt_IXMT) |
274 (0xff << CP0TCSt_TASID),
275 .CP1_fcr0 = (1 << FCR0_F64) | (1 << FCR0_L) | (1 << FCR0_W) |
276 (1 << FCR0_D) | (1 << FCR0_S) | (0x95 << FCR0_PRID),
277 .CP1_fcr31 = 0,
278 .CP1_fcr31_rw_bitmask = 0xFF83FFFF,
279 .CP0_SRSCtl = (0xf << CP0SRSCtl_HSS),
280 .CP0_SRSConf0_rw_bitmask = 0x3fffffff,
281 .CP0_SRSConf0 = (1U << CP0SRSC0_M) | (0x3fe << CP0SRSC0_SRS3) |
282 (0x3fe << CP0SRSC0_SRS2) | (0x3fe << CP0SRSC0_SRS1),
283 .CP0_SRSConf1_rw_bitmask = 0x3fffffff,
284 .CP0_SRSConf1 = (1U << CP0SRSC1_M) | (0x3fe << CP0SRSC1_SRS6) |
285 (0x3fe << CP0SRSC1_SRS5) | (0x3fe << CP0SRSC1_SRS4),
286 .CP0_SRSConf2_rw_bitmask = 0x3fffffff,
287 .CP0_SRSConf2 = (1U << CP0SRSC2_M) | (0x3fe << CP0SRSC2_SRS9) |
288 (0x3fe << CP0SRSC2_SRS8) | (0x3fe << CP0SRSC2_SRS7),
289 .CP0_SRSConf3_rw_bitmask = 0x3fffffff,
290 .CP0_SRSConf3 = (1U << CP0SRSC3_M) | (0x3fe << CP0SRSC3_SRS12) |
291 (0x3fe << CP0SRSC3_SRS11) | (0x3fe << CP0SRSC3_SRS10),
292 .CP0_SRSConf4_rw_bitmask = 0x3fffffff,
293 .CP0_SRSConf4 = (0x3fe << CP0SRSC4_SRS15) |
294 (0x3fe << CP0SRSC4_SRS14) | (0x3fe << CP0SRSC4_SRS13),
295 .SEGBITS = 32,
296 .PABITS = 32,
297 .insn_flags = CPU_MIPS32R2 | ASE_MIPS16 | ASE_DSP | ASE_MT,
298 .mmu_type = MMU_TYPE_R4000,
299 },
300 {
301 .name = "74Kf",
302 .CP0_PRid = 0x00019700,
303 .CP0_Config0 = MIPS_CONFIG0 | (0x1 << CP0C0_AR) |
304 (MMU_TYPE_R4000 << CP0C0_MT),
305 .CP0_Config1 = MIPS_CONFIG1 | (1 << CP0C1_FP) | (15 << CP0C1_MMU) |
306 (0 << CP0C1_IS) | (3 << CP0C1_IL) | (1 << CP0C1_IA) |
307 (0 << CP0C1_DS) | (3 << CP0C1_DL) | (1 << CP0C1_DA) |
308 (1 << CP0C1_CA),
309 .CP0_Config2 = MIPS_CONFIG2,
310 .CP0_Config3 = MIPS_CONFIG3 | (1 << CP0C3_DSP2P) | (1 << CP0C3_DSPP) |
311 (1 << CP0C3_VInt),
312 .CP0_LLAddr_rw_bitmask = 0,
313 .CP0_LLAddr_shift = 4,
314 .SYNCI_Step = 32,
315 .CCRes = 2,
316 .CP0_Status_rw_bitmask = 0x3778FF1F,
317 .CP1_fcr0 = (1 << FCR0_F64) | (1 << FCR0_L) | (1 << FCR0_W) |
318 (1 << FCR0_D) | (1 << FCR0_S) | (0x93 << FCR0_PRID),
319 .CP1_fcr31 = 0,
320 .CP1_fcr31_rw_bitmask = 0xFF83FFFF,
321 .SEGBITS = 32,
322 .PABITS = 32,
323 .insn_flags = CPU_MIPS32R2 | ASE_MIPS16 | ASE_DSP | ASE_DSP_R2,
324 .mmu_type = MMU_TYPE_R4000,
325 },
326 {
327 .name = "M14K",
328 .CP0_PRid = 0x00019b00,
329 /* Config1 implemented, fixed mapping MMU,
330 no virtual icache, uncached coherency. */
331 .CP0_Config0 = MIPS_CONFIG0 | (0x2 << CP0C0_KU) | (0x2 << CP0C0_K23) |
332 (0x1 << CP0C0_AR) | (MMU_TYPE_FMT << CP0C0_MT),
333 .CP0_Config1 = MIPS_CONFIG1,
334 .CP0_Config2 = MIPS_CONFIG2,
335 .CP0_Config3 = MIPS_CONFIG3 | (0x2 << CP0C3_ISA) | (1 << CP0C3_VInt),
336 .CP0_LLAddr_rw_bitmask = 0,
337 .CP0_LLAddr_shift = 4,
338 .SYNCI_Step = 32,
339 .CCRes = 2,
340 .CP0_Status_rw_bitmask = 0x1258FF17,
341 .SEGBITS = 32,
342 .PABITS = 32,
343 .insn_flags = CPU_MIPS32R2 | ASE_MICROMIPS,
344 .mmu_type = MMU_TYPE_FMT,
345 },
346 {
347 .name = "M14Kc",
348 /* This is the TLB-based MMU core. */
349 .CP0_PRid = 0x00019c00,
350 .CP0_Config0 = MIPS_CONFIG0 | (0x1 << CP0C0_AR) |
351 (MMU_TYPE_R4000 << CP0C0_MT),
352 .CP0_Config1 = MIPS_CONFIG1 | (15 << CP0C1_MMU) |
353 (0 << CP0C1_IS) | (3 << CP0C1_IL) | (1 << CP0C1_IA) |
354 (0 << CP0C1_DS) | (3 << CP0C1_DL) | (1 << CP0C1_DA),
355 .CP0_Config2 = MIPS_CONFIG2,
356 .CP0_Config3 = MIPS_CONFIG3 | (0x2 << CP0C3_ISA) | (0 << CP0C3_VInt),
357 .CP0_LLAddr_rw_bitmask = 0,
358 .CP0_LLAddr_shift = 4,
359 .SYNCI_Step = 32,
360 .CCRes = 2,
361 .CP0_Status_rw_bitmask = 0x1278FF17,
362 .SEGBITS = 32,
363 .PABITS = 32,
364 .insn_flags = CPU_MIPS32R2 | ASE_MICROMIPS,
365 .mmu_type = MMU_TYPE_R4000,
366 },
367 {
368 /* FIXME:
369 * Config3: CMGCR, PW, VZ, CTXTC, CDMM, TL
370 * Config4: MMUExtDef
371 * Config5: MRP
372 * FIR(FCR0): Has2008
373 * */
374 .name = "P5600",
375 .CP0_PRid = 0x0001A800,
376 .CP0_Config0 = MIPS_CONFIG0 | (1 << CP0C0_MM) | (1 << CP0C0_AR) |
377 (MMU_TYPE_R4000 << CP0C0_MT),
378 .CP0_Config1 = MIPS_CONFIG1 | (0x3F << CP0C1_MMU) |
379 (2 << CP0C1_IS) | (4 << CP0C1_IL) | (3 << CP0C1_IA) |
380 (2 << CP0C1_DS) | (4 << CP0C1_DL) | (3 << CP0C1_DA) |
381 (1 << CP0C1_PC) | (1 << CP0C1_FP),
382 .CP0_Config2 = MIPS_CONFIG2,
383 .CP0_Config3 = MIPS_CONFIG3 | (1U << CP0C3_M) | (1 << CP0C3_MSAP) |
384 (1 << CP0C3_BP) | (1 << CP0C3_BI) | (1 << CP0C3_SC) |
385 (1 << CP0C3_ULRI) | (1 << CP0C3_RXI) | (1 << CP0C3_LPA) |
386 (1 << CP0C3_VInt),
387 .CP0_Config4 = MIPS_CONFIG4 | (1U << CP0C4_M) | (2 << CP0C4_IE) |
388 (0x1c << CP0C4_KScrExist),
389 .CP0_Config4_rw_bitmask = 0,
390 .CP0_Config5 = MIPS_CONFIG5 | (1 << CP0C5_EVA) | (1 << CP0C5_MVH) |
391 (1 << CP0C5_LLB) | (1 << CP0C5_MRP),
392 .CP0_Config5_rw_bitmask = (1 << CP0C5_K) | (1 << CP0C5_CV) |
393 (1 << CP0C5_MSAEn) | (1 << CP0C5_UFE) |
394 (1 << CP0C5_FRE) | (1 << CP0C5_UFR),
395 .CP0_LLAddr_rw_bitmask = 0,
396 .CP0_LLAddr_shift = 0,
397 .SYNCI_Step = 32,
398 .CCRes = 2,
399 .CP0_Status_rw_bitmask = 0x3C68FF1F,
400 .CP0_PageGrain_rw_bitmask = (1U << CP0PG_RIE) | (1 << CP0PG_XIE) |
401 (1 << CP0PG_ELPA) | (1 << CP0PG_IEC),
402 .CP0_EBaseWG_rw_bitmask = (1 << CP0EBase_WG),
403 .CP1_fcr0 = (1 << FCR0_FREP) | (1 << FCR0_UFRP) | (1 << FCR0_HAS2008) |
404 (1 << FCR0_F64) | (1 << FCR0_L) | (1 << FCR0_W) |
405 (1 << FCR0_D) | (1 << FCR0_S) | (0x03 << FCR0_PRID),
406 .CP1_fcr31 = (1 << FCR31_ABS2008) | (1 << FCR31_NAN2008),
407 .CP1_fcr31_rw_bitmask = 0xFF83FFFF,
408 .SEGBITS = 32,
409 .PABITS = 40,
410 .insn_flags = CPU_MIPS32R5 | ASE_MSA,
411 .mmu_type = MMU_TYPE_R4000,
412 },
413 {
414 /* A generic CPU supporting MIPS32 Release 6 ISA.
415 FIXME: Support IEEE 754-2008 FP.
416 Eventually this should be replaced by a real CPU model. */
417 .name = "mips32r6-generic",
418 .CP0_PRid = 0x00010000,
419 .CP0_Config0 = MIPS_CONFIG0 | (0x2 << CP0C0_AR) |
420 (MMU_TYPE_R4000 << CP0C0_MT),
421 .CP0_Config1 = MIPS_CONFIG1 | (1 << CP0C1_FP) | (31 << CP0C1_MMU) |
422 (2 << CP0C1_IS) | (4 << CP0C1_IL) | (3 << CP0C1_IA) |
423 (2 << CP0C1_DS) | (4 << CP0C1_DL) | (3 << CP0C1_DA) |
424 (0 << CP0C1_PC) | (1 << CP0C1_WR) | (1 << CP0C1_EP),
425 .CP0_Config2 = MIPS_CONFIG2,
426 .CP0_Config3 = MIPS_CONFIG3 | (1 << CP0C3_BP) | (1 << CP0C3_BI) |
427 (2 << CP0C3_ISA) | (1 << CP0C3_ULRI) |
428 (1 << CP0C3_RXI) | (1U << CP0C3_M),
429 .CP0_Config4 = MIPS_CONFIG4 | (0xfc << CP0C4_KScrExist) |
430 (3 << CP0C4_IE) | (1U << CP0C4_M),
431 .CP0_Config5 = MIPS_CONFIG5 | (1 << CP0C5_XNP) | (1 << CP0C5_LLB),
432 .CP0_Config5_rw_bitmask = (1 << CP0C5_SBRI) | (1 << CP0C5_FRE) |
433 (1 << CP0C5_UFE),
434 .CP0_LLAddr_rw_bitmask = 0,
435 .CP0_LLAddr_shift = 0,
436 .SYNCI_Step = 32,
437 .CCRes = 2,
438 .CP0_Status_rw_bitmask = 0x3058FF1F,
439 .CP0_PageGrain = (1 << CP0PG_IEC) | (1 << CP0PG_XIE) |
440 (1U << CP0PG_RIE),
441 .CP0_PageGrain_rw_bitmask = 0,
442 .CP1_fcr0 = (1 << FCR0_FREP) | (1 << FCR0_HAS2008) | (1 << FCR0_F64) |
443 (1 << FCR0_L) | (1 << FCR0_W) | (1 << FCR0_D) |
444 (1 << FCR0_S) | (0x00 << FCR0_PRID) | (0x0 << FCR0_REV),
445 .CP1_fcr31 = (1 << FCR31_ABS2008) | (1 << FCR31_NAN2008),
446 .CP1_fcr31_rw_bitmask = 0x0103FFFF,
447 .SEGBITS = 32,
448 .PABITS = 32,
449 .insn_flags = CPU_MIPS32R6 | ASE_MICROMIPS,
450 .mmu_type = MMU_TYPE_R4000,
451 },
452 {
453 .name = "I7200",
454 .CP0_PRid = 0x00010000,
455 .CP0_Config0 = MIPS_CONFIG0 | (1 << CP0C0_MM) | (0x2 << CP0C0_AR) |
456 (MMU_TYPE_R4000 << CP0C0_MT),
457 .CP0_Config1 = (1U << CP0C1_M) | (15 << CP0C1_MMU) | (2 << CP0C1_IS) |
458 (4 << CP0C1_IL) | (3 << CP0C1_IA) | (2 << CP0C1_DS) |
459 (4 << CP0C1_DL) | (3 << CP0C1_DA) | (1 << CP0C1_PC) |
460 (1 << CP0C1_EP),
461 .CP0_Config2 = MIPS_CONFIG2,
462 .CP0_Config3 = MIPS_CONFIG3 | (1U << CP0C3_M) | (1 << CP0C3_CMGCR) |
463 (1 << CP0C3_BI) | (1 << CP0C3_SC) | (3 << CP0C3_MMAR) |
464 (1 << CP0C3_ISA_ON_EXC) | (1 << CP0C3_ISA) |
465 (1 << CP0C3_ULRI) | (1 << CP0C3_RXI) |
466 (1 << CP0C3_DSP2P) | (1 << CP0C3_DSPP) |
467 (1 << CP0C3_CTXTC) | (1 << CP0C3_VInt) |
468 (1 << CP0C3_CDMM) | (1 << CP0C3_MT) | (1 << CP0C3_TL),
469 .CP0_Config4 = MIPS_CONFIG4 | (0xfc << CP0C4_KScrExist) |
470 (2 << CP0C4_IE) | (1U << CP0C4_M),
471 .CP0_Config5 = MIPS_CONFIG5 | (1 << CP0C5_MVH) | (1 << CP0C5_LLB),
472 .CP0_Config5_rw_bitmask = (1 << CP0C5_SBRI) | (1 << CP0C5_FRE) |
473 (1 << CP0C5_UFE),
474 .CP0_LLAddr_rw_bitmask = 0,
475 .CP0_LLAddr_shift = 0,
476 .SYNCI_Step = 32,
477 .CCRes = 2,
478 .CP0_Status_rw_bitmask = 0x3158FF1F,
479 .CP0_PageGrain = (1 << CP0PG_IEC) | (1 << CP0PG_XIE) |
480 (1U << CP0PG_RIE),
481 .CP0_PageGrain_rw_bitmask = 0,
482 .CP1_fcr0 = (1 << FCR0_FREP) | (1 << FCR0_HAS2008) | (1 << FCR0_F64) |
483 (1 << FCR0_L) | (1 << FCR0_W) | (1 << FCR0_D) |
484 (1 << FCR0_S) | (0x02 << FCR0_PRID) | (0x0 << FCR0_REV),
485 .CP1_fcr31 = (1 << FCR31_ABS2008) | (1 << FCR31_NAN2008),
486 .SEGBITS = 32,
487 .PABITS = 32,
488 .insn_flags = CPU_NANOMIPS32 | ASE_DSP | ASE_DSP_R2 | ASE_DSP_R3 |
489 ASE_MT,
490 .mmu_type = MMU_TYPE_R4000,
491 },
492 #if defined(TARGET_MIPS64)
493 // 8 byte counter for CPU revision. Bump this every time there is major incompatible change
494 // so that we can print a warning when booting CheriBSD with a too old QEMU
495 #define CHERI_PROCESSOR_REVISION_COUNTER 0x5
496 // Revision 1: initial QEMU-specific processor ID (around ISA v5 or v6)
497 // Revision 2: ISA v7 (including CNULL and special-purpose CHERI registers)
498 // Revision 3: ISA v7 + bugfixes + CCall without delay slot
499 // Revision 4: Working CRAM/CRRL
500 // - No more delay slot in $pcc
501 // - Target $pcc permissions + range are now checked on jump rater than at
502 // the target which avoids unrepresentable $pcc
503 // - Clang now emits csetboundsimmediate with > 1024 and previous versions of
504 // QEMU would interpret that as a signed number, cast it to uint64_t and
505 // give a length violation. This avoids surprising crashes at runtime
506 // - Tons of branch-delay slot bugs
507 // Revision 5:
508 // - Capability compares no longer include tag bit
509 // - Working sentry caps
510 // - CGetPCCIncOffset/CGetPCCSetAddr
511 #define CHERI_PROCESSOR_ID 0x0f << 16 | 0x04 << 8 | CHERI_PROCESSOR_REVISION_COUNTER
512
513 {
514 .name = "R4000",
515 #if defined(TARGET_CHERI)
516 .CP0_PRid = CHERI_PROCESSOR_ID,
517 #else
518 .CP0_PRid = 0x00000400,
519 #endif
520 /* No L2 cache, icache size 8k, dcache size 8k, uncached coherency. */
521 .CP0_Config0 = (1 << 17) | (0x1 << 9) | (0x1 << 6) | (0x2 << CP0C0_K0),
522 /* Note: Config1 is only used internally, the R4000 has only Config0. */
523 #if defined(TARGET_CHERI)
524 .CP0_Config1 = (1 << CP0C1_FP) | (47 << CP0C1_MMU) | 0x40,
525 #else
526 .CP0_Config1 = (1 << CP0C1_FP) | (47 << CP0C1_MMU),
527 #endif
528 .CP0_LLAddr_rw_bitmask = 0xFFFFFFFF,
529 #if defined(TARGET_CHERI)
530 .CP0_LLAddr_shift = 0,
531 #else
532 .CP0_LLAddr_shift = 4,
533 #endif
534 .SYNCI_Step = 16,
535 .CCRes = 2,
536 #if defined(TARGET_CHERI)
537 .CP0_Status_rw_bitmask = 0x7678FFFF,
538 #else
539 .CP0_Status_rw_bitmask = 0x3678FFFF,
540 #endif
541 /* The R4000 has a full 64bit FPU but doesn't use the fcr0 bits. */
542 .CP1_fcr0 = (0x5 << FCR0_PRID) | (0x0 << FCR0_REV),
543 .CP1_fcr31 = 0,
544 #if defined(TARGET_CHERI)
545 .CP1_fcr31_rw_bitmask = 0x018FFFFF,
546 #else
547 .CP1_fcr31_rw_bitmask = 0x0183FFFF,
548 #endif
549 .SEGBITS = 40,
550 #if defined(TARGET_CHERI)
551 .PABITS = 40,
552 #else
553 .PABITS = 36,
554 #endif
555 .insn_flags = CPU_MIPS3,
556 .mmu_type = MMU_TYPE_R4000,
557 },
558 {
559 .name = "VR5432",
560 .CP0_PRid = 0x00005400,
561 /* No L2 cache, icache size 8k, dcache size 8k, uncached coherency. */
562 .CP0_Config0 = (1 << 17) | (0x1 << 9) | (0x1 << 6) | (0x2 << CP0C0_K0),
563 .CP0_Config1 = (1 << CP0C1_FP) | (47 << CP0C1_MMU),
564 .CP0_LLAddr_rw_bitmask = 0xFFFFFFFFL,
565 .CP0_LLAddr_shift = 4,
566 .SYNCI_Step = 16,
567 .CCRes = 2,
568 .CP0_Status_rw_bitmask = 0x3678FFFF,
569 /* The VR5432 has a full 64bit FPU but doesn't use the fcr0 bits. */
570 .CP1_fcr0 = (0x54 << FCR0_PRID) | (0x0 << FCR0_REV),
571 .CP1_fcr31 = 0,
572 .CP1_fcr31_rw_bitmask = 0xFF83FFFF,
573 .SEGBITS = 40,
574 .PABITS = 32,
575 .insn_flags = CPU_VR54XX,
576 .mmu_type = MMU_TYPE_R4000,
577 },
578 {
579 .name = "5Kc",
580 .CP0_PRid = 0x00018100,
581 .CP0_Config0 = MIPS_CONFIG0 | (0x2 << CP0C0_AT) |
582 (MMU_TYPE_R4000 << CP0C0_MT),
583 .CP0_Config1 = MIPS_CONFIG1 | (31 << CP0C1_MMU) |
584 (1 << CP0C1_IS) | (4 << CP0C1_IL) | (1 << CP0C1_IA) |
585 (1 << CP0C1_DS) | (4 << CP0C1_DL) | (1 << CP0C1_DA) |
586 (1 << CP0C1_PC) | (1 << CP0C1_WR) | (1 << CP0C1_EP),
587 .CP0_Config2 = MIPS_CONFIG2,
588 .CP0_Config3 = MIPS_CONFIG3,
589 .CP0_LLAddr_rw_bitmask = 0,
590 .CP0_LLAddr_shift = 4,
591 .SYNCI_Step = 32,
592 .CCRes = 2,
593 .CP0_Status_rw_bitmask = 0x12F8FFFF,
594 .SEGBITS = 42,
595 .PABITS = 36,
596 .insn_flags = CPU_MIPS64,
597 .mmu_type = MMU_TYPE_R4000,
598 },
599 {
600 .name = "5Kf",
601 #if defined(TARGET_CHERI)
602 /* cpu vendor = 0x0f, cpu impl = 0x04, cpu rev = 0x01 */
603 .CP0_PRid = CHERI_PROCESSOR_ID,
604 #else /* ! TARGET_CHERI */
605 .CP0_PRid = 0x00018100,
606 #endif /* ! TARGET_CHERI */
607 .CP0_Config0 = MIPS_CONFIG0 | (0x2 << CP0C0_AT) |
608 (MMU_TYPE_R4000 << CP0C0_MT),
609 #if defined(TARGET_CHERI)
610 .CP0_Config1 = MIPS_CONFIG1 | (1 << CP0C1_FP) | (31 << CP0C1_MMU) |
611 (1 << CP0C1_IS) | (4 << CP0C1_IL) | (1 << CP0C1_IA) |
612 (1 << CP0C1_DS) | (4 << CP0C1_DL) | (1 << CP0C1_DA) |
613 (1 << CP0C1_PC) | (1 << CP0C1_WR) | (1 << CP0C1_EP) |
614 0x40,
615 #else /* ! TARGET_CHERI */
616 .CP0_Config1 = MIPS_CONFIG1 | (1 << CP0C1_FP) | (31 << CP0C1_MMU) |
617 (1 << CP0C1_IS) | (4 << CP0C1_IL) | (1 << CP0C1_IA) |
618 (1 << CP0C1_DS) | (4 << CP0C1_DL) | (1 << CP0C1_DA) |
619 (1 << CP0C1_PC) | (1 << CP0C1_WR) | (1 << CP0C1_EP),
620 #endif /* ! TARGET_CHERI */
621 .CP0_Config2 = MIPS_CONFIG2,
622 #if defined(TARGET_CHERI)
623 .CP0_Config3 = MIPS_CONFIG3 | (1 << CP0C3_ULRI) | (1 << CP0C3_BI) |
624 (1 << CP0C3_BP),
625 #else
626 .CP0_Config3 = MIPS_CONFIG3,
627 #endif
628 .CP0_LLAddr_rw_bitmask = 0,
629 #if defined(TARGET_CHERI)
630 .CP0_LLAddr_shift = 0,
631 #else
632 .CP0_LLAddr_shift = 4,
633 #endif
634 .SYNCI_Step = 32,
635 .CCRes = 2,
636 #if defined(TARGET_CHERI)
637 .CP0_Status_rw_bitmask = 0x76F8FFFF,
638 #else
639 .CP0_Status_rw_bitmask = 0x36F8FFFF,
640 #endif
641 /* The 5Kf has F64 / L / W but doesn't use the fcr0 bits. */
642 .CP1_fcr0 = (1 << FCR0_D) | (1 << FCR0_S) |
643 (0x81 << FCR0_PRID) | (0x0 << FCR0_REV),
644 .CP1_fcr31 = 0,
645 #if defined(TARGET_CHERI)
646 .CP1_fcr31_rw_bitmask = 0xFF8FFFFF,
647 #else
648 .CP1_fcr31_rw_bitmask = 0xFF83FFFF,
649 #endif
650 .SEGBITS = 42,
651 .PABITS = 36,
652 #if defined(TARGET_CHERI)
653 .insn_flags = CPU_MIPS64R2,
654 #else
655 .insn_flags = CPU_MIPS64,
656 #endif
657 .mmu_type = MMU_TYPE_R4000,
658 },
659 {
660 .name = "BERI",
661 /* cpu vendor = 0x0f, cpu impl = 0x04, cpu rev = 0x01 */
662 .CP0_PRid = CHERI_PROCESSOR_ID,
663 .CP0_Config0 = MIPS_CONFIG0 | (0x2 << CP0C0_AT) |
664 (MMU_TYPE_R4000 << CP0C0_MT),
665 .CP0_Config1 = MIPS_CONFIG1 |
666 #if defined(TARGET_CHERI)
667 (1 << CP0C1_C2) |
668 #endif /* ! TARGET_CHERI */
669 (1 << CP0C1_FP) | (31 << CP0C1_MMU) |
670 (1 << CP0C1_IS) | (4 << CP0C1_IL) | (1 << CP0C1_IA) |
671 (1 << CP0C1_DS) | (4 << CP0C1_DL) | (1 << CP0C1_DA) |
672 (1 << CP0C1_PC) | (1 << CP0C1_WR) | (1 << CP0C1_EP),
673 .CP0_Config2 = MIPS_CONFIG2,
674 .CP0_Config3 = MIPS_CONFIG3 | (1 << CP0C3_ULRI) | (1 << CP0C3_BI) |
675 (1 << CP0C3_BP) | (1 << CP0C3_LPA),
676 .CP0_LLAddr_rw_bitmask = 0,
677 .CP0_LLAddr_shift = 0,
678 .SYNCI_Step = 32,
679 .CCRes = 2,
680 #if defined(TARGET_CHERI)
681 .CP0_Status_rw_bitmask = 0x76F8FFFF,
682 #else
683 .CP0_Status_rw_bitmask = 0x36F8FFFF,
684 #endif
685 /* The 5Kf has F64 / L / W but doesn't use the fcr0 bits. */
686 .CP1_fcr0 = (1 << FCR0_D) | (1 << FCR0_S) |
687 (0x81 << FCR0_PRID) | (0x0 << FCR0_REV),
688 .CP1_fcr31 = 0,
689 .CP1_fcr31_rw_bitmask = 0xFF8FFFFF,
690 .SEGBITS = 42,
691 .PABITS = 40,
692 /* These flags are needed in addition to Config3.LPA for > 36 bits PA */
693 .CP0_PageGrain = (1 << CP0PG_ELPA),
694 .CP0_PageGrain_rw_bitmask = (1 << CP0PG_ELPA), /* TODO: should it be R/W? */
695 .insn_flags = CPU_MIPS64R2,
696 .mmu_type = MMU_TYPE_R4000,
697 },
698 {
699 .name = "20Kc",
700 /* We emulate a later version of the 20Kc, earlier ones had a broken
701 WAIT instruction. */
702 .CP0_PRid = 0x000182a0,
703 .CP0_Config0 = MIPS_CONFIG0 | (0x2 << CP0C0_AT) |
704 (MMU_TYPE_R4000 << CP0C0_MT) | (1 << CP0C0_VI),
705 .CP0_Config1 = MIPS_CONFIG1 | (1 << CP0C1_FP) | (47 << CP0C1_MMU) |
706 (2 << CP0C1_IS) | (4 << CP0C1_IL) | (3 << CP0C1_IA) |
707 (2 << CP0C1_DS) | (4 << CP0C1_DL) | (3 << CP0C1_DA) |
708 (1 << CP0C1_PC) | (1 << CP0C1_WR) | (1 << CP0C1_EP),
709 .CP0_Config2 = MIPS_CONFIG2,
710 .CP0_Config3 = MIPS_CONFIG3,
711 .CP0_LLAddr_rw_bitmask = 0,
712 .CP0_LLAddr_shift = 0,
713 .SYNCI_Step = 32,
714 .CCRes = 1,
715 .CP0_Status_rw_bitmask = 0x36FBFFFF,
716 /* The 20Kc has F64 / L / W but doesn't use the fcr0 bits. */
717 .CP1_fcr0 = (1 << FCR0_3D) | (1 << FCR0_PS) |
718 (1 << FCR0_D) | (1 << FCR0_S) |
719 (0x82 << FCR0_PRID) | (0x0 << FCR0_REV),
720 .CP1_fcr31 = 0,
721 .CP1_fcr31_rw_bitmask = 0xFF83FFFF,
722 .SEGBITS = 40,
723 .PABITS = 36,
724 .insn_flags = CPU_MIPS64 | ASE_MIPS3D,
725 .mmu_type = MMU_TYPE_R4000,
726 },
727 {
728 /* A generic CPU providing MIPS64 Release 2 features.
729 FIXME: Eventually this should be replaced by a real CPU model. */
730 .name = "MIPS64R2-generic",
731 .CP0_PRid = 0x00010000,
732 .CP0_Config0 = MIPS_CONFIG0 | (0x1 << CP0C0_AR) | (0x2 << CP0C0_AT) |
733 (MMU_TYPE_R4000 << CP0C0_MT),
734 .CP0_Config1 = MIPS_CONFIG1 | (1 << CP0C1_FP) | (63 << CP0C1_MMU) |
735 (2 << CP0C1_IS) | (4 << CP0C1_IL) | (3 << CP0C1_IA) |
736 (2 << CP0C1_DS) | (4 << CP0C1_DL) | (3 << CP0C1_DA) |
737 (1 << CP0C1_PC) | (1 << CP0C1_WR) | (1 << CP0C1_EP),
738 .CP0_Config2 = MIPS_CONFIG2,
739 .CP0_Config3 = MIPS_CONFIG3 | (1 << CP0C3_LPA),
740 .CP0_LLAddr_rw_bitmask = 0,
741 .CP0_LLAddr_shift = 0,
742 .SYNCI_Step = 32,
743 .CCRes = 2,
744 .CP0_Status_rw_bitmask = 0x36FBFFFF,
745 .CP0_EBaseWG_rw_bitmask = (1 << CP0EBase_WG),
746 .CP1_fcr0 = (1 << FCR0_F64) | (1 << FCR0_3D) | (1 << FCR0_PS) |
747 (1 << FCR0_L) | (1 << FCR0_W) | (1 << FCR0_D) |
748 (1 << FCR0_S) | (0x00 << FCR0_PRID) | (0x0 << FCR0_REV),
749 .CP1_fcr31 = 0,
750 .CP1_fcr31_rw_bitmask = 0xFF83FFFF,
751 .SEGBITS = 42,
752 .PABITS = 36,
753 .insn_flags = CPU_MIPS64R2 | ASE_MIPS3D,
754 .mmu_type = MMU_TYPE_R4000,
755 },
756 {
757 .name = "5KEc",
758 .CP0_PRid = 0x00018900,
759 .CP0_Config0 = MIPS_CONFIG0 | (0x1 << CP0C0_AR) | (0x2 << CP0C0_AT) |
760 (MMU_TYPE_R4000 << CP0C0_MT),
761 .CP0_Config1 = MIPS_CONFIG1 | (31 << CP0C1_MMU) |
762 (1 << CP0C1_IS) | (4 << CP0C1_IL) | (1 << CP0C1_IA) |
763 (1 << CP0C1_DS) | (4 << CP0C1_DL) | (1 << CP0C1_DA) |
764 (1 << CP0C1_PC) | (1 << CP0C1_WR) | (1 << CP0C1_EP),
765 .CP0_Config2 = MIPS_CONFIG2,
766 .CP0_Config3 = MIPS_CONFIG3,
767 .CP0_LLAddr_rw_bitmask = 0,
768 .CP0_LLAddr_shift = 4,
769 .SYNCI_Step = 32,
770 .CCRes = 2,
771 .CP0_Status_rw_bitmask = 0x12F8FFFF,
772 .SEGBITS = 42,
773 .PABITS = 36,
774 .insn_flags = CPU_MIPS64R2,
775 .mmu_type = MMU_TYPE_R4000,
776 },
777 {
778 .name = "5KEf",
779 .CP0_PRid = 0x00018900,
780 .CP0_Config0 = MIPS_CONFIG0 | (0x1 << CP0C0_AR) | (0x2 << CP0C0_AT) |
781 (MMU_TYPE_R4000 << CP0C0_MT),
782 .CP0_Config1 = MIPS_CONFIG1 | (1 << CP0C1_FP) | (31 << CP0C1_MMU) |
783 (1 << CP0C1_IS) | (4 << CP0C1_IL) | (1 << CP0C1_IA) |
784 (1 << CP0C1_DS) | (4 << CP0C1_DL) | (1 << CP0C1_DA) |
785 (1 << CP0C1_PC) | (1 << CP0C1_WR) | (1 << CP0C1_EP),
786 .CP0_Config2 = MIPS_CONFIG2,
787 .CP0_Config3 = MIPS_CONFIG3,
788 .CP0_LLAddr_rw_bitmask = 0,
789 .CP0_LLAddr_shift = 4,
790 .SYNCI_Step = 32,
791 .CCRes = 2,
792 .CP0_Status_rw_bitmask = 0x36F8FFFF,
793 .CP1_fcr0 = (1 << FCR0_F64) | (1 << FCR0_L) | (1 << FCR0_W) |
794 (1 << FCR0_D) | (1 << FCR0_S) |
795 (0x89 << FCR0_PRID) | (0x0 << FCR0_REV),
796 .SEGBITS = 42,
797 .PABITS = 36,
798 .insn_flags = CPU_MIPS64R2,
799 .mmu_type = MMU_TYPE_R4000,
800 },
801 {
802 .name = "I6400",
803 .CP0_PRid = 0x1A900,
804 .CP0_Config0 = MIPS_CONFIG0 | (0x2 << CP0C0_AR) | (0x2 << CP0C0_AT) |
805 (MMU_TYPE_R4000 << CP0C0_MT),
806 .CP0_Config1 = MIPS_CONFIG1 | (1 << CP0C1_FP) | (15 << CP0C1_MMU) |
807 (2 << CP0C1_IS) | (5 << CP0C1_IL) | (3 << CP0C1_IA) |
808 (2 << CP0C1_DS) | (5 << CP0C1_DL) | (3 << CP0C1_DA) |
809 (0 << CP0C1_PC) | (1 << CP0C1_WR) | (1 << CP0C1_EP),
810 .CP0_Config2 = MIPS_CONFIG2,
811 .CP0_Config3 = MIPS_CONFIG3 | (1U << CP0C3_M) |
812 (1 << CP0C3_CMGCR) | (1 << CP0C3_MSAP) |
813 (1 << CP0C3_BP) | (1 << CP0C3_BI) | (1 << CP0C3_ULRI) |
814 (1 << CP0C3_RXI) | (1 << CP0C3_LPA) | (1 << CP0C3_VInt),
815 .CP0_Config4 = MIPS_CONFIG4 | (1U << CP0C4_M) | (3 << CP0C4_IE) |
816 (1 << CP0C4_AE) | (0xfc << CP0C4_KScrExist),
817 .CP0_Config5 = MIPS_CONFIG5 | (1 << CP0C5_XNP) | (1 << CP0C5_VP) |
818 (1 << CP0C5_LLB) | (1 << CP0C5_MRP),
819 .CP0_Config5_rw_bitmask = (1 << CP0C5_MSAEn) | (1 << CP0C5_SBRI) |
820 (1 << CP0C5_FRE) | (1 << CP0C5_UFE),
821 .CP0_LLAddr_rw_bitmask = 0,
822 .CP0_LLAddr_shift = 0,
823 .SYNCI_Step = 32,
824 .CCRes = 2,
825 .CP0_Status_rw_bitmask = 0x30D8FFFF,
826 .CP0_PageGrain = (1 << CP0PG_IEC) | (1 << CP0PG_XIE) |
827 (1U << CP0PG_RIE),
828 .CP0_PageGrain_rw_bitmask = (1 << CP0PG_ELPA),
829 .CP0_EBaseWG_rw_bitmask = (1 << CP0EBase_WG),
830 .CP1_fcr0 = (1 << FCR0_FREP) | (1 << FCR0_HAS2008) | (1 << FCR0_F64) |
831 (1 << FCR0_L) | (1 << FCR0_W) | (1 << FCR0_D) |
832 (1 << FCR0_S) | (0x03 << FCR0_PRID) | (0x0 << FCR0_REV),
833 .CP1_fcr31 = (1 << FCR31_ABS2008) | (1 << FCR31_NAN2008),
834 .CP1_fcr31_rw_bitmask = 0x0103FFFF,
835 .MSAIR = 0x03 << MSAIR_ProcID,
836 .SEGBITS = 48,
837 .PABITS = 48,
838 .insn_flags = CPU_MIPS64R6 | ASE_MSA,
839 .mmu_type = MMU_TYPE_R4000,
840 },
841 {
842 .name = "I6500",
843 .CP0_PRid = 0x1B000,
844 .CP0_Config0 = MIPS_CONFIG0 | (0x2 << CP0C0_AR) | (0x2 << CP0C0_AT) |
845 (MMU_TYPE_R4000 << CP0C0_MT),
846 .CP0_Config1 = MIPS_CONFIG1 | (1 << CP0C1_FP) | (15 << CP0C1_MMU) |
847 (2 << CP0C1_IS) | (5 << CP0C1_IL) | (3 << CP0C1_IA) |
848 (2 << CP0C1_DS) | (5 << CP0C1_DL) | (3 << CP0C1_DA) |
849 (0 << CP0C1_PC) | (1 << CP0C1_WR) | (1 << CP0C1_EP),
850 .CP0_Config2 = MIPS_CONFIG2,
851 .CP0_Config3 = MIPS_CONFIG3 | (1U << CP0C3_M) |
852 (1 << CP0C3_CMGCR) | (1 << CP0C3_MSAP) |
853 (1 << CP0C3_BP) | (1 << CP0C3_BI) | (1 << CP0C3_ULRI) |
854 (1 << CP0C3_RXI) | (1 << CP0C3_LPA) | (1 << CP0C3_VInt),
855 .CP0_Config4 = MIPS_CONFIG4 | (1U << CP0C4_M) | (3 << CP0C4_IE) |
856 (1 << CP0C4_AE) | (0xfc << CP0C4_KScrExist),
857 .CP0_Config5 = MIPS_CONFIG5 | (1 << CP0C5_XNP) | (1 << CP0C5_VP) |
858 (1 << CP0C5_LLB) | (1 << CP0C5_MRP),
859 .CP0_Config5_rw_bitmask = (1 << CP0C5_MSAEn) | (1 << CP0C5_SBRI) |
860 (1 << CP0C5_FRE) | (1 << CP0C5_UFE),
861 .CP0_LLAddr_rw_bitmask = 0,
862 .CP0_LLAddr_shift = 0,
863 .SYNCI_Step = 64,
864 .CCRes = 2,
865 .CP0_Status_rw_bitmask = 0x30D8FFFF,
866 .CP0_PageGrain = (1 << CP0PG_IEC) | (1 << CP0PG_XIE) |
867 (1U << CP0PG_RIE),
868 .CP0_PageGrain_rw_bitmask = (1 << CP0PG_ELPA),
869 .CP0_EBaseWG_rw_bitmask = (1 << CP0EBase_WG),
870 .CP1_fcr0 = (1 << FCR0_FREP) | (1 << FCR0_HAS2008) | (1 << FCR0_F64) |
871 (1 << FCR0_L) | (1 << FCR0_W) | (1 << FCR0_D) |
872 (1 << FCR0_S) | (0x03 << FCR0_PRID) | (0x0 << FCR0_REV),
873 .CP1_fcr31 = (1 << FCR31_ABS2008) | (1 << FCR31_NAN2008),
874 .CP1_fcr31_rw_bitmask = 0x0103FFFF,
875 .MSAIR = 0x03 << MSAIR_ProcID,
876 .SEGBITS = 48,
877 .PABITS = 48,
878 .insn_flags = CPU_MIPS64R6 | ASE_MSA,
879 .mmu_type = MMU_TYPE_R4000,
880 },
881 {
882 .name = "Loongson-2E",
883 .CP0_PRid = 0x6302,
884 /* 64KB I-cache and d-cache. 4 way with 32 bit cache line size. */
885 .CP0_Config0 = (0x1<<17) | (0x1<<16) | (0x1<<11) | (0x1<<8) |
886 (0x1<<5) | (0x1<<4) | (0x1<<1),
887 /* Note: Config1 is only used internally,
888 Loongson-2E has only Config0. */
889 .CP0_Config1 = (1 << CP0C1_FP) | (47 << CP0C1_MMU),
890 .SYNCI_Step = 16,
891 .CCRes = 2,
892 .CP0_Status_rw_bitmask = 0x35D0FFFF,
893 .CP1_fcr0 = (0x5 << FCR0_PRID) | (0x1 << FCR0_REV),
894 .CP1_fcr31 = 0,
895 .CP1_fcr31_rw_bitmask = 0xFF83FFFF,
896 .SEGBITS = 40,
897 .PABITS = 40,
898 .insn_flags = CPU_LOONGSON2E,
899 .mmu_type = MMU_TYPE_R4000,
900 },
901 {
902 .name = "Loongson-2F",
903 .CP0_PRid = 0x6303,
904 /* 64KB I-cache and d-cache. 4 way with 32 bit cache line size. */
905 .CP0_Config0 = (0x1<<17) | (0x1<<16) | (0x1<<11) | (0x1<<8) |
906 (0x1<<5) | (0x1<<4) | (0x1<<1),
907 /* Note: Config1 is only used internally,
908 Loongson-2F has only Config0. */
909 .CP0_Config1 = (1 << CP0C1_FP) | (47 << CP0C1_MMU),
910 .SYNCI_Step = 16,
911 .CCRes = 2,
912 .CP0_Status_rw_bitmask = 0xF5D0FF1F, /* Bits 7:5 not writable. */
913 .CP1_fcr0 = (0x5 << FCR0_PRID) | (0x1 << FCR0_REV),
914 .CP1_fcr31 = 0,
915 .CP1_fcr31_rw_bitmask = 0xFF83FFFF,
916 .SEGBITS = 40,
917 .PABITS = 40,
918 .insn_flags = CPU_LOONGSON2F,
919 .mmu_type = MMU_TYPE_R4000,
920 },
921 {
922 /* A generic CPU providing MIPS64 DSP R2 ASE features.
923 FIXME: Eventually this should be replaced by a real CPU model. */
924 .name = "mips64dspr2",
925 .CP0_PRid = 0x00010000,
926 .CP0_Config0 = MIPS_CONFIG0 | (0x1 << CP0C0_AR) | (0x2 << CP0C0_AT) |
927 (MMU_TYPE_R4000 << CP0C0_MT),
928 .CP0_Config1 = MIPS_CONFIG1 | (1 << CP0C1_FP) | (63 << CP0C1_MMU) |
929 (2 << CP0C1_IS) | (4 << CP0C1_IL) | (3 << CP0C1_IA) |
930 (2 << CP0C1_DS) | (4 << CP0C1_DL) | (3 << CP0C1_DA) |
931 (1 << CP0C1_PC) | (1 << CP0C1_WR) | (1 << CP0C1_EP),
932 .CP0_Config2 = MIPS_CONFIG2,
933 .CP0_Config3 = MIPS_CONFIG3 | (1U << CP0C3_M) | (1 << CP0C3_DSP2P) |
934 (1 << CP0C3_DSPP) | (1 << CP0C3_LPA),
935 .CP0_LLAddr_rw_bitmask = 0,
936 .CP0_LLAddr_shift = 0,
937 .SYNCI_Step = 32,
938 .CCRes = 2,
939 .CP0_Status_rw_bitmask = 0x37FBFFFF,
940 .CP1_fcr0 = (1 << FCR0_F64) | (1 << FCR0_3D) | (1 << FCR0_PS) |
941 (1 << FCR0_L) | (1 << FCR0_W) | (1 << FCR0_D) |
942 (1 << FCR0_S) | (0x00 << FCR0_PRID) | (0x0 << FCR0_REV),
943 .CP1_fcr31 = 0,
944 .CP1_fcr31_rw_bitmask = 0xFF83FFFF,
945 .SEGBITS = 42,
946 .PABITS = 36,
947 .insn_flags = CPU_MIPS64R2 | ASE_DSP | ASE_DSP_R2,
948 .mmu_type = MMU_TYPE_R4000,
949 },
950
951 #endif
952 };
953 const int mips_defs_number = ARRAY_SIZE(mips_defs);
954
mips_cpu_list(void)955 void mips_cpu_list(void)
956 {
957 int i;
958
959 for (i = 0; i < ARRAY_SIZE(mips_defs); i++) {
960 qemu_printf("MIPS '%s'\n", mips_defs[i].name);
961 }
962 }
963
964 #ifndef CONFIG_USER_ONLY
no_mmu_init(CPUMIPSState * env,const mips_def_t * def)965 static void no_mmu_init (CPUMIPSState *env, const mips_def_t *def)
966 {
967 env->tlb->nb_tlb = 1;
968 env->tlb->map_address = &no_mmu_map_address;
969 }
970
fixed_mmu_init(CPUMIPSState * env,const mips_def_t * def)971 static void fixed_mmu_init (CPUMIPSState *env, const mips_def_t *def)
972 {
973 env->tlb->nb_tlb = 1;
974 env->tlb->map_address = &fixed_mmu_map_address;
975 }
976
r4k_mmu_init(CPUMIPSState * env,const mips_def_t * def)977 static void r4k_mmu_init (CPUMIPSState *env, const mips_def_t *def)
978 {
979 env->tlb->nb_tlb = 1 + ((def->CP0_Config1 >> CP0C1_MMU) & 63);
980 env->tlb->map_address = &r4k_map_address;
981 env->tlb->helper_tlbwi = r4k_helper_tlbwi;
982 env->tlb->helper_tlbwr = r4k_helper_tlbwr;
983 env->tlb->helper_tlbp = r4k_helper_tlbp;
984 env->tlb->helper_tlbr = r4k_helper_tlbr;
985 env->tlb->helper_tlbinv = r4k_helper_tlbinv;
986 env->tlb->helper_tlbinvf = r4k_helper_tlbinvf;
987 }
988
mmu_init(CPUMIPSState * env,const mips_def_t * def)989 static void mmu_init (CPUMIPSState *env, const mips_def_t *def)
990 {
991 env->tlb = g_malloc0(sizeof(CPUMIPSTLBContext));
992
993 switch (def->mmu_type) {
994 case MMU_TYPE_NONE:
995 no_mmu_init(env, def);
996 break;
997 case MMU_TYPE_R4000:
998 r4k_mmu_init(env, def);
999 break;
1000 case MMU_TYPE_FMT:
1001 fixed_mmu_init(env, def);
1002 break;
1003 case MMU_TYPE_R3000:
1004 case MMU_TYPE_R6000:
1005 case MMU_TYPE_R8000:
1006 default:
1007 cpu_abort(env_cpu(env), "MMU type not supported\n");
1008 }
1009 }
1010 #endif /* CONFIG_USER_ONLY */
1011
fpu_init(CPUMIPSState * env,const mips_def_t * def)1012 static void fpu_init (CPUMIPSState *env, const mips_def_t *def)
1013 {
1014 int i;
1015
1016 for (i = 0; i < MIPS_FPU_MAX; i++)
1017 env->fpus[i].fcr0 = def->CP1_fcr0;
1018
1019 memcpy(&env->active_fpu, &env->fpus[0], sizeof(env->active_fpu));
1020 }
1021
mvp_init(CPUMIPSState * env,const mips_def_t * def)1022 static void mvp_init (CPUMIPSState *env, const mips_def_t *def)
1023 {
1024 env->mvp = g_malloc0(sizeof(CPUMIPSMVPContext));
1025
1026 /* MVPConf1 implemented, TLB sharable, no gating storage support,
1027 programmable cache partitioning implemented, number of allocatable
1028 and sharable TLB entries, MVP has allocatable TCs, 2 VPEs
1029 implemented, 5 TCs implemented. */
1030 env->mvp->CP0_MVPConf0 = (1U << CP0MVPC0_M) | (1 << CP0MVPC0_TLBS) |
1031 (0 << CP0MVPC0_GS) | (1 << CP0MVPC0_PCP) |
1032 // TODO: actually do 2 VPEs.
1033 // (1 << CP0MVPC0_TCA) | (0x1 << CP0MVPC0_PVPE) |
1034 // (0x04 << CP0MVPC0_PTC);
1035 (1 << CP0MVPC0_TCA) | (0x0 << CP0MVPC0_PVPE) |
1036 (0x00 << CP0MVPC0_PTC);
1037 #if !defined(CONFIG_USER_ONLY)
1038 /* Usermode has no TLB support */
1039 env->mvp->CP0_MVPConf0 |= (env->tlb->nb_tlb << CP0MVPC0_PTLBE);
1040 #endif
1041
1042 /* Allocatable CP1 have media extensions, allocatable CP1 have FP support,
1043 no UDI implemented, no CP2 implemented, 1 CP1 implemented. */
1044 env->mvp->CP0_MVPConf1 = (1U << CP0MVPC1_CIM) | (1 << CP0MVPC1_CIF) |
1045 (0x0 << CP0MVPC1_PCX) | (0x0 << CP0MVPC1_PCP2) |
1046 (0x1 << CP0MVPC1_PCP1);
1047 }
1048
msa_reset(CPUMIPSState * env)1049 static void msa_reset(CPUMIPSState *env)
1050 {
1051 #ifdef CONFIG_USER_ONLY
1052 /* MSA access enabled */
1053 env->CP0_Config5 |= 1 << CP0C5_MSAEn;
1054 env->CP0_Status |= (1 << CP0St_CU1) | (1 << CP0St_FR);
1055 #endif
1056
1057 /* MSA CSR:
1058 - non-signaling floating point exception mode off (NX bit is 0)
1059 - Cause, Enables, and Flags are all 0
1060 - round to nearest / ties to even (RM bits are 0) */
1061 env->active_tc.msacsr = 0;
1062
1063 restore_msa_fp_status(env);
1064
1065 /* tininess detected after rounding.*/
1066 set_float_detect_tininess(float_tininess_after_rounding,
1067 &env->active_tc.msa_fp_status);
1068
1069 /* clear float_status exception flags */
1070 set_float_exception_flags(0, &env->active_tc.msa_fp_status);
1071
1072 /* clear float_status nan mode */
1073 set_default_nan_mode(0, &env->active_tc.msa_fp_status);
1074
1075 /* set proper signanling bit meaning ("1" means "quiet") */
1076 set_snan_bit_is_one(0, &env->active_tc.msa_fp_status);
1077 }
1078