blob: 51c571d0e65ea73cac57d82e51d2246e7d1b2f67 [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
24/* Have config1, is MIPS32R1, uses TLB, no virtual icache,
25 uncached coherency */
26#define MIPS_CONFIG0 \
27 ((1 << CP0C0_M) | (0x0 << CP0C0_K23) | (0x0 << CP0C0_KU) | \
28 (0x0 << CP0C0_AT) | (0x0 << CP0C0_AR) | (0x1 << CP0C0_MT) | \
29 (0x2 << CP0C0_K0))
30
thsfcb4a412007-04-17 15:26:47 +000031/* Have config2, 64 sets Icache, 16 bytes Icache line,
ths3953d782007-03-21 11:04:42 +000032 2-way Icache, 64 sets Dcache, 16 bytes Dcache line, 2-way Dcache,
33 no coprocessor2 attached, no MDMX support attached,
34 no performance counters, watch registers present,
35 no code compression, EJTAG present, no FPU */
36#define MIPS_CONFIG1 \
thsfcb4a412007-04-17 15:26:47 +000037((1 << CP0C1_M) | \
ths3953d782007-03-21 11:04:42 +000038 (0x0 << CP0C1_IS) | (0x3 << CP0C1_IL) | (0x1 << CP0C1_IA) | \
39 (0x0 << CP0C1_DS) | (0x3 << CP0C1_DL) | (0x1 << CP0C1_DA) | \
40 (0 << CP0C1_C2) | (0 << CP0C1_MD) | (0 << CP0C1_PC) | \
41 (1 << CP0C1_WR) | (0 << CP0C1_CA) | (1 << CP0C1_EP) | \
42 (0 << CP0C1_FP))
43
44/* Have config3, no tertiary/secondary caches implemented */
45#define MIPS_CONFIG2 \
46((1 << CP0C2_M))
47
48/* No config4, no DSP ASE, no large physaddr,
49 no external interrupt controller, no vectored interupts,
50 no 1kb pages, no MT ASE, no SmartMIPS ASE, no trace logic */
51#define MIPS_CONFIG3 \
52((0 << CP0C3_M) | (0 << CP0C3_DSPP) | (0 << CP0C3_LPA) | \
53 (0 << CP0C3_VEIC) | (0 << CP0C3_VInt) | (0 << CP0C3_SP) | \
54 (0 << CP0C3_MT) | (0 << CP0C3_SM) | (0 << CP0C3_TL))
55
56/* Define a implementation number of 1.
57 Define a major version 1, minor version 0. */
58#define MIPS_FCR0 ((0 << 16) | (1 << 8) | (1 << 4) | 0)
59
60
ths33d68b52007-03-18 00:30:29 +000061struct mips_def_t {
62 const unsigned char *name;
63 int32_t CP0_PRid;
64 int32_t CP0_Config0;
65 int32_t CP0_Config1;
ths3953d782007-03-21 11:04:42 +000066 int32_t CP0_Config2;
67 int32_t CP0_Config3;
ths34ee2ed2007-03-24 23:36:18 +000068 int32_t CP0_Config6;
69 int32_t CP0_Config7;
ths2f644542007-04-11 20:34:23 +000070 int32_t SYNCI_Step;
71 int32_t CCRes;
ths3953d782007-03-21 11:04:42 +000072 int32_t CP1_fcr0;
ths33d68b52007-03-18 00:30:29 +000073};
74
75/*****************************************************************************/
76/* MIPS CPU definitions */
77static mips_def_t mips_defs[] =
78{
ths60aa19a2007-04-01 12:36:18 +000079#ifndef TARGET_MIPS64
ths33d68b52007-03-18 00:30:29 +000080 {
81 .name = "4Kc",
82 .CP0_PRid = 0x00018000,
83 .CP0_Config0 = MIPS_CONFIG0,
thsfcb4a412007-04-17 15:26:47 +000084 .CP0_Config1 = MIPS_CONFIG1 | (15 << CP0C1_MMU),
ths3953d782007-03-21 11:04:42 +000085 .CP0_Config2 = MIPS_CONFIG2,
86 .CP0_Config3 = MIPS_CONFIG3,
ths2f644542007-04-11 20:34:23 +000087 .SYNCI_Step = 32,
88 .CCRes = 2,
ths3953d782007-03-21 11:04:42 +000089 .CP1_fcr0 = MIPS_FCR0,
ths33d68b52007-03-18 00:30:29 +000090 },
91 {
ths34ee2ed2007-03-24 23:36:18 +000092 .name = "4KEcR1",
ths33d68b52007-03-18 00:30:29 +000093 .CP0_PRid = 0x00018400,
ths34ee2ed2007-03-24 23:36:18 +000094 .CP0_Config0 = MIPS_CONFIG0,
thsfcb4a412007-04-17 15:26:47 +000095 .CP0_Config1 = MIPS_CONFIG1 | (15 << CP0C1_MMU),
ths34ee2ed2007-03-24 23:36:18 +000096 .CP0_Config2 = MIPS_CONFIG2,
97 .CP0_Config3 = MIPS_CONFIG3,
ths2f644542007-04-11 20:34:23 +000098 .SYNCI_Step = 32,
99 .CCRes = 2,
ths34ee2ed2007-03-24 23:36:18 +0000100 .CP1_fcr0 = MIPS_FCR0,
101 },
102 {
103 .name = "4KEc",
104 .CP0_PRid = 0x00019000,
105 .CP0_Config0 = MIPS_CONFIG0 | (0x1 << CP0C0_AR),
thsfcb4a412007-04-17 15:26:47 +0000106 .CP0_Config1 = MIPS_CONFIG1 | (15 << CP0C1_MMU),
ths34ee2ed2007-03-24 23:36:18 +0000107 .CP0_Config2 = MIPS_CONFIG2,
108 .CP0_Config3 = MIPS_CONFIG3,
ths2f644542007-04-11 20:34:23 +0000109 .SYNCI_Step = 32,
110 .CCRes = 2,
ths34ee2ed2007-03-24 23:36:18 +0000111 .CP1_fcr0 = MIPS_FCR0,
112 },
113 {
114 .name = "24Kc",
115 .CP0_PRid = 0x00019300,
ths33d68b52007-03-18 00:30:29 +0000116 .CP0_Config0 = MIPS_CONFIG0 | (0x1 << CP0C0_AR),
thsfcb4a412007-04-17 15:26:47 +0000117 .CP0_Config1 = MIPS_CONFIG1 | (15 << CP0C1_MMU),
ths3953d782007-03-21 11:04:42 +0000118 .CP0_Config2 = MIPS_CONFIG2,
119 .CP0_Config3 = MIPS_CONFIG3,
ths2f644542007-04-11 20:34:23 +0000120 .SYNCI_Step = 32,
121 .CCRes = 2,
ths3953d782007-03-21 11:04:42 +0000122 .CP1_fcr0 = MIPS_FCR0,
ths33d68b52007-03-18 00:30:29 +0000123 },
124 {
125 .name = "24Kf",
126 .CP0_PRid = 0x00019300,
127 .CP0_Config0 = MIPS_CONFIG0 | (0x1 << CP0C0_AR),
thsfcb4a412007-04-17 15:26:47 +0000128 .CP0_Config1 = MIPS_CONFIG1 | (1 << CP0C1_FP) | (15 << CP0C1_MMU),
ths3953d782007-03-21 11:04:42 +0000129 .CP0_Config2 = MIPS_CONFIG2,
130 .CP0_Config3 = MIPS_CONFIG3,
ths2f644542007-04-11 20:34:23 +0000131 .SYNCI_Step = 32,
132 .CCRes = 2,
ths3953d782007-03-21 11:04:42 +0000133 .CP1_fcr0 = MIPS_FCR0,
ths33d68b52007-03-18 00:30:29 +0000134 },
135#else
136 {
137 .name = "R4000",
138 .CP0_PRid = 0x00000400,
139 .CP0_Config0 = MIPS_CONFIG0 | (0x2 << CP0C0_AT),
thsfcb4a412007-04-17 15:26:47 +0000140 .CP0_Config1 = MIPS_CONFIG1 | (1 << CP0C1_FP) | (47 << CP0C1_MMU),
ths3953d782007-03-21 11:04:42 +0000141 .CP0_Config2 = MIPS_CONFIG2,
142 .CP0_Config3 = MIPS_CONFIG3,
ths2f644542007-04-11 20:34:23 +0000143 .SYNCI_Step = 16,
144 .CCRes = 2,
ths3953d782007-03-21 11:04:42 +0000145 .CP1_fcr0 = MIPS_FCR0,
ths33d68b52007-03-18 00:30:29 +0000146 },
147#endif
148};
149
150int mips_find_by_name (const unsigned char *name, mips_def_t **def)
151{
152 int i, ret;
153
154 ret = -1;
155 *def = NULL;
156 for (i = 0; i < sizeof(mips_defs) / sizeof(mips_defs[0]); i++) {
157 if (strcasecmp(name, mips_defs[i].name) == 0) {
158 *def = &mips_defs[i];
159 ret = 0;
160 break;
161 }
162 }
163
164 return ret;
165}
166
167void mips_cpu_list (FILE *f, int (*cpu_fprintf)(FILE *f, const char *fmt, ...))
168{
169 int i;
170
171 for (i = 0; i < sizeof(mips_defs) / sizeof(mips_defs[0]); i++) {
172 (*cpu_fprintf)(f, "MIPS '%s'\n",
173 mips_defs[i].name);
174 }
175}
176
177int cpu_mips_register (CPUMIPSState *env, mips_def_t *def)
178{
179 if (!def)
180 cpu_abort(env, "Unable to find MIPS CPU definition\n");
181 env->CP0_PRid = def->CP0_PRid;
ths3953d782007-03-21 11:04:42 +0000182#ifdef TARGET_WORDS_BIGENDIAN
183 env->CP0_Config0 = def->CP0_Config0 | (1 << CP0C0_BE);
184#else
ths33d68b52007-03-18 00:30:29 +0000185 env->CP0_Config0 = def->CP0_Config0;
ths3953d782007-03-21 11:04:42 +0000186#endif
ths33d68b52007-03-18 00:30:29 +0000187 env->CP0_Config1 = def->CP0_Config1;
ths3953d782007-03-21 11:04:42 +0000188 env->CP0_Config2 = def->CP0_Config2;
189 env->CP0_Config3 = def->CP0_Config3;
ths34ee2ed2007-03-24 23:36:18 +0000190 env->CP0_Config6 = def->CP0_Config6;
191 env->CP0_Config7 = def->CP0_Config7;
ths2f644542007-04-11 20:34:23 +0000192 env->SYNCI_Step = def->SYNCI_Step;
193 env->CCRes = def->CCRes;
ths3953d782007-03-21 11:04:42 +0000194 env->fcr0 = def->CP1_fcr0;
thsfcb4a412007-04-17 15:26:47 +0000195#if defined (MIPS_USES_R4K_TLB)
196 env->nb_tlb = 1 + ((def->CP0_Config1 >> CP0C1_MMU) & 63);
197 env->CP0_Random = env->nb_tlb - 1;
198 env->tlb_in_use = env->nb_tlb;
199#endif
ths33d68b52007-03-18 00:30:29 +0000200 return 0;
201}