2002-04-20 23:01:30 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2002 by Linus Nielsen Feltzing
|
|
|
|
*
|
2008-06-28 18:10:04 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2002-04-20 23:01:30 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2005-01-27 19:17:08 +00:00
|
|
|
|
2002-04-20 23:01:30 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdarg.h>
|
2002-04-30 19:43:54 +00:00
|
|
|
#include "config.h"
|
2005-01-27 19:17:08 +00:00
|
|
|
#include "cpu.h"
|
2006-02-04 00:04:02 +00:00
|
|
|
#ifdef HAVE_GDB_API
|
|
|
|
#include "gdb_api.h"
|
|
|
|
#endif
|
2002-04-20 23:01:30 +00:00
|
|
|
|
2002-05-31 13:15:48 +00:00
|
|
|
#ifdef DEBUG
|
2005-08-16 08:32:43 +00:00
|
|
|
static char debugmembuf[200];
|
2007-03-02 20:03:41 +00:00
|
|
|
#if CONFIG_CPU == SH7034
|
2005-08-16 08:32:43 +00:00
|
|
|
static char debugbuf[400];
|
2002-05-31 13:15:48 +00:00
|
|
|
#endif
|
2006-02-12 23:26:18 +00:00
|
|
|
#endif
|
2002-04-20 23:01:30 +00:00
|
|
|
|
2002-07-02 15:58:56 +00:00
|
|
|
#include "kernel.h"
|
|
|
|
#include "system.h"
|
2008-05-03 08:35:14 +00:00
|
|
|
#include "debug.h"
|
2002-04-30 19:43:54 +00:00
|
|
|
|
2005-05-08 13:24:30 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
#if CONFIG_CPU == SH7034 /* these are still very SH-oriented */
|
2002-05-17 19:48:27 +00:00
|
|
|
void debug_init(void)
|
|
|
|
{
|
|
|
|
/* Clear it all! */
|
|
|
|
SSR1 &= ~(SCI_RDRF | SCI_ORER | SCI_PER | SCI_FER);
|
|
|
|
|
|
|
|
/* This enables the serial Rx interrupt, to be able to exit into the
|
|
|
|
debugger when you hit CTRL-C */
|
|
|
|
SCR1 |= 0x40;
|
|
|
|
SCR1 &= ~0x80;
|
|
|
|
IPRE |= 0xf000; /* Set to highest priority */
|
|
|
|
}
|
|
|
|
|
2002-04-20 23:01:30 +00:00
|
|
|
static int debug_tx_ready(void)
|
|
|
|
{
|
2002-05-02 11:44:15 +00:00
|
|
|
return (SSR1 & SCI_TDRE);
|
2002-04-20 23:01:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void debug_tx_char(char ch)
|
|
|
|
{
|
|
|
|
while (!debug_tx_ready())
|
|
|
|
{
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Write data into TDR and clear TDRE
|
|
|
|
*/
|
|
|
|
TDR1 = ch;
|
|
|
|
SSR1 &= ~SCI_TDRE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void debug_handle_error(char ssr)
|
|
|
|
{
|
2002-05-31 13:15:48 +00:00
|
|
|
(void)ssr;
|
|
|
|
SSR1 &= ~(SCI_ORER | SCI_PER | SCI_FER);
|
2002-04-20 23:01:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int debug_rx_ready(void)
|
|
|
|
{
|
|
|
|
char ssr;
|
|
|
|
|
|
|
|
ssr = SSR1 & ( SCI_PER | SCI_FER | SCI_ORER );
|
|
|
|
if ( ssr )
|
|
|
|
debug_handle_error ( ssr );
|
|
|
|
return SSR1 & SCI_RDRF;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char debug_rx_char(void)
|
|
|
|
{
|
|
|
|
char ch;
|
|
|
|
char ssr;
|
|
|
|
|
|
|
|
while (!debug_rx_ready())
|
|
|
|
{
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
ch = RDR1;
|
|
|
|
SSR1 &= ~SCI_RDRF;
|
|
|
|
|
|
|
|
ssr = SSR1 & (SCI_PER | SCI_FER | SCI_ORER);
|
|
|
|
|
|
|
|
if (ssr)
|
|
|
|
debug_handle_error (ssr);
|
|
|
|
|
|
|
|
return ch;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char hexchars[] = "0123456789abcdef";
|
|
|
|
|
|
|
|
static char highhex(int x)
|
|
|
|
{
|
|
|
|
return hexchars[(x >> 4) & 0xf];
|
|
|
|
}
|
|
|
|
|
|
|
|
static char lowhex(int x)
|
|
|
|
{
|
|
|
|
return hexchars[x & 0xf];
|
|
|
|
}
|
|
|
|
|
2004-08-16 23:37:23 +00:00
|
|
|
static void putpacket (const char *buffer)
|
2002-04-20 23:01:30 +00:00
|
|
|
{
|
|
|
|
register int checksum;
|
|
|
|
|
2004-08-16 23:37:23 +00:00
|
|
|
const char *src = buffer;
|
2002-04-23 13:41:18 +00:00
|
|
|
|
|
|
|
/* Special debug hack. Shut off the Rx IRQ during I/O to prevent the debug
|
|
|
|
stub from interrupting the message */
|
|
|
|
SCR1 &= ~0x40;
|
|
|
|
|
2002-04-20 23:01:30 +00:00
|
|
|
debug_tx_char ('$');
|
|
|
|
checksum = 0;
|
|
|
|
|
|
|
|
while (*src)
|
|
|
|
{
|
|
|
|
int runlen;
|
|
|
|
|
|
|
|
/* Do run length encoding */
|
|
|
|
for (runlen = 0; runlen < 100; runlen ++)
|
|
|
|
{
|
2004-07-27 19:19:52 +00:00
|
|
|
if (src[0] != src[runlen] || runlen == 99)
|
2002-04-20 23:01:30 +00:00
|
|
|
{
|
|
|
|
if (runlen > 3)
|
|
|
|
{
|
|
|
|
int encode;
|
|
|
|
/* Got a useful amount */
|
|
|
|
debug_tx_char (*src);
|
|
|
|
checksum += *src;
|
|
|
|
debug_tx_char ('*');
|
|
|
|
checksum += '*';
|
|
|
|
checksum += (encode = runlen + ' ' - 4);
|
|
|
|
debug_tx_char (encode);
|
|
|
|
src += runlen;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
debug_tx_char (*src);
|
|
|
|
checksum += *src;
|
|
|
|
src++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
debug_tx_char ('#');
|
|
|
|
debug_tx_char (highhex(checksum));
|
|
|
|
debug_tx_char (lowhex(checksum));
|
|
|
|
|
|
|
|
/* Wait for the '+' */
|
|
|
|
debug_rx_char();
|
2002-04-23 13:41:18 +00:00
|
|
|
|
|
|
|
/* Special debug hack. Enable the IRQ again */
|
|
|
|
SCR1 |= 0x40;
|
2002-04-20 23:01:30 +00:00
|
|
|
}
|
|
|
|
|
2002-05-31 13:15:48 +00:00
|
|
|
|
2002-04-20 23:01:30 +00:00
|
|
|
/* convert the memory, pointed to by mem into hex, placing result in buf */
|
|
|
|
/* return a pointer to the last char put in buf (null) */
|
2004-08-16 23:37:23 +00:00
|
|
|
static char *mem2hex (const char *mem, char *buf, int count)
|
2002-04-20 23:01:30 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int ch;
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
ch = *mem++;
|
|
|
|
*buf++ = highhex (ch);
|
|
|
|
*buf++ = lowhex (ch);
|
|
|
|
}
|
|
|
|
*buf = 0;
|
|
|
|
return (buf);
|
|
|
|
}
|
|
|
|
|
2004-08-16 23:37:23 +00:00
|
|
|
static void debug(const char *msg)
|
2002-04-20 23:01:30 +00:00
|
|
|
{
|
|
|
|
debugbuf[0] = 'O';
|
|
|
|
|
|
|
|
mem2hex(msg, &debugbuf[1], strlen(msg));
|
|
|
|
putpacket(debugbuf);
|
|
|
|
}
|
2009-07-02 10:24:27 +00:00
|
|
|
#elif defined(HAVE_GDB_API)
|
2006-02-04 00:04:02 +00:00
|
|
|
static void *get_api_function(int n)
|
|
|
|
{
|
|
|
|
struct gdb_api *api = (struct gdb_api *)GDB_API_ADDRESS;
|
|
|
|
if (api->magic == GDB_API_MAGIC)
|
|
|
|
return api->func[n];
|
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void breakpoint(void)
|
|
|
|
{
|
|
|
|
void (*f)(void) = get_api_function(0);
|
|
|
|
if (f) (*f)();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void debug(char *msg)
|
|
|
|
{
|
|
|
|
void (*f)(char *) = get_api_function(1);
|
|
|
|
if (f) (*f)(msg);
|
|
|
|
}
|
|
|
|
|
2006-02-12 23:26:18 +00:00
|
|
|
void debug_init(void)
|
2006-02-04 00:04:02 +00:00
|
|
|
{
|
|
|
|
}
|
2009-07-02 10:24:27 +00:00
|
|
|
#else /* !SH7034 && !HAVE_GDB_API */
|
|
|
|
void debug_init(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void debug(char *msg)
|
|
|
|
{
|
|
|
|
(void)msg;
|
|
|
|
}
|
|
|
|
#endif
|
2006-02-04 00:04:02 +00:00
|
|
|
|
2002-05-31 13:15:48 +00:00
|
|
|
#endif /* end of DEBUG section */
|
2002-04-20 23:01:30 +00:00
|
|
|
|
2002-10-20 22:50:58 +00:00
|
|
|
#ifdef __GNUC__
|
2004-08-16 23:37:23 +00:00
|
|
|
void debugf(const char *fmt, ...)
|
2002-10-20 22:50:58 +00:00
|
|
|
#endif
|
2002-04-20 23:01:30 +00:00
|
|
|
{
|
2002-05-02 14:05:51 +00:00
|
|
|
#ifdef DEBUG
|
2002-04-20 23:01:30 +00:00
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
2002-05-02 11:44:15 +00:00
|
|
|
vsnprintf(debugmembuf, sizeof(debugmembuf), fmt, ap);
|
2002-04-20 23:01:30 +00:00
|
|
|
va_end(ap);
|
|
|
|
debug(debugmembuf);
|
2002-05-31 13:15:48 +00:00
|
|
|
#else
|
|
|
|
(void)fmt;
|
2002-05-02 14:05:51 +00:00
|
|
|
#endif
|
2002-04-20 23:01:30 +00:00
|
|
|
}
|
2002-04-30 19:43:54 +00:00
|
|
|
|