avr-libc-dev
[Top][All Lists]
Advanced

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

Re: [avr-libc-dev] make main a normal function


From: Anatoly Sokolov
Subject: Re: [avr-libc-dev] make main a normal function
Date: Sun, 11 Jun 2006 14:13:51 +0400

Hello.

>> 2.) make main a normal function
>>
>> As discussed on the avr-libc-dev list, it is desirable that main() is
>> just
>> an ordinary function like any other. The stack pointer initialization is
>> now only located in the gcrt1.S file of the avr-libc.
>>

This patch make main a normal function and eliminate saving "Call-saved" 
registers in main function.

Index: gcc/config/avr/avr.c
===================================================================
--- gcc/config/avr/avr.c (revision 114540)
+++ gcc/config/avr/avr.c (working copy)
@@ -408,6 +408,7 @@
   int int_or_sig_p = (interrupt_function_p (current_function_decl)
         || signal_function_p (current_function_decl));
   int leaf_func_p = leaf_function_p ();
+  int main_p = MAIN_NAME_P (DECL_NAME (current_function_decl));
 
   if (set)
     CLEAR_HARD_REG_SET (*set);
@@ -417,6 +418,9 @@
   if (TREE_THIS_VOLATILE (current_function_decl))
     return 0;
 
+  if(main_p)
+    return 0;
+
   for (reg = 0; reg < 32; reg++)
     {
       /* Do not push/pop __tmp_reg__, __zero_reg__, as well as
@@ -465,7 +469,6 @@
    && ! interrupt_function_p (current_function_decl)
    && ! signal_function_p (current_function_decl)
    && ! avr_naked_function_p (current_function_decl)
-   && ! MAIN_NAME_P (DECL_NAME (current_function_decl))
    && ! TREE_THIS_VOLATILE (current_function_decl));
 }
 
@@ -655,7 +658,7 @@
   main_p = MAIN_NAME_P (DECL_NAME (current_function_decl));
   live_seq = sequent_regs_live ();
   minimize = (TARGET_CALL_PROLOGUES
-       && !interrupt_func_p && !signal_func_p && live_seq);
+       && !main_p && !interrupt_func_p && !signal_func_p && live_seq);
 
   if (interrupt_func_p)
     {
@@ -672,19 +675,8 @@
         AS1 (clr,__zero_reg__)    "\n");
       prologue_size += 5;
     }
-  if (main_p)
+  if (minimize && (frame_pointer_needed || live_seq > 6)) 
     {
-      fprintf (file, ("\t" 
-        AS1 (ldi,r28) ",lo8(%s - " HOST_WIDE_INT_PRINT_DEC ")" CR_TAB
-        AS1 (ldi,r29) ",hi8(%s - " HOST_WIDE_INT_PRINT_DEC ")" CR_TAB
-        AS2 (out,__SP_H__,r29)     CR_TAB
-        AS2 (out,__SP_L__,r28) "\n"),
-        avr_init_stack, size, avr_init_stack, size);
-      
-      prologue_size += 4;
-    }
-  else if (minimize && (frame_pointer_needed || live_seq > 6)) 
-    {
       fprintf (file, ("\t"
         AS1 (ldi, r26) ",lo8(" HOST_WIDE_INT_PRINT_DEC ")" CR_TAB
         AS1 (ldi, r27) ",hi8(" HOST_WIDE_INT_PRINT_DEC ")" CR_TAB), size, 
size);
@@ -796,25 +788,10 @@
   main_p = MAIN_NAME_P (DECL_NAME (current_function_decl));
   live_seq = sequent_regs_live ();
   minimize = (TARGET_CALL_PROLOGUES
-       && !interrupt_func_p && !signal_func_p && live_seq);
+       && !main_p && !interrupt_func_p && !signal_func_p && live_seq);
   
-  if (main_p)
+  if (minimize && (frame_pointer_needed || live_seq > 4))
     {
-      /* Return value from main() is already in the correct registers
-  (r25:r24) as the exit() argument.  */
-      if (AVR_MEGA)
- {
-   fputs ("\t" AS1 (jmp,exit) "\n", file);
-   epilogue_size += 2;
- }
-      else
- {
-   fputs ("\t" AS1 (rjmp,exit) "\n", file);
-   ++epilogue_size;
- }
-    }
-  else if (minimize && (frame_pointer_needed || live_seq > 4))
-    {
       fprintf (file, ("\t" AS2 (ldi, r30, %d) CR_TAB), live_seq);
       ++epilogue_size;
       if (frame_pointer_needed)


Anatoly.




reply via email to

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