Rev 3424 | Rev 3611 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3424 | Rev 3471 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (c) 2008 Jiri Svoboda |
2 | * Copyright (c) 2008 Jiri Svoboda |
3 | * All rights reserved. |
3 | * All rights reserved. |
4 | * |
4 | * |
5 | * Redistribution and use in source and binary forms, with or without |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions |
6 | * modification, are permitted provided that the following conditions |
7 | * are met: |
7 | * are met: |
8 | * |
8 | * |
9 | * - Redistributions of source code must retain the above copyright |
9 | * - Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. |
10 | * notice, this list of conditions and the following disclaimer. |
11 | * - Redistributions in binary form must reproduce the above copyright |
11 | * - Redistributions in binary form must reproduce the above copyright |
12 | * notice, this list of conditions and the following disclaimer in the |
12 | * notice, this list of conditions and the following disclaimer in the |
13 | * documentation and/or other materials provided with the distribution. |
13 | * documentation and/or other materials provided with the distribution. |
14 | * - The name of the author may not be used to endorse or promote products |
14 | * - The name of the author may not be used to endorse or promote products |
15 | * derived from this software without specific prior written permission. |
15 | * derived from this software without specific prior written permission. |
16 | * |
16 | * |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | */ |
27 | */ |
28 | 28 | ||
29 | /** @addtogroup generic |
29 | /** @addtogroup generic |
30 | * @{ |
30 | * @{ |
31 | */ |
31 | */ |
32 | 32 | ||
33 | /** |
33 | /** |
34 | * @file |
34 | * @file |
35 | * @brief Udebug IPC message handling. |
35 | * @brief Udebug IPC message handling. |
- | 36 | * |
|
- | 37 | * This module handles udebug IPC messages and calls the appropriate |
|
- | 38 | * functions from the udebug_ops module which implement them. |
|
36 | */ |
39 | */ |
37 | 40 | ||
38 | #include <print.h> |
- | |
39 | #include <proc/task.h> |
41 | #include <proc/task.h> |
40 | #include <proc/thread.h> |
42 | #include <proc/thread.h> |
41 | #include <arch.h> |
43 | #include <arch.h> |
42 | #include <errno.h> |
44 | #include <errno.h> |
43 | #include <ipc/ipc.h> |
45 | #include <ipc/ipc.h> |
44 | #include <syscall/copy.h> |
46 | #include <syscall/copy.h> |
45 | #include <udebug/udebug.h> |
47 | #include <udebug/udebug.h> |
46 | #include <udebug/udebug_ops.h> |
48 | #include <udebug/udebug_ops.h> |
47 | #include <udebug/udebug_ipc.h> |
49 | #include <udebug/udebug_ipc.h> |
48 | 50 | ||
49 | static int udebug_rp_regs_write(call_t *call, phone_t *phone) |
51 | static int udebug_rp_regs_write(call_t *call, phone_t *phone) |
50 | { |
52 | { |
51 | void *uspace_data; |
53 | void *uspace_data; |
52 | unative_t to_copy; |
54 | unative_t to_copy; |
53 | int rc; |
55 | int rc; |
54 | void *buffer; |
56 | void *buffer; |
55 | 57 | ||
56 | printf("debug_regs_write()\n"); |
58 | printf("debug_regs_write()\n"); |
57 | 59 | ||
58 | uspace_data = (void *)IPC_GET_ARG3(call->data); |
60 | uspace_data = (void *)IPC_GET_ARG3(call->data); |
59 | to_copy = sizeof(istate_t); |
61 | to_copy = sizeof(istate_t); |
60 | buffer = malloc(to_copy, 0); |
62 | buffer = malloc(to_copy, 0); |
61 | 63 | ||
62 | rc = copy_from_uspace(buffer, uspace_data, to_copy); |
64 | rc = copy_from_uspace(buffer, uspace_data, to_copy); |
63 | if (rc != 0) { |
65 | if (rc != 0) { |
64 | printf("debug_regs_write() - copy failed\n"); |
66 | printf("debug_regs_write() - copy failed\n"); |
65 | return rc; |
67 | return rc; |
66 | } |
68 | } |
67 | 69 | ||
68 | call->buffer = buffer; |
70 | call->buffer = buffer; |
69 | 71 | ||
70 | printf(" - done\n"); |
72 | printf(" - done\n"); |
71 | return 0; |
73 | return 0; |
72 | } |
74 | } |
73 | 75 | ||
74 | static int udebug_rp_mem_write(call_t *call, phone_t *phone) |
76 | static int udebug_rp_mem_write(call_t *call, phone_t *phone) |
75 | { |
77 | { |
76 | void *uspace_data; |
78 | void *uspace_data; |
77 | unative_t to_copy; |
79 | unative_t to_copy; |
78 | int rc; |
80 | int rc; |
79 | void *buffer; |
81 | void *buffer; |
80 | 82 | ||
81 | printf("udebug_rp_mem_write()\n"); |
83 | printf("udebug_rp_mem_write()\n"); |
82 | 84 | ||
83 | uspace_data = (void *)IPC_GET_ARG2(call->data); |
85 | uspace_data = (void *)IPC_GET_ARG2(call->data); |
84 | to_copy = IPC_GET_ARG4(call->data); |
86 | to_copy = IPC_GET_ARG4(call->data); |
85 | 87 | ||
86 | buffer = malloc(to_copy, 0); |
88 | buffer = malloc(to_copy, 0); |
87 | 89 | ||
88 | rc = copy_from_uspace(buffer, uspace_data, to_copy); |
90 | rc = copy_from_uspace(buffer, uspace_data, to_copy); |
89 | if (rc != 0) { |
91 | if (rc != 0) { |
90 | printf(" - copy failed\n"); |
92 | printf(" - copy failed\n"); |
91 | return rc; |
93 | return rc; |
92 | } |
94 | } |
93 | 95 | ||
94 | call->buffer = buffer; |
96 | call->buffer = buffer; |
95 | 97 | ||
96 | printf(" - done\n"); |
98 | printf(" - done\n"); |
97 | return 0; |
99 | return 0; |
98 | } |
100 | } |
99 | 101 | ||
100 | 102 | ||
101 | int udebug_request_preprocess(call_t *call, phone_t *phone) |
103 | int udebug_request_preprocess(call_t *call, phone_t *phone) |
102 | { |
104 | { |
103 | int rc; |
105 | int rc; |
104 | 106 | ||
105 | switch (IPC_GET_ARG1(call->data)) { |
107 | switch (IPC_GET_ARG1(call->data)) { |
106 | case UDEBUG_M_REGS_WRITE: |
108 | case UDEBUG_M_REGS_WRITE: |
107 | rc = udebug_rp_regs_write(call, phone); |
109 | rc = udebug_rp_regs_write(call, phone); |
108 | return rc; |
110 | return rc; |
109 | case UDEBUG_M_MEM_WRITE: |
111 | case UDEBUG_M_MEM_WRITE: |
110 | rc = udebug_rp_mem_write(call, phone); |
112 | rc = udebug_rp_mem_write(call, phone); |
111 | return rc; |
113 | return rc; |
112 | default: |
114 | default: |
113 | break; |
115 | break; |
114 | } |
116 | } |
115 | 117 | ||
116 | return 0; |
118 | return 0; |
117 | } |
119 | } |
118 | 120 | ||
- | 121 | /** Process a BEGIN call. |
|
- | 122 | * |
|
- | 123 | * Initiates a debugging session for the current task. The reply |
|
- | 124 | * to this call may or may not be sent before this function returns. |
|
- | 125 | * |
|
- | 126 | * @param call The call structure. |
|
- | 127 | */ |
|
119 | static void udebug_receive_begin(call_t *call) |
128 | static void udebug_receive_begin(call_t *call) |
120 | { |
129 | { |
121 | int rc; |
130 | int rc; |
122 | 131 | ||
123 | rc = udebug_begin(call); |
132 | rc = udebug_begin(call); |
124 | if (rc < 0) { |
133 | if (rc < 0) { |
125 | IPC_SET_RETVAL(call->data, rc); |
134 | IPC_SET_RETVAL(call->data, rc); |
126 | ipc_answer(&TASK->kernel_box, call); |
135 | ipc_answer(&TASK->kernel_box, call); |
127 | return; |
136 | return; |
128 | } |
137 | } |
129 | 138 | ||
- | 139 | /* |
|
- | 140 | * If the initialization of the debugging session has finished, |
|
- | 141 | * send a reply. |
|
- | 142 | */ |
|
130 | if (rc != 0) { |
143 | if (rc != 0) { |
131 | IPC_SET_RETVAL(call->data, 0); |
144 | IPC_SET_RETVAL(call->data, 0); |
132 | ipc_answer(&TASK->kernel_box, call); |
145 | ipc_answer(&TASK->kernel_box, call); |
133 | } |
146 | } |
134 | } |
147 | } |
135 | 148 | ||
- | 149 | /** Process an END call. |
|
- | 150 | * |
|
- | 151 | * Terminates the debugging session for the current task. |
|
- | 152 | * @param call The call structure. |
|
- | 153 | */ |
|
136 | static void udebug_receive_end(call_t *call) |
154 | static void udebug_receive_end(call_t *call) |
137 | { |
155 | { |
138 | int rc; |
156 | int rc; |
139 | 157 | ||
140 | rc = udebug_end(); |
158 | rc = udebug_end(); |
141 | 159 | ||
142 | IPC_SET_RETVAL(call->data, rc); |
160 | IPC_SET_RETVAL(call->data, rc); |
143 | ipc_answer(&TASK->kernel_box, call); |
161 | ipc_answer(&TASK->kernel_box, call); |
144 | } |
162 | } |
145 | 163 | ||
- | 164 | /** Process a SET_EVMASK call. |
|
- | 165 | * |
|
- | 166 | * Sets an event mask for the current debugging session. |
|
- | 167 | * @param call The call structure. |
|
- | 168 | */ |
|
146 | static void udebug_receive_set_evmask(call_t *call) |
169 | static void udebug_receive_set_evmask(call_t *call) |
147 | { |
170 | { |
148 | int rc; |
171 | int rc; |
149 | udebug_evmask_t mask; |
172 | udebug_evmask_t mask; |
150 | 173 | ||
151 | mask = IPC_GET_ARG2(call->data); |
174 | mask = IPC_GET_ARG2(call->data); |
152 | rc = udebug_set_evmask(mask); |
175 | rc = udebug_set_evmask(mask); |
153 | 176 | ||
154 | IPC_SET_RETVAL(call->data, rc); |
177 | IPC_SET_RETVAL(call->data, rc); |
155 | ipc_answer(&TASK->kernel_box, call); |
178 | ipc_answer(&TASK->kernel_box, call); |
156 | } |
179 | } |
157 | 180 | ||
158 | 181 | ||
- | 182 | /** Process a GO call. |
|
- | 183 | * |
|
- | 184 | * Resumes execution of the specified thread. |
|
- | 185 | * @param call The call structure. |
|
- | 186 | */ |
|
159 | static void udebug_receive_go(call_t *call) |
187 | static void udebug_receive_go(call_t *call) |
160 | { |
188 | { |
161 | thread_t *t; |
189 | thread_t *t; |
162 | int rc; |
190 | int rc; |
163 | 191 | ||
164 | //printf("debug_go()\n"); |
- | |
165 | - | ||
166 | t = (thread_t *)IPC_GET_ARG2(call->data); |
192 | t = (thread_t *)IPC_GET_ARG2(call->data); |
167 | 193 | ||
168 | rc = udebug_go(t, call); |
194 | rc = udebug_go(t, call); |
169 | if (rc < 0) { |
195 | if (rc < 0) { |
170 | IPC_SET_RETVAL(call->data, rc); |
196 | IPC_SET_RETVAL(call->data, rc); |
171 | ipc_answer(&TASK->kernel_box, call); |
197 | ipc_answer(&TASK->kernel_box, call); |
172 | return; |
198 | return; |
173 | } |
199 | } |
174 | } |
200 | } |
175 | 201 | ||
- | 202 | /** Process a STOP call. |
|
- | 203 | * |
|
- | 204 | * Suspends execution of the specified thread. |
|
- | 205 | * @param call The call structure. |
|
- | 206 | */ |
|
176 | static void udebug_receive_stop(call_t *call) |
207 | static void udebug_receive_stop(call_t *call) |
177 | { |
208 | { |
178 | thread_t *t; |
209 | thread_t *t; |
179 | int rc; |
210 | int rc; |
180 | 211 | ||
181 | printf("debug_stop()\n"); |
- | |
182 | - | ||
183 | t = (thread_t *)IPC_GET_ARG2(call->data); |
212 | t = (thread_t *)IPC_GET_ARG2(call->data); |
184 | 213 | ||
185 | rc = udebug_stop(t, call); |
214 | rc = udebug_stop(t, call); |
186 | IPC_SET_RETVAL(call->data, rc); |
215 | IPC_SET_RETVAL(call->data, rc); |
187 | ipc_answer(&TASK->kernel_box, call); |
216 | ipc_answer(&TASK->kernel_box, call); |
188 | } |
217 | } |
189 | 218 | ||
- | 219 | /** Process a THREAD_READ call. |
|
- | 220 | * |
|
- | 221 | * Reads the list of hashes of the (userspace) threads in the current task. |
|
- | 222 | * @param call The call structure. |
|
- | 223 | */ |
|
190 | static void udebug_receive_thread_read(call_t *call) |
224 | static void udebug_receive_thread_read(call_t *call) |
191 | { |
225 | { |
192 | unative_t uspace_addr; |
226 | unative_t uspace_addr; |
193 | unative_t to_copy; |
227 | unative_t to_copy; |
194 | unsigned total_bytes; |
228 | unsigned total_bytes; |
195 | unsigned buf_size; |
229 | unsigned buf_size; |
196 | void *buffer; |
230 | void *buffer; |
197 | size_t n; |
231 | size_t n; |
198 | int rc; |
232 | int rc; |
199 | 233 | ||
200 | uspace_addr = IPC_GET_ARG2(call->data); /* Destination address */ |
234 | uspace_addr = IPC_GET_ARG2(call->data); /* Destination address */ |
201 | buf_size = IPC_GET_ARG3(call->data); /* Dest. buffer size */ |
235 | buf_size = IPC_GET_ARG3(call->data); /* Dest. buffer size */ |
202 | 236 | ||
203 | /* |
237 | /* |
204 | * Read thread list. Variable n will be filled with actual number |
238 | * Read thread list. Variable n will be filled with actual number |
205 | * of threads times thread-id size. |
239 | * of threads times thread-id size. |
206 | */ |
240 | */ |
207 | rc = udebug_thread_read(&buffer, buf_size, &n); |
241 | rc = udebug_thread_read(&buffer, buf_size, &n); |
208 | if (rc < 0) { |
242 | if (rc < 0) { |
209 | IPC_SET_RETVAL(call->data, rc); |
243 | IPC_SET_RETVAL(call->data, rc); |
210 | ipc_answer(&TASK->kernel_box, call); |
244 | ipc_answer(&TASK->kernel_box, call); |
211 | return; |
245 | return; |
212 | } |
246 | } |
213 | 247 | ||
214 | total_bytes = n; |
248 | total_bytes = n; |
215 | 249 | ||
216 | /* Copy MAX(buf_size, total_bytes) bytes */ |
250 | /* Copy MAX(buf_size, total_bytes) bytes */ |
217 | 251 | ||
218 | if (buf_size > total_bytes) |
252 | if (buf_size > total_bytes) |
219 | to_copy = total_bytes; |
253 | to_copy = total_bytes; |
220 | else |
254 | else |
221 | to_copy = buf_size; |
255 | to_copy = buf_size; |
222 | 256 | ||
223 | /* |
257 | /* |
224 | * Make use of call->buffer to transfer data to caller's userspace |
258 | * Make use of call->buffer to transfer data to caller's userspace |
225 | */ |
259 | */ |
226 | 260 | ||
227 | IPC_SET_RETVAL(call->data, 0); |
261 | IPC_SET_RETVAL(call->data, 0); |
228 | /* ARG1=dest, ARG2=size as in IPC_M_DATA_READ so that |
262 | /* ARG1=dest, ARG2=size as in IPC_M_DATA_READ so that |
229 | same code in process_answer() can be used |
263 | same code in process_answer() can be used |
230 | (no way to distinguish method in answer) */ |
264 | (no way to distinguish method in answer) */ |
231 | IPC_SET_ARG1(call->data, uspace_addr); |
265 | IPC_SET_ARG1(call->data, uspace_addr); |
232 | IPC_SET_ARG2(call->data, to_copy); |
266 | IPC_SET_ARG2(call->data, to_copy); |
233 | 267 | ||
234 | IPC_SET_ARG3(call->data, total_bytes); |
268 | IPC_SET_ARG3(call->data, total_bytes); |
235 | call->buffer = buffer; |
269 | call->buffer = buffer; |
236 | 270 | ||
237 | ipc_answer(&TASK->kernel_box, call); |
271 | ipc_answer(&TASK->kernel_box, call); |
238 | } |
272 | } |
239 | 273 | ||
- | 274 | /** Process an ARGS_READ call. |
|
- | 275 | * |
|
- | 276 | * Reads the argument of a current syscall event (SYSCALL_B or SYSCALL_E). |
|
- | 277 | * @param call The call structure. |
|
- | 278 | */ |
|
240 | static void udebug_receive_args_read(call_t *call) |
279 | static void udebug_receive_args_read(call_t *call) |
241 | { |
280 | { |
242 | thread_t *t; |
281 | thread_t *t; |
243 | unative_t uspace_addr; |
282 | unative_t uspace_addr; |
244 | int rc; |
283 | int rc; |
245 | void *buffer; |
284 | void *buffer; |
246 | 285 | ||
247 | t = (thread_t *)IPC_GET_ARG2(call->data); |
286 | t = (thread_t *)IPC_GET_ARG2(call->data); |
248 | 287 | ||
249 | rc = udebug_args_read(t, &buffer); |
288 | rc = udebug_args_read(t, &buffer); |
250 | if (rc != EOK) { |
289 | if (rc != EOK) { |
251 | IPC_SET_RETVAL(call->data, rc); |
290 | IPC_SET_RETVAL(call->data, rc); |
252 | ipc_answer(&TASK->kernel_box, call); |
291 | ipc_answer(&TASK->kernel_box, call); |
253 | return; |
292 | return; |
254 | } |
293 | } |
255 | 294 | ||
256 | /* |
295 | /* |
257 | * Make use of call->buffer to transfer data to caller's userspace |
296 | * Make use of call->buffer to transfer data to caller's userspace |
258 | */ |
297 | */ |
259 | 298 | ||
260 | uspace_addr = IPC_GET_ARG3(call->data); |
299 | uspace_addr = IPC_GET_ARG3(call->data); |
261 | 300 | ||
262 | IPC_SET_RETVAL(call->data, 0); |
301 | IPC_SET_RETVAL(call->data, 0); |
263 | /* ARG1=dest, ARG2=size as in IPC_M_DATA_READ so that |
302 | /* ARG1=dest, ARG2=size as in IPC_M_DATA_READ so that |
264 | same code in process_answer() can be used |
303 | same code in process_answer() can be used |
265 | (no way to distinguish method in answer) */ |
304 | (no way to distinguish method in answer) */ |
266 | IPC_SET_ARG1(call->data, uspace_addr); |
305 | IPC_SET_ARG1(call->data, uspace_addr); |
267 | IPC_SET_ARG2(call->data, 6 * sizeof(unative_t)); |
306 | IPC_SET_ARG2(call->data, 6 * sizeof(unative_t)); |
268 | call->buffer = buffer; |
307 | call->buffer = buffer; |
269 | 308 | ||
270 | ipc_answer(&TASK->kernel_box, call); |
309 | ipc_answer(&TASK->kernel_box, call); |
271 | } |
310 | } |
272 | 311 | ||
273 | static void udebug_receive_regs_read(call_t *call) |
312 | static void udebug_receive_regs_read(call_t *call) |
274 | { |
313 | { |
275 | thread_t *t; |
314 | thread_t *t; |
276 | unative_t uspace_addr; |
315 | unative_t uspace_addr; |
277 | unative_t to_copy; |
316 | unative_t to_copy; |
278 | void *buffer; |
317 | void *buffer; |
279 | int rc; |
318 | int rc; |
280 | 319 | ||
281 | printf("debug_regs_read()\n"); |
320 | printf("debug_regs_read()\n"); |
282 | 321 | ||
283 | t = (thread_t *) IPC_GET_ARG2(call->data); |
322 | t = (thread_t *) IPC_GET_ARG2(call->data); |
284 | buffer = malloc(sizeof(istate_t), 0); |
323 | buffer = malloc(sizeof(istate_t), 0); |
285 | 324 | ||
286 | rc = udebug_regs_read(t, buffer); |
325 | rc = udebug_regs_read(t, buffer); |
287 | if (rc < 0) { |
326 | if (rc < 0) { |
288 | IPC_SET_RETVAL(call->data, rc); |
327 | IPC_SET_RETVAL(call->data, rc); |
289 | ipc_answer(&TASK->kernel_box, call); |
328 | ipc_answer(&TASK->kernel_box, call); |
290 | return; |
329 | return; |
291 | } |
330 | } |
292 | 331 | ||
293 | /* |
332 | /* |
294 | * Make use of call->buffer to transfer data to caller's userspace |
333 | * Make use of call->buffer to transfer data to caller's userspace |
295 | */ |
334 | */ |
296 | 335 | ||
297 | uspace_addr = IPC_GET_ARG3(call->data); |
336 | uspace_addr = IPC_GET_ARG3(call->data); |
298 | to_copy = sizeof(istate_t); |
337 | to_copy = sizeof(istate_t); |
299 | 338 | ||
300 | IPC_SET_RETVAL(call->data, 0); |
339 | IPC_SET_RETVAL(call->data, 0); |
301 | /* ARG1=dest, ARG2=size as in IPC_M_DATA_READ so that |
340 | /* ARG1=dest, ARG2=size as in IPC_M_DATA_READ so that |
302 | same code in process_answer() can be used |
341 | same code in process_answer() can be used |
303 | (no way to distinguish method in answer) */ |
342 | (no way to distinguish method in answer) */ |
304 | IPC_SET_ARG1(call->data, uspace_addr); |
343 | IPC_SET_ARG1(call->data, uspace_addr); |
305 | IPC_SET_ARG2(call->data, to_copy); |
344 | IPC_SET_ARG2(call->data, to_copy); |
306 | 345 | ||
307 | call->buffer = buffer; |
346 | call->buffer = buffer; |
308 | 347 | ||
309 | ipc_answer(&TASK->kernel_box, call); |
348 | ipc_answer(&TASK->kernel_box, call); |
310 | } |
349 | } |
311 | 350 | ||
312 | static void udebug_receive_regs_write(call_t *call) |
351 | static void udebug_receive_regs_write(call_t *call) |
313 | { |
352 | { |
314 | thread_t *t; |
353 | thread_t *t; |
315 | void *uspace_data; |
354 | void *uspace_data; |
316 | int rc; |
355 | int rc; |
317 | 356 | ||
318 | t = (thread_t *) IPC_GET_ARG2(call->data); |
357 | t = (thread_t *) IPC_GET_ARG2(call->data); |
319 | uspace_data = (void *)IPC_GET_ARG3(call->data); |
358 | uspace_data = (void *)IPC_GET_ARG3(call->data); |
320 | 359 | ||
321 | rc = udebug_regs_write(t, call->buffer); |
360 | rc = udebug_regs_write(t, call->buffer); |
322 | if (rc < 0) { |
361 | if (rc < 0) { |
323 | IPC_SET_RETVAL(call->data, rc); |
362 | IPC_SET_RETVAL(call->data, rc); |
324 | ipc_answer(&TASK->kernel_box, call); |
363 | ipc_answer(&TASK->kernel_box, call); |
325 | return; |
364 | return; |
326 | } |
365 | } |
327 | 366 | ||
328 | /* Set answer values */ |
367 | /* Set answer values */ |
329 | 368 | ||
330 | IPC_SET_RETVAL(call->data, 0); |
369 | IPC_SET_RETVAL(call->data, 0); |
331 | free(call->buffer); |
370 | free(call->buffer); |
332 | call->buffer = NULL; |
371 | call->buffer = NULL; |
333 | 372 | ||
334 | ipc_answer(&TASK->kernel_box, call); |
373 | ipc_answer(&TASK->kernel_box, call); |
335 | } |
374 | } |
336 | 375 | ||
- | 376 | /** Process an MEM_READ call. |
|
337 | 377 | * |
|
- | 378 | * Reads memory of the current (debugged) task. |
|
- | 379 | * @param call The call structure. |
|
- | 380 | */ |
|
338 | static void udebug_receive_mem_read(call_t *call) |
381 | static void udebug_receive_mem_read(call_t *call) |
339 | { |
382 | { |
340 | unative_t uspace_dst; |
383 | unative_t uspace_dst; |
341 | unative_t uspace_src; |
384 | unative_t uspace_src; |
342 | unsigned size; |
385 | unsigned size; |
343 | void *buffer; |
386 | void *buffer; |
344 | int rc; |
387 | int rc; |
345 | 388 | ||
346 | uspace_dst = IPC_GET_ARG2(call->data); |
389 | uspace_dst = IPC_GET_ARG2(call->data); |
347 | uspace_src = IPC_GET_ARG3(call->data); |
390 | uspace_src = IPC_GET_ARG3(call->data); |
348 | size = IPC_GET_ARG4(call->data); |
391 | size = IPC_GET_ARG4(call->data); |
349 | 392 | ||
350 | rc = udebug_mem_read(uspace_src, size, &buffer); |
393 | rc = udebug_mem_read(uspace_src, size, &buffer); |
351 | if (rc < 0) { |
394 | if (rc < 0) { |
352 | IPC_SET_RETVAL(call->data, rc); |
395 | IPC_SET_RETVAL(call->data, rc); |
353 | ipc_answer(&TASK->kernel_box, call); |
396 | ipc_answer(&TASK->kernel_box, call); |
354 | return; |
397 | return; |
355 | } |
398 | } |
356 | 399 | ||
357 | IPC_SET_RETVAL(call->data, 0); |
400 | IPC_SET_RETVAL(call->data, 0); |
358 | /* ARG1=dest, ARG2=size as in IPC_M_DATA_READ so that |
401 | /* ARG1=dest, ARG2=size as in IPC_M_DATA_READ so that |
359 | same code in process_answer() can be used |
402 | same code in process_answer() can be used |
360 | (no way to distinguish method in answer) */ |
403 | (no way to distinguish method in answer) */ |
361 | IPC_SET_ARG1(call->data, uspace_dst); |
404 | IPC_SET_ARG1(call->data, uspace_dst); |
362 | IPC_SET_ARG2(call->data, size); |
405 | IPC_SET_ARG2(call->data, size); |
363 | call->buffer = buffer; |
406 | call->buffer = buffer; |
364 | 407 | ||
365 | ipc_answer(&TASK->kernel_box, call); |
408 | ipc_answer(&TASK->kernel_box, call); |
366 | } |
409 | } |
367 | 410 | ||
368 | static void udebug_receive_mem_write(call_t *call) |
411 | static void udebug_receive_mem_write(call_t *call) |
369 | { |
412 | { |
370 | unative_t uspace_dst; |
413 | unative_t uspace_dst; |
371 | unsigned size; |
414 | unsigned size; |
372 | int rc; |
415 | int rc; |
373 | 416 | ||
374 | printf("udebug_receive_mem_write()\n"); |
417 | printf("udebug_receive_mem_write()\n"); |
375 | 418 | ||
376 | uspace_dst = IPC_GET_ARG3(call->data); |
419 | uspace_dst = IPC_GET_ARG3(call->data); |
377 | size = IPC_GET_ARG4(call->data); |
420 | size = IPC_GET_ARG4(call->data); |
378 | 421 | ||
379 | rc = udebug_mem_write(uspace_dst, call->buffer, size); |
422 | rc = udebug_mem_write(uspace_dst, call->buffer, size); |
380 | if (rc < 0) { |
423 | if (rc < 0) { |
381 | IPC_SET_RETVAL(call->data, rc); |
424 | IPC_SET_RETVAL(call->data, rc); |
382 | ipc_answer(&TASK->kernel_box, call); |
425 | ipc_answer(&TASK->kernel_box, call); |
383 | return; |
426 | return; |
384 | } |
427 | } |
385 | 428 | ||
386 | IPC_SET_RETVAL(call->data, 0); |
429 | IPC_SET_RETVAL(call->data, 0); |
387 | free(call->buffer); |
430 | free(call->buffer); |
388 | call->buffer = NULL; |
431 | call->buffer = NULL; |
389 | 432 | ||
390 | ipc_answer(&TASK->kernel_box, call); |
433 | ipc_answer(&TASK->kernel_box, call); |
391 | } |
434 | } |
392 | 435 | ||
393 | 436 | ||
394 | /** |
- | |
395 | * Handle a debug call received on the kernel answerbox. |
437 | /** Handle a debug call received on the kernel answerbox. |
396 | * |
438 | * |
397 | * This is called by the kbox servicing thread. |
439 | * This is called by the kbox servicing thread. Verifies that the sender |
- | 440 | * is indeed the debugger and calls the appropriate processing function. |
|
398 | */ |
441 | */ |
399 | void udebug_call_receive(call_t *call) |
442 | void udebug_call_receive(call_t *call) |
400 | { |
443 | { |
401 | int debug_method; |
444 | int debug_method; |
402 | 445 | ||
403 | debug_method = IPC_GET_ARG1(call->data); |
446 | debug_method = IPC_GET_ARG1(call->data); |
404 | 447 | ||
405 | if (debug_method != UDEBUG_M_BEGIN) { |
448 | if (debug_method != UDEBUG_M_BEGIN) { |
406 | /* |
449 | /* |
407 | * Verify that the sender is this task's debugger. |
450 | * Verify that the sender is this task's debugger. |
408 | * Note that this is the only thread that could change |
451 | * Note that this is the only thread that could change |
409 | * TASK->debugger. Therefore no locking is necessary |
452 | * TASK->debugger. Therefore no locking is necessary |
410 | * and the sender can be safely considered valid until |
453 | * and the sender can be safely considered valid until |
411 | * control exits this function. |
454 | * control exits this function. |
412 | */ |
455 | */ |
413 | if (TASK->udebug.debugger != call->sender) { |
456 | if (TASK->udebug.debugger != call->sender) { |
414 | IPC_SET_RETVAL(call->data, EINVAL); |
457 | IPC_SET_RETVAL(call->data, EINVAL); |
415 | ipc_answer(&TASK->kernel_box, call); |
458 | ipc_answer(&TASK->kernel_box, call); |
416 | return; |
459 | return; |
417 | } |
460 | } |
418 | } |
461 | } |
419 | 462 | ||
420 | switch (debug_method) { |
463 | switch (debug_method) { |
421 | case UDEBUG_M_BEGIN: |
464 | case UDEBUG_M_BEGIN: |
422 | udebug_receive_begin(call); |
465 | udebug_receive_begin(call); |
423 | break; |
466 | break; |
424 | case UDEBUG_M_END: |
467 | case UDEBUG_M_END: |
425 | udebug_receive_end(call); |
468 | udebug_receive_end(call); |
426 | break; |
469 | break; |
427 | case UDEBUG_M_SET_EVMASK: |
470 | case UDEBUG_M_SET_EVMASK: |
428 | udebug_receive_set_evmask(call); |
471 | udebug_receive_set_evmask(call); |
429 | break; |
472 | break; |
430 | case UDEBUG_M_GO: |
473 | case UDEBUG_M_GO: |
431 | udebug_receive_go(call); |
474 | udebug_receive_go(call); |
432 | break; |
475 | break; |
433 | case UDEBUG_M_STOP: |
476 | case UDEBUG_M_STOP: |
434 | udebug_receive_stop(call); |
477 | udebug_receive_stop(call); |
435 | break; |
478 | break; |
436 | case UDEBUG_M_THREAD_READ: |
479 | case UDEBUG_M_THREAD_READ: |
437 | udebug_receive_thread_read(call); |
480 | udebug_receive_thread_read(call); |
438 | break; |
481 | break; |
439 | case UDEBUG_M_ARGS_READ: |
482 | case UDEBUG_M_ARGS_READ: |
440 | udebug_receive_args_read(call); |
483 | udebug_receive_args_read(call); |
441 | break; |
484 | break; |
442 | case UDEBUG_M_REGS_READ: |
485 | case UDEBUG_M_REGS_READ: |
443 | udebug_receive_regs_read(call); |
486 | udebug_receive_regs_read(call); |
444 | break; |
487 | break; |
445 | case UDEBUG_M_REGS_WRITE: |
488 | case UDEBUG_M_REGS_WRITE: |
446 | udebug_receive_regs_write(call); |
489 | udebug_receive_regs_write(call); |
447 | break; |
490 | break; |
448 | case UDEBUG_M_MEM_READ: |
491 | case UDEBUG_M_MEM_READ: |
449 | udebug_receive_mem_read(call); |
492 | udebug_receive_mem_read(call); |
450 | break; |
493 | break; |
451 | case UDEBUG_M_MEM_WRITE: |
494 | case UDEBUG_M_MEM_WRITE: |
452 | udebug_receive_mem_write(call); |
495 | udebug_receive_mem_write(call); |
453 | break; |
496 | break; |
454 | } |
497 | } |
455 | } |
498 | } |
456 | 499 | ||
457 | /** @} |
500 | /** @} |
458 | */ |
501 | */ |
459 | 502 |