avr-gcc-list
[Top][All Lists]
Advanced

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

[avr-gcc-list] avr-gcc code generation and initialization of the return


From: Torleif Sandnes
Subject: [avr-gcc-list] avr-gcc code generation and initialization of the return stack
Date: Wed, 05 May 2004 16:13:47 +0200
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.5b) Gecko/20030901 Thunderbird/0.2

Hi.

While adding debug support for avr-gcc elf/dwarf object files in AVR Studio, we have come upon a problem with some of the code generated by avr-gcc.

Quoting an e-mail from my colleague Svenn-Ivar:

It seems like the main function does an re-initialization of the return
stack (SPL/SPH). Actually, the new JTAGICE mkII expects the stack pointer
not to be modified this way apart from in the system startup-code, or the
single-stepping mechanisms wont work. The avr-gcc does set up the stack
properly in the startup-code, so I dont clearly see why it's done over again
in 'main'.

Do any of you know why the stack is reinitialized this way?
Can gcc's code egeneration be changed to not reinitialize the return stack?


Regards,

Torleif Sandnes


Here is a partial disassembly of an object file that illustrates the issue:
---------------------------------------------------------------------------
+00000000:   940C002E    JMP     0x0000002E       Jump
+00000002:   940C0049    JMP     0x00000049       Jump
+00000004:   940C0049    JMP     0x00000049       Jump
+00000006:   940C0049    JMP     0x00000049       Jump
+00000008:   940C0049    JMP     0x00000049       Jump
+0000000A:   940C0049    JMP     0x00000049       Jump
+0000000C:   940C0049    JMP     0x00000049       Jump
+0000000E:   940C0049    JMP     0x00000049       Jump
+00000010:   940C0049    JMP     0x00000049       Jump
+00000012:   940C0049    JMP     0x00000049       Jump
+00000014:   940C0049    JMP     0x00000049       Jump
+00000016:   940C0049    JMP     0x00000049       Jump
+00000018:   940C0049    JMP     0x00000049       Jump
+0000001A:   940C0049    JMP     0x00000049       Jump
+0000001C:   940C0049    JMP     0x00000049       Jump
+0000001E:   940C0049    JMP     0x00000049       Jump
+00000020:   940C0049    JMP     0x00000049       Jump
+00000022:   940C0049    JMP     0x00000049       Jump
+00000024:   940C0049    JMP     0x00000049       Jump
+00000026:   940C0049    JMP     0x00000049       Jump
+00000028:   940C0049    JMP     0x00000049       Jump
+0000002A:   940C0049    JMP     0x00000049       Jump
+0000002C:   940C0049    JMP     0x00000049       Jump
+0000002E:   2411        CLR     R1               Exclusive OR
+0000002F:   BE1F        OUT     0x3F,R1          Out to I/O location

+00000030:   EFCF        SER     R28              Load immediate
+00000031:   E0D4        LDI     R29,0x04         Load immediate
+00000032:   BFDE        OUT     0x3E,R29         Out to I/O location
+00000033:   BFCD        OUT     0x3D,R28         Out to I/O location
The previous four instructions set up the return stack for the first time


