aboutsummaryrefslogtreecommitdiff
path: root/devel/avr-gcc/files/patch-xx-os_main
blob: 8b69a3c18c690bb9df09e26633d6d7d8b9b20717 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
--- ./gcc/config/avr/avr.c.orig	2010-03-05 18:01:20.000000000 +0100
+++ ./gcc/config/avr/avr.c	2010-03-05 18:01:51.000000000 +0100
@@ -57,6 +57,7 @@
 static int signal_function_p (tree);
 static int nmi_function_p (tree);
 static int avr_OS_task_function_p (tree);
+static int avr_OS_main_function_p (tree);
 static int avr_regs_to_save (HARD_REG_SET *);
 static int sequent_regs_live (void);
 static const char *ptrreg_to_str (int);
@@ -603,6 +604,19 @@
   return a != NULL_TREE;
 }
 
+/* Return nonzero if FUNC is a OS_main function.  */
+
+static int
+avr_OS_main_function_p (tree func)
+{
+  tree a;
+
+  gcc_assert (TREE_CODE (func) == FUNCTION_DECL);
+  
+  a = lookup_attribute ("OS_main", TYPE_ATTRIBUTES (TREE_TYPE (func)));
+  return a != NULL_TREE;
+}
+
 /* Return the number of hard registers to push/pop in the prologue/epilogue
    of the current function, and optionally store these registers in SET.  */
 
@@ -621,9 +635,10 @@
   count = 0;
 
   /* No need to save any registers if the function never returns or 
-     is have "OS_task" attribute.  */
+     is have "OS_task" or "OS_main" attribute.  */
   if (TREE_THIS_VOLATILE (current_function_decl)
-      || cfun->machine->is_OS_task)
+      || cfun->machine->is_OS_task
+      || cfun->machine->is_OS_main)
     return 0;
 
   for (reg = 0; reg < 32; reg++)
@@ -742,6 +757,8 @@
   rtx pushword = gen_rtx_MEM (HImode,
                   gen_rtx_POST_DEC (HImode, stack_pointer_rtx));
   rtx insn;
+  int method1_length;
+  int sp_plus_length;
 
   last_insn_address = 0;
   
@@ -751,6 +768,7 @@
   cfun->machine->is_signal = signal_function_p (current_function_decl);
   cfun->machine->is_nmi = nmi_function_p (current_function_decl);
   cfun->machine->is_OS_task = avr_OS_task_function_p (current_function_decl);
+  cfun->machine->is_OS_main = avr_OS_main_function_p (current_function_decl);
   
   /* Prologue: naked.  */
   if (cfun->machine->is_naked)
@@ -764,6 +782,7 @@
 	      && !cfun->machine->is_interrupt
 	      && !cfun->machine->is_signal
 	      && !cfun->machine->is_OS_task
+	      && !cfun->machine->is_OS_main
 	      && live_seq);
 
   if (cfun->machine->is_interrupt || cfun->machine->is_signal)
@@ -903,7 +922,7 @@
         }
       if (frame_pointer_needed)
         {
-	  if(!cfun->machine->is_OS_task)
+	  if (!(cfun->machine->is_OS_task || cfun->machine->is_OS_main))
 	    {
               /* Push frame pointer.  */
 	      insn = emit_move_insn (pushword, frame_pointer_rtx);
@@ -933,7 +952,7 @@
               if (TARGET_TINY_STACK)
                 {
                   if (size < -63 || size > 63)
-                    warning (0, "large frame pointer change (%d) with -mtiny-stack", size);
+                    warning (0, "large frame pointer change (%ld) with -mtiny-stack", size);
                     
                   /* The high byte (r29) doesn't change - prefer 'subi' (1 cycle)
                      over 'sbiw' (2 cycles, same size).  */
@@ -945,7 +964,6 @@
                   myfp = frame_pointer_rtx;
                 }
               /* Calculate length.  */ 
-              int method1_length;
               method1_length =
 	        get_attr_length (gen_move_insn (frame_pointer_rtx, stack_pointer_rtx));
               method1_length +=
@@ -1043,6 +1061,7 @@
   HARD_REG_SET set;      
   int minimize;
   HOST_WIDE_INT size = get_frame_size();
+  int sp_plus_length;
   
   /* epilogue: naked  */
   if (cfun->machine->is_naked)
@@ -1057,6 +1076,7 @@
 	      && !cfun->machine->is_interrupt
 	      && !cfun->machine->is_signal
 	      && !cfun->machine->is_OS_task
+	      && !cfun->machine->is_OS_main
 	      && live_seq);
   
   if (minimize && (frame_pointer_needed || live_seq > 4))
@@ -1119,7 +1139,7 @@
                   emit_move_insn (stack_pointer_rtx, frame_pointer_rtx);
                 }
             }
