[Patch]: PR49868: Named address space support for AVR

Georg-Johann Lay avr@gjlay.de
Thu Oct 6 15:16:00 GMT 2011


This patch adds named address space support to read data from flash (aka.
progmem) to target AVR.

The patch has two parts:

The first part is a repost of Ulrich's work from
   http://gcc.gnu.org/ml/gcc/2011-08/msg00131.html
with the needed changes to ./gcc and ./gcc/doc

This patch is needed because the target hooks MODE_CODE_BASE_REG_CLASS and
REGNO_MODE_CODE_OK_FOR_BASE_P don't distinguish between different address
spaces.  Ulrich's patch adds respective support to these hooks.

The second part is the AVR dependent part that adds __pgm as address space
qualifier for address space AS1.

The AVR part is just the worker code.  If there is agreement that AS support
for AVR is okay in principle and Ulrich's work will go into GCC, I will supply
test programs and updates to the user manual, of course.

The major drawbacks of the current AS implementation are:

- It works only for C.
  For C++, a language extension would be needed as indicated in
     ISO/IEC DTR 18037
     Annex F - C++ Compatibility and Migration issues
     F.2 Multiple Address Spaces Support

- Register allocation does not a good job. AS1 can only be addressed
  byte-wise by one single address register (Z) as per *Z or *Z++.

The AVR part does several things:

- It locates data in AS1 into appropriate section, i.e. somewhere in
  .progmem

- It does early sanity checks to ensure that __pgm is always accompanied
  with const so that writing to AS1 in not possible.

- It prints LPM instructions to access flash memory.

Hint on how to proceed with this are appreciated, likewise I'd like to know if
such extension is not appropriate so that I can focus on other stuff or if
there are hints to improve the patch.

Thanks, Johann

	PR target/49868
	* config/avr/avr.h (ADDR_SPACE_PGM): New define for address space AS1.
	(REGISTER_TARGET_PRAGMAS): New define.
	(MODE_CODE_BASE_REG_CLASS): New define.
	(REGNO_MODE_CODE_OK_FOR_BASE_P): New define.
	(BASE_REG_CLASS): Remove define.
	(REGNO_OK_FOR_BASE_P): Remove define.
	(REG_OK_FOR_BASE_NOSTRICT_P): Remove define.
	(REG_OK_FOR_BASE_STRICT_P): Remove define.
	* config/avr/avr-protos.h (avr_mem_pgm_p): New prototype.
	(avr_register_target_pragmas): New prototype.
	(avr_mode_code_base_reg_class): New prototype.
	(avr_regno_mode_code_ok_for_base_p): New prototype.
	(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 (avr_register_target_pragmas): New function.
	Register address space AS1 as "__pgm".
	* config/avr/avr.c: Include "c-family/c-common.h".
	(TARGET_LEGITIMATE_ADDRESS_P): Don't define this macro any more.
	(TARGET_LEGITIMIZE_ADDRESS): Don't define this macro any more.
	(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): New function.
	(avr_regno_mode_code_ok_for_base_p): New function.
	(lpm_addr_reg_rtx, lpm_reg_rtx): New static GTYed variables.
	(avr_decl_pgm_p): New static function.
	(avr_mem_pgm_p): New function.
	(avr_reg_ok_for_addr): New static function.
	(avr_legitimate_address_p): Use it.
	(avr_asm_len): Return "" instead of void.
	(avr_out_lpm_no_lpmx): New static function.
	(avr_out_lpm): New static function.
	(output_movqi, output_movhi, output_movsisf): Call avr_out_lpm to
	handle loads from progmem.
	(avr_progmem_p): Test if decl is in AS1.
	(avr_pgm_pointer_const_p): New static function.
	(avr_pgm_check_var_decl): New static function.
	(avr_insert_attributes): Use it.  Change error message to report
	cause when code wants to write to AS1.
	(avr_section_type_flags): Unset section flag SECTION_BSS for
	data in progmem.
	* config/avr/avr.md (LPM_REGNO): New define_constants.
	(movqi, movhi, movsi, movsf): Skip if code would write to AS1.
	(movmemhi): Ditto.  Propagate address space information to newly
	created MEM.
	(split-lpmx): New split.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pgm-v6-avr.diff
Type: text/x-patch
Size: 37393 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20111006/782eae1b/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pgm-v6-weigand.diff
Type: text/x-patch
Size: 43228 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20111006/782eae1b/attachment-0001.bin>


More information about the Gcc-patches mailing list