translate_init.c 25.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*
 *  MIPS emulation for qemu: CPU initialisation routines.
 *
 *  Copyright (c) 2004-2005 Jocelyn Mayer
 *  Copyright (c) 2007 Herve Poussineau
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * 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 22
/* CPU / CPU family specific config register values. */

23
/* Have config1, uncached coherency */
24
#define MIPS_CONFIG0                                              \
25
  ((1 << CP0C0_M) | (0x2 << CP0C0_K0))
26

27
/* Have config2, no coprocessor2 attached, no MDMX support attached,
28 29 30
   no performance counters, watch registers present,
   no code compression, EJTAG present, no FPU */
#define MIPS_CONFIG1                                              \
31
((1 << CP0C1_M) |                                                 \
32 33 34 35 36 37 38 39
 (0 << CP0C1_C2) | (0 << CP0C1_MD) | (0 << CP0C1_PC) |            \
 (1 << CP0C1_WR) | (0 << CP0C1_CA) | (1 << CP0C1_EP) |            \
 (0 << CP0C1_FP))

/* Have config3, no tertiary/secondary caches implemented */
#define MIPS_CONFIG2                                              \
((1 << CP0C2_M))

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 44 45
#define MIPS_CONFIG3                                              \
((0 << CP0C3_M) | (0 << CP0C3_DSPP) | (0 << CP0C3_LPA) |          \
 (0 << CP0C3_VEIC) | (0 << CP0C3_VInt) | (0 << CP0C3_SP) |        \
46
 (0 << CP0C3_SM) | (0 << CP0C3_TL))
47

48 49 50 51 52 53 54 55 56 57 58 59
/* MMU types, the first four entries have the same layout as the
   CP0C0_MT field.  */
enum mips_mmu_types {
    MMU_TYPE_NONE,
    MMU_TYPE_R4000,
    MMU_TYPE_RESERVED,
    MMU_TYPE_FMT,
    MMU_TYPE_R3000,
    MMU_TYPE_R6000,
    MMU_TYPE_R8000
};

A
Anthony Liguori 已提交
60
struct mips_def_t {
T
ths 已提交
61
    const char *name;
62 63 64
    int32_t CP0_PRid;
    int32_t CP0_Config0;
    int32_t CP0_Config1;
65 66
    int32_t CP0_Config2;
    int32_t CP0_Config3;
67 68
    int32_t CP0_Config6;
    int32_t CP0_Config7;
69 70
    target_ulong CP0_LLAddr_rw_bitmask;
    int CP0_LLAddr_shift;
T
ths 已提交
71 72
    int32_t SYNCI_Step;
    int32_t CCRes;
73 74 75
    int32_t CP0_Status_rw_bitmask;
    int32_t CP0_TCStatus_rw_bitmask;
    int32_t CP0_SRSCtl;
76
    int32_t CP1_fcr0;
T
ths 已提交
77
    int32_t SEGBITS;
78
    int32_t PABITS;
79 80 81 82 83 84 85 86 87 88
    int32_t CP0_SRSConf0_rw_bitmask;
    int32_t CP0_SRSConf0;
    int32_t CP0_SRSConf1_rw_bitmask;
    int32_t CP0_SRSConf1;
    int32_t CP0_SRSConf2_rw_bitmask;
    int32_t CP0_SRSConf2;
    int32_t CP0_SRSConf3_rw_bitmask;
    int32_t CP0_SRSConf3;
    int32_t CP0_SRSConf4_rw_bitmask;
    int32_t CP0_SRSConf4;
89
    int insn_flags;
90
    enum mips_mmu_types mmu_type;
91 92 93 94
};

