I'm working with the 4809 nano curiosity. I had a routine to print a string constant. It failed. I traced it to the string constant not existing in sram.
Looking at the same C source compiled for mega328p and mega4809 leads to some significant differences. I'm using objdump -D to peer into the binary.
Notice below that the 328p elf has the string in the .data section and the 4809 elf has the string in the .rodata section, and that the do_copy_data code is inserted in the 328p object but not in the 4809 one. I believe gcc is the tool that inserts the copy of text to data. Any hints on why the 4809 is not being done?
The C code:
#define F_CPU 20000000UL #include <avr/io.h> char *s; int main(void) { s = "abc"; while (1); }
Here is a relevant segment of the main.elf run through "avr-objdump -D main.elf for the 328p
Disassembly of section .data: 00800100 <__data_start>: 800100: 61 62 ori r22, 0x21 ; 33 800102: 63 00 .word 0x0063 ; ???? Disassembly of section .text: 00000000 <__vectors>: 0: 0c 94 34 00 jmp 0x68 ; 0x68 <__ctors_end> 4: 0c 94 51 00 jmp 0xa2 ; 0xa2 <__bad_interrupt> .... 64: 0c 94 51 00 jmp 0xa2 ; 0xa2 <__bad_interrupt> 00000068 <__ctors_end>: 68: 11 24 eor r1, r1 6a: 1f be out 0x3f, r1 ; 63 6c: cf ef ldi r28, 0xFF ; 255 6e: d8 e0 ldi r29, 0x08 ; 8 70: de bf out 0x3e, r29 ; 62 72: cd bf out 0x3d, r28 ; 61 00000074 <__do_copy_data>: 74: 11 e0 ldi r17, 0x01 ; 1 76: a0 e0 ldi r26, 0x00 ; 0 78: b1 e0 ldi r27, 0x01 ; 1 7a: e8 eb ldi r30, 0xB8 ; 184 7c: f0 e0 ldi r31, 0x00 ; 0 7e: 02 c0 rjmp .+4 ; 0x84 <__do_copy_data+0x10> 80: 05 90 lpm r0, Z+ 82: 0d 92 st X+, r0 84: a4 30 cpi r26, 0x04 ; 4 86: b1 07 cpc r27, r17 88: d9 f7 brne .-10 ; 0x80 <__do_copy_data+0xc> 0000008a <__do_clear_bss>: 8a: 21 e0 ldi r18, 0x01 ; 1 8c: a4 e0 ldi r26, 0x04 ; 4 8e: b1 e0 ldi r27, 0x01 ; 1 90: 01 c0 rjmp .+2 ; 0x94 <.do_clear_bss_start> 00000092 <.do_clear_bss_loop>: 92: 1d 92 st X+, r1 00000094 <.do_clear_bss_start>: 94: a6 30 cpi r26, 0x06 ; 6 96: b2 07 cpc r27, r18 98: e1 f7 brne .-8 ; 0x92 <.do_clear_bss_loop> 9a: 0e 94 53 00 call 0xa6 ; 0xa6 <main> 9e: 0c 94 5a 00 jmp 0xb4 ; 0xb4 <_exit> 000000a2 <__bad_interrupt>: a2: 0c 94 00 00 jmp 0 ; 0x0 <__vectors> 000000a6 <main>: a6: 80 e0 ldi r24, 0x00 ; 0 a8: 91 e0 ldi r25, 0x01 ; 1 aa: 90 93 05 01 sts 0x0105, r25 ; 0x800105 <__data_end+0x1> ae: 80 93 04 01 sts 0x0104, r24 ; 0x800104 <__data_end> b2: ff cf rjmp .-2 ; 0xb2 <main+0xc> 000000b4 <_exit>: b4: f8 94 cli 000000b6 <__stop_program>: b6: ff cf rjmp .-2 ; 0xb6 <__stop_program>
Here is the same for the 4809.
Disassembly of section .text: 00000000 <__vectors>: 0: 0c 94 50 00 jmp 0xa0 ; 0xa0 <__ctors_end> 4: 0c 94 62 00 jmp 0xc4 ; 0xc4 <__bad_interrupt> ... 9c: 0c 94 62 00 jmp 0xc4 ; 0xc4 <__bad_interrupt> 000000a0 <__ctors_end>: a0: 11 24 eor r1, r1 a2: 1f be out 0x3f, r1 ; 63 a4: cf ef ldi r28, 0xFF ; 255 a6: cd bf out 0x3d, r28 ; 61 a8: df e3 ldi r29, 0x3F ; 63 aa: de bf out 0x3e, r29 ; 62 000000ac <__do_clear_bss>: ac: 28 e2 ldi r18, 0x28 ; 40 ae: a0 e0 ldi r26, 0x00 ; 0 b0: b8 e2 ldi r27, 0x28 ; 40 b2: 01 c0 rjmp .+2 ; 0xb6 <.do_clear_bss_start> 000000b4 <.do_clear_bss_loop>: b4: 1d 92 st X+, r1 000000b6 <.do_clear_bss_start>: b6: a2 30 cpi r26, 0x02 ; 2 b8: b2 07 cpc r27, r18 ba: e1 f7 brne .-8 ; 0xb4 <.do_clear_bss_loop> bc: 0e 94 64 00 call 0xc8 ; 0xc8 <main> c0: 0c 94 6b 00 jmp 0xd6 ; 0xd6 <_exit> 000000c4 <__bad_interrupt>: c4: 0c 94 00 00 jmp 0 ; 0x0 <__vectors> 000000c8 <main>: c8: 8a ed ldi r24, 0xDA ; 218 ca: 90 e4 ldi r25, 0x40 ; 64 cc: 80 93 00 28 sts 0x2800, r24 ; 0x802800 <__DATA_REGION_ORIGIN__> d0: 90 93 01 28 sts 0x2801, r25 ; 0x802801 <__DATA_REGION_ORIGIN__+0x1> d4: ff cf rjmp .-2 ; 0xd4 <main+0xc> 000000d6 <_exit>: d6: f8 94 cli 000000d8 <__stop_program>: d8: ff cf rjmp .-2 ; 0xd8 <__stop_program> Disassembly of section .rodata: 000040da <.rodata>: 40da: 61 62 ori r22, 0x21 ; 33 40dc: 63 00 .word 0x0063 ; ????
Here is relevant section of the ldscript for the 328p (i.e., avr5.xn):
.data : { PROVIDE (__data_start = .) ; *(.data) *(.data*) *(.gnu.linkonce.d*) *(.rodata) /* We need to include .rodata here if gcc is used */ *(.rodata*) /* with -fdata-sections. */ *(.gnu.linkonce.r*) . = ALIGN(2); _edata = . ; PROVIDE (__data_end = .) ; } > data AT> text
Here is the relevant section of the ldscript for the 4809 (i.e., avrxmega3.xn):
.data : { PROVIDE (__data_start = .) ; *(.data) *(.data*) *(.gnu.linkonce.d*) . = ALIGN(2); _edata = . ; PROVIDE (__data_end = .) ; } > data AT> text .rodata ADDR(.text) + SIZEOF (.text) + __RODATA_PM_OFFSET__ : { *(.rodata) *(.rodata*) *(.gnu.linkonce.r*) } AT> text
The 328p ldscript has no .rodata section listed.