From e130b681c43ee2215512ffcf6cadcbc4487e96e6 Mon Sep 17 00:00:00 2001 From: Carmelo Amoroso Date: Fri, 16 Nov 2007 14:26:46 +0000 Subject: Added AVR32 support to uClibc. Signed-off-by: Hans-Christian Egtvedt --- Rules.mak | 6 + extra/Configs/Config.avr32 | 31 ++++ extra/Configs/Config.in | 7 + extra/Configs/defconfigs/avr32 | 1 + include/elf.h | 51 ++++++ ldso/include/dl-string.h | 3 +- ldso/ldso/avr32/dl-debug.h | 45 +++++ ldso/ldso/avr32/dl-startup.h | 112 ++++++++++++ ldso/ldso/avr32/dl-syscalls.h | 6 + ldso/ldso/avr32/dl-sysdep.h | 105 +++++++++++ ldso/ldso/avr32/elfinterp.c | 193 +++++++++++++++++++++ ldso/ldso/avr32/resolve.S | 28 +++ ldso/ldso/dl-startup.c | 4 +- libc/string/avr32/Makefile | 26 +++ libc/string/avr32/bcopy.S | 26 +++ libc/string/avr32/bzero.S | 22 +++ libc/string/avr32/memcmp.S | 61 +++++++ libc/string/avr32/memcpy.S | 111 ++++++++++++ libc/string/avr32/memmove.S | 116 +++++++++++++ libc/string/avr32/memset.S | 70 ++++++++ libc/string/avr32/strcmp.S | 91 ++++++++++ libc/string/avr32/strlen.S | 62 +++++++ libc/sysdeps/linux/avr32/Makefile | 25 +++ libc/sysdeps/linux/avr32/Makefile.arch | 13 ++ libc/sysdeps/linux/avr32/__longjmp.S | 21 +++ libc/sysdeps/linux/avr32/bits/atomic.h | 120 +++++++++++++ libc/sysdeps/linux/avr32/bits/byteswap.h | 70 ++++++++ libc/sysdeps/linux/avr32/bits/endian.h | 7 + libc/sysdeps/linux/avr32/bits/fcntl.h | 165 ++++++++++++++++++ libc/sysdeps/linux/avr32/bits/kernel_stat.h | 67 +++++++ libc/sysdeps/linux/avr32/bits/kernel_types.h | 55 ++++++ libc/sysdeps/linux/avr32/bits/mman.h | 103 +++++++++++ libc/sysdeps/linux/avr32/bits/setjmp.h | 30 ++++ libc/sysdeps/linux/avr32/bits/stackinfo.h | 28 +++ libc/sysdeps/linux/avr32/bits/syscalls.h | 143 +++++++++++++++ .../linux/avr32/bits/uClibc_arch_features.h | 45 +++++ libc/sysdeps/linux/avr32/bits/wordsize.h | 1 + libc/sysdeps/linux/avr32/brk.c | 31 ++++ libc/sysdeps/linux/avr32/bsd-_setjmp.S | 16 ++ libc/sysdeps/linux/avr32/bsd-setjmp.S | 16 ++ libc/sysdeps/linux/avr32/clone.c | 41 +++++ libc/sysdeps/linux/avr32/crt1.S | 97 +++++++++++ libc/sysdeps/linux/avr32/crti.S | 26 +++ libc/sysdeps/linux/avr32/crtn.S | 14 ++ libc/sysdeps/linux/avr32/mmap.c | 33 ++++ libc/sysdeps/linux/avr32/setjmp.S | 29 ++++ libc/sysdeps/linux/avr32/sigaction.c | 59 +++++++ libc/sysdeps/linux/avr32/sigrestorer.S | 15 ++ libc/sysdeps/linux/avr32/sys/elf.h | 26 +++ libc/sysdeps/linux/avr32/sys/procfs.h | 123 +++++++++++++ libc/sysdeps/linux/avr32/sys/ucontext.h | 90 ++++++++++ libc/sysdeps/linux/avr32/sys/user.h | 46 +++++ libc/sysdeps/linux/avr32/syscall.S | 71 ++++++++ libc/sysdeps/linux/avr32/vfork.S | 58 +++++++ .../linuxthreads.old/sysdeps/avr32/pt-machine.h | 73 ++++++++ libpthread/linuxthreads/sysdeps/avr32/pt-machine.h | 73 ++++++++ utils/ldd.c | 5 + 57 files changed, 3010 insertions(+), 2 deletions(-) create mode 100644 extra/Configs/Config.avr32 create mode 100644 extra/Configs/defconfigs/avr32 create mode 100644 ldso/ldso/avr32/dl-debug.h create mode 100644 ldso/ldso/avr32/dl-startup.h create mode 100644 ldso/ldso/avr32/dl-syscalls.h create mode 100644 ldso/ldso/avr32/dl-sysdep.h create mode 100644 ldso/ldso/avr32/elfinterp.c create mode 100644 ldso/ldso/avr32/resolve.S create mode 100644 libc/string/avr32/Makefile create mode 100644 libc/string/avr32/bcopy.S create mode 100644 libc/string/avr32/bzero.S create mode 100644 libc/string/avr32/memcmp.S create mode 100644 libc/string/avr32/memcpy.S create mode 100644 libc/string/avr32/memmove.S create mode 100644 libc/string/avr32/memset.S create mode 100644 libc/string/avr32/strcmp.S create mode 100644 libc/string/avr32/strlen.S create mode 100644 libc/sysdeps/linux/avr32/Makefile create mode 100644 libc/sysdeps/linux/avr32/Makefile.arch create mode 100644 libc/sysdeps/linux/avr32/__longjmp.S create mode 100644 libc/sysdeps/linux/avr32/bits/atomic.h create mode 100644 libc/sysdeps/linux/avr32/bits/byteswap.h create mode 100644 libc/sysdeps/linux/avr32/bits/endian.h create mode 100644 libc/sysdeps/linux/avr32/bits/fcntl.h create mode 100644 libc/sysdeps/linux/avr32/bits/kernel_stat.h create mode 100644 libc/sysdeps/linux/avr32/bits/kernel_types.h create mode 100644 libc/sysdeps/linux/avr32/bits/mman.h create mode 100644 libc/sysdeps/linux/avr32/bits/setjmp.h create mode 100644 libc/sysdeps/linux/avr32/bits/stackinfo.h create mode 100644 libc/sysdeps/linux/avr32/bits/syscalls.h create mode 100644 libc/sysdeps/linux/avr32/bits/uClibc_arch_features.h create mode 100644 libc/sysdeps/linux/avr32/bits/wordsize.h create mode 100644 libc/sysdeps/linux/avr32/brk.c create mode 100644 libc/sysdeps/linux/avr32/bsd-_setjmp.S create mode 100644 libc/sysdeps/linux/avr32/bsd-setjmp.S create mode 100644 libc/sysdeps/linux/avr32/clone.c create mode 100644 libc/sysdeps/linux/avr32/crt1.S create mode 100644 libc/sysdeps/linux/avr32/crti.S create mode 100644 libc/sysdeps/linux/avr32/crtn.S create mode 100644 libc/sysdeps/linux/avr32/mmap.c create mode 100644 libc/sysdeps/linux/avr32/setjmp.S create mode 100644 libc/sysdeps/linux/avr32/sigaction.c create mode 100644 libc/sysdeps/linux/avr32/sigrestorer.S create mode 100644 libc/sysdeps/linux/avr32/sys/elf.h create mode 100644 libc/sysdeps/linux/avr32/sys/procfs.h create mode 100644 libc/sysdeps/linux/avr32/sys/ucontext.h create mode 100644 libc/sysdeps/linux/avr32/sys/user.h create mode 100644 libc/sysdeps/linux/avr32/syscall.S create mode 100644 libc/sysdeps/linux/avr32/vfork.S create mode 100644 libpthread/linuxthreads.old/sysdeps/avr32/pt-machine.h create mode 100644 libpthread/linuxthreads/sysdeps/avr32/pt-machine.h diff --git a/Rules.mak b/Rules.mak index 5be6bbed4..33bc7ab99 100644 --- a/Rules.mak +++ b/Rules.mak @@ -317,6 +317,12 @@ ifeq ($(TARGET_ARCH),frv) UCLIBC_LDSO=ld.so.1 endif +ifeq ($(strip $(TARGET_ARCH)),avr32) + CPU_CFLAGS-$(CONFIG_AVR32_AP7) += -march=ap + CPU_CFLAGS-$(CONFIG_LINKRELAX) += -mrelax + CPU_LDFLAGS-$(CONFIG_LINKRELAX) += --relax +endif + # Keep the check_gcc from being needlessly executed ifndef PIEFLAG ifneq ($(UCLIBC_BUILD_PIE),y) diff --git a/extra/Configs/Config.avr32 b/extra/Configs/Config.avr32 new file mode 100644 index 000000000..0706e7ff9 --- /dev/null +++ b/extra/Configs/Config.avr32 @@ -0,0 +1,31 @@ +# +# For a description of the syntax of this configuration file, +# see extra/config/Kconfig-language.txt +# + +config TARGET_ARCH + string + default "avr32" + +config FORCE_OPTIONS_FOR_ARCH + bool + default y + select ARCH_BIG_ENDIAN + select FORCE_SHAREABLE_TEXT_SEGMENTS + +config ARCH_CFLAGS + string + +choice + prompt "Target CPU Type" + default CONFIG_AVR32_AP7 + +config CONFIG_AVR32_AP7 + bool "AVR32 AP7" + select ARCH_HAS_MMU + +endchoice + +config LINKRELAX + bool "Enable linker optimizations" + default y diff --git a/extra/Configs/Config.in b/extra/Configs/Config.in index cc23a98ad..eb5bf15f2 100644 --- a/extra/Configs/Config.in +++ b/extra/Configs/Config.in @@ -16,6 +16,9 @@ config TARGET_alpha config TARGET_arm bool "arm" +config TARGET_avr32 + bool "avr32" + config TARGET_bfin bool "bfin" @@ -92,6 +95,10 @@ if TARGET_arm source "extra/Configs/Config.arm" endif +if TARGET_avr32 +source "extra/Configs/Config.avr32" +endif + if TARGET_bfin source "extra/Configs/Config.bfin" endif diff --git a/extra/Configs/defconfigs/avr32 b/extra/Configs/defconfigs/avr32 new file mode 100644 index 000000000..0b890a291 --- /dev/null +++ b/extra/Configs/defconfigs/avr32 @@ -0,0 +1 @@ +TARGET_avr32=y diff --git a/include/elf.h b/include/elf.h index eb298292f..4611f3f29 100644 --- a/include/elf.h +++ b/include/elf.h @@ -354,6 +354,8 @@ typedef struct /* NIOS magic number - no EABI available. */ #define EM_NIOS32 0xFEBB +#define EM_AVR32 0x18ad + /* V850 backend magic number. Written in the absense of an ABI. */ #define EM_CYGNUS_V850 0x9080 @@ -2830,6 +2832,55 @@ typedef Elf32_Addr Elf32_Conflict; /* Keep this the last entry. */ #define R_V850_NUM 25 +/* Atmel AVR32 relocations. */ +#define R_AVR32_NONE 0 +#define R_AVR32_32 1 +#define R_AVR32_16 2 +#define R_AVR32_8 3 +#define R_AVR32_32_PCREL 4 +#define R_AVR32_16_PCREL 5 +#define R_AVR32_8_PCREL 6 +#define R_AVR32_DIFF32 7 +#define R_AVR32_DIFF16 8 +#define R_AVR32_DIFF8 9 +#define R_AVR32_GOT32 10 +#define R_AVR32_GOT16 11 +#define R_AVR32_GOT8 12 +#define R_AVR32_21S 13 +#define R_AVR32_16U 14 +#define R_AVR32_16S 15 +#define R_AVR32_8S 16 +#define R_AVR32_8S_EXT 17 +#define R_AVR32_22H_PCREL 18 +#define R_AVR32_18W_PCREL 19 +#define R_AVR32_16B_PCREL 20 +#define R_AVR32_16N_PCREL 21 +#define R_AVR32_14UW_PCREL 22 +#define R_AVR32_11H_PCREL 23 +#define R_AVR32_10UW_PCREL 24 +#define R_AVR32_9H_PCREL 25 +#define R_AVR32_9UW_PCREL 26 +#define R_AVR32_HI16 27 +#define R_AVR32_LO16 28 +#define R_AVR32_GOTPC 29 +#define R_AVR32_GOTCALL 30 +#define R_AVR32_LDA_GOT 31 +#define R_AVR32_GOT21S 32 +#define R_AVR32_GOT18SW 33 +#define R_AVR32_GOT16S 34 +#define R_AVR32_GOT7UW 35 +#define R_AVR32_32_CPENT 36 +#define R_AVR32_CPCALL 37 +#define R_AVR32_16_CP 38 +#define R_AVR32_9W_CP 39 +#define R_AVR32_RELATIVE 40 +#define R_AVR32_GLOB_DAT 41 +#define R_AVR32_JMP_SLOT 42 +#define R_AVR32_ALIGN 43 +#define R_AVR32_NUM 44 + +/* AVR32 dynamic tags */ +#define DT_AVR32_GOTSZ 0x70000001 /* Total size of GOT in bytes */ /* Renesas H8/300 Relocations */ #define R_H8_NONE 0 diff --git a/ldso/include/dl-string.h b/ldso/include/dl-string.h index 32c5bf83a..4a35a1c8d 100644 --- a/ldso/include/dl-string.h +++ b/ldso/include/dl-string.h @@ -285,7 +285,8 @@ static __always_inline char * _dl_simple_ltoahex(char * local, unsigned long i) /* On some arches constant strings are referenced through the GOT. * This requires that load_addr must already be defined... */ #if defined(mc68000) || defined(__arm__) || defined(__thumb__) || \ - defined(__mips__) || defined(__sh__) || defined(__powerpc__) + defined(__mips__) || defined(__sh__) || defined(__powerpc__) || \ + defined(__avr32__) # define CONSTANT_STRING_GOT_FIXUP(X) \ if ((X) < (const char *) load_addr) (X) += load_addr # define NO_EARLY_SEND_STDERR diff --git a/ldso/ldso/avr32/dl-debug.h b/ldso/ldso/avr32/dl-debug.h new file mode 100644 index 000000000..fe35539f6 --- /dev/null +++ b/ldso/ldso/avr32/dl-debug.h @@ -0,0 +1,45 @@ +/* + * AVR32 ELF shared libary loader support + * + * Copyright (C) 2005-2007 Atmel Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. The name of the above contributors may not be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +static const char *_dl_reltypes_tab[] = { + "R_AVR32_NONE", + "R_AVR32_32", "R_AVR32_16", "R_AVR32_8", + "R_AVR32_32_PCREL", "R_AVR32_16_PCREL", "R_AVR32_8_PCREL", + "R_AVR32_DIFF32", "R_AVR32_DIFF16", "R_AVR32_DIFF8", + "R_AVR32_GOT32", "R_AVR32_GOT16", "R_AVR32_GOT8", + "R_AVR32_21S", "R_AVR32_16U", "R_AVR32_16S", "R_AVR32_8S", "R_AVR32_8S_EXT", + "R_AVR32_22H_PCREL", "R_AVR32_18W_PCREL", "R_AVR32_16B_PCREL", + "R_AVR32_16N_PCREL", "R_AVR32_14UW_PCREL", "R_AVR32_11H_PCREL", + "R_AVR32_10UW_PCREL", "R_AVR32_9H_PCREL", "R_AVR32_9UW_PCREL", + "R_AVR32_HI16", "R_AVR32_LO16", + "R_AVR32_GOTPC", "R_AVR32_GOTCALL", "R_AVR32_LDA_GOT", + "R_AVR32_GOT21S", "R_AVR32_GOT18SW", "R_AVR32_GOT16S", "R_AVR32_GOT7UW", + "R_AVR32_32_CPENT", "R_AVR32_CPCALL", "R_AVR32_16_CP", "R_AVR32_9W_CP", + "R_AVR32_RELATIVE", "R_AVR32_GLOB_DAT", "R_AVR32_JMP_SLOT", + "R_AVR32_ALIGN", +}; diff --git a/ldso/ldso/avr32/dl-startup.h b/ldso/ldso/avr32/dl-startup.h new file mode 100644 index 000000000..2280b2629 --- /dev/null +++ b/ldso/ldso/avr32/dl-startup.h @@ -0,0 +1,112 @@ +/* + * Architecture specific code used by dl-startup.c + * + * Copyright (C) 2005-2007 Atmel Corporation + * + * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. + */ + +/* This is the library loader's main entry point. Let _dl_boot2 do its + * initializations and jump to the application's entry point + * afterwards. */ +asm( " .text\n" + " .global _start\n" + " .type _start,@function\n" + "_start:\n" + /* All arguments are on the stack initially */ + " mov r12, sp\n" + " rcall _dl_start\n" + /* Returns user entry point in r12. Save it. */ + " mov r0, r12\n" + /* We're PIC, so get the Global Offset Table */ + " lddpc r6, .L_GOT\n" + ".L_RGOT:\n" + " rsub r6, pc\n" + /* Adjust argc and argv according to _dl_skip_args */ + " ld.w r1, r6[_dl_skip_args@got]\n" + " ld.w r1, r1[0]\n" + " ld.w r2, sp++\n" + " sub r2, r1\n" + " add sp, sp, r1 << 2\n" + " st.w --sp, r2\n" + /* Load the finalizer function */ + " ld.w r12, r6[_dl_fini@got]\n" + /* Jump to the user's entry point */ + " mov pc, r0\n\n" + + " .align 2\n" + ".L_GOT:" + " .long .L_RGOT - _GLOBAL_OFFSET_TABLE_\n" + " .size _start, . - _start\n" + " .previous\n"); + +/* Get a pointer to the argv array. On many platforms this can be just + * the address if the first argument, on other platforms we need to + * do something a little more subtle here. */ +#define GET_ARGV(ARGVP, ARGS) ARGVP = ((unsigned long *)ARGS + 1) + + +/* We can't call functions before the GOT has been initialized */ +#define NO_FUNCS_BEFORE_BOOTSTRAP + +/* + * Relocate the GOT during dynamic loader bootstrap. This will add + * the load address to all entries in the GOT, which is necessary + * because the linker doesn't generate R_AVR32_RELATIVE relocs for the + * GOT. + */ +static __always_inline +void PERFORM_BOOTSTRAP_GOT(struct elf_resolve *tpnt) +{ + Elf32_Addr i, nr_got; + register Elf32_Addr *__r6 __asm__("r6"); + Elf32_Addr *got = __r6; + + nr_got = tpnt->dynamic_info[DT_AVR32_GOTSZ_IDX] / sizeof(*got); + for (i = 2; i < nr_got; i++) + got[i] += tpnt->loadaddr; +} + +#define PERFORM_BOOTSTRAP_GOT(tpnt) PERFORM_BOOTSTRAP_GOT(tpnt) + +/* Handle relocation of the symbols in the dynamic loader. */ +static __always_inline +void PERFORM_BOOTSTRAP_RELOC(ELF_RELOC *rpnt, unsigned long *reloc_addr, + unsigned long symbol_addr, + unsigned long load_addr, Elf32_Sym *symtab) +{ + switch(ELF32_R_TYPE(rpnt->r_info)) { + case R_AVR32_NONE: + break; + case R_AVR32_GLOB_DAT: + case R_AVR32_JMP_SLOT: + *reloc_addr = symbol_addr; + break; + case R_AVR32_RELATIVE: + SEND_STDERR_DEBUG("Applying RELATIVE relocation: "); + SEND_ADDRESS_STDERR_DEBUG(load_addr, 0); + SEND_STDERR_DEBUG(" + "); + SEND_ADDRESS_STDERR_DEBUG(rpnt->r_addend, 1); + *reloc_addr = load_addr + rpnt->r_addend; + break; + default: + SEND_STDERR("BOOTSTRAP_RELOC: unhandled reloc_type "); + SEND_NUMBER_STDERR(ELF32_R_TYPE(rpnt->r_info), 1); + SEND_STDERR("REL, SYMBOL, LOAD: "); + SEND_ADDRESS_STDERR(reloc_addr, 0); + SEND_STDERR(", "); + SEND_ADDRESS_STDERR(symbol_addr, 0); + SEND_STDERR(", "); + SEND_ADDRESS_STDERR(load_addr, 1); + _dl_exit(1); + } +} + +/* Transfer control to the user's application, once the dynamic loader + * is done. This routine has to exit the current function, then call + * the _dl_elf_main function. + * + * Since our _dl_boot will simply call whatever is returned by + * _dl_boot2, we can just return the address we're supposed to + * call. */ +#define START() return _dl_elf_main; diff --git a/ldso/ldso/avr32/dl-syscalls.h b/ldso/ldso/avr32/dl-syscalls.h new file mode 100644 index 000000000..996bb87c6 --- /dev/null +++ b/ldso/ldso/avr32/dl-syscalls.h @@ -0,0 +1,6 @@ +/* We can't use the real errno in ldso, since it has not yet + * been dynamicly linked in yet. */ +#include "sys/syscall.h" +extern int _dl_errno; +#undef __set_errno +#define __set_errno(X) {(_dl_errno) = (X);} diff --git a/ldso/ldso/avr32/dl-sysdep.h b/ldso/ldso/avr32/dl-sysdep.h new file mode 100644 index 000000000..270800ade --- /dev/null +++ b/ldso/ldso/avr32/dl-sysdep.h @@ -0,0 +1,105 @@ +/* + * Various assembly language/system dependent hacks that are required + * so that we can minimize the amount of platform specific code. + * + * Copyright (C) 2004-2007 Atmel Corporation + * + * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. + */ + +/* Define this if the system uses RELOCA. */ +#define ELF_USES_RELOCA + +#include + +#define ARCH_NUM 1 +#define DT_AVR32_GOTSZ_IDX (DT_NUM + OS_NUM) + +#define ARCH_DYNAMIC_INFO(dpnt, dynamic, debug_addr) \ + do { \ + if (dpnt->d_tag == DT_AVR32_GOTSZ) \ + dynamic[DT_AVR32_GOTSZ_IDX] = dpnt->d_un.d_val; \ + } while (0) + +/* Initialization sequence for the application/library GOT. */ +#define INIT_GOT(GOT_BASE,MODULE) \ + do { \ + unsigned long i, nr_got; \ + \ + GOT_BASE[0] = (unsigned long) _dl_linux_resolve; \ + GOT_BASE[1] = (unsigned long) MODULE; \ + \ + /* Add load address displacement to all GOT entries */ \ + nr_got = MODULE->dynamic_info[DT_AVR32_GOTSZ_IDX] / 4; \ + for (i = 2; i < nr_got; i++) \ + GOT_BASE[i] += (unsigned long)MODULE->loadaddr; \ + } while (0) + +#define do_rem(result, n, base) ((result) = (n) % (base)) + +/* Here we define the magic numbers that this dynamic loader should accept */ +#define MAGIC1 EM_AVR32 +#undef MAGIC2 + +/* Used for error messages */ +#define ELF_TARGET "AVR32" + +unsigned long _dl_linux_resolver(unsigned long got_offset, unsigned long *got); + +/* 4096 bytes alignment */ +#define PAGE_ALIGN 0xfffff000 +#define ADDR_ALIGN 0xfff +#define OFFS_ALIGN 0x7ffff000 + +#define elf_machine_type_class(type) \ + ((type == R_AVR32_JMP_SLOT) * ELF_RTYPE_CLASS_PLT) + +/* AVR32 doesn't need any COPY relocs */ +#define DL_NO_COPY_RELOCS + +/* Return the link-time address of _DYNAMIC. Conveniently, this is the + first element of the GOT. This must be inlined in a function which + uses global data. */ +static inline Elf32_Addr +elf_machine_dynamic (void) +{ + register Elf32_Addr *got asm ("r6"); + return *got; +} + +/* Return the run-time load address of the shared object. */ +static inline Elf32_Addr +elf_machine_load_address (void) +{ + extern void __dl_start asm("_dl_start"); + Elf32_Addr got_addr = (Elf32_Addr) &__dl_start; + Elf32_Addr pcrel_addr; + + asm (" lddpc %0, 2f\n" + "1: add %0, pc\n" + " rjmp 3f\n" + " .align 2\n" + "2: .long _dl_start - 1b\n" + "3:\n" + : "=r"(pcrel_addr) : : "cc"); + + return pcrel_addr - got_addr; +} + +/* + * Perform any RELATIVE relocations specified by DT_RELCOUNT. + * Currently, we don't use that tag, but we might in the future as + * this would reduce the startup time somewhat (although probably not by much). + */ +static inline void +elf_machine_relative (Elf32_Addr load_off, const Elf32_Addr rel_addr, + Elf32_Word relative_count) +{ + Elf32_Rela *rpnt = (void *)rel_addr; + + do { + Elf32_Addr *reloc_addr; + reloc_addr = (void *)(load_off + (rpnt++)->r_offset); + *reloc_addr = load_off + rpnt->r_addend; + } while (--relative_count); +} diff --git a/ldso/ldso/avr32/elfinterp.c b/ldso/ldso/avr32/elfinterp.c new file mode 100644 index 000000000..e236e4825 --- /dev/null +++ b/ldso/ldso/avr32/elfinterp.c @@ -0,0 +1,193 @@ +/* + * AVR32 ELF shared library loader suppport + * + * Copyright (C) 2004-2006 Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. The name of the above contributors may not be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +unsigned long _dl_linux_resolver(unsigned long got_offset, unsigned long *got) +{ + /* + * AVR32 currently does not do lazy relocation. + */ +#if 0 + struct elf_resolve *tpnt = (struct elf_resolve *)got[1]; + Elf32_Sym *sym; + unsigned long local_gotno; + unsigned long gotsym; + unsigned long new_addr; + char *strtab, *symname; + unsigned long *entry; + unsigned long sym_index = got_offset / 4; + + local_gotno = tpnt->dynamic_info[DT_AVR32_LOCAL_GOTNO]; + gotsym = tpnt->dynamic_info[DT_AVR32_GOTSYM]; + + sym = ((Elf32_Sym *)(tpnt->dynamic_info[DT_SYMTAB] + tpnt->loadaddr)) + + sym_index; + strtab = (char *)(tpnt->dynamic_info[DT_STRTAB] + tpnt->loadaddr); + symname = strtab + sym->st_name; + + new_addr = (unsigned long) _dl_find_hash(strtab + sym->st_name, + tpnt->symbol_scope, tpnt, + resolver); + + entry = (unsigned long *)(got + local_gotno + sym_index - gotsym); + *entry = new_addr; + + return new_addr; +#endif + return 0; +} + +static int +_dl_parse(struct elf_resolve *tpnt, struct dyn_elf *scope, + unsigned long rel_addr, unsigned long rel_size, + int (*reloc_func)(struct elf_resolve *tpnt, struct dyn_elf *scope, + Elf32_Rela *rpnt, Elf32_Sym *symtab, char *strtab)) +{ + Elf32_Sym *symtab; + Elf32_Rela *rpnt; + char *strtab; + int i; + + rpnt = (Elf32_Rela *)rel_addr; + rel_size /= sizeof(Elf32_Rela); + symtab = (Elf32_Sym *)tpnt->dynamic_info[DT_SYMTAB]; + strtab = (char *)tpnt->dynamic_info[DT_STRTAB]; + + for (i = 0; i < rel_size; i++, rpnt++) { + int symtab_index, res; + + symtab_index = ELF32_R_SYM(rpnt->r_info); + + debug_sym(symtab, strtab, symtab_index); + debug_reloc(symtab, strtab, rpnt); + + res = reloc_func(tpnt, scope, rpnt, symtab, strtab); + + if (res == 0) + continue; + + _dl_dprintf(2, "\n%s: ", _dl_progname); + + if (symtab_index) + _dl_dprintf(2, "symbol '%s': ", + strtab + symtab[symtab_index].st_name); + + if (res < 0) { + int reloc_type = ELF32_R_TYPE(rpnt->r_info); +#if defined(__SUPPORT_LD_DEBUG__) + _dl_dprintf(2, "can't handle reloc type %s\n", + _dl_reltypes(reloc_type)); +#else + _dl_dprintf(2, "can't handle reloc type %x\n", + reloc_type); +#endif + _dl_exit(-res); + } else { + _dl_dprintf(2, "can't resolve symbol\n"); + return res; + } + } + + return 0; +} + +static int _dl_do_reloc(struct elf_resolve *tpnt, struct dyn_elf *scope, + Elf32_Rela *rpnt, Elf32_Sym *symtab, char *strtab) +{ + int reloc_type; + int symtab_index; + char *symname; + unsigned long *reloc_addr; + unsigned long symbol_addr; +#if defined(__SUPPORT_LD_DEBUG__) + unsigned long old_val; +#endif + + reloc_addr = (unsigned long *)(tpnt->loadaddr + rpnt->r_offset); + reloc_type = ELF32_R_TYPE(rpnt->r_info); + symtab_index = ELF32_R_SYM(rpnt->r_info); + symbol_addr = 0; + symname = strtab + symtab[symtab_index].st_name; + + if (symtab_index) { + symbol_addr = (unsigned long) + _dl_find_hash(strtab + symtab[symtab_index].st_name, + tpnt->symbol_scope, tpnt, + elf_machine_type_class(reloc_type)); + + /* Allow undefined references to weak symbols */ + if (!symbol_addr && + ELF32_ST_BIND(symtab[symtab_index].st_info) != STB_WEAK) { + _dl_dprintf(2, "%s: can't resolve symbol '%s'\n", + _dl_progname, symname); + return 0; + } + } + +#if defined(__SUPPORT_LD_DEBUG__) + old_val = *reloc_addr; +#endif + switch (reloc_type) { + case R_AVR32_NONE: + break; + case R_AVR32_GLOB_DAT: + case R_AVR32_JMP_SLOT: + *reloc_addr = symbol_addr + rpnt->r_addend; + break; + case R_AVR32_RELATIVE: + *reloc_addr = (unsigned long)tpnt->loadaddr + + rpnt->r_addend; + break; + default: + return -1; + } + +#if defined(__SUPPORT_LD_DEBUG__) + if (_dl_debug_reloc && _dl_debug_detail) + _dl_dprintf(_dl_debug_file, "\tpatched: %x ==> %x @ %x\n", + old_val, *reloc_addr); +#endif + + return 0; +} + +void _dl_parse_lazy_relocation_information(struct dyn_elf *rpnt, + unsigned long rel_addr, + unsigned long rel_size) +{ + /* TODO: Might want to support this in order to get faster + * startup times... */ +} + +int _dl_parse_relocation_information(struct dyn_elf *rpnt, + unsigned long rel_addr, + unsigned long rel_size) +{ + return _dl_parse(rpnt->dyn, rpnt->dyn->symbol_scope, rel_addr, rel_size, + _dl_do_reloc); +} diff --git a/ldso/ldso/avr32/resolve.S b/ldso/ldso/avr32/resolve.S new file mode 100644 index 000000000..ad90c2548 --- /dev/null +++ b/ldso/ldso/avr32/resolve.S @@ -0,0 +1,28 @@ +/* + * Linux dynamic resolving code for AVR32. Fixes up the GOT entry as + * indicated in register r12 and jumps to the resolved address. + * + * This file is subject to the terms and conditions of the GNU Lesser General + * Public License. See the file "COPYING.LIB" in the main directory of this + * archive for more details. + * + * Copyright (C) 2004-2007 Atmel Corporation + */ + +#define ip r5 + + .text + .global _dl_linux_resolve + .type _dl_linux_resolve,@function +_dl_linux_resolve: + /* The PLT code pushed r8 for us. It contains the address of this + function's GOT entry, that is entry 0. ip contains the address + of the GOT entry of the function we wanted to call. */ + stm --sp, r9-r12, lr + mov r11, r8 + sub r12, ip, r8 + rcall _dl_linux_resolver + mov ip, r12 + popm r8-r12,lr + mov pc, ip + .size _dl_linux_resolve, . - _dl_linux_resolve diff --git a/ldso/ldso/dl-startup.c b/ldso/ldso/dl-startup.c index 5cf1d049e..d4294ec3a 100644 --- a/ldso/ldso/dl-startup.c +++ b/ldso/ldso/dl-startup.c @@ -217,7 +217,9 @@ DL_START(unsigned long args) /* some arches (like MIPS) we have to tweak the GOT before relocations */ PERFORM_BOOTSTRAP_GOT(tpnt); -#else +#endif + +#if !defined(PERFORM_BOOTSTRAP_GOT) || defined(__avr32__) /* OK, now do the relocations. We do not do a lazy binding here, so that once we are done, we have considerably more flexibility. */ diff --git a/libc/string/avr32/Makefile b/libc/string/avr32/Makefile new file mode 100644 index 000000000..0002ffdce --- /dev/null +++ b/libc/string/avr32/Makefile @@ -0,0 +1,26 @@ +# Makefile for uClibc +# +# Copyright (C) 2000-2003 Erik Andersen +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU Library General Public License as published by the Free +# Software Foundation; either version 2 of the License, or (at your option) any +# later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more +# details. +# +# You should have received a copy of the GNU Library General Public License +# along with this program; if not, write to the Free Software Foundation, Inc., +# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +top_srcdir := ../../../ +top_builddir := ../../../ + +all: objs + +include $(top_builddir)Rules.mak +include ../Makefile.in +include $(top_srcdir)Makerules diff --git a/libc/string/avr32/bcopy.S b/libc/string/avr32/bcopy.S new file mode 100644 index 000000000..193919084 --- /dev/null +++ b/libc/string/avr32/bcopy.S @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2004-2007 Atmel Corporation + * + * This file is subject to the terms and conditions of the GNU Lesser General + * Public License. See the file "COPYING.LIB" in the main directory of this + * archive for more details. + */ + +#include + +#ifdef __UCLIBC_SUSV3_LEGACY__ + + .text + .global bcopy + .type bcopy, @function + .align 1 +bcopy: + /* Swap the first two arguments */ + eor r11, r12 + eor r12, r11 + eor r11, r12 + rjmp __GI_memmove + + .size bcopy, . - bcopy + +#endif /* __UCLIBC_SUSV3_LEGACY__ */ diff --git a/libc/string/avr32/bzero.S b/libc/string/avr32/bzero.S new file mode 100644 index 000000000..6ced0cbb1 --- /dev/null +++ b/libc/string/avr32/bzero.S @@ -0,0 +1,22 @@ +/* + * Copyright (C) 2004-2007 Atmel Corporation + * + * This file is subject to the terms and conditions of the GNU Lesser General + * Public License. See the file "COPYING.LIB" in the main directory of this + * archive for more details. + */ + +#ifdef __UCLIBC_SUSV3_LEGACY__ + + .text + .global bzero + .type bzero, @function + .align 1 +bzero: + mov r10, r11 + mov r11, 0 + rjmp __memset + + .size bzero, . - bzero + +#endif /* __UCLIBC_SUSV3_LEGACY__ */ diff --git a/libc/string/avr32/memcmp.S b/libc/string/avr32/memcmp.S new file mode 100644 index 000000000..5d7eac3d9 --- /dev/null +++ b/libc/string/avr32/memcmp.S @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2004-2007 Atmel Corporation + * + * This file is subject to the terms and conditions of the GNU Lesser General + * Public License. See the file "COPYING.LIB" in the main directory of this + * archive for more details. + */ + +#include + +#define s1 r12 +#define s2 r11 +#define len r10 + + .text + .global memcmp + .type memcmp, @function + .align 1 +memcmp: + sub len, 4 + brlt .Lless_than_4 + +1: ld.w r8, s1++ + ld.w r9, s2++ + cp.w r8, r9 + brne .Lfound_word + sub len, 4 + brge 1b + +.Lless_than_4: + sub len, -4 + reteq 0 + +1: ld.ub r8, s1++ + ld.ub r9, s2++ + sub r8, r9 + retne r8 + sub len, 1 + brgt 1b + + retal 0 + +.Lfound_word: + mov len, 4 + +2: bfextu r11, r9, 24, 8 + bfextu r12, r8, 24, 8 + sub r12, r11 + retne r12 + lsl r8, 8 + lsl r9, 8 + sub len, 1 + brne 2b + retal r12 + + .size memcmp, . - memcmp + +libc_hidden_def(memcmp) +#ifdef __UCLIBC_SUSV3_LEGACY__ +strong_alias(memcmp,bcmp) +#endif diff --git a/libc/string/avr32/memcpy.S b/libc/string/avr32/memcpy.S new file mode 100644 index 000000000..f95aabd13 --- /dev/null +++ b/libc/string/avr32/memcpy.S @@ -0,0 +1,111 @@ +/* + * Copyright (C) 2004-2007 Atmel Corporation + * + * This file is subject to the terms and conditions of the GNU Lesser General + * Public License. See the file "COPYING.LIB" in the main directory of this + * archive for more details. + */ + +/* Don't use r12 as dst since we must return it unmodified */ +#define dst r9 +#define src r11 +#define len r10 + + .text + .global memcpy + .type memcpy, @function +memcpy: + pref src[0] + mov dst, r12 + + /* If we have less than 32 bytes, don't do anything fancy */ + cp.w len, 32 + brge .Lmore_than_31 + + sub len, 1 + retlt r12 +1: ld.ub r8, src++ + st.b dst++, r8 + sub len, 1 + brge 1b + retal r12 + +.Lmore_than_31: + pushm r0-r7, lr + + /* Check alignment */ + mov r8, src + andl r8, 31, COH + brne .Lunaligned_src + mov r8, dst + andl r8, 3, COH + brne .Lunaligned_dst + +.Laligned_copy: + sub len, 32 + brlt .Lless_than_32 + +1: /* Copy 32 bytes at a time */ + ldm src, r0-r7 + sub src, -32 + stm dst, r0-r7 + sub dst, -32 + sub len, 32 + brge 1b + +.Lless_than_32: + /* Copy 16 more bytes if possible */ + sub len, -16 + brlt .Lless_than_16 + ldm src, r0-r3 + sub src, -16 + sub len, 16 + stm dst, r0-r3 + sub dst, -16 + +.Lless_than_16: + /* Do the remaining as byte copies */ + neg len + add pc, pc, len << 2 + .rept 15 + ld.ub r0, src++ + st.b dst++, r0 + .endr + + popm r0-r7, pc + +.Lunaligned_src: + /* Make src cacheline-aligned. r8 = (src & 31) */ + rsub r8, r8, 32 + sub len, r8 +1: ld.ub r0, src++ + st.b dst++, r0 + sub r8, 1 + brne 1b + + /* If dst is word-aligned, we're ready to go */ + pref src[0] + mov r8, 3 + tst dst, r8 + breq .Laligned_copy + +.Lunaligned_dst: + /* src is aligned, but dst is not. Expect bad performance */ + sub len, 4 + brlt 2f +1: ld.w r0, src++ + st.w dst++, r0 + sub len, 4 + brge 1b + +2: neg len + add pc, pc, len << 2 + .rept 3 + ld.ub r0, src++ + st.b dst++, r0 + .endr + + popm r0-r7, pc + .size memcpy, . - memcpy + +libc_hidden_def(memcpy) diff --git a/libc/string/avr32/memmove.S b/libc/string/avr32/memmove.S new file mode 100644 index 000000000..659cdd199 --- /dev/null +++ b/libc/string/avr32/memmove.S @@ -0,0 +1,116 @@ +/* + * Copyright (C) 2004-2007 Atmel Corporation + * + * This file is subject to the terms and conditions of the GNU Lesser General + * Public License. See the file "COPYING.LIB" in the main directory of this + * archive for more details. + */ + +#define dst r12 +#define src r11 +#define len r10 + + .text + .global memmove + .type memmove, @function +memmove: + cp.w src, dst + brge __GI_memcpy + + add dst, len + add src, len + pref src[-1] + + /* + * The rest is basically the same as in memcpy.S except that + * the direction is reversed. + */ + cp.w len, 32 + brge .Lmore_than_31 + + sub len, 1 + retlt r12 +1: ld.ub r8, --src + st.b --dst, r8 + sub len, 1 + brge 1b + retal r12 + +.Lmore_than_31: + pushm r0-r7, lr + + /* Check alignment */ + mov r8, src + andl r8, 31, COH + brne .Lunaligned_src + mov r8, r12 + andl r8, 3, COH + brne .Lunaligned_dst + +.Laligned_copy: + sub len, 32 + brlt .Lless_than_32 + +1: /* Copy 32 bytes at a time */ + sub src, 32 + ldm src, r0-r7 + sub dst, 32 + sub len, 32 + stm dst, r0-r7 + brge 1b + +.Lless_than_32: + /* Copy 16 more bytes if possible */ + sub len, -16 + brlt .Lless_than_16 + sub src, 16 + ldm src, r0-r3 + sub dst, 16 + sub len, 16 + stm dst, r0-r3 + +.Lless_than_16: + /* Do the remaining as byte copies */ + sub len, -16 + breq 2f +1: ld.ub r0, --src + st.b --dst, r0 + sub len, 1 + brne 1b + +2: popm r0-r7, pc + +.Lunaligned_src: + /* Make src cacheline-aligned. r8 = (src & 31) */ + sub len, r8 +1: ld.ub r0, --src + st.b --dst, r0 + sub r8, 1 + brne 1b + + /* If dst is word-aligned, we're ready to go */ + pref src[-4] + mov r8, 3 + tst dst, r8 + breq .Laligned_copy + +.Lunaligned_dst: + /* src is aligned, but dst is not. Expect bad performance */ + sub len, 4 + brlt 2f +1: ld.w r0, --src + st.w --dst, r0 + sub len, 4 + brge 1b + +2: neg len + add pc, pc, len << 2 + .rept 3 + ld.ub r0, --src + st.b --dst, r0 + .endr + + popm r0-r7, pc + .size memmove, . - memmove + +libc_hidden_def(memmove) diff --git a/libc/string/avr32/memset.S b/libc/string/avr32/memset.S new file mode 100644 index 000000000..ca5b53a1a --- /dev/null +++ b/libc/string/avr32/memset.S @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2004-2007 Atmel Corporation + * + * This file is subject to the terms and conditions of the GNU Lesser General + * Public License. See the file "COPYING.LIB" in the main directory of this + * archive for more details. + */ + +#include + +#define s r12 +#define c r11 +#define n r10 + + .text + .global memset + .type memset, @function + + .global __memset + .hidden __memset + .type __memset, @function + + .align 1 +memset: +__memset: + cp.w n, 32 + mov r9, s + brge .Llarge_memset + + sub n, 1 + retlt s +1: st.b s++, c + sub n, 1 + brge 1b + + retal r9 + +.Llarge_memset: + mov r8, r11 + mov r11, 3 + bfins r8, r8, 8, 8 + bfins r8, r8, 16, 16 + tst s, r11 + breq 2f + +1: st.b s++, r8 + sub n, 1 + tst s, r11 + brne 1b + +2: mov r11, r9 + mov r9, r8 + sub n, 8 + +3: st.d s++, r8 + sub n, 8 + brge 3b + + /* If we are done, n == -8 and we'll skip all st.b insns below */ + neg n + lsl n, 1 + add pc, n + .rept 7 + st.b s++, r8 + .endr + retal r11 + + .size memset, . - memset + +libc_hidden_def(memset) diff --git a/libc/string/avr32/strcmp.S b/libc/string/avr32/strcmp.S new file mode 100644 index 000000000..e9f087577 --- /dev/null +++ b/libc/string/avr32/strcmp.S @@ -0,0 +1,91 @@ +/* + * Copyright (C) 2004-2007 Atmel Corporation + * + * This file is subject to the terms and conditions of the GNU Lesser General + * Public License. See the file "COPYING.LIB" in the main directory of this + * archive for more details. + */ + +#include + +#define s1 r12 +#define s2 r11 +#define len r10 + + .text + .global strcmp + .type strcmp, @function + .align 1 +strcmp: + mov r8, 3 + tst s1, r8 + brne .Lunaligned_s1 + tst s2, r8 + brne .Lunaligned_s2 + +1: ld.w r8, s1++ + ld.w r9, s2++ + cp.w r8, r9 + brne 2f + tnbz r8 + brne 1b + retal 0 + +2: bfextu r12, r8, 24, 8 + bfextu r11, r9, 24, 8 + sub r12, r11 + retne r12 + cp.w r11, 0 + reteq 0 + bfextu r12, r8, 16, 8 + bfextu r11, r9, 16, 8 + sub r12, r11 + retne r12 + cp.w r11, 0 + reteq 0 + bfextu r12, r8, 8, 8 + bfextu r11, r9, 8, 8 + sub r12, r11 + retne r12 + cp.w r11, 0 + reteq 0 + bfextu r12, r8, 0, 8 + bfextu r11, r9, 0, 8 + sub r12, r11 + retal r12 + +.Lunaligned_s1: +3: tst s1, r8 + breq 4f + ld.ub r10, s1++ + ld.ub r9, s2++ + sub r10, r9 + retne r10 + cp.w r9, 0 + brne 3b + retal r10 + +4: tst s2, r8 + breq 1b + +.Lunaligned_s2: + /* + * s1 and s2 can't both be aligned, and unaligned word loads + * can trigger spurious exceptions if we cross a page boundary. + * Do it the slow way... + */ +1: ld.ub r8, s1++ + ld.ub r9, s2++ + sub r8, r9 + retne r8 + cp.w r9, 0 + brne 1b + retal 0 + + .size strcmp, . - strcmp + +libc_hidden_def(strcmp) +#ifndef __UCLIBC_HAS_LOCALE__ +strong_alias(strcmp, strcoll) +libc_hidden_def(strcoll) +#endif diff --git a/libc/string/avr32/strlen.S b/libc/string/avr32/strlen.S new file mode 100644 index 000000000..d2808998d --- /dev/null +++ b/libc/string/avr32/strlen.S @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2004-2007 Atmel Corporation + * + * This file is subject to the terms and conditions of the GNU Lesser General + * Public License. See the file "COPYING.LIB" in the main directory of this + * archive for more details. + */ + +#include + +#define str r12 + + .text + .global strlen + .type strlen, @function +strlen: + mov r11, r12 + + mov r9, str + andl r9, 3, COH + brne .Lunaligned_str + +1: ld.w r8, str++ + tnbz r8 + brne 1b + + sub r12, r11 + bfextu r9, r8, 24, 8 + cp.w r9, 0 + subeq r12, 4 + reteq r12 + bfextu r9, r8, 16, 8 + cp.w r9, 0 + subeq r12, 3 + reteq r12 + bfextu r9, r8, 8, 8 + cp.w r9, 0 + subeq r12, 2 + reteq r12 + sub r12, 1 + retal r12 + +.Lunaligned_str: + add pc, pc, r9 << 3 + sub r0, r0, 0 /* 4-byte nop */ + ld.ub r8, str++ + sub r8, r8, 0 + breq 1f + ld.ub r8, str++ + sub r8, r8, 0 + breq 1f + ld.ub r8, str++ + sub r8, r8, 0 + brne 1b + +1: sub r12, 1 + sub r12, r11 + retal r12 + + .size strlen, . - strlen + +libc_hidden_def(strlen) diff --git a/libc/sysdeps/linux/avr32/Makefile b/libc/sysdeps/linux/avr32/Makefile new file mode 100644 index 000000000..338abc086 --- /dev/null +++ b/libc/sysdeps/linux/avr32/Makefile @@ -0,0 +1,25 @@ +# Makefile for uClibc +# +# Copyright (C) 2000-2003 Erik Andersen +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU Library General Public License as published by the Free +# Software Foundation; either version 2 of the License, or (at your option) any +# later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more +# details. +# +# You should have received a copy of the GNU Library General Public License +# along with this program; if not, write to the Free Software Foundation, Inc., +# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +top_srcdir=../../../../ +top_builddir=../../../../ +all: objs + +include $(top_builddir)Rules.mak +include Makefile.arch +include $(top_srcdir)Makerules diff --git a/libc/sysdeps/linux/avr32/Makefile.arch b/libc/sysdeps/linux/avr32/Makefile.arch new file mode 100644 index 000000000..c71c3ce56 --- /dev/null +++ b/libc/sysdeps/linux/avr32/Makefile.arch @@ -0,0 +1,13 @@ +# Makefile for uClibc +# +# Copyright (C) 2000-2005 Erik Andersen +# +# Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. +# + +CSRC := brk.c clone.c mmap.c sigaction.c + +SSRC := __longjmp.S setjmp.S bsd-setjmp.S bsd-_setjmp.S \ + sigrestorer.S syscall.S vfork.S + +include $(top_srcdir)/libc/sysdeps/linux/Makefile.commonarch diff --git a/libc/sysdeps/linux/avr32/__longjmp.S b/libc/sysdeps/linux/avr32/__longjmp.S new file mode 100644 index 000000000..245611a46 --- /dev/null +++ b/libc/sysdeps/linux/avr32/__longjmp.S @@ -0,0 +1,21 @@ +/* + * Copyright (C) 2004-2007 Atmel Corporation + * + * This file is subject to the terms and conditions of the GNU Lesser General + * Public License. See the file "COPYING.LIB" in the main directory of this + * archive for more details. + */ + + .global __longjmp + .type __longjmp,"function" + .align 1 +__longjmp: + ldm r12++, r0-r8,sp,lr + mustr r8 /* restore status register (lower half) */ + cp r11, 0 /* can't return zero */ + frs + moveq r11, 1 + retal r11 + .size __longjmp, . - __longjmp + +libc_hidden_def(__longjmp) diff --git a/libc/sysdeps/linux/avr32/bits/atomic.h b/libc/sysdeps/linux/avr32/bits/atomic.h new file mode 100644 index 000000000..4f870c023 --- /dev/null +++ b/libc/sysdeps/linux/avr32/bits/atomic.h @@ -0,0 +1,120 @@ +/* + * Copyright (C) 2007 Atmel Corporation + * + * This file is subject to the terms and conditions of the GNU Lesser General + * Public License. See the file "COPYING.LIB" in the main directory of this + * archive for more details. + */ +#ifndef _AVR32_BITS_ATOMIC_H +#define _AVR32_BITS_ATOMIC_H 1 + +#include + +typedef int32_t atomic32_t; +typedef uint32_t uatomic32_t; +typedef int_fast32_t atomic_fast32_t; +typedef uint_fast32_t uatomic_fast32_t; + +typedef intptr_t atomicptr_t; +typedef uintptr_t uatomicptr_t; +typedef intmax_t atomic_max_t; +typedef uintmax_t uatomic_max_t; + +#define __arch_compare_and_exchange_val_8_acq(mem, newval, oldval) \ + (abort(), 0) + +#define __arch_compare_and_exchange_val_16_acq(mem, newval, oldval) \ + (abort(), 0) + +#define __arch_compare_and_exchange_val_32_acq(mem, newval, oldval) \ + ({ \ + __typeof__(*(mem)) __prev; \ + __asm__ __volatile__( \ + "/* __arch_compare_and_exchange_val_32_acq */\n" \ + "1: ssrf 5\n" \ + " ld.w %[result], %[m]\n" \ + " cp.w %[result], %[old]\n" \ + " brne 2f\n" \ + " stcond %[m], %[new]\n" \ + " brne 1b\n" \ + "2:" \ + : [result] "=&r"(__result), [m] "=m"(*(mem)) \ + : "m"(*(mem)), [old] "ir"(oldval), \ + [new] "r"(newval) \ + : "memory", "cc"); \ + __prev; \ + }) + +#define __arch_compare_and_exchange_val_64_acq(mem, newval, oldval) \ + (abort(), 0) + +#define __arch_exchange_32_acq(mem, newval) \ + ({ \ + __typeof__(*(mem)) __oldval; \ + __asm__ __volatile__( \ + "/*__arch_exchange_32_acq */\n" \ + " xchg %[old], %[m], %[new]" \ + : [old] "=&r"(__oldval) \ + : [m] "r"(mem), [new] "r"(newval) \ + : "memory"); \ + __oldval; \ + }) + +#define __arch_atomic_exchange_and_add_32(mem, value) \ + ({ \ + __typeof__(*(mem)) __oldval, __tmp; \ + __asm__ __volatile__( \ + "/* __arch_atomic_exchange_and_add_32 */\n" \ + "1: ssrf 5\n" \ + " ld.w %[old], %[m]\n" \ + " add %[tmp], %[old], %[val]\n" \ + " stcond %[m], %[tmp]\n" \ + " brne 1b" \ + : [old] "=&r"(__oldval), [tmp] "=&r"(__tmp), \ + [m] "=m"(*(mem)) \ + : "m"(*(mem)), [val] "r"(value) \ + : "memory", "cc"); \ + __oldval; \ + }) + +#define __arch_atomic_decrement_if_positive_32(mem) \ + ({ \ + __typeof__(*(mem)) __oldval, __tmp; \ + __asm__ __volatile__( \ + "/* __arch_atomic_decrement_if_positive_32 */\n" \ + "1: ssrf 5\n" \ + " ld.w %[old], %[m]\n" \ + " sub %[tmp], %[old], 1\n" \ + " brlt 2f\n" \ + " stcond %[m], %[tmp]\n" \ + " brne 1b" \ + "2:" \ + : [old] "=&r"(__oldval), [tmp] "=&r"(__tmp), \ + [m] "=m"(*(mem)) \ + : "m"(*(mem)) \ + : "memory", "cc"); \ + __oldval; \ + }) + +#define atomic_exchange_acq(mem, newval) \ + ({ \ + if (sizeof(*(mem)) != 4) \ + abort(); \ + __arch_exchange_32_acq(mem, newval); \ + }) + +#define atomic_exchange_and_add(mem, newval) \ + ({ \ + if (sizeof(*(mem)) != 4) \ + abort(); \ + __arch_atomic_exchange_and_add_32(mem, newval); \ + }) + +#define atomic_decrement_if_positive(mem) \ + ({ \ + if (sizeof(*(mem)) != 4) \ + abort(); \ + __arch_atomic_decrement_if_positive_32(mem); \ + }) + +#endif /* _AVR32_BITS_ATOMIC_H */ diff --git a/libc/sysdeps/linux/avr32/bits/byteswap.h b/libc/sysdeps/linux/avr32/bits/byteswap.h new file mode 100644 index 000000000..59e96320f --- /dev/null +++ b/libc/sysdeps/linux/avr32/bits/byteswap.h @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2005 Atmel Corporation + * + * This file is subject to the terms and conditions of the GNU Lesser General + * Public License. See the file "COPYING.LIB" in the main directory of this + * archive for more details. + */ + +#if !defined _BYTESWAP_H && !defined _NETINET_IN_H +# error "Never use directly; include instead." +#endif + +#ifndef _BITS_BYTESWAP_H +#define _BITS_BYTESWAP_H 1 + +/* Swap bytes in 16 bit value. */ +#if defined __GNUC__ +# define __bswap_16(x) (__extension__ __builtin_bswap_16(x)) +#else +/* This is better than nothing. */ +static __inline unsigned short int +__bswap_16 (unsigned short int __bsx) +{ + return ((((__bsx) >> 8) & 0xff) | (((__bsx) & 0xff) << 8)); +} +#endif + +/* Swap bytes in 32 bit value. */ +#if defined __GNUC__ +# define __bswap_32(x) (__extension__ __builtin_bswap_32(x)) +#else +static __inline unsigned int +__bswap_32 (unsigned int __bsx) +{ + return ((((__bsx) & 0xff000000) >> 24) | (((__bsx) & 0x00ff0000) >> 8) | + (((__bsx) & 0x0000ff00) << 8) | (((__bsx) & 0x000000ff) << 24)); +} +#endif + +#if defined __GNUC__ +/* Swap bytes in 64 bit value. */ +# define __bswap_constant_64(x) \ + ((((x) & 0xff00000000000000ull) >> 56) \ + | (((x) & 0x00ff000000000000ull) >> 40) \ + | (((x) & 0x0000ff0000000000ull) >> 24) \ + | (((x) & 0x000000ff00000000ull) >> 8) \ + | (((x) & 0x00000000ff000000ull) << 8) \ + | (((x) & 0x0000000000ff0000ull) << 24) \ + | (((x) & 0x000000000000ff00ull) << 40) \ + | (((x) & 0x00000000000000ffull) << 56)) + +# define __bswap_64(x) \ + (__extension__ \ + ({ \ + union { \ + __extension__ unsigned long long int __ll; \ + unsigned int __l[2]; \ + } __w, __r; \ + if (__builtin_constant_p(x)) \ + __r.__ll = __bswap_constant_64(x); \ + else { \ + __w.__ll = (x); \ + __r.__l[0] = __bswap_32(__w.__l[1]); \ + __r.__l[1] = __bswap_32(__w.__l[0]); \ + } \ + __r.__ll; \ + })) +#endif + +#endif /* _BITS_BYTESWAP_H */ diff --git a/libc/sysdeps/linux/avr32/bits/endian.h b/libc/sysdeps/linux/avr32/bits/endian.h new file mode 100644 index 000000000..7bb63585d --- /dev/null +++ b/libc/sysdeps/linux/avr32/bits/endian.h @@ -0,0 +1,7 @@ +/* AVR32 is big-endian */ + +#ifndef _ENDIAN_H +# error "Never use directly; include instead." +#endif + +#define __BYTE_ORDER __BIG_ENDIAN diff --git a/libc/sysdeps/linux/avr32/bits/fcntl.h b/libc/sysdeps/linux/avr32/bits/fcntl.h new file mode 100644 index 000000000..b45dd2c4c --- /dev/null +++ b/libc/sysdeps/linux/avr32/bits/fcntl.h @@ -0,0 +1,165 @@ +#ifndef _FCNTL_H +# error "Never use directly; include instead." +#endif + +#include + +/* + * open/fcntl - O_SYNC is only implemented on blocks devices and on files + * located on an ext2 file system + */ +#define O_ACCMODE 00000003 +#define O_RDONLY 00000000 +#define O_WRONLY 00000001 +#define O_RDWR 00000002 +#define O_CREAT 00000100 /* not fcntl */ +#define O_EXCL 00000200 /* not fcntl */ +#define O_NOCTTY 00000400 /* not fcntl */ +#define O_TRUNC 00001000 /* not fcntl */ +#define O_APPEND 00002000 +#define O_NONBLOCK 00004000 +#define O_NDELAY O_NONBLOCK +#define O_SYNC 00010000 +#define O_ASYNC 00020000 + +#ifdef __USE_GNU +# define O_DIRECT 00040000 /* must be a directory */ +# define O_DIRECTORY 00200000 /* direct disk access */ +# define O_NOFOLLOW 00400000 /* don't follow links */ +# define O_NOATIME 01000000 /* don't set atime */ +#endif + +#ifdef __USE_LARGEFILE64 +# define O_LARGEFILE 00100000 +#endif + +/* For now Linux has synchronisity options for data and read operations. + We define the symbols here but let them do the same as O_SYNC since + this is a superset. */ +#if defined __USE_POSIX199309 || defined __USE_UNIX98 +# define O_DSYNC O_SYNC /* Synchronize data. */ +# define O_RSYNC O_SYNC /* Synchronize read operations. */ +#endif + +#define F_DUPFD 0 /* dup */ +#define F_GETFD 1 /* get close_on_exec */ +#define F_SETFD 2 /* set/clear close_on_exec */ +#define F_GETFL 3 /* get file->f_flags */ +#define F_SETFL 4 /* set file->f_flags */ + +#ifndef __USE_FILE_OFFSET64 +# define F_GETLK 5 +# define F_SETLK 6 +# define F_SETLKW 7 +#else +# define F_GETLK F_GETLK64 +# define F_SETLK F_SETLK64 +# define F_SETLKW F_SETLKW64 +#endif +#define F_GETLK64 12 /* using 'struct flock64' */ +#define F_SETLK64 13 +#define F_SETLKW64 14 + +#if defined __USE_BSD || defined __USE_XOPEN2K +# define F_SETOWN 8 /* for sockets. */ +# define F_GETOWN 9 /* for sockets. */ +#endif + +#ifdef __USE_GNU +# define F_SETSIG 10 /* for sockets. */ +# define F_GETSIG 11 /* for sockets. */ +#endif + +#ifdef __USE_GNU +# define F_SETLEASE 1024 /* Set a lease. */ +# define F_GETLEASE 1025 /* Enquire what lease is active. */ +# define F_NOTIFY 1026 /* Request notfications on a directory. */ +#endif + +/* for F_[GET|SET]FL */ +#define FD_CLOEXEC 1 /* actually anything with low bit set goes */ + +/* for posix fcntl() and lockf() */ +#define F_RDLCK 0 +#define F_WRLCK 1 +#define F_UNLCK 2 + +/* for old implementation of bsd flock () */ +#define F_EXLCK 4 /* or 3 */ +#define F_SHLCK 8 /* or 4 */ + +/* for leases */ +#define F_INPROGRESS 16 + +#ifdef __USE_BSD +/* operations for bsd flock(), also used by the kernel implementation */ +# define LOCK_SH 1 /* shared lock */ +# define LOCK_EX 2 /* exclusive lock */ +# define LOCK_NB 4 /* or'd with one of the above to prevent + blocking */ +# define LOCK_UN 8 /* remove lock */ +#endif + +#ifdef __USE_GNU +# define LOCK_MAND 32 /* This is a mandatory flock */ +# define LOCK_READ 64 /* ... Which allows concurrent + read operations */ +# define LOCK_WRITE 128 /* ... Which allows concurrent + write operations */ +# define LOCK_RW 192 /* ... Which allows concurrent + read & write ops */ +#endif + +#ifdef __USE_GNU +/* Types of directory notifications that may be requested with F_NOTIFY. */ +# define DN_ACCESS 0x00000001 /* File accessed. */ +# define DN_MODIFY 0x00000002 /* File modified. */ +# define DN_CREATE 0x00000004 /* File created. */ +# define DN_DELETE 0x00000008 /* File removed. */ +# define DN_RENAME 0x00000010 /* File renamed. */ +# define DN_ATTRIB 0x00000020 /* File changed attibutes. */ +# define DN_MULTISHOT 0x80000000 /* Don't remove notifier. */ +#endif + +struct flock { + short l_type; + short l_whence; +#ifndef __USE_FILE_OFFSET64 + __off_t l_start; + __off_t l_len; +#else + __off64_t l_start; + __off64_t l_len; +#endif + __pid_t l_pid; +}; + +#ifdef __USE_LARGEFILE64 +struct flock64 { + short l_type; + short l_whence; + __off64_t l_start; + __off64_t l_len; + __pid_t l_pid; +}; +#endif + +/* Define some more compatibility macros to be backward compatible with + * BSD systems which did not managed