xref: /openbmc/qemu/target/ppc/cpu_init.c (revision dbdf841b)
1 /*
2  *  PowerPC CPU initialization for qemu.
3  *
4  *  Copyright (c) 2003-2007 Jocelyn Mayer
5  *  Copyright 2011 Freescale Semiconductor, Inc.
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.1 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, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #include "qemu/osdep.h"
22 #include "disas/dis-asm.h"
23 #include "gdbstub/helpers.h"
24 #include "sysemu/cpus.h"
25 #include "sysemu/hw_accel.h"
26 #include "sysemu/tcg.h"
27 #include "cpu-models.h"
28 #include "mmu-hash32.h"
29 #include "mmu-hash64.h"
30 #include "qemu/error-report.h"
31 #include "qemu/module.h"
32 #include "qemu/qemu-print.h"
33 #include "qapi/error.h"
34 #include "qapi/qmp/qnull.h"
35 #include "qapi/visitor.h"
36 #include "hw/qdev-properties.h"
37 #include "hw/ppc/ppc.h"
38 #include "mmu-book3s-v3.h"
39 #include "qemu/cutils.h"
40 #include "disas/capstone.h"
41 #include "fpu/softfloat.h"
42 
43 #include "helper_regs.h"
44 #include "internal.h"
45 #include "spr_common.h"
46 #include "power8-pmu.h"
47 
48 #ifndef CONFIG_USER_ONLY
49 #include "hw/boards.h"
50 #include "hw/intc/intc.h"
51 #include "kvm_ppc.h"
52 #endif
53 
54 /* #define PPC_DEBUG_SPR */
55 /* #define USE_APPLE_GDB */
56 
57 static inline void vscr_init(CPUPPCState *env, uint32_t val)
58 {
59     /* Altivec always uses round-to-nearest */
60     set_float_rounding_mode(float_round_nearest_even, &env->vec_status);
61     ppc_store_vscr(env, val);
62 }
63 
64 static void register_745_sprs(CPUPPCState *env)
65 {
66     /* SGPRs */
67     spr_register(env, SPR_SPRG4, "SPRG4",
68                  SPR_NOACCESS, SPR_NOACCESS,
69                  &spr_read_generic, &spr_write_generic,
70                  0x00000000);
71     spr_register(env, SPR_SPRG5, "SPRG5",
72                  SPR_NOACCESS, SPR_NOACCESS,
73                  &spr_read_generic, &spr_write_generic,
74                  0x00000000);
75     spr_register(env, SPR_SPRG6, "SPRG6",
76                  SPR_NOACCESS, SPR_NOACCESS,
77                  &spr_read_generic, &spr_write_generic,
78                  0x00000000);
79     spr_register(env, SPR_SPRG7, "SPRG7",
80                  SPR_NOACCESS, SPR_NOACCESS,
81                  &spr_read_generic, &spr_write_generic,
82                  0x00000000);
83 
84     /* Hardware implementation registers */
85     spr_register(env, SPR_HID0, "HID0",
86                  SPR_NOACCESS, SPR_NOACCESS,
87                  &spr_read_generic, &spr_write_generic,
88                  0x00000000);
89 
90     spr_register(env, SPR_HID1, "HID1",
91                  SPR_NOACCESS, SPR_NOACCESS,
92                  &spr_read_generic, &spr_write_generic,
93                  0x00000000);
94 
95     spr_register(env, SPR_HID2, "HID2",
96                  SPR_NOACCESS, SPR_NOACCESS,
97                  &spr_read_generic, &spr_write_generic,
98                  0x00000000);
99 }
100 
101 static void register_755_sprs(CPUPPCState *env)
102 {
103     /* L2 cache control */
104     spr_register(env, SPR_L2CR, "L2CR",
105                  SPR_NOACCESS, SPR_NOACCESS,
106                  &spr_read_generic, spr_access_nop,
107                  0x00000000);
108 
109     spr_register(env, SPR_L2PMCR, "L2PMCR",
110                  SPR_NOACCESS, SPR_NOACCESS,
111                  &spr_read_generic, &spr_write_generic,
112                  0x00000000);
113 }
114 
115 /* SPR common to all 7xx PowerPC implementations */
116 static void register_7xx_sprs(CPUPPCState *env)
117 {
118     /* Breakpoints */
119     spr_register_kvm(env, SPR_DABR, "DABR",
120                      SPR_NOACCESS, SPR_NOACCESS,
121                      &spr_read_generic, &spr_write_generic,
122                      KVM_REG_PPC_DABR, 0x00000000);
123 
124     spr_register(env, SPR_IABR, "IABR",
125                  SPR_NOACCESS, SPR_NOACCESS,
126                  &spr_read_generic, &spr_write_generic,
127                  0x00000000);
128     /* Cache management */
129     spr_register(env, SPR_ICTC, "ICTC",
130                  SPR_NOACCESS, SPR_NOACCESS,
131                  &spr_read_generic, &spr_write_generic,
132                  0x00000000);
133     /* Performance monitors */
134     spr_register(env, SPR_7XX_MMCR0, "MMCR0",
135                  SPR_NOACCESS, SPR_NOACCESS,
136                  &spr_read_generic, &spr_write_generic,
137                  0x00000000);
138 
139     spr_register(env, SPR_7XX_MMCR1, "MMCR1",
140                  SPR_NOACCESS, SPR_NOACCESS,
141                  &spr_read_generic, &spr_write_generic,
142                  0x00000000);
143 
144     spr_register(env, SPR_7XX_PMC1, "PMC1",
145                  SPR_NOACCESS, SPR_NOACCESS,
146                  &spr_read_generic, &spr_write_generic,
147                  0x00000000);
148 
149     spr_register(env, SPR_7XX_PMC2, "PMC2",
150                  SPR_NOACCESS, SPR_NOACCESS,
151                  &spr_read_generic, &spr_write_generic,
152                  0x00000000);
153 
154     spr_register(env, SPR_7XX_PMC3, "PMC3",
155                  SPR_NOACCESS, SPR_NOACCESS,
156                  &spr_read_generic, &spr_write_generic,
157                  0x00000000);
158 
159     spr_register(env, SPR_7XX_PMC4, "PMC4",
160                  SPR_NOACCESS, SPR_NOACCESS,
161                  &spr_read_generic, &spr_write_generic,
162                  0x00000000);
163 
164     spr_register(env, SPR_7XX_SIAR, "SIAR",
165                  SPR_NOACCESS, SPR_NOACCESS,
166                  &spr_read_generic, SPR_NOACCESS,
167                  0x00000000);
168 
169     spr_register(env, SPR_7XX_UMMCR0, "UMMCR0",
170                  &spr_read_ureg, SPR_NOACCESS,
171                  &spr_read_ureg, SPR_NOACCESS,
172                  0x00000000);
173 
174     spr_register(env, SPR_7XX_UMMCR1, "UMMCR1",
175                  &spr_read_ureg, SPR_NOACCESS,
176                  &spr_read_ureg, SPR_NOACCESS,
177                  0x00000000);
178 
179     spr_register(env, SPR_7XX_UPMC1, "UPMC1",
180                  &spr_read_ureg, SPR_NOACCESS,
181                  &spr_read_ureg, SPR_NOACCESS,
182                  0x00000000);
183 
184     spr_register(env, SPR_7XX_UPMC2, "UPMC2",
185                  &spr_read_ureg, SPR_NOACCESS,
186                  &spr_read_ureg, SPR_NOACCESS,
187                  0x00000000);
188 
189     spr_register(env, SPR_7XX_UPMC3, "UPMC3",
190                  &spr_read_ureg, SPR_NOACCESS,
191                  &spr_read_ureg, SPR_NOACCESS,
192                  0x00000000);
193 
194     spr_register(env, SPR_7XX_UPMC4, "UPMC4",
195                  &spr_read_ureg, SPR_NOACCESS,
196                  &spr_read_ureg, SPR_NOACCESS,
197                  0x00000000);
198 
199     spr_register(env, SPR_7XX_USIAR, "USIAR",
200                  &spr_read_ureg, SPR_NOACCESS,
201                  &spr_read_ureg, SPR_NOACCESS,
202                  0x00000000);
203     /* External access control */
204     spr_register(env, SPR_EAR, "EAR",
205                  SPR_NOACCESS, SPR_NOACCESS,
206                  &spr_read_generic, &spr_write_generic,
207                  0x00000000);
208 
209     /* Hardware implementation registers */
210     spr_register(env, SPR_HID0, "HID0",
211                  SPR_NOACCESS, SPR_NOACCESS,
212                  &spr_read_generic, &spr_write_generic,
213                  0x00000000);
214 
215     spr_register(env, SPR_HID1, "HID1",
216                  SPR_NOACCESS, SPR_NOACCESS,
217                  &spr_read_generic, &spr_write_generic,
218                  0x00000000);
219 }
220 
221 #ifdef TARGET_PPC64
222 static void register_amr_sprs(CPUPPCState *env)
223 {
224 #ifndef CONFIG_USER_ONLY
225     /*
226      * Virtual Page Class Key protection
227      *
228      * The AMR is accessible either via SPR 13 or SPR 29.  13 is
229      * userspace accessible, 29 is privileged.  So we only need to set
230      * the kvm ONE_REG id on one of them, we use 29
231      */
232     spr_register(env, SPR_UAMR, "UAMR",
233                  &spr_read_generic, &spr_write_amr,
234                  &spr_read_generic, &spr_write_amr,
235                  0);
236     spr_register_kvm_hv(env, SPR_AMR, "AMR",
237                      SPR_NOACCESS, SPR_NOACCESS,
238                      &spr_read_generic, &spr_write_amr,
239                      &spr_read_generic, &spr_write_generic,
240                      KVM_REG_PPC_AMR, 0);
241     spr_register_kvm_hv(env, SPR_UAMOR, "UAMOR",
242                      SPR_NOACCESS, SPR_NOACCESS,
243                      &spr_read_generic, &spr_write_uamor,
244                      &spr_read_generic, &spr_write_generic,
245                      KVM_REG_PPC_UAMOR, 0);
246     spr_register_hv(env, SPR_AMOR, "AMOR",
247                     SPR_NOACCESS, SPR_NOACCESS,
248                     SPR_NOACCESS, SPR_NOACCESS,
249                     &spr_read_generic, &spr_write_generic,
250                     0);
251 #endif /* !CONFIG_USER_ONLY */
252 }
253 
254 static void register_iamr_sprs(CPUPPCState *env)
255 {
256 #ifndef CONFIG_USER_ONLY
257     spr_register_kvm_hv(env, SPR_IAMR, "IAMR",
258                         SPR_NOACCESS, SPR_NOACCESS,
259                         &spr_read_generic, &spr_write_iamr,
260                         &spr_read_generic, &spr_write_generic,
261                         KVM_REG_PPC_IAMR, 0);
262 #endif /* !CONFIG_USER_ONLY */
263 }
264 #endif /* TARGET_PPC64 */
265 
266 /* SPR specific to PowerPC 604 implementation */
267 static void register_604_sprs(CPUPPCState *env)
268 {
269     /* Processor identification */
270     spr_register(env, SPR_PIR, "PIR",
271                  SPR_NOACCESS, SPR_NOACCESS,
272                  &spr_read_generic, &spr_write_pir,
273                  0x00000000);
274     /* Breakpoints */
275     spr_register(env, SPR_IABR, "IABR",
276                  SPR_NOACCESS, SPR_NOACCESS,
277                  &spr_read_generic, &spr_write_generic,
278                  0x00000000);
279 
280     spr_register_kvm(env, SPR_DABR, "DABR",
281                      SPR_NOACCESS, SPR_NOACCESS,
282                      &spr_read_generic, &spr_write_generic,
283                      KVM_REG_PPC_DABR, 0x00000000);
284     /* Performance counters */
285     spr_register(env, SPR_7XX_MMCR0, "MMCR0",
286                  SPR_NOACCESS, SPR_NOACCESS,
287                  &spr_read_generic, &spr_write_generic,
288                  0x00000000);
289 
290     spr_register(env, SPR_7XX_PMC1, "PMC1",
291                  SPR_NOACCESS, SPR_NOACCESS,
292                  &spr_read_generic, &spr_write_generic,
293                  0x00000000);
294 
295     spr_register(env, SPR_7XX_PMC2, "PMC2",
296                  SPR_NOACCESS, SPR_NOACCESS,
297                  &spr_read_generic, &spr_write_generic,
298                  0x00000000);
299 
300     spr_register(env, SPR_7XX_SIAR, "SIAR",
301                  SPR_NOACCESS, SPR_NOACCESS,
302                  &spr_read_generic, SPR_NOACCESS,
303                  0x00000000);
304 
305     spr_register(env, SPR_SDA, "SDA",
306                  SPR_NOACCESS, SPR_NOACCESS,
307                  &spr_read_generic, SPR_NOACCESS,
308                  0x00000000);
309     /* External access control */
310     spr_register(env, SPR_EAR, "EAR",
311                  SPR_NOACCESS, SPR_NOACCESS,
312                  &spr_read_generic, &spr_write_generic,
313                  0x00000000);
314 
315     /* Hardware implementation registers */
316     spr_register(env, SPR_HID0, "HID0",
317                  SPR_NOACCESS, SPR_NOACCESS,
318                  &spr_read_generic, &spr_write_generic,
319                  0x00000000);
320 }
321 
322 static void register_604e_sprs(CPUPPCState *env)
323 {
324     spr_register(env, SPR_7XX_MMCR1, "MMCR1",
325                  SPR_NOACCESS, SPR_NOACCESS,
326                  &spr_read_generic, &spr_write_generic,
327                  0x00000000);
328 
329     spr_register(env, SPR_7XX_PMC3, "PMC3",
330                  SPR_NOACCESS, SPR_NOACCESS,
331                  &spr_read_generic, &spr_write_generic,
332                  0x00000000);
333 
334     spr_register(env, SPR_7XX_PMC4, "PMC4",
335                  SPR_NOACCESS, SPR_NOACCESS,
336                  &spr_read_generic, &spr_write_generic,
337                  0x00000000);
338     /* Hardware implementation registers */
339     spr_register(env, SPR_HID1, "HID1",
340                  SPR_NOACCESS, SPR_NOACCESS,
341                  &spr_read_generic, &spr_write_generic,
342                  0x00000000);
343 }
344 
345 /* SPR specific to PowerPC 603 implementation */
346 static void register_603_sprs(CPUPPCState *env)
347 {
348     /* External access control */
349     spr_register(env, SPR_EAR, "EAR",
350                  SPR_NOACCESS, SPR_NOACCESS,
351                  &spr_read_generic, &spr_write_generic,
352                  0x00000000);
353     /* Breakpoints */
354     spr_register(env, SPR_IABR, "IABR",
355                  SPR_NOACCESS, SPR_NOACCESS,
356                  &spr_read_generic, &spr_write_generic,
357                  0x00000000);
358 
359     spr_register(env, SPR_HID0, "HID0",
360                  SPR_NOACCESS, SPR_NOACCESS,
361                  &spr_read_generic, &spr_write_generic,
362                  0x00000000);
363 
364     spr_register(env, SPR_HID1, "HID1",
365                  SPR_NOACCESS, SPR_NOACCESS,
366                  &spr_read_generic, &spr_write_generic,
367                  0x00000000);
368 }
369 
370 static void register_e300_sprs(CPUPPCState *env)
371 {
372     /* hardware implementation registers */
373     spr_register(env, SPR_HID2, "HID2",
374                  SPR_NOACCESS, SPR_NOACCESS,
375                  &spr_read_generic, &spr_write_generic,
376                  0x00000000);
377     /* Breakpoints */
378     spr_register(env, SPR_DABR, "DABR",
379                  SPR_NOACCESS, SPR_NOACCESS,
380                  &spr_read_generic, &spr_write_generic,
381                  0x00000000);
382 
383     spr_register(env, SPR_DABR2, "DABR2",
384                  SPR_NOACCESS, SPR_NOACCESS,
385                  &spr_read_generic, &spr_write_generic,
386                  0x00000000);
387 
388     spr_register(env, SPR_IABR2, "IABR2",
389                  SPR_NOACCESS, SPR_NOACCESS,
390                  &spr_read_generic, &spr_write_generic,
391                  0x00000000);
392 
393     spr_register(env, SPR_IBCR, "IBCR",
394                  SPR_NOACCESS, SPR_NOACCESS,
395                  &spr_read_generic, &spr_write_generic,
396                  0x00000000);
397 
398     spr_register(env, SPR_DBCR, "DBCR",
399                  SPR_NOACCESS, SPR_NOACCESS,
400                  &spr_read_generic, &spr_write_generic,
401                  0x00000000);
402 }
403 
404 /* SPR specific to PowerPC G2 implementation */
405 static void register_G2_sprs(CPUPPCState *env)
406 {
407     /* Memory base address */
408     /* MBAR */
409     spr_register(env, SPR_MBAR, "MBAR",
410                  SPR_NOACCESS, SPR_NOACCESS,
411                  &spr_read_generic, &spr_write_generic,
412                  0x00000000);
413     /* Exception processing */
414     spr_register(env, SPR_BOOKE_CSRR0, "CSRR0",
415                  SPR_NOACCESS, SPR_NOACCESS,
416                  &spr_read_generic, &spr_write_generic,
417                  0x00000000);
418     spr_register(env, SPR_BOOKE_CSRR1, "CSRR1",
419                  SPR_NOACCESS, SPR_NOACCESS,
420                  &spr_read_generic, &spr_write_generic,
421                  0x00000000);
422     /* Breakpoints */
423     spr_register(env, SPR_DABR, "DABR",
424                  SPR_NOACCESS, SPR_NOACCESS,
425                  &spr_read_generic, &spr_write_generic,
426                  0x00000000);
427 
428     spr_register(env, SPR_DABR2, "DABR2",
429                  SPR_NOACCESS, SPR_NOACCESS,
430                  &spr_read_generic, &spr_write_generic,
431                  0x00000000);
432 
433     spr_register(env, SPR_IABR, "IABR",
434                  SPR_NOACCESS, SPR_NOACCESS,
435                  &spr_read_generic, &spr_write_generic,
436                  0x00000000);
437 
438     spr_register(env, SPR_IABR2, "IABR2",
439                  SPR_NOACCESS, SPR_NOACCESS,
440                  &spr_read_generic, &spr_write_generic,
441                  0x00000000);
442 
443     spr_register(env, SPR_IBCR, "IBCR",
444                  SPR_NOACCESS, SPR_NOACCESS,
445                  &spr_read_generic, &spr_write_generic,
446                  0x00000000);
447 
448     spr_register(env, SPR_DBCR, "DBCR",
449                  SPR_NOACCESS, SPR_NOACCESS,
450                  &spr_read_generic, &spr_write_generic,
451                  0x00000000);
452 
453     /* External access control */
454     spr_register(env, SPR_EAR, "EAR",
455                  SPR_NOACCESS, SPR_NOACCESS,
456                  &spr_read_generic, &spr_write_generic,
457                  0x00000000);
458     /* Hardware implementation register */
459     spr_register(env, SPR_HID0, "HID0",
460                  SPR_NOACCESS, SPR_NOACCESS,
461                  &spr_read_generic, &spr_write_generic,
462                  0x00000000);
463 
464     spr_register(env, SPR_HID1, "HID1",
465                  SPR_NOACCESS, SPR_NOACCESS,
466                  &spr_read_generic, &spr_write_generic,
467                  0x00000000);
468 
469     spr_register(env, SPR_HID2, "HID2",
470                  SPR_NOACCESS, SPR_NOACCESS,
471                  &spr_read_generic, &spr_write_generic,
472                  0x00000000);
473 
474     /* SGPRs */
475     spr_register(env, SPR_SPRG4, "SPRG4",
476                  SPR_NOACCESS, SPR_NOACCESS,
477                  &spr_read_generic, &spr_write_generic,
478                  0x00000000);
479     spr_register(env, SPR_SPRG5, "SPRG5",
480                  SPR_NOACCESS, SPR_NOACCESS,
481                  &spr_read_generic, &spr_write_generic,
482                  0x00000000);
483     spr_register(env, SPR_SPRG6, "SPRG6",
484                  SPR_NOACCESS, SPR_NOACCESS,
485                  &spr_read_generic, &spr_write_generic,
486                  0x00000000);
487     spr_register(env, SPR_SPRG7, "SPRG7",
488                  SPR_NOACCESS, SPR_NOACCESS,
489                  &spr_read_generic, &spr_write_generic,
490                  0x00000000);
491 }
492 
493 static void register_74xx_sprs(CPUPPCState *env)
494 {
495     /* Breakpoints */
496     spr_register_kvm(env, SPR_DABR, "DABR",
497                      SPR_NOACCESS, SPR_NOACCESS,
498                      &spr_read_generic, &spr_write_generic,
499                      KVM_REG_PPC_DABR, 0x00000000);
500 
501     spr_register(env, SPR_IABR, "IABR",
502                  SPR_NOACCESS, SPR_NOACCESS,
503                  &spr_read_generic, &spr_write_generic,
504                  0x00000000);
505     /* Cache management */
506     spr_register(env, SPR_ICTC, "ICTC",
507                  SPR_NOACCESS, SPR_NOACCESS,
508                  &spr_read_generic, &spr_write_generic,
509                  0x00000000);
510     /* Performance monitors */
511     spr_register(env, SPR_7XX_MMCR0, "MMCR0",
512                  SPR_NOACCESS, SPR_NOACCESS,
513                  &spr_read_generic, &spr_write_generic,
514                  0x00000000);
515 
516     spr_register(env, SPR_7XX_MMCR1, "MMCR1",
517                  SPR_NOACCESS, SPR_NOACCESS,
518                  &spr_read_generic, &spr_write_generic,
519                  0x00000000);
520 
521     spr_register(env, SPR_7XX_PMC1, "PMC1",
522                  SPR_NOACCESS, SPR_NOACCESS,
523                  &spr_read_generic, &spr_write_generic,
524                  0x00000000);
525 
526     spr_register(env, SPR_7XX_PMC2, "PMC2",
527                  SPR_NOACCESS, SPR_NOACCESS,
528                  &spr_read_generic, &spr_write_generic,
529                  0x00000000);
530 
531     spr_register(env, SPR_7XX_PMC3, "PMC3",
532                  SPR_NOACCESS, SPR_NOACCESS,
533                  &spr_read_generic, &spr_write_generic,
534                  0x00000000);
535 
536     spr_register(env, SPR_7XX_PMC4, "PMC4",
537                  SPR_NOACCESS, SPR_NOACCESS,
538                  &spr_read_generic, &spr_write_generic,
539                  0x00000000);
540 
541     spr_register(env, SPR_7XX_SIAR, "SIAR",
542                  SPR_NOACCESS, SPR_NOACCESS,
543                  &spr_read_generic, SPR_NOACCESS,
544                  0x00000000);
545 
546     spr_register(env, SPR_7XX_UMMCR0, "UMMCR0",
547                  &spr_read_ureg, SPR_NOACCESS,
548                  &spr_read_ureg, SPR_NOACCESS,
549                  0x00000000);
550 
551     spr_register(env, SPR_7XX_UMMCR1, "UMMCR1",
552                  &spr_read_ureg, SPR_NOACCESS,
553                  &spr_read_ureg, SPR_NOACCESS,
554                  0x00000000);
555 
556     spr_register(env, SPR_7XX_UPMC1, "UPMC1",
557                  &spr_read_ureg, SPR_NOACCESS,
558                  &spr_read_ureg, SPR_NOACCESS,
559                  0x00000000);
560 
561     spr_register(env, SPR_7XX_UPMC2, "UPMC2",
562                  &spr_read_ureg, SPR_NOACCESS,
563                  &spr_read_ureg, SPR_NOACCESS,
564                  0x00000000);
565 
566     spr_register(env, SPR_7XX_UPMC3, "UPMC3",
567                  &spr_read_ureg, SPR_NOACCESS,
568                  &spr_read_ureg, SPR_NOACCESS,
569                  0x00000000);
570 
571     spr_register(env, SPR_7XX_UPMC4, "UPMC4",
572                  &spr_read_ureg, SPR_NOACCESS,
573                  &spr_read_ureg, SPR_NOACCESS,
574                  0x00000000);
575 
576     spr_register(env, SPR_7XX_USIAR, "USIAR",
577                  &spr_read_ureg, SPR_NOACCESS,
578                  &spr_read_ureg, SPR_NOACCESS,
579                  0x00000000);
580     /* External access control */
581     spr_register(env, SPR_EAR, "EAR",
582                  SPR_NOACCESS, SPR_NOACCESS,
583                  &spr_read_generic, &spr_write_generic,
584                  0x00000000);
585 
586     /* Processor identification */
587     spr_register(env, SPR_PIR, "PIR",
588                  SPR_NOACCESS, SPR_NOACCESS,
589                  &spr_read_generic, &spr_write_pir,
590                  0x00000000);
591 
592     spr_register(env, SPR_74XX_MMCR2, "MMCR2",
593                  SPR_NOACCESS, SPR_NOACCESS,
594                  &spr_read_generic, &spr_write_generic,
595                  0x00000000);
596 
597     spr_register(env, SPR_74XX_UMMCR2, "UMMCR2",
598                  &spr_read_ureg, SPR_NOACCESS,
599                  &spr_read_ureg, SPR_NOACCESS,
600                  0x00000000);
601 
602     spr_register(env, SPR_BAMR, "BAMR",
603                  SPR_NOACCESS, SPR_NOACCESS,
604                  &spr_read_generic, &spr_write_generic,
605                  0x00000000);
606 
607     spr_register(env, SPR_MSSCR0, "MSSCR0",
608                  SPR_NOACCESS, SPR_NOACCESS,
609                  &spr_read_generic, &spr_write_generic,
610                  0x00000000);
611     /* Hardware implementation registers */
612     spr_register(env, SPR_HID0, "HID0",
613                  SPR_NOACCESS, SPR_NOACCESS,
614                  &spr_read_generic, &spr_write_generic,
615                  0x00000000);
616 
617     spr_register(env, SPR_HID1, "HID1",
618                  SPR_NOACCESS, SPR_NOACCESS,
619                  &spr_read_generic, &spr_write_generic,
620                  0x00000000);
621     /* Altivec */
622     spr_register(env, SPR_VRSAVE, "VRSAVE",
623                  &spr_read_generic, &spr_write_generic,
624                  &spr_read_generic, &spr_write_generic,
625                  0x00000000);
626 
627     spr_register(env, SPR_L2CR, "L2CR",
628                  SPR_NOACCESS, SPR_NOACCESS,
629                  &spr_read_generic, spr_access_nop,
630                  0x00000000);
631 }
632 
633 static void register_l3_ctrl(CPUPPCState *env)
634 {
635     /* L3CR */
636     spr_register(env, SPR_L3CR, "L3CR",
637                  SPR_NOACCESS, SPR_NOACCESS,
638                  &spr_read_generic, &spr_write_generic,
639                  0x00000000);
640     /* L3ITCR0 */
641     spr_register(env, SPR_L3ITCR0, "L3ITCR0",
642                  SPR_NOACCESS, SPR_NOACCESS,
643                  &spr_read_generic, &spr_write_generic,
644                  0x00000000);
645     /* L3PM */
646     spr_register(env, SPR_L3PM, "L3PM",
647                  SPR_NOACCESS, SPR_NOACCESS,
648                  &spr_read_generic, &spr_write_generic,
649                  0x00000000);
650 }
651 
652 /* PowerPC BookE SPR */
653 static void register_BookE_sprs(CPUPPCState *env, uint64_t ivor_mask)
654 {
655     const char *ivor_names[64] = {
656         "IVOR0",  "IVOR1",  "IVOR2",  "IVOR3",
657         "IVOR4",  "IVOR5",  "IVOR6",  "IVOR7",
658         "IVOR8",  "IVOR9",  "IVOR10", "IVOR11",
659         "IVOR12", "IVOR13", "IVOR14", "IVOR15",
660         "IVOR16", "IVOR17", "IVOR18", "IVOR19",
661         "IVOR20", "IVOR21", "IVOR22", "IVOR23",
662         "IVOR24", "IVOR25", "IVOR26", "IVOR27",
663         "IVOR28", "IVOR29", "IVOR30", "IVOR31",
664         "IVOR32", "IVOR33", "IVOR34", "IVOR35",
665         "IVOR36", "IVOR37", "IVOR38", "IVOR39",
666         "IVOR40", "IVOR41", "IVOR42", "IVOR43",
667         "IVOR44", "IVOR45", "IVOR46", "IVOR47",
668         "IVOR48", "IVOR49", "IVOR50", "IVOR51",
669         "IVOR52", "IVOR53", "IVOR54", "IVOR55",
670         "IVOR56", "IVOR57", "IVOR58", "IVOR59",
671         "IVOR60", "IVOR61", "IVOR62", "IVOR63",
672     };
673 #define SPR_BOOKE_IVORxx (-1)
674     int ivor_sprn[64] = {
675         SPR_BOOKE_IVOR0,  SPR_BOOKE_IVOR1,  SPR_BOOKE_IVOR2,  SPR_BOOKE_IVOR3,
676         SPR_BOOKE_IVOR4,  SPR_BOOKE_IVOR5,  SPR_BOOKE_IVOR6,  SPR_BOOKE_IVOR7,
677         SPR_BOOKE_IVOR8,  SPR_BOOKE_IVOR9,  SPR_BOOKE_IVOR10, SPR_BOOKE_IVOR11,
678         SPR_BOOKE_IVOR12, SPR_BOOKE_IVOR13, SPR_BOOKE_IVOR14, SPR_BOOKE_IVOR15,
679         SPR_BOOKE_IVORxx, SPR_BOOKE_IVORxx, SPR_BOOKE_IVORxx, SPR_BOOKE_IVORxx,
680         SPR_BOOKE_IVORxx, SPR_BOOKE_IVORxx, SPR_BOOKE_IVORxx, SPR_BOOKE_IVORxx,
681         SPR_BOOKE_IVORxx, SPR_BOOKE_IVORxx, SPR_BOOKE_IVORxx, SPR_BOOKE_IVORxx,
682         SPR_BOOKE_IVORxx, SPR_BOOKE_IVORxx, SPR_BOOKE_IVORxx, SPR_BOOKE_IVORxx,
683         SPR_BOOKE_IVOR32, SPR_BOOKE_IVOR33, SPR_BOOKE_IVOR34, SPR_BOOKE_IVOR35,
684         SPR_BOOKE_IVOR36, SPR_BOOKE_IVOR37, SPR_BOOKE_IVOR38, SPR_BOOKE_IVOR39,
685         SPR_BOOKE_IVOR40, SPR_BOOKE_IVOR41, SPR_BOOKE_IVOR42, SPR_BOOKE_IVORxx,
686         SPR_BOOKE_IVORxx, SPR_BOOKE_IVORxx, SPR_BOOKE_IVORxx, SPR_BOOKE_IVORxx,
687         SPR_BOOKE_IVORxx, SPR_BOOKE_IVORxx, SPR_BOOKE_IVORxx, SPR_BOOKE_IVORxx,
688         SPR_BOOKE_IVORxx, SPR_BOOKE_IVORxx, SPR_BOOKE_IVORxx, SPR_BOOKE_IVORxx,
689         SPR_BOOKE_IVORxx, SPR_BOOKE_IVORxx, SPR_BOOKE_IVORxx, SPR_BOOKE_IVORxx,
690         SPR_BOOKE_IVORxx, SPR_BOOKE_IVORxx, SPR_BOOKE_IVORxx, SPR_BOOKE_IVORxx,
691     };
692     int i;
693 
694     /* Interrupt processing */
695     spr_register(env, SPR_BOOKE_CSRR0, "CSRR0",
696                  SPR_NOACCESS, SPR_NOACCESS,
697                  &spr_read_generic, &spr_write_generic,
698                  0x00000000);
699     spr_register(env, SPR_BOOKE_CSRR1, "CSRR1",
700                  SPR_NOACCESS, SPR_NOACCESS,
701                  &spr_read_generic, &spr_write_generic,
702                  0x00000000);
703     /* Debug */
704     spr_register(env, SPR_BOOKE_IAC1, "IAC1",
705                  SPR_NOACCESS, SPR_NOACCESS,
706                  &spr_read_generic, &spr_write_generic,
707                  0x00000000);
708 
709     spr_register(env, SPR_BOOKE_IAC2, "IAC2",
710                  SPR_NOACCESS, SPR_NOACCESS,
711                  &spr_read_generic, &spr_write_generic,
712                  0x00000000);
713 
714     spr_register(env, SPR_BOOKE_DAC1, "DAC1",
715                  SPR_NOACCESS, SPR_NOACCESS,
716                  &spr_read_generic, &spr_write_generic,
717                  0x00000000);
718 
719     spr_register(env, SPR_BOOKE_DAC2, "DAC2",
720                  SPR_NOACCESS, SPR_NOACCESS,
721                  &spr_read_generic, &spr_write_generic,
722                  0x00000000);
723 
724     spr_register(env, SPR_BOOKE_DBCR0, "DBCR0",
725                  SPR_NOACCESS, SPR_NOACCESS,
726                  &spr_read_generic, &spr_write_40x_dbcr0,
727                  0x00000000);
728 
729     spr_register(env, SPR_BOOKE_DBCR1, "DBCR1",
730                  SPR_NOACCESS, SPR_NOACCESS,
731                  &spr_read_generic, &spr_write_generic,
732                  0x00000000);
733 
734     spr_register(env, SPR_BOOKE_DBCR2, "DBCR2",
735                  SPR_NOACCESS, SPR_NOACCESS,
736                  &spr_read_generic, &spr_write_generic,
737                  0x00000000);
738     spr_register(env, SPR_BOOKE_DSRR0, "DSRR0",
739                  SPR_NOACCESS, SPR_NOACCESS,
740                  &spr_read_generic, &spr_write_generic,
741                  0x00000000);
742     spr_register(env, SPR_BOOKE_DSRR1, "DSRR1",
743                  SPR_NOACCESS, SPR_NOACCESS,
744                  &spr_read_generic, &spr_write_generic,
745                  0x00000000);
746 
747     spr_register(env, SPR_BOOKE_DBSR, "DBSR",
748                  SPR_NOACCESS, SPR_NOACCESS,
749                  &spr_read_generic, &spr_write_clear,
750                  0x00000000);
751     spr_register(env, SPR_BOOKE_DEAR, "DEAR",
752                  SPR_NOACCESS, SPR_NOACCESS,
753                  &spr_read_generic, &spr_write_generic,
754                  0x00000000);
755     spr_register(env, SPR_BOOKE_ESR, "ESR",
756                  SPR_NOACCESS, SPR_NOACCESS,
757                  &spr_read_generic, &spr_write_generic,
758                  0x00000000);
759     spr_register(env, SPR_BOOKE_IVPR, "IVPR",
760                  SPR_NOACCESS, SPR_NOACCESS,
761                  &spr_read_generic, &spr_write_excp_prefix,
762                  0x00000000);
763     /* Exception vectors */
764     for (i = 0; i < 64; i++) {
765         if (ivor_mask & (1ULL << i)) {
766             if (ivor_sprn[i] == SPR_BOOKE_IVORxx) {
767                 fprintf(stderr, "ERROR: IVOR %d SPR is not defined\n", i);
768                 exit(1);
769             }
770             spr_register(env, ivor_sprn[i], ivor_names[i],
771                          SPR_NOACCESS, SPR_NOACCESS,
772                          &spr_read_generic, &spr_write_excp_vector,
773                          0x00000000);
774         }
775     }
776     spr_register(env, SPR_BOOKE_PID, "PID",
777                  SPR_NOACCESS, SPR_NOACCESS,
778                  &spr_read_generic, &spr_write_booke_pid,
779                  0x00000000);
780     spr_register(env, SPR_BOOKE_TCR, "TCR",
781                  SPR_NOACCESS, SPR_NOACCESS,
782                  &spr_read_generic, &spr_write_booke_tcr,
783                  0x00000000);
784     spr_register(env, SPR_BOOKE_TSR, "TSR",
785                  SPR_NOACCESS, SPR_NOACCESS,
786                  &spr_read_generic, &spr_write_booke_tsr,
787                  0x00000000);
788     /* Timer */
789     spr_register(env, SPR_DECR, "DECR",
790                  SPR_NOACCESS, SPR_NOACCESS,
791                  &spr_read_decr, &spr_write_decr,
792                  0x00000000);
793     spr_register(env, SPR_BOOKE_DECAR, "DECAR",
794                  SPR_NOACCESS, SPR_NOACCESS,
795                  SPR_NOACCESS, &spr_write_generic,
796                  0x00000000);
797     /* SPRGs */
798     spr_register(env, SPR_USPRG0, "USPRG0",
799                  &spr_read_generic, &spr_write_generic,
800                  &spr_read_generic, &spr_write_generic,
801                  0x00000000);
802     spr_register(env, SPR_SPRG4, "SPRG4",
803                  SPR_NOACCESS, SPR_NOACCESS,
804                  &spr_read_generic, &spr_write_generic,
805                  0x00000000);
806     spr_register(env, SPR_SPRG5, "SPRG5",
807                  SPR_NOACCESS, SPR_NOACCESS,
808                  &spr_read_generic, &spr_write_generic,
809                  0x00000000);
810     spr_register(env, SPR_SPRG6, "SPRG6",
811                  SPR_NOACCESS, SPR_NOACCESS,
812                  &spr_read_generic, &spr_write_generic,
813                  0x00000000);
814     spr_register(env, SPR_SPRG7, "SPRG7",
815                  SPR_NOACCESS, SPR_NOACCESS,
816                  &spr_read_generic, &spr_write_generic,
817                  0x00000000);
818     spr_register(env, SPR_BOOKE_SPRG8, "SPRG8",
819                  SPR_NOACCESS, SPR_NOACCESS,
820                  &spr_read_generic, &spr_write_generic,
821                  0x00000000);
822     spr_register(env, SPR_BOOKE_SPRG9, "SPRG9",
823                  SPR_NOACCESS, SPR_NOACCESS,
824                  &spr_read_generic, &spr_write_generic,
825                  0x00000000);
826 }
827 
828 #if !defined(CONFIG_USER_ONLY)
829 static inline uint32_t register_tlbncfg(uint32_t assoc, uint32_t minsize,
830                                    uint32_t maxsize, uint32_t flags,
831                                    uint32_t nentries)
832 {
833     return (assoc << TLBnCFG_ASSOC_SHIFT) |
834            (minsize << TLBnCFG_MINSIZE_SHIFT) |
835            (maxsize << TLBnCFG_MAXSIZE_SHIFT) |
836            flags | nentries;
837 }
838 #endif /* !CONFIG_USER_ONLY */
839 
840 /* BookE 2.06 storage control registers */
841 static void register_BookE206_sprs(CPUPPCState *env, uint32_t mas_mask,
842                              uint32_t *tlbncfg, uint32_t mmucfg)
843 {
844 #if !defined(CONFIG_USER_ONLY)
845     const char *mas_names[8] = {
846         "MAS0", "MAS1", "MAS2", "MAS3", "MAS4", "MAS5", "MAS6", "MAS7",
847     };
848     int mas_sprn[8] = {
849         SPR_BOOKE_MAS0, SPR_BOOKE_MAS1, SPR_BOOKE_MAS2, SPR_BOOKE_MAS3,
850         SPR_BOOKE_MAS4, SPR_BOOKE_MAS5, SPR_BOOKE_MAS6, SPR_BOOKE_MAS7,
851     };
852     int i;
853 
854     /* TLB assist registers */
855     for (i = 0; i < 8; i++) {
856         if (mas_mask & (1 << i)) {
857             spr_register(env, mas_sprn[i], mas_names[i],
858                          SPR_NOACCESS, SPR_NOACCESS,
859                          &spr_read_generic,
860                          (i == 2 && (env->insns_flags & PPC_64B))
861                          ? &spr_write_generic : &spr_write_generic32,
862                          0x00000000);
863         }
864     }
865     if (env->nb_pids > 1) {
866         spr_register(env, SPR_BOOKE_PID1, "PID1",
867                      SPR_NOACCESS, SPR_NOACCESS,
868                      &spr_read_generic, &spr_write_booke_pid,
869                      0x00000000);
870     }
871     if (env->nb_pids > 2) {
872         spr_register(env, SPR_BOOKE_PID2, "PID2",
873                      SPR_NOACCESS, SPR_NOACCESS,
874                      &spr_read_generic, &spr_write_booke_pid,
875                      0x00000000);
876     }
877 
878     spr_register(env, SPR_BOOKE_EPLC, "EPLC",
879                  SPR_NOACCESS, SPR_NOACCESS,
880                  &spr_read_generic, &spr_write_eplc,
881                  0x00000000);
882     spr_register(env, SPR_BOOKE_EPSC, "EPSC",
883                  SPR_NOACCESS, SPR_NOACCESS,
884                  &spr_read_generic, &spr_write_epsc,
885                  0x00000000);
886 
887     spr_register(env, SPR_MMUCFG, "MMUCFG",
888                  SPR_NOACCESS, SPR_NOACCESS,
889                  &spr_read_generic, SPR_NOACCESS,
890                  mmucfg);
891     switch (env->nb_ways) {
892     case 4:
893         spr_register(env, SPR_BOOKE_TLB3CFG, "TLB3CFG",
894                      SPR_NOACCESS, SPR_NOACCESS,
895                      &spr_read_generic, SPR_NOACCESS,
896                      tlbncfg[3]);
897         /* Fallthru */
898     case 3:
899         spr_register(env, SPR_BOOKE_TLB2CFG, "TLB2CFG",
900                      SPR_NOACCESS, SPR_NOACCESS,
901                      &spr_read_generic, SPR_NOACCESS,
902                      tlbncfg[2]);
903         /* Fallthru */
904     case 2:
905         spr_register(env, SPR_BOOKE_TLB1CFG, "TLB1CFG",
906                      SPR_NOACCESS, SPR_NOACCESS,
907                      &spr_read_generic, SPR_NOACCESS,
908                      tlbncfg[1]);
909         /* Fallthru */
910     case 1:
911         spr_register(env, SPR_BOOKE_TLB0CFG, "TLB0CFG",
912                      SPR_NOACCESS, SPR_NOACCESS,
913                      &spr_read_generic, SPR_NOACCESS,
914                      tlbncfg[0]);
915         /* Fallthru */
916     case 0:
917     default:
918         break;
919     }
920 #endif
921 }
922 
923 /* SPR specific to PowerPC 440 implementation */
924 static void register_440_sprs(CPUPPCState *env)
925 {
926     /* Cache control */
927     spr_register(env, SPR_440_DNV0, "DNV0",
928                  SPR_NOACCESS, SPR_NOACCESS,
929                  &spr_read_generic, &spr_write_generic,
930                  0x00000000);
931 
932     spr_register(env, SPR_440_DNV1, "DNV1",
933                  SPR_NOACCESS, SPR_NOACCESS,
934                  &spr_read_generic, &spr_write_generic,
935                  0x00000000);
936 
937     spr_register(env, SPR_440_DNV2, "DNV2",
938                  SPR_NOACCESS, SPR_NOACCESS,
939                  &spr_read_generic, &spr_write_generic,
940                  0x00000000);
941 
942     spr_register(env, SPR_440_DNV3, "DNV3",
943                  SPR_NOACCESS, SPR_NOACCESS,
944                  &spr_read_generic, &spr_write_generic,
945                  0x00000000);
946 
947     spr_register(env, SPR_440_DTV0, "DTV0",
948                  SPR_NOACCESS, SPR_NOACCESS,
949                  &spr_read_generic, &spr_write_generic,
950                  0x00000000);
951 
952     spr_register(env, SPR_440_DTV1, "DTV1",
953                  SPR_NOACCESS, SPR_NOACCESS,
954                  &spr_read_generic, &spr_write_generic,
955                  0x00000000);
956 
957     spr_register(env, SPR_440_DTV2, "DTV2",
958                  SPR_NOACCESS, SPR_NOACCESS,
959                  &spr_read_generic, &spr_write_generic,
960                  0x00000000);
961 
962     spr_register(env, SPR_440_DTV3, "DTV3",
963                  SPR_NOACCESS, SPR_NOACCESS,
964                  &spr_read_generic, &spr_write_generic,
965                  0x00000000);
966 
967     spr_register(env, SPR_440_DVLIM, "DVLIM",
968                  SPR_NOACCESS, SPR_NOACCESS,
969                  &spr_read_generic, &spr_write_generic,
970                  0x00000000);
971 
972     spr_register(env, SPR_440_INV0, "INV0",
973                  SPR_NOACCESS, SPR_NOACCESS,
974                  &spr_read_generic, &spr_write_generic,
975                  0x00000000);
976 
977     spr_register(env, SPR_440_INV1, "INV1",
978                  SPR_NOACCESS, SPR_NOACCESS,
979                  &spr_read_generic, &spr_write_generic,
980                  0x00000000);
981 
982     spr_register(env, SPR_440_INV2, "INV2",
983                  SPR_NOACCESS, SPR_NOACCESS,
984                  &spr_read_generic, &spr_write_generic,
985                  0x00000000);
986 
987     spr_register(env, SPR_440_INV3, "INV3",
988                  SPR_NOACCESS, SPR_NOACCESS,
989                  &spr_read_generic, &spr_write_generic,
990                  0x00000000);
991 
992     spr_register(env, SPR_440_ITV0, "ITV0",
993                  SPR_NOACCESS, SPR_NOACCESS,
994                  &spr_read_generic, &spr_write_generic,
995                  0x00000000);
996 
997     spr_register(env, SPR_440_ITV1, "ITV1",
998                  SPR_NOACCESS, SPR_NOACCESS,
999                  &spr_read_generic, &spr_write_generic,
1000                  0x00000000);
1001 
1002     spr_register(env, SPR_440_ITV2, "ITV2",
1003                  SPR_NOACCESS, SPR_NOACCESS,
1004                  &spr_read_generic, &spr_write_generic,
1005                  0x00000000);
1006 
1007     spr_register(env, SPR_440_ITV3, "ITV3",
1008                  SPR_NOACCESS, SPR_NOACCESS,
1009                  &spr_read_generic, &spr_write_generic,
1010                  0x00000000);
1011 
1012     spr_register(env, SPR_440_IVLIM, "IVLIM",
1013                  SPR_NOACCESS, SPR_NOACCESS,
1014                  &spr_read_generic, &spr_write_generic,
1015                  0x00000000);
1016     /* Cache debug */
1017     spr_register(env, SPR_BOOKE_DCDBTRH, "DCDBTRH",
1018                  SPR_NOACCESS, SPR_NOACCESS,
1019                  &spr_read_generic, SPR_NOACCESS,
1020                  0x00000000);
1021 
1022     spr_register(env, SPR_BOOKE_DCDBTRL, "DCDBTRL",
1023                  SPR_NOACCESS, SPR_NOACCESS,
1024                  &spr_read_generic, SPR_NOACCESS,
1025                  0x00000000);
1026 
1027     spr_register(env, SPR_BOOKE_ICDBDR, "ICDBDR",
1028                  SPR_NOACCESS, SPR_NOACCESS,
1029                  &spr_read_generic, SPR_NOACCESS,
1030                  0x00000000);
1031 
1032     spr_register(env, SPR_BOOKE_ICDBTRH, "ICDBTRH",
1033                  SPR_NOACCESS, SPR_NOACCESS,
1034                  &spr_read_generic, SPR_NOACCESS,
1035                  0x00000000);
1036 
1037     spr_register(env, SPR_BOOKE_ICDBTRL, "ICDBTRL",
1038                  SPR_NOACCESS, SPR_NOACCESS,
1039                  &spr_read_generic, SPR_NOACCESS,
1040                  0x00000000);
1041 
1042     spr_register(env, SPR_440_DBDR, "DBDR",
1043                  SPR_NOACCESS, SPR_NOACCESS,
1044                  &spr_read_generic, &spr_write_generic,
1045                  0x00000000);
1046     /* Processor control */
1047     spr_register(env, SPR_4xx_CCR0, "CCR0",
1048                  SPR_NOACCESS, SPR_NOACCESS,
1049                  &spr_read_generic, &spr_write_generic,
1050                  0x00000000);
1051     spr_register(env, SPR_440_RSTCFG, "RSTCFG",
1052                  SPR_NOACCESS, SPR_NOACCESS,
1053                  &spr_read_generic, SPR_NOACCESS,
1054                  0x00000000);
1055     /* Storage control */
1056     spr_register(env, SPR_440_MMUCR, "MMUCR",
1057                  SPR_NOACCESS, SPR_NOACCESS,
1058                  &spr_read_generic, &spr_write_generic,
1059                  0x00000000);
1060 
1061     /* Processor identification */
1062     spr_register(env, SPR_BOOKE_PIR, "PIR",
1063                  SPR_NOACCESS, SPR_NOACCESS,
1064                  &spr_read_generic, &spr_write_pir,
1065                  0x00000000);
1066 
1067     spr_register(env, SPR_BOOKE_IAC3, "IAC3",
1068                  SPR_NOACCESS, SPR_NOACCESS,
1069                  &spr_read_generic, &spr_write_generic,
1070                  0x00000000);
1071 
1072     spr_register(env, SPR_BOOKE_IAC4, "IAC4",
1073                  SPR_NOACCESS, SPR_NOACCESS,
1074                  &spr_read_generic, &spr_write_generic,
1075                  0x00000000);
1076 
1077     spr_register(env, SPR_BOOKE_DVC1, "DVC1",
1078                  SPR_NOACCESS, SPR_NOACCESS,
1079                  &spr_read_generic, &spr_write_generic,
1080                  0x00000000);
1081 
1082     spr_register(env, SPR_BOOKE_DVC2, "DVC2",
1083                  SPR_NOACCESS, SPR_NOACCESS,
1084                  &spr_read_generic, &spr_write_generic,
1085                  0x00000000);
1086 }
1087 
1088 /* SPR shared between PowerPC 40x implementations */
1089 static void register_40x_sprs(CPUPPCState *env)
1090 {
1091     /* Cache */
1092     /* not emulated, as QEMU do not emulate caches */
1093     spr_register(env, SPR_40x_DCCR, "DCCR",
1094                  SPR_NOACCESS, SPR_NOACCESS,
1095                  &spr_read_generic, &spr_write_generic,
1096                  0x00000000);
1097     /* not emulated, as QEMU do not emulate caches */
1098     spr_register(env, SPR_40x_ICCR, "ICCR",
1099                  SPR_NOACCESS, SPR_NOACCESS,
1100                  &spr_read_generic, &spr_write_generic,
1101                  0x00000000);
1102     /* not emulated, as QEMU do not emulate caches */
1103     spr_register(env, SPR_BOOKE_ICDBDR, "ICDBDR",
1104                  SPR_NOACCESS, SPR_NOACCESS,
1105                  &spr_read_generic, SPR_NOACCESS,
1106                  0x00000000);
1107     /* Exception */
1108     spr_register(env, SPR_40x_DEAR, "DEAR",
1109                  SPR_NOACCESS, SPR_NOACCESS,
1110                  &spr_read_generic, &spr_write_generic,
1111                  0x00000000);
1112     spr_register(env, SPR_40x_ESR, "ESR",
1113                  SPR_NOACCESS, SPR_NOACCESS,
1114                  &spr_read_generic, &spr_write_generic,
1115                  0x00000000);
1116     spr_register(env, SPR_40x_EVPR, "EVPR",
1117                  SPR_NOACCESS, SPR_NOACCESS,
1118                  &spr_read_generic, &spr_write_excp_prefix,
1119                  0x00000000);
1120     spr_register(env, SPR_40x_SRR2, "SRR2",
1121                  &spr_read_generic, &spr_write_generic,
1122                  &spr_read_generic, &spr_write_generic,
1123                  0x00000000);
1124     spr_register(env, SPR_40x_SRR3, "SRR3",
1125                  &spr_read_generic, &spr_write_generic,
1126                  &spr_read_generic, &spr_write_generic,
1127                  0x00000000);
1128     /* Timers */
1129     spr_register(env, SPR_40x_PIT, "PIT",
1130                  SPR_NOACCESS, SPR_NOACCESS,
1131                  &spr_read_40x_pit, &spr_write_40x_pit,
1132                  0x00000000);
1133     spr_register(env, SPR_40x_TCR, "TCR",
1134                  SPR_NOACCESS, SPR_NOACCESS,
1135                  &spr_read_generic, &spr_write_40x_tcr,
1136                  0x00000000);
1137     spr_register(env, SPR_40x_TSR, "TSR",
1138                  SPR_NOACCESS, SPR_NOACCESS,
1139                  &spr_read_generic, &spr_write_40x_tsr,
1140                  0x00000000);
1141 }
1142 
1143 /* SPR specific to PowerPC 405 implementation */
1144 static void register_405_sprs(CPUPPCState *env)
1145 {
1146     /* MMU */
1147     spr_register(env, SPR_40x_PID, "PID",
1148                  SPR_NOACCESS, SPR_NOACCESS,
1149                  &spr_read_generic, &spr_write_40x_pid,
1150                  0x00000000);
1151     spr_register(env, SPR_4xx_CCR0, "CCR0",
1152                  SPR_NOACCESS, SPR_NOACCESS,
1153                  &spr_read_generic, &spr_write_generic,
1154                  0x00700000);
1155     /* Debug interface */
1156     spr_register(env, SPR_40x_DBCR0, "DBCR0",
1157                  SPR_NOACCESS, SPR_NOACCESS,
1158                  &spr_read_generic, &spr_write_40x_dbcr0,
1159                  0x00000000);
1160 
1161     spr_register(env, SPR_405_DBCR1, "DBCR1",
1162                  SPR_NOACCESS, SPR_NOACCESS,
1163                  &spr_read_generic, &spr_write_generic,
1164                  0x00000000);
1165 
1166     spr_register(env, SPR_40x_DBSR, "DBSR",
1167                  SPR_NOACCESS, SPR_NOACCESS,
1168                  &spr_read_generic, &spr_write_clear,
1169                  /* Last reset was system reset */
1170                  0x00000300);
1171 
1172     spr_register(env, SPR_40x_DAC1, "DAC1",
1173                  SPR_NOACCESS, SPR_NOACCESS,
1174                  &spr_read_generic, &spr_write_generic,
1175                  0x00000000);
1176     spr_register(env, SPR_40x_DAC2, "DAC2",
1177                  SPR_NOACCESS, SPR_NOACCESS,
1178                  &spr_read_generic, &spr_write_generic,
1179                  0x00000000);
1180 
1181     spr_register(env, SPR_405_DVC1, "DVC1",
1182                  SPR_NOACCESS, SPR_NOACCESS,
1183                  &spr_read_generic, &spr_write_generic,
1184                  0x00000000);
1185 
1186     spr_register(env, SPR_405_DVC2, "DVC2",
1187                  SPR_NOACCESS, SPR_NOACCESS,
1188                  &spr_read_generic, &spr_write_generic,
1189                  0x00000000);
1190 
1191     spr_register(env, SPR_40x_IAC1, "IAC1",
1192                  SPR_NOACCESS, SPR_NOACCESS,
1193                  &spr_read_generic, &spr_write_generic,
1194                  0x00000000);
1195     spr_register(env, SPR_40x_IAC2, "IAC2",
1196                  SPR_NOACCESS, SPR_NOACCESS,
1197                  &spr_read_generic, &spr_write_generic,
1198                  0x00000000);
1199 
1200     spr_register(env, SPR_405_IAC3, "IAC3",
1201                  SPR_NOACCESS, SPR_NOACCESS,
1202                  &spr_read_generic, &spr_write_generic,
1203                  0x00000000);
1204 
1205     spr_register(env, SPR_405_IAC4, "IAC4",
1206                  SPR_NOACCESS, SPR_NOACCESS,
1207                  &spr_read_generic, &spr_write_generic,
1208                  0x00000000);
1209     /* Storage control */
1210     spr_register(env, SPR_405_SLER, "SLER",
1211                  SPR_NOACCESS, SPR_NOACCESS,
1212                  &spr_read_generic, &spr_write_40x_sler,
1213                  0x00000000);
1214     spr_register(env, SPR_40x_ZPR, "ZPR",
1215                  SPR_NOACCESS, SPR_NOACCESS,
1216                  &spr_read_generic, &spr_write_generic,
1217                  0x00000000);
1218 
1219     spr_register(env, SPR_405_SU0R, "SU0R",
1220                  SPR_NOACCESS, SPR_NOACCESS,
1221                  &spr_read_generic, &spr_write_generic,
1222                  0x00000000);
1223     /* SPRG */
1224     spr_register(env, SPR_USPRG0, "USPRG0",
1225                  &spr_read_ureg, SPR_NOACCESS,
1226                  &spr_read_ureg, SPR_NOACCESS,
1227                  0x00000000);
1228     spr_register(env, SPR_SPRG4, "SPRG4",
1229                  SPR_NOACCESS, SPR_NOACCESS,
1230                  &spr_read_generic, &spr_write_generic,
1231                  0x00000000);
1232     spr_register(env, SPR_SPRG5, "SPRG5",
1233                  SPR_NOACCESS, SPR_NOACCESS,
1234                  spr_read_generic, &spr_write_generic,
1235                  0x00000000);
1236     spr_register(env, SPR_SPRG6, "SPRG6",
1237                  SPR_NOACCESS, SPR_NOACCESS,
1238                  spr_read_generic, &spr_write_generic,
1239                  0x00000000);
1240     spr_register(env, SPR_SPRG7, "SPRG7",
1241                  SPR_NOACCESS, SPR_NOACCESS,
1242                  spr_read_generic, &spr_write_generic,
1243                  0x00000000);
1244 
1245     /* Bus access control */
1246     /* not emulated, as QEMU never does speculative access */
1247     spr_register(env, SPR_40x_SGR, "SGR",
1248                  SPR_NOACCESS, SPR_NOACCESS,
1249                  &spr_read_generic, &spr_write_generic,
1250                  0xFFFFFFFF);
1251     /* not emulated, as QEMU do not emulate caches */
1252     spr_register(env, SPR_40x_DCWR, "DCWR",
1253                  SPR_NOACCESS, SPR_NOACCESS,
1254                  &spr_read_generic, &spr_write_generic,
1255                  0x00000000);
1256 }
1257 
1258 
1259 static void register_5xx_8xx_sprs(CPUPPCState *env)
1260 {
1261     /* Exception processing */
1262     spr_register_kvm(env, SPR_DSISR, "DSISR",
1263                      SPR_NOACCESS, SPR_NOACCESS,
1264                      &spr_read_generic, &spr_write_generic,
1265                      KVM_REG_PPC_DSISR, 0x00000000);
1266     spr_register_kvm(env, SPR_DAR, "DAR",
1267                      SPR_NOACCESS, SPR_NOACCESS,
1268                      &spr_read_generic, &spr_write_generic,
1269                      KVM_REG_PPC_DAR, 0x00000000);
1270     /* Timer */
1271     spr_register(env, SPR_DECR, "DECR",
1272                  SPR_NOACCESS, SPR_NOACCESS,
1273                  &spr_read_decr, &spr_write_decr,
1274                  0x00000000);
1275 
1276     spr_register(env, SPR_MPC_EIE, "EIE",
1277                  SPR_NOACCESS, SPR_NOACCESS,
1278                  &spr_read_generic, &spr_write_generic,
1279                  0x00000000);
1280 
1281     spr_register(env, SPR_MPC_EID, "EID",
1282                  SPR_NOACCESS, SPR_NOACCESS,
1283                  &spr_read_generic, &spr_write_generic,
1284                  0x00000000);
1285 
1286     spr_register(env, SPR_MPC_NRI, "NRI",
1287                  SPR_NOACCESS, SPR_NOACCESS,
1288                  &spr_read_generic, &spr_write_generic,
1289                  0x00000000);
1290 
1291     spr_register(env, SPR_MPC_CMPA, "CMPA",
1292                  SPR_NOACCESS, SPR_NOACCESS,
1293                  &spr_read_generic, &spr_write_generic,
1294                  0x00000000);
1295 
1296     spr_register(env, SPR_MPC_CMPB, "CMPB",
1297                  SPR_NOACCESS, SPR_NOACCESS,
1298                  &spr_read_generic, &spr_write_generic,
1299                  0x00000000);
1300 
1301     spr_register(env, SPR_MPC_CMPC, "CMPC",
1302                  SPR_NOACCESS, SPR_NOACCESS,
1303                  &spr_read_generic, &spr_write_generic,
1304                  0x00000000);
1305 
1306     spr_register(env, SPR_MPC_CMPD, "CMPD",
1307                  SPR_NOACCESS, SPR_NOACCESS,
1308                  &spr_read_generic, &spr_write_generic,
1309                  0x00000000);
1310 
1311     spr_register(env, SPR_MPC_ECR, "ECR",
1312                  SPR_NOACCESS, SPR_NOACCESS,
1313                  &spr_read_generic, &spr_write_generic,
1314                  0x00000000);
1315 
1316     spr_register(env, SPR_MPC_DER, "DER",
1317                  SPR_NOACCESS, SPR_NOACCESS,
1318                  &spr_read_generic, &spr_write_generic,
1319                  0x00000000);
1320 
1321     spr_register(env, SPR_MPC_COUNTA, "COUNTA",
1322                  SPR_NOACCESS, SPR_NOACCESS,
1323                  &spr_read_generic, &spr_write_generic,
1324                  0x00000000);
1325 
1326     spr_register(env, SPR_MPC_COUNTB, "COUNTB",
1327                  SPR_NOACCESS, SPR_NOACCESS,
1328                  &spr_read_generic, &spr_write_generic,
1329                  0x00000000);
1330 
1331     spr_register(env, SPR_MPC_CMPE, "CMPE",
1332                  SPR_NOACCESS, SPR_NOACCESS,
1333                  &spr_read_generic, &spr_write_generic,
1334                  0x00000000);
1335 
1336     spr_register(env, SPR_MPC_CMPF, "CMPF",
1337                  SPR_NOACCESS, SPR_NOACCESS,
1338                  &spr_read_generic, &spr_write_generic,
1339                  0x00000000);
1340 
1341     spr_register(env, SPR_MPC_CMPG, "CMPG",
1342                  SPR_NOACCESS, SPR_NOACCESS,
1343                  &spr_read_generic, &spr_write_generic,
1344                  0x00000000);
1345 
1346     spr_register(env, SPR_MPC_CMPH, "CMPH",
1347                  SPR_NOACCESS, SPR_NOACCESS,
1348                  &spr_read_generic, &spr_write_generic,
1349                  0x00000000);
1350 
1351     spr_register(env, SPR_MPC_LCTRL1, "LCTRL1",
1352                  SPR_NOACCESS, SPR_NOACCESS,
1353                  &spr_read_generic, &spr_write_generic,
1354                  0x00000000);
1355 
1356     spr_register(env, SPR_MPC_LCTRL2, "LCTRL2",
1357                  SPR_NOACCESS, SPR_NOACCESS,
1358                  &spr_read_generic, &spr_write_generic,
1359                  0x00000000);
1360 
1361     spr_register(env, SPR_MPC_BAR, "BAR",
1362                  SPR_NOACCESS, SPR_NOACCESS,
1363                  &spr_read_generic, &spr_write_generic,
1364                  0x00000000);
1365 
1366     spr_register(env, SPR_MPC_DPDR, "DPDR",
1367                  SPR_NOACCESS, SPR_NOACCESS,
1368                  &spr_read_generic, &spr_write_generic,
1369                  0x00000000);
1370 
1371     spr_register(env, SPR_MPC_IMMR, "IMMR",
1372                  SPR_NOACCESS, SPR_NOACCESS,
1373                  &spr_read_generic, &spr_write_generic,
1374                  0x00000000);
1375 }
1376 
1377 static void register_5xx_sprs(CPUPPCState *env)
1378 {
1379     spr_register(env, SPR_RCPU_MI_GRA, "MI_GRA",
1380                  SPR_NOACCESS, SPR_NOACCESS,
1381                  &spr_read_generic, &spr_write_generic,
1382                  0x00000000);
1383 
1384     spr_register(env, SPR_RCPU_L2U_GRA, "L2U_GRA",
1385                  SPR_NOACCESS, SPR_NOACCESS,
1386                  &spr_read_generic, &spr_write_generic,
1387                  0x00000000);
1388 
1389     spr_register(env, SPR_RPCU_BBCMCR, "L2U_BBCMCR",
1390                  SPR_NOACCESS, SPR_NOACCESS,
1391                  &spr_read_generic, &spr_write_generic,
1392                  0x00000000);
1393 
1394     spr_register(env, SPR_RCPU_L2U_MCR, "L2U_MCR",
1395                  SPR_NOACCESS, SPR_NOACCESS,
1396                  &spr_read_generic, &spr_write_generic,
1397                  0x00000000);
1398 
1399     spr_register(env, SPR_RCPU_MI_RBA0, "MI_RBA0",
1400                  SPR_NOACCESS, SPR_NOACCESS,
1401                  &spr_read_generic, &spr_write_generic,
1402                  0x00000000);
1403 
1404     spr_register(env, SPR_RCPU_MI_RBA1, "MI_RBA1",
1405                  SPR_NOACCESS, SPR_NOACCESS,
1406                  &spr_read_generic, &spr_write_generic,
1407                  0x00000000);
1408 
1409     spr_register(env, SPR_RCPU_MI_RBA2, "MI_RBA2",
1410                  SPR_NOACCESS, SPR_NOACCESS,
1411                  &spr_read_generic, &spr_write_generic,
1412                  0x00000000);
1413 
1414     spr_register(env, SPR_RCPU_MI_RBA3, "MI_RBA3",
1415                  SPR_NOACCESS, SPR_NOACCESS,
1416                  &spr_read_generic, &spr_write_generic,
1417                  0x00000000);
1418 
1419     spr_register(env, SPR_RCPU_L2U_RBA0, "L2U_RBA0",
1420                  SPR_NOACCESS, SPR_NOACCESS,
1421                  &spr_read_generic, &spr_write_generic,
1422                  0x00000000);
1423 
1424     spr_register(env, SPR_RCPU_L2U_RBA1, "L2U_RBA1",
1425                  SPR_NOACCESS, SPR_NOACCESS,
1426                  &spr_read_generic, &spr_write_generic,
1427                  0x00000000);
1428 
1429     spr_register(env, SPR_RCPU_L2U_RBA2, "L2U_RBA2",
1430                  SPR_NOACCESS, SPR_NOACCESS,
1431                  &spr_read_generic, &spr_write_generic,
1432                  0x00000000);
1433 
1434     spr_register(env, SPR_RCPU_L2U_RBA3, "L2U_RBA3",
1435                  SPR_NOACCESS, SPR_NOACCESS,
1436                  &spr_read_generic, &spr_write_generic,
1437                  0x00000000);
1438 
1439     spr_register(env, SPR_RCPU_MI_RA0, "MI_RA0",
1440                  SPR_NOACCESS, SPR_NOACCESS,
1441                  &spr_read_generic, &spr_write_generic,
1442                  0x00000000);
1443 
1444     spr_register(env, SPR_RCPU_MI_RA1, "MI_RA1",
1445                  SPR_NOACCESS, SPR_NOACCESS,
1446                  &spr_read_generic, &spr_write_generic,
1447                  0x00000000);
1448 
1449     spr_register(env, SPR_RCPU_MI_RA2, "MI_RA2",
1450                  SPR_NOACCESS, SPR_NOACCESS,
1451                  &spr_read_generic, &spr_write_generic,
1452                  0x00000000);
1453 
1454     spr_register(env, SPR_RCPU_MI_RA3, "MI_RA3",
1455                  SPR_NOACCESS, SPR_NOACCESS,
1456                  &spr_read_generic, &spr_write_generic,
1457                  0x00000000);
1458 
1459     spr_register(env, SPR_RCPU_L2U_RA0, "L2U_RA0",
1460                  SPR_NOACCESS, SPR_NOACCESS,
1461                  &spr_read_generic, &spr_write_generic,
1462                  0x00000000);
1463 
1464     spr_register(env, SPR_RCPU_L2U_RA1, "L2U_RA1",
1465                  SPR_NOACCESS, SPR_NOACCESS,
1466                  &spr_read_generic, &spr_write_generic,
1467                  0x00000000);
1468 
1469     spr_register(env, SPR_RCPU_L2U_RA2, "L2U_RA2",
1470                  SPR_NOACCESS, SPR_NOACCESS,
1471                  &spr_read_generic, &spr_write_generic,
1472                  0x00000000);
1473 
1474     spr_register(env, SPR_RCPU_L2U_RA3, "L2U_RA3",
1475                  SPR_NOACCESS, SPR_NOACCESS,
1476                  &spr_read_generic, &spr_write_generic,
1477                  0x00000000);
1478 
1479     spr_register(env, SPR_RCPU_FPECR, "FPECR",
1480                  SPR_NOACCESS, SPR_NOACCESS,
1481                  &spr_read_generic, &spr_write_generic,
1482                  0x00000000);
1483 }
1484 
1485 static void register_8xx_sprs(CPUPPCState *env)
1486 {
1487 
1488     spr_register(env, SPR_MPC_IC_CST, "IC_CST",
1489                  SPR_NOACCESS, SPR_NOACCESS,
1490                  &spr_read_generic, &spr_write_generic,
1491                  0x00000000);
1492 
1493     spr_register(env, SPR_MPC_IC_ADR, "IC_ADR",
1494                  SPR_NOACCESS, SPR_NOACCESS,
1495                  &spr_read_generic, &spr_write_generic,
1496                  0x00000000);
1497 
1498     spr_register(env, SPR_MPC_IC_DAT, "IC_DAT",
1499                  SPR_NOACCESS, SPR_NOACCESS,
1500                  &spr_read_generic, &spr_write_generic,
1501                  0x00000000);
1502 
1503     spr_register(env, SPR_MPC_DC_CST, "DC_CST",
1504                  SPR_NOACCESS, SPR_NOACCESS,
1505                  &spr_read_generic, &spr_write_generic,
1506                  0x00000000);
1507 
1508     spr_register(env, SPR_MPC_DC_ADR, "DC_ADR",
1509                  SPR_NOACCESS, SPR_NOACCESS,
1510                  &spr_read_generic, &spr_write_generic,
1511                  0x00000000);
1512 
1513     spr_register(env, SPR_MPC_DC_DAT, "DC_DAT",
1514                  SPR_NOACCESS, SPR_NOACCESS,
1515                  &spr_read_generic, &spr_write_generic,
1516                  0x00000000);
1517 
1518     spr_register(env, SPR_MPC_MI_CTR, "MI_CTR",
1519                  SPR_NOACCESS, SPR_NOACCESS,
1520                  &spr_read_generic, &spr_write_generic,
1521                  0x00000000);
1522 
1523     spr_register(env, SPR_MPC_MI_AP, "MI_AP",
1524                  SPR_NOACCESS, SPR_NOACCESS,
1525                  &spr_read_generic, &spr_write_generic,
1526                  0x00000000);
1527 
1528     spr_register(env, SPR_MPC_MI_EPN, "MI_EPN",
1529                  SPR_NOACCESS, SPR_NOACCESS,
1530                  &spr_read_generic, &spr_write_generic,
1531                  0x00000000);
1532 
1533     spr_register(env, SPR_MPC_MI_TWC, "MI_TWC",
1534                  SPR_NOACCESS, SPR_NOACCESS,
1535                  &spr_read_generic, &spr_write_generic,
1536                  0x00000000);
1537 
1538     spr_register(env, SPR_MPC_MI_RPN, "MI_RPN",
1539                  SPR_NOACCESS, SPR_NOACCESS,
1540                  &spr_read_generic, &spr_write_generic,
1541                  0x00000000);
1542 
1543     spr_register(env, SPR_MPC_MI_DBCAM, "MI_DBCAM",
1544                  SPR_NOACCESS, SPR_NOACCESS,
1545                  &spr_read_generic, &spr_write_generic,
1546                  0x00000000);
1547 
1548     spr_register(env, SPR_MPC_MI_DBRAM0, "MI_DBRAM0",
1549                  SPR_NOACCESS, SPR_NOACCESS,
1550                  &spr_read_generic, &spr_write_generic,
1551                  0x00000000);
1552 
1553     spr_register(env, SPR_MPC_MI_DBRAM1, "MI_DBRAM1",
1554                  SPR_NOACCESS, SPR_NOACCESS,
1555                  &spr_read_generic, &spr_write_generic,
1556                  0x00000000);
1557 
1558     spr_register(env, SPR_MPC_MD_CTR, "MD_CTR",
1559                  SPR_NOACCESS, SPR_NOACCESS,
1560                  &spr_read_generic, &spr_write_generic,
1561                  0x00000000);
1562 
1563     spr_register(env, SPR_MPC_MD_CASID, "MD_CASID",
1564                  SPR_NOACCESS, SPR_NOACCESS,
1565                  &spr_read_generic, &spr_write_generic,
1566                  0x00000000);
1567 
1568     spr_register(env, SPR_MPC_MD_AP, "MD_AP",
1569                  SPR_NOACCESS, SPR_NOACCESS,
1570                  &spr_read_generic, &spr_write_generic,
1571                  0x00000000);
1572 
1573     spr_register(env, SPR_MPC_MD_EPN, "MD_EPN",
1574                  SPR_NOACCESS, SPR_NOACCESS,
1575                  &spr_read_generic, &spr_write_generic,
1576                  0x00000000);
1577 
1578     spr_register(env, SPR_MPC_MD_TWB, "MD_TWB",
1579                  SPR_NOACCESS, SPR_NOACCESS,
1580                  &spr_read_generic, &spr_write_generic,
1581                  0x00000000);
1582 
1583     spr_register(env, SPR_MPC_MD_TWC, "MD_TWC",
1584                  SPR_NOACCESS, SPR_NOACCESS,
1585                  &spr_read_generic, &spr_write_generic,
1586                  0x00000000);
1587 
1588     spr_register(env, SPR_MPC_MD_RPN, "MD_RPN",
1589                  SPR_NOACCESS, SPR_NOACCESS,
1590                  &spr_read_generic, &spr_write_generic,
1591                  0x00000000);
1592 
1593     spr_register(env, SPR_MPC_MD_TW, "MD_TW",
1594                  SPR_NOACCESS, SPR_NOACCESS,
1595                  &spr_read_generic, &spr_write_generic,
1596                  0x00000000);
1597 
1598     spr_register(env, SPR_MPC_MD_DBCAM, "MD_DBCAM",
1599                  SPR_NOACCESS, SPR_NOACCESS,
1600                  &spr_read_generic, &spr_write_generic,
1601                  0x00000000);
1602 
1603     spr_register(env, SPR_MPC_MD_DBRAM0, "MD_DBRAM0",
1604                  SPR_NOACCESS, SPR_NOACCESS,
1605                  &spr_read_generic, &spr_write_generic,
1606                  0x00000000);
1607 
1608     spr_register(env, SPR_MPC_MD_DBRAM1, "MD_DBRAM1",
1609                  SPR_NOACCESS, SPR_NOACCESS,
1610                  &spr_read_generic, &spr_write_generic,
1611                  0x00000000);
1612 }
1613 
1614 /*
1615  * AMR     => SPR 29 (Power 2.04)
1616  * CTRL    => SPR 136 (Power 2.04)
1617  * CTRL    => SPR 152 (Power 2.04)
1618  * SCOMC   => SPR 276 (64 bits ?)
1619  * SCOMD   => SPR 277 (64 bits ?)
1620  * TBU40   => SPR 286 (Power 2.04 hypv)
1621  * HSPRG0  => SPR 304 (Power 2.04 hypv)
1622  * HSPRG1  => SPR 305 (Power 2.04 hypv)
1623  * HDSISR  => SPR 306 (Power 2.04 hypv)
1624  * HDAR    => SPR 307 (Power 2.04 hypv)
1625  * PURR    => SPR 309 (Power 2.04 hypv)
1626  * HDEC    => SPR 310 (Power 2.04 hypv)
1627  * HIOR    => SPR 311 (hypv)
1628  * RMOR    => SPR 312 (970)
1629  * HRMOR   => SPR 313 (Power 2.04 hypv)
1630  * HSRR0   => SPR 314 (Power 2.04 hypv)
1631  * HSRR1   => SPR 315 (Power 2.04 hypv)
1632  * LPIDR   => SPR 317 (970)
1633  * HEIR    => SPR 339 (Power 2.05 hypv) (64-bit reg from 3.1)
1634  * EPR     => SPR 702 (Power 2.04 emb)
1635  * perf    => 768-783 (Power 2.04)
1636  * perf    => 784-799 (Power 2.04)
1637  * PPR     => SPR 896 (Power 2.04)
1638  * DABRX   => 1015    (Power 2.04 hypv)
1639  * FPECR   => SPR 1022 (?)
1640  * ... and more (thermal management, performance counters, ...)
1641  */
1642 
1643 /*****************************************************************************/
1644 /* Exception vectors models                                                  */
1645 static void init_excp_4xx_softmmu(CPUPPCState *env)
1646 {
1647 #if !defined(CONFIG_USER_ONLY)
1648     env->excp_vectors[POWERPC_EXCP_CRITICAL] = 0x00000100;
1649     env->excp_vectors[POWERPC_EXCP_MCHECK]   = 0x00000200;
1650     env->excp_vectors[POWERPC_EXCP_DSI]      = 0x00000300;
1651     env->excp_vectors[POWERPC_EXCP_ISI]      = 0x00000400;
1652     env->excp_vectors[POWERPC_EXCP_EXTERNAL] = 0x00000500;
1653     env->excp_vectors[POWERPC_EXCP_ALIGN]    = 0x00000600;
1654     env->excp_vectors[POWERPC_EXCP_PROGRAM]  = 0x00000700;
1655     env->excp_vectors[POWERPC_EXCP_SYSCALL]  = 0x00000C00;
1656     env->excp_vectors[POWERPC_EXCP_PIT]      = 0x00001000;
1657     env->excp_vectors[POWERPC_EXCP_FIT]      = 0x00001010;
1658     env->excp_vectors[POWERPC_EXCP_WDT]      = 0x00001020;
1659     env->excp_vectors[POWERPC_EXCP_DTLB]     = 0x00001100;
1660     env->excp_vectors[POWERPC_EXCP_ITLB]     = 0x00001200;
1661     env->excp_vectors[POWERPC_EXCP_DEBUG]    = 0x00002000;
1662     env->ivor_mask = 0x0000FFF0UL;
1663     env->ivpr_mask = 0xFFFF0000UL;
1664     /* Hardware reset vector */
1665     env->hreset_vector = 0xFFFFFFFCUL;
1666 #endif
1667 }
1668 
1669 static void init_excp_MPC5xx(CPUPPCState *env)
1670 {
1671 #if !defined(CONFIG_USER_ONLY)
1672     env->excp_vectors[POWERPC_EXCP_RESET]    = 0x00000100;
1673     env->excp_vectors[POWERPC_EXCP_MCHECK]   = 0x00000200;
1674     env->excp_vectors[POWERPC_EXCP_EXTERNAL] = 0x00000500;
1675     env->excp_vectors[POWERPC_EXCP_ALIGN]    = 0x00000600;
1676     env->excp_vectors[POWERPC_EXCP_PROGRAM]  = 0x00000700;
1677     env->excp_vectors[POWERPC_EXCP_FPU]      = 0x00000800;
1678     env->excp_vectors[POWERPC_EXCP_DECR]     = 0x00000900;
1679     env->excp_vectors[POWERPC_EXCP_SYSCALL]  = 0x00000C00;
1680     env->excp_vectors[POWERPC_EXCP_TRACE]    = 0x00000D00;
1681     env->excp_vectors[POWERPC_EXCP_FPA]      = 0x00000E00;
1682     env->excp_vectors[POWERPC_EXCP_EMUL]     = 0x00001000;
1683     env->excp_vectors[POWERPC_EXCP_DABR]     = 0x00001C00;
1684     env->excp_vectors[POWERPC_EXCP_IABR]     = 0x00001C00;
1685     env->excp_vectors[POWERPC_EXCP_MEXTBR]   = 0x00001E00;
1686     env->excp_vectors[POWERPC_EXCP_NMEXTBR]  = 0x00001F00;
1687     env->ivor_mask = 0x0000FFF0UL;
1688     env->ivpr_mask = 0xFFFF0000UL;
1689     /* Hardware reset vector */
1690     env->hreset_vector = 0x00000100UL;
1691 #endif
1692 }
1693 
1694 static void init_excp_MPC8xx(CPUPPCState *env)
1695 {
1696 #if !defined(CONFIG_USER_ONLY)
1697     env->excp_vectors[POWERPC_EXCP_RESET]    = 0x00000100;
1698     env->excp_vectors[POWERPC_EXCP_MCHECK]   = 0x00000200;
1699     env->excp_vectors[POWERPC_EXCP_DSI]      = 0x00000300;
1700     env->excp_vectors[POWERPC_EXCP_ISI]      = 0x00000400;
1701     env->excp_vectors[POWERPC_EXCP_EXTERNAL] = 0x00000500;
1702     env->excp_vectors[POWERPC_EXCP_ALIGN]    = 0x00000600;
1703     env->excp_vectors[POWERPC_EXCP_PROGRAM]  = 0x00000700;
1704     env->excp_vectors[POWERPC_EXCP_FPU]      = 0x00000800;
1705     env->excp_vectors[POWERPC_EXCP_DECR]     = 0x00000900;
1706     env->excp_vectors[POWERPC_EXCP_SYSCALL]  = 0x00000C00;
1707     env->excp_vectors[POWERPC_EXCP_TRACE]    = 0x00000D00;
1708     env->excp_vectors[POWERPC_EXCP_FPA]      = 0x00000E00;
1709     env->excp_vectors[POWERPC_EXCP_EMUL]     = 0x00001000;
1710     env->excp_vectors[POWERPC_EXCP_ITLB]     = 0x00001100;
1711     env->excp_vectors[POWERPC_EXCP_DTLB]     = 0x00001200;
1712     env->excp_vectors[POWERPC_EXCP_ITLBE]    = 0x00001300;
1713     env->excp_vectors[POWERPC_EXCP_DTLBE]    = 0x00001400;
1714     env->excp_vectors[POWERPC_EXCP_DABR]     = 0x00001C00;
1715     env->excp_vectors[POWERPC_EXCP_IABR]     = 0x00001C00;
1716     env->excp_vectors[POWERPC_EXCP_MEXTBR]   = 0x00001E00;
1717     env->excp_vectors[POWERPC_EXCP_NMEXTBR]  = 0x00001F00;
1718     env->ivor_mask = 0x0000FFF0UL;
1719     env->ivpr_mask = 0xFFFF0000UL;
1720     /* Hardware reset vector */
1721     env->hreset_vector = 0x00000100UL;
1722 #endif
1723 }
1724 
1725 static void init_excp_G2(CPUPPCState *env)
1726 {
1727 #if !defined(CONFIG_USER_ONLY)
1728     env->excp_vectors[POWERPC_EXCP_RESET]    = 0x00000100;
1729     env->excp_vectors[POWERPC_EXCP_MCHECK]   = 0x00000200;
1730     env->excp_vectors[POWERPC_EXCP_DSI]      = 0x00000300;
1731     env->excp_vectors[POWERPC_EXCP_ISI]      = 0x00000400;
1732     env->excp_vectors[POWERPC_EXCP_EXTERNAL] = 0x00000500;
1733     env->excp_vectors[POWERPC_EXCP_ALIGN]    = 0x00000600;
1734     env->excp_vectors[POWERPC_EXCP_PROGRAM]  = 0x00000700;
1735     env->excp_vectors[POWERPC_EXCP_FPU]      = 0x00000800;
1736     env->excp_vectors[POWERPC_EXCP_DECR]     = 0x00000900;
1737     env->excp_vectors[POWERPC_EXCP_CRITICAL] = 0x00000A00;
1738     env->excp_vectors[POWERPC_EXCP_SYSCALL]  = 0x00000C00;
1739     env->excp_vectors[POWERPC_EXCP_TRACE]    = 0x00000D00;
1740     env->excp_vectors[POWERPC_EXCP_IFTLB]    = 0x00001000;
1741     env->excp_vectors[POWERPC_EXCP_DLTLB]    = 0x00001100;
1742     env->excp_vectors[POWERPC_EXCP_DSTLB]    = 0x00001200;
1743     env->excp_vectors[POWERPC_EXCP_IABR]     = 0x00001300;
1744     env->excp_vectors[POWERPC_EXCP_SMI]      = 0x00001400;
1745     /* Hardware reset vector */
1746     env->hreset_vector = 0x00000100UL;
1747 #endif
1748 }
1749 
1750 static void init_excp_e200(CPUPPCState *env, target_ulong ivpr_mask)
1751 {
1752 #if !defined(CONFIG_USER_ONLY)
1753     env->excp_vectors[POWERPC_EXCP_RESET]    = 0x00000FFC;
1754     env->excp_vectors[POWERPC_EXCP_CRITICAL] = 0x00000000;
1755     env->excp_vectors[POWERPC_EXCP_MCHECK]   = 0x00000000;
1756     env->excp_vectors[POWERPC_EXCP_DSI]      = 0x00000000;
1757     env->excp_vectors[POWERPC_EXCP_ISI]      = 0x00000000;
1758     env->excp_vectors[POWERPC_EXCP_EXTERNAL] = 0x00000000;
1759     env->excp_vectors[POWERPC_EXCP_ALIGN]    = 0x00000000;
1760     env->excp_vectors[POWERPC_EXCP_PROGRAM]  = 0x00000000;
1761     env->excp_vectors[POWERPC_EXCP_FPU]      = 0x00000000;
1762     env->excp_vectors[POWERPC_EXCP_SYSCALL]  = 0x00000000;
1763     env->excp_vectors[POWERPC_EXCP_APU]      = 0x00000000;
1764     env->excp_vectors[POWERPC_EXCP_DECR]     = 0x00000000;
1765     env->excp_vectors[POWERPC_EXCP_FIT]      = 0x00000000;
1766     env->excp_vectors[POWERPC_EXCP_WDT]      = 0x00000000;
1767     env->excp_vectors[POWERPC_EXCP_DTLB]     = 0x00000000;
1768     env->excp_vectors[POWERPC_EXCP_ITLB]     = 0x00000000;
1769     env->excp_vectors[POWERPC_EXCP_DEBUG]    = 0x00000000;
1770     /*
1771      * These two are the same IVOR as POWERPC_EXCP_VPU and
1772      * POWERPC_EXCP_VPUA. We deal with that when dispatching at
1773      * powerpc_excp().
1774      */
1775     env->excp_vectors[POWERPC_EXCP_SPEU]     = 0x00000000;
1776     env->excp_vectors[POWERPC_EXCP_EFPDI]    = 0x00000000;
1777 
1778     env->excp_vectors[POWERPC_EXCP_EFPRI]    = 0x00000000;
1779     env->ivor_mask = 0x0000FFF7UL;
1780     env->ivpr_mask = ivpr_mask;
1781     /* Hardware reset vector */
1782     env->hreset_vector = 0xFFFFFFFCUL;
1783 #endif
1784 }
1785 
1786 static void init_excp_BookE(CPUPPCState *env)
1787 {
1788 #if !defined(CONFIG_USER_ONLY)
1789     env->excp_vectors[POWERPC_EXCP_CRITICAL] = 0x00000000;
1790     env->excp_vectors[POWERPC_EXCP_MCHECK]   = 0x00000000;
1791     env->excp_vectors[POWERPC_EXCP_DSI]      = 0x00000000;
1792     env->excp_vectors[POWERPC_EXCP_ISI]      = 0x00000000;
1793     env->excp_vectors[POWERPC_EXCP_EXTERNAL] = 0x00000000;
1794     env->excp_vectors[POWERPC_EXCP_ALIGN]    = 0x00000000;
1795     env->excp_vectors[POWERPC_EXCP_PROGRAM]  = 0x00000000;
1796     env->excp_vectors[POWERPC_EXCP_FPU]      = 0x00000000;
1797     env->excp_vectors[POWERPC_EXCP_SYSCALL]  = 0x00000000;
1798     env->excp_vectors[POWERPC_EXCP_APU]      = 0x00000000;
1799     env->excp_vectors[POWERPC_EXCP_DECR]     = 0x00000000;
1800     env->excp_vectors[POWERPC_EXCP_FIT]      = 0x00000000;
1801     env->excp_vectors[POWERPC_EXCP_WDT]      = 0x00000000;
1802     env->excp_vectors[POWERPC_EXCP_DTLB]     = 0x00000000;
1803     env->excp_vectors[POWERPC_EXCP_ITLB]     = 0x00000000;
1804     env->excp_vectors[POWERPC_EXCP_DEBUG]    = 0x00000000;
1805     env->ivor_mask = 0x0000FFF0UL;
1806     env->ivpr_mask = 0xFFFF0000UL;
1807     /* Hardware reset vector */
1808     env->hreset_vector = 0xFFFFFFFCUL;
1809 #endif
1810 }
1811 
1812 static void init_excp_603(CPUPPCState *env)
1813 {
1814 #if !defined(CONFIG_USER_ONLY)
1815     env->excp_vectors[POWERPC_EXCP_RESET]    = 0x00000100;
1816     env->excp_vectors[POWERPC_EXCP_MCHECK]   = 0x00000200;
1817     env->excp_vectors[POWERPC_EXCP_DSI]      = 0x00000300;
1818     env->excp_vectors[POWERPC_EXCP_ISI]      = 0x00000400;
1819     env->excp_vectors[POWERPC_EXCP_EXTERNAL] = 0x00000500;
1820     env->excp_vectors[POWERPC_EXCP_ALIGN]    = 0x00000600;
1821     env->excp_vectors[POWERPC_EXCP_PROGRAM]  = 0x00000700;
1822     env->excp_vectors[POWERPC_EXCP_FPU]      = 0x00000800;
1823     env->excp_vectors[POWERPC_EXCP_DECR]     = 0x00000900;
1824     env->excp_vectors[POWERPC_EXCP_SYSCALL]  = 0x00000C00;
1825     env->excp_vectors[POWERPC_EXCP_TRACE]    = 0x00000D00;
1826     env->excp_vectors[POWERPC_EXCP_IFTLB]    = 0x00001000;
1827     env->excp_vectors[POWERPC_EXCP_DLTLB]    = 0x00001100;
1828     env->excp_vectors[POWERPC_EXCP_DSTLB]    = 0x00001200;
1829     env->excp_vectors[POWERPC_EXCP_IABR]     = 0x00001300;
1830     env->excp_vectors[POWERPC_EXCP_SMI]      = 0x00001400;
1831     /* Hardware reset vector */
1832     env->hreset_vector = 0x00000100UL;
1833 #endif
1834 }
1835 
1836 static void init_excp_604(CPUPPCState *env)
1837 {
1838 #if !defined(CONFIG_USER_ONLY)
1839     env->excp_vectors[POWERPC_EXCP_RESET]    = 0x00000100;
1840     env->excp_vectors[POWERPC_EXCP_MCHECK]   = 0x00000200;
1841     env->excp_vectors[POWERPC_EXCP_DSI]      = 0x00000300;
1842     env->excp_vectors[POWERPC_EXCP_ISI]      = 0x00000400;
1843     env->excp_vectors[POWERPC_EXCP_EXTERNAL] = 0x00000500;
1844     env->excp_vectors[POWERPC_EXCP_ALIGN]    = 0x00000600;
1845     env->excp_vectors[POWERPC_EXCP_PROGRAM]  = 0x00000700;
1846     env->excp_vectors[POWERPC_EXCP_FPU]      = 0x00000800;
1847     env->excp_vectors[POWERPC_EXCP_DECR]     = 0x00000900;
1848     env->excp_vectors[POWERPC_EXCP_SYSCALL]  = 0x00000C00;
1849     env->excp_vectors[POWERPC_EXCP_TRACE]    = 0x00000D00;
1850     env->excp_vectors[POWERPC_EXCP_PERFM]    = 0x00000F00;
1851     env->excp_vectors[POWERPC_EXCP_IABR]     = 0x00001300;
1852     env->excp_vectors[POWERPC_EXCP_SMI]      = 0x00001400;
1853     /* Hardware reset vector */
1854     env->hreset_vector = 0x00000100UL;
1855 #endif
1856 }
1857 
1858 static void init_excp_7x0(CPUPPCState *env)
1859 {
1860 #if !defined(CONFIG_USER_ONLY)
1861     env->excp_vectors[POWERPC_EXCP_RESET]    = 0x00000100;
1862     env->excp_vectors[POWERPC_EXCP_MCHECK]   = 0x00000200;
1863     env->excp_vectors[POWERPC_EXCP_DSI]      = 0x00000300;
1864     env->excp_vectors[POWERPC_EXCP_ISI]      = 0x00000400;
1865     env->excp_vectors[POWERPC_EXCP_EXTERNAL] = 0x00000500;
1866     env->excp_vectors[POWERPC_EXCP_ALIGN]    = 0x00000600;
1867     env->excp_vectors[POWERPC_EXCP_PROGRAM]  = 0x00000700;
1868     env->excp_vectors[POWERPC_EXCP_FPU]      = 0x00000800;
1869     env->excp_vectors[POWERPC_EXCP_DECR]     = 0x00000900;
1870     env->excp_vectors[POWERPC_EXCP_SYSCALL]  = 0x00000C00;
1871     env->excp_vectors[POWERPC_EXCP_TRACE]    = 0x00000D00;
1872     env->excp_vectors[POWERPC_EXCP_PERFM]    = 0x00000F00;
1873     env->excp_vectors[POWERPC_EXCP_IABR]     = 0x00001300;
1874     env->excp_vectors[POWERPC_EXCP_SMI]      = 0x00001400;
1875     env->excp_vectors[POWERPC_EXCP_THERM]    = 0x00001700;
1876     /* Hardware reset vector */
1877     env->hreset_vector = 0x00000100UL;
1878 #endif
1879 }
1880 
1881 static void init_excp_750cl(CPUPPCState *env)
1882 {
1883 #if !defined(CONFIG_USER_ONLY)
1884     env->excp_vectors[POWERPC_EXCP_RESET]    = 0x00000100;
1885     env->excp_vectors[POWERPC_EXCP_MCHECK]   = 0x00000200;
1886     env->excp_vectors[POWERPC_EXCP_DSI]      = 0x00000300;
1887     env->excp_vectors[POWERPC_EXCP_ISI]      = 0x00000400;
1888     env->excp_vectors[POWERPC_EXCP_EXTERNAL] = 0x00000500;
1889     env->excp_vectors[POWERPC_EXCP_ALIGN]    = 0x00000600;
1890     env->excp_vectors[POWERPC_EXCP_PROGRAM]  = 0x00000700;
1891     env->excp_vectors[POWERPC_EXCP_FPU]      = 0x00000800;
1892     env->excp_vectors[POWERPC_EXCP_DECR]     = 0x00000900;
1893     env->excp_vectors[POWERPC_EXCP_SYSCALL]  = 0x00000C00;
1894     env->excp_vectors[POWERPC_EXCP_TRACE]    = 0x00000D00;
1895     env->excp_vectors[POWERPC_EXCP_PERFM]    = 0x00000F00;
1896     env->excp_vectors[POWERPC_EXCP_IABR]     = 0x00001300;
1897     env->excp_vectors[POWERPC_EXCP_SMI]      = 0x00001400;
1898     /* Hardware reset vector */
1899     env->hreset_vector = 0x00000100UL;
1900 #endif
1901 }
1902 
1903 static void init_excp_750cx(CPUPPCState *env)
1904 {
1905 #if !defined(CONFIG_USER_ONLY)
1906     env->excp_vectors[POWERPC_EXCP_RESET]    = 0x00000100;
1907     env->excp_vectors[POWERPC_EXCP_MCHECK]   = 0x00000200;
1908     env->excp_vectors[POWERPC_EXCP_DSI]      = 0x00000300;
1909     env->excp_vectors[POWERPC_EXCP_ISI]      = 0x00000400;
1910     env->excp_vectors[POWERPC_EXCP_EXTERNAL] = 0x00000500;
1911     env->excp_vectors[POWERPC_EXCP_ALIGN]    = 0x00000600;
1912     env->excp_vectors[POWERPC_EXCP_PROGRAM]  = 0x00000700;
1913     env->excp_vectors[POWERPC_EXCP_FPU]      = 0x00000800;
1914     env->excp_vectors[POWERPC_EXCP_DECR]     = 0x00000900;
1915     env->excp_vectors[POWERPC_EXCP_SYSCALL]  = 0x00000C00;
1916     env->excp_vectors[POWERPC_EXCP_TRACE]    = 0x00000D00;
1917     env->excp_vectors[POWERPC_EXCP_PERFM]    = 0x00000F00;
1918     env->excp_vectors[POWERPC_EXCP_IABR]     = 0x00001300;
1919     env->excp_vectors[POWERPC_EXCP_THERM]    = 0x00001700;
1920     /* Hardware reset vector */
1921     env->hreset_vector = 0x00000100UL;
1922 #endif
1923 }
1924 
1925 /* XXX: Check if this is correct */
1926 static void init_excp_7x5(CPUPPCState *env)
1927 {
1928 #if !defined(CONFIG_USER_ONLY)
1929     env->excp_vectors[POWERPC_EXCP_RESET]    = 0x00000100;
1930     env->excp_vectors[POWERPC_EXCP_MCHECK]   = 0x00000200;
1931     env->excp_vectors[POWERPC_EXCP_DSI]      = 0x00000300;
1932     env->excp_vectors[POWERPC_EXCP_ISI]      = 0x00000400;
1933     env->excp_vectors[POWERPC_EXCP_EXTERNAL] = 0x00000500;
1934     env->excp_vectors[POWERPC_EXCP_ALIGN]    = 0x00000600;
1935     env->excp_vectors[POWERPC_EXCP_PROGRAM]  = 0x00000700;
1936     env->excp_vectors[POWERPC_EXCP_FPU]      = 0x00000800;
1937     env->excp_vectors[POWERPC_EXCP_DECR]     = 0x00000900;
1938     env->excp_vectors[POWERPC_EXCP_SYSCALL]  = 0x00000C00;
1939     env->excp_vectors[POWERPC_EXCP_TRACE]    = 0x00000D00;
1940     env->excp_vectors[POWERPC_EXCP_PERFM]    = 0x00000F00;
1941     env->excp_vectors[POWERPC_EXCP_IFTLB]    = 0x00001000;
1942     env->excp_vectors[POWERPC_EXCP_DLTLB]    = 0x00001100;
1943     env->excp_vectors[POWERPC_EXCP_DSTLB]    = 0x00001200;
1944     env->excp_vectors[POWERPC_EXCP_IABR]     = 0x00001300;
1945     env->excp_vectors[POWERPC_EXCP_SMI]      = 0x00001400;
1946     env->excp_vectors[POWERPC_EXCP_THERM]    = 0x00001700;
1947     /* Hardware reset vector */
1948     env->hreset_vector = 0x00000100UL;
1949 #endif
1950 }
1951 
1952 static void init_excp_7400(CPUPPCState *env)
1953 {
1954 #if !defined(CONFIG_USER_ONLY)
1955     env->excp_vectors[POWERPC_EXCP_RESET]    = 0x00000100;
1956     env->excp_vectors[POWERPC_EXCP_MCHECK]   = 0x00000200;
1957     env->excp_vectors[POWERPC_EXCP_DSI]      = 0x00000300;
1958     env->excp_vectors[POWERPC_EXCP_ISI]      = 0x00000400;
1959     env->excp_vectors[POWERPC_EXCP_EXTERNAL] = 0x00000500;
1960     env->excp_vectors[POWERPC_EXCP_ALIGN]    = 0x00000600;
1961     env->excp_vectors[POWERPC_EXCP_PROGRAM]  = 0x00000700;
1962     env->excp_vectors[POWERPC_EXCP_FPU]      = 0x00000800;
1963     env->excp_vectors[POWERPC_EXCP_DECR]     = 0x00000900;
1964     env->excp_vectors[POWERPC_EXCP_SYSCALL]  = 0x00000C00;
1965     env->excp_vectors[POWERPC_EXCP_TRACE]    = 0x00000D00;
1966     env->excp_vectors[POWERPC_EXCP_PERFM]    = 0x00000F00;
1967     env->excp_vectors[POWERPC_EXCP_VPU]      = 0x00000F20;
1968     env->excp_vectors[POWERPC_EXCP_IABR]     = 0x00001300;
1969     env->excp_vectors[POWERPC_EXCP_SMI]      = 0x00001400;
1970     env->excp_vectors[POWERPC_EXCP_VPUA]     = 0x00001600;
1971     env->excp_vectors[POWERPC_EXCP_THERM]    = 0x00001700;
1972     /* Hardware reset vector */
1973     env->hreset_vector = 0x00000100UL;
1974 #endif
1975 }
1976 
1977 static void init_excp_7450(CPUPPCState *env)
1978 {
1979 #if !defined(CONFIG_USER_ONLY)
1980     env->excp_vectors[POWERPC_EXCP_RESET]    = 0x00000100;
1981     env->excp_vectors[POWERPC_EXCP_MCHECK]   = 0x00000200;
1982     env->excp_vectors[POWERPC_EXCP_DSI]      = 0x00000300;
1983     env->excp_vectors[POWERPC_EXCP_ISI]      = 0x00000400;
1984     env->excp_vectors[POWERPC_EXCP_EXTERNAL] = 0x00000500;
1985     env->excp_vectors[POWERPC_EXCP_ALIGN]    = 0x00000600;
1986     env->excp_vectors[POWERPC_EXCP_PROGRAM]  = 0x00000700;
1987     env->excp_vectors[POWERPC_EXCP_FPU]      = 0x00000800;
1988     env->excp_vectors[POWERPC_EXCP_DECR]     = 0x00000900;
1989     env->excp_vectors[POWERPC_EXCP_SYSCALL]  = 0x00000C00;
1990     env->excp_vectors[POWERPC_EXCP_TRACE]    = 0x00000D00;
1991     env->excp_vectors[POWERPC_EXCP_PERFM]    = 0x00000F00;
1992     env->excp_vectors[POWERPC_EXCP_VPU]      = 0x00000F20;
1993     env->excp_vectors[POWERPC_EXCP_IABR]     = 0x00001300;
1994     env->excp_vectors[POWERPC_EXCP_SMI]      = 0x00001400;
1995     env->excp_vectors[POWERPC_EXCP_VPUA]     = 0x00001600;
1996     /* Hardware reset vector */
1997     env->hreset_vector = 0x00000100UL;
1998 #endif
1999 }
2000 
2001 #if defined(TARGET_PPC64)
2002 static void init_excp_970(CPUPPCState *env)
2003 {
2004 #if !defined(CONFIG_USER_ONLY)
2005     env->excp_vectors[POWERPC_EXCP_RESET]    = 0x00000100;
2006     env->excp_vectors[POWERPC_EXCP_MCHECK]   = 0x00000200;
2007     env->excp_vectors[POWERPC_EXCP_DSI]      = 0x00000300;
2008     env->excp_vectors[POWERPC_EXCP_DSEG]     = 0x00000380;
2009     env->excp_vectors[POWERPC_EXCP_ISI]      = 0x00000400;
2010     env->excp_vectors[POWERPC_EXCP_ISEG]     = 0x00000480;
2011     env->excp_vectors[POWERPC_EXCP_EXTERNAL] = 0x00000500;
2012     env->excp_vectors[POWERPC_EXCP_ALIGN]    = 0x00000600;
2013     env->excp_vectors[POWERPC_EXCP_PROGRAM]  = 0x00000700;
2014     env->excp_vectors[POWERPC_EXCP_FPU]      = 0x00000800;
2015     env->excp_vectors[POWERPC_EXCP_DECR]     = 0x00000900;
2016     env->excp_vectors[POWERPC_EXCP_HDECR]    = 0x00000980;
2017     env->excp_vectors[POWERPC_EXCP_SYSCALL]  = 0x00000C00;
2018     env->excp_vectors[POWERPC_EXCP_TRACE]    = 0x00000D00;
2019     env->excp_vectors[POWERPC_EXCP_PERFM]    = 0x00000F00;
2020     env->excp_vectors[POWERPC_EXCP_VPU]      = 0x00000F20;
2021     env->excp_vectors[POWERPC_EXCP_IABR]     = 0x00001300;
2022     env->excp_vectors[POWERPC_EXCP_MAINT]    = 0x00001600;
2023     env->excp_vectors[POWERPC_EXCP_VPUA]     = 0x00001700;
2024     env->excp_vectors[POWERPC_EXCP_THERM]    = 0x00001800;
2025     /* Hardware reset vector */
2026     env->hreset_vector = 0x0000000000000100ULL;
2027 #endif
2028 }
2029 
2030 static void init_excp_POWER7(CPUPPCState *env)
2031 {
2032 #if !defined(CONFIG_USER_ONLY)
2033     env->excp_vectors[POWERPC_EXCP_RESET]    = 0x00000100;
2034     env->excp_vectors[POWERPC_EXCP_MCHECK]   = 0x00000200;
2035     env->excp_vectors[POWERPC_EXCP_DSI]      = 0x00000300;
2036     env->excp_vectors[POWERPC_EXCP_DSEG]     = 0x00000380;
2037     env->excp_vectors[POWERPC_EXCP_ISI]      = 0x00000400;
2038     env->excp_vectors[POWERPC_EXCP_ISEG]     = 0x00000480;
2039     env->excp_vectors[POWERPC_EXCP_EXTERNAL] = 0x00000500;
2040     env->excp_vectors[POWERPC_EXCP_ALIGN]    = 0x00000600;
2041     env->excp_vectors[POWERPC_EXCP_PROGRAM]  = 0x00000700;
2042     env->excp_vectors[POWERPC_EXCP_FPU]      = 0x00000800;
2043     env->excp_vectors[POWERPC_EXCP_DECR]     = 0x00000900;
2044     env->excp_vectors[POWERPC_EXCP_HDECR]    = 0x00000980;
2045     env->excp_vectors[POWERPC_EXCP_SYSCALL]  = 0x00000C00;
2046     env->excp_vectors[POWERPC_EXCP_TRACE]    = 0x00000D00;
2047     env->excp_vectors[POWERPC_EXCP_HDSI]     = 0x00000E00;
2048     env->excp_vectors[POWERPC_EXCP_HISI]     = 0x00000E20;
2049     env->excp_vectors[POWERPC_EXCP_HV_EMU]   = 0x00000E40;
2050     env->excp_vectors[POWERPC_EXCP_HV_MAINT] = 0x00000E60;
2051     env->excp_vectors[POWERPC_EXCP_PERFM]    = 0x00000F00;
2052     env->excp_vectors[POWERPC_EXCP_VPU]      = 0x00000F20;
2053     env->excp_vectors[POWERPC_EXCP_VSXU]     = 0x00000F40;
2054     /* Hardware reset vector */
2055     env->hreset_vector = 0x0000000000000100ULL;
2056 #endif
2057 }
2058 
2059 static void init_excp_POWER8(CPUPPCState *env)
2060 {
2061     init_excp_POWER7(env);
2062 
2063 #if !defined(CONFIG_USER_ONLY)
2064     env->excp_vectors[POWERPC_EXCP_SDOOR]    = 0x00000A00;
2065     env->excp_vectors[POWERPC_EXCP_FU]       = 0x00000F60;
2066     env->excp_vectors[POWERPC_EXCP_HV_FU]    = 0x00000F80;
2067     env->excp_vectors[POWERPC_EXCP_SDOOR_HV] = 0x00000E80;
2068 
2069     /* Userland exceptions without vector value in PowerISA v3.1 */
2070     env->excp_vectors[POWERPC_EXCP_PERFM_EBB] = 0x0;
2071     env->excp_vectors[POWERPC_EXCP_EXTERNAL_EBB] = 0x0;
2072 #endif
2073 }
2074 
2075 static void init_excp_POWER9(CPUPPCState *env)
2076 {
2077     init_excp_POWER8(env);
2078 
2079 #if !defined(CONFIG_USER_ONLY)
2080     env->excp_vectors[POWERPC_EXCP_HVIRT]    = 0x00000EA0;
2081     env->excp_vectors[POWERPC_EXCP_SYSCALL_VECTORED] = 0x00017000;
2082 #endif
2083 }
2084 
2085 static void init_excp_POWER10(CPUPPCState *env)
2086 {
2087     init_excp_POWER9(env);
2088 }
2089 
2090 #endif
2091 
2092 static int check_pow_hid0(CPUPPCState *env)
2093 {
2094     if (env->spr[SPR_HID0] & 0x00E00000) {
2095         return 1;
2096     }
2097 
2098     return 0;
2099 }
2100 
2101 static int check_pow_hid0_74xx(CPUPPCState *env)
2102 {
2103     if (env->spr[SPR_HID0] & 0x00600000) {
2104         return 1;
2105     }
2106 
2107     return 0;
2108 }
2109 
2110 static void init_proc_405(CPUPPCState *env)
2111 {
2112     register_40x_sprs(env);
2113     register_405_sprs(env);
2114     register_usprgh_sprs(env);
2115 
2116     /* Memory management */
2117 #if !defined(CONFIG_USER_ONLY)
2118     env->nb_tlb = 64;
2119     env->nb_ways = 1;
2120     env->id_tlbs = 0;
2121     env->tlb_type = TLB_EMB;
2122 #endif
2123     init_excp_4xx_softmmu(env);
2124     env->dcache_line_size = 32;
2125     env->icache_line_size = 32;
2126     /* Allocate hardware IRQ controller */
2127     ppc40x_irq_init(env_archcpu(env));
2128 
2129     SET_FIT_PERIOD(8, 12, 16, 20);
2130     SET_WDT_PERIOD(16, 20, 24, 28);
2131 }
2132 
2133 POWERPC_FAMILY(405)(ObjectClass *oc, void *data)
2134 {
2135     DeviceClass *dc = DEVICE_CLASS(oc);
2136     PowerPCCPUClass *pcc = POWERPC_CPU_CLASS(oc);
2137 
2138     dc->desc = "PowerPC 405";
2139     pcc->init_proc = init_proc_405;
2140     pcc->check_pow = check_pow_nocheck;
2141     pcc->insns_flags = PPC_INSNS_BASE | PPC_STRING | PPC_MFTB |
2142                        PPC_DCR | PPC_WRTEE |
2143                        PPC_CACHE | PPC_CACHE_ICBI | PPC_40x_ICBT |
2144                        PPC_CACHE_DCBZ | PPC_CACHE_DCBA |
2145                        PPC_MEM_SYNC | PPC_MEM_EIEIO |
2146                        PPC_40x_TLB | PPC_MEM_TLBIA | PPC_MEM_TLBSYNC |
2147                        PPC_4xx_COMMON | PPC_405_MAC | PPC_40x_EXCP;
2148     pcc->msr_mask = (1ull << MSR_WE) |
2149                     (1ull << MSR_CE) |
2150                     (1ull << MSR_EE) |
2151                     (1ull << MSR_PR) |
2152                     (1ull << MSR_FP) |
2153                     (1ull << MSR_ME) |
2154                     (1ull << MSR_DWE) |
2155                     (1ull << MSR_DE) |
2156                     (1ull << MSR_IR) |
2157                     (1ull << MSR_DR);
2158     pcc->mmu_model = POWERPC_MMU_SOFT_4xx;
2159     pcc->excp_model = POWERPC_EXCP_40x;
2160     pcc->bus_model = PPC_FLAGS_INPUT_405;
2161     pcc->bfd_mach = bfd_mach_ppc_403;
2162     pcc->flags = POWERPC_FLAG_CE | POWERPC_FLAG_DWE |
2163                  POWERPC_FLAG_DE | POWERPC_FLAG_BUS_CLK;
2164 }
2165 
2166 static void init_proc_440EP(CPUPPCState *env)
2167 {
2168     register_BookE_sprs(env, 0x000000000000FFFFULL);
2169     register_440_sprs(env);
2170     register_usprgh_sprs(env);
2171 
2172     spr_register(env, SPR_BOOKE_MCSR, "MCSR",
2173                  SPR_NOACCESS, SPR_NOACCESS,
2174                  &spr_read_generic, &spr_write_generic,
2175                  0x00000000);
2176     spr_register(env, SPR_BOOKE_MCSRR0, "MCSRR0",
2177                  SPR_NOACCESS, SPR_NOACCESS,
2178                  &spr_read_generic, &spr_write_generic,
2179                  0x00000000);
2180     spr_register(env, SPR_BOOKE_MCSRR1, "MCSRR1",
2181                  SPR_NOACCESS, SPR_NOACCESS,
2182                  &spr_read_generic, &spr_write_generic,
2183                  0x00000000);
2184 
2185     spr_register(env, SPR_440_CCR1, "CCR1",
2186                  SPR_NOACCESS, SPR_NOACCESS,
2187                  &spr_read_generic, &spr_write_generic,
2188                  0x00000000);
2189     /* Memory management */
2190 #if !defined(CONFIG_USER_ONLY)
2191     env->nb_tlb = 64;
2192     env->nb_ways = 1;
2193     env->id_tlbs = 0;
2194     env->tlb_type = TLB_EMB;
2195 #endif
2196     init_excp_BookE(env);
2197     env->dcache_line_size = 32;
2198     env->icache_line_size = 32;
2199     ppc40x_irq_init(env_archcpu(env));
2200 
2201     SET_FIT_PERIOD(12, 16, 20, 24);
2202     SET_WDT_PERIOD(20, 24, 28, 32);
2203 }
2204 
2205 POWERPC_FAMILY(440EP)(ObjectClass *oc, void *data)
2206 {
2207     DeviceClass *dc = DEVICE_CLASS(oc);
2208     PowerPCCPUClass *pcc = POWERPC_CPU_CLASS(oc);
2209 
2210     dc->desc = "PowerPC 440 EP";
2211     pcc->init_proc = init_proc_440EP;
2212     pcc->check_pow = check_pow_nocheck;
2213     pcc->insns_flags = PPC_INSNS_BASE | PPC_STRING |
2214                        PPC_FLOAT | PPC_FLOAT_FRES | PPC_FLOAT_FSEL |
2215                        PPC_FLOAT_FSQRT | PPC_FLOAT_FRSQRTE |
2216                        PPC_FLOAT_STFIWX |
2217                        PPC_DCR | PPC_WRTEE | PPC_RFMCI |
2218                        PPC_CACHE | PPC_CACHE_ICBI |
2219                        PPC_CACHE_DCBZ | PPC_CACHE_DCBA |
2220                        PPC_MEM_TLBSYNC | PPC_MFTB |
2221                        PPC_BOOKE | PPC_4xx_COMMON | PPC_405_MAC |
2222                        PPC_440_SPEC;
2223     pcc->msr_mask = (1ull << MSR_POW) |
2224                     (1ull << MSR_CE) |
2225                     (1ull << MSR_EE) |
2226                     (1ull << MSR_PR) |
2227                     (1ull << MSR_FP) |
2228                     (1ull << MSR_ME) |
2229                     (1ull << MSR_FE0) |
2230                     (1ull << MSR_DWE) |
2231                     (1ull << MSR_DE) |
2232                     (1ull << MSR_FE1) |
2233                     (1ull << MSR_IR) |
2234                     (1ull << MSR_DR);
2235     pcc->mmu_model = POWERPC_MMU_BOOKE;
2236     pcc->excp_model = POWERPC_EXCP_BOOKE;
2237     pcc->bus_model = PPC_FLAGS_INPUT_BookE;
2238     pcc->bfd_mach = bfd_mach_ppc_403;
2239     pcc->flags = POWERPC_FLAG_CE | POWERPC_FLAG_DWE |
2240                  POWERPC_FLAG_DE | POWERPC_FLAG_BUS_CLK;
2241 }
2242 
2243 POWERPC_FAMILY(460EX)(ObjectClass *oc, void *data)
2244 {
2245     DeviceClass *dc = DEVICE_CLASS(oc);
2246     PowerPCCPUClass *pcc = POWERPC_CPU_CLASS(oc);
2247 
2248     dc->desc = "PowerPC 460 EX";
2249     pcc->init_proc = init_proc_440EP;
2250     pcc->check_pow = check_pow_nocheck;
2251     pcc->insns_flags = PPC_INSNS_BASE | PPC_STRING |
2252                        PPC_FLOAT | PPC_FLOAT_FRES | PPC_FLOAT_FSEL |
2253                        PPC_FLOAT_FSQRT | PPC_FLOAT_FRSQRTE |
2254                        PPC_FLOAT_STFIWX |
2255                        PPC_DCR | PPC_DCRX | PPC_WRTEE | PPC_RFMCI |
2256                        PPC_CACHE | PPC_CACHE_ICBI |
2257                        PPC_CACHE_DCBZ | PPC_CACHE_DCBA |
2258                        PPC_MEM_TLBSYNC | PPC_MFTB |
2259                        PPC_BOOKE | PPC_4xx_COMMON | PPC_405_MAC |
2260                        PPC_440_SPEC;
2261     pcc->msr_mask = (1ull << MSR_POW) |
2262                     (1ull << MSR_CE) |
2263                     (1ull << MSR_EE) |
2264                     (1ull << MSR_PR) |
2265                     (1ull << MSR_FP) |
2266                     (1ull << MSR_ME) |
2267                     (1ull << MSR_FE0) |
2268                     (1ull << MSR_DWE) |
2269                     (1ull << MSR_DE) |
2270                     (1ull << MSR_FE1) |
2271                     (1ull << MSR_IR) |
2272                     (1ull << MSR_DR);
2273     pcc->mmu_model = POWERPC_MMU_BOOKE;
2274     pcc->excp_model = POWERPC_EXCP_BOOKE;
2275     pcc->bus_model = PPC_FLAGS_INPUT_BookE;
2276     pcc->bfd_mach = bfd_mach_ppc_403;
2277     pcc->flags = POWERPC_FLAG_CE | POWERPC_FLAG_DWE |
2278                  POWERPC_FLAG_DE | POWERPC_FLAG_BUS_CLK;
2279 }
2280 
2281 static void init_proc_440GP(CPUPPCState *env)
2282 {
2283     register_BookE_sprs(env, 0x000000000000FFFFULL);
2284     register_440_sprs(env);
2285     register_usprgh_sprs(env);
2286 
2287     /* Memory management */
2288 #if !defined(CONFIG_USER_ONLY)
2289     env->nb_tlb = 64;
2290     env->nb_ways = 1;
2291     env->id_tlbs = 0;
2292     env->tlb_type = TLB_EMB;
2293 #endif
2294     init_excp_BookE(env);
2295     env->dcache_line_size = 32;
2296     env->icache_line_size = 32;
2297     /* XXX: TODO: allocate internal IRQ controller */
2298 
2299     SET_FIT_PERIOD(12, 16, 20, 24);
2300     SET_WDT_PERIOD(20, 24, 28, 32);
2301 }
2302 
2303 POWERPC_FAMILY(440GP)(ObjectClass *oc, void *data)
2304 {
2305     DeviceClass *dc = DEVICE_CLASS(oc);
2306     PowerPCCPUClass *pcc = POWERPC_CPU_CLASS(oc);
2307 
2308     dc->desc = "PowerPC 440 GP";
2309     pcc->init_proc = init_proc_440GP;
2310     pcc->check_pow = check_pow_nocheck;
2311     pcc->insns_flags = PPC_INSNS_BASE | PPC_STRING |
2312                        PPC_DCR | PPC_DCRX | PPC_WRTEE | PPC_MFAPIDI |
2313                        PPC_CACHE | PPC_CACHE_ICBI |
2314                        PPC_CACHE_DCBZ | PPC_CACHE_DCBA |
2315                        PPC_MEM_TLBSYNC | PPC_TLBIVA | PPC_MFTB |
2316                        PPC_BOOKE | PPC_4xx_COMMON | PPC_405_MAC |
2317                        PPC_440_SPEC;
2318     pcc->msr_mask = (1ull << MSR_POW) |
2319                     (1ull << MSR_CE) |
2320                     (1ull << MSR_EE) |
2321                     (1ull << MSR_PR) |
2322                     (1ull << MSR_FP) |
2323                     (1ull << MSR_ME) |
2324                     (1ull << MSR_FE0) |
2325                     (1ull << MSR_DWE) |
2326                     (1ull << MSR_DE) |
2327                     (1ull << MSR_FE1) |
2328                     (1ull << MSR_IR) |
2329                     (1ull << MSR_DR);
2330     pcc->mmu_model = POWERPC_MMU_BOOKE;
2331     pcc->excp_model = POWERPC_EXCP_BOOKE;
2332     pcc->bus_model = PPC_FLAGS_INPUT_BookE;
2333     pcc->bfd_mach = bfd_mach_ppc_403;
2334     pcc->flags = POWERPC_FLAG_CE | POWERPC_FLAG_DWE |
2335                  POWERPC_FLAG_DE | POWERPC_FLAG_BUS_CLK;
2336 }
2337 
2338 static void init_proc_440x5(CPUPPCState *env)
2339 {
2340     register_BookE_sprs(env, 0x000000000000FFFFULL);
2341     register_440_sprs(env);
2342     register_usprgh_sprs(env);
2343 
2344     spr_register(env, SPR_BOOKE_MCSR, "MCSR",
2345                  SPR_NOACCESS, SPR_NOACCESS,
2346                  &spr_read_generic, &spr_write_generic,
2347                  0x00000000);
2348     spr_register(env, SPR_BOOKE_MCSRR0, "MCSRR0",
2349                  SPR_NOACCESS, SPR_NOACCESS,
2350                  &spr_read_generic, &spr_write_generic,
2351                  0x00000000);
2352     spr_register(env, SPR_BOOKE_MCSRR1, "MCSRR1",
2353                  SPR_NOACCESS, SPR_NOACCESS,
2354                  &spr_read_generic, &spr_write_generic,
2355                  0x00000000);
2356 
2357     spr_register(env, SPR_440_CCR1, "CCR1",
2358                  SPR_NOACCESS, SPR_NOACCESS,
2359                  &spr_read_generic, &spr_write_generic,
2360                  0x00000000);
2361     /* Memory management */
2362 #if !defined(CONFIG_USER_ONLY)
2363     env->nb_tlb = 64;
2364     env->nb_ways = 1;
2365     env->id_tlbs = 0;
2366     env->tlb_type = TLB_EMB;
2367 #endif
2368     init_excp_BookE(env);
2369     env->dcache_line_size = 32;
2370     env->icache_line_size = 32;
2371     ppc40x_irq_init(env_archcpu(env));
2372 
2373     SET_FIT_PERIOD(12, 16, 20, 24);
2374     SET_WDT_PERIOD(20, 24, 28, 32);
2375 }
2376 
2377 POWERPC_FAMILY(440x5)(ObjectClass *oc, void *data)
2378 {
2379     DeviceClass *dc = DEVICE_CLASS(oc);
2380     PowerPCCPUClass *pcc = POWERPC_CPU_CLASS(oc);
2381 
2382     dc->desc = "PowerPC 440x5";
2383     pcc->init_proc = init_proc_440x5;
2384     pcc->check_pow = check_pow_nocheck;
2385     pcc->insns_flags = PPC_INSNS_BASE | PPC_STRING |
2386                        PPC_DCR | PPC_WRTEE | PPC_RFMCI |
2387                        PPC_CACHE | PPC_CACHE_ICBI |
2388                        PPC_CACHE_DCBZ | PPC_CACHE_DCBA |
2389                        PPC_MEM_TLBSYNC | PPC_MFTB |
2390                        PPC_BOOKE | PPC_4xx_COMMON | PPC_405_MAC |
2391                        PPC_440_SPEC;
2392     pcc->msr_mask = (1ull << MSR_POW) |
2393                     (1ull << MSR_CE) |
2394                     (1ull << MSR_EE) |
2395                     (1ull << MSR_PR) |
2396                     (1ull << MSR_FP) |
2397                     (1ull << MSR_ME) |
2398                     (1ull << MSR_FE0) |
2399                     (1ull << MSR_DWE) |
2400                     (1ull << MSR_DE) |
2401                     (1ull << MSR_FE1) |
2402                     (1ull << MSR_IR) |
2403                     (1ull << MSR_DR);
2404     pcc->mmu_model = POWERPC_MMU_BOOKE;
2405     pcc->excp_model = POWERPC_EXCP_BOOKE;
2406     pcc->bus_model = PPC_FLAGS_INPUT_BookE;
2407     pcc->bfd_mach = bfd_mach_ppc_403;
2408     pcc->flags = POWERPC_FLAG_CE | POWERPC_FLAG_DWE |
2409                  POWERPC_FLAG_DE | POWERPC_FLAG_BUS_CLK;
2410 }
2411 
2412 POWERPC_FAMILY(440x5wDFPU)(ObjectClass *oc, void *data)
2413 {
2414     DeviceClass *dc = DEVICE_CLASS(oc);
2415     PowerPCCPUClass *pcc = POWERPC_CPU_CLASS(oc);
2416 
2417     dc->desc = "PowerPC 440x5 with double precision FPU";
2418     pcc->init_proc = init_proc_440x5;
2419     pcc->check_pow = check_pow_nocheck;
2420     pcc->insns_flags = PPC_INSNS_BASE | PPC_STRING |
2421                        PPC_FLOAT | PPC_FLOAT_FSQRT |
2422                        PPC_FLOAT_STFIWX |
2423                        PPC_DCR | PPC_WRTEE | PPC_RFMCI |
2424                        PPC_CACHE | PPC_CACHE_ICBI |
2425                        PPC_CACHE_DCBZ | PPC_CACHE_DCBA |
2426                        PPC_MEM_TLBSYNC | PPC_MFTB |
2427                        PPC_BOOKE | PPC_4xx_COMMON | PPC_405_MAC |
2428                        PPC_440_SPEC;
2429     pcc->insns_flags2 = PPC2_FP_CVT_S64;
2430     pcc->msr_mask = (1ull << MSR_POW) |
2431                     (1ull << MSR_CE) |
2432                     (1ull << MSR_EE) |
2433                     (1ull << MSR_PR) |
2434                     (1ull << MSR_FP) |
2435                     (1ull << MSR_ME) |
2436                     (1ull << MSR_FE0) |
2437                     (1ull << MSR_DWE) |
2438                     (1ull << MSR_DE) |
2439                     (1ull << MSR_FE1) |
2440                     (1ull << MSR_IR) |
2441                     (1ull << MSR_DR);
2442     pcc->mmu_model = POWERPC_MMU_BOOKE;
2443     pcc->excp_model = POWERPC_EXCP_BOOKE;
2444     pcc->bus_model = PPC_FLAGS_INPUT_BookE;
2445     pcc->bfd_mach = bfd_mach_ppc_403;
2446     pcc->flags = POWERPC_FLAG_CE | POWERPC_FLAG_DWE |
2447                  POWERPC_FLAG_DE | POWERPC_FLAG_BUS_CLK;
2448 }
2449 
2450 static void init_proc_MPC5xx(CPUPPCState *env)
2451 {
2452     register_5xx_8xx_sprs(env);
2453     register_5xx_sprs(env);
2454     init_excp_MPC5xx(env);
2455     env->dcache_line_size = 32;
2456     env->icache_line_size = 32;
2457     /* XXX: TODO: allocate internal IRQ controller */
2458 }
2459 
2460 POWERPC_FAMILY(MPC5xx)(ObjectClass *oc, void *data)
2461 {
2462     DeviceClass *dc = DEVICE_CLASS(oc);
2463     PowerPCCPUClass *pcc = POWERPC_CPU_CLASS(oc);
2464 
2465     dc->desc = "Freescale 5xx cores (aka RCPU)";
2466     pcc->init_proc = init_proc_MPC5xx;
2467     pcc->check_pow = check_pow_none;
2468     pcc->insns_flags = PPC_INSNS_BASE | PPC_STRING |
2469                        PPC_MEM_EIEIO | PPC_MEM_SYNC |
2470                        PPC_CACHE_ICBI | PPC_FLOAT | PPC_FLOAT_STFIWX |
2471                        PPC_MFTB;
2472     pcc->msr_mask = (1ull << MSR_ILE) |
2473                     (1ull << MSR_EE) |
2474                     (1ull << MSR_PR) |
2475                     (1ull << MSR_FP) |
2476                     (1ull << MSR_ME) |
2477                     (1ull << MSR_FE0) |
2478                     (1ull << MSR_SE) |
2479                     (1ull << MSR_DE) |
2480                     (1ull << MSR_FE1) |
2481                     (1ull << MSR_EP) |
2482                     (1ull << MSR_RI) |
2483                     (1ull << MSR_LE);
2484     pcc->mmu_model = POWERPC_MMU_REAL;
2485     pcc->excp_model = POWERPC_EXCP_6xx;
2486     pcc->bus_model = PPC_FLAGS_INPUT_RCPU;
2487     pcc->bfd_mach = bfd_mach_ppc_505;
2488     pcc->flags = POWERPC_FLAG_SE | POWERPC_FLAG_BE |
2489                  POWERPC_FLAG_BUS_CLK;
2490 }
2491 
2492 static void init_proc_MPC8xx(CPUPPCState *env)
2493 {
2494     register_5xx_8xx_sprs(env);
2495     register_8xx_sprs(env);
2496     init_excp_MPC8xx(env);
2497     env->dcache_line_size = 32;
2498     env->icache_line_size = 32;
2499     /* XXX: TODO: allocate internal IRQ controller */
2500 }
2501 
2502 POWERPC_FAMILY(MPC8xx)(ObjectClass *oc, void *data)
2503 {
2504     DeviceClass *dc = DEVICE_CLASS(oc);
2505     PowerPCCPUClass *pcc = POWERPC_CPU_CLASS(oc);
2506 
2507     dc->desc = "Freescale 8xx cores (aka PowerQUICC)";
2508     pcc->init_proc = init_proc_MPC8xx;
2509     pcc->check_pow = check_pow_none;
2510     pcc->insns_flags = PPC_INSNS_BASE | PPC_STRING  |
2511                        PPC_MEM_EIEIO | PPC_MEM_SYNC |
2512                        PPC_CACHE_ICBI | PPC_MFTB;
2513     pcc->msr_mask = (1ull << MSR_ILE) |
2514                     (1ull << MSR_EE) |
2515                     (1ull << MSR_PR) |
2516                     (1ull << MSR_FP) |
2517                     (1ull << MSR_ME) |
2518                     (1ull << MSR_SE) |
2519                     (1ull << MSR_DE) |
2520                     (1ull << MSR_EP) |
2521                     (1ull << MSR_IR) |
2522                     (1ull << MSR_DR) |
2523                     (1ull << MSR_RI) |
2524                     (1ull << MSR_LE);
2525     pcc->mmu_model = POWERPC_MMU_MPC8xx;
2526     pcc->excp_model = POWERPC_EXCP_6xx;
2527     pcc->bus_model = PPC_FLAGS_INPUT_RCPU;
2528     pcc->bfd_mach = bfd_mach_ppc_860;
2529     pcc->flags = POWERPC_FLAG_SE | POWERPC_FLAG_BE |
2530                  POWERPC_FLAG_BUS_CLK;
2531 }
2532 
2533 /* Freescale 82xx cores (aka PowerQUICC-II)                                  */
2534 
2535 static void init_proc_G2(CPUPPCState *env)
2536 {
2537     register_non_embedded_sprs(env);
2538     register_sdr1_sprs(env);
2539     register_G2_sprs(env);
2540 
2541     /* Memory management */
2542     register_low_BATs(env);
2543     register_high_BATs(env);
2544     register_6xx_7xx_soft_tlb(env, 64, 2);
2545     init_excp_G2(env);
2546     env->dcache_line_size = 32;
2547     env->icache_line_size = 32;
2548     /* Allocate hardware IRQ controller */
2549     ppc6xx_irq_init(env_archcpu(env));
2550 }
2551 
2552 POWERPC_FAMILY(G2)(ObjectClass *oc, void *data)
2553 {
2554     DeviceClass *dc = DEVICE_CLASS(oc);
2555     PowerPCCPUClass *pcc = POWERPC_CPU_CLASS(oc);
2556 
2557     dc->desc = "PowerPC G2";
2558     pcc->init_proc = init_proc_G2;
2559     pcc->check_pow = check_pow_hid0;
2560     pcc->insns_flags = PPC_INSNS_BASE | PPC_STRING | PPC_MFTB |
2561                        PPC_FLOAT | PPC_FLOAT_FSEL | PPC_FLOAT_FRES |
2562                        PPC_FLOAT_STFIWX |
2563                        PPC_CACHE | PPC_CACHE_ICBI | PPC_CACHE_DCBZ |
2564                        PPC_MEM_SYNC | PPC_MEM_EIEIO |
2565                        PPC_MEM_TLBIE | PPC_MEM_TLBSYNC | PPC_6xx_TLB |
2566                        PPC_SEGMENT | PPC_EXTERN;
2567     pcc->msr_mask = (1ull << MSR_POW) |
2568                     (1ull << MSR_TGPR) |
2569                     (1ull << MSR_EE) |
2570                     (1ull << MSR_PR) |
2571                     (1ull << MSR_FP) |
2572                     (1ull << MSR_ME) |
2573                     (1ull << MSR_FE0) |
2574                     (1ull << MSR_SE) |
2575                     (1ull << MSR_DE) |
2576                     (1ull << MSR_FE1) |
2577                     (1ull << MSR_AL) |
2578                     (1ull << MSR_EP) |
2579                     (1ull << MSR_IR) |
2580                     (1ull << MSR_DR) |
2581                     (1ull << MSR_RI);
2582     pcc->mmu_model = POWERPC_MMU_SOFT_6xx;
2583     pcc->excp_model = POWERPC_EXCP_6xx;
2584     pcc->bus_model = PPC_FLAGS_INPUT_6xx;
2585     pcc->bfd_mach = bfd_mach_ppc_ec603e;
2586     pcc->flags = POWERPC_FLAG_TGPR | POWERPC_FLAG_SE |
2587                  POWERPC_FLAG_BE | POWERPC_FLAG_BUS_CLK;
2588 }
2589 
2590 POWERPC_FAMILY(G2LE)(ObjectClass *oc, void *data)
2591 {
2592     DeviceClass *dc = DEVICE_CLASS(oc);
2593     PowerPCCPUClass *pcc = POWERPC_CPU_CLASS(oc);
2594 
2595     dc->desc = "PowerPC G2LE";
2596     pcc->init_proc = init_proc_G2;
2597     pcc->check_pow = check_pow_hid0;
2598     pcc->insns_flags = PPC_INSNS_BASE | PPC_STRING | PPC_MFTB |
2599                        PPC_FLOAT | PPC_FLOAT_FSEL | PPC_FLOAT_FRES |
2600                        PPC_FLOAT_STFIWX |
2601                        PPC_CACHE | PPC_CACHE_ICBI | PPC_CACHE_DCBZ |
2602                        PPC_MEM_SYNC | PPC_MEM_EIEIO |
2603                        PPC_MEM_TLBIE | PPC_MEM_TLBSYNC | PPC_6xx_TLB |
2604                        PPC_SEGMENT | PPC_EXTERN;
2605     pcc->msr_mask = (1ull << MSR_POW) |
2606                     (1ull << MSR_TGPR) |
2607                     (1ull << MSR_ILE) |
2608                     (1ull << MSR_EE) |
2609                     (1ull << MSR_PR) |
2610                     (1ull << MSR_FP) |
2611                     (1ull << MSR_ME) |
2612                     (1ull << MSR_FE0) |
2613                     (1ull << MSR_SE) |
2614                     (1ull << MSR_DE) |
2615                     (1ull << MSR_FE1) |
2616                     (1ull << MSR_AL) |
2617                     (1ull << MSR_EP) |
2618                     (1ull << MSR_IR) |
2619                     (1ull << MSR_DR) |
2620                     (1ull << MSR_RI) |
2621                     (1ull << MSR_LE);
2622     pcc->mmu_model = POWERPC_MMU_SOFT_6xx;
2623     pcc->excp_model = POWERPC_EXCP_6xx;
2624     pcc->bus_model = PPC_FLAGS_INPUT_6xx;
2625     pcc->bfd_mach = bfd_mach_ppc_ec603e;
2626     pcc->flags = POWERPC_FLAG_TGPR | POWERPC_FLAG_SE |
2627                  POWERPC_FLAG_BE | POWERPC_FLAG_BUS_CLK;
2628 }
2629 
2630 static void init_proc_e200(CPUPPCState *env)
2631 {
2632     register_BookE_sprs(env, 0x000000070000FFFFULL);
2633 
2634     spr_register(env, SPR_BOOKE_SPEFSCR, "SPEFSCR",
2635                  &spr_read_spefscr, &spr_write_spefscr,
2636                  &spr_read_spefscr, &spr_write_spefscr,
2637                  0x00000000);
2638     /* Memory management */
2639     register_BookE206_sprs(env, 0x0000005D, NULL, 0);
2640     register_usprgh_sprs(env);
2641 
2642     spr_register(env, SPR_HID0, "HID0",
2643                  SPR_NOACCESS, SPR_NOACCESS,
2644                  &spr_read_generic, &spr_write_generic,
2645                  0x00000000);
2646 
2647     spr_register(env, SPR_HID1, "HID1",
2648                  SPR_NOACCESS, SPR_NOACCESS,
2649                  &spr_read_generic, &spr_write_generic,
2650                  0x00000000);
2651 
2652     spr_register(env, SPR_Exxx_ALTCTXCR, "ALTCTXCR",
2653                  SPR_NOACCESS, SPR_NOACCESS,
2654                  &spr_read_generic, &spr_write_generic,
2655                  0x00000000);
2656 
2657     spr_register(env, SPR_Exxx_BUCSR, "BUCSR",
2658                  SPR_NOACCESS, SPR_NOACCESS,
2659                  &spr_read_generic, &spr_write_generic,
2660                  0x00000000);
2661 
2662     spr_register(env, SPR_Exxx_CTXCR, "CTXCR",
2663                  SPR_NOACCESS, SPR_NOACCESS,
2664                  &spr_read_generic, &spr_write_generic,
2665                  0x00000000);
2666 
2667     spr_register(env, SPR_Exxx_DBCNT, "DBCNT",
2668                  SPR_NOACCESS, SPR_NOACCESS,
2669                  &spr_read_generic, &spr_write_generic,
2670                  0x00000000);
2671 
2672     spr_register(env, SPR_Exxx_DBCR3, "DBCR3",
2673                  SPR_NOACCESS, SPR_NOACCESS,
2674                  &spr_read_generic, &spr_write_generic,
2675                  0x00000000);
2676 
2677     spr_register(env, SPR_Exxx_L1CFG0, "L1CFG0",
2678                  &spr_read_generic, SPR_NOACCESS,
2679                  &spr_read_generic, SPR_NOACCESS,
2680                  0x00000000);
2681 
2682     spr_register(env, SPR_Exxx_L1CSR0, "L1CSR0",
2683                  SPR_NOACCESS, SPR_NOACCESS,
2684                  &spr_read_generic, &spr_write_generic,
2685                  0x00000000);
2686 
2687     spr_register(env, SPR_Exxx_L1FINV0, "L1FINV0",
2688                  SPR_NOACCESS, SPR_NOACCESS,
2689                  &spr_read_generic, &spr_write_generic,
2690                  0x00000000);
2691 
2692     spr_register(env, SPR_BOOKE_TLB0CFG, "TLB0CFG",
2693                  SPR_NOACCESS, SPR_NOACCESS,
2694                  &spr_read_generic, &spr_write_generic,
2695                  0x00000000);
2696 
2697     spr_register(env, SPR_BOOKE_TLB1CFG, "TLB1CFG",
2698                  SPR_NOACCESS, SPR_NOACCESS,
2699                  &spr_read_generic, &spr_write_generic,
2700                  0x00000000);
2701 
2702     spr_register(env, SPR_BOOKE_IAC3, "IAC3",
2703                  SPR_NOACCESS, SPR_NOACCESS,
2704                  &spr_read_generic, &spr_write_generic,
2705                  0x00000000);
2706 
2707     spr_register(env, SPR_BOOKE_IAC4, "IAC4",
2708                  SPR_NOACCESS, SPR_NOACCESS,
2709                  &spr_read_generic, &spr_write_generic,
2710                  0x00000000);
2711 
2712     spr_register(env, SPR_MMUCSR0, "MMUCSR0",
2713                  SPR_NOACCESS, SPR_NOACCESS,
2714                  &spr_read_generic, &spr_write_generic,
2715                  0x00000000); /* TOFIX */
2716     spr_register(env, SPR_BOOKE_DSRR0, "DSRR0",
2717                  SPR_NOACCESS, SPR_NOACCESS,
2718                  &spr_read_generic, &spr_write_generic,
2719                  0x00000000);
2720     spr_register(env, SPR_BOOKE_DSRR1, "DSRR1",
2721                  SPR_NOACCESS, SPR_NOACCESS,
2722                  &spr_read_generic, &spr_write_generic,
2723                  0x00000000);
2724 #if !defined(CONFIG_USER_ONLY)
2725     env->nb_tlb = 64;
2726     env->nb_ways = 1;
2727     env->id_tlbs = 0;
2728     env->tlb_type = TLB_EMB;
2729 #endif
2730     init_excp_e200(env, 0xFFFF0000UL);
2731     env->dcache_line_size = 32;
2732     env->icache_line_size = 32;
2733     /* XXX: TODO: allocate internal IRQ controller */
2734 }
2735 
2736 POWERPC_FAMILY(e200)(ObjectClass *oc, void *data)
2737 {
2738     DeviceClass *dc = DEVICE_CLASS(oc);
2739     PowerPCCPUClass *pcc = POWERPC_CPU_CLASS(oc);
2740 
2741     dc->desc = "e200 core";
2742     pcc->init_proc = init_proc_e200;
2743     pcc->check_pow = check_pow_hid0;
2744     /*
2745      * XXX: unimplemented instructions:
2746      * dcblc
2747      * dcbtlst
2748      * dcbtstls
2749      * icblc
2750      * icbtls
2751      * tlbivax
2752      * all SPE multiply-accumulate instructions
2753      */
2754     pcc->insns_flags = PPC_INSNS_BASE | PPC_ISEL |
2755                        PPC_SPE | PPC_SPE_SINGLE |
2756                        PPC_WRTEE | PPC_RFDI |
2757                        PPC_CACHE | PPC_CACHE_LOCK | PPC_CACHE_ICBI |
2758                        PPC_CACHE_DCBZ | PPC_CACHE_DCBA |
2759                        PPC_MEM_TLBSYNC | PPC_TLBIVAX |
2760                        PPC_BOOKE;
2761     pcc->msr_mask = (1ull << MSR_UCLE) |
2762                     (1ull << MSR_SPE) |
2763                     (1ull << MSR_POW) |
2764                     (1ull << MSR_CE) |
2765                     (1ull << MSR_EE) |
2766                     (1ull << MSR_PR) |
2767                     (1ull << MSR_FP) |
2768                     (1ull << MSR_ME) |
2769                     (1ull << MSR_FE0) |
2770                     (1ull << MSR_DWE) |
2771                     (1ull << MSR_DE) |
2772                     (1ull << MSR_FE1) |
2773                     (1ull << MSR_IR) |
2774                     (1ull << MSR_DR);
2775     pcc->mmu_model = POWERPC_MMU_BOOKE206;
2776     pcc->excp_model = POWERPC_EXCP_BOOKE;
2777     pcc->bus_model = PPC_FLAGS_INPUT_BookE;
2778     pcc->bfd_mach = bfd_mach_ppc_860;
2779     pcc->flags = POWERPC_FLAG_SPE | POWERPC_FLAG_CE |
2780                  POWERPC_FLAG_UBLE | POWERPC_FLAG_DE |
2781                  POWERPC_FLAG_BUS_CLK;
2782 }
2783 
2784 enum fsl_e500_version {
2785     fsl_e500v1,
2786     fsl_e500v2,
2787     fsl_e500mc,
2788     fsl_e5500,
2789     fsl_e6500,
2790 };
2791 
2792 static void init_proc_e500(CPUPPCState *env, int version)
2793 {
2794     uint32_t tlbncfg[2];
2795     uint64_t ivor_mask;
2796     uint64_t ivpr_mask = 0xFFFF0000ULL;
2797     uint32_t l1cfg0 = 0x3800  /* 8 ways */
2798                     | 0x0020; /* 32 kb */
2799     uint32_t l1cfg1 = 0x3800  /* 8 ways */
2800                     | 0x0020; /* 32 kb */
2801     uint32_t mmucfg = 0;
2802 #if !defined(CONFIG_USER_ONLY)
2803     int i;
2804 #endif
2805 
2806     /*
2807      * XXX The e500 doesn't implement IVOR7 and IVOR9, but doesn't
2808      *     complain when accessing them.
2809      * register_BookE_sprs(env, 0x0000000F0000FD7FULL);
2810      */
2811     switch (version) {
2812     case fsl_e500v1:
2813     case fsl_e500v2:
2814     default:
2815         ivor_mask = 0x0000000F0000FFFFULL;
2816         break;
2817     case fsl_e500mc:
2818     case fsl_e5500:
2819         ivor_mask = 0x000003FE0000FFFFULL;
2820         break;
2821     case fsl_e6500:
2822         ivor_mask = 0x000003FF0000FFFFULL;
2823         break;
2824     }
2825     register_BookE_sprs(env, ivor_mask);
2826 
2827     spr_register(env, SPR_USPRG3, "USPRG3",
2828                  &spr_read_ureg, SPR_NOACCESS,
2829                  &spr_read_ureg, SPR_NOACCESS,
2830                  0x00000000);
2831 
2832     /* Processor identification */
2833     spr_register(env, SPR_BOOKE_PIR, "PIR",
2834                  SPR_NOACCESS, SPR_NOACCESS,
2835                  &spr_read_generic, &spr_write_pir,
2836                  0x00000000);
2837 
2838     spr_register(env, SPR_BOOKE_SPEFSCR, "SPEFSCR",
2839                  &spr_read_spefscr, &spr_write_spefscr,
2840                  &spr_read_spefscr, &spr_write_spefscr,
2841                  0x00000000);
2842 #if !defined(CONFIG_USER_ONLY)
2843     /* Memory management */
2844     env->nb_pids = 3;
2845     env->nb_ways = 2;
2846     env->id_tlbs = 0;
2847     switch (version) {
2848     case fsl_e500v1:
2849         tlbncfg[0] = register_tlbncfg(2, 1, 1, 0, 256);
2850         tlbncfg[1] = register_tlbncfg(16, 1, 9, TLBnCFG_AVAIL | TLBnCFG_IPROT, 16);
2851         break;
2852     case fsl_e500v2:
2853         tlbncfg[0] = register_tlbncfg(4, 1, 1, 0, 512);
2854         tlbncfg[1] = register_tlbncfg(16, 1, 12, TLBnCFG_AVAIL | TLBnCFG_IPROT, 16);
2855         break;
2856     case fsl_e500mc:
2857     case fsl_e5500:
2858         tlbncfg[0] = register_tlbncfg(4, 1, 1, 0, 512);
2859         tlbncfg[1] = register_tlbncfg(64, 1, 12, TLBnCFG_AVAIL | TLBnCFG_IPROT, 64);
2860         break;
2861     case fsl_e6500:
2862         mmucfg = 0x6510B45;
2863         env->nb_pids = 1;
2864         tlbncfg[0] = 0x08052400;
2865         tlbncfg[1] = 0x40028040;
2866         break;
2867     default:
2868         cpu_abort(env_cpu(env), "Unknown CPU: " TARGET_FMT_lx "\n",
2869                   env->spr[SPR_PVR]);
2870     }
2871 #endif
2872     /* Cache sizes */
2873     switch (version) {
2874     case fsl_e500v1:
2875     case fsl_e500v2:
2876         env->dcache_line_size = 32;
2877         env->icache_line_size = 32;
2878         break;
2879     case fsl_e500mc:
2880     case fsl_e5500:
2881         env->dcache_line_size = 64;
2882         env->icache_line_size = 64;
2883         l1cfg0 |= 0x1000000; /* 64 byte cache block size */
2884         l1cfg1 |= 0x1000000; /* 64 byte cache block size */
2885         break;
2886     case fsl_e6500:
2887         env->dcache_line_size = 32;
2888         env->icache_line_size = 32;
2889         l1cfg0 |= 0x0F83820;
2890         l1cfg1 |= 0x0B83820;
2891         break;
2892     default:
2893         cpu_abort(env_cpu(env), "Unknown CPU: " TARGET_FMT_lx "\n",
2894                   env->spr[SPR_PVR]);
2895     }
2896     register_BookE206_sprs(env, 0x000000DF, tlbncfg, mmucfg);
2897     register_usprgh_sprs(env);
2898 
2899     spr_register(env, SPR_HID0, "HID0",
2900                  SPR_NOACCESS, SPR_NOACCESS,
2901                  &spr_read_generic, &spr_write_generic,
2902                  0x00000000);
2903 
2904     spr_register(env, SPR_HID1, "HID1",
2905                  SPR_NOACCESS, SPR_NOACCESS,
2906                  &spr_read_generic, &spr_write_generic,
2907                  0x00000000);
2908 
2909     spr_register(env, SPR_Exxx_BBEAR, "BBEAR",
2910                  SPR_NOACCESS, SPR_NOACCESS,
2911                  &spr_read_generic, &spr_write_generic,
2912                  0x00000000);
2913 
2914     spr_register(env, SPR_Exxx_BBTAR, "BBTAR",
2915                  SPR_NOACCESS, SPR_NOACCESS,
2916                  &spr_read_generic, &spr_write_generic,
2917                  0x00000000);
2918 
2919     spr_register(env, SPR_Exxx_MCAR, "MCAR",
2920                  SPR_NOACCESS, SPR_NOACCESS,
2921                  &spr_read_generic, &spr_write_generic,
2922                  0x00000000);
2923 
2924     spr_register(env, SPR_BOOKE_MCSR, "MCSR",
2925                  SPR_NOACCESS, SPR_NOACCESS,
2926                  &spr_read_generic, &spr_write_generic,
2927                  0x00000000);
2928 
2929     spr_register(env, SPR_Exxx_NPIDR, "NPIDR",
2930                  SPR_NOACCESS, SPR_NOACCESS,
2931                  &spr_read_generic, &spr_write_generic,
2932                  0x00000000);
2933 
2934     spr_register(env, SPR_Exxx_BUCSR, "BUCSR",
2935                  SPR_NOACCESS, SPR_NOACCESS,
2936                  &spr_read_generic, &spr_write_generic,
2937                  0x00000000);
2938 
2939     spr_register(env, SPR_Exxx_L1CFG0, "L1CFG0",
2940                  &spr_read_generic, SPR_NOACCESS,
2941                  &spr_read_generic, SPR_NOACCESS,
2942                  l1cfg0);
2943     spr_register(env, SPR_Exxx_L1CFG1, "L1CFG1",
2944                  &spr_read_generic, SPR_NOACCESS,
2945                  &spr_read_generic, SPR_NOACCESS,
2946                  l1cfg1);
2947     spr_register(env, SPR_Exxx_L1CSR0, "L1CSR0",
2948                  SPR_NOACCESS, SPR_NOACCESS,
2949                  &spr_read_generic, &spr_write_e500_l1csr0,
2950                  0x00000000);
2951     spr_register(env, SPR_Exxx_L1CSR1, "L1CSR1",
2952                  SPR_NOACCESS, SPR_NOACCESS,
2953                  &spr_read_generic, &spr_write_e500_l1csr1,
2954                  0x00000000);
2955     if (version != fsl_e500v1 && version != fsl_e500v2) {
2956         spr_register(env, SPR_Exxx_L2CSR0, "L2CSR0",
2957                      SPR_NOACCESS, SPR_NOACCESS,
2958                      &spr_read_generic, &spr_write_e500_l2csr0,
2959                      0x00000000);
2960     }
2961     spr_register(env, SPR_BOOKE_MCSRR0, "MCSRR0",
2962                  SPR_NOACCESS, SPR_NOACCESS,
2963                  &spr_read_generic, &spr_write_generic,
2964                  0x00000000);
2965     spr_register(env, SPR_BOOKE_MCSRR1, "MCSRR1",
2966                  SPR_NOACCESS, SPR_NOACCESS,
2967                  &spr_read_generic, &spr_write_generic,
2968                  0x00000000);
2969     spr_register(env, SPR_MMUCSR0, "MMUCSR0",
2970                  SPR_NOACCESS, SPR_NOACCESS,
2971                  &spr_read_generic, &spr_write_booke206_mmucsr0,
2972                  0x00000000);
2973     spr_register(env, SPR_BOOKE_EPR, "EPR",
2974                  SPR_NOACCESS, SPR_NOACCESS,
2975                  &spr_read_generic, SPR_NOACCESS,
2976                  0x00000000);
2977     /* XXX better abstract into Emb.xxx features */
2978     if ((version == fsl_e5500) || (version == fsl_e6500)) {
2979         spr_register(env, SPR_BOOKE_EPCR, "EPCR",
2980                      SPR_NOACCESS, SPR_NOACCESS,
2981                      &spr_read_generic, &spr_write_generic,
2982                      0x00000000);
2983         spr_register(env, SPR_BOOKE_MAS7_MAS3, "MAS7_MAS3",
2984                      SPR_NOACCESS, SPR_NOACCESS,
2985                      &spr_read_mas73, &spr_write_mas73,
2986                      0x00000000);
2987         ivpr_mask = (target_ulong)~0xFFFFULL;
2988     }
2989 
2990     if (version == fsl_e6500) {
2991         /* Thread identification */
2992         spr_register(env, SPR_TIR, "TIR",
2993                      SPR_NOACCESS, SPR_NOACCESS,
2994                      &spr_read_generic, SPR_NOACCESS,
2995                      0x00000000);
2996         spr_register(env, SPR_BOOKE_TLB0PS, "TLB0PS",
2997                      SPR_NOACCESS, SPR_NOACCESS,
2998                      &spr_read_generic, SPR_NOACCESS,
2999                      0x00000004);
3000         spr_register(env, SPR_BOOKE_TLB1PS, "TLB1PS",
3001                      SPR_NOACCESS, SPR_NOACCESS,
3002                      &spr_read_generic, SPR_NOACCESS,
3003                      0x7FFFFFFC);
3004     }
3005 
3006 #if !defined(CONFIG_USER_ONLY)
3007     env->nb_tlb = 0;
3008     env->tlb_type = TLB_MAS;
3009     for (i = 0; i < BOOKE206_MAX_TLBN; i++) {
3010         env->nb_tlb += booke206_tlb_size(env, i);
3011     }
3012 #endif
3013 
3014     init_excp_e200(env, ivpr_mask);
3015     /* Allocate hardware IRQ controller */
3016     ppce500_irq_init(env_archcpu(env));
3017 }
3018 
3019 static void init_proc_e500v1(CPUPPCState *env)
3020 {
3021     init_proc_e500(env, fsl_e500v1);
3022 }
3023 
3024 POWERPC_FAMILY(e500v1)(ObjectClass *oc, void *data)
3025 {
3026     DeviceClass *dc = DEVICE_CLASS(oc);
3027     PowerPCCPUClass *pcc = POWERPC_CPU_CLASS(oc);
3028 
3029     dc->desc = "e500v1 core";
3030     pcc->init_proc = init_proc_e500v1;
3031     pcc->check_pow = check_pow_hid0;
3032     pcc->insns_flags = PPC_INSNS_BASE | PPC_ISEL |
3033                        PPC_SPE | PPC_SPE_SINGLE |
3034                        PPC_WRTEE | PPC_RFDI |
3035                        PPC_CACHE | PPC_CACHE_LOCK | PPC_CACHE_ICBI |
3036                        PPC_CACHE_DCBZ | PPC_CACHE_DCBA |
3037                        PPC_MEM_TLBSYNC | PPC_TLBIVAX | PPC_MEM_SYNC;
3038     pcc->insns_flags2 = PPC2_BOOKE206;
3039     pcc->msr_mask = (1ull << MSR_UCLE) |
3040                     (1ull << MSR_SPE) |
3041                     (1ull << MSR_POW) |
3042                     (1ull << MSR_CE) |
3043                     (1ull << MSR_EE) |
3044                     (1ull << MSR_PR) |
3045                     (1ull << MSR_FP) |
3046                     (1ull << MSR_ME) |
3047                     (1ull << MSR_FE0) |
3048                     (1ull << MSR_DWE) |
3049                     (1ull << MSR_DE) |
3050                     (1ull << MSR_FE1) |
3051                     (1ull << MSR_IR) |
3052                     (1ull << MSR_DR);
3053     pcc->mmu_model = POWERPC_MMU_BOOKE206;
3054     pcc->excp_model = POWERPC_EXCP_BOOKE;
3055     pcc->bus_model = PPC_FLAGS_INPUT_BookE;
3056     pcc->bfd_mach = bfd_mach_ppc_860;
3057     pcc->flags = POWERPC_FLAG_SPE | POWERPC_FLAG_CE |
3058                  POWERPC_FLAG_UBLE | POWERPC_FLAG_DE |
3059                  POWERPC_FLAG_BUS_CLK;
3060 }
3061 
3062 static void init_proc_e500v2(CPUPPCState *env)
3063 {
3064     init_proc_e500(env, fsl_e500v2);
3065 }
3066 
3067 POWERPC_FAMILY(e500v2)(ObjectClass *oc, void *data)
3068 {
3069     DeviceClass *dc = DEVICE_CLASS(oc);
3070     PowerPCCPUClass *pcc = POWERPC_CPU_CLASS(oc);
3071 
3072     dc->desc = "e500v2 core";
3073     pcc->init_proc = init_proc_e500v2;
3074     pcc->check_pow = check_pow_hid0;
3075     pcc->insns_flags = PPC_INSNS_BASE | PPC_ISEL |
3076                        PPC_SPE | PPC_SPE_SINGLE | PPC_SPE_DOUBLE |
3077                        PPC_WRTEE | PPC_RFDI |
3078                        PPC_CACHE | PPC_CACHE_LOCK | PPC_CACHE_ICBI |
3079                        PPC_CACHE_DCBZ | PPC_CACHE_DCBA |
3080                        PPC_MEM_TLBSYNC | PPC_TLBIVAX | PPC_MEM_SYNC;
3081     pcc->insns_flags2 = PPC2_BOOKE206;
3082     pcc->msr_mask = (1ull << MSR_UCLE) |
3083                     (1ull << MSR_SPE) |
3084                     (1ull << MSR_POW) |
3085                     (1ull << MSR_CE) |
3086                     (1ull << MSR_EE) |
3087                     (1ull << MSR_PR) |
3088                     (1ull << MSR_FP) |
3089                     (1ull << MSR_ME) |
3090                     (1ull << MSR_FE0) |
3091                     (1ull << MSR_DWE) |
3092                     (1ull << MSR_DE) |
3093                     (1ull << MSR_FE1) |
3094                     (1ull << MSR_IR) |
3095                     (1ull << MSR_DR);
3096     pcc->mmu_model = POWERPC_MMU_BOOKE206;
3097     pcc->excp_model = POWERPC_EXCP_BOOKE;
3098     pcc->bus_model = PPC_FLAGS_INPUT_BookE;
3099     pcc->bfd_mach = bfd_mach_ppc_860;
3100     pcc->flags = POWERPC_FLAG_SPE | POWERPC_FLAG_CE |
3101                  POWERPC_FLAG_UBLE | POWERPC_FLAG_DE |
3102                  POWERPC_FLAG_BUS_CLK;
3103 }
3104 
3105 static void init_proc_e500mc(CPUPPCState *env)
3106 {
3107     init_proc_e500(env, fsl_e500mc);
3108 }
3109 
3110 POWERPC_FAMILY(e500mc)(ObjectClass *oc, void *data)
3111 {
3112     DeviceClass *dc = DEVICE_CLASS(oc);
3113     PowerPCCPUClass *pcc = POWERPC_CPU_CLASS(oc);
3114 
3115     dc->desc = "e500mc core";
3116     pcc->init_proc = init_proc_e500mc;
3117     pcc->check_pow = check_pow_none;
3118     pcc->insns_flags = PPC_INSNS_BASE | PPC_ISEL | PPC_MFTB |
3119                        PPC_WRTEE | PPC_RFDI | PPC_RFMCI |
3120                        PPC_CACHE | PPC_CACHE_LOCK | PPC_CACHE_ICBI |
3121                        PPC_CACHE_DCBZ | PPC_CACHE_DCBA |
3122                        PPC_FLOAT | PPC_FLOAT_FRES |
3123                        PPC_FLOAT_FRSQRTE | PPC_FLOAT_FSEL |
3124                        PPC_FLOAT_STFIWX | PPC_WAIT |
3125                        PPC_MEM_TLBSYNC | PPC_TLBIVAX | PPC_MEM_SYNC;
3126     pcc->insns_flags2 = PPC2_BOOKE206 | PPC2_PRCNTL;
3127     pcc->msr_mask = (1ull << MSR_GS) |
3128                     (1ull << MSR_UCLE) |
3129                     (1ull << MSR_CE) |
3130                     (1ull << MSR_EE) |
3131                     (1ull << MSR_PR) |
3132                     (1ull << MSR_FP) |
3133                     (1ull << MSR_ME) |
3134                     (1ull << MSR_FE0) |
3135                     (1ull << MSR_DE) |
3136                     (1ull << MSR_FE1) |
3137                     (1ull << MSR_IR) |
3138                     (1ull << MSR_DR) |
3139                     (1ull << MSR_PX) |
3140                     (1ull << MSR_RI);
3141     pcc->mmu_model = POWERPC_MMU_BOOKE206;
3142     pcc->excp_model = POWERPC_EXCP_BOOKE;
3143     pcc->bus_model = PPC_FLAGS_INPUT_BookE;
3144     /* FIXME: figure out the correct flag for e500mc */
3145     pcc->bfd_mach = bfd_mach_ppc_e500;
3146     pcc->flags = POWERPC_FLAG_CE | POWERPC_FLAG_DE |
3147                  POWERPC_FLAG_PMM | POWERPC_FLAG_BUS_CLK;
3148 }
3149 
3150 #ifdef TARGET_PPC64
3151 static void init_proc_e5500(CPUPPCState *env)
3152 {
3153     init_proc_e500(env, fsl_e5500);
3154 }
3155 
3156 POWERPC_FAMILY(e5500)(ObjectClass *oc, void *data)
3157 {
3158     DeviceClass *dc = DEVICE_CLASS(oc);
3159     PowerPCCPUClass *pcc = POWERPC_CPU_CLASS(oc);
3160 
3161     dc->desc = "e5500 core";
3162     pcc->init_proc = init_proc_e5500;
3163     pcc->check_pow = check_pow_none;
3164     pcc->insns_flags = PPC_INSNS_BASE | PPC_ISEL | PPC_MFTB |
3165                        PPC_WRTEE | PPC_RFDI | PPC_RFMCI |
3166                        PPC_CACHE | PPC_CACHE_LOCK | PPC_CACHE_ICBI |
3167                        PPC_CACHE_DCBZ | PPC_CACHE_DCBA |
3168                        PPC_FLOAT | PPC_FLOAT_FRES |
3169                        PPC_FLOAT_FRSQRTE | PPC_FLOAT_FSEL |
3170                        PPC_FLOAT_STFIWX | PPC_WAIT |
3171                        PPC_MEM_TLBSYNC | PPC_TLBIVAX | PPC_MEM_SYNC |
3172                        PPC_64B | PPC_POPCNTB | PPC_POPCNTWD;
3173     pcc->insns_flags2 = PPC2_BOOKE206 | PPC2_PRCNTL | PPC2_PERM_ISA206 |
3174                         PPC2_FP_CVT_S64;
3175     pcc->msr_mask = (1ull << MSR_CM) |
3176                     (1ull << MSR_GS) |
3177                     (1ull << MSR_UCLE) |
3178                     (1ull << MSR_CE) |
3179                     (1ull << MSR_EE) |
3180                     (1ull << MSR_PR) |
3181                     (1ull << MSR_FP) |
3182                     (1ull << MSR_ME) |
3183                     (1ull << MSR_FE0) |
3184                     (1ull << MSR_DE) |
3185                     (1ull << MSR_FE1) |
3186                     (1ull << MSR_IR) |
3187                     (1ull << MSR_DR) |
3188                     (1ull << MSR_PX) |
3189                     (1ull << MSR_RI);
3190     pcc->mmu_model = POWERPC_MMU_BOOKE206;
3191     pcc->excp_model = POWERPC_EXCP_BOOKE;
3192     pcc->bus_model = PPC_FLAGS_INPUT_BookE;
3193     /* FIXME: figure out the correct flag for e5500 */
3194     pcc->bfd_mach = bfd_mach_ppc_e500;
3195     pcc->flags = POWERPC_FLAG_CE | POWERPC_FLAG_DE |
3196                  POWERPC_FLAG_PMM | POWERPC_FLAG_BUS_CLK;
3197 }
3198 
3199 static void init_proc_e6500(CPUPPCState *env)
3200 {
3201     init_proc_e500(env, fsl_e6500);
3202 }
3203 
3204 POWERPC_FAMILY(e6500)(ObjectClass *oc, void *data)
3205 {
3206     DeviceClass *dc = DEVICE_CLASS(oc);
3207     PowerPCCPUClass *pcc = POWERPC_CPU_CLASS(oc);
3208 
3209     dc->desc = "e6500 core";
3210     pcc->init_proc = init_proc_e6500;
3211     pcc->check_pow = check_pow_none;
3212     pcc->insns_flags = PPC_INSNS_BASE | PPC_ISEL | PPC_MFTB |
3213                        PPC_WRTEE | PPC_RFDI | PPC_RFMCI |
3214                        PPC_CACHE | PPC_CACHE_LOCK | PPC_CACHE_ICBI |
3215                        PPC_CACHE_DCBZ | PPC_CACHE_DCBA |
3216                        PPC_FLOAT | PPC_FLOAT_FRES |
3217                        PPC_FLOAT_FRSQRTE | PPC_FLOAT_FSEL |
3218                        PPC_FLOAT_STFIWX | PPC_WAIT |
3219                        PPC_MEM_TLBSYNC | PPC_TLBIVAX | PPC_MEM_SYNC |
3220                        PPC_64B | PPC_POPCNTB | PPC_POPCNTWD | PPC_ALTIVEC;
3221     pcc->insns_flags2 = PPC2_BOOKE206 | PPC2_PRCNTL | PPC2_PERM_ISA206 |
3222                         PPC2_FP_CVT_S64 | PPC2_ATOMIC_ISA206;
3223     pcc->msr_mask = (1ull << MSR_CM) |
3224                     (1ull << MSR_GS) |
3225                     (1ull << MSR_UCLE) |
3226                     (1ull << MSR_CE) |
3227                     (1ull << MSR_EE) |
3228                     (1ull << MSR_PR) |
3229                     (1ull << MSR_FP) |
3230                     (1ull << MSR_ME) |
3231                     (1ull << MSR_FE0) |
3232                     (1ull << MSR_DE) |
3233                     (1ull << MSR_FE1) |
3234                     (1ull << MSR_IS) |
3235                     (1ull << MSR_DS) |
3236                     (1ull << MSR_PX) |
3237                     (1ull << MSR_RI) |
3238                     (1ull << MSR_VR);
3239     pcc->mmu_model = POWERPC_MMU_BOOKE206;
3240     pcc->excp_model = POWERPC_EXCP_BOOKE;
3241     pcc->bus_model = PPC_FLAGS_INPUT_BookE;
3242     pcc->bfd_mach = bfd_mach_ppc_e500;
3243     pcc->flags = POWERPC_FLAG_CE | POWERPC_FLAG_DE |
3244                  POWERPC_FLAG_PMM | POWERPC_FLAG_BUS_CLK | POWERPC_FLAG_VRE;
3245 }
3246 
3247 #endif
3248 
3249 /* Non-embedded PowerPC                                                      */
3250 static void init_proc_603(CPUPPCState *env)
3251 {
3252     register_non_embedded_sprs(env);
3253     register_sdr1_sprs(env);
3254     register_603_sprs(env);
3255 
3256     /* Memory management */
3257     register_low_BATs(env);
3258     register_6xx_7xx_soft_tlb(env, 64, 2);
3259     init_excp_603(env);
3260     env->dcache_line_size = 32;
3261     env->icache_line_size = 32;
3262     /* Allocate hardware IRQ controller */
3263     ppc6xx_irq_init(env_archcpu(env));
3264 }
3265 
3266 POWERPC_FAMILY(603)(ObjectClass *oc, void *data)
3267 {
3268     DeviceClass *dc = DEVICE_CLASS(oc);
3269     PowerPCCPUClass *pcc = POWERPC_CPU_CLASS(oc);
3270 
3271     dc->desc = "PowerPC 603";
3272     pcc->init_proc = init_proc_603;
3273     pcc->check_pow = check_pow_hid0;
3274     pcc->insns_flags = PPC_INSNS_BASE | PPC_STRING | PPC_MFTB |
3275                        PPC_FLOAT | PPC_FLOAT_FSEL | PPC_FLOAT_FRES |
3276                        PPC_FLOAT_FRSQRTE | PPC_FLOAT_STFIWX |
3277                        PPC_CACHE | PPC_CACHE_ICBI | PPC_CACHE_DCBZ |
3278                        PPC_MEM_SYNC | PPC_MEM_EIEIO |
3279                        PPC_MEM_TLBIE | PPC_MEM_TLBSYNC | PPC_6xx_TLB |
3280                        PPC_SEGMENT | PPC_EXTERN;
3281     pcc->msr_mask = (1ull << MSR_POW) |
3282                     (1ull << MSR_TGPR) |
3283                     (1ull << MSR_ILE) |
3284                     (1ull << MSR_EE) |
3285                     (1ull << MSR_PR) |
3286                     (1ull << MSR_FP) |
3287                     (1ull << MSR_ME) |
3288                     (1ull << MSR_FE0) |
3289                     (1ull << MSR_SE) |
3290                     (1ull << MSR_DE) |
3291                     (1ull << MSR_FE1) |
3292                     (1ull << MSR_EP) |
3293                     (1ull << MSR_IR) |
3294                     (1ull << MSR_DR) |
3295                     (1ull << MSR_RI) |
3296                     (1ull << MSR_LE);
3297     pcc->mmu_model = POWERPC_MMU_SOFT_6xx;
3298     pcc->excp_model = POWERPC_EXCP_6xx;
3299     pcc->bus_model = PPC_FLAGS_INPUT_6xx;
3300     pcc->bfd_mach = bfd_mach_ppc_603;
3301     pcc->flags = POWERPC_FLAG_TGPR | POWERPC_FLAG_SE |
3302                  POWERPC_FLAG_BE | POWERPC_FLAG_BUS_CLK;
3303 }
3304 
3305 POWERPC_FAMILY(603E)(ObjectClass *oc, void *data)
3306 {
3307     DeviceClass *dc = DEVICE_CLASS(oc);
3308     PowerPCCPUClass *pcc = POWERPC_CPU_CLASS(oc);
3309 
3310     dc->desc = "PowerPC 603e";
3311     pcc->init_proc = init_proc_603;
3312     pcc->check_pow = check_pow_hid0;
3313     pcc->insns_flags = PPC_INSNS_BASE | PPC_STRING | PPC_MFTB |
3314                        PPC_FLOAT | PPC_FLOAT_FSEL | PPC_FLOAT_FRES |
3315                        PPC_FLOAT_FRSQRTE | PPC_FLOAT_STFIWX |
3316                        PPC_CACHE | PPC_CACHE_ICBI | PPC_CACHE_DCBZ |
3317                        PPC_MEM_SYNC | PPC_MEM_EIEIO |
3318                        PPC_MEM_TLBIE | PPC_MEM_TLBSYNC | PPC_6xx_TLB |
3319                        PPC_SEGMENT | PPC_EXTERN;
3320     pcc->msr_mask = (1ull << MSR_POW) |
3321                     (1ull << MSR_TGPR) |
3322                     (1ull << MSR_ILE) |
3323                     (1ull << MSR_EE) |
3324                     (1ull << MSR_PR) |
3325                     (1ull << MSR_FP) |
3326                     (1ull << MSR_ME) |
3327                     (1ull << MSR_FE0) |
3328                     (1ull << MSR_SE) |
3329                     (1ull << MSR_DE) |
3330                     (1ull << MSR_FE1) |
3331                     (1ull << MSR_EP) |
3332                     (1ull << MSR_IR) |
3333                     (1ull << MSR_DR) |
3334                     (1ull << MSR_RI) |
3335                     (1ull << MSR_LE);
3336     pcc->mmu_model = POWERPC_MMU_SOFT_6xx;
3337     pcc->excp_model = POWERPC_EXCP_6xx;
3338     pcc->bus_model = PPC_FLAGS_INPUT_6xx;
3339     pcc->bfd_mach = bfd_mach_ppc_ec603e;
3340     pcc->flags = POWERPC_FLAG_TGPR | POWERPC_FLAG_SE |
3341                  POWERPC_FLAG_BE | POWERPC_FLAG_BUS_CLK;
3342 }
3343 
3344 static void init_proc_e300(CPUPPCState *env)
3345 {
3346     init_proc_603(env);
3347     register_e300_sprs(env);
3348 }
3349 
3350 POWERPC_FAMILY(e300)(ObjectClass *oc, void *data)
3351 {
3352     DeviceClass *dc = DEVICE_CLASS(oc);
3353     PowerPCCPUClass *pcc = POWERPC_CPU_CLASS(oc);
3354 
3355     dc->desc = "e300 core";
3356     pcc->init_proc = init_proc_e300;
3357     pcc->check_pow = check_pow_hid0;
3358     pcc->insns_flags = PPC_INSNS_BASE | PPC_STRING | PPC_MFTB |
3359                        PPC_FLOAT | PPC_FLOAT_FSEL | PPC_FLOAT_FRES |
3360                        PPC_FLOAT_STFIWX |
3361                        PPC_CACHE | PPC_CACHE_ICBI | PPC_CACHE_DCBZ |
3362                        PPC_MEM_SYNC | PPC_MEM_EIEIO |
3363                        PPC_MEM_TLBIE | PPC_MEM_TLBSYNC | PPC_6xx_TLB |
3364                        PPC_SEGMENT | PPC_EXTERN;
3365     pcc->msr_mask = (1ull << MSR_POW) |
3366                     (1ull << MSR_TGPR) |
3367                     (1ull << MSR_ILE) |
3368                     (1ull << MSR_EE) |
3369                     (1ull << MSR_PR) |
3370                     (1ull << MSR_FP) |
3371                     (1ull << MSR_ME) |
3372                     (1ull << MSR_FE0) |
3373                     (1ull << MSR_SE) |
3374                     (1ull << MSR_DE) |
3375                     (1ull << MSR_FE1) |
3376                     (1ull << MSR_AL) |
3377                     (1ull << MSR_EP) |
3378                     (1ull << MSR_IR) |
3379                     (1ull << MSR_DR) |
3380                     (1ull << MSR_RI) |
3381                     (1ull << MSR_LE);
3382     pcc->mmu_model = POWERPC_MMU_SOFT_6xx;
3383     pcc->excp_model = POWERPC_EXCP_6xx;
3384     pcc->bus_model = PPC_FLAGS_INPUT_6xx;
3385     pcc->bfd_mach = bfd_mach_ppc_603;
3386     pcc->flags = POWERPC_FLAG_TGPR | POWERPC_FLAG_SE |
3387                  POWERPC_FLAG_BE | POWERPC_FLAG_BUS_CLK;
3388 }
3389 
3390 static void init_proc_604(CPUPPCState *env)
3391 {
3392     register_non_embedded_sprs(env);
3393     register_sdr1_sprs(env);
3394     register_604_sprs(env);
3395 
3396     /* Memory management */
3397     register_low_BATs(env);
3398     init_excp_604(env);
3399     env->dcache_line_size = 32;
3400     env->icache_line_size = 32;
3401     /* Allocate hardware IRQ controller */
3402     ppc6xx_irq_init(env_archcpu(env));
3403 }
3404 
3405 POWERPC_FAMILY(604)(ObjectClass *oc, void *data)
3406 {
3407     DeviceClass *dc = DEVICE_CLASS(oc);
3408     PowerPCCPUClass *pcc = POWERPC_CPU_CLASS(oc);
3409 
3410     dc->desc = "PowerPC 604";
3411     pcc->init_proc = init_proc_604;
3412     pcc->check_pow = check_pow_nocheck;
3413     pcc->insns_flags = PPC_INSNS_BASE | PPC_STRING | PPC_MFTB |
3414                        PPC_FLOAT | PPC_FLOAT_FSEL | PPC_FLOAT_FRES |
3415                        PPC_FLOAT_FRSQRTE | PPC_FLOAT_STFIWX |
3416                        PPC_CACHE | PPC_CACHE_ICBI | PPC_CACHE_DCBZ |
3417                        PPC_MEM_SYNC | PPC_MEM_EIEIO |
3418                        PPC_MEM_TLBIE | PPC_MEM_TLBSYNC |
3419                        PPC_SEGMENT | PPC_EXTERN;
3420     pcc->msr_mask = (1ull << MSR_POW) |
3421                     (1ull << MSR_ILE) |
3422                     (1ull << MSR_EE) |
3423                     (1ull << MSR_PR) |
3424                     (1ull << MSR_FP) |
3425                     (1ull << MSR_ME) |
3426                     (1ull << MSR_FE0) |
3427                     (1ull << MSR_SE) |
3428                     (1ull << MSR_DE) |
3429                     (1ull << MSR_FE1) |
3430                     (1ull << MSR_EP) |
3431                     (1ull << MSR_IR) |
3432                     (1ull << MSR_DR) |
3433                     (1ull << MSR_PMM) |
3434                     (1ull << MSR_RI) |
3435                     (1ull << MSR_LE);
3436     pcc->mmu_model = POWERPC_MMU_32B;
3437     pcc->excp_model = POWERPC_EXCP_6xx;
3438     pcc->bus_model = PPC_FLAGS_INPUT_6xx;
3439     pcc->bfd_mach = bfd_mach_ppc_604;
3440     pcc->flags = POWERPC_FLAG_SE | POWERPC_FLAG_BE |
3441                  POWERPC_FLAG_PMM | POWERPC_FLAG_BUS_CLK;
3442 }
3443 
3444 static void init_proc_604E(CPUPPCState *env)
3445 {
3446     init_proc_604(env);
3447     register_604e_sprs(env);
3448 }
3449 
3450 POWERPC_FAMILY(604E)(ObjectClass *oc, void *data)
3451 {
3452     DeviceClass *dc = DEVICE_CLASS(oc);
3453     PowerPCCPUClass *pcc = POWERPC_CPU_CLASS(oc);
3454 
3455     dc->desc = "PowerPC 604E";
3456     pcc->init_proc = init_proc_604E;
3457     pcc->check_pow = check_pow_nocheck;
3458     pcc->insns_flags = PPC_INSNS_BASE | PPC_STRING | PPC_MFTB |
3459                        PPC_FLOAT | PPC_FLOAT_FSEL | PPC_FLOAT_FRES |
3460                        PPC_FLOAT_FRSQRTE | PPC_FLOAT_STFIWX |
3461                        PPC_CACHE | PPC_CACHE_ICBI | PPC_CACHE_DCBZ |
3462                        PPC_MEM_SYNC | PPC_MEM_EIEIO |
3463                        PPC_MEM_TLBIE | PPC_MEM_TLBSYNC |
3464                        PPC_SEGMENT | PPC_EXTERN;
3465     pcc->msr_mask = (1ull << MSR_POW) |
3466                     (1ull << MSR_ILE) |
3467                     (1ull << MSR_EE) |
3468                     (1ull << MSR_PR) |
3469                     (1ull << MSR_FP) |
3470                     (1ull << MSR_ME) |
3471                     (1ull << MSR_FE0) |
3472                     (1ull << MSR_SE) |
3473                     (1ull << MSR_DE) |
3474                     (1ull << MSR_FE1) |
3475                     (1ull << MSR_EP) |
3476                     (1ull << MSR_IR) |
3477                     (1ull << MSR_DR) |
3478                     (1ull << MSR_PMM) |
3479                     (1ull << MSR_RI) |
3480                     (1ull << MSR_LE);
3481     pcc->mmu_model = POWERPC_MMU_32B;
3482     pcc->excp_model = POWERPC_EXCP_6xx;
3483     pcc->bus_model = PPC_FLAGS_INPUT_6xx;
3484     pcc->bfd_mach = bfd_mach_ppc_604;
3485     pcc->flags = POWERPC_FLAG_SE | POWERPC_FLAG_BE |
3486                  POWERPC_FLAG_PMM | POWERPC_FLAG_BUS_CLK;
3487 }
3488 
3489 static void init_proc_740(CPUPPCState *env)
3490 {
3491     register_non_embedded_sprs(env);
3492     register_sdr1_sprs(env);
3493     register_7xx_sprs(env);
3494     /* Thermal management */
3495     register_thrm_sprs(env);
3496 
3497     /* Memory management */
3498     register_low_BATs(env);
3499     init_excp_7x0(env);
3500     env->dcache_line_size = 32;
3501     env->icache_line_size = 32;
3502     /* Allocate hardware IRQ controller */
3503     ppc6xx_irq_init(env_archcpu(env));
3504 }
3505 
3506 POWERPC_FAMILY(740)(ObjectClass *oc, void *data)
3507 {
3508     DeviceClass *dc = DEVICE_CLASS(oc);
3509     PowerPCCPUClass *pcc = POWERPC_CPU_CLASS(oc);
3510 
3511     dc->desc = "PowerPC 740";
3512     pcc->init_proc = init_proc_740;
3513     pcc->check_pow = check_pow_hid0;
3514     pcc->insns_flags = PPC_INSNS_BASE | PPC_STRING | PPC_MFTB |
3515                        PPC_FLOAT | PPC_FLOAT_FSEL | PPC_FLOAT_FRES |
3516                        PPC_FLOAT_FRSQRTE | PPC_FLOAT_STFIWX |
3517                        PPC_CACHE | PPC_CACHE_ICBI | PPC_CACHE_DCBZ |
3518                        PPC_MEM_SYNC | PPC_MEM_EIEIO |
3519                        PPC_MEM_TLBIE | PPC_MEM_TLBSYNC |
3520                        PPC_SEGMENT | PPC_EXTERN;
3521     pcc->msr_mask = (1ull << MSR_POW) |
3522                     (1ull << MSR_ILE) |
3523                     (1ull << MSR_EE) |
3524                     (1ull << MSR_PR) |
3525                     (1ull << MSR_FP) |
3526                     (1ull << MSR_ME) |
3527                     (1ull << MSR_FE0) |
3528                     (1ull << MSR_SE) |
3529                     (1ull << MSR_DE) |
3530                     (1ull << MSR_FE1) |
3531                     (1ull << MSR_EP) |
3532                     (1ull << MSR_IR) |
3533                     (1ull << MSR_DR) |
3534                     (1ull << MSR_PMM) |
3535                     (1ull << MSR_RI) |
3536                     (1ull << MSR_LE);
3537     pcc->mmu_model = POWERPC_MMU_32B;
3538     pcc->excp_model = POWERPC_EXCP_7xx;
3539     pcc->bus_model = PPC_FLAGS_INPUT_6xx;
3540     pcc->bfd_mach = bfd_mach_ppc_750;
3541     pcc->flags = POWERPC_FLAG_SE | POWERPC_FLAG_BE |
3542                  POWERPC_FLAG_PMM | POWERPC_FLAG_BUS_CLK;
3543 }
3544 
3545 static void init_proc_750(CPUPPCState *env)
3546 {
3547     register_non_embedded_sprs(env);
3548     register_sdr1_sprs(env);
3549     register_7xx_sprs(env);
3550 
3551     spr_register(env, SPR_L2CR, "L2CR",
3552                  SPR_NOACCESS, SPR_NOACCESS,
3553                  &spr_read_generic, spr_access_nop,
3554                  0x00000000);
3555     /* Thermal management */
3556     register_thrm_sprs(env);
3557 
3558     /* Memory management */
3559     register_low_BATs(env);
3560     /*
3561      * XXX: high BATs are also present but are known to be bugged on
3562      *      die version 1.x
3563      */
3564     init_excp_7x0(env);
3565     env->dcache_line_size = 32;
3566     env->icache_line_size = 32;
3567     /* Allocate hardware IRQ controller */
3568     ppc6xx_irq_init(env_archcpu(env));
3569 }
3570 
3571 POWERPC_FAMILY(750)(ObjectClass *oc, void *data)
3572 {
3573     DeviceClass *dc = DEVICE_CLASS(oc);
3574     PowerPCCPUClass *pcc = POWERPC_CPU_CLASS(oc);
3575 
3576     dc->desc = "PowerPC 750";
3577     pcc->init_proc = init_proc_750;
3578     pcc->check_pow = check_pow_hid0;
3579     pcc->insns_flags = PPC_INSNS_BASE | PPC_STRING | PPC_MFTB |
3580                        PPC_FLOAT | PPC_FLOAT_FSEL | PPC_FLOAT_FRES |
3581                        PPC_FLOAT_FRSQRTE | PPC_FLOAT_STFIWX |
3582                        PPC_CACHE | PPC_CACHE_ICBI | PPC_CACHE_DCBZ |
3583                        PPC_MEM_SYNC | PPC_MEM_EIEIO |
3584                        PPC_MEM_TLBIE | PPC_MEM_TLBSYNC |
3585                        PPC_SEGMENT | PPC_EXTERN;
3586     pcc->msr_mask = (1ull << MSR_POW) |
3587                     (1ull << MSR_ILE) |
3588                     (1ull << MSR_EE) |
3589                     (1ull << MSR_PR) |
3590                     (1ull << MSR_FP) |
3591                     (1ull << MSR_ME) |
3592                     (1ull << MSR_FE0) |
3593                     (1ull << MSR_SE) |
3594                     (1ull << MSR_DE) |
3595                     (1ull << MSR_FE1) |
3596                     (1ull << MSR_EP) |
3597                     (1ull << MSR_IR) |
3598                     (1ull << MSR_DR) |
3599                     (1ull << MSR_PMM) |
3600                     (1ull << MSR_RI) |
3601                     (1ull << MSR_LE);
3602     pcc->mmu_model = POWERPC_MMU_32B;
3603     pcc->excp_model = POWERPC_EXCP_7xx;
3604     pcc->bus_model = PPC_FLAGS_INPUT_6xx;
3605     pcc->bfd_mach = bfd_mach_ppc_750;
3606     pcc->flags = POWERPC_FLAG_SE | POWERPC_FLAG_BE |
3607                  POWERPC_FLAG_PMM | POWERPC_FLAG_BUS_CLK;
3608 }
3609 
3610 static void init_proc_750cl(CPUPPCState *env)
3611 {
3612     register_non_embedded_sprs(env);
3613     register_sdr1_sprs(env);
3614     register_7xx_sprs(env);
3615 
3616     spr_register(env, SPR_L2CR, "L2CR",
3617                  SPR_NOACCESS, SPR_NOACCESS,
3618                  &spr_read_generic, spr_access_nop,
3619                  0x00000000);
3620     /* Thermal management */
3621     /* Those registers are fake on 750CL */
3622     spr_register(env, SPR_THRM1, "THRM1",
3623                  SPR_NOACCESS, SPR_NOACCESS,
3624                  &spr_read_generic, &spr_write_generic,
3625                  0x00000000);
3626     spr_register(env, SPR_THRM2, "THRM2",
3627                  SPR_NOACCESS, SPR_NOACCESS,
3628                  &spr_read_generic, &spr_write_generic,
3629                  0x00000000);
3630     spr_register(env, SPR_THRM3, "THRM3",
3631                  SPR_NOACCESS, SPR_NOACCESS,
3632                  &spr_read_generic, &spr_write_generic,
3633                  0x00000000);
3634 
3635     spr_register(env, SPR_750_TDCL, "TDCL",
3636                  SPR_NOACCESS, SPR_NOACCESS,
3637                  &spr_read_generic, &spr_write_generic,
3638                  0x00000000);
3639     spr_register(env, SPR_750_TDCH, "TDCH",
3640                  SPR_NOACCESS, SPR_NOACCESS,
3641                  &spr_read_generic, &spr_write_generic,
3642                  0x00000000);
3643     /* DMA */
3644     spr_register(env, SPR_750_WPAR, "WPAR",
3645                  SPR_NOACCESS, SPR_NOACCESS,
3646                  &spr_read_generic, &spr_write_generic,
3647                  0x00000000);
3648     spr_register(env, SPR_750_DMAL, "DMAL",
3649                  SPR_NOACCESS, SPR_NOACCESS,
3650                  &spr_read_generic, &spr_write_generic,
3651                  0x00000000);
3652     spr_register(env, SPR_750_DMAU, "DMAU",
3653                  SPR_NOACCESS, SPR_NOACCESS,
3654                  &spr_read_generic, &spr_write_generic,
3655                  0x00000000);
3656     /* Hardware implementation registers */
3657     spr_register(env, SPR_750CL_HID2, "HID2",
3658                  SPR_NOACCESS, SPR_NOACCESS,
3659                  &spr_read_generic, &spr_write_generic,
3660                  0x00000000);
3661 
3662     spr_register(env, SPR_750CL_HID4, "HID4",
3663                  SPR_NOACCESS, SPR_NOACCESS,
3664                  &spr_read_generic, &spr_write_generic,
3665                  0x00000000);
3666     /* Quantization registers */
3667     spr_register(env, SPR_750_GQR0, "GQR0",
3668                  SPR_NOACCESS, SPR_NOACCESS,
3669                  &spr_read_generic, &spr_write_generic,
3670                  0x00000000);
3671 
3672     spr_register(env, SPR_750_GQR1, "GQR1",
3673                  SPR_NOACCESS, SPR_NOACCESS,
3674                  &spr_read_generic, &spr_write_generic,
3675                  0x00000000);
3676 
3677     spr_register(env, SPR_750_GQR2, "GQR2",
3678                  SPR_NOACCESS, SPR_NOACCESS,
3679                  &spr_read_generic, &spr_write_generic,
3680                  0x00000000);
3681 
3682     spr_register(env, SPR_750_GQR3, "GQR3",
3683                  SPR_NOACCESS, SPR_NOACCESS,
3684                  &spr_read_generic, &spr_write_generic,
3685                  0x00000000);
3686 
3687     spr_register(env, SPR_750_GQR4, "GQR4",
3688                  SPR_NOACCESS, SPR_NOACCESS,
3689                  &spr_read_generic, &spr_write_generic,
3690                  0x00000000);
3691 
3692     spr_register(env, SPR_750_GQR5, "GQR5",
3693                  SPR_NOACCESS, SPR_NOACCESS,
3694                  &spr_read_generic, &spr_write_generic,
3695                  0x00000000);
3696 
3697     spr_register(env, SPR_750_GQR6, "GQR6",
3698                  SPR_NOACCESS, SPR_NOACCESS,
3699                  &spr_read_generic, &spr_write_generic,
3700                  0x00000000);
3701 
3702     spr_register(env, SPR_750_GQR7, "GQR7",
3703                  SPR_NOACCESS, SPR_NOACCESS,
3704                  &spr_read_generic, &spr_write_generic,
3705                  0x00000000);
3706     /* Memory management */
3707     register_low_BATs(env);
3708     /* PowerPC 750cl has 8 DBATs and 8 IBATs */
3709     register_high_BATs(env);
3710     init_excp_750cl(env);
3711     env->dcache_line_size = 32;
3712     env->icache_line_size = 32;
3713     /* Allocate hardware IRQ controller */
3714     ppc6xx_irq_init(env_archcpu(env));
3715 }
3716 
3717 POWERPC_FAMILY(750cl)(ObjectClass *oc, void *data)
3718 {
3719     DeviceClass *dc = DEVICE_CLASS(oc);
3720     PowerPCCPUClass *pcc = POWERPC_CPU_CLASS(oc);
3721 
3722     dc->desc = "PowerPC 750 CL";
3723     pcc->init_proc = init_proc_750cl;
3724     pcc->check_pow = check_pow_hid0;
3725     /*
3726      * XXX: not implemented:
3727      * cache lock instructions:
3728      * dcbz_l
3729      * floating point paired instructions
3730      * psq_lux
3731      * psq_lx
3732      * psq_stux
3733      * psq_stx
3734      * ps_abs
3735      * ps_add
3736      * ps_cmpo0
3737      * ps_cmpo1
3738      * ps_cmpu0
3739      * ps_cmpu1
3740      * ps_div
3741      * ps_madd
3742      * ps_madds0
3743      * ps_madds1
3744      * ps_merge00
3745      * ps_merge01
3746      * ps_merge10
3747      * ps_merge11
3748      * ps_mr
3749      * ps_msub
3750      * ps_mul
3751      * ps_muls0
3752      * ps_muls1
3753      * ps_nabs
3754      * ps_neg
3755      * ps_nmadd
3756      * ps_nmsub
3757      * ps_res
3758      * ps_rsqrte
3759      * ps_sel
3760      * ps_sub
3761      * ps_sum0
3762      * ps_sum1
3763      */
3764     pcc->insns_flags = PPC_INSNS_BASE | PPC_STRING | PPC_MFTB |
3765                        PPC_FLOAT | PPC_FLOAT_FSEL | PPC_FLOAT_FRES |
3766                        PPC_FLOAT_FRSQRTE | PPC_FLOAT_STFIWX |
3767                        PPC_CACHE | PPC_CACHE_ICBI | PPC_CACHE_DCBZ |
3768                        PPC_MEM_SYNC | PPC_MEM_EIEIO |
3769                        PPC_MEM_TLBIE | PPC_MEM_TLBSYNC |
3770                        PPC_SEGMENT | PPC_EXTERN;
3771     pcc->msr_mask = (1ull << MSR_POW) |
3772                     (1ull << MSR_ILE) |
3773                     (1ull << MSR_EE) |
3774                     (1ull << MSR_PR) |
3775                     (1ull << MSR_FP) |
3776                     (1ull << MSR_ME) |
3777                     (1ull << MSR_FE0) |
3778                     (1ull << MSR_SE) |
3779                     (1ull << MSR_DE) |
3780                     (1ull << MSR_FE1) |
3781                     (1ull << MSR_EP) |
3782                     (1ull << MSR_IR) |
3783                     (1ull << MSR_DR) |
3784                     (1ull << MSR_PMM) |
3785                     (1ull << MSR_RI) |
3786                     (1ull << MSR_LE);
3787     pcc->mmu_model = POWERPC_MMU_32B;
3788     pcc->excp_model = POWERPC_EXCP_7xx;
3789     pcc->bus_model = PPC_FLAGS_INPUT_6xx;
3790     pcc->bfd_mach = bfd_mach_ppc_750;
3791     pcc->flags = POWERPC_FLAG_SE | POWERPC_FLAG_BE |
3792                  POWERPC_FLAG_PMM | POWERPC_FLAG_BUS_CLK;
3793 }
3794 
3795 static void init_proc_750cx(CPUPPCState *env)
3796 {
3797     register_non_embedded_sprs(env);
3798     register_sdr1_sprs(env);
3799     register_7xx_sprs(env);
3800 
3801     spr_register(env, SPR_L2CR, "L2CR",
3802                  SPR_NOACCESS, SPR_NOACCESS,
3803                  &spr_read_generic, spr_access_nop,
3804                  0x00000000);
3805     /* Thermal management */
3806     register_thrm_sprs(env);
3807 
3808     spr_register(env, SPR_SDA, "SDA",
3809                  SPR_NOACCESS, SPR_NOACCESS,
3810                  &spr_read_generic, &spr_write_generic,
3811                  0x00000000);
3812 
3813     /* Memory management */
3814     register_low_BATs(env);
3815     /* PowerPC 750cx has 8 DBATs and 8 IBATs */
3816     register_high_BATs(env);
3817     init_excp_750cx(env);
3818     env->dcache_line_size = 32;
3819     env->icache_line_size = 32;
3820     /* Allocate hardware IRQ controller */
3821     ppc6xx_irq_init(env_archcpu(env));
3822 }
3823 
3824 POWERPC_FAMILY(750cx)(ObjectClass *oc, void *data)
3825 {
3826     DeviceClass *dc = DEVICE_CLASS(oc);
3827     PowerPCCPUClass *pcc = POWERPC_CPU_CLASS(oc);
3828 
3829     dc->desc = "PowerPC 750CX";
3830     pcc->init_proc = init_proc_750cx;
3831     pcc->check_pow = check_pow_hid0;
3832     pcc->insns_flags = PPC_INSNS_BASE | PPC_STRING | PPC_MFTB |
3833                        PPC_FLOAT | PPC_FLOAT_FSEL | PPC_FLOAT_FRES |
3834                        PPC_FLOAT_FRSQRTE | PPC_FLOAT_STFIWX |
3835                        PPC_CACHE | PPC_CACHE_ICBI | PPC_CACHE_DCBZ |
3836                        PPC_MEM_SYNC | PPC_MEM_EIEIO |
3837                        PPC_MEM_TLBIE | PPC_MEM_TLBSYNC |
3838                        PPC_SEGMENT | PPC_EXTERN;
3839     pcc->msr_mask = (1ull << MSR_POW) |
3840                     (1ull << MSR_ILE) |
3841                     (1ull << MSR_EE) |
3842                     (1ull << MSR_PR) |
3843                     (1ull << MSR_FP) |
3844                     (1ull << MSR_ME) |
3845                     (1ull << MSR_FE0) |
3846                     (1ull << MSR_SE) |
3847                     (1ull << MSR_DE) |
3848                     (1ull << MSR_FE1) |
3849                     (1ull << MSR_EP) |
3850                     (1ull << MSR_IR) |
3851                     (1ull << MSR_DR) |
3852                     (1ull << MSR_PMM) |
3853                     (1ull << MSR_RI) |
3854                     (1ull << MSR_LE);
3855     pcc->mmu_model = POWERPC_MMU_32B;
3856     pcc->excp_model = POWERPC_EXCP_7xx;
3857     pcc->bus_model = PPC_FLAGS_INPUT_6xx;
3858     pcc->bfd_mach = bfd_mach_ppc_750;
3859     pcc->flags = POWERPC_FLAG_SE | POWERPC_FLAG_BE |
3860                  POWERPC_FLAG_PMM | POWERPC_FLAG_BUS_CLK;
3861 }
3862 
3863 static void init_proc_750fx(CPUPPCState *env)
3864 {
3865     register_non_embedded_sprs(env);
3866     register_sdr1_sprs(env);
3867     register_7xx_sprs(env);
3868 
3869     spr_register(env, SPR_L2CR, "L2CR",
3870                  SPR_NOACCESS, SPR_NOACCESS,
3871                  &spr_read_generic, spr_access_nop,
3872                  0x00000000);
3873     /* Thermal management */
3874     register_thrm_sprs(env);
3875 
3876     spr_register(env, SPR_750_THRM4, "THRM4",
3877                  SPR_NOACCESS, SPR_NOACCESS,
3878                  &spr_read_generic, &spr_write_generic,
3879                  0x00000000);
3880     /* Hardware implementation registers */
3881     spr_register(env, SPR_750FX_HID2, "HID2",
3882                  SPR_NOACCESS, SPR_NOACCESS,
3883                  &spr_read_generic, &spr_write_generic,
3884                  0x00000000);
3885     /* Memory management */
3886     register_low_BATs(env);
3887     /* PowerPC 750fx & 750gx has 8 DBATs and 8 IBATs */
3888     register_high_BATs(env);
3889     init_excp_7x0(env);
3890     env->dcache_line_size = 32;
3891     env->icache_line_size = 32;
3892     /* Allocate hardware IRQ controller */
3893     ppc6xx_irq_init(env_archcpu(env));
3894 }
3895 
3896 POWERPC_FAMILY(750fx)(ObjectClass *oc, void *data)
3897 {
3898     DeviceClass *dc = DEVICE_CLASS(oc);
3899     PowerPCCPUClass *pcc = POWERPC_CPU_CLASS(oc);
3900 
3901     dc->desc = "PowerPC 750FX";
3902     pcc->init_proc = init_proc_750fx;
3903     pcc->check_pow = check_pow_hid0;
3904     pcc->insns_flags = PPC_INSNS_BASE | PPC_STRING | PPC_MFTB |
3905                        PPC_FLOAT | PPC_FLOAT_FSEL | PPC_FLOAT_FRES |
3906                        PPC_FLOAT_FRSQRTE | PPC_FLOAT_STFIWX |
3907                        PPC_CACHE | PPC_CACHE_ICBI | PPC_CACHE_DCBZ |
3908                        PPC_MEM_SYNC | PPC_MEM_EIEIO |
3909                        PPC_MEM_TLBIE | PPC_MEM_TLBSYNC |
3910                        PPC_SEGMENT | PPC_EXTERN;
3911     pcc->msr_mask = (1ull << MSR_POW) |
3912                     (1ull << MSR_ILE) |
3913                     (1ull << MSR_EE) |
3914                     (1ull << MSR_PR) |
3915                     (1ull << MSR_FP) |
3916                     (1ull << MSR_ME) |
3917                     (1ull << MSR_FE0) |
3918                     (1ull << MSR_SE) |
3919                     (1ull << MSR_DE) |
3920                     (1ull << MSR_FE1) |
3921                     (1ull << MSR_EP) |
3922                     (1ull << MSR_IR) |
3923                     (1ull << MSR_DR) |
3924                     (1ull << MSR_PMM) |
3925                     (1ull << MSR_RI) |
3926                     (1ull << MSR_LE);
3927     pcc->mmu_model = POWERPC_MMU_32B;
3928     pcc->excp_model = POWERPC_EXCP_7xx;
3929     pcc->bus_model = PPC_FLAGS_INPUT_6xx;
3930     pcc->bfd_mach = bfd_mach_ppc_750;
3931     pcc->flags = POWERPC_FLAG_SE | POWERPC_FLAG_BE |
3932                  POWERPC_FLAG_PMM | POWERPC_FLAG_BUS_CLK;
3933 }
3934 
3935 static void init_proc_750gx(CPUPPCState *env)
3936 {
3937     register_non_embedded_sprs(env);
3938     register_sdr1_sprs(env);
3939     register_7xx_sprs(env);
3940 
3941     spr_register(env, SPR_L2CR, "L2CR",
3942                  SPR_NOACCESS, SPR_NOACCESS,
3943                  &spr_read_generic, spr_access_nop,
3944                  0x00000000);
3945     /* Thermal management */
3946     register_thrm_sprs(env);
3947 
3948     spr_register(env, SPR_750_THRM4, "THRM4",
3949                  SPR_NOACCESS, SPR_NOACCESS,
3950                  &spr_read_generic, &spr_write_generic,
3951                  0x00000000);
3952     /* Hardware implementation registers */
3953     spr_register(env, SPR_750FX_HID2, "HID2",
3954                  SPR_NOACCESS, SPR_NOACCESS,
3955                  &spr_read_generic, &spr_write_generic,
3956                  0x00000000);
3957     /* Memory management */
3958     register_low_BATs(env);
3959     /* PowerPC 750fx & 750gx has 8 DBATs and 8 IBATs */
3960     register_high_BATs(env);
3961     init_excp_7x0(env);
3962     env->dcache_line_size = 32;
3963     env->icache_line_size = 32;
3964     /* Allocate hardware IRQ controller */
3965     ppc6xx_irq_init(env_archcpu(env));
3966 }
3967 
3968 POWERPC_FAMILY(750gx)(ObjectClass *oc, void *data)
3969 {
3970     DeviceClass *dc = DEVICE_CLASS(oc);
3971     PowerPCCPUClass *pcc = POWERPC_CPU_CLASS(oc);
3972 
3973     dc->desc = "PowerPC 750GX";
3974     pcc->init_proc = init_proc_750gx;
3975     pcc->check_pow = check_pow_hid0;
3976     pcc->insns_flags = PPC_INSNS_BASE | PPC_STRING | PPC_MFTB |
3977                        PPC_FLOAT | PPC_FLOAT_FSEL | PPC_FLOAT_FRES |
3978                        PPC_FLOAT_FRSQRTE | PPC_FLOAT_STFIWX |
3979                        PPC_CACHE | PPC_CACHE_ICBI | PPC_CACHE_DCBZ |
3980                        PPC_MEM_SYNC | PPC_MEM_EIEIO |
3981                        PPC_MEM_TLBIE | PPC_MEM_TLBSYNC |
3982                        PPC_SEGMENT | PPC_EXTERN;
3983     pcc->msr_mask = (1ull << MSR_POW) |
3984                     (1ull << MSR_ILE) |
3985                     (1ull << MSR_EE) |
3986                     (1ull << MSR_PR) |
3987                     (1ull << MSR_FP) |
3988                     (1ull << MSR_ME) |
3989                     (1ull << MSR_FE0) |
3990                     (1ull << MSR_SE) |
3991                     (1ull << MSR_DE) |
3992                     (1ull << MSR_FE1) |
3993                     (1ull << MSR_EP) |
3994                     (1ull << MSR_IR) |
3995                     (1ull << MSR_DR) |
3996                     (1ull << MSR_PMM) |
3997                     (1ull << MSR_RI) |
3998                     (1ull << MSR_LE);
3999     pcc->mmu_model = POWERPC_MMU_32B;
4000     pcc->excp_model = POWERPC_EXCP_7xx;
4001     pcc->bus_model = PPC_FLAGS_INPUT_6xx;
4002     pcc->bfd_mach = bfd_mach_ppc_750;
4003     pcc->flags = POWERPC_FLAG_SE | POWERPC_FLAG_BE |
4004                  POWERPC_FLAG_PMM | POWERPC_FLAG_BUS_CLK;
4005 }
4006 
4007 static void init_proc_745(CPUPPCState *env)
4008 {
4009     register_non_embedded_sprs(env);
4010     register_sdr1_sprs(env);
4011     register_7xx_sprs(env);
4012     register_745_sprs(env);
4013     /* Thermal management */
4014     register_thrm_sprs(env);
4015 
4016     /* Memory management */
4017     register_low_BATs(env);
4018     register_high_BATs(env);
4019     register_6xx_7xx_soft_tlb(env, 64, 2);
4020     init_excp_7x5(env);
4021     env->dcache_line_size = 32;
4022     env->icache_line_size = 32;
4023     /* Allocate hardware IRQ controller */
4024     ppc6xx_irq_init(env_archcpu(env));
4025 }
4026 
4027 POWERPC_FAMILY(745)(ObjectClass *oc, void *data)
4028 {
4029     DeviceClass *dc = DEVICE_CLASS(oc);
4030     PowerPCCPUClass *pcc = POWERPC_CPU_CLASS(oc);
4031 
4032     dc->desc = "PowerPC 745";
4033     pcc->init_proc = init_proc_745;
4034     pcc->check_pow = check_pow_hid0;
4035     pcc->insns_flags = PPC_INSNS_BASE | PPC_STRING | PPC_MFTB |
4036                        PPC_FLOAT | PPC_FLOAT_FSEL | PPC_FLOAT_FRES |
4037                        PPC_FLOAT_FRSQRTE | PPC_FLOAT_STFIWX |
4038                        PPC_CACHE | PPC_CACHE_ICBI | PPC_CACHE_DCBZ |
4039                        PPC_MEM_SYNC | PPC_MEM_EIEIO |
4040                        PPC_MEM_TLBIE | PPC_MEM_TLBSYNC | PPC_6xx_TLB |
4041                        PPC_SEGMENT | PPC_EXTERN;
4042     pcc->msr_mask = (1ull << MSR_POW) |
4043                     (1ull << MSR_ILE) |
4044                     (1ull << MSR_EE) |
4045                     (1ull << MSR_PR) |
4046                     (1ull << MSR_FP) |
4047                     (1ull << MSR_ME) |
4048                     (1ull << MSR_FE0) |
4049                     (1ull << MSR_SE) |
4050                     (1ull << MSR_DE) |
4051                     (1ull << MSR_FE1) |
4052                     (1ull << MSR_EP) |
4053                     (1ull << MSR_IR) |
4054                     (1ull << MSR_DR) |
4055                     (1ull << MSR_PMM) |
4056                     (1ull << MSR_RI) |
4057                     (1ull << MSR_LE);
4058     pcc->mmu_model = POWERPC_MMU_SOFT_6xx;
4059     pcc->excp_model = POWERPC_EXCP_7xx;
4060     pcc->bus_model = PPC_FLAGS_INPUT_6xx;
4061     pcc->bfd_mach = bfd_mach_ppc_750;
4062     pcc->flags = POWERPC_FLAG_SE | POWERPC_FLAG_BE |
4063                  POWERPC_FLAG_PMM | POWERPC_FLAG_BUS_CLK;
4064 }
4065 
4066 static void init_proc_755(CPUPPCState *env)
4067 {
4068     init_proc_745(env);
4069     register_755_sprs(env);
4070 }
4071 
4072 POWERPC_FAMILY(755)(ObjectClass *oc, void *data)
4073 {
4074     DeviceClass *dc = DEVICE_CLASS(oc);
4075     PowerPCCPUClass *pcc = POWERPC_CPU_CLASS(oc);
4076 
4077     dc->desc = "PowerPC 755";
4078     pcc->init_proc = init_proc_755;
4079     pcc->check_pow = check_pow_hid0;
4080     pcc->insns_flags = PPC_INSNS_BASE | PPC_STRING | PPC_MFTB |
4081                        PPC_FLOAT | PPC_FLOAT_FSEL | PPC_FLOAT_FRES |
4082                        PPC_FLOAT_FRSQRTE | PPC_FLOAT_STFIWX |
4083                        PPC_CACHE | PPC_CACHE_ICBI | PPC_CACHE_DCBZ |
4084                        PPC_MEM_SYNC | PPC_MEM_EIEIO |
4085                        PPC_MEM_TLBIE | PPC_MEM_TLBSYNC | PPC_6xx_TLB |
4086                        PPC_SEGMENT | PPC_EXTERN;
4087     pcc->msr_mask = (1ull << MSR_POW) |
4088                     (1ull << MSR_ILE) |
4089                     (1ull << MSR_EE) |
4090                     (1ull << MSR_PR) |
4091                     (1ull << MSR_FP) |
4092                     (1ull << MSR_ME) |
4093                     (1ull << MSR_FE0) |
4094                     (1ull << MSR_SE) |
4095                     (1ull << MSR_DE) |
4096                     (1ull << MSR_FE1) |
4097                     (1ull << MSR_EP) |
4098                     (1ull << MSR_IR) |
4099                     (1ull << MSR_DR) |
4100                     (1ull << MSR_PMM) |
4101                     (1ull << MSR_RI) |
4102                     (1ull << MSR_LE);
4103     pcc->mmu_model = POWERPC_MMU_SOFT_6xx;
4104     pcc->excp_model = POWERPC_EXCP_7xx;
4105     pcc->bus_model = PPC_FLAGS_INPUT_6xx;
4106     pcc->bfd_mach = bfd_mach_ppc_750;
4107     pcc->flags = POWERPC_FLAG_SE | POWERPC_FLAG_BE |
4108                  POWERPC_FLAG_PMM | POWERPC_FLAG_BUS_CLK;
4109 }
4110 
4111 static void init_proc_7400(CPUPPCState *env)
4112 {
4113     register_non_embedded_sprs(env);
4114     register_sdr1_sprs(env);
4115     register_74xx_sprs(env);
4116     vscr_init(env, 0x00010000);
4117 
4118     spr_register(env, SPR_UBAMR, "UBAMR",
4119                  &spr_read_ureg, SPR_NOACCESS,
4120                  &spr_read_ureg, SPR_NOACCESS,
4121                  0x00000000);
4122 
4123     spr_register(env, SPR_MSSCR1, "MSSCR1",
4124                  SPR_NOACCESS, SPR_NOACCESS,
4125                  &spr_read_generic, &spr_write_generic,
4126                  0x00000000);
4127     /* Thermal management */
4128     register_thrm_sprs(env);
4129     /* Memory management */
4130     register_low_BATs(env);
4131     init_excp_7400(env);
4132     env->dcache_line_size = 32;
4133     env->icache_line_size = 32;
4134     /* Allocate hardware IRQ controller */
4135     ppc6xx_irq_init(env_archcpu(env));
4136 }
4137 
4138 POWERPC_FAMILY(7400)(ObjectClass *oc, void *data)
4139 {
4140     DeviceClass *dc = DEVICE_CLASS(oc);
4141     PowerPCCPUClass *pcc = POWERPC_CPU_CLASS(oc);
4142 
4143     dc->desc = "PowerPC 7400 (aka G4)";
4144     pcc->init_proc = init_proc_7400;
4145     pcc->check_pow = check_pow_hid0;
4146     pcc->insns_flags = PPC_INSNS_BASE | PPC_STRING | PPC_MFTB |
4147                        PPC_FLOAT | PPC_FLOAT_FSEL | PPC_FLOAT_FRES |
4148                        PPC_FLOAT_FSQRT | PPC_FLOAT_FRSQRTE |
4149                        PPC_FLOAT_STFIWX |
4150                        PPC_CACHE | PPC_CACHE_ICBI |
4151                        PPC_CACHE_DCBA | PPC_CACHE_DCBZ |
4152                        PPC_MEM_SYNC | PPC_MEM_EIEIO |
4153                        PPC_MEM_TLBIE | PPC_MEM_TLBSYNC |
4154                        PPC_MEM_TLBIA |
4155                        PPC_SEGMENT | PPC_EXTERN |
4156                        PPC_ALTIVEC;
4157     pcc->msr_mask = (1ull << MSR_VR) |
4158                     (1ull << MSR_POW) |
4159                     (1ull << MSR_ILE) |
4160                     (1ull << MSR_EE) |
4161                     (1ull << MSR_PR) |
4162                     (1ull << MSR_FP) |
4163                     (1ull << MSR_ME) |
4164                     (1ull << MSR_FE0) |
4165                     (1ull << MSR_SE) |
4166                     (1ull << MSR_DE) |
4167                     (1ull << MSR_FE1) |
4168                     (1ull << MSR_EP) |
4169                     (1ull << MSR_IR) |
4170                     (1ull << MSR_DR) |
4171                     (1ull << MSR_PMM) |
4172                     (1ull << MSR_RI) |
4173                     (1ull << MSR_LE);
4174     pcc->mmu_model = POWERPC_MMU_32B;
4175     pcc->excp_model = POWERPC_EXCP_74xx;
4176     pcc->bus_model = PPC_FLAGS_INPUT_6xx;
4177     pcc->bfd_mach = bfd_mach_ppc_7400;
4178     pcc->flags = POWERPC_FLAG_VRE | POWERPC_FLAG_SE |
4179                  POWERPC_FLAG_BE | POWERPC_FLAG_PMM |
4180                  POWERPC_FLAG_BUS_CLK;
4181 }
4182 
4183 static void init_proc_7410(CPUPPCState *env)
4184 {
4185     register_non_embedded_sprs(env);
4186     register_sdr1_sprs(env);
4187     register_74xx_sprs(env);
4188     vscr_init(env, 0x00010000);
4189 
4190     spr_register(env, SPR_UBAMR, "UBAMR",
4191                  &spr_read_ureg, SPR_NOACCESS,
4192                  &spr_read_ureg, SPR_NOACCESS,
4193                  0x00000000);
4194     /* Thermal management */
4195     register_thrm_sprs(env);
4196     /* L2PMCR */
4197 
4198     spr_register(env, SPR_L2PMCR, "L2PMCR",
4199                  SPR_NOACCESS, SPR_NOACCESS,
4200                  &spr_read_generic, &spr_write_generic,
4201                  0x00000000);
4202     /* LDSTDB */
4203 
4204     spr_register(env, SPR_LDSTDB, "LDSTDB",
4205                  SPR_NOACCESS, SPR_NOACCESS,
4206                  &spr_read_generic, &spr_write_generic,
4207                  0x00000000);
4208     /* Memory management */
4209     register_low_BATs(env);
4210     init_excp_7400(env);
4211     env->dcache_line_size = 32;
4212     env->icache_line_size = 32;
4213     /* Allocate hardware IRQ controller */
4214     ppc6xx_irq_init(env_archcpu(env));
4215 }
4216 
4217 POWERPC_FAMILY(7410)(ObjectClass *oc, void *data)
4218 {
4219     DeviceClass *dc = DEVICE_CLASS(oc);
4220     PowerPCCPUClass *pcc = POWERPC_CPU_CLASS(oc);
4221 
4222     dc->desc = "PowerPC 7410 (aka G4)";
4223     pcc->init_proc = init_proc_7410;
4224     pcc->check_pow = check_pow_hid0;
4225     pcc->insns_flags = PPC_INSNS_BASE | PPC_STRING | PPC_MFTB |
4226                        PPC_FLOAT | PPC_FLOAT_FSEL | PPC_FLOAT_FRES |
4227                        PPC_FLOAT_FSQRT | PPC_FLOAT_FRSQRTE |
4228                        PPC_FLOAT_STFIWX |
4229                        PPC_CACHE | PPC_CACHE_ICBI |
4230                        PPC_CACHE_DCBA | PPC_CACHE_DCBZ |
4231                        PPC_MEM_SYNC | PPC_MEM_EIEIO |
4232                        PPC_MEM_TLBIE | PPC_MEM_TLBSYNC |
4233                        PPC_MEM_TLBIA |
4234                        PPC_SEGMENT | PPC_EXTERN |
4235                        PPC_ALTIVEC;
4236     pcc->msr_mask = (1ull << MSR_VR) |
4237                     (1ull << MSR_POW) |
4238                     (1ull << MSR_ILE) |
4239                     (1ull << MSR_EE) |
4240                     (1ull << MSR_PR) |
4241                     (1ull << MSR_FP) |
4242                     (1ull << MSR_ME) |
4243                     (1ull << MSR_FE0) |
4244                     (1ull << MSR_SE) |
4245                     (1ull << MSR_DE) |
4246                     (1ull << MSR_FE1) |
4247                     (1ull << MSR_EP) |
4248                     (1ull << MSR_IR) |
4249                     (1ull << MSR_DR) |
4250                     (1ull << MSR_PMM) |
4251                     (1ull << MSR_RI) |
4252                     (1ull << MSR_LE);
4253     pcc->mmu_model = POWERPC_MMU_32B;
4254     pcc->excp_model = POWERPC_EXCP_74xx;
4255     pcc->bus_model = PPC_FLAGS_INPUT_6xx;
4256     pcc->bfd_mach = bfd_mach_ppc_7400;
4257     pcc->flags = POWERPC_FLAG_VRE | POWERPC_FLAG_SE |
4258                  POWERPC_FLAG_BE | POWERPC_FLAG_PMM |
4259                  POWERPC_FLAG_BUS_CLK;
4260 }
4261 
4262 static void init_proc_7440(CPUPPCState *env)
4263 {
4264     register_non_embedded_sprs(env);
4265     register_sdr1_sprs(env);
4266     register_74xx_sprs(env);
4267     vscr_init(env, 0x00010000);
4268 
4269     spr_register(env, SPR_UBAMR, "UBAMR",
4270                  &spr_read_ureg, SPR_NOACCESS,
4271                  &spr_read_ureg, SPR_NOACCESS,
4272                  0x00000000);
4273     /* LDSTCR */
4274     spr_register(env, SPR_LDSTCR, "LDSTCR",
4275                  SPR_NOACCESS, SPR_NOACCESS,
4276                  &spr_read_generic, &spr_write_generic,
4277                  0x00000000);
4278     /* ICTRL */
4279     spr_register(env, SPR_ICTRL, "ICTRL",
4280                  SPR_NOACCESS, SPR_NOACCESS,
4281                  &spr_read_generic, &spr_write_generic,
4282                  0x00000000);
4283     /* MSSSR0 */
4284     spr_register(env, SPR_MSSSR0, "MSSSR0",
4285                  SPR_NOACCESS, SPR_NOACCESS,
4286                  &spr_read_generic, &spr_write_generic,
4287                  0x00000000);
4288     /* PMC */
4289     spr_register(env, SPR_7XX_PMC5, "PMC5",
4290                  SPR_NOACCESS, SPR_NOACCESS,
4291                  &spr_read_generic, &spr_write_generic,
4292                  0x00000000);
4293 
4294     spr_register(env, SPR_7XX_UPMC5, "UPMC5",
4295                  &spr_read_ureg, SPR_NOACCESS,
4296                  &spr_read_ureg, SPR_NOACCESS,
4297                  0x00000000);
4298 
4299     spr_register(env, SPR_7XX_PMC6, "PMC6",
4300                  SPR_NOACCESS, SPR_NOACCESS,
4301                  &spr_read_generic, &spr_write_generic,
4302                  0x00000000);
4303 
4304     spr_register(env, SPR_7XX_UPMC6, "UPMC6",
4305                  &spr_read_ureg, SPR_NOACCESS,
4306                  &spr_read_ureg, SPR_NOACCESS,
4307                  0x00000000);
4308     /* Memory management */
4309     register_low_BATs(env);
4310     init_excp_7450(env);
4311     env->dcache_line_size = 32;
4312     env->icache_line_size = 32;
4313     /* Allocate hardware IRQ controller */
4314     ppc6xx_irq_init(env_archcpu(env));
4315 }
4316 
4317 POWERPC_FAMILY(7440)(ObjectClass *oc, void *data)
4318 {
4319     DeviceClass *dc = DEVICE_CLASS(oc);
4320     PowerPCCPUClass *pcc = POWERPC_CPU_CLASS(oc);
4321 
4322     dc->desc = "PowerPC 7440 (aka G4)";
4323     pcc->init_proc = init_proc_7440;
4324     pcc->check_pow = check_pow_hid0_74xx;
4325     pcc->insns_flags = PPC_INSNS_BASE | PPC_STRING | PPC_MFTB |
4326                        PPC_FLOAT | PPC_FLOAT_FSEL | PPC_FLOAT_FRES |
4327                        PPC_FLOAT_FSQRT | PPC_FLOAT_FRSQRTE |
4328                        PPC_FLOAT_STFIWX |
4329                        PPC_CACHE | PPC_CACHE_ICBI |
4330                        PPC_CACHE_DCBA | PPC_CACHE_DCBZ |
4331                        PPC_MEM_SYNC | PPC_MEM_EIEIO |
4332                        PPC_MEM_TLBIE | PPC_MEM_TLBSYNC |
4333                        PPC_MEM_TLBIA |
4334                        PPC_SEGMENT | PPC_EXTERN |
4335                        PPC_ALTIVEC;
4336     pcc->msr_mask = (1ull << MSR_VR) |
4337                     (1ull << MSR_POW) |
4338                     (1ull << MSR_ILE) |
4339                     (1ull << MSR_EE) |
4340                     (1ull << MSR_PR) |
4341                     (1ull << MSR_FP) |
4342                     (1ull << MSR_ME) |
4343                     (1ull << MSR_FE0) |
4344                     (1ull << MSR_SE) |
4345                     (1ull << MSR_DE) |
4346                     (1ull << MSR_FE1) |
4347                     (1ull << MSR_EP) |
4348                     (1ull << MSR_IR) |
4349                     (1ull << MSR_DR) |
4350                     (1ull << MSR_PMM) |
4351                     (1ull << MSR_RI) |
4352                     (1ull << MSR_LE);
4353     pcc->mmu_model = POWERPC_MMU_32B;
4354     pcc->excp_model = POWERPC_EXCP_74xx;
4355     pcc->bus_model = PPC_FLAGS_INPUT_6xx;
4356     pcc->bfd_mach = bfd_mach_ppc_7400;
4357     pcc->flags = POWERPC_FLAG_VRE | POWERPC_FLAG_SE |
4358                  POWERPC_FLAG_BE | POWERPC_FLAG_PMM |
4359                  POWERPC_FLAG_BUS_CLK;
4360 }
4361 
4362 static void init_proc_7450(CPUPPCState *env)
4363 {
4364     register_non_embedded_sprs(env);
4365     register_sdr1_sprs(env);
4366     register_74xx_sprs(env);
4367     vscr_init(env, 0x00010000);
4368     /* Level 3 cache control */
4369     register_l3_ctrl(env);
4370     /* L3ITCR1 */
4371     spr_register(env, SPR_L3ITCR1, "L3ITCR1",
4372                  SPR_NOACCESS, SPR_NOACCESS,
4373                  &spr_read_generic, &spr_write_generic,
4374                  0x00000000);
4375     /* L3ITCR2 */
4376     spr_register(env, SPR_L3ITCR2, "L3ITCR2",
4377                  SPR_NOACCESS, SPR_NOACCESS,
4378                  &spr_read_generic, &spr_write_generic,
4379                  0x00000000);
4380     /* L3ITCR3 */
4381     spr_register(env, SPR_L3ITCR3, "L3ITCR3",
4382                  SPR_NOACCESS, SPR_NOACCESS,
4383                  &spr_read_generic, &spr_write_generic,
4384                  0x00000000);
4385     /* L3OHCR */
4386     spr_register(env, SPR_L3OHCR, "L3OHCR",
4387                  SPR_NOACCESS, SPR_NOACCESS,
4388                  &spr_read_generic, &spr_write_generic,
4389                  0x00000000);
4390 
4391     spr_register(env, SPR_UBAMR, "UBAMR",
4392                  &spr_read_ureg, SPR_NOACCESS,
4393                  &spr_read_ureg, SPR_NOACCESS,
4394                  0x00000000);
4395     /* LDSTCR */
4396     spr_register(env, SPR_LDSTCR, "LDSTCR",
4397                  SPR_NOACCESS, SPR_NOACCESS,
4398                  &spr_read_generic, &spr_write_generic,
4399                  0x00000000);
4400     /* ICTRL */
4401     spr_register(env, SPR_ICTRL, "ICTRL",
4402                  SPR_NOACCESS, SPR_NOACCESS,
4403                  &spr_read_generic, &spr_write_generic,
4404                  0x00000000);
4405     /* MSSSR0 */
4406     spr_register(env, SPR_MSSSR0, "MSSSR0",
4407                  SPR_NOACCESS, SPR_NOACCESS,
4408                  &spr_read_generic, &spr_write_generic,
4409                  0x00000000);
4410     /* PMC */
4411     spr_register(env, SPR_7XX_PMC5, "PMC5",
4412                  SPR_NOACCESS, SPR_NOACCESS,
4413                  &spr_read_generic, &spr_write_generic,
4414                  0x00000000);
4415 
4416     spr_register(env, SPR_7XX_UPMC5, "UPMC5",
4417                  &spr_read_ureg, SPR_NOACCESS,
4418                  &spr_read_ureg, SPR_NOACCESS,
4419                  0x00000000);
4420 
4421     spr_register(env, SPR_7XX_PMC6, "PMC6",
4422                  SPR_NOACCESS, SPR_NOACCESS,
4423                  &spr_read_generic, &spr_write_generic,
4424                  0x00000000);
4425 
4426     spr_register(env, SPR_7XX_UPMC6, "UPMC6",
4427                  &spr_read_ureg, SPR_NOACCESS,
4428                  &spr_read_ureg, SPR_NOACCESS,
4429                  0x00000000);
4430     /* Memory management */
4431     register_low_BATs(env);
4432     init_excp_7450(env);
4433     env->dcache_line_size = 32;
4434     env->icache_line_size = 32;
4435     /* Allocate hardware IRQ controller */
4436     ppc6xx_irq_init(env_archcpu(env));
4437 }
4438 
4439 POWERPC_FAMILY(7450)(ObjectClass *oc, void *data)
4440 {
4441     DeviceClass *dc = DEVICE_CLASS(oc);
4442     PowerPCCPUClass *pcc = POWERPC_CPU_CLASS(oc);
4443 
4444     dc->desc = "PowerPC 7450 (aka G4)";
4445     pcc->init_proc = init_proc_7450;
4446     pcc->check_pow = check_pow_hid0_74xx;
4447     pcc->insns_flags = PPC_INSNS_BASE | PPC_STRING | PPC_MFTB |
4448                        PPC_FLOAT | PPC_FLOAT_FSEL | PPC_FLOAT_FRES |
4449                        PPC_FLOAT_FSQRT | PPC_FLOAT_FRSQRTE |
4450                        PPC_FLOAT_STFIWX |
4451                        PPC_CACHE | PPC_CACHE_ICBI |
4452                        PPC_CACHE_DCBA | PPC_CACHE_DCBZ |
4453                        PPC_MEM_SYNC | PPC_MEM_EIEIO |
4454                        PPC_MEM_TLBIE | PPC_MEM_TLBSYNC |
4455                        PPC_MEM_TLBIA |
4456                        PPC_SEGMENT | PPC_EXTERN |
4457                        PPC_ALTIVEC;
4458     pcc->msr_mask = (1ull << MSR_VR) |
4459                     (1ull << MSR_POW) |
4460                     (1ull << MSR_ILE) |
4461                     (1ull << MSR_EE) |
4462                     (1ull << MSR_PR) |
4463                     (1ull << MSR_FP) |
4464                     (1ull << MSR_ME) |
4465                     (1ull << MSR_FE0) |
4466                     (1ull << MSR_SE) |
4467                     (1ull << MSR_DE) |
4468                     (1ull << MSR_FE1) |
4469                     (1ull << MSR_EP) |
4470                     (1ull << MSR_IR) |
4471                     (1ull << MSR_DR) |
4472                     (1ull << MSR_PMM) |
4473                     (1ull << MSR_RI) |
4474                     (1ull << MSR_LE);
4475     pcc->mmu_model = POWERPC_MMU_32B;
4476     pcc->excp_model = POWERPC_EXCP_74xx;
4477     pcc->bus_model = PPC_FLAGS_INPUT_6xx;
4478     pcc->bfd_mach = bfd_mach_ppc_7400;
4479     pcc->flags = POWERPC_FLAG_VRE | POWERPC_FLAG_SE |
4480                  POWERPC_FLAG_BE | POWERPC_FLAG_PMM |
4481                  POWERPC_FLAG_BUS_CLK;
4482 }
4483 
4484 static void init_proc_7445(CPUPPCState *env)
4485 {
4486     register_non_embedded_sprs(env);
4487     register_sdr1_sprs(env);
4488     register_74xx_sprs(env);
4489     vscr_init(env, 0x00010000);
4490     /* LDSTCR */
4491     spr_register(env, SPR_LDSTCR, "LDSTCR",
4492                  SPR_NOACCESS, SPR_NOACCESS,
4493                  &spr_read_generic, &spr_write_generic,
4494                  0x00000000);
4495     /* ICTRL */
4496     spr_register(env, SPR_ICTRL, "ICTRL",
4497                  SPR_NOACCESS, SPR_NOACCESS,
4498                  &spr_read_generic, &spr_write_generic,
4499                  0x00000000);
4500     /* MSSSR0 */
4501     spr_register(env, SPR_MSSSR0, "MSSSR0",
4502                  SPR_NOACCESS, SPR_NOACCESS,
4503                  &spr_read_generic, &spr_write_generic,
4504                  0x00000000);
4505     /* PMC */
4506     spr_register(env, SPR_7XX_PMC5, "PMC5",
4507                  SPR_NOACCESS, SPR_NOACCESS,
4508                  &spr_read_generic, &spr_write_generic,
4509                  0x00000000);
4510 
4511     spr_register(env, SPR_7XX_UPMC5, "UPMC5",
4512                  &spr_read_ureg, SPR_NOACCESS,
4513                  &spr_read_ureg, SPR_NOACCESS,
4514                  0x00000000);
4515 
4516     spr_register(env, SPR_7XX_PMC6, "PMC6",
4517                  SPR_NOACCESS, SPR_NOACCESS,
4518                  &spr_read_generic, &spr_write_generic,
4519                  0x00000000);
4520 
4521     spr_register(env, SPR_7XX_UPMC6, "UPMC6",
4522                  &spr_read_ureg, SPR_NOACCESS,
4523                  &spr_read_ureg, SPR_NOACCESS,
4524                  0x00000000);
4525     /* SPRGs */
4526     spr_register(env, SPR_SPRG4, "SPRG4",
4527                  SPR_NOACCESS, SPR_NOACCESS,
4528                  &spr_read_generic, &spr_write_generic,
4529                  0x00000000);
4530     spr_register(env, SPR_USPRG4, "USPRG4",
4531                  &spr_read_ureg, SPR_NOACCESS,
4532                  &spr_read_ureg, SPR_NOACCESS,
4533                  0x00000000);
4534     spr_register(env, SPR_SPRG5, "SPRG5",
4535                  SPR_NOACCESS, SPR_NOACCESS,
4536                  &spr_read_generic, &spr_write_generic,
4537                  0x00000000);
4538     spr_register(env, SPR_USPRG5, "USPRG5",
4539                  &spr_read_ureg, SPR_NOACCESS,
4540                  &spr_read_ureg, SPR_NOACCESS,
4541                  0x00000000);
4542     spr_register(env, SPR_SPRG6, "SPRG6",
4543                  SPR_NOACCESS, SPR_NOACCESS,
4544                  &spr_read_generic, &spr_write_generic,
4545                  0x00000000);
4546     spr_register(env, SPR_USPRG6, "USPRG6",
4547                  &spr_read_ureg, SPR_NOACCESS,
4548                  &spr_read_ureg, SPR_NOACCESS,
4549                  0x00000000);
4550     spr_register(env, SPR_SPRG7, "SPRG7",
4551                  SPR_NOACCESS, SPR_NOACCESS,
4552                  &spr_read_generic, &spr_write_generic,
4553                  0x00000000);
4554     spr_register(env, SPR_USPRG7, "USPRG7",
4555                  &spr_read_ureg, SPR_NOACCESS,
4556                  &spr_read_ureg, SPR_NOACCESS,
4557                  0x00000000);
4558     /* Memory management */
4559     register_low_BATs(env);
4560     register_high_BATs(env);
4561     init_excp_7450(env);
4562     env->dcache_line_size = 32;
4563     env->icache_line_size = 32;
4564     /* Allocate hardware IRQ controller */
4565     ppc6xx_irq_init(env_archcpu(env));
4566 }
4567 
4568 POWERPC_FAMILY(7445)(ObjectClass *oc, void *data)
4569 {
4570     DeviceClass *dc = DEVICE_CLASS(oc);
4571     PowerPCCPUClass *pcc = POWERPC_CPU_CLASS(oc);
4572 
4573     dc->desc = "PowerPC 7445 (aka G4)";
4574     pcc->init_proc = init_proc_7445;
4575     pcc->check_pow = check_pow_hid0_74xx;
4576     pcc->insns_flags = PPC_INSNS_BASE | PPC_STRING | PPC_MFTB |
4577                        PPC_FLOAT | PPC_FLOAT_FSEL | PPC_FLOAT_FRES |
4578                        PPC_FLOAT_FSQRT | PPC_FLOAT_FRSQRTE |
4579                        PPC_FLOAT_STFIWX |
4580                        PPC_CACHE | PPC_CACHE_ICBI |
4581                        PPC_CACHE_DCBA | PPC_CACHE_DCBZ |
4582                        PPC_MEM_SYNC | PPC_MEM_EIEIO |
4583                        PPC_MEM_TLBIE | PPC_MEM_TLBSYNC |
4584                        PPC_MEM_TLBIA |
4585                        PPC_SEGMENT | PPC_EXTERN |
4586                        PPC_ALTIVEC;
4587     pcc->msr_mask = (1ull << MSR_VR) |
4588                     (1ull << MSR_POW) |
4589                     (1ull << MSR_ILE) |
4590                     (1ull << MSR_EE) |
4591                     (1ull << MSR_PR) |
4592                     (1ull << MSR_FP) |
4593                     (1ull << MSR_ME) |
4594                     (1ull << MSR_FE0) |
4595                     (1ull << MSR_SE) |
4596                     (1ull << MSR_DE) |
4597                     (1ull << MSR_FE1) |
4598                     (1ull << MSR_EP) |
4599                     (1ull << MSR_IR) |
4600                     (1ull << MSR_DR) |
4601                     (1ull << MSR_PMM) |
4602                     (1ull << MSR_RI) |
4603                     (1ull << MSR_LE);
4604     pcc->mmu_model = POWERPC_MMU_32B;
4605     pcc->excp_model = POWERPC_EXCP_74xx;
4606     pcc->bus_model = PPC_FLAGS_INPUT_6xx;
4607     pcc->bfd_mach = bfd_mach_ppc_7400;
4608     pcc->flags = POWERPC_FLAG_VRE | POWERPC_FLAG_SE |
4609                  POWERPC_FLAG_BE | POWERPC_FLAG_PMM |
4610                  POWERPC_FLAG_BUS_CLK;
4611 }
4612 
4613 static void init_proc_7455(CPUPPCState *env)
4614 {
4615     register_non_embedded_sprs(env);
4616     register_sdr1_sprs(env);
4617     register_74xx_sprs(env);
4618     vscr_init(env, 0x00010000);
4619     /* Level 3 cache control */
4620     register_l3_ctrl(env);
4621     /* LDSTCR */
4622     spr_register(env, SPR_LDSTCR, "LDSTCR",
4623                  SPR_NOACCESS, SPR_NOACCESS,
4624                  &spr_read_generic, &spr_write_generic,
4625                  0x00000000);
4626     /* ICTRL */
4627     spr_register(env, SPR_ICTRL, "ICTRL",
4628                  SPR_NOACCESS, SPR_NOACCESS,
4629                  &spr_read_generic, &spr_write_generic,
4630                  0x00000000);
4631     /* MSSSR0 */
4632     spr_register(env, SPR_MSSSR0, "MSSSR0",
4633                  SPR_NOACCESS, SPR_NOACCESS,
4634                  &spr_read_generic, &spr_write_generic,
4635                  0x00000000);
4636     /* PMC */
4637     spr_register(env, SPR_7XX_PMC5, "PMC5",
4638                  SPR_NOACCESS, SPR_NOACCESS,
4639                  &spr_read_generic, &spr_write_generic,
4640                  0x00000000);
4641 
4642     spr_register(env, SPR_7XX_UPMC5, "UPMC5",
4643                  &spr_read_ureg, SPR_NOACCESS,
4644                  &spr_read_ureg, SPR_NOACCESS,
4645                  0x00000000);
4646 
4647     spr_register(env, SPR_7XX_PMC6, "PMC6",
4648                  SPR_NOACCESS, SPR_NOACCESS,
4649                  &spr_read_generic, &spr_write_generic,
4650                  0x00000000);
4651 
4652     spr_register(env, SPR_7XX_UPMC6, "UPMC6",
4653                  &spr_read_ureg, SPR_NOACCESS,
4654                  &spr_read_ureg, SPR_NOACCESS,
4655                  0x00000000);
4656     /* SPRGs */
4657     spr_register(env, SPR_SPRG4, "SPRG4",
4658                  SPR_NOACCESS, SPR_NOACCESS,
4659                  &spr_read_generic, &spr_write_generic,
4660                  0x00000000);
4661     spr_register(env, SPR_USPRG4, "USPRG4",
4662                  &spr_read_ureg, SPR_NOACCESS,
4663                  &spr_read_ureg, SPR_NOACCESS,
4664                  0x00000000);
4665     spr_register(env, SPR_SPRG5, "SPRG5",
4666                  SPR_NOACCESS, SPR_NOACCESS,
4667                  &spr_read_generic, &spr_write_generic,
4668                  0x00000000);
4669     spr_register(env, SPR_USPRG5, "USPRG5",
4670                  &spr_read_ureg, SPR_NOACCESS,
4671                  &spr_read_ureg, SPR_NOACCESS,
4672                  0x00000000);
4673     spr_register(env, SPR_SPRG6, "SPRG6",
4674                  SPR_NOACCESS, SPR_NOACCESS,
4675                  &spr_read_generic, &spr_write_generic,
4676                  0x00000000);
4677     spr_register(env, SPR_USPRG6, "USPRG6",
4678                  &spr_read_ureg, SPR_NOACCESS,
4679                  &spr_read_ureg, SPR_NOACCESS,
4680                  0x00000000);
4681     spr_register(env, SPR_SPRG7, "SPRG7",
4682                  SPR_NOACCESS, SPR_NOACCESS,
4683                  &spr_read_generic, &spr_write_generic,
4684                  0x00000000);
4685     spr_register(env, SPR_USPRG7, "USPRG7",
4686                  &spr_read_ureg, SPR_NOACCESS,
4687                  &spr_read_ureg, SPR_NOACCESS,
4688                  0x00000000);
4689     /* Memory management */
4690     register_low_BATs(env);
4691     register_high_BATs(env);
4692     init_excp_7450(env);
4693     env->dcache_line_size = 32;
4694     env->icache_line_size = 32;
4695     /* Allocate hardware IRQ controller */
4696     ppc6xx_irq_init(env_archcpu(env));
4697 }
4698 
4699 POWERPC_FAMILY(7455)(ObjectClass *oc, void *data)
4700 {
4701     DeviceClass *dc = DEVICE_CLASS(oc);
4702     PowerPCCPUClass *pcc = POWERPC_CPU_CLASS(oc);
4703 
4704     dc->desc = "PowerPC 7455 (aka G4)";
4705     pcc->init_proc = init_proc_7455;
4706     pcc->check_pow = check_pow_hid0_74xx;
4707     pcc->insns_flags = PPC_INSNS_BASE | PPC_STRING | PPC_MFTB |
4708                        PPC_FLOAT | PPC_FLOAT_FSEL | PPC_FLOAT_FRES |
4709                        PPC_FLOAT_FSQRT | PPC_FLOAT_FRSQRTE |
4710                        PPC_FLOAT_STFIWX |
4711                        PPC_CACHE | PPC_CACHE_ICBI |
4712                        PPC_CACHE_DCBA | PPC_CACHE_DCBZ |
4713                        PPC_MEM_SYNC | PPC_MEM_EIEIO |
4714                        PPC_MEM_TLBIE | PPC_MEM_TLBSYNC |
4715                        PPC_MEM_TLBIA |
4716                        PPC_SEGMENT | PPC_EXTERN |
4717                        PPC_ALTIVEC;
4718     pcc->msr_mask = (1ull << MSR_VR) |
4719                     (1ull << MSR_POW) |
4720                     (1ull << MSR_ILE) |
4721                     (1ull << MSR_EE) |
4722                     (1ull << MSR_PR) |
4723                     (1ull << MSR_FP) |
4724                     (1ull << MSR_ME) |
4725                     (1ull << MSR_FE0) |
4726                     (1ull << MSR_SE) |
4727                     (1ull << MSR_DE) |
4728                     (1ull << MSR_FE1) |
4729                     (1ull << MSR_EP) |
4730                     (1ull << MSR_IR) |
4731                     (1ull << MSR_DR) |
4732                     (1ull << MSR_PMM) |
4733                     (1ull << MSR_RI) |
4734                     (1ull << MSR_LE);
4735     pcc->mmu_model = POWERPC_MMU_32B;
4736     pcc->excp_model = POWERPC_EXCP_74xx;
4737     pcc->bus_model = PPC_FLAGS_INPUT_6xx;
4738     pcc->bfd_mach = bfd_mach_ppc_7400;
4739     pcc->flags = POWERPC_FLAG_VRE | POWERPC_FLAG_SE |
4740                  POWERPC_FLAG_BE | POWERPC_FLAG_PMM |
4741                  POWERPC_FLAG_BUS_CLK;
4742 }
4743 
4744 static void init_proc_7457(CPUPPCState *env)
4745 {
4746     register_non_embedded_sprs(env);
4747     register_sdr1_sprs(env);
4748     register_74xx_sprs(env);
4749     vscr_init(env, 0x00010000);
4750     /* Level 3 cache control */
4751     register_l3_ctrl(env);
4752     /* L3ITCR1 */
4753     spr_register(env, SPR_L3ITCR1, "L3ITCR1",
4754                  SPR_NOACCESS, SPR_NOACCESS,
4755                  &spr_read_generic, &spr_write_generic,
4756                  0x00000000);
4757     /* L3ITCR2 */
4758     spr_register(env, SPR_L3ITCR2, "L3ITCR2",
4759                  SPR_NOACCESS, SPR_NOACCESS,
4760                  &spr_read_generic, &spr_write_generic,
4761                  0x00000000);
4762     /* L3ITCR3 */
4763     spr_register(env, SPR_L3ITCR3, "L3ITCR3",
4764                  SPR_NOACCESS, SPR_NOACCESS,
4765                  &spr_read_generic, &spr_write_generic,
4766                  0x00000000);
4767     /* L3OHCR */
4768     spr_register(env, SPR_L3OHCR, "L3OHCR",
4769                  SPR_NOACCESS, SPR_NOACCESS,
4770                  &spr_read_generic, &spr_write_generic,
4771                  0x00000000);
4772     /* LDSTCR */
4773     spr_register(env, SPR_LDSTCR, "LDSTCR",
4774                  SPR_NOACCESS, SPR_NOACCESS,
4775                  &spr_read_generic, &spr_write_generic,
4776                  0x00000000);
4777     /* ICTRL */
4778     spr_register(env, SPR_ICTRL, "ICTRL",
4779                  SPR_NOACCESS, SPR_NOACCESS,
4780                  &spr_read_generic, &spr_write_generic,
4781                  0x00000000);
4782     /* MSSSR0 */
4783     spr_register(env, SPR_MSSSR0, "MSSSR0",
4784                  SPR_NOACCESS, SPR_NOACCESS,
4785                  &spr_read_generic, &spr_write_generic,
4786                  0x00000000);
4787     /* PMC */
4788     spr_register(env, SPR_7XX_PMC5, "PMC5",
4789                  SPR_NOACCESS, SPR_NOACCESS,
4790                  &spr_read_generic, &spr_write_generic,
4791                  0x00000000);
4792 
4793     spr_register(env, SPR_7XX_UPMC5, "UPMC5",
4794                  &spr_read_ureg, SPR_NOACCESS,
4795                  &spr_read_ureg, SPR_NOACCESS,
4796                  0x00000000);
4797 
4798     spr_register(env, SPR_7XX_PMC6, "PMC6",
4799                  SPR_NOACCESS, SPR_NOACCESS,
4800                  &spr_read_generic, &spr_write_generic,
4801                  0x00000000);
4802 
4803     spr_register(env, SPR_7XX_UPMC6, "UPMC6",
4804                  &spr_read_ureg, SPR_NOACCESS,
4805                  &spr_read_ureg, SPR_NOACCESS,
4806                  0x00000000);
4807     /* SPRGs */
4808     spr_register(env, SPR_SPRG4, "SPRG4",
4809                  SPR_NOACCESS, SPR_NOACCESS,
4810                  &spr_read_generic, &spr_write_generic,
4811                  0x00000000);
4812     spr_register(env, SPR_USPRG4, "USPRG4",
4813                  &spr_read_ureg, SPR_NOACCESS,
4814                  &spr_read_ureg, SPR_NOACCESS,
4815                  0x00000000);
4816     spr_register(env, SPR_SPRG5, "SPRG5",
4817                  SPR_NOACCESS, SPR_NOACCESS,
4818                  &spr_read_generic, &spr_write_generic,
4819                  0x00000000);
4820     spr_register(env, SPR_USPRG5, "USPRG5",
4821                  &spr_read_ureg, SPR_NOACCESS,
4822                  &spr_read_ureg, SPR_NOACCESS,
4823                  0x00000000);
4824     spr_register(env, SPR_SPRG6, "SPRG6",
4825                  SPR_NOACCESS, SPR_NOACCESS,
4826                  &spr_read_generic, &spr_write_generic,
4827                  0x00000000);
4828     spr_register(env, SPR_USPRG6, "USPRG6",
4829                  &spr_read_ureg, SPR_NOACCESS,
4830                  &spr_read_ureg, SPR_NOACCESS,
4831                  0x00000000);
4832     spr_register(env, SPR_SPRG7, "SPRG7",
4833                  SPR_NOACCESS, SPR_NOACCESS,
4834                  &spr_read_generic, &spr_write_generic,
4835                  0x00000000);
4836     spr_register(env, SPR_USPRG7, "USPRG7",
4837                  &spr_read_ureg, SPR_NOACCESS,
4838                  &spr_read_ureg, SPR_NOACCESS,
4839                  0x00000000);
4840     /* Memory management */
4841     register_low_BATs(env);
4842     register_high_BATs(env);
4843     init_excp_7450(env);
4844     env->dcache_line_size = 32;
4845     env->icache_line_size = 32;
4846     /* Allocate hardware IRQ controller */
4847     ppc6xx_irq_init(env_archcpu(env));
4848 }
4849 
4850 POWERPC_FAMILY(7457)(ObjectClass *oc, void *data)
4851 {
4852     DeviceClass *dc = DEVICE_CLASS(oc);
4853     PowerPCCPUClass *pcc = POWERPC_CPU_CLASS(oc);
4854 
4855     dc->desc = "PowerPC 7457 (aka G4)";
4856     pcc->init_proc = init_proc_7457;
4857     pcc->check_pow = check_pow_hid0_74xx;
4858     pcc->insns_flags = PPC_INSNS_BASE | PPC_STRING | PPC_MFTB |
4859                        PPC_FLOAT | PPC_FLOAT_FSEL | PPC_FLOAT_FRES |
4860                        PPC_FLOAT_FSQRT | PPC_FLOAT_FRSQRTE |
4861                        PPC_FLOAT_STFIWX |
4862                        PPC_CACHE | PPC_CACHE_ICBI |
4863                        PPC_CACHE_DCBA | PPC_CACHE_DCBZ |
4864                        PPC_MEM_SYNC | PPC_MEM_EIEIO |
4865                        PPC_MEM_TLBIE | PPC_MEM_TLBSYNC |
4866                        PPC_MEM_TLBIA |
4867                        PPC_SEGMENT | PPC_EXTERN |
4868                        PPC_ALTIVEC;
4869     pcc->msr_mask = (1ull << MSR_VR) |
4870                     (1ull << MSR_POW) |
4871                     (1ull << MSR_ILE) |
4872                     (1ull << MSR_EE) |
4873                     (1ull << MSR_PR) |
4874                     (1ull << MSR_FP) |
4875                     (1ull << MSR_ME) |
4876                     (1ull << MSR_FE0) |
4877                     (1ull << MSR_SE) |
4878                     (1ull << MSR_DE) |
4879                     (1ull << MSR_FE1) |
4880                     (1ull << MSR_EP) |
4881                     (1ull << MSR_IR) |
4882                     (1ull << MSR_DR) |
4883                     (1ull << MSR_PMM) |
4884                     (1ull << MSR_RI) |
4885                     (1ull << MSR_LE);
4886     pcc->mmu_model = POWERPC_MMU_32B;
4887     pcc->excp_model = POWERPC_EXCP_74xx;
4888     pcc->bus_model = PPC_FLAGS_INPUT_6xx;
4889     pcc->bfd_mach = bfd_mach_ppc_7400;
4890     pcc->flags = POWERPC_FLAG_VRE | POWERPC_FLAG_SE |
4891                  POWERPC_FLAG_BE | POWERPC_FLAG_PMM |
4892                  POWERPC_FLAG_BUS_CLK;
4893 }
4894 
4895 static void init_proc_e600(CPUPPCState *env)
4896 {
4897     register_non_embedded_sprs(env);
4898     register_sdr1_sprs(env);
4899     register_74xx_sprs(env);
4900     vscr_init(env, 0x00010000);
4901 
4902     spr_register(env, SPR_UBAMR, "UBAMR",
4903                  &spr_read_ureg, SPR_NOACCESS,
4904                  &spr_read_ureg, SPR_NOACCESS,
4905                  0x00000000);
4906 
4907     spr_register(env, SPR_LDSTCR, "LDSTCR",
4908                  SPR_NOACCESS, SPR_NOACCESS,
4909                  &spr_read_generic, &spr_write_generic,
4910                  0x00000000);
4911 
4912     spr_register(env, SPR_ICTRL, "ICTRL",
4913                  SPR_NOACCESS, SPR_NOACCESS,
4914                  &spr_read_generic, &spr_write_generic,
4915                  0x00000000);
4916 
4917     spr_register(env, SPR_MSSSR0, "MSSSR0",
4918                  SPR_NOACCESS, SPR_NOACCESS,
4919                  &spr_read_generic, &spr_write_generic,
4920                  0x00000000);
4921 
4922     spr_register(env, SPR_7XX_PMC5, "PMC5",
4923                  SPR_NOACCESS, SPR_NOACCESS,
4924                  &spr_read_generic, &spr_write_generic,
4925                  0x00000000);
4926 
4927     spr_register(env, SPR_7XX_UPMC5, "UPMC5",
4928                  &spr_read_ureg, SPR_NOACCESS,
4929                  &spr_read_ureg, SPR_NOACCESS,
4930                  0x00000000);
4931 
4932     spr_register(env, SPR_7XX_PMC6, "PMC6",
4933                  SPR_NOACCESS, SPR_NOACCESS,
4934                  &spr_read_generic, &spr_write_generic,
4935                  0x00000000);
4936 
4937     spr_register(env, SPR_7XX_UPMC6, "UPMC6",
4938                  &spr_read_ureg, SPR_NOACCESS,
4939                  &spr_read_ureg, SPR_NOACCESS,
4940                  0x00000000);
4941     /* SPRGs */
4942     spr_register(env, SPR_SPRG4, "SPRG4",
4943                  SPR_NOACCESS, SPR_NOACCESS,
4944                  &spr_read_generic, &spr_write_generic,
4945                  0x00000000);
4946     spr_register(env, SPR_USPRG4, "USPRG4",
4947                  &spr_read_ureg, SPR_NOACCESS,
4948                  &spr_read_ureg, SPR_NOACCESS,
4949                  0x00000000);
4950     spr_register(env, SPR_SPRG5, "SPRG5",
4951                  SPR_NOACCESS, SPR_NOACCESS,
4952                  &spr_read_generic, &spr_write_generic,
4953                  0x00000000);
4954     spr_register(env, SPR_USPRG5, "USPRG5",
4955                  &spr_read_ureg, SPR_NOACCESS,
4956                  &spr_read_ureg, SPR_NOACCESS,
4957                  0x00000000);
4958     spr_register(env, SPR_SPRG6, "SPRG6",
4959                  SPR_NOACCESS, SPR_NOACCESS,
4960                  &spr_read_generic, &spr_write_generic,
4961                  0x00000000);
4962     spr_register(env, SPR_USPRG6, "USPRG6",
4963                  &spr_read_ureg, SPR_NOACCESS,
4964                  &spr_read_ureg, SPR_NOACCESS,
4965                  0x00000000);
4966     spr_register(env, SPR_SPRG7, "SPRG7",
4967                  SPR_NOACCESS, SPR_NOACCESS,
4968                  &spr_read_generic, &spr_write_generic,
4969                  0x00000000);
4970     spr_register(env, SPR_USPRG7, "USPRG7",
4971                  &spr_read_ureg, SPR_NOACCESS,
4972                  &spr_read_ureg, SPR_NOACCESS,
4973                  0x00000000);
4974     /* Memory management */
4975     register_low_BATs(env);
4976     register_high_BATs(env);
4977     init_excp_7450(env);
4978     env->dcache_line_size = 32;
4979     env->icache_line_size = 32;
4980     /* Allocate hardware IRQ controller */
4981     ppc6xx_irq_init(env_archcpu(env));
4982 }
4983 
4984 POWERPC_FAMILY(e600)(ObjectClass *oc, void *data)
4985 {
4986     DeviceClass *dc = DEVICE_CLASS(oc);
4987     PowerPCCPUClass *pcc = POWERPC_CPU_CLASS(oc);
4988 
4989     dc->desc = "PowerPC e600";
4990     pcc->init_proc = init_proc_e600;
4991     pcc->check_pow = check_pow_hid0_74xx;
4992     pcc->insns_flags = PPC_INSNS_BASE | PPC_STRING | PPC_MFTB |
4993                        PPC_FLOAT | PPC_FLOAT_FSEL | PPC_FLOAT_FRES |
4994                        PPC_FLOAT_FSQRT | PPC_FLOAT_FRSQRTE |
4995                        PPC_FLOAT_STFIWX |
4996                        PPC_CACHE | PPC_CACHE_ICBI |
4997                        PPC_CACHE_DCBA | PPC_CACHE_DCBZ |
4998                        PPC_MEM_SYNC | PPC_MEM_EIEIO |
4999                        PPC_MEM_TLBIE | PPC_MEM_TLBSYNC |
5000                        PPC_MEM_TLBIA |
5001                        PPC_SEGMENT | PPC_EXTERN |
5002                        PPC_ALTIVEC;
5003     pcc->insns_flags2 = PPC_NONE;
5004     pcc->msr_mask = (1ull << MSR_VR) |
5005                     (1ull << MSR_POW) |
5006                     (1ull << MSR_ILE) |
5007                     (1ull << MSR_EE) |
5008                     (1ull << MSR_PR) |
5009                     (1ull << MSR_FP) |
5010                     (1ull << MSR_ME) |
5011                     (1ull << MSR_FE0) |
5012                     (1ull << MSR_SE) |
5013                     (1ull << MSR_DE) |
5014                     (1ull << MSR_FE1) |
5015                     (1ull << MSR_EP) |
5016                     (1ull << MSR_IR) |
5017                     (1ull << MSR_DR) |
5018                     (1ull << MSR_PMM) |
5019                     (1ull << MSR_RI) |
5020                     (1ull << MSR_LE);
5021     pcc->mmu_model = POWERPC_MMU_32B;
5022     pcc->excp_model = POWERPC_EXCP_74xx;
5023     pcc->bus_model = PPC_FLAGS_INPUT_6xx;
5024     pcc->bfd_mach = bfd_mach_ppc_7400;
5025     pcc->flags = POWERPC_FLAG_VRE | POWERPC_FLAG_SE |
5026                  POWERPC_FLAG_BE | POWERPC_FLAG_PMM |
5027                  POWERPC_FLAG_BUS_CLK;
5028 }
5029 
5030 #if defined(TARGET_PPC64)
5031 #if defined(CONFIG_USER_ONLY)
5032 #define POWERPC970_HID5_INIT 0x00000080
5033 #else
5034 #define POWERPC970_HID5_INIT 0x00000000
5035 #endif
5036 
5037 static int check_pow_970(CPUPPCState *env)
5038 {
5039     if (env->spr[SPR_HID0] & (HID0_DEEPNAP | HID0_DOZE | HID0_NAP)) {
5040         return 1;
5041     }
5042 
5043     return 0;
5044 }
5045 
5046 static void register_970_hid_sprs(CPUPPCState *env)
5047 {
5048     /* Hardware implementation registers */
5049     spr_register(env, SPR_HID0, "HID0",
5050                  SPR_NOACCESS, SPR_NOACCESS,
5051                  &spr_read_generic, &spr_write_clear,
5052                  0x60000000);
5053     spr_register(env, SPR_HID1, "HID1",
5054                  SPR_NOACCESS, SPR_NOACCESS,
5055                  &spr_read_generic, &spr_write_generic,
5056                  0x00000000);
5057     spr_register(env, SPR_970_HID5, "HID5",
5058                  SPR_NOACCESS, SPR_NOACCESS,
5059                  &spr_read_generic, &spr_write_generic,
5060                  POWERPC970_HID5_INIT);
5061 }
5062 
5063 static void register_970_hior_sprs(CPUPPCState *env)
5064 {
5065     spr_register(env, SPR_HIOR, "SPR_HIOR",
5066                  SPR_NOACCESS, SPR_NOACCESS,
5067                  &spr_read_hior, &spr_write_hior,
5068                  0x00000000);
5069 }
5070 
5071 static void register_book3s_ctrl_sprs(CPUPPCState *env)
5072 {
5073     spr_register(env, SPR_CTRL, "SPR_CTRL",
5074                  SPR_NOACCESS, SPR_NOACCESS,
5075                  SPR_NOACCESS, &spr_write_CTRL,
5076                  0x00000000);
5077     spr_register(env, SPR_UCTRL, "SPR_UCTRL",
5078                  &spr_read_ureg, SPR_NOACCESS,
5079                  &spr_read_ureg, SPR_NOACCESS,
5080                  0x00000000);
5081 }
5082 
5083 static void register_book3s_altivec_sprs(CPUPPCState *env)
5084 {
5085     if (!(env->insns_flags & PPC_ALTIVEC)) {
5086         return;
5087     }
5088 
5089     spr_register_kvm(env, SPR_VRSAVE, "VRSAVE",
5090                      &spr_read_generic, &spr_write_generic32,
5091                      &spr_read_generic, &spr_write_generic32,
5092                      KVM_REG_PPC_VRSAVE, 0x00000000);
5093 
5094 }
5095 
5096 static void register_book3s_dbg_sprs(CPUPPCState *env)
5097 {
5098     /*
5099      * TODO: different specs define different scopes for these,
5100      * will have to address this:
5101      * 970: super/write and super/read
5102      * powerisa 2.03..2.04: hypv/write and super/read.
5103      * powerisa 2.05 and newer: hypv/write and hypv/read.
5104      */
5105     spr_register_kvm(env, SPR_DABR, "DABR",
5106                      SPR_NOACCESS, SPR_NOACCESS,
5107                      &spr_read_generic, &spr_write_generic,
5108                      KVM_REG_PPC_DABR, 0x00000000);
5109     spr_register_kvm(env, SPR_DABRX, "DABRX",
5110                      SPR_NOACCESS, SPR_NOACCESS,
5111                      &spr_read_generic, &spr_write_generic,
5112                      KVM_REG_PPC_DABRX, 0x00000000);
5113 }
5114 
5115 static void register_book3s_207_dbg_sprs(CPUPPCState *env)
5116 {
5117     spr_register_kvm_hv(env, SPR_DAWR0, "DAWR0",
5118                         SPR_NOACCESS, SPR_NOACCESS,
5119                         SPR_NOACCESS, SPR_NOACCESS,
5120                         &spr_read_generic, &spr_write_generic,
5121                         KVM_REG_PPC_DAWR, 0x00000000);
5122     spr_register_kvm_hv(env, SPR_DAWRX0, "DAWRX0",
5123                         SPR_NOACCESS, SPR_NOACCESS,
5124                         SPR_NOACCESS, SPR_NOACCESS,
5125                         &spr_read_generic, &spr_write_generic32,
5126                         KVM_REG_PPC_DAWRX, 0x00000000);
5127     spr_register_kvm_hv(env, SPR_CIABR, "CIABR",
5128                         SPR_NOACCESS, SPR_NOACCESS,
5129                         SPR_NOACCESS, SPR_NOACCESS,
5130                         &spr_read_generic, &spr_write_generic,
5131                         KVM_REG_PPC_CIABR, 0x00000000);
5132 }
5133 
5134 static void register_970_dbg_sprs(CPUPPCState *env)
5135 {
5136     /* Breakpoints */
5137     spr_register(env, SPR_IABR, "IABR",
5138                  SPR_NOACCESS, SPR_NOACCESS,
5139                  &spr_read_generic, &spr_write_generic,
5140                  0x00000000);
5141 }
5142 
5143 static void register_book3s_pmu_sup_sprs(CPUPPCState *env)
5144 {
5145     spr_register_kvm(env, SPR_POWER_MMCR0, "MMCR0",
5146                      SPR_NOACCESS, SPR_NOACCESS,
5147                      &spr_read_generic, &spr_write_MMCR0,
5148                      KVM_REG_PPC_MMCR0, 0x80000000);
5149     spr_register_kvm(env, SPR_POWER_MMCR1, "MMCR1",
5150                      SPR_NOACCESS, SPR_NOACCESS,
5151                      &spr_read_generic, &spr_write_MMCR1,
5152                      KVM_REG_PPC_MMCR1, 0x00000000);
5153     spr_register_kvm(env, SPR_POWER_MMCRA, "MMCRA",
5154                      SPR_NOACCESS, SPR_NOACCESS,
5155                      &spr_read_generic, &spr_write_generic,
5156                      KVM_REG_PPC_MMCRA, 0x00000000);
5157     spr_register_kvm(env, SPR_POWER_PMC1, "PMC1",
5158                      SPR_NOACCESS, SPR_NOACCESS,
5159                      &spr_read_PMC, &spr_write_PMC,
5160                      KVM_REG_PPC_PMC1, 0x00000000);
5161     spr_register_kvm(env, SPR_POWER_PMC2, "PMC2",
5162                      SPR_NOACCESS, SPR_NOACCESS,
5163                      &spr_read_PMC, &spr_write_PMC,
5164                      KVM_REG_PPC_PMC2, 0x00000000);
5165     spr_register_kvm(env, SPR_POWER_PMC3, "PMC3",
5166                      SPR_NOACCESS, SPR_NOACCESS,
5167                      &spr_read_PMC, &spr_write_PMC,
5168                      KVM_REG_PPC_PMC3, 0x00000000);
5169     spr_register_kvm(env, SPR_POWER_PMC4, "PMC4",
5170                      SPR_NOACCESS, SPR_NOACCESS,
5171                      &spr_read_PMC, &spr_write_PMC,
5172                      KVM_REG_PPC_PMC4, 0x00000000);
5173     spr_register_kvm(env, SPR_POWER_PMC5, "PMC5",
5174                      SPR_NOACCESS, SPR_NOACCESS,
5175                      &spr_read_PMC, &spr_write_PMC,
5176                      KVM_REG_PPC_PMC5, 0x00000000);
5177     spr_register_kvm(env, SPR_POWER_PMC6, "PMC6",
5178                      SPR_NOACCESS, SPR_NOACCESS,
5179                      &spr_read_PMC, &spr_write_PMC,
5180                      KVM_REG_PPC_PMC6, 0x00000000);
5181     spr_register_kvm(env, SPR_POWER_SIAR, "SIAR",
5182                      SPR_NOACCESS, SPR_NOACCESS,
5183                      &spr_read_generic, &spr_write_generic,
5184                      KVM_REG_PPC_SIAR, 0x00000000);
5185     spr_register_kvm(env, SPR_POWER_SDAR, "SDAR",
5186                      SPR_NOACCESS, SPR_NOACCESS,
5187                      &spr_read_generic, &spr_write_generic,
5188                      KVM_REG_PPC_SDAR, 0x00000000);
5189 }
5190 
5191 static void register_book3s_pmu_user_sprs(CPUPPCState *env)
5192 {
5193     spr_register(env, SPR_POWER_UMMCR0, "UMMCR0",
5194                  &spr_read_MMCR0_ureg, &spr_write_MMCR0_ureg,
5195                  &spr_read_ureg, &spr_write_ureg,
5196                  0x80000000);
5197     spr_register(env, SPR_POWER_UMMCR1, "UMMCR1",
5198                  &spr_read_ureg, SPR_NOACCESS,
5199                  &spr_read_ureg, &spr_write_ureg,
5200                  0x00000000);
5201     spr_register(env, SPR_POWER_UMMCRA, "UMMCRA",
5202                  &spr_read_ureg, SPR_NOACCESS,
5203                  &spr_read_ureg, &spr_write_ureg,
5204                  0x00000000);
5205     spr_register(env, SPR_POWER_UPMC1, "UPMC1",
5206                  &spr_read_PMC14_ureg, &spr_write_PMC14_ureg,
5207                  &spr_read_ureg, &spr_write_ureg,
5208                  0x00000000);
5209     spr_register(env, SPR_POWER_UPMC2, "UPMC2",
5210                  &spr_read_PMC14_ureg, &spr_write_PMC14_ureg,
5211                  &spr_read_ureg, &spr_write_ureg,
5212                  0x00000000);
5213     spr_register(env, SPR_POWER_UPMC3, "UPMC3",
5214                  &spr_read_PMC14_ureg, &spr_write_PMC14_ureg,
5215                  &spr_read_ureg, &spr_write_ureg,
5216                  0x00000000);
5217     spr_register(env, SPR_POWER_UPMC4, "UPMC4",
5218                  &spr_read_PMC14_ureg, &spr_write_PMC14_ureg,
5219                  &spr_read_ureg, &spr_write_ureg,
5220                  0x00000000);
5221     spr_register(env, SPR_POWER_UPMC5, "UPMC5",
5222                  &spr_read_PMC56_ureg, &spr_write_PMC56_ureg,
5223                  &spr_read_ureg, &spr_write_ureg,
5224                  0x00000000);
5225     spr_register(env, SPR_POWER_UPMC6, "UPMC6",
5226                  &spr_read_PMC56_ureg, &spr_write_PMC56_ureg,
5227                  &spr_read_ureg, &spr_write_ureg,
5228                  0x00000000);
5229     spr_register(env, SPR_POWER_USIAR, "USIAR",
5230                  &spr_read_ureg, SPR_NOACCESS,
5231                  &spr_read_ureg, &spr_write_ureg,
5232                  0x00000000);
5233     spr_register(env, SPR_POWER_USDAR, "USDAR",
5234                  &spr_read_ureg, SPR_NOACCESS,
5235                  &spr_read_ureg, &spr_write_ureg,
5236                  0x00000000);
5237 }
5238 
5239 static void register_970_pmu_sup_sprs(CPUPPCState *env)
5240 {
5241     spr_register_kvm(env, SPR_970_PMC7, "PMC7",
5242                      SPR_NOACCESS, SPR_NOACCESS,
5243                      &spr_read_generic, &spr_write_generic,
5244                      KVM_REG_PPC_PMC7, 0x00000000);
5245     spr_register_kvm(env, SPR_970_PMC8, "PMC8",
5246                      SPR_NOACCESS, SPR_NOACCESS,
5247                      &spr_read_generic, &spr_write_generic,
5248                      KVM_REG_PPC_PMC8, 0x00000000);
5249 }
5250 
5251 static void register_970_pmu_user_sprs(CPUPPCState *env)
5252 {
5253     spr_register(env, SPR_970_UPMC7, "UPMC7",
5254                  &spr_read_ureg, SPR_NOACCESS,
5255                  &spr_read_ureg, &spr_write_ureg,
5256                  0x00000000);
5257     spr_register(env, SPR_970_UPMC8, "UPMC8",
5258                  &spr_read_ureg, SPR_NOACCESS,
5259                  &spr_read_ureg, &spr_write_ureg,
5260                  0x00000000);
5261 }
5262 
5263 static void register_power8_pmu_sup_sprs(CPUPPCState *env)
5264 {
5265     spr_register_kvm(env, SPR_POWER_MMCR2, "MMCR2",
5266                      SPR_NOACCESS, SPR_NOACCESS,
5267                      &spr_read_generic, &spr_write_generic,
5268                      KVM_REG_PPC_MMCR2, 0x00000000);
5269     spr_register_kvm(env, SPR_POWER_MMCRS, "MMCRS",
5270                      SPR_NOACCESS, SPR_NOACCESS,
5271                      &spr_read_generic, &spr_write_generic,
5272                      KVM_REG_PPC_MMCRS, 0x00000000);
5273     spr_register_kvm(env, SPR_POWER_SIER, "SIER",
5274                      SPR_NOACCESS, SPR_NOACCESS,
5275                      &spr_read_generic, &spr_write_generic,
5276                      KVM_REG_PPC_SIER, 0x00000000);
5277     spr_register_kvm(env, SPR_POWER_SPMC1, "SPMC1",
5278                      SPR_NOACCESS, SPR_NOACCESS,
5279                      &spr_read_generic, &spr_write_generic,
5280                      KVM_REG_PPC_SPMC1, 0x00000000);
5281     spr_register_kvm(env, SPR_POWER_SPMC2, "SPMC2",
5282                      SPR_NOACCESS, SPR_NOACCESS,
5283                      &spr_read_generic, &spr_write_generic,
5284                      KVM_REG_PPC_SPMC2, 0x00000000);
5285     spr_register_kvm(env, SPR_TACR, "TACR",
5286                      SPR_NOACCESS, SPR_NOACCESS,
5287                      &spr_read_generic, &spr_write_generic,
5288                      KVM_REG_PPC_TACR, 0x00000000);
5289     spr_register_kvm(env, SPR_TCSCR, "TCSCR",
5290                      SPR_NOACCESS, SPR_NOACCESS,
5291                      &spr_read_generic, &spr_write_generic,
5292                      KVM_REG_PPC_TCSCR, 0x00000000);
5293     spr_register_kvm(env, SPR_CSIGR, "CSIGR",
5294                      SPR_NOACCESS, SPR_NOACCESS,
5295                      &spr_read_generic, &spr_write_generic,
5296                      KVM_REG_PPC_CSIGR, 0x00000000);
5297 }
5298 
5299 static void register_power8_pmu_user_sprs(CPUPPCState *env)
5300 {
5301     spr_register(env, SPR_POWER_UMMCR2, "UMMCR2",
5302                  &spr_read_MMCR2_ureg, &spr_write_MMCR2_ureg,
5303                  &spr_read_ureg, &spr_write_ureg,
5304                  0x00000000);
5305     spr_register(env, SPR_POWER_USIER, "USIER",
5306                  &spr_read_generic, SPR_NOACCESS,
5307                  &spr_read_generic, &spr_write_generic,
5308                  0x00000000);
5309 }
5310 
5311 static void register_power5p_ear_sprs(CPUPPCState *env)
5312 {
5313     /* External access control */
5314     spr_register(env, SPR_EAR, "EAR",
5315                  SPR_NOACCESS, SPR_NOACCESS,
5316                  &spr_read_generic, &spr_write_generic,
5317                  0x00000000);
5318 }
5319 
5320 static void register_power5p_tb_sprs(CPUPPCState *env)
5321 {
5322     /* TBU40 (High 40 bits of the Timebase register */
5323     spr_register_hv(env, SPR_TBU40, "TBU40",
5324                     SPR_NOACCESS, SPR_NOACCESS,
5325                     SPR_NOACCESS, SPR_NOACCESS,
5326                     SPR_NOACCESS, &spr_write_tbu40,
5327                     0x00000000);
5328 }
5329 
5330 static void register_970_lpar_sprs(CPUPPCState *env)
5331 {
5332 #if !defined(CONFIG_USER_ONLY)
5333     /*
5334      * PPC970: HID4 covers things later controlled by the LPCR and
5335      * RMOR in later CPUs, but with a different encoding.  We only
5336      * support the 970 in "Apple mode" which has all hypervisor
5337      * facilities disabled by strapping, so we can basically just
5338      * ignore it
5339      */
5340     spr_register(env, SPR_970_HID4, "HID4",
5341                  SPR_NOACCESS, SPR_NOACCESS,
5342                  &spr_read_generic, &spr_write_generic,
5343                  0x00000000);
5344 #endif
5345 }
5346 
5347 static void register_power5p_lpar_sprs(CPUPPCState *env)
5348 {
5349 #if !defined(CONFIG_USER_ONLY)
5350     /* Logical partitionning */
5351     spr_register_kvm_hv(env, SPR_LPCR, "LPCR",
5352                         SPR_NOACCESS, SPR_NOACCESS,
5353                         SPR_NOACCESS, SPR_NOACCESS,
5354                         &spr_read_generic, &spr_write_lpcr,
5355                         KVM_REG_PPC_LPCR, LPCR_LPES0 | LPCR_LPES1);
5356     spr_register_hv(env, SPR_HDEC, "HDEC",
5357                     SPR_NOACCESS, SPR_NOACCESS,
5358                     SPR_NOACCESS, SPR_NOACCESS,
5359                     &spr_read_hdecr, &spr_write_hdecr, 0);
5360 #endif
5361 }
5362 
5363 static void register_book3s_ids_sprs(CPUPPCState *env)
5364 {
5365     /* FIXME: Will need to deal with thread vs core only SPRs */
5366 
5367     /* Processor identification */
5368     spr_register_hv(env, SPR_PIR, "PIR",
5369                  SPR_NOACCESS, SPR_NOACCESS,
5370                  &spr_read_generic, SPR_NOACCESS,
5371                  &spr_read_generic, NULL,
5372                  0x00000000);
5373     spr_register_hv(env, SPR_LPIDR, "LPIDR",
5374                  SPR_NOACCESS, SPR_NOACCESS,
5375                  SPR_NOACCESS, SPR_NOACCESS,
5376                  &spr_read_generic, &spr_write_lpidr,
5377                  0x00000000);
5378     spr_register_hv(env, SPR_HFSCR, "HFSCR",
5379                  SPR_NOACCESS, SPR_NOACCESS,
5380                  SPR_NOACCESS, SPR_NOACCESS,
5381                  &spr_read_generic, &spr_write_generic,
5382                  0x00000000);
5383     spr_register_hv(env, SPR_MMCRC, "MMCRC",
5384                  SPR_NOACCESS, SPR_NOACCESS,
5385                  SPR_NOACCESS, SPR_NOACCESS,
5386                  &spr_read_generic, &spr_write_generic32,
5387                  0x00000000);
5388     spr_register_hv(env, SPR_MMCRH, "MMCRH",
5389                  SPR_NOACCESS, SPR_NOACCESS,
5390                  SPR_NOACCESS, SPR_NOACCESS,
5391                  &spr_read_generic, &spr_write_generic,
5392                  0x00000000);
5393     spr_register_hv(env, SPR_HSPRG0, "HSPRG0",
5394                  SPR_NOACCESS, SPR_NOACCESS,
5395                  SPR_NOACCESS, SPR_NOACCESS,
5396                  &spr_read_generic, &spr_write_generic,
5397                  0x00000000);
5398     spr_register_hv(env, SPR_HSPRG1, "HSPRG1",
5399                  SPR_NOACCESS, SPR_NOACCESS,
5400                  SPR_NOACCESS, SPR_NOACCESS,
5401                  &spr_read_generic, &spr_write_generic,
5402                  0x00000000);
5403     spr_register_hv(env, SPR_HSRR0, "HSRR0",
5404                  SPR_NOACCESS, SPR_NOACCESS,
5405                  SPR_NOACCESS, SPR_NOACCESS,
5406                  &spr_read_generic, &spr_write_generic,
5407                  0x00000000);
5408     spr_register_hv(env, SPR_HSRR1, "HSRR1",
5409                  SPR_NOACCESS, SPR_NOACCESS,
5410                  SPR_NOACCESS, SPR_NOACCESS,
5411                  &spr_read_generic, &spr_write_generic,
5412                  0x00000000);
5413     spr_register_hv(env, SPR_HDAR, "HDAR",
5414                  SPR_NOACCESS, SPR_NOACCESS,
5415                  SPR_NOACCESS, SPR_NOACCESS,
5416                  &spr_read_generic, &spr_write_generic,
5417                  0x00000000);
5418     spr_register_hv(env, SPR_HDSISR, "HDSISR",
5419                  SPR_NOACCESS, SPR_NOACCESS,
5420                  SPR_NOACCESS, SPR_NOACCESS,
5421                  &spr_read_generic, &spr_write_generic32,
5422                  0x00000000);
5423     spr_register_hv(env, SPR_HRMOR, "HRMOR",
5424                  SPR_NOACCESS, SPR_NOACCESS,
5425                  SPR_NOACCESS, SPR_NOACCESS,
5426                  &spr_read_generic, &spr_write_generic,
5427                  0x00000000);
5428 }
5429 
5430 static void register_rmor_sprs(CPUPPCState *env)
5431 {
5432     spr_register_hv(env, SPR_RMOR, "RMOR",
5433                  SPR_NOACCESS, SPR_NOACCESS,
5434                  SPR_NOACCESS, SPR_NOACCESS,
5435                  &spr_read_generic, &spr_write_generic,
5436                  0x00000000);
5437 }
5438 
5439 static void register_power8_ids_sprs(CPUPPCState *env)
5440 {
5441     /* Thread identification */
5442     spr_register(env, SPR_TIR, "TIR",
5443                  SPR_NOACCESS, SPR_NOACCESS,
5444                  &spr_read_generic, SPR_NOACCESS,
5445                  0x00000000);
5446 }
5447 
5448 static void register_book3s_purr_sprs(CPUPPCState *env)
5449 {
5450 #if !defined(CONFIG_USER_ONLY)
5451     /* PURR & SPURR: Hack - treat these as aliases for the TB for now */
5452     spr_register_kvm_hv(env, SPR_PURR,   "PURR",
5453                         &spr_read_purr, SPR_NOACCESS,
5454                         &spr_read_purr, SPR_NOACCESS,
5455                         &spr_read_purr, &spr_write_purr,
5456                         KVM_REG_PPC_PURR, 0x00000000);
5457     spr_register_kvm_hv(env, SPR_SPURR,   "SPURR",
5458                         &spr_read_purr, SPR_NOACCESS,
5459                         &spr_read_purr, SPR_NOACCESS,
5460                         &spr_read_purr, &spr_write_purr,
5461                         KVM_REG_PPC_SPURR, 0x00000000);
5462 #endif
5463 }
5464 
5465 static void register_power6_dbg_sprs(CPUPPCState *env)
5466 {
5467 #if !defined(CONFIG_USER_ONLY)
5468     spr_register(env, SPR_CFAR, "SPR_CFAR",
5469                  SPR_NOACCESS, SPR_NOACCESS,
5470                  &spr_read_cfar, &spr_write_cfar,
5471                  0x00000000);
5472 #endif
5473 }
5474 
5475 static void register_power5p_common_sprs(CPUPPCState *env)
5476 {
5477     spr_register_kvm(env, SPR_PPR, "PPR",
5478                      &spr_read_generic, &spr_write_generic,
5479                      &spr_read_generic, &spr_write_generic,
5480                      KVM_REG_PPC_PPR, 0x00000000);
5481 }
5482 
5483 static void register_power6_common_sprs(CPUPPCState *env)
5484 {
5485 #if !defined(CONFIG_USER_ONLY)
5486     spr_register_kvm(env, SPR_DSCR, "SPR_DSCR",
5487                      SPR_NOACCESS, SPR_NOACCESS,
5488                      &spr_read_generic, &spr_write_generic,
5489                      KVM_REG_PPC_DSCR, 0x00000000);
5490 #endif
5491     /*
5492      * Register PCR to report POWERPC_EXCP_PRIV_REG instead of
5493      * POWERPC_EXCP_INVAL_SPR in userspace. Permit hypervisor access.
5494      */
5495     spr_register_hv(env, SPR_PCR, "PCR",
5496                  SPR_NOACCESS, SPR_NOACCESS,
5497                  SPR_NOACCESS, SPR_NOACCESS,
5498                  &spr_read_generic, &spr_write_pcr,
5499                  0x00000000);
5500 }
5501 
5502 static void register_HEIR32_spr(CPUPPCState *env)
5503 {
5504     spr_register_hv(env, SPR_HEIR, "HEIR",
5505                  SPR_NOACCESS, SPR_NOACCESS,
5506                  SPR_NOACCESS, SPR_NOACCESS,
5507                  &spr_read_generic, &spr_write_generic32,
5508                  0x00000000);
5509 }
5510 
5511 static void register_HEIR64_spr(CPUPPCState *env)
5512 {
5513     spr_register_hv(env, SPR_HEIR, "HEIR",
5514                  SPR_NOACCESS, SPR_NOACCESS,
5515                  SPR_NOACCESS, SPR_NOACCESS,
5516                  &spr_read_generic, &spr_write_generic,
5517                  0x00000000);
5518 }
5519 
5520 static void register_power8_tce_address_control_sprs(CPUPPCState *env)
5521 {
5522     spr_register_kvm(env, SPR_TAR, "TAR",
5523                      &spr_read_tar, &spr_write_tar,
5524                      &spr_read_generic, &spr_write_generic,
5525                      KVM_REG_PPC_TAR, 0x00000000);
5526 }
5527 
5528 static void register_power8_tm_sprs(CPUPPCState *env)
5529 {
5530     spr_register_kvm(env, SPR_TFHAR, "TFHAR",
5531                      &spr_read_tm, &spr_write_tm,
5532                      &spr_read_tm, &spr_write_tm,
5533                      KVM_REG_PPC_TFHAR, 0x00000000);
5534     spr_register_kvm(env, SPR_TFIAR, "TFIAR",
5535                      &spr_read_tm, &spr_write_tm,
5536                      &spr_read_tm, &spr_write_tm,
5537                      KVM_REG_PPC_TFIAR, 0x00000000);
5538     spr_register_kvm(env, SPR_TEXASR, "TEXASR",
5539                      &spr_read_tm, &spr_write_tm,
5540                      &spr_read_tm, &spr_write_tm,
5541                      KVM_REG_PPC_TEXASR, 0x00000000);
5542     spr_register(env, SPR_TEXASRU, "TEXASRU",
5543                  &spr_read_tm_upper32, &spr_write_tm_upper32,
5544                  &spr_read_tm_upper32, &spr_write_tm_upper32,
5545                  0x00000000);
5546 }
5547 
5548 static void register_power8_ebb_sprs(CPUPPCState *env)
5549 {
5550     spr_register(env, SPR_BESCRS, "BESCRS",
5551                  &spr_read_ebb, &spr_write_ebb,
5552                  &spr_read_generic, &spr_write_generic,
5553                  0x00000000);
5554     spr_register(env, SPR_BESCRSU, "BESCRSU",
5555                  &spr_read_ebb_upper32, &spr_write_ebb_upper32,
5556                  &spr_read_prev_upper32, &spr_write_prev_upper32,
5557                  0x00000000);
5558     spr_register(env, SPR_BESCRR, "BESCRR",
5559                  &spr_read_ebb, &spr_write_ebb,
5560                  &spr_read_generic, &spr_write_generic,
5561                  0x00000000);
5562     spr_register(env, SPR_BESCRRU, "BESCRRU",
5563                  &spr_read_ebb_upper32, &spr_write_ebb_upper32,
5564                  &spr_read_prev_upper32, &spr_write_prev_upper32,
5565                  0x00000000);
5566     spr_register_kvm(env, SPR_EBBHR, "EBBHR",
5567                      &spr_read_ebb, &spr_write_ebb,
5568                      &spr_read_generic, &spr_write_generic,
5569                      KVM_REG_PPC_EBBHR, 0x00000000);
5570     spr_register_kvm(env, SPR_EBBRR, "EBBRR",
5571                      &spr_read_ebb, &spr_write_ebb,
5572                      &spr_read_generic, &spr_write_generic,
5573                      KVM_REG_PPC_EBBRR, 0x00000000);
5574     spr_register_kvm(env, SPR_BESCR, "BESCR",
5575                      &spr_read_ebb, &spr_write_ebb,
5576                      &spr_read_generic, &spr_write_generic,
5577                      KVM_REG_PPC_BESCR, 0x00000000);
5578 }
5579 
5580 /* Virtual Time Base */
5581 static void register_vtb_sprs(CPUPPCState *env)
5582 {
5583     spr_register_kvm_hv(env, SPR_VTB, "VTB",
5584                         SPR_NOACCESS, SPR_NOACCESS,
5585                         &spr_read_vtb, SPR_NOACCESS,
5586                         &spr_read_vtb, &spr_write_vtb,
5587                         KVM_REG_PPC_VTB, 0x00000000);
5588 }
5589 
5590 static void register_power8_fscr_sprs(CPUPPCState *env)
5591 {
5592 #if defined(CONFIG_USER_ONLY)
5593     target_ulong initval = 1ULL << FSCR_TAR;
5594 #else
5595     target_ulong initval = 0;
5596 #endif
5597     spr_register_kvm(env, SPR_FSCR, "FSCR",
5598                      SPR_NOACCESS, SPR_NOACCESS,
5599                      &spr_read_generic, &spr_write_generic,
5600                      KVM_REG_PPC_FSCR, initval);
5601 }
5602 
5603 static void register_power8_pspb_sprs(CPUPPCState *env)
5604 {
5605     spr_register_kvm(env, SPR_PSPB, "PSPB",
5606                      SPR_NOACCESS, SPR_NOACCESS,
5607                      &spr_read_generic, &spr_write_generic32,
5608                      KVM_REG_PPC_PSPB, 0);
5609 }
5610 
5611 static void register_power8_dpdes_sprs(CPUPPCState *env)
5612 {
5613 #if !defined(CONFIG_USER_ONLY)
5614     /* Directed Privileged Door-bell Exception State, used for IPI */
5615     spr_register_kvm_hv(env, SPR_DPDES, "DPDES",
5616                         SPR_NOACCESS, SPR_NOACCESS,
5617                         &spr_read_dpdes, SPR_NOACCESS,
5618                         &spr_read_dpdes, &spr_write_dpdes,
5619                         KVM_REG_PPC_DPDES, 0x00000000);
5620 #endif
5621 }
5622 
5623 static void register_power8_ic_sprs(CPUPPCState *env)
5624 {
5625 #if !defined(CONFIG_USER_ONLY)
5626     spr_register_hv(env, SPR_IC, "IC",
5627                     SPR_NOACCESS, SPR_NOACCESS,
5628                     &spr_read_generic, SPR_NOACCESS,
5629                     &spr_read_generic, &spr_write_generic,
5630                     0);
5631 #endif
5632 }
5633 
5634 /* SPRs specific to IBM POWER CPUs */
5635 static void register_power_common_book4_sprs(CPUPPCState *env)
5636 {
5637 #if !defined(CONFIG_USER_ONLY)
5638     spr_register_hv(env, SPR_HID0, "HID0",
5639                  SPR_NOACCESS, SPR_NOACCESS,
5640                  SPR_NOACCESS, SPR_NOACCESS,
5641                  &spr_read_generic, &spr_core_write_generic,
5642                  0x00000000);
5643     spr_register_hv(env, SPR_TSCR, "TSCR",
5644                  SPR_NOACCESS, SPR_NOACCESS,
5645                  SPR_NOACCESS, SPR_NOACCESS,
5646                  &spr_read_generic, &spr_write_generic32,
5647                  0x00000000);
5648     spr_register_hv(env, SPR_HMER, "HMER",
5649                  SPR_NOACCESS, SPR_NOACCESS,
5650                  SPR_NOACCESS, SPR_NOACCESS,
5651                  &spr_read_generic, &spr_write_hmer,
5652                  0x00000000);
5653     spr_register_hv(env, SPR_HMEER, "HMEER",
5654                  SPR_NOACCESS, SPR_NOACCESS,
5655                  SPR_NOACCESS, SPR_NOACCESS,
5656                  &spr_read_generic, &spr_write_generic,
5657                  0x00000000);
5658     spr_register_hv(env, SPR_TFMR, "TFMR",
5659                  SPR_NOACCESS, SPR_NOACCESS,
5660                  SPR_NOACCESS, SPR_NOACCESS,
5661                  &spr_read_tfmr, &spr_write_tfmr,
5662                  0x00000000);
5663 #endif
5664 }
5665 
5666 static void register_power9_book4_sprs(CPUPPCState *env)
5667 {
5668     /* Add a number of P9 book4 registers */
5669     register_power_common_book4_sprs(env);
5670 #if !defined(CONFIG_USER_ONLY)
5671     spr_register_kvm(env, SPR_WORT, "WORT",
5672                      SPR_NOACCESS, SPR_NOACCESS,
5673                      &spr_read_generic, &spr_write_generic,
5674                      KVM_REG_PPC_WORT, 0);
5675 #endif
5676 }
5677 
5678 static void register_power8_book4_sprs(CPUPPCState *env)
5679 {
5680     /* Add a number of P8 book4 registers */
5681     register_power_common_book4_sprs(env);
5682 #if !defined(CONFIG_USER_ONLY)
5683     spr_register_kvm(env, SPR_ACOP, "ACOP",
5684                      SPR_NOACCESS, SPR_NOACCESS,
5685                      &spr_read_generic, &spr_write_generic,
5686                      KVM_REG_PPC_ACOP, 0);
5687     /* PID is only in BookE in ISA v2.07 */
5688     spr_register_kvm(env, SPR_BOOKS_PID, "PID",
5689                      SPR_NOACCESS, SPR_NOACCESS,
5690                      &spr_read_generic, &spr_write_pidr,
5691                      KVM_REG_PPC_PID, 0);
5692     spr_register_kvm(env, SPR_WORT, "WORT",
5693                      SPR_NOACCESS, SPR_NOACCESS,
5694                      &spr_read_generic, &spr_write_generic,
5695                      KVM_REG_PPC_WORT, 0);
5696 #endif
5697 }
5698 
5699 static void register_power7_book4_sprs(CPUPPCState *env)
5700 {
5701     /* Add a number of P7 book4 registers */
5702 #if !defined(CONFIG_USER_ONLY)
5703     register_power_common_book4_sprs(env);
5704     spr_register_kvm(env, SPR_ACOP, "ACOP",
5705                      SPR_NOACCESS, SPR_NOACCESS,
5706                      &spr_read_generic, &spr_write_generic,
5707                      KVM_REG_PPC_ACOP, 0);
5708     /* PID is only in BookE in ISA v2.06 */
5709     spr_register_kvm(env, SPR_BOOKS_PID, "PID",
5710                      SPR_NOACCESS, SPR_NOACCESS,
5711                      &spr_read_generic, &spr_write_generic32,
5712                      KVM_REG_PPC_PID, 0);
5713 #endif
5714 }
5715 
5716 static void register_power8_rpr_sprs(CPUPPCState *env)
5717 {
5718 #if !defined(CONFIG_USER_ONLY)
5719     spr_register_hv(env, SPR_RPR, "RPR",
5720                     SPR_NOACCESS, SPR_NOACCESS,
5721                     SPR_NOACCESS, SPR_NOACCESS,
5722                     &spr_read_generic, &spr_write_generic,
5723                     0x00000103070F1F3F);
5724 #endif
5725 }
5726 
5727 static void register_power9_mmu_sprs(CPUPPCState *env)
5728 {
5729 #if !defined(CONFIG_USER_ONLY)
5730     /* Partition Table Control */
5731     spr_register_kvm_hv(env, SPR_PTCR, "PTCR",
5732                         SPR_NOACCESS, SPR_NOACCESS,
5733                         SPR_NOACCESS, SPR_NOACCESS,
5734                         &spr_read_generic, &spr_write_ptcr,
5735                         KVM_REG_PPC_PTCR, 0x00000000);
5736     /* Address Segment Descriptor Register */
5737     spr_register_hv(env, SPR_ASDR, "ASDR",
5738                     SPR_NOACCESS, SPR_NOACCESS,
5739                     SPR_NOACCESS, SPR_NOACCESS,
5740                     &spr_read_generic, &spr_write_generic,
5741                     0x0000000000000000);
5742     /* PID is part of the BookS ISA from v3.0 */
5743     spr_register_kvm(env, SPR_BOOKS_PID, "PID",
5744                      SPR_NOACCESS, SPR_NOACCESS,
5745                      &spr_read_generic, &spr_write_pidr,
5746                      KVM_REG_PPC_PID, 0);
5747 #endif
5748 }
5749 
5750 static void register_power10_hash_sprs(CPUPPCState *env)
5751 {
5752     /*
5753      * it's the OS responsability to generate a random value for the registers
5754      * in each process' context. So, initialize it with 0 here.
5755      */
5756     uint64_t hashkeyr_initial_value = 0, hashpkeyr_initial_value = 0;
5757 #if defined(CONFIG_USER_ONLY)
5758     /* in linux-user, setup the hash register with a random value */
5759     GRand *rand = g_rand_new();
5760     hashkeyr_initial_value =
5761         ((uint64_t)g_rand_int(rand) << 32) | (uint64_t)g_rand_int(rand);
5762     hashpkeyr_initial_value =
5763         ((uint64_t)g_rand_int(rand) << 32) | (uint64_t)g_rand_int(rand);
5764     g_rand_free(rand);
5765 #endif
5766     spr_register(env, SPR_HASHKEYR, "HASHKEYR",
5767             SPR_NOACCESS, SPR_NOACCESS,
5768             &spr_read_generic, &spr_write_generic,
5769             hashkeyr_initial_value);
5770     spr_register_hv(env, SPR_HASHPKEYR, "HASHPKEYR",
5771             SPR_NOACCESS, SPR_NOACCESS,
5772             SPR_NOACCESS, SPR_NOACCESS,
5773             &spr_read_generic, &spr_write_generic,
5774             hashpkeyr_initial_value);
5775 }
5776 
5777 static void register_power10_dexcr_sprs(CPUPPCState *env)
5778 {
5779     spr_register(env, SPR_DEXCR, "DEXCR",
5780             SPR_NOACCESS, SPR_NOACCESS,
5781             &spr_read_generic, &spr_write_generic32,
5782             0);
5783 
5784     spr_register(env, SPR_UDEXCR, "DEXCR",
5785             &spr_read_dexcr_ureg, SPR_NOACCESS,
5786             &spr_read_dexcr_ureg, SPR_NOACCESS,
5787             0);
5788 
5789     spr_register_hv(env, SPR_HDEXCR, "HDEXCR",
5790             SPR_NOACCESS, SPR_NOACCESS,
5791             SPR_NOACCESS, SPR_NOACCESS,
5792             &spr_read_generic, &spr_write_generic32,
5793             0);
5794 
5795     spr_register(env, SPR_UHDEXCR, "HDEXCR",
5796             &spr_read_dexcr_ureg, SPR_NOACCESS,
5797             &spr_read_dexcr_ureg, SPR_NOACCESS,
5798             0);
5799 }
5800 
5801 /*
5802  * Initialize PMU counter overflow timers for Power8 and
5803  * newer Power chips when using TCG.
5804  */
5805 static void init_tcg_pmu_power8(CPUPPCState *env)
5806 {
5807     /* Init PMU overflow timers */
5808     if (tcg_enabled()) {
5809         cpu_ppc_pmu_init(env);
5810     }
5811 }
5812 
5813 static void init_proc_book3s_common(CPUPPCState *env)
5814 {
5815     register_non_embedded_sprs(env);
5816     register_book3s_altivec_sprs(env);
5817     register_book3s_pmu_sup_sprs(env);
5818     register_book3s_pmu_user_sprs(env);
5819     register_book3s_ctrl_sprs(env);
5820     /*
5821      * Can't find information on what this should be on reset.  This
5822      * value is the one used by 74xx processors.
5823      */
5824     vscr_init(env, 0x00010000);
5825 
5826     spr_register(env, SPR_USPRG3, "USPRG3",
5827                  &spr_read_ureg, SPR_NOACCESS,
5828                  &spr_read_ureg, SPR_NOACCESS,
5829                  0x00000000);
5830 }
5831 
5832 static void init_proc_970(CPUPPCState *env)
5833 {
5834     /* Common Registers */
5835     init_proc_book3s_common(env);
5836     register_sdr1_sprs(env);
5837     register_book3s_dbg_sprs(env);
5838 
5839     /* 970 Specific Registers */
5840     register_970_hid_sprs(env);
5841     register_970_hior_sprs(env);
5842     register_low_BATs(env);
5843     register_970_pmu_sup_sprs(env);
5844     register_970_pmu_user_sprs(env);
5845     register_970_lpar_sprs(env);
5846     register_970_dbg_sprs(env);
5847 
5848     /* env variables */
5849     env->dcache_line_size = 128;
5850     env->icache_line_size = 128;
5851 
5852     /* Allocate hardware IRQ controller */
5853     init_excp_970(env);
5854     ppc970_irq_init(env_archcpu(env));
5855 }
5856 
5857 POWERPC_FAMILY(970)(ObjectClass *oc, void *data)
5858 {
5859     DeviceClass *dc = DEVICE_CLASS(oc);
5860     PowerPCCPUClass *pcc = POWERPC_CPU_CLASS(oc);
5861 
5862     dc->desc = "PowerPC 970";
5863     pcc->init_proc = init_proc_970;
5864     pcc->check_pow = check_pow_970;
5865     pcc->insns_flags = PPC_INSNS_BASE | PPC_STRING | PPC_MFTB |
5866                        PPC_FLOAT | PPC_FLOAT_FSEL | PPC_FLOAT_FRES |
5867                        PPC_FLOAT_FSQRT | PPC_FLOAT_FRSQRTE |
5868                        PPC_FLOAT_STFIWX |
5869                        PPC_CACHE | PPC_CACHE_ICBI | PPC_CACHE_DCBZ |
5870                        PPC_MEM_SYNC | PPC_MEM_EIEIO |
5871                        PPC_MEM_TLBIE | PPC_MEM_TLBSYNC |
5872                        PPC_64B | PPC_ALTIVEC |
5873                        PPC_SEGMENT_64B | PPC_SLBI;
5874     pcc->insns_flags2 = PPC2_FP_CVT_S64 | PPC2_MEM_LWSYNC;
5875     pcc->msr_mask = (1ull << MSR_SF) |
5876                     (1ull << MSR_VR) |
5877                     (1ull << MSR_POW) |
5878                     (1ull << MSR_EE) |
5879                     (1ull << MSR_PR) |
5880                     (1ull << MSR_FP) |
5881                     (1ull << MSR_ME) |
5882                     (1ull << MSR_FE0) |
5883                     (1ull << MSR_SE) |
5884                     (1ull << MSR_DE) |
5885                     (1ull << MSR_FE1) |
5886                     (1ull << MSR_IR) |
5887                     (1ull << MSR_DR) |
5888                     (1ull << MSR_PMM) |
5889                     (1ull << MSR_RI);
5890     pcc->mmu_model = POWERPC_MMU_64B;
5891 #if !defined(CONFIG_USER_ONLY)
5892     pcc->hash64_opts = &ppc_hash64_opts_basic;
5893 #endif
5894     pcc->excp_model = POWERPC_EXCP_970;
5895     pcc->bus_model = PPC_FLAGS_INPUT_970;
5896     pcc->bfd_mach = bfd_mach_ppc64;
5897     pcc->flags = POWERPC_FLAG_VRE | POWERPC_FLAG_SE |
5898                  POWERPC_FLAG_BE | POWERPC_FLAG_PMM |
5899                  POWERPC_FLAG_BUS_CLK;
5900     pcc->l1_dcache_size = 0x8000;
5901     pcc->l1_icache_size = 0x10000;
5902 }
5903 
5904 static void init_proc_power5plus(CPUPPCState *env)
5905 {
5906     /* Common Registers */
5907     init_proc_book3s_common(env);
5908     register_sdr1_sprs(env);
5909     register_book3s_dbg_sprs(env);
5910 
5911     /* POWER5+ Specific Registers */
5912     register_970_hid_sprs(env);
5913     register_970_hior_sprs(env);
5914     register_low_BATs(env);
5915     register_970_pmu_sup_sprs(env);
5916     register_970_pmu_user_sprs(env);
5917     register_power5p_common_sprs(env);
5918     register_power5p_lpar_sprs(env);
5919     register_power5p_ear_sprs(env);
5920     register_power5p_tb_sprs(env);
5921 
5922     /* env variables */
5923     env->dcache_line_size = 128;
5924     env->icache_line_size = 128;
5925 
5926     /* Allocate hardware IRQ controller */
5927     init_excp_970(env);
5928     ppc970_irq_init(env_archcpu(env));
5929 }
5930 
5931 POWERPC_FAMILY(POWER5P)(ObjectClass *oc, void *data)
5932 {
5933     DeviceClass *dc = DEVICE_CLASS(oc);
5934     PowerPCCPUClass *pcc = POWERPC_CPU_CLASS(oc);
5935 
5936     dc->fw_name = "PowerPC,POWER5";
5937     dc->desc = "POWER5+";
5938     pcc->init_proc = init_proc_power5plus;
5939     pcc->check_pow = check_pow_970;
5940     pcc->insns_flags = PPC_INSNS_BASE | PPC_STRING | PPC_MFTB |
5941                        PPC_FLOAT | PPC_FLOAT_FSEL | PPC_FLOAT_FRES |
5942                        PPC_FLOAT_FSQRT | PPC_FLOAT_FRSQRTE |
5943                        PPC_FLOAT_STFIWX |
5944                        PPC_FLOAT_EXT |
5945                        PPC_CACHE | PPC_CACHE_ICBI | PPC_CACHE_DCBZ |
5946                        PPC_MEM_SYNC | PPC_MEM_EIEIO |
5947                        PPC_MEM_TLBIE | PPC_MEM_TLBSYNC |
5948                        PPC_64B |
5949                        PPC_POPCNTB |
5950                        PPC_SEGMENT_64B | PPC_SLBI;
5951     pcc->insns_flags2 = PPC2_FP_CVT_S64 | PPC2_MEM_LWSYNC;
5952     pcc->msr_mask = (1ull << MSR_SF) |
5953                     (1ull << MSR_VR) |
5954                     (1ull << MSR_POW) |
5955                     (1ull << MSR_EE) |
5956                     (1ull << MSR_PR) |
5957                     (1ull << MSR_FP) |
5958                     (1ull << MSR_ME) |
5959                     (1ull << MSR_FE0) |
5960                     (1ull << MSR_SE) |
5961                     (1ull << MSR_DE) |
5962                     (1ull << MSR_FE1) |
5963                     (1ull << MSR_IR) |
5964                     (1ull << MSR_DR) |
5965                     (1ull << MSR_PMM) |
5966                     (1ull << MSR_RI);
5967     pcc->lpcr_mask = LPCR_RMLS | LPCR_ILE | LPCR_LPES0 | LPCR_LPES1 |
5968         LPCR_RMI | LPCR_HDICE;
5969     pcc->mmu_model = POWERPC_MMU_2_03;
5970 #if !defined(CONFIG_USER_ONLY)
5971     pcc->hash64_opts = &ppc_hash64_opts_basic;
5972     pcc->lrg_decr_bits = 32;
5973 #endif
5974     pcc->excp_model = POWERPC_EXCP_970;
5975     pcc->bus_model = PPC_FLAGS_INPUT_970;
5976     pcc->bfd_mach = bfd_mach_ppc64;
5977     pcc->flags = POWERPC_FLAG_VRE | POWERPC_FLAG_SE |
5978                  POWERPC_FLAG_BE | POWERPC_FLAG_PMM |
5979                  POWERPC_FLAG_BUS_CLK;
5980     pcc->l1_dcache_size = 0x8000;
5981     pcc->l1_icache_size = 0x10000;
5982 }
5983 
5984 static void init_proc_POWER7(CPUPPCState *env)
5985 {
5986     /* Common Registers */
5987     init_proc_book3s_common(env);
5988     register_sdr1_sprs(env);
5989     register_book3s_dbg_sprs(env);
5990 
5991     /* POWER7 Specific Registers */
5992     register_book3s_ids_sprs(env);
5993     register_rmor_sprs(env);
5994     register_amr_sprs(env);
5995     register_book3s_purr_sprs(env);
5996     register_power5p_common_sprs(env);
5997     register_power5p_lpar_sprs(env);
5998     register_power5p_ear_sprs(env);
5999     register_power5p_tb_sprs(env);
6000     register_power6_common_sprs(env);
6001     register_HEIR32_spr(env);
6002     register_power6_dbg_sprs(env);
6003     register_power7_book4_sprs(env);
6004 
6005     /* env variables */
6006     env->dcache_line_size = 128;
6007     env->icache_line_size = 128;
6008 
6009     /* Allocate hardware IRQ controller */
6010     init_excp_POWER7(env);
6011     ppcPOWER7_irq_init(env_archcpu(env));
6012 }
6013 
6014 static bool ppc_pvr_match_power7(PowerPCCPUClass *pcc, uint32_t pvr, bool best)
6015 {
6016     uint32_t base = pvr & CPU_POWERPC_POWER_SERVER_MASK;
6017     uint32_t pcc_base = pcc->pvr & CPU_POWERPC_POWER_SERVER_MASK;
6018 
6019     if (!best) {
6020         if (base == CPU_POWERPC_POWER7_BASE) {
6021             return true;
6022         }
6023         if (base == CPU_POWERPC_POWER7P_BASE) {
6024             return true;
6025         }
6026     }
6027 
6028     if (base != pcc_base) {
6029         return false;
6030     }
6031 
6032     return true;
6033 }
6034 
6035 POWERPC_FAMILY(POWER7)(ObjectClass *oc, void *data)
6036 {
6037     DeviceClass *dc = DEVICE_CLASS(oc);
6038     PowerPCCPUClass *pcc = POWERPC_CPU_CLASS(oc);
6039 
6040     dc->fw_name = "PowerPC,POWER7";
6041     dc->desc = "POWER7";
6042     pcc->pvr_match = ppc_pvr_match_power7;
6043     pcc->pcr_mask = PCR_VEC_DIS | PCR_VSX_DIS | PCR_COMPAT_2_05;
6044     pcc->pcr_supported = PCR_COMPAT_2_06 | PCR_COMPAT_2_05;
6045     pcc->init_proc = init_proc_POWER7;
6046     pcc->check_pow = check_pow_nocheck;
6047     pcc->insns_flags = PPC_INSNS_BASE | PPC_ISEL | PPC_STRING | PPC_MFTB |
6048                        PPC_FLOAT | PPC_FLOAT_FSEL | PPC_FLOAT_FRES |
6049                        PPC_FLOAT_FSQRT | PPC_FLOAT_FRSQRTE |
6050                        PPC_FLOAT_FRSQRTES |
6051                        PPC_FLOAT_STFIWX |
6052                        PPC_FLOAT_EXT |
6053                        PPC_CACHE | PPC_CACHE_ICBI | PPC_CACHE_DCBZ |
6054                        PPC_MEM_SYNC | PPC_MEM_EIEIO |
6055                        PPC_MEM_TLBIE | PPC_MEM_TLBSYNC |
6056                        PPC_64B | PPC_64H | PPC_64BX | PPC_ALTIVEC |
6057                        PPC_SEGMENT_64B | PPC_SLBI |
6058                        PPC_POPCNTB | PPC_POPCNTWD |
6059                        PPC_CILDST;
6060     pcc->insns_flags2 = PPC2_VSX | PPC2_DFP | PPC2_DBRX | PPC2_ISA205 |
6061                         PPC2_PERM_ISA206 | PPC2_DIVE_ISA206 |
6062                         PPC2_ATOMIC_ISA206 | PPC2_FP_CVT_ISA206 |
6063                         PPC2_FP_TST_ISA206 | PPC2_FP_CVT_S64 |
6064                         PPC2_PM_ISA206 | PPC2_MEM_LWSYNC | PPC2_BCDA_ISA206;
6065     pcc->msr_mask = (1ull << MSR_SF) |
6066                     (1ull << MSR_VR) |
6067                     (1ull << MSR_VSX) |
6068                     (1ull << MSR_EE) |
6069                     (1ull << MSR_PR) |
6070                     (1ull << MSR_FP) |
6071                     (1ull << MSR_ME) |
6072                     (1ull << MSR_FE0) |
6073                     (1ull << MSR_SE) |
6074                     (1ull << MSR_DE) |
6075                     (1ull << MSR_FE1) |
6076                     (1ull << MSR_IR) |
6077                     (1ull << MSR_DR) |
6078                     (1ull << MSR_PMM) |
6079                     (1ull << MSR_RI) |
6080                     (1ull << MSR_LE);
6081     pcc->lpcr_mask = LPCR_VPM0 | LPCR_VPM1 | LPCR_ISL | LPCR_DPFD |
6082         LPCR_VRMASD | LPCR_RMLS | LPCR_ILE |
6083         LPCR_P7_PECE0 | LPCR_P7_PECE1 | LPCR_P7_PECE2 |
6084         LPCR_MER | LPCR_TC |
6085         LPCR_LPES0 | LPCR_LPES1 | LPCR_HDICE;
6086     pcc->lpcr_pm = LPCR_P7_PECE0 | LPCR_P7_PECE1 | LPCR_P7_PECE2;
6087     pcc->mmu_model = POWERPC_MMU_2_06;
6088 #if !defined(CONFIG_USER_ONLY)
6089     pcc->hash64_opts = &ppc_hash64_opts_POWER7;
6090     pcc->lrg_decr_bits = 32;
6091 #endif
6092     pcc->excp_model = POWERPC_EXCP_POWER7;
6093     pcc->bus_model = PPC_FLAGS_INPUT_POWER7;
6094     pcc->bfd_mach = bfd_mach_ppc64;
6095     pcc->flags = POWERPC_FLAG_VRE | POWERPC_FLAG_SE |
6096                  POWERPC_FLAG_BE | POWERPC_FLAG_PMM |
6097                  POWERPC_FLAG_BUS_CLK | POWERPC_FLAG_CFAR |
6098                  POWERPC_FLAG_VSX;
6099     pcc->l1_dcache_size = 0x8000;
6100     pcc->l1_icache_size = 0x8000;
6101 }
6102 
6103 static void init_proc_POWER8(CPUPPCState *env)
6104 {
6105     /* Common Registers */
6106     init_proc_book3s_common(env);
6107     register_sdr1_sprs(env);
6108     register_book3s_207_dbg_sprs(env);
6109 
6110     /* Common TCG PMU */
6111     init_tcg_pmu_power8(env);
6112 
6113     /* POWER8 Specific Registers */
6114     register_book3s_ids_sprs(env);
6115     register_rmor_sprs(env);
6116     register_amr_sprs(env);
6117     register_iamr_sprs(env);
6118     register_book3s_purr_sprs(env);
6119     register_power5p_common_sprs(env);
6120     register_power5p_lpar_sprs(env);
6121     register_power5p_ear_sprs(env);
6122     register_power5p_tb_sprs(env);
6123     register_power6_common_sprs(env);
6124     register_HEIR32_spr(env);
6125     register_power6_dbg_sprs(env);
6126     register_power8_tce_address_control_sprs(env);
6127     register_power8_ids_sprs(env);
6128     register_power8_ebb_sprs(env);
6129     register_power8_fscr_sprs(env);
6130     register_power8_pmu_sup_sprs(env);
6131     register_power8_pmu_user_sprs(env);
6132     register_power8_tm_sprs(env);
6133     register_power8_pspb_sprs(env);
6134     register_power8_dpdes_sprs(env);
6135     register_vtb_sprs(env);
6136     register_power8_ic_sprs(env);
6137     register_power8_book4_sprs(env);
6138     register_power8_rpr_sprs(env);
6139 
6140     /* env variables */
6141     env->dcache_line_size = 128;
6142     env->icache_line_size = 128;
6143 
6144     /* Allocate hardware IRQ controller */
6145     init_excp_POWER8(env);
6146     ppcPOWER7_irq_init(env_archcpu(env));
6147 }
6148 
6149 static bool ppc_pvr_match_power8(PowerPCCPUClass *pcc, uint32_t pvr, bool best)
6150 {
6151     uint32_t base = pvr & CPU_POWERPC_POWER_SERVER_MASK;
6152     uint32_t pcc_base = pcc->pvr & CPU_POWERPC_POWER_SERVER_MASK;
6153 
6154     if (!best) {
6155         if (base == CPU_POWERPC_POWER8_BASE) {
6156             return true;
6157         }
6158         if (base == CPU_POWERPC_POWER8E_BASE) {
6159             return true;
6160         }
6161         if (base == CPU_POWERPC_POWER8NVL_BASE) {
6162             return true;
6163         }
6164     }
6165     if (base != pcc_base) {
6166         return false;
6167     }
6168 
6169     return true;
6170 }
6171 
6172 POWERPC_FAMILY(POWER8)(ObjectClass *oc, void *data)
6173 {
6174     DeviceClass *dc = DEVICE_CLASS(oc);
6175     PowerPCCPUClass *pcc = POWERPC_CPU_CLASS(oc);
6176 
6177     dc->fw_name = "PowerPC,POWER8";
6178     dc->desc = "POWER8";
6179     pcc->pvr_match = ppc_pvr_match_power8;
6180     pcc->pcr_mask = PCR_TM_DIS | PCR_COMPAT_2_06 | PCR_COMPAT_2_05;
6181     pcc->pcr_supported = PCR_COMPAT_2_07 | PCR_COMPAT_2_06 | PCR_COMPAT_2_05;
6182     pcc->init_proc = init_proc_POWER8;
6183     pcc->check_pow = check_pow_nocheck;
6184     pcc->insns_flags = PPC_INSNS_BASE | PPC_ISEL | PPC_STRING | PPC_MFTB |
6185                        PPC_FLOAT | PPC_FLOAT_FSEL | PPC_FLOAT_FRES |
6186                        PPC_FLOAT_FSQRT | PPC_FLOAT_FRSQRTE |
6187                        PPC_FLOAT_FRSQRTES |
6188                        PPC_FLOAT_STFIWX |
6189                        PPC_FLOAT_EXT |
6190                        PPC_CACHE | PPC_CACHE_ICBI | PPC_CACHE_DCBZ |
6191                        PPC_MEM_SYNC | PPC_MEM_EIEIO |
6192                        PPC_MEM_TLBIE | PPC_MEM_TLBSYNC |
6193                        PPC_64B | PPC_64H | PPC_64BX | PPC_ALTIVEC |
6194                        PPC_SEGMENT_64B | PPC_SLBI |
6195                        PPC_POPCNTB | PPC_POPCNTWD |
6196                        PPC_CILDST;
6197     pcc->insns_flags2 = PPC2_VSX | PPC2_VSX207 | PPC2_DFP | PPC2_DBRX |
6198                         PPC2_PERM_ISA206 | PPC2_DIVE_ISA206 |
6199                         PPC2_ATOMIC_ISA206 | PPC2_FP_CVT_ISA206 |
6200                         PPC2_FP_TST_ISA206 | PPC2_BCTAR_ISA207 |
6201                         PPC2_LSQ_ISA207 | PPC2_ALTIVEC_207 |
6202                         PPC2_ISA205 | PPC2_ISA207S | PPC2_FP_CVT_S64 |
6203                         PPC2_TM | PPC2_PM_ISA206 | PPC2_MEM_LWSYNC |
6204                         PPC2_BCDA_ISA206;
6205     pcc->msr_mask = (1ull << MSR_SF) |
6206                     (1ull << MSR_HV) |
6207                     (1ull << MSR_TM) |
6208                     (1ull << MSR_VR) |
6209                     (1ull << MSR_VSX) |
6210                     (1ull << MSR_EE) |
6211                     (1ull << MSR_PR) |
6212                     (1ull << MSR_FP) |
6213                     (1ull << MSR_ME) |
6214                     (1ull << MSR_FE0) |
6215                     (1ull << MSR_SE) |
6216                     (1ull << MSR_DE) |
6217                     (1ull << MSR_FE1) |
6218                     (1ull << MSR_IR) |
6219                     (1ull << MSR_DR) |
6220                     (1ull << MSR_PMM) |
6221                     (1ull << MSR_RI) |
6222                     (1ull << MSR_TS0) |
6223                     (1ull << MSR_TS1) |
6224                     (1ull << MSR_LE);
6225     pcc->lpcr_mask = LPCR_VPM0 | LPCR_VPM1 | LPCR_ISL | LPCR_KBV |
6226         LPCR_DPFD | LPCR_VRMASD | LPCR_RMLS | LPCR_ILE |
6227         LPCR_AIL | LPCR_ONL | LPCR_P8_PECE0 | LPCR_P8_PECE1 |
6228         LPCR_P8_PECE2 | LPCR_P8_PECE3 | LPCR_P8_PECE4 |
6229         LPCR_MER | LPCR_TC | LPCR_LPES0 | LPCR_HDICE;
6230     pcc->lpcr_pm = LPCR_P8_PECE0 | LPCR_P8_PECE1 | LPCR_P8_PECE2 |
6231                    LPCR_P8_PECE3 | LPCR_P8_PECE4;
6232     pcc->mmu_model = POWERPC_MMU_2_07;
6233 #if !defined(CONFIG_USER_ONLY)
6234     pcc->hash64_opts = &ppc_hash64_opts_POWER7;
6235     pcc->lrg_decr_bits = 32;
6236     pcc->n_host_threads = 8;
6237 #endif
6238     pcc->excp_model = POWERPC_EXCP_POWER8;
6239     pcc->bus_model = PPC_FLAGS_INPUT_POWER7;
6240     pcc->bfd_mach = bfd_mach_ppc64;
6241     pcc->flags = POWERPC_FLAG_VRE | POWERPC_FLAG_SE |
6242                  POWERPC_FLAG_BE | POWERPC_FLAG_PMM |
6243                  POWERPC_FLAG_BUS_CLK | POWERPC_FLAG_CFAR |
6244                  POWERPC_FLAG_VSX | POWERPC_FLAG_TM;
6245     pcc->l1_dcache_size = 0x8000;
6246     pcc->l1_icache_size = 0x8000;
6247 }
6248 
6249 #ifndef CONFIG_USER_ONLY
6250 /*
6251  * Radix pg sizes and AP encodings for dt node ibm,processor-radix-AP-encodings
6252  * Encoded as array of int_32s in the form:
6253  *  0bxxxyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
6254  *  x -> AP encoding
6255  *  y -> radix mode supported page size (encoded as a shift)
6256  */
6257 static struct ppc_radix_page_info POWER9_radix_page_info = {
6258     .count = 4,
6259     .entries = {
6260         0x0000000c, /*  4K - enc: 0x0 */
6261         0xa0000010, /* 64K - enc: 0x5 */
6262         0x20000015, /*  2M - enc: 0x1 */
6263         0x4000001e  /*  1G - enc: 0x2 */
6264     }
6265 };
6266 #endif /* CONFIG_USER_ONLY */
6267 
6268 static void init_proc_POWER9(CPUPPCState *env)
6269 {
6270     /* Common Registers */
6271     init_proc_book3s_common(env);
6272     register_book3s_207_dbg_sprs(env);
6273 
6274     /* Common TCG PMU */
6275     init_tcg_pmu_power8(env);
6276 
6277     /* POWER8 Specific Registers */
6278     register_book3s_ids_sprs(env);
6279     register_amr_sprs(env);
6280     register_iamr_sprs(env);
6281     register_book3s_purr_sprs(env);
6282     register_power5p_common_sprs(env);
6283     register_power5p_lpar_sprs(env);
6284     register_power5p_ear_sprs(env);
6285     register_power5p_tb_sprs(env);
6286     register_power6_common_sprs(env);
6287     register_HEIR32_spr(env);
6288     register_power6_dbg_sprs(env);
6289     register_power8_tce_address_control_sprs(env);
6290     register_power8_ids_sprs(env);
6291     register_power8_ebb_sprs(env);
6292     register_power8_fscr_sprs(env);
6293     register_power8_pmu_sup_sprs(env);
6294     register_power8_pmu_user_sprs(env);
6295     register_power8_tm_sprs(env);
6296     register_power8_pspb_sprs(env);
6297     register_power8_dpdes_sprs(env);
6298     register_vtb_sprs(env);
6299     register_power8_ic_sprs(env);
6300     register_power9_book4_sprs(env);
6301     register_power8_rpr_sprs(env);
6302     register_power9_mmu_sprs(env);
6303 
6304     /* POWER9 Specific registers */
6305     spr_register_kvm(env, SPR_TIDR, "TIDR", NULL, NULL,
6306                      spr_read_generic, spr_write_generic,
6307                      KVM_REG_PPC_TIDR, 0);
6308 
6309     /* FIXME: Filter fields properly based on privilege level */
6310     spr_register_kvm_hv(env, SPR_PSSCR, "PSSCR", NULL, NULL, NULL, NULL,
6311                         spr_read_generic, spr_write_generic,
6312                         KVM_REG_PPC_PSSCR, 0);
6313 
6314     /* env variables */
6315     env->dcache_line_size = 128;
6316     env->icache_line_size = 128;
6317 
6318     /* Allocate hardware IRQ controller */
6319     init_excp_POWER9(env);
6320     ppcPOWER9_irq_init(env_archcpu(env));
6321 }
6322 
6323 static bool ppc_pvr_match_power9(PowerPCCPUClass *pcc, uint32_t pvr, bool best)
6324 {
6325     uint32_t base = pvr & CPU_POWERPC_POWER_SERVER_MASK;
6326     uint32_t pcc_base = pcc->pvr & CPU_POWERPC_POWER_SERVER_MASK;
6327 
6328     if (!best) {
6329         if (base == CPU_POWERPC_POWER9_BASE) {
6330             return true;
6331         }
6332     }
6333 
6334     if (base != pcc_base) {
6335         return false;
6336     }
6337 
6338     if ((pvr & 0x0f00) != (pcc->pvr & 0x0f00)) {
6339         /* Major DD version does not match */
6340         return false;
6341     }
6342 
6343     if ((pvr & 0x0f00) == 0x100) {
6344         /* DD1.x always matches power9_v1.0 */
6345         return true;
6346     } else if ((pvr & 0x0f00) == 0x200) {
6347         if ((pvr & 0xf) < 2) {
6348             /* DD2.0, DD2.1 match power9_v2.0 */
6349             if ((pcc->pvr & 0xf) == 0) {
6350                 return true;
6351             }
6352         } else {
6353             /* DD2.2, DD2.3 match power9_v2.2 */
6354             if ((pcc->pvr & 0xf) == 2) {
6355                 return true;
6356             }
6357         }
6358     }
6359 
6360     return false;
6361 }
6362 
6363 POWERPC_FAMILY(POWER9)(ObjectClass *oc, void *data)
6364 {
6365     DeviceClass *dc = DEVICE_CLASS(oc);
6366     PowerPCCPUClass *pcc = POWERPC_CPU_CLASS(oc);
6367 
6368     dc->fw_name = "PowerPC,POWER9";
6369     dc->desc = "POWER9";
6370     pcc->pvr_match = ppc_pvr_match_power9;
6371     pcc->pcr_mask = PCR_COMPAT_2_05 | PCR_COMPAT_2_06 | PCR_COMPAT_2_07;
6372     pcc->pcr_supported = PCR_COMPAT_3_00 | PCR_COMPAT_2_07 | PCR_COMPAT_2_06 |
6373                          PCR_COMPAT_2_05;
6374     pcc->init_proc = init_proc_POWER9;
6375     pcc->check_pow = check_pow_nocheck;
6376     pcc->insns_flags = PPC_INSNS_BASE | PPC_ISEL | PPC_STRING | PPC_MFTB |
6377                        PPC_FLOAT | PPC_FLOAT_FSEL | PPC_FLOAT_FRES |
6378                        PPC_FLOAT_FSQRT | PPC_FLOAT_FRSQRTE |
6379                        PPC_FLOAT_FRSQRTES |
6380                        PPC_FLOAT_STFIWX |
6381                        PPC_FLOAT_EXT |
6382                        PPC_CACHE | PPC_CACHE_ICBI | PPC_CACHE_DCBZ |
6383                        PPC_MEM_SYNC | PPC_MEM_EIEIO |
6384                        PPC_MEM_TLBIE | PPC_MEM_TLBSYNC |
6385                        PPC_64B | PPC_64H | PPC_64BX | PPC_ALTIVEC |
6386                        PPC_SEGMENT_64B | PPC_SLBI |
6387                        PPC_POPCNTB | PPC_POPCNTWD |
6388                        PPC_CILDST;
6389     pcc->insns_flags2 = PPC2_VSX | PPC2_VSX207 | PPC2_DFP | PPC2_DBRX |
6390                         PPC2_PERM_ISA206 | PPC2_DIVE_ISA206 |
6391                         PPC2_ATOMIC_ISA206 | PPC2_FP_CVT_ISA206 |
6392                         PPC2_FP_TST_ISA206 | PPC2_BCTAR_ISA207 |
6393                         PPC2_LSQ_ISA207 | PPC2_ALTIVEC_207 |
6394                         PPC2_ISA205 | PPC2_ISA207S | PPC2_FP_CVT_S64 |
6395                         PPC2_TM | PPC2_ISA300 | PPC2_PRCNTL | PPC2_MEM_LWSYNC |
6396                         PPC2_BCDA_ISA206;
6397     pcc->msr_mask = (1ull << MSR_SF) |
6398                     (1ull << MSR_HV) |
6399                     (1ull << MSR_TM) |
6400                     (1ull << MSR_VR) |
6401                     (1ull << MSR_VSX) |
6402                     (1ull << MSR_EE) |
6403                     (1ull << MSR_PR) |
6404                     (1ull << MSR_FP) |
6405                     (1ull << MSR_ME) |
6406                     (1ull << MSR_FE0) |
6407                     (1ull << MSR_SE) |
6408                     (1ull << MSR_DE) |
6409                     (1ull << MSR_FE1) |
6410                     (1ull << MSR_IR) |
6411                     (1ull << MSR_DR) |
6412                     (1ull << MSR_PMM) |
6413                     (1ull << MSR_RI) |
6414                     (1ull << MSR_LE);
6415     pcc->lpcr_mask = LPCR_VPM1 | LPCR_ISL | LPCR_KBV | LPCR_DPFD |
6416         (LPCR_PECE_U_MASK & LPCR_HVEE) | LPCR_ILE | LPCR_AIL |
6417         LPCR_UPRT | LPCR_EVIRT | LPCR_ONL | LPCR_HR | LPCR_LD |
6418         (LPCR_PECE_L_MASK & (LPCR_PDEE | LPCR_HDEE | LPCR_EEE |
6419                              LPCR_DEE | LPCR_OEE))
6420         | LPCR_MER | LPCR_GTSE | LPCR_TC |
6421         LPCR_HEIC | LPCR_LPES0 | LPCR_HVICE | LPCR_HDICE;
6422     pcc->lpcr_pm = LPCR_PDEE | LPCR_HDEE | LPCR_EEE | LPCR_DEE | LPCR_OEE;
6423     pcc->mmu_model = POWERPC_MMU_3_00;
6424 #if !defined(CONFIG_USER_ONLY)
6425     /* segment page size remain the same */
6426     pcc->hash64_opts = &ppc_hash64_opts_POWER7;
6427     pcc->radix_page_info = &POWER9_radix_page_info;
6428     pcc->lrg_decr_bits = 56;
6429     pcc->n_host_threads = 4;
6430 #endif
6431     pcc->excp_model = POWERPC_EXCP_POWER9;
6432     pcc->bus_model = PPC_FLAGS_INPUT_POWER9;
6433     pcc->bfd_mach = bfd_mach_ppc64;
6434     pcc->flags = POWERPC_FLAG_VRE | POWERPC_FLAG_SE |
6435                  POWERPC_FLAG_BE | POWERPC_FLAG_PMM |
6436                  POWERPC_FLAG_BUS_CLK | POWERPC_FLAG_CFAR |
6437                  POWERPC_FLAG_VSX | POWERPC_FLAG_TM | POWERPC_FLAG_SCV;
6438     pcc->l1_dcache_size = 0x8000;
6439     pcc->l1_icache_size = 0x8000;
6440 }
6441 
6442 #ifndef CONFIG_USER_ONLY
6443 /*
6444  * Radix pg sizes and AP encodings for dt node ibm,processor-radix-AP-encodings
6445  * Encoded as array of int_32s in the form:
6446  *  0bxxxyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
6447  *  x -> AP encoding
6448  *  y -> radix mode supported page size (encoded as a shift)
6449  */
6450 static struct ppc_radix_page_info POWER10_radix_page_info = {
6451     .count = 4,
6452     .entries = {
6453         0x0000000c, /*  4K - enc: 0x0 */
6454         0xa0000010, /* 64K - enc: 0x5 */
6455         0x20000015, /*  2M - enc: 0x1 */
6456         0x4000001e  /*  1G - enc: 0x2 */
6457     }
6458 };
6459 #endif /* !CONFIG_USER_ONLY */
6460 
6461 static void init_proc_POWER10(CPUPPCState *env)
6462 {
6463     /* Common Registers */
6464     init_proc_book3s_common(env);
6465     register_book3s_207_dbg_sprs(env);
6466 
6467     /* Common TCG PMU */
6468     init_tcg_pmu_power8(env);
6469 
6470     /* POWER8 Specific Registers */
6471     register_book3s_ids_sprs(env);
6472     register_amr_sprs(env);
6473     register_iamr_sprs(env);
6474     register_book3s_purr_sprs(env);
6475     register_power5p_common_sprs(env);
6476     register_power5p_lpar_sprs(env);
6477     register_power5p_ear_sprs(env);
6478     register_power5p_tb_sprs(env);
6479     register_power6_common_sprs(env);
6480     register_HEIR64_spr(env);
6481     register_power6_dbg_sprs(env);
6482     register_power8_tce_address_control_sprs(env);
6483     register_power8_ids_sprs(env);
6484     register_power8_ebb_sprs(env);
6485     register_power8_fscr_sprs(env);
6486     register_power8_pmu_sup_sprs(env);
6487     register_power8_pmu_user_sprs(env);
6488     register_power8_tm_sprs(env);
6489     register_power8_pspb_sprs(env);
6490     register_power8_dpdes_sprs(env);
6491     register_vtb_sprs(env);
6492     register_power8_ic_sprs(env);
6493     register_power9_book4_sprs(env);
6494     register_power8_rpr_sprs(env);
6495     register_power9_mmu_sprs(env);
6496     register_power10_hash_sprs(env);
6497     register_power10_dexcr_sprs(env);
6498 
6499     /* FIXME: Filter fields properly based on privilege level */
6500     spr_register_kvm_hv(env, SPR_PSSCR, "PSSCR", NULL, NULL, NULL, NULL,
6501                         spr_read_generic, spr_write_generic,
6502                         KVM_REG_PPC_PSSCR, 0);
6503 
6504     /* env variables */
6505     env->dcache_line_size = 128;
6506     env->icache_line_size = 128;
6507 
6508     /* Allocate hardware IRQ controller */
6509     init_excp_POWER10(env);
6510     ppcPOWER9_irq_init(env_archcpu(env));
6511 }
6512 
6513 static bool ppc_pvr_match_power10(PowerPCCPUClass *pcc, uint32_t pvr, bool best)
6514 {
6515     uint32_t base = pvr & CPU_POWERPC_POWER_SERVER_MASK;
6516     uint32_t pcc_base = pcc->pvr & CPU_POWERPC_POWER_SERVER_MASK;
6517 
6518     if (!best) {
6519         if (base == CPU_POWERPC_POWER10_BASE) {
6520             return true;
6521         }
6522     }
6523 
6524     if (base != pcc_base) {
6525         return false;
6526     }
6527 
6528     if ((pvr & 0x0f00) == (pcc->pvr & 0x0f00)) {
6529         /* Major DD version matches to power10_v1.0 and power10_v2.0 */
6530         return true;
6531     }
6532 
6533     return false;
6534 }
6535 
6536 POWERPC_FAMILY(POWER10)(ObjectClass *oc, void *data)
6537 {
6538     DeviceClass *dc = DEVICE_CLASS(oc);
6539     PowerPCCPUClass *pcc = POWERPC_CPU_CLASS(oc);
6540 
6541     dc->fw_name = "PowerPC,POWER10";
6542     dc->desc = "POWER10";
6543     pcc->pvr_match = ppc_pvr_match_power10;
6544     pcc->pcr_mask = PCR_COMPAT_2_05 | PCR_COMPAT_2_06 | PCR_COMPAT_2_07 |
6545                     PCR_COMPAT_3_00;
6546     pcc->pcr_supported = PCR_COMPAT_3_10 | PCR_COMPAT_3_00 | PCR_COMPAT_2_07 |
6547                          PCR_COMPAT_2_06 | PCR_COMPAT_2_05;
6548     pcc->init_proc = init_proc_POWER10;
6549     pcc->check_pow = check_pow_nocheck;
6550     pcc->insns_flags = PPC_INSNS_BASE | PPC_ISEL | PPC_STRING | PPC_MFTB |
6551                        PPC_FLOAT | PPC_FLOAT_FSEL | PPC_FLOAT_FRES |
6552                        PPC_FLOAT_FSQRT | PPC_FLOAT_FRSQRTE |
6553                        PPC_FLOAT_FRSQRTES |
6554                        PPC_FLOAT_STFIWX |
6555                        PPC_FLOAT_EXT |
6556                        PPC_CACHE | PPC_CACHE_ICBI | PPC_CACHE_DCBZ |
6557                        PPC_MEM_SYNC | PPC_MEM_EIEIO |
6558                        PPC_MEM_TLBIE | PPC_MEM_TLBSYNC |
6559                        PPC_64B | PPC_64H | PPC_64BX | PPC_ALTIVEC |
6560                        PPC_SEGMENT_64B | PPC_SLBI |
6561                        PPC_POPCNTB | PPC_POPCNTWD |
6562                        PPC_CILDST;
6563     pcc->insns_flags2 = PPC2_VSX | PPC2_VSX207 | PPC2_DFP | PPC2_DBRX |
6564                         PPC2_PERM_ISA206 | PPC2_DIVE_ISA206 |
6565                         PPC2_ATOMIC_ISA206 | PPC2_FP_CVT_ISA206 |
6566                         PPC2_FP_TST_ISA206 | PPC2_BCTAR_ISA207 |
6567                         PPC2_LSQ_ISA207 | PPC2_ALTIVEC_207 |
6568                         PPC2_ISA205 | PPC2_ISA207S | PPC2_FP_CVT_S64 |
6569                         PPC2_TM | PPC2_ISA300 | PPC2_PRCNTL | PPC2_ISA310 |
6570                         PPC2_MEM_LWSYNC | PPC2_BCDA_ISA206;
6571     pcc->msr_mask = (1ull << MSR_SF) |
6572                     (1ull << MSR_HV) |
6573                     (1ull << MSR_TM) |
6574                     (1ull << MSR_VR) |
6575                     (1ull << MSR_VSX) |
6576                     (1ull << MSR_EE) |
6577                     (1ull << MSR_PR) |
6578                     (1ull << MSR_FP) |
6579                     (1ull << MSR_ME) |
6580                     (1ull << MSR_FE0) |
6581                     (1ull << MSR_SE) |
6582                     (1ull << MSR_DE) |
6583                     (1ull << MSR_FE1) |
6584                     (1ull << MSR_IR) |
6585                     (1ull << MSR_DR) |
6586                     (1ull << MSR_PMM) |
6587                     (1ull << MSR_RI) |
6588                     (1ull << MSR_LE);
6589     pcc->lpcr_mask = LPCR_VPM1 | LPCR_ISL | LPCR_KBV | LPCR_DPFD |
6590         (LPCR_PECE_U_MASK & LPCR_HVEE) | LPCR_ILE | LPCR_AIL |
6591         LPCR_UPRT | LPCR_EVIRT | LPCR_ONL | LPCR_HR | LPCR_LD |
6592         (LPCR_PECE_L_MASK & (LPCR_PDEE | LPCR_HDEE | LPCR_EEE |
6593                              LPCR_DEE | LPCR_OEE))
6594         | LPCR_MER | LPCR_GTSE | LPCR_TC |
6595         LPCR_HEIC | LPCR_LPES0 | LPCR_HVICE | LPCR_HDICE;
6596     /* DD2 adds an extra HAIL bit */
6597     pcc->lpcr_mask |= LPCR_HAIL;
6598 
6599     pcc->lpcr_pm = LPCR_PDEE | LPCR_HDEE | LPCR_EEE | LPCR_DEE | LPCR_OEE;
6600     pcc->mmu_model = POWERPC_MMU_3_00;
6601 #if !defined(CONFIG_USER_ONLY)
6602     /* segment page size remain the same */
6603     pcc->hash64_opts = &ppc_hash64_opts_POWER7;
6604     pcc->radix_page_info = &POWER10_radix_page_info;
6605     pcc->lrg_decr_bits = 56;
6606 #endif
6607     pcc->excp_model = POWERPC_EXCP_POWER10;
6608     pcc->bus_model = PPC_FLAGS_INPUT_POWER9;
6609     pcc->bfd_mach = bfd_mach_ppc64;
6610     pcc->flags = POWERPC_FLAG_VRE | POWERPC_FLAG_SE |
6611                  POWERPC_FLAG_BE | POWERPC_FLAG_PMM |
6612                  POWERPC_FLAG_BUS_CLK | POWERPC_FLAG_CFAR |
6613                  POWERPC_FLAG_VSX | POWERPC_FLAG_TM | POWERPC_FLAG_SCV;
6614     pcc->l1_dcache_size = 0x8000;
6615     pcc->l1_icache_size = 0x8000;
6616 }
6617 
6618 #if !defined(CONFIG_USER_ONLY)
6619 void cpu_ppc_set_vhyp(PowerPCCPU *cpu, PPCVirtualHypervisor *vhyp)
6620 {
6621     CPUPPCState *env = &cpu->env;
6622 
6623     cpu->vhyp = vhyp;
6624 
6625     /*
6626      * With a virtual hypervisor mode we never allow the CPU to go
6627      * hypervisor mode itself
6628      */
6629     env->msr_mask &= ~MSR_HVB;
6630 }
6631 
6632 void cpu_ppc_set_1lpar(PowerPCCPU *cpu)
6633 {
6634     CPUPPCState *env = &cpu->env;
6635 
6636     /*
6637      * pseries SMT means "LPAR per core" mode, e.g., msgsndp is usable
6638      * between threads.
6639      */
6640     if (env->flags & POWERPC_FLAG_SMT) {
6641         env->flags |= POWERPC_FLAG_SMT_1LPAR;
6642     }
6643 }
6644 #endif /* !defined(CONFIG_USER_ONLY) */
6645 
6646 #endif /* defined(TARGET_PPC64) */
6647 
6648 /*****************************************************************************/
6649 /* Generic CPU instantiation routine                                         */
6650 static void init_ppc_proc(PowerPCCPU *cpu)
6651 {
6652     PowerPCCPUClass *pcc = POWERPC_CPU_GET_CLASS(cpu);
6653     CPUPPCState *env = &cpu->env;
6654 #if !defined(CONFIG_USER_ONLY)
6655     int i;
6656 
6657     /* Set all exception vectors to an invalid address */
6658     for (i = 0; i < POWERPC_EXCP_NB; i++) {
6659         env->excp_vectors[i] = (target_ulong)(-1ULL);
6660     }
6661     env->ivor_mask = 0x00000000;
6662     env->ivpr_mask = 0x00000000;
6663     /* Default MMU definitions */
6664     env->nb_BATs = 0;
6665     env->nb_tlb = 0;
6666     env->nb_ways = 0;
6667     env->tlb_type = TLB_NONE;
6668 #endif
6669     /* Register SPR common to all PowerPC implementations */
6670     register_generic_sprs(cpu);
6671 
6672     /* PowerPC implementation specific initialisations (SPRs, timers, ...) */
6673     (*pcc->init_proc)(env);
6674 
6675 #if !defined(CONFIG_USER_ONLY)
6676     ppc_gdb_gen_spr_xml(cpu);
6677 #endif
6678 
6679     /* MSR bits & flags consistency checks */
6680     if (env->msr_mask & (1 << 25)) {
6681         switch (env->flags & (POWERPC_FLAG_SPE | POWERPC_FLAG_VRE)) {
6682         case POWERPC_FLAG_SPE:
6683         case POWERPC_FLAG_VRE:
6684             break;
6685         default:
6686             fprintf(stderr, "PowerPC MSR definition inconsistency\n"
6687                     "Should define POWERPC_FLAG_SPE or POWERPC_FLAG_VRE\n");
6688             exit(1);
6689         }
6690     } else if (env->flags & (POWERPC_FLAG_SPE | POWERPC_FLAG_VRE)) {
6691         fprintf(stderr, "PowerPC MSR definition inconsistency\n"
6692                 "Should not define POWERPC_FLAG_SPE nor POWERPC_FLAG_VRE\n");
6693         exit(1);
6694     }
6695     if (env->msr_mask & (1 << 17)) {
6696         switch (env->flags & (POWERPC_FLAG_TGPR | POWERPC_FLAG_CE)) {
6697         case POWERPC_FLAG_TGPR:
6698         case POWERPC_FLAG_CE:
6699             break;
6700         default:
6701             fprintf(stderr, "PowerPC MSR definition inconsistency\n"
6702                     "Should define POWERPC_FLAG_TGPR or POWERPC_FLAG_CE\n");
6703             exit(1);
6704         }
6705     } else if (env->flags & (POWERPC_FLAG_TGPR | POWERPC_FLAG_CE)) {
6706         fprintf(stderr, "PowerPC MSR definition inconsistency\n"
6707                 "Should not define POWERPC_FLAG_TGPR nor POWERPC_FLAG_CE\n");
6708         exit(1);
6709     }
6710     if (env->msr_mask & (1 << 10)) {
6711         switch (env->flags & (POWERPC_FLAG_SE | POWERPC_FLAG_DWE |
6712                               POWERPC_FLAG_UBLE)) {
6713         case POWERPC_FLAG_SE:
6714         case POWERPC_FLAG_DWE:
6715         case POWERPC_FLAG_UBLE:
6716             break;
6717         default:
6718             fprintf(stderr, "PowerPC MSR definition inconsistency\n"
6719                     "Should define POWERPC_FLAG_SE or POWERPC_FLAG_DWE or "
6720                     "POWERPC_FLAG_UBLE\n");
6721             exit(1);
6722         }
6723     } else if (env->flags & (POWERPC_FLAG_SE | POWERPC_FLAG_DWE |
6724                              POWERPC_FLAG_UBLE)) {
6725         fprintf(stderr, "PowerPC MSR definition inconsistency\n"
6726                 "Should not define POWERPC_FLAG_SE nor POWERPC_FLAG_DWE nor "
6727                 "POWERPC_FLAG_UBLE\n");
6728             exit(1);
6729     }
6730     if (env->msr_mask & (1 << 9)) {
6731         switch (env->flags & (POWERPC_FLAG_BE | POWERPC_FLAG_DE)) {
6732         case POWERPC_FLAG_BE:
6733         case POWERPC_FLAG_DE:
6734             break;
6735         default:
6736             fprintf(stderr, "PowerPC MSR definition inconsistency\n"
6737                     "Should define POWERPC_FLAG_BE or POWERPC_FLAG_DE\n");
6738             exit(1);
6739         }
6740     } else if (env->flags & (POWERPC_FLAG_BE | POWERPC_FLAG_DE)) {
6741         fprintf(stderr, "PowerPC MSR definition inconsistency\n"
6742                 "Should not define POWERPC_FLAG_BE nor POWERPC_FLAG_DE\n");
6743         exit(1);
6744     }
6745     if (env->msr_mask & (1 << 2)) {
6746         switch (env->flags & (POWERPC_FLAG_PX | POWERPC_FLAG_PMM)) {
6747         case POWERPC_FLAG_PX:
6748         case POWERPC_FLAG_PMM:
6749             break;
6750         default:
6751             fprintf(stderr, "PowerPC MSR definition inconsistency\n"
6752                     "Should define POWERPC_FLAG_PX or POWERPC_FLAG_PMM\n");
6753             exit(1);
6754         }
6755     } else if (env->flags & (POWERPC_FLAG_PX | POWERPC_FLAG_PMM)) {
6756         fprintf(stderr, "PowerPC MSR definition inconsistency\n"
6757                 "Should not define POWERPC_FLAG_PX nor POWERPC_FLAG_PMM\n");
6758         exit(1);
6759     }
6760     if ((env->flags & POWERPC_FLAG_BUS_CLK) == 0) {
6761         fprintf(stderr, "PowerPC flags inconsistency\n"
6762                 "Should define the time-base and decrementer clock source\n");
6763         exit(1);
6764     }
6765     /* Allocate TLBs buffer when needed */
6766 #if !defined(CONFIG_USER_ONLY)
6767     if (env->nb_tlb != 0) {
6768         int nb_tlb = env->nb_tlb;
6769         if (env->id_tlbs != 0) {
6770             nb_tlb *= 2;
6771         }
6772         switch (env->tlb_type) {
6773         case TLB_6XX:
6774             env->tlb.tlb6 = g_new0(ppc6xx_tlb_t, nb_tlb);
6775             break;
6776         case TLB_EMB:
6777             env->tlb.tlbe = g_new0(ppcemb_tlb_t, nb_tlb);
6778             break;
6779         case TLB_MAS:
6780             env->tlb.tlbm = g_new0(ppcmas_tlb_t, nb_tlb);
6781             break;
6782         }
6783         /* Pre-compute some useful values */
6784         env->tlb_per_way = env->nb_tlb / env->nb_ways;
6785     }
6786 #endif
6787     if (env->check_pow == NULL) {
6788         warn_report("no power management check handler registered."
6789                     " Attempt QEMU to crash very soon !");
6790     }
6791 }
6792 
6793 
6794 static void ppc_cpu_realize(DeviceState *dev, Error **errp)
6795 {
6796     CPUState *cs = CPU(dev);
6797     PowerPCCPU *cpu = POWERPC_CPU(dev);
6798     CPUPPCState *env = &cpu->env;
6799     PowerPCCPUClass *pcc = POWERPC_CPU_GET_CLASS(cpu);
6800     Error *local_err = NULL;
6801 
6802     cpu_exec_realizefn(cs, &local_err);
6803     if (local_err != NULL) {
6804         error_propagate(errp, local_err);
6805         return;
6806     }
6807     if (cpu->vcpu_id == UNASSIGNED_CPU_INDEX) {
6808         cpu->vcpu_id = cs->cpu_index;
6809     }
6810 
6811     if (tcg_enabled()) {
6812         if (ppc_fixup_cpu(cpu) != 0) {
6813             error_setg(errp, "Unable to emulate selected CPU with TCG");
6814             goto unrealize;
6815         }
6816     }
6817 
6818     create_ppc_opcodes(cpu, &local_err);
6819     if (local_err != NULL) {
6820         error_propagate(errp, local_err);
6821         goto unrealize;
6822     }
6823     init_ppc_proc(cpu);
6824 
6825     ppc_gdb_init(cs, pcc);
6826     qemu_init_vcpu(cs);
6827 
6828     pcc->parent_realize(dev, errp);
6829 
6830     if (env_cpu(env)->nr_threads > 1) {
6831         env->flags |= POWERPC_FLAG_SMT;
6832     }
6833 
6834     return;
6835 
6836 unrealize:
6837     cpu_exec_unrealizefn(cs);
6838 }
6839 
6840 static void ppc_cpu_unrealize(DeviceState *dev)
6841 {
6842     PowerPCCPU *cpu = POWERPC_CPU(dev);
6843     PowerPCCPUClass *pcc = POWERPC_CPU_GET_CLASS(cpu);
6844 
6845     pcc->parent_unrealize(dev);
6846 
6847     cpu_remove_sync(CPU(cpu));
6848 
6849     destroy_ppc_opcodes(cpu);
6850 }
6851 
6852 static gint ppc_cpu_compare_class_pvr(gconstpointer a, gconstpointer b)
6853 {
6854     ObjectClass *oc = (ObjectClass *)a;
6855     uint32_t pvr = *(uint32_t *)b;
6856     PowerPCCPUClass *pcc = (PowerPCCPUClass *)a;
6857 
6858     /* -cpu host does a PVR lookup during construction */
6859     if (unlikely(strcmp(object_class_get_name(oc),
6860                         TYPE_HOST_POWERPC_CPU) == 0)) {
6861         return -1;
6862     }
6863 
6864     return pcc->pvr == pvr ? 0 : -1;
6865 }
6866 
6867 PowerPCCPUClass *ppc_cpu_class_by_pvr(uint32_t pvr)
6868 {
6869     GSList *list, *item;
6870     PowerPCCPUClass *pcc = NULL;
6871 
6872     list = object_class_get_list(TYPE_POWERPC_CPU, false);
6873     item = g_slist_find_custom(list, &pvr, ppc_cpu_compare_class_pvr);
6874     if (item != NULL) {
6875         pcc = POWERPC_CPU_CLASS(item->data);
6876     }
6877     g_slist_free(list);
6878 
6879     return pcc;
6880 }
6881 
6882 static gint ppc_cpu_compare_class_pvr_mask(gconstpointer a, gconstpointer b)
6883 {
6884     ObjectClass *oc = (ObjectClass *)a;
6885     uint32_t pvr = *(uint32_t *)b;
6886     PowerPCCPUClass *pcc = (PowerPCCPUClass *)a;
6887 
6888     /* -cpu host does a PVR lookup during construction */
6889     if (unlikely(strcmp(object_class_get_name(oc),
6890                         TYPE_HOST_POWERPC_CPU) == 0)) {
6891         return -1;
6892     }
6893 
6894     if (pcc->pvr_match(pcc, pvr, true)) {
6895         return 0;
6896     }
6897 
6898     return -1;
6899 }
6900 
6901 PowerPCCPUClass *ppc_cpu_class_by_pvr_mask(uint32_t pvr)
6902 {
6903     GSList *list, *item;
6904     PowerPCCPUClass *pcc = NULL;
6905 
6906     list = object_class_get_list(TYPE_POWERPC_CPU, true);
6907     item = g_slist_find_custom(list, &pvr, ppc_cpu_compare_class_pvr_mask);
6908     if (item != NULL) {
6909         pcc = POWERPC_CPU_CLASS(item->data);
6910     }
6911     g_slist_free(list);
6912 
6913     return pcc;
6914 }
6915 
6916 static const char *ppc_cpu_lookup_alias(const char *alias)
6917 {
6918     int ai;
6919 
6920     for (ai = 0; ppc_cpu_aliases[ai].alias != NULL; ai++) {
6921         if (strcmp(ppc_cpu_aliases[ai].alias, alias) == 0) {
6922             return ppc_cpu_aliases[ai].model;
6923         }
6924     }
6925 
6926     return NULL;
6927 }
6928 
6929 ObjectClass *ppc_cpu_class_by_name(const char *name)
6930 {
6931     char *cpu_model, *typename;
6932     ObjectClass *oc;
6933     const char *p;
6934     unsigned long pvr;
6935 
6936     /*
6937      * Lookup by PVR if cpu_model is valid 8 digit hex number (excl:
6938      * 0x prefix if present)
6939      */
6940     if (!qemu_strtoul(name, &p, 16, &pvr)) {
6941         int len = p - name;
6942         len = (len == 10) && (name[1] == 'x') ? len - 2 : len;
6943         if ((len == 8) && (*p == '\0')) {
6944             return OBJECT_CLASS(ppc_cpu_class_by_pvr(pvr));
6945         }
6946     }
6947 
6948     /*
6949      * All ppc CPUs represent hardware that exists in the real world, i.e.: we
6950      * do not have a "max" CPU with all possible emulated features enabled.
6951      * Return the default CPU type for the machine because that has greater
6952      * chance of being useful as the "max" CPU.
6953      */
6954 #if !defined(CONFIG_USER_ONLY)
6955     if (strcmp(name, "max") == 0) {
6956         MachineClass *mc = MACHINE_GET_CLASS(qdev_get_machine());
6957         if (mc) {
6958             return object_class_by_name(mc->default_cpu_type);
6959         }
6960     }
6961 #endif
6962 
6963     cpu_model = g_ascii_strdown(name, -1);
6964     p = ppc_cpu_lookup_alias(cpu_model);
6965     if (p) {
6966         g_free(cpu_model);
6967         cpu_model = g_strdup(p);
6968     }
6969 
6970     typename = g_strdup_printf("%s" POWERPC_CPU_TYPE_SUFFIX, cpu_model);
6971     oc = object_class_by_name(typename);
6972     g_free(typename);
6973     g_free(cpu_model);
6974 
6975     return oc;
6976 }
6977 
6978 PowerPCCPUClass *ppc_cpu_get_family_class(PowerPCCPUClass *pcc)
6979 {
6980     ObjectClass *oc = OBJECT_CLASS(pcc);
6981 
6982     while (oc && !object_class_is_abstract(oc)) {
6983         oc = object_class_get_parent(oc);
6984     }
6985     assert(oc);
6986 
6987     return POWERPC_CPU_CLASS(oc);
6988 }
6989 
6990 /* Sort by PVR, ordering special case "host" last. */
6991 static gint ppc_cpu_list_compare(gconstpointer a, gconstpointer b)
6992 {
6993     ObjectClass *oc_a = (ObjectClass *)a;
6994     ObjectClass *oc_b = (ObjectClass *)b;
6995     PowerPCCPUClass *pcc_a = POWERPC_CPU_CLASS(oc_a);
6996     PowerPCCPUClass *pcc_b = POWERPC_CPU_CLASS(oc_b);
6997     const char *name_a = object_class_get_name(oc_a);
6998     const char *name_b = object_class_get_name(oc_b);
6999 
7000     if (strcmp(name_a, TYPE_HOST_POWERPC_CPU) == 0) {
7001         return 1;
7002     } else if (strcmp(name_b, TYPE_HOST_POWERPC_CPU) == 0) {
7003         return -1;
7004     } else {
7005         /* Avoid an integer overflow during subtraction */
7006         if (pcc_a->pvr < pcc_b->pvr) {
7007             return -1;
7008         } else if (pcc_a->pvr > pcc_b->pvr) {
7009             return 1;
7010         } else {
7011             return 0;
7012         }
7013     }
7014 }
7015 
7016 static void ppc_cpu_list_entry(gpointer data, gpointer user_data)
7017 {
7018     ObjectClass *oc = data;
7019     PowerPCCPUClass *pcc = POWERPC_CPU_CLASS(oc);
7020     DeviceClass *family = DEVICE_CLASS(ppc_cpu_get_family_class(pcc));
7021     const char *typename = object_class_get_name(oc);
7022     char *name;
7023     int i;
7024 
7025     if (unlikely(strcmp(typename, TYPE_HOST_POWERPC_CPU) == 0)) {
7026         return;
7027     }
7028 
7029     name = g_strndup(typename,
7030                      strlen(typename) - strlen(POWERPC_CPU_TYPE_SUFFIX));
7031     qemu_printf("PowerPC %-16s PVR %08x\n", name, pcc->pvr);
7032     for (i = 0; ppc_cpu_aliases[i].alias != NULL; i++) {
7033         PowerPCCPUAlias *alias = &ppc_cpu_aliases[i];
7034         ObjectClass *alias_oc = ppc_cpu_class_by_name(alias->model);
7035 
7036         if (alias_oc != oc) {
7037             continue;
7038         }
7039         /*
7040          * If running with KVM, we might update the family alias later, so
7041          * avoid printing the wrong alias here and use "preferred" instead
7042          */
7043         if (strcmp(alias->alias, family->desc) == 0) {
7044             qemu_printf("PowerPC %-16s (alias for preferred %s CPU)\n",
7045                         alias->alias, family->desc);
7046         } else {
7047             qemu_printf("PowerPC %-16s (alias for %s)\n",
7048                         alias->alias, name);
7049         }
7050     }
7051     g_free(name);
7052 }
7053 
7054 void ppc_cpu_list(void)
7055 {
7056     GSList *list;
7057 
7058     list = object_class_get_list(TYPE_POWERPC_CPU, false);
7059     list = g_slist_sort(list, ppc_cpu_list_compare);
7060     g_slist_foreach(list, ppc_cpu_list_entry, NULL);
7061     g_slist_free(list);
7062 
7063 #ifdef CONFIG_KVM
7064     qemu_printf("\n");
7065     qemu_printf("PowerPC %s\n", "host");
7066 #endif
7067 }
7068 
7069 static void ppc_cpu_set_pc(CPUState *cs, vaddr value)
7070 {
7071     PowerPCCPU *cpu = POWERPC_CPU(cs);
7072 
7073     cpu->env.nip = value;
7074 }
7075 
7076 static vaddr ppc_cpu_get_pc(CPUState *cs)
7077 {
7078     PowerPCCPU *cpu = POWERPC_CPU(cs);
7079 
7080     return cpu->env.nip;
7081 }
7082 
7083 #ifdef CONFIG_TCG
7084 static void ppc_restore_state_to_opc(CPUState *cs,
7085                                      const TranslationBlock *tb,
7086                                      const uint64_t *data)
7087 {
7088     PowerPCCPU *cpu = POWERPC_CPU(cs);
7089 
7090     cpu->env.nip = data[0];
7091 }
7092 #endif /* CONFIG_TCG */
7093 
7094 static bool ppc_cpu_has_work(CPUState *cs)
7095 {
7096     return cs->interrupt_request & CPU_INTERRUPT_HARD;
7097 }
7098 
7099 static void ppc_cpu_reset_hold(Object *obj)
7100 {
7101     CPUState *s = CPU(obj);
7102     PowerPCCPU *cpu = POWERPC_CPU(s);
7103     PowerPCCPUClass *pcc = POWERPC_CPU_GET_CLASS(cpu);
7104     CPUPPCState *env = &cpu->env;
7105     target_ulong msr;
7106     int i;
7107 
7108     if (pcc->parent_phases.hold) {
7109         pcc->parent_phases.hold(obj);
7110     }
7111 
7112     msr = (target_ulong)0;
7113     msr |= (target_ulong)MSR_HVB;
7114     msr |= (target_ulong)1 << MSR_EP;
7115 #if defined(DO_SINGLE_STEP) && 0
7116     /* Single step trace mode */
7117     msr |= (target_ulong)1 << MSR_SE;
7118     msr |= (target_ulong)1 << MSR_BE;
7119 #endif
7120 #if defined(CONFIG_USER_ONLY)
7121     msr |= (target_ulong)1 << MSR_FP; /* Allow floating point usage */
7122     msr |= (target_ulong)1 << MSR_FE0; /* Allow floating point exceptions */
7123     msr |= (target_ulong)1 << MSR_FE1;
7124     msr |= (target_ulong)1 << MSR_VR; /* Allow altivec usage */
7125     msr |= (target_ulong)1 << MSR_VSX; /* Allow VSX usage */
7126     msr |= (target_ulong)1 << MSR_SPE; /* Allow SPE usage */
7127     msr |= (target_ulong)1 << MSR_PR;
7128 #if defined(TARGET_PPC64)
7129     msr |= (target_ulong)1 << MSR_TM; /* Transactional memory */
7130 #endif
7131 #if !TARGET_BIG_ENDIAN
7132     msr |= (target_ulong)1 << MSR_LE; /* Little-endian user mode */
7133     if (!((env->msr_mask >> MSR_LE) & 1)) {
7134         fprintf(stderr, "Selected CPU does not support little-endian.\n");
7135         exit(1);
7136     }
7137 #endif
7138 #endif
7139 
7140 #if defined(TARGET_PPC64)
7141     if (mmu_is_64bit(env->mmu_model)) {
7142         msr |= (1ULL << MSR_SF);
7143     }
7144 #endif
7145 
7146     hreg_store_msr(env, msr, 1);
7147 
7148 #if !defined(CONFIG_USER_ONLY)
7149     env->nip = env->hreset_vector | env->excp_prefix;
7150 
7151     if (tcg_enabled()) {
7152         if (env->mmu_model != POWERPC_MMU_REAL) {
7153             ppc_tlb_invalidate_all(env);
7154         }
7155         pmu_mmcr01_updated(env);
7156     }
7157 
7158     /* clean any pending stop state */
7159     env->resume_as_sreset = 0;
7160 #endif
7161     hreg_compute_hflags(env);
7162     env->reserve_addr = (target_ulong)-1ULL;
7163     /* Be sure no exception or interrupt is pending */
7164     env->pending_interrupts = 0;
7165     s->exception_index = POWERPC_EXCP_NONE;
7166     env->error_code = 0;
7167     ppc_irq_reset(cpu);
7168 
7169     /* tininess for underflow is detected before rounding */
7170     set_float_detect_tininess(float_tininess_before_rounding,
7171                               &env->fp_status);
7172 
7173     for (i = 0; i < ARRAY_SIZE(env->spr_cb); i++) {
7174         ppc_spr_t *spr = &env->spr_cb[i];
7175 
7176         if (!spr->name) {
7177             continue;
7178         }
7179         env->spr[i] = spr->default_value;
7180     }
7181 }
7182 
7183 #ifndef CONFIG_USER_ONLY
7184 
7185 static bool ppc_cpu_is_big_endian(CPUState *cs)
7186 {
7187     PowerPCCPU *cpu = POWERPC_CPU(cs);
7188     CPUPPCState *env = &cpu->env;
7189 
7190     cpu_synchronize_state(cs);
7191 
7192     return !FIELD_EX64(env->msr, MSR, LE);
7193 }
7194 
7195 static bool ppc_get_irq_stats(InterruptStatsProvider *obj,
7196                               uint64_t **irq_counts, unsigned int *nb_irqs)
7197 {
7198     CPUPPCState *env = &POWERPC_CPU(obj)->env;
7199 
7200     *irq_counts = env->excp_stats;
7201     *nb_irqs = ARRAY_SIZE(env->excp_stats);
7202     return true;
7203 }
7204 
7205 #ifdef CONFIG_TCG
7206 static void ppc_cpu_exec_enter(CPUState *cs)
7207 {
7208     PowerPCCPU *cpu = POWERPC_CPU(cs);
7209 
7210     if (cpu->vhyp) {
7211         PPCVirtualHypervisorClass *vhc =
7212             PPC_VIRTUAL_HYPERVISOR_GET_CLASS(cpu->vhyp);
7213         vhc->cpu_exec_enter(cpu->vhyp, cpu);
7214     }
7215 }
7216 
7217 static void ppc_cpu_exec_exit(CPUState *cs)
7218 {
7219     PowerPCCPU *cpu = POWERPC_CPU(cs);
7220 
7221     if (cpu->vhyp) {
7222         PPCVirtualHypervisorClass *vhc =
7223             PPC_VIRTUAL_HYPERVISOR_GET_CLASS(cpu->vhyp);
7224         vhc->cpu_exec_exit(cpu->vhyp, cpu);
7225     }
7226 }
7227 #endif /* CONFIG_TCG */
7228 
7229 #endif /* !CONFIG_USER_ONLY */
7230 
7231 static void ppc_cpu_instance_init(Object *obj)
7232 {
7233     PowerPCCPU *cpu = POWERPC_CPU(obj);
7234     PowerPCCPUClass *pcc = POWERPC_CPU_GET_CLASS(cpu);
7235     CPUPPCState *env = &cpu->env;
7236 
7237     cpu_set_cpustate_pointers(cpu);
7238     cpu->vcpu_id = UNASSIGNED_CPU_INDEX;
7239 
7240     env->msr_mask = pcc->msr_mask;
7241     env->mmu_model = pcc->mmu_model;
7242     env->excp_model = pcc->excp_model;
7243     env->bus_model = pcc->bus_model;
7244     env->insns_flags = pcc->insns_flags;
7245     env->insns_flags2 = pcc->insns_flags2;
7246     env->flags = pcc->flags;
7247     env->bfd_mach = pcc->bfd_mach;
7248     env->check_pow = pcc->check_pow;
7249 
7250     /*
7251      * Mark HV mode as supported if the CPU has an MSR_HV bit in the
7252      * msr_mask. The mask can later be cleared by PAPR mode but the hv
7253      * mode support will remain, thus enforcing that we cannot use
7254      * priv. instructions in guest in PAPR mode. For 970 we currently
7255      * simply don't set HV in msr_mask thus simulating an "Apple mode"
7256      * 970. If we ever want to support 970 HV mode, we'll have to add
7257      * a processor attribute of some sort.
7258      */
7259 #if !defined(CONFIG_USER_ONLY)
7260     env->has_hv_mode = !!(env->msr_mask & MSR_HVB);
7261 #endif
7262 
7263     ppc_hash64_init(cpu);
7264 }
7265 
7266 static void ppc_cpu_instance_finalize(Object *obj)
7267 {
7268     PowerPCCPU *cpu = POWERPC_CPU(obj);
7269 
7270     ppc_hash64_finalize(cpu);
7271 }
7272 
7273 static bool ppc_pvr_match_default(PowerPCCPUClass *pcc, uint32_t pvr, bool best)
7274 {
7275     return pcc->pvr == pvr;
7276 }
7277 
7278 static void ppc_disas_set_info(CPUState *cs, disassemble_info *info)
7279 {
7280     PowerPCCPU *cpu = POWERPC_CPU(cs);
7281     CPUPPCState *env = &cpu->env;
7282 
7283     if ((env->hflags >> MSR_LE) & 1) {
7284         info->endian = BFD_ENDIAN_LITTLE;
7285     }
7286     info->mach = env->bfd_mach;
7287     if (!env->bfd_mach) {
7288 #ifdef TARGET_PPC64
7289         info->mach = bfd_mach_ppc64;
7290 #else
7291         info->mach = bfd_mach_ppc;
7292 #endif
7293     }
7294 
7295     info->cap_arch = CS_ARCH_PPC;
7296 #ifdef TARGET_PPC64
7297     info->cap_mode = CS_MODE_64;
7298 #endif
7299 }
7300 
7301 static Property ppc_cpu_properties[] = {
7302     DEFINE_PROP_BOOL("pre-2.8-migration", PowerPCCPU, pre_2_8_migration, false),
7303     DEFINE_PROP_BOOL("pre-2.10-migration", PowerPCCPU, pre_2_10_migration,
7304                      false),
7305     DEFINE_PROP_BOOL("pre-3.0-migration", PowerPCCPU, pre_3_0_migration,
7306                      false),
7307     DEFINE_PROP_END_OF_LIST(),
7308 };
7309 
7310 #ifndef CONFIG_USER_ONLY
7311 #include "hw/core/sysemu-cpu-ops.h"
7312 
7313 static const struct SysemuCPUOps ppc_sysemu_ops = {
7314     .get_phys_page_debug = ppc_cpu_get_phys_page_debug,
7315     .write_elf32_note = ppc32_cpu_write_elf32_note,
7316     .write_elf64_note = ppc64_cpu_write_elf64_note,
7317     .virtio_is_big_endian = ppc_cpu_is_big_endian,
7318     .legacy_vmsd = &vmstate_ppc_cpu,
7319 };
7320 #endif
7321 
7322 #ifdef CONFIG_TCG
7323 #include "hw/core/tcg-cpu-ops.h"
7324 
7325 static const struct TCGCPUOps ppc_tcg_ops = {
7326   .initialize = ppc_translate_init,
7327   .restore_state_to_opc = ppc_restore_state_to_opc,
7328 
7329 #ifdef CONFIG_USER_ONLY
7330   .record_sigsegv = ppc_cpu_record_sigsegv,
7331 #else
7332   .tlb_fill = ppc_cpu_tlb_fill,
7333   .cpu_exec_interrupt = ppc_cpu_exec_interrupt,
7334   .do_interrupt = ppc_cpu_do_interrupt,
7335   .cpu_exec_enter = ppc_cpu_exec_enter,
7336   .cpu_exec_exit = ppc_cpu_exec_exit,
7337   .do_unaligned_access = ppc_cpu_do_unaligned_access,
7338   .do_transaction_failed = ppc_cpu_do_transaction_failed,
7339 #endif /* !CONFIG_USER_ONLY */
7340 };
7341 #endif /* CONFIG_TCG */
7342 
7343 static void ppc_cpu_class_init(ObjectClass *oc, void *data)
7344 {
7345     PowerPCCPUClass *pcc = POWERPC_CPU_CLASS(oc);
7346     CPUClass *cc = CPU_CLASS(oc);
7347     DeviceClass *dc = DEVICE_CLASS(oc);
7348     ResettableClass *rc = RESETTABLE_CLASS(oc);
7349 
7350     device_class_set_parent_realize(dc, ppc_cpu_realize,
7351                                     &pcc->parent_realize);
7352     device_class_set_parent_unrealize(dc, ppc_cpu_unrealize,
7353                                       &pcc->parent_unrealize);
7354     pcc->pvr_match = ppc_pvr_match_default;
7355     device_class_set_props(dc, ppc_cpu_properties);
7356 
7357     resettable_class_set_parent_phases(rc, NULL, ppc_cpu_reset_hold, NULL,
7358                                        &pcc->parent_phases);
7359 
7360     cc->class_by_name = ppc_cpu_class_by_name;
7361     cc->has_work = ppc_cpu_has_work;
7362     cc->dump_state = ppc_cpu_dump_state;
7363     cc->set_pc = ppc_cpu_set_pc;
7364     cc->get_pc = ppc_cpu_get_pc;
7365     cc->gdb_read_register = ppc_cpu_gdb_read_register;
7366     cc->gdb_write_register = ppc_cpu_gdb_write_register;
7367 #ifndef CONFIG_USER_ONLY
7368     cc->sysemu_ops = &ppc_sysemu_ops;
7369     INTERRUPT_STATS_PROVIDER_CLASS(oc)->get_statistics = ppc_get_irq_stats;
7370 #endif
7371 
7372     cc->gdb_num_core_regs = 71;
7373 #ifndef CONFIG_USER_ONLY
7374     cc->gdb_get_dynamic_xml = ppc_gdb_get_dynamic_xml;
7375 #endif
7376 #ifdef USE_APPLE_GDB
7377     cc->gdb_read_register = ppc_cpu_gdb_read_register_apple;
7378     cc->gdb_write_register = ppc_cpu_gdb_write_register_apple;
7379     cc->gdb_num_core_regs = 71 + 32;
7380 #endif
7381 
7382     cc->gdb_arch_name = ppc_gdb_arch_name;
7383 #if defined(TARGET_PPC64)
7384     cc->gdb_core_xml_file = "power64-core.xml";
7385 #else
7386     cc->gdb_core_xml_file = "power-core.xml";
7387 #endif
7388     cc->disas_set_info = ppc_disas_set_info;
7389 
7390     dc->fw_name = "PowerPC,UNKNOWN";
7391 
7392 #ifdef CONFIG_TCG
7393     cc->tcg_ops = &ppc_tcg_ops;
7394 #endif /* CONFIG_TCG */
7395 }
7396 
7397 static const TypeInfo ppc_cpu_type_info = {
7398     .name = TYPE_POWERPC_CPU,
7399     .parent = TYPE_CPU,
7400     .instance_size = sizeof(PowerPCCPU),
7401     .instance_align = __alignof__(PowerPCCPU),
7402     .instance_init = ppc_cpu_instance_init,
7403     .instance_finalize = ppc_cpu_instance_finalize,
7404     .abstract = true,
7405     .class_size = sizeof(PowerPCCPUClass),
7406     .class_init = ppc_cpu_class_init,
7407 #ifndef CONFIG_USER_ONLY
7408     .interfaces = (InterfaceInfo[]) {
7409           { TYPE_INTERRUPT_STATS_PROVIDER },
7410           { }
7411     },
7412 #endif
7413 };
7414 
7415 #ifndef CONFIG_USER_ONLY
7416 static const TypeInfo ppc_vhyp_type_info = {
7417     .name = TYPE_PPC_VIRTUAL_HYPERVISOR,
7418     .parent = TYPE_INTERFACE,
7419     .class_size = sizeof(PPCVirtualHypervisorClass),
7420 };
7421 #endif
7422 
7423 static void ppc_cpu_register_types(void)
7424 {
7425     type_register_static(&ppc_cpu_type_info);
7426 #ifndef CONFIG_USER_ONLY
7427     type_register_static(&ppc_vhyp_type_info);
7428 #endif
7429 }
7430 
7431 void ppc_cpu_dump_state(CPUState *cs, FILE *f, int flags)
7432 {
7433 #define RGPL  4
7434 #define RFPL  4
7435 
7436     PowerPCCPU *cpu = POWERPC_CPU(cs);
7437     CPUPPCState *env = &cpu->env;
7438     int i;
7439 
7440     qemu_fprintf(f, "NIP " TARGET_FMT_lx "   LR " TARGET_FMT_lx " CTR "
7441                  TARGET_FMT_lx " XER " TARGET_FMT_lx " CPU#%d\n",
7442                  env->nip, env->lr, env->ctr, cpu_read_xer(env),
7443                  cs->cpu_index);
7444     qemu_fprintf(f, "MSR " TARGET_FMT_lx " HID0 " TARGET_FMT_lx "  HF "
7445                  "%08x iidx %d didx %d\n",
7446                  env->msr, env->spr[SPR_HID0], env->hflags,
7447                  cpu_mmu_index(env, true), cpu_mmu_index(env, false));
7448 #if !defined(CONFIG_USER_ONLY)
7449     if (env->tb_env) {
7450         qemu_fprintf(f, "TB %08" PRIu32 " %08" PRIu64
7451                      " DECR " TARGET_FMT_lu "\n", cpu_ppc_load_tbu(env),
7452                      cpu_ppc_load_tbl(env), cpu_ppc_load_decr(env));
7453     }
7454 #else
7455     qemu_fprintf(f, "TB %08" PRIu32 " %08" PRIu64 "\n", cpu_ppc_load_tbu(env),
7456                  cpu_ppc_load_tbl(env));
7457 #endif
7458     for (i = 0; i < 32; i++) {
7459         if ((i & (RGPL - 1)) == 0) {
7460             qemu_fprintf(f, "GPR%02d", i);
7461         }
7462         qemu_fprintf(f, " %016" PRIx64, ppc_dump_gpr(env, i));
7463         if ((i & (RGPL - 1)) == (RGPL - 1)) {
7464             qemu_fprintf(f, "\n");
7465         }
7466     }
7467     qemu_fprintf(f, "CR ");
7468     for (i = 0; i < 8; i++)
7469         qemu_fprintf(f, "%01x", env->crf[i]);
7470     qemu_fprintf(f, "  [");
7471     for (i = 0; i < 8; i++) {
7472         char a = '-';
7473         if (env->crf[i] & 0x08) {
7474             a = 'L';
7475         } else if (env->crf[i] & 0x04) {
7476             a = 'G';
7477         } else if (env->crf[i] & 0x02) {
7478             a = 'E';
7479         }
7480         qemu_fprintf(f, " %c%c", a, env->crf[i] & 0x01 ? 'O' : ' ');
7481     }
7482     qemu_fprintf(f, " ]     RES %03x@" TARGET_FMT_lx "\n",
7483                  (int)env->reserve_length, env->reserve_addr);
7484 
7485     if (flags & CPU_DUMP_FPU) {
7486         for (i = 0; i < 32; i++) {
7487             if ((i & (RFPL - 1)) == 0) {
7488                 qemu_fprintf(f, "FPR%02d", i);
7489             }
7490             qemu_fprintf(f, " %016" PRIx64, *cpu_fpr_ptr(env, i));
7491             if ((i & (RFPL - 1)) == (RFPL - 1)) {
7492                 qemu_fprintf(f, "\n");
7493             }
7494         }
7495         qemu_fprintf(f, "FPSCR " TARGET_FMT_lx "\n", env->fpscr);
7496     }
7497 
7498 #if !defined(CONFIG_USER_ONLY)
7499     qemu_fprintf(f, " SRR0 " TARGET_FMT_lx "  SRR1 " TARGET_FMT_lx
7500                  "    PVR " TARGET_FMT_lx " VRSAVE " TARGET_FMT_lx "\n",
7501                  env->spr[SPR_SRR0], env->spr[SPR_SRR1],
7502                  env->spr[SPR_PVR], env->spr[SPR_VRSAVE]);
7503 
7504     qemu_fprintf(f, "SPRG0 " TARGET_FMT_lx " SPRG1 " TARGET_FMT_lx
7505                  "  SPRG2 " TARGET_FMT_lx "  SPRG3 " TARGET_FMT_lx "\n",
7506                  env->spr[SPR_SPRG0], env->spr[SPR_SPRG1],
7507                  env->spr[SPR_SPRG2], env->spr[SPR_SPRG3]);
7508 
7509     qemu_fprintf(f, "SPRG4 " TARGET_FMT_lx " SPRG5 " TARGET_FMT_lx
7510                  "  SPRG6 " TARGET_FMT_lx "  SPRG7 " TARGET_FMT_lx "\n",
7511                  env->spr[SPR_SPRG4], env->spr[SPR_SPRG5],
7512                  env->spr[SPR_SPRG6], env->spr[SPR_SPRG7]);
7513 
7514     switch (env->excp_model) {
7515 #if defined(TARGET_PPC64)
7516     case POWERPC_EXCP_POWER7:
7517     case POWERPC_EXCP_POWER8:
7518     case POWERPC_EXCP_POWER9:
7519     case POWERPC_EXCP_POWER10:
7520         qemu_fprintf(f, "HSRR0 " TARGET_FMT_lx " HSRR1 " TARGET_FMT_lx "\n",
7521                      env->spr[SPR_HSRR0], env->spr[SPR_HSRR1]);
7522         break;
7523 #endif
7524     case POWERPC_EXCP_BOOKE:
7525         qemu_fprintf(f, "CSRR0 " TARGET_FMT_lx " CSRR1 " TARGET_FMT_lx
7526                      " MCSRR0 " TARGET_FMT_lx " MCSRR1 " TARGET_FMT_lx "\n",
7527                      env->spr[SPR_BOOKE_CSRR0], env->spr[SPR_BOOKE_CSRR1],
7528                      env->spr[SPR_BOOKE_MCSRR0], env->spr[SPR_BOOKE_MCSRR1]);
7529 
7530         qemu_fprintf(f, "  TCR " TARGET_FMT_lx "   TSR " TARGET_FMT_lx
7531                      "    ESR " TARGET_FMT_lx "   DEAR " TARGET_FMT_lx "\n",
7532                      env->spr[SPR_BOOKE_TCR], env->spr[SPR_BOOKE_TSR],
7533                      env->spr[SPR_BOOKE_ESR], env->spr[SPR_BOOKE_DEAR]);
7534 
7535         qemu_fprintf(f, "  PIR " TARGET_FMT_lx " DECAR " TARGET_FMT_lx
7536                      "   IVPR " TARGET_FMT_lx "   EPCR " TARGET_FMT_lx "\n",
7537                      env->spr[SPR_BOOKE_PIR], env->spr[SPR_BOOKE_DECAR],
7538                      env->spr[SPR_BOOKE_IVPR], env->spr[SPR_BOOKE_EPCR]);
7539 
7540         qemu_fprintf(f, " MCSR " TARGET_FMT_lx " SPRG8 " TARGET_FMT_lx
7541                      "    EPR " TARGET_FMT_lx "\n",
7542                      env->spr[SPR_BOOKE_MCSR], env->spr[SPR_BOOKE_SPRG8],
7543                      env->spr[SPR_BOOKE_EPR]);
7544 
7545         /* FSL-specific */
7546         qemu_fprintf(f, " MCAR " TARGET_FMT_lx "  PID1 " TARGET_FMT_lx
7547                      "   PID2 " TARGET_FMT_lx "    SVR " TARGET_FMT_lx "\n",
7548                      env->spr[SPR_Exxx_MCAR], env->spr[SPR_BOOKE_PID1],
7549                      env->spr[SPR_BOOKE_PID2], env->spr[SPR_E500_SVR]);
7550 
7551         /*
7552          * IVORs are left out as they are large and do not change often --
7553          * they can be read with "p $ivor0", "p $ivor1", etc.
7554          */
7555         break;
7556     case POWERPC_EXCP_40x:
7557         qemu_fprintf(f, "  TCR " TARGET_FMT_lx "   TSR " TARGET_FMT_lx
7558                      "    ESR " TARGET_FMT_lx "   DEAR " TARGET_FMT_lx "\n",
7559                      env->spr[SPR_40x_TCR], env->spr[SPR_40x_TSR],
7560                      env->spr[SPR_40x_ESR], env->spr[SPR_40x_DEAR]);
7561 
7562         qemu_fprintf(f, " EVPR " TARGET_FMT_lx "  SRR2 " TARGET_FMT_lx
7563                      "   SRR3 " TARGET_FMT_lx  "   PID " TARGET_FMT_lx "\n",
7564                      env->spr[SPR_40x_EVPR], env->spr[SPR_40x_SRR2],
7565                      env->spr[SPR_40x_SRR3], env->spr[SPR_40x_PID]);
7566         break;
7567     default:
7568         break;
7569     }
7570 
7571 #if defined(TARGET_PPC64)
7572     if (env->flags & POWERPC_FLAG_CFAR) {
7573         qemu_fprintf(f, " CFAR " TARGET_FMT_lx"\n", env->cfar);
7574     }
7575 #endif
7576 
7577     if (env->spr_cb[SPR_LPCR].name) {
7578         qemu_fprintf(f, " LPCR " TARGET_FMT_lx "\n", env->spr[SPR_LPCR]);
7579     }
7580 
7581     switch (env->mmu_model) {
7582     case POWERPC_MMU_32B:
7583     case POWERPC_MMU_SOFT_6xx:
7584 #if defined(TARGET_PPC64)
7585     case POWERPC_MMU_64B:
7586     case POWERPC_MMU_2_03:
7587     case POWERPC_MMU_2_06:
7588     case POWERPC_MMU_2_07:
7589     case POWERPC_MMU_3_00:
7590 #endif
7591         if (env->spr_cb[SPR_SDR1].name) { /* SDR1 Exists */
7592             qemu_fprintf(f, " SDR1 " TARGET_FMT_lx " ", env->spr[SPR_SDR1]);
7593         }
7594         if (env->spr_cb[SPR_PTCR].name) { /* PTCR Exists */
7595             qemu_fprintf(f, " PTCR " TARGET_FMT_lx " ", env->spr[SPR_PTCR]);
7596         }
7597         qemu_fprintf(f, "  DAR " TARGET_FMT_lx "  DSISR " TARGET_FMT_lx "\n",
7598                      env->spr[SPR_DAR], env->spr[SPR_DSISR]);
7599         break;
7600     case POWERPC_MMU_BOOKE206:
7601         qemu_fprintf(f, " MAS0 " TARGET_FMT_lx "  MAS1 " TARGET_FMT_lx
7602                      "   MAS2 " TARGET_FMT_lx "   MAS3 " TARGET_FMT_lx "\n",
7603                      env->spr[SPR_BOOKE_MAS0], env->spr[SPR_BOOKE_MAS1],
7604                      env->spr[SPR_BOOKE_MAS2], env->spr[SPR_BOOKE_MAS3]);
7605 
7606         qemu_fprintf(f, " MAS4 " TARGET_FMT_lx "  MAS6 " TARGET_FMT_lx
7607                      "   MAS7 " TARGET_FMT_lx "    PID " TARGET_FMT_lx "\n",
7608                      env->spr[SPR_BOOKE_MAS4], env->spr[SPR_BOOKE_MAS6],
7609                      env->spr[SPR_BOOKE_MAS7], env->spr[SPR_BOOKE_PID]);
7610 
7611         qemu_fprintf(f, "MMUCFG " TARGET_FMT_lx " TLB0CFG " TARGET_FMT_lx
7612                      " TLB1CFG " TARGET_FMT_lx "\n",
7613                      env->spr[SPR_MMUCFG], env->spr[SPR_BOOKE_TLB0CFG],
7614                      env->spr[SPR_BOOKE_TLB1CFG]);
7615         break;
7616     default:
7617         break;
7618     }
7619 #endif
7620 
7621 #undef RGPL
7622 #undef RFPL
7623 }
7624 type_init(ppc_cpu_register_types)
7625