--- insight+dejagnu-20030830/sim/h8300/compile.org.c	2003-09-01 16:11:06.000000000 +0530
+++ insight+dejagnu-20030830/sim/h8300/compile.c	2003-09-03 15:38:10.000000000 +0530
@@ -53,7 +53,7 @@ static void set_simcache_size (SIM_DESC,
 
 #define X(op, size)  (op * 4 + size)
 
-#define SP (h8300hmode ? SL : SW)
+#define SP ((h8300hmode && !NormalMode ) ? SL : SW)
 
 #define h8_opcodes ops
 #define DEFINE_TABLE
@@ -511,6 +511,7 @@ enum { POLL_QUIT_INTERVAL = 0x80000 };
 int h8300hmode  = 0;
 int h8300smode  = 0;
 int h8300sxmode = 0;
+int NormalMode  = 0;
 
 static int memory_size;
 
@@ -539,7 +540,7 @@ bitfrom (int x)
     case L_32:
       return SL;
     case L_P:
-      return h8300hmode ? SL : SW;
+      return (h8300hmode && !NormalMode) ? SL : SW;
     }
   return 0;
 }
@@ -575,9 +576,9 @@ lvalue (SIM_DESC sd, int x, int rn, unsi
 static int
 cmdline_location()
 {
-  if (h8300smode)
+  if (h8300smode && !NormalMode)
     return 0xffff00L;
-  else if (h8300hmode)
+  else if (h8300hmode && !NormalMode)
     return 0x2ff00L;
   else
     return 0xff00L;
@@ -838,7 +839,10 @@ decode (SIM_DESC sd, int addr, unsigned 
 	      else if ((looking_for & MODE) == VECIND)
 		{
 		  /* FIXME: Multiplier should be 2 for "normal" mode.  */
-		  cst[opnum] = ((data[1] & 0x7f) + 0x80) * 4;
+		  if(NormalMode)
+		    cst[opnum] = ((data[1] & 0x7f) + 0x80) * 2;
+		  else
+		    cst[opnum] = ((data[1] & 0x7f) + 0x80) * 4;
 		  cst[opnum] += h8_get_vbr (sd); /* Add vector base reg.  */
 		}
 	      else if ((looking_for & SIZE) == L_32)
@@ -1774,9 +1778,9 @@ init_pointers (SIM_DESC sd)
 
       littleendian.i = 1;
 
-      if (h8300smode)
+      if (h8300smode && !NormalMode)
 	memory_size = H8300S_MSIZE;
-      else if (h8300hmode)
+      else if (h8300hmode && !NormalMode)
 	memory_size = H8300H_MSIZE;
       else
 	memory_size = H8300_MSIZE;
@@ -1950,7 +1954,7 @@ sim_resume (SIM_DESC sd, int step, int s
     }
 
   oldmask = h8_get_mask (sd);
-  if (!h8300hmode)
+  if (!h8300hmode  || NormalMode)
     h8_set_mask (sd, 0xffff);
   do
     {
@@ -2790,7 +2794,7 @@ sim_resume (SIM_DESC sd, int step, int s
 
 	    /* Setting char_ptr_size to the sizeof (char *) on the different
 	       architectures.  */
-	    if (h8300hmode || h8300smode)
+	    if ((h8300hmode || h8300smode)  && !NormalMode)
 	      {
 		char_ptr_size = 4;
 	      }
@@ -2859,7 +2863,7 @@ sim_resume (SIM_DESC sd, int step, int s
 	    for (i = 0; i < no_of_args; i++)
 	      {
 		/* Saving the argv pointer.  */
-		if (h8300hmode || h8300smode)
+		if ((h8300hmode || h8300smode)  && !NormalMode)
 		  {
 		    SET_MEMORY_L (argv_ptrs_location, argv_ptrs[i]);
 		  }
@@ -2875,7 +2879,7 @@ sim_resume (SIM_DESC sd, int step, int s
 
 	    /* Required by POSIX, Setting 0x0 at the end of the list of argv
 	       pointers.  */
-	    if (h8300hmode || h8300smode)
+	    if ((h8300hmode || h8300smode)  && !NormalMode)
 	      {
 		SET_MEMORY_L (old_sp, 0x0);
 	      }
@@ -2914,7 +2918,7 @@ sim_resume (SIM_DESC sd, int step, int s
 
 	    /* Setting filename_ptr to first argument of open,  */
 	    /* and trying to get mode.  */
-	    if (h8300sxmode || h8300hmode || h8300smode)
+	    if ((h8300sxmode || h8300hmode || h8300smode)  && !NormalMode)
 	      {
 		filename_ptr = GET_L_REG (0);
 		mode = GET_MEMORY_L (h8_get_reg (sd, SP_REGNUM) + 4);
@@ -2965,8 +2969,8 @@ sim_resume (SIM_DESC sd, int step, int s
 	    int read_return = 0;	/* Return value from callback to
 					   read.  */
 
-	    fd = h8300hmode ? GET_L_REG (0) : GET_W_REG (0);
-	    buf_size = h8300hmode ? GET_L_REG (2) : GET_W_REG (2);
+	    fd = (h8300hmode  && !NormalMode) ? GET_L_REG (0) : GET_W_REG (0);
+	    buf_size = (h8300hmode  && !NormalMode) ? GET_L_REG (2) : GET_W_REG (2);
 
 	    char_ptr = (char *) malloc (sizeof (char) * buf_size);
 
@@ -3000,9 +3004,9 @@ sim_resume (SIM_DESC sd, int step, int s
 	    int write_return;	/* Return value from callback to write.  */
 	    int i = 0;		/* Loop counter */
 
-	    fd = h8300hmode ? GET_L_REG (0) : GET_W_REG (0);
-	    char_ptr = h8300hmode ? GET_L_REG (1) : GET_W_REG (1);
-	    len = h8300hmode ? GET_L_REG (2) : GET_W_REG (2);
+	    fd = (h8300hmode  && !NormalMode) ? GET_L_REG (0) : GET_W_REG (0);
+	    char_ptr = (h8300hmode  && !NormalMode) ? GET_L_REG (1) : GET_W_REG (1);
+	    len = (h8300hmode  && !NormalMode) ? GET_L_REG (2) : GET_W_REG (2);
 
 	    /* Allocating space for the characters to be written.  */
 	    ptr = (char *) malloc (sizeof (char) * len);
@@ -3032,9 +3036,9 @@ sim_resume (SIM_DESC sd, int step, int s
 	    int origin;		/* Origin */
 	    int lseek_return;	/* Return value from callback to lseek.  */
 
-	    fd = h8300hmode ? GET_L_REG (0) : GET_W_REG (0);
-	    offset = h8300hmode ? GET_L_REG (1) : GET_W_REG (1);
-	    origin = h8300hmode ? GET_L_REG (2) : GET_W_REG (2);
+	    fd = (h8300hmode  && !NormalMode) ? GET_L_REG (0) : GET_W_REG (0);
+	    offset = (h8300hmode  && !NormalMode) ? GET_L_REG (1) : GET_W_REG (1);
+	    origin = (h8300hmode  && !NormalMode) ? GET_L_REG (2) : GET_W_REG (2);
 
 	    /* Callback lseek and return offset.  */
 	    lseek_return =
@@ -3050,7 +3054,7 @@ sim_resume (SIM_DESC sd, int step, int s
 	    int fd;		/* File descriptor */
 	    int close_return;	/* Return value from callback to close.  */
 
-	    fd = h8300hmode ? GET_L_REG (0) : GET_W_REG (0);
+	    fd = (h8300hmode  && !NormalMode) ? GET_L_REG (0) : GET_W_REG (0);
 
 	    /* Callback close and return.  */
 	    close_return = sim_callback->close (sim_callback, fd);
@@ -3068,10 +3072,10 @@ sim_resume (SIM_DESC sd, int step, int s
 	    int stat_ptr;	/* Pointer to stat record.  */
 	    char *temp_stat_ptr;	/* Temporary stat_rec pointer.  */
 
-	    fd = h8300hmode ? GET_L_REG (0) : GET_W_REG (0);
+	    fd = (h8300hmode  && !NormalMode) ? GET_L_REG (0) : GET_W_REG (0);
 
 	    /* Setting stat_ptr to second argument of stat.  */
-	    stat_ptr = h8300hmode ? GET_L_REG (1) : GET_W_REG (1);
+	    stat_ptr = (h8300hmode  && !NormalMode) ? GET_L_REG (1) : GET_W_REG (1);
 
 	    /* Callback stat and return.  */
 	    fstat_return = sim_callback->fstat (sim_callback, fd, &stat_rec);
@@ -3120,7 +3124,7 @@ sim_resume (SIM_DESC sd, int step, int s
 	    int i = 0;		/* Loop Counter */
 
 	    /* Setting filename_ptr to first argument of open.  */
-	    filename_ptr = h8300hmode ? GET_L_REG (0) : GET_W_REG (0);
+	    filename_ptr = (h8300hmode  && !NormalMode) ? GET_L_REG (0) : GET_W_REG (0);
 
 	    /* Trying to find the length of the filename.  */
 	    temp_char = GET_MEMORY_B (h8_get_reg (sd, 0));
@@ -3144,7 +3148,7 @@ sim_resume (SIM_DESC sd, int step, int s
 
 	    /* Setting stat_ptr to second argument of stat.  */
 	    /* stat_ptr = h8_get_reg (sd, 1); */
-	    stat_ptr = h8300hmode ? GET_L_REG (1) : GET_W_REG (1);
+	    stat_ptr = (h8300hmode  && !NormalMode) ? GET_L_REG (1) : GET_W_REG (1);
 
 	    /* Callback stat and return.  */
 	    stat_return =
@@ -3552,7 +3556,7 @@ sim_resume (SIM_DESC sd, int step, int s
 	call:
 	  tmp = h8_get_reg (sd, SP_REGNUM);
 
-	  if (h8300hmode)
+	  if (h8300hmode  && !NormalMode)
 	    {
 	      tmp -= 4;
 	      SET_MEMORY_L (tmp, code->next_pc);
@@ -3584,7 +3588,7 @@ sim_resume (SIM_DESC sd, int step, int s
 	      h8_set_exr (sd, GET_MEMORY_L (tmp));
 	      tmp += 4;
 	    }
-	  if (h8300hmode)
+	  if (h8300hmode  && !NormalMode)
 	    {
 	      h8_set_ccr (sd, GET_MEMORY_L (tmp));
 	      tmp += 4;
@@ -3607,7 +3611,7 @@ sim_resume (SIM_DESC sd, int step, int s
 	rts:
 	  tmp = h8_get_reg (sd, SP_REGNUM);
 
-	  if (h8300hmode)
+	  if (h8300hmode  && !NormalMode)
 	    {
 	      pc = GET_MEMORY_L (tmp);
 	      tmp += 4;
@@ -3658,10 +3662,20 @@ sim_resume (SIM_DESC sd, int step, int s
 	    goto end;			/* res is vector number.  */
 
 	  tmp = h8_get_reg (sd, SP_REGNUM);
-	  tmp -= 4;
-	  SET_MEMORY_L (tmp, code->next_pc);
-	  tmp -= 4;
-	  SET_MEMORY_L (tmp, h8_get_ccr (sd));
+	  if(!NormalMode)
+	  {
+	    tmp -= 4;
+	    SET_MEMORY_L (tmp, code->next_pc);
+	    tmp -= 4;
+	    SET_MEMORY_L (tmp, h8_get_ccr (sd));
+	  }
+	  else
+	  {
+	    tmp -= 2;
+	    SET_MEMORY_W (tmp, code->next_pc);
+	    tmp -= 2;
+	    SET_MEMORY_W (tmp, h8_get_ccr (sd));
+	  }
 	  intMaskBit = 1;
 	  BUILDSR (sd);
 
@@ -3674,7 +3688,10 @@ sim_resume (SIM_DESC sd, int step, int s
 	  h8_set_reg (sd, SP_REGNUM, tmp);
 
 	  /* FIXME: "normal" mode should use 2-byte ptrs.  */
-	  pc = GET_MEMORY_L (0x20 + res * 4);
+	  if(NormalMode)
+	    pc = GET_MEMORY_L (0x10 + res * 2); /* Vector addresses are 0x10,0x12,0x14 and 0x16 */
+	  else
+	    pc = GET_MEMORY_L (0x20 + res * 4);
 	  goto end;
 
 	case O (O_BPT, SN):
@@ -4697,7 +4714,7 @@ sim_store_register (SIM_DESC sd, int rn,
   int intval;
   longval = (value[0] << 24) | (value[1] << 16) | (value[2] << 8) | value[3];
   shortval = (value[0] << 8) | (value[1]);
-  intval = h8300hmode ? longval : shortval;
+  intval = (h8300hmode  && !NormalMode) ? longval : shortval;
 
   init_pointers (sd);
   switch (rn)
@@ -4919,6 +4936,10 @@ set_h8300h (unsigned long machine)
 
   if (machine == bfd_mach_h8300h || machine == bfd_mach_h8300hn || h8300smode)
     h8300hmode = 1;
+
+  if (machine == bfd_mach_h8300hn || machine == bfd_mach_h8300sn || machine == bfd_mach_h8300sxn )
+    NormalMode = 1;
+
 }
 
 /* Cover function of sim_state_free to free the cpu buffers as well.  */
@@ -5054,9 +5075,9 @@ sim_load (SIM_DESC sd, char *prog, bfd *
      switching between H8/300 and H8/300H programs without exiting
      gdb.  */
 
-  if (h8300smode)
+  if (h8300smode && !NormalMode)
     memory_size = H8300S_MSIZE;
-  else if (h8300hmode)
+  else if (h8300hmode && !NormalMode)
     memory_size = H8300H_MSIZE;
   else
     memory_size = H8300_MSIZE;
