avr-libc-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[avr-libc-dev] [PATCH series] AVR: add support for new controller family


From: Björn Haase
Subject: [avr-libc-dev] [PATCH series] AVR: add support for new controller family to binutils, gcc and avr-libc
Date: Fri, 12 May 2006 13:44:19 +0200
User-agent: KMail/1.7.1

Hi,

Here is a patch series that adds support for a new controller family avr6 to 
the AVR ports of the gnu toolchain. This mail is cross-posted on the lists 
for the three affected projects since in their isolated form the patches are 
not really usefull:

binutils, gcc and avr-libc.

The attached patches are against current head of binutils, gccs and avr-libc. 

I'd like to classify them now to be "beta" versions rather than "alpha" and, 
IMO, they now should be compliant with the coding requirements for gcc and 
binutils for the respective head branches.

The basic problem for adding support for devices with > 64k Words of program
memory was that gcc would need more than the 2-Bytes that are currently used 
for program memory pointers. Using 4-Byte pointers would have resulted in 
very inefficient code and many changes in the avr backend of gcc.

The used method follows Marek's suggestions concerning the insertion of 
trampolines in the lower memory, if the target address happens not to be
reachable with 16 bit relocs. Most of the work, thus is at the binutils
side. GCC itself had mainly only to be teached to use different frame offset 
for the different devices. (The other changes were only necessary in order to 
enable bootloader support).


Two other general issues are fixed with gcc part of the present patch family:

1.) citing from the gcc info pages:

`-fdelete-null-pointer-checks'
     Use global dataflow analysis to identify and eliminate useless
     checks for null pointers.  The compiler assumes that dereferencing
     a null pointer would have halted the program.  If a pointer is
     checked after it has already been dereferenced, it cannot be null.

     In some environments, this assumption is not true, and programs can
     safely dereference null pointers.  Use
     `-fno-delete-null-pointer-checks' to disable this optimization for
     programs which depend on that behavior.

The AVR HW does not implement null-pointer-checks and this option now is
allways used for the avr target.

2.) make main a normal function

As discussed on the avr-libc-dev list, it is desirable that main() is just
an ordinary function like any other. The stack pointer initialization is
now only located in the gcrt1.S file of the avr-libc.


In comparison to the earlier patches posted on the avr-libc-dev list,
some bugs of the binutils part for that I had received private mail have now 
been fixed and Mareks suggestions concerning new relocs and bootloader 
support have been realized.

Note that concerning the avr-libc part the device specific header files for 
mega2560 and mega2561 still need some checking!

Yours,

Bjoern.


Summary of the changes to the binutils:

The template used for implementing the linker stubs for avr was the hppa
target. The difference here is, that we are having only one single
stub section that is created at the very beginning in the linker emulation
template. The placement of this stub section is controlled by it's name that
is included in the scripttemplate. It will be linked right after the 
section used for initializing the contents of the .data section.

In order to implement this, it was necessary to add support for a derived
linker hash table and an additional stub hash table.

avr-ld now is aware of new target specific options (documented in the
avr-ld --help output):

The two options

 --no-call-ret-replacement
 --pmem-wrap-around

control the linker relaxation optimizations. When defining 
--pm-wrap-around=16k,
the linker now tries to shorten jumps from absolute 14k to absolute 1k by 
using
the fact that the PC wraps around when using a shorter relative jump.
This is, IMO, useful only for the 16k and 32k devices. 

When using --no-stubs, the linker will not generate the jump stubs even when
using an avr6 device.

By use of the --debug-stubs and --debug-relax switches one could activate
debugging printout to stdout that is meant to be used when debugging avr-ld 
itself. It's not meant to be used by the user, but documented never the less.

In order to distinguish relocs where stubs should be generated and relocs 
where
no stubs should be generated, there are now two new ldi-type PM relocs that
carry the GS suffix instead of PM. Gas now knows of the directives gs() that
has the same functionality as pm(), only that it generates the GS relocs that
force the linker to generate stubs.


Change log for the binutils part:

