Index: c/src/lib/libbsp/mips/genmongoosev/ChangeLog
===================================================================
--- c/src/lib/libbsp/mips/genmongoosev/ChangeLog	(revision e2040badd22f8ad392976d324d1a8daa953e926f)
+++ c/src/lib/libbsp/mips/genmongoosev/ChangeLog	(revision a355e3ea982d7bb8a8cb5a67f810c66cbfc78330)
@@ -1,2 +1,11 @@
+2001-05-22	Greg Menke <gregory.menke@gsfc.nasa.gov>
+
+	* Assisted in design and debug by Joel Sherrill <joel@OARcorp.com>.
+	* clock/clockdrv.c, console/conscfg.c: Corrected.
+	* include/bsp.h: Support for tm27 and addition of CPU_CLOCK_RATE.
+	* startup/bspstart.c: Properly set initial status register and
+	pending interrupts.
+	* timer/timer.c: Works now.
+
 2001-05-10	Ralf Corsepius	<corsepiu@faw.uni-ulm.de>
 
Index: c/src/lib/libbsp/mips/genmongoosev/clock/clockdrv.c
===================================================================
--- c/src/lib/libbsp/mips/genmongoosev/clock/clockdrv.c	(revision e2040badd22f8ad392976d324d1a8daa953e926f)
+++ c/src/lib/libbsp/mips/genmongoosev/clock/clockdrv.c	(revision a355e3ea982d7bb8a8cb5a67f810c66cbfc78330)
@@ -24,12 +24,14 @@
 #endif
 
+
+
 /* reset Timeout (TO) bit */
+
 #define Clock_driver_support_at_tick() \
-  MONGOOSEV_WRITE_REGISTER( \
-    CLOCK_BASE, \
-    MONGOOSEV_TIMER_CONTROL_REGISTER, \
-    (MONGOOSEV_TIMER_CONTROL_COUNTER_ENABLE | \
-     MONGOOSEV_TIMER_CONTROL_INTERRUPT_ENABLE) \
-  );
+  do { \
+    MONGOOSEV_WRITE_REGISTER( CLOCK_BASE, MONGOOSEV_TIMER_CONTROL_REGISTER, \
+         (MONGOOSEV_TIMER_CONTROL_COUNTER_ENABLE | MONGOOSEV_TIMER_CONTROL_INTERRUPT_ENABLE)); \
+  } while(0)
+
 
 #define Clock_driver_support_install_isr( _new, _old ) \
@@ -39,18 +41,10 @@
 
 
-extern int ClockRate;
-
-#define CLICKS (((unsigned32) &ClockRate) / 1000000 )
 #define Clock_driver_support_initialize_hardware() \
-  do { \
-    unsigned32 _clicks; \
-    _clicks = CLICKS * rtems_configuration_get_microseconds_per_tick(); \
-    MONGOOSEV_WRITE_REGISTER( \
-      CLOCK_BASE, \
-      MONGOOSEV_TIMER_INITIAL_COUNTER_REGISTER, \
-      _clicks \
-    ); \
+   do { \
+    unsigned32 _clicks = CPU_CLOCK_RATE_MHZ * rtems_configuration_get_microseconds_per_tick(); \
+    MONGOOSEV_WRITE_REGISTER( CLOCK_BASE, MONGOOSEV_TIMER_INITIAL_COUNTER_REGISTER, _clicks ); \
     Clock_driver_support_at_tick(); \
-  } while(0)
+   } while(0)
 
 #define Clock_driver_support_shutdown_hardware() \
Index: c/src/lib/libbsp/mips/genmongoosev/console/conscfg.c
===================================================================
--- c/src/lib/libbsp/mips/genmongoosev/console/conscfg.c	(revision e2040badd22f8ad392976d324d1a8daa953e926f)
+++ c/src/lib/libbsp/mips/genmongoosev/console/conscfg.c	(revision a355e3ea982d7bb8a8cb5a67f810c66cbfc78330)
@@ -19,5 +19,7 @@
 #include <libchip/mg5uart.h>
 
