Subversion Repositories HelenOS

Rev

Rev 2441 | Rev 2767 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2441 Rev 2712
1
/*
1
/*
2
 * Copyright (c) 2006 Ondrej Palkovsky
2
 * Copyright (c) 2006 Ondrej Palkovsky
3
 * All rights reserved.
3
 * All rights reserved.
4
 *
4
 *
5
 * Redistribution and use in source and binary forms, with or without
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
6
 * modification, are permitted provided that the following conditions
7
 * are met:
7
 * are met:
8
 *
8
 *
9
 * - Redistributions of source code must retain the above copyright
9
 * - Redistributions of source code must retain the above copyright
10
 *   notice, this list of conditions and the following disclaimer.
10
 *   notice, this list of conditions and the following disclaimer.
11
 * - Redistributions in binary form must reproduce the above copyright
11
 * - Redistributions in binary form must reproduce the above copyright
12
 *   notice, this list of conditions and the following disclaimer in the
12
 *   notice, this list of conditions and the following disclaimer in the
13
 *   documentation and/or other materials provided with the distribution.
13
 *   documentation and/or other materials provided with the distribution.
14
 * - The name of the author may not be used to endorse or promote products
14
 * - The name of the author may not be used to endorse or promote products
15
 *   derived from this software without specific prior written permission.
15
 *   derived from this software without specific prior written permission.
16
 *
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 */
27
 */
28
 
28
 
29
/** @addtogroup amd64debug
29
/** @addtogroup amd64debug
30
 * @{
30
 * @{
31
 */
31
 */
32
/** @file
32
/** @file
33
 */
33
 */
34
 
34
 
35
#include <arch/debugger.h>
35
#include <arch/debugger.h>
36
#include <console/kconsole.h>
36
#include <console/kconsole.h>
37
#include <console/cmd.h>
37
#include <console/cmd.h>
38
#include <symtab.h>
38
#include <symtab.h>
39
#include <print.h>
39
#include <print.h>
40
#include <panic.h>
40
#include <panic.h>
41
#include <interrupt.h>
41
#include <interrupt.h>
42
#include <arch/asm.h>
42
#include <arch/asm.h>
43
#include <arch/cpu.h>
43
#include <arch/cpu.h>
44
#include <debug.h>
44
#include <debug.h>
45
#include <func.h>
45
#include <func.h>
46
#include <smp/ipi.h>
46
#include <smp/ipi.h>
47
 
47
 
48
typedef struct  {
48
typedef struct  {
49
    uintptr_t address;      /**< Breakpoint address */
49
    uintptr_t address;      /**< Breakpoint address */
50
    int flags;              /**< Flags regarding breakpoint */
50
    int flags;              /**< Flags regarding breakpoint */
51
    int counter;            /**< How many times the exception occured */
51
    int counter;            /**< How many times the exception occured */
52
} bpinfo_t;
52
} bpinfo_t;
53
 
53
 
54
static bpinfo_t breakpoints[BKPOINTS_MAX];
54
static bpinfo_t breakpoints[BKPOINTS_MAX];
55
SPINLOCK_INITIALIZE(bkpoint_lock);
55
SPINLOCK_INITIALIZE(bkpoint_lock);
56
 
56
 
57
static int cmd_print_breakpoints(cmd_arg_t *argv);
57
static int cmd_print_breakpoints(cmd_arg_t *argv);
58
static cmd_info_t bkpts_info = {
58
static cmd_info_t bkpts_info = {
59
    .name = "bkpts",
59
    .name = "bkpts",
60
    .description = "Print breakpoint table.",
60
    .description = "Print breakpoint table.",
61
    .func = cmd_print_breakpoints,
61
    .func = cmd_print_breakpoints,
62
    .argc = 0,
62
    .argc = 0,
63
};
63
};
64
 
64
 