/*****************************************************************************/
/* MIPS CPU definitions */
A
Anthony Liguori 已提交
95
static const mips_def_t mips_defs[] =
96 97 98 99
{
    {
        .name = "4Kc",
        .CP0_PRid = 0x00018000,
100
        .CP0_Config0 = MIPS_CONFIG0 | (MMU_TYPE_R4000 << CP0C0_MT),
101
        .CP0_Config1 = MIPS_CONFIG1 | (15 << CP0C1_MMU) |
A
aurel32 已提交
102
                       (0 << CP0C1_IS) | (3 << CP0C1_IL) | (1 << CP0C1_IA) |
103
                       (0 << CP0C1_DS) | (3 << CP0C1_DL) | (1 << CP0C1_DA) |
104
                       (0 << CP0C1_CA),
105 106
        .CP0_Config2 = MIPS_CONFIG2,
        .CP0_Config3 = MIPS_CONFIG3,
107 108
        .CP0_LLAddr_rw_bitmask = 0,
        .CP0_LLAddr_shift = 4,
T
ths 已提交
109 110
        .SYNCI_Step = 32,
        .CCRes = 2,
111
        .CP0_Status_rw_bitmask = 0x1278FF17,
112 113
        .SEGBITS = 32,
        .PABITS = 32,
114
        .insn_flags = CPU_MIPS32,
115
        .mmu_type = MMU_TYPE_R4000,
116
    },
T
ths 已提交
117 118 119 120 121
    {
        .name = "4Km",
        .CP0_PRid = 0x00018300,
        /* Config1 implemented, fixed mapping MMU,
           no virtual icache, uncached coherency. */
122
        .CP0_Config0 = MIPS_CONFIG0 | (MMU_TYPE_FMT << CP0C0_MT),
T
ths 已提交
123
        .CP0_Config1 = MIPS_CONFIG1 |
A
aurel32 已提交
124
                       (0 << CP0C1_IS) | (3 << CP0C1_IL) | (1 << CP0C1_IA) |
125 126
                       (0 << CP0C1_DS) | (3 << CP0C1_DL) | (1 << CP0C1_DA) |
                       (1 << CP0C1_CA),
T
ths 已提交
127 128
        .CP0_Config2 = MIPS_CONFIG2,
        .CP0_Config3 = MIPS_CONFIG3,
129 130
        .CP0_LLAddr_rw_bitmask = 0,
        .CP0_LLAddr_shift = 4,
T
ths 已提交
131 132 133
        .SYNCI_Step = 32,
        .CCRes = 2,
        .CP0_Status_rw_bitmask = 0x1258FF17,
134 135
        .SEGBITS = 32,
        .PABITS = 32,
T
ths 已提交
136
        .insn_flags = CPU_MIPS32 | ASE_MIPS16,
137
        .mmu_type = MMU_TYPE_FMT,
T
ths 已提交
138
    },
139
    {
140
        .name = "4KEcR1",
141
        .CP0_PRid = 0x00018400,
142
        .CP0_Config0 = MIPS_CONFIG0 | (MMU_TYPE_R4000 << CP0C0_MT),
143
        .CP0_Config1 = MIPS_CONFIG1 | (15 << CP0C1_MMU) |
A
aurel32 已提交
144
                       (0 << CP0C1_IS) | (3 << CP0C1_IL) | (1 << CP0C1_IA) |
145
                       (0 << CP0C1_DS) | (3 << CP0C1_DL) | (1 << CP0C1_DA) |
146
                       (0 << CP0C1_CA),
147 148
        .CP0_Config2 = MIPS_CONFIG2,
        .CP0_Config3 = MIPS_CONFIG3,
149 150
        .CP0_LLAddr_rw_bitmask = 0,
        .CP0_LLAddr_shift = 4,
T
ths 已提交
151 152
        .SYNCI_Step = 32,
        .CCRes = 2,
153
        .CP0_Status_rw_bitmask = 0x1278FF17,
154 155
        .SEGBITS = 32,
        .PABITS = 32,
156
        .insn_flags = CPU_MIPS32,
157
        .mmu_type = MMU_TYPE_R4000,
158
    },
T
ths 已提交
159 160 161
    {
        .name = "4KEmR1",
        .CP0_PRid = 0x00018500,
162
        .CP0_Config0 = MIPS_CONFIG0 | (MMU_TYPE_FMT << CP0C0_MT),
T
ths 已提交
163
        .CP0_Config1 = MIPS_CONFIG1 |
A
aurel32 已提交
164
                       (0 << CP0C1_IS) | (3 << CP0C1_IL) | (1 << CP0C1_IA) |
165 166
                       (0 << CP0C1_DS) | (3 << CP0C1_DL) | (1 << CP0C1_DA) |
                       (1 << CP0C1_CA),
T
ths 已提交
167 168
        .CP0_Config2 = MIPS_CONFIG2,
        .CP0_Config3 = MIPS_CONFIG3,
169 170
        .CP0_LLAddr_rw_bitmask = 0,
        .CP0_LLAddr_shift = 4,
T
ths 已提交
171 172 173
        .SYNCI_Step = 32,
        .CCRes = 2,
        .CP0_Status_rw_bitmask = 0x1258FF17,
174 175
        .SEGBITS = 32,
        .PABITS = 32,
T
ths 已提交
176
        .insn_flags = CPU_MIPS32 | ASE_MIPS16,
177
        .mmu_type = MMU_TYPE_FMT,
T
ths 已提交
178
    },
179 180 181
    {
        .name = "4KEc",
        .CP0_PRid = 0x00019000,
182 183
        .CP0_Config0 = MIPS_CONFIG0 | (0x1 << CP0C0_AR) |
                    (MMU_TYPE_R4000 << CP0C0_MT),
184
        .CP0_Config1 = MIPS_CONFIG1 | (15 << CP0C1_MMU) |
A
aurel32 已提交
185
                       (0 << CP0C1_IS) | (3 << CP0C1_IL) | (1 << CP0C1_IA) |
186
                       (0 << CP0C1_DS) | (3 << CP0C1_DL) | (1 << CP0C1_DA) |
187
                       (0 << CP0C1_CA),
188
        .CP0_Config2 = MIPS_CONFIG2,
189
        .CP0_Config3 = MIPS_CONFIG3 | (0 << CP0C3_VInt),
190 191
        .CP0_LLAddr_rw_bitmask = 0,
        .CP0_LLAddr_shift = 4,
T
ths 已提交
192 193
        .SYNCI_Step = 32,
        .CCRes = 2,
194
        .CP0_Status_rw_bitmask = 0x1278FF17,
195 196
        .SEGBITS = 32,
        .PABITS = 32,
197
        .insn_flags = CPU_MIPS32R2,
198
        .mmu_type = MMU_TYPE_R4000,
199
    },
200 201 202
    {
        .name = "4KEm",
        .CP0_PRid = 0x00019100,
203
        .CP0_Config0 = MIPS_CONFIG0 | (0x1 << CP0C0_AR) |
A
aurel32 已提交
204
                       (MMU_TYPE_FMT << CP0C0_MT),
205
        .CP0_Config1 = MIPS_CONFIG1 |
A
aurel32 已提交
206
                       (0 << CP0C1_IS) | (3 << CP0C1_IL) | (1 << CP0C1_IA) |
207 208
                       (0 << CP0C1_DS) | (3 << CP0C1_DL) | (1 << CP0C1_DA) |
                       (1 << CP0C1_CA),
209 210
        .CP0_Config2 = MIPS_CONFIG2,
        .CP0_Config3 = MIPS_CONFIG3,
211 212
        .CP0_LLAddr_rw_bitmask = 0,
        .CP0_LLAddr_shift = 4,
213 214 215
        .SYNCI_Step = 32,
        .CCRes = 2,
        .CP0_Status_rw_bitmask = 0x1258FF17,
216 217
        .SEGBITS = 32,
        .PABITS = 32,
218
        .insn_flags = CPU_MIPS32R2 | ASE_MIPS16,
219
        .mmu_type = MMU_TYPE_FMT,
220
    },
221 222 223
    {
        .name = "24Kc",
        .CP0_PRid = 0x00019300,
224
        .CP0_Config0 = MIPS_CONFIG0 | (0x1 << CP0C0_AR) |
A
aurel32 已提交
225
                       (MMU_TYPE_R4000 << CP0C0_MT),
226
        .CP0_Config1 = MIPS_CONFIG1 | (15 << CP0C1_MMU) |
A
aurel32 已提交
227
                       (0 << CP0C1_IS) | (3 << CP0C1_IL) | (1 << CP0C1_IA) |
228 229
                       (0 << CP0C1_DS) | (3 << CP0C1_DL) | (1 << CP0C1_DA) |
                       (1 << CP0C1_CA),
230
        .CP0_Config2 = MIPS_CONFIG2,
231
        .CP0_Config3 = MIPS_CONFIG3 | (0 << CP0C3_VInt),
232 233
        .CP0_LLAddr_rw_bitmask = 0,
        .CP0_LLAddr_shift = 4,
T
ths 已提交
234 235
        .SYNCI_Step = 32,
        .CCRes = 2,
236
        /* No DSP implemented. */
237
        .CP0_Status_rw_bitmask = 0x1278FF1F,
238 239
        .SEGBITS = 32,
        .PABITS = 32,
240
        .insn_flags = CPU_MIPS32R2 | ASE_MIPS16,
241
        .mmu_type = MMU_TYPE_R4000,
242 243 244 245
    },
    {
        .name = "24Kf",
        .CP0_PRid = 0x00019300,
246 247
        .CP0_Config0 = MIPS_CONFIG0 | (0x1 << CP0C0_AR) |
                    (MMU_TYPE_R4000 << CP0C0_MT),
248
        .CP0_Config1 = MIPS_CONFIG1 | (1 << CP0C1_FP) | (15 << CP0C1_MMU) |
A
aurel32 已提交
249
                       (0 << CP0C1_IS) | (3 << CP0C1_IL) | (1 << CP0C1_IA) |
250 251
                       (0 << CP0C1_DS) | (3 << CP0C1_DL) | (1 << CP0C1_DA) |
                       (1 << CP0C1_CA),
252
        .CP0_Config2 = MIPS_CONFIG2,
253
        .CP0_Config3 = MIPS_CONFIG3 | (0 << CP0C3_VInt),
254 255
        .CP0_LLAddr_rw_bitmask = 0,
        .CP0_LLAddr_shift = 4,
T
ths 已提交
256 257
        .SYNCI_Step = 32,
        .CCRes = 2,
258
        /* No DSP implemented. */
259
        .CP0_Status_rw_bitmask = 0x3678FF1F,
260 261
        .CP1_fcr0 = (1 << FCR0_F64) | (1 << FCR0_L) | (1 << FCR0_W) |
                    (1 << FCR0_D) | (1 << FCR0_S) | (0x93 << FCR0_PRID),
262 263
        .SEGBITS = 32,
        .PABITS = 32,
264
        .insn_flags = CPU_MIPS32R2 | ASE_MIPS16,
265
        .mmu_type = MMU_TYPE_R4000,
266
    },
267 268 269
    {
        .name = "34Kf",
        .CP0_PRid = 0x00019500,
270
        .CP0_Config0 = MIPS_CONFIG0 | (0x1 << CP0C0_AR) |
A
aurel32 已提交
271
                       (MMU_TYPE_R4000 << CP0C0_MT),
272
        .CP0_Config1 = MIPS_CONFIG1 | (1 << CP0C1_FP) | (15 << CP0C1_MMU) |
A
aurel32 已提交
273
                       (0 << CP0C1_IS) | (3 << CP0C1_IL) | (1 << CP0C1_IA) |
274 275
                       (0 << CP0C1_DS) | (3 << CP0C1_DL) | (1 << CP0C1_DA) |
                       (1 << CP0C1_CA),
276
        .CP0_Config2 = MIPS_CONFIG2,
277 278
        .CP0_Config3 = MIPS_CONFIG3 | (1 << CP0C3_VInt) | (1 << CP0C3_MT) |
                       (1 << CP0C3_DSPP),
279 280
        .CP0_LLAddr_rw_bitmask = 0,
        .CP0_LLAddr_shift = 0,
281 282
        .SYNCI_Step = 32,
        .CCRes = 2,
283
        .CP0_Status_rw_bitmask = 0x3778FF1F,
284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307
        .CP0_TCStatus_rw_bitmask = (0 << CP0TCSt_TCU3) | (0 << CP0TCSt_TCU2) |
                    (1 << CP0TCSt_TCU1) | (1 << CP0TCSt_TCU0) |
                    (0 << CP0TCSt_TMX) | (1 << CP0TCSt_DT) |
                    (1 << CP0TCSt_DA) | (1 << CP0TCSt_A) |
                    (0x3 << CP0TCSt_TKSU) | (1 << CP0TCSt_IXMT) |
                    (0xff << CP0TCSt_TASID),
        .CP1_fcr0 = (1 << FCR0_F64) | (1 << FCR0_L) | (1 << FCR0_W) |
                    (1 << FCR0_D) | (1 << FCR0_S) | (0x95 << FCR0_PRID),
        .CP0_SRSCtl = (0xf << CP0SRSCtl_HSS),
        .CP0_SRSConf0_rw_bitmask = 0x3fffffff,
        .CP0_SRSConf0 = (1 << CP0SRSC0_M) | (0x3fe << CP0SRSC0_SRS3) |
                    (0x3fe << CP0SRSC0_SRS2) | (0x3fe << CP0SRSC0_SRS1),
        .CP0_SRSConf1_rw_bitmask = 0x3fffffff,
        .CP0_SRSConf1 = (1 << CP0SRSC1_M) | (0x3fe << CP0SRSC1_SRS6) |
                    (0x3fe << CP0SRSC1_SRS5) | (0x3fe << CP0SRSC1_SRS4),
        .CP0_SRSConf2_rw_bitmask = 0x3fffffff,
        .CP0_SRSConf2 = (1 << CP0SRSC2_M) | (0x3fe << CP0SRSC2_SRS9) |
                    (0x3fe << CP0SRSC2_SRS8) | (0x3fe << CP0SRSC2_SRS7),
        .CP0_SRSConf3_rw_bitmask = 0x3fffffff,
        .CP0_SRSConf3 = (1 << CP0SRSC3_M) | (0x3fe << CP0SRSC3_SRS12) |
                    (0x3fe << CP0SRSC3_SRS11) | (0x3fe << CP0SRSC3_SRS10),
        .CP0_SRSConf4_rw_bitmask = 0x3fffffff,
        .CP0_SRSConf4 = (0x3fe << CP0SRSC4_SRS15) |
                    (0x3fe << CP0SRSC4_SRS14) | (0x3fe << CP0SRSC4_SRS13),
308 309
        .SEGBITS = 32,
        .PABITS = 32,
310
        .insn_flags = CPU_MIPS32R2 | ASE_MIPS16 | ASE_DSP | ASE_MT,
311
        .mmu_type = MMU_TYPE_R4000,
312
    },
J
Jia Liu 已提交
313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335
    {
        .name = "74Kf",
        .CP0_PRid = 0x00019700,
        .CP0_Config0 = MIPS_CONFIG0 | (0x1 << CP0C0_AR) |
                    (MMU_TYPE_R4000 << CP0C0_MT),
        .CP0_Config1 = MIPS_CONFIG1 | (1 << CP0C1_FP) | (15 << CP0C1_MMU) |
                       (0 << CP0C1_IS) | (3 << CP0C1_IL) | (1 << CP0C1_IA) |
                       (0 << CP0C1_DS) | (3 << CP0C1_DL) | (1 << CP0C1_DA) |
                       (1 << CP0C1_CA),
        .CP0_Config2 = MIPS_CONFIG2,
        .CP0_Config3 = MIPS_CONFIG3 | (0 << CP0C3_VInt) | (1 << CP0C3_DSPP),
        .CP0_LLAddr_rw_bitmask = 0,
        .CP0_LLAddr_shift = 4,
        .SYNCI_Step = 32,
        .CCRes = 2,
        .CP0_Status_rw_bitmask = 0x3778FF1F,
        .CP1_fcr0 = (1 << FCR0_F64) | (1 << FCR0_L) | (1 << FCR0_W) |
                    (1 << FCR0_D) | (1 << FCR0_S) | (0x93 << FCR0_PRID),
        .SEGBITS = 32,
        .PABITS = 32,
        .insn_flags = CPU_MIPS32R2 | ASE_MIPS16 | ASE_DSP | ASE_DSPR2,
        .mmu_type = MMU_TYPE_R4000,
    },
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360
    {
        /* A generic CPU providing MIPS32 Release 5 features.
           FIXME: Eventually this should be replaced by a real CPU model. */
        .name = "mips32r5-generic",
        .CP0_PRid = 0x00019700,
        .CP0_Config0 = MIPS_CONFIG0 | (0x1 << CP0C0_AR) |
                    (MMU_TYPE_R4000 << CP0C0_MT),
        .CP0_Config1 = MIPS_CONFIG1 | (1 << CP0C1_FP) | (15 << CP0C1_MMU) |
                       (0 << CP0C1_IS) | (3 << CP0C1_IL) | (1 << CP0C1_IA) |
                       (0 << CP0C1_DS) | (3 << CP0C1_DL) | (1 << CP0C1_DA) |
                       (1 << CP0C1_CA),
        .CP0_Config2 = MIPS_CONFIG2,
        .CP0_Config3 = MIPS_CONFIG3,
        .CP0_LLAddr_rw_bitmask = 0,
        .CP0_LLAddr_shift = 4,
        .SYNCI_Step = 32,
        .CCRes = 2,
        .CP0_Status_rw_bitmask = 0x3778FF1F,
        .CP1_fcr0 = (1 << FCR0_F64) | (1 << FCR0_L) | (1 << FCR0_W) |
                    (1 << FCR0_D) | (1 << FCR0_S) | (0x93 << FCR0_PRID),
        .SEGBITS = 32,
        .PABITS = 32,
        .insn_flags = CPU_MIPS32R5 | ASE_MIPS16 | ASE_DSP | ASE_DSPR2,
        .mmu_type = MMU_TYPE_R4000,
    },
361
#if defined(TARGET_MIPS64)
362 363 364
    {
        .name = "R4000",
        .CP0_PRid = 0x00000400,
365 366
        /* No L2 cache, icache size 8k, dcache size 8k, uncached coherency. */
        .CP0_Config0 = (1 << 17) | (0x1 << 9) | (0x1 << 6) | (0x2 << CP0C0_K0),
A
aurel32 已提交
367
        /* Note: Config1 is only used internally, the R4000 has only Config0. */
368
        .CP0_Config1 = (1 << CP0C1_FP) | (47 << CP0C1_MMU),
369 370
        .CP0_LLAddr_rw_bitmask = 0xFFFFFFFF,
        .CP0_LLAddr_shift = 4,
T
ths 已提交
371 372
        .SYNCI_Step = 16,
        .CCRes = 2,
373
        .CP0_Status_rw_bitmask = 0x3678FFFF,
A
aurel32 已提交
374
        /* The R4000 has a full 64bit FPU but doesn't use the fcr0 bits. */
375
        .CP1_fcr0 = (0x5 << FCR0_PRID) | (0x0 << FCR0_REV),
T
ths 已提交
376
        .SEGBITS = 40,
377
        .PABITS = 36,
378
        .insn_flags = CPU_MIPS3,
379
        .mmu_type = MMU_TYPE_R4000,
380
    },
381 382 383 384 385 386
    {
        .name = "VR5432",
        .CP0_PRid = 0x00005400,
        /* No L2 cache, icache size 8k, dcache size 8k, uncached coherency. */
        .CP0_Config0 = (1 << 17) | (0x1 << 9) | (0x1 << 6) | (0x2 << CP0C0_K0),
        .CP0_Config1 = (1 << CP0C1_FP) | (47 << CP0C1_MMU),
387 388
        .CP0_LLAddr_rw_bitmask = 0xFFFFFFFFL,
        .CP0_LLAddr_shift = 4,
389 390 391 392 393 394 395 396 397 398
        .SYNCI_Step = 16,
        .CCRes = 2,
        .CP0_Status_rw_bitmask = 0x3678FFFF,
        /* The VR5432 has a full 64bit FPU but doesn't use the fcr0 bits. */
        .CP1_fcr0 = (0x54 << FCR0_PRID) | (0x0 << FCR0_REV),
        .SEGBITS = 40,
        .PABITS = 32,
        .insn_flags = CPU_VR54XX,
        .mmu_type = MMU_TYPE_R4000,
    },
399 400 401
    {
        .name = "5Kc",
        .CP0_PRid = 0x00018100,
T
ths 已提交
402
        .CP0_Config0 = MIPS_CONFIG0 | (0x2 << CP0C0_AT) |
A
aurel32 已提交
403
                       (MMU_TYPE_R4000 << CP0C0_MT),
404
        .CP0_Config1 = MIPS_CONFIG1 | (31 << CP0C1_MMU) |
A
aurel32 已提交
405 406 407
                       (1 << CP0C1_IS) | (4 << CP0C1_IL) | (1 << CP0C1_IA) |
                       (1 << CP0C1_DS) | (4 << CP0C1_DL) | (1 << CP0C1_DA) |
                       (1 << CP0C1_PC) | (1 << CP0C1_WR) | (1 << CP0C1_EP),
408 409
        .CP0_Config2 = MIPS_CONFIG2,
        .CP0_Config3 = MIPS_CONFIG3,
410 411
        .CP0_LLAddr_rw_bitmask = 0,
        .CP0_LLAddr_shift = 4,
412 413
        .SYNCI_Step = 32,
        .CCRes = 2,
414
        .CP0_Status_rw_bitmask = 0x32F8FFFF,
T
ths 已提交
415
        .SEGBITS = 42,
416
        .PABITS = 36,
417
        .insn_flags = CPU_MIPS64,
418
        .mmu_type = MMU_TYPE_R4000,
419 420 421 422
    },
    {
        .name = "5Kf",
        .CP0_PRid = 0x00018100,
T
ths 已提交
423
        .CP0_Config0 = MIPS_CONFIG0 | (0x2 << CP0C0_AT) |
A
aurel32 已提交
424
                       (MMU_TYPE_R4000 << CP0C0_MT),
425
        .CP0_Config1 = MIPS_CONFIG1 | (1 << CP0C1_FP) | (31 << CP0C1_MMU) |
A
aurel32 已提交
426 427 428
                       (1 << CP0C1_IS) | (4 << CP0C1_IL) | (1 << CP0C1_IA) |
                       (1 << CP0C1_DS) | (4 << CP0C1_DL) | (1 << CP0C1_DA) |
                       (1 << CP0C1_PC) | (1 << CP0C1_WR) | (1 << CP0C1_EP),
429 430
        .CP0_Config2 = MIPS_CONFIG2,
        .CP0_Config3 = MIPS_CONFIG3,
431 432
        .CP0_LLAddr_rw_bitmask = 0,
        .CP0_LLAddr_shift = 4,
433 434
        .SYNCI_Step = 32,
        .CCRes = 2,
435
        .CP0_Status_rw_bitmask = 0x36F8FFFF,
A
aurel32 已提交
436
        /* The 5Kf has F64 / L / W but doesn't use the fcr0 bits. */
437 438
        .CP1_fcr0 = (1 << FCR0_D) | (1 << FCR0_S) |
                    (0x81 << FCR0_PRID) | (0x0 << FCR0_REV),
T
ths 已提交
439
        .SEGBITS = 42,
440
        .PABITS = 36,
441
        .insn_flags = CPU_MIPS64,
442
        .mmu_type = MMU_TYPE_R4000,
443 444 445
    },
    {
        .name = "20Kc",
A
aurel32 已提交
446
        /* We emulate a later version of the 20Kc, earlier ones had a broken
T
ths 已提交
447 448
           WAIT instruction. */
        .CP0_PRid = 0x000182a0,
T
ths 已提交
449
        .CP0_Config0 = MIPS_CONFIG0 | (0x2 << CP0C0_AT) |
450
                    (MMU_TYPE_R4000 << CP0C0_MT) | (1 << CP0C0_VI),
451
        .CP0_Config1 = MIPS_CONFIG1 | (1 << CP0C1_FP) | (47 << CP0C1_MMU) |
A
aurel32 已提交
452 453 454
                       (2 << CP0C1_IS) | (4 << CP0C1_IL) | (3 << CP0C1_IA) |
                       (2 << CP0C1_DS) | (4 << CP0C1_DL) | (3 << CP0C1_DA) |
                       (1 << CP0C1_PC) | (1 << CP0C1_WR) | (1 << CP0C1_EP),
455 456
        .CP0_Config2 = MIPS_CONFIG2,
        .CP0_Config3 = MIPS_CONFIG3,
457 458
        .CP0_LLAddr_rw_bitmask = 0,
        .CP0_LLAddr_shift = 0,
459
        .SYNCI_Step = 32,
T
ths 已提交
460
        .CCRes = 1,
461
        .CP0_Status_rw_bitmask = 0x36FBFFFF,
A
aurel32 已提交
462
        /* The 20Kc has F64 / L / W but doesn't use the fcr0 bits. */
463
        .CP1_fcr0 = (1 << FCR0_3D) | (1 << FCR0_PS) |
464
                    (1 << FCR0_D) | (1 << FCR0_S) |
465
                    (0x82 << FCR0_PRID) | (0x0 << FCR0_REV),
T
ths 已提交
466
        .SEGBITS = 40,
467
        .PABITS = 36,
468
        .insn_flags = CPU_MIPS64 | ASE_MIPS3D,
469
        .mmu_type = MMU_TYPE_R4000,
470
    },
T
ths 已提交
471
    {
A
aurel32 已提交
472
        /* A generic CPU providing MIPS64 Release 2 features.
T
ths 已提交
473 474
           FIXME: Eventually this should be replaced by a real CPU model. */
        .name = "MIPS64R2-generic",
T
ths 已提交
475
        .CP0_PRid = 0x00010000,
476
        .CP0_Config0 = MIPS_CONFIG0 | (0x1 << CP0C0_AR) | (0x2 << CP0C0_AT) |
A
aurel32 已提交
477
                       (MMU_TYPE_R4000 << CP0C0_MT),
T
ths 已提交
478
        .CP0_Config1 = MIPS_CONFIG1 | (1 << CP0C1_FP) | (63 << CP0C1_MMU) |
A
aurel32 已提交
479 480 481
                       (2 << CP0C1_IS) | (4 << CP0C1_IL) | (3 << CP0C1_IA) |
                       (2 << CP0C1_DS) | (4 << CP0C1_DL) | (3 << CP0C1_DA) |
                       (1 << CP0C1_PC) | (1 << CP0C1_WR) | (1 << CP0C1_EP),
T
ths 已提交
482
        .CP0_Config2 = MIPS_CONFIG2,
483
        .CP0_Config3 = MIPS_CONFIG3 | (1 << CP0C3_LPA),
484 485
        .CP0_LLAddr_rw_bitmask = 0,
        .CP0_LLAddr_shift = 0,
T
ths 已提交
486 487 488
        .SYNCI_Step = 32,
        .CCRes = 2,
        .CP0_Status_rw_bitmask = 0x36FBFFFF,
489 490 491
        .CP1_fcr0 = (1 << FCR0_F64) | (1 << FCR0_3D) | (1 << FCR0_PS) |
                    (1 << FCR0_L) | (1 << FCR0_W) | (1 << FCR0_D) |
                    (1 << FCR0_S) | (0x00 << FCR0_PRID) | (0x0 << FCR0_REV),
492 493 494 495 496
        .SEGBITS = 42,
        /* The architectural limit is 59, but we have hardcoded 36 bit
           in some places...
        .PABITS = 59, */ /* the architectural limit */
        .PABITS = 36,
T
ths 已提交
497
        .insn_flags = CPU_MIPS64R2 | ASE_MIPS3D,
498
        .mmu_type = MMU_TYPE_R4000,
T
ths 已提交
499
    },
500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526
    {
        .name = "Loongson-2E",
        .CP0_PRid = 0x6302,
        /*64KB I-cache and d-cache. 4 way with 32 bit cache line size*/
        .CP0_Config0 = (0x1<<17) | (0x1<<16) | (0x1<<11) | (0x1<<8) | (0x1<<5) |
                       (0x1<<4) | (0x1<<1),
        /* Note: Config1 is only used internally, Loongson-2E has only Config0. */
        .CP0_Config1 = (1 << CP0C1_FP) | (47 << CP0C1_MMU),
        .SYNCI_Step = 16,
        .CCRes = 2,
        .CP0_Status_rw_bitmask = 0x35D0FFFF,
        .CP1_fcr0 = (0x5 << FCR0_PRID) | (0x1 << FCR0_REV),
        .SEGBITS = 40,
        .PABITS = 40,
        .insn_flags = CPU_LOONGSON2E,
        .mmu_type = MMU_TYPE_R4000,
    },
    {
      .name = "Loongson-2F",
      .CP0_PRid = 0x6303,
      /*64KB I-cache and d-cache. 4 way with 32 bit cache line size*/
      .CP0_Config0 = (0x1<<17) | (0x1<<16) | (0x1<<11) | (0x1<<8) | (0x1<<5) |
                     (0x1<<4) | (0x1<<1),
      /* Note: Config1 is only used internally, Loongson-2F has only Config0. */
      .CP0_Config1 = (1 << CP0C1_FP) | (47 << CP0C1_MMU),
      .SYNCI_Step = 16,
      .CCRes = 2,
S
Stefan Weil 已提交
527
      .CP0_Status_rw_bitmask = 0xF5D0FF1F,   /*bit5:7 not writable*/
528 529 530 531 532 533
      .CP1_fcr0 = (0x5 << FCR0_PRID) | (0x1 << FCR0_REV),
      .SEGBITS = 40,
      .PABITS = 40,
      .insn_flags = CPU_LOONGSON2F,
      .mmu_type = MMU_TYPE_R4000,
    },
J
Jia Liu 已提交
534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562
    {
        /* A generic CPU providing MIPS64 ASE DSP 2 features.
           FIXME: Eventually this should be replaced by a real CPU model. */
        .name = "mips64dspr2",
        .CP0_PRid = 0x00010000,
        .CP0_Config0 = MIPS_CONFIG0 | (0x1 << CP0C0_AR) | (0x2 << CP0C0_AT) |
                       (MMU_TYPE_R4000 << CP0C0_MT),
        .CP0_Config1 = MIPS_CONFIG1 | (1 << CP0C1_FP) | (63 << CP0C1_MMU) |
                       (2 << CP0C1_IS) | (4 << CP0C1_IL) | (3 << CP0C1_IA) |
                       (2 << CP0C1_DS) | (4 << CP0C1_DL) | (3 << CP0C1_DA) |
                       (1 << CP0C1_PC) | (1 << CP0C1_WR) | (1 << CP0C1_EP),
        .CP0_Config2 = MIPS_CONFIG2,
        .CP0_Config3 = MIPS_CONFIG3 | (1 << CP0C3_LPA),
        .CP0_LLAddr_rw_bitmask = 0,
        .CP0_LLAddr_shift = 0,
        .SYNCI_Step = 32,
        .CCRes = 2,
        .CP0_Status_rw_bitmask = 0x37FBFFFF,
        .CP1_fcr0 = (1 << FCR0_F64) | (1 << FCR0_3D) | (1 << FCR0_PS) |
                    (1 << FCR0_L) | (1 << FCR0_W) | (1 << FCR0_D) |
                    (1 << FCR0_S) | (0x00 << FCR0_PRID) | (0x0 << FCR0_REV),
        .SEGBITS = 42,
        /* The architectural limit is 59, but we have hardcoded 36 bit
           in some places...
        .PABITS = 59, */ /* the architectural limit */
        .PABITS = 36,
        .insn_flags = CPU_MIPS64R2 | ASE_DSP | ASE_DSPR2,
        .mmu_type = MMU_TYPE_R4000,
    },
563

564 565 566
#endif
};