2006-05-10  Bjoern Haase  <address@hidden> 

        * bfd/archures.c
        bfd_mach_avr6: add.
        
        * bfd/bfd-in2.h
        bfd_mach_avr6, BFD_RELOC_AVR_LO8_LDI_GS, BFD_RELOC_AVR_HI8_LDI_GS: add.

        * bfd/libbfd.h
        BFD_RELOC_AVR_LO8_LDI_GS, BFD_RELOC_AVR_HI8_LDI_GS: add.

        * bfd/reloc.c
        BFD_RELOC_AVR_LO8_LDI_GS, BFD_RELOC_AVR_HI8_LDI_GS: add.
        
        * bfd/cpu-avr.c
        bfd_mach_avr6: add.
        
        * bfd/elf32-avr.h: new file
        
        * bfd/elf32-avr.c
        Add elf32-avr.h to include list.
        elf32_avr_stub_hash_entry: add.
        elf32_avr_link_hash_table: add.
        avr_link_hash_table: add.
        avr_stub_hash_entry: add.
        avr_stub_hash_lookup: add.
        stub_hash_newfunc: add.
        elf32_avr_link_hash_table_create: add.
        elf32_avr_link_hash_table_free: add.
        avr_get_stub_addr: add.
        debug_relax, debug_stubs: add.
        avr_pc_wrap_around: Change type to bfd_vma.
        avr_replace_call_ret_sequences: add.
        avr_stub_is_required_for_16_bit_reloc: add.
        avr_final_link_relocate: 
        Add linker hashtable to parameter list. Use stub addr. if necessary.
        elf32_avr_relocate_section:
        Add linker hashtable to parameter list of avr_final_link_relocate.
        bfd_elf_avr_final_write_processing:
        Add handling for bfd_mach_avr6.
        elf32_avr_object_p:
        Add support for E_AVR_MACH_AVR6.
        elf32_avr_relax_delete_bytes:
        Iterate over all sections of a bfd when adjusting relocs addends.
        elf32_avr_relax_section:
        Use avr_replace_call_ret_sequences, recalculate size of stub section.
        avr_stub_name: add.
        avr_get_stub_addr: add.
        avr_get_stub_entry: add.
        avr_add_stub: add.
        avr_build_one_stub: add.
        avr_size_one_stub: add.
        elf32_avr_setup_params: add.
        elf32_avr_setup_section_lists: add.
        get_local_syms: add.
        elf32_avr_size_stubs: add.
        bfd_elf32_bfd_link_hash_table_create: add.
        bfd_elf32_bfd_link_hash_table_free: add
        
        * gas/config/tc-avr.c: add avr6, avr2560 and avr2561
        
        * gas/config/tc-avr.h:
        TC_VALIDATE_FIX: Don't generate fixups for PM type relocs
        
        * include/elf/avr.h
        E_AVR_MACH_AVR6, R_AVR_LO8_LDI_GS, R_AVR_HI8_LDI_GS: add.
        
        * ld/configure.tgt: Add avr6 to emulation list.
        
        * ld/Makefile.am, ld/Makefile.in:
        Add eavr6.o and corresponding rule.
        
        * ld/emulparams/avr6.sh: add
        
        * ld/emulparams/avrX.sh:
        TEMPLATE_NAME: Change to elf32 instead of generic.
        EXTRA_EM_FILE: add reference to new avrelf.
        
        * ld/scripttempl/avr.sc: Add ".trampolines" section.
        
        * ld/emultampl/avrelf.em: New file.


        Summary of the changes to gcc:

There is now a new variable holding the size of the PC and the frame
offsets are adjusted accordingly.
The tablejump insn now use eijmp instead of ijmp for the
3-Byte PC devices and so does libgcc.S. 
New builtin defines for __AVR_3_BYTE_PC__ and _AVR_2_BYTE_PC__ are now
available.
The option -fno-delete-null-pointer-checks has been added to the option
list, since 0 is a perfectly legal address for some avr devices.
main() now is a normal function without any special handling.


Change log for the gcc part:

2006-05-10  Bjoern Haase  <address@hidden> 

        * gcc/gcc/config/avr/avr.c:
        avr_pc_size: add
        struct base_arch: add three_byte_pc to struct.
        struct base_arch_s: add new struct member and add avr6 entry.
        struct mcu_type_s: add atmega2560 and atmega2561.
        avr_override_options: set avr_pc_size to 3 if necessary.
        initial_elimination_offset: use (avr_pc_size) instead of fixed value 2.
        avr_output_function_prologue: use gs() asm specifier instead of pm()
        print_operand_address: ditto.
        avr_assemble_integer: ditto.
        avr_output_addr_vec_elt: ditto.
        avr_output_function_prologue: handle main() like any normal function.
        avr_output_function_epilogue: ditto.

        * gcc/gcc/config/avr/avr.h:
        CC1_SPEC: add -fno-delete-null-pointer-checks to list.
        CC1PLUS_SPEC: ditto.
        LINK_SPEC: add atmega2560 and atmega2561
        CRT_BINUTILS_SPEC: 
        add atmega2560 (crtm2560.o) and atmega2561 (crtm2561.o).
        TARGET_CPU_CPP_BUILTINS: add __AVR_3_BYTE_PC__ and __AVR_2_BYTE_PC__
        AVR_3_BYTE_PC: add.
        AVR_2_BYTE_PC: add.
        
        * gcc/gcc/config/avr/libgcc.S
        
        * gcc/gcc/config/avr/avr.md
        call_insn: use eicall instead of icall for 3 byte PC devices.
        call_value_insn: ditto.
        indirect_jump: use only if AVR_2_BYTE_PC
        tablejump_enh: ditto.
        tablejump: ditto.
        indirect_jump_avr6: add.
        tablejump_avr6: add.    

        * gcc/gcc/config/avr/t-avr:
        MULITLIB_OPTIONS: add avr6 architecture to list
        MULITLIB_DIRNAMES: ditto. 
        MULTILIB_MATCHES: add atmega2560 and atmega2561 to list.


Changes in avr-libc:

The build script and bootstrap scripts have been extended to generate the 
required directories and files for the avr6 family devices.
For the avr6 devices EIND is now initialized in the .init2 step of gcrt1.S and
gcrt1.S is now aware of main() being a normal function.


Change Log for avr-libc:

2006-05-10  Bjoern Haase  <address@hidden> 

        * devtools/gen-avr-lib-tree.sh:
        AVR6_DEV_INFO: add.
        AVR_ARH_INFO: add AVR6_DEV_INFO.

        * configure.ac:
        AC_CONFIG_FILES: add avr6/Makefile, atmega2560 and atmega2561.

        * include/avr/io.h:
        add "#include"s for atmega2560 and atmega2561.

        * include/avr/iom2560.h: New file. Register locations are untested.
        * include/avr/iom2561.h: New file. Register locations are untested.

        * crt1/gcrt1.S:
        init2: add EIND initialization to hh8(pm(__vectors))
        init9: use XCALL main instead of XJMP main. Add XJMP exit

Attachment: mega_256x_avrlibc_5.patch
Description: Text Data

Attachment: mega_256x_gcc_5.patch
Description: Text Data

Attachment: mega_256x_binutils_5.patch
Description: Text Data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]