translate_init.c 24.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
        .CP0_Config3 = MIPS_CONFIG3 | (1 << CP0C3_VInt) | (1 << CP0C3_MT),
278 279
        .CP0_LLAddr_rw_bitmask = 0,
        .CP0_LLAddr_shift = 0,
280 281 282
        .SYNCI_Step = 32,
        .CCRes = 2,
        /* No DSP implemented. */
283
        .CP0_Status_rw_bitmask = 0x3678FF1F,
284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308
        /* No DSP implemented. */
        .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),
309 310
        .SEGBITS = 32,
        .PABITS = 32,
311
        .insn_flags = CPU_MIPS32R2 | ASE_MIPS16 | ASE_DSP | ASE_MT,
312
        .mmu_type = MMU_TYPE_R4000,
313
    },
J
Jia Liu 已提交
314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336
    {
        .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,
    },
337
#if defined(TARGET_MIPS64)
338 339 340
    {
        .name = "R4000",
        .CP0_PRid = 0x00000400,
341 342
        /* No L2 cache, icache size 8k, dcache size 8k, uncached coherency. */
        .CP0_Config0 = (1 << 17) | (0x1 << 9) | (0x1 << 6) | (0x2 << CP0C0_K0),
A
aurel32 已提交
343
        /* Note: Config1 is only used internally, the R4000 has only Config0. */
344
        .CP0_Config1 = (1 << CP0C1_FP) | (47 << CP0C1_MMU),
345 346
        .CP0_LLAddr_rw_bitmask = 0xFFFFFFFF,
        .CP0_LLAddr_shift = 4,
T
ths 已提交
347 348
        .SYNCI_Step = 16,
        .CCRes = 2,
349
        .CP0_Status_rw_bitmask = 0x3678FFFF,
A
aurel32 已提交
350
        /* The R4000 has a full 64bit FPU but doesn't use the fcr0 bits. */
351
        .CP1_fcr0 = (0x5 << FCR0_PRID) | (0x0 << FCR0_REV),
T
ths 已提交
352
        .SEGBITS = 40,
353
        .PABITS = 36,
354
        .insn_flags = CPU_MIPS3,
355
        .mmu_type = MMU_TYPE_R4000,
356
    },
357 358 359 360 361 362
    {
        .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),
363 364
        .CP0_LLAddr_rw_bitmask = 0xFFFFFFFFL,
        .CP0_LLAddr_shift = 4,
365 366 367 368 369 370 371 372 373 374
        .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,
    },
