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

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

[avr-gcc-list] Fixed, external function "pointers"


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)

I've got a bootloader under development (started in C, converted to ASM blind, now am validating ASM piece by piece) that should fit in 512 bytes, uses I2C for communication, and provides the application with an I2C register-style interface, as well as a function to write to PROGMEM arrays. And of course application-code uploads when in bootloader mode.

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




reply via email to

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