GCC Bugzilla has been upgraded from version 4.4.9 to 5.0rc3. If you see any problem, please report it to bug 64968.
Bug 49868 - Implement named address space to place/access data in flash memory
Summary: Implement named address space to place/access data in flash memory
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 4.7.0
: P4 enhancement
Target Milestone: 4.7.0
Assignee: Not yet assigned to anyone
URL:
Keywords: addr-space
Depends on: 50931 53344
Blocks: 43745 49857
  Show dependency treegraph
 
Reported: 2011-07-27 12:44 UTC by Georg-Johann Lay
Modified: 2012-05-14 14:06 UTC (History)
3 users (show)

See Also:
Host:
Target: avr
Build:
Known to work:
Known to fail:
Last reconfirmed: 2011-10-07 00:00:00


Attachments
Sample code to show usage of __pgm address space. (483 bytes, text/plain)
2011-07-27 12:44 UTC, Georg-Johann Lay
Details
Draft work on AS against r177314 (6.54 KB, patch)
2011-08-04 13:51 UTC, Georg-Johann Lay
Details | Diff
1/2: r179594: Ulrich Weigand's extension to some GCC hooks (8.71 KB, patch)
2011-10-07 15:22 UTC, Georg-Johann Lay
Details | Diff
2/2: r179594: AVR part of implementation (8.54 KB, patch)
2011-10-07 15:24 UTC, Georg-Johann Lay
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Georg-Johann Lay 2011-07-27 12:44:47 UTC
Created attachment 24841 [details]
Sample code to show usage of __pgm address space.

AVR is Harvard architecture and it need special instructions to read data from flash (LPM) which are different to the instructions needed to read data from RAM.

The address space is not linearized.  Linearizing the address space at the compiler level is not really wanted because this would mean gread deal of overhead and incompatibility with current implementation.

The current situation is this:

To put data in flash storage (section .progmem.data) there is a decl attribute "progmem".  To access the data, inline assembly is used, e.g. by means of pgm_read_* functions supplied by avr-libc.

A Named Address Space enales to write type-safe code that is not cluttered up with inline assembly access functions all over the place.

Moreover, some optimizations like PR49857 (Put constant switch-tables into flash) and PR43745 (Put VTABLES into flash) need named addresses to express the flash-access inside GCC.
Comment 1 Georg-Johann Lay 2011-08-04 13:51:28 UTC
Created attachment 24916 [details]
Draft work on AS against r177314

This is just an update of my local work on a named address support for AVR.

There are still problems, see

http://gcc.gnu.org/ml/gcc/2011-08/msg00083.html
http://gcc.gnu.org/ml/gcc/2011-08/msg00095.html
Comment 2 Georg-Johann Lay 2011-10-07 15:22:51 UTC
Created attachment 25438 [details]
1/2: r179594: Ulrich Weigand's extension to some GCC hooks

As posted by Ulrich in http://gcc.gnu.org/ml/gcc/2011-08/msg00131.html and updated to SVN 175594.
Comment 3 Georg-Johann Lay 2011-10-07 15:24:32 UTC
Created attachment 25439 [details]
2/2: r179594: AVR part of implementation
Comment 4 Georg-Johann Lay 2011-10-07 15:28:45 UTC
See also discussion in gcc-patches@

http://gcc.gnu.org/ml/gcc-patches/2011-10/msg00471.html
Comment 5 Eric Weddington 2011-10-20 14:36:01 UTC
Hi Johann,

I would prefer if the name of the address space for program memory be named "__flash" so that way it is the same name as what the IAR compiler uses. Using the same name as the IAR compiler assists users who wish to migrate from the IAR to the GCC toolchains. Like so:

