1 /* $NetBSD: process_machdep.c,v 1.5 2018/05/18 20:10:25 reinoud Exp $ */
2
3 /*-
4 * Copyright (c) 2007 Jared D. McNeill <jmcneill@invisible.ca>
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 *
16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 */
28
29
30 /* from sys/arch/amd64/amd64/process_machdep.c */
31 /*
32 * This file may seem a bit stylized, but that so that it's easier to port.
33 * Functions to be implemented here are:
34 *
35 * process_read_regs(proc, regs)
36 * Get the current user-visible register set from the process
37 * and copy it into the regs structure (<machine/reg.h>).
38 * The process is stopped at the time read_regs is called.
39 *
40 * process_write_regs(proc, regs)
41 * Update the current register set from the passed in regs
42 * structure. Take care to avoid clobbering special CPU
43 * registers or privileged bits in the PSL.
44 * The process is stopped at the time write_regs is called.
45 *
46 * process_read_fpregs(proc, regs, sz)
47 * Get the current user-visible register set from the process
48 * and copy it into the regs structure (<machine/reg.h>).
49 * The process is stopped at the time read_fpregs is called.
50 *
51 * process_write_fpregs(proc, regs, sz)
52 * Update the current register set from the passed in regs
53 * structure. Take care to avoid clobbering special CPU
54 * registers or privileged bits in the PSL.
55 * The process is stopped at the time write_fpregs is called.
56 *
57 * process_read_dbregs(proc, regs, sz)
58 * Get the current user-visible register set from the process
59 * and copy it into the regs structure (<machine/reg.h>).
60 * The process is stopped at the time read_dbregs is called.
61 *
62 * process_write_dbregs(proc, regs, sz)
63 * Update the current register set from the passed in regs
64 * structure. Take care to avoid clobbering special CPU
65 * registers or privileged bits in the PSL.
66 * The process is stopped at the time write_dbregs is called.
67 *
68 * process_sstep(proc)
69 * Arrange for the process to trap after executing a single instruction.
70 *
71 * process_set_pc(proc)
72 * Set the process's program counter.
73 */
74
75 #include <sys/cdefs.h>
76 __KERNEL_RCSID(0, "$NetBSD: process_machdep.c,v 1.5 2018/05/18 20:10:25 reinoud Exp $");
77
78 #include <sys/types.h>
79 #include <sys/param.h>
80 #include <sys/ptrace.h>
81
82 #include <sys/ucontext.h>
83 #include <machine/pcb.h>
84 #include <sys/lwp.h>
85
86 #include <machine/thunk.h>
87
88 int
process_read_regs(struct lwp * l,struct reg * regs)89 process_read_regs(struct lwp *l, struct reg *regs)
90 {
91 struct pcb *pcb = lwp_getpcb(l);
92 ucontext_t *ucp;
93 register_t *reg;
94
95 ucp = &pcb->pcb_userret_ucp;
96 reg = (register_t *) &ucp->uc_mcontext.__gregs;
97
98 memcpy(regs, reg, sizeof(__gregset_t));
99
100 return 0;
101 }
102
103 int
process_read_fpregs(struct lwp * l,struct fpreg * regs,size_t * sz)104 process_read_fpregs(struct lwp *l, struct fpreg *regs, size_t *sz)
105 {
106 struct pcb *pcb = lwp_getpcb(l);
107 ucontext_t *ucp;
108 register_t *reg;
109
110 ucp = &pcb->pcb_userret_ucp;
111 reg = (register_t *) &ucp->uc_mcontext.__fpregs;
112
113 *sz = sizeof(__fpregset_t);
114 memcpy(regs, reg, *sz);
115
116 return 0;
117 }
118
119 int
process_write_regs(struct lwp * l,const struct reg * regs)120 process_write_regs(struct lwp *l, const struct reg *regs)
121 {
122 thunk_printf("%s called, not implemented\n", __func__);
123 return 0;
124 }
125
126 int
process_write_fpregs(struct lwp * l,const struct fpreg * regs,size_t sz)127 process_write_fpregs(struct lwp *l, const struct fpreg *regs, size_t sz)
128 {
129 thunk_printf("%s called, not implemented\n", __func__);
130 return 0;
131 }
132
133 int
process_sstep(struct lwp * l,int sstep)134 process_sstep(struct lwp *l, int sstep)
135 {
136 thunk_printf("%s called, not implemented\n", __func__);
137 return 0;
138 }
139
140 int
process_set_pc(struct lwp * l,void * addr)141 process_set_pc(struct lwp *l, void *addr)
142 {
143 thunk_printf("%s called, not implemented\n", __func__);
144 return 0;
145 }
146
147 int
process_write_dbregs(struct lwp * l,const struct dbreg * regs,size_t sz)148 process_write_dbregs(struct lwp *l, const struct dbreg *regs, size_t sz)
149 {
150 thunk_printf("%s called, not implemented\n", __func__);
151 return 0;
152 }
153
154 int
process_read_dbregs(struct lwp * l,struct dbreg * regs,size_t * sz)155 process_read_dbregs(struct lwp *l, struct dbreg *regs, size_t *sz)
156 {
157 thunk_printf("%s called, not implemented\n", __func__);
158 return 0;
159 }
160
161