[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [avr-libc-dev] [bug #19050] gcrt1.S should call main rather thanjump
From: |
Björn Haase |
Subject: |
Re: [avr-libc-dev] [bug #19050] gcrt1.S should call main rather thanjumping to it |
Date: |
Tue, 13 Feb 2007 23:22:59 +0100 |
User-agent: |
KMail/1.7.1 |
I agree with Anatoly partly. I think the best way is:
1.) Let make gcrt.s set the stack pointer instead of the old version where
main() did it. We need it for c++ global static constructor functions. They
will be called before main! So we need stack pointer setup in gcrt.s. The
second stack pointer setup in main() is not necessary.
2.) Make it possible that main is a special function so that it does not use
unnecessary space.
If 2) happens not to be compliant with gcc philosophy, one could add a
-mmain-function-uncallable switch that implements 2). However, already today
main() must not be called from outside, since it overwrites the stack
pointer. The solution above would therefore not turn the solution less C
standard confrom than today's solution.
Greetings and keep on doing the good things.
Björn.
P.S.: Maybe somebody is in Nurenberg tomorrow?
Anatoly Sokolov wrote on Dienstag, 13. Februar 2007 22:11 :
> Hello.
>
> Let's consider the worst variant:
>
> demo.c
> -----
> void foo(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8,
> int a9 )
> {
> }
>
> int main()
> {
> int i;
>
> foo(0x0201, 0x0202, 0x0203, 0x0204, 0x0205, 0x0206, 0x0207, 0x0208 ,
> 0x0209);
> return 0;
> }
> -----
>
> 1. In GCC 4.3 main look so:
>
> int main()
> {
> 100: cd e5 ldi r28, 0x5D ; 93
> 102: d8 e0 ldi r29, 0x08 ; 8
> 104: de bf out 0x3e, r29 ; 62
> 106: cd bf out 0x3d, r28 ; 61
> int i;
>
> foo(0x0201, 0x0202, 0x0203, 0x0204, 0x0205, 0x0206, 0x0207, 0x0208 ,
> 0x0209);
> 108: 0f 2e mov r0, r31
> ......
> 14a: 92 e0 ldi r25, 0x02 ; 2
> 14c: 0e 94 47 00 call 0x8e ; 0x8e <foo>
> return 0;
> 150: 80 e0 ldi r24, 0x00 ; 0
> 152: 90 e0 ldi r25, 0x00 ; 0
> 154: 0c 94 ac 00 jmp 0x158 ; 0x158 <_exit>
>
> 00000158 <_exit>:
> 158: ff cf rjmp .-2 ; 0x158 <_exit>
>
> 5 instructions in prologue/epilogue, 0 ( 2 for 'i' ) RAM bytes used.
>
> 2. main() as normal function:
>
> int main()
> {
> 100: 8f 92 push r8
> 102: 9f 92 push r9
> 104: af 92 push r10
> 106: bf 92 push r11
> 108: cf 92 push r12
> 10a: df 92 push r13
> 10c: ef 92 push r14
> 10e: ff 92 push r15
> 110: 0f 93 push r16
> 112: 1f 93 push r17
> 114: cf 93 push r28
> 116: df 93 push r29
> 118: cd b7 in r28, 0x3d ; 61
> 11a: de b7 in r29, 0x3e ; 62
> 11c: 22 97 sbiw r28, 0x02 ; 2
> 11e: 0f b6 in r0, 0x3f ; 63
> 120: f8 94 cli
> 122: de bf out 0x3e, r29 ; 62
> 124: 0f be out 0x3f, r0 ; 63
> 126: cd bf out 0x3d, r28 ; 61
> int i;
>
> foo(0x0201, 0x0202, 0x0203, 0x0204, 0x0205, 0x0206, 0x0207, 0x0208 ,
> 0x0209);
> 128: 0f 2e mov r0, r31
> .....
> 16c: 0e 94 47 00 call 0x8e ; 0x8e <foo>
> return 0;
> 170: 80 e0 ldi r24, 0x00 ; 0
> 172: 90 e0 ldi r25, 0x00 ; 0
> 174: 22 96 adiw r28, 0x02 ; 2
> 176: 0f b6 in r0, 0x3f ; 63
> 178: f8 94 cli
> 17a: de bf out 0x3e, r29 ; 62
> 17c: 0f be out 0x3f, r0 ; 63
> 17e: cd bf out 0x3d, r28 ; 61
> 180: df 91 pop r29
> 182: cf 91 pop r28
> 184: 1f 91 pop r17
> 186: 0f 91 pop r16
> 188: ff 90 pop r15
> 18a: ef 90 pop r14
> 18c: df 90 pop r13
> 18e: cf 90 pop r12
> 190: bf 90 pop r11
> 192: af 90 pop r10
> 194: 9f 90 pop r9
> 196: 8f 90 pop r8
> 198: 08 95 ret
>
> 39 instructions in prologue/epilogue, 12( +2 for 'i') RAM bytes used.
>
> I would prefer to correspond to 'C' standard completely, but we are ready
> to pay such price, for that that function 'main()' to be callable?
>
> Anatoly.
>
>
>
>
> _______________________________________________
> AVR-libc-dev mailing list
> address@hidden
> http://lists.nongnu.org/mailman/listinfo/avr-libc-dev
- [avr-libc-dev] [bug #19050] gcrt1.S should call main rather than jumping to it, Joerg Wunsch, 2007/02/13
- [avr-libc-dev] [bug #19050] gcrt1.S should call main rather than jumping to it, Joerg Wunsch, 2007/02/13
- [avr-libc-dev] [bug #19050] gcrt1.S should call main rather than jumping to it, Anatoly Sokolov, 2007/02/13
- RE: [avr-libc-dev] [bug #19050] gcrt1.S should call main rather thanjumping to it, Eric Weddington, 2007/02/13
- Re: [avr-libc-dev] [bug #19050] gcrt1.S should call main rather thanjumping to it, Anatoly Sokolov, 2007/02/13
- RE: [avr-libc-dev] [bug #19050] gcrt1.S should call main rather thanjumping to it, Eric Weddington, 2007/02/13
- Re: [avr-libc-dev] [bug #19050] gcrt1.S should call main rather thanjumping to it, Joerg Wunsch, 2007/02/13
- RE: [avr-libc-dev] [bug #19050] gcrt1.S should call main rather thanjumping to it, Eric Weddington, 2007/02/13
- Re: [avr-libc-dev] [bug #19050] gcrt1.S should call main rather thanjumping to it, Anatoly Sokolov, 2007/02/13
- Re: [avr-libc-dev] [bug #19050] gcrt1.S should call main rather thanjumping to it,
Björn Haase <=
- Re: [avr-libc-dev] [bug #19050] gcrt1.S should call main rather thanjumping to it, Joerg Wunsch, 2007/02/13
- RE: [avr-libc-dev] [bug #19050] gcrt1.S should call main ratherthanjumping to it, Eric Weddington, 2007/02/13
- Re: [avr-libc-dev] [bug #19050] gcrt1.S should call main ratherthanjumping to it, Joerg Wunsch, 2007/02/13
- Re: [avr-libc-dev] [bug #19050] gcrt1.S should call main rather thanjumping to it, Bob Paddock, 2007/02/13
- Re: [avr-libc-dev] [bug #19050] gcrt1.S should call main rather thanjumping to it, Alexey Boyko, 2007/02/14
- Re: [avr-libc-dev] [bug #19050] gcrt1.S should call main rather thanjumping to it, Marek Michalkiewicz, 2007/02/13
- Re: [avr-libc-dev] [bug #19050] gcrt1.S should call main rather thanjumping to it, Björn Haase, 2007/02/13
- RE: [avr-libc-dev] [bug #19050] gcrt1.S should call main ratherthanjumping to it, Eric Weddington, 2007/02/13
- Re: [avr-libc-dev] [bug #19050] gcrt1.S should call main ratherthanjumping to it, Marek Michalkiewicz, 2007/02/13
- Re: [avr-libc-dev] [bug #19050] gcrt1.S should call main ratherthanjumping to it, David Brown, 2007/02/14