backport: re PR target/55897 ([avr] Allocate __memx data to .progmemx.data)

Backport from 2013-01-07 trunk r194991, r194992.
	PR target/55897
	* doc/extend.texi (AVR Named Address Spaces): __memx goes into
	.progmemx.data now.
	* config/avr/avr.h (ADDR_SPACE_COUNT): New enum.
	(avr_addrspace_t): Add .section_name field.
	* config/avr/avr.c (progmem_section): Use ADDR_SPACE_COUNT as
	array size.
	(avr_addrspace): Same.  Initialize .section_name.  Remove last
	NULL entry.  Put __memx into .progmemx.data.
	(progmem_section_prefix): Remove.
	(avr_asm_init_sections): No need to initialize progmem_section.
	(avr_asm_named_section): Use avr_addrspace[].section_name to get
	section name prefix.
	(avr_asm_select_section): Ditto.  And use get_unnamed_section to
	retrieve the progmem section.
	* avr-c.c (avr_cpu_cpp_builtins): Use ADDR_SPACE_COUNT as loop
	boundary to run over avr_addrspace[].
	(avr_register_target_pragmas): Ditto.

From-SVN: r194993
This commit is contained in:
Georg-Johann Lay 2013-01-07 18:51:33 +00:00 committed by Georg-Johann Lay
parent 1e7aecb585
commit ed8a63c1c8
5 changed files with 64 additions and 43 deletions

View File

@ -1,3 +1,27 @@
2013-01-07 Georg-Johann Lay <avr@gjlay.de>
Backport from 2013-01-07 trunk r194991, r194992.
PR target/55897
* doc/extend.texi (AVR Named Address Spaces): __memx goes into
.progmemx.data now.
* config/avr/avr.h (ADDR_SPACE_COUNT): New enum.
(avr_addrspace_t): Add .section_name field.
* config/avr/avr.c (progmem_section): Use ADDR_SPACE_COUNT as
array size.
(avr_addrspace): Same. Initialize .section_name. Remove last
NULL entry. Put __memx into .progmemx.data.
(progmem_section_prefix): Remove.
(avr_asm_init_sections): No need to initialize progmem_section.
(avr_asm_named_section): Use avr_addrspace[].section_name to get
section name prefix.
(avr_asm_select_section): Ditto. And use get_unnamed_section to
retrieve the progmem section.
* avr-c.c (avr_cpu_cpp_builtins): Use ADDR_SPACE_COUNT as loop
boundary to run over avr_addrspace[].
(avr_register_target_pragmas): Ditto.
2013-01-07 Georg-Johann Lay <avr@gjlay.de>
Backport from 2013-01-07 trunk r194978.

View File