65
#ifndef CONFIG_DEBUG_AS_WATCHPOINT
65
#ifndef CONFIG_DEBUG_AS_WATCHPOINT
66
 
66
 
67
static int cmd_del_breakpoint(cmd_arg_t *argv);
67
static int cmd_del_breakpoint(cmd_arg_t *argv);
68
static cmd_arg_t del_argv = {
68
static cmd_arg_t del_argv = {
69
    .type = ARG_TYPE_INT
69
    .type = ARG_TYPE_INT
70
};
70
};
71
static cmd_info_t delbkpt_info = {
71
static cmd_info_t delbkpt_info = {
72
    .name = "delbkpt",
72
    .name = "delbkpt",
73
    .description = "delbkpt <number> - Delete breakpoint.",
73
    .description = "delbkpt <number> - Delete breakpoint.",
74
    .func = cmd_del_breakpoint,
74
    .func = cmd_del_breakpoint,
75
    .argc = 1,
75
    .argc = 1,
76
    .argv = &del_argv
76
    .argv = &del_argv
77
};
77
};
78
 
78
 
79
static int cmd_add_breakpoint(cmd_arg_t *argv);
79
static int cmd_add_breakpoint(cmd_arg_t *argv);
80
static cmd_arg_t add_argv = {
80
static cmd_arg_t add_argv = {
81
    .type = ARG_TYPE_INT
81
    .type = ARG_TYPE_INT
82
};
82
};
83
static cmd_info_t addbkpt_info = {
83
static cmd_info_t addbkpt_info = {
84
    .name = "addbkpt",
84
    .name = "addbkpt",
85
    .description = "addbkpt <&symbol> - new breakpoint.",
85
    .description = "addbkpt <&symbol> - new breakpoint.",
86
    .func = cmd_add_breakpoint,
86
    .func = cmd_add_breakpoint,
87
    .argc = 1,
87
    .argc = 1,
88
    .argv = &add_argv
88
    .argv = &add_argv
89
};
89
};
90
 
90
 
91
static cmd_arg_t addw_argv = {
91
static cmd_arg_t addw_argv = {
92
    .type = ARG_TYPE_INT
92
    .type = ARG_TYPE_INT
93
};
93
};
94
static cmd_info_t addwatchp_info = {
94
static cmd_info_t addwatchp_info = {
95
    .name = "addwatchp",
95
    .name = "addwatchp",
96
    .description = "addbwatchp <&symbol> - new write watchpoint.",
96
    .description = "addbwatchp <&symbol> - new write watchpoint.",
97
    .func = cmd_add_breakpoint,
97
    .func = cmd_add_breakpoint,
98
    .argc = 1,
98
    .argc = 1,
99
    .argv = &addw_argv
99
    .argv = &addw_argv
100
};
100
};
101
 
101
 
102
#endif
102
#endif
103
 
103
 
104
/** Print table of active breakpoints */
104
/** Print table of active breakpoints */
105
int cmd_print_breakpoints(cmd_arg_t *argv __attribute__((unused)))
105
int cmd_print_breakpoints(cmd_arg_t *argv __attribute__((unused)))
106
{
106
{
107
    int i;
107
    unsigned int i;
108
    char *symbol;
108
    char *symbol;
109
 
109
   
-
 
110
    if (sizeof(void *) == 4) {
110
    printf("Breakpoint table.\n");
111
        printf("#  Count Address    In symbol\n");
-
 
112
        printf("-- ----- ---------- ---------\n");
-
 
113
    } else {
-
 
114
        printf("#  Count Address            In symbol\n");
-
 
115
        printf("-- ----- ------------------ ---------\n");
-
 
116
    }
-
 
117
   
111
    for (i=0; i < BKPOINTS_MAX; i++)
118
    for (i = 0; i < BKPOINTS_MAX; i++)
112
        if (breakpoints[i].address) {
119
        if (breakpoints[i].address) {
113
            symbol = get_symtab_entry(breakpoints[i].address);
120
            symbol = get_symtab_entry(breakpoints[i].address);
-
 
121
           
114
            printf("%d. %lx in %s\n", i,
122
            if (sizeof(void *) == 4)
-
 
123
                printf("%-2u %-5d %#10zx %s\n", i, breakpoints[i].counter,
-
 
124
                    breakpoints[i].address, symbol);
-
 
125
            else
-
 
126
                printf("%-2u %-5d %#18zx %s\n", i, breakpoints[i].counter,
115
                   breakpoints[i].address, symbol);
127
                    breakpoints[i].address, symbol);
116
            printf("     Count(%d) ", breakpoints[i].counter);
-
 
117
            printf("\n");
-
 
118
        }
128
        }
119
    return 1;
129
    return 1;
120
}
130
}
121
 