A
Anthony Liguori 已提交
567
static const mips_def_t *cpu_mips_find_by_name (const char *name)
568
{
B
bellard 已提交
569
    int i;
570

571
    for (i = 0; i < ARRAY_SIZE(mips_defs); i++) {
572
        if (strcasecmp(name, mips_defs[i].name) == 0) {
B
bellard 已提交
573
            return &mips_defs[i];
574 575
        }
    }
B
bellard 已提交
576
    return NULL;
577 578
}

579
void mips_cpu_list (FILE *f, fprintf_function cpu_fprintf)
580 581 582
{
    int i;

583
    for (i = 0; i < ARRAY_SIZE(mips_defs); i++) {
584 585 586 587 588
        (*cpu_fprintf)(f, "MIPS '%s'\n",
                       mips_defs[i].name);
    }
}

T
ths 已提交
589
#ifndef CONFIG_USER_ONLY
A
Anthony Liguori 已提交
590
static void no_mmu_init (CPUMIPSState *env, const mips_def_t *def)
591
{
592 593
    env->tlb->nb_tlb = 1;
    env->tlb->map_address = &no_mmu_map_address;
594 595
}

A
Anthony Liguori 已提交
596
static void fixed_mmu_init (CPUMIPSState *env, const mips_def_t *def)
597
{
598 599
    env->tlb->nb_tlb = 1;
    env->tlb->map_address = &fixed_mmu_map_address;
600 601
}

