From 20f5ee26366d5d03115112636b80a685a25a30c0 Mon Sep 17 00:00:00 2001 From: Miod Vallat Date: Sat, 24 Jan 2004 21:10:34 +0000 Subject: Preserve SPRG0-SPRG3 around BUG calls, as required in the PPC1Bug UM; reminded by drahn@, thanks! --- sys/arch/mvmeppc/dev/bugio.c | 78 +++++++++++++++++++++++++++++++++----- sys/arch/mvmeppc/include/bugio.h | 4 +- sys/arch/mvmeppc/include/prom.h | 6 +-- sys/arch/mvmeppc/mvmeppc/machdep.c | 7 ++-- 4 files changed, 75 insertions(+), 20 deletions(-) (limited to 'sys') diff --git a/sys/arch/mvmeppc/dev/bugio.c b/sys/arch/mvmeppc/dev/bugio.c index 7986e25dba7..d3ee34ca413 100644 --- a/sys/arch/mvmeppc/dev/bugio.c +++ b/sys/arch/mvmeppc/dev/bugio.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bugio.c,v 1.3 2002/06/08 15:48:01 miod Exp $ */ +/* $OpenBSD: bugio.c,v 1.4 2004/01/24 21:10:29 miod Exp $ */ /* * bug routines -- assumes that the necessary sections of memory @@ -13,16 +13,54 @@ int bugenvsz(void); +/* + * BUG register preserving + */ + +register_t sprg0, sprg1, sprg2, sprg3; +register_t bugsprg3; + +#define BUGCTXT() \ + do { \ + sprg0 = ppc_mfsprg0(); \ + sprg1 = ppc_mfsprg1(); \ + sprg2 = ppc_mfsprg2(); \ + sprg3 = ppc_mfsprg3(); \ + ppc_mtsprg3(bugsprg3); \ + } while (0) + +#define OSCTXT() \ + do { \ + ppc_mtsprg0(sprg0); \ + ppc_mtsprg1(sprg1); \ + ppc_mtsprg2(sprg2); \ + ppc_mtsprg3(sprg3); \ + } while (0) + +/* Invoke the BUG */ +#define MVMEPROM_CALL(x) \ + __asm__ __volatile__ ( __CONCAT("addi %r10,%r0,",__STRING(x)) ); \ + __asm__ __volatile__ ("sc"); + +void +buginit() +{ + bugsprg3 = ppc_mfsprg3(); +} + + /* BUG - query board routines */ void mvmeprom_brdid(id) struct mvmeprom_brdid *id; { unsigned long omsr = ppc_get_msr(); - ppc_set_msr(((omsr | PSL_IP) &~ PSL_EE)); + BUGCTXT(); + ppc_set_msr(((omsr | PSL_IP) &~ PSL_EE)); MVMEPROM_CALL(MVMEPROM_BRD_ID); asm volatile ("mr %0, 3": "=r" (id):); + OSCTXT(); ppc_set_msr(omsr); } @@ -32,10 +70,12 @@ mvmeprom_getchar() { int ret; unsigned long omsr = ppc_get_msr(); - ppc_set_msr(((omsr | PSL_IP) &~ PSL_EE)); + BUGCTXT(); + ppc_set_msr(((omsr | PSL_IP) &~ PSL_EE)); MVMEPROM_CALL(MVMEPROM_INCHR); asm volatile ("mr %0, 3" : "=r" (ret)); + OSCTXT(); ppc_set_msr(omsr); return ret; } @@ -46,10 +86,12 @@ mvmeprom_instat() { int ret; unsigned long omsr = ppc_get_msr(); - ppc_set_msr(((omsr | PSL_IP) &~ PSL_EE)); + BUGCTXT(); + ppc_set_msr(((omsr | PSL_IP) &~ PSL_EE)); MVMEPROM_CALL(MVMEPROM_INSTAT); asm volatile ("mr %0, 3" : "=r" (ret)); + OSCTXT(); ppc_set_msr(omsr); return (!(ret & 0x4)); } @@ -59,10 +101,13 @@ mvmeprom_outln(start, end) char *start, *end; { unsigned long omsr = ppc_get_msr(); + + BUGCTXT(); ppc_set_msr(((omsr | PSL_IP) &~ PSL_EE)); asm volatile ("mr 3, %0": : "r" (start)); asm volatile ("mr 4, %0": : "r" (end)); MVMEPROM_CALL(MVMEPROM_OUTLN); + OSCTXT(); ppc_set_msr(omsr); } @@ -71,10 +116,13 @@ mvmeprom_outstr(start, end) char *start, *end; { unsigned long omsr = ppc_get_msr(); + + BUGCTXT(); ppc_set_msr(((omsr | PSL_IP) &~ PSL_EE)); asm volatile ("mr 3, %0": : "r" (start)); asm volatile ("mr 4, %0": : "r" (end)); MVMEPROM_CALL(MVMEPROM_OUTSTR); + OSCTXT(); ppc_set_msr(omsr); } @@ -83,9 +131,12 @@ mvmeprom_outchar(c) int c; { unsigned long omsr = ppc_get_msr(); + + BUGCTXT(); ppc_set_msr(((omsr | PSL_IP) &~ PSL_EE)); asm volatile ("mr 3, %0" :: "r" (c)); MVMEPROM_CALL(MVMEPROM_OUTCHR); + OSCTXT(); ppc_set_msr(omsr); } @@ -94,8 +145,11 @@ void mvmeprom_return() { unsigned long omsr = ppc_get_msr(); + + BUGCTXT(); ppc_set_msr(((omsr | PSL_IP) &~ PSL_EE)); MVMEPROM_CALL(MVMEPROM_RETURN); + OSCTXT(); ppc_set_msr(omsr); /*NOTREACHED*/ } @@ -109,6 +163,7 @@ mvmeprom_rtc_rd(ptime) ppc_set_msr(((omsr | PSL_IP) &~ PSL_EE)); asm volatile ("mr 3, %0": : "r" (ptime)); MVMEPROM_CALL(MVMEPROM_RTC_RD); + OSCTXT(); ppc_set_msr(omsr); } @@ -119,13 +174,15 @@ bugenvsz(void) char tmp[1]; void *ptr = tmp; unsigned long omsr = ppc_get_msr(); + + BUGCTXT(); ppc_set_msr(((omsr | PSL_IP) &~ PSL_EE)); - asm volatile ("mr 3, %0": : "r" (ptr)); asm volatile ("li 5, 0x1"); asm volatile ("li 5, 0x0"); /* get size */ MVMEPROM_CALL(MVMEPROM_ENVIRON); asm volatile ("mr %0, 3" : "=r" (ret)); + OSCTXT(); ppc_set_msr(omsr); return(ret); @@ -189,7 +246,6 @@ mvmeprom_envrd(void) int env_size = 0; int pkt_typ, pkt_len; unsigned long omsr = ppc_get_msr(); - ppc_set_msr(((omsr | PSL_IP) &~ PSL_EE)); env_size = bugenvsz(); bzero(&bugenviron, sizeof(struct bugenviron)); @@ -198,16 +254,19 @@ mvmeprom_envrd(void) if (ptr != NULL) { + ppc_set_msr(((omsr | PSL_IP) &~ PSL_EE)); + BUGCTXT(); asm volatile ("mr 3, %0": : "r" (ptr)); asm volatile ("mr 4, %0": : "r" (env_size)); asm volatile ("li 5, 0x2"); MVMEPROM_CALL(MVMEPROM_ENVIRON); asm volatile ("mr %0, 3" : "=r" (ret)); + OSCTXT(); + ppc_set_msr(omsr); - if (ret) { /* scram if we have an error */ - ppc_set_msr(omsr); + if (ret) return NULL; - } + ptr_end = ptr + env_size; while (ptr <= ptr_end) { pkt_typ = *ptr++; @@ -258,6 +317,5 @@ mvmeprom_envrd(void) ptr += pkt_len; } } - ppc_set_msr(omsr); return NULL; } diff --git a/sys/arch/mvmeppc/include/bugio.h b/sys/arch/mvmeppc/include/bugio.h index 09eb7c6bd84..22fbaea125d 100644 --- a/sys/arch/mvmeppc/include/bugio.h +++ b/sys/arch/mvmeppc/include/bugio.h @@ -1,4 +1,4 @@ -/* $OpenBSD: bugio.h,v 1.2 2003/04/16 17:34:50 miod Exp $ */ +/* $OpenBSD: bugio.h,v 1.3 2004/01/24 21:10:31 miod Exp $ */ /* * Copyright (c) 2002, Miodrag Vallat. * All rights reserved. @@ -42,4 +42,6 @@ void mvmeprom_return(void); void mvmeprom_rtc_rd(struct mvmeprom_time *); struct bugenviron *mvmeprom_envrd(void); +void buginit(void); + #endif /* _MACHINE_BUGIO_H_ */ diff --git a/sys/arch/mvmeppc/include/prom.h b/sys/arch/mvmeppc/include/prom.h index 89403f4b56a..a089e625db2 100644 --- a/sys/arch/mvmeppc/include/prom.h +++ b/sys/arch/mvmeppc/include/prom.h @@ -1,4 +1,4 @@ -/* $OpenBSD: prom.h,v 1.4 2003/06/02 07:07:25 deraadt Exp $ */ +/* $OpenBSD: prom.h,v 1.5 2004/01/24 21:10:31 miod Exp $ */ /* * Copyright (c) 2001 Steve Murphree, Jr. * All rights reserved. @@ -350,10 +350,6 @@ struct mvmeprom_args { #endif -#define MVMEPROM_CALL(x) \ - __asm__ __volatile__ ( __CONCAT("addi 10,0,",__STRING(x)) ); \ - __asm__ __volatile__ ("sc"); - #define MVMEPROM_REG_CTRLLUN "3" #define MVMEPROM_REG_DEVLUN "4" #define MVMEPROM_REG_SCSUPP "5" diff --git a/sys/arch/mvmeppc/mvmeppc/machdep.c b/sys/arch/mvmeppc/mvmeppc/machdep.c index 84590a2efe0..78c13a4532a 100644 --- a/sys/arch/mvmeppc/mvmeppc/machdep.c +++ b/sys/arch/mvmeppc/mvmeppc/machdep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: machdep.c,v 1.38 2004/01/23 10:40:01 miod Exp $ */ +/* $OpenBSD: machdep.c,v 1.39 2004/01/24 21:10:33 miod Exp $ */ /* $NetBSD: machdep.c,v 1.4 1996/10/16 19:33:11 ws Exp $ */ /* @@ -57,6 +57,7 @@ #include #include +#include #include #include #include @@ -186,7 +187,6 @@ initppc(startkernel, endkernel, args) extern caddr_t ddblow, ddbsize; #endif extern void consinit(void); - extern void callback(void *); extern void *msgbuf_addr; int exc, scratch; @@ -194,6 +194,7 @@ initppc(startkernel, endkernel, args) bzero(proc0.p_addr, sizeof *proc0.p_addr); fw = &ppc1_firmware; /* Just PPC1-Bug for now... */ + buginit(); curpcb = &proc0paddr->u_pcb; @@ -528,9 +529,7 @@ cpu_startup() * Allocate a submap for exec arguments. This map effectively * limits the number of processes exec'ing at any time. */ -#if 1 minaddr = vm_map_min(kernel_map); -#endif exec_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr, 16 * NCARGS, VM_MAP_PAGEABLE, FALSE, NULL); -- cgit v1.2.3