375 376 377
    {
        .name = "5Kc",
        .CP0_PRid = 0x00018100,
T
ths 已提交
378
        .CP0_Config0 = MIPS_CONFIG0 | (0x2 << CP0C0_AT) |
A
aurel32 已提交
379
                       (MMU_TYPE_R4000 << CP0C0_MT),
380
        .CP0_Config1 = MIPS_CONFIG1 | (31 << CP0C1_MMU) |
A
aurel32 已提交
381 382 383
                       (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),
384 385
        .CP0_Config2 = MIPS_CONFIG2,
        .CP0_Config3 = MIPS_CONFIG3,
386 387
        .CP0_LLAddr_rw_bitmask = 0,
        .CP0_LLAddr_shift = 4,
388 389
        .SYNCI_Step = 32,
        .CCRes = 2,
390
        .CP0_Status_rw_bitmask = 0x32F8FFFF,
T
ths 已提交
391
        .SEGBITS = 42,
392
        .PABITS = 36,
393
        .insn_flags = CPU_MIPS64,
394
        .mmu_type = MMU_TYPE_R4000,
395 396 397 398
    },
    {
        .name = "5Kf",
        .CP0_PRid = 0x00018100,
T
ths 已提交
399
        .CP0_Config0 = MIPS_CONFIG0 | (0x2 << CP0C0_AT) |
A
aurel32 已提交
400
                       (MMU_TYPE_R4000 << CP0C0_MT),
401
        .CP0_Config1 = MIPS_CONFIG1 | (1 << CP0C1_FP) | (31 << CP0C1_MMU) |
A
aurel32 已提交
402 403 404
                       (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),
405 406
        .CP0_Config2 = MIPS_CONFIG2,
        .CP0_Config3 = MIPS_CONFIG3,
407 408
        .CP0_LLAddr_rw_bitmask = 0,
        .CP0_LLAddr_shift = 4,
409 410
        .SYNCI_Step = 32,
        .CCRes = 2,
411
        .CP0_Status_rw_bitmask = 0x36F8FFFF,
A
aurel32 已提交
412
        /* The 5Kf has F64 / L / W but doesn't use the fcr0 bits. */
413 414
        .CP1_fcr0 = (1 << FCR0_D) | (1 << FCR0_S) |
                    (0x81 << FCR0_PRID) | (0x0 << FCR0_REV),
T
ths 已提交
415
        .SEGBITS = 42,
416
        .PABITS = 36,
417
        .insn_flags = CPU_MIPS64,
418
        .mmu_type = MMU_TYPE_R4000,
419 420 421
    },
    {
        .name = "20Kc",
A
aurel32 已提交
422
        /* We emulate a later version of the 20Kc, earlier ones had a broken
T
ths 已提交
423 424
           WAIT instruction. */
        .CP0_PRid = 0x000182a0,
T
ths 已提交
425
        .CP0_Config0 = MIPS_CONFIG0 | (0x2 << CP0C0_AT) |
426
                    (MMU_TYPE_R4000 << CP0C0_MT) | (1 << CP0C0_VI),
427
        .CP0_Config1 = MIPS_CONFIG1 | (1 << CP0C1_FP) | (47 << CP0C1_MMU) |
A
aurel32 已提交
428 429 430
                       (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),
431 432
        .CP0_Config2 = MIPS_CONFIG2,
        .CP0_Config3 = MIPS_CONFIG3,
433 434
        .CP0_LLAddr_rw_bitmask = 0,
        .CP0_LLAddr_shift = 0,
435
        .SYNCI_Step = 32,
T
ths 已提交
436
        .CCRes = 1,
437
        .CP0_Status_rw_bitmask = 0x36FBFFFF,
A
aurel32 已提交
438
        /* The 20Kc has F64 / L / W but doesn't use the fcr0 bits. */
439
        .CP1_fcr0 = (1 << FCR0_3D) | (1 << FCR0_PS) |
440
                    (1 << FCR0_D) | (1 << FCR0_S) |
441
                    (0x82 << FCR0_PRID) | (0x0 << FCR0_REV),
T
ths 已提交
442
        .SEGBITS = 40,
443
        .PABITS = 36,
444
        .insn_flags = CPU_MIPS64 | ASE_MIPS3D,
445
        .mmu_type = MMU_TYPE_R4000,
446
    },
T
ths 已提交
447
    {
A
aurel32 已提交
448
        /* A generic CPU providing MIPS64 Release 2 features.
T
ths 已提交
449 450
           FIXME: Eventually this should be replaced by a real CPU model. */
        .name = "MIPS64R2-generic",
T
ths 已提交
451
        .CP0_PRid = 0x00010000,
452
        .CP0_Config0 = MIPS_CONFIG0 | (0x1 << CP0C0_AR) | (0x2 << CP0C0_AT) |
A
aurel32 已提交
453
                       (MMU_TYPE_R4000 << CP0C0_MT),
T
ths 已提交
454
        .CP0_Config1 = MIPS_CONFIG1 | (1 << CP0C1_FP) | (63 << CP0C1_MMU) |
A
aurel32 已提交
455 456 457
                       (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 已提交
458
        .CP0_Config2 = MIPS_CONFIG2,
459
        .CP0_Config3 = MIPS_CONFIG3 | (1 << CP0C3_LPA),
460 461
        .CP0_LLAddr_rw_bitmask = 0,
        .CP0_LLAddr_shift = 0,
T
ths 已提交
462 463 464
        .SYNCI_Step = 32,
        .CCRes = 2,
        .CP0_Status_rw_bitmask = 0x36FBFFFF,
465 466 467
        .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),
468 469 470 471 472
        .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 已提交
473
        .insn_flags = CPU_MIPS64R2 | ASE_MIPS3D,
474
        .mmu_type = MMU_TYPE_R4000,
T
ths 已提交
475
    },
