1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2002 by Linus Nielsen Feltzing
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
30 static char debugmembuf
[200];
31 #if CONFIG_CPU == SH3704
32 static char debugbuf
[400];
36 #ifndef SIMULATOR /* allow non archos platforms to display output */
41 #if CONFIG_CPU == SH7034 /* these are still very SH-oriented */
45 SSR1
&= ~(SCI_RDRF
| SCI_ORER
| SCI_PER
| SCI_FER
);
47 /* This enables the serial Rx interrupt, to be able to exit into the
48 debugger when you hit CTRL-C */
51 IPRE
|= 0xf000; /* Set to highest priority */
54 static int debug_tx_ready(void)
56 return (SSR1
& SCI_TDRE
);
59 static void debug_tx_char(char ch
)
61 while (!debug_tx_ready())
67 * Write data into TDR and clear TDRE
73 static void debug_handle_error(char ssr
)
76 SSR1
&= ~(SCI_ORER
| SCI_PER
| SCI_FER
);
79 static int debug_rx_ready(void)
83 ssr
= SSR1
& ( SCI_PER
| SCI_FER
| SCI_ORER
);
85 debug_handle_error ( ssr
);
86 return SSR1
& SCI_RDRF
;
89 static char debug_rx_char(void)
94 while (!debug_rx_ready())
102 ssr
= SSR1
& (SCI_PER
| SCI_FER
| SCI_ORER
);
105 debug_handle_error (ssr
);
110 static const char hexchars
[] = "0123456789abcdef";
112 static char highhex(int x
)
114 return hexchars
[(x
>> 4) & 0xf];
117 static char lowhex(int x
)
119 return hexchars
[x
& 0xf];
122 static void putpacket (const char *buffer
)
124 register int checksum
;
126 const char *src
= buffer
;
128 /* Special debug hack. Shut off the Rx IRQ during I/O to prevent the debug
129 stub from interrupting the message */
139 /* Do run length encoding */
140 for (runlen
= 0; runlen
< 100; runlen
++)
142 if (src
[0] != src
[runlen
] || runlen
== 99)
147 /* Got a useful amount */
148 debug_tx_char (*src
);
152 checksum
+= (encode
= runlen
+ ' ' - 4);
153 debug_tx_char (encode
);
158 debug_tx_char (*src
);
169 debug_tx_char (highhex(checksum
));
170 debug_tx_char (lowhex(checksum
));
172 /* Wait for the '+' */
175 /* Special debug hack. Enable the IRQ again */
180 /* convert the memory, pointed to by mem into hex, placing result in buf */
181 /* return a pointer to the last char put in buf (null) */
182 static char *mem2hex (const char *mem
, char *buf
, int count
)
186 for (i
= 0; i
< count
; i
++)
189 *buf
++ = highhex (ch
);
190 *buf
++ = lowhex (ch
);
196 static void debug(const char *msg
)
200 mem2hex(msg
, &debugbuf
[1], strlen(msg
));
206 static void *get_api_function(int n
)
208 struct gdb_api
*api
= (struct gdb_api
*)GDB_API_ADDRESS
;
209 if (api
->magic
== GDB_API_MAGIC
)
215 void breakpoint(void)
217 void (*f
)(void) = get_api_function(0);
221 static void debug(char *msg
)
223 void (*f
)(char *) = get_api_function(1);
227 void debug_init(void)
231 #endif /* HAVE_GDB_API */
232 #endif /* end of DEBUG section */
235 void debugf(const char *fmt
, ...)
242 vsnprintf(debugmembuf
, sizeof(debugmembuf
), fmt
, ap
);