[Top][All Lists]

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

Re: [avr-gcc-list] Choose where the code is placed in flash memory.

From: Klaus Rudolph
Subject: Re: [avr-gcc-list] Choose where the code is placed in flash memory.
Date: Tue, 03 Dec 2002 21:13:22 +0100

frantz Capiez wrote:
> Hello,
> I want to place myself a portion of my code (like a function), in
> particular address. I use an Atmega16 target with the latest version of
> gcc.
>  If somedy can write me the method for have this behavior, thank you in
> advance,
> Frantz
> avr-gcc-list at http://avr1.org
Hallo Franz,

seems to be a simple question :-)

First you give the function a section attribute:

main.c ---> 
#include <io.h>
/*place a function to a specific section*/
int f2(int a, int b) __attribute__ ((section ("test99")));

int f2(int a, int b)
        return a+b;

int main () {
        volatile int a = 5;
        volatile int b;

        for (a;a<10; a++) {
<--- end

Now you compile it as you normal compile your code
avr-gcc -O2 -g main.c -o
you got main.o
now you tell the linker that the section "test99" will start at 0x5432
So you tell the linker your wishes:
avr-ld   --section-start test99=0x5432  main.o -o mainprog

or you place the linker parameters in avr-gcc line... sorry I don´t know
the syntax in that moment (to much C2H5OH here :-)

now try a look:
avr-nm mainprog
00000000 a *ABS*
00000002 a _PC_
0000003e a __SP_H__
0000003d a __SP_L__
0000003f a __SREG__
00810000 ? __eeprom_end
0000025f A __stack
00000036 t __stop_progIi__
00000000 a __tmp_reg__
00000001 a __zero_reg__
00800060 D _edata
00800060 B _end
00000038 T _etext
00005432 ? f2                  <<<<< here the section is moved!!
00000000 T main

and now in the code:
  20:   89 81           ldd     r24, Y+1        ; 0x01
  22:   9a 81           ldd     r25, Y+2        ; 0x02
  24:   06 da           rcall   .-3060          ; 0xfffff432
  26:   8b 83           std     Y+3, r24        ; 0x03
  28:   9c 83           std     Y+4, r25        ; 0x04
in line 24: you find a rcall to 5432, don´t worry about the FFFF at the
start of the 
address, this is normal and this is not an error! the function call goes
to 0x5432

If you have more than one sestion, place it in the linker script. If you
put the section in the linker script you can but you must not use the
section attribute
in your source. Here you can specify also source modules which should be
located to specified addresses. Please read the ld manual for detailed

avr-gcc-list at http://avr1.org

reply via email to

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