wdenk | 1dda0b1 | 2002-08-27 10:52:29 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Bedbug Functions specific to the MPC603e core |
| 3 | */ |
| 4 | |
| 5 | #include <common.h> |
| 6 | #include <command.h> |
| 7 | #include <linux/ctype.h> |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 8 | #include <bedbug/type.h> |
wdenk | 1dda0b1 | 2002-08-27 10:52:29 +0000 | [diff] [blame] | 9 | #include <bedbug/bedbug.h> |
| 10 | #include <bedbug/regs.h> |
| 11 | #include <bedbug/ppc.h> |
| 12 | |
Jon Loeliger | 4431283 | 2007-07-09 19:06:00 -0500 | [diff] [blame] | 13 | #if defined(CONFIG_CMD_BEDBUG) \ |
Jon Loeliger | f48070f | 2007-06-11 19:03:08 -0500 | [diff] [blame] | 14 | && (defined(CONFIG_MPC824X) || defined(CONFIG_MPC8260)) |
wdenk | 1dda0b1 | 2002-08-27 10:52:29 +0000 | [diff] [blame] | 15 | |
| 16 | #define MAX_BREAK_POINTS 1 |
| 17 | |
| 18 | extern CPU_DEBUG_CTX bug_ctx; |
| 19 | |
| 20 | void bedbug603e_init __P((void)); |
Wolfgang Denk | 54841ab | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 21 | void bedbug603e_do_break __P((cmd_tbl_t*,int,int,char*const[])); |
wdenk | 1dda0b1 | 2002-08-27 10:52:29 +0000 | [diff] [blame] | 22 | void bedbug603e_break_isr __P((struct pt_regs*)); |
| 23 | int bedbug603e_find_empty __P((void)); |
| 24 | int bedbug603e_set __P((int,unsigned long)); |
| 25 | int bedbug603e_clear __P((int)); |
| 26 | |
| 27 | |
| 28 | /* ====================================================================== |
| 29 | * Initialize the global bug_ctx structure for the processor. Clear all |
| 30 | * of the breakpoints. |
| 31 | * ====================================================================== */ |
| 32 | |
| 33 | void bedbug603e_init( void ) |
| 34 | { |
| 35 | int i; |
| 36 | /* -------------------------------------------------- */ |
| 37 | |
| 38 | bug_ctx.hw_debug_enabled = 0; |
| 39 | bug_ctx.stopped = 0; |
| 40 | bug_ctx.current_bp = 0; |
| 41 | bug_ctx.regs = NULL; |
| 42 | |
| 43 | bug_ctx.do_break = bedbug603e_do_break; |
| 44 | bug_ctx.break_isr = bedbug603e_break_isr; |
| 45 | bug_ctx.find_empty = bedbug603e_find_empty; |
| 46 | bug_ctx.set = bedbug603e_set; |
| 47 | bug_ctx.clear = bedbug603e_clear; |
| 48 | |
| 49 | for( i = 1; i <= MAX_BREAK_POINTS; ++i ) |
| 50 | (*bug_ctx.clear)( i ); |
| 51 | |
| 52 | puts ("BEDBUG:ready\n"); |
| 53 | return; |
| 54 | } /* bedbug_init_breakpoints */ |
| 55 | |
| 56 | |
| 57 | |
| 58 | /* ====================================================================== |
| 59 | * Set/clear/show the hardware breakpoint for the 603e. The "off" |
| 60 | * string will disable a specific breakpoint. The "show" string will |
| 61 | * display the current breakpoints. Otherwise an address will set a |
| 62 | * breakpoint at that address. Setting a breakpoint uses the CPU-specific |
| 63 | * set routine which will assign a breakpoint number. |
| 64 | * ====================================================================== */ |
| 65 | |
| 66 | void bedbug603e_do_break (cmd_tbl_t *cmdtp, int flag, int argc, |
Wolfgang Denk | 54841ab | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 67 | char * const argv[]) |
wdenk | 1dda0b1 | 2002-08-27 10:52:29 +0000 | [diff] [blame] | 68 | { |
| 69 | long addr; /* Address to break at */ |
| 70 | int which_bp; /* Breakpoint number */ |
| 71 | /* -------------------------------------------------- */ |
| 72 | |
| 73 | if (argc < 2) |
Wolfgang Denk | 47e26b1 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 74 | return cmd_usage(cmdtp); |
wdenk | 1dda0b1 | 2002-08-27 10:52:29 +0000 | [diff] [blame] | 75 | |
| 76 | /* Turn off a breakpoint */ |
| 77 | |
| 78 | if( strcmp( argv[ 1 ], "off" ) == 0 ) |
| 79 | { |
| 80 | if( bug_ctx.hw_debug_enabled == 0 ) |
| 81 | { |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 82 | puts ( "No breakpoints enabled\n" ); |
wdenk | 1dda0b1 | 2002-08-27 10:52:29 +0000 | [diff] [blame] | 83 | return; |
| 84 | } |
| 85 | |
| 86 | which_bp = simple_strtoul( argv[ 2 ], NULL, 10 ); |
| 87 | |
| 88 | if( bug_ctx.clear ) |
| 89 | (*bug_ctx.clear)( which_bp ); |
| 90 | |
| 91 | printf( "Breakpoint %d removed\n", which_bp ); |
| 92 | return; |
| 93 | } |
| 94 | |
| 95 | /* Show a list of breakpoints */ |
| 96 | |
| 97 | if( strcmp( argv[ 1 ], "show" ) == 0 ) |
| 98 | { |
| 99 | for( which_bp = 1; which_bp <= MAX_BREAK_POINTS; ++which_bp ) |
| 100 | { |
| 101 | |
| 102 | addr = GET_IABR(); |
| 103 | |
| 104 | printf( "Breakpoint [%d]: ", which_bp ); |
| 105 | if( (addr & 0x00000002) == 0 ) |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 106 | puts ( "NOT SET\n" ); |
wdenk | 1dda0b1 | 2002-08-27 10:52:29 +0000 | [diff] [blame] | 107 | else |
| 108 | disppc( (unsigned char *)(addr & 0xFFFFFFFC), 0, 1, bedbug_puts, F_RADHEX ); |
| 109 | } |
| 110 | return; |
| 111 | } |
| 112 | |
| 113 | /* Set a breakpoint at the address */ |
| 114 | |
| 115 | if(!(( isdigit( argv[ 1 ][ 0 ] )) || |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 116 | (( argv[ 1 ][ 0 ] >= 'a' ) && ( argv[ 1 ][ 0 ] <= 'f' )) || |
| 117 | (( argv[ 1 ][ 0 ] >= 'A' ) && ( argv[ 1 ][ 0 ] <= 'F' )))) |
Wolfgang Denk | 47e26b1 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 118 | return cmd_usage(cmdtp); |
wdenk | 1dda0b1 | 2002-08-27 10:52:29 +0000 | [diff] [blame] | 119 | |
| 120 | addr = simple_strtoul( argv[ 1 ], NULL, 16 ); |
| 121 | |
| 122 | if(( bug_ctx.set ) && ( which_bp = (*bug_ctx.set)( 0, addr )) > 0 ) |
| 123 | { |
| 124 | printf( "Breakpoint [%d]: ", which_bp ); |
| 125 | disppc( (unsigned char *)addr, 0, 1, bedbug_puts, F_RADHEX ); |
| 126 | } |
| 127 | |
| 128 | return; |
| 129 | } /* bedbug603e_do_break */ |
| 130 | |
| 131 | |
| 132 | |
| 133 | /* ====================================================================== |
| 134 | * Handle a breakpoint. Enter a mini main loop. Stay in the loop until |
| 135 | * the stopped flag in the debug context is cleared. |
| 136 | * ====================================================================== */ |
| 137 | |
| 138 | void bedbug603e_break_isr( struct pt_regs *regs ) |
| 139 | { |
| 140 | unsigned long addr; /* Address stopped at */ |
| 141 | /* -------------------------------------------------- */ |
| 142 | |
| 143 | bug_ctx.current_bp = 1; |
| 144 | addr = GET_IABR() & 0xFFFFFFFC; |
| 145 | |
| 146 | bedbug_main_loop( addr, regs ); |
| 147 | return; |
| 148 | } /* bedbug603e_break_isr */ |
| 149 | |
| 150 | |
| 151 | |
| 152 | /* ====================================================================== |
| 153 | * See if the hardware breakpoint is available. |
| 154 | * ====================================================================== */ |
| 155 | |
| 156 | int bedbug603e_find_empty( void ) |
| 157 | { |
| 158 | /* -------------------------------------------------- */ |
| 159 | |
| 160 | if( (GET_IABR() && 0x00000002) == 0 ) |
| 161 | return 1; |
| 162 | |
| 163 | return 0; |
| 164 | } /* bedbug603e_find_empty */ |
| 165 | |
| 166 | |
| 167 | |
| 168 | /* ====================================================================== |
| 169 | * Set a breakpoint. If 'which_bp' is zero then find an unused breakpoint |
| 170 | * number, otherwise reassign the given breakpoint. If hardware debugging |
| 171 | * is not enabled, then turn it on via the MSR and DBCR0. Set the break |
| 172 | * address in the IABR register. |
| 173 | * ====================================================================== */ |
| 174 | |
| 175 | int bedbug603e_set( int which_bp, unsigned long addr ) |
| 176 | { |
| 177 | /* -------------------------------------------------- */ |
| 178 | |
| 179 | if(( addr & 0x00000003 ) != 0 ) |
| 180 | { |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 181 | puts ( "Breakpoints must be on a 32 bit boundary\n" ); |
wdenk | 1dda0b1 | 2002-08-27 10:52:29 +0000 | [diff] [blame] | 182 | return 0; |
| 183 | } |
| 184 | |
| 185 | /* Only look if which_bp == 0, else use which_bp */ |
| 186 | if(( bug_ctx.find_empty ) && ( !which_bp ) && |
| 187 | ( which_bp = (*bug_ctx.find_empty)()) == 0 ) |
| 188 | { |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 189 | puts ( "All breakpoints in use\n" ); |
wdenk | 1dda0b1 | 2002-08-27 10:52:29 +0000 | [diff] [blame] | 190 | return 0; |
| 191 | } |
| 192 | |
| 193 | if( which_bp < 1 || which_bp > MAX_BREAK_POINTS ) |
| 194 | { |
| 195 | printf( "Invalid break point # %d\n", which_bp ); |
| 196 | return 0; |
| 197 | } |
| 198 | |
| 199 | if( ! bug_ctx.hw_debug_enabled ) |
| 200 | { |
| 201 | bug_ctx.hw_debug_enabled = 1; |
| 202 | } |
| 203 | |
| 204 | SET_IABR( addr | 0x00000002 ); |
| 205 | |
| 206 | return which_bp; |
| 207 | } /* bedbug603e_set */ |
| 208 | |
| 209 | |
| 210 | |
| 211 | /* ====================================================================== |
| 212 | * Disable a specific breakoint by setting the IABR register to zero. |
| 213 | * ====================================================================== */ |
| 214 | |
| 215 | int bedbug603e_clear( int which_bp ) |
| 216 | { |
| 217 | /* -------------------------------------------------- */ |
| 218 | |
| 219 | if( which_bp < 1 || which_bp > MAX_BREAK_POINTS ) |
| 220 | { |
| 221 | printf( "Invalid break point # (%d)\n", which_bp ); |
| 222 | return -1; |
| 223 | } |
| 224 | |
| 225 | SET_IABR( 0 ); |
| 226 | |
| 227 | return 0; |
| 228 | } /* bedbug603e_clear */ |
| 229 | |
| 230 | |
| 231 | /* ====================================================================== */ |
| 232 | #endif |