-#if (CONSOLE_USE_INTERRUPTS)
+/* #define CONSOLE_USE_INTERRUPTS */
+
+#ifdef CONSOLE_USE_INTERRUPTS
 #define MG5UART_FUNCTIONS &mg5uart_fns
 #else
@@ -25,6 +27,4 @@
 #endif
 
-extern int ClockRate;
-#define CLOCK_RATE (unsigned32) &ClockRate
 
 console_tbl     Console_Port_Tbl[] = {
@@ -92,4 +92,2 @@
 BSP_output_char_function_type           BSP_output_char = GENMG5_output_char;
 BSP_polling_getchar_function_type       BSP_poll_char = NULL;
-   
-
Index: c/src/lib/libbsp/mips/genmongoosev/include/bsp.h
===================================================================
--- c/src/lib/libbsp/mips/genmongoosev/include/bsp.h	(revision e2040badd22f8ad392976d324d1a8daa953e926f)
+++ c/src/lib/libbsp/mips/genmongoosev/include/bsp.h	(revision a355e3ea982d7bb8a8cb5a67f810c66cbfc78330)
@@ -27,4 +27,32 @@
 #include <libcpu/mongoose-v.h>
 
+
+#ifndef CPU_CLOCK_RATE
+#define CLOCK_RATE	12000000
+#endif
+
+#define CPU_CLOCK_RATE_HZ	CLOCK_RATE
+#define CPU_CLOCK_RATE_MHZ	(CLOCK_RATE/1000000)
+
+
+/*
+ * Useful defines set here so we can avoid duplicating them all over
+ * creation.
+ *
+ */
+
+
+
+/* 
+ * assertSoftwareInt defined in vectorisrs.c the prototype is here so
+ * userspace code can get to it directly.
+ *  */
+
+extern void assertSoftwareInterrupt(unsigned32);
+
+
+
+
+
 /*
  *  Define the time limits for RTEMS Test Suite test durations.
@@ -45,21 +73,26 @@
  */
 
+
+#define CLOCK_VECTOR	MONGOOSEV_IRQ_TIMER1
+
+
 #define MUST_WAIT_FOR_INTERRUPT 1
 
-#if 0
+#if 1
+
 #define Install_tm27_vector( handler ) \
-    (void) set_vector( handler, MONGOOSEV_IRQ_SOFTWARE_1, 1 ); \
+    (void) set_vector( handler, MONGOOSEV_IRQ_SOFTWARE_1, 1 ); 
 
-#define Cause_tm27_intr() \
-    asm volatile ( "syscall 0x01" : : );
 
-#define CLOCK_VECTOR MONGOOSEV_IRQ_TMR0
+
+#define Cause_tm27_intr()   assertSoftwareInterrupt(0);
 
 #define Clear_tm27_intr()  
+#define Lower_tm27_intr()
 
-#define Lower_tm27_intr()
 #else
+
 #define Install_tm27_vector( handler ) \
-    (void) set_vector( handler, MONGOOSEV_IRQ_TMR0, 1 ); \
+    (void) set_vector( handler, MONGOOSEV_IRQ_TIMER1, 1 ); 
 
 #define Cause_tm27_intr() \
@@ -69,5 +102,4 @@
 
 #define Clear_tm27_intr() 
-
 #define Lower_tm27_intr()
 
Index: c/src/lib/libbsp/mips/genmongoosev/startup/bspstart.c
===================================================================
--- c/src/lib/libbsp/mips/genmongoosev/startup/bspstart.c	(revision e2040badd22f8ad392976d324d1a8daa953e926f)
+++ c/src/lib/libbsp/mips/genmongoosev/startup/bspstart.c	(revision a355e3ea982d7bb8a8cb5a67f810c66cbfc78330)
@@ -21,4 +21,6 @@
 #include <rtems/libcsupport.h>
 #include <libcpu/mongoose-v.h>
+
+
 
 /*
@@ -58,8 +60,9 @@
 void bsp_pretasking_hook(void)
 {
-    extern int   HeapBase;
-    extern int   HeapSize;
+    extern int HeapBase;
+    extern int HeapSize;
     void         *heapStart = &HeapBase;
     unsigned long heapSize = (unsigned long)&HeapSize;
+    unsigned long ramSpace;
 
     bsp_libc_init(heapStart, (unsigned32) heapSize, 0);
@@ -68,6 +71,9 @@
     rtems_debug_enable( RTEMS_DEBUG_ALL_MASK );
 #endif
+
 }
- 
+
+
+
 /*
  *  bsp_start
@@ -80,9 +86,6 @@
   extern int _end;
   extern int WorkspaceBase;
-  extern int _RamSize, _RamBase;
-  int ram_left;
 
-  ram_left = (unsigned32) &_RamSize - 
-             (unsigned32)&WorkspaceBase - (unsigned32) &_RamBase;
+  /* Configure Number of Register Caches */
 
   Cpu_table.pretasking_hook = bsp_pretasking_hook;  /* init libc, etc. */
@@ -90,22 +93,57 @@
   Cpu_table.interrupt_stack_size = 4096;
 
-  if ( BSP_Configuration.work_space_size >  ram_left )
-    _sys_exit( 1 );
+  /* HACK -- tied to value linkcmds */
+  if ( BSP_Configuration.work_space_size >(4096*1024) )
+   _sys_exit( 1 );
 
   BSP_Configuration.work_space_start = (void *) &WorkspaceBase;
 
-  /* Clear all pending peripheral interrupts and mask them. */
-   
-  MONGOOSEV_WRITE( MONGOOSEV_PERIPHERAL_FUNCTION_INTERRUPT_CAUSE_REGISTER, 0 );
+  MONGOOSEV_WRITE( MONGOOSEV_WATCHDOG, 0xA0 );
+
+  /* reset the config register & clear any pending peripheral interrupts */
+  MONGOOSEV_WRITE( MONGOOSEV_PERIPHERAL_COMMAND_REGISTER, 0 );
+  MONGOOSEV_WRITE( MONGOOSEV_PERIPHERAL_COMMAND_REGISTER, MONGOOSEV_UART_CMD_RESET_BOTH_PORTS );
+  MONGOOSEV_WRITE( MONGOOSEV_PERIPHERAL_COMMAND_REGISTER, 0 );
+
+  /* reset both timers */
+  MONGOOSEV_WRITE_REGISTER( MONGOOSEV_TIMER1_BASE, MONGOOSEV_TIMER_INITIAL_COUNTER_REGISTER, 0xffffffff );
+  MONGOOSEV_WRITE_REGISTER( MONGOOSEV_TIMER1_BASE, MONGOOSEV_TIMER_CONTROL_REGISTER, 0);
+
+  MONGOOSEV_WRITE_REGISTER( MONGOOSEV_TIMER2_BASE, MONGOOSEV_TIMER_INITIAL_COUNTER_REGISTER, 0xffffffff );
+  MONGOOSEV_WRITE_REGISTER( MONGOOSEV_TIMER2_BASE, MONGOOSEV_TIMER_CONTROL_REGISTER, 0);
+
   MONGOOSEV_WRITE( MONGOOSEV_PERIPHERAL_FUNCTION_INTERRUPT_MASK_REGISTER, 0 );
+  MONGOOSEV_WRITE( MONGOOSEV_PERIPHERAL_STATUS_REGISTER, 0xffffffff );
 
-  /*
-   *  Enable coprocessors.
-   *  Disable external interrupts.
-   *  Enable software interrupts.
-   */
+  /* clear any writable bits in the cause register */
+  mips_set_cause( 0 );
 
-  mips_set_sr( (SR_CU0 | SR_CU1 | SR_IBIT1 | SR_IBIT2) );
+  /*all interrupts unmasked but globally off.  depend on the IRC to take care of things */
+  mips_set_sr( (SR_CU0 | SR_CU1 | 0xff00) );
 
   mips_install_isr_entries();
 }
