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 == SH7034
32 static char debugbuf
[400];
36 #ifndef SIMULATOR /* allow non archos platforms to display output */
42 #if CONFIG_CPU == SH7034 /* these are still very SH-oriented */
46 SSR1
&= ~(SCI_RDRF
| SCI_ORER
| SCI_PER
| SCI_FER
);
48 /* This enables the serial Rx interrupt, to be able to exit into the
49 debugger when you hit CTRL-C */
52 IPRE
|= 0xf000; /* Set to highest priority */
55 static int debug_tx_ready(void)
57 return (SSR1
& SCI_TDRE
);
60 static void debug_tx_char(char ch
)
62 while (!debug_tx_ready())
68 * Write data into TDR and clear TDRE
74 static void debug_handle_error(char ssr
)
77 SSR1
&= ~(SCI_ORER
| SCI_PER
| SCI_FER
);
80 static int debug_rx_ready(void)
84 ssr
= SSR1
& ( SCI_PER
| SCI_FER
| SCI_ORER
);
86 debug_handle_error ( ssr
);
87 return SSR1
& SCI_RDRF
;
90 static char debug_rx_char(void)
95 while (!debug_rx_ready())
103 ssr
= SSR1
& (SCI_PER
| SCI_FER
| SCI_ORER
);
106 debug_handle_error (ssr
);
111 static const char hexchars
[] = "0123456789abcdef";
113 static char highhex(int x
)
115 return hexchars
[(x
>> 4) & 0xf];
118 static char lowhex(int x
)
120 return hexchars
[x
& 0xf];
123 static void putpacket (const char *buffer
)
125 register int checksum
;
127 const char *src
= buffer
;
129 /* Special debug hack. Shut off the Rx IRQ during I/O to prevent the debug
130 stub from interrupting the message */
140 /* Do run length encoding */
141 for (runlen
= 0; runlen
< 100; runlen
++)
143 if (src
[0] != src
[runlen
] || runlen
== 99)
148 /* Got a useful amount */
149 debug_tx_char (*src
);
153 checksum
+= (encode
= runlen
+ ' ' - 4);
154 debug_tx_char (encode
);
159 debug_tx_char (*src
);
170 debug_tx_char (highhex(checksum
));
171 debug_tx_char (lowhex(checksum
));
173 /* Wait for the '+' */
176 /* Special debug hack. Enable the IRQ again */
181 /* convert the memory, pointed to by mem into hex, placing result in buf */
182 /* return a pointer to the last char put in buf (null) */
183 static char *mem2hex (const char *mem
, char *buf
, int count
)
187 for (i
= 0; i
< count
; i
++)
190 *buf
++ = highhex (ch
);
191 *buf
++ = lowhex (ch
);
197 static void debug(const char *msg
)
201 mem2hex(msg
, &debugbuf
[1], strlen(msg
));
207 static void *get_api_function(int n
)
209 struct gdb_api
*api
= (struct gdb_api
*)GDB_API_ADDRESS
;
210 if (api
->magic
== GDB_API_MAGIC
)
216 void breakpoint(void)
218 void (*f
)(void) = get_api_function(0);
222 static void debug(char *msg
)
224 void (*f
)(char *) = get_api_function(1);
228 void debug_init(void)
232 #endif /* HAVE_GDB_API */
233 #endif /* end of DEBUG section */
236 void debugf(const char *fmt
, ...)
243 vsnprintf(debugmembuf
, sizeof(debugmembuf
), fmt
, ap
);