476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502
    {
        .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 已提交
503
      .CP0_Status_rw_bitmask = 0xF5D0FF1F,   /*bit5:7 not writable*/
504 505 506 507 508 509
      .CP1_fcr0 = (0x5 << FCR0_PRID) | (0x1 << FCR0_REV),
      .SEGBITS = 40,
      .PABITS = 40,
      .insn_flags = CPU_LOONGSON2F,
      .mmu_type = MMU_TYPE_R4000,
    },
J
Jia Liu 已提交
510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538
    {
        /* 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,
    },
539

540 541 542
#endif
};

A
Anthony Liguori 已提交
543
static const mips_def_t *cpu_mips_find_by_name (const char *name)
544
{
B
bellard 已提交
545
    int i;
546

547
    for (i = 0; i < ARRAY_SIZE(mips_defs); i++) {
548
        if (strcasecmp(name, mips_defs[i].name) == 0) {
B
bellard 已提交
549
            return &mips_defs[i];
550 551
        }
    }
B
bellard 已提交
552
    return NULL;
553 554
}

555
void mips_cpu_list (FILE *f, fprintf_function cpu_fprintf)
556 557 558
{
    int i;

559
    for (i = 0; i < ARRAY_SIZE(mips_defs); i++) {
560 561 562 563 564
        (*cpu_fprintf)(f, "MIPS '%s'\n",
                       mips_defs[i].name);
    }
}

T
ths 已提交
565
#ifndef CONFIG_USER_ONLY
A
Anthony Liguori 已提交
566
static void no_mmu_init (CPUMIPSState *env, const mips_def_t *def)
567
{
568 569
    env->tlb->nb_tlb = 1;
    env->tlb->map_address = &no_mmu_map_address;
570 571
}

A
Anthony Liguori 已提交
572
static void fixed_mmu_init (CPUMIPSState *env, const mips_def_t *def)
573
{
574 575
    env->tlb->nb_tlb = 1;
    env->tlb->map_address = &fixed_mmu_map_address;
576 577
}

A
Anthony Liguori 已提交
578
static void r4k_mmu_init (CPUMIPSState *env, const mips_def_t *def)
579
{
580 581
    env->tlb->nb_tlb = 1 + ((def->CP0_Config1 >> CP0C1_MMU) & 63);
    env->tlb->map_address = &r4k_map_address;
582 583 584 585
    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;
586 587
}

A
Anthony Liguori 已提交
588
static void mmu_init (CPUMIPSState *env, const mips_def_t *def)
589
{
590
    env->tlb = g_malloc0(sizeof(CPUMIPSTLBContext));
591

592 593
    switch (def->mmu_type) {
        case MMU_TYPE_NONE:
594 595
            no_mmu_init(env, def);
            break;
596
        case MMU_TYPE_R4000:
597 598
            r4k_mmu_init(env, def);
            break;
599
        case MMU_TYPE_FMT:
600 601
            fixed_mmu_init(env, def);
            break;
602 603 604
        case MMU_TYPE_R3000:
        case MMU_TYPE_R6000:
        case MMU_TYPE_R8000:
605 606 607
        default:
            cpu_abort(env, "MMU type not supported\n");
    }
608
}
T
ths 已提交
609
#endif /* CONFIG_USER_ONLY */
610

A
Anthony Liguori 已提交
611
static void fpu_init (CPUMIPSState *env, const mips_def_t *def)
612
{
613 614 615 616
    int i;

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

618
    memcpy(&env->active_fpu, &env->fpus[0], sizeof(env->active_fpu));
619 620
}

A
Anthony Liguori 已提交
621
static void mvp_init (CPUMIPSState *env, const mips_def_t *def)
622
{
623
    env->mvp = g_malloc0(sizeof(CPUMIPSMVPContext));
624 625 626 627 628 629 630 631 632 633 634

    /* 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) |
635
                             (0x00 << CP0MVPC0_PTC);
636
#if !defined(CONFIG_USER_ONLY)
T
ths 已提交
637
    /* Usermode has no TLB support */
638 639
    env->mvp->CP0_MVPConf0 |= (env->tlb->nb_tlb << CP0MVPC0_PTLBE);
#endif
T
ths 已提交
640

641 642 643 644 645 646
    /* 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);
}