+
+
+void clear_cache( void *address, size_t n )
+{
+}
+
+/* Structure filled in by get_mem_info.  Only the size field is
+   actually used (to clear bss), so the others aren't even filled in.  */
+
+struct s_mem
+{
+  unsigned int size;
+  unsigned int icsize;
+  unsigned int dcsize;
+};
+
+
+void
+get_mem_info (mem)
+     struct s_mem *mem;
+{
+  mem->size = 0x1000000;        /* XXX figure out something here */
+}
+
Index: c/src/lib/libbsp/mips/genmongoosev/timer/timer.c
===================================================================
--- c/src/lib/libbsp/mips/genmongoosev/timer/timer.c	(revision e2040badd22f8ad392976d324d1a8daa953e926f)
+++ c/src/lib/libbsp/mips/genmongoosev/timer/timer.c	(revision a355e3ea982d7bb8a8cb5a67f810c66cbfc78330)
@@ -38,18 +38,19 @@
    */
 
-  MONGOOSEV_WRITE_REGISTER(
-    TIMER_BASE,
-    MONGOOSEV_TIMER_INITIAL_COUNTER_REGISTER,
-    0xffffffff
-  );
-  MONGOOSEV_WRITE_REGISTER(
-    TIMER_BASE,
-    MONGOOSEV_TIMER_CONTROL_REGISTER,
-    MONGOOSEV_TIMER_CONTROL_COUNTER_ENABLE
-  );
+   MONGOOSEV_WRITE_REGISTER( TIMER_BASE, MONGOOSEV_TIMER_CONTROL_REGISTER, 0);
+
+   MONGOOSEV_WRITE_REGISTER( TIMER_BASE,
+			     MONGOOSEV_TIMER_INITIAL_COUNTER_REGISTER,
+			     0xffffffff );
+
+   MONGOOSEV_WRITE_REGISTER( TIMER_BASE,
+			     MONGOOSEV_TIMER_CONTROL_REGISTER,
+			     MONGOOSEV_TIMER_CONTROL_COUNTER_ENABLE );
+
 }
 
 #define AVG_OVERHEAD      0  /* It typically takes N instructions */
                              /*     to start/stop the timer. */
