Index: c/src/lib/libbsp/mips/genmongoosev/ChangeLog
===================================================================
--- c/src/lib/libbsp/mips/genmongoosev/ChangeLog	(revision 090de1adf5c64d4c59d86fa3d5c3f1dd2bae1f80)
+++ c/src/lib/libbsp/mips/genmongoosev/ChangeLog	(revision 3491e9e5447e53242645f0495cd25ae94ab7a743)
@@ -1,2 +1,8 @@
+2001-04-16	Joel Sherrill <joel@OARcorp.com>
+
+	* start/start.S, startup/bspstart.c, startup/linkcmds: 
+	Modifications made with Gregory Menke <gregory.menke@gsfc.nasa.gov>
+	as he debugged this BSP using a logic analyzer.
+
 2001-03-14	Joel Sherrill <joel@OARcorp.com>
 
Index: c/src/lib/libbsp/mips/genmongoosev/start/start.S
===================================================================
--- c/src/lib/libbsp/mips/genmongoosev/start/start.S	(revision 090de1adf5c64d4c59d86fa3d5c3f1dd2bae1f80)
+++ c/src/lib/libbsp/mips/genmongoosev/start/start.S	(revision 3491e9e5447e53242645f0495cd25ae94ab7a743)
@@ -28,14 +28,5 @@
 #endif
 
-#include <asm.h>
 #include "regs.S"
-
-/*
- * Set up some room for a stack. We just grab a chunk of memory.
- */
-#define STACK_SIZE  0x4000
-#define GLOBAL_SIZE 0x2000
-
-#define STARTUP_STACK_SIZE	0x0100
 
 /* This is for referencing addresses that are not in the .sdata or
@@ -51,8 +42,41 @@
 #endif /* __mips_embedded_pic */ 
 
-	.comm	__memsize, 12
-	.comm	__lstack, STARTUP_STACK_SIZE
-	.comm   __stackbase,4
-
+#define zero		$0
+#define	AT		$1		/* assembler temporaries */
+#define	v0		$2		/* value holders */
+#define	v1		$3
+#define	a0		$4		/* arguments */
+#define	a1		$5
+#define	a2		$6
+#define	a3		$7
+#define	t0		$8		/* temporaries */
+#define	t1		$9
+#define	t2		$10
+#define	t3		$11
+#define	t4		$12
+#define	t5		$13
+#define	t6		$14
+#define	t7		$15
+#define	s0		$16		/* saved registers */
+#define	s1		$17
+#define	s2		$18
+#define	s3		$19
+#define	s4		$20
+#define	s5		$21
+#define	s6		$22
+#define	s7		$23
+#define	t8		$24		/* temporaries */
+#define	t9		$25
+#define	k0		$26		/* kernel registers */
+#define	k1		$27
+#define	gp		$28		/* global pointer */
+#define	sp		$29		/* stack pointer */
+#define	s8		$30		/* saved register */
+#define	fp		$30		/* frame pointer (old usage) */
+#define	ra		$31		/* return address */
+
+
+
+	
 	.text
 	.align	2
@@ -63,9 +87,41 @@
  */
 	nop
-
+	
 	.globl	_start
 	.ent	_start
 _start:
 	.set	noreorder
+	# Get the address of start into $5 in a position independent fashion.
+	# This lets us know whether we have been relocated or not.
+	
+	$LF1 = . + 8
+	bal     $LF1
+	nop
+_branch:
+	move	$5, $31				# $5 == where are we
+	li	$6, 0x8002000c			# $6 == where we want to be
+	beq	$5, $6, _start_in_ram
+	nop
+	# relocate the code from EEPROM to RAM
+        la	$7, _edata
+relocate:
+	lw	$8, ($5)			# $8 = *EEPROM
+	addu	$5, $5, 4			# EEPROM++
+        sw      $8, ($6)			# *RAM = $8
+	addu	$6, $6, 4			# RAM++
+	bne	$6, $7, relocate		# copied all the way to edata?
+	nop
+
+	la	$6, _start_in_ram
+	jr	$6
+	nop
+	.end _start
+
+	
+	.globl	_start_in_ram
+	.ent _start_in_ram
+_start_in_ram:
+	nop
+
 #ifdef __mips_embedded_pic
 	PICBASE = .+8
@@ -117,7 +173,4 @@
  */
 	.globl	__memsize
-	.globl	get_mem_info .text
-	.globl	__stack
-	.globl	__global
 	.globl	zerobss
 	.ent	zerobss
@@ -130,20 +183,5 @@
 	addiu	v0,v0,4				# executed in delay slot
 
-	la	t0, __lstack			# make a small stack so we
-	addiu	sp, t0, STARTUP_STACK_SIZE	# can run some C code
-	la	a0, __memsize			# get the usable memory size
-	jal	get_mem_info
-	nop
-
-	/* setup the stack pointer */
-	LA (t0, __stack)			# is __stack set ?
-	bne	t0,zero,4f
-	nop
-
-	/* NOTE: a0[0] contains the amount of memory available, and
-	         not the last memory address. */
-	lw	t0,0(a0)			# last address of memory available
-	la	t1,K0BASE			# cached kernel memory
-	addu	t0,t0,t1			# get the end of memory address
+	la	t0, _stack_init			# initialize stack so we 
 	/* We must subtract 24 bytes for the 3 8 byte arguments to main, in
 	   case main wants to write them back to the stack.  The caller is
@@ -155,50 +193,12 @@
 	   32, which satisifes the stack for the arguments and keeps the
 	   stack pointer better aligned.  */
