xref: /netbsd/sys/arch/alpha/alpha/process_machdep.c (revision bf9ec67e)
1 /* $NetBSD: process_machdep.c,v 1.18 2001/07/12 23:35:43 thorpej Exp $ */
2 
3 /*
4  * Copyright (c) 1994 Christopher G. Demetriou
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. All advertising materials mentioning features or use of this software
16  *    must display the following acknowledgement:
17  *      This product includes software developed by Christopher G. Demetriou.
18  * 4. The name of the author may not be used to endorse or promote products
19  *    derived from this software without specific prior written permission
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 /*
34  * This file may seem a bit stylized, but that so that it's easier to port.
35  * Functions to be implemented here are:
36  *
37  * process_read_regs(proc, regs)
38  *	Get the current user-visible register set from the process
39  *	and copy it into the regs structure (<machine/reg.h>).
40  *	The process is stopped at the time read_regs is called.
41  *
42  * process_write_regs(proc, regs)
43  *	Update the current register set from the passed in regs
44  *	structure.  Take care to avoid clobbering special CPU
45  *	registers or privileged bits in the PSL.
46  *	The process is stopped at the time write_regs is called.
47  *
48  * process_sstep(proc)
49  *	Arrange for the process to trap after executing a single instruction.
50  *
51  * process_set_pc(proc)
52  *	Set the process's program counter.
53  */
54 
55 #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
56 
57 __KERNEL_RCSID(0, "$NetBSD: process_machdep.c,v 1.18 2001/07/12 23:35:43 thorpej Exp $");
58 
59 #include <sys/param.h>
60 #include <sys/systm.h>
61 #include <sys/kernel.h>
62 #include <sys/proc.h>
63 #include <sys/user.h>
64 #include <sys/vnode.h>
65 #include <sys/ptrace.h>
66 
67 #include <machine/cpu.h>
68 #include <machine/reg.h>
69 #include <machine/frame.h>
70 #include <machine/alpha.h>
71 
72 #define	process_frame(p)	((p)->p_md.md_tf)
73 #define	process_pcb(p)		(&(p)->p_addr->u_pcb)
74 #define	process_fpframe(p)	(&(process_pcb(p)->pcb_fp))
75 
76 int
77 process_read_regs(struct proc *p, struct reg *regs)
78 {
79 
80 	frametoreg(process_frame(p), regs);
81 	regs->r_regs[R_ZERO] = process_frame(p)->tf_regs[FRAME_PC];
82 	regs->r_regs[R_SP] = process_pcb(p)->pcb_hw.apcb_usp;
83 	return (0);
84 }
85 
86 int
87 process_write_regs(struct proc *p, struct reg *regs)
88 {
89 
90 	regtoframe(regs, process_frame(p));
91 	process_frame(p)->tf_regs[FRAME_PC] = regs->r_regs[R_ZERO];
92 	process_pcb(p)->pcb_hw.apcb_usp = regs->r_regs[R_SP];
93 	return (0);
94 }
95 
96 int
97 process_sstep(struct proc *p, int sstep)
98 {
99 
100 	if (sstep)
101 		return (EINVAL);
102 
103 	return (0);
104 }
105 
106 int
107 process_set_pc(struct proc *p, caddr_t addr)
108 {
109 	struct trapframe *frame = process_frame(p);
110 
111 	frame->tf_regs[FRAME_PC] = (u_int64_t)addr;
112 	return (0);
113 }
114 
115 int
116 process_read_fpregs(struct proc *p, struct fpreg *regs)
117 {
118 
119 	if (p->p_addr->u_pcb.pcb_fpcpu != NULL)
120 		fpusave_proc(p, 1);
121 
122 	memcpy(regs, process_fpframe(p), sizeof(struct fpreg));
123 	return (0);
124 }
125 
126 int
127 process_write_fpregs(struct proc *p, struct fpreg *regs)
128 {
129 
130 	if (p->p_addr->u_pcb.pcb_fpcpu != NULL)
131 		fpusave_proc(p, 0);
132 
133 	memcpy(process_fpframe(p), regs, sizeof(struct fpreg));
134 	return (0);
135 }
136