Subversion Repositories HelenOS-historic

Rev

Rev 1705 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1705 Rev 1780
Line 89... Line 89...
89
    .argc = 2,
89
    .argc = 2,
90
    .argv = adde_argv
90
    .argv = adde_argv
91
};
91
};
92
 
92
 
93
static struct {
93
static struct {
94
    __u32 andmask;
94
    uint32_t andmask;
95
    __u32 value;
95
    uint32_t value;
96
}jmpinstr[] = {
96
}jmpinstr[] = {
97
    {0xf3ff0000, 0x41000000}, /* BCzF */
97
    {0xf3ff0000, 0x41000000}, /* BCzF */
98
    {0xf3ff0000, 0x41020000}, /* BCzFL */
98
    {0xf3ff0000, 0x41020000}, /* BCzFL */
99
    {0xf3ff0000, 0x41010000}, /* BCzT */
99
    {0xf3ff0000, 0x41010000}, /* BCzT */
100
    {0xf3ff0000, 0x41030000}, /* BCzTL */
100
    {0xf3ff0000, 0x41030000}, /* BCzTL */
Line 123... Line 123...
123
/** Test, if the given instruction is a jump or branch instruction
123
/** Test, if the given instruction is a jump or branch instruction
124
 *
124
 *
125
 * @param instr Instruction code
125
 * @param instr Instruction code
126
 * @return true - it is jump instruction, false otherwise
126
 * @return true - it is jump instruction, false otherwise
127
 */
127
 */
128
static bool is_jump(__native instr)
128
static bool is_jump(unative_t instr)
129
{
129
{
130
    int i;
130
    int i;
131
 
131
 
132
    for (i=0;jmpinstr[i].andmask;i++) {
132
    for (i=0;jmpinstr[i].andmask;i++) {
133
        if ((instr & jmpinstr[i].andmask) == jmpinstr[i].value)
133
        if ((instr & jmpinstr[i].andmask) == jmpinstr[i].value)
Line 151... Line 151...
151
    ipl = interrupts_disable();
151
    ipl = interrupts_disable();
152
    spinlock_lock(&bkpoint_lock);
152
    spinlock_lock(&bkpoint_lock);
153
 
153
 
154
    /* Check, that the breakpoints do not conflict */
154
    /* Check, that the breakpoints do not conflict */
155
    for (i=0; i<BKPOINTS_MAX; i++) {
155
    for (i=0; i<BKPOINTS_MAX; i++) {
156
        if (breakpoints[i].address == (__address)argv->intval) {
156
        if (breakpoints[i].address == (uintptr_t)argv->intval) {
157
            printf("Duplicate breakpoint %d.\n", i);
157
            printf("Duplicate breakpoint %d.\n", i);
158
            spinlock_unlock(&bkpoints_lock);
158
            spinlock_unlock(&bkpoints_lock);
159
            return 0;
159
            return 0;
160
        } else if (breakpoints[i].address == (__address)argv->intval + sizeof(__native) || \
160
        } else if (breakpoints[i].address == (uintptr_t)argv->intval + sizeof(unative_t) || \
161
               breakpoints[i].address == (__address)argv->intval - sizeof(__native)) {
161
               breakpoints[i].address == (uintptr_t)argv->intval - sizeof(unative_t)) {
162
            printf("Adjacent breakpoints not supported, conflict with %d.\n", i);
162
            printf("Adjacent breakpoints not supported, conflict with %d.\n", i);
163
            spinlock_unlock(&bkpoints_lock);
163
            spinlock_unlock(&bkpoints_lock);
164
            return 0;
164
            return 0;
165
        }
165
        }
166
           
166
           
Line 175... Line 175...
175
        printf("Too many breakpoints.\n");
175
        printf("Too many breakpoints.\n");
176
        spinlock_unlock(&bkpoint_lock);
176
        spinlock_unlock(&bkpoint_lock);
177
        interrupts_restore(ipl);
177
        interrupts_restore(ipl);
178
        return 0;
178
        return 0;
179
    }
179
    }
180
    cur->address = (__address) argv->intval;
180
    cur->address = (uintptr_t) argv->intval;
181
    printf("Adding breakpoint on address: %p\n", argv->intval);
181
    printf("Adding breakpoint on address: %p\n", argv->intval);
182
    cur->instruction = ((__native *)cur->address)[0];
182
    cur->instruction = ((unative_t *)cur->address)[0];
183
    cur->nextinstruction = ((__native *)cur->address)[1];
183
    cur->nextinstruction = ((unative_t *)cur->address)[1];
184
    if (argv == &add_argv) {
184
    if (argv == &add_argv) {
185
        cur->flags = 0;
185
        cur->flags = 0;
186
    } else { /* We are add extended */
186
    } else { /* We are add extended */
187
        cur->flags = BKPOINT_FUNCCALL;
187
        cur->flags = BKPOINT_FUNCCALL;
188
        cur->bkfunc =   (void (*)(void *, istate_t *)) argv[1].intval;
188
        cur->bkfunc =   (void (*)(void *, istate_t *)) argv[1].intval;
Line 190... Line 190...
190
    if (is_jump(cur->instruction))
190
    if (is_jump(cur->instruction))
191
        cur->flags |= BKPOINT_ONESHOT;
191
        cur->flags |= BKPOINT_ONESHOT;
192
    cur->counter = 0;
192
    cur->counter = 0;
193
 
193
 
194
    /* Set breakpoint */
194
    /* Set breakpoint */
195
    *((__native *)cur->address) = 0x0d;
195
    *((unative_t *)cur->address) = 0x0d;
196
 
196
 
197
    spinlock_unlock(&bkpoint_lock);
197
    spinlock_unlock(&bkpoint_lock);
198
    interrupts_restore(ipl);
198
    interrupts_restore(ipl);
199
 
199
 
200
    return 1;
200
    return 1;
Line 226... Line 226...
226
        printf("Cannot remove one-shot breakpoint in-progress\n");
226
        printf("Cannot remove one-shot breakpoint in-progress\n");
227
        spinlock_unlock(&bkpoint_lock);
227
        spinlock_unlock(&bkpoint_lock);
228
        interrupts_restore(ipl);
228
        interrupts_restore(ipl);
229
        return 0;
229
        return 0;
230
    }
230
    }
231
    ((__u32 *)cur->address)[0] = cur->instruction;
231
    ((uint32_t *)cur->address)[0] = cur->instruction;
232
    ((__u32 *)cur->address)[1] = cur->nextinstruction;
232
    ((uint32_t *)cur->address)[1] = cur->nextinstruction;
233
 
233
 
234
    cur->address = NULL;
234
    cur->address = NULL;
235
 
235
 
236
    spinlock_unlock(&bkpoint_lock);
236
    spinlock_unlock(&bkpoint_lock);
237
    interrupts_restore(ipl);
237
    interrupts_restore(ipl);
Line 296... Line 296...
296
 * next instruction.
296
 * next instruction.
297
 */
297
 */
298
void debugger_bpoint(istate_t *istate)
298
void debugger_bpoint(istate_t *istate)
299
{
299
{
300
    bpinfo_t *cur = NULL;
300
    bpinfo_t *cur = NULL;
301
    __address fireaddr = istate->epc;
301
    uintptr_t fireaddr = istate->epc;
302
    int i;
302
    int i;
303
 
303
 
304
    /* test branch delay slot */
304
    /* test branch delay slot */
305
    if (cp0_cause_read() & 0x80000000)
305
    if (cp0_cause_read() & 0x80000000)
306
        panic("Breakpoint in branch delay slot not supported.\n");
306
        panic("Breakpoint in branch delay slot not supported.\n");
Line 313... Line 313...
313
            cur = &breakpoints[i];
313
            cur = &breakpoints[i];
314
            break;
314
            break;
315
        }
315
        }
316
        /* Reinst only breakpoint */
316
        /* Reinst only breakpoint */
317
        if ((breakpoints[i].flags & BKPOINT_REINST) \
317
        if ((breakpoints[i].flags & BKPOINT_REINST) \
318
            && (fireaddr ==breakpoints[i].address+sizeof(__native))) {
318
            && (fireaddr ==breakpoints[i].address+sizeof(unative_t))) {
319
            cur = &breakpoints[i];
319
            cur = &breakpoints[i];
320
            break;
320
            break;
321
        }
321
        }
322
    }
322
    }
323
    if (cur) {
323
    if (cur) {
324
        if (cur->flags & BKPOINT_REINST) {
324
        if (cur->flags & BKPOINT_REINST) {
325
            /* Set breakpoint on first instruction */
325
            /* Set breakpoint on first instruction */
326
            ((__u32 *)cur->address)[0] = 0x0d;
326
            ((uint32_t *)cur->address)[0] = 0x0d;
327
            /* Return back the second */
327
            /* Return back the second */
328
            ((__u32 *)cur->address)[1] = cur->nextinstruction;
328
            ((uint32_t *)cur->address)[1] = cur->nextinstruction;
329
            cur->flags &= ~BKPOINT_REINST;
329
            cur->flags &= ~BKPOINT_REINST;
330
            spinlock_unlock(&bkpoint_lock);
330
            spinlock_unlock(&bkpoint_lock);
331
            return;
331
            return;
332
        }
332
        }
333
        if (cur->flags & BKPOINT_INPROG)
333
        if (cur->flags & BKPOINT_INPROG)
Line 336... Line 336...
336
        if (!(cur->flags & BKPOINT_FUNCCALL))
336
        if (!(cur->flags & BKPOINT_FUNCCALL))
337
            printf("***Breakpoint %d: %p in %s.\n", i,
337
            printf("***Breakpoint %d: %p in %s.\n", i,
338
                   fireaddr, get_symtab_entry(istate->epc));
338
                   fireaddr, get_symtab_entry(istate->epc));
339
 
339
 
340
        /* Return first instruction back */
340
        /* Return first instruction back */
341
        ((__u32 *)cur->address)[0] = cur->instruction;
341
        ((uint32_t *)cur->address)[0] = cur->instruction;
342
 
342
 
343
        if (! (cur->flags & BKPOINT_ONESHOT)) {
343
        if (! (cur->flags & BKPOINT_ONESHOT)) {
344
            /* Set Breakpoint on next instruction */
344
            /* Set Breakpoint on next instruction */
345
            ((__u32 *)cur->address)[1] = 0x0d;
345
            ((uint32_t *)cur->address)[1] = 0x0d;
346
            cur->flags |= BKPOINT_REINST;
346
            cur->flags |= BKPOINT_REINST;
347
        }
347
        }
348
        cur->flags |= BKPOINT_INPROG;
348
        cur->flags |= BKPOINT_INPROG;
349
    } else {
349
    } else {
350
        printf("***Breakpoint %p in %s.\n", fireaddr,
350
        printf("***Breakpoint %p in %s.\n", fireaddr,