summaryrefslogtreecommitdiffstats
path: root/sys/powerpc/aim/ofw_machdep.c
diff options
context:
space:
mode:
authorgrehan <grehan@FreeBSD.org>2005-10-30 21:29:59 +0000
committergrehan <grehan@FreeBSD.org>2005-10-30 21:29:59 +0000
commit7d06f79e600999d829bd8331f5e724190cf0bc42 (patch)
tree971aa25d14f57ed82614d1b341236a5efc684c08 /sys/powerpc/aim/ofw_machdep.c
parent3b37508b0e27e0b27bd3627de056d0c18386a6b5 (diff)
downloadFreeBSD-src-7d06f79e600999d829bd8331f5e724190cf0bc42.zip
FreeBSD-src-7d06f79e600999d829bd8331f5e724190cf0bc42.tar.gz
Copy SPRG0-3 registers at boot-time and restore when calling into
OpenFirmware. FreeBSD/ppc uses SPRG0 as the per-cpu data area pointer, and SPRG1-3 as temporary registers during exception handling. There have been a few instances where OpenFirmware does require these to be part of it's context, such as cd-booting an eMac. reported by: many MFC after: 3 days
Diffstat (limited to 'sys/powerpc/aim/ofw_machdep.c')
-rw-r--r--sys/powerpc/aim/ofw_machdep.c50
1 files changed, 46 insertions, 4 deletions
diff --git a/sys/powerpc/aim/ofw_machdep.c b/sys/powerpc/aim/ofw_machdep.c
index b4c97a2..7475929 100644
--- a/sys/powerpc/aim/ofw_machdep.c
+++ b/sys/powerpc/aim/ofw_machdep.c
@@ -59,12 +59,50 @@ __FBSDID("$FreeBSD$");
static struct mem_region OFmem[OFMEM_REGIONS + 1], OFavail[OFMEM_REGIONS + 3];
static struct mem_region OFfree[OFMEM_REGIONS + 3];
-extern long ofmsr;
+extern register_t ofmsr[5];
+extern struct pcpu __pcpu[MAXCPU];
extern struct pmap ofw_pmap;
extern int pmap_bootstrapped;
static int (*ofwcall)(void *);
/*
+ * Saved SPRG0-3 from OpenFirmware. Will be restored prior to the callback.
+ */
+register_t ofw_sprg0_save;
+
+static __inline void
+ofw_sprg_prepare(void)
+{
+ /*
+ * Assume that interrupt are disabled at this point, or
+ * SPRG1-3 could be trashed
+ */
+ __asm __volatile("mfsprg0 %0\n\t"
+ "mtsprg0 %1\n\t"
+ "mtsprg1 %2\n\t"
+ "mtsprg2 %3\n\t"
+ "mtsprg3 %4\n\t"
+ : "=&r"(ofw_sprg0_save)
+ : "r"(ofmsr[1]),
+ "r"(ofmsr[2]),
+ "r"(ofmsr[3]),
+ "r"(ofmsr[4]));
+}
+
+static __inline void
+ofw_sprg_restore(void)
+{
+ /*
+ * Note that SPRG1-3 contents are irrelevant. They are scratch
+ * registers used in the early portion of trap handling when
+ * interrupts are disabled.
+ *
+ * PCPU data cannot be used until this routine is called !
+ */
+ __asm __volatile("mtsprg0 %0" :: "r"(ofw_sprg0_save));
+}
+
+/*
* Memory region utilities: determine if two regions overlap,
* and merge two overlapping regions into one
*/
@@ -173,9 +211,11 @@ openfirmware(void *args)
"mtmsr %1\n\t"
"isync\n"
: "=r" (oldmsr)
- : "r" (ofmsr)
+ : "r" (ofmsr[0])
);
+ ofw_sprg_prepare();
+
if (pmap_bootstrapped) {
/*
* Swap the kernel's address space with Open Firmware's
@@ -192,8 +232,8 @@ openfirmware(void *args)
"mtdbatu 3, %0" : : "r" (0));
isync();
}
-
- result = ofwcall(args);
+
+ result = ofwcall(args);
if (pmap_bootstrapped) {
/*
@@ -207,6 +247,8 @@ openfirmware(void *args)
}
}
+ ofw_sprg_restore();
+
__asm( "\t"
"mtmsr %0\n\t"
"isync\n"
OpenPOWER on IntegriCloud