Subversion Repositories HelenOS

Rev

Rev 2817 | Rev 2819 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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