Added GDB API - a way to call stub procedures from a DEBUG build.


git-svn-id: svn://svn.rockbox.org/rockbox/trunk@8561 a1c6a512-1295-4272-9138-f99709370657
diff --git a/firmware/debug.c b/firmware/debug.c
index ba19a96..4031ba4 100644
--- a/firmware/debug.c
+++ b/firmware/debug.c
@@ -22,6 +22,9 @@
 #include <stdarg.h>
 #include "config.h"
 #include "cpu.h"
+#ifdef HAVE_GDB_API
+#include "gdb_api.h"
+#endif
 
 #ifdef DEBUG
 static char debugmembuf[200];
@@ -196,6 +199,34 @@
     putpacket(debugbuf);
 }
 #endif /* SH7034 */
+
+#ifdef HAVE_GDB_API
+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);
+}
+
+void debug_init()
+{
+}
+
+#endif /* HAVE_GDB_API */
 #endif /* end of DEBUG section */
 
 #ifdef __GNUC__
diff --git a/firmware/export/config-ifp7xx.h b/firmware/export/config-ifp7xx.h
index 086b455..9e5a432 100644
--- a/firmware/export/config-ifp7xx.h
+++ b/firmware/export/config-ifp7xx.h
@@ -84,6 +84,8 @@
 
 #define USB_ISP1582
 
+#define HAVE_GDB_API
+
 /* Virtual LED (icon) */
 #define CONFIG_LED LED_VIRTUAL
 
diff --git a/firmware/export/debug.h b/firmware/export/debug.h
index 0506ff1..52b6687 100644
--- a/firmware/export/debug.h
+++ b/firmware/export/debug.h
@@ -31,6 +31,11 @@
 #define LDEBUGF(...) ldebugf(__FILE__, __LINE__, __VA_ARGS__)
 #else
 #if defined(DEBUG)
+
+#ifdef HAVE_GDB_API
+void breakpoint(void);
+#endif
+
 #define DEBUGF	debugf
 #define LDEBUGF debugf
 #else
diff --git a/firmware/export/gdb_api.h b/firmware/export/gdb_api.h
new file mode 100644
index 0000000..896c8d3
--- /dev/null
+++ b/firmware/export/gdb_api.h
@@ -0,0 +1,35 @@
+/***************************************************************************
+ *             __________               __   ___.
+ *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
+ *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
+ *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
+ *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
+ *                     \/            \/     \/    \/            \/
+ * $Id$
+ *
+ * Copyright (C) 2006 by Tomasz Malesinski
+ *
+ * All files in this archive are subject to the GNU General Public License.
+ * See the file COPYING in the source tree root for full license agreement.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+
+#ifndef _GDB_API_H_
+#define _GDB_API_H_
+
+#include "config.h"
+
+#define GDB_API_MAGIC 0x6db570b
+#ifdef IRIVER_IFP7XX_SERIES
+#define GDB_API_ADDRESS 0x24006000
+#endif
+
+struct gdb_api
+{
+    unsigned long magic;
+    void *func[];
+};
+#endif
diff --git a/gdb/linker.cfg b/gdb/linker.cfg
index 2cc6a0e..46ec779 100644
--- a/gdb/linker.cfg
+++ b/gdb/linker.cfg
@@ -13,7 +13,8 @@
 MEMORY
 {
    IRAM : ORIGIN = 0, LENGTH = 0x10000
-   DRAM : ORIGIN = 0x24000000, LENGTH = 0x8000
+   DRAM : ORIGIN = 0x24000000, LENGTH = 0x6000
+   DRAM_API : ORIGIN = 0x24006000, LENGTH = 0x100
 }
 
 SECTIONS
@@ -29,6 +30,11 @@
         *(.glue_7t)
     } >DRAM
 
+    .gdbapi :
+    {
+        *(.gdbapi)
+    } >DRAM_API
+
     .data :
     {
         *(.data)