-	  if(!cfun->machine->is_OS_task)
+	  if (!(cfun->machine->is_OS_task || cfun->machine->is_OS_main))
 	    {
               /* Restore previous frame_pointer.  */
 	      emit_insn (gen_pophi (frame_pointer_rtx));
@@ -1939,10 +1959,18 @@
 		}
               /*  Use simple load of stack pointer if no interrupts are used
               or inside main or signal function prologue where they disabled.  */
-	      else if (TARGET_NO_INTERRUPTS
+              else if ((!AVR_XMEGA && TARGET_NO_INTERRUPTS)
                         || (!AVR_XMEGA
-			    && reload_completed 
+                            && reload_completed 
                             && cfun->machine->is_signal 
+                            && prologue_epilogue_contains (insn))
+                        || (!AVR_XMEGA
+                            && reload_completed 
+                            && cfun->machine->is_OS_main 
+                            && prologue_contains (insn))
+                        || (AVR_XMEGA
+                            && reload_completed 
+                            && cfun->machine->is_nmi 
                             && prologue_epilogue_contains (insn)))
                 {
                   *l = 2;
@@ -4969,6 +4997,7 @@
   { "nmi",       0, 0, true,  false, false,  avr_handle_fndecl_attribute },
   { "naked",     0, 0, false, true,  true,   avr_handle_fntype_attribute },
   { "OS_task",   0, 0, false, true,  true,   avr_handle_fntype_attribute },
+  { "OS_main",   0, 0, false, true,  true,   avr_handle_fntype_attribute },
   { NULL,        0, 0, false, false, false, NULL }
 };
 
--- ./gcc/config/avr/avr.h.orig	2010-03-05 18:01:20.000000000 +0100
+++ ./gcc/config/avr/avr.h	2010-03-05 18:01:51.000000000 +0100
@@ -1320,4 +1320,8 @@
   /* 'true' - if current function is a task function 
      as specified by the "OS_task" attribute.  */
   int is_OS_task;
+
+  /* 'true' - if current function is a 'main' function 
+     as specified by the "OS_main" attribute.  */
+  int is_OS_main;
 };
--- ./gcc/function.c.orig	2009-06-19 23:44:24.000000000 +0200
+++ ./gcc/function.c	2010-03-05 18:01:51.000000000 +0100
@@ -4757,6 +4757,14 @@
 }
 
 int
+prologue_contains (const_rtx insn)
+{
+  if (contains (insn, &prologue))
+    return 1;
+  return 0;
+}
+
+int
 prologue_epilogue_contains (const_rtx insn)
 {
   if (contains (insn, &prologue))
--- ./gcc/rtl.h.orig	2009-07-14 11:32:55.000000000 +0200
+++ ./gcc/rtl.h	2010-03-05 18:01:51.000000000 +0100
@@ -2145,6 +2145,7 @@
 
 /* In function.c */
 extern void reposition_prologue_and_epilogue_notes (void);
+extern int prologue_contains (const_rtx);
 extern int prologue_epilogue_contains (const_rtx);
 extern int sibcall_epilogue_contains (const_rtx);
 extern void mark_temp_addr_taken (rtx);