I wrote the following code:
#include <avr/io.h>
__attribute__((noinline, section(".app_start"))) void app_start() //app_start section starts at 0xFA0
{
//register_packet_dispatch(packet_received);
PORTB = 0xFF;
}
__attribute__ ((noinline)) void call_app()
{
asm ("call 0xFA0\nret");
//app_start();
}
int main()
{
DDRB = 0xFF;
//call_app();
app_start();
while(1){}
}
What I compiled with:
avr-gcc -Wl,--section-start=.reg_dispatch=0xdac -Wl,--section-start=.app_start=0xFA0 -mmcu=atmega328p -Os -o ubb.o ub_bootloader.cpp -DF_CPU=16000000
Which tries to simulate a host application that tries to call a relocated client application, begins from the 4000 address (0xFA0). If it would work, it's light up the LED wired to the arduino's 13. pin. But why app_start
won't be called?
I've also inspected the output assemlby:
avr-objcopy -j .text -j .data -O ihex ubb.o ubb.hex
00000fa0 <_Z9app_startv>:
fa0: 8f ef ldi r24, 0xFF ; 255
fa2: 85 b9 out 0x05, r24 ; 5
fa4: 08 95 ret
00000080 <main>:
80: 8f ef ldi r24, 0xFF ; 255
82: 84 b9 out 0x04, r24 ; 4
84: 0e 94 d0 07 call 0xfa0 ; 0xfa0 <_Z9app_startv>
88: ff cf rjmp .-2 ; 0x88 <main+0x8>
Everything seems correct, why it isn't working at all? Of course, if i remove the "noinline" attribute, it works. But that's a mirage, the compiler inlines the content of the function, but when I build this into an application, the code after the 0xFA0 address will be rewritten by the host application.
app_start
won't be called even if i call directly (calling app_start() shown in comment, instead of asm "call 0xFA0") – Dankó Dávid Jan 28 '19 at 11:07-o ubb.elf
? – Edgar Bonet Jan 28 '19 at 12:15app_start
directly from themain
also doesn't work. – Dankó Dávid Jan 28 '19 at 12:34ubb.o
:.elf
and.o
are just file endingsfile ubb.o
says:ubb.o: ELF 32-bit LSB executable, Atmel AVR 8-bit, version 1 (SYSV), statically linked, not stripped
. – Dankó Dávid Jan 28 '19 at 12:37