+  c_register_addr_space ("__flash", ADDR_SPACE_PGM);
Comment 6 Georg-Johann Lay 2011-10-20 15:18:51 UTC
(In reply to comment #5)
> Hi Johann,
> 
> I would prefer if the name of the address space for program memory be named
> "__flash" so that way it is the same name as what the IAR compiler uses. Using
> the same name as the IAR compiler assists users who wish to migrate from the
> IAR to the GCC toolchains. Like so:
> 
> +  c_register_addr_space ("__flash", ADDR_SPACE_PGM);

I chose __pgm because it is different to __flash. Even though I know nothing about IAR's __flash I can hardly imagine that __pgm does 100% the same.

It's implementation defined and using the same identifier would give rise to the incorrect assumption that both imlementations behave exactly the same, which most probably is not the case.

Moreover, the problem of > 64k flash is not yet addressed. As far as I can see, there are three approches:

1.
Don't do anything about it.

2.
Implement bunch of ASes like __pgm1, __pgm2 for each 64k chunk.
This is easiest to implement and has least side effects on avr back end.
These AVRs are segmented architecture and at some points an implementation cannot hide that to the user.

This would require changes in default ld script or user would have to supply his own ld script to locate the 64k chunks/sections.

3.
Implement thing like __pgmx that is attached to 24 bit address.
This is way more complicated because a new machine mode PSI must be supported or else the AS has to hitchhike SImode.

When crossing section boundaries ELPM Z+ changes RAMPZ, leading to messy code in the general case.

Notice that it is not possible to split additions in the AVR BE because there is still cc0. And there is *no* address register that can hold pointers > 16 bits. X cannot because Y might be FP, Y cannot because it might be PF, Z cannot because there is no register R32 whouch would then be RAMPZ. Dunno if treating RAMPZ as GPR instead of as SFR is doable and sane.
Comment 7 Georg-Johann Lay 2011-11-15 09:01:50 UTC
Author: gjl
Date: Tue Nov 15 09:01:46 2011
New Revision: 181378

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=181378
Log:
gcc/
	PR target/49868
	* config/avr/avr.h (ADDR_SPACE_PGM): New address spaces.
	(REGISTER_TARGET_PRAGMAS): New define.
	* config/avr/avr-protos.h (avr_mem_pgm_p): New.
	(avr_load_libgcc_p): New.
	(asm_output_external_libcall): Remove.
	(avr_register_target_pragmas): New.
	(avr_log_t): Add field "progmem".  Order alphabetically.
	* config/avr/avr-log.c (avr_log_set_avr_log): Set avr_log.progmem.
	* config/avr/avr-c.c (langhooks.h): New include.
	(avr_register_target_pragmas): New function. Register address
	space __pgm.
	(avr_cpu_cpp_builtins): Add built-in define __PGM.
	* config/avr/avr.c: Include "c-family/c-common.h".
	(TARGET_LEGITIMATE_ADDRESS_P): Remove define.
	(TARGET_LEGITIMIZE_ADDRESS): Remove define.
	(TARGET_ADDR_SPACE_SUBSET_P): Define to...
	(avr_addr_space_subset_p): ...this new static function.
	(TARGET_ADDR_SPACE_CONVERT): Define to...
	(avr_addr_space_convert): ...this new static function.
	(TARGET_ADDR_SPACE_ADDRESS_MODE): Define to...
	(avr_addr_space_address_mode): ...this new static function.
	(TARGET_ADDR_SPACE_POINTER_MODE): Define to...
	(avr_addr_space_pointer_mode): ...this new static function.
	(TARGET_ADDR_SPACE_LEGITIMATE_ADDRESS_P): Define to...
	(avr_addr_space_legitimate_address_p): ...this new static function.
	(TARGET_ADDR_SPACE_LEGITIMIZE_ADDRESS): Define to...
	(avr_addr_space_legitimize_address): ...this new static function.
	(avr_mode_code_base_reg_class): Handle address spaces.
	(avr_regno_mode_code_ok_for_base_p): Ditto.
	(lpm_addr_reg_rtx, lpm_reg_rtx, all_regs_rtx): New static variables.
	(avr_option_override): Initialize them.
	(output_reload_in_const): Use all_regs_rtx. Fix signedness of loop
	variables.
	(avr_pgm_segment): New static function.
	(avr_decl_pgm_p, avr_mem_pgm_p): New static functions.
	(avr_out_lpm, avr_out_lpm_no_lpmx): New static functions.
	(output_movqi, output_movhi, output_movsisf, avr_out_movpsi): Call
	avr_out_lpm to handle loads from progmem.
	(avr_load_libgcc_p): New static function.
	(avr_progmem_p): Test if decl is in flash.
	(avr_pgm_pointer_const_p): New static function.
	(avr_nonconst_pointer_addrspace): New static function.
	(avr_pgm_check_var_decl): New static function.
	(avr_insert_attributes): Use it.  Change error message to report
	cause (progmem or address space) when code wants to write to flash.
	(avr_section_type_flags): Unset section flag SECTION_BSS for
	data in progmem.
	* config/avr/predicates.md (nop_general_operand): New predicate.
	(nox_general_operand): New predicate.
	* config/avr/avr.md (LPM_REGNO): New define_constant.
	(load<mode>_libgcc): New expander.
	(*load.<mode>.libgcc): New insn.
	(mov<mode>): Handle loads from non-generic AS.
	(movmemhi): Ditto.  Propagate address space information to newly
	created MEM.
	(movqi_insn, *movhi, *movpsi, *movsi, *movsf): Change predicate #1
	to nox_general_operand.
	(ashrqi3, ashrhi3, ashrsi3): Change predicate #1 to nop_general_operand.
	(ashlqi3, *ashlqi3, ashlhi3, ashlsi3): Ditto.
	(lshrqi3, *lshrqi3, lshrhi3, lshrsi3): Ditto.
	(split-lpmx): New split.
	(*ashlhi3_const, *ashlsi3_const, *ashrhi3_const, *ashrsi3_const,
	*lshrhi3_const, *lshrsi3_const): Indent, unquote C.

libgcc/
	PR target/49868
	* config/avr/t-avr (LIB1ASMFUNCS): Add _load_3,  _load_4.
	* config/avr/lib1funcs.S (__load_3, __load_4, __xload_2): New functions.


Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/avr/avr-c.c
    trunk/gcc/config/avr/avr-log.c
    trunk/gcc/config/avr/avr-protos.h
    trunk/gcc/config/avr/avr.c
    trunk/gcc/config/avr/avr.h
    trunk/gcc/config/avr/avr.md
    trunk/gcc/config/avr/predicates.md
    trunk/libgcc/ChangeLog
    trunk/libgcc/config/avr/lib1funcs.S
    trunk/libgcc/config/avr/t-avr
Comment 8 Georg-Johann Lay 2011-11-18 16:44:12 UTC
Author: gjl
Date: Fri Nov 18 16:44:00 2011
New Revision: 181482

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=181482
Log:
gcc/
	PR target/49868
	* config/avr/avr.h (base_arch_s): Add field n_segments.
	(ADDR_SPACE_PGM1, ADDR_SPACE_PGM2, ADDR_SPACE_PGM3,
	ADDR_SPACE_PGM4, ADDR_SPACE_PGM5, ADDR_SPACE_PGMX): New address spaces.
	(AVR_HAVE_ELPM, AVR_HAVE_ELPMX): New defines.
	(INIT_EXPANDERS): New define.
	* config/avr/avr-protos.h (avr_mem_pgmx_p): New.
	(avr_init_expanders): New.
	(avr_emit_movmemhi, avr_out_movmem): New.
	(avr_xload_libgcc_p): New.
	* config/avr/avr-c.c (avr_register_target_pragmas): Register
	address spaces __pgm1, __pgm2,  __pgm3,  __pgm4  __pgm5,  __pgmx.
	(avr_cpu_cpp_builtins): Add built-in defines __PGM1,
	__PGM2, __PGM3, __PGM4, __PGM5, __PGMX.
	* config/avr/avr-devices.c (avr_arch_types): Set field n_segments.

	* config/avr/avr.c (AVR_SECTION_PROGMEM): Change define to cover
	3 bits instead of just 1.
	(xstring_empty, xstring_e, rampz_rtx): New static GTYed variables.
	(progmem_section): Change from section to array of sections.
	(progmem_section_prefix): New static variable.
	(avr_file_start): Print set for __RAMPZ__
	(avr_option_override): Move initialization of RTXes from here...
	(avr_init_expanders): ...to this new function.
	(avr_pgm_segment): New static function.
	(avr_decl_pgm_p): Handle error_mark_node.
	(avr_mem_pgmx_p, avr_decl_pgmx_p): New static functions.
	(avr_out_xload,	avr_find_unused_d_reg): New static functions.
	(expand_prologue, expand_epilogue): Use rampz_rtx.
	(print_operand): Hande CONST_STRING.
	(avr_xload_libgcc_p): New static function.
	(avr_out_lpm_no_lpmx, avr_out_lpm): Handle ELPM.
	(avr_progmem_p): Return 2 for 24-bit flash address space.
	(avr_out_sbxx_branch): Clean-up code from ASn macros.
	(out_movqi_r_mr, out_movqi_mr_r): Ditto. And recognize RAMPZ's
	address and print symbolically.
	(avr_asm_named_section, avr_section_type_flags,
	avr_encode_section_info, avr_asm_select_section,
	avr_addr_space_address_mode, avr_addr_space_pointer_mode,
	avr_addr_space_legitimate_address_p, avr_addr_space_convert,
	avr_addr_space_legitimize_address): Handle new address spaces.
	(avr_output_progmem_section_asm_op): New static function.
	(avr_asm_init_sections): Initialize progmem_section[].
	(adjust_insn_length): Handle ADJUST_LEN_XLOAD, ADJUST_LEN_MOVMEM.
	(avr_const_address_lo16): New static function.
	(avr_assemble_integer): Use it to handle 3-byte integers.
	(avr_emit_movmemhi, avr_out_movmem): New functions.
	
	* config/avr/predicates.md (nox_general_operand): Handle new
	address spaces.
	* config/avr/avr.md (unspec): Add UNSPEC_MOVMEM.
	(adjust_len): Add xload, movmem.
	(SP_ADDR): New define_constants.
	(isa): Add "lpm", "lpmx", "elpm", "elpmx".
	(enabled): Handle them.
	(load<mode>_libgcc): New expander.
	(*load.<mode>.libgcc): Rename to load_<mode>_libgcc.
	(xload8_A, xload<mode>_A): New insn-and-splits.
	(xload_8, xload_<mode>_libgcc, xload_<mode>, loadmem_elpm): New insns.
	(mov<mode>): Handle new address spaces.
	(movmemhi): Rewrite using avr_emit_movmemhi.
	(MOVMEM_r_d): New mode attribute.
	(movmem_<mode>, movmem_qi_elpm): New insns.
	(setmemhi, *clrmemqi, *clrmemhi, strlenhi, *strlenhi): Unquote
	C-code.  Use label instead of hard-coded instrunction lengths.
	
libgcc/
	PR target/49868
	* config/avr/t-avr (LIB1ASMFUNCS): Add _xload_2 _xload_3 _xload_4.
	* config/avr/lib1funcs.S (__xload_2, __xload_3, __xload_4):
	New functions.


Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/avr/avr-c.c
    trunk/gcc/config/avr/avr-devices.c
    trunk/gcc/config/avr/avr-protos.h
    trunk/gcc/config/avr/avr.c
    trunk/gcc/config/avr/avr.h
    trunk/gcc/config/avr/avr.md
    trunk/gcc/config/avr/predicates.md
    trunk/libgcc/ChangeLog
    trunk/libgcc/config/avr/lib1funcs.S
    trunk/libgcc/config/avr/t-avr
Comment 9 Georg-Johann Lay 2011-12-06 14:39:30 UTC
Author: gjl
Date: Tue Dec  6 14:39:25 2011
New Revision: 182051

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=182051
Log:
	PR target/51409
	PR target/49868
	* config/avr/avr.h (ADDR_SPACE_PGM, ADDR_SPACE_PGM1,
	ADDR_SPACE_PGM2, ADDR_SPACE_PGM3, ADDR_SPACE_PGM4,
	ADDR_SPACE_PGM5, ADDR_SPACE_PGMX): Write as enum.
	(avr_addrspace_t): New typedef.
	(avr_addrspace): New declaration.
	* config/avr/avr-c.c (avr_toupper): New static function.
	(avr_register_target_pragmas, avr_cpu_cpp_builtins): Use
	avr_addrspace to get address space information.
	* config/avr/avr.c (avr_addrspace): New variable.
	(avr_out_lpm, avr_pgm_check_var_decl, avr_insert_attributes,
	avr_asm_named_section, avr_section_type_flags,
	avr_asm_select_section, avr_addr_space_address_mode, 
	avr_addr_space_convert, avr_emit_movmemhi): Use it.
	(avr_addr_space_pointer_mode): Forward to avr_addr_space_address_mode.
	(avr_pgm_segment): Remove.


Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/avr/avr-c.c
    trunk/gcc/config/avr/avr.c
    trunk/gcc/config/avr/avr.h
Comment 10 Georg-Johann Lay 2011-12-15 16:28:42 UTC
More dependency: Need RELOCs to represent byte

http://sourceware.org/PR13503
Comment 11 Georg-Johann Lay 2012-01-10 09:42:14 UTC
Author: gjl
Date: Tue Jan 10 09:42:10 2012
New Revision: 183058

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=183058
Log:
libgcc/
	PR target/49868
	Extend __pgmx semantics to linearize memory.
	* config/avr/t-avr (LIB1ASMFUNCS): Add _xload_1, _movmemx.
	* config/avr/lib1funcs.S (__xload_1): New function.
	(__movmemx_qi, __movmemx_hi): New functions.
	(__xload_2, __xload_3, __xload_4): Rewrite to fit new __pgmx
	semantics.

gcc/
	PR target/49868
	Extend __pgmx semantics to linearize memory.
	* config/avr/avr.md (mov<mode>): Use avr_xload_libgcc_p to
	determine if code comes inline or from libgcc.
	(MOVMEM_r_d:HI): Add "w" to constraint for better preference.
	(movmem_qi, movmem_qi): Set constraint #2 to "n".
	(movmem_qi_elpm, movmem_hi_elpm): Remove insns.
	(movmemx_qi, movmemx_hi): New insns.
	(xload_<mode>_libgcc): Rewrite to new insn condition.
	(xload_<mode>): Remove insns.
	* config/avr/avr.c (avr_out_xload): Rewrite: Only need to handle
	cases that don't satisfy avr_xload_libgcc_p().
	(avr_addr_space_convert): Allow converting in any direction.
	(avr_addr_space_subset_p): Return always true.
	(avr_xload_libgcc_p): Rewrite to fit new __pgmx semantics.
	(avr_emit_movmemhi): Ditto.
	(avr_out_lpm): No need to handle ADDR_SPACE_PGMX any more.
	(avr_out_movmem): Ditto.
	(AVR_SYMBOL_FLAG_PROGMEM): New macro.
	(AVR_SYMBOL_SET_ADDR_SPACE): New macro.
	(AVR_SYMBOL_GET_ADDR_SPACE): New macro.
	(avr_encode_section_info): Encode 'progmem' in symbol flags.
	(output_reload_in_const): Don't zero-extend any 24-bit symbols.


Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/avr/avr.c
    trunk/gcc/config/avr/avr.md
    trunk/libgcc/ChangeLog
    trunk/libgcc/config/avr/lib1funcs.S
    trunk/libgcc/config/avr/t-avr
Comment 12 Georg-Johann Lay 2012-01-20 12:31:59 UTC
Author: gjl
Date: Fri Jan 20 12:31:46 2012
New Revision: 183336

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=183336
Log:
	PR target/49868
	PR target/50887
	* doc/extend.texi (Named Address Spaces): Split into subsections.
	(AVR Named Address Spaces): New subsection.
	(M32C Named Address Spaces): New subsection.
	(RL78 Named Address Spaces): New subsection.
	(SPU Named Address Spaces): New subsection.
	(Variable Attributes): New anchor "AVR Variable Attributes".
	(AVR Variable Attributes): Rewrite and avoid wording
	"address space" in this context.
	* doc/invoke.texi (AVR Options): Rewrite and add documentation
	for -maccumulate-args, -mbranch-cost=, -mrelax, -mshort-calls.
	(AVR Built-in Macros): New subsubsection therein.
	* doc/md.texi (AVR constraints): Remove "C04", "R".


Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/doc/extend.texi
    trunk/gcc/doc/invoke.texi
    trunk/gcc/doc/md.texi
Comment 13 Georg-Johann Lay 2012-01-20 12:34:37 UTC
Clodes with the documentation
Comment 14 Georg-Johann Lay 2012-01-24 12:38:59 UTC
Author: gjl
Date: Tue Jan 24 12:38:52 2012
New Revision: 183473

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=183473
Log:
	PR target/49868
	* doc/extend.texi (AVR Named Address Spaces): Move sample code up.
	Remove note on size/offset limitation.
	(AVR Variable Attributes): Add example how to read data located
	with progmem.  Refer to named address spaces.
	* doc/invoke.texi (AVR Options): Fix typo.


Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/doc/extend.texi
    trunk/gcc/doc/invoke.texi
Comment 15 Georg-Johann Lay 2012-01-25 18:17:14 UTC
Author: gjl
Date: Wed Jan 25 18:17:07 2012
New Revision: 183529

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=183529
Log:
	PR target/49868
	Rename __pgm to __flash.
	Rename __pgm1 to __flash1.
	Rename __pgm2 to __flash2.
	Rename __pgm3 to __flash3.
	Rename __pgm4 to __flash4.
	Rename __pgm5 to __flash5.
	Rename __pgmx to __memx.
	* doc/extend.texi (AVR Named Address Spaces)
	Rename address space names as indicated above.
	* config/avr/avr.c (avr_addrspace): Ditto.
	* config/avr/avr-protos.h
	(avr_mem_pgmx_p): Rename to avr_mem_memx_p.
	(avr_mem_pgm_p): Rename to avr_mem_flash_p.
	* config/avr/predicates.md: Ditto.
	* config/avr/avr.c Ditto, and
	(avr_decl_pgmx_p): Rename to avr_decl_memx_p.
	(avr_decl_pgm_p): Rename to avr_decl_flash_p.
	* config/avr/avr.h (ADDR_SPACE_PGM): Rename to ADDR_SPACE_FLASH.
	(ADDR_SPACE_PGM1): Rename to ADDR_SPACE_FLASH1.
	(ADDR_SPACE_PGM2): Rename to ADDR_SPACE_FLASH2.
	(ADDR_SPACE_PGM3): Rename to ADDR_SPACE_FLASH3.
	(ADDR_SPACE_PGM4): Rename to ADDR_SPACE_FLASH4.
	(ADDR_SPACE_PGM5): Rename to ADDR_SPACE_FLASH5.
	(ADDR_SPACE_PGMX): Rename to ADDR_SPACE_MEMX.
	* config/avr/avr.c: Ditto.
	* config/avr/avr.md: Ditto.


Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/avr/avr-protos.h
    trunk/gcc/config/avr/avr.c
    trunk/gcc/config/avr/avr.h
    trunk/gcc/config/avr/avr.md
    trunk/gcc/config/avr/predicates.md
    trunk/gcc/doc/extend.texi
Comment 16 Georg-Johann Lay 2012-02-28 08:44:14 UTC
Author: gjl
Date: Tue Feb 28 08:44:08 2012
New Revision: 184614

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=184614
Log:
	PR target/49868
	PR target/52261
	* doc/extend.texi (AVR Named Address Spaces): No more try to fix
	address spaces located outside of device flash.
	* config/avr/avr.h (base_arch_s): Remove field n_segments.
	(mcu_type_s): Add field n_flash.
	* config/avr/avr-devices.c (avr_arch_types): Remove .n_segments.
	Set .have_elpm and .have_elpmx to 1 for avrxmega4 and avrxmega5.
	(AVR_MCU): Add N_FLASH argument.
	* config/avr/avr-mcus.def (AVR_MCU): Add initializer for .n_flash.
	* config/avr/avr-c.c (avr_cpu_cpp_builtins): Only define built-in
	macro __FLASH<n> if that address space makes sense for the device.
	* config/avr/avr.c (avr_out_lpm): Don't try to fix address spaces
	outside of target flash.
	(avr_asm_named_section): Ditto.
	(avr_asm_select_section): Ditto.
	(avr_addr_space_convert): Ditto.
	(avr_emit_movmemhi): Ditto.
	(avr_nonconst_pointer_addrspace, avr_pgm_check_var_decl): Error if
	address space is outside of device flash.
	(avr_insert_attributes): Ditto.
	(avr_xload_libgcc_p): Use avr_current_device->n_flash instead of
	avr_current_arch->n_segments.


Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/avr/avr-c.c
    trunk/gcc/config/avr/avr-devices.c
    trunk/gcc/config/avr/avr-mcus.def
    trunk/gcc/config/avr/avr.c
    trunk/gcc/config/avr/avr.h
    trunk/gcc/doc/extend.texi
Comment 17 Georg-Johann Lay 2012-03-12 17:55:36 UTC
Author: gjl
Date: Mon Mar 12 17:55:30 2012
New Revision: 185255

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=185255
Log:
	PR target/49868
	* gcc.target/avr/torture/addr-space-1.h: New file.
	* gcc.target/avr/torture/addr-space-g.h: New test.
	* gcc.target/avr/torture/addr-space-0.h: New test.
	* gcc.target/avr/torture/addr-space-1.h: New test.
	* gcc.target/avr/torture/addr-space-x.h: New test.
	


Added:
    trunk/gcc/testsuite/gcc.target/avr/torture/addr-space-1-0.c
    trunk/gcc/testsuite/gcc.target/avr/torture/addr-space-1-1.c
    trunk/gcc/testsuite/gcc.target/avr/torture/addr-space-1-g.c
    trunk/gcc/testsuite/gcc.target/avr/torture/addr-space-1-x.c
    trunk/gcc/testsuite/gcc.target/avr/torture/addr-space-1.h
Modified:
    trunk/gcc/testsuite/ChangeLog
Comment 18 Georg-Johann Lay 2012-03-20 11:32:59 UTC
Author: gjl
Date: Tue Mar 20 11:32:54 2012
New Revision: 185570

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=185570
Log:
	PR target/49868
	* gcc.target/avr/torture/addr-space-2.h: New file.
	* gcc.target/avr/torture/addr-space-2-g.h: New test.
	* gcc.target/avr/torture/addr-space-2-0.h: New test.
	* gcc.target/avr/torture/addr-space-2-1.h: New test.
	* gcc.target/avr/torture/addr-space-2-x.h: New test.


Added:
    trunk/gcc/testsuite/gcc.target/avr/torture/addr-space-2-0.c
    trunk/gcc/testsuite/gcc.target/avr/torture/addr-space-2-1.c
    trunk/gcc/testsuite/gcc.target/avr/torture/addr-space-2-g.c
    trunk/gcc/testsuite/gcc.target/avr/torture/addr-space-2-x.c
    trunk/gcc/testsuite/gcc.target/avr/torture/addr-space-2.h
Modified:
    trunk/gcc/testsuite/ChangeLog
Comment 19 Georg-Johann Lay 2012-03-22 14:49:13 UTC
Author: gjl
Date: Thu Mar 22 14:48:55 2012
New Revision: 185696

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=185696
Log:
	Backport from 2012-03-20 mainline r185583.

	* gcc.target/avr/progmem.h (pgm_read_char): Define depending on
	__AVR_HAVE_LPMX__

	Backport from 2012-03-20 mainline r185570.

        PR target/49868
        * gcc.target/avr/torture/addr-space-2.h: New file.
        * gcc.target/avr/torture/addr-space-2-g.h: New test.
        * gcc.target/avr/torture/addr-space-2-0.h: New test.
        * gcc.target/avr/torture/addr-space-2-1.h: New test.
        * gcc.target/avr/torture/addr-space-2-x.h: New test.
	
	Backport from 2012-03-12 mainline r185255.

        PR target/49868
        * gcc.target/avr/torture/addr-space-1.h: New file.
        * gcc.target/avr/torture/addr-space-g.h: New test.
        * gcc.target/avr/torture/addr-space-0.h: New test.
        * gcc.target/avr/torture/addr-space-1.h: New test.
        * gcc.target/avr/torture/addr-space-x.h: New test.


Added:
    branches/gcc-4_7-branch/gcc/testsuite/gcc.target/avr/torture/addr-space-1-0.c
    branches/gcc-4_7-branch/gcc/testsuite/gcc.target/avr/torture/addr-space-1-1.c
    branches/gcc-4_7-branch/gcc/testsuite/gcc.target/avr/torture/addr-space-1-g.c
    branches/gcc-4_7-branch/gcc/testsuite/gcc.target/avr/torture/addr-space-1-x.c
    branches/gcc-4_7-branch/gcc/testsuite/gcc.target/avr/torture/addr-space-1.h
    branches/gcc-4_7-branch/gcc/testsuite/gcc.target/avr/torture/addr-space-2-0.c
    branches/gcc-4_7-branch/gcc/testsuite/gcc.target/avr/torture/addr-space-2-1.c
    branches/gcc-4_7-branch/gcc/testsuite/gcc.target/avr/torture/addr-space-2-g.c
    branches/gcc-4_7-branch/gcc/testsuite/gcc.target/avr/torture/addr-space-2-x.c
    branches/gcc-4_7-branch/gcc/testsuite/gcc.target/avr/torture/addr-space-2.h
Modified:
    branches/gcc-4_7-branch/gcc/testsuite/ChangeLog
    branches/gcc-4_7-branch/gcc/testsuite/gcc.target/avr/progmem.h