xref: /netbsd-src/sys/arch/powerpc/powerpc/setfault.S (revision 16031f7d46f56c21335839c17974dddd9f9800b4)
1/*	$NetBSD: setfault.S,v 1.10 2020/07/06 09:34:18 rin Exp $	*/
2
3/*
4 * Copyright (c) 2001 Wasabi Systems, Inc.
5 * All rights reserved.
6 *
7 * Written by Eduardo Horvath and Simon Burge for Wasabi Systems, Inc.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 *    notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 *    notice, this list of conditions and the following disclaimer in the
16 *    documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 *    must display the following acknowledgement:
19 *	This product includes software developed for the NetBSD Project by
20 *	Wasabi Systems, Inc.
21 * 4. The name of Wasabi Systems, Inc. may not be used to endorse
22 *    or promote products derived from this software without specific prior
23 *    written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
29 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE.
36 */
37
38/*
39 * Copyright (C) 1995, 1996 Wolfgang Solfrank.
40 * Copyright (C) 1995, 1996 TooLs GmbH.
41 * All rights reserved.
42 *
43 * Redistribution and use in source and binary forms, with or without
44 * modification, are permitted provided that the following conditions
45 * are met:
46 * 1. Redistributions of source code must retain the above copyright
47 *    notice, this list of conditions and the following disclaimer.
48 * 2. Redistributions in binary form must reproduce the above copyright
49 *    notice, this list of conditions and the following disclaimer in the
50 *    documentation and/or other materials provided with the distribution.
51 * 3. All advertising materials mentioning features or use of this software
52 *    must display the following acknowledgement:
53 *	This product includes software developed by TooLs GmbH.
54 * 4. The name of TooLs GmbH may not be used to endorse or promote products
55 *    derived from this software without specific prior written permission.
56 *
57 * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
58 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
59 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
60 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
61 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
62 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
63 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
64 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
65 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
66 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
67 */
68
69#include "assym.h"
70
71#ifdef _KERNEL_OPT
72#include "opt_ppcarch.h"
73#endif
74
75#include <machine/asm.h>
76#include <machine/psl.h>
77
78/* LINTSTUB: include <sys/param.h> */
79/* LINTSTUB: include <sys/types.h> */
80/* LINTSTUB: include <machine/reg.h> */
81/* LINTSTUB: include <machine/pcb.h> */
82/* LINTSTUB: Func: int setfault(struct faultbuf *fb); */
83
84/*
85 * int setfault(faultbuf_t *)
86 *
87 * Similar to setjmp to setup for handling faults on accesses to user memory.
88 * Any routine using this may only call bcopy, either the form below,
89 * or the (currently used) C code optimized, so it doesn't use any non-volatile
90 * registers.
91 */
92	.globl	_C_LABEL(setfault)
93_C_LABEL(setfault):
94	mflr	%r11
95	mfcr	%r12
96	GET_CPUINFO(%r4)
97	ldptr	%r4,CI_CURPCB(%r4)
98	stptr	%r3,PCB_ONFAULT(%r4)
99	streg	%r1,FB_SP(%r3)			/* SP (R1) */
100	streg	%r2,FB_R2(%r3)			/* why?? */
101#ifdef PPC_BOOKE
102	mfmsr	%r10
103	andi.	%r0,%r10,PSL_PR@l
104	twnei	%r0,0
105	stmw	%r10,FB_MSR(%r3)		/* MSR, LR, CR, R13-R31 */
106#else
107	streg	%r11,FB_PC(%r3)			/* LR */
108	streg	%r12,FB_CR(%r3)			/* CR */
109	streg	%r13,FB_R13(%r3)		/* R13-R31 */
110	streg	%r14,FB_R14(%r3)
111	streg	%r15,FB_R15(%r3)
112	streg	%r16,FB_R16(%r3)
113	streg	%r17,FB_R17(%r3)
114	streg	%r18,FB_R18(%r3)
115	streg	%r19,FB_R19(%r3)
116	streg	%r20,FB_R20(%r3)
117	streg	%r21,FB_R21(%r3)
118	streg	%r22,FB_R22(%r3)
119	streg	%r23,FB_R23(%r3)
120	streg	%r24,FB_R24(%r3)
121	streg	%r25,FB_R25(%r3)
122	streg	%r26,FB_R26(%r3)
123	streg	%r27,FB_R27(%r3)
124	streg	%r28,FB_R28(%r3)
125	streg	%r29,FB_R29(%r3)
126	streg	%r30,FB_R30(%r3)
127	streg	%r31,FB_R31(%r3)
128#endif
129	li	%r3,0
130	blr
131