1 diff --git a/Rules.mak b/Rules.mak
2 index d054bbb..55381cf 100644
5 @@ -313,6 +313,12 @@ ifeq ($(TARGET_ARCH),frv)
9 +ifeq ($(strip $(TARGET_ARCH)),avr32)
10 + CPU_CFLAGS-$(CONFIG_AVR32_AP7) += -march=ap
11 + CPU_CFLAGS-$(CONFIG_LINKRELAX) += -mrelax
12 + CPU_LDFLAGS-$(CONFIG_LINKRELAX) += --relax
15 # Keep the check_gcc from being needlessly executed
17 ifneq ($(UCLIBC_BUILD_PIE),y)
18 diff --git a/extra/Configs/Config.avr32 b/extra/Configs/Config.avr32
20 index 0000000..8d70e6e
22 +++ b/extra/Configs/Config.avr32
25 +# For a description of the syntax of this configuration file,
26 +# see extra/config/Kconfig-language.txt
33 +config FORCE_OPTIONS_FOR_ARCH
36 + select ARCH_BIG_ENDIAN
37 + select FORCE_SHAREABLE_TEXT_SEGMENTS
43 + prompt "Target CPU Type"
44 + default CONFIG_AVR32_AP7
46 +config CONFIG_AVR32_AP7
53 + bool "Enable linker optimizations"
55 diff --git a/extra/Configs/Config.in b/extra/Configs/Config.in
56 index 8eab394..10c9f7b 100644
57 --- a/extra/Configs/Config.in
58 +++ b/extra/Configs/Config.in
59 @@ -16,6 +16,9 @@ config TARGET_alpha
69 @@ -92,6 +95,10 @@ if TARGET_arm
70 source "extra/Configs/Config.arm"
74 +source "extra/Configs/Config.avr32"
78 source "extra/Configs/Config.bfin"
80 diff --git a/extra/Configs/defconfigs/avr32 b/extra/Configs/defconfigs/avr32
82 index 0000000..0b890a2
84 +++ b/extra/Configs/defconfigs/avr32
87 diff --git a/include/elf.h b/include/elf.h
88 index 19805d7..ab90160 100644
91 @@ -354,6 +354,8 @@ typedef struct
92 /* NIOS magic number - no EABI available. */
93 #define EM_NIOS32 0xFEBB
95 +#define EM_AVR32 0x18ad
97 /* V850 backend magic number. Written in the absense of an ABI. */
98 #define EM_CYGNUS_V850 0x9080
100 @@ -2828,6 +2830,55 @@ typedef Elf32_Addr Elf32_Conflict;
101 /* Keep this the last entry. */
102 #define R_V850_NUM 25
104 +/* Atmel AVR32 relocations. */
105 +#define R_AVR32_NONE 0
106 +#define R_AVR32_32 1
107 +#define R_AVR32_16 2
109 +#define R_AVR32_32_PCREL 4
110 +#define R_AVR32_16_PCREL 5
111 +#define R_AVR32_8_PCREL 6
112 +#define R_AVR32_DIFF32 7
113 +#define R_AVR32_DIFF16 8
114 +#define R_AVR32_DIFF8 9
115 +#define R_AVR32_GOT32 10
116 +#define R_AVR32_GOT16 11
117 +#define R_AVR32_GOT8 12
118 +#define R_AVR32_21S 13
119 +#define R_AVR32_16U 14
120 +#define R_AVR32_16S 15
121 +#define R_AVR32_8S 16
122 +#define R_AVR32_8S_EXT 17
123 +#define R_AVR32_22H_PCREL 18
124 +#define R_AVR32_18W_PCREL 19
125 +#define R_AVR32_16B_PCREL 20
126 +#define R_AVR32_16N_PCREL 21
127 +#define R_AVR32_14UW_PCREL 22
128 +#define R_AVR32_11H_PCREL 23
129 +#define R_AVR32_10UW_PCREL 24
130 +#define R_AVR32_9H_PCREL 25
131 +#define R_AVR32_9UW_PCREL 26
132 +#define R_AVR32_HI16 27
133 +#define R_AVR32_LO16 28
134 +#define R_AVR32_GOTPC 29
135 +#define R_AVR32_GOTCALL 30
136 +#define R_AVR32_LDA_GOT 31
137 +#define R_AVR32_GOT21S 32
138 +#define R_AVR32_GOT18SW 33
139 +#define R_AVR32_GOT16S 34
140 +#define R_AVR32_GOT7UW 35
141 +#define R_AVR32_32_CPENT 36
142 +#define R_AVR32_CPCALL 37
143 +#define R_AVR32_16_CP 38
144 +#define R_AVR32_9W_CP 39
145 +#define R_AVR32_RELATIVE 40
146 +#define R_AVR32_GLOB_DAT 41
147 +#define R_AVR32_JMP_SLOT 42
148 +#define R_AVR32_ALIGN 43
149 +#define R_AVR32_NUM 44
151 +/* AVR32 dynamic tags */
152 +#define DT_AVR32_GOTSZ 0x70000001 /* Total size of GOT in bytes */
154 /* Renesas H8/300 Relocations */
156 diff --git a/ldso/include/dl-string.h b/ldso/include/dl-string.h
157 index 32c5bf8..eb43bd9 100644
158 --- a/ldso/include/dl-string.h
159 +++ b/ldso/include/dl-string.h
160 @@ -285,7 +285,8 @@ static __always_inline char * _dl_simple_ltoahex(char * local, unsigned long i)
161 /* On some arches constant strings are referenced through the GOT.
162 * This requires that load_addr must already be defined... */
163 #if defined(mc68000) || defined(__arm__) || defined(__thumb__) || \
164 - defined(__mips__) || defined(__sh__) || defined(__powerpc__)
165 + defined(__mips__) || defined(__sh__) || defined(__powerpc__) || \
167 # define CONSTANT_STRING_GOT_FIXUP(X) \
168 if ((X) < (const char *) load_addr) (X) += load_addr
169 # define NO_EARLY_SEND_STDERR
170 diff --git a/ldso/include/dl-syscall.h b/ldso/include/dl-syscall.h
171 index b42416a..4404219 100644
172 --- a/ldso/include/dl-syscall.h
173 +++ b/ldso/include/dl-syscall.h
175 dynamic linking at all, so we cannot return any error codes.
176 We just punt if there is an error. */
177 #define __NR__dl_exit __NR_exit
178 -static inline _syscall1(void, _dl_exit, int, status);
179 +static __always_inline _syscall1(void, _dl_exit, int, status);
181 #define __NR__dl_close __NR_close
182 -static inline _syscall1(int, _dl_close, int, fd);
183 +static __always_inline _syscall1(int, _dl_close, int, fd);
185 #define __NR__dl_open __NR_open
186 -static inline _syscall3(int, _dl_open, const char *, fn, int, flags,
187 +static __always_inline _syscall3(int, _dl_open, const char *, fn, int, flags,
188 __kernel_mode_t, mode);
190 #define __NR__dl_write __NR_write
191 -static inline _syscall3(unsigned long, _dl_write, int, fd,
192 +static __always_inline _syscall3(unsigned long, _dl_write, int, fd,
193 const void *, buf, unsigned long, count);
195 #define __NR__dl_read __NR_read
196 -static inline _syscall3(unsigned long, _dl_read, int, fd,
197 +static __always_inline _syscall3(unsigned long, _dl_read, int, fd,
198 const void *, buf, unsigned long, count);
200 #define __NR__dl_mprotect __NR_mprotect
201 -static inline _syscall3(int, _dl_mprotect, const void *, addr,
202 +static __always_inline _syscall3(int, _dl_mprotect, const void *, addr,
203 unsigned long, len, int, prot);
205 #define __NR__dl_stat __NR_stat
206 -static inline _syscall2(int, _dl_stat, const char *, file_name,
207 +static __always_inline _syscall2(int, _dl_stat, const char *, file_name,
210 #define __NR__dl_fstat __NR_fstat
211 -static inline _syscall2(int, _dl_fstat, int, fd, struct stat *, buf);
212 +static __always_inline _syscall2(int, _dl_fstat, int, fd, struct stat *, buf);
214 #define __NR__dl_munmap __NR_munmap
215 -static inline _syscall2(int, _dl_munmap, void *, start, unsigned long, length);
216 +static __always_inline _syscall2(int, _dl_munmap, void *, start, unsigned long, length);
219 # define __NR_getuid __NR_getxuid
221 #define __NR__dl_getuid __NR_getuid
222 -static inline _syscall0(uid_t, _dl_getuid);
223 +static __always_inline _syscall0(uid_t, _dl_getuid);
226 # define __NR_geteuid __NR_getuid
228 #define __NR__dl_geteuid __NR_geteuid
229 -static inline _syscall0(uid_t, _dl_geteuid);
230 +static __always_inline _syscall0(uid_t, _dl_geteuid);
233 # define __NR_getgid __NR_getxgid
235 #define __NR__dl_getgid __NR_getgid
236 -static inline _syscall0(gid_t, _dl_getgid);
237 +static __always_inline _syscall0(gid_t, _dl_getgid);
240 # define __NR_getegid __NR_getgid
242 #define __NR__dl_getegid __NR_getegid
243 -static inline _syscall0(gid_t, _dl_getegid);
244 +static __always_inline _syscall0(gid_t, _dl_getegid);
247 # define __NR_getpid __NR_getxpid
249 #define __NR__dl_getpid __NR_getpid
250 -static inline _syscall0(gid_t, _dl_getpid);
251 +static __always_inline _syscall0(gid_t, _dl_getpid);
253 #define __NR__dl_readlink __NR_readlink
254 -static inline _syscall3(int, _dl_readlink, const char *, path, char *, buf,
255 +static __always_inline _syscall3(int, _dl_readlink, const char *, path, char *, buf,
258 #ifdef __UCLIBC_HAS_SSP__
259 @@ -146,14 +146,14 @@ static inline _syscall2(int, _dl_gettimeofday, struct timeval *, tv,
260 #if defined(__UCLIBC_MMAP_HAS_6_ARGS__) && defined(__NR_mmap)
262 # define __NR__dl_mmap __NR_mmap
263 -static inline _syscall6(void *, _dl_mmap, void *, start, size_t, length,
264 +static __always_inline _syscall6(void *, _dl_mmap, void *, start, size_t, length,
265 int, prot, int, flags, int, fd, off_t, offset);
267 /* then try mmap2() */
268 #elif defined(__NR_mmap2)
270 # define __NR___syscall_mmap2 __NR_mmap2
271 -static inline _syscall6(__ptr_t, __syscall_mmap2, __ptr_t, addr, size_t, len,
272 +static __always_inline _syscall6(__ptr_t, __syscall_mmap2, __ptr_t, addr, size_t, len,
273 int, prot, int, flags, int, fd, off_t, offset);
275 /* Some architectures always use 12 as page shift for mmap2() eventhough the
276 @@ -164,7 +164,7 @@ static inline _syscall6(__ptr_t, __syscall_mmap2, __ptr_t, addr, size_t, len,
277 # define MMAP2_PAGE_SHIFT 12
280 -static inline void * _dl_mmap(void * addr, unsigned long size, int prot,
281 +static __always_inline void * _dl_mmap(void * addr, unsigned long size, int prot,
282 int flags, int fd, unsigned long offset)
284 if (offset & ((1 << MMAP2_PAGE_SHIFT) - 1))
285 @@ -177,8 +177,8 @@ static inline void * _dl_mmap(void * addr, unsigned long size, int prot,
286 #elif defined(__NR_mmap)
288 # define __NR__dl_mmap_real __NR_mmap
289 -static inline _syscall1(void *, _dl_mmap_real, unsigned long *, buffer);
290 -static inline void * _dl_mmap(void * addr, unsigned long size, int prot,
291 +static __always_inline _syscall1(void *, _dl_mmap_real, unsigned long *, buffer);
292 +static __always_inline void * _dl_mmap(void * addr, unsigned long size, int prot,
293 int flags, int fd, unsigned long offset)
295 unsigned long buffer[6];
296 diff --git a/ldso/ldso/avr32/dl-debug.h b/ldso/ldso/avr32/dl-debug.h
298 index 0000000..fe35539
300 +++ b/ldso/ldso/avr32/dl-debug.h
303 + * AVR32 ELF shared libary loader support
305 + * Copyright (C) 2005-2007 Atmel Corporation
306 + * All rights reserved.
308 + * Redistribution and use in source and binary forms, with or without
309 + * modification, are permitted provided that the following conditions
311 + * 1. Redistributions of source code must retain the above copyright
312 + * notice, this list of conditions and the following disclaimer.
313 + * 2. The name of the above contributors may not be
314 + * used to endorse or promote products derived from this software
315 + * without specific prior written permission.
317 + * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND
318 + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
319 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
320 + * ARE DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE
321 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
322 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
323 + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
324 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
325 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
326 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
330 +static const char *_dl_reltypes_tab[] = {
332 + "R_AVR32_32", "R_AVR32_16", "R_AVR32_8",
333 + "R_AVR32_32_PCREL", "R_AVR32_16_PCREL", "R_AVR32_8_PCREL",
334 + "R_AVR32_DIFF32", "R_AVR32_DIFF16", "R_AVR32_DIFF8",
335 + "R_AVR32_GOT32", "R_AVR32_GOT16", "R_AVR32_GOT8",
336 + "R_AVR32_21S", "R_AVR32_16U", "R_AVR32_16S", "R_AVR32_8S", "R_AVR32_8S_EXT",
337 + "R_AVR32_22H_PCREL", "R_AVR32_18W_PCREL", "R_AVR32_16B_PCREL",
338 + "R_AVR32_16N_PCREL", "R_AVR32_14UW_PCREL", "R_AVR32_11H_PCREL",
339 + "R_AVR32_10UW_PCREL", "R_AVR32_9H_PCREL", "R_AVR32_9UW_PCREL",
340 + "R_AVR32_HI16", "R_AVR32_LO16",
341 + "R_AVR32_GOTPC", "R_AVR32_GOTCALL", "R_AVR32_LDA_GOT",
342 + "R_AVR32_GOT21S", "R_AVR32_GOT18SW", "R_AVR32_GOT16S", "R_AVR32_GOT7UW",
343 + "R_AVR32_32_CPENT", "R_AVR32_CPCALL", "R_AVR32_16_CP", "R_AVR32_9W_CP",
344 + "R_AVR32_RELATIVE", "R_AVR32_GLOB_DAT", "R_AVR32_JMP_SLOT",
347 diff --git a/ldso/ldso/avr32/dl-startup.h b/ldso/ldso/avr32/dl-startup.h
349 index 0000000..3b9a641
351 +++ b/ldso/ldso/avr32/dl-startup.h
354 + * Architecture specific code used by dl-startup.c
356 + * Copyright (C) 2005-2007 Atmel Corporation
358 + * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
361 +/* This is the library loader's main entry point. Let _dl_boot2 do its
362 + * initializations and jump to the application's entry point
365 + " .global _start\n"
366 + " .type _start,@function\n"
368 + /* All arguments are on the stack initially */
370 + " rcall _dl_start\n"
371 + /* Returns user entry point in r12. Save it. */
373 + /* We're PIC, so get the Global Offset Table */
374 + " lddpc r6, .L_GOT\n"
377 + /* Adjust argc and argv according to _dl_skip_args */
378 + " ld.w r1, r6[_dl_skip_args@got]\n"
379 + " ld.w r1, r1[0]\n"
382 + " add sp, sp, r1 << 2\n"
384 + /* Load the finalizer function */
385 + " ld.w r12, r6[_dl_fini@got]\n"
386 + /* Jump to the user's entry point */
391 + " .long .L_RGOT - _GLOBAL_OFFSET_TABLE_\n"
392 + " .size _start, . - _start\n"
395 +/* Get a pointer to the argv array. On many platforms this can be just
396 + * the address if the first argument, on other platforms we need to
397 + * do something a little more subtle here. */
398 +#define GET_ARGV(ARGVP, ARGS) ARGVP = ((unsigned long *)ARGS + 1)
401 +/* We can't call functions before the GOT has been initialized */
402 +#define NO_FUNCS_BEFORE_BOOTSTRAP
405 + * Relocate the GOT during dynamic loader bootstrap. This will add
406 + * the load address to all entries in the GOT, which is necessary
407 + * because the linker doesn't generate R_AVR32_RELATIVE relocs for the
410 +static __always_inline
411 +void PERFORM_BOOTSTRAP_GOT(struct elf_resolve *tpnt)
413 + Elf32_Addr i, nr_got;
414 + register Elf32_Addr *__r6 __asm__("r6");
415 + Elf32_Addr *got = __r6;
417 + nr_got = tpnt->dynamic_info[DT_AVR32_GOTSZ_IDX] / sizeof(*got);
418 + for (i = 2; i < nr_got; i++)
419 + got[i] += tpnt->loadaddr;
422 +#define PERFORM_BOOTSTRAP_GOT(tpnt) PERFORM_BOOTSTRAP_GOT(tpnt)
424 +/* Handle relocation of the symbols in the dynamic loader. */
425 +static __always_inline
426 +void PERFORM_BOOTSTRAP_RELOC(ELF_RELOC *rpnt, unsigned long *reloc_addr,
427 + unsigned long symbol_addr,
428 + unsigned long load_addr, Elf32_Sym *symtab)
430 + switch(ELF32_R_TYPE(rpnt->r_info)) {
433 + case R_AVR32_GLOB_DAT:
434 + case R_AVR32_JMP_SLOT:
435 + *reloc_addr = symbol_addr;
437 + case R_AVR32_RELATIVE:
438 + SEND_STDERR_DEBUG("Applying RELATIVE relocation: ");
439 + SEND_ADDRESS_STDERR_DEBUG(load_addr, 0);
440 + SEND_STDERR_DEBUG(" + ");
441 + SEND_ADDRESS_STDERR_DEBUG(rpnt->r_addend, 1);
442 + *reloc_addr = load_addr + rpnt->r_addend;
445 + SEND_STDERR("BOOTSTRAP_RELOC: unhandled reloc_type ");
446 + SEND_NUMBER_STDERR(ELF32_R_TYPE(rpnt->r_info), 1);
447 + SEND_STDERR("REL, SYMBOL, LOAD: ");
448 + SEND_ADDRESS_STDERR(reloc_addr, 0);
450 + SEND_ADDRESS_STDERR(symbol_addr, 0);
452 + SEND_ADDRESS_STDERR(load_addr, 1);
457 +/* Transfer control to the user's application, once the dynamic loader
458 + * is done. This routine has to exit the current function, then call
459 + * the _dl_elf_main function.
461 + * Since our _dl_boot will simply call whatever is returned by
462 + * _dl_boot2, we can just return the address we're supposed to
464 +#define START() return _dl_elf_main;
465 diff --git a/ldso/ldso/avr32/dl-syscalls.h b/ldso/ldso/avr32/dl-syscalls.h
467 index 0000000..996bb87
469 +++ b/ldso/ldso/avr32/dl-syscalls.h
471 +/* We can't use the real errno in ldso, since it has not yet
472 + * been dynamicly linked in yet. */
473 +#include "sys/syscall.h"
474 +extern int _dl_errno;
476 +#define __set_errno(X) {(_dl_errno) = (X);}
477 diff --git a/ldso/ldso/avr32/dl-sysdep.h b/ldso/ldso/avr32/dl-sysdep.h
479 index 0000000..1a30172
481 +++ b/ldso/ldso/avr32/dl-sysdep.h
484 + * Various assembly language/system dependent hacks that are required
485 + * so that we can minimize the amount of platform specific code.
487 + * Copyright (C) 2004-2007 Atmel Corporation
489 + * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
492 +/* Define this if the system uses RELOCA. */
493 +#define ELF_USES_RELOCA
498 +#define DT_AVR32_GOTSZ_IDX (DT_NUM + OS_NUM)
500 +#define ARCH_DYNAMIC_INFO(dpnt, dynamic, debug_addr) \
502 + if (dpnt->d_tag == DT_AVR32_GOTSZ) \
503 + dynamic[DT_AVR32_GOTSZ_IDX] = dpnt->d_un.d_val; \
506 +/* Initialization sequence for the application/library GOT. */
507 +#define INIT_GOT(GOT_BASE,MODULE) \
509 + unsigned long i, nr_got; \
511 + GOT_BASE[0] = (unsigned long) _dl_linux_resolve; \
512 + GOT_BASE[1] = (unsigned long) MODULE; \
514 + /* Add load address displacement to all GOT entries */ \
515 + nr_got = MODULE->dynamic_info[DT_AVR32_GOTSZ_IDX] / 4; \
516 + for (i = 2; i < nr_got; i++) \
517 + GOT_BASE[i] += (unsigned long)MODULE->loadaddr; \
520 +#define do_rem(result, n, base) ((result) = (n) % (base))
522 +/* Here we define the magic numbers that this dynamic loader should accept */
523 +#define MAGIC1 EM_AVR32
526 +/* Used for error messages */
527 +#define ELF_TARGET "AVR32"
529 +unsigned long _dl_linux_resolver(unsigned long got_offset, unsigned long *got);
531 +/* 4096 bytes alignment */
532 +#define PAGE_ALIGN 0xfffff000
533 +#define ADDR_ALIGN 0xfff
534 +#define OFFS_ALIGN 0x7ffff000
536 +#define elf_machine_type_class(type) \
537 + ((type == R_AVR32_JMP_SLOT) * ELF_RTYPE_CLASS_PLT)
539 +/* AVR32 doesn't need any COPY relocs */
540 +#define DL_NO_COPY_RELOCS
542 +/* Return the link-time address of _DYNAMIC. Conveniently, this is the
543 + first element of the GOT. This must be inlined in a function which
544 + uses global data. */
545 +static inline Elf32_Addr
546 +elf_machine_dynamic (void)
548 + register Elf32_Addr *got asm ("r6");
552 +/* Return the run-time load address of the shared object. */
553 +static inline Elf32_Addr
554 +elf_machine_load_address (void)
556 + extern void __dl_start asm("_dl_start");
557 + Elf32_Addr got_addr = (Elf32_Addr) &__dl_start;
558 + Elf32_Addr pcrel_addr;
560 + asm (" lddpc %0, 2f\n"
564 + "2: .long _dl_start - 1b\n"
566 + : "=r"(pcrel_addr) : : "cc");
568 + return pcrel_addr - got_addr;
572 + * Perform any RELATIVE relocations specified by DT_RELCOUNT.
573 + * Currently, we don't use that tag, but we might in the future as
574 + * this would reduce the startup time somewhat (although probably not by much).
577 +elf_machine_relative (Elf32_Addr load_off, const Elf32_Addr rel_addr,
578 + Elf32_Word relative_count)
580 + Elf32_Rela *rpnt = (void *)rel_addr;
583 + Elf32_Addr *reloc_addr;
584 + reloc_addr = (void *)(load_off + (rpnt++)->r_offset);
585 + *reloc_addr = load_off + rpnt->r_addend;
586 + } while (--relative_count);
588 diff --git a/ldso/ldso/avr32/elfinterp.c b/ldso/ldso/avr32/elfinterp.c
590 index 0000000..196292b
592 +++ b/ldso/ldso/avr32/elfinterp.c
595 + * AVR32 ELF shared library loader suppport
597 + * Copyright (C) 2004-2006 Atmel Corporation
599 + * All rights reserved.
601 + * Redistribution and use in source and binary forms, with or without
602 + * modification, are permitted provided that the following conditions
604 + * 1. Redistributions of source code must retain the above copyright
605 + * notice, this list of conditions and the following disclaimer.
606 + * 2. The name of the above contributors may not be
607 + * used to endorse or promote products derived from this software
608 + * without specific prior written permission.
610 + * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND
611 + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
612 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
613 + * ARE DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE
614 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
615 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
616 + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
617 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
618 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
619 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
623 +unsigned long _dl_linux_resolver(unsigned long got_offset, unsigned long *got)
625 + struct elf_resolve *tpnt = (struct elf_resolve *)got[1];
627 + unsigned long local_gotno;
628 + unsigned long gotsym;
629 + unsigned long new_addr;
630 + char *strtab, *symname;
631 + unsigned long *entry;
632 + unsigned long sym_index = got_offset / 4;
635 + local_gotno = tpnt->dynamic_info[DT_AVR32_LOCAL_GOTNO];
636 + gotsym = tpnt->dynamic_info[DT_AVR32_GOTSYM];
638 + sym = ((Elf32_Sym *)(tpnt->dynamic_info[DT_SYMTAB] + tpnt->loadaddr))
640 + strtab = (char *)(tpnt->dynamic_info[DT_STRTAB] + tpnt->loadaddr);
641 + symname = strtab + sym->st_name;
644 + new_addr = (unsigned long) _dl_find_hash(strtab + sym->st_name,
645 + tpnt->symbol_scope, tpnt,
649 + entry = (unsigned long *)(got + local_gotno + sym_index - gotsym);
657 +_dl_parse(struct elf_resolve *tpnt, struct dyn_elf *scope,
658 + unsigned long rel_addr, unsigned long rel_size,
659 + int (*reloc_func)(struct elf_resolve *tpnt, struct dyn_elf *scope,
660 + Elf32_Rela *rpnt, Elf32_Sym *symtab, char *strtab))
667 + rpnt = (Elf32_Rela *)rel_addr;
668 + rel_size /= sizeof(Elf32_Rela);
669 + symtab = (Elf32_Sym *)tpnt->dynamic_info[DT_SYMTAB];
670 + strtab = (char *)tpnt->dynamic_info[DT_STRTAB];
672 + for (i = 0; i < rel_size; i++, rpnt++) {
673 + int symtab_index, res;
675 + symtab_index = ELF32_R_SYM(rpnt->r_info);
677 + debug_sym(symtab, strtab, symtab_index);
678 + debug_reloc(symtab, strtab, rpnt);
680 + res = reloc_func(tpnt, scope, rpnt, symtab, strtab);
685 + _dl_dprintf(2, "\n%s: ", _dl_progname);
688 + _dl_dprintf(2, "symbol '%s': ",
689 + strtab + symtab[symtab_index].st_name);
692 + int reloc_type = ELF32_R_TYPE(rpnt->r_info);
693 +#if defined(__SUPPORT_LD_DEBUG__)
694 + _dl_dprintf(2, "can't handle reloc type %s\n",
695 + _dl_reltypes(reloc_type));
697 + _dl_dprintf(2, "can't handle reloc type %x\n",
702 + _dl_dprintf(2, "can't resolve symbol\n");
710 +static int _dl_do_reloc(struct elf_resolve *tpnt, struct dyn_elf *scope,
711 + Elf32_Rela *rpnt, Elf32_Sym *symtab, char *strtab)
716 + unsigned long *reloc_addr;
717 + unsigned long symbol_addr;
718 +#if defined(__SUPPORT_LD_DEBUG__)
719 + unsigned long old_val;
722 + reloc_addr = (unsigned long *)(tpnt->loadaddr + rpnt->r_offset);
723 + reloc_type = ELF32_R_TYPE(rpnt->r_info);
724 + symtab_index = ELF32_R_SYM(rpnt->r_info);
726 + symname = strtab + symtab[symtab_index].st_name;
728 + if (symtab_index) {
729 + symbol_addr = (unsigned long)
730 + _dl_find_hash(strtab + symtab[symtab_index].st_name,
731 + tpnt->symbol_scope, tpnt,
732 + elf_machine_type_class(reloc_type));
734 + /* Allow undefined references to weak symbols */
735 + if (!symbol_addr &&
736 + ELF32_ST_BIND(symtab[symtab_index].st_info) != STB_WEAK) {
737 + _dl_dprintf(2, "%s: can't resolve symbol '%s'\n",
738 + _dl_progname, symname);
743 +#if defined(__SUPPORT_LD_DEBUG__)
744 + old_val = *reloc_addr;
746 + switch (reloc_type) {
749 + case R_AVR32_GLOB_DAT:
750 + case R_AVR32_JMP_SLOT:
751 + *reloc_addr = symbol_addr + rpnt->r_addend;
753 + case R_AVR32_RELATIVE:
754 + *reloc_addr = (unsigned long)tpnt->loadaddr
761 +#if defined(__SUPPORT_LD_DEBUG__)
762 + if (_dl_debug_reloc && _dl_debug_detail)
763 + _dl_dprintf(_dl_debug_file, "\tpatched: %x ==> %x @ %x\n",
764 + old_val, *reloc_addr);
770 +void _dl_parse_lazy_relocation_information(struct dyn_elf *rpnt,
771 + unsigned long rel_addr,
772 + unsigned long rel_size)
774 + /* TODO: Might want to support this in order to get faster
775 + * startup times... */
778 +int _dl_parse_relocation_information(struct dyn_elf *rpnt,
779 + unsigned long rel_addr,
780 + unsigned long rel_size)
782 + return _dl_parse(rpnt->dyn, rpnt->dyn->symbol_scope, rel_addr, rel_size,
785 diff --git a/ldso/ldso/avr32/resolve.S b/ldso/ldso/avr32/resolve.S
787 index 0000000..e3cb7f4
789 +++ b/ldso/ldso/avr32/resolve.S
792 + * Linux dynamic resolving code for AVR32. Fixes up the GOT entry as
793 + * indicated in register r12 and jumps to the resolved address.
795 + * This file is subject to the terms and conditions of the GNU Lesser General
796 + * Public License. See the file "COPYING.LIB" in the main directory of this
797 + * archive for more details.
799 + * Copyright (C) 2004-2007 Atmel Corporation
805 + .global _dl_linux_resolve
806 + .type _dl_linux_resolve,@function
808 + /* The PLT code pushed r8 for us. It contains the address of this
809 + function's GOT entry, that is entry 0. ip contains the address
810 + of the GOT entry of the function we wanted to call. */
811 + stm --sp, r9-r12, lr
814 + rcall _dl_linux_resolver
818 + .size _dl_linux_resolve, . - _dl_linux_resolve
819 diff --git a/ldso/ldso/dl-startup.c b/ldso/ldso/dl-startup.c
820 index 5cf1d04..d4294ec 100644
821 --- a/ldso/ldso/dl-startup.c
822 +++ b/ldso/ldso/dl-startup.c
823 @@ -217,7 +217,9 @@ DL_START(unsigned long args)
824 /* some arches (like MIPS) we have to tweak the GOT before relocations */
825 PERFORM_BOOTSTRAP_GOT(tpnt);
830 +#if !defined(PERFORM_BOOTSTRAP_GOT) || defined(__avr32__)
832 /* OK, now do the relocations. We do not do a lazy binding here, so
833 that once we are done, we have considerably more flexibility. */
834 diff --git a/libc/inet/resolv.c b/libc/inet/resolv.c
835 index f4e6cac..9cdc3fe 100644
836 --- a/libc/inet/resolv.c
837 +++ b/libc/inet/resolv.c
838 @@ -1643,7 +1643,7 @@ int attribute_hidden __read_etc_hosts_r(FILE * fp, const char * name, int type,
841 #ifdef __UCLIBC_HAS_IPV6__
842 - } else if (type == AF_INET6 && inet_pton(AF_INET6, alias[0], in6) > 0) {
843 + } else if (type == AF_INET6 && inet_pton(AF_INET6, alias[0], in6) > 0) {
844 DPRINTF("Found INET6\n");
847 @@ -1658,8 +1658,8 @@ int attribute_hidden __read_etc_hosts_r(FILE * fp, const char * name, int type,
851 - break; /* bad ip address */
853 + continue; /* bad ip address, keep searching */
856 if (action!=GETHOSTENT) {
858 diff --git a/libc/string/avr32/Makefile b/libc/string/avr32/Makefile
860 index 0000000..e19e9d9
862 +++ b/libc/string/avr32/Makefile
864 +# Makefile for uClibc
866 +# Copyright (C) 2000-2003 Erik Andersen <andersen@uclibc.org>
868 +# This program is free software; you can redistribute it and/or modify it under
869 +# the terms of the GNU Library General Public License as published by the Free
870 +# Software Foundation; either version 2 of the License, or (at your option) any
873 +# This program is distributed in the hope that it will be useful, but WITHOUT
874 +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
875 +# FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more
878 +# You should have received a copy of the GNU Library General Public License
879 +# along with this program; if not, write to the Free Software Foundation, Inc.,
880 +# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
882 +top_srcdir := ../../../
883 +top_builddir := ../../../
887 +include $(top_builddir)Rules.mak
888 +include ../Makefile.in
889 +include $(top_srcdir)Makerules
890 diff --git a/libc/string/avr32/bcopy.S b/libc/string/avr32/bcopy.S
892 index 0000000..87c1e04
894 +++ b/libc/string/avr32/bcopy.S
897 + * Copyright (C) 2004-2007 Atmel Corporation
899 + * This file is subject to the terms and conditions of the GNU Lesser General
900 + * Public License. See the file "COPYING.LIB" in the main directory of this
901 + * archive for more details.
904 +#include <features.h>
906 +#ifdef __UCLIBC_SUSV3_LEGACY__
910 + .type bcopy, @function
913 + /* Swap the first two arguments */
919 + .size bcopy, . - bcopy
921 +#endif /* __UCLIBC_SUSV3_LEGACY__ */
922 diff --git a/libc/string/avr32/bzero.S b/libc/string/avr32/bzero.S
924 index 0000000..c999e65
926 +++ b/libc/string/avr32/bzero.S
929 + * Copyright (C) 2004-2007 Atmel Corporation
931 + * This file is subject to the terms and conditions of the GNU Lesser General
932 + * Public License. See the file "COPYING.LIB" in the main directory of this
933 + * archive for more details.
936 +#ifdef __UCLIBC_SUSV3_LEGACY__
940 + .type bzero, @function
947 + .size bzero, . - bzero
949 +#endif /* __UCLIBC_SUSV3_LEGACY__ */
950 diff --git a/libc/string/avr32/memcmp.S b/libc/string/avr32/memcmp.S
952 index 0000000..ae6cc91
954 +++ b/libc/string/avr32/memcmp.S
957 + * Copyright (C) 2004-2007 Atmel Corporation
959 + * This file is subject to the terms and conditions of the GNU Lesser General
960 + * Public License. See the file "COPYING.LIB" in the main directory of this
961 + * archive for more details.
964 +#include <features.h>
972 + .type memcmp, @function
1001 +2: bfextu r11, r9, 24, 8
1002 + bfextu r12, r8, 24, 8
1011 + .size memcmp, . - memcmp
1013 +libc_hidden_def(memcmp)
1014 +#ifdef __UCLIBC_SUSV3_LEGACY__
1015 +strong_alias(memcmp,bcmp)
1017 diff --git a/libc/string/avr32/memcpy.S b/libc/string/avr32/memcpy.S
1018 new file mode 100644
1019 index 0000000..bf091ab
1021 +++ b/libc/string/avr32/memcpy.S
1024 + * Copyright (C) 2004-2007 Atmel Corporation
1026 + * This file is subject to the terms and conditions of the GNU Lesser General
1027 + * Public License. See the file "COPYING.LIB" in the main directory of this
1028 + * archive for more details.
1031 +/* Don't use r12 as dst since we must return it unmodified */
1038 + .type memcpy, @function
1043 + /* If we have less than 32 bytes, don't do anything fancy */
1045 + brge .Lmore_than_31
1058 + /* Check alignment */
1061 + brne .Lunaligned_src
1064 + brne .Lunaligned_dst
1068 + brlt .Lless_than_32
1070 +1: /* Copy 32 bytes at a time */
1079 + /* Copy 16 more bytes if possible */
1081 + brlt .Lless_than_16
1089 + /* Do the remaining as byte copies */
1091 + add pc, pc, len << 2
1100 + /* Make src cacheline-aligned. r8 = (src & 31) */
1108 + /* If dst is word-aligned, we're ready to go */
1112 + breq .Laligned_copy
1115 + /* src is aligned, but dst is not. Expect bad performance */
1124 + add pc, pc, len << 2
1131 + .size memcpy, . - memcpy
1133 +libc_hidden_def(memcpy)
1134 diff --git a/libc/string/avr32/memmove.S b/libc/string/avr32/memmove.S
1135 new file mode 100644
1136 index 0000000..98287c5
1138 +++ b/libc/string/avr32/memmove.S
1141 + * Copyright (C) 2004-2007 Atmel Corporation
1143 + * This file is subject to the terms and conditions of the GNU Lesser General
1144 + * Public License. See the file "COPYING.LIB" in the main directory of this
1145 + * archive for more details.
1154 + .type memmove, @function
1164 + * The rest is basically the same as in memcpy.S except that
1165 + * the direction is reversed.
1168 + brge .Lmore_than_31
1181 + /* Check alignment */
1184 + brne .Lunaligned_src
1187 + brne .Lunaligned_dst
1191 + brlt .Lless_than_32
1193 +1: /* Copy 32 bytes at a time */
1202 + /* Copy 16 more bytes if possible */
1204 + brlt .Lless_than_16
1212 + /* Do the remaining as byte copies */
1223 + /* Make src cacheline-aligned. r8 = (src & 31) */
1230 + /* If dst is word-aligned, we're ready to go */
1234 + breq .Laligned_copy
1237 + /* src is aligned, but dst is not. Expect bad performance */
1246 + add pc, pc, len << 2
1253 + .size memmove, . - memmove
1255 +libc_hidden_def(memmove)
1256 diff --git a/libc/string/avr32/memset.S b/libc/string/avr32/memset.S
1257 new file mode 100644
1258 index 0000000..33cfaed
1260 +++ b/libc/string/avr32/memset.S
1263 + * Copyright (C) 2004-2007 Atmel Corporation
1265 + * This file is subject to the terms and conditions of the GNU Lesser General
1266 + * Public License. See the file "COPYING.LIB" in the main directory of this
1267 + * archive for more details.
1270 +#include <features.h>
1278 + .type memset, @function
1282 + .type __memset, @function
1289 + brge .Llarge_memset
1302 + bfins r8, r8, 8, 8
1303 + bfins r8, r8, 16, 16
1320 + /* If we are done, n == -8 and we'll skip all st.b insns below */
1329 + .size memset, . - memset
1331 +libc_hidden_def(memset)
1332 diff --git a/libc/string/avr32/strcmp.S b/libc/string/avr32/strcmp.S
1333 new file mode 100644
1334 index 0000000..f73bd43
1336 +++ b/libc/string/avr32/strcmp.S
1339 + * Copyright (C) 2004-2007 Atmel Corporation
1341 + * This file is subject to the terms and conditions of the GNU Lesser General
1342 + * Public License. See the file "COPYING.LIB" in the main directory of this
1343 + * archive for more details.
1346 +#include <features.h>
1354 + .type strcmp, @function
1359 + brne .Lunaligned_s1
1361 + brne .Lunaligned_s2
1371 +2: bfextu r12, r8, 24, 8
1372 + bfextu r11, r9, 24, 8
1377 + bfextu r12, r8, 16, 8
1378 + bfextu r11, r9, 16, 8
1383 + bfextu r12, r8, 8, 8
1384 + bfextu r11, r9, 8, 8
1389 + bfextu r12, r8, 0, 8
1390 + bfextu r11, r9, 0, 8
1410 + * s1 and s2 can't both be aligned, and unaligned word loads
1411 + * can trigger spurious exceptions if we cross a page boundary.
1412 + * Do it the slow way...
1422 + .size strcmp, . - strcmp
1424 +libc_hidden_def(strcmp)
1425 +#ifndef __UCLIBC_HAS_LOCALE__
1426 +strong_alias(strcmp, strcoll)
1427 +libc_hidden_def(strcoll)
1429 diff --git a/libc/string/avr32/strlen.S b/libc/string/avr32/strlen.S
1430 new file mode 100644
1431 index 0000000..5223e53
1433 +++ b/libc/string/avr32/strlen.S
1436 + * Copyright (C) 2004-2007 Atmel Corporation
1438 + * This file is subject to the terms and conditions of the GNU Lesser General
1439 + * Public License. See the file "COPYING.LIB" in the main directory of this
1440 + * archive for more details.
1443 +#include <features.h>
1449 + .type strlen, @function
1455 + brne .Lunaligned_str
1462 + bfextu r9, r8, 24, 8
1466 + bfextu r9, r8, 16, 8
1470 + bfextu r9, r8, 8, 8
1478 + add pc, pc, r9 << 3
1479 + sub r0, r0, 0 /* 4-byte nop */
1494 + .size strlen, . - strlen
1496 +libc_hidden_def(strlen)
1497 diff --git a/libc/sysdeps/linux/avr32/Makefile b/libc/sysdeps/linux/avr32/Makefile
1498 new file mode 100644
1499 index 0000000..338abc0
1501 +++ b/libc/sysdeps/linux/avr32/Makefile
1503 +# Makefile for uClibc
1505 +# Copyright (C) 2000-2003 Erik Andersen <andersen@uclibc.org>
1507 +# This program is free software; you can redistribute it and/or modify it under
1508 +# the terms of the GNU Library General Public License as published by the Free
1509 +# Software Foundation; either version 2 of the License, or (at your option) any
1512 +# This program is distributed in the hope that it will be useful, but WITHOUT
1513 +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
1514 +# FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more
1517 +# You should have received a copy of the GNU Library General Public License
1518 +# along with this program; if not, write to the Free Software Foundation, Inc.,
1519 +# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1521 +top_srcdir=../../../../
1522 +top_builddir=../../../../
1525 +include $(top_builddir)Rules.mak
1526 +include Makefile.arch
1527 +include $(top_srcdir)Makerules
1528 diff --git a/libc/sysdeps/linux/avr32/Makefile.arch b/libc/sysdeps/linux/avr32/Makefile.arch
1529 new file mode 100644
1530 index 0000000..44fc01e
1532 +++ b/libc/sysdeps/linux/avr32/Makefile.arch
1534 +# Makefile for uClibc
1536 +# Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
1538 +# Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
1541 +CSRC := brk.c clone.c mmap.c sigaction.c
1543 +SSRC := __longjmp.S setjmp.S bsd-setjmp.S bsd-_setjmp.S \
1544 + sigrestorer.S syscall.S vfork.S
1546 +include $(top_srcdir)/libc/sysdeps/linux/Makefile.commonarch
1547 diff --git a/libc/sysdeps/linux/avr32/__longjmp.S b/libc/sysdeps/linux/avr32/__longjmp.S
1548 new file mode 100644
1549 index 0000000..6154bb2
1551 +++ b/libc/sysdeps/linux/avr32/__longjmp.S
1554 + * Copyright (C) 2004-2007 Atmel Corporation
1556 + * This file is subject to the terms and conditions of the GNU Lesser General
1557 + * Public License. See the file "COPYING.LIB" in the main directory of this
1558 + * archive for more details.
1562 + .type __longjmp,"function"
1565 + ldm r12++, r0-r8,sp,lr
1566 + mustr r8 /* restore status register (lower half) */
1567 + cp r11, 0 /* can't return zero */
1571 + .size __longjmp, . - __longjmp
1573 +libc_hidden_def(__longjmp)
1574 diff --git a/libc/sysdeps/linux/avr32/bits/atomic.h b/libc/sysdeps/linux/avr32/bits/atomic.h
1575 new file mode 100644
1576 index 0000000..e6be41f
1578 +++ b/libc/sysdeps/linux/avr32/bits/atomic.h
1581 + * Copyright (C) 2007 Atmel Corporation
1583 + * This file is subject to the terms and conditions of the GNU Lesser General
1584 + * Public License. See the file "COPYING.LIB" in the main directory of this
1585 + * archive for more details.
1587 +#ifndef _AVR32_BITS_ATOMIC_H
1588 +#define _AVR32_BITS_ATOMIC_H 1
1590 +#include <inttypes.h>
1592 +typedef int32_t atomic32_t;
1593 +typedef uint32_t uatomic32_t;
1594 +typedef int_fast32_t atomic_fast32_t;
1595 +typedef uint_fast32_t uatomic_fast32_t;
1597 +typedef intptr_t atomicptr_t;
1598 +typedef uintptr_t uatomicptr_t;
1599 +typedef intmax_t atomic_max_t;
1600 +typedef uintmax_t uatomic_max_t;
1602 +#define __arch_compare_and_exchange_val_8_acq(mem, newval, oldval) \
1605 +#define __arch_compare_and_exchange_val_16_acq(mem, newval, oldval) \
1608 +#define __arch_compare_and_exchange_val_32_acq(mem, newval, oldval) \
1610 + __typeof__(*(mem)) __prev; \
1611 + __asm__ __volatile__( \
1612 + "/* __arch_compare_and_exchange_val_32_acq */\n" \
1614 + " ld.w %[result], %[m]\n" \
1615 + " cp.w %[result], %[old]\n" \
1617 + " stcond %[m], %[new]\n" \
1620 + : [result] "=&r"(__result), [m] "=m"(*(mem)) \
1621 + : "m"(*(mem)), [old] "ir"(oldval), \
1622 + [new] "r"(newval) \
1623 + : "memory", "cc"); \
1627 +#define __arch_compare_and_exchange_val_64_acq(mem, newval, oldval) \
1630 +#define __arch_exchange_32_acq(mem, newval) \
1632 + __typeof__(*(mem)) __oldval; \
1633 + __asm__ __volatile__( \
1634 + "/*__arch_exchange_32_acq */\n" \
1635 + " xchg %[old], %[m], %[new]" \
1636 + : [old] "=&r"(__oldval) \
1637 + : [m] "r"(mem), [new] "r"(newval) \
1642 +#define __arch_atomic_exchange_and_add_32(mem, value) \
1644 + __typeof__(*(mem)) __oldval, __tmp; \
1645 + __asm__ __volatile__( \
1646 + "/* __arch_atomic_exchange_and_add_32 */\n" \
1648 + " ld.w %[old], %[m]\n" \
1649 + " add %[tmp], %[old], %[val]\n" \
1650 + " stcond %[m], %[tmp]\n" \
1652 + : [old] "=&r"(__oldval), [tmp] "=&r"(__tmp), \
1653 + [m] "=m"(*(mem)) \
1654 + : "m"(*(mem)), [val] "r"(value) \
1655 + : "memory", "cc"); \
1659 +#define __arch_atomic_decrement_if_positive_32(mem) \
1661 + __typeof__(*(mem)) __oldval, __tmp; \
1662 + __asm__ __volatile__( \
1663 + "/* __arch_atomic_decrement_if_positive_32 */\n" \
1665 + " ld.w %[old], %[m]\n" \
1666 + " sub %[tmp], %[old], 1\n" \
1668 + " stcond %[m], %[tmp]\n" \
1671 + : [old] "=&r"(__oldval), [tmp] "=&r"(__tmp), \
1672 + [m] "=m"(*(mem)) \
1674 + : "memory", "cc"); \
1678 +#define atomic_exchange_acq(mem, newval) \
1680 + if (sizeof(*(mem)) != 4) \
1682 + __arch_exchange_32_acq(mem, newval); \
1685 +#define atomic_exchange_and_add(mem, newval) \
1687 + if (sizeof(*(mem)) != 4) \
1689 + __arch_atomic_exchange_and_add_32(mem, newval); \
1692 +#define atomic_decrement_if_positive(mem) \
1694 + if (sizeof(*(mem)) != 4) \
1696 + __arch_atomic_decrement_if_positive_32(mem); \
1699 +#endif /* _AVR32_BITS_ATOMIC_H */
1700 diff --git a/libc/sysdeps/linux/avr32/bits/byteswap.h b/libc/sysdeps/linux/avr32/bits/byteswap.h
1701 new file mode 100644
1702 index 0000000..1c030b9
1704 +++ b/libc/sysdeps/linux/avr32/bits/byteswap.h
1707 + * Copyright (C) 2005 Atmel Corporation
1709 + * This file is subject to the terms and conditions of the GNU Lesser General
1710 + * Public License. See the file "COPYING.LIB" in the main directory of this
1711 + * archive for more details.
1714 +#if !defined _BYTESWAP_H && !defined _NETINET_IN_H
1715 +# error "Never use <bits/byteswap.h> directly; include <byteswap.h> instead."
1718 +#ifndef _BITS_BYTESWAP_H
1719 +#define _BITS_BYTESWAP_H 1
1721 +/* Swap bytes in 16 bit value. */
1722 +#if defined __GNUC__
1723 +# define __bswap_16(x) (__extension__ __builtin_bswap_16(x))
1725 +/* This is better than nothing. */
1726 +static __inline unsigned short int
1727 +__bswap_16 (unsigned short int __bsx)
1729 + return ((((__bsx) >> 8) & 0xff) | (((__bsx) & 0xff) << 8));
1733 +/* Swap bytes in 32 bit value. */
1734 +#if defined __GNUC__
1735 +# define __bswap_32(x) (__extension__ __builtin_bswap_32(x))
1737 +static __inline unsigned int
1738 +__bswap_32 (unsigned int __bsx)
1740 + return ((((__bsx) & 0xff000000) >> 24) | (((__bsx) & 0x00ff0000) >> 8) |
1741 + (((__bsx) & 0x0000ff00) << 8) | (((__bsx) & 0x000000ff) << 24));
1745 +#if defined __GNUC__
1746 +/* Swap bytes in 64 bit value. */
1747 +# define __bswap_constant_64(x) \
1748 + ((((x) & 0xff00000000000000ull) >> 56) \
1749 + | (((x) & 0x00ff000000000000ull) >> 40) \
1750 + | (((x) & 0x0000ff0000000000ull) >> 24) \
1751 + | (((x) & 0x000000ff00000000ull) >> 8) \
1752 + | (((x) & 0x00000000ff000000ull) << 8) \
1753 + | (((x) & 0x0000000000ff0000ull) << 24) \
1754 + | (((x) & 0x000000000000ff00ull) << 40) \
1755 + | (((x) & 0x00000000000000ffull) << 56))
1757 +# define __bswap_64(x) \
1761 + __extension__ unsigned long long int __ll; \
1762 + unsigned int __l[2]; \
1764 + if (__builtin_constant_p(x)) \
1765 + __r.__ll = __bswap_constant_64(x); \
1768 + __r.__l[0] = __bswap_32(__w.__l[1]); \
1769 + __r.__l[1] = __bswap_32(__w.__l[0]); \
1775 +#endif /* _BITS_BYTESWAP_H */
1776 diff --git a/libc/sysdeps/linux/avr32/bits/endian.h b/libc/sysdeps/linux/avr32/bits/endian.h
1777 new file mode 100644
1778 index 0000000..7bb6358
1780 +++ b/libc/sysdeps/linux/avr32/bits/endian.h
1782 +/* AVR32 is big-endian */
1785 +# error "Never use <bits/endian.h> directly; include <endian.h> instead."
1788 +#define __BYTE_ORDER __BIG_ENDIAN
1789 diff --git a/libc/sysdeps/linux/avr32/bits/fcntl.h b/libc/sysdeps/linux/avr32/bits/fcntl.h
1790 new file mode 100644
1791 index 0000000..1abff17
1793 +++ b/libc/sysdeps/linux/avr32/bits/fcntl.h
1796 +# error "Never use <bits/fcntl.h> directly; include <fcntl.h> instead."
1799 +#include <sys/types.h>
1802 + * open/fcntl - O_SYNC is only implemented on blocks devices and on files
1803 + * located on an ext2 file system
1805 +#define O_ACCMODE 00000003
1806 +#define O_RDONLY 00000000
1807 +#define O_WRONLY 00000001
1808 +#define O_RDWR 00000002
1809 +#define O_CREAT 00000100 /* not fcntl */
1810 +#define O_EXCL 00000200 /* not fcntl */
1811 +#define O_NOCTTY 00000400 /* not fcntl */
1812 +#define O_TRUNC 00001000 /* not fcntl */
1813 +#define O_APPEND 00002000
1814 +#define O_NONBLOCK 00004000
1815 +#define O_NDELAY O_NONBLOCK
1816 +#define O_SYNC 00010000
1817 +#define O_ASYNC 00020000
1820 +# define O_DIRECT 00040000 /* must be a directory */
1821 +# define O_DIRECTORY 00200000 /* direct disk access */
1822 +# define O_NOFOLLOW 00400000 /* don't follow links */
1823 +# define O_NOATIME 01000000 /* don't set atime */
1826 +#ifdef __USE_LARGEFILE64
1827 +# define O_LARGEFILE 00100000
1830 +/* For now Linux has synchronisity options for data and read operations.
1831 + We define the symbols here but let them do the same as O_SYNC since
1832 + this is a superset. */
1833 +#if defined __USE_POSIX199309 || defined __USE_UNIX98
1834 +# define O_DSYNC O_SYNC /* Synchronize data. */
1835 +# define O_RSYNC O_SYNC /* Synchronize read operations. */
1838 +#define F_DUPFD 0 /* dup */
1839 +#define F_GETFD 1 /* get close_on_exec */
1840 +#define F_SETFD 2 /* set/clear close_on_exec */
1841 +#define F_GETFL 3 /* get file->f_flags */
1842 +#define F_SETFL 4 /* set file->f_flags */
1844 +#ifndef __USE_FILE_OFFSET64
1847 +# define F_SETLKW 7
1849 +# define F_GETLK F_GETLK64
1850 +# define F_SETLK F_SETLK64
1851 +# define F_SETLKW F_SETLKW64
1853 +#define F_GETLK64 12 /* using 'struct flock64' */
1854 +#define F_SETLK64 13
1855 +#define F_SETLKW64 14
1857 +#if defined __USE_BSD || defined __USE_XOPEN2K
1858 +# define F_SETOWN 8 /* for sockets. */
1859 +# define F_GETOWN 9 /* for sockets. */
1863 +# define F_SETSIG 10 /* for sockets. */
1864 +# define F_GETSIG 11 /* for sockets. */
1868 +# define F_SETLEASE 1024 /* Set a lease. */
1869 +# define F_GETLEASE 1025 /* Enquire what lease is active. */
1870 +# define F_NOTIFY 1026 /* Request notfications on a directory. */
1873 +/* for F_[GET|SET]FL */
1874 +#define FD_CLOEXEC 1 /* actually anything with low bit set goes */
1876 +/* for posix fcntl() and lockf() */
1881 +/* for old implementation of bsd flock () */
1882 +#define F_EXLCK 4 /* or 3 */
1883 +#define F_SHLCK 8 /* or 4 */
1886 +#define F_INPROGRESS 16
1889 +/* operations for bsd flock(), also used by the kernel implementation */
1890 +# define LOCK_SH 1 /* shared lock */
1891 +# define LOCK_EX 2 /* exclusive lock */
1892 +# define LOCK_NB 4 /* or'd with one of the above to prevent
1894 +# define LOCK_UN 8 /* remove lock */
1898 +# define LOCK_MAND 32 /* This is a mandatory flock */
1899 +# define LOCK_READ 64 /* ... Which allows concurrent
1900 + read operations */
1901 +# define LOCK_WRITE 128 /* ... Which allows concurrent
1902 + write operations */
1903 +# define LOCK_RW 192 /* ... Which allows concurrent
1904 + read & write ops */
1908 +/* Types of directory notifications that may be requested with F_NOTIFY. */
1909 +# define DN_ACCESS 0x00000001 /* File accessed. */
1910 +# define DN_MODIFY 0x00000002 /* File modified. */
1911 +# define DN_CREATE 0x00000004 /* File created. */
1912 +# define DN_DELETE 0x00000008 /* File removed. */
1913 +# define DN_RENAME 0x00000010 /* File renamed. */
1914 +# define DN_ATTRIB 0x00000020 /* File changed attibutes. */
1915 +# define DN_MULTISHOT 0x80000000 /* Don't remove notifier. */
1921 +#ifndef __USE_FILE_OFFSET64
1925 + __off64_t l_start;
1931 +#ifdef __USE_LARGEFILE64
1935 + __off64_t l_start;
1941 +/* Define some more compatibility macros to be backward compatible with
1942 + * BSD systems which did not managed to hide these kernel macros. */
1944 +# define FAPPEND O_APPEND
1945 +# define FFSYNC O_FSYNC
1946 +# define FASYNC O_ASYNC
1947 +# define FNONBLOCK O_NONBLOCK
1948 +# define FNDELAY O_NDELAY
1949 +#endif /* Use BSD. */
1951 +/* Advise to `posix_fadvise'. */
1952 +#ifdef __USE_XOPEN2K
1953 +# define POSIX_FADV_NORMAL 0 /* No further special treatment. */
1954 +# define POSIX_FADV_RANDOM 1 /* Expect random page references. */
1955 +# define POSIX_FADV_SEQUENTIAL 2 /* Expect sequential page references. */
1956 +# define POSIX_FADV_WILLNEED 3 /* Will need these pages. */
1957 +# define POSIX_FADV_DONTNEED 4 /* Don't need these pages. */
1958 +# define POSIX_FADV_NOREUSE 5 /* Data will be accessed once. */
1960 diff --git a/libc/sysdeps/linux/avr32/bits/kernel_stat.h b/libc/sysdeps/linux/avr32/bits/kernel_stat.h
1961 new file mode 100644
1962 index 0000000..f97d23b
1964 +++ b/libc/sysdeps/linux/avr32/bits/kernel_stat.h
1966 +#ifndef _BITS_STAT_STRUCT_H
1967 +#define _BITS_STAT_STRUCT_H
1970 +#error bits/kernel_stat.h is for internal uClibc use only!
1974 + * This file provides struct stat, taken from kernel 2.6.4. Verified
1975 + * to match kernel 2.6.22.
1978 +struct kernel_stat {
1979 + unsigned long st_dev;
1980 + unsigned long st_ino;
1981 + unsigned short st_mode;
1982 + unsigned short st_nlink;
1983 + unsigned short st_uid;
1984 + unsigned short st_gid;
1985 + unsigned long st_rdev;
1986 + unsigned long st_size;
1987 + unsigned long st_blksize;
1988 + unsigned long st_blocks;
1989 + unsigned long st_atime;
1990 + unsigned long st_atime_nsec;
1991 + unsigned long st_mtime;
1992 + unsigned long st_mtime_nsec;
1993 + unsigned long st_ctime;
1994 + unsigned long st_ctime_nsec;
1995 + unsigned long __unused4;
1996 + unsigned long __unused5;
1999 +#define STAT_HAVE_NSEC 1
2001 +struct kernel_stat64 {
2002 + unsigned long long st_dev;
2004 + unsigned long long st_ino;
2005 + unsigned int st_mode;
2006 + unsigned int st_nlink;
2008 + unsigned long st_uid;
2009 + unsigned long st_gid;
2011 + unsigned long long st_rdev;
2013 + long long st_size;
2014 + unsigned long __pad1;
2015 + unsigned long st_blksize;
2017 + unsigned long long st_blocks;
2019 + unsigned long st_atime;
2020 + unsigned long st_atime_nsec;
2022 + unsigned long st_mtime;
2023 + unsigned long st_mtime_nsec;
2025 + unsigned long st_ctime;
2026 + unsigned long st_ctime_nsec;
2028 + unsigned long __unused1;
2029 + unsigned long __unused2;
2032 +#endif /* _BITS_STAT_STRUCT_H */
2033 diff --git a/libc/sysdeps/linux/avr32/bits/kernel_types.h b/libc/sysdeps/linux/avr32/bits/kernel_types.h
2034 new file mode 100644
2035 index 0000000..f7d8b52
2037 +++ b/libc/sysdeps/linux/avr32/bits/kernel_types.h
2039 +/* Note that we use the exact same include guard #define names
2040 + * as asm/posix_types.h. This will avoid gratuitous conflicts
2041 + * with the posix_types.h kernel header, and will ensure that
2042 + * our private content, and not the kernel header, will win.
2045 +#ifndef __ASM_AVR32_POSIX_TYPES_H
2046 +#define __ASM_AVR32_POSIX_TYPES_H
2049 + * This file is generally used by user-level software, so you need to
2050 + * be a little careful about namespace pollution etc. Also, we cannot
2051 + * assume GCC is being used.
2054 +typedef unsigned long __kernel_dev_t;
2055 +typedef unsigned long __kernel_ino_t;
2056 +typedef unsigned short __kernel_mode_t;
2057 +typedef unsigned short __kernel_nlink_t;
2058 +typedef long __kernel_off_t;
2059 +typedef int __kernel_pid_t;
2060 +typedef unsigned short __kernel_ipc_pid_t;
2061 +typedef unsigned int __kernel_uid_t;
2062 +typedef unsigned int __kernel_gid_t;
2063 +typedef unsigned long __kernel_size_t;
2064 +typedef long __kernel_ssize_t;
2065 +typedef int __kernel_ptrdiff_t;
2066 +typedef long __kernel_time_t;
2067 +typedef long __kernel_suseconds_t;
2068 +typedef long __kernel_clock_t;
2069 +typedef int __kernel_timer_t;
2070 +typedef int __kernel_clockid_t;
2071 +typedef int __kernel_daddr_t;
2072 +typedef char * __kernel_caddr_t;
2073 +typedef unsigned short __kernel_uid16_t;
2074 +typedef unsigned short __kernel_gid16_t;
2075 +typedef unsigned int __kernel_uid32_t;
2076 +typedef unsigned int __kernel_gid32_t;
2077 +typedef unsigned short __kernel_old_uid_t;
2078 +typedef unsigned short __kernel_old_gid_t;
2079 +typedef unsigned short __kernel_old_dev_t;
2082 +typedef long long __kernel_loff_t;
2086 +#if defined(__USE_ALL)
2093 +#endif /* __ASM_AVR32_POSIX_TYPES_H */
2094 diff --git a/libc/sysdeps/linux/avr32/bits/mman.h b/libc/sysdeps/linux/avr32/bits/mman.h
2095 new file mode 100644
2096 index 0000000..5f6e3c3
2098 +++ b/libc/sysdeps/linux/avr32/bits/mman.h
2100 +/* Definitions for POSIX memory map interface. Linux/AVR32 version.
2101 + Copyright (C) 1997, 2000 Free Software Foundation, Inc.
2102 + This file is part of the GNU C Library.
2104 + The GNU C Library is free software; you can redistribute it and/or
2105 + modify it under the terms of the GNU Lesser General Public
2106 + License as published by the Free Software Foundation; either
2107 + version 2.1 of the License, or (at your option) any later version.
2109 + The GNU C Library is distributed in the hope that it will be useful,
2110 + but WITHOUT ANY WARRANTY; without even the implied warranty of
2111 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2112 + Lesser General Public License for more details.
2114 + You should have received a copy of the GNU Lesser General Public
2115 + License along with the GNU C Library; if not, write to the Free
2116 + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
2117 + 02111-1307 USA. */
2119 +#ifndef _SYS_MMAN_H
2120 +# error "Never include this file directly. Use <sys/mman.h> instead"
2123 +/* The following definitions basically come from the kernel headers.
2124 + But the kernel header is not namespace clean. */
2127 +/* Protections are chosen from these bits, OR'd together. The
2128 + implementation does not necessarily support PROT_EXEC or PROT_WRITE
2129 + without PROT_READ. The only guarantees are that no writing will be
2130 + allowed without PROT_WRITE and no access will be allowed for PROT_NONE. */
2132 +#define PROT_READ 0x1 /* Page can be read. */
2133 +#define PROT_WRITE 0x2 /* Page can be written. */
2134 +#define PROT_EXEC 0x4 /* Page can be executed. */
2135 +#define PROT_NONE 0x0 /* Page can not be accessed. */
2136 +#define PROT_GROWSDOWN 0x01000000 /* Extend change to start of
2137 + growsdown vma (mprotect only). */
2138 +#define PROT_GROWSUP 0x02000000 /* Extend change to start of
2139 + growsup vma (mprotect only). */
2141 +/* Sharing types (must choose one and only one of these). */
2142 +#define MAP_SHARED 0x01 /* Share changes. */
2143 +#define MAP_PRIVATE 0x02 /* Changes are private. */
2145 +# define MAP_TYPE 0x0f /* Mask for type of mapping. */
2149 +#define MAP_FIXED 0x10 /* Interpret addr exactly. */
2151 +# define MAP_FILE 0
2152 +# define MAP_ANONYMOUS 0x20 /* Don't use a file. */
2153 +# define MAP_ANON MAP_ANONYMOUS
2156 +/* These are Linux-specific. */
2158 +# define MAP_GROWSDOWN 0x0100 /* Stack-like segment. */
2159 +# define MAP_DENYWRITE 0x0800 /* ETXTBSY */
2160 +# define MAP_EXECUTABLE 0x1000 /* Mark it as an executable. */
2161 +# define MAP_LOCKED 0x2000 /* Lock the mapping. */
2162 +# define MAP_NORESERVE 0x4000 /* Don't check for reservations. */
2163 +# define MAP_POPULATE 0x8000 /* populate (prefault) pagetables */
2164 +# define MAP_NONBLOCK 0x10000 /* do not block on IO */
2167 +/* Flags to `msync'. */
2168 +#define MS_ASYNC 1 /* Sync memory asynchronously. */
2169 +#define MS_SYNC 4 /* Synchronous memory sync. */
2170 +#define MS_INVALIDATE 2 /* Invalidate the caches. */
2172 +/* Flags for `mlockall'. */
2173 +#define MCL_CURRENT 1 /* Lock all currently mapped pages. */
2174 +#define MCL_FUTURE 2 /* Lock all additions to address
2177 +/* Flags for `mremap'. */
2179 +# define MREMAP_MAYMOVE 1
2180 +# define MREMAP_FIXED 2
2183 +/* Advise to `madvise'. */
2185 +# define MADV_NORMAL 0 /* No further special treatment. */
2186 +# define MADV_RANDOM 1 /* Expect random page references. */
2187 +# define MADV_SEQUENTIAL 2 /* Expect sequential page references. */
2188 +# define MADV_WILLNEED 3 /* Will need these pages. */
2189 +# define MADV_DONTNEED 4 /* Don't need these pages. */
2190 +# define MADV_REMOVE 9 /* Remove these pages and resources. */
2191 +# define MADV_DONTFORK 10 /* Do not inherit across fork. */
2192 +# define MADV_DOFORK 11 /* Do inherit across fork. */
2195 +/* The POSIX people had to invent similar names for the same things. */
2196 +#ifdef __USE_XOPEN2K
2197 +# define POSIX_MADV_NORMAL 0 /* No further special treatment. */
2198 +# define POSIX_MADV_RANDOM 1 /* Expect random page references. */
2199 +# define POSIX_MADV_SEQUENTIAL 2 /* Expect sequential page references. */
2200 +# define POSIX_MADV_WILLNEED 3 /* Will need these pages. */
2201 +# define POSIX_MADV_DONTNEED 4 /* Don't need these pages. */
2203 diff --git a/libc/sysdeps/linux/avr32/bits/setjmp.h b/libc/sysdeps/linux/avr32/bits/setjmp.h
2204 new file mode 100644
2205 index 0000000..78348a3
2207 +++ b/libc/sysdeps/linux/avr32/bits/setjmp.h
2210 + * Copyright (C) 2004-2005 Atmel Corporation
2212 + * This file is subject to the terms and conditions of the GNU Lesser General
2213 + * Public License. See the file "COPYING.LIB" in the main directory of this
2214 + * archive for more details.
2216 +#ifndef _BITS_SETJMP_H
2217 +#define _BITS_SETJMP_H 1
2219 +#if !defined _SETJMP_H && !defined _PTHREAD_H
2220 +# error "Never include <bits/setjmp.h> directly; use <setjmp.h> instead."
2225 + * The jump buffer contains r0-r7, sr, sp and lr. Other registers are
2228 +typedef int __jmp_buf[11];
2231 +#define __JMP_BUF_SP 4
2233 +/* Test if longjmp to JMPBUF would unwind the frame containing a local
2234 + variable at ADDRESS. */
2235 +#define _JMPBUF_UNWINDS(jmpbuf, address) \
2236 + ((void *)(address) < (void *)(jmpbuf[__JMP_BUF_SP]))
2238 +#endif /* _BITS_SETJMP_H */
2239 diff --git a/libc/sysdeps/linux/avr32/bits/stackinfo.h b/libc/sysdeps/linux/avr32/bits/stackinfo.h
2240 new file mode 100644
2241 index 0000000..29b8452
2243 +++ b/libc/sysdeps/linux/avr32/bits/stackinfo.h
2245 +/* Copyright (C) 1999 Free Software Foundation, Inc.
2246 + This file is part of the GNU C Library.
2248 + The GNU C Library is free software; you can redistribute it and/or
2249 + modify it under the terms of the GNU Lesser General Public
2250 + License as published by the Free Software Foundation; either
2251 + version 2.1 of the License, or (at your option) any later version.
2253 + The GNU C Library is distributed in the hope that it will be useful,
2254 + but WITHOUT ANY WARRANTY; without even the implied warranty of
2255 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2256 + Lesser General Public License for more details.
2258 + You should have received a copy of the GNU Lesser General Public
2259 + License along with the GNU C Library; if not, write to the Free
2260 + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
2261 + 02111-1307 USA. */
2263 +/* This file contains a bit of information about the stack allocation
2264 + of the processor. */
2266 +#ifndef _STACKINFO_H
2267 +#define _STACKINFO_H 1
2269 +/* On AVR32 the stack grows down. */
2270 +#define _STACK_GROWS_DOWN 1
2272 +#endif /* stackinfo.h */
2273 diff --git a/libc/sysdeps/linux/avr32/bits/syscalls.h b/libc/sysdeps/linux/avr32/bits/syscalls.h
2274 new file mode 100644
2275 index 0000000..22ac059
2277 +++ b/libc/sysdeps/linux/avr32/bits/syscalls.h
2279 +#ifndef _BITS_SYSCALLS_H
2280 +#define _BITS_SYSCALLS_H
2282 +# error "Never use <bits/syscalls.h> directly; include <sys/syscall.h> instead."
2286 + * This includes the `__NR_<name>' syscall numbers taken from the
2287 + * Linux kernel header files. It also defines the traditional
2288 + * `SYS_<name>' macros for older programs.
2290 +#include <bits/sysnum.h>
2292 +#ifndef __ASSEMBLER__
2296 +#define SYS_ify(syscall_name) (__NR_##syscall_name)
2299 +#define _syscall0(type,name) \
2302 + return (type)(INLINE_SYSCALL(name, 0)); \
2306 +#define _syscall1(type,name,type1,arg1) \
2307 + type name(type1 arg1) \
2309 + return (type)(INLINE_SYSCALL(name, 1, arg1)); \
2313 +#define _syscall2(type,name,type1,arg1,type2,arg2) \
2314 + type name(type1 arg1, type2 arg2) \
2316 + return (type)(INLINE_SYSCALL(name, 2, arg1, arg2)); \
2320 +#define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \
2321 + type name(type1 arg1, type2 arg2, type3 arg3) \
2323 + return (type)(INLINE_SYSCALL(name, 3, arg1, \
2328 +#define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3, \
2330 + type name(type1 arg1, type2 arg2, type3 arg3, type4 arg4) \
2332 + return (type)(INLINE_SYSCALL(name, 4, arg1, arg2, \
2337 +#define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3, \
2338 + type4,arg4,type5,arg5) \
2339 + type name(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \
2342 + return (type)(INLINE_SYSCALL(name, 5, arg1, arg2, \
2343 + arg3, arg4, arg5)); \
2347 +#define _syscall6(type,name,type1,arg1,type2,arg2,type3,arg3, \
2348 + type4,arg4,type5,arg5,type6,arg6) \
2349 + type name(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \
2350 + type5 arg5, type6 arg6) \
2352 + return (type)(INLINE_SYSCALL(name, 6, arg1, arg2, arg3, \
2353 + arg4, arg5, arg6)); \
2357 +#define unlikely(x) __builtin_expect((x), 0)
2359 +#undef INLINE_SYSCALL
2360 +#define INLINE_SYSCALL(name, nr, args...) \
2362 + unsigned _sys_result = INTERNAL_SYSCALL(name, , nr, args); \
2363 + if (unlikely(INTERNAL_SYSCALL_ERROR_P(_sys_result, ))) { \
2364 + __set_errno(INTERNAL_SYSCALL_ERRNO(_sys_result, )); \
2365 + _sys_result = (unsigned int) -1; \
2367 + (int) _sys_result; \
2370 +#undef INTERNAL_SYSCALL_DECL
2371 +#define INTERNAL_SYSCALL_DECL(err) do { } while(0)
2373 +#undef INTERNAL_SYSCALL
2374 +#define INTERNAL_SYSCALL(name, err, nr, args...) \
2376 + register int _a1 asm ("r12"); \
2377 + register int _scno asm("r8") = SYS_ify(name); \
2378 + LOAD_ARGS_##nr (args); \
2379 + asm volatile ("scall /* syscall " #name " */" \
2381 + : "r"(_scno) ASM_ARGS_##nr \
2382 + : "cc", "memory"); \
2386 +#undef INTERNAL_SYSCALL_ERROR_P
2387 +#define INTERNAL_SYSCALL_ERROR_P(val, err) \
2388 + ((unsigned int)(val) >= 0xfffff001U)
2390 +#undef INTERNAL_SYSCALL_ERRNO
2391 +#define INTERNAL_SYSCALL_ERRNO(val, errr) (-(val))
2393 +#define LOAD_ARGS_0() do { } while(0)
2395 +#define LOAD_ARGS_1(a1) \
2396 + _a1 = (int) (a1); \
2398 +#define ASM_ARGS_1 ASM_ARGS_0, "r"(_a1)
2399 +#define LOAD_ARGS_2(a1, a2) \
2400 + register int _a2 asm("r11") = (int)(a2); \
2402 +#define ASM_ARGS_2 ASM_ARGS_1, "r"(_a2)
2403 +#define LOAD_ARGS_3(a1, a2, a3) \
2404 + register int _a3 asm("r10") = (int)(a3); \
2405 + LOAD_ARGS_2(a1, a2)
2406 +#define ASM_ARGS_3 ASM_ARGS_2, "r"(_a3)
2407 +#define LOAD_ARGS_4(a1, a2, a3, a4) \
2408 + register int _a4 asm("r9") = (int)(a4); \
2409 + LOAD_ARGS_3(a1, a2, a3)
2410 +#define ASM_ARGS_4 ASM_ARGS_3, "r"(_a4)
2411 +#define LOAD_ARGS_5(a1, a2, a3, a4, a5) \
2412 + register int _a5 asm("r5") = (int)(a5); \
2413 + LOAD_ARGS_4(a1, a2, a3, a4)
2414 +#define ASM_ARGS_5 ASM_ARGS_4, "r"(_a5)
2415 +#define LOAD_ARGS_6(a1, a2, a3, a4, a5, a6) \
2416 + register int _a6 asm("r3") = (int)(a6); \
2417 + LOAD_ARGS_5(a1, a2, a3, a4, a5)
2418 +#define ASM_ARGS_6 ASM_ARGS_5, "r"(_a6)
2420 +#endif /* __ASSEMBLER__ */
2421 +#endif /* _BITS_SYSCALLS_H */
2422 diff --git a/libc/sysdeps/linux/avr32/bits/uClibc_arch_features.h b/libc/sysdeps/linux/avr32/bits/uClibc_arch_features.h
2423 new file mode 100644
2424 index 0000000..e95e8a5
2426 +++ b/libc/sysdeps/linux/avr32/bits/uClibc_arch_features.h
2429 + * Track misc arch-specific features that aren't config options
2432 +#ifndef _BITS_UCLIBC_ARCH_FEATURES_H
2433 +#define _BITS_UCLIBC_ARCH_FEATURES_H
2435 +/* instruction used when calling abort() to kill yourself */
2436 +/* trigger illegal instruction exception, same as BUG in Linux */
2437 +#define __UCLIBC_ABORT_INSTRUCTION__ ".short 0x5df0"
2439 +/* can your target use syscall6() for mmap ? */
2440 +#define __UCLIBC_MMAP_HAS_6_ARGS__
2442 +/* does your target use syscall4() for truncate64 ? (32bit arches only) */
2443 +#undef __UCLIBC_TRUNCATE64_HAS_4_ARGS__
2445 +/* does your target have a broken create_module() ? */
2446 +#undef __UCLIBC_BROKEN_CREATE_MODULE__
2448 +/* does your target have to worry about older [gs]etrlimit() ? */
2449 +#undef __UCLIBC_HANDLE_OLDER_RLIMIT__
2451 +/* does your target prefix all symbols with an _ ? */
2452 +#define __UCLIBC_NO_UNDERSCORES__
2454 +/* does your target have an asm .set ? */
2455 +#define __UCLIBC_HAVE_ASM_SET_DIRECTIVE__
2457 +/* define if target doesn't like .global */
2458 +#undef __UCLIBC_ASM_GLOBAL_DIRECTIVE__
2460 +/* define if target supports .weak */
2461 +#define __UCLIBC_HAVE_ASM_WEAK_DIRECTIVE__
2463 +/* define if target supports .weakext */
2464 +#undef __UCLIBC_HAVE_ASM_WEAKEXT_DIRECTIVE__
2466 +/* needed probably only for ppc64 */
2467 +#undef __UCLIBC_HAVE_ASM_GLOBAL_DOT_NAME__
2469 +/* define if target supports IEEE signed zero floats */
2470 +#define __UCLIBC_HAVE_SIGNED_ZERO__
2472 +#endif /* _BITS_UCLIBC_ARCH_FEATURES_H */
2473 diff --git a/libc/sysdeps/linux/avr32/bits/wordsize.h b/libc/sysdeps/linux/avr32/bits/wordsize.h
2474 new file mode 100644
2475 index 0000000..1b5842a
2477 +++ b/libc/sysdeps/linux/avr32/bits/wordsize.h
2479 +#define __WORDSIZE 32
2480 diff --git a/libc/sysdeps/linux/avr32/brk.c b/libc/sysdeps/linux/avr32/brk.c
2481 new file mode 100644
2482 index 0000000..a54b49a
2484 +++ b/libc/sysdeps/linux/avr32/brk.c
2487 + * Copyright (C) 2004-2007 Atmel Corporation
2489 + * This file is subject to the terms and conditions of the GNU Lesser General
2490 + * Public License. See the file "COPYING.LIB" in the main directory of this
2491 + * archive for more details.
2494 +#include <unistd.h>
2495 +#include <sys/syscall.h>
2497 +libc_hidden_proto(brk)
2499 +void *__curbrk attribute_hidden = 0;
2501 +int brk (void *addr)
2505 + newbrk = (void *)INLINE_SYSCALL(brk, 1, addr);
2507 + __curbrk = newbrk;
2509 + if (newbrk < addr) {
2510 + __set_errno (ENOMEM);
2516 +libc_hidden_def(brk)
2517 diff --git a/libc/sysdeps/linux/avr32/bsd-_setjmp.S b/libc/sysdeps/linux/avr32/bsd-_setjmp.S
2518 new file mode 100644
2519 index 0000000..be66a10
2521 +++ b/libc/sysdeps/linux/avr32/bsd-_setjmp.S
2524 + * Copyright (C) 2004-2007 Atmel Corporation
2526 + * This file is subject to the terms and conditions of the GNU Lesser General
2527 + * Public License. See the file "COPYING.LIB" in the main directory of this
2528 + * archive for more details.
2531 + /* This just does a tail-call to __sigsetjmp(env, 0) */
2533 + .type _setjmp,"function"
2537 + bral __GI___sigsetjmp
2538 + .size _setjmp, . - _setjmp
2539 diff --git a/libc/sysdeps/linux/avr32/bsd-setjmp.S b/libc/sysdeps/linux/avr32/bsd-setjmp.S
2540 new file mode 100644
2541 index 0000000..4635eeb
2543 +++ b/libc/sysdeps/linux/avr32/bsd-setjmp.S
2546 + * Copyright (C) 2004-2007 Atmel Corporation
2548 + * This file is subject to the terms and conditions of the GNU Lesser General
2549 + * Public License. See the file "COPYING.LIB" in the main directory of this
2550 + * archive for more details.
2553 + /* This just does a tail-call to __sigsetjmp(env, 1) */
2555 + .type setjmp,"function"
2559 + bral __GI___sigsetjmp
2560 + .size setjmp, . - setjmp
2561 diff --git a/libc/sysdeps/linux/avr32/clone.c b/libc/sysdeps/linux/avr32/clone.c
2562 new file mode 100644
2563 index 0000000..e43b0f3
2565 +++ b/libc/sysdeps/linux/avr32/clone.c
2568 + * Copyright (C) 2004 Atmel Corporation
2570 + * This file is subject to the terms and conditions of the GNU Lesser General
2571 + * Public License. See the file "COPYING.LIB" in the main directory of this
2572 + * archive for more details.
2575 +#include <sys/syscall.h>
2576 +#include <unistd.h>
2579 + * I don't know if we can be absolutely certain that the fn and arg
2580 + * parameters are preserved when returning as the child. If the
2581 + * compiler stores them in registers (r0-r7), they should be.
2583 +int clone(int (*fn)(void *arg), void *child_stack, int flags, void *arg)
2585 + register int (*_fn)(void *arg) = fn;
2586 + register void *_arg = arg;
2589 + /* Sanity check the arguments */
2592 + goto syscall_error;
2594 + goto syscall_error;
2596 + err = INLINE_SYSCALL(clone, 2, flags, child_stack);
2598 + goto syscall_error;
2599 + else if (err != 0)
2605 + __set_errno (-err);
2608 diff --git a/libc/sysdeps/linux/avr32/crt1.S b/libc/sysdeps/linux/avr32/crt1.S
2609 new file mode 100644
2610 index 0000000..ca1fa7a
2612 +++ b/libc/sysdeps/linux/avr32/crt1.S
2615 + * Copyright (C) 2004-2007 Atmel Corporation
2617 + * This file is subject to the terms and conditions of the GNU Lesser General
2618 + * Public License. See the file "COPYING.LIB" in the main directory of this
2619 + * archive for more details.
2621 + * When we enter _start, the stack looks like this:
2622 + * argc argument counter
2623 + * argv[0] pointer to program name
2624 + * argv[1..argc-1] pointers to program args
2626 + * env[0..N] pointers to environment variables
2629 + * r12 contains a function pointer to be registered with `atexit'.
2630 + * This is how the dynamic linker arranges to have DT_FINI functions
2631 + * called for shared libraries that have been loaded before this
2634 + * We're going to call the following function:
2635 + * __uClibc_main(int (*main)(int, char **, char **), int argc,
2636 + * char **argv, void (*app_init)(void), void (*app_fini)(void),
2637 + * void (*rtld_fini)(void), void *stack_end)
2639 + * So we need to set up things as follows:
2640 + * r12 = address of main
2643 + * r9 = address of _init
2644 + * r8 = address of _fini
2645 + * sp[0] = whatever we got passed in r12
2648 +#include <features.h>
2652 + .type _start, @function
2654 + /* Clear the frame pointer and link register since this is the outermost frame. */
2658 + ld.w r11, sp++ /* argc */
2659 + mov r10, sp /* &argv[0] */
2661 + st.w --sp, r10 /* stack_end */
2662 + st.w --sp, r12 /* rtld_fini */
2672 + /* Ok, now run uClibc's main() -- should not return */
2673 + call __uClibc_main
2677 + .long .L_RGOT - _GLOBAL_OFFSET_TABLE_
2679 + lddpc r9, __init_addr /* app_init */
2680 + lddpc r8, __fini_addr /* app_fini */
2681 + lddpc r12, __main_addr /* main */
2683 + /* Ok, now run uClibc's main() -- should not return */
2684 + lddpc pc, ___uClibc_main_addr
2693 +___uClibc_main_addr:
2694 + .long __uClibc_main
2696 + .size _start, . - _start
2699 + * The LSB says we need this.
2701 + .section ".note.ABI-tag", "a"
2703 + .long 2f - 1f /* namesz */
2704 + .long 4f - 3f /* descsz */
2705 + .long 1 /* type */
2706 +1: .asciz "GNU" /* name */
2708 +3: .long 0 /* Linux executable */
2709 + .long 2,6,0 /* Earliest compatible kernel */
2711 diff --git a/libc/sysdeps/linux/avr32/crti.S b/libc/sysdeps/linux/avr32/crti.S
2712 new file mode 100644
2713 index 0000000..660f47c
2715 +++ b/libc/sysdeps/linux/avr32/crti.S
2721 + .type _init, @function
2728 +2: .long 1b - _GLOBAL_OFFSET_TABLE_
2734 + .type _fini, @function
2741 +2: .long 1b - _GLOBAL_OFFSET_TABLE_
2743 diff --git a/libc/sysdeps/linux/avr32/crtn.S b/libc/sysdeps/linux/avr32/crtn.S
2744 new file mode 100644
2745 index 0000000..f7d1040
2747 +++ b/libc/sysdeps/linux/avr32/crtn.S
2753 + .type _init, @function
2755 + .size _init, . - _init
2760 + .type _fini, @function
2762 + .size _fini, . - _fini
2763 diff --git a/libc/sysdeps/linux/avr32/mmap.c b/libc/sysdeps/linux/avr32/mmap.c
2764 new file mode 100644
2765 index 0000000..2ee025a
2767 +++ b/libc/sysdeps/linux/avr32/mmap.c
2770 + * Copyright (C) 2004-2007 Atmel Corporation
2772 + * This file is subject to the terms and conditions of the GNU Lesser General
2773 + * Public License. See the file "COPYING.LIB" in the main directory of this
2774 + * archive for more details.
2778 +#include <unistd.h>
2779 +#include <sys/mman.h>
2780 +#include <sys/syscall.h>
2782 +libc_hidden_proto(mmap)
2784 +static _syscall6(__ptr_t, mmap2, __ptr_t, addr, size_t, len, int, prot,
2785 + int, flags, int, fd, __off_t, pgoff);
2787 +__ptr_t mmap(__ptr_t addr, size_t len, int prot, int flags, int fd, __off_t offset)
2789 + unsigned long page_size = sysconf(_SC_PAGESIZE);
2790 + unsigned long pgoff;
2792 + if (offset & (page_size - 1)) {
2793 + __set_errno(EINVAL);
2794 + return MAP_FAILED;
2797 + pgoff = (unsigned long)offset >> (31 - __builtin_clz(page_size));
2799 + return mmap2(addr, len, prot, flags, fd, pgoff);
2801 +libc_hidden_def(mmap)
2802 diff --git a/libc/sysdeps/linux/avr32/setjmp.S b/libc/sysdeps/linux/avr32/setjmp.S
2803 new file mode 100644
2804 index 0000000..7d0354b
2806 +++ b/libc/sysdeps/linux/avr32/setjmp.S
2809 + * Copyright (C) 2004-2007 Atmel Corporation
2811 + * This file is subject to the terms and conditions of the GNU Lesser General
2812 + * Public License. See the file "COPYING.LIB" in the main directory of this
2813 + * archive for more details.
2817 +#include <bits/setjmp.h>
2821 + .global __sigsetjmp
2822 + .type __sigsetjmp,"function"
2827 + stm r12, r0,r1,r2,r3,r4,r5,r6,r7,r8,sp,lr
2830 + * Make a tail call to __sigjmp_save; it takes the same args
2831 + * and is hidden so we don't need to mess around with the GOT.
2833 + rjmp __sigjmp_save
2834 + .size __sigsetjmp, . - __sigsetjmp
2836 +libc_hidden_def(__sigsetjmp)
2837 diff --git a/libc/sysdeps/linux/avr32/sigaction.c b/libc/sysdeps/linux/avr32/sigaction.c
2838 new file mode 100644
2839 index 0000000..a97ff3d
2841 +++ b/libc/sysdeps/linux/avr32/sigaction.c
2844 + * Copyright (C) 2004-2007 Atmel Corporation
2846 + * This file is subject to the terms and conditions of the GNU Lesser General
2847 + * Public License. See the file "COPYING.LIB" in the main directory of this
2848 + * archive for more details.
2851 +#include <signal.h>
2852 +#include <string.h>
2853 +#include <sys/syscall.h>
2854 +#include <bits/kernel_sigaction.h>
2856 +#define SA_RESTORER 0x04000000
2857 +extern void __default_rt_sa_restorer(void);
2859 +libc_hidden_proto(memcpy)
2862 + * If act is not NULL, change the action for sig to *act.
2863 + * If oact is not NULL, put the old action for sig in *oact.
2865 +int __libc_sigaction(int signum, const struct sigaction *act,
2866 + struct sigaction *oldact)
2868 + struct kernel_sigaction kact, koact;
2872 + kact.k_sa_handler = act->sa_handler;
2873 + memcpy(&kact.sa_mask, &act->sa_mask, sizeof (kact.sa_mask));
2874 + kact.sa_flags = act->sa_flags;
2875 + if (kact.sa_flags & (SA_RESTORER | SA_ONSTACK))
2876 + kact.sa_restorer = act->sa_restorer;
2878 + kact.sa_restorer = __default_rt_sa_restorer;
2879 + kact.sa_flags |= SA_RESTORER;
2882 + result = __syscall_rt_sigaction(signum, act ? __ptrvalue(&kact) : NULL,
2883 + oldact ? __ptrvalue(&koact) : NULL,
2886 + if (oldact && result >= 0) {
2887 + oldact->sa_handler = koact.k_sa_handler;
2888 + memcpy(&oldact->sa_mask, &koact.sa_mask,
2889 + sizeof(oldact->sa_mask));
2890 + oldact->sa_flags = koact.sa_flags;
2891 + oldact->sa_restorer = koact.sa_restorer;
2897 +#ifndef LIBC_SIGACTION
2898 +libc_hidden_proto(sigaction)
2899 +weak_alias(__libc_sigaction, sigaction)
2900 +libc_hidden_weak(sigaction)
2902 diff --git a/libc/sysdeps/linux/avr32/sigrestorer.S b/libc/sysdeps/linux/avr32/sigrestorer.S
2903 new file mode 100644
2904 index 0000000..df6a1ba
2906 +++ b/libc/sysdeps/linux/avr32/sigrestorer.S
2909 + * Copyright (C) 2004 Atmel Corporation
2911 + * This file is subject to the terms and conditions of the GNU Lesser General
2912 + * Public License. See the file "COPYING.LIB" in the main directory of this
2913 + * archive for more details.
2915 +#include <sys/syscall.h>
2917 + .global __default_rt_sa_restorer
2918 + .type __default_rt_sa_restorer,"function"
2920 +__default_rt_sa_restorer:
2921 + mov r8, __NR_rt_sigreturn
2923 diff --git a/libc/sysdeps/linux/avr32/sys/elf.h b/libc/sysdeps/linux/avr32/sys/elf.h
2924 new file mode 100644
2925 index 0000000..faa7310
2927 +++ b/libc/sysdeps/linux/avr32/sys/elf.h
2929 +/* Copyright (C) 1996, 1997, 1999, 2001 Free Software Foundation, Inc.
2930 + This file is part of the GNU C Library.
2932 + The GNU C Library is free software; you can redistribute it and/or
2933 + modify it under the terms of the GNU Lesser General Public
2934 + License as published by the Free Software Foundation; either
2935 + version 2.1 of the License, or (at your option) any later version.
2937 + The GNU C Library is distributed in the hope that it will be useful,
2938 + but WITHOUT ANY WARRANTY; without even the implied warranty of
2939 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2940 + Lesser General Public License for more details.
2942 + You should have received a copy of the GNU Lesser General Public
2943 + License along with the GNU C Library; if not, write to the Free
2944 + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
2945 + 02111-1307 USA. */
2948 +#define _SYS_ELF_H 1
2950 +#warning "This header is obsolete; use <sys/procfs.h> instead."
2952 +#include <sys/procfs.h>
2954 +#endif /* sys/elf.h */
2955 diff --git a/libc/sysdeps/linux/avr32/sys/procfs.h b/libc/sysdeps/linux/avr32/sys/procfs.h
2956 new file mode 100644
2957 index 0000000..3b37363
2959 +++ b/libc/sysdeps/linux/avr32/sys/procfs.h
2961 +/* Copyright (C) 1996, 1997, 1999, 2001 Free Software Foundation, Inc.
2962 + This file is part of the GNU C Library.
2964 + The GNU C Library is free software; you can redistribute it and/or
2965 + modify it under the terms of the GNU Lesser General Public
2966 + License as published by the Free Software Foundation; either
2967 + version 2.1 of the License, or (at your option) any later version.
2969 + The GNU C Library is distributed in the hope that it will be useful,
2970 + but WITHOUT ANY WARRANTY; without even the implied warranty of
2971 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2972 + Lesser General Public License for more details.
2974 + You should have received a copy of the GNU Lesser General Public
2975 + License along with the GNU C Library; if not, write to the Free
2976 + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
2977 + 02111-1307 USA. */
2979 +#ifndef _SYS_PROCFS_H
2980 +#define _SYS_PROCFS_H 1
2982 +/* This is somewhat modelled after the file of the same name on SVR4
2983 + systems. It provides a definition of the core file format for ELF
2984 + used on Linux. It doesn't have anything to do with the /proc file
2985 + system, even though Linux has one.
2987 + Anyway, the whole purpose of this file is for GDB and GDB only.
2988 + Don't read too much into it. Don't use it for anything other than
2989 + GDB unless you know what you are doing. */
2991 +#include <features.h>
2992 +#include <sys/time.h>
2993 +#include <sys/types.h>
2994 +#include <sys/user.h>
2998 +/* Type for a general-purpose register. */
2999 +typedef unsigned long elf_greg_t;
3001 +/* And the whole bunch of them. We could have used `struct
3002 + user_regs' directly in the typedef, but tradition says that
3003 + the register set is an array, which does have some peculiar
3004 + semantics, so leave it that way. */
3005 +#define ELF_NGREG (sizeof (struct user_regs) / sizeof(elf_greg_t))
3006 +typedef elf_greg_t elf_gregset_t[ELF_NGREG];
3008 +/* Register set for the floating-point registers. */
3009 +typedef struct user_fpregs elf_fpregset_t;
3014 + int si_signo; /* Signal number. */
3015 + int si_code; /* Extra code. */
3016 + int si_errno; /* Errno. */
3019 +/* Definitions to generate Intel SVR4-like core files. These mostly
3020 + have the same names as the SVR4 types with "elf_" tacked on the
3021 + front to prevent clashes with Linux definitions, and the typedef
3022 + forms have been avoided. This is mostly like the SVR4 structure,
3023 + but more Linuxy, with things that Linux does not support and which
3024 + GDB doesn't really use excluded. */
3026 +struct elf_prstatus
3028 + struct elf_siginfo pr_info; /* Info associated with signal. */
3029 + short int pr_cursig; /* Current signal. */
3030 + unsigned long int pr_sigpend; /* Set of pending signals. */
3031 + unsigned long int pr_sighold; /* Set of held signals. */
3036 + struct timeval pr_utime; /* User time. */
3037 + struct timeval pr_stime; /* System time. */
3038 + struct timeval pr_cutime; /* Cumulative user time. */
3039 + struct timeval pr_cstime; /* Cumulative system time. */
3040 + elf_gregset_t pr_reg; /* GP registers. */
3041 + int pr_fpvalid; /* True if math copro being used. */
3045 +#define ELF_PRARGSZ (80) /* Number of chars for args. */
3047 +struct elf_prpsinfo
3049 + char pr_state; /* Numeric process state. */
3050 + char pr_sname; /* Char for pr_state. */
3051 + char pr_zomb; /* Zombie. */
3052 + char pr_nice; /* Nice val. */
3053 + unsigned long int pr_flag; /* Flags. */
3054 + unsigned short int pr_uid;
3055 + unsigned short int pr_gid;
3056 + int pr_pid, pr_ppid, pr_pgrp, pr_sid;
3057 + /* Lots missing */
3058 + char pr_fname[16]; /* Filename of executable. */
3059 + char pr_psargs[ELF_PRARGSZ]; /* Initial part of arg list. */
3062 +/* The rest of this file provides the types for emulation of the
3063 + Solaris <proc_service.h> interfaces that should be implemented by
3064 + users of libthread_db. */
3067 +typedef void *psaddr_t;
3069 +/* Register sets. Linux has different names. */
3070 +typedef elf_gregset_t prgregset_t;
3071 +typedef elf_fpregset_t prfpregset_t;
3073 +/* We don't have any differences between processes and threads,
3074 + therefore have only one PID type. */
3075 +typedef __pid_t lwpid_t;
3077 +/* Process status and info. In the end we do provide typedefs for them. */
3078 +typedef struct elf_prstatus prstatus_t;
3079 +typedef struct elf_prpsinfo prpsinfo_t;
3083 +#endif /* sys/procfs.h */
3084 diff --git a/libc/sysdeps/linux/avr32/sys/ucontext.h b/libc/sysdeps/linux/avr32/sys/ucontext.h
3085 new file mode 100644
3086 index 0000000..82c7fe2
3088 +++ b/libc/sysdeps/linux/avr32/sys/ucontext.h
3090 +/* Copyright (C) 1998, 1999, 2001 Free Software Foundation, Inc.
3091 + This file is part of the GNU C Library.
3093 + The GNU C Library is free software; you can redistribute it and/or
3094 + modify it under the terms of the GNU Lesser General Public
3095 + License as published by the Free Software Foundation; either
3096 + version 2.1 of the License, or (at your option) any later version.
3098 + The GNU C Library is distributed in the hope that it will be useful,
3099 + but WITHOUT ANY WARRANTY; without even the implied warranty of
3100 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3101 + Lesser General Public License for more details.
3103 + You should have received a copy of the GNU Lesser General Public
3104 + License along with the GNU C Library; if not, write to the Free
3105 + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
3106 + 02111-1307 USA. */
3108 +/* Linux/AVR32 ABI compliant context switching support. */
3110 +#ifndef _SYS_UCONTEXT_H
3111 +#define _SYS_UCONTEXT_H 1
3113 +#include <features.h>
3114 +#include <signal.h>
3115 +#include <sys/procfs.h>
3116 +#include <bits/sigcontext.h>
3118 +typedef int greg_t;
3120 +/* Number of general registers. */
3123 +/* Container for all general registers. */
3124 +typedef elf_gregset_t gregset_t;
3126 +/* Number of each register is the `gregset_t' array. */
3163 +/* Structure to describe FPU registers. */
3164 +typedef elf_fpregset_t fpregset_t;
3166 +/* Context to describe whole processor state. */
3167 +typedef struct sigcontext mcontext_t;
3169 +/* Userlevel context. */
3170 +typedef struct ucontext
3172 + unsigned long uc_flags;
3173 + struct ucontext *uc_link;
3175 + mcontext_t uc_mcontext;
3176 + sigset_t uc_sigmask; /* mask last for extensibility */
3179 +#endif /* sys/ucontext.h */
3180 diff --git a/libc/sysdeps/linux/avr32/sys/user.h b/libc/sysdeps/linux/avr32/sys/user.h
3181 new file mode 100644
3182 index 0000000..c0b3d38
3184 +++ b/libc/sysdeps/linux/avr32/sys/user.h
3186 +#ifndef _SYS_USER_H
3187 +#define _SYS_USER_H
3200 + unsigned long r12;
3201 + unsigned long r11;
3202 + unsigned long r10;
3213 + unsigned long r12_orig;
3218 + struct user_regs regs; /* general registers */
3219 + size_t u_tsize; /* text size (pages) */
3220 + size_t u_dsize; /* data size (pages) */
3221 + size_t u_ssize; /* stack size (pages) */
3222 + unsigned long start_code; /* text starting address */
3223 + unsigned long start_data; /* data starting address */
3224 + unsigned long start_stack; /* stack starting address */
3225 + long int signal; /* signal causing core dump */
3226 + struct user_regs * u_ar0; /* help gdb find registers */
3227 + unsigned long magic; /* identifies a core file */
3228 + char u_comm[32]; /* user command name */
3231 +#endif /* _SYS_USER_H */
3232 diff --git a/libc/sysdeps/linux/avr32/syscall.S b/libc/sysdeps/linux/avr32/syscall.S
3233 new file mode 100644
3234 index 0000000..55c1b1f
3236 +++ b/libc/sysdeps/linux/avr32/syscall.S
3239 + * Copyright (C) 2004-2007 Atmel Corporation
3241 + * This file is subject to the terms and conditions of the GNU Lesser General
3242 + * Public License. See the file "COPYING.LIB" in the main directory of this
3243 + * archive for more details.
3245 +#include <features.h>
3250 + * long int syscall(long int sysno, ...)
3253 + .type syscall, @function
3256 + stm --sp, r3,r5,r6,lr
3259 + ldm lr, r3,r5,r9-r12
3268 +# ifdef __UCLIBC_HAS_THREADS__
3270 + mcall r6[__errno_location@got]
3273 + ld.w r3, r6[errno@got]
3278 +# ifdef __UCLIBC_HAS_THREADS__
3280 + mcall .Lerrno_location
3291 + ldm sp++, r3,r5,r6,pc
3296 + .long .Lgotcalc - _GLOBAL_OFFSET_TABLE_
3298 +# ifdef __UCLIBC_HAS_THREADS__
3300 + .long __errno_location
3308 + .size syscall, . - syscall
3309 diff --git a/libc/sysdeps/linux/avr32/vfork.S b/libc/sysdeps/linux/avr32/vfork.S
3310 new file mode 100644
3311 index 0000000..03ca99f
3313 +++ b/libc/sysdeps/linux/avr32/vfork.S
3316 + * Copyright (C) 2005 Atmel Corporation
3318 + * This file is subject to the terms and conditions of the GNU Lesser General
3319 + * Public License. See the file "COPYING.LIB" in the main directory of this
3320 + * archive for more details.
3324 + * Clone the process without copying the address space. The
3325 + * calling process is suspended until the child either exits
3326 + * or calls execve.
3328 + * This all means that we cannot rely on the stack to store
3329 + * away registers, since they will be overwritten by the child
3330 + * as soon as it makes another function call (e.g. execve()).
3331 + * Fortunately, the Linux kernel preserves LR across system calls.
3334 +#include <features.h>
3335 +#include <sys/syscall.h>
3338 + .type __vfork,@function
3341 + mov r8, __NR_vfork
3346 + /* vfork failed, so we may use the stack freely */
3353 + mcall r6[__errno_location@got]
3356 + mcall .L__errno_location
3359 + popm r4-r7,pc,r12=-1
3364 + .long .L_RGOT - _GLOBAL_OFFSET_TABLE_
3366 +.L__errno_location:
3367 + .long __errno_location
3369 + .size __vfork, . - __vfork
3371 +weak_alias(__vfork,vfork)
3372 +libc_hidden_weak(vfork)
3373 diff --git a/libpthread/linuxthreads.old/sysdeps/avr32/pt-machine.h b/libpthread/linuxthreads.old/sysdeps/avr32/pt-machine.h
3374 new file mode 100644
3375 index 0000000..eccf329
3377 +++ b/libpthread/linuxthreads.old/sysdeps/avr32/pt-machine.h
3379 +/* Machine-dependent pthreads configuration and inline functions.
3381 + * Copyright (C) 2005-2007 Atmel Corporation
3383 + * This file is subject to the terms and conditions of the GNU Lesser General
3384 + * Public License. See the file "COPYING.LIB" in the main directory of this
3385 + * archive for more details.
3387 +#ifndef _PT_MACHINE_H
3388 +#define _PT_MACHINE_H 1
3390 +#include <features.h>
3393 +_test_and_set (int *p, int v)
3397 + __asm__ __volatile__(
3398 + "/* Inline test and set */\n"
3399 + " xchg %[old], %[mem], %[new]"
3400 + : [old] "=&r"(result)
3401 + : [mem] "r"(p), [new] "r"(v)
3408 +# define PT_EI extern inline
3411 +extern long int testandset (int *spinlock);
3412 +extern int __compare_and_swap (long int *p, long int oldval, long int newval);
3414 +/* Spinlock implementation; required. */
3416 +testandset (int *spinlock)
3418 + return _test_and_set(spinlock, 1);
3422 +/* Get some notion of the current stack. Need not be exactly the top
3423 + of the stack, just something somewhere in the current frame. */
3424 +#define CURRENT_STACK_FRAME stack_pointer
3425 +register char * stack_pointer __asm__ ("sp");
3427 +/* Compare-and-swap for semaphores. */
3429 +#define HAS_COMPARE_AND_SWAP
3431 +__compare_and_swap(long int *p, long int oldval, long int newval)
3435 + __asm__ __volatile__(
3436 + "/* Inline compare and swap */\n"
3438 + " ld.w %[result], %[mem]\n"
3439 + " eor %[result], %[old]\n"
3441 + " stcond %[mem], %[new]\n"
3444 + : [result] "=&r"(result), [mem] "=m"(*p)
3445 + : "m"(*p), [new] "r"(newval), [old] "r"(oldval)
3446 + : "cc", "memory");
3448 + return result == 0;
3451 +#endif /* pt-machine.h */
3452 diff --git a/libpthread/linuxthreads/sysdeps/avr32/pt-machine.h b/libpthread/linuxthreads/sysdeps/avr32/pt-machine.h
3453 new file mode 100644
3454 index 0000000..fe12bf8
3456 +++ b/libpthread/linuxthreads/sysdeps/avr32/pt-machine.h
3458 +/* Machine-dependent pthreads configuration and inline functions.
3460 + * Copyright (C) 2005-2007 Atmel Corporation
3462 + * This file is subject to the terms and conditions of the GNU Lesser General
3463 + * Public License. See the file "COPYING.LIB" in the main directory of this
3464 + * archive for more details.
3466 +#ifndef _PT_MACHINE_H
3467 +#define _PT_MACHINE_H 1
3469 +#include <features.h>
3472 +_test_and_set (int *p, int v) __THROW
3476 + __asm__ __volatile__(
3477 + "/* Inline test and set */\n"
3478 + " xchg %[old], %[mem], %[new]"
3479 + : [old] "=&r"(result)
3480 + : [mem] "r"(p), [new] "r"(v)
3487 +# define PT_EI extern inline
3490 +extern long int testandset (int *spinlock);
3491 +extern int __compare_and_swap (long int *p, long int oldval, long int newval);
3493 +/* Spinlock implementation; required. */
3495 +testandset (int *spinlock)
3497 + return _test_and_set(spinlock, 1);
3501 +/* Get some notion of the current stack. Need not be exactly the top
3502 + of the stack, just something somewhere in the current frame. */
3503 +#define CURRENT_STACK_FRAME stack_pointer
3504 +register char * stack_pointer __asm__ ("sp");
3506 +/* Compare-and-swap for semaphores. */
3508 +#define HAS_COMPARE_AND_SWAP
3510 +__compare_and_swap(long int *p, long int oldval, long int newval)
3514 + __asm__ __volatile__(
3515 + "/* Inline compare and swap */\n"
3517 + " ld.w %[result], %[mem]\n"
3518 + " eor %[result], %[old]\n"
3520 + " stcond %[mem], %[new]\n"
3523 + : [result] "=&r"(result), [mem] "=m"(*p)
3524 + : "m"(*p), [new] "r"(newval), [old] "r"(oldval)
3525 + : "cc", "memory");
3527 + return result == 0;
3530 +#endif /* pt-machine.h */
3531 diff --git a/utils/ldd.c b/utils/ldd.c
3532 index 75ad628..e34acd9 100644
3536 #define ELFCLASSM ELFCLASS32
3539 +#if defined(__avr32__)
3540 +#define MATCH_MACHINE(x) (x == EM_AVR32)
3541 +#define ELFCLASSM ELFCLASS32
3544 #if defined(__s390__)
3545 #define MATCH_MACHINE(x) (x == EM_S390)
3546 #define ELFCLASSM ELFCLASS32