+
 #define LEAST_VALID       1  /* Don't trust a value lower than this */
                              /* mongoose-v can count cycles. :) */
@@ -62,11 +63,14 @@
   rtems_unsigned32  tcr;
 
-  clicks = MONGOOSEV_READ_REGISTER(
-    TIMER_BASE,
-    MONGOOSEV_TIMER_INITIAL_COUNTER_REGISTER
-  );
+  clicks = MONGOOSEV_READ_REGISTER( TIMER_BASE,
+				    MONGOOSEV_TIMER_INITIAL_COUNTER_REGISTER );
   total = 0xffffffff - clicks;
 
   tcr = MONGOOSEV_READ_REGISTER( TIMER_BASE, MONGOOSEV_TIMER_CONTROL_REGISTER );
+
+  MONGOOSEV_WRITE_REGISTER( TIMER_BASE, 
+			    MONGOOSEV_TIMER_CONTROL_REGISTER, 
+			    0 );
+
   if ( tcr & MONGOOSEV_TIMER_CONTROL_TIMEOUT )
     printk( "MG5 timer overran\n" );
@@ -78,5 +82,5 @@
     return 0;            /* below timer resolution */
 
-  return total - AVG_OVERHEAD;
+  return (total - AVG_OVERHEAD) / CPU_CLOCK_RATE_MHZ;
 }
 
@@ -92,2 +96,5 @@
   Timer_driver_Find_average_overhead = find_flag;
 }
+
+
+/* eof */
