--- ./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);