1178172Simp/*	$OpenBSD: pcb.h,v 1.3 1998/09/15 10:50:12 pefo Exp $	*/
2178172Simp
3178172Simp/*-
4178172Simp * Copyright (c) 1988 University of Utah.
5178172Simp * Copyright (c) 1992, 1993
6178172Simp *	The Regents of the University of California.  All rights reserved.
7178172Simp *
8178172Simp * This code is derived from software contributed to Berkeley by
9178172Simp * the Systems Programming Group of the University of Utah Computer
10178172Simp * Science Department and Ralph Campbell.
11178172Simp *
12178172Simp * Redistribution and use in source and binary forms, with or without
13178172Simp * modification, are permitted provided that the following conditions
14178172Simp * are met:
15178172Simp * 1. Redistributions of source code must retain the above copyright
16178172Simp *    notice, this list of conditions and the following disclaimer.
17178172Simp * 2. Redistributions in binary form must reproduce the above copyright
18178172Simp *    notice, this list of conditions and the following disclaimer in the
19178172Simp *    documentation and/or other materials provided with the distribution.
20178172Simp * 4. Neither the name of the University nor the names of its contributors
21178172Simp *    may be used to endorse or promote products derived from this software
22178172Simp *    without specific prior written permission.
23178172Simp *
24178172Simp * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25178172Simp * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26178172Simp * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27178172Simp * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28178172Simp * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29178172Simp * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30178172Simp * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31178172Simp * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32178172Simp * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33178172Simp * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34178172Simp * SUCH DAMAGE.
35178172Simp *
36178172Simp *	from: Utah Hdr: pcb.h 1.13 89/04/23
37178172Simp *	from: @(#)pcb.h 8.1 (Berkeley) 6/10/93
38178172Simp *	JNPR: pcb.h,v 1.2 2006/08/07 11:51:17 katta
39178172Simp * $FreeBSD$
40178172Simp */
41178172Simp
42178172Simp#ifndef _MACHINE_PCB_H_
43178172Simp#define	_MACHINE_PCB_H_
44178172Simp
45178172Simp/*
46178172Simp * used by switch.S
47178172Simp */
48211862Sjchandra#define	PCB_REG_S0	0
49211862Sjchandra#define	PCB_REG_S1	1
50211862Sjchandra#define	PCB_REG_S2	2
51211862Sjchandra#define	PCB_REG_S3	3
52211862Sjchandra#define	PCB_REG_S4	4
53211862Sjchandra#define	PCB_REG_S5	5
54211862Sjchandra#define	PCB_REG_S6	6
55211862Sjchandra#define	PCB_REG_S7	7
56211862Sjchandra#define	PCB_REG_SP	8
57211862Sjchandra#define	PCB_REG_S8	9
58211862Sjchandra#define	PCB_REG_RA	10
59211862Sjchandra#define	PCB_REG_SR	11
60211862Sjchandra#define	PCB_REG_GP	12
61211862Sjchandra#define	PCB_REG_PC	13
62178172Simp
63256494Simp/*
64256494Simp * Call ast if required
65256494Simp *
66256494Simp * XXX Do we really need to disable interrupts?
67256494Simp */
68256494Simp#define DO_AST				             \
69256494Simp44:				                     \
70256494Simp	mfc0	t0, MIPS_COP_0_STATUS               ;\
71256494Simp	and	a0, t0, MIPS_SR_INT_IE              ;\
72256494Simp	xor	t0, a0, t0                          ;\
73256494Simp	mtc0	t0, MIPS_COP_0_STATUS               ;\
74256494Simp	COP0_SYNC                                   ;\
75256494Simp	GET_CPU_PCPU(s1)                            ;\
76256494Simp	PTR_L	s3, PC_CURPCB(s1)                   ;\
77256494Simp	PTR_L	s1, PC_CURTHREAD(s1)                ;\
78256494Simp	lw	s2, TD_FLAGS(s1)                    ;\
79256494Simp	li	s0, TDF_ASTPENDING | TDF_NEEDRESCHED;\
80256494Simp	and	s2, s0                              ;\
81256494Simp	mfc0	t0, MIPS_COP_0_STATUS               ;\
82256494Simp	or	t0, a0, t0                          ;\
83256494Simp	mtc0	t0, MIPS_COP_0_STATUS               ;\
84256494Simp	COP0_SYNC                                   ;\
85256494Simp	beq	s2, zero, 4f                        ;\
86256494Simp	nop                                         ;\
87256494Simp	PTR_LA	s0, _C_LABEL(ast)                   ;\
88256494Simp	jalr	s0                                  ;\
89256494Simp	PTR_ADDU a0, s3, U_PCB_REGS                 ;\
90256494Simp	j	44b		                    ;\
91256494Simp        nop                                         ;\
92256494Simp4:
93256494Simp
94256494Simp#define	SAVE_U_PCB_REG(reg, offs, base) \
95256494Simp	REG_S	reg, U_PCB_REGS + (SZREG * offs) (base)
96256494Simp
97256494Simp#define	RESTORE_U_PCB_REG(reg, offs, base) \
98256494Simp	REG_L	reg, U_PCB_REGS + (SZREG * offs) (base)
99256494Simp
100256494Simp#define	SAVE_U_PCB_FPREG(reg, offs, base) \
101256494Simp	FP_S	reg, U_PCB_FPREGS + (SZFPREG * offs) (base)
102256494Simp
103256494Simp#define	RESTORE_U_PCB_FPREG(reg, offs, base) \
104256494Simp	FP_L	reg, U_PCB_FPREGS + (SZFPREG * offs) (base)
105256494Simp
106256494Simp#define	SAVE_U_PCB_FPSR(reg, offs, base) \
107256494Simp	REG_S	reg, U_PCB_FPREGS + (SZFPREG * offs) (base)
108256494Simp
109256494Simp#define	RESTORE_U_PCB_FPSR(reg, offs, base) \
110256494Simp	REG_L	reg, U_PCB_FPREGS + (SZFPREG * offs) (base)
111256494Simp
112256494Simp#define	SAVE_U_PCB_CONTEXT(reg, offs, base) \
113256494Simp	REG_S	reg, U_PCB_CONTEXT + (SZREG * offs) (base)
114256494Simp
115256494Simp#define	RESTORE_U_PCB_CONTEXT(reg, offs, base) \
116256494Simp	REG_L	reg, U_PCB_CONTEXT + (SZREG * offs) (base)
117256494Simp
118249882Simp#ifndef LOCORE
119249882Simp#include <machine/frame.h>
120178172Simp
121249882Simp/*
122249882Simp * MIPS process control block
123249882Simp */
124249882Simpstruct pcb
125249882Simp{
126249882Simp	struct trapframe pcb_regs;	/* saved CPU and registers */
127249882Simp	__register_t pcb_context[14];	/* kernel context for resume */
128249882Simp	void *pcb_onfault;		/* for copyin/copyout faults */
129249882Simp	register_t pcb_tpc;
130249882Simp};
131249882Simp
132178172Simp#ifdef _KERNEL
133178172Simpextern struct pcb *curpcb;		/* the current running pcb */
134178172Simp
135178172Simpvoid makectx(struct trapframe *, struct pcb *);
136234785Sdimint savectx(struct pcb *) __returns_twice;
137256494Simp
138178172Simp#endif
139249882Simp#endif
140178172Simp
141178172Simp#endif	/* !_MACHINE_PCB_H_ */
142