-	subu	t0,t0,32			# and generate a starting stack-pointer
-4:
+	subu	t0,t0,32
 	move	sp,t0				# set stack pointer
-	sw	sp,__stackbase			# keep this for future ref
 	.end	zerobss
 
-/*
- * initialize target specific stuff. Only execute these
- * functions it they exist.
- */
-#if 0
-	.globl	hardware_init_hook .text
-	.globl	software_init_hook .text
-	.globl	__do_global_dtors .text
-	.globl	atexit .text
-#endif
 	.globl	exit .text
 	.globl	init
 	.ent	init
 init:
-#if 0
-	LA (t9, hardware_init_hook)		# init the hardware if needed
-	beq	t9,zero,6f
-	nop
-	jal	t9
-	nop
-6:
-	LA (t9, software_init_hook)		# init the hardware if needed
-	beq	t9,zero,7f
-	nop
-	jal	t9
-	nop
-7:
-	LA (a0, __do_global_dtors)
-	jal	atexit
-	nop
-#endif
-
-#ifdef GCRT0
-	.globl	_ftext
-	.globl	_extext
-	LA (a0, _ftext)
-	LA (a1, _etext)
-	jal	monstartup
-	nop
-#endif
 
 	move	a0,zero				# set argc to 0
@@ -207,5 +207,5 @@
 
 	# fall through to the "exit" routine
-	jal	exit				# call libc exit to run the G++
+	jal	_sys_exit			# call libc exit to run the G++
 						# destructors
 	move	a0,v0				# pass through the exit code
@@ -213,13 +213,14 @@
 	
 /*
- *  Exit from the application. Normally we cause a user trap
- *  to return to the ROM monitor for another run. NOTE: This is
- *  the only other routine we provide in the crt0.o object, since
- *  it may be tied to the "_start" routine. It also allows
- *  executables that contain a complete world to be linked with
- *  just the crt0.o object.
- */
-
-FRAME(_sys_exit,sp,0,ra)
+ * _sys_exit -- Exit from the application. Normally we cause a user trap
+ *          to return to the ROM monitor for another run. NOTE: This is
+ *	    the only other routine we provide in the crt0.o object, since
+ *          it may be tied to the "_start" routine. It also allows
+ *          executables that contain a complete world to be linked with
+ *          just the crt0.o object.
+ */
+	.globl	_sys_exit
+	.ent _sys_exit
+_sys_exit:
 7:
 #ifdef GCRT0
@@ -232,5 +233,43 @@
 	b	7b				# but loop back just in-case
 	nop
-ENDFRAME(_sys_exit)
+	.end _sys_exit
+
+#define FRAME(name,frm_reg,offset,ret_reg)      \
+        .globl  name;                           \
+        .ent    name;                           \
+name:;                                          \
+        .frame  frm_reg,offset,ret_reg
+#define ENDFRAME(name)                          \
+        .end name
+
+FRAME(mips_enable_interrupts,sp,0,ra)
+        mfc0 t0,C0_SR           /* get status reg */
+        nop
+        or t0,t0,a0
+        mtc0 t0,C0_SR           /* save updated status reg */
+        j ra
+        nop
+ENDFRAME(mips_enable_interrupts)
+#define SR_IEC          0x00000001      /* cur interrupt enable, 1 => enable */
+#define C0_SR           $12             /* status register */
+
+/*
+FRAME(_CPU_ISR_Set_level,sp,0,ra)
+        nop
+        mfc0 t0,C0_SR
+        andi a0, SR_IEC
+        or   t0, a0
+        mtc0 t0,C0_SR
+        nop
+        j ra
+ENDFRAME(_CPU_ISR_Set_level)
+*/
+
+	.section vectors
+	.align	2
+
+FRAME(__ISR_MAIN,sp,0,ra)
+	
+ENDFRAME(__ISR_MAIN)
 
 /* EOF crt0.S */
Index: c/src/lib/libbsp/mips/genmongoosev/startup/bspstart.c
===================================================================
--- c/src/lib/libbsp/mips/genmongoosev/startup/bspstart.c	(revision 090de1adf5c64d4c59d86fa3d5c3f1dd2bae1f80)
+++ c/src/lib/libbsp/mips/genmongoosev/startup/bspstart.c	(revision 3491e9e5447e53242645f0495cd25ae94ab7a743)
@@ -20,4 +20,6 @@
 #include <rtems/libio.h>
 #include <rtems/libcsupport.h>
+#include <libcpu/mongoose-v.h>
+
 
 /*
@@ -70,4 +72,5 @@
 
 }
+
  
 /*
@@ -93,4 +96,5 @@
   BSP_Configuration.work_space_start = (void *) &WorkspaceBase;
 
+  MONGOOSEV_WRITE( MONGOOSEV_PERIPHERAL_FUNCTION_INTERRUPT_CAUSE_REGISTER, 0 );
   mips_set_sr( 0xff00 );  /* all interrupts unmasked but globally off */
                           /* depend on the IRC to take care of things */
