blob: 72788e81c9b77b8bc783bbe2b03b9219ccc04912 [file] [log] [blame]
ths33d68b52007-03-18 00:30:29 +00001/*
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
ths3953d782007-03-21 11:04:42 +000022/* CPU / CPU family specific config register values. */
23
ths6d355242007-12-25 03:13:56 +000024/* Have config1, uncached coherency */
ths3953d782007-03-21 11:04:42 +000025#define MIPS_CONFIG0 \
ths6d355242007-12-25 03:13:56 +000026 ((1 << CP0C0_M) | (0x2 << CP0C0_K0))
ths3953d782007-03-21 11:04:42 +000027
thsae5d8052007-07-29 22:11:46 +000028/* Have config2, no coprocessor2 attached, no MDMX support attached,
ths3953d782007-03-21 11:04:42 +000029 no performance counters, watch registers present,
30 no code compression, EJTAG present, no FPU */
31#define MIPS_CONFIG1 \
thsfcb4a412007-04-17 15:26:47 +000032((1 << CP0C1_M) | \
ths3953d782007-03-21 11:04:42 +000033 (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
ths6d355242007-12-25 03:13:56 +000041/* No config4, no DSP ASE, no large physaddr (PABITS),
ths3953d782007-03-21 11:04:42 +000042 no external interrupt controller, no vectored interupts,
thsead93602007-09-06 00:18:15 +000043 no 1kb pages, no SmartMIPS ASE, no trace logic */
ths3953d782007-03-21 11:04:42 +000044#define MIPS_CONFIG3 \
45((0 << CP0C3_M) | (0 << CP0C3_DSPP) | (0 << CP0C3_LPA) | \
46 (0 << CP0C3_VEIC) | (0 << CP0C3_VInt) | (0 << CP0C3_SP) | \
thsead93602007-09-06 00:18:15 +000047 (0 << CP0C3_SM) | (0 << CP0C3_TL))
ths3953d782007-03-21 11:04:42 +000048
49/* Define a implementation number of 1.
50 Define a major version 1, minor version 0. */
ths5a5012e2007-05-07 13:55:33 +000051#define MIPS_FCR0 ((0 << FCR0_S) | (0x1 << FCR0_PRID) | (0x10 << FCR0_REV))
ths3953d782007-03-21 11:04:42 +000052
ths6d355242007-12-25 03:13:56 +000053/* 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
ths33d68b52007-03-18 00:30:29 +000065struct mips_def_t {
66 const unsigned char *name;
67 int32_t CP0_PRid;
68 int32_t CP0_Config0;
69 int32_t CP0_Config1;
ths3953d782007-03-21 11:04:42 +000070 int32_t CP0_Config2;
71 int32_t CP0_Config3;
ths34ee2ed2007-03-24 23:36:18 +000072 int32_t CP0_Config6;
73 int32_t CP0_Config7;
ths2f644542007-04-11 20:34:23 +000074 int32_t SYNCI_Step;
75 int32_t CCRes;
thsead93602007-09-06 00:18:15 +000076 int32_t CP0_Status_rw_bitmask;
77 int32_t CP0_TCStatus_rw_bitmask;
78 int32_t CP0_SRSCtl;
ths3953d782007-03-21 11:04:42 +000079 int32_t CP1_fcr0;
thse034e2c2007-06-23 18:04:12 +000080 int32_t SEGBITS;
ths6d355242007-12-25 03:13:56 +000081 int32_t PABITS;
thsead93602007-09-06 00:18:15 +000082 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;
thse189e742007-09-24 12:48:00 +000092 int insn_flags;
ths6d355242007-12-25 03:13:56 +000093 enum mips_mmu_types mmu_type;
ths33d68b52007-03-18 00:30:29 +000094};
95
96/*****************************************************************************/
97/* MIPS CPU definitions */
98static mips_def_t mips_defs[] =
99{
ths33d68b52007-03-18 00:30:29 +0000100 {
101 .name = "4Kc",
102 .CP0_PRid = 0x00018000,
ths6d355242007-12-25 03:13:56 +0000103 .CP0_Config0 = MIPS_CONFIG0 | (MMU_TYPE_R4000 << CP0C0_MT),
thsae5d8052007-07-29 22:11:46 +0000104 .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),
ths3953d782007-03-21 11:04:42 +0000107 .CP0_Config2 = MIPS_CONFIG2,
108 .CP0_Config3 = MIPS_CONFIG3,
ths2f644542007-04-11 20:34:23 +0000109 .SYNCI_Step = 32,
110 .CCRes = 2,
thsead93602007-09-06 00:18:15 +0000111 .CP0_Status_rw_bitmask = 0x1278FF17,
ths6d355242007-12-25 03:13:56 +0000112 .SEGBITS = 32,
113 .PABITS = 32,
thse189e742007-09-24 12:48:00 +0000114 .insn_flags = CPU_MIPS32 | ASE_MIPS16,
ths6d355242007-12-25 03:13:56 +0000115 .mmu_type = MMU_TYPE_R4000,
ths33d68b52007-03-18 00:30:29 +0000116 },
117 {
ths8d162c22007-11-19 16:10:33 +0000118 .name = "4Km",
119 .CP0_PRid = 0x00018300,
120 /* Config1 implemented, fixed mapping MMU,
121 no virtual icache, uncached coherency. */
ths6d355242007-12-25 03:13:56 +0000122 .CP0_Config0 = MIPS_CONFIG0 | (MMU_TYPE_FMT << CP0C0_MT),
ths8d162c22007-11-19 16:10:33 +0000123 .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,
ths6d355242007-12-25 03:13:56 +0000131 .SEGBITS = 32,
132 .PABITS = 32,
ths8d162c22007-11-19 16:10:33 +0000133 .insn_flags = CPU_MIPS32 | ASE_MIPS16,
ths6d355242007-12-25 03:13:56 +0000134 .mmu_type = MMU_TYPE_FMT,
ths8d162c22007-11-19 16:10:33 +0000135 },
136 {
ths34ee2ed2007-03-24 23:36:18 +0000137 .name = "4KEcR1",
ths33d68b52007-03-18 00:30:29 +0000138 .CP0_PRid = 0x00018400,
ths6d355242007-12-25 03:13:56 +0000139 .CP0_Config0 = MIPS_CONFIG0 | (MMU_TYPE_R4000 << CP0C0_MT),
thsae5d8052007-07-29 22:11:46 +0000140 .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),
ths34ee2ed2007-03-24 23:36:18 +0000143 .CP0_Config2 = MIPS_CONFIG2,
144 .CP0_Config3 = MIPS_CONFIG3,
ths2f644542007-04-11 20:34:23 +0000145 .SYNCI_Step = 32,
146 .CCRes = 2,
thsead93602007-09-06 00:18:15 +0000147 .CP0_Status_rw_bitmask = 0x1278FF17,
ths6d355242007-12-25 03:13:56 +0000148 .SEGBITS = 32,
149 .PABITS = 32,
thse189e742007-09-24 12:48:00 +0000150 .insn_flags = CPU_MIPS32 | ASE_MIPS16,
ths6d355242007-12-25 03:13:56 +0000151 .mmu_type = MMU_TYPE_R4000,
ths34ee2ed2007-03-24 23:36:18 +0000152 },
153 {
ths8d162c22007-11-19 16:10:33 +0000154 .name = "4KEmR1",
155 .CP0_PRid = 0x00018500,
ths6d355242007-12-25 03:13:56 +0000156 .CP0_Config0 = MIPS_CONFIG0 | (MMU_TYPE_FMT << CP0C0_MT),
ths8d162c22007-11-19 16:10:33 +0000157 .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,
ths6d355242007-12-25 03:13:56 +0000165 .SEGBITS = 32,
166 .PABITS = 32,
ths8d162c22007-11-19 16:10:33 +0000167 .insn_flags = CPU_MIPS32 | ASE_MIPS16,
ths6d355242007-12-25 03:13:56 +0000168 .mmu_type = MMU_TYPE_FMT,
ths8d162c22007-11-19 16:10:33 +0000169 },
170 {
ths34ee2ed2007-03-24 23:36:18 +0000171 .name = "4KEc",
172 .CP0_PRid = 0x00019000,
ths6d355242007-12-25 03:13:56 +0000173 .CP0_Config0 = MIPS_CONFIG0 | (0x1 << CP0C0_AR) |
174 (MMU_TYPE_R4000 << CP0C0_MT),
thsae5d8052007-07-29 22:11:46 +0000175 .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),
ths34ee2ed2007-03-24 23:36:18 +0000178 .CP0_Config2 = MIPS_CONFIG2,
thsead93602007-09-06 00:18:15 +0000179 .CP0_Config3 = MIPS_CONFIG3 | (0 << CP0C3_VInt),
ths2f644542007-04-11 20:34:23 +0000180 .SYNCI_Step = 32,
181 .CCRes = 2,
thsead93602007-09-06 00:18:15 +0000182 .CP0_Status_rw_bitmask = 0x1278FF17,
ths6d355242007-12-25 03:13:56 +0000183 .SEGBITS = 32,
184 .PABITS = 32,
thse189e742007-09-24 12:48:00 +0000185 .insn_flags = CPU_MIPS32R2 | ASE_MIPS16,
ths6d355242007-12-25 03:13:56 +0000186 .mmu_type = MMU_TYPE_R4000,
ths34ee2ed2007-03-24 23:36:18 +0000187 },
188 {
ths3e4587d2007-11-14 03:11:17 +0000189 .name = "4KEm",
190 .CP0_PRid = 0x00019100,
ths6d355242007-12-25 03:13:56 +0000191 .CP0_Config0 = MIPS_CONFIG0 | (0x1 << CP0C0_AR) |
192 (MMU_TYPE_FMT << CP0C0_MT),
ths3e4587d2007-11-14 03:11:17 +0000193 .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,
ths6d355242007-12-25 03:13:56 +0000201 .SEGBITS = 32,
202 .PABITS = 32,
ths3e4587d2007-11-14 03:11:17 +0000203 .insn_flags = CPU_MIPS32R2 | ASE_MIPS16,
ths6d355242007-12-25 03:13:56 +0000204 .mmu_type = MMU_TYPE_FMT,
ths3e4587d2007-11-14 03:11:17 +0000205 },
206 {
ths34ee2ed2007-03-24 23:36:18 +0000207 .name = "24Kc",
208 .CP0_PRid = 0x00019300,
ths6d355242007-12-25 03:13:56 +0000209 .CP0_Config0 = MIPS_CONFIG0 | (0x1 << CP0C0_AR) |
210 (MMU_TYPE_R4000 << CP0C0_MT),
thsae5d8052007-07-29 22:11:46 +0000211 .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),
ths3953d782007-03-21 11:04:42 +0000214 .CP0_Config2 = MIPS_CONFIG2,
thsead93602007-09-06 00:18:15 +0000215 .CP0_Config3 = MIPS_CONFIG3 | (0 << CP0C3_VInt),
ths2f644542007-04-11 20:34:23 +0000216 .SYNCI_Step = 32,
217 .CCRes = 2,
thsead93602007-09-06 00:18:15 +0000218 /* No DSP implemented. */
ths671880e2007-09-29 19:21:36 +0000219 .CP0_Status_rw_bitmask = 0x1278FF1F,
ths6d355242007-12-25 03:13:56 +0000220 .SEGBITS = 32,
221 .PABITS = 32,
ths3e4587d2007-11-14 03:11:17 +0000222 .insn_flags = CPU_MIPS32R2 | ASE_MIPS16,
ths6d355242007-12-25 03:13:56 +0000223 .mmu_type = MMU_TYPE_R4000,
ths33d68b52007-03-18 00:30:29 +0000224 },
225 {
226 .name = "24Kf",
227 .CP0_PRid = 0x00019300,
ths6d355242007-12-25 03:13:56 +0000228 .CP0_Config0 = MIPS_CONFIG0 | (0x1 << CP0C0_AR) |
229 (MMU_TYPE_R4000 << CP0C0_MT),
thsae5d8052007-07-29 22:11:46 +0000230 .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),
ths3953d782007-03-21 11:04:42 +0000233 .CP0_Config2 = MIPS_CONFIG2,
thsead93602007-09-06 00:18:15 +0000234 .CP0_Config3 = MIPS_CONFIG3 | (0 << CP0C3_VInt),
ths2f644542007-04-11 20:34:23 +0000235 .SYNCI_Step = 32,
236 .CCRes = 2,
thsead93602007-09-06 00:18:15 +0000237 /* No DSP implemented. */
ths671880e2007-09-29 19:21:36 +0000238 .CP0_Status_rw_bitmask = 0x3678FF1F,
ths5a5012e2007-05-07 13:55:33 +0000239 .CP1_fcr0 = (1 << FCR0_F64) | (1 << FCR0_L) | (1 << FCR0_W) |
240 (1 << FCR0_D) | (1 << FCR0_S) | (0x93 << FCR0_PRID),
ths6d355242007-12-25 03:13:56 +0000241 .SEGBITS = 32,
242 .PABITS = 32,
ths3e4587d2007-11-14 03:11:17 +0000243 .insn_flags = CPU_MIPS32R2 | ASE_MIPS16,
ths6d355242007-12-25 03:13:56 +0000244 .mmu_type = MMU_TYPE_R4000,
ths33d68b52007-03-18 00:30:29 +0000245 },
thsead93602007-09-06 00:18:15 +0000246 {
247 .name = "34Kf",
248 .CP0_PRid = 0x00019500,
ths6d355242007-12-25 03:13:56 +0000249 .CP0_Config0 = MIPS_CONFIG0 | (0x1 << CP0C0_AR) |
250 (MMU_TYPE_R4000 << CP0C0_MT),
thsead93602007-09-06 00:18:15 +0000251 .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. */
ths671880e2007-09-29 19:21:36 +0000259 .CP0_Status_rw_bitmask = 0x3678FF1F,
thsead93602007-09-06 00:18:15 +0000260 /* 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),
ths6d355242007-12-25 03:13:56 +0000285 .SEGBITS = 32,
286 .PABITS = 32,
ths7385ac02007-10-23 17:04:27 +0000287 .insn_flags = CPU_MIPS32R2 | ASE_MIPS16 | ASE_DSP | ASE_MT,
ths6d355242007-12-25 03:13:56 +0000288 .mmu_type = MMU_TYPE_R4000,
thsead93602007-09-06 00:18:15 +0000289 },
thsd26bc212007-11-08 18:05:37 +0000290#if defined(TARGET_MIPS64)
ths33d68b52007-03-18 00:30:29 +0000291 {
292 .name = "R4000",
293 .CP0_PRid = 0x00000400,
ths6d355242007-12-25 03:13:56 +0000294 /* 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),
ths2f644542007-04-11 20:34:23 +0000298 .SYNCI_Step = 16,
299 .CCRes = 2,
thsead93602007-09-06 00:18:15 +0000300 .CP0_Status_rw_bitmask = 0x3678FFFF,
ths6d355242007-12-25 03:13:56 +0000301 /* The R4000 has a full 64bit FPU but doesn't use the fcr0 bits. */
thsc9c1a062007-06-01 14:58:56 +0000302 .CP1_fcr0 = (0x5 << FCR0_PRID) | (0x0 << FCR0_REV),
thse034e2c2007-06-23 18:04:12 +0000303 .SEGBITS = 40,
ths6d355242007-12-25 03:13:56 +0000304 .PABITS = 36,
thse189e742007-09-24 12:48:00 +0000305 .insn_flags = CPU_MIPS3,
ths6d355242007-12-25 03:13:56 +0000306 .mmu_type = MMU_TYPE_R4000,
thsc9c1a062007-06-01 14:58:56 +0000307 },
308 {
thse9c71dd2007-12-25 20:46:56 +0000309 .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 },
324 {
thsc9c1a062007-06-01 14:58:56 +0000325 .name = "5Kc",
326 .CP0_PRid = 0x00018100,
ths29fe0e32007-12-25 17:32:46 +0000327 .CP0_Config0 = MIPS_CONFIG0 | (0x2 << CP0C0_AT) |
ths6d355242007-12-25 03:13:56 +0000328 (MMU_TYPE_R4000 << CP0C0_MT),
thsc9c1a062007-06-01 14:58:56 +0000329 .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,
thsead93602007-09-06 00:18:15 +0000337 .CP0_Status_rw_bitmask = 0x32F8FFFF,
thse034e2c2007-06-23 18:04:12 +0000338 .SEGBITS = 42,
ths6d355242007-12-25 03:13:56 +0000339 .PABITS = 36,
thse189e742007-09-24 12:48:00 +0000340 .insn_flags = CPU_MIPS64,
ths6d355242007-12-25 03:13:56 +0000341 .mmu_type = MMU_TYPE_R4000,
thsc9c1a062007-06-01 14:58:56 +0000342 },
343 {
344 .name = "5Kf",
345 .CP0_PRid = 0x00018100,
ths29fe0e32007-12-25 17:32:46 +0000346 .CP0_Config0 = MIPS_CONFIG0 | (0x2 << CP0C0_AT) |
ths6d355242007-12-25 03:13:56 +0000347 (MMU_TYPE_R4000 << CP0C0_MT),
thsc9c1a062007-06-01 14:58:56 +0000348 .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,
thsead93602007-09-06 00:18:15 +0000356 .CP0_Status_rw_bitmask = 0x36F8FFFF,
ths1e3d0552007-06-01 21:57:32 +0000357 /* The 5Kf has F64 / L / W but doesn't use the fcr0 bits. */
thsc9c1a062007-06-01 14:58:56 +0000358 .CP1_fcr0 = (1 << FCR0_D) | (1 << FCR0_S) |
359 (0x81 << FCR0_PRID) | (0x0 << FCR0_REV),
thse034e2c2007-06-23 18:04:12 +0000360 .SEGBITS = 42,
ths6d355242007-12-25 03:13:56 +0000361 .PABITS = 36,
thse189e742007-09-24 12:48:00 +0000362 .insn_flags = CPU_MIPS64,
ths6d355242007-12-25 03:13:56 +0000363 .mmu_type = MMU_TYPE_R4000,
thsc9c1a062007-06-01 14:58:56 +0000364 },
365 {
366 .name = "20Kc",
thsbd04c6f2007-06-12 12:43:47 +0000367 /* We emulate a later version of the 20Kc, earlier ones had a broken
368 WAIT instruction. */
369 .CP0_PRid = 0x000182a0,
ths29fe0e32007-12-25 17:32:46 +0000370 .CP0_Config0 = MIPS_CONFIG0 | (0x2 << CP0C0_AT) |
ths6d355242007-12-25 03:13:56 +0000371 (MMU_TYPE_R4000 << CP0C0_MT) | (1 << CP0C0_VI),
thsc9c1a062007-06-01 14:58:56 +0000372 .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,
thsa1daafd2007-12-24 14:33:57 +0000379 .CCRes = 1,
thsead93602007-09-06 00:18:15 +0000380 .CP0_Status_rw_bitmask = 0x36FBFFFF,
ths1e3d0552007-06-01 21:57:32 +0000381 /* The 20Kc has F64 / L / W but doesn't use the fcr0 bits. */
thsc9c1a062007-06-01 14:58:56 +0000382 .CP1_fcr0 = (1 << FCR0_3D) | (1 << FCR0_PS) |
ths5a5012e2007-05-07 13:55:33 +0000383 (1 << FCR0_D) | (1 << FCR0_S) |
thsc9c1a062007-06-01 14:58:56 +0000384 (0x82 << FCR0_PRID) | (0x0 << FCR0_REV),
thse034e2c2007-06-23 18:04:12 +0000385 .SEGBITS = 40,
ths6d355242007-12-25 03:13:56 +0000386 .PABITS = 36,
thse189e742007-09-24 12:48:00 +0000387 .insn_flags = CPU_MIPS64 | ASE_MIPS3D,
ths6d355242007-12-25 03:13:56 +0000388 .mmu_type = MMU_TYPE_R4000,
ths33d68b52007-03-18 00:30:29 +0000389 },
thsd2123ea2007-10-29 09:38:43 +0000390 {
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",
ths8c893952007-11-18 03:19:58 +0000394 .CP0_PRid = 0x00010000,
ths6d355242007-12-25 03:13:56 +0000395 .CP0_Config0 = MIPS_CONFIG0 | (0x1 << CP0C0_AR) | (0x2 << CP0C0_AT) |
396 (MMU_TYPE_R4000 << CP0C0_MT),
thsd2123ea2007-10-29 09:38:43 +0000397 .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,
ths6d355242007-12-25 03:13:56 +0000402 .CP0_Config3 = MIPS_CONFIG3 | (1 << CP0C3_LPA),
thsd2123ea2007-10-29 09:38:43 +0000403 .SYNCI_Step = 32,
404 .CCRes = 2,
405 .CP0_Status_rw_bitmask = 0x36FBFFFF,
thsea4b07f2007-12-28 12:35:05 +0000406 .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),
ths6d355242007-12-25 03:13:56 +0000409 .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,
thsd2123ea2007-10-29 09:38:43 +0000414 .insn_flags = CPU_MIPS64R2 | ASE_MIPS3D,
ths6d355242007-12-25 03:13:56 +0000415 .mmu_type = MMU_TYPE_R4000,
thsd2123ea2007-10-29 09:38:43 +0000416 },
ths33d68b52007-03-18 00:30:29 +0000417#endif
418};
419
bellardaaed9092007-11-10 15:15:54 +0000420static const mips_def_t *cpu_mips_find_by_name (const unsigned char *name)
ths33d68b52007-03-18 00:30:29 +0000421{
bellardaaed9092007-11-10 15:15:54 +0000422 int i;
ths33d68b52007-03-18 00:30:29 +0000423
ths33d68b52007-03-18 00:30:29 +0000424 for (i = 0; i < sizeof(mips_defs) / sizeof(mips_defs[0]); i++) {
425 if (strcasecmp(name, mips_defs[i].name) == 0) {
bellardaaed9092007-11-10 15:15:54 +0000426 return &mips_defs[i];
ths33d68b52007-03-18 00:30:29 +0000427 }
428 }
bellardaaed9092007-11-10 15:15:54 +0000429 return NULL;
ths33d68b52007-03-18 00:30:29 +0000430}
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
ths29929e32007-05-13 13:49:44 +0000442#ifndef CONFIG_USER_ONLY
bellardaaed9092007-11-10 15:15:54 +0000443static void no_mmu_init (CPUMIPSState *env, const mips_def_t *def)
ths29929e32007-05-13 13:49:44 +0000444{
thsead93602007-09-06 00:18:15 +0000445 env->tlb->nb_tlb = 1;
446 env->tlb->map_address = &no_mmu_map_address;
ths29929e32007-05-13 13:49:44 +0000447}
448
bellardaaed9092007-11-10 15:15:54 +0000449static void fixed_mmu_init (CPUMIPSState *env, const mips_def_t *def)
ths29929e32007-05-13 13:49:44 +0000450{
thsead93602007-09-06 00:18:15 +0000451 env->tlb->nb_tlb = 1;
452 env->tlb->map_address = &fixed_mmu_map_address;
ths29929e32007-05-13 13:49:44 +0000453}
454
bellardaaed9092007-11-10 15:15:54 +0000455static void r4k_mmu_init (CPUMIPSState *env, const mips_def_t *def)
ths29929e32007-05-13 13:49:44 +0000456{
thsead93602007-09-06 00:18:15 +0000457 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
bellardaaed9092007-11-10 15:15:54 +0000465static void mmu_init (CPUMIPSState *env, const mips_def_t *def)
thsead93602007-09-06 00:18:15 +0000466{
467 env->tlb = qemu_mallocz(sizeof(CPUMIPSTLBContext));
468
ths6d355242007-12-25 03:13:56 +0000469 switch (def->mmu_type) {
470 case MMU_TYPE_NONE:
thsead93602007-09-06 00:18:15 +0000471 no_mmu_init(env, def);
472 break;
ths6d355242007-12-25 03:13:56 +0000473 case MMU_TYPE_R4000:
thsead93602007-09-06 00:18:15 +0000474 r4k_mmu_init(env, def);
475 break;
ths6d355242007-12-25 03:13:56 +0000476 case MMU_TYPE_FMT:
thsead93602007-09-06 00:18:15 +0000477 fixed_mmu_init(env, def);
478 break;
ths6d355242007-12-25 03:13:56 +0000479 case MMU_TYPE_R3000:
480 case MMU_TYPE_R6000:
481 case MMU_TYPE_R8000:
thsead93602007-09-06 00:18:15 +0000482 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;
ths29929e32007-05-13 13:49:44 +0000487}
488#endif /* CONFIG_USER_ONLY */
489
bellardaaed9092007-11-10 15:15:54 +0000490static void fpu_init (CPUMIPSState *env, const mips_def_t *def)
thsead93602007-09-06 00:18:15 +0000491{
492 env->fpu = qemu_mallocz(sizeof(CPUMIPSFPUContext));
493
494 env->fpu->fcr0 = def->CP1_fcr0;
495#ifdef CONFIG_USER_ONLY
496 if (env->CP0_Config1 & (1 << CP0C1_FP))
497 env->hflags |= MIPS_HFLAG_FPU;
498 if (env->fpu->fcr0 & (1 << FCR0_F64))
499 env->hflags |= MIPS_HFLAG_F64;
500#endif
501}
502
bellardaaed9092007-11-10 15:15:54 +0000503static void mvp_init (CPUMIPSState *env, const mips_def_t *def)
thsead93602007-09-06 00:18:15 +0000504{
505 env->mvp = qemu_mallocz(sizeof(CPUMIPSMVPContext));
506
507 /* MVPConf1 implemented, TLB sharable, no gating storage support,
508 programmable cache partitioning implemented, number of allocatable
509 and sharable TLB entries, MVP has allocatable TCs, 2 VPEs
510 implemented, 5 TCs implemented. */
511 env->mvp->CP0_MVPConf0 = (1 << CP0MVPC0_M) | (1 << CP0MVPC0_TLBS) |
512 (0 << CP0MVPC0_GS) | (1 << CP0MVPC0_PCP) |
ths2337fdc2007-09-23 17:54:29 +0000513#ifndef CONFIG_USER_ONLY
514 /* Usermode has no TLB support */
thsead93602007-09-06 00:18:15 +0000515 (env->tlb->nb_tlb << CP0MVPC0_PTLBE) |
ths2337fdc2007-09-23 17:54:29 +0000516#endif
thsead93602007-09-06 00:18:15 +0000517// TODO: actually do 2 VPEs.
518// (1 << CP0MVPC0_TCA) | (0x1 << CP0MVPC0_PVPE) |
519// (0x04 << CP0MVPC0_PTC);
520 (1 << CP0MVPC0_TCA) | (0x0 << CP0MVPC0_PVPE) |
521 (0x04 << CP0MVPC0_PTC);
522 /* Allocatable CP1 have media extensions, allocatable CP1 have FP support,
523 no UDI implemented, no CP2 implemented, 1 CP1 implemented. */
524 env->mvp->CP0_MVPConf1 = (1 << CP0MVPC1_CIM) | (1 << CP0MVPC1_CIF) |
525 (0x0 << CP0MVPC1_PCX) | (0x0 << CP0MVPC1_PCP2) |
526 (0x1 << CP0MVPC1_PCP1);
527}
528
bellardaaed9092007-11-10 15:15:54 +0000529static int cpu_mips_register (CPUMIPSState *env, const mips_def_t *def)
ths33d68b52007-03-18 00:30:29 +0000530{
ths33d68b52007-03-18 00:30:29 +0000531 env->CP0_PRid = def->CP0_PRid;
532 env->CP0_Config0 = def->CP0_Config0;
ths51b27722007-05-30 20:46:02 +0000533#ifdef TARGET_WORDS_BIGENDIAN
534 env->CP0_Config0 |= (1 << CP0C0_BE);
ths3953d782007-03-21 11:04:42 +0000535#endif
ths33d68b52007-03-18 00:30:29 +0000536 env->CP0_Config1 = def->CP0_Config1;
ths3953d782007-03-21 11:04:42 +0000537 env->CP0_Config2 = def->CP0_Config2;
538 env->CP0_Config3 = def->CP0_Config3;
ths34ee2ed2007-03-24 23:36:18 +0000539 env->CP0_Config6 = def->CP0_Config6;
540 env->CP0_Config7 = def->CP0_Config7;
ths2f644542007-04-11 20:34:23 +0000541 env->SYNCI_Step = def->SYNCI_Step;
542 env->CCRes = def->CCRes;
thsead93602007-09-06 00:18:15 +0000543 env->CP0_Status_rw_bitmask = def->CP0_Status_rw_bitmask;
544 env->CP0_TCStatus_rw_bitmask = def->CP0_TCStatus_rw_bitmask;
545 env->CP0_SRSCtl = def->CP0_SRSCtl;
ths6d355242007-12-25 03:13:56 +0000546 env->SEGBITS = def->SEGBITS;
547 env->SEGMask = (target_ulong)((1ULL << def->SEGBITS) - 1);
thsd26bc212007-11-08 18:05:37 +0000548#if defined(TARGET_MIPS64)
ths6d355242007-12-25 03:13:56 +0000549 if (def->insn_flags & ISA_MIPS3) {
ths3ddf0b52007-08-26 17:37:23 +0000550 env->hflags |= MIPS_HFLAG_64;
ths6d355242007-12-25 03:13:56 +0000551 env->SEGMask |= 3ULL << 62;
ths3ddf0b52007-08-26 17:37:23 +0000552 }
thse034e2c2007-06-23 18:04:12 +0000553#endif
ths6d355242007-12-25 03:13:56 +0000554 env->PABITS = def->PABITS;
555 env->PAMask = (target_ulong)((1ULL << def->PABITS) - 1);
thsead93602007-09-06 00:18:15 +0000556 env->CP0_SRSConf0_rw_bitmask = def->CP0_SRSConf0_rw_bitmask;
557 env->CP0_SRSConf0 = def->CP0_SRSConf0;
558 env->CP0_SRSConf1_rw_bitmask = def->CP0_SRSConf1_rw_bitmask;
559 env->CP0_SRSConf1 = def->CP0_SRSConf1;
560 env->CP0_SRSConf2_rw_bitmask = def->CP0_SRSConf2_rw_bitmask;
561 env->CP0_SRSConf2 = def->CP0_SRSConf2;
562 env->CP0_SRSConf3_rw_bitmask = def->CP0_SRSConf3_rw_bitmask;
563 env->CP0_SRSConf3 = def->CP0_SRSConf3;
564 env->CP0_SRSConf4_rw_bitmask = def->CP0_SRSConf4_rw_bitmask;
565 env->CP0_SRSConf4 = def->CP0_SRSConf4;
thse189e742007-09-24 12:48:00 +0000566 env->insn_flags = def->insn_flags;
thsead93602007-09-06 00:18:15 +0000567
568#ifndef CONFIG_USER_ONLY
569 mmu_init(env, def);
570#endif
571 fpu_init(env, def);
572 mvp_init(env, def);
ths33d68b52007-03-18 00:30:29 +0000573 return 0;
574}