131
 
122
/* Setup DR register according to table */
132
/* Setup DR register according to table */
123
static void setup_dr(int curidx)
133
static void setup_dr(int curidx)
124
{
134
{
125
    unative_t dr7;
135
    unative_t dr7;
126
    bpinfo_t *cur = &breakpoints[curidx];
136
    bpinfo_t *cur = &breakpoints[curidx];
127
    int flags = breakpoints[curidx].flags;
137
    int flags = breakpoints[curidx].flags;
128
 
138
 
129
    /* Disable breakpoint in DR7 */
139
    /* Disable breakpoint in DR7 */
130
    dr7 = read_dr7();
140
    dr7 = read_dr7();
131
    dr7 &= ~(0x2 << (curidx*2));
141
    dr7 &= ~(0x2 << (curidx*2));
132
 
142
 
133
    if (cur->address) { /* Setup DR register */
143
    if (cur->address) { /* Setup DR register */
134
        /* Set breakpoint to debug registers */
144
        /* Set breakpoint to debug registers */
135
        switch (curidx) {
145
        switch (curidx) {
136
        case 0:
146
        case 0:
137
            write_dr0(cur->address);
147
            write_dr0(cur->address);
138
            break;
148
            break;
139
        case 1:
149
        case 1:
140
            write_dr1(cur->address);
150
            write_dr1(cur->address);
141
            break;
151
            break;
142
        case 2:
152
        case 2:
143
            write_dr2(cur->address);
153
            write_dr2(cur->address);
144
            break;
154
            break;
145
        case 3:
155
        case 3:
146
            write_dr3(cur->address);
156
            write_dr3(cur->address);
147
            break;
157
            break;
148
        }
158
        }
149
        /* Set type to requested breakpoint & length*/
159
        /* Set type to requested breakpoint & length*/
150
        dr7 &= ~ (0x3 << (16 + 4*curidx));
160
        dr7 &= ~ (0x3 << (16 + 4*curidx));
151
        dr7 &= ~ (0x3 << (18 + 4*curidx));
161
        dr7 &= ~ (0x3 << (18 + 4*curidx));
152
        if ((flags & BKPOINT_INSTR)) {
162
        if ((flags & BKPOINT_INSTR)) {
153
            ;
163
            ;
154
        } else {
164
        } else {
155
            if (sizeof(int) == 4)
165
            if (sizeof(int) == 4)
156
                dr7 |= ((unative_t) 0x3) << (18 + 4*curidx);
166
                dr7 |= ((unative_t) 0x3) << (18 + 4*curidx);
157
            else /* 8 */
167
            else /* 8 */
158
                dr7 |= ((unative_t) 0x2) << (18 + 4*curidx);
168
                dr7 |= ((unative_t) 0x2) << (18 + 4*curidx);
159
           
169
           
160
            if ((flags & BKPOINT_WRITE))
170
            if ((flags & BKPOINT_WRITE))
161
                dr7 |= ((unative_t) 0x1) << (16 + 4*curidx);
171
                dr7 |= ((unative_t) 0x1) << (16 + 4*curidx);
162
            else if ((flags & BKPOINT_READ_WRITE))
172
            else if ((flags & BKPOINT_READ_WRITE))
163
                dr7 |= ((unative_t) 0x3) << (16 + 4*curidx);
173
                dr7 |= ((unative_t) 0x3) << (16 + 4*curidx);
164
        }
174
        }
165
 
175
 
166
        /* Enable global breakpoint */
176
        /* Enable global breakpoint */
167
        dr7 |= 0x2 << (curidx*2);
177
        dr7 |= 0x2 << (curidx*2);
168
 
178
 
169
        write_dr7(dr7);
179
        write_dr7(dr7);
170
       
180
       
171
    }
181
    }
172
}
182
}
173
   
