Changeset 6c6a19e6 in mainline
- Timestamp:
- 2006-03-17T13:37:59Z (19 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 0f250f9
- Parents:
- bd72b475
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
arch/amd64/include/debugger.h
rbd72b475 r6c6a19e6 43 43 44 44 extern void debugger_init(void); 45 extern int breakpoint_add(void * where, int flags );45 extern int breakpoint_add(void * where, int flags, int curidx); 46 46 extern void breakpoint_del(int slot); 47 47 -
arch/amd64/include/interrupt.h
rbd72b475 r6c6a19e6 61 61 #define VECTOR_TLB_SHOOTDOWN_IPI (IVT_FREEBASE+0) 62 62 #define VECTOR_WAKEUP_IPI (IVT_FREEBASE+1) 63 #define VECTOR_DEBUG_IPI (IVT_FREEBASE+2) 63 64 64 65 /** This is passed to interrupt handlers */ -
arch/amd64/src/debugger.c
rbd72b475 r6c6a19e6 38 38 #include <debug.h> 39 39 #include <func.h> 40 #include <smp/ipi.h> 40 41 41 42 typedef struct { … … 56 57 }; 57 58 59 #ifndef CONFIG_DEBUG_AS_WATCHPOINT 60 58 61 static int cmd_del_breakpoint(cmd_arg_t *argv); 59 62 static cmd_arg_t del_argv = { … … 91 94 }; 92 95 96 #endif 93 97 94 98 /** Print table of active breakpoints */ … … 110 114 } 111 115 116 /* Setup DR register according to table */ 117 static void setup_dr(int curidx) 118 { 119 __native dr7; 120 bpinfo_t *cur = &breakpoints[curidx]; 121 int flags = breakpoints[curidx].flags; 122 123 /* Disable breakpoint in DR7 */ 124 dr7 = read_dr7(); 125 dr7 &= ~(0x2 << (curidx*2)); 126 127 if (cur->address) { /* Setup DR register */ 128 /* Set breakpoint to debug registers */ 129 switch (curidx) { 130 case 0: 131 write_dr0(cur->address); 132 break; 133 case 1: 134 write_dr1(cur->address); 135 break; 136 case 2: 137 write_dr2(cur->address); 138 break; 139 case 3: 140 write_dr3(cur->address); 141 break; 142 } 143 /* Set type to requested breakpoint & length*/ 144 dr7 &= ~ (0x3 << (16 + 4*curidx)); 145 dr7 &= ~ (0x3 << (18 + 4*curidx)); 146 if ((flags & BKPOINT_INSTR)) { 147 ; 148 } else { 149 if (sizeof(int) == 4) 150 dr7 |= ((__native) 0x3) << (18 + 4*curidx); 151 else /* 8 */ 152 dr7 |= ((__native) 0x2) << (18 + 4*curidx); 153 154 if ((flags & BKPOINT_WRITE)) 155 dr7 |= ((__native) 0x1) << (16 + 4*curidx); 156 else if ((flags & BKPOINT_READ_WRITE)) 157 dr7 |= ((__native) 0x3) << (16 + 4*curidx); 158 } 159 160 /* Enable global breakpoint */ 161 dr7 |= 0x2 << (curidx*2); 162 163 write_dr7(dr7); 164 165 } 166 } 167 112 168 /** Enable hardware breakpoint 113 169 * … … 117 173 * @return Debug slot on success, -1 - no available HW breakpoint 118 174 */ 119 int breakpoint_add(void * where, int flags) 120 { 121 bpinfo_t *cur = NULL; 122 int curidx; 175 int breakpoint_add(void * where, int flags, int curidx) 176 { 123 177 ipl_t ipl; 124 178 int i; 125 __native dr7;179 bpinfo_t *cur; 126 180 127 181 ASSERT( flags & (BKPOINT_INSTR | BKPOINT_WRITE | BKPOINT_READ_WRITE)); … … 130 184 spinlock_lock(&bkpoint_lock); 131 185 132 /* Find free space in slots */ 133 for (i=0; i<BKPOINTS_MAX; i++) 134 if (!breakpoints[i].address) { 135 cur = &breakpoints[i]; 136 curidx = i; 137 break; 138 } 139 if (!cur) { 140 /* Too many breakpoints */ 141 spinlock_unlock(&bkpoint_lock); 142 interrupts_restore(ipl); 143 return -1; 144 } 186 if (curidx == -1) { 187 /* Find free space in slots */ 188 for (i=0; i<BKPOINTS_MAX; i++) 189 if (!breakpoints[i].address) { 190 curidx = i; 191 break; 192 } 193 if (curidx == -1) { 194 /* Too many breakpoints */ 195 spinlock_unlock(&bkpoint_lock); 196 interrupts_restore(ipl); 197 return -1; 198 } 199 } 200 cur = &breakpoints[curidx]; 201 145 202 cur->address = (__address) where; 146 203 cur->flags = flags; 147 204 cur->counter = 0; 148 205 149 /* Set breakpoint to debug registers */ 150 switch (curidx) { 151 case 0: 152 write_dr0(cur->address); 153 break; 154 case 1: 155 write_dr1(cur->address); 156 break; 157 case 2: 158 write_dr2(cur->address); 159 break; 160 case 3: 161 write_dr3(cur->address); 162 break; 163 } 164 dr7 = read_dr7(); 165 /* Set type to requested breakpoint & length*/ 166 dr7 &= ~ (0x3 << (16 + 4*curidx)); 167 dr7 &= ~ (0x3 << (18 + 4*curidx)); 168 if ((flags & BKPOINT_INSTR)) { 169 printf("Instr breakpoint\n"); 170 ; 171 } else { 172 if (sizeof(int) == 4) 173 dr7 |= 0x3 << (18 + 4*curidx); 174 else /* 8 */ 175 dr7 |= 0x2 << (18 + 4*curidx); 176 177 if ((flags & BKPOINT_WRITE)) 178 dr7 |= 0x1 << (16 + 4*curidx); 179 else if ((flags & BKPOINT_READ_WRITE)) 180 dr7 |= 0x3 << (16 + 4*curidx); 181 } 182 183 /* Enable global breakpoint */ 184 dr7 |= 0x2 << (curidx*2); 185 186 write_dr7(dr7); 206 setup_dr(curidx); 187 207 188 208 spinlock_unlock(&bkpoint_lock); 189 209 interrupts_restore(ipl); 210 211 /* Send IPI */ 212 #ifdef CONFIG_SMP 213 // ipi_broadcast(VECTOR_DEBUG_IPI); 214 #endif 190 215 191 216 return curidx; … … 222 247 } 223 248 249 void breakpoint_del(int slot) 250 { 251 bpinfo_t *cur; 252 ipl_t ipl; 253 254 ipl = interrupts_disable(); 255 spinlock_lock(&bkpoint_lock); 256 257 cur = &breakpoints[slot]; 258 if (!cur->address) { 259 spinlock_unlock(&bkpoint_lock); 260 interrupts_restore(ipl); 261 return; 262 } 263 264 cur->address = NULL; 265 266 setup_dr(slot); 267 268 spinlock_unlock(&bkpoint_lock); 269 interrupts_restore(ipl); 270 #ifdef CONFIG_SMP 271 // ipi_broadcast(VECTOR_DEBUG_IPI); 272 #endif 273 } 274 275 #ifndef CONFIG_DEBUG_AS_WATCHPOINT 276 277 /** Remove breakpoint from table */ 278 int cmd_del_breakpoint(cmd_arg_t *argv) 279 { 280 if (argv->intval < 0 || argv->intval > BKPOINTS_MAX) { 281 printf("Invalid breakpoint number.\n"); 282 return 0; 283 } 284 breakpoint_del(argv->intval); 285 return 1; 286 } 287 288 /** Add new breakpoint to table */ 289 static int cmd_add_breakpoint(cmd_arg_t *argv) 290 { 291 int flags; 292 int id; 293 294 if (argv == &add_argv) { 295 flags = BKPOINT_INSTR; 296 } else { /* addwatchp */ 297 flags = BKPOINT_WRITE; 298 } 299 printf("Adding breakpoint on address: %p\n", argv->intval); 300 id = breakpoint_add((void *)argv->intval, flags, -1); 301 if (id < 0) 302 printf("Add breakpoint failed.\n"); 303 else 304 printf("Added breakpoint %d.\n", id); 305 306 return 1; 307 } 308 #endif 309 224 310 static void debug_exception(int n, istate_t *istate) 225 311 { … … 245 331 } 246 332 247 void breakpoint_del(int slot) 248 { 249 bpinfo_t *cur; 250 ipl_t ipl; 251 __native dr7; 252 253 ipl = interrupts_disable(); 333 #ifdef CONFIG_SMP 334 static void debug_ipi(int n, istate_t *istate) 335 { 336 int i; 337 254 338 spinlock_lock(&bkpoint_lock); 255 256 cur = &breakpoints[slot]; 257 if (!cur->address) { 258 spinlock_unlock(&bkpoint_lock); 259 interrupts_restore(ipl); 260 return; 261 } 262 263 cur->address = NULL; 264 265 /* Disable breakpoint in DR7 */ 266 dr7 = read_dr7(); 267 dr7 &= ~(0x2 << (slot*2)); 268 write_dr7(dr7); 269 339 for (i=0; i < BKPOINTS_MAX; i++) 340 setup_dr(i); 270 341 spinlock_unlock(&bkpoint_lock); 271 interrupts_restore(ipl); 272 } 273 274 /** Remove breakpoint from table */ 275 int cmd_del_breakpoint(cmd_arg_t *argv) 276 { 277 if (argv->intval < 0 || argv->intval > BKPOINTS_MAX) { 278 printf("Invalid breakpoint number.\n"); 279 return 0; 280 } 281 breakpoint_del(argv->intval); 282 return 1; 283 } 284 285 /** Add new breakpoint to table */ 286 static int cmd_add_breakpoint(cmd_arg_t *argv) 287 { 288 int flags; 289 290 if (argv == &add_argv) { 291 flags = BKPOINT_INSTR; 292 } else { /* addwatchp */ 293 flags = BKPOINT_WRITE; 294 } 295 printf("Adding breakpoint on address: %p\n", argv->intval); 296 if (breakpoint_add((void *)argv->intval, flags)) 297 printf("Add breakpoint failed.\n"); 298 299 return 1; 300 } 342 } 343 #endif 301 344 302 345 /** Initialize debugger */ … … 312 355 panic("could not register command %s\n", bkpts_info.name); 313 356 357 #ifndef CONFIG_DEBUG_AS_WATCHPOINT 314 358 cmd_initialize(&delbkpt_info); 315 359 if (!cmd_register(&delbkpt_info)) … … 323 367 if (!cmd_register(&addwatchp_info)) 324 368 panic("could not register command %s\n", addwatchp_info.name); 369 #endif 325 370 326 371 exc_register(VECTOR_DEBUG, "debugger", 327 372 debug_exception); 328 } 373 #ifdef CONFIG_SMP 374 exc_register(VECTOR_DEBUG_IPI, "debugger_smp", 375 debug_ipi); 376 #endif 377 } -
arch/amd64/src/proc/scheduler.c
rbd72b475 r6c6a19e6 35 35 #include <arch/debugger.h> 36 36 37 #include <print.h> 37 38 void before_thread_runs_arch(void) 38 39 { … … 45 46 swapgs(); 46 47 47 48 48 #ifdef CONFIG_DEBUG_AS_WATCHPOINT 49 49 /* Set watchpoint on AS to ensure that nobody sets it to zero */ 50 static int old_slot = -1; 51 if (old_slot >=0) 52 breakpoint_del(old_slot); 53 old_slot = breakpoint_add(&((the_t *) THREAD->kstack)->as, 54 BKPOINT_WRITE | BKPOINT_CHECK_ZERO); 50 if (CPU->id < BKPOINTS_MAX) 51 breakpoint_add(&((the_t *) THREAD->kstack)->as, 52 BKPOINT_WRITE | BKPOINT_CHECK_ZERO, 53 CPU->id); 55 54 #endif 56 55 } -
arch/ia32/include/interrupt.h
rbd72b475 r6c6a19e6 61 61 #define VECTOR_SYSCALL (IVT_FREEBASE+0) 62 62 #define VECTOR_TLB_SHOOTDOWN_IPI (IVT_FREEBASE+1) 63 #define VECTOR_DEBUG_IPI (IVT_FREEBASE+2) 63 64 64 65 struct istate { -
arch/ia32/src/proc/scheduler.c
rbd72b475 r6c6a19e6 41 41 #ifdef CONFIG_DEBUG_AS_WATCHPOINT 42 42 /* Set watchpoint on AS to ensure that nobody sets it to zero */ 43 static int old_slot = -1; 44 if (old_slot >=0) 45 breakpoint_del(old_slot); 46 old_slot = breakpoint_add(&((the_t *) THREAD->kstack)->as, 47 BKPOINT_WRITE | BKPOINT_CHECK_ZERO); 43 if (CPU->id < BKPOINTS_MAX) 44 breakpoint_add(&((the_t *) THREAD->kstack)->as, 45 BKPOINT_WRITE | BKPOINT_CHECK_ZERO, 46 CPU->id); 48 47 #endif 49 50 48 } 51 49 -
test/thread/thread1/test.c
rbd72b475 r6c6a19e6 42 42 static void threadtest(void *data) 43 43 { 44 while(1) 45 { 46 printf("%d\n",(int)(THREAD->tid)); 47 scheduler(); 48 } 44 while(1) 45 { 46 while (1) 47 ; 48 printf("%d\n",(int)(THREAD->tid)); 49 scheduler(); 50 } 49 51 } 50 52
Note:
See TracChangeset
for help on using the changeset viewer.