[Unreviewed PATCH] h8300 #pragma interrupt works only for first ISR with -O3

Dhananjay R. Deshpande dhananjayd@kpit.com
Fri Jun 14 07:06:00 GMT 2002


Hi,
If there are multiple functions in one file with #pragma interrupt, then with optimization level -O3, only first function is compiled as interrupt function and rest all are compiled as normal functions. 

If __attribute__((interrupt_handler)) is used instead of #pragma interrupt then it works fine.

Try compiling following code with h8300-hms-gcc -S -O3 ( gcc-3.1 )

extern int iTemp ;

#pragma interrupt
void  isr1(void)
{
 iTemp = 0x3732 ;
}
#pragma interrupt
void  isr2(void)
{
 iTemp = 0x3632 ;
}

Assembly output - 

; GCC For the Hitachi H8/300
; By Hitachi America Ltd and Cygnus Support
; -O3

 .file "isr.c"
 .section .text
 .align 1
 .global _isr1
_isr1:
     push r6
     mov.w r7,r6
     push r0
     push r2
     mov.w #14130,r0
     mov.w r0,@_iTemp
     pop r2
     pop r0
     pop r6
     rte
     .align 1
     .global _isr2
_isr2:    
     push r6                            
     mov.w r7,r6
     mov.w #13874,r0     -----> Register R0 is not saved.
     mov.w r0,@_iTemp
     pop r6
     rts                 -----> rts instead of rte
     .end
     .ident
"GCC: (GNU) 3.1"

If -fno-inline is specified along with -o3, then it works fine.

All #pragma interrupt get processed before code generation and the variable pragma_interrupt gets cleared at first function epilogue output. So next interrupt function is treated as normal function.

Following patch fixes this problem.

h8300.c: Define TARGET_INSERT_ATTRIBUTES
         h8300_insert_attributes() New. Insert interrupt_handler 			   attribute if #pragma interrupt is seen.

===========================================================================
--- h8300.c.orig Fri Jun 14 14:22:48 2002
+++ h8300.c Fri Jun 14 15:36:02 2002
@@ -60,6 +60,7 @@
 static tree h8300_handle_tiny_data_attribute PARAMS ((tree *, tree, tree, int, bool *));
 static void h8300_output_function_prologue PARAMS ((FILE *, HOST_WIDE_INT));
 static void h8300_output_function_epilogue PARAMS ((FILE *, HOST_WIDE_INT));
+static void h8300_insert_attributes PARAMS ((tree, tree *));
 #ifndef OBJECT_FORMAT_ELF
 static void h8300_asm_named_section PARAMS ((const char *, unsigned int));
 #endif
@@ -111,6 +112,9 @@
 #undef TARGET_ASM_FUNCTION_EPILOGUE
 #define TARGET_ASM_FUNCTION_EPILOGUE h8300_output_function_epilogue
 
+#undef TARGET_INSERT_ATTRIBUTES
+#define TARGET_INSERT_ATTRIBUTES h8300_insert_attributes
+
 struct gcc_target targetm = TARGET_INITIALIZER;
 

 /* Initialize various cpu specific globals at start up.  */
@@ -3088,6 +3092,27 @@
 
   a = lookup_attribute ("tiny_data", DECL_ATTRIBUTES (decl));
   return a != NULL_TREE;
+}
+
+/* Generate 'handle_interrupt' attribute for decls */
+
+static void
+h8300_insert_attributes (node, attributes)
+     tree node;
+     tree * attributes;
+{
+  if (! interrupt_handler
+      || TREE_CODE (node) != FUNCTION_DECL)
+    return;
+
+  /* We are only interested in fields.  */
+  if (TREE_CODE_CLASS (TREE_CODE (node)) != 'd')
+    return;
+
+  /* Add a 'interrupt_handler' attribute.  */
+  * attributes = tree_cons (get_identifier ("interrupt_handler"), NULL, * attributes);
+
+  return;
 }
 
 /* Supported attributes:

===========================================================================
Assembly output after applying patch - 

;	GCC For the Hitachi H8/300
;	By Hitachi America Ltd and Cygnus Support
; -O3


	.file	"isr.c"
	.section .text
	.align 1
	.global _isr1
_isr1:
	push	r6
	mov.w	r7,r6
	push	r0
	push	r2
	mov.w	#14130,r0
	mov.w	r0,@_iTemp
	pop	r2
	pop	r0
	pop	r6
	rte
	.align 1
	.global _isr2
_isr2:
	push	r6
	mov.w	r7,r6
	push	r0
	push	r2
	mov.w	#13874,r0
	mov.w	r0,@_iTemp
	pop	r2
	pop	r0
	pop	r6
	rte
	.end
	.ident
"GCC: (GNU) 3.1"

As seen now both interrupt functions are correct.

Regards,
Dhananjay

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Free download of GNUSH and GNUH8 tool chains for Hitachi's SH and H8 Series.
The following site also offers free support to European customers.
Read more at http://www.kpit.com/products/support.htm
Latest versions of GNUSH and GNUH8 are released on Apr 1, 2002.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 



More information about the Gcc-bugs mailing list