183
   
174
/** Enable hardware breakpoint
184
/** Enable hardware breakpoint
175
 *
185
 *
176
 * @param where Address of HW breakpoint
186
 * @param where Address of HW breakpoint
177
 * @param flags Type of breakpoint (EXECUTE, WRITE)
187
 * @param flags Type of breakpoint (EXECUTE, WRITE)
178
 * @return Debug slot on success, -1 - no available HW breakpoint
188
 * @return Debug slot on success, -1 - no available HW breakpoint
179
 */
189
 */
180
int breakpoint_add(const void *where, const int flags, int curidx)
190
int breakpoint_add(const void *where, const int flags, int curidx)
181
{
191
{
182
    ipl_t ipl;
192
    ipl_t ipl;
183
    int i;
193
    int i;
184
    bpinfo_t *cur;
194
    bpinfo_t *cur;
185
 
195
 
186
    ASSERT(flags & (BKPOINT_INSTR | BKPOINT_WRITE | BKPOINT_READ_WRITE));
196
    ASSERT(flags & (BKPOINT_INSTR | BKPOINT_WRITE | BKPOINT_READ_WRITE));
187
 
197
 
188
    ipl = interrupts_disable();
198
    ipl = interrupts_disable();
189
    spinlock_lock(&bkpoint_lock);
199
    spinlock_lock(&bkpoint_lock);
190
   
200
   
191
    if (curidx == -1) {
201
    if (curidx == -1) {
192
        /* Find free space in slots */
202
        /* Find free space in slots */
193
        for (i = 0; i < BKPOINTS_MAX; i++)
203
        for (i = 0; i < BKPOINTS_MAX; i++)
194
            if (!breakpoints[i].address) {
204
            if (!breakpoints[i].address) {
195
                curidx = i;
205
                curidx = i;
196
                break;
206
                break;
197
            }
207
            }
198
        if (curidx == -1) {
208
        if (curidx == -1) {
199
            /* Too many breakpoints */
209
            /* Too many breakpoints */
200
            spinlock_unlock(&bkpoint_lock);
210
            spinlock_unlock(&bkpoint_lock);
201
            interrupts_restore(ipl);
211
            interrupts_restore(ipl);
202
            return -1;
212
            return -1;
203
        }
213
        }
204
    }
214
    }
205
    cur = &breakpoints[curidx];
215
    cur = &breakpoints[curidx];
206
 
216
 
207
    cur->address = (uintptr_t) where;
217
    cur->address = (uintptr_t) where;
208
    cur->flags = flags;
218
    cur->flags = flags;
209
    cur->counter = 0;
219
    cur->counter = 0;
210
 
220
 
211
    setup_dr(curidx);
221
    setup_dr(curidx);
212
 
222
 
213
    spinlock_unlock(&bkpoint_lock);
223
    spinlock_unlock(&bkpoint_lock);
214
    interrupts_restore(ipl);
224
    interrupts_restore(ipl);
215
 
225
 
216
    /* Send IPI */
226
    /* Send IPI */
217
#ifdef CONFIG_SMP
227
#ifdef CONFIG_SMP
218
//  ipi_broadcast(VECTOR_DEBUG_IPI);    
228
//  ipi_broadcast(VECTOR_DEBUG_IPI);    
219
#endif  
229
#endif  
220
 
230
 
221
    return curidx;
231
    return curidx;
222
}
232
}
223
 
