avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[avr-gcc-list] RFC: patch for "signal" functions similar to msp430-gcc


From: Marek Michalkiewicz
Subject: [avr-gcc-list] RFC: patch for "signal" functions similar to msp430-gcc
Date: Mon, 12 Sep 2005 00:48:50 +0200
User-agent: Mutt/1.5.9i

Hello,

see below for a proof of concept patch for mainline (not yet committed).

The "signal" attribute ("interrupt" not implemented - deprecated...)
now takes an optional numeric argument, interrupt number 1...N.
With this number specified, the function may have any name you want,
this name (not __vector_NN) appears in "avr-objdump -d" output, and
the jump in the interrupt vector table still points to this function.
Without it, function must be named __vector_NN as before - GCC with
this patch remains backwards-compatible with current avr-libc.

As mentioned previously, we don't follow msp430-gcc exactly, because
of reversed signal/interrupt meanings.  May be better to invent a new
name for this attribute, and later deprecate signal/interrupt.

To do: perhaps add some kind of sanity check on the specified number,
warn if it is out of range for the MCU?

Known bug in this patch: gcc crashes (tree check, integer_cst expected)
if the argument is not a number (but an identifier, string etc.).
This needs to be checked too.  Will fix later - going to sleep now...

Thanks,
Marek

Index: avr-protos.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/avr/avr-protos.h,v
retrieving revision 1.34
diff -c -3 -p -r1.34 avr-protos.h
*** avr-protos.h        25 Jun 2005 01:20:56 -0000      1.34
--- avr-protos.h        11 Sep 2005 22:03:43 -0000
*************** extern void gas_output_ascii (FILE *file
*** 43,48 ****
--- 43,49 ----
  #ifdef TREE_CODE
  extern void asm_output_external (FILE *file, tree decl, char *name);
  extern int avr_progmem_p (tree decl, tree attributes);
+ extern void avr_declare_function_name (FILE *file, const char *name, tree 
decl);
  
  #ifdef RTX_CODE /* inside TREE_CODE */
  extern rtx avr_function_value (tree type, tree func);
Index: avr.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/avr/avr.c,v
retrieving revision 1.141
diff -c -3 -p -r1.141 avr.c
*** avr.c       27 Jul 2005 22:29:46 -0000      1.141
--- avr.c       11 Sep 2005 22:03:46 -0000
*************** signal_function_p (tree func)
*** 393,398 ****
--- 393,426 ----
    return a != NULL_TREE;
  }
  
+ void
+ avr_declare_function_name (FILE *file, const char *name, tree decl)
+ {
+   tree a = NULL_TREE;
+   int vector = -1;
+ 
+   if (TREE_CODE (decl) == FUNCTION_DECL)
+     a = lookup_attribute ("signal", DECL_ATTRIBUTES (decl));
+ 
+   if (a)
+     a = TREE_VALUE (a);
+ 
+   if (a)
+     a = TREE_VALUE (a);
+ 
+   if (a)
+     vector = TREE_INT_CST_LOW (a);
+ 
+   ASM_OUTPUT_TYPE_DIRECTIVE (file, name, "function");
+   ASM_OUTPUT_LABEL (file, name);
+ 
+   if (vector != -1)
+     {
+       fprintf (file, ".global __vector_%d\n", vector);
+       fprintf (file, "__vector_%d:\n", vector);
+     }
+ }
+ 
  /* Return the number of hard registers to push/pop in the prologue/epilogue
     of the current function, and optionally store these registers in SET.  */
  
*************** const struct attribute_spec avr_attribut
*** 4613,4619 ****
  {
    /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
    { "progmem",   0, 0, false, false, false,  avr_handle_progmem_attribute },
!   { "signal",    0, 0, true,  false, false,  avr_handle_fndecl_attribute },
    { "interrupt", 0, 0, true,  false, false,  avr_handle_fndecl_attribute },
    { "naked",     0, 0, true,  false, false,  avr_handle_fndecl_attribute },
    { NULL,        0, 0, false, false, false, NULL }
--- 4641,4647 ----
  {
    /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
    { "progmem",   0, 0, false, false, false,  avr_handle_progmem_attribute },
!   { "signal",    0, 1, true,  false, false,  avr_handle_fndecl_attribute },
    { "interrupt", 0, 0, true,  false, false,  avr_handle_fndecl_attribute },
    { "naked",     0, 0, true,  false, false,  avr_handle_fndecl_attribute },
    { NULL,        0, 0, false, false, false, NULL }
*************** avr_handle_progmem_attribute (tree *node
*** 4667,4673 ****
  
  static tree
  avr_handle_fndecl_attribute (tree *node, tree name,
!                            tree args ATTRIBUTE_UNUSED,
                             int flags ATTRIBUTE_UNUSED,
                             bool *no_add_attrs)
  {
--- 4695,4701 ----
  
  static tree
  avr_handle_fndecl_attribute (tree *node, tree name,
!                            tree args,
                             int flags ATTRIBUTE_UNUSED,
                             bool *no_add_attrs)
  {
*************** avr_handle_fndecl_attribute (tree *node,
*** 4677,4683 ****
               IDENTIFIER_POINTER (name));
        *no_add_attrs = true;
      }
!   else
      {
        const char *func_name = IDENTIFIER_POINTER (DECL_NAME (*node));
        const char *attr = IDENTIFIER_POINTER (name);
--- 4705,4711 ----
               IDENTIFIER_POINTER (name));
        *no_add_attrs = true;
      }
!   else if (args == NULL_TREE)
      {
        const char *func_name = IDENTIFIER_POINTER (DECL_NAME (*node));
        const char *attr = IDENTIFIER_POINTER (name);
Index: avr.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/avr/avr.h,v
retrieving revision 1.115
diff -c -3 -p -r1.115 avr.h
*** avr.h       25 Jun 2005 01:20:56 -0000      1.115
--- avr.h       11 Sep 2005 22:03:47 -0000
*************** do {                                                            
        \
*** 551,560 ****
     specific tm.h file (depending upon the particulars of your assembler).  */
  
  #define ASM_DECLARE_FUNCTION_NAME(FILE, NAME, DECL)           \
! do {                                                          \
!      ASM_OUTPUT_TYPE_DIRECTIVE (FILE, NAME, "function");      \
!      ASM_OUTPUT_LABEL (FILE, NAME);                           \
! } while (0)
  
  #define ASM_DECLARE_FUNCTION_SIZE(FILE, FNAME, DECL)                  \
    do {                                                                        
\
--- 551,557 ----
     specific tm.h file (depending upon the particulars of your assembler).  */
  
  #define ASM_DECLARE_FUNCTION_NAME(FILE, NAME, DECL)           \
!   avr_declare_function_name (FILE, NAME, DECL)
  
  #define ASM_DECLARE_FUNCTION_SIZE(FILE, FNAME, DECL)                  \
    do {                                                                        
\





reply via email to

[Prev in Thread] Current Thread [Next in Thread]