diff -upNr gcc-orig/config/h8300/h8300.c gcc/config/h8300/h8300.c
--- gcc-orig/config/h8300/h8300.c	2011-12-20 22:16:22.000000000 +0530
+++ gcc/config/h8300/h8300.c	2012-04-03 16:51:51.000000000 +0530
@@ -316,6 +316,14 @@ h8300_option_override (void)
   static const char *const h8_pop_ops[2]  = { "pop"  , "pop.l"  };
   static const char *const h8_mov_ops[2]  = { "mov.w", "mov.l"  };
 
+#ifndef OBJECT_FORMAT_ELF
+  if (TARGET_H8300SX)
+    {
+      error ("-msx is not supported in coff");
+      target_flags |= MASK_H8300S;
+    }
+#endif
+
   if (TARGET_H8300)
     {
       cpu_type = (int) CPU_H8300;
@@ -339,10 +347,34 @@ h8300_option_override (void)
 
   if (TARGET_H8300 && TARGET_NORMAL_MODE)
     {
-      error ("-mn is used without -mh or -ms");
+      error ("-mn is used without -mh or -ms or -msx");
       target_flags ^= MASK_NORMAL_MODE;
     }
 
+  if (! TARGET_H8300S &&  TARGET_EXR)
+    {
+      error ("-mexr is used without -ms");
+      target_flags |= MASK_H8300S_1;
+    }
+
+  if (TARGET_H8300 && TARGET_INT32)
+   {
+      error ("-mint32 is not supported for H8300 and H8300L targets");
+      target_flags ^= MASK_INT32;
+   }
+
+ if ((!TARGET_H8300S  &&  TARGET_EXR) && (!TARGET_H8300SX && TARGET_EXR))
+   {
+      error ("-mexr is used without -ms or -msx");
+      target_flags |= MASK_H8300S_1;
+   }
+
+ if ((!TARGET_H8300S  &&  TARGET_NEXR) && (!TARGET_H8300SX && TARGET_NEXR))
+   {
+      warning (OPT_mno_exr, "-mno-exr valid only with -ms or -msx    \
+               - Option ignored!");
+   }
+
   /* Some of the shifts are optimized for speed by default.
      See http://gcc.gnu.org/ml/gcc-patches/2002-07/msg01858.html
      If optimizing for size, change shift_alg for those shift to
@@ -795,9 +827,9 @@ h8300_expand_prologue (void)
     return;
 
   if (h8300_monitor_function_p (current_function_decl))
-    /* My understanding of monitor functions is they act just like
-       interrupt functions, except the prologue must mask
-       interrupts.  */
+ /* The monitor function act as normal functions, which means it
+    can accept parameters and return values. In addition to this, 
+    interrupts are masked in prologue and return with "rte" in epilogue. */
     emit_insn (gen_monitor_prologue ());
 
   if (frame_pointer_needed)
@@ -925,8 +957,13 @@ h8300_expand_epilogue (void)
 int
 h8300_current_function_interrupt_function_p (void)
 {
-  return (h8300_interrupt_function_p (current_function_decl)
-	  || h8300_monitor_function_p (current_function_decl));
+  return (h8300_interrupt_function_p (current_function_decl));
+}
+
+int
+h8300_current_function_monitor_function_p ()
+{
+  return (h8300_monitor_function_p (current_function_decl));
 }
 
 /* Output assembly code for the start of the file.  */
diff -upNr gcc-orig/config/h8300/h8300.md gcc/config/h8300/h8300.md
--- gcc-orig/config/h8300/h8300.md	2011-09-13 23:42:53.000000000 +0530
+++ gcc/config/h8300/h8300.md	2012-03-20 13:04:26.000000000 +0530
@@ -2609,7 +2609,8 @@
   {
     operands[3] = SET_DEST (XVECEXP (operands[0], 0,
 				     XVECLEN (operands[0], 0) - 2));
-    if (h8300_current_function_interrupt_function_p ())
+    if (h8300_current_function_interrupt_function_p ()
+        || h8300_current_function_monitor_function_p ())
       return "rte/l\t%S1-%S3";
     else
       return "rts/l\t%S1-%S3";
@@ -2628,7 +2629,8 @@
   "reload_completed"
   "*
 {
-  if (h8300_current_function_interrupt_function_p ())
+  if (h8300_current_function_interrupt_function_p ()
+      || h8300_current_function_monitor_function_p ())
     return \"rte\";
   else
     return \"rts\";
@@ -2654,8 +2656,16 @@
 {
   if (TARGET_H8300)
     return \"subs\\t#2,r7\;mov.w\\tr0,@-r7\;stc\\tccr,r0l\;mov.b\tr0l,@(2,r7)\;mov.w\\t@r7+,r0\;orc\t#128,ccr\";
+  else if (TARGET_H8300H && TARGET_NORMAL_MODE)
+    return \"subs\\t#2,er7\;mov.l\\ter0,@-er7\;stc\\tccr,r0l\;mov.b\\tr0l,@(4,er7)\;mov.l\\t@er7+,er0\;orc\\t#128,ccr\";
   else if (TARGET_H8300H)
     return \"mov.l\\ter0,@-er7\;stc\\tccr,r0l\;mov.b\\tr0l,@(4,er7)\;mov.l\\t@er7+,er0\;orc\\t#128,ccr\";
+  else if (TARGET_H8300S && TARGET_NEXR )
+    return \"mov.l\\ter0,@-er7\;stc\tccr,r0l\;mov.b\tr0l,@(4,er7)\;mov.l\\t@er7+,er0\;orc\t#128,ccr\"; 
+  else if (TARGET_H8300S && TARGET_NEXR && TARGET_NORMAL_MODE)
+    return \"subs\\t#2,er7\;mov.l\\ter0,@-er7\;stc\tccr,r0l\;mov.b\tr0l,@(4,er7)\;mov.l\\t@er7+,er0\;orc\t#128,ccr\";
+  else if (TARGET_H8300S && TARGET_NORMAL_MODE)
+    return \"subs\\t#2,er7\;stc\texr,@-er7\;mov.l\\ter0,@-er7\;stc\tccr,r0l\;mov.b\tr0l,@(6,er7)\;mov.l\\t@er7+,er0\;orc\t#128,ccr\";
   else if (TARGET_H8300S)
     return \"stc\texr,@-er7\;mov.l\\ter0,@-er7\;stc\tccr,r0l\;mov.b\tr0l,@(6,er7)\;mov.l\\t@er7+,er0\;orc\t#128,ccr\";
   gcc_unreachable ();
@@ -6199,3 +6209,5 @@
    && !reg_overlap_mentioned_p (operands[0], operands[2])"
   [(set (match_dup 2)
 	(match_dup 1))])
+	
+
diff -upNr gcc-orig/config/h8300/h8300.opt gcc/config/h8300/h8300.opt
--- gcc-orig/config/h8300/h8300.opt	2007-08-02 16:19:31.000000000 +0530
+++ gcc/config/h8300/h8300.opt	2012-04-03 20:58:19.000000000 +0530
@@ -60,3 +60,12 @@ Enable the normal mode
 malign-300
 Target RejectNegative Mask(ALIGN_300)
 Use H8/300 alignment rules
+
+mexr
+Target Mask(EXR)
+Push extended registers on stack in monitor functions
+
+mno-exr
+Target Mask(NEXR)
+Do not push extended registers on stack in monitor functions
+
diff -upNr gcc-orig/config/h8300/h8300-protos.h gcc/config/h8300/h8300-protos.h
--- gcc-orig/config/h8300/h8300-protos.h	2011-08-03 00:18:00.000000000 +0530
+++ gcc/config/h8300/h8300-protos.h	2012-03-20 13:04:26.000000000 +0530
@@ -96,6 +96,7 @@ extern int h8300_can_use_return_insn_p (
 extern void h8300_expand_prologue (void);
 extern void h8300_expand_epilogue (void);
 extern int h8300_current_function_interrupt_function_p (void);
+extern int h8300_current_function_monitor_function_p (void);
 extern int h8300_initial_elimination_offset (int, int);
 extern int h8300_regs_ok_for_stm (int, rtx[]);
 extern int h8300_hard_regno_rename_ok (unsigned int, unsigned int);
diff -upNr gcc-orig/doc/invoke.texi gcc/doc/invoke.texi
--- gcc-orig/doc/invoke.texi	2012-03-01 15:27:59.000000000 +0530
+++ gcc/doc/invoke.texi	2012-03-20 13:04:26.000000000 +0530
@@ -598,7 +598,7 @@ Objective-C and Objective-C++ Dialects}.
 -tno-android-cc -tno-android-ld}
 
 @emph{H8/300 Options}
-@gccoptlist{-mrelax  -mh  -ms  -mn  -mint32  -malign-300}
+@gccoptlist{-mrelax  -mh  -ms  -mn  -mexr -mno-exr  -mint32  -malign-300}
 
 @emph{HPPA Options}
 @gccoptlist{-march=@var{architecture-type} @gol
@@ -12736,6 +12736,18 @@ must be used either with @option{-mh} or
 @opindex ms2600
 Generate code for the H8S/2600.  This switch must be used with @option{-ms}.
 
+@item -mexr
+@opindex mexr
+Extended registers are stored on stack before execution of function
+with monitor attribute. Default option is @option{-mexr}.
+This option is valid only for H8S targets.
+
+@item -mno-exr
+@opindex mno-exr
+Extended registers are not stored on stack before execution of function 
+with monitor attribute. Default option is @option{-mno-exr}. 
+This option is valid only for H8S targets.
+
 @item -mint32
 @opindex mint32
 Make @code{int} data 32 bits by default.