@ -43,7 +43,7 @@ avr_register_target_pragmas (void)
/* Register address spaces. The order must be the same as in the respective
enum from avr.h (or designated initialized must be used in avr.c). */
for (i = 0; avr_addrspace[i].name; i++)
for (i = 0; i < ADDR_SPACE_COUNT; i++)
{
gcc_assert (i == avr_addrspace[i].id);
@ -160,7 +160,7 @@ avr_cpu_cpp_builtins (struct cpp_reader *pfile)
if (!strcmp (lang_hooks.name, "GNU C"))
{
for (i = 0; avr_addrspace[i].name; i++)
for (i = 0; i < ADDR_SPACE_COUNT; i++)
if (!ADDR_SPACE_GENERIC_P (i)
/* Only supply __FLASH<n> macro if the address space is reasonable
for this target. The address space qualifier itself is still

View File

@ -80,29 +80,18 @@
/* Known address spaces. The order must be the same as in the respective
enum from avr.h (or designated initialized must be used). */
const avr_addrspace_t avr_addrspace[] =
const avr_addrspace_t avr_addrspace[ADDR_SPACE_COUNT] =
{
{ ADDR_SPACE_RAM, 0, 2, "" , 0 },
{ ADDR_SPACE_FLASH, 1, 2, "__flash", 0 },
{ ADDR_SPACE_FLASH1, 1, 2, "__flash1", 1 },
{ ADDR_SPACE_FLASH2, 1, 2, "__flash2", 2 },
{ ADDR_SPACE_FLASH3, 1, 2, "__flash3", 3 },
{ ADDR_SPACE_FLASH4, 1, 2, "__flash4", 4 },
{ ADDR_SPACE_FLASH5, 1, 2, "__flash5", 5 },
{ ADDR_SPACE_MEMX, 1, 3, "__memx", 0 },
{ 0 , 0, 0, NULL, 0 }
{ ADDR_SPACE_RAM, 0, 2, "", 0, NULL },
{ ADDR_SPACE_FLASH, 1, 2, "__flash", 0, ".progmem.data" },
{ ADDR_SPACE_FLASH1, 1, 2, "__flash1", 1, ".progmem1.data" },
{ ADDR_SPACE_FLASH2, 1, 2, "__flash2", 2, ".progmem2.data" },
{ ADDR_SPACE_FLASH3, 1, 2, "__flash3", 3, ".progmem3.data" },
{ ADDR_SPACE_FLASH4, 1, 2, "__flash4", 4, ".progmem4.data" },
{ ADDR_SPACE_FLASH5, 1, 2, "__flash5", 5, ".progmem5.data" },
{ ADDR_SPACE_MEMX, 1, 3, "__memx", 0, ".progmemx.data" },
};
/* Map 64-k Flash segment to section prefix. */
static const char* const progmem_section_prefix[6] =
{
".progmem.data",
".progmem1.data",
".progmem2.data",
".progmem3.data",
".progmem4.data",
".progmem5.data"
};
/* Holding RAM addresses of some SFRs used by the compiler and that
are unique over all devices in an architecture like 'avr4'. */
@ -208,8 +197,9 @@ const struct mcu_type_s *avr_current_device;
static GTY(()) section *progmem_swtable_section;
/* Unnamed sections associated to __attribute__((progmem)) aka. PROGMEM
or to address space __flash*. */
static GTY(()) section *progmem_section[6];
or to address space __flash* or __memx. Only used as singletons inside
avr_asm_select_section, but it must not be local there because of GTY. */
static GTY(()) section *progmem_section[ADDR_SPACE_COUNT];
/* Condition for insns/expanders from avr-dimode.md. */
bool avr_have_dimode = true;
@ -7120,8 +7110,6 @@ avr_output_progmem_section_asm_op (const void *data)
static void
avr_asm_init_sections (void)
{
unsigned int n;
/* Set up a section for jump tables. Alignment is handled by
ASM_OUTPUT_BEFORE_CASE_LABEL. */
@ -7140,13 +7128,6 @@ avr_asm_init_sections (void)
",\"ax\",@progbits");
}
for (n = 0; n < sizeof (progmem_section) / sizeof (*progmem_section); n++)
{
progmem_section[n]
= get_unnamed_section (0, avr_output_progmem_section_asm_op,
progmem_section_prefix[n]);
}
/* Override section callbacks to keep track of `avr_need_clear_bss_p'
resp. `avr_need_copy_data_p'. */
@ -7224,10 +7205,9 @@ avr_asm_named_section (const char *name, unsigned int flags, tree decl)
if (flags & AVR_SECTION_PROGMEM)
{
addr_space_t as = (flags & AVR_SECTION_PROGMEM) / SECTION_MACH_DEP;
int segment = avr_addrspace[as].segment;
const char *old_prefix = ".rodata";
const char *new_prefix = progmem_section_prefix[segment];
const char *new_prefix = avr_addrspace[as].section_name;
if (STR_PREFIX_P (name, old_prefix))
{
const char *sname = ACONCAT ((new_prefix,
@ -7339,13 +7319,18 @@ avr_asm_select_section (tree decl, int reloc, unsigned HOST_WIDE_INT align)
&& avr_progmem_p (decl, DECL_ATTRIBUTES (decl)))
{
addr_space_t as = TYPE_ADDR_SPACE (TREE_TYPE (decl));
int segment = avr_addrspace[as].segment;
/* __progmem__ goes in generic space but shall be allocated to
.progmem.data */
if (ADDR_SPACE_GENERIC_P (as))
as = ADDR_SPACE_FLASH;
if (sect->common.flags & SECTION_NAMED)
{
const char * name = sect->named.name;
const char * old_prefix = ".rodata";
const char * new_prefix = progmem_section_prefix[segment];
const char * new_prefix = avr_addrspace[as].section_name;
if (STR_PREFIX_P (name, old_prefix))
{
@ -7354,8 +7339,15 @@ avr_asm_select_section (tree decl, int reloc, unsigned HOST_WIDE_INT align)
return get_section (sname, sect->common.flags, sect->named.decl);
}
}
return progmem_section[segment];
if (!progmem_section[as])
{
progmem_section[as]
= get_unnamed_section (0, avr_output_progmem_section_asm_op,
avr_addrspace[as].section_name);
}
return progmem_section[as];
}
return sect;

View File

@ -156,6 +156,9 @@ typedef struct
/* Segment (i.e. 64k memory chunk) number. */
int segment;
/* Section prefix, e.g. ".progmem1.data" */
const char *section_name;
} avr_addrspace_t;
extern const avr_addrspace_t avr_addrspace[];
@ -164,14 +167,16 @@ extern const avr_addrspace_t avr_addrspace[];
enum
{
ADDR_SPACE_RAM,
ADDR_SPACE_RAM, /* ADDR_SPACE_GENERIC */
ADDR_SPACE_FLASH,
ADDR_SPACE_FLASH1,
ADDR_SPACE_FLASH2,
ADDR_SPACE_FLASH3,
ADDR_SPACE_FLASH4,
ADDR_SPACE_FLASH5,
ADDR_SPACE_MEMX
ADDR_SPACE_MEMX,
/* Sentinel */
ADDR_SPACE_COUNT
};
#define TARGET_CPU_CPP_BUILTINS() avr_cpu_cpp_builtins (pfile)

View File

@ -1274,7 +1274,7 @@ RAM using the lower two bytes as RAM address.
If the high bit of the address is clear, data is read from flash
with @code{RAMPZ} set according to the high byte of the address.
Objects in this address space will be located in @code{.progmem.data}.
Objects in this address space will be located in @code{.progmemx.data}.
@end table
@b{Example}