1/* $NetBSD: process_machdep.c,v 1.26 2011/06/07 00:48:30 matt 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.26 2011/06/07 00:48:30 matt 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/vnode.h>
64#include <sys/ptrace.h>
65
66#include <machine/cpu.h>
67#include <machine/reg.h>
68#include <machine/frame.h>
69#include <machine/alpha.h>
70
71#define	lwp_frame(l)	((l)->l_md.md_tf)
72
73int
74process_read_regs(struct lwp *l, struct reg *regs)
75{
76	struct pcb *pcb = lwp_getpcb(l);
77
78	frametoreg(lwp_frame(l), regs);
79	regs->r_regs[R_ZERO] = lwp_frame(l)->tf_regs[FRAME_PC];
80	regs->r_regs[R_SP] = pcb->pcb_hw.apcb_usp;
81	return (0);
82}
83
84int
85process_write_regs(struct lwp *l, const struct reg *regs)
86{
87	struct pcb *pcb = lwp_getpcb(l);
88
89	regtoframe(regs, lwp_frame(l));
90	lwp_frame(l)->tf_regs[FRAME_PC] = regs->r_regs[R_ZERO];
91	pcb->pcb_hw.apcb_usp = regs->r_regs[R_SP];
92	return (0);
93}
94
95int
96process_sstep(struct lwp *l, int sstep)
97{
98
99	if (sstep)
100		return (EINVAL);
101
102	return (0);
103}
104
105int
106process_set_pc(struct lwp *l, void *addr)
107{
108	struct trapframe *frame = lwp_frame(l);
109
110	frame->tf_regs[FRAME_PC] = (uint64_t)addr;
111	return (0);
112}
113
114int
115process_read_fpregs(struct lwp *l, struct fpreg *regs)
116{
117	struct pcb *pcb = lwp_getpcb(l);
118
119	fpu_save();
120
121	memcpy(regs, &pcb->pcb_fp, sizeof(struct fpreg));
122	return (0);
123}
124
125int
126process_write_fpregs(struct lwp *l, const struct fpreg *regs)
127{
128	struct pcb *pcb = lwp_getpcb(l);
129
130	fpu_discard();
131	fpu_mark_used(l);
132
133	memcpy(&pcb->pcb_fp, regs, sizeof(struct fpreg));
134	return (0);
135}
136