233
 
224
#ifdef amd64
234
#ifdef amd64
225
#   define getip(x) ((x)->rip)
235
#   define getip(x) ((x)->rip)
226
#else
236
#else
227
#   define getip(x) ((x)->eip)
237
#   define getip(x) ((x)->eip)
228
#endif
238
#endif
229
 
239
 
230
static void handle_exception(int slot, istate_t *istate)
240
static void handle_exception(int slot, istate_t *istate)
231
{
241
{
232
    ASSERT(breakpoints[slot].address);
242
    ASSERT(breakpoints[slot].address);
233
 
243
 
234
    /* Handle zero checker */
244
    /* Handle zero checker */
235
    if (! (breakpoints[slot].flags & BKPOINT_INSTR)) {
245
    if (! (breakpoints[slot].flags & BKPOINT_INSTR)) {
236
        if ((breakpoints[slot].flags & BKPOINT_CHECK_ZERO)) {
246
        if ((breakpoints[slot].flags & BKPOINT_CHECK_ZERO)) {
237
            if (*((unative_t *) breakpoints[slot].address) != 0)
247
            if (*((unative_t *) breakpoints[slot].address) != 0)
238
                return;
248
                return;
239
            printf("**** Found ZERO on address %lx (slot %d) ****\n",
249
            printf("**** Found ZERO on address %lx (slot %d) ****\n",
240
                breakpoints[slot].address, slot);
250
                breakpoints[slot].address, slot);
241
        } else {
251
        } else {
242
            printf("Data watchpoint - new data: %lx\n",
252
            printf("Data watchpoint - new data: %lx\n",
243
                   *((unative_t *) breakpoints[slot].address));
253
                   *((unative_t *) breakpoints[slot].address));
244
        }
254
        }
245
    }
255
    }
246
    printf("Reached breakpoint %d:%lx(%s)\n", slot, getip(istate),
256
    printf("Reached breakpoint %d:%lx(%s)\n", slot, getip(istate),
247
           get_symtab_entry(getip(istate)));
257
           get_symtab_entry(getip(istate)));
248
    printf("***Type 'exit' to exit kconsole.\n");
258
    printf("***Type 'exit' to exit kconsole.\n");
249
    atomic_set(&haltstate,1);
259
    atomic_set(&haltstate,1);
250
    kconsole((void *) "debug");
260
    kconsole((void *) "debug");
251
    atomic_set(&haltstate,0);
261
    atomic_set(&haltstate,0);
252
}
262
}
253
 
263
 
254
void breakpoint_del(int slot)
264
void breakpoint_del(int slot)
255
{
265
{
256
    bpinfo_t *cur;
266
    bpinfo_t *cur;
257
    ipl_t ipl;
267
    ipl_t ipl;
258
 
268
 
259
    ipl = interrupts_disable();
269
    ipl = interrupts_disable();
260
    spinlock_lock(&bkpoint_lock);
270
    spinlock_lock(&bkpoint_lock);
261
 
271
 
262
    cur = &breakpoints[slot];
272
    cur = &breakpoints[slot];
263
    if (!cur->address) {
273
    if (!cur->address) {
264
        spinlock_unlock(&bkpoint_lock);
274
        spinlock_unlock(&bkpoint_lock);
265
        interrupts_restore(ipl);
275
        interrupts_restore(ipl);
266
        return;
276
        return;
267
    }
277
    }
268
 
278
 
269
    cur->address = NULL;
279
    cur->address = NULL;
270
 
280
 
271
    setup_dr(slot);
281
    setup_dr(slot);
272
 
282
 
273
    spinlock_unlock(&bkpoint_lock);
283
    spinlock_unlock(&bkpoint_lock);
274
    interrupts_restore(ipl);
284
    interrupts_restore(ipl);
275
#ifdef CONFIG_SMP
285
#ifdef CONFIG_SMP
276
//  ipi_broadcast(VECTOR_DEBUG_IPI);    
286
//  ipi_broadcast(VECTOR_DEBUG_IPI);    
277
#endif
287
#endif
278
}
288
}
279
 