A
Anthony Liguori 已提交
602
static void r4k_mmu_init (CPUMIPSState *env, const mips_def_t *def)
603
{
604 605
    env->tlb->nb_tlb = 1 + ((def->CP0_Config1 >> CP0C1_MMU) & 63);
    env->tlb->map_address = &r4k_map_address;
606 607 608 609
    env->tlb->helper_tlbwi = r4k_helper_tlbwi;
    env->tlb->helper_tlbwr = r4k_helper_tlbwr;
    env->tlb->helper_tlbp = r4k_helper_tlbp;
    env->tlb->helper_tlbr = r4k_helper_tlbr;
610 611
}

A
Anthony Liguori 已提交
612
static void mmu_init (CPUMIPSState *env, const mips_def_t *def)
613
{
614
    env->tlb = g_malloc0(sizeof(CPUMIPSTLBContext));
615

616 617
    switch (def->mmu_type) {
        case MMU_TYPE_NONE:
618 619
            no_mmu_init(env, def);
            break;
620
        case MMU_TYPE_R4000:
621 622
            r4k_mmu_init(env, def);
            break;
623
        case MMU_TYPE_FMT:
624 625
            fixed_mmu_init(env, def);
            break;
626 627 628
        case MMU_TYPE_R3000:
        case MMU_TYPE_R6000:
        case MMU_TYPE_R8000:
629 630 631
        default:
            cpu_abort(env, "MMU type not supported\n");
    }
632
}
T
ths 已提交
633
#endif /* CONFIG_USER_ONLY */
634

