This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH]: Fix push of SP on 68HC12 and conflict between -mlong-callsand interrupt


This patch fixes:

- the push of SP register for 68HC12.  It was written 'sts -2,sp' which means
 (MEM (PLUS SP -2)) but it must be written 'sts 2,-sp' which means
 (MEM (PRE_DEC SP)).  This form is used when comparing the SP with another
 register (X, D, Y) as compare can only compare with memory or immediate.

- an interrupt handler that is compiled with -mlong-calls is marked with asm
  .far which tells the linker to emit a trampoline when the function address
  is taken.  For an interrupt handler, this is wrong and causes a crash when
  it returns.  An interrupt handler must not be put in a banked area anyway.
  This pb is registered in Savannah under
 [bugs #8028] Problem with interrupt handlers and -mlong-calls

Committed on 3_4 and mainline.


2004-03-06 Stephane Carrez <>

	* config/m68hc11/m68hc11.c (m68hc11_gen_movhi): Use 2,-sp to push
	the stack register.
	(expand_prologue): Don't make an interrupt or a trap handler a far
	(m68hc11_initial_elimination_offset): Likewise.

Index: config/m68hc11/m68hc11.c
RCS file: /cvs/gcc/gcc/gcc/config/m68hc11/m68hc11.c,v
retrieving revision
diff -u -p -r1.91.6.3 m68hc11.c
--- config/m68hc11/m68hc11.c	3 Mar 2004 21:44:11 -0000
+++ config/m68hc11/m68hc11.c	7 Mar 2004 09:50:27 -0000
@@ -1401,15 +1401,19 @@ m68hc11_initial_elimination_offset (int 
   /* For a trap handler, we must take into account the registers which
      are pushed on the stack during the trap (except the PC).  */
   func_attr = TYPE_ATTRIBUTES (TREE_TYPE (current_function_decl));
+  current_function_interrupt = lookup_attribute ("interrupt",
+						 func_attr) != NULL_TREE;
+  trap_handler = lookup_attribute ("trap", func_attr) != NULL_TREE;
   if (lookup_attribute ("far", func_attr) != 0)
     current_function_far = 1;
   else if (lookup_attribute ("near", func_attr) != 0)
     current_function_far = 0;
-    current_function_far = TARGET_LONG_CALLS != 0;
+    current_function_far = (TARGET_LONG_CALLS != 0
+                            && !current_function_interrupt
+                            && !trap_handler);
-  trap_handler = lookup_attribute ("trap", func_attr) != NULL_TREE;
   if (trap_handler && from == ARG_POINTER_REGNUM)
     size = 7;
@@ -1689,7 +1693,9 @@ expand_prologue (void)
   else if (lookup_attribute ("near", func_attr) != NULL_TREE)
     current_function_far = 0;
-    current_function_far = TARGET_LONG_CALLS != 0;
+    current_function_far = (TARGET_LONG_CALLS != 0
+                            && !current_function_interrupt
+                            && !current_function_trap);
   /* Get the scratch register to build the frame and push registers.
      If the first argument is a 32-bit quantity, the D+X registers
@@ -3230,7 +3236,7 @@ m68hc11_gen_movhi (rtx insn, rtx *operan
 	      output_asm_insn ("psh%1", operands);
             case HARD_SP_REGNUM:
-              output_asm_insn ("sts\t-2,sp", operands);
+              output_asm_insn ("sts\t2,-sp", operands);
 	      abort ();

Attachment: pgp00000.pgp
Description: PGP signature

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]