Rev 2838 | Rev 2842 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2813 | svoboda | 1 | /** @addtogroup generic |
2 | * @{ |
||
3 | */ |
||
4 | |||
5 | /** |
||
6 | * @file |
||
7 | * @brief Tdebug. |
||
8 | */ |
||
9 | |||
10 | #include <console/klog.h> |
||
11 | #include <proc/task.h> |
||
12 | #include <proc/thread.h> |
||
2815 | svoboda | 13 | #include <arch.h> |
2813 | svoboda | 14 | #include <errno.h> |
15 | #include <ipc/ipc.h> |
||
16 | #include <syscall/copy.h> |
||
17 | #include <udebug/udebug.h> |
||
18 | #include <udebug/udebug_ipc.h> |
||
19 | |||
2823 | svoboda | 20 | /** |
21 | * Get and lock a phone's callee task. |
||
22 | * |
||
23 | * This will return a pointer to the task to which the phone |
||
24 | * is connected. It will lock the task, making sure it exists. |
||
25 | * (TODO: make sure the udebug-cleanup of the task hasn't |
||
26 | * started yet) |
||
27 | */ |
||
2813 | svoboda | 28 | static task_t *get_lock_callee_task(phone_t *phone) |
29 | { |
||
2823 | svoboda | 30 | answerbox_t *box; |
2813 | svoboda | 31 | task_t *ta; |
2823 | svoboda | 32 | task_id_t taskid; |
33 | ipl_t ipl; |
||
2813 | svoboda | 34 | |
2823 | svoboda | 35 | ipl = interrupts_disable(); |
36 | spinlock_lock(&phone->lock); |
||
37 | if (phone->state != IPC_PHONE_CONNECTED) { |
||
38 | spinlock_unlock(&phone->lock); |
||
39 | interrupts_restore(ipl); |
||
40 | return NULL; |
||
41 | } |
||
2813 | svoboda | 42 | |
2823 | svoboda | 43 | box = phone->callee; |
44 | |||
45 | spinlock_lock(&box->lock); |
||
46 | ta = box->task; |
||
47 | taskid = ta->taskid; |
||
48 | spinlock_unlock(&box->lock); |
||
49 | spinlock_unlock(&phone->lock); |
||
2813 | svoboda | 50 | |
2823 | svoboda | 51 | /* Locking decoupled using taskid */ |
52 | |||
53 | spinlock_lock(&tasks_lock); |
||
54 | ta = task_find_by_id(taskid); |
||
55 | if (ta == NULL) { |
||
56 | spinlock_unlock(&tasks_lock); |
||
57 | interrupts_restore(ipl); |
||
58 | return NULL; |
||
59 | } |
||
60 | |||
2813 | svoboda | 61 | spinlock_lock(&ta->lock); |
2823 | svoboda | 62 | spinlock_unlock(&tasks_lock); |
63 | interrupts_restore(ipl); |
||
2813 | svoboda | 64 | |
65 | return ta; |
||
66 | } |
||
67 | |||
2841 | svoboda | 68 | static int verify_thread(thread_t *t) |
69 | { |
||
70 | /* Verify that 't' exists and belongs to task 'ta' */ |
||
71 | if (!thread_exists(t) || (t->task != ta)) { |
||
72 | spinlock_unlock(&threads_lock); |
||
73 | interrupts_restore(ipl); |
||
74 | return ENOENT; |
||
75 | } |
||
76 | |||
77 | /* Verify that 't' is a userspace thread */ |
||
78 | if ((t->flags & THREAD_FLAG_USPACE) == 0) { |
||
79 | /* It's not, deny its existence */ |
||
80 | return ENOENT; |
||
81 | } |
||
82 | |||
83 | if ((t->debug_active != true) || (t->debug_stop != true)) { |
||
84 | /* Not in debugging session or already has GO */ |
||
85 | spinlock_unlock(&threads_lock); |
||
86 | interrupts_restore(ipl); |
||
87 | return EBUSY; |
||
88 | } |
||
89 | |||
90 | return EOK; |
||
91 | } |
||
92 | |||
2813 | svoboda | 93 | static int udebug_rp_begin(call_t *call, phone_t *phone) |
94 | { |
||
95 | task_t *ta; |
||
2823 | svoboda | 96 | ipl_t ipl; |
2827 | svoboda | 97 | int rc; |
2813 | svoboda | 98 | |
2827 | svoboda | 99 | thread_t *t; |
100 | link_t *cur; |
||
101 | |||
2813 | svoboda | 102 | klog_printf("debug_begin()"); |
103 | |||
2823 | svoboda | 104 | ipl = interrupts_disable(); |
2813 | svoboda | 105 | ta = get_lock_callee_task(phone); |
106 | klog_printf("debugging task %llu", ta->taskid); |
||
107 | |||
2825 | svoboda | 108 | if (ta->dt_state != UDEBUG_TS_INACTIVE) { |
2813 | svoboda | 109 | spinlock_unlock(&ta->lock); |
2823 | svoboda | 110 | interrupts_restore(ipl); |
2813 | svoboda | 111 | klog_printf("debug_begin(): busy error"); |
112 | return EBUSY; |
||
113 | } |
||
114 | |||
2825 | svoboda | 115 | ta->dt_state = UDEBUG_TS_BEGINNING; |
2813 | svoboda | 116 | ta->debug_begin_call = call; |
117 | |||
118 | if (ta->not_stoppable_count == 0) { |
||
2825 | svoboda | 119 | ta->dt_state = UDEBUG_TS_ACTIVE; |
2813 | svoboda | 120 | ta->debug_begin_call = NULL; |
2827 | svoboda | 121 | rc = 1; /* actually we need backsend with 0 retval */ |
122 | } else { |
||
123 | rc = 0; /* no backsend */ |
||
2813 | svoboda | 124 | } |
2827 | svoboda | 125 | |
126 | /* Set debug_active on all of the task's userspace threads */ |
||
2813 | svoboda | 127 | |
2827 | svoboda | 128 | for (cur = ta->th_head.next; cur != &ta->th_head; cur = cur->next) { |
129 | t = list_get_instance(cur, thread_t, th_link); |
||
130 | |||
131 | spinlock_lock(&t->lock); |
||
132 | if ((t->flags & THREAD_FLAG_USPACE) != 0) |
||
133 | t->debug_active = true; |
||
134 | spinlock_unlock(&t->lock); |
||
135 | } |
||
136 | |||
2813 | svoboda | 137 | spinlock_unlock(&ta->lock); |
2823 | svoboda | 138 | interrupts_restore(ipl); |
2813 | svoboda | 139 | |
2827 | svoboda | 140 | klog_printf("debug_begin() done (%s)", |
141 | rc ? "backsend" : "stoppability wait"); |
||
142 | |||
143 | return rc; |
||
2813 | svoboda | 144 | } |
145 | |||
2834 | svoboda | 146 | static int udebug_rp_end(call_t *call, phone_t *phone) |
147 | { |
||
148 | task_t *ta; |
||
149 | ipl_t ipl; |
||
150 | |||
151 | thread_t *t; |
||
152 | link_t *cur; |
||
153 | |||
154 | klog_printf("udebug_rp_end()"); |
||
155 | |||
156 | ipl = interrupts_disable(); |
||
157 | ta = get_lock_callee_task(phone); |
||
158 | klog_printf("task %llu", ta->taskid); |
||
159 | |||
2835 | svoboda | 160 | if (ta->dt_state == UDEBUG_TS_BEGINNING && |
161 | ta->dt_state != UDEBUG_TS_ACTIVE) { |
||
2834 | svoboda | 162 | spinlock_unlock(&ta->lock); |
163 | interrupts_restore(ipl); |
||
2835 | svoboda | 164 | klog_printf("udebug_rp_begin(): task not being debugged"); |
2834 | svoboda | 165 | return EINVAL; |
166 | } |
||
167 | |||
2835 | svoboda | 168 | /* Finish debugging of all userspace threads */ |
2834 | svoboda | 169 | for (cur = ta->th_head.next; cur != &ta->th_head; cur = cur->next) { |
170 | t = list_get_instance(cur, thread_t, th_link); |
||
171 | |||
172 | spinlock_lock(&t->lock); |
||
173 | |||
2835 | svoboda | 174 | /* Only process userspace threads */ |
175 | if ((t->flags & THREAD_FLAG_USPACE) != 0) { |
||
176 | /* Prevent any further debug activity in thread */ |
||
177 | t->debug_active = false; |
||
2834 | svoboda | 178 | |
2835 | svoboda | 179 | /* Still has go? */ |
180 | if (t->debug_stop == false) { |
||
181 | /* |
||
182 | * Yes, so clear go. As debug_active == false, |
||
183 | * this doesn't affect anything. |
||
184 | */ |
||
185 | t->debug_stop = true; |
||
2834 | svoboda | 186 | |
2835 | svoboda | 187 | /* Answer GO call */ |
2838 | svoboda | 188 | klog_printf("answer GO call with EVENT_FINISHED"); |
189 | IPC_SET_RETVAL(t->debug_go_call->data, 0); |
||
190 | IPC_SET_ARG1(t->debug_go_call->data, UDEBUG_EVENT_FINISHED); |
||
2835 | svoboda | 191 | ipc_answer(&ta->answerbox, t->debug_go_call); |
192 | } else { |
||
193 | /* |
||
194 | * Debug_stop is already at initial value. |
||
195 | * Yet this means the thread needs waking up. |
||
196 | */ |
||
197 | waitq_wakeup(&t->go_wq, WAKEUP_FIRST); |
||
198 | } |
||
199 | } |
||
2834 | svoboda | 200 | |
201 | spinlock_unlock(&t->lock); |
||
202 | } |
||
203 | |||
204 | ta->dt_state = UDEBUG_TS_INACTIVE; |
||
205 | |||
206 | spinlock_unlock(&ta->lock); |
||
207 | interrupts_restore(ipl); |
||
208 | |||
2838 | svoboda | 209 | IPC_SET_RETVAL(call->data, 0); |
210 | |||
2834 | svoboda | 211 | klog_printf("udebug_rp_end() done\n"); |
212 | |||
213 | return 1; |
||
214 | } |
||
215 | |||
216 | |||
2813 | svoboda | 217 | static int udebug_rp_go(call_t *call, phone_t *phone) |
218 | { |
||
219 | thread_t *t; |
||
220 | task_t *ta; |
||
2823 | svoboda | 221 | ipl_t ipl; |
2813 | svoboda | 222 | |
223 | klog_printf("debug_go()"); |
||
224 | ta = get_lock_callee_task(phone); |
||
2823 | svoboda | 225 | spinlock_unlock(&ta->lock); |
2826 | svoboda | 226 | // TODO: don't lock ta |
2823 | svoboda | 227 | |
2816 | svoboda | 228 | t = (thread_t *) IPC_GET_ARG2(call->data); |
2823 | svoboda | 229 | |
230 | ipl = interrupts_disable(); |
||
231 | spinlock_lock(&threads_lock); |
||
2825 | svoboda | 232 | |
2813 | svoboda | 233 | |
2826 | svoboda | 234 | t->debug_go_call = call; |
2825 | svoboda | 235 | t->debug_stop = false; |
2813 | svoboda | 236 | waitq_wakeup(&t->go_wq, WAKEUP_FIRST); |
2825 | svoboda | 237 | |
2823 | svoboda | 238 | spinlock_unlock(&threads_lock); |
239 | interrupts_restore(ipl); |
||
2813 | svoboda | 240 | |
241 | return 0; /* no backsend */ |
||
242 | } |
||
243 | |||
244 | static int udebug_rp_args_read(call_t *call, phone_t *phone) |
||
245 | { |
||
246 | thread_t *t; |
||
247 | task_t *ta; |
||
248 | void *uspace_buffer; |
||
249 | int rc; |
||
2823 | svoboda | 250 | ipl_t ipl; |
2827 | svoboda | 251 | unative_t buffer[6]; |
2813 | svoboda | 252 | |
253 | klog_printf("debug_args_read()"); |
||
254 | |||
255 | ta = get_lock_callee_task(phone); |
||
256 | klog_printf("task %llu", ta->taskid); |
||
2823 | svoboda | 257 | spinlock_unlock(&ta->lock); |
258 | |||
2816 | svoboda | 259 | t = (thread_t *) IPC_GET_ARG2(call->data); |
2823 | svoboda | 260 | |
261 | ipl = interrupts_disable(); |
||
262 | spinlock_lock(&threads_lock); |
||
263 | |||
2841 | svoboda | 264 | /* Verify that thread t exists and may be operated on */ |
265 | rc = verify_thread(t); |
||
266 | if (rc != EOK) { |
||
2823 | svoboda | 267 | spinlock_unlock(&threads_lock); |
268 | interrupts_restore(ipl); |
||
2841 | svoboda | 269 | return rc; |
2813 | svoboda | 270 | } |
271 | |||
2827 | svoboda | 272 | //FIXME: additionally we need to verify that we are inside a syscall |
273 | |||
274 | /* Copy to a local buffer before releasing the lock */ |
||
275 | memcpy(buffer, t->syscall_args, 6 * sizeof(unative_t)); |
||
276 | |||
2823 | svoboda | 277 | spinlock_unlock(&threads_lock); |
278 | interrupts_restore(ipl); |
||
279 | |||
2827 | svoboda | 280 | /* Now copy to userspace */ |
281 | |||
2813 | svoboda | 282 | uspace_buffer = (void *)IPC_GET_ARG3(call->data); |
283 | |||
2833 | svoboda | 284 | rc = copy_to_uspace(uspace_buffer, buffer, 6 * sizeof(unative_t)); |
2813 | svoboda | 285 | if (rc != 0) { |
286 | spinlock_unlock(&ta->lock); |
||
287 | klog_printf("debug_args_read() - copy failed"); |
||
288 | return rc; |
||
289 | } |
||
290 | |||
291 | klog_printf("debug_args_read() done"); |
||
292 | return 1; /* actually need becksend with retval 0 */ |
||
293 | } |
||
294 | |||
2817 | svoboda | 295 | static int udebug_rp_regs_read(call_t *call, phone_t *phone) |
296 | { |
||
297 | thread_t *t; |
||
298 | task_t *ta; |
||
299 | void *uspace_buffer; |
||
300 | unative_t to_copy; |
||
301 | int rc; |
||
302 | istate_t *state; |
||
2824 | svoboda | 303 | istate_t state_copy; |
304 | ipl_t ipl; |
||
2817 | svoboda | 305 | |
306 | klog_printf("debug_regs_read()"); |
||
307 | |||
2824 | svoboda | 308 | ta = get_lock_callee_task(phone); |
309 | spinlock_unlock(&ta->lock); |
||
2827 | svoboda | 310 | //FIXME: don't lock ta |
2817 | svoboda | 311 | |
2824 | svoboda | 312 | ipl = interrupts_disable(); |
313 | spinlock_lock(&threads_lock); |
||
314 | |||
2817 | svoboda | 315 | t = (thread_t *) IPC_GET_ARG2(call->data); |
2827 | svoboda | 316 | |
2841 | svoboda | 317 | /* Verify that thread t exists and may be operated on */ |
318 | rc = verify_thread(t); |
||
319 | if (rc != EOK) { |
||
2827 | svoboda | 320 | spinlock_unlock(&threads_lock); |
321 | interrupts_restore(ipl); |
||
2841 | svoboda | 322 | return rc; |
2817 | svoboda | 323 | } |
324 | |||
2824 | svoboda | 325 | state = t->uspace_state; |
326 | if (state == NULL) { |
||
327 | spinlock_unlock(&threads_lock); |
||
328 | interrupts_restore(ipl); |
||
329 | klog_printf("debug_regs_read() - istate not available"); |
||
330 | return EBUSY; |
||
331 | } |
||
332 | |||
333 | /* Copy to a local buffer so that we can release the lock */ |
||
334 | memcpy(&state_copy, state, sizeof(state_copy)); |
||
335 | spinlock_unlock(&threads_lock); |
||
336 | interrupts_restore(ipl); |
||
337 | |||
2817 | svoboda | 338 | uspace_buffer = (void *)IPC_GET_ARG3(call->data); |
339 | to_copy = IPC_GET_ARG4(call->data); |
||
340 | if (to_copy > sizeof(istate_t)) to_copy = sizeof(istate_t); |
||
341 | |||
2824 | svoboda | 342 | rc = copy_to_uspace(uspace_buffer, &state_copy, to_copy); |
2817 | svoboda | 343 | if (rc != 0) { |
344 | spinlock_unlock(&ta->lock); |
||
345 | klog_printf("debug_regs_read() - copy failed"); |
||
346 | return rc; |
||
347 | } |
||
348 | |||
349 | IPC_SET_ARG1(call->data, to_copy); |
||
350 | IPC_SET_ARG2(call->data, sizeof(istate_t)); |
||
351 | |||
352 | klog_printf("debug_regs_read() done"); |
||
353 | return 1; /* actually need becksend with retval 0 */ |
||
354 | } |
||
355 | |||
356 | static int udebug_rp_regs_write(call_t *call, phone_t *phone) |
||
357 | { |
||
358 | thread_t *t; |
||
359 | task_t *ta; |
||
360 | void *uspace_data; |
||
361 | unative_t to_copy; |
||
362 | int rc; |
||
363 | istate_t *state; |
||
2824 | svoboda | 364 | istate_t data_copy; |
365 | ipl_t ipl; |
||
2817 | svoboda | 366 | |
367 | klog_printf("debug_regs_write()"); |
||
368 | |||
2824 | svoboda | 369 | /* First copy to a local buffer */ |
2817 | svoboda | 370 | |
371 | uspace_data = (void *)IPC_GET_ARG3(call->data); |
||
372 | to_copy = IPC_GET_ARG4(call->data); |
||
373 | if (to_copy > sizeof(istate_t)) to_copy = sizeof(istate_t); |
||
374 | |||
2824 | svoboda | 375 | rc = copy_from_uspace(&data_copy, uspace_data, to_copy); |
2817 | svoboda | 376 | if (rc != 0) { |
377 | klog_printf("debug_regs_write() - copy failed"); |
||
378 | return rc; |
||
379 | } |
||
380 | |||
2824 | svoboda | 381 | ta = get_lock_callee_task(phone); |
2817 | svoboda | 382 | spinlock_unlock(&ta->lock); |
2827 | svoboda | 383 | //FIXME: don't lock ta |
2817 | svoboda | 384 | |
2824 | svoboda | 385 | /* Now try to change the thread's uspace_state */ |
386 | |||
387 | ipl = interrupts_disable(); |
||
388 | spinlock_lock(&threads_lock); |
||
389 | |||
390 | t = (thread_t *) IPC_GET_ARG2(call->data); |
||
2827 | svoboda | 391 | |
2841 | svoboda | 392 | /* Verify that thread t exists and may be operated on */ |
393 | rc = verify_thread(t); |
||
394 | if (rc != EOK) { |
||
2824 | svoboda | 395 | spinlock_unlock(&threads_lock); |
396 | interrupts_restore(ipl); |
||
2841 | svoboda | 397 | return rc; |
2824 | svoboda | 398 | } |
399 | |||
400 | state = t->uspace_state; |
||
401 | if (state == NULL) { |
||
402 | spinlock_unlock(&threads_lock); |
||
403 | interrupts_restore(ipl); |
||
404 | klog_printf("debug_regs_write() - istate not available"); |
||
405 | return EBUSY; |
||
406 | } |
||
407 | |||
408 | memcpy(t->uspace_state, &data_copy, sizeof(t->uspace_state)); |
||
409 | |||
410 | spinlock_unlock(&threads_lock); |
||
411 | interrupts_restore(ipl); |
||
412 | |||
413 | /* Set answer values */ |
||
414 | |||
2817 | svoboda | 415 | IPC_SET_ARG1(call->data, to_copy); |
416 | IPC_SET_ARG2(call->data, sizeof(istate_t)); |
||
417 | |||
418 | klog_printf("debug_regs_write() done"); |
||
419 | return 1; /* actually need becksend with retval 0 */ |
||
420 | } |
||
421 | |||
2813 | svoboda | 422 | static int udebug_rp_thread_read(call_t *call, phone_t *phone) |
423 | { |
||
424 | thread_t *t; |
||
425 | link_t *cur; |
||
426 | task_t *ta; |
||
427 | unative_t *uspace_buffer; |
||
428 | unative_t to_copy; |
||
429 | int rc; |
||
2824 | svoboda | 430 | unsigned total_bytes; |
2813 | svoboda | 431 | unsigned buf_size; |
432 | unative_t tid; |
||
2824 | svoboda | 433 | unsigned num_threads, copied_ids; |
434 | ipl_t ipl; |
||
435 | unative_t *buffer; |
||
436 | int flags; |
||
2813 | svoboda | 437 | |
438 | klog_printf("debug_thread_read()"); |
||
439 | |||
2824 | svoboda | 440 | ipl = interrupts_disable(); |
2813 | svoboda | 441 | ta = get_lock_callee_task(phone); |
442 | |||
2827 | svoboda | 443 | /* Verify task state */ |
444 | if (ta->dt_state != UDEBUG_TS_ACTIVE) { |
||
445 | spinlock_unlock(&ta->lock); |
||
446 | interrupts_restore(ipl); |
||
447 | return EBUSY; |
||
448 | } |
||
449 | |||
2824 | svoboda | 450 | /* Count the threads first */ |
451 | |||
452 | num_threads = 0; |
||
2813 | svoboda | 453 | for (cur = ta->th_head.next; cur != &ta->th_head; cur = cur->next) { |
2824 | svoboda | 454 | /* Count all threads, to be on the safe side */ |
455 | ++num_threads; |
||
456 | } |
||
457 | |||
458 | /* Allocate a buffer and copy down the threads' ids */ |
||
459 | buffer = malloc(num_threads * sizeof(unative_t), 0); // ??? |
||
460 | |||
461 | copied_ids = 0; |
||
462 | for (cur = ta->th_head.next; cur != &ta->th_head; cur = cur->next) { |
||
2813 | svoboda | 463 | t = list_get_instance(cur, thread_t, th_link); |
464 | |||
2824 | svoboda | 465 | spinlock_lock(&t->lock); |
466 | flags = t->flags; |
||
467 | spinlock_unlock(&t->lock); |
||
468 | |||
2813 | svoboda | 469 | /* Not interested in kernel threads */ |
2824 | svoboda | 470 | if ((flags & THREAD_FLAG_USPACE) != 0) { |
471 | /* Using thread struct pointer for identification */ |
||
472 | tid = (unative_t) t; |
||
473 | buffer[copied_ids++] = tid; |
||
474 | } |
||
475 | } |
||
2813 | svoboda | 476 | |
2824 | svoboda | 477 | spinlock_unlock(&ta->lock); |
478 | interrupts_restore(ipl); |
||
2813 | svoboda | 479 | |
2824 | svoboda | 480 | /* Now copy to userspace */ |
2813 | svoboda | 481 | |
2824 | svoboda | 482 | uspace_buffer = (void *)IPC_GET_ARG2(call->data); |
483 | buf_size = IPC_GET_ARG3(call->data); |
||
2813 | svoboda | 484 | |
2824 | svoboda | 485 | total_bytes = copied_ids * sizeof(unative_t); |
486 | |||
487 | if (buf_size > total_bytes) |
||
488 | to_copy = total_bytes; |
||
489 | else |
||
490 | to_copy = buf_size; |
||
491 | |||
492 | rc = copy_to_uspace(uspace_buffer, buffer, to_copy); |
||
493 | free(buffer); |
||
494 | |||
495 | if (rc != 0) { |
||
496 | klog_printf("debug_thread_read() - copy failed"); |
||
497 | return rc; |
||
2813 | svoboda | 498 | } |
499 | |||
2824 | svoboda | 500 | IPC_SET_ARG1(call->data, to_copy); |
501 | IPC_SET_ARG2(call->data, total_bytes); |
||
2813 | svoboda | 502 | |
503 | klog_printf("debug_thread_read() done"); |
||
504 | return 1; /* actually need becksend with retval 0 */ |
||
505 | } |
||
506 | |||
2818 | svoboda | 507 | static int udebug_rp_mem_write(call_t *call, phone_t *phone) |
508 | { |
||
509 | void *uspace_data; |
||
510 | unative_t to_copy; |
||
511 | int rc; |
||
512 | void *buffer; |
||
513 | |||
514 | klog_printf("udebug_rp_mem_write()"); |
||
515 | |||
516 | uspace_data = (void *)IPC_GET_ARG2(call->data); |
||
517 | to_copy = IPC_GET_ARG4(call->data); |
||
518 | |||
519 | buffer = malloc(to_copy, 0); // ??? |
||
520 | |||
521 | rc = copy_from_uspace(buffer, uspace_data, to_copy); |
||
522 | if (rc != 0) { |
||
523 | klog_printf(" - copy failed"); |
||
524 | return rc; |
||
525 | } |
||
526 | |||
527 | call->buffer = buffer; |
||
528 | |||
529 | klog_printf(" - done"); |
||
530 | return 1; /* actually need becksend with retval 0 */ |
||
531 | } |
||
532 | |||
533 | |||
2813 | svoboda | 534 | int udebug_request_preprocess(call_t *call, phone_t *phone) |
535 | { |
||
536 | int rc; |
||
537 | |||
538 | switch (IPC_GET_ARG1(call->data)) { |
||
539 | case UDEBUG_M_BEGIN: |
||
540 | rc = udebug_rp_begin(call, phone); |
||
541 | return rc; |
||
2834 | svoboda | 542 | case UDEBUG_M_END: |
543 | rc = udebug_rp_end(call, phone); |
||
544 | return rc; |
||
2813 | svoboda | 545 | case UDEBUG_M_GO: |
546 | rc = udebug_rp_go(call, phone); |
||
547 | return rc; |
||
548 | case UDEBUG_M_ARGS_READ: |
||
549 | rc = udebug_rp_args_read(call, phone); |
||
550 | return rc; |
||
2817 | svoboda | 551 | case UDEBUG_M_REGS_READ: |
552 | rc = udebug_rp_regs_read(call, phone); |
||
553 | return rc; |
||
554 | case UDEBUG_M_REGS_WRITE: |
||
555 | rc = udebug_rp_regs_write(call, phone); |
||
556 | return rc; |
||
2813 | svoboda | 557 | case UDEBUG_M_THREAD_READ: |
558 | rc = udebug_rp_thread_read(call, phone); |
||
2819 | svoboda | 559 | return rc; |
2818 | svoboda | 560 | case UDEBUG_M_MEM_WRITE: |
561 | rc = udebug_rp_mem_write(call, phone); |
||
2813 | svoboda | 562 | return rc; |
563 | default: |
||
564 | break; |
||
565 | } |
||
566 | |||
567 | return 0; |
||
568 | } |
||
569 | |||
2815 | svoboda | 570 | static void udebug_receive_mem_read(call_t *call) |
571 | { |
||
572 | unative_t uspace_dst; |
||
573 | void *uspace_ptr; |
||
574 | unsigned size; |
||
575 | void *buffer; |
||
576 | int rc; |
||
2813 | svoboda | 577 | |
2815 | svoboda | 578 | klog_printf("debug_mem_read()"); |
579 | uspace_dst = IPC_GET_ARG2(call->data); |
||
580 | uspace_ptr = (void *)IPC_GET_ARG3(call->data); |
||
581 | size = IPC_GET_ARG4(call->data); |
||
582 | |||
583 | buffer = malloc(size, 0); // ??? |
||
584 | klog_printf("debug_mem_read: src=%u, size=%u", uspace_ptr, size); |
||
585 | |||
586 | /* NOTE: this is not strictly from a syscall... but that shouldn't |
||
587 | * be a problem */ |
||
588 | rc = copy_from_uspace(buffer, uspace_ptr, size); |
||
589 | if (rc) { |
||
590 | IPC_SET_RETVAL(call->data, rc); |
||
591 | return; |
||
592 | } |
||
593 | |||
594 | klog_printf("first word: %u", *((unative_t *)buffer)); |
||
595 | |||
596 | IPC_SET_RETVAL(call->data, 0); |
||
597 | /* Hack: ARG1=dest, ARG2=size as in IPC_M_DATA_READ so that |
||
598 | same code in process_answer() can be used |
||
599 | (no way to distinguish method in answer) */ |
||
600 | IPC_SET_ARG1(call->data, uspace_dst); |
||
601 | IPC_SET_ARG2(call->data, size); |
||
602 | call->buffer = buffer; |
||
603 | |||
604 | ipc_answer(&TASK->kernel_box, call); |
||
605 | } |
||
606 | |||
2818 | svoboda | 607 | static void udebug_receive_mem_write(call_t *call) |
608 | { |
||
609 | void *uspace_dst; |
||
610 | unsigned size; |
||
611 | void *buffer; |
||
612 | int rc; |
||
2827 | svoboda | 613 | udebug_task_state_t dts; |
2818 | svoboda | 614 | |
615 | klog_printf("udebug_receive_mem_write()"); |
||
2827 | svoboda | 616 | |
617 | /* Verify task state */ |
||
618 | spinlock_lock(&TASK->lock); |
||
619 | dts = TASK->dt_state; |
||
620 | spinlock_unlock(&TASK->lock); |
||
621 | |||
622 | if (dts != UDEBUG_TS_ACTIVE) { |
||
623 | IPC_SET_RETVAL(call->data, EBUSY); |
||
624 | ipc_answer(&TASK->kernel_box, call); |
||
625 | return; |
||
626 | } |
||
627 | |||
2818 | svoboda | 628 | uspace_dst = (void *)IPC_GET_ARG3(call->data); |
629 | size = IPC_GET_ARG4(call->data); |
||
630 | |||
631 | buffer = call->buffer; |
||
632 | klog_printf("dst=%u, size=%u", uspace_dst, size); |
||
633 | |||
634 | /* NOTE: this is not strictly from a syscall... but that shouldn't |
||
635 | * be a problem */ |
||
636 | rc = copy_to_uspace(uspace_dst, buffer, size); |
||
637 | if (rc) { |
||
638 | IPC_SET_RETVAL(call->data, rc); |
||
2827 | svoboda | 639 | ipc_answer(&TASK->kernel_box, call); |
2818 | svoboda | 640 | return; |
641 | } |
||
642 | |||
643 | IPC_SET_RETVAL(call->data, 0); |
||
644 | |||
645 | free(call->buffer); |
||
646 | call->buffer = NULL; |
||
647 | |||
648 | ipc_answer(&TASK->kernel_box, call); |
||
649 | } |
||
650 | |||
651 | |||
2815 | svoboda | 652 | /** |
653 | * Handle a debug call received on the kernel answerbox. |
||
654 | * |
||
655 | * This is called by the kbox servicing thread. |
||
656 | */ |
||
657 | void udebug_call_receive(call_t *call) |
||
658 | { |
||
659 | int debug_method; |
||
660 | |||
661 | debug_method = IPC_GET_ARG1(call->data); |
||
662 | |||
663 | switch (debug_method) { |
||
664 | case UDEBUG_M_MEM_READ: |
||
665 | udebug_receive_mem_read(call); |
||
666 | break; |
||
2818 | svoboda | 667 | case UDEBUG_M_MEM_WRITE: |
668 | udebug_receive_mem_write(call); |
||
669 | break; |
||
2815 | svoboda | 670 | } |
671 | } |
||
672 | |||
2813 | svoboda | 673 | /** @} |
674 | */ |