Re: [avr-gcc-list] Add 'OS_main' and 'OS_task' attributes in avr-gcc 4.2.1

2008-12-09 Thread Bob Paddock
On Mon, Jul 23, 2007 at 2:48 PM, Anatoly Sokolov [EMAIL PROTECTED] wrote:

 This patch add OS_main and 'OS_task' attributes in GCC 4.2.1. Function with
 OS_main and 'OS_task' attributes do not save any call-saved registers.

I had hoped that using OS_main would get rid of the call to main,
wastes stack space, and all of the dead _exit code, which is not allowed
under some design guidelines (as well as taking space), that will
never be executed, but it doesn't.
Is there an attribute that would?

using 'noreturn' does not work on main, causes:

Main/main.cpp: In function 'int main()':
Main/main.cpp:60: warning: function declared 'noreturn' has a 'return' statement

Removing 'int' from main causes different errors.

Test case:

int main( void ) __attribute__ ((OS_main));
int main( void )
{
 for(;;)
   ;
}

generates the following where main will never return and
_exit will never be executed.

  5a:   02 d0   rcall   .+4 ; 0x60 main
  5c:   02 c0   rjmp.+4 ; 0x62 _exit

005e __bad_interrupt:
  5e:   d0 cf   rjmp.-96; 0x0 __vectors

0060 main:

int main( void )
  60:   ff cf   rjmp.-2 ; 0x60 main

0062 _exit:
  62:   f8 94   cli

0064 __stop_program:
  64:   ff cf   rjmp.-2 ; 0x64 __stop_program


___
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list


Re: [avr-gcc-list] Add 'OS_main' and 'OS_task' attributes in avr-gcc 4.2.1

2008-12-09 Thread Ruud Vlaming
On Tuesday 09 December 2008 14:39, Bob Paddock wrote:

 I had hoped that using OS_main would get rid of the call to main,
 wastes stack space, and all of the dead _exit code, which is not allowed
 under some design guidelines (as well as taking space), that will
 never be executed, but it doesn't.
 Is there an attribute that would?

I am aware of two solutions. 

First, and most rigorous, is writing your own startup code and link with option 
-nostartfiles. Please note this requires that you generate a vector table 
yourself, 
and has other drawbacks. (for example no .data section possible)

Second, and this trick works in some situations:
  http://www.mail-archive.com/avr-gcc-list@nongnu.org/msg02390.html

For me the latter was not reliable enough, so i use the first option most of the
time.  If you exactly know which interrupts to expect, you may even utilize 
part of
the vector table for code.

But the most beautiful would be to have a compiler option like -embedded
or so, which gets rid of all junk. 

I would be more that happy to hear how others solved this.

Below three examples (gcc 4.3.2 with patches):
1) Standard compile
2) Overwriting __methodes (Bjoern's trick)
3) with -nostartfiles + custom startup code
Note that, since the data section was empty in this example the
whole data copy loop is wasted space two.

Btw, if you compile with -Wno-main then you can use:
void main(void) __attribute__ (( OS_main ))
which reduces code somewhat more


1) Standard compile === 

 __vectors:
   0:   12 c0   rjmp.+36; 0x26 __ctors_end
   2:   2c c0   rjmp.+88; 0x5c __bad_interrupt
   4:   2b c0   rjmp.+86; 0x5c __bad_interrupt
   6:   2a c0   rjmp.+84; 0x5c __bad_interrupt
   8:   29 c0   rjmp.+82; 0x5c __bad_interrupt
   a:   28 c0   rjmp.+80; 0x5c __bad_interrupt
   c:   27 c0   rjmp.+78; 0x5c __bad_interrupt
   e:   26 c0   rjmp.+76; 0x5c __bad_interrupt
  10:   25 c0   rjmp.+74; 0x5c __bad_interrupt
  12:   24 c0   rjmp.+72; 0x5c __bad_interrupt
  14:   23 c0   rjmp.+70; 0x5c __bad_interrupt
  16:   22 c0   rjmp.+68; 0x5c __bad_interrupt
  18:   21 c0   rjmp.+66; 0x5c __bad_interrupt
  1a:   20 c0   rjmp.+64; 0x5c __bad_interrupt
  1c:   df c0   rjmp.+446   ; 0x1dc __vector_14
  1e:   1e c0   rjmp.+60; 0x5c __bad_interrupt
  20:   1d c0   rjmp.+58; 0x5c __bad_interrupt
  22:   1c c0   rjmp.+56; 0x5c __bad_interrupt
  24:   1b c0   rjmp.+54; 0x5c __bad_interrupt