289
 
280
#ifndef CONFIG_DEBUG_AS_WATCHPOINT
290
#ifndef CONFIG_DEBUG_AS_WATCHPOINT
281
 
291
 
282
/** Remove breakpoint from table */
292
/** Remove breakpoint from table */
283
int cmd_del_breakpoint(cmd_arg_t *argv)
293
int cmd_del_breakpoint(cmd_arg_t *argv)
284
{
294
{
285
    if (argv->intval < 0 || argv->intval > BKPOINTS_MAX) {
295
    if (argv->intval < 0 || argv->intval > BKPOINTS_MAX) {
286
        printf("Invalid breakpoint number.\n");
296
        printf("Invalid breakpoint number.\n");
287
        return 0;
297
        return 0;
288
    }
298
    }
289
    breakpoint_del(argv->intval);
299
    breakpoint_del(argv->intval);
290
    return 1;
300
    return 1;
291
}
301
}
292
 
302
 
293
/** Add new breakpoint to table */
303
/** Add new breakpoint to table */
294
static int cmd_add_breakpoint(cmd_arg_t *argv)
304
static int cmd_add_breakpoint(cmd_arg_t *argv)
295
{
305
{
296
    int flags;
306
    int flags;
297
    int id;
307
    int id;
298
 
308
 
299
    if (argv == &add_argv) {
309
    if (argv == &add_argv) {
300
        flags = BKPOINT_INSTR;
310
        flags = BKPOINT_INSTR;
301
    } else { /* addwatchp */
311
    } else { /* addwatchp */
302
        flags = BKPOINT_WRITE;
312
        flags = BKPOINT_WRITE;
303
    }
313
    }
304
    printf("Adding breakpoint on address: %p\n", argv->intval);
314
    printf("Adding breakpoint on address: %p\n", argv->intval);
305
    id = breakpoint_add((void *)argv->intval, flags, -1);
315
    id = breakpoint_add((void *)argv->intval, flags, -1);
306
    if (id < 0)
316
    if (id < 0)
307
        printf("Add breakpoint failed.\n");
317
        printf("Add breakpoint failed.\n");
308
    else
318
    else
309
        printf("Added breakpoint %d.\n", id);
319
        printf("Added breakpoint %d.\n", id);
310
   
320
   
311
    return 1;
321
    return 1;
312
}
322
}
313
#endif
323
#endif
314
 
324
 
315
static void debug_exception(int n __attribute__((unused)), istate_t *istate)
325
static void debug_exception(int n __attribute__((unused)), istate_t *istate)
316
{
326
{
317
    unative_t dr6;
327
    unative_t dr6;
318
    int i;
328
    int i;
319
   
329
   
320
    /* Set RF to restart the instruction  */
330
    /* Set RF to restart the instruction  */
321
#ifdef amd64       
331
#ifdef amd64       
322
    istate->rflags |= RFLAGS_RF;
332
    istate->rflags |= RFLAGS_RF;
323
#else
333
#else
324
    istate->eflags |= EFLAGS_RF;
334
    istate->eflags |= EFLAGS_RF;
325
#endif
335
#endif
326
 
336
 
327
    dr6 = read_dr6();
337
    dr6 = read_dr6();
328
    for (i=0; i < BKPOINTS_MAX; i++) {
338
    for (i=0; i < BKPOINTS_MAX; i++) {
329
        if (dr6 & (1 << i)) {
339
        if (dr6 & (1 << i)) {
330
            dr6 &= ~ (1 << i);
340
            dr6 &= ~ (1 << i);
331
            write_dr6(dr6);
341
            write_dr6(dr6);
332
           
342
           
333
            handle_exception(i, istate);
343
            handle_exception(i, istate);
334
        }
344
        }
335
    }
345
    }
336
}
346
}
337
 
