xref: /f-stack/freebsd/mips/include/pcb.h (revision 22ce4aff)
1 /*	$OpenBSD: pcb.h,v 1.3 1998/09/15 10:50:12 pefo Exp $	*/
2 
3 /*-
4  * SPDX-License-Identifier: BSD-3-Clause
5  *
6  * Copyright (c) 1988 University of Utah.
7  * Copyright (c) 1992, 1993
8  *	The Regents of the University of California.  All rights reserved.
9  *
10  * This code is derived from software contributed to Berkeley by
11  * the Systems Programming Group of the University of Utah Computer
12  * Science Department and Ralph Campbell.
13  *
14  * Redistribution and use in source and binary forms, with or without
15  * modification, are permitted provided that the following conditions
16  * are met:
17  * 1. Redistributions of source code must retain the above copyright
18  *    notice, this list of conditions and the following disclaimer.
19  * 2. Redistributions in binary form must reproduce the above copyright
20  *    notice, this list of conditions and the following disclaimer in the
21  *    documentation and/or other materials provided with the distribution.
22  * 3. Neither the name of the University nor the names of its contributors
23  *    may be used to endorse or promote products derived from this software
24  *    without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36  * SUCH DAMAGE.
37  *
38  *	from: Utah Hdr: pcb.h 1.13 89/04/23
39  *	from: @(#)pcb.h 8.1 (Berkeley) 6/10/93
40  *	JNPR: pcb.h,v 1.2 2006/08/07 11:51:17 katta
41  * $FreeBSD$
42  */
43 
44 #ifndef _MACHINE_PCB_H_
45 #define	_MACHINE_PCB_H_
46 
47 /*
48  * used by switch.S
49  */
50 #define	PCB_REG_S0	0
51 #define	PCB_REG_S1	1
52 #define	PCB_REG_S2	2
53 #define	PCB_REG_S3	3
54 #define	PCB_REG_S4	4
55 #define	PCB_REG_S5	5
56 #define	PCB_REG_S6	6
57 #define	PCB_REG_S7	7
58 #define	PCB_REG_SP	8
59 #define	PCB_REG_S8	9
60 #define	PCB_REG_RA	10
61 #define	PCB_REG_SR	11
62 #define	PCB_REG_GP	12
63 #define	PCB_REG_PC	13
64 
65 /*
66  * Call ast if required
67  *
68  * XXX Do we really need to disable interrupts?
69  */
70 #define DO_AST				             \
71 44:				                     \
72 	mfc0	t0, MIPS_COP_0_STATUS               ;\
73 	and	a0, t0, MIPS_SR_INT_IE              ;\
74 	xor	t0, a0, t0                          ;\
75 	mtc0	t0, MIPS_COP_0_STATUS               ;\
76 	COP0_SYNC                                   ;\
77 	GET_CPU_PCPU(s1)                            ;\
78 	PTR_L	s3, PC_CURPCB(s1)                   ;\
79 	PTR_L	s1, PC_CURTHREAD(s1)                ;\
80 	lw	s2, TD_FLAGS(s1)                    ;\
81 	li	s0, TDF_ASTPENDING | TDF_NEEDRESCHED;\
82 	and	s2, s0                              ;\
83 	mfc0	t0, MIPS_COP_0_STATUS               ;\
84 	or	t0, a0, t0                          ;\
85 	mtc0	t0, MIPS_COP_0_STATUS               ;\
86 	COP0_SYNC                                   ;\
87 	beq	s2, zero, 4f                        ;\
88 	nop                                         ;\
89 	PTR_LA	s0, _C_LABEL(ast)                   ;\
90 	jalr	s0                                  ;\
91 	PTR_ADDU a0, s3, U_PCB_REGS                 ;\
92 	j	44b		                    ;\
93         nop                                         ;\
94 4:
95 
96 #define	SAVE_U_PCB_REG(reg, offs, base) \
97 	REG_S	reg, U_PCB_REGS + (SZREG * offs) (base)
98 
99 #define	RESTORE_U_PCB_REG(reg, offs, base) \
100 	REG_L	reg, U_PCB_REGS + (SZREG * offs) (base)
101 
102 #define	SAVE_U_PCB_FPREG(reg, offs, base) \
103 	FP_S	reg, U_PCB_FPREGS + (SZFPREG * offs) (base)
104 
105 #define	RESTORE_U_PCB_FPREG(reg, offs, base) \
106 	FP_L	reg, U_PCB_FPREGS + (SZFPREG * offs) (base)
107 
108 #define	SAVE_U_PCB_FPSR(reg, offs, base) \
109 	REG_S	reg, U_PCB_FPREGS + (SZFPREG * offs) (base)
110 
111 #define	RESTORE_U_PCB_FPSR(reg, offs, base) \
112 	REG_L	reg, U_PCB_FPREGS + (SZFPREG * offs) (base)
113 
114 #define	SAVE_U_PCB_CONTEXT(reg, offs, base) \
115 	REG_S	reg, U_PCB_CONTEXT + (SZREG * offs) (base)
116 
117 #define	RESTORE_U_PCB_CONTEXT(reg, offs, base) \
118 	REG_L	reg, U_PCB_CONTEXT + (SZREG * offs) (base)
119 
120 #ifndef LOCORE
121 #include <machine/frame.h>
122 
123 /*
124  * MIPS process control block
125  */
126 struct pcb
127 {
128 	struct trapframe pcb_regs;	/* saved CPU and registers */
129 	__register_t pcb_context[14];	/* kernel context for resume */
130 	void *pcb_onfault;		/* for copyin/copyout faults */
131 	register_t pcb_tpc;
132 };
133 
134 #ifdef _KERNEL
135 extern struct pcb *curpcb;		/* the current running pcb */
136 
137 void makectx(struct trapframe *, struct pcb *);
138 int savectx(struct pcb *) __returns_twice;
139 
140 #endif
141 #endif
142 
143 #endif	/* !_MACHINE_PCB_H_ */
144