1 /*	$NetBSD: process_machdep.c,v 1.7 2001/07/22 11:29:46 wiz Exp $	*/
2 
3 /*
4  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
5  * Copyright (C) 1995, 1996 TooLs GmbH.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. All advertising materials mentioning features or use of this software
17  *    must display the following acknowledgement:
18  *	This product includes software developed by TooLs GmbH.
19  * 4. The name of TooLs GmbH may not be used to endorse or promote products
20  *    derived from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
23  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25  * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
28  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 #include <sys/param.h>
35 #include <sys/proc.h>
36 #include <sys/user.h>
37 #include <sys/systm.h>
38 #include <sys/ptrace.h>
39 
40 #include <machine/fpu.h>
41 #include <machine/pcb.h>
42 #include <machine/reg.h>
43 
44 int
45 process_read_regs(p, regs)
46 	struct proc *p;
47 	struct reg *regs;
48 {
49 	struct trapframe *tf = trapframe(p);
50 
51 	memcpy(regs->fixreg, tf->fixreg, sizeof(regs->fixreg));
52 	regs->lr = tf->lr;
53 	regs->cr = tf->cr;
54 	regs->xer = tf->xer;
55 	regs->ctr = tf->ctr;
56 	regs->pc = tf->srr0;
57 
58 	return 0;
59 }
60 
61 int
62 process_write_regs(p, regs)
63 	struct proc *p;
64 	struct reg *regs;
65 {
66 	struct trapframe *tf = trapframe(p);
67 
68 	memcpy(tf->fixreg, regs->fixreg, sizeof(regs->fixreg));
69 	tf->lr = regs->lr;
70 	tf->cr = regs->cr;
71 	tf->xer = regs->xer;
72 	tf->ctr = regs->ctr;
73 	tf->srr0 = regs->pc;
74 
75 	return 0;
76 }
77 
78 int
79 process_read_fpregs(p, regs)
80 	struct proc *p;
81 	struct fpreg *regs;
82 {
83 	struct pcb *pcb = &p->p_addr->u_pcb;
84 
85 	/* Is the process using the fpu? */
86 	if ((pcb->pcb_flags & PCB_FPU) == 0) {
87 		memset(regs, 0, sizeof (struct fpreg));
88 		return 0;
89 	}
90 
91 #ifdef PPC_HAVE_FPU
92 	if (p == fpuproc)
93 		save_fpu(p);
94 #endif
95 	memcpy(regs, &pcb->pcb_fpu, sizeof (struct fpreg));
96 
97 	return 0;
98 }
99 
100 int
101 process_write_fpregs(p, regs)
102 	struct proc *p;
103 	struct fpreg *regs;
104 {
105 	struct pcb *pcb = &p->p_addr->u_pcb;
106 
107 #ifdef PPC_HAVE_FPU
108 	if (p == fpuproc)
109 		fpuproc = NULL;
110 #endif
111 
112 	memcpy(&pcb->pcb_fpu, regs, sizeof(struct fpreg));
113 
114 	/* pcb_fpu is initialized now. */
115 	pcb->pcb_flags |= PCB_FPU;
116 
117 	return 0;
118 }
119 
120 /*
121  * Set the process's program counter.
122  */
123 int
124 process_set_pc(p, addr)
125 	struct proc *p;
126 	caddr_t addr;
127 {
128 	struct trapframe *tf = trapframe(p);
129 
130 	tf->srr0 = (int)addr;
131 	return 0;
132 }
133 
134 int
135 process_sstep(p, sstep)
136 	struct proc *p;
137 	int sstep;
138 {
139 	struct trapframe *tf = trapframe(p);
140 
141 	if (sstep)
142 		tf->srr1 |= PSL_SE;
143 	else
144 		tf->srr1 &= ~PSL_SE;
145 	return 0;
146 }
147