From 7d06f79e600999d829bd8331f5e724190cf0bc42 Mon Sep 17 00:00:00 2001 From: grehan Date: Sun, 30 Oct 2005 21:29:59 +0000 Subject: 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 --- sys/powerpc/aim/locore.S | 15 ++++++++++--- sys/powerpc/aim/ofw_machdep.c | 50 +++++++++++++++++++++++++++++++++++++++---- 2 files changed, 58 insertions(+), 7 deletions(-) (limited to 'sys/powerpc/aim') diff --git a/sys/powerpc/aim/locore.S b/sys/powerpc/aim/locore.S index f4a2379..1a3c0bb 100644 --- a/sys/powerpc/aim/locore.S +++ b/sys/powerpc/aim/locore.S @@ -81,7 +81,7 @@ GLOBAL(esym) .long 0 /* end of symbol table */ GLOBAL(ofmsr) - .long 0 /* msr used in Open Firmware */ + .long 0, 0, 0, 0, 0 /* msr/sprg0-3 used in Open Firmware */ GLOBAL(powersave) .long 0 @@ -154,8 +154,17 @@ __start: mfmsr 0 lis 9,ofmsr@ha - stw 0,ofmsr@l(9) - + stwu 0,ofmsr@l(9) + + mfsprg0 0 /* save SPRG0-3 */ + stw 0,4(9) /* ofmsr[1] = sprg0 */ + mfsprg1 0 + stw 0,8(9) /* ofmsr[2] = sprg1 */ + mfsprg2 0 + stw 0,12(9) /* ofmsr[3] = sprg2 */ + mfsprg3 0 + stw 0,16(9) /* ofmsr[4] = sprg3 */ + bl OF_init lis 4,end@ha 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" -- cgit v1.1