#! /bin/sh
# Configure SH/edk7708 eCos to create EDK7708 GDB stubs
# Ensure that PATH include the directory where the SH tools reside.
#
# Run from an empty temporary directory with one argument: the path to
# the packages directory (i.e., where pkgconf.tcl lives).
#
# Output will be ./stubrom.bin which is suitable for burning into ROM.

if ( echo | tclsh ) 2>/dev/null ; then
  TCL=tclsh
elif ( echo | cygtclsh80 ) 2>/dev/null ; then
  TCL=cygtclsh80
else
  echo Could not find TCL interpreter
  exit 1
fi

$TCL $1/pkgconf.tcl                                                    \
   --target=sh --platform=edk7708 --startup=rom                        \
   --disable CYGPKG_KERNEL --disable CYGPKG_UITRON                     \
   --disable CYGPKG_LIBC --disable CYGPKG_LIBM                         \
   --disable CYGPKG_ERROR --disable CYGPKG_IO                          \
   --disable CYGPKG_IO_SERIAL --disable CYGPKG_DEVICES_WALLCLOCK       \
   --disable CYGPKG_DEVICES_WATCHDOG

patch <<END_OF_PATCH -p0
--- pkgconf/hal.h.orig	Thu Feb 10 09:05:07 2000
+++ pkgconf/hal.h	Thu Feb 10 09:04:56 2000
@@ -122,7 +122,7 @@
  }
 
  }}CFG_DATA */
-#define CYGFUN_HAL_COMMON_KERNEL_SUPPORT
+#undef  CYGFUN_HAL_COMMON_KERNEL_SUPPORT
 #undef  CYGDBG_HAL_DIAG_DISABLE_GDB_PROTOCOL
 
 #ifdef CYGDBG_HAL_DIAG_DISABLE_GDB_PROTOCOL
@@ -243,7 +243,7 @@
 #define CYGIMP_HAL_COMMON_INTERRUPTS_USE_INTERRUPT_STACK
 #define CYGNUM_HAL_COMMON_INTERRUPTS_STACK_SIZE 4096
 #undef  CYGSEM_HAL_COMMON_INTERRUPTS_ALLOW_NESTING
-#define CYGDBG_HAL_COMMON_INTERRUPTS_SAVE_MINIMUM_CONTEXT
+#undef  CYGDBG_HAL_COMMON_INTERRUPTS_SAVE_MINIMUM_CONTEXT
 #undef  CYGIMP_HAL_COMMON_INTERRUPTS_CHAIN
 #undef  CYGIMP_HAL_COMMON_INTERRUPTS_IGNORE_SPURIOUS
 
@@ -272,7 +272,7 @@
  }
  
  }}CFG_DATA */
-#define CYGDBG_HAL_COMMON_CONTEXT_SAVE_MINIMUM
+#undef  CYGDBG_HAL_COMMON_CONTEXT_SAVE_MINIMUM
 
 /* {{CFG_DATA
 
@@ -423,10 +423,10 @@
 
    }}CFG_DATA */
 
-#undef   CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS
+#define  CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS
 #undef   CYGDBG_HAL_DEBUG_GDB_BREAK_SUPPORT
-#define  CYGDBG_HAL_DEBUG_GDB_CTRLC_SUPPORT
-#define  CYGDBG_HAL_DEBUG_GDB_THREAD_SUPPORT
+#undef   CYGDBG_HAL_DEBUG_GDB_CTRLC_SUPPORT
+#undef   CYGDBG_HAL_DEBUG_GDB_THREAD_SUPPORT
 
 /*
  * NOTE:
@@ -522,7 +522,7 @@

 
 /* Enable this when configuring as a ROM monitor (i.e., stub) */
-#undef  CYGSEM_HAL_ROM_MONITOR
+#define CYGSEM_HAL_ROM_MONITOR
 
 #include CYGBLD_HAL_TARGET_H
 #include CYGBLD_HAL_PLATFORM_H 
END_OF_PATCH

make
make -C hal/common/current/src/stubrom
sh-elf-objcopy -O binary hal/common/current/src/stubrom/stubrom stubrom.bin
