Rev 2819 | Rev 2824 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2819 | Rev 2823 | ||
---|---|---|---|
1 | /** @addtogroup generic |
1 | /** @addtogroup generic |
2 | * @{ |
2 | * @{ |
3 | */ |
3 | */ |
4 | 4 | ||
5 | /** |
5 | /** |
6 | * @file |
6 | * @file |
7 | * @brief Tdebug. |
7 | * @brief Tdebug. |
8 | */ |
8 | */ |
9 | 9 | ||
10 | #include <console/klog.h> |
10 | #include <console/klog.h> |
11 | #include <proc/task.h> |
11 | #include <proc/task.h> |
12 | #include <proc/thread.h> |
12 | #include <proc/thread.h> |
13 | #include <arch.h> |
13 | #include <arch.h> |
14 | #include <errno.h> |
14 | #include <errno.h> |
15 | #include <ipc/ipc.h> |
15 | #include <ipc/ipc.h> |
16 | #include <syscall/copy.h> |
16 | #include <syscall/copy.h> |
17 | #include <udebug/udebug.h> |
17 | #include <udebug/udebug.h> |
18 | #include <udebug/udebug_ipc.h> |
18 | #include <udebug/udebug_ipc.h> |
19 | 19 | ||
- | 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 | */ |
|
20 | static task_t *get_lock_callee_task(phone_t *phone) |
28 | static task_t *get_lock_callee_task(phone_t *phone) |
21 | { |
29 | { |
22 | answerbox_t *answerbox; |
30 | answerbox_t *box; |
23 | task_t *ta; |
31 | task_t *ta; |
- | 32 | task_id_t taskid; |
|
- | 33 | ipl_t ipl; |
|
24 | 34 | ||
- | 35 | ipl = interrupts_disable(); |
|
25 | // FIXME: locking!!! |
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 | } |
|
26 | 42 | ||
27 | answerbox = phone->callee; |
43 | box = phone->callee; |
- | 44 | ||
- | 45 | spinlock_lock(&box->lock); |
|
28 | ta = answerbox->task; |
46 | ta = box->task; |
- | 47 | taskid = ta->taskid; |
|
- | 48 | spinlock_unlock(&box->lock); |
|
- | 49 | spinlock_unlock(&phone->lock); |
|
- | 50 | ||
- | 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 | } |
|
29 | 60 | ||
30 | spinlock_lock(&ta->lock); |
61 | spinlock_lock(&ta->lock); |
- | 62 | spinlock_unlock(&tasks_lock); |
|
- | 63 | interrupts_restore(ipl); |
|
31 | 64 | ||
32 | return ta; |
65 | return ta; |
33 | } |
66 | } |
34 | 67 | ||
35 | static int udebug_rp_begin(call_t *call, phone_t *phone) |
68 | static int udebug_rp_begin(call_t *call, phone_t *phone) |
36 | { |
69 | { |
37 | task_t *ta; |
70 | task_t *ta; |
- | 71 | ipl_t ipl; |
|
38 | 72 | ||
39 | klog_printf("debug_begin()"); |
73 | klog_printf("debug_begin()"); |
40 | 74 | ||
- | 75 | ipl = interrupts_disable(); |
|
41 | ta = get_lock_callee_task(phone); |
76 | ta = get_lock_callee_task(phone); |
42 | klog_printf("debugging task %llu", ta->taskid); |
77 | klog_printf("debugging task %llu", ta->taskid); |
43 | 78 | ||
44 | if (ta->being_debugged != false) { |
79 | if (ta->being_debugged != false) { |
45 | spinlock_unlock(&ta->lock); |
80 | spinlock_unlock(&ta->lock); |
- | 81 | interrupts_restore(ipl); |
|
46 | klog_printf("debug_begin(): busy error"); |
82 | klog_printf("debug_begin(): busy error"); |
47 | return EBUSY; |
83 | return EBUSY; |
48 | } |
84 | } |
49 | 85 | ||
50 | ta->being_debugged = true; |
86 | ta->being_debugged = true; |
51 | ta->stop_request = true; |
87 | ta->stop_request = true; |
52 | ta->debug_begin_call = call; |
88 | ta->debug_begin_call = call; |
53 | 89 | ||
54 | if (ta->not_stoppable_count == 0) { |
90 | if (ta->not_stoppable_count == 0) { |
55 | ta->debug_begin_call = NULL; |
91 | ta->debug_begin_call = NULL; |
56 | ta->stop_request = false; |
92 | ta->stop_request = false; |
57 | spinlock_unlock(&ta->lock); |
93 | spinlock_unlock(&ta->lock); |
- | 94 | interrupts_restore(ipl); |
|
58 | klog_printf("debug_begin(): immediate backsend"); |
95 | klog_printf("debug_begin(): immediate backsend"); |
59 | return 1; /* actually we need backsend with 0 retval */ |
96 | return 1; /* actually we need backsend with 0 retval */ |
60 | } |
97 | } |
61 | 98 | ||
62 | spinlock_unlock(&ta->lock); |
99 | spinlock_unlock(&ta->lock); |
- | 100 | interrupts_restore(ipl); |
|
63 | 101 | ||
64 | klog_printf("debug_begin() done (wait for stoppability)"); |
102 | klog_printf("debug_begin() done (wait for stoppability)"); |
65 | return 0; |
103 | return 0; |
66 | } |
104 | } |
67 | 105 | ||
68 | static int udebug_rp_go(call_t *call, phone_t *phone) |
106 | static int udebug_rp_go(call_t *call, phone_t *phone) |
69 | { |
107 | { |
70 | thread_t *t; |
108 | thread_t *t; |
71 | task_t *ta; |
109 | task_t *ta; |
- | 110 | ipl_t ipl; |
|
72 | 111 | ||
73 | klog_printf("debug_go()"); |
112 | klog_printf("debug_go()"); |
74 | ta = get_lock_callee_task(phone); |
113 | ta = get_lock_callee_task(phone); |
75 | 114 | ||
76 | // FIXME: must save this in thread struct, not task struct!!! |
115 | // FIXME: must save this in thread struct, not task struct!!! |
77 | ta->debug_go_call = call; |
116 | ta->debug_go_call = call; |
- | 117 | spinlock_unlock(&ta->lock); |
|
- | 118 | ||
78 | t = (thread_t *) IPC_GET_ARG2(call->data); |
119 | t = (thread_t *) IPC_GET_ARG2(call->data); |
- | 120 | ||
- | 121 | ipl = interrupts_disable(); |
|
- | 122 | spinlock_lock(&threads_lock); |
|
79 | if (!thread_exists(t)) { |
123 | if (!thread_exists(t)) { |
80 | spinlock_unlock(&ta->lock); |
124 | spinlock_unlock(&threads_lock); |
- | 125 | interrupts_restore(ipl); |
|
81 | return ENOENT; |
126 | return ENOENT; |
82 | } |
127 | } |
83 | 128 | ||
84 | klog_printf("debug_go(): waitq_wakeup"); |
- | |
85 | waitq_wakeup(&t->go_wq, WAKEUP_FIRST); |
129 | waitq_wakeup(&t->go_wq, WAKEUP_FIRST); |
86 | - | ||
87 | spinlock_unlock(&ta->lock); |
130 | spinlock_unlock(&threads_lock); |
- | 131 | interrupts_restore(ipl); |
|
88 | 132 | ||
89 | return 0; /* no backsend */ |
133 | return 0; /* no backsend */ |
90 | } |
134 | } |
91 | 135 | ||
92 | static int udebug_rp_args_read(call_t *call, phone_t *phone) |
136 | static int udebug_rp_args_read(call_t *call, phone_t *phone) |
93 | { |
137 | { |
94 | thread_t *t; |
138 | thread_t *t; |
95 | task_t *ta; |
139 | task_t *ta; |
96 | void *uspace_buffer; |
140 | void *uspace_buffer; |
97 | unative_t to_copy; |
141 | unative_t to_copy; |
98 | int rc; |
142 | int rc; |
- | 143 | ipl_t ipl; |
|
99 | 144 | ||
100 | klog_printf("debug_args_read()"); |
145 | klog_printf("debug_args_read()"); |
101 | // FIXME: verify task/thread state |
146 | // FIXME: verify task/thread state |
102 | 147 | ||
103 | ta = get_lock_callee_task(phone); |
148 | ta = get_lock_callee_task(phone); |
104 | klog_printf("task %llu", ta->taskid); |
149 | klog_printf("task %llu", ta->taskid); |
- | 150 | spinlock_unlock(&ta->lock); |
|
- | 151 | ||
105 | t = (thread_t *) IPC_GET_ARG2(call->data); |
152 | t = (thread_t *) IPC_GET_ARG2(call->data); |
- | 153 | ||
- | 154 | ipl = interrupts_disable(); |
|
- | 155 | spinlock_lock(&threads_lock); |
|
- | 156 | ||
106 | if (!thread_exists(t)) { |
157 | if (!thread_exists(t)) { |
107 | spinlock_unlock(&ta->lock); |
158 | spinlock_unlock(&threads_lock); |
- | 159 | interrupts_restore(ipl); |
|
108 | return ENOENT; |
160 | return ENOENT; |
109 | } |
161 | } |
110 | 162 | ||
- | 163 | // FIXME: copy to a local buffer before releasing the lock |
|
- | 164 | spinlock_unlock(&threads_lock); |
|
- | 165 | interrupts_restore(ipl); |
|
- | 166 | ||
111 | uspace_buffer = (void *)IPC_GET_ARG3(call->data); |
167 | uspace_buffer = (void *)IPC_GET_ARG3(call->data); |
112 | to_copy = IPC_GET_ARG4(call->data); |
168 | to_copy = IPC_GET_ARG4(call->data); |
113 | if (to_copy > 6 * sizeof(unative_t)) to_copy = 6 * sizeof(unative_t); |
169 | if (to_copy > 6 * sizeof(unative_t)) to_copy = 6 * sizeof(unative_t); |
114 | 170 | ||
115 | rc = copy_to_uspace(uspace_buffer, t->syscall_args, to_copy); |
171 | rc = copy_to_uspace(uspace_buffer, t->syscall_args, to_copy); |
116 | if (rc != 0) { |
172 | if (rc != 0) { |
117 | spinlock_unlock(&ta->lock); |
173 | spinlock_unlock(&ta->lock); |
118 | klog_printf("debug_args_read() - copy failed"); |
174 | klog_printf("debug_args_read() - copy failed"); |
119 | return rc; |
175 | return rc; |
120 | } |
176 | } |
121 | 177 | ||
122 | spinlock_unlock(&ta->lock); |
- | |
123 | - | ||
124 | IPC_SET_ARG1(call->data, to_copy); |
178 | IPC_SET_ARG1(call->data, to_copy); |
125 | 179 | ||
126 | klog_printf("debug_args_read() done"); |
180 | klog_printf("debug_args_read() done"); |
127 | return 1; /* actually need becksend with retval 0 */ |
181 | return 1; /* actually need becksend with retval 0 */ |
128 | } |
182 | } |
129 | 183 | ||
130 | static int udebug_rp_regs_read(call_t *call, phone_t *phone) |
184 | static int udebug_rp_regs_read(call_t *call, phone_t *phone) |
131 | { |
185 | { |
132 | thread_t *t; |
186 | thread_t *t; |
133 | task_t *ta; |
187 | task_t *ta; |
134 | void *uspace_buffer; |
188 | void *uspace_buffer; |
135 | unative_t to_copy; |
189 | unative_t to_copy; |
136 | int rc; |
190 | int rc; |
137 | istate_t *state; |
191 | istate_t *state; |
138 | 192 | ||
139 | klog_printf("debug_regs_read()"); |
193 | klog_printf("debug_regs_read()"); |
140 | // FIXME: verify task/thread state |
194 | // FIXME: verify task/thread state |
141 | 195 | ||
142 | state = THREAD->uspace_state; |
196 | state = THREAD->uspace_state; |
143 | if (state == NULL) { |
197 | if (state == NULL) { |
144 | klog_printf("debug_regs_read() - istate not available"); |
198 | klog_printf("debug_regs_read() - istate not available"); |
145 | return EBUSY; |
199 | return EBUSY; |
146 | } |
200 | } |
147 | 201 | ||
148 | ta = get_lock_callee_task(phone); |
202 | ta = get_lock_callee_task(phone); |
149 | t = (thread_t *) IPC_GET_ARG2(call->data); |
203 | t = (thread_t *) IPC_GET_ARG2(call->data); |
150 | if (!thread_exists(t)) { |
204 | if (!thread_exists(t)) { |
151 | spinlock_unlock(&ta->lock); |
205 | spinlock_unlock(&ta->lock); |
152 | return ENOENT; |
206 | return ENOENT; |
153 | } |
207 | } |
154 | 208 | ||
155 | uspace_buffer = (void *)IPC_GET_ARG3(call->data); |
209 | uspace_buffer = (void *)IPC_GET_ARG3(call->data); |
156 | to_copy = IPC_GET_ARG4(call->data); |
210 | to_copy = IPC_GET_ARG4(call->data); |
157 | if (to_copy > sizeof(istate_t)) to_copy = sizeof(istate_t); |
211 | if (to_copy > sizeof(istate_t)) to_copy = sizeof(istate_t); |
158 | 212 | ||
159 | rc = copy_to_uspace(uspace_buffer, t->uspace_state, to_copy); |
213 | rc = copy_to_uspace(uspace_buffer, t->uspace_state, to_copy); |
160 | if (rc != 0) { |
214 | if (rc != 0) { |
161 | spinlock_unlock(&ta->lock); |
215 | spinlock_unlock(&ta->lock); |
162 | klog_printf("debug_regs_read() - copy failed"); |
216 | klog_printf("debug_regs_read() - copy failed"); |
163 | return rc; |
217 | return rc; |
164 | } |
218 | } |
165 | 219 | ||
166 | spinlock_unlock(&ta->lock); |
220 | spinlock_unlock(&ta->lock); |
167 | 221 | ||
168 | IPC_SET_ARG1(call->data, to_copy); |
222 | IPC_SET_ARG1(call->data, to_copy); |
169 | IPC_SET_ARG2(call->data, sizeof(istate_t)); |
223 | IPC_SET_ARG2(call->data, sizeof(istate_t)); |
170 | 224 | ||
171 | klog_printf("debug_regs_read() done"); |
225 | klog_printf("debug_regs_read() done"); |
172 | return 1; /* actually need becksend with retval 0 */ |
226 | return 1; /* actually need becksend with retval 0 */ |
173 | } |
227 | } |
174 | 228 | ||
175 | static int udebug_rp_regs_write(call_t *call, phone_t *phone) |
229 | static int udebug_rp_regs_write(call_t *call, phone_t *phone) |
176 | { |
230 | { |
177 | thread_t *t; |
231 | thread_t *t; |
178 | task_t *ta; |
232 | task_t *ta; |
179 | void *uspace_data; |
233 | void *uspace_data; |
180 | unative_t to_copy; |
234 | unative_t to_copy; |
181 | int rc; |
235 | int rc; |
182 | istate_t *state; |
236 | istate_t *state; |
183 | 237 | ||
184 | klog_printf("debug_regs_write()"); |
238 | klog_printf("debug_regs_write()"); |
185 | // FIXME: verify task/thread state |
239 | // FIXME: verify task/thread state |
186 | 240 | ||
187 | state = THREAD->uspace_state; |
241 | state = THREAD->uspace_state; |
188 | if (state == NULL) { |
242 | if (state == NULL) { |
189 | klog_printf("debug_regs_write() - istate not available"); |
243 | klog_printf("debug_regs_write() - istate not available"); |
190 | return EBUSY; |
244 | return EBUSY; |
191 | } |
245 | } |
192 | 246 | ||
193 | ta = get_lock_callee_task(phone); |
247 | ta = get_lock_callee_task(phone); |
194 | t = (thread_t *) IPC_GET_ARG2(call->data); |
248 | t = (thread_t *) IPC_GET_ARG2(call->data); |
195 | if (!thread_exists(t)) { |
249 | if (!thread_exists(t)) { |
196 | spinlock_unlock(&ta->lock); |
250 | spinlock_unlock(&ta->lock); |
197 | return ENOENT; |
251 | return ENOENT; |
198 | } |
252 | } |
199 | 253 | ||
200 | uspace_data = (void *)IPC_GET_ARG3(call->data); |
254 | uspace_data = (void *)IPC_GET_ARG3(call->data); |
201 | to_copy = IPC_GET_ARG4(call->data); |
255 | to_copy = IPC_GET_ARG4(call->data); |
202 | if (to_copy > sizeof(istate_t)) to_copy = sizeof(istate_t); |
256 | if (to_copy > sizeof(istate_t)) to_copy = sizeof(istate_t); |
203 | 257 | ||
204 | rc = copy_from_uspace(t->uspace_state, uspace_data, to_copy); |
258 | rc = copy_from_uspace(t->uspace_state, uspace_data, to_copy); |
205 | if (rc != 0) { |
259 | if (rc != 0) { |
206 | spinlock_unlock(&ta->lock); |
260 | spinlock_unlock(&ta->lock); |
207 | klog_printf("debug_regs_write() - copy failed"); |
261 | klog_printf("debug_regs_write() - copy failed"); |
208 | return rc; |
262 | return rc; |
209 | } |
263 | } |
210 | 264 | ||
211 | spinlock_unlock(&ta->lock); |
265 | spinlock_unlock(&ta->lock); |
212 | 266 | ||
213 | IPC_SET_ARG1(call->data, to_copy); |
267 | IPC_SET_ARG1(call->data, to_copy); |
214 | IPC_SET_ARG2(call->data, sizeof(istate_t)); |
268 | IPC_SET_ARG2(call->data, sizeof(istate_t)); |
215 | 269 | ||
216 | klog_printf("debug_regs_write() done"); |
270 | klog_printf("debug_regs_write() done"); |
217 | return 1; /* actually need becksend with retval 0 */ |
271 | return 1; /* actually need becksend with retval 0 */ |
218 | } |
272 | } |
219 | 273 | ||
220 | static int udebug_rp_thread_read(call_t *call, phone_t *phone) |
274 | static int udebug_rp_thread_read(call_t *call, phone_t *phone) |
221 | { |
275 | { |
222 | thread_t *t; |
276 | thread_t *t; |
223 | link_t *cur; |
277 | link_t *cur; |
224 | task_t *ta; |
278 | task_t *ta; |
225 | unative_t *uspace_buffer; |
279 | unative_t *uspace_buffer; |
226 | unative_t to_copy; |
280 | unative_t to_copy; |
227 | int rc; |
281 | int rc; |
228 | unsigned copied, total; |
282 | unsigned copied, total; |
229 | unsigned buf_size; |
283 | unsigned buf_size; |
230 | unative_t tid; |
284 | unative_t tid; |
231 | 285 | ||
232 | klog_printf("debug_thread_read()"); |
286 | klog_printf("debug_thread_read()"); |
233 | // FIXME: verify task/thread state |
287 | // FIXME: verify task/thread state |
234 | 288 | ||
235 | ta = get_lock_callee_task(phone); |
289 | ta = get_lock_callee_task(phone); |
236 | klog_printf("task %llu", ta->taskid); |
290 | klog_printf("task %llu", ta->taskid); |
237 | 291 | ||
238 | uspace_buffer = (void *)IPC_GET_ARG2(call->data); |
292 | uspace_buffer = (void *)IPC_GET_ARG2(call->data); |
239 | buf_size = IPC_GET_ARG3(call->data); |
293 | buf_size = IPC_GET_ARG3(call->data); |
240 | 294 | ||
241 | copied = total = 0; |
295 | copied = total = 0; |
242 | for (cur = ta->th_head.next; cur != &ta->th_head; cur = cur->next) { |
296 | for (cur = ta->th_head.next; cur != &ta->th_head; cur = cur->next) { |
243 | t = list_get_instance(cur, thread_t, th_link); |
297 | t = list_get_instance(cur, thread_t, th_link); |
244 | 298 | ||
245 | /* Not interested in kernel threads */ |
299 | /* Not interested in kernel threads */ |
246 | if ((t->flags & THREAD_FLAG_USPACE) == 0) |
300 | if ((t->flags & THREAD_FLAG_USPACE) == 0) |
247 | continue; |
301 | continue; |
248 | 302 | ||
249 | /* Using thread struct pointer for identification */ |
303 | /* Using thread struct pointer for identification */ |
250 | tid = (unative_t) t; |
304 | tid = (unative_t) t; |
251 | 305 | ||
252 | to_copy = sizeof(unative_t); |
306 | to_copy = sizeof(unative_t); |
253 | if (copied + to_copy >= buf_size) |
307 | if (copied + to_copy >= buf_size) |
254 | to_copy = buf_size - copied; |
308 | to_copy = buf_size - copied; |
255 | 309 | ||
256 | if (to_copy > 0) { |
310 | if (to_copy > 0) { |
257 | rc = copy_to_uspace(uspace_buffer, &tid, to_copy); |
311 | rc = copy_to_uspace(uspace_buffer, &tid, to_copy); |
258 | if (rc != 0) { |
312 | if (rc != 0) { |
259 | spinlock_unlock(&ta->lock); |
313 | spinlock_unlock(&ta->lock); |
260 | klog_printf("debug_thread_read() - copy failed"); |
314 | klog_printf("debug_thread_read() - copy failed"); |
261 | return rc; |
315 | return rc; |
262 | } |
316 | } |
263 | } |
317 | } |
264 | 318 | ||
265 | ++uspace_buffer; |
319 | ++uspace_buffer; |
266 | total += sizeof(unative_t); |
320 | total += sizeof(unative_t); |
267 | copied += to_copy; |
321 | copied += to_copy; |
268 | } |
322 | } |
269 | 323 | ||
270 | spinlock_unlock(&ta->lock); |
324 | spinlock_unlock(&ta->lock); |
271 | 325 | ||
272 | IPC_SET_ARG1(call->data, copied); |
326 | IPC_SET_ARG1(call->data, copied); |
273 | IPC_SET_ARG2(call->data, total); |
327 | IPC_SET_ARG2(call->data, total); |
274 | 328 | ||
275 | klog_printf("debug_thread_read() done"); |
329 | klog_printf("debug_thread_read() done"); |
276 | return 1; /* actually need becksend with retval 0 */ |
330 | return 1; /* actually need becksend with retval 0 */ |
277 | } |
331 | } |
278 | 332 | ||
279 | static int udebug_rp_mem_write(call_t *call, phone_t *phone) |
333 | static int udebug_rp_mem_write(call_t *call, phone_t *phone) |
280 | { |
334 | { |
281 | void *uspace_data; |
335 | void *uspace_data; |
282 | unative_t to_copy; |
336 | unative_t to_copy; |
283 | int rc; |
337 | int rc; |
284 | void *buffer; |
338 | void *buffer; |
285 | 339 | ||
286 | klog_printf("udebug_rp_mem_write()"); |
340 | klog_printf("udebug_rp_mem_write()"); |
287 | // FIXME: verify task/thread state |
341 | // FIXME: verify task/thread state |
288 | 342 | ||
289 | uspace_data = (void *)IPC_GET_ARG2(call->data); |
343 | uspace_data = (void *)IPC_GET_ARG2(call->data); |
290 | to_copy = IPC_GET_ARG4(call->data); |
344 | to_copy = IPC_GET_ARG4(call->data); |
291 | 345 | ||
292 | buffer = malloc(to_copy, 0); // ??? |
346 | buffer = malloc(to_copy, 0); // ??? |
293 | 347 | ||
294 | rc = copy_from_uspace(buffer, uspace_data, to_copy); |
348 | rc = copy_from_uspace(buffer, uspace_data, to_copy); |
295 | if (rc != 0) { |
349 | if (rc != 0) { |
296 | klog_printf(" - copy failed"); |
350 | klog_printf(" - copy failed"); |
297 | return rc; |
351 | return rc; |
298 | } |
352 | } |
299 | 353 | ||
300 | call->buffer = buffer; |
354 | call->buffer = buffer; |
301 | 355 | ||
302 | klog_printf(" - done"); |
356 | klog_printf(" - done"); |
303 | return 1; /* actually need becksend with retval 0 */ |
357 | return 1; /* actually need becksend with retval 0 */ |
304 | } |
358 | } |
305 | 359 | ||
306 | 360 | ||
307 | int udebug_request_preprocess(call_t *call, phone_t *phone) |
361 | int udebug_request_preprocess(call_t *call, phone_t *phone) |
308 | { |
362 | { |
309 | int rc; |
363 | int rc; |
310 | 364 | ||
311 | switch (IPC_GET_ARG1(call->data)) { |
365 | switch (IPC_GET_ARG1(call->data)) { |
312 | case UDEBUG_M_BEGIN: |
366 | case UDEBUG_M_BEGIN: |
313 | rc = udebug_rp_begin(call, phone); |
367 | rc = udebug_rp_begin(call, phone); |
314 | return rc; |
368 | return rc; |
315 | case UDEBUG_M_GO: |
369 | case UDEBUG_M_GO: |
316 | rc = udebug_rp_go(call, phone); |
370 | rc = udebug_rp_go(call, phone); |
317 | return rc; |
371 | return rc; |
318 | case UDEBUG_M_ARGS_READ: |
372 | case UDEBUG_M_ARGS_READ: |
319 | rc = udebug_rp_args_read(call, phone); |
373 | rc = udebug_rp_args_read(call, phone); |
320 | return rc; |
374 | return rc; |
321 | case UDEBUG_M_REGS_READ: |
375 | case UDEBUG_M_REGS_READ: |
322 | rc = udebug_rp_regs_read(call, phone); |
376 | rc = udebug_rp_regs_read(call, phone); |
323 | return rc; |
377 | return rc; |
324 | case UDEBUG_M_REGS_WRITE: |
378 | case UDEBUG_M_REGS_WRITE: |
325 | rc = udebug_rp_regs_write(call, phone); |
379 | rc = udebug_rp_regs_write(call, phone); |
326 | return rc; |
380 | return rc; |
327 | case UDEBUG_M_THREAD_READ: |
381 | case UDEBUG_M_THREAD_READ: |
328 | rc = udebug_rp_thread_read(call, phone); |
382 | rc = udebug_rp_thread_read(call, phone); |
329 | return rc; |
383 | return rc; |
330 | case UDEBUG_M_MEM_WRITE: |
384 | case UDEBUG_M_MEM_WRITE: |
331 | rc = udebug_rp_mem_write(call, phone); |
385 | rc = udebug_rp_mem_write(call, phone); |
332 | return rc; |
386 | return rc; |
333 | default: |
387 | default: |
334 | break; |
388 | break; |
335 | } |
389 | } |
336 | 390 | ||
337 | return 0; |
391 | return 0; |
338 | } |
392 | } |
339 | 393 | ||
340 | static void udebug_receive_mem_read(call_t *call) |
394 | static void udebug_receive_mem_read(call_t *call) |
341 | { |
395 | { |
342 | unative_t uspace_dst; |
396 | unative_t uspace_dst; |
343 | void *uspace_ptr; |
397 | void *uspace_ptr; |
344 | unsigned size; |
398 | unsigned size; |
345 | void *buffer; |
399 | void *buffer; |
346 | int rc; |
400 | int rc; |
347 | 401 | ||
348 | klog_printf("debug_mem_read()"); |
402 | klog_printf("debug_mem_read()"); |
349 | uspace_dst = IPC_GET_ARG2(call->data); |
403 | uspace_dst = IPC_GET_ARG2(call->data); |
350 | uspace_ptr = (void *)IPC_GET_ARG3(call->data); |
404 | uspace_ptr = (void *)IPC_GET_ARG3(call->data); |
351 | size = IPC_GET_ARG4(call->data); |
405 | size = IPC_GET_ARG4(call->data); |
352 | 406 | ||
353 | buffer = malloc(size, 0); // ??? |
407 | buffer = malloc(size, 0); // ??? |
354 | klog_printf("debug_mem_read: src=%u, size=%u", uspace_ptr, size); |
408 | klog_printf("debug_mem_read: src=%u, size=%u", uspace_ptr, size); |
355 | 409 | ||
356 | /* NOTE: this is not strictly from a syscall... but that shouldn't |
410 | /* NOTE: this is not strictly from a syscall... but that shouldn't |
357 | * be a problem */ |
411 | * be a problem */ |
358 | rc = copy_from_uspace(buffer, uspace_ptr, size); |
412 | rc = copy_from_uspace(buffer, uspace_ptr, size); |
359 | if (rc) { |
413 | if (rc) { |
360 | IPC_SET_RETVAL(call->data, rc); |
414 | IPC_SET_RETVAL(call->data, rc); |
361 | return; |
415 | return; |
362 | } |
416 | } |
363 | 417 | ||
364 | klog_printf("first word: %u", *((unative_t *)buffer)); |
418 | klog_printf("first word: %u", *((unative_t *)buffer)); |
365 | 419 | ||
366 | IPC_SET_RETVAL(call->data, 0); |
420 | IPC_SET_RETVAL(call->data, 0); |
367 | /* Hack: ARG1=dest, ARG2=size as in IPC_M_DATA_READ so that |
421 | /* Hack: ARG1=dest, ARG2=size as in IPC_M_DATA_READ so that |
368 | same code in process_answer() can be used |
422 | same code in process_answer() can be used |
369 | (no way to distinguish method in answer) */ |
423 | (no way to distinguish method in answer) */ |
370 | IPC_SET_ARG1(call->data, uspace_dst); |
424 | IPC_SET_ARG1(call->data, uspace_dst); |
371 | IPC_SET_ARG2(call->data, size); |
425 | IPC_SET_ARG2(call->data, size); |
372 | call->buffer = buffer; |
426 | call->buffer = buffer; |
373 | 427 | ||
374 | ipc_answer(&TASK->kernel_box, call); |
428 | ipc_answer(&TASK->kernel_box, call); |
375 | } |
429 | } |
376 | 430 | ||
377 | static void udebug_receive_mem_write(call_t *call) |
431 | static void udebug_receive_mem_write(call_t *call) |
378 | { |
432 | { |
379 | void *uspace_dst; |
433 | void *uspace_dst; |
380 | unsigned size; |
434 | unsigned size; |
381 | void *buffer; |
435 | void *buffer; |
382 | int rc; |
436 | int rc; |
383 | 437 | ||
384 | klog_printf("udebug_receive_mem_write()"); |
438 | klog_printf("udebug_receive_mem_write()"); |
385 | uspace_dst = (void *)IPC_GET_ARG3(call->data); |
439 | uspace_dst = (void *)IPC_GET_ARG3(call->data); |
386 | size = IPC_GET_ARG4(call->data); |
440 | size = IPC_GET_ARG4(call->data); |
387 | 441 | ||
388 | buffer = call->buffer; |
442 | buffer = call->buffer; |
389 | klog_printf("dst=%u, size=%u", uspace_dst, size); |
443 | klog_printf("dst=%u, size=%u", uspace_dst, size); |
390 | 444 | ||
391 | /* NOTE: this is not strictly from a syscall... but that shouldn't |
445 | /* NOTE: this is not strictly from a syscall... but that shouldn't |
392 | * be a problem */ |
446 | * be a problem */ |
393 | rc = copy_to_uspace(uspace_dst, buffer, size); |
447 | rc = copy_to_uspace(uspace_dst, buffer, size); |
394 | if (rc) { |
448 | if (rc) { |
395 | IPC_SET_RETVAL(call->data, rc); |
449 | IPC_SET_RETVAL(call->data, rc); |
396 | return; |
450 | return; |
397 | } |
451 | } |
398 | 452 | ||
399 | IPC_SET_RETVAL(call->data, 0); |
453 | IPC_SET_RETVAL(call->data, 0); |
400 | 454 | ||
401 | free(call->buffer); |
455 | free(call->buffer); |
402 | call->buffer = NULL; |
456 | call->buffer = NULL; |
403 | 457 | ||
404 | ipc_answer(&TASK->kernel_box, call); |
458 | ipc_answer(&TASK->kernel_box, call); |
405 | } |
459 | } |
406 | 460 | ||
407 | 461 | ||
408 | /** |
462 | /** |
409 | * Handle a debug call received on the kernel answerbox. |
463 | * Handle a debug call received on the kernel answerbox. |
410 | * |
464 | * |
411 | * This is called by the kbox servicing thread. |
465 | * This is called by the kbox servicing thread. |
412 | */ |
466 | */ |
413 | void udebug_call_receive(call_t *call) |
467 | void udebug_call_receive(call_t *call) |
414 | { |
468 | { |
415 | int debug_method; |
469 | int debug_method; |
416 | 470 | ||
417 | debug_method = IPC_GET_ARG1(call->data); |
471 | debug_method = IPC_GET_ARG1(call->data); |
418 | 472 | ||
419 | switch (debug_method) { |
473 | switch (debug_method) { |
420 | case UDEBUG_M_MEM_READ: |
474 | case UDEBUG_M_MEM_READ: |
421 | udebug_receive_mem_read(call); |
475 | udebug_receive_mem_read(call); |
422 | break; |
476 | break; |
423 | case UDEBUG_M_MEM_WRITE: |
477 | case UDEBUG_M_MEM_WRITE: |
424 | udebug_receive_mem_write(call); |
478 | udebug_receive_mem_write(call); |
425 | break; |
479 | break; |
426 | } |
480 | } |
427 | } |
481 | } |
428 | 482 | ||
429 | /** @} |
483 | /** @} |
430 | */ |
484 | */ |
431 | 485 |