|
From: | Erik Walthinsen |
Subject: | [avr-gcc-list] Fixed, external function "pointers" |
Date: | Tue, 10 Jan 2006 22:21:34 -0800 |
User-agent: | Debian Thunderbird 1.0.7 (X11/20051017) |
The trick is that I need to find an efficient way for the application to call functions that will be at a fixed *known* address in the final bootloader. Obviously I can use function pointers defined in a header, but that takes up SRAM and each call is quite bulky.
The next method that works is to put stub *inline* functions in the header, that load the address and 'icall'. The problem with this is that it's rather inflexible: if the CPU in question has 'call', it'd be better to use that. More specifically, if the calling code is within the first 1.5KB-2KB of Flash, it should be using 'rjmp' instead...
A third method is to create __naked__ stubs of these functions, each one in its own section. Relocate each section with something like "-Wl,--section-start=.bootloader_enter=0x1840" on the compiler commandline, then remove them with "--remove-section=.bootloader_enter" with objcopy. This lets the compiler produce the most appropriate call code, but has a *severe* disadvantage in that it's an absolute beast to compile/link/etc. because of all these "ghost" sections being relocated and then removed.
This last method even works for the interrupt handler, if I define __vector_17 (SIG_TWI on the mega8) the same way as the others. I get a negative rjmp in the vector table pointing "backwards" into the bootloader.
My question is: is there some more elegant way of achieving this same result without having to put all this mess on the compiler and objcopy commandlines? Can I define a "fixed function pointer" in C (const doesn't do anything) that will tell it where to go without the section stupidities? Maybe some assembler constructs that I can pass through the C? Or even some kind of magic .o I can link into the app? If any of these are possible, will they also work for interrupt vectors? (I really don't want to have to double-jump for the TWI IRQ).
TIA, Omega aka Erik Walthinsen address@hidden
[Prev in Thread] | Current Thread | [Next in Thread] |