Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Located sections are ignored by simavr #484

Open
ManfredSteiner opened this issue Apr 12, 2022 · 2 comments
Open

Located sections are ignored by simavr #484

ManfredSteiner opened this issue Apr 12, 2022 · 2 comments

Comments

@ManfredSteiner
Copy link

For a project with an Atmega324P I use special sections to ensure that some code is located on desired addresses. Works fine on real target, but these sections are not loaded proper in simavr.

Any idea what is going wrong and how to solve this problem?

To reproduce this problem I use an Ubuntu system with avr-gcc (5.4.0), avr-gdb (10.1.90.20210103-git) and simavr (1.6+dfsg-3).

  1. Create file main.c
#define ATT_SECTION_APP __attribute__((section(".app")))

int main () ATT_SECTION_APP;

int main () {
    asm("nop");
    return 0;
}
  1. Build project and locate section .app to 0x7100
avr-gcc -c -o main.o main.c
avr-gcc -o main.elf -Wl,-section-start=.app=0x7100  -mmcu=atmega324p main.o
  1. Check result in elf-file

Disassemble elf-file with avr-objdump -d main.elf

Disassembly of section .app:

00007100 <main>:
    7100:	cf 93       	push	r28
    7102:	df 93       	push	r29
    7104:	cd b7       	in	r28, 0x3d	; 61
    7106:	de b7       	in	r29, 0x3e	; 62
    7108:	00 00       	nop
    710a:	80 e0       	ldi	r24, 0x00	; 0
    710c:	90 e0       	ldi	r25, 0x00	; 0
    710e:	df 91       	pop	r29
    7110:	cf 91       	pop	r28
    7112:	08 95       	ret
  1. Start simavr
simavr -g -m atmega324p main.elf
  1. Start avr-gdb and show memory on location 0x7100

Start in another shell avr-gdb with avr-gdb main.elf.
Then execute the following commands on gdb console:

  • target remote localhost:1234
  • x/20b 0x7100

As you can see, the memory locations starting with 0x7100 are cleared (= 0xff) instead of showing the same content as in disassembly view. Symbols like main are shown as desired.

(gdb) target remote localhost:1234
Remote debugging using localhost:1234
0x00000000 in __vectors ()
(gdb) x/20b 0x7100
0x7100 <main>:		0xff	0xff	0xff	0xff	0xff	0xff	0xff	0xff
0x7108 <main+8>:	0xff	0xff	0xff	0xff	0xff	0xff	0xff	0xff
0x7110 <main+16>:	0xff	0xff	0xff	0xff
@gatk555
Copy link
Collaborator

gatk555 commented Apr 13, 2022

A probable work-round would be to convert the ELF file to ihex and load that. That does lose debug symbols.

The problem sounds similar to #462, with the same cause: simavr does not really follow the ELF spec.

@ManfredSteiner
Copy link
Author

Thank your for response. Your statement in #462 ...

simavr loads only the .text, .data, .eeprom, .fuse and .lock sections and assumes the first two are contiguous.

... seems to be true, which is definitely a failure in simavr.

In my project I build now in different ways. One variant for hardware target and one variant for simulation (without modification of default section configuration). That's my work-arround at the moment.

gatk555 pushed a commit to gatk555/simavr that referenced this issue Apr 20, 2022
… than

the Section Table.  Fixes upstream buserror#484 "Located sections are ignored
by simavr".
gatk555 pushed a commit to gatk555/simavr that referenced this issue Apr 20, 2022
… than

the Section Table.  Fixes upstream buserror#484 "Located sections are ignored
by simavr".
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants