]> git.proxmox.com Git - qemu.git/blame - target-mips/translate_init.c
Refactor and enhance break/watchpoint API (Jan Kiszka)
[qemu.git] / target-mips / translate_init.c
CommitLineData
33d68b5f
TS
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, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21
3953d786
TS
22/* CPU / CPU family specific config register values. */
23
6d35524c 24/* Have config1, uncached coherency */
3953d786 25#define MIPS_CONFIG0 \
6d35524c 26 ((1 << CP0C0_M) | (0x2 << CP0C0_K0))
3953d786 27
ae5d8053 28/* Have config2, no coprocessor2 attached, no MDMX support attached,
3953d786
TS
29 no performance counters, watch registers present,
30 no code compression, EJTAG present, no FPU */
31#define MIPS_CONFIG1 \
fcb4a419 32((1 << CP0C1_M) | \
3953d786
TS
33 (0 << CP0C1_C2) | (0 << CP0C1_MD) | (0 << CP0C1_PC) | \
34 (1 << CP0C1_WR) | (0 << CP0C1_CA) | (1 << CP0C1_EP) | \
35 (0 << CP0C1_FP))
36
37/* Have config3, no tertiary/secondary caches implemented */
38#define MIPS_CONFIG2 \
39((1 << CP0C2_M))
40
6d35524c 41/* No config4, no DSP ASE, no large physaddr (PABITS),
3953d786 42 no external interrupt controller, no vectored interupts,
ead9360e 43 no 1kb pages, no SmartMIPS ASE, no trace logic */
3953d786
TS
44#define MIPS_CONFIG3 \
45((0 << CP0C3_M) | (0 << CP0C3_DSPP) | (0 << CP0C3_LPA) | \
46 (0 << CP0C3_VEIC) | (0 << CP0C3_VInt) | (0 << CP0C3_SP) | \
ead9360e 47 (0 << CP0C3_SM) | (0 << CP0C3_TL))
3953d786
TS
48
49/* Define a implementation number of 1.
50 Define a major version 1, minor version 0. */
5a5012ec 51#define MIPS_FCR0 ((0 << FCR0_S) | (0x1 << FCR0_PRID) | (0x10 << FCR0_REV))
3953d786 52
6d35524c
TS
53/* MMU types, the first four entries have the same layout as the
54 CP0C0_MT field. */
55enum mips_mmu_types {
56 MMU_TYPE_NONE,
57 MMU_TYPE_R4000,
58 MMU_TYPE_RESERVED,
59 MMU_TYPE_FMT,
60 MMU_TYPE_R3000,
61 MMU_TYPE_R6000,
62 MMU_TYPE_R8000
63};
64
33d68b5f 65struct mips_def_t {
50366fe9 66 const char *name;
33d68b5f
TS
67 int32_t CP0_PRid;
68 int32_t CP0_Config0;
69 int32_t CP0_Config1;
3953d786
TS
70 int32_t CP0_Config2;
71 int32_t CP0_Config3;
34ee2ede
TS
72 int32_t CP0_Config6;
73 int32_t CP0_Config7;
2f644545
TS
74 int32_t SYNCI_Step;
75 int32_t CCRes;
ead9360e
TS
76 int32_t CP0_Status_rw_bitmask;
77 int32_t CP0_TCStatus_rw_bitmask;
78 int32_t CP0_SRSCtl;
3953d786 79 int32_t CP1_fcr0;
e034e2c3 80 int32_t SEGBITS;
6d35524c 81 int32_t PABITS;
ead9360e
TS
82 int32_t CP0_SRSConf0_rw_bitmask;
83 int32_t CP0_SRSConf0;
84 int32_t CP0_SRSConf1_rw_bitmask;
85 int32_t CP0_SRSConf1;
86 int32_t CP0_SRSConf2_rw_bitmask;
87 int32_t CP0_SRSConf2;
88 int32_t CP0_SRSConf3_rw_bitmask;
89 int32_t CP0_SRSConf3;
90 int32_t CP0_SRSConf4_rw_bitmask;
91 int32_t CP0_SRSConf4;
e189e748 92 int insn_flags;
6d35524c 93 enum mips_mmu_types mmu_type;
33d68b5f
TS
94};
95
96/*****************************************************************************/
97/* MIPS CPU definitions */
8706c382 98static const mips_def_t mips_defs[] =
33d68b5f 99{
33d68b5f
TS
100 {
101 .name = "4Kc",
102 .CP0_PRid = 0x00018000,
6d35524c 103 .CP0_Config0 = MIPS_CONFIG0 | (MMU_TYPE_R4000 << CP0C0_MT),
ae5d8053
TS
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),
3953d786
TS
107 .CP0_Config2 = MIPS_CONFIG2,
108 .CP0_Config3 = MIPS_CONFIG3,
2f644545
TS
109 .SYNCI_Step = 32,
110 .CCRes = 2,
ead9360e 111 .CP0_Status_rw_bitmask = 0x1278FF17,
6d35524c
TS
112 .SEGBITS = 32,
113 .PABITS = 32,
e189e748 114 .insn_flags = CPU_MIPS32 | ASE_MIPS16,
6d35524c 115 .mmu_type = MMU_TYPE_R4000,
33d68b5f 116 },
8d162c2b
TS
117 {
118 .name = "4Km",
119 .CP0_PRid = 0x00018300,
120 /* Config1 implemented, fixed mapping MMU,
121 no virtual icache, uncached coherency. */
6d35524c 122 .CP0_Config0 = MIPS_CONFIG0 | (MMU_TYPE_FMT << CP0C0_MT),
8d162c2b
TS
123 .CP0_Config1 = MIPS_CONFIG1 |
124 (0 << CP0C1_IS) | (3 << CP0C1_IL) | (1 << CP0C1_IA) |
125 (0 << CP0C1_DS) | (3 << CP0C1_DL) | (1 << CP0C1_DA),
126 .CP0_Config2 = MIPS_CONFIG2,
127 .CP0_Config3 = MIPS_CONFIG3,
128 .SYNCI_Step = 32,
129 .CCRes = 2,
130 .CP0_Status_rw_bitmask = 0x1258FF17,
6d35524c
TS
131 .SEGBITS = 32,
132 .PABITS = 32,
8d162c2b 133 .insn_flags = CPU_MIPS32 | ASE_MIPS16,
6d35524c 134 .mmu_type = MMU_TYPE_FMT,
8d162c2b 135 },
33d68b5f 136 {
34ee2ede 137 .name = "4KEcR1",
33d68b5f 138 .CP0_PRid = 0x00018400,
6d35524c 139 .CP0_Config0 = MIPS_CONFIG0 | (MMU_TYPE_R4000 << CP0C0_MT),
ae5d8053
TS
140 .CP0_Config1 = MIPS_CONFIG1 | (15 << CP0C1_MMU) |
141 (0 << CP0C1_IS) | (3 << CP0C1_IL) | (1 << CP0C1_IA) |
142 (0 << CP0C1_DS) | (3 << CP0C1_DL) | (1 << CP0C1_DA),
34ee2ede
TS
143 .CP0_Config2 = MIPS_CONFIG2,
144 .CP0_Config3 = MIPS_CONFIG3,
2f644545
TS
145 .SYNCI_Step = 32,
146 .CCRes = 2,
ead9360e 147 .CP0_Status_rw_bitmask = 0x1278FF17,
6d35524c
TS
148 .SEGBITS = 32,
149 .PABITS = 32,
e189e748 150 .insn_flags = CPU_MIPS32 | ASE_MIPS16,
6d35524c 151 .mmu_type = MMU_TYPE_R4000,
34ee2ede 152 },
8d162c2b
TS
153 {
154 .name = "4KEmR1",
155 .CP0_PRid = 0x00018500,
6d35524c 156 .CP0_Config0 = MIPS_CONFIG0 | (MMU_TYPE_FMT << CP0C0_MT),
8d162c2b
TS
157 .CP0_Config1 = MIPS_CONFIG1 |
158 (0 << CP0C1_IS) | (3 << CP0C1_IL) | (1 << CP0C1_IA) |
159 (0 << CP0C1_DS) | (3 << CP0C1_DL) | (1 << CP0C1_DA),
160 .CP0_Config2 = MIPS_CONFIG2,
161 .CP0_Config3 = MIPS_CONFIG3,
162 .SYNCI_Step = 32,
163 .CCRes = 2,
164 .CP0_Status_rw_bitmask = 0x1258FF17,
6d35524c
TS
165 .SEGBITS = 32,
166 .PABITS = 32,
8d162c2b 167 .insn_flags = CPU_MIPS32 | ASE_MIPS16,
6d35524c 168 .mmu_type = MMU_TYPE_FMT,
8d162c2b 169 },
34ee2ede
TS
170 {
171 .name = "4KEc",
172 .CP0_PRid = 0x00019000,
6d35524c
TS
173 .CP0_Config0 = MIPS_CONFIG0 | (0x1 << CP0C0_AR) |
174 (MMU_TYPE_R4000 << CP0C0_MT),
ae5d8053
TS
175 .CP0_Config1 = MIPS_CONFIG1 | (15 << CP0C1_MMU) |
176 (0 << CP0C1_IS) | (3 << CP0C1_IL) | (1 << CP0C1_IA) |
177 (0 << CP0C1_DS) | (3 << CP0C1_DL) | (1 << CP0C1_DA),
34ee2ede 178 .CP0_Config2 = MIPS_CONFIG2,
ead9360e 179 .CP0_Config3 = MIPS_CONFIG3 | (0 << CP0C3_VInt),
2f644545
TS
180 .SYNCI_Step = 32,
181 .CCRes = 2,
ead9360e 182 .CP0_Status_rw_bitmask = 0x1278FF17,
6d35524c
TS
183 .SEGBITS = 32,
184 .PABITS = 32,
e189e748 185 .insn_flags = CPU_MIPS32R2 | ASE_MIPS16,
6d35524c 186 .mmu_type = MMU_TYPE_R4000,
34ee2ede 187 },
3e4587d5
TS
188 {
189 .name = "4KEm",
190 .CP0_PRid = 0x00019100,
6d35524c
TS
191 .CP0_Config0 = MIPS_CONFIG0 | (0x1 << CP0C0_AR) |
192 (MMU_TYPE_FMT << CP0C0_MT),
3e4587d5
TS
193 .CP0_Config1 = MIPS_CONFIG1 |
194 (0 << CP0C1_IS) | (3 << CP0C1_IL) | (1 << CP0C1_IA) |
195 (0 << CP0C1_DS) | (3 << CP0C1_DL) | (1 << CP0C1_DA),
196 .CP0_Config2 = MIPS_CONFIG2,
197 .CP0_Config3 = MIPS_CONFIG3,
198 .SYNCI_Step = 32,
199 .CCRes = 2,
200 .CP0_Status_rw_bitmask = 0x1258FF17,
6d35524c
TS
201 .SEGBITS = 32,
202 .PABITS = 32,
3e4587d5 203 .insn_flags = CPU_MIPS32R2 | ASE_MIPS16,
6d35524c 204 .mmu_type = MMU_TYPE_FMT,
3e4587d5 205 },
34ee2ede
TS
206 {
207 .name = "24Kc",
208 .CP0_PRid = 0x00019300,
6d35524c
TS
209 .CP0_Config0 = MIPS_CONFIG0 | (0x1 << CP0C0_AR) |
210 (MMU_TYPE_R4000 << CP0C0_MT),
ae5d8053
TS
211 .CP0_Config1 = MIPS_CONFIG1 | (15 << CP0C1_MMU) |
212 (0 << CP0C1_IS) | (3 << CP0C1_IL) | (1 << CP0C1_IA) |
213 (0 << CP0C1_DS) | (3 << CP0C1_DL) | (1 << CP0C1_DA),
3953d786 214 .CP0_Config2 = MIPS_CONFIG2,
ead9360e 215 .CP0_Config3 = MIPS_CONFIG3 | (0 << CP0C3_VInt),
2f644545
TS
216 .SYNCI_Step = 32,
217 .CCRes = 2,
ead9360e 218 /* No DSP implemented. */
671880e6 219 .CP0_Status_rw_bitmask = 0x1278FF1F,
6d35524c
TS
220 .SEGBITS = 32,
221 .PABITS = 32,
3e4587d5 222 .insn_flags = CPU_MIPS32R2 | ASE_MIPS16,
6d35524c 223 .mmu_type = MMU_TYPE_R4000,
33d68b5f
TS
224 },
225 {
226 .name = "24Kf",
227 .CP0_PRid = 0x00019300,
6d35524c
TS
228 .CP0_Config0 = MIPS_CONFIG0 | (0x1 << CP0C0_AR) |
229 (MMU_TYPE_R4000 << CP0C0_MT),
ae5d8053
TS
230 .CP0_Config1 = MIPS_CONFIG1 | (1 << CP0C1_FP) | (15 << CP0C1_MMU) |
231 (0 << CP0C1_IS) | (3 << CP0C1_IL) | (1 << CP0C1_IA) |
232 (0 << CP0C1_DS) | (3 << CP0C1_DL) | (1 << CP0C1_DA),
3953d786 233 .CP0_Config2 = MIPS_CONFIG2,
ead9360e 234 .CP0_Config3 = MIPS_CONFIG3 | (0 << CP0C3_VInt),
2f644545
TS
235 .SYNCI_Step = 32,
236 .CCRes = 2,
ead9360e 237 /* No DSP implemented. */
671880e6 238 .CP0_Status_rw_bitmask = 0x3678FF1F,
5a5012ec
TS
239 .CP1_fcr0 = (1 << FCR0_F64) | (1 << FCR0_L) | (1 << FCR0_W) |
240 (1 << FCR0_D) | (1 << FCR0_S) | (0x93 << FCR0_PRID),
6d35524c
TS
241 .SEGBITS = 32,
242 .PABITS = 32,
3e4587d5 243 .insn_flags = CPU_MIPS32R2 | ASE_MIPS16,
6d35524c 244 .mmu_type = MMU_TYPE_R4000,
33d68b5f 245 },
ead9360e
TS
246 {
247 .name = "34Kf",
248 .CP0_PRid = 0x00019500,
6d35524c
TS
249 .CP0_Config0 = MIPS_CONFIG0 | (0x1 << CP0C0_AR) |
250 (MMU_TYPE_R4000 << CP0C0_MT),
ead9360e
TS
251 .CP0_Config1 = MIPS_CONFIG1 | (1 << CP0C1_FP) | (15 << CP0C1_MMU) |
252 (0 << CP0C1_IS) | (3 << CP0C1_IL) | (1 << CP0C1_IA) |
253 (0 << CP0C1_DS) | (3 << CP0C1_DL) | (1 << CP0C1_DA),
254 .CP0_Config2 = MIPS_CONFIG2,
255 .CP0_Config3 = MIPS_CONFIG3 | (0 << CP0C3_VInt) | (1 << CP0C3_MT),
256 .SYNCI_Step = 32,
257 .CCRes = 2,
258 /* No DSP implemented. */
671880e6 259 .CP0_Status_rw_bitmask = 0x3678FF1F,
ead9360e
TS
260 /* No DSP implemented. */
261 .CP0_TCStatus_rw_bitmask = (0 << CP0TCSt_TCU3) | (0 << CP0TCSt_TCU2) |
262 (1 << CP0TCSt_TCU1) | (1 << CP0TCSt_TCU0) |
263 (0 << CP0TCSt_TMX) | (1 << CP0TCSt_DT) |
264 (1 << CP0TCSt_DA) | (1 << CP0TCSt_A) |
265 (0x3 << CP0TCSt_TKSU) | (1 << CP0TCSt_IXMT) |
266 (0xff << CP0TCSt_TASID),
267 .CP1_fcr0 = (1 << FCR0_F64) | (1 << FCR0_L) | (1 << FCR0_W) |
268 (1 << FCR0_D) | (1 << FCR0_S) | (0x95 << FCR0_PRID),
269 .CP0_SRSCtl = (0xf << CP0SRSCtl_HSS),
270 .CP0_SRSConf0_rw_bitmask = 0x3fffffff,
271 .CP0_SRSConf0 = (1 << CP0SRSC0_M) | (0x3fe << CP0SRSC0_SRS3) |
272 (0x3fe << CP0SRSC0_SRS2) | (0x3fe << CP0SRSC0_SRS1),
273 .CP0_SRSConf1_rw_bitmask = 0x3fffffff,
274 .CP0_SRSConf1 = (1 << CP0SRSC1_M) | (0x3fe << CP0SRSC1_SRS6) |
275 (0x3fe << CP0SRSC1_SRS5) | (0x3fe << CP0SRSC1_SRS4),
276 .CP0_SRSConf2_rw_bitmask = 0x3fffffff,
277 .CP0_SRSConf2 = (1 << CP0SRSC2_M) | (0x3fe << CP0SRSC2_SRS9) |
278 (0x3fe << CP0SRSC2_SRS8) | (0x3fe << CP0SRSC2_SRS7),
279 .CP0_SRSConf3_rw_bitmask = 0x3fffffff,
280 .CP0_SRSConf3 = (1 << CP0SRSC3_M) | (0x3fe << CP0SRSC3_SRS12) |
281 (0x3fe << CP0SRSC3_SRS11) | (0x3fe << CP0SRSC3_SRS10),
282 .CP0_SRSConf4_rw_bitmask = 0x3fffffff,
283 .CP0_SRSConf4 = (0x3fe << CP0SRSC4_SRS15) |
284 (0x3fe << CP0SRSC4_SRS14) | (0x3fe << CP0SRSC4_SRS13),
6d35524c
TS
285 .SEGBITS = 32,
286 .PABITS = 32,
7385ac0b 287 .insn_flags = CPU_MIPS32R2 | ASE_MIPS16 | ASE_DSP | ASE_MT,
6d35524c 288 .mmu_type = MMU_TYPE_R4000,
ead9360e 289 },
d26bc211 290#if defined(TARGET_MIPS64)
33d68b5f
TS
291 {
292 .name = "R4000",
293 .CP0_PRid = 0x00000400,
6d35524c
TS
294 /* No L2 cache, icache size 8k, dcache size 8k, uncached coherency. */
295 .CP0_Config0 = (1 << 17) | (0x1 << 9) | (0x1 << 6) | (0x2 << CP0C0_K0),
296 /* Note: Config1 is only used internally, the R4000 has only Config0. */
297 .CP0_Config1 = (1 << CP0C1_FP) | (47 << CP0C1_MMU),
2f644545
TS
298 .SYNCI_Step = 16,
299 .CCRes = 2,
ead9360e 300 .CP0_Status_rw_bitmask = 0x3678FFFF,
6d35524c 301 /* The R4000 has a full 64bit FPU but doesn't use the fcr0 bits. */
c9c1a064 302 .CP1_fcr0 = (0x5 << FCR0_PRID) | (0x0 << FCR0_REV),
e034e2c3 303 .SEGBITS = 40,
6d35524c 304 .PABITS = 36,
e189e748 305 .insn_flags = CPU_MIPS3,
6d35524c 306 .mmu_type = MMU_TYPE_R4000,
c9c1a064 307 },
e9c71dd1
TS
308 {
309 .name = "VR5432",
310 .CP0_PRid = 0x00005400,
311 /* No L2 cache, icache size 8k, dcache size 8k, uncached coherency. */
312 .CP0_Config0 = (1 << 17) | (0x1 << 9) | (0x1 << 6) | (0x2 << CP0C0_K0),
313 .CP0_Config1 = (1 << CP0C1_FP) | (47 << CP0C1_MMU),
314 .SYNCI_Step = 16,
315 .CCRes = 2,
316 .CP0_Status_rw_bitmask = 0x3678FFFF,
317 /* The VR5432 has a full 64bit FPU but doesn't use the fcr0 bits. */
318 .CP1_fcr0 = (0x54 << FCR0_PRID) | (0x0 << FCR0_REV),
319 .SEGBITS = 40,
320 .PABITS = 32,
321 .insn_flags = CPU_VR54XX,
322 .mmu_type = MMU_TYPE_R4000,
323 },
c9c1a064
TS
324 {
325 .name = "5Kc",
326 .CP0_PRid = 0x00018100,
29fe0e34 327 .CP0_Config0 = MIPS_CONFIG0 | (0x2 << CP0C0_AT) |
6d35524c 328 (MMU_TYPE_R4000 << CP0C0_MT),
c9c1a064
TS
329 .CP0_Config1 = MIPS_CONFIG1 | (31 << CP0C1_MMU) |
330 (1 << CP0C1_IS) | (4 << CP0C1_IL) | (1 << CP0C1_IA) |
331 (1 << CP0C1_DS) | (4 << CP0C1_DL) | (1 << CP0C1_DA) |
332 (1 << CP0C1_PC) | (1 << CP0C1_WR) | (1 << CP0C1_EP),
333 .CP0_Config2 = MIPS_CONFIG2,
334 .CP0_Config3 = MIPS_CONFIG3,
335 .SYNCI_Step = 32,
336 .CCRes = 2,
ead9360e 337 .CP0_Status_rw_bitmask = 0x32F8FFFF,
e034e2c3 338 .SEGBITS = 42,
6d35524c 339 .PABITS = 36,
e189e748 340 .insn_flags = CPU_MIPS64,
6d35524c 341 .mmu_type = MMU_TYPE_R4000,
c9c1a064
TS
342 },
343 {
344 .name = "5Kf",
345 .CP0_PRid = 0x00018100,
29fe0e34 346 .CP0_Config0 = MIPS_CONFIG0 | (0x2 << CP0C0_AT) |
6d35524c 347 (MMU_TYPE_R4000 << CP0C0_MT),
c9c1a064
TS
348 .CP0_Config1 = MIPS_CONFIG1 | (1 << CP0C1_FP) | (31 << CP0C1_MMU) |
349 (1 << CP0C1_IS) | (4 << CP0C1_IL) | (1 << CP0C1_IA) |
350 (1 << CP0C1_DS) | (4 << CP0C1_DL) | (1 << CP0C1_DA) |
351 (1 << CP0C1_PC) | (1 << CP0C1_WR) | (1 << CP0C1_EP),
352 .CP0_Config2 = MIPS_CONFIG2,
353 .CP0_Config3 = MIPS_CONFIG3,
354 .SYNCI_Step = 32,
355 .CCRes = 2,
ead9360e 356 .CP0_Status_rw_bitmask = 0x36F8FFFF,
1e3d0552 357 /* The 5Kf has F64 / L / W but doesn't use the fcr0 bits. */
c9c1a064
TS
358 .CP1_fcr0 = (1 << FCR0_D) | (1 << FCR0_S) |
359 (0x81 << FCR0_PRID) | (0x0 << FCR0_REV),
e034e2c3 360 .SEGBITS = 42,
6d35524c 361 .PABITS = 36,
e189e748 362 .insn_flags = CPU_MIPS64,
6d35524c 363 .mmu_type = MMU_TYPE_R4000,
c9c1a064
TS
364 },
365 {
366 .name = "20Kc",
bd04c6fe
TS
367 /* We emulate a later version of the 20Kc, earlier ones had a broken
368 WAIT instruction. */
369 .CP0_PRid = 0x000182a0,
29fe0e34 370 .CP0_Config0 = MIPS_CONFIG0 | (0x2 << CP0C0_AT) |
6d35524c 371 (MMU_TYPE_R4000 << CP0C0_MT) | (1 << CP0C0_VI),
c9c1a064
TS
372 .CP0_Config1 = MIPS_CONFIG1 | (1 << CP0C1_FP) | (47 << CP0C1_MMU) |
373 (2 << CP0C1_IS) | (4 << CP0C1_IL) | (3 << CP0C1_IA) |
374 (2 << CP0C1_DS) | (4 << CP0C1_DL) | (3 << CP0C1_DA) |
375 (1 << CP0C1_PC) | (1 << CP0C1_WR) | (1 << CP0C1_EP),
376 .CP0_Config2 = MIPS_CONFIG2,
377 .CP0_Config3 = MIPS_CONFIG3,
378 .SYNCI_Step = 32,
a1daafd8 379 .CCRes = 1,
ead9360e 380 .CP0_Status_rw_bitmask = 0x36FBFFFF,
1e3d0552 381 /* The 20Kc has F64 / L / W but doesn't use the fcr0 bits. */
c9c1a064 382 .CP1_fcr0 = (1 << FCR0_3D) | (1 << FCR0_PS) |
5a5012ec 383 (1 << FCR0_D) | (1 << FCR0_S) |
c9c1a064 384 (0x82 << FCR0_PRID) | (0x0 << FCR0_REV),
e034e2c3 385 .SEGBITS = 40,
6d35524c 386 .PABITS = 36,
e189e748 387 .insn_flags = CPU_MIPS64 | ASE_MIPS3D,
6d35524c 388 .mmu_type = MMU_TYPE_R4000,
33d68b5f 389 },
d2123ead
TS
390 {
391 /* A generic CPU providing MIPS64 Release 2 features.
392 FIXME: Eventually this should be replaced by a real CPU model. */
393 .name = "MIPS64R2-generic",
8c89395e 394 .CP0_PRid = 0x00010000,
6d35524c
TS
395 .CP0_Config0 = MIPS_CONFIG0 | (0x1 << CP0C0_AR) | (0x2 << CP0C0_AT) |
396 (MMU_TYPE_R4000 << CP0C0_MT),
d2123ead
TS
397 .CP0_Config1 = MIPS_CONFIG1 | (1 << CP0C1_FP) | (63 << CP0C1_MMU) |
398 (2 << CP0C1_IS) | (4 << CP0C1_IL) | (3 << CP0C1_IA) |
399 (2 << CP0C1_DS) | (4 << CP0C1_DL) | (3 << CP0C1_DA) |
400 (1 << CP0C1_PC) | (1 << CP0C1_WR) | (1 << CP0C1_EP),
401 .CP0_Config2 = MIPS_CONFIG2,
6d35524c 402 .CP0_Config3 = MIPS_CONFIG3 | (1 << CP0C3_LPA),
d2123ead
TS
403 .SYNCI_Step = 32,
404 .CCRes = 2,
405 .CP0_Status_rw_bitmask = 0x36FBFFFF,
ea4b07f7
TS
406 .CP1_fcr0 = (1 << FCR0_F64) | (1 << FCR0_3D) | (1 << FCR0_PS) |
407 (1 << FCR0_L) | (1 << FCR0_W) | (1 << FCR0_D) |
408 (1 << FCR0_S) | (0x00 << FCR0_PRID) | (0x0 << FCR0_REV),
6d35524c
TS
409 .SEGBITS = 42,
410 /* The architectural limit is 59, but we have hardcoded 36 bit
411 in some places...
412 .PABITS = 59, */ /* the architectural limit */
413 .PABITS = 36,
d2123ead 414 .insn_flags = CPU_MIPS64R2 | ASE_MIPS3D,
6d35524c 415 .mmu_type = MMU_TYPE_R4000,
d2123ead 416 },
33d68b5f
TS
417#endif
418};
419
929a62a0 420static const mips_def_t *cpu_mips_find_by_name (const char *name)
33d68b5f 421{
aaed909a 422 int i;
33d68b5f 423
33d68b5f
TS
424 for (i = 0; i < sizeof(mips_defs) / sizeof(mips_defs[0]); i++) {
425 if (strcasecmp(name, mips_defs[i].name) == 0) {
aaed909a 426 return &mips_defs[i];
33d68b5f
TS
427 }
428 }
aaed909a 429 return NULL;
33d68b5f
TS
430}
431
432void mips_cpu_list (FILE *f, int (*cpu_fprintf)(FILE *f, const char *fmt, ...))
433{
434 int i;
435
436 for (i = 0; i < sizeof(mips_defs) / sizeof(mips_defs[0]); i++) {
437 (*cpu_fprintf)(f, "MIPS '%s'\n",
438 mips_defs[i].name);
439 }
440}
441
f8a6ec58 442#ifndef CONFIG_USER_ONLY
aaed909a 443static void no_mmu_init (CPUMIPSState *env, const mips_def_t *def)
29929e34 444{
ead9360e
TS
445 env->tlb->nb_tlb = 1;
446 env->tlb->map_address = &no_mmu_map_address;
29929e34
TS
447}
448
aaed909a 449static void fixed_mmu_init (CPUMIPSState *env, const mips_def_t *def)
29929e34 450{
ead9360e
TS
451 env->tlb->nb_tlb = 1;
452 env->tlb->map_address = &fixed_mmu_map_address;
29929e34
TS
453}
454
aaed909a 455static void r4k_mmu_init (CPUMIPSState *env, const mips_def_t *def)
29929e34 456{
ead9360e
TS
457 env->tlb->nb_tlb = 1 + ((def->CP0_Config1 >> CP0C1_MMU) & 63);
458 env->tlb->map_address = &r4k_map_address;
459 env->tlb->do_tlbwi = r4k_do_tlbwi;
460 env->tlb->do_tlbwr = r4k_do_tlbwr;
461 env->tlb->do_tlbp = r4k_do_tlbp;
462 env->tlb->do_tlbr = r4k_do_tlbr;
463}
464
aaed909a 465static void mmu_init (CPUMIPSState *env, const mips_def_t *def)
ead9360e
TS
466{
467 env->tlb = qemu_mallocz(sizeof(CPUMIPSTLBContext));
468
6d35524c
TS
469 switch (def->mmu_type) {
470 case MMU_TYPE_NONE:
ead9360e
TS
471 no_mmu_init(env, def);
472 break;
6d35524c 473 case MMU_TYPE_R4000:
ead9360e
TS
474 r4k_mmu_init(env, def);
475 break;
6d35524c 476 case MMU_TYPE_FMT:
ead9360e
TS
477 fixed_mmu_init(env, def);
478 break;
6d35524c
TS
479 case MMU_TYPE_R3000:
480 case MMU_TYPE_R6000:
481 case MMU_TYPE_R8000:
ead9360e
TS
482 default:
483 cpu_abort(env, "MMU type not supported\n");
484 }
485 env->CP0_Random = env->tlb->nb_tlb - 1;
486 env->tlb->tlb_in_use = env->tlb->nb_tlb;
29929e34 487}
f8a6ec58 488#endif /* CONFIG_USER_ONLY */
29929e34 489
aaed909a 490static void fpu_init (CPUMIPSState *env, const mips_def_t *def)
ead9360e 491{
f01be154
TS
492 int i;
493
494 for (i = 0; i < MIPS_FPU_MAX; i++)
495 env->fpus[i].fcr0 = def->CP1_fcr0;
ead9360e 496
f01be154 497 memcpy(&env->active_fpu, &env->fpus[0], sizeof(env->active_fpu));
0eaef5aa
TS
498 if (env->user_mode_only) {
499 if (env->CP0_Config1 & (1 << CP0C1_FP))
500 env->hflags |= MIPS_HFLAG_FPU;
36271893 501#ifdef TARGET_MIPS64
f01be154 502 if (env->active_fpu.fcr0 & (1 << FCR0_F64))
0eaef5aa 503 env->hflags |= MIPS_HFLAG_F64;
36271893 504#endif
0eaef5aa 505 }
ead9360e
TS
506}
507
aaed909a 508static void mvp_init (CPUMIPSState *env, const mips_def_t *def)
ead9360e
TS
509{
510 env->mvp = qemu_mallocz(sizeof(CPUMIPSMVPContext));
511
512 /* MVPConf1 implemented, TLB sharable, no gating storage support,
513 programmable cache partitioning implemented, number of allocatable
514 and sharable TLB entries, MVP has allocatable TCs, 2 VPEs
515 implemented, 5 TCs implemented. */
516 env->mvp->CP0_MVPConf0 = (1 << CP0MVPC0_M) | (1 << CP0MVPC0_TLBS) |
517 (0 << CP0MVPC0_GS) | (1 << CP0MVPC0_PCP) |
ead9360e
TS
518// TODO: actually do 2 VPEs.
519// (1 << CP0MVPC0_TCA) | (0x1 << CP0MVPC0_PVPE) |
520// (0x04 << CP0MVPC0_PTC);
521 (1 << CP0MVPC0_TCA) | (0x0 << CP0MVPC0_PVPE) |
522 (0x04 << CP0MVPC0_PTC);
0eaef5aa
TS
523 /* Usermode has no TLB support */
524 if (!env->user_mode_only)
525 env->mvp->CP0_MVPConf0 |= (env->tlb->nb_tlb << CP0MVPC0_PTLBE);
526
ead9360e
TS
527 /* Allocatable CP1 have media extensions, allocatable CP1 have FP support,
528 no UDI implemented, no CP2 implemented, 1 CP1 implemented. */
529 env->mvp->CP0_MVPConf1 = (1 << CP0MVPC1_CIM) | (1 << CP0MVPC1_CIF) |
530 (0x0 << CP0MVPC1_PCX) | (0x0 << CP0MVPC1_PCP2) |
531 (0x1 << CP0MVPC1_PCP1);
532}
533
aaed909a 534static int cpu_mips_register (CPUMIPSState *env, const mips_def_t *def)
33d68b5f 535{
33d68b5f
TS
536 env->CP0_PRid = def->CP0_PRid;
537 env->CP0_Config0 = def->CP0_Config0;
51b2772f
TS
538#ifdef TARGET_WORDS_BIGENDIAN
539 env->CP0_Config0 |= (1 << CP0C0_BE);
3953d786 540#endif
33d68b5f 541 env->CP0_Config1 = def->CP0_Config1;
3953d786
TS
542 env->CP0_Config2 = def->CP0_Config2;
543 env->CP0_Config3 = def->CP0_Config3;
34ee2ede
TS
544 env->CP0_Config6 = def->CP0_Config6;
545 env->CP0_Config7 = def->CP0_Config7;
2f644545
TS
546 env->SYNCI_Step = def->SYNCI_Step;
547 env->CCRes = def->CCRes;
ead9360e
TS
548 env->CP0_Status_rw_bitmask = def->CP0_Status_rw_bitmask;
549 env->CP0_TCStatus_rw_bitmask = def->CP0_TCStatus_rw_bitmask;
550 env->CP0_SRSCtl = def->CP0_SRSCtl;
958fb4a9 551 env->current_tc = 0;
6d35524c
TS
552 env->SEGBITS = def->SEGBITS;
553 env->SEGMask = (target_ulong)((1ULL << def->SEGBITS) - 1);
d26bc211 554#if defined(TARGET_MIPS64)
6d35524c 555 if (def->insn_flags & ISA_MIPS3) {
3ddf0b5c 556 env->hflags |= MIPS_HFLAG_64;
6d35524c 557 env->SEGMask |= 3ULL << 62;
3ddf0b5c 558 }
e034e2c3 559#endif
6d35524c
TS
560 env->PABITS = def->PABITS;
561 env->PAMask = (target_ulong)((1ULL << def->PABITS) - 1);
ead9360e
TS
562 env->CP0_SRSConf0_rw_bitmask = def->CP0_SRSConf0_rw_bitmask;
563 env->CP0_SRSConf0 = def->CP0_SRSConf0;
564 env->CP0_SRSConf1_rw_bitmask = def->CP0_SRSConf1_rw_bitmask;
565 env->CP0_SRSConf1 = def->CP0_SRSConf1;
566 env->CP0_SRSConf2_rw_bitmask = def->CP0_SRSConf2_rw_bitmask;
567 env->CP0_SRSConf2 = def->CP0_SRSConf2;
568 env->CP0_SRSConf3_rw_bitmask = def->CP0_SRSConf3_rw_bitmask;
569 env->CP0_SRSConf3 = def->CP0_SRSConf3;
570 env->CP0_SRSConf4_rw_bitmask = def->CP0_SRSConf4_rw_bitmask;
571 env->CP0_SRSConf4 = def->CP0_SRSConf4;
e189e748 572 env->insn_flags = def->insn_flags;
ead9360e 573
f8a6ec58 574#ifndef CONFIG_USER_ONLY
0eaef5aa
TS
575 if (!env->user_mode_only)
576 mmu_init(env, def);
f8a6ec58 577#endif
ead9360e
TS
578 fpu_init(env, def);
579 mvp_init(env, def);
33d68b5f
TS
580 return 0;
581}