1 /*	$NetBSD: process_machdep.c,v 1.9 2002/07/28 07:07:45 chs 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 	save_fpu_proc(p);
93 #endif
94 	memcpy(regs, &pcb->pcb_fpu, sizeof (struct fpreg));
95 
96 	return 0;
97 }
98 
99 int
100 process_write_fpregs(p, regs)
101 	struct proc *p;
102 	struct fpreg *regs;
103 {
104 	struct pcb *pcb = &p->p_addr->u_pcb;
105 
106 #ifdef PPC_HAVE_FPU
107 	save_fpu_proc(p);
108 #endif
109 
110 	memcpy(&pcb->pcb_fpu, regs, sizeof(struct fpreg));
111 
112 	/* pcb_fpu is initialized now. */
113 	pcb->pcb_flags |= PCB_FPU;
114 
115 	return 0;
116 }
117 
118 /*
119  * Set the process's program counter.
120  */
121 int
122 process_set_pc(p, addr)
123 	struct proc *p;
124 	caddr_t addr;
125 {
126 	struct trapframe *tf = trapframe(p);
127 
128 	tf->srr0 = (int)addr;
129 	return 0;
130 }
131 
132 int
133 process_sstep(p, sstep)
134 	struct proc *p;
135 	int sstep;
136 {
137 	struct trapframe *tf = trapframe(p);
138 
139 	if (sstep)
140 		tf->srr1 |= PSL_SE;
141 	else
142 		tf->srr1 &= ~PSL_SE;
143 	return 0;
144 }
145