+00000034:   E011        LDI     R17,0x01         Load immediate
+00000035:   E0A0        LDI     R26,0x00         Load immediate
+00000036:   E0B1        LDI     R27,0x01         Load immediate
+00000037:   EFE4        LDI     R30,0xF4         Load immediate
+00000038:   E0F0        LDI     R31,0x00         Load immediate
+00000039:   C002        RJMP    +0x0002          Relative jump
+0000003A: 9005 LPM R0,Z+ Load program memory and postincrement
+0000003B:   920D        ST      X+,R0            Store indirect and 
postincrement
+0000003C:   30A0        CPI     R26,0x00         Compare with immediate
+0000003D:   07B1        CPC     R27,R17          Compare with carry
+0000003E:   F7D9        BRNE    -0x05            Branch if not equal
+0000003F:   E011        LDI     R17,0x01         Load immediate
+00000040:   E0A0        LDI     R26,0x00         Load immediate
+00000041:   E0B1        LDI     R27,0x01         Load immediate
+00000042:   C001        RJMP    +0x0001          Relative jump
+00000043:   921D        ST      X+,R1            Store indirect and 
postincrement
+00000044:   30A0        CPI     R26,0x00         Compare with immediate
+00000045:   07B1        CPC     R27,R17          Compare with carry
+00000046:   F7E1        BRNE    -0x04            Branch if not equal
+00000047:   940C0066    JMP     0x00000066       Jump
+00000049:   940C0000    JMP     0x00000000       Jump
@0000004B: delay
17:       {
+0000004B:   93CF        PUSH    R28              Push register on stack
+0000004C:   93DF        PUSH    R29              Push register on stack
+0000004D:   B7CD        IN      R28,0x3D         In from I/O location
+0000004E:   B7DE        IN      R29,0x3E         In from I/O location
+0000004F:   9722        SBIW    R28,0x02         Subtract immediate from word
+00000050:   B60F        IN      R0,0x3F          In from I/O location
+00000051:   94F8        CLI                      Flag clear
+00000052:   BFDE        OUT     0x3E,R29         Out to I/O location
+00000053:   BE0F        OUT     0x3F,R0          Out to I/O location
+00000054:   BFCD        OUT     0x3D,R28         Out to I/O location
19:           while(++i); // sleep until i wraps
+00000055:   8189        LDD     R24,Y+1          Load indirect with 
displacement
+00000056:   819A        LDD     R25,Y+2          Load indirect with 
displacement
+00000057:   9601        ADIW    R24,0x01         Add immediate to word
+00000058:   8389        STD     Y+1,R24          Store indirect with 
displacement
+00000059:   839A        STD     Y+2,R25          Store indirect with 
displacement
+0000005A:   9700        SBIW    R24,0x00         Subtract immediate from word
+0000005B:   F009        BREQ    +0x01            Branch if equal
19:           while(++i); // sleep until i wraps
+0000005C:   CFF8        RJMP    -0x0008          Relative jump
+0000005D:   9622        ADIW    R28,0x02         Add immediate to word
+0000005E:   B60F        IN      R0,0x3F          In from I/O location
+0000005F:   94F8        CLI                      Flag clear
+00000060:   BFDE        OUT     0x3E,R29         Out to I/O location
+00000061:   BE0F        OUT     0x3F,R0          Out to I/O location
+00000062:   BFCD        OUT     0x3D,R28         Out to I/O location
+00000063:   91DF        POP     R29              Pop register from stack
+00000064:   91CF        POP     R28              Pop register from stack
+00000065:   9508        RET                      Subroutine return
@00000066: main
35:       {

+00000066:   EECB        LDI     R28,0xEB         Load immediate
+00000067:   E0D4        LDI     R29,0x04         Load immediate
+00000068:   BFDE        OUT     0x3E,R29         Out to I/O location
+00000069:   BFCD        OUT     0x3D,R28         Out to I/O location
The previous four instructions set up the return stack a second time^^


41:         int            counter = 0;
+0000006A:   8A1B        STD     Y+19,R1          Store indirect with 
displacement
+0000006B:   8A1C        STD     Y+20,R1          Store indirect with 
displacement
43:           DDRB = 0xff;
+0000006C:   EF8F        SER     R24              Load immediate
+0000006D:   93800024    STS     0x0024,R24       Store direct to data space
50:               PORTB = 0xaa;
+0000006F:   EA8A        LDI     R24,0xAA         Load immediate
+00000070:   93800025    STS     0x0025,R24       Store direct to data space
51:               delay();
+00000072:   940E004B    CALL    0x0000004B       Call subroutine
52:               PORTB = 0x55;
+00000074:   E585        LDI     R24,0x55         Load immediate
+00000075:   93800025    STS     0x0025,R24       Store direct to data space
53:               delay();
+00000077:   940E004B    CALL    0x0000004B       Call subroutine
+00000079:   CFF5        RJMP    -0x000B          Relative jump





reply via email to

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