Subversion Repositories HelenOS

Rev

Rev 2823 | Rev 2826 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2801 svoboda 1
/** @addtogroup generic
2
 * @{
3
 */
4
 
5
/**
6
 * @file
7
 * @brief   Tdebug.
8
 */
9
 
10
#include <synch/waitq.h>
11
#include <console/klog.h>
2813 svoboda 12
#include <udebug/udebug.h>
2801 svoboda 13
#include <arch.h>
14
 
2804 svoboda 15
void udebug_stoppable_begin(void)
2801 svoboda 16
{
2804 svoboda 17
    int nsc;
18
    call_t *db_call;
2823 svoboda 19
    ipl_t ipl;
2804 svoboda 20
 
2823 svoboda 21
    ipl = interrupts_disable();
2804 svoboda 22
    spinlock_lock(&TASK->lock);
23
 
24
    nsc = --TASK->not_stoppable_count;
25
    db_call = TASK->debug_begin_call;
26
 
2825 svoboda 27
    if (TASK->dt_state == UDEBUG_TS_BEGINNING) {
2804 svoboda 28
        klog_printf("udebug_stoppable_begin");
29
        klog_printf(" - nsc := %d", nsc);
30
    }
31
 
2825 svoboda 32
    if (TASK->dt_state == UDEBUG_TS_BEGINNING && nsc == 0) {
33
        TASK->dt_state = UDEBUG_TS_ACTIVE;
2801 svoboda 34
        TASK->debug_begin_call = NULL;
2804 svoboda 35
        spinlock_unlock(&TASK->lock);
2823 svoboda 36
        interrupts_restore(ipl);
2804 svoboda 37
 
38
        IPC_SET_RETVAL(db_call->data, 0);
39
        klog_printf("udebug_stoppable_begin/ipc_answer");
40
        ipc_answer(&TASK->answerbox, db_call);     
41
    } else {
42
            spinlock_unlock(&TASK->lock);
2823 svoboda 43
        interrupts_restore(ipl);
2804 svoboda 44
    }
45
}
46
 
47
void udebug_stoppable_end(void)
48
{
2823 svoboda 49
    ipl_t ipl;
50
 
2804 svoboda 51
restart:
2823 svoboda 52
    ipl = interrupts_disable();
2804 svoboda 53
    spinlock_lock(&TASK->lock);
54
 
2825 svoboda 55
    if ((TASK->dt_state == UDEBUG_TS_BEGINNING ||
56
        TASK->dt_state == UDEBUG_TS_ACTIVE) &&
57
        THREAD->debug_stop == true) {
2804 svoboda 58
        TASK->debug_begin_call = NULL;
59
        spinlock_unlock(&TASK->lock);
2823 svoboda 60
        interrupts_restore(ipl);
61
 
2804 svoboda 62
        klog_printf("udebug_stoppable_end: waitq_sleep");
2801 svoboda 63
        waitq_sleep(&THREAD->go_wq);
2804 svoboda 64
        goto restart;
65
        /* must try again - have to lose stoppability atomically */
66
    } else {
67
        ++TASK->not_stoppable_count;
68
        spinlock_unlock(&TASK->lock);
2823 svoboda 69
        interrupts_restore(ipl);
2801 svoboda 70
    }
71
}
72
 
2805 svoboda 73
void udebug_syscall_event(unative_t a1, unative_t a2, unative_t a3,
74
    unative_t a4, unative_t a5, unative_t a6, unative_t id, unative_t rc)
2801 svoboda 75
{
2805 svoboda 76
    call_t *call;
2823 svoboda 77
    ipl_t ipl;
2805 svoboda 78
 
2823 svoboda 79
    ipl = interrupts_disable();
2804 svoboda 80
    spinlock_lock(&TASK->lock);
2823 svoboda 81
 
2825 svoboda 82
    if (TASK->dt_state == UDEBUG_TS_ACTIVE) {
2801 svoboda 83
        klog_printf("udebug_syscall_event");
2805 svoboda 84
        call = TASK->debug_go_call;
85
        IPC_SET_RETVAL(call->data, 0);
86
        IPC_SET_ARG1(call->data, UDEBUG_EVENT_SYSCALL);
87
        IPC_SET_ARG2(call->data, id);
88
        IPC_SET_ARG3(call->data, rc);
2804 svoboda 89
        klog_printf("udebug_syscall_event/ipc_answer");
90
 
2805 svoboda 91
        THREAD->syscall_args[0] = a1;
92
        THREAD->syscall_args[1] = a2;
93
        THREAD->syscall_args[2] = a3;
94
        THREAD->syscall_args[3] = a4;
95
        THREAD->syscall_args[4] = a5;
96
        THREAD->syscall_args[5] = a6;
97
 
2825 svoboda 98
        /*
99
         * Make sure debug_stop is true when going to sleep
100
         * in case we get woken up by DEBUG_END. (At which
101
         * point it must be back to the initial true value).
102
         */
103
        THREAD->debug_stop = true;
104
 
2801 svoboda 105
        ipc_answer(&TASK->answerbox, TASK->debug_go_call);
2804 svoboda 106
        spinlock_unlock(&TASK->lock);
2823 svoboda 107
        interrupts_restore(ipl);
108
 
2801 svoboda 109
        waitq_sleep(&THREAD->go_wq);
2804 svoboda 110
    } else {
111
        spinlock_unlock(&TASK->lock);
2823 svoboda 112
        interrupts_restore(ipl);
2801 svoboda 113
    }
114
}
115
 
116
/** @}
117
 */