xref: /openbmc/qemu/target/ppc/helper_regs.c (revision 243705aa)
1 /*
2  *  PowerPC emulation special registers manipulation helpers for qemu.
3  *
4  *  Copyright (c) 2003-2007 Jocelyn Mayer
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #include "qemu/osdep.h"
21 #include "cpu.h"
22 #include "qemu/main-loop.h"
23 #include "exec/exec-all.h"
24 #include "sysemu/kvm.h"
25 #include "sysemu/tcg.h"
26 #include "helper_regs.h"
27 #include "power8-pmu.h"
28 #include "cpu-models.h"
29 #include "spr_common.h"
30 
31 /* Swap temporary saved registers with GPRs */
32 void hreg_swap_gpr_tgpr(CPUPPCState *env)
33 {
34     target_ulong tmp;
35 
36     tmp = env->gpr[0];
37     env->gpr[0] = env->tgpr[0];
38     env->tgpr[0] = tmp;
39     tmp = env->gpr[1];
40     env->gpr[1] = env->tgpr[1];
41     env->tgpr[1] = tmp;
42     tmp = env->gpr[2];
43     env->gpr[2] = env->tgpr[2];
44     env->tgpr[2] = tmp;
45     tmp = env->gpr[3];
46     env->gpr[3] = env->tgpr[3];
47     env->tgpr[3] = tmp;
48 }
49 
50 static uint32_t hreg_compute_pmu_hflags_value(CPUPPCState *env)
51 {
52     uint32_t hflags = 0;
53 
54 #if defined(TARGET_PPC64)
55     if (env->spr[SPR_POWER_MMCR0] & MMCR0_PMCC0) {
56         hflags |= 1 << HFLAGS_PMCC0;
57     }
58     if (env->spr[SPR_POWER_MMCR0] & MMCR0_PMCC1) {
59         hflags |= 1 << HFLAGS_PMCC1;
60     }
61     if (env->spr[SPR_POWER_MMCR0] & MMCR0_PMCjCE) {
62         hflags |= 1 << HFLAGS_PMCJCE;
63     }
64 
65 #ifndef CONFIG_USER_ONLY
66     if (env->pmc_ins_cnt) {
67         hflags |= 1 << HFLAGS_INSN_CNT;
68     }
69     if (env->pmc_ins_cnt & 0x1e) {
70         hflags |= 1 << HFLAGS_PMC_OTHER;
71     }
72 #endif
73 #endif
74 
75     return hflags;
76 }
77 
78 /* Mask of all PMU hflags */
79 static uint32_t hreg_compute_pmu_hflags_mask(CPUPPCState *env)
80 {
81     uint32_t hflags_mask = 0;
82 #if defined(TARGET_PPC64)
83     hflags_mask |= 1 << HFLAGS_PMCC0;
84     hflags_mask |= 1 << HFLAGS_PMCC1;
85     hflags_mask |= 1 << HFLAGS_PMCJCE;
86     hflags_mask |= 1 << HFLAGS_INSN_CNT;
87     hflags_mask |= 1 << HFLAGS_PMC_OTHER;
88 #endif
89     return hflags_mask;
90 }
91 
92 static uint32_t hreg_compute_hflags_value(CPUPPCState *env)
93 {
94     target_ulong msr = env->msr;
95     uint32_t ppc_flags = env->flags;
96     uint32_t hflags = 0;
97     uint32_t msr_mask;
98 
99     /* Some bits come straight across from MSR. */
100     QEMU_BUILD_BUG_ON(MSR_LE != HFLAGS_LE);
101     QEMU_BUILD_BUG_ON(MSR_PR != HFLAGS_PR);
102     QEMU_BUILD_BUG_ON(MSR_DR != HFLAGS_DR);
103     QEMU_BUILD_BUG_ON(MSR_FP != HFLAGS_FP);
104     msr_mask = ((1 << MSR_LE) | (1 << MSR_PR) |
105                 (1 << MSR_DR) | (1 << MSR_FP));
106 
107     if (ppc_flags & POWERPC_FLAG_DE) {
108         target_ulong dbcr0 = env->spr[SPR_BOOKE_DBCR0];
109         if ((dbcr0 & DBCR0_ICMP) && FIELD_EX64(env->msr, MSR, DE)) {
110             hflags |= 1 << HFLAGS_SE;
111         }
112         if ((dbcr0 & DBCR0_BRT) && FIELD_EX64(env->msr, MSR, DE)) {
113             hflags |= 1 << HFLAGS_BE;
114         }
115     } else {
116         if (ppc_flags & POWERPC_FLAG_BE) {
117             QEMU_BUILD_BUG_ON(MSR_BE != HFLAGS_BE);
118             msr_mask |= 1 << MSR_BE;
119         }
120         if (ppc_flags & POWERPC_FLAG_SE) {
121             QEMU_BUILD_BUG_ON(MSR_SE != HFLAGS_SE);
122             msr_mask |= 1 << MSR_SE;
123         }
124     }
125 
126     if (msr_is_64bit(env, msr)) {
127         hflags |= 1 << HFLAGS_64;
128     }
129     if ((ppc_flags & POWERPC_FLAG_SPE) && (msr & (1 << MSR_SPE))) {
130         hflags |= 1 << HFLAGS_SPE;
131     }
132     if (ppc_flags & POWERPC_FLAG_VRE) {
133         QEMU_BUILD_BUG_ON(MSR_VR != HFLAGS_VR);
134         msr_mask |= 1 << MSR_VR;
135     }
136     if (ppc_flags & POWERPC_FLAG_VSX) {
137         QEMU_BUILD_BUG_ON(MSR_VSX != HFLAGS_VSX);
138         msr_mask |= 1 << MSR_VSX;
139     }
140     if ((ppc_flags & POWERPC_FLAG_TM) && (msr & (1ull << MSR_TM))) {
141         hflags |= 1 << HFLAGS_TM;
142     }
143     if (env->spr[SPR_LPCR] & LPCR_GTSE) {
144         hflags |= 1 << HFLAGS_GTSE;
145     }
146     if (env->spr[SPR_LPCR] & LPCR_HR) {
147         hflags |= 1 << HFLAGS_HR;
148     }
149 
150 #ifndef CONFIG_USER_ONLY
151     if (!env->has_hv_mode || (msr & (1ull << MSR_HV))) {
152         hflags |= 1 << HFLAGS_HV;
153     }
154 
155     /*
156      * This is our encoding for server processors. The architecture
157      * specifies that there is no such thing as userspace with
158      * translation off, however it appears that MacOS does it and some
159      * 32-bit CPUs support it. Weird...
160      *
161      *   0 = Guest User space virtual mode
162      *   1 = Guest Kernel space virtual mode
163      *   2 = Guest User space real mode
164      *   3 = Guest Kernel space real mode
165      *   4 = HV User space virtual mode
166      *   5 = HV Kernel space virtual mode
167      *   6 = HV User space real mode
168      *   7 = HV Kernel space real mode
169      *
170      * For BookE, we need 8 MMU modes as follow:
171      *
172      *  0 = AS 0 HV User space
173      *  1 = AS 0 HV Kernel space
174      *  2 = AS 1 HV User space
175      *  3 = AS 1 HV Kernel space
176      *  4 = AS 0 Guest User space
177      *  5 = AS 0 Guest Kernel space
178      *  6 = AS 1 Guest User space
179      *  7 = AS 1 Guest Kernel space
180      */
181     unsigned immu_idx, dmmu_idx;
182     dmmu_idx = msr & (1 << MSR_PR) ? 0 : 1;
183     if (env->mmu_model == POWERPC_MMU_BOOKE ||
184         env->mmu_model == POWERPC_MMU_BOOKE206) {
185         dmmu_idx |= msr & (1 << MSR_GS) ? 4 : 0;
186         immu_idx = dmmu_idx;
187         immu_idx |= msr & (1 << MSR_IS) ? 2 : 0;
188         dmmu_idx |= msr & (1 << MSR_DS) ? 2 : 0;
189     } else {
190         dmmu_idx |= msr & (1ull << MSR_HV) ? 4 : 0;
191         immu_idx = dmmu_idx;
192         immu_idx |= msr & (1 << MSR_IR) ? 0 : 2;
193         dmmu_idx |= msr & (1 << MSR_DR) ? 0 : 2;
194     }
195     hflags |= immu_idx << HFLAGS_IMMU_IDX;
196     hflags |= dmmu_idx << HFLAGS_DMMU_IDX;
197 #endif
198 
199     hflags |= hreg_compute_pmu_hflags_value(env);
200 
201     return hflags | (msr & msr_mask);
202 }
203 
204 void hreg_compute_hflags(CPUPPCState *env)
205 {
206     env->hflags = hreg_compute_hflags_value(env);
207 }
208 
209 /*
210  * This can be used as a lighter-weight alternative to hreg_compute_hflags
211  * when PMU MMCR0 or pmc_ins_cnt changes. pmc_ins_cnt is changed by
212  * pmu_update_summaries.
213  */
214 void hreg_update_pmu_hflags(CPUPPCState *env)
215 {
216     env->hflags &= ~hreg_compute_pmu_hflags_mask(env);
217     env->hflags |= hreg_compute_pmu_hflags_value(env);
218 }
219 
220 #ifdef CONFIG_DEBUG_TCG
221 void cpu_get_tb_cpu_state(CPUPPCState *env, target_ulong *pc,
222                           target_ulong *cs_base, uint32_t *flags)
223 {
224     uint32_t hflags_current = env->hflags;
225     uint32_t hflags_rebuilt;
226 
227     *pc = env->nip;
228     *cs_base = 0;
229     *flags = hflags_current;
230 
231     hflags_rebuilt = hreg_compute_hflags_value(env);
232     if (unlikely(hflags_current != hflags_rebuilt)) {
233         cpu_abort(env_cpu(env),
234                   "TCG hflags mismatch (current:0x%08x rebuilt:0x%08x)\n",
235                   hflags_current, hflags_rebuilt);
236     }
237 }
238 #endif
239 
240 void cpu_interrupt_exittb(CPUState *cs)
241 {
242     /*
243      * We don't need to worry about translation blocks
244      * unless running with TCG.
245      */
246     if (tcg_enabled()) {
247         QEMU_IOTHREAD_LOCK_GUARD();
248         cpu_interrupt(cs, CPU_INTERRUPT_EXITTB);
249     }
250 }
251 
252 int hreg_store_msr(CPUPPCState *env, target_ulong value, int alter_hv)
253 {
254     int excp;
255 #if !defined(CONFIG_USER_ONLY)
256     CPUState *cs = env_cpu(env);
257 #endif
258 
259     excp = 0;
260     value &= env->msr_mask;
261 #if !defined(CONFIG_USER_ONLY)
262     /* Neither mtmsr nor guest state can alter HV */
263     if (!alter_hv || !(env->msr & MSR_HVB)) {
264         value &= ~MSR_HVB;
265         value |= env->msr & MSR_HVB;
266     }
267     if ((value ^ env->msr) & (R_MSR_IR_MASK | R_MSR_DR_MASK)) {
268         cpu_interrupt_exittb(cs);
269     }
270     if ((env->mmu_model == POWERPC_MMU_BOOKE ||
271          env->mmu_model == POWERPC_MMU_BOOKE206) &&
272         ((value ^ env->msr) & R_MSR_GS_MASK)) {
273         cpu_interrupt_exittb(cs);
274     }
275     if (unlikely((env->flags & POWERPC_FLAG_TGPR) &&
276                  ((value ^ env->msr) & (1 << MSR_TGPR)))) {
277         /* Swap temporary saved registers with GPRs */
278         hreg_swap_gpr_tgpr(env);
279     }
280     if (unlikely((value ^ env->msr) & R_MSR_EP_MASK)) {
281         env->excp_prefix = FIELD_EX64(value, MSR, EP) * 0xFFF00000;
282     }
283     /*
284      * If PR=1 then EE, IR and DR must be 1
285      *
286      * Note: We only enforce this on 64-bit server processors.
287      * It appears that:
288      * - 32-bit implementations supports PR=1 and EE/DR/IR=0 and MacOS
289      *   exploits it.
290      * - 64-bit embedded implementations do not need any operation to be
291      *   performed when PR is set.
292      */
293     if (is_book3s_arch2x(env) && ((value >> MSR_PR) & 1)) {
294         value |= (1 << MSR_EE) | (1 << MSR_DR) | (1 << MSR_IR);
295     }
296 #endif
297     env->msr = value;
298     hreg_compute_hflags(env);
299 #if !defined(CONFIG_USER_ONLY)
300     ppc_maybe_interrupt(env);
301 
302     if (unlikely(FIELD_EX64(env->msr, MSR, POW))) {
303         if (!env->pending_interrupts && (*env->check_pow)(env)) {
304             cs->halted = 1;
305             excp = EXCP_HALTED;
306         }
307     }
308 #endif
309 
310     return excp;
311 }
312 
313 #ifdef CONFIG_SOFTMMU
314 void store_40x_sler(CPUPPCState *env, uint32_t val)
315 {
316     /* XXX: TO BE FIXED */
317     if (val != 0x00000000) {
318         cpu_abort(env_cpu(env),
319                   "Little-endian regions are not supported by now\n");
320     }
321     env->spr[SPR_405_SLER] = val;
322 }
323 #endif /* CONFIG_SOFTMMU */
324 
325 #ifndef CONFIG_USER_ONLY
326 void check_tlb_flush(CPUPPCState *env, bool global)
327 {
328     CPUState *cs = env_cpu(env);
329 
330     /* Handle global flushes first */
331     if (global && (env->tlb_need_flush & TLB_NEED_GLOBAL_FLUSH)) {
332         env->tlb_need_flush &= ~TLB_NEED_GLOBAL_FLUSH;
333         env->tlb_need_flush &= ~TLB_NEED_LOCAL_FLUSH;
334         tlb_flush_all_cpus(cs);
335         return;
336     }
337 
338     /* Then handle local ones */
339     if (env->tlb_need_flush & TLB_NEED_LOCAL_FLUSH) {
340         env->tlb_need_flush &= ~TLB_NEED_LOCAL_FLUSH;
341         tlb_flush(cs);
342     }
343 }
344 #endif
345 
346 /**
347  * _spr_register
348  *
349  * Register an SPR with all the callbacks required for tcg,
350  * and the ID number for KVM.
351  *
352  * The reason for the conditional compilation is that the tcg functions
353  * may be compiled out, and the system kvm header may not be available
354  * for supplying the ID numbers.  This is ugly, but the best we can do.
355  */
356 void _spr_register(CPUPPCState *env, int num, const char *name,
357                    USR_ARG(spr_callback *uea_read)
358                    USR_ARG(spr_callback *uea_write)
359                    SYS_ARG(spr_callback *oea_read)
360                    SYS_ARG(spr_callback *oea_write)
361                    SYS_ARG(spr_callback *hea_read)
362                    SYS_ARG(spr_callback *hea_write)
363                    KVM_ARG(uint64_t one_reg_id)
364                    target_ulong initial_value)
365 {
366     ppc_spr_t *spr = &env->spr_cb[num];
367 
368     /* No SPR should be registered twice. */
369     assert(spr->name == NULL);
370     assert(name != NULL);
371 
372     spr->name = name;
373     spr->default_value = initial_value;
374     env->spr[num] = initial_value;
375 
376 #ifdef CONFIG_TCG
377     spr->uea_read = uea_read;
378     spr->uea_write = uea_write;
379 # ifndef CONFIG_USER_ONLY
380     spr->oea_read = oea_read;
381     spr->oea_write = oea_write;
382     spr->hea_read = hea_read;
383     spr->hea_write = hea_write;
384 # endif
385 #endif
386 #ifdef CONFIG_KVM
387     spr->one_reg_id = one_reg_id;
388 #endif
389 }
390 
391 /* Generic PowerPC SPRs */
392 void register_generic_sprs(PowerPCCPU *cpu)
393 {
394     PowerPCCPUClass *pcc = POWERPC_CPU_GET_CLASS(cpu);
395     CPUPPCState *env = &cpu->env;
396 
397     /* Integer processing */
398     spr_register(env, SPR_XER, "XER",
399                  &spr_read_xer, &spr_write_xer,
400                  &spr_read_xer, &spr_write_xer,
401                  0x00000000);
402     /* Branch control */
403     spr_register(env, SPR_LR, "LR",
404                  &spr_read_lr, &spr_write_lr,
405                  &spr_read_lr, &spr_write_lr,
406                  0x00000000);
407     spr_register(env, SPR_CTR, "CTR",
408                  &spr_read_ctr, &spr_write_ctr,
409                  &spr_read_ctr, &spr_write_ctr,
410                  0x00000000);
411     /* Interrupt processing */
412     spr_register(env, SPR_SRR0, "SRR0",
413                  SPR_NOACCESS, SPR_NOACCESS,
414                  &spr_read_generic, &spr_write_generic,
415                  0x00000000);
416     spr_register(env, SPR_SRR1, "SRR1",
417                  SPR_NOACCESS, SPR_NOACCESS,
418                  &spr_read_generic, &spr_write_generic,
419                  0x00000000);
420     /* Processor control */
421     spr_register(env, SPR_SPRG0, "SPRG0",
422                  SPR_NOACCESS, SPR_NOACCESS,
423                  &spr_read_generic, &spr_write_generic,
424                  0x00000000);
425     spr_register(env, SPR_SPRG1, "SPRG1",
426                  SPR_NOACCESS, SPR_NOACCESS,
427                  &spr_read_generic, &spr_write_generic,
428                  0x00000000);
429     spr_register(env, SPR_SPRG2, "SPRG2",
430                  SPR_NOACCESS, SPR_NOACCESS,
431                  &spr_read_generic, &spr_write_generic,
432                  0x00000000);
433     spr_register(env, SPR_SPRG3, "SPRG3",
434                  SPR_NOACCESS, SPR_NOACCESS,
435                  &spr_read_generic, &spr_write_generic,
436                  0x00000000);
437 
438     spr_register(env, SPR_PVR, "PVR",
439                  /* Linux permits userspace to read PVR */
440 #if defined(CONFIG_LINUX_USER)
441                  &spr_read_generic,
442 #else
443                  SPR_NOACCESS,
444 #endif
445                  SPR_NOACCESS,
446                  &spr_read_generic, SPR_NOACCESS,
447                  pcc->pvr);
448 
449     /* Register SVR if it's defined to anything else than POWERPC_SVR_NONE */
450     if (pcc->svr != POWERPC_SVR_NONE) {
451         if (pcc->svr & POWERPC_SVR_E500) {
452             spr_register(env, SPR_E500_SVR, "SVR",
453                          SPR_NOACCESS, SPR_NOACCESS,
454                          &spr_read_generic, SPR_NOACCESS,
455                          pcc->svr & ~POWERPC_SVR_E500);
456         } else {
457             spr_register(env, SPR_SVR, "SVR",
458                          SPR_NOACCESS, SPR_NOACCESS,
459                          &spr_read_generic, SPR_NOACCESS,
460                          pcc->svr);
461         }
462     }
463 
464     /* Time base */
465     spr_register(env, SPR_VTBL,  "TBL",
466                  &spr_read_tbl, SPR_NOACCESS,
467                  &spr_read_tbl, SPR_NOACCESS,
468                  0x00000000);
469     spr_register(env, SPR_TBL,   "TBL",
470                  &spr_read_tbl, SPR_NOACCESS,
471                  &spr_read_tbl, &spr_write_tbl,
472                  0x00000000);
473     spr_register(env, SPR_VTBU,  "TBU",
474                  &spr_read_tbu, SPR_NOACCESS,
475                  &spr_read_tbu, SPR_NOACCESS,
476                  0x00000000);
477     spr_register(env, SPR_TBU,   "TBU",
478                  &spr_read_tbu, SPR_NOACCESS,
479                  &spr_read_tbu, &spr_write_tbu,
480                  0x00000000);
481 }
482 
483 void register_non_embedded_sprs(CPUPPCState *env)
484 {
485     /* Exception processing */
486     spr_register_kvm(env, SPR_DSISR, "DSISR",
487                      SPR_NOACCESS, SPR_NOACCESS,
488                      &spr_read_generic, &spr_write_generic32,
489                      KVM_REG_PPC_DSISR, 0x00000000);
490     spr_register_kvm(env, SPR_DAR, "DAR",
491                      SPR_NOACCESS, SPR_NOACCESS,
492                      &spr_read_generic, &spr_write_generic,
493                      KVM_REG_PPC_DAR, 0x00000000);
494     /* Timer */
495     spr_register(env, SPR_DECR, "DECR",
496                  SPR_NOACCESS, SPR_NOACCESS,
497                  &spr_read_decr, &spr_write_decr,
498                  0x00000000);
499 }
500 
501 /* Storage Description Register 1 */
502 void register_sdr1_sprs(CPUPPCState *env)
503 {
504 #ifndef CONFIG_USER_ONLY
505     if (env->has_hv_mode) {
506         /*
507          * SDR1 is a hypervisor resource on CPUs which have a
508          * hypervisor mode
509          */
510         spr_register_hv(env, SPR_SDR1, "SDR1",
511                         SPR_NOACCESS, SPR_NOACCESS,
512                         SPR_NOACCESS, SPR_NOACCESS,
513                         &spr_read_generic, &spr_write_sdr1,
514                         0x00000000);
515     } else {
516         spr_register(env, SPR_SDR1, "SDR1",
517                      SPR_NOACCESS, SPR_NOACCESS,
518                      &spr_read_generic, &spr_write_sdr1,
519                      0x00000000);
520     }
521 #endif
522 }
523 
524 /* BATs 0-3 */
525 void register_low_BATs(CPUPPCState *env)
526 {
527 #if !defined(CONFIG_USER_ONLY)
528     spr_register(env, SPR_IBAT0U, "IBAT0U",
529                  SPR_NOACCESS, SPR_NOACCESS,
530                  &spr_read_ibat, &spr_write_ibatu,
531                  0x00000000);
532     spr_register(env, SPR_IBAT0L, "IBAT0L",
533                  SPR_NOACCESS, SPR_NOACCESS,
534                  &spr_read_ibat, &spr_write_ibatl,
535                  0x00000000);
536     spr_register(env, SPR_IBAT1U, "IBAT1U",
537                  SPR_NOACCESS, SPR_NOACCESS,
538                  &spr_read_ibat, &spr_write_ibatu,
539                  0x00000000);
540     spr_register(env, SPR_IBAT1L, "IBAT1L",
541                  SPR_NOACCESS, SPR_NOACCESS,
542                  &spr_read_ibat, &spr_write_ibatl,
543                  0x00000000);
544     spr_register(env, SPR_IBAT2U, "IBAT2U",
545                  SPR_NOACCESS, SPR_NOACCESS,
546                  &spr_read_ibat, &spr_write_ibatu,
547                  0x00000000);
548     spr_register(env, SPR_IBAT2L, "IBAT2L",
549                  SPR_NOACCESS, SPR_NOACCESS,
550                  &spr_read_ibat, &spr_write_ibatl,
551                  0x00000000);
552     spr_register(env, SPR_IBAT3U, "IBAT3U",
553                  SPR_NOACCESS, SPR_NOACCESS,
554                  &spr_read_ibat, &spr_write_ibatu,
555                  0x00000000);
556     spr_register(env, SPR_IBAT3L, "IBAT3L",
557                  SPR_NOACCESS, SPR_NOACCESS,
558                  &spr_read_ibat, &spr_write_ibatl,
559                  0x00000000);
560     spr_register(env, SPR_DBAT0U, "DBAT0U",
561                  SPR_NOACCESS, SPR_NOACCESS,
562                  &spr_read_dbat, &spr_write_dbatu,
563                  0x00000000);
564     spr_register(env, SPR_DBAT0L, "DBAT0L",
565                  SPR_NOACCESS, SPR_NOACCESS,
566                  &spr_read_dbat, &spr_write_dbatl,
567                  0x00000000);
568     spr_register(env, SPR_DBAT1U, "DBAT1U",
569                  SPR_NOACCESS, SPR_NOACCESS,
570                  &spr_read_dbat, &spr_write_dbatu,
571                  0x00000000);
572     spr_register(env, SPR_DBAT1L, "DBAT1L",
573                  SPR_NOACCESS, SPR_NOACCESS,
574                  &spr_read_dbat, &spr_write_dbatl,
575                  0x00000000);
576     spr_register(env, SPR_DBAT2U, "DBAT2U",
577                  SPR_NOACCESS, SPR_NOACCESS,
578                  &spr_read_dbat, &spr_write_dbatu,
579                  0x00000000);
580     spr_register(env, SPR_DBAT2L, "DBAT2L",
581                  SPR_NOACCESS, SPR_NOACCESS,
582                  &spr_read_dbat, &spr_write_dbatl,
583                  0x00000000);
584     spr_register(env, SPR_DBAT3U, "DBAT3U",
585                  SPR_NOACCESS, SPR_NOACCESS,
586                  &spr_read_dbat, &spr_write_dbatu,
587                  0x00000000);
588     spr_register(env, SPR_DBAT3L, "DBAT3L",
589                  SPR_NOACCESS, SPR_NOACCESS,
590                  &spr_read_dbat, &spr_write_dbatl,
591                  0x00000000);
592     env->nb_BATs += 4;
593 #endif
594 }
595 
596 /* BATs 4-7 */
597 void register_high_BATs(CPUPPCState *env)
598 {
599 #if !defined(CONFIG_USER_ONLY)
600     spr_register(env, SPR_IBAT4U, "IBAT4U",
601                  SPR_NOACCESS, SPR_NOACCESS,
602                  &spr_read_ibat_h, &spr_write_ibatu_h,
603                  0x00000000);
604     spr_register(env, SPR_IBAT4L, "IBAT4L",
605                  SPR_NOACCESS, SPR_NOACCESS,
606                  &spr_read_ibat_h, &spr_write_ibatl_h,
607                  0x00000000);
608     spr_register(env, SPR_IBAT5U, "IBAT5U",
609                  SPR_NOACCESS, SPR_NOACCESS,
610                  &spr_read_ibat_h, &spr_write_ibatu_h,
611                  0x00000000);
612     spr_register(env, SPR_IBAT5L, "IBAT5L",
613                  SPR_NOACCESS, SPR_NOACCESS,
614                  &spr_read_ibat_h, &spr_write_ibatl_h,
615                  0x00000000);
616     spr_register(env, SPR_IBAT6U, "IBAT6U",
617                  SPR_NOACCESS, SPR_NOACCESS,
618                  &spr_read_ibat_h, &spr_write_ibatu_h,
619                  0x00000000);
620     spr_register(env, SPR_IBAT6L, "IBAT6L",
621                  SPR_NOACCESS, SPR_NOACCESS,
622                  &spr_read_ibat_h, &spr_write_ibatl_h,
623                  0x00000000);
624     spr_register(env, SPR_IBAT7U, "IBAT7U",
625                  SPR_NOACCESS, SPR_NOACCESS,
626                  &spr_read_ibat_h, &spr_write_ibatu_h,
627                  0x00000000);
628     spr_register(env, SPR_IBAT7L, "IBAT7L",
629                  SPR_NOACCESS, SPR_NOACCESS,
630                  &spr_read_ibat_h, &spr_write_ibatl_h,
631                  0x00000000);
632     spr_register(env, SPR_DBAT4U, "DBAT4U",
633                  SPR_NOACCESS, SPR_NOACCESS,
634                  &spr_read_dbat_h, &spr_write_dbatu_h,
635                  0x00000000);
636     spr_register(env, SPR_DBAT4L, "DBAT4L",
637                  SPR_NOACCESS, SPR_NOACCESS,
638                  &spr_read_dbat_h, &spr_write_dbatl_h,
639                  0x00000000);
640     spr_register(env, SPR_DBAT5U, "DBAT5U",
641                  SPR_NOACCESS, SPR_NOACCESS,
642                  &spr_read_dbat_h, &spr_write_dbatu_h,
643                  0x00000000);
644     spr_register(env, SPR_DBAT5L, "DBAT5L",
645                  SPR_NOACCESS, SPR_NOACCESS,
646                  &spr_read_dbat_h, &spr_write_dbatl_h,
647                  0x00000000);
648     spr_register(env, SPR_DBAT6U, "DBAT6U",
649                  SPR_NOACCESS, SPR_NOACCESS,
650                  &spr_read_dbat_h, &spr_write_dbatu_h,
651                  0x00000000);
652     spr_register(env, SPR_DBAT6L, "DBAT6L",
653                  SPR_NOACCESS, SPR_NOACCESS,
654                  &spr_read_dbat_h, &spr_write_dbatl_h,
655                  0x00000000);
656     spr_register(env, SPR_DBAT7U, "DBAT7U",
657                  SPR_NOACCESS, SPR_NOACCESS,
658                  &spr_read_dbat_h, &spr_write_dbatu_h,
659                  0x00000000);
660     spr_register(env, SPR_DBAT7L, "DBAT7L",
661                  SPR_NOACCESS, SPR_NOACCESS,
662                  &spr_read_dbat_h, &spr_write_dbatl_h,
663                  0x00000000);
664     env->nb_BATs += 4;
665 #endif
666 }
667 
668 /* Softare table search registers */
669 void register_6xx_7xx_soft_tlb(CPUPPCState *env, int nb_tlbs, int nb_ways)
670 {
671 #if !defined(CONFIG_USER_ONLY)
672     env->nb_tlb = nb_tlbs;
673     env->nb_ways = nb_ways;
674     env->id_tlbs = 1;
675     env->tlb_type = TLB_6XX;
676     spr_register(env, SPR_DMISS, "DMISS",
677                  SPR_NOACCESS, SPR_NOACCESS,
678                  &spr_read_generic, SPR_NOACCESS,
679                  0x00000000);
680     spr_register(env, SPR_DCMP, "DCMP",
681                  SPR_NOACCESS, SPR_NOACCESS,
682                  &spr_read_generic, SPR_NOACCESS,
683                  0x00000000);
684     spr_register(env, SPR_HASH1, "HASH1",
685                  SPR_NOACCESS, SPR_NOACCESS,
686                  &spr_read_generic, SPR_NOACCESS,
687                  0x00000000);
688     spr_register(env, SPR_HASH2, "HASH2",
689                  SPR_NOACCESS, SPR_NOACCESS,
690                  &spr_read_generic, SPR_NOACCESS,
691                  0x00000000);
692     spr_register(env, SPR_IMISS, "IMISS",
693                  SPR_NOACCESS, SPR_NOACCESS,
694                  &spr_read_generic, SPR_NOACCESS,
695                  0x00000000);
696     spr_register(env, SPR_ICMP, "ICMP",
697                  SPR_NOACCESS, SPR_NOACCESS,
698                  &spr_read_generic, SPR_NOACCESS,
699                  0x00000000);
700     spr_register(env, SPR_RPA, "RPA",
701                  SPR_NOACCESS, SPR_NOACCESS,
702                  &spr_read_generic, &spr_write_generic,
703                  0x00000000);
704 #endif
705 }
706 
707 void register_thrm_sprs(CPUPPCState *env)
708 {
709     /* Thermal management */
710     spr_register(env, SPR_THRM1, "THRM1",
711                  SPR_NOACCESS, SPR_NOACCESS,
712                  &spr_read_thrm, &spr_write_generic,
713                  0x00000000);
714 
715     spr_register(env, SPR_THRM2, "THRM2",
716                  SPR_NOACCESS, SPR_NOACCESS,
717                  &spr_read_thrm, &spr_write_generic,
718                  0x00000000);
719 
720     spr_register(env, SPR_THRM3, "THRM3",
721                  SPR_NOACCESS, SPR_NOACCESS,
722                  &spr_read_thrm, &spr_write_generic,
723                  0x00000000);
724 }
725 
726 void register_usprgh_sprs(CPUPPCState *env)
727 {
728     spr_register(env, SPR_USPRG4, "USPRG4",
729                  &spr_read_ureg, SPR_NOACCESS,
730                  &spr_read_ureg, SPR_NOACCESS,
731                  0x00000000);
732     spr_register(env, SPR_USPRG5, "USPRG5",
733                  &spr_read_ureg, SPR_NOACCESS,
734                  &spr_read_ureg, SPR_NOACCESS,
735                  0x00000000);
736     spr_register(env, SPR_USPRG6, "USPRG6",
737                  &spr_read_ureg, SPR_NOACCESS,
738                  &spr_read_ureg, SPR_NOACCESS,
739                  0x00000000);
740     spr_register(env, SPR_USPRG7, "USPRG7",
741                  &spr_read_ureg, SPR_NOACCESS,
742                  &spr_read_ureg, SPR_NOACCESS,
743                  0x00000000);
744 }
745