Rev 3438 | Rev 3457 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3438 | Rev 3441 | ||
---|---|---|---|
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 | */ |
36 | */ |
37 | 37 | ||
38 | #include <print.h> |
- | |
39 | #include <proc/task.h> |
38 | #include <proc/task.h> |
40 | #include <proc/thread.h> |
39 | #include <proc/thread.h> |
41 | #include <arch.h> |
40 | #include <arch.h> |
42 | #include <errno.h> |
41 | #include <errno.h> |
43 | #include <ipc/ipc.h> |
42 | #include <ipc/ipc.h> |
44 | #include <syscall/copy.h> |
43 | #include <syscall/copy.h> |
45 | #include <udebug/udebug.h> |
44 | #include <udebug/udebug.h> |
46 | #include <udebug/udebug_ops.h> |
45 | #include <udebug/udebug_ops.h> |
47 | #include <udebug/udebug_ipc.h> |
46 | #include <udebug/udebug_ipc.h> |
48 | 47 | ||
49 | int udebug_request_preprocess(call_t *call, phone_t *phone) |
48 | int udebug_request_preprocess(call_t *call, phone_t *phone) |
50 | { |
49 | { |
51 | switch (IPC_GET_ARG1(call->data)) { |
50 | switch (IPC_GET_ARG1(call->data)) { |
52 | /* future UDEBUG_M_REGS_WRITE, UDEBUG_M_MEM_WRITE: */ |
51 | /* future UDEBUG_M_REGS_WRITE, UDEBUG_M_MEM_WRITE: */ |
53 | default: |
52 | default: |
54 | break; |
53 | break; |
55 | } |
54 | } |
56 | 55 | ||
57 | return 0; |
56 | return 0; |
58 | } |
57 | } |
59 | 58 | ||
60 | static void udebug_receive_begin(call_t *call) |
59 | static void udebug_receive_begin(call_t *call) |
61 | { |
60 | { |
62 | int rc; |
61 | int rc; |
63 | 62 | ||
64 | rc = udebug_begin(call); |
63 | rc = udebug_begin(call); |
65 | if (rc < 0) { |
64 | if (rc < 0) { |
66 | IPC_SET_RETVAL(call->data, rc); |
65 | IPC_SET_RETVAL(call->data, rc); |
67 | ipc_answer(&TASK->kernel_box, call); |
66 | ipc_answer(&TASK->kernel_box, call); |
68 | return; |
67 | return; |
69 | } |
68 | } |
70 | 69 | ||
71 | if (rc != 0) { |
70 | if (rc != 0) { |
72 | IPC_SET_RETVAL(call->data, 0); |
71 | IPC_SET_RETVAL(call->data, 0); |
73 | ipc_answer(&TASK->kernel_box, call); |
72 | ipc_answer(&TASK->kernel_box, call); |
74 | } |
73 | } |
75 | } |
74 | } |
76 | 75 | ||
77 | static void udebug_receive_end(call_t *call) |
76 | static void udebug_receive_end(call_t *call) |
78 | { |
77 | { |
79 | int rc; |
78 | int rc; |
80 | 79 | ||
81 | rc = udebug_end(); |
80 | rc = udebug_end(); |
82 | 81 | ||
83 | IPC_SET_RETVAL(call->data, rc); |
82 | IPC_SET_RETVAL(call->data, rc); |
84 | ipc_answer(&TASK->kernel_box, call); |
83 | ipc_answer(&TASK->kernel_box, call); |
85 | } |
84 | } |
86 | 85 | ||
87 | static void udebug_receive_set_evmask(call_t *call) |
86 | static void udebug_receive_set_evmask(call_t *call) |
88 | { |
87 | { |
89 | int rc; |
88 | int rc; |
90 | udebug_evmask_t mask; |
89 | udebug_evmask_t mask; |
91 | 90 | ||
92 | mask = IPC_GET_ARG2(call->data); |
91 | mask = IPC_GET_ARG2(call->data); |
93 | rc = udebug_set_evmask(mask); |
92 | rc = udebug_set_evmask(mask); |
94 | 93 | ||
95 | IPC_SET_RETVAL(call->data, rc); |
94 | IPC_SET_RETVAL(call->data, rc); |
96 | ipc_answer(&TASK->kernel_box, call); |
95 | ipc_answer(&TASK->kernel_box, call); |
97 | } |
96 | } |
98 | 97 | ||
99 | 98 | ||
100 | static void udebug_receive_go(call_t *call) |
99 | static void udebug_receive_go(call_t *call) |
101 | { |
100 | { |
102 | thread_t *t; |
101 | thread_t *t; |
103 | int rc; |
102 | int rc; |
104 | 103 | ||
105 | //printf("debug_go()\n"); |
- | |
106 | - | ||
107 | t = (thread_t *)IPC_GET_ARG2(call->data); |
104 | t = (thread_t *)IPC_GET_ARG2(call->data); |
108 | 105 | ||
109 | rc = udebug_go(t, call); |
106 | rc = udebug_go(t, call); |
110 | if (rc < 0) { |
107 | if (rc < 0) { |
111 | IPC_SET_RETVAL(call->data, rc); |
108 | IPC_SET_RETVAL(call->data, rc); |
112 | ipc_answer(&TASK->kernel_box, call); |
109 | ipc_answer(&TASK->kernel_box, call); |
113 | return; |
110 | return; |
114 | } |
111 | } |
115 | } |
112 | } |
116 | 113 | ||
117 | static void udebug_receive_stop(call_t *call) |
114 | static void udebug_receive_stop(call_t *call) |
118 | { |
115 | { |
119 | thread_t *t; |
116 | thread_t *t; |
120 | int rc; |
117 | int rc; |
121 | 118 | ||
122 | printf("debug_stop()\n"); |
- | |
123 | - | ||
124 | t = (thread_t *)IPC_GET_ARG2(call->data); |
119 | t = (thread_t *)IPC_GET_ARG2(call->data); |
125 | 120 | ||
126 | rc = udebug_stop(t, call); |
121 | rc = udebug_stop(t, call); |
127 | IPC_SET_RETVAL(call->data, rc); |
122 | IPC_SET_RETVAL(call->data, rc); |
128 | ipc_answer(&TASK->kernel_box, call); |
123 | ipc_answer(&TASK->kernel_box, call); |
129 | } |
124 | } |
130 | 125 | ||
131 | static void udebug_receive_thread_read(call_t *call) |
126 | static void udebug_receive_thread_read(call_t *call) |
132 | { |
127 | { |
133 | unative_t uspace_addr; |
128 | unative_t uspace_addr; |
134 | unative_t to_copy; |
129 | unative_t to_copy; |
135 | unsigned total_bytes; |
130 | unsigned total_bytes; |
136 | unsigned buf_size; |
131 | unsigned buf_size; |
137 | void *buffer; |
132 | void *buffer; |
138 | size_t n; |
133 | size_t n; |
139 | int rc; |
134 | int rc; |
140 | 135 | ||
141 | uspace_addr = IPC_GET_ARG2(call->data); /* Destination address */ |
136 | uspace_addr = IPC_GET_ARG2(call->data); /* Destination address */ |
142 | buf_size = IPC_GET_ARG3(call->data); /* Dest. buffer size */ |
137 | buf_size = IPC_GET_ARG3(call->data); /* Dest. buffer size */ |
143 | 138 | ||
144 | /* |
139 | /* |
145 | * Read thread list. Variable n will be filled with actual number |
140 | * Read thread list. Variable n will be filled with actual number |
146 | * of threads times thread-id size. |
141 | * of threads times thread-id size. |
147 | */ |
142 | */ |
148 | rc = udebug_thread_read(&buffer, buf_size, &n); |
143 | rc = udebug_thread_read(&buffer, buf_size, &n); |
149 | if (rc < 0) { |
144 | if (rc < 0) { |
150 | IPC_SET_RETVAL(call->data, rc); |
145 | IPC_SET_RETVAL(call->data, rc); |
151 | ipc_answer(&TASK->kernel_box, call); |
146 | ipc_answer(&TASK->kernel_box, call); |
152 | return; |
147 | return; |
153 | } |
148 | } |
154 | 149 | ||
155 | total_bytes = n; |
150 | total_bytes = n; |
156 | 151 | ||
157 | /* Copy MAX(buf_size, total_bytes) bytes */ |
152 | /* Copy MAX(buf_size, total_bytes) bytes */ |
158 | 153 | ||
159 | if (buf_size > total_bytes) |
154 | if (buf_size > total_bytes) |
160 | to_copy = total_bytes; |
155 | to_copy = total_bytes; |
161 | else |
156 | else |
162 | to_copy = buf_size; |
157 | to_copy = buf_size; |
163 | 158 | ||
164 | /* |
159 | /* |
165 | * Make use of call->buffer to transfer data to caller's userspace |
160 | * Make use of call->buffer to transfer data to caller's userspace |
166 | */ |
161 | */ |
167 | 162 | ||
168 | IPC_SET_RETVAL(call->data, 0); |
163 | IPC_SET_RETVAL(call->data, 0); |
169 | /* ARG1=dest, ARG2=size as in IPC_M_DATA_READ so that |
164 | /* ARG1=dest, ARG2=size as in IPC_M_DATA_READ so that |
170 | same code in process_answer() can be used |
165 | same code in process_answer() can be used |
171 | (no way to distinguish method in answer) */ |
166 | (no way to distinguish method in answer) */ |
172 | IPC_SET_ARG1(call->data, uspace_addr); |
167 | IPC_SET_ARG1(call->data, uspace_addr); |
173 | IPC_SET_ARG2(call->data, to_copy); |
168 | IPC_SET_ARG2(call->data, to_copy); |
174 | 169 | ||
175 | IPC_SET_ARG3(call->data, total_bytes); |
170 | IPC_SET_ARG3(call->data, total_bytes); |
176 | call->buffer = buffer; |
171 | call->buffer = buffer; |
177 | 172 | ||
178 | ipc_answer(&TASK->kernel_box, call); |
173 | ipc_answer(&TASK->kernel_box, call); |
179 | } |
174 | } |
180 | 175 | ||
181 | static void udebug_receive_args_read(call_t *call) |
176 | static void udebug_receive_args_read(call_t *call) |
182 | { |
177 | { |
183 | thread_t *t; |
178 | thread_t *t; |
184 | unative_t uspace_addr; |
179 | unative_t uspace_addr; |
185 | int rc; |
180 | int rc; |
186 | void *buffer; |
181 | void *buffer; |
187 | 182 | ||
188 | t = (thread_t *)IPC_GET_ARG2(call->data); |
183 | t = (thread_t *)IPC_GET_ARG2(call->data); |
189 | 184 | ||
190 | rc = udebug_args_read(t, &buffer); |
185 | rc = udebug_args_read(t, &buffer); |
191 | if (rc != EOK) { |
186 | if (rc != EOK) { |
192 | IPC_SET_RETVAL(call->data, rc); |
187 | IPC_SET_RETVAL(call->data, rc); |
193 | ipc_answer(&TASK->kernel_box, call); |
188 | ipc_answer(&TASK->kernel_box, call); |
194 | return; |
189 | return; |
195 | } |
190 | } |
196 | 191 | ||
197 | /* |
192 | /* |
198 | * Make use of call->buffer to transfer data to caller's userspace |
193 | * Make use of call->buffer to transfer data to caller's userspace |
199 | */ |
194 | */ |
200 | 195 | ||
201 | uspace_addr = IPC_GET_ARG3(call->data); |
196 | uspace_addr = IPC_GET_ARG3(call->data); |
202 | 197 | ||
203 | IPC_SET_RETVAL(call->data, 0); |
198 | IPC_SET_RETVAL(call->data, 0); |
204 | /* ARG1=dest, ARG2=size as in IPC_M_DATA_READ so that |
199 | /* ARG1=dest, ARG2=size as in IPC_M_DATA_READ so that |
205 | same code in process_answer() can be used |
200 | same code in process_answer() can be used |
206 | (no way to distinguish method in answer) */ |
201 | (no way to distinguish method in answer) */ |
207 | IPC_SET_ARG1(call->data, uspace_addr); |
202 | IPC_SET_ARG1(call->data, uspace_addr); |
208 | IPC_SET_ARG2(call->data, 6 * sizeof(unative_t)); |
203 | IPC_SET_ARG2(call->data, 6 * sizeof(unative_t)); |
209 | call->buffer = buffer; |
204 | call->buffer = buffer; |
210 | 205 | ||
211 | ipc_answer(&TASK->kernel_box, call); |
206 | ipc_answer(&TASK->kernel_box, call); |
212 | } |
207 | } |
213 | 208 | ||
214 | static void udebug_receive_mem_read(call_t *call) |
209 | static void udebug_receive_mem_read(call_t *call) |
215 | { |
210 | { |
216 | unative_t uspace_dst; |
211 | unative_t uspace_dst; |
217 | unative_t uspace_src; |
212 | unative_t uspace_src; |
218 | unsigned size; |
213 | unsigned size; |
219 | void *buffer; |
214 | void *buffer; |
220 | int rc; |
215 | int rc; |
221 | 216 | ||
222 | uspace_dst = IPC_GET_ARG2(call->data); |
217 | uspace_dst = IPC_GET_ARG2(call->data); |
223 | uspace_src = IPC_GET_ARG3(call->data); |
218 | uspace_src = IPC_GET_ARG3(call->data); |
224 | size = IPC_GET_ARG4(call->data); |
219 | size = IPC_GET_ARG4(call->data); |
225 | 220 | ||
226 | rc = udebug_mem_read(uspace_src, size, &buffer); |
221 | rc = udebug_mem_read(uspace_src, size, &buffer); |
227 | if (rc < 0) { |
222 | if (rc < 0) { |
228 | IPC_SET_RETVAL(call->data, rc); |
223 | IPC_SET_RETVAL(call->data, rc); |
229 | ipc_answer(&TASK->kernel_box, call); |
224 | ipc_answer(&TASK->kernel_box, call); |
230 | return; |
225 | return; |
231 | } |
226 | } |
232 | 227 | ||
233 | IPC_SET_RETVAL(call->data, 0); |
228 | IPC_SET_RETVAL(call->data, 0); |
234 | /* ARG1=dest, ARG2=size as in IPC_M_DATA_READ so that |
229 | /* ARG1=dest, ARG2=size as in IPC_M_DATA_READ so that |
235 | same code in process_answer() can be used |
230 | same code in process_answer() can be used |
236 | (no way to distinguish method in answer) */ |
231 | (no way to distinguish method in answer) */ |
237 | IPC_SET_ARG1(call->data, uspace_dst); |
232 | IPC_SET_ARG1(call->data, uspace_dst); |
238 | IPC_SET_ARG2(call->data, size); |
233 | IPC_SET_ARG2(call->data, size); |
239 | call->buffer = buffer; |
234 | call->buffer = buffer; |
240 | 235 | ||
241 | ipc_answer(&TASK->kernel_box, call); |
236 | ipc_answer(&TASK->kernel_box, call); |
242 | } |
237 | } |
243 | 238 | ||
244 | /** |
239 | /** |
245 | * Handle a debug call received on the kernel answerbox. |
240 | * Handle a debug call received on the kernel answerbox. |
246 | * |
241 | * |
247 | * This is called by the kbox servicing thread. |
242 | * This is called by the kbox servicing thread. |
248 | */ |
243 | */ |
249 | void udebug_call_receive(call_t *call) |
244 | void udebug_call_receive(call_t *call) |
250 | { |
245 | { |
251 | int debug_method; |
246 | int debug_method; |
252 | 247 | ||
253 | debug_method = IPC_GET_ARG1(call->data); |
248 | debug_method = IPC_GET_ARG1(call->data); |
254 | 249 | ||
255 | if (debug_method != UDEBUG_M_BEGIN) { |
250 | if (debug_method != UDEBUG_M_BEGIN) { |
256 | /* |
251 | /* |
257 | * Verify that the sender is this task's debugger. |
252 | * Verify that the sender is this task's debugger. |
258 | * Note that this is the only thread that could change |
253 | * Note that this is the only thread that could change |
259 | * TASK->debugger. Therefore no locking is necessary |
254 | * TASK->debugger. Therefore no locking is necessary |
260 | * and the sender can be safely considered valid until |
255 | * and the sender can be safely considered valid until |
261 | * control exits this function. |
256 | * control exits this function. |
262 | */ |
257 | */ |
263 | if (TASK->udebug.debugger != call->sender) { |
258 | if (TASK->udebug.debugger != call->sender) { |
264 | IPC_SET_RETVAL(call->data, EINVAL); |
259 | IPC_SET_RETVAL(call->data, EINVAL); |
265 | ipc_answer(&TASK->kernel_box, call); |
260 | ipc_answer(&TASK->kernel_box, call); |
266 | return; |
261 | return; |
267 | } |
262 | } |
268 | } |
263 | } |
269 | 264 | ||
270 | switch (debug_method) { |
265 | switch (debug_method) { |
271 | case UDEBUG_M_BEGIN: |
266 | case UDEBUG_M_BEGIN: |
272 | udebug_receive_begin(call); |
267 | udebug_receive_begin(call); |
273 | break; |
268 | break; |
274 | case UDEBUG_M_END: |
269 | case UDEBUG_M_END: |
275 | udebug_receive_end(call); |
270 | udebug_receive_end(call); |
276 | break; |
271 | break; |
277 | case UDEBUG_M_SET_EVMASK: |
272 | case UDEBUG_M_SET_EVMASK: |
278 | udebug_receive_set_evmask(call); |
273 | udebug_receive_set_evmask(call); |
279 | break; |
274 | break; |
280 | case UDEBUG_M_GO: |
275 | case UDEBUG_M_GO: |
281 | udebug_receive_go(call); |
276 | udebug_receive_go(call); |
282 | break; |
277 | break; |
283 | case UDEBUG_M_STOP: |
278 | case UDEBUG_M_STOP: |
284 | udebug_receive_stop(call); |
279 | udebug_receive_stop(call); |
285 | break; |
280 | break; |
286 | case UDEBUG_M_THREAD_READ: |
281 | case UDEBUG_M_THREAD_READ: |
287 | udebug_receive_thread_read(call); |
282 | udebug_receive_thread_read(call); |
288 | break; |
283 | break; |
289 | case UDEBUG_M_ARGS_READ: |
284 | case UDEBUG_M_ARGS_READ: |
290 | udebug_receive_args_read(call); |
285 | udebug_receive_args_read(call); |
291 | break; |
286 | break; |
292 | case UDEBUG_M_MEM_READ: |
287 | case UDEBUG_M_MEM_READ: |
293 | udebug_receive_mem_read(call); |
288 | udebug_receive_mem_read(call); |
294 | break; |
289 | break; |
295 | } |
290 | } |
296 | } |
291 | } |
297 | 292 | ||
298 | /** @} |
293 | /** @} |
299 | */ |
294 | */ |
300 | 295 |