A
Anthony Liguori 已提交
635
static void fpu_init (CPUMIPSState *env, const mips_def_t *def)
636
{
637 638 639 640
    int i;

    for (i = 0; i < MIPS_FPU_MAX; i++)
        env->fpus[i].fcr0 = def->CP1_fcr0;
641

642
    memcpy(&env->active_fpu, &env->fpus[0], sizeof(env->active_fpu));
643 644
}

A
Anthony Liguori 已提交
645
static void mvp_init (CPUMIPSState *env, const mips_def_t *def)
646
{
647
    env->mvp = g_malloc0(sizeof(CPUMIPSMVPContext));
648 649 650 651 652 653 654 655 656 657 658

    /* MVPConf1 implemented, TLB sharable, no gating storage support,
       programmable cache partitioning implemented, number of allocatable
       and sharable TLB entries, MVP has allocatable TCs, 2 VPEs
       implemented, 5 TCs implemented. */
    env->mvp->CP0_MVPConf0 = (1 << CP0MVPC0_M) | (1 << CP0MVPC0_TLBS) |
                             (0 << CP0MVPC0_GS) | (1 << CP0MVPC0_PCP) |
// TODO: actually do 2 VPEs.
//                             (1 << CP0MVPC0_TCA) | (0x1 << CP0MVPC0_PVPE) |
//                             (0x04 << CP0MVPC0_PTC);
                             (1 << CP0MVPC0_TCA) | (0x0 << CP0MVPC0_PVPE) |
659
                             (0x00 << CP0MVPC0_PTC);
660
#if !defined(CONFIG_USER_ONLY)
T
ths 已提交
661
    /* Usermode has no TLB support */
662 663
    env->mvp->CP0_MVPConf0 |= (env->tlb->nb_tlb << CP0MVPC0_PTLBE);
#endif
T
ths 已提交
664

665 666 667 668 669 670
    /* Allocatable CP1 have media extensions, allocatable CP1 have FP support,
       no UDI implemented, no CP2 implemented, 1 CP1 implemented. */
    env->mvp->CP0_MVPConf1 = (1 << CP0MVPC1_CIM) | (1 << CP0MVPC1_CIF) |
                             (0x0 << CP0MVPC1_PCX) | (0x0 << CP0MVPC1_PCP2) |
                             (0x1 << CP0MVPC1_PCP1);
}