347
 
338
#ifdef CONFIG_SMP
348
#ifdef CONFIG_SMP
339
static void debug_ipi(int n __attribute__((unused)), istate_t *istate __attribute__((unused)))
349
static void debug_ipi(int n __attribute__((unused)), istate_t *istate __attribute__((unused)))
340
{
350
{
341
    int i;
351
    int i;
342
 
352
 
343
    spinlock_lock(&bkpoint_lock);
353
    spinlock_lock(&bkpoint_lock);
344
    for (i = 0; i < BKPOINTS_MAX; i++)
354
    for (i = 0; i < BKPOINTS_MAX; i++)
345
        setup_dr(i);
355
        setup_dr(i);
346
    spinlock_unlock(&bkpoint_lock);
356
    spinlock_unlock(&bkpoint_lock);
347
}
357
}
348
#endif
358
#endif
349
 
359
 
350
/** Initialize debugger */
360
/** Initialize debugger */
351
void debugger_init()
361
void debugger_init()
352
{
362
{
353
    int i;
363
    int i;
354
 
364
 
355
    for (i=0; i<BKPOINTS_MAX; i++)
365
    for (i=0; i<BKPOINTS_MAX; i++)
356
        breakpoints[i].address = NULL;
366
        breakpoints[i].address = NULL;
357
   
367
   
358
    cmd_initialize(&bkpts_info);
368
    cmd_initialize(&bkpts_info);
359
    if (!cmd_register(&bkpts_info))
369
    if (!cmd_register(&bkpts_info))
360
        panic("could not register command %s\n", bkpts_info.name);
370
        panic("could not register command %s\n", bkpts_info.name);
361
 
371
 
362
#ifndef CONFIG_DEBUG_AS_WATCHPOINT
372
#ifndef CONFIG_DEBUG_AS_WATCHPOINT
363
    cmd_initialize(&delbkpt_info);
373
    cmd_initialize(&delbkpt_info);
364
    if (!cmd_register(&delbkpt_info))
374
    if (!cmd_register(&delbkpt_info))
365
        panic("could not register command %s\n", delbkpt_info.name);
375
        panic("could not register command %s\n", delbkpt_info.name);
366
 
376
 
367
    cmd_initialize(&addbkpt_info);
377
    cmd_initialize(&addbkpt_info);
368
    if (!cmd_register(&addbkpt_info))
378
    if (!cmd_register(&addbkpt_info))
369
        panic("could not register command %s\n", addbkpt_info.name);
379
        panic("could not register command %s\n", addbkpt_info.name);
370
 
380
 
371
    cmd_initialize(&addwatchp_info);
381
    cmd_initialize(&addwatchp_info);
372
    if (!cmd_register(&addwatchp_info))
382
    if (!cmd_register(&addwatchp_info))
373
        panic("could not register command %s\n", addwatchp_info.name);
383
        panic("could not register command %s\n", addwatchp_info.name);
374
#endif
384
#endif
375
   
385
   
376
    exc_register(VECTOR_DEBUG, "debugger",
386
    exc_register(VECTOR_DEBUG, "debugger",
377
             debug_exception);
387
             debug_exception);
378
#ifdef CONFIG_SMP
388
#ifdef CONFIG_SMP
379
    exc_register(VECTOR_DEBUG_IPI, "debugger_smp",
389
    exc_register(VECTOR_DEBUG_IPI, "debugger_smp",
380
             debug_ipi);
390
             debug_ipi);
381
#endif
391
#endif
382
}
392
}
383
 
393
 
384
/** @}
394
/** @}
385
 */
395
 */
386
 
396