0026 __ctors_end:
  26:   11 24   eor r1, r1
  28:   1f be   out 0x3f, r1; 63
  2a:   cf e6   ldi r28, 0x6F   ; 111
  2c:   d0 e0   ldi r29, 0x00   ; 0
  2e:   de bf   out 0x3e, r29   ; 62
  30:   cd bf   out 0x3d, r28   ; 61

0032 __do_copy_data:
  32:   10 e0   ldi r17, 0x00   ; 0
  34:   a0 e6   ldi r26, 0x60   ; 96
  36:   b0 e0   ldi r27, 0x00   ; 0
  38:   e8 e3   ldi r30, 0x38   ; 56
  3a:   f2 e0   ldi r31, 0x02   ; 2
  3c:   02 c0   rjmp.+4 ; 0x42 .do_copy_data_start

003e .do_copy_data_loop:
  3e:   05 90   lpm r0, Z+
  40:   0d 92   st  X+, r0

0042 .do_copy_data_start:
  42:   a0 36   cpi r26, 0x60   ; 96
  44:   b1 07   cpc r27, r17
  46:   d9 f7   brne.-10; 0x3e __SP_H__

0048 __do_clear_bss:
  48:   10 e0   ldi r17, 0x00   ; 0
  4a:   a0 e6   ldi r26, 0x60   ; 96
  4c:   b0 e0   ldi r27, 0x00   ; 0
  4e:   01 c0   rjmp.+2 ; 0x52 .do_clear_bss_start

0050 .do_clear_bss_loop:
  50:   1d 92   st  X+, r1

0052 .do_clear_bss_start:
  52:   a3 37   cpi r26, 0x73   ; 115
  54:   b1 07   cpc r27, r17
  56:   e1 f7   brne.-8 ; 0x50 .do_clear_bss_loop
  58:   5c d0   rcall   .+184   ; 0x112 main
  5a:   ec c0   rjmp.+472   ; 0x234 _exit

0112 main:
 112:   0a d0   rcall   .+20; 0x128 portInit
 

0234 _exit:
 234:   f8 94   cli

0236 __stop_program:
 236:   ff cf   rjmp.-2 ; 0x236 __stop_program

 
2) Overwriting __methodes (Bjoern's trick) 

 __vectors:
   0:   12 c0   rjmp.+36; 0x26 __ctors_end
   2:   26 c0   rjmp.+76; 0x50 __bad_interrupt
   4:   25 

Re: [avr-gcc-list] Add 'OS_main' and 'OS_task' attributes in avr-gcc 4.2.1

2007-07-23 Thread Erik Christiansen
On Tue, Jul 24, 2007 at 02:21:10PM +1100, Dmitry K. wrote:
 [...]
  begin 666 gcc-4.2.1-os_main_os_task.txt
  [EMAIL PROTECTED](=C8R]C;VYF:6O879R+V%VBYCCT]/3T]/3T]/3T]/3T]/3T]
 [...]

 Possible, my mail program is too old.
 How to decode this patch?

Dmitry,

Too new maybe. ;-)

That looks rather like a uuencoded file. Try using uudecode, which
should still be included in whatever linux distro you're using. It's a
looong time since we used that regularly!

Erik


___
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list