2 extra/Configs/Config.avr32 | 31 ++++
3 extra/Configs/Config.in | 7 +
4 extra/Configs/defconfigs/avr32 | 1 +
5 include/elf.h | 51 ++++++
6 ldso/include/dl-string.h | 3 +-
7 ldso/include/dl-syscall.h | 40 ++--
8 ldso/ldso/avr32/dl-debug.h | 45 +++++
9 ldso/ldso/avr32/dl-startup.h | 112 ++++++++++++
10 ldso/ldso/avr32/dl-syscalls.h | 6 +
11 ldso/ldso/avr32/dl-sysdep.h | 105 +++++++++++
12 ldso/ldso/avr32/elfinterp.c | 191 ++++++++++++++++++++
13 ldso/ldso/avr32/resolve.S | 28 +++
14 ldso/ldso/dl-startup.c | 4 +-
15 libc/inet/resolv.c | 6 +-
16 libc/string/avr32/Makefile | 26 +++
17 libc/string/avr32/bcopy.S | 26 +++
18 libc/string/avr32/bzero.S | 22 +++
19 libc/string/avr32/memcmp.S | 61 +++++++
20 libc/string/avr32/memcpy.S | 111 ++++++++++++
21 libc/string/avr32/memmove.S | 116 ++++++++++++
22 libc/string/avr32/memset.S | 70 +++++++
23 libc/string/avr32/strcmp.S | 91 ++++++++++
24 libc/string/avr32/strlen.S | 62 +++++++
25 libc/sysdeps/linux/avr32/Makefile | 25 +++
26 libc/sysdeps/linux/avr32/Makefile.arch | 13 ++
27 libc/sysdeps/linux/avr32/__longjmp.S | 21 +++
28 libc/sysdeps/linux/avr32/bits/atomic.h | 120 ++++++++++++
29 libc/sysdeps/linux/avr32/bits/byteswap.h | 70 +++++++
30 libc/sysdeps/linux/avr32/bits/endian.h | 7 +
31 libc/sysdeps/linux/avr32/bits/fcntl.h | 165 +++++++++++++++++
32 libc/sysdeps/linux/avr32/bits/kernel_stat.h | 67 +++++++
33 libc/sysdeps/linux/avr32/bits/kernel_types.h | 55 ++++++
34 libc/sysdeps/linux/avr32/bits/mman.h | 103 +++++++++++
35 libc/sysdeps/linux/avr32/bits/setjmp.h | 30 +++
36 libc/sysdeps/linux/avr32/bits/stackinfo.h | 28 +++
37 libc/sysdeps/linux/avr32/bits/syscalls.h | 143 +++++++++++++++
38 .../linux/avr32/bits/uClibc_arch_features.h | 45 +++++
39 libc/sysdeps/linux/avr32/bits/wordsize.h | 1 +
40 libc/sysdeps/linux/avr32/brk.c | 31 ++++
41 libc/sysdeps/linux/avr32/bsd-_setjmp.S | 16 ++
42 libc/sysdeps/linux/avr32/bsd-setjmp.S | 16 ++
43 libc/sysdeps/linux/avr32/clone.c | 41 +++++
44 libc/sysdeps/linux/avr32/crt1.S | 97 ++++++++++
45 libc/sysdeps/linux/avr32/crti.S | 26 +++
46 libc/sysdeps/linux/avr32/crtn.S | 14 ++
47 libc/sysdeps/linux/avr32/mmap.c | 33 ++++
48 libc/sysdeps/linux/avr32/setjmp.S | 29 +++
49 libc/sysdeps/linux/avr32/sigaction.c | 59 ++++++
50 libc/sysdeps/linux/avr32/sigrestorer.S | 15 ++
51 libc/sysdeps/linux/avr32/sys/elf.h | 26 +++
52 libc/sysdeps/linux/avr32/sys/procfs.h | 123 +++++++++++++
53 libc/sysdeps/linux/avr32/sys/ucontext.h | 90 +++++++++
54 libc/sysdeps/linux/avr32/sys/user.h | 46 +++++
55 libc/sysdeps/linux/avr32/syscall.S | 71 ++++++++
56 libc/sysdeps/linux/avr32/vfork.S | 58 ++++++
57 .../linuxthreads.old/sysdeps/avr32/pt-machine.h | 73 ++++++++
58 libpthread/linuxthreads/sysdeps/avr32/pt-machine.h | 73 ++++++++
60 60 files changed, 3094 insertions(+), 25 deletions(-)
61 create mode 100644 extra/Configs/Config.avr32
62 create mode 100644 extra/Configs/defconfigs/avr32
63 create mode 100644 ldso/ldso/avr32/dl-debug.h
64 create mode 100644 ldso/ldso/avr32/dl-startup.h
65 create mode 100644 ldso/ldso/avr32/dl-syscalls.h
66 create mode 100644 ldso/ldso/avr32/dl-sysdep.h
67 create mode 100644 ldso/ldso/avr32/elfinterp.c
68 create mode 100644 ldso/ldso/avr32/resolve.S
69 create mode 100644 libc/string/avr32/Makefile
70 create mode 100644 libc/string/avr32/bcopy.S
71 create mode 100644 libc/string/avr32/bzero.S
72 create mode 100644 libc/string/avr32/memcmp.S
73 create mode 100644 libc/string/avr32/memcpy.S
74 create mode 100644 libc/string/avr32/memmove.S
75 create mode 100644 libc/string/avr32/memset.S
76 create mode 100644 libc/string/avr32/strcmp.S
77 create mode 100644 libc/string/avr32/strlen.S
78 create mode 100644 libc/sysdeps/linux/avr32/Makefile
79 create mode 100644 libc/sysdeps/linux/avr32/Makefile.arch
80 create mode 100644 libc/sysdeps/linux/avr32/__longjmp.S
81 create mode 100644 libc/sysdeps/linux/avr32/bits/atomic.h
82 create mode 100644 libc/sysdeps/linux/avr32/bits/byteswap.h
83 create mode 100644 libc/sysdeps/linux/avr32/bits/endian.h
84 create mode 100644 libc/sysdeps/linux/avr32/bits/fcntl.h
85 create mode 100644 libc/sysdeps/linux/avr32/bits/kernel_stat.h
86 create mode 100644 libc/sysdeps/linux/avr32/bits/kernel_types.h
87 create mode 100644 libc/sysdeps/linux/avr32/bits/mman.h
88 create mode 100644 libc/sysdeps/linux/avr32/bits/setjmp.h
89 create mode 100644 libc/sysdeps/linux/avr32/bits/stackinfo.h
90 create mode 100644 libc/sysdeps/linux/avr32/bits/syscalls.h
91 create mode 100644 libc/sysdeps/linux/avr32/bits/uClibc_arch_features.h
92 create mode 100644 libc/sysdeps/linux/avr32/bits/wordsize.h
93 create mode 100644 libc/sysdeps/linux/avr32/brk.c
94 create mode 100644 libc/sysdeps/linux/avr32/bsd-_setjmp.S
95 create mode 100644 libc/sysdeps/linux/avr32/bsd-setjmp.S
96 create mode 100644 libc/sysdeps/linux/avr32/clone.c
97 create mode 100644 libc/sysdeps/linux/avr32/crt1.S
98 create mode 100644 libc/sysdeps/linux/avr32/crti.S
99 create mode 100644 libc/sysdeps/linux/avr32/crtn.S
100 create mode 100644 libc/sysdeps/linux/avr32/mmap.c
101 create mode 100644 libc/sysdeps/linux/avr32/setjmp.S
102 create mode 100644 libc/sysdeps/linux/avr32/sigaction.c
103 create mode 100644 libc/sysdeps/linux/avr32/sigrestorer.S
104 create mode 100644 libc/sysdeps/linux/avr32/sys/elf.h
105 create mode 100644 libc/sysdeps/linux/avr32/sys/procfs.h
106 create mode 100644 libc/sysdeps/linux/avr32/sys/ucontext.h
107 create mode 100644 libc/sysdeps/linux/avr32/sys/user.h
108 create mode 100644 libc/sysdeps/linux/avr32/syscall.S
109 create mode 100644 libc/sysdeps/linux/avr32/vfork.S
110 create mode 100644 libpthread/linuxthreads.old/sysdeps/avr32/pt-machine.h
111 create mode 100644 libpthread/linuxthreads/sysdeps/avr32/pt-machine.h
112 diff --git a/Rules.mak b/Rules.mak
113 index d054bbb..55381cf 100644
116 @@ -313,6 +313,12 @@ ifeq ($(TARGET_ARCH),frv)
120 +ifeq ($(strip $(TARGET_ARCH)),avr32)
121 + CPU_CFLAGS-$(CONFIG_AVR32_AP7) += -march=ap
122 + CPU_CFLAGS-$(CONFIG_LINKRELAX) += -mrelax
123 + CPU_LDFLAGS-$(CONFIG_LINKRELAX) += --relax
126 # Keep the check_gcc from being needlessly executed
128 ifneq ($(UCLIBC_BUILD_PIE),y)
129 diff --git a/extra/Configs/Config.avr32 b/extra/Configs/Config.avr32
131 index 0000000..8d70e6e
133 +++ b/extra/Configs/Config.avr32
136 +# For a description of the syntax of this configuration file,
137 +# see extra/config/Kconfig-language.txt
144 +config FORCE_OPTIONS_FOR_ARCH
147 + select ARCH_BIG_ENDIAN
148 + select FORCE_SHAREABLE_TEXT_SEGMENTS
154 + prompt "Target CPU Type"
155 + default CONFIG_AVR32_AP7
157 +config CONFIG_AVR32_AP7
159 + select ARCH_HAS_MMU
164 + bool "Enable linker optimizations"
166 diff --git a/extra/Configs/Config.in b/extra/Configs/Config.in
167 index 8eab394..10c9f7b 100644
168 --- a/extra/Configs/Config.in
169 +++ b/extra/Configs/Config.in
170 @@ -16,6 +16,9 @@ config TARGET_alpha
180 @@ -92,6 +95,10 @@ if TARGET_arm
181 source "extra/Configs/Config.arm"
185 +source "extra/Configs/Config.avr32"
189 source "extra/Configs/Config.bfin"
191 diff --git a/extra/Configs/defconfigs/avr32 b/extra/Configs/defconfigs/avr32
193 index 0000000..0b890a2
195 +++ b/extra/Configs/defconfigs/avr32
198 diff --git a/include/elf.h b/include/elf.h
199 index 19805d7..ab90160 100644
202 @@ -354,6 +354,8 @@ typedef struct
203 /* NIOS magic number - no EABI available. */
204 #define EM_NIOS32 0xFEBB
206 +#define EM_AVR32 0x18ad
208 /* V850 backend magic number. Written in the absense of an ABI. */
209 #define EM_CYGNUS_V850 0x9080
211 @@ -2828,6 +2830,55 @@ typedef Elf32_Addr Elf32_Conflict;
212 /* Keep this the last entry. */
213 #define R_V850_NUM 25
215 +/* Atmel AVR32 relocations. */
216 +#define R_AVR32_NONE 0
217 +#define R_AVR32_32 1
218 +#define R_AVR32_16 2
220 +#define R_AVR32_32_PCREL 4
221 +#define R_AVR32_16_PCREL 5
222 +#define R_AVR32_8_PCREL 6
223 +#define R_AVR32_DIFF32 7
224 +#define R_AVR32_DIFF16 8
225 +#define R_AVR32_DIFF8 9
226 +#define R_AVR32_GOT32 10
227 +#define R_AVR32_GOT16 11
228 +#define R_AVR32_GOT8 12
229 +#define R_AVR32_21S 13
230 +#define R_AVR32_16U 14
231 +#define R_AVR32_16S 15
232 +#define R_AVR32_8S 16
233 +#define R_AVR32_8S_EXT 17
234 +#define R_AVR32_22H_PCREL 18
235 +#define R_AVR32_18W_PCREL 19
236 +#define R_AVR32_16B_PCREL 20
237 +#define R_AVR32_16N_PCREL 21
238 +#define R_AVR32_14UW_PCREL 22
239 +#define R_AVR32_11H_PCREL 23
240 +#define R_AVR32_10UW_PCREL 24
241 +#define R_AVR32_9H_PCREL 25
242 +#define R_AVR32_9UW_PCREL 26
243 +#define R_AVR32_HI16 27
244 +#define R_AVR32_LO16 28
245 +#define R_AVR32_GOTPC 29
246 +#define R_AVR32_GOTCALL 30
247 +#define R_AVR32_LDA_GOT 31
248 +#define R_AVR32_GOT21S 32
249 +#define R_AVR32_GOT18SW 33
250 +#define R_AVR32_GOT16S 34
251 +#define R_AVR32_GOT7UW 35
252 +#define R_AVR32_32_CPENT 36
253 +#define R_AVR32_CPCALL 37
254 +#define R_AVR32_16_CP 38
255 +#define R_AVR32_9W_CP 39
256 +#define R_AVR32_RELATIVE 40
257 +#define R_AVR32_GLOB_DAT 41
258 +#define R_AVR32_JMP_SLOT 42
259 +#define R_AVR32_ALIGN 43
260 +#define R_AVR32_NUM 44
262 +/* AVR32 dynamic tags */
263 +#define DT_AVR32_GOTSZ 0x70000001 /* Total size of GOT in bytes */
265 /* Renesas H8/300 Relocations */
267 diff --git a/ldso/include/dl-string.h b/ldso/include/dl-string.h
268 index 32c5bf8..eb43bd9 100644
269 --- a/ldso/include/dl-string.h
270 +++ b/ldso/include/dl-string.h
271 @@ -285,7 +285,8 @@ static __always_inline char * _dl_simple_ltoahex(char * local, unsigned long i)
272 /* On some arches constant strings are referenced through the GOT.
273 * This requires that load_addr must already be defined... */
274 #if defined(mc68000) || defined(__arm__) || defined(__thumb__) || \
275 - defined(__mips__) || defined(__sh__) || defined(__powerpc__)
276 + defined(__mips__) || defined(__sh__) || defined(__powerpc__) || \
278 # define CONSTANT_STRING_GOT_FIXUP(X) \
279 if ((X) < (const char *) load_addr) (X) += load_addr
280 # define NO_EARLY_SEND_STDERR
281 diff --git a/ldso/include/dl-syscall.h b/ldso/include/dl-syscall.h
282 index b42416a..4404219 100644
283 --- a/ldso/include/dl-syscall.h
284 +++ b/ldso/include/dl-syscall.h
286 dynamic linking at all, so we cannot return any error codes.
287 We just punt if there is an error. */
288 #define __NR__dl_exit __NR_exit
289 -static inline _syscall1(void, _dl_exit, int, status);
290 +static __always_inline _syscall1(void, _dl_exit, int, status);
292 #define __NR__dl_close __NR_close
293 -static inline _syscall1(int, _dl_close, int, fd);
294 +static __always_inline _syscall1(int, _dl_close, int, fd);
296 #define __NR__dl_open __NR_open
297 -static inline _syscall3(int, _dl_open, const char *, fn, int, flags,
298 +static __always_inline _syscall3(int, _dl_open, const char *, fn, int, flags,
299 __kernel_mode_t, mode);
301 #define __NR__dl_write __NR_write
302 -static inline _syscall3(unsigned long, _dl_write, int, fd,
303 +static __always_inline _syscall3(unsigned long, _dl_write, int, fd,
304 const void *, buf, unsigned long, count);
306 #define __NR__dl_read __NR_read
307 -static inline _syscall3(unsigned long, _dl_read, int, fd,
308 +static __always_inline _syscall3(unsigned long, _dl_read, int, fd,
309 const void *, buf, unsigned long, count);
311 #define __NR__dl_mprotect __NR_mprotect
312 -static inline _syscall3(int, _dl_mprotect, const void *, addr,
313 +static __always_inline _syscall3(int, _dl_mprotect, const void *, addr,
314 unsigned long, len, int, prot);
316 #define __NR__dl_stat __NR_stat
317 -static inline _syscall2(int, _dl_stat, const char *, file_name,
318 +static __always_inline _syscall2(int, _dl_stat, const char *, file_name,
321 #define __NR__dl_fstat __NR_fstat
322 -static inline _syscall2(int, _dl_fstat, int, fd, struct stat *, buf);
323 +static __always_inline _syscall2(int, _dl_fstat, int, fd, struct stat *, buf);
325 #define __NR__dl_munmap __NR_munmap
326 -static inline _syscall2(int, _dl_munmap, void *, start, unsigned long, length);
327 +static __always_inline _syscall2(int, _dl_munmap, void *, start, unsigned long, length);
330 # define __NR_getuid __NR_getxuid
332 #define __NR__dl_getuid __NR_getuid
333 -static inline _syscall0(uid_t, _dl_getuid);
334 +static __always_inline _syscall0(uid_t, _dl_getuid);
337 # define __NR_geteuid __NR_getuid
339 #define __NR__dl_geteuid __NR_geteuid
340 -static inline _syscall0(uid_t, _dl_geteuid);
341 +static __always_inline _syscall0(uid_t, _dl_geteuid);
344 # define __NR_getgid __NR_getxgid
346 #define __NR__dl_getgid __NR_getgid
347 -static inline _syscall0(gid_t, _dl_getgid);
348 +static __always_inline _syscall0(gid_t, _dl_getgid);
351 # define __NR_getegid __NR_getgid
353 #define __NR__dl_getegid __NR_getegid
354 -static inline _syscall0(gid_t, _dl_getegid);
355 +static __always_inline _syscall0(gid_t, _dl_getegid);
358 # define __NR_getpid __NR_getxpid
360 #define __NR__dl_getpid __NR_getpid
361 -static inline _syscall0(gid_t, _dl_getpid);
362 +static __always_inline _syscall0(gid_t, _dl_getpid);
364 #define __NR__dl_readlink __NR_readlink
365 -static inline _syscall3(int, _dl_readlink, const char *, path, char *, buf,
366 +static __always_inline _syscall3(int, _dl_readlink, const char *, path, char *, buf,
369 #ifdef __UCLIBC_HAS_SSP__
370 @@ -146,14 +146,14 @@ static inline _syscall2(int, _dl_gettimeofday, struct timeval *, tv,
371 #if defined(__UCLIBC_MMAP_HAS_6_ARGS__) && defined(__NR_mmap)
373 # define __NR__dl_mmap __NR_mmap
374 -static inline _syscall6(void *, _dl_mmap, void *, start, size_t, length,
375 +static __always_inline _syscall6(void *, _dl_mmap, void *, start, size_t, length,
376 int, prot, int, flags, int, fd, off_t, offset);
378 /* then try mmap2() */
379 #elif defined(__NR_mmap2)
381 # define __NR___syscall_mmap2 __NR_mmap2
382 -static inline _syscall6(__ptr_t, __syscall_mmap2, __ptr_t, addr, size_t, len,
383 +static __always_inline _syscall6(__ptr_t, __syscall_mmap2, __ptr_t, addr, size_t, len,
384 int, prot, int, flags, int, fd, off_t, offset);
386 /* Some architectures always use 12 as page shift for mmap2() eventhough the
387 @@ -164,7 +164,7 @@ static inline _syscall6(__ptr_t, __syscall_mmap2, __ptr_t, addr, size_t, len,
388 # define MMAP2_PAGE_SHIFT 12
391 -static inline void * _dl_mmap(void * addr, unsigned long size, int prot,
392 +static __always_inline void * _dl_mmap(void * addr, unsigned long size, int prot,
393 int flags, int fd, unsigned long offset)
395 if (offset & ((1 << MMAP2_PAGE_SHIFT) - 1))
396 @@ -177,8 +177,8 @@ static inline void * _dl_mmap(void * addr, unsigned long size, int prot,
397 #elif defined(__NR_mmap)
399 # define __NR__dl_mmap_real __NR_mmap
400 -static inline _syscall1(void *, _dl_mmap_real, unsigned long *, buffer);
401 -static inline void * _dl_mmap(void * addr, unsigned long size, int prot,
402 +static __always_inline _syscall1(void *, _dl_mmap_real, unsigned long *, buffer);
403 +static __always_inline void * _dl_mmap(void * addr, unsigned long size, int prot,
404 int flags, int fd, unsigned long offset)
406 unsigned long buffer[6];
407 diff --git a/ldso/ldso/avr32/dl-debug.h b/ldso/ldso/avr32/dl-debug.h
409 index 0000000..fe35539
411 +++ b/ldso/ldso/avr32/dl-debug.h
414 + * AVR32 ELF shared libary loader support
416 + * Copyright (C) 2005-2007 Atmel Corporation
417 + * All rights reserved.
419 + * Redistribution and use in source and binary forms, with or without
420 + * modification, are permitted provided that the following conditions
422 + * 1. Redistributions of source code must retain the above copyright
423 + * notice, this list of conditions and the following disclaimer.
424 + * 2. The name of the above contributors may not be
425 + * used to endorse or promote products derived from this software
426 + * without specific prior written permission.
428 + * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND
429 + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
430 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
431 + * ARE DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE
432 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
433 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
434 + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
435 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
436 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
437 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
441 +static const char *_dl_reltypes_tab[] = {
443 + "R_AVR32_32", "R_AVR32_16", "R_AVR32_8",
444 + "R_AVR32_32_PCREL", "R_AVR32_16_PCREL", "R_AVR32_8_PCREL",
445 + "R_AVR32_DIFF32", "R_AVR32_DIFF16", "R_AVR32_DIFF8",
446 + "R_AVR32_GOT32", "R_AVR32_GOT16", "R_AVR32_GOT8",
447 + "R_AVR32_21S", "R_AVR32_16U", "R_AVR32_16S", "R_AVR32_8S", "R_AVR32_8S_EXT",
448 + "R_AVR32_22H_PCREL", "R_AVR32_18W_PCREL", "R_AVR32_16B_PCREL",
449 + "R_AVR32_16N_PCREL", "R_AVR32_14UW_PCREL", "R_AVR32_11H_PCREL",
450 + "R_AVR32_10UW_PCREL", "R_AVR32_9H_PCREL", "R_AVR32_9UW_PCREL",
451 + "R_AVR32_HI16", "R_AVR32_LO16",
452 + "R_AVR32_GOTPC", "R_AVR32_GOTCALL", "R_AVR32_LDA_GOT",
453 + "R_AVR32_GOT21S", "R_AVR32_GOT18SW", "R_AVR32_GOT16S", "R_AVR32_GOT7UW",
454 + "R_AVR32_32_CPENT", "R_AVR32_CPCALL", "R_AVR32_16_CP", "R_AVR32_9W_CP",
455 + "R_AVR32_RELATIVE", "R_AVR32_GLOB_DAT", "R_AVR32_JMP_SLOT",
458 diff --git a/ldso/ldso/avr32/dl-startup.h b/ldso/ldso/avr32/dl-startup.h
460 index 0000000..3b9a641
462 +++ b/ldso/ldso/avr32/dl-startup.h
465 + * Architecture specific code used by dl-startup.c
467 + * Copyright (C) 2005-2007 Atmel Corporation
469 + * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
472 +/* This is the library loader's main entry point. Let _dl_boot2 do its
473 + * initializations and jump to the application's entry point
476 + " .global _start\n"
477 + " .type _start,@function\n"
479 + /* All arguments are on the stack initially */
481 + " rcall _dl_start\n"
482 + /* Returns user entry point in r12. Save it. */
484 + /* We're PIC, so get the Global Offset Table */
485 + " lddpc r6, .L_GOT\n"
488 + /* Adjust argc and argv according to _dl_skip_args */
489 + " ld.w r1, r6[_dl_skip_args@got]\n"
490 + " ld.w r1, r1[0]\n"
493 + " add sp, sp, r1 << 2\n"
495 + /* Load the finalizer function */
496 + " ld.w r12, r6[_dl_fini@got]\n"
497 + /* Jump to the user's entry point */
502 + " .long .L_RGOT - _GLOBAL_OFFSET_TABLE_\n"
503 + " .size _start, . - _start\n"
506 +/* Get a pointer to the argv array. On many platforms this can be just
507 + * the address if the first argument, on other platforms we need to
508 + * do something a little more subtle here. */
509 +#define GET_ARGV(ARGVP, ARGS) ARGVP = ((unsigned long *)ARGS + 1)
512 +/* We can't call functions before the GOT has been initialized */
513 +#define NO_FUNCS_BEFORE_BOOTSTRAP
516 + * Relocate the GOT during dynamic loader bootstrap. This will add
517 + * the load address to all entries in the GOT, which is necessary
518 + * because the linker doesn't generate R_AVR32_RELATIVE relocs for the
521 +static __always_inline
522 +void PERFORM_BOOTSTRAP_GOT(struct elf_resolve *tpnt)
524 + Elf32_Addr i, nr_got;
525 + register Elf32_Addr *__r6 __asm__("r6");
526 + Elf32_Addr *got = __r6;
528 + nr_got = tpnt->dynamic_info[DT_AVR32_GOTSZ_IDX] / sizeof(*got);
529 + for (i = 2; i < nr_got; i++)
530 + got[i] += tpnt->loadaddr;
533 +#define PERFORM_BOOTSTRAP_GOT(tpnt) PERFORM_BOOTSTRAP_GOT(tpnt)
535 +/* Handle relocation of the symbols in the dynamic loader. */
536 +static __always_inline
537 +void PERFORM_BOOTSTRAP_RELOC(ELF_RELOC *rpnt, unsigned long *reloc_addr,
538 + unsigned long symbol_addr,
539 + unsigned long load_addr, Elf32_Sym *symtab)
541 + switch(ELF32_R_TYPE(rpnt->r_info)) {
544 + case R_AVR32_GLOB_DAT:
545 + case R_AVR32_JMP_SLOT:
546 + *reloc_addr = symbol_addr;
548 + case R_AVR32_RELATIVE:
549 + SEND_STDERR_DEBUG("Applying RELATIVE relocation: ");
550 + SEND_ADDRESS_STDERR_DEBUG(load_addr, 0);
551 + SEND_STDERR_DEBUG(" + ");
552 + SEND_ADDRESS_STDERR_DEBUG(rpnt->r_addend, 1);
553 + *reloc_addr = load_addr + rpnt->r_addend;
556 + SEND_STDERR("BOOTSTRAP_RELOC: unhandled reloc_type ");
557 + SEND_NUMBER_STDERR(ELF32_R_TYPE(rpnt->r_info), 1);
558 + SEND_STDERR("REL, SYMBOL, LOAD: ");
559 + SEND_ADDRESS_STDERR(reloc_addr, 0);
561 + SEND_ADDRESS_STDERR(symbol_addr, 0);
563 + SEND_ADDRESS_STDERR(load_addr, 1);
568 +/* Transfer control to the user's application, once the dynamic loader
569 + * is done. This routine has to exit the current function, then call
570 + * the _dl_elf_main function.
572 + * Since our _dl_boot will simply call whatever is returned by
573 + * _dl_boot2, we can just return the address we're supposed to
575 +#define START() return _dl_elf_main;
576 diff --git a/ldso/ldso/avr32/dl-syscalls.h b/ldso/ldso/avr32/dl-syscalls.h
578 index 0000000..996bb87
580 +++ b/ldso/ldso/avr32/dl-syscalls.h
582 +/* We can't use the real errno in ldso, since it has not yet
583 + * been dynamicly linked in yet. */
584 +#include "sys/syscall.h"
585 +extern int _dl_errno;
587 +#define __set_errno(X) {(_dl_errno) = (X);}
588 diff --git a/ldso/ldso/avr32/dl-sysdep.h b/ldso/ldso/avr32/dl-sysdep.h
590 index 0000000..1a30172
592 +++ b/ldso/ldso/avr32/dl-sysdep.h
595 + * Various assembly language/system dependent hacks that are required
596 + * so that we can minimize the amount of platform specific code.
598 + * Copyright (C) 2004-2007 Atmel Corporation
600 + * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
603 +/* Define this if the system uses RELOCA. */
604 +#define ELF_USES_RELOCA
609 +#define DT_AVR32_GOTSZ_IDX (DT_NUM + OS_NUM)
611 +#define ARCH_DYNAMIC_INFO(dpnt, dynamic, debug_addr) \
613 + if (dpnt->d_tag == DT_AVR32_GOTSZ) \
614 + dynamic[DT_AVR32_GOTSZ_IDX] = dpnt->d_un.d_val; \
617 +/* Initialization sequence for the application/library GOT. */
618 +#define INIT_GOT(GOT_BASE,MODULE) \
620 + unsigned long i, nr_got; \
622 + GOT_BASE[0] = (unsigned long) _dl_linux_resolve; \
623 + GOT_BASE[1] = (unsigned long) MODULE; \
625 + /* Add load address displacement to all GOT entries */ \
626 + nr_got = MODULE->dynamic_info[DT_AVR32_GOTSZ_IDX] / 4; \
627 + for (i = 2; i < nr_got; i++) \
628 + GOT_BASE[i] += (unsigned long)MODULE->loadaddr; \
631 +#define do_rem(result, n, base) ((result) = (n) % (base))
633 +/* Here we define the magic numbers that this dynamic loader should accept */
634 +#define MAGIC1 EM_AVR32
637 +/* Used for error messages */
638 +#define ELF_TARGET "AVR32"
640 +unsigned long _dl_linux_resolver(unsigned long got_offset, unsigned long *got);
642 +/* 4096 bytes alignment */
643 +#define PAGE_ALIGN 0xfffff000
644 +#define ADDR_ALIGN 0xfff
645 +#define OFFS_ALIGN 0x7ffff000
647 +#define elf_machine_type_class(type) \
648 + ((type == R_AVR32_JMP_SLOT) * ELF_RTYPE_CLASS_PLT)
650 +/* AVR32 doesn't need any COPY relocs */
651 +#define DL_NO_COPY_RELOCS
653 +/* Return the link-time address of _DYNAMIC. Conveniently, this is the
654 + first element of the GOT. This must be inlined in a function which
655 + uses global data. */
656 +static inline Elf32_Addr
657 +elf_machine_dynamic (void)
659 + register Elf32_Addr *got asm ("r6");
663 +/* Return the run-time load address of the shared object. */
664 +static inline Elf32_Addr
665 +elf_machine_load_address (void)
667 + extern void __dl_start asm("_dl_start");
668 + Elf32_Addr got_addr = (Elf32_Addr) &__dl_start;
669 + Elf32_Addr pcrel_addr;
671 + asm (" lddpc %0, 2f\n"
675 + "2: .long _dl_start - 1b\n"
677 + : "=r"(pcrel_addr) : : "cc");
679 + return pcrel_addr - got_addr;
683 + * Perform any RELATIVE relocations specified by DT_RELCOUNT.
684 + * Currently, we don't use that tag, but we might in the future as
685 + * this would reduce the startup time somewhat (although probably not by much).
688 +elf_machine_relative (Elf32_Addr load_off, const Elf32_Addr rel_addr,
689 + Elf32_Word relative_count)
691 + Elf32_Rela *rpnt = (void *)rel_addr;
694 + Elf32_Addr *reloc_addr;
695 + reloc_addr = (void *)(load_off + (rpnt++)->r_offset);
696 + *reloc_addr = load_off + rpnt->r_addend;
697 + } while (--relative_count);
699 diff --git a/ldso/ldso/avr32/elfinterp.c b/ldso/ldso/avr32/elfinterp.c
701 index 0000000..196292b
703 +++ b/ldso/ldso/avr32/elfinterp.c
706 + * AVR32 ELF shared library loader suppport
708 + * Copyright (C) 2004-2006 Atmel Corporation
710 + * All rights reserved.
712 + * Redistribution and use in source and binary forms, with or without
713 + * modification, are permitted provided that the following conditions
715 + * 1. Redistributions of source code must retain the above copyright
716 + * notice, this list of conditions and the following disclaimer.
717 + * 2. The name of the above contributors may not be
718 + * used to endorse or promote products derived from this software
719 + * without specific prior written permission.
721 + * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND
722 + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
723 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
724 + * ARE DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE
725 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
726 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
727 + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
728 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
729 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
730 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
734 +unsigned long _dl_linux_resolver(unsigned long got_offset, unsigned long *got)
736 + struct elf_resolve *tpnt = (struct elf_resolve *)got[1];
738 + unsigned long local_gotno;
739 + unsigned long gotsym;
740 + unsigned long new_addr;
741 + char *strtab, *symname;
742 + unsigned long *entry;
743 + unsigned long sym_index = got_offset / 4;
746 + local_gotno = tpnt->dynamic_info[DT_AVR32_LOCAL_GOTNO];
747 + gotsym = tpnt->dynamic_info[DT_AVR32_GOTSYM];
749 + sym = ((Elf32_Sym *)(tpnt->dynamic_info[DT_SYMTAB] + tpnt->loadaddr))
751 + strtab = (char *)(tpnt->dynamic_info[DT_STRTAB] + tpnt->loadaddr);
752 + symname = strtab + sym->st_name;
755 + new_addr = (unsigned long) _dl_find_hash(strtab + sym->st_name,
756 + tpnt->symbol_scope, tpnt,
760 + entry = (unsigned long *)(got + local_gotno + sym_index - gotsym);
768 +_dl_parse(struct elf_resolve *tpnt, struct dyn_elf *scope,
769 + unsigned long rel_addr, unsigned long rel_size,
770 + int (*reloc_func)(struct elf_resolve *tpnt, struct dyn_elf *scope,
771 + Elf32_Rela *rpnt, Elf32_Sym *symtab, char *strtab))
778 + rpnt = (Elf32_Rela *)rel_addr;
779 + rel_size /= sizeof(Elf32_Rela);
780 + symtab = (Elf32_Sym *)tpnt->dynamic_info[DT_SYMTAB];
781 + strtab = (char *)tpnt->dynamic_info[DT_STRTAB];
783 + for (i = 0; i < rel_size; i++, rpnt++) {
784 + int symtab_index, res;
786 + symtab_index = ELF32_R_SYM(rpnt->r_info);
788 + debug_sym(symtab, strtab, symtab_index);
789 + debug_reloc(symtab, strtab, rpnt);
791 + res = reloc_func(tpnt, scope, rpnt, symtab, strtab);
796 + _dl_dprintf(2, "\n%s: ", _dl_progname);
799 + _dl_dprintf(2, "symbol '%s': ",
800 + strtab + symtab[symtab_index].st_name);
803 + int reloc_type = ELF32_R_TYPE(rpnt->r_info);
804 +#if defined(__SUPPORT_LD_DEBUG__)
805 + _dl_dprintf(2, "can't handle reloc type %s\n",
806 + _dl_reltypes(reloc_type));
808 + _dl_dprintf(2, "can't handle reloc type %x\n",
813 + _dl_dprintf(2, "can't resolve symbol\n");
821 +static int _dl_do_reloc(struct elf_resolve *tpnt, struct dyn_elf *scope,
822 + Elf32_Rela *rpnt, Elf32_Sym *symtab, char *strtab)
827 + unsigned long *reloc_addr;
828 + unsigned long symbol_addr;
829 +#if defined(__SUPPORT_LD_DEBUG__)
830 + unsigned long old_val;
833 + reloc_addr = (unsigned long *)(tpnt->loadaddr + rpnt->r_offset);
834 + reloc_type = ELF32_R_TYPE(rpnt->r_info);
835 + symtab_index = ELF32_R_SYM(rpnt->r_info);
837 + symname = strtab + symtab[symtab_index].st_name;
839 + if (symtab_index) {
840 + symbol_addr = (unsigned long)
841 + _dl_find_hash(strtab + symtab[symtab_index].st_name,
842 + tpnt->symbol_scope, tpnt,
843 + elf_machine_type_class(reloc_type));
845 + /* Allow undefined references to weak symbols */
846 + if (!symbol_addr &&
847 + ELF32_ST_BIND(symtab[symtab_index].st_info) != STB_WEAK) {
848 + _dl_dprintf(2, "%s: can't resolve symbol '%s'\n",
849 + _dl_progname, symname);
854 +#if defined(__SUPPORT_LD_DEBUG__)
855 + old_val = *reloc_addr;
857 + switch (reloc_type) {
860 + case R_AVR32_GLOB_DAT:
861 + case R_AVR32_JMP_SLOT:
862 + *reloc_addr = symbol_addr + rpnt->r_addend;
864 + case R_AVR32_RELATIVE:
865 + *reloc_addr = (unsigned long)tpnt->loadaddr
872 +#if defined(__SUPPORT_LD_DEBUG__)
873 + if (_dl_debug_reloc && _dl_debug_detail)
874 + _dl_dprintf(_dl_debug_file, "\tpatched: %x ==> %x @ %x\n",
875 + old_val, *reloc_addr);
881 +void _dl_parse_lazy_relocation_information(struct dyn_elf *rpnt,
882 + unsigned long rel_addr,
883 + unsigned long rel_size)
885 + /* TODO: Might want to support this in order to get faster
886 + * startup times... */
889 +int _dl_parse_relocation_information(struct dyn_elf *rpnt,
890 + unsigned long rel_addr,
891 + unsigned long rel_size)
893 + return _dl_parse(rpnt->dyn, rpnt->dyn->symbol_scope, rel_addr, rel_size,
896 diff --git a/ldso/ldso/avr32/resolve.S b/ldso/ldso/avr32/resolve.S
898 index 0000000..e3cb7f4
900 +++ b/ldso/ldso/avr32/resolve.S
903 + * Linux dynamic resolving code for AVR32. Fixes up the GOT entry as
904 + * indicated in register r12 and jumps to the resolved address.
906 + * This file is subject to the terms and conditions of the GNU Lesser General
907 + * Public License. See the file "COPYING.LIB" in the main directory of this
908 + * archive for more details.
910 + * Copyright (C) 2004-2007 Atmel Corporation
916 + .global _dl_linux_resolve
917 + .type _dl_linux_resolve,@function
919 + /* The PLT code pushed r8 for us. It contains the address of this
920 + function's GOT entry, that is entry 0. ip contains the address
921 + of the GOT entry of the function we wanted to call. */
922 + stm --sp, r9-r12, lr
925 + rcall _dl_linux_resolver
929 + .size _dl_linux_resolve, . - _dl_linux_resolve
930 diff --git a/ldso/ldso/dl-startup.c b/ldso/ldso/dl-startup.c
931 index 5cf1d04..d4294ec 100644
932 --- a/ldso/ldso/dl-startup.c
933 +++ b/ldso/ldso/dl-startup.c
934 @@ -217,7 +217,9 @@ DL_START(unsigned long args)
935 /* some arches (like MIPS) we have to tweak the GOT before relocations */
936 PERFORM_BOOTSTRAP_GOT(tpnt);
941 +#if !defined(PERFORM_BOOTSTRAP_GOT) || defined(__avr32__)
943 /* OK, now do the relocations. We do not do a lazy binding here, so
944 that once we are done, we have considerably more flexibility. */
945 diff --git a/libc/inet/resolv.c b/libc/inet/resolv.c
946 index f4e6cac..9cdc3fe 100644
947 --- a/libc/inet/resolv.c
948 +++ b/libc/inet/resolv.c
949 @@ -1643,7 +1643,7 @@ int attribute_hidden __read_etc_hosts_r(FILE * fp, const char * name, int type,
952 #ifdef __UCLIBC_HAS_IPV6__
953 - } else if (type == AF_INET6 && inet_pton(AF_INET6, alias[0], in6) > 0) {
954 + } else if (type == AF_INET6 && inet_pton(AF_INET6, alias[0], in6) > 0) {
955 DPRINTF("Found INET6\n");
958 @@ -1658,8 +1658,8 @@ int attribute_hidden __read_etc_hosts_r(FILE * fp, const char * name, int type,
962 - break; /* bad ip address */
964 + continue; /* bad ip address, keep searching */
967 if (action!=GETHOSTENT) {
969 diff --git a/libc/string/avr32/Makefile b/libc/string/avr32/Makefile
971 index 0000000..e19e9d9
973 +++ b/libc/string/avr32/Makefile
975 +# Makefile for uClibc
977 +# Copyright (C) 2000-2003 Erik Andersen <andersen@uclibc.org>
979 +# This program is free software; you can redistribute it and/or modify it under
980 +# the terms of the GNU Library General Public License as published by the Free
981 +# Software Foundation; either version 2 of the License, or (at your option) any
984 +# This program is distributed in the hope that it will be useful, but WITHOUT
985 +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
986 +# FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more
989 +# You should have received a copy of the GNU Library General Public License
990 +# along with this program; if not, write to the Free Software Foundation, Inc.,
991 +# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
993 +top_srcdir := ../../../
994 +top_builddir := ../../../
998 +include $(top_builddir)Rules.mak
999 +include ../Makefile.in
1000 +include $(top_srcdir)Makerules
1001 diff --git a/libc/string/avr32/bcopy.S b/libc/string/avr32/bcopy.S
1002 new file mode 100644
1003 index 0000000..87c1e04
1005 +++ b/libc/string/avr32/bcopy.S
1008 + * Copyright (C) 2004-2007 Atmel Corporation
1010 + * This file is subject to the terms and conditions of the GNU Lesser General
1011 + * Public License. See the file "COPYING.LIB" in the main directory of this
1012 + * archive for more details.
1015 +#include <features.h>
1017 +#ifdef __UCLIBC_SUSV3_LEGACY__
1021 + .type bcopy, @function
1024 + /* Swap the first two arguments */
1030 + .size bcopy, . - bcopy
1032 +#endif /* __UCLIBC_SUSV3_LEGACY__ */
1033 diff --git a/libc/string/avr32/bzero.S b/libc/string/avr32/bzero.S
1034 new file mode 100644
1035 index 0000000..c999e65
1037 +++ b/libc/string/avr32/bzero.S
1040 + * Copyright (C) 2004-2007 Atmel Corporation
1042 + * This file is subject to the terms and conditions of the GNU Lesser General
1043 + * Public License. See the file "COPYING.LIB" in the main directory of this
1044 + * archive for more details.
1047 +#ifdef __UCLIBC_SUSV3_LEGACY__
1051 + .type bzero, @function
1058 + .size bzero, . - bzero
1060 +#endif /* __UCLIBC_SUSV3_LEGACY__ */
1061 diff --git a/libc/string/avr32/memcmp.S b/libc/string/avr32/memcmp.S
1062 new file mode 100644
1063 index 0000000..ae6cc91
1065 +++ b/libc/string/avr32/memcmp.S
1068 + * Copyright (C) 2004-2007 Atmel Corporation
1070 + * This file is subject to the terms and conditions of the GNU Lesser General
1071 + * Public License. See the file "COPYING.LIB" in the main directory of this
1072 + * archive for more details.
1075 +#include <features.h>
1083 + .type memcmp, @function
1087 + brlt .Lless_than_4
1112 +2: bfextu r11, r9, 24, 8
1113 + bfextu r12, r8, 24, 8
1122 + .size memcmp, . - memcmp
1124 +libc_hidden_def(memcmp)
1125 +#ifdef __UCLIBC_SUSV3_LEGACY__
1126 +strong_alias(memcmp,bcmp)
1128 diff --git a/libc/string/avr32/memcpy.S b/libc/string/avr32/memcpy.S
1129 new file mode 100644
1130 index 0000000..bf091ab
1132 +++ b/libc/string/avr32/memcpy.S
1135 + * Copyright (C) 2004-2007 Atmel Corporation
1137 + * This file is subject to the terms and conditions of the GNU Lesser General
1138 + * Public License. See the file "COPYING.LIB" in the main directory of this
1139 + * archive for more details.
1142 +/* Don't use r12 as dst since we must return it unmodified */
1149 + .type memcpy, @function
1154 + /* If we have less than 32 bytes, don't do anything fancy */
1156 + brge .Lmore_than_31
1169 + /* Check alignment */
1172 + brne .Lunaligned_src
1175 + brne .Lunaligned_dst
1179 + brlt .Lless_than_32
1181 +1: /* Copy 32 bytes at a time */
1190 + /* Copy 16 more bytes if possible */
1192 + brlt .Lless_than_16
1200 + /* Do the remaining as byte copies */
1202 + add pc, pc, len << 2
1211 + /* Make src cacheline-aligned. r8 = (src & 31) */
1219 + /* If dst is word-aligned, we're ready to go */
1223 + breq .Laligned_copy
1226 + /* src is aligned, but dst is not. Expect bad performance */
1235 + add pc, pc, len << 2
1242 + .size memcpy, . - memcpy
1244 +libc_hidden_def(memcpy)
1245 diff --git a/libc/string/avr32/memmove.S b/libc/string/avr32/memmove.S
1246 new file mode 100644
1247 index 0000000..98287c5
1249 +++ b/libc/string/avr32/memmove.S
1252 + * Copyright (C) 2004-2007 Atmel Corporation
1254 + * This file is subject to the terms and conditions of the GNU Lesser General
1255 + * Public License. See the file "COPYING.LIB" in the main directory of this
1256 + * archive for more details.
1265 + .type memmove, @function
1275 + * The rest is basically the same as in memcpy.S except that
1276 + * the direction is reversed.
1279 + brge .Lmore_than_31
1292 + /* Check alignment */
1295 + brne .Lunaligned_src
1298 + brne .Lunaligned_dst
1302 + brlt .Lless_than_32
1304 +1: /* Copy 32 bytes at a time */
1313 + /* Copy 16 more bytes if possible */
1315 + brlt .Lless_than_16
1323 + /* Do the remaining as byte copies */
1334 + /* Make src cacheline-aligned. r8 = (src & 31) */
1341 + /* If dst is word-aligned, we're ready to go */
1345 + breq .Laligned_copy
1348 + /* src is aligned, but dst is not. Expect bad performance */
1357 + add pc, pc, len << 2
1364 + .size memmove, . - memmove
1366 +libc_hidden_def(memmove)
1367 diff --git a/libc/string/avr32/memset.S b/libc/string/avr32/memset.S
1368 new file mode 100644
1369 index 0000000..33cfaed
1371 +++ b/libc/string/avr32/memset.S
1374 + * Copyright (C) 2004-2007 Atmel Corporation
1376 + * This file is subject to the terms and conditions of the GNU Lesser General
1377 + * Public License. See the file "COPYING.LIB" in the main directory of this
1378 + * archive for more details.
1381 +#include <features.h>
1389 + .type memset, @function
1393 + .type __memset, @function
1400 + brge .Llarge_memset
1413 + bfins r8, r8, 8, 8
1414 + bfins r8, r8, 16, 16
1431 + /* If we are done, n == -8 and we'll skip all st.b insns below */
1440 + .size memset, . - memset
1442 +libc_hidden_def(memset)
1443 diff --git a/libc/string/avr32/strcmp.S b/libc/string/avr32/strcmp.S
1444 new file mode 100644
1445 index 0000000..f73bd43
1447 +++ b/libc/string/avr32/strcmp.S
1450 + * Copyright (C) 2004-2007 Atmel Corporation
1452 + * This file is subject to the terms and conditions of the GNU Lesser General
1453 + * Public License. See the file "COPYING.LIB" in the main directory of this
1454 + * archive for more details.
1457 +#include <features.h>
1465 + .type strcmp, @function
1470 + brne .Lunaligned_s1
1472 + brne .Lunaligned_s2
1482 +2: bfextu r12, r8, 24, 8
1483 + bfextu r11, r9, 24, 8
1488 + bfextu r12, r8, 16, 8
1489 + bfextu r11, r9, 16, 8
1494 + bfextu r12, r8, 8, 8
1495 + bfextu r11, r9, 8, 8
1500 + bfextu r12, r8, 0, 8
1501 + bfextu r11, r9, 0, 8
1521 + * s1 and s2 can't both be aligned, and unaligned word loads
1522 + * can trigger spurious exceptions if we cross a page boundary.
1523 + * Do it the slow way...
1533 + .size strcmp, . - strcmp
1535 +libc_hidden_def(strcmp)
1536 +#ifndef __UCLIBC_HAS_LOCALE__
1537 +strong_alias(strcmp, strcoll)
1538 +libc_hidden_def(strcoll)
1540 diff --git a/libc/string/avr32/strlen.S b/libc/string/avr32/strlen.S
1541 new file mode 100644
1542 index 0000000..5223e53
1544 +++ b/libc/string/avr32/strlen.S
1547 + * Copyright (C) 2004-2007 Atmel Corporation
1549 + * This file is subject to the terms and conditions of the GNU Lesser General
1550 + * Public License. See the file "COPYING.LIB" in the main directory of this
1551 + * archive for more details.
1554 +#include <features.h>
1560 + .type strlen, @function
1566 + brne .Lunaligned_str
1573 + bfextu r9, r8, 24, 8
1577 + bfextu r9, r8, 16, 8
1581 + bfextu r9, r8, 8, 8
1589 + add pc, pc, r9 << 3
1590 + sub r0, r0, 0 /* 4-byte nop */
1605 + .size strlen, . - strlen
1607 +libc_hidden_def(strlen)
1608 diff --git a/libc/sysdeps/linux/avr32/Makefile b/libc/sysdeps/linux/avr32/Makefile
1609 new file mode 100644
1610 index 0000000..338abc0
1612 +++ b/libc/sysdeps/linux/avr32/Makefile
1614 +# Makefile for uClibc
1616 +# Copyright (C) 2000-2003 Erik Andersen <andersen@uclibc.org>
1618 +# This program is free software; you can redistribute it and/or modify it under
1619 +# the terms of the GNU Library General Public License as published by the Free
1620 +# Software Foundation; either version 2 of the License, or (at your option) any
1623 +# This program is distributed in the hope that it will be useful, but WITHOUT
1624 +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
1625 +# FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more
1628 +# You should have received a copy of the GNU Library General Public License
1629 +# along with this program; if not, write to the Free Software Foundation, Inc.,
1630 +# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1632 +top_srcdir=../../../../
1633 +top_builddir=../../../../
1636 +include $(top_builddir)Rules.mak
1637 +include Makefile.arch
1638 +include $(top_srcdir)Makerules
1639 diff --git a/libc/sysdeps/linux/avr32/Makefile.arch b/libc/sysdeps/linux/avr32/Makefile.arch
1640 new file mode 100644
1641 index 0000000..44fc01e
1643 +++ b/libc/sysdeps/linux/avr32/Makefile.arch
1645 +# Makefile for uClibc
1647 +# Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
1649 +# Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
1652 +CSRC := brk.c clone.c mmap.c sigaction.c
1654 +SSRC := __longjmp.S setjmp.S bsd-setjmp.S bsd-_setjmp.S \
1655 + sigrestorer.S syscall.S vfork.S
1657 +include $(top_srcdir)/libc/sysdeps/linux/Makefile.commonarch
1658 diff --git a/libc/sysdeps/linux/avr32/__longjmp.S b/libc/sysdeps/linux/avr32/__longjmp.S
1659 new file mode 100644
1660 index 0000000..6154bb2
1662 +++ b/libc/sysdeps/linux/avr32/__longjmp.S
1665 + * Copyright (C) 2004-2007 Atmel Corporation
1667 + * This file is subject to the terms and conditions of the GNU Lesser General
1668 + * Public License. See the file "COPYING.LIB" in the main directory of this
1669 + * archive for more details.
1673 + .type __longjmp,"function"
1676 + ldm r12++, r0-r8,sp,lr
1677 + mustr r8 /* restore status register (lower half) */
1678 + cp r11, 0 /* can't return zero */
1682 + .size __longjmp, . - __longjmp
1684 +libc_hidden_def(__longjmp)
1685 diff --git a/libc/sysdeps/linux/avr32/bits/atomic.h b/libc/sysdeps/linux/avr32/bits/atomic.h
1686 new file mode 100644
1687 index 0000000..e6be41f
1689 +++ b/libc/sysdeps/linux/avr32/bits/atomic.h
1692 + * Copyright (C) 2007 Atmel Corporation
1694 + * This file is subject to the terms and conditions of the GNU Lesser General
1695 + * Public License. See the file "COPYING.LIB" in the main directory of this
1696 + * archive for more details.
1698 +#ifndef _AVR32_BITS_ATOMIC_H
1699 +#define _AVR32_BITS_ATOMIC_H 1
1701 +#include <inttypes.h>
1703 +typedef int32_t atomic32_t;
1704 +typedef uint32_t uatomic32_t;
1705 +typedef int_fast32_t atomic_fast32_t;
1706 +typedef uint_fast32_t uatomic_fast32_t;
1708 +typedef intptr_t atomicptr_t;
1709 +typedef uintptr_t uatomicptr_t;
1710 +typedef intmax_t atomic_max_t;
1711 +typedef uintmax_t uatomic_max_t;
1713 +#define __arch_compare_and_exchange_val_8_acq(mem, newval, oldval) \
1716 +#define __arch_compare_and_exchange_val_16_acq(mem, newval, oldval) \
1719 +#define __arch_compare_and_exchange_val_32_acq(mem, newval, oldval) \
1721 + __typeof__(*(mem)) __prev; \
1722 + __asm__ __volatile__( \
1723 + "/* __arch_compare_and_exchange_val_32_acq */\n" \
1725 + " ld.w %[result], %[m]\n" \
1726 + " cp.w %[result], %[old]\n" \
1728 + " stcond %[m], %[new]\n" \
1731 + : [result] "=&r"(__result), [m] "=m"(*(mem)) \
1732 + : "m"(*(mem)), [old] "ir"(oldval), \
1733 + [new] "r"(newval) \
1734 + : "memory", "cc"); \
1738 +#define __arch_compare_and_exchange_val_64_acq(mem, newval, oldval) \
1741 +#define __arch_exchange_32_acq(mem, newval) \
1743 + __typeof__(*(mem)) __oldval; \
1744 + __asm__ __volatile__( \
1745 + "/*__arch_exchange_32_acq */\n" \
1746 + " xchg %[old], %[m], %[new]" \
1747 + : [old] "=&r"(__oldval) \
1748 + : [m] "r"(mem), [new] "r"(newval) \
1753 +#define __arch_atomic_exchange_and_add_32(mem, value) \
1755 + __typeof__(*(mem)) __oldval, __tmp; \
1756 + __asm__ __volatile__( \
1757 + "/* __arch_atomic_exchange_and_add_32 */\n" \
1759 + " ld.w %[old], %[m]\n" \
1760 + " add %[tmp], %[old], %[val]\n" \
1761 + " stcond %[m], %[tmp]\n" \
1763 + : [old] "=&r"(__oldval), [tmp] "=&r"(__tmp), \
1764 + [m] "=m"(*(mem)) \
1765 + : "m"(*(mem)), [val] "r"(value) \
1766 + : "memory", "cc"); \
1770 +#define __arch_atomic_decrement_if_positive_32(mem) \
1772 + __typeof__(*(mem)) __oldval, __tmp; \
1773 + __asm__ __volatile__( \
1774 + "/* __arch_atomic_decrement_if_positive_32 */\n" \
1776 + " ld.w %[old], %[m]\n" \
1777 + " sub %[tmp], %[old], 1\n" \
1779 + " stcond %[m], %[tmp]\n" \
1782 + : [old] "=&r"(__oldval), [tmp] "=&r"(__tmp), \
1783 + [m] "=m"(*(mem)) \
1785 + : "memory", "cc"); \
1789 +#define atomic_exchange_acq(mem, newval) \
1791 + if (sizeof(*(mem)) != 4) \
1793 + __arch_exchange_32_acq(mem, newval); \
1796 +#define atomic_exchange_and_add(mem, newval) \
1798 + if (sizeof(*(mem)) != 4) \
1800 + __arch_atomic_exchange_and_add_32(mem, newval); \
1803 +#define atomic_decrement_if_positive(mem) \
1805 + if (sizeof(*(mem)) != 4) \
1807 + __arch_atomic_decrement_if_positive_32(mem); \
1810 +#endif /* _AVR32_BITS_ATOMIC_H */
1811 diff --git a/libc/sysdeps/linux/avr32/bits/byteswap.h b/libc/sysdeps/linux/avr32/bits/byteswap.h
1812 new file mode 100644
1813 index 0000000..1c030b9
1815 +++ b/libc/sysdeps/linux/avr32/bits/byteswap.h
1818 + * Copyright (C) 2005 Atmel Corporation
1820 + * This file is subject to the terms and conditions of the GNU Lesser General
1821 + * Public License. See the file "COPYING.LIB" in the main directory of this
1822 + * archive for more details.
1825 +#if !defined _BYTESWAP_H && !defined _NETINET_IN_H
1826 +# error "Never use <bits/byteswap.h> directly; include <byteswap.h> instead."
1829 +#ifndef _BITS_BYTESWAP_H
1830 +#define _BITS_BYTESWAP_H 1
1832 +/* Swap bytes in 16 bit value. */
1833 +#if defined __GNUC__
1834 +# define __bswap_16(x) (__extension__ __builtin_bswap_16(x))
1836 +/* This is better than nothing. */
1837 +static __inline unsigned short int
1838 +__bswap_16 (unsigned short int __bsx)
1840 + return ((((__bsx) >> 8) & 0xff) | (((__bsx) & 0xff) << 8));
1844 +/* Swap bytes in 32 bit value. */
1845 +#if defined __GNUC__
1846 +# define __bswap_32(x) (__extension__ __builtin_bswap_32(x))
1848 +static __inline unsigned int
1849 +__bswap_32 (unsigned int __bsx)
1851 + return ((((__bsx) & 0xff000000) >> 24) | (((__bsx) & 0x00ff0000) >> 8) |
1852 + (((__bsx) & 0x0000ff00) << 8) | (((__bsx) & 0x000000ff) << 24));
1856 +#if defined __GNUC__
1857 +/* Swap bytes in 64 bit value. */
1858 +# define __bswap_constant_64(x) \
1859 + ((((x) & 0xff00000000000000ull) >> 56) \
1860 + | (((x) & 0x00ff000000000000ull) >> 40) \
1861 + | (((x) & 0x0000ff0000000000ull) >> 24) \
1862 + | (((x) & 0x000000ff00000000ull) >> 8) \
1863 + | (((x) & 0x00000000ff000000ull) << 8) \
1864 + | (((x) & 0x0000000000ff0000ull) << 24) \
1865 + | (((x) & 0x000000000000ff00ull) << 40) \
1866 + | (((x) & 0x00000000000000ffull) << 56))
1868 +# define __bswap_64(x) \
1872 + __extension__ unsigned long long int __ll; \
1873 + unsigned int __l[2]; \
1875 + if (__builtin_constant_p(x)) \
1876 + __r.__ll = __bswap_constant_64(x); \
1879 + __r.__l[0] = __bswap_32(__w.__l[1]); \
1880 + __r.__l[1] = __bswap_32(__w.__l[0]); \
1886 +#endif /* _BITS_BYTESWAP_H */
1887 diff --git a/libc/sysdeps/linux/avr32/bits/endian.h b/libc/sysdeps/linux/avr32/bits/endian.h
1888 new file mode 100644
1889 index 0000000..7bb6358
1891 +++ b/libc/sysdeps/linux/avr32/bits/endian.h
1893 +/* AVR32 is big-endian */
1896 +# error "Never use <bits/endian.h> directly; include <endian.h> instead."
1899 +#define __BYTE_ORDER __BIG_ENDIAN
1900 diff --git a/libc/sysdeps/linux/avr32/bits/fcntl.h b/libc/sysdeps/linux/avr32/bits/fcntl.h
1901 new file mode 100644
1902 index 0000000..1abff17
1904 +++ b/libc/sysdeps/linux/avr32/bits/fcntl.h
1907 +# error "Never use <bits/fcntl.h> directly; include <fcntl.h> instead."
1910 +#include <sys/types.h>
1913 + * open/fcntl - O_SYNC is only implemented on blocks devices and on files
1914 + * located on an ext2 file system
1916 +#define O_ACCMODE 00000003
1917 +#define O_RDONLY 00000000
1918 +#define O_WRONLY 00000001
1919 +#define O_RDWR 00000002
1920 +#define O_CREAT 00000100 /* not fcntl */
1921 +#define O_EXCL 00000200 /* not fcntl */
1922 +#define O_NOCTTY 00000400 /* not fcntl */
1923 +#define O_TRUNC 00001000 /* not fcntl */
1924 +#define O_APPEND 00002000
1925 +#define O_NONBLOCK 00004000
1926 +#define O_NDELAY O_NONBLOCK
1927 +#define O_SYNC 00010000
1928 +#define O_ASYNC 00020000
1931 +# define O_DIRECT 00040000 /* must be a directory */
1932 +# define O_DIRECTORY 00200000 /* direct disk access */
1933 +# define O_NOFOLLOW 00400000 /* don't follow links */
1934 +# define O_NOATIME 01000000 /* don't set atime */
1937 +#ifdef __USE_LARGEFILE64
1938 +# define O_LARGEFILE 00100000
1941 +/* For now Linux has synchronisity options for data and read operations.
1942 + We define the symbols here but let them do the same as O_SYNC since
1943 + this is a superset. */
1944 +#if defined __USE_POSIX199309 || defined __USE_UNIX98
1945 +# define O_DSYNC O_SYNC /* Synchronize data. */
1946 +# define O_RSYNC O_SYNC /* Synchronize read operations. */
1949 +#define F_DUPFD 0 /* dup */
1950 +#define F_GETFD 1 /* get close_on_exec */
1951 +#define F_SETFD 2 /* set/clear close_on_exec */
1952 +#define F_GETFL 3 /* get file->f_flags */
1953 +#define F_SETFL 4 /* set file->f_flags */
1955 +#ifndef __USE_FILE_OFFSET64
1958 +# define F_SETLKW 7
1960 +# define F_GETLK F_GETLK64
1961 +# define F_SETLK F_SETLK64
1962 +# define F_SETLKW F_SETLKW64
1964 +#define F_GETLK64 12 /* using 'struct flock64' */
1965 +#define F_SETLK64 13
1966 +#define F_SETLKW64 14
1968 +#if defined __USE_BSD || defined __USE_XOPEN2K
1969 +# define F_SETOWN 8 /* for sockets. */
1970 +# define F_GETOWN 9 /* for sockets. */
1974 +# define F_SETSIG 10 /* for sockets. */
1975 +# define F_GETSIG 11 /* for sockets. */
1979 +# define F_SETLEASE 1024 /* Set a lease. */
1980 +# define F_GETLEASE 1025 /* Enquire what lease is active. */
1981 +# define F_NOTIFY 1026 /* Request notfications on a directory. */
1984 +/* for F_[GET|SET]FL */
1985 +#define FD_CLOEXEC 1 /* actually anything with low bit set goes */
1987 +/* for posix fcntl() and lockf() */
1992 +/* for old implementation of bsd flock () */
1993 +#define F_EXLCK 4 /* or 3 */
1994 +#define F_SHLCK 8 /* or 4 */
1997 +#define F_INPROGRESS 16
2000 +/* operations for bsd flock(), also used by the kernel implementation */
2001 +# define LOCK_SH 1 /* shared lock */
2002 +# define LOCK_EX 2 /* exclusive lock */
2003 +# define LOCK_NB 4 /* or'd with one of the above to prevent
2005 +# define LOCK_UN 8 /* remove lock */
2009 +# define LOCK_MAND 32 /* This is a mandatory flock */
2010 +# define LOCK_READ 64 /* ... Which allows concurrent
2011 + read operations */
2012 +# define LOCK_WRITE 128 /* ... Which allows concurrent
2013 + write operations */
2014 +# define LOCK_RW 192 /* ... Which allows concurrent
2015 + read & write ops */
2019 +/* Types of directory notifications that may be requested with F_NOTIFY. */
2020 +# define DN_ACCESS 0x00000001 /* File accessed. */
2021 +# define DN_MODIFY 0x00000002 /* File modified. */
2022 +# define DN_CREATE 0x00000004 /* File created. */
2023 +# define DN_DELETE 0x00000008 /* File removed. */
2024 +# define DN_RENAME 0x00000010 /* File renamed. */
2025 +# define DN_ATTRIB 0x00000020 /* File changed attibutes. */
2026 +# define DN_MULTISHOT 0x80000000 /* Don't remove notifier. */
2032 +#ifndef __USE_FILE_OFFSET64
2036 + __off64_t l_start;
2042 +#ifdef __USE_LARGEFILE64
2046 + __off64_t l_start;
2052 +/* Define some more compatibility macros to be backward compatible with
2053 + * BSD systems which did not managed to hide these kernel macros. */
2055 +# define FAPPEND O_APPEND
2056 +# define FFSYNC O_FSYNC
2057 +# define FASYNC O_ASYNC
2058 +# define FNONBLOCK O_NONBLOCK
2059 +# define FNDELAY O_NDELAY
2060 +#endif /* Use BSD. */
2062 +/* Advise to `posix_fadvise'. */
2063 +#ifdef __USE_XOPEN2K
2064 +# define POSIX_FADV_NORMAL 0 /* No further special treatment. */
2065 +# define POSIX_FADV_RANDOM 1 /* Expect random page references. */
2066 +# define POSIX_FADV_SEQUENTIAL 2 /* Expect sequential page references. */
2067 +# define POSIX_FADV_WILLNEED 3 /* Will need these pages. */
2068 +# define POSIX_FADV_DONTNEED 4 /* Don't need these pages. */
2069 +# define POSIX_FADV_NOREUSE 5 /* Data will be accessed once. */
2071 diff --git a/libc/sysdeps/linux/avr32/bits/kernel_stat.h b/libc/sysdeps/linux/avr32/bits/kernel_stat.h
2072 new file mode 100644
2073 index 0000000..f97d23b
2075 +++ b/libc/sysdeps/linux/avr32/bits/kernel_stat.h
2077 +#ifndef _BITS_STAT_STRUCT_H
2078 +#define _BITS_STAT_STRUCT_H
2081 +#error bits/kernel_stat.h is for internal uClibc use only!
2085 + * This file provides struct stat, taken from kernel 2.6.4. Verified
2086 + * to match kernel 2.6.22.
2089 +struct kernel_stat {
2090 + unsigned long st_dev;
2091 + unsigned long st_ino;
2092 + unsigned short st_mode;
2093 + unsigned short st_nlink;
2094 + unsigned short st_uid;
2095 + unsigned short st_gid;
2096 + unsigned long st_rdev;
2097 + unsigned long st_size;
2098 + unsigned long st_blksize;
2099 + unsigned long st_blocks;
2100 + unsigned long st_atime;
2101 + unsigned long st_atime_nsec;
2102 + unsigned long st_mtime;
2103 + unsigned long st_mtime_nsec;
2104 + unsigned long st_ctime;
2105 + unsigned long st_ctime_nsec;
2106 + unsigned long __unused4;
2107 + unsigned long __unused5;
2110 +#define STAT_HAVE_NSEC 1
2112 +struct kernel_stat64 {
2113 + unsigned long long st_dev;
2115 + unsigned long long st_ino;
2116 + unsigned int st_mode;
2117 + unsigned int st_nlink;
2119 + unsigned long st_uid;
2120 + unsigned long st_gid;
2122 + unsigned long long st_rdev;
2124 + long long st_size;
2125 + unsigned long __pad1;
2126 + unsigned long st_blksize;
2128 + unsigned long long st_blocks;
2130 + unsigned long st_atime;
2131 + unsigned long st_atime_nsec;
2133 + unsigned long st_mtime;
2134 + unsigned long st_mtime_nsec;
2136 + unsigned long st_ctime;
2137 + unsigned long st_ctime_nsec;
2139 + unsigned long __unused1;
2140 + unsigned long __unused2;
2143 +#endif /* _BITS_STAT_STRUCT_H */
2144 diff --git a/libc/sysdeps/linux/avr32/bits/kernel_types.h b/libc/sysdeps/linux/avr32/bits/kernel_types.h
2145 new file mode 100644
2146 index 0000000..f7d8b52
2148 +++ b/libc/sysdeps/linux/avr32/bits/kernel_types.h
2150 +/* Note that we use the exact same include guard #define names
2151 + * as asm/posix_types.h. This will avoid gratuitous conflicts
2152 + * with the posix_types.h kernel header, and will ensure that
2153 + * our private content, and not the kernel header, will win.
2156 +#ifndef __ASM_AVR32_POSIX_TYPES_H
2157 +#define __ASM_AVR32_POSIX_TYPES_H
2160 + * This file is generally used by user-level software, so you need to
2161 + * be a little careful about namespace pollution etc. Also, we cannot
2162 + * assume GCC is being used.
2165 +typedef unsigned long __kernel_dev_t;
2166 +typedef unsigned long __kernel_ino_t;
2167 +typedef unsigned short __kernel_mode_t;
2168 +typedef unsigned short __kernel_nlink_t;
2169 +typedef long __kernel_off_t;
2170 +typedef int __kernel_pid_t;
2171 +typedef unsigned short __kernel_ipc_pid_t;
2172 +typedef unsigned int __kernel_uid_t;
2173 +typedef unsigned int __kernel_gid_t;
2174 +typedef unsigned long __kernel_size_t;
2175 +typedef long __kernel_ssize_t;
2176 +typedef int __kernel_ptrdiff_t;
2177 +typedef long __kernel_time_t;
2178 +typedef long __kernel_suseconds_t;
2179 +typedef long __kernel_clock_t;
2180 +typedef int __kernel_timer_t;
2181 +typedef int __kernel_clockid_t;
2182 +typedef int __kernel_daddr_t;
2183 +typedef char * __kernel_caddr_t;
2184 +typedef unsigned short __kernel_uid16_t;
2185 +typedef unsigned short __kernel_gid16_t;
2186 +typedef unsigned int __kernel_uid32_t;
2187 +typedef unsigned int __kernel_gid32_t;
2188 +typedef unsigned short __kernel_old_uid_t;
2189 +typedef unsigned short __kernel_old_gid_t;
2190 +typedef unsigned short __kernel_old_dev_t;
2193 +typedef long long __kernel_loff_t;
2197 +#if defined(__USE_ALL)
2204 +#endif /* __ASM_AVR32_POSIX_TYPES_H */
2205 diff --git a/libc/sysdeps/linux/avr32/bits/mman.h b/libc/sysdeps/linux/avr32/bits/mman.h
2206 new file mode 100644
2207 index 0000000..5f6e3c3
2209 +++ b/libc/sysdeps/linux/avr32/bits/mman.h
2211 +/* Definitions for POSIX memory map interface. Linux/AVR32 version.
2212 + Copyright (C) 1997, 2000 Free Software Foundation, Inc.
2213 + This file is part of the GNU C Library.
2215 + The GNU C Library is free software; you can redistribute it and/or
2216 + modify it under the terms of the GNU Lesser General Public
2217 + License as published by the Free Software Foundation; either
2218 + version 2.1 of the License, or (at your option) any later version.
2220 + The GNU C Library is distributed in the hope that it will be useful,
2221 + but WITHOUT ANY WARRANTY; without even the implied warranty of
2222 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2223 + Lesser General Public License for more details.
2225 + You should have received a copy of the GNU Lesser General Public
2226 + License along with the GNU C Library; if not, write to the Free
2227 + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
2228 + 02111-1307 USA. */
2230 +#ifndef _SYS_MMAN_H
2231 +# error "Never include this file directly. Use <sys/mman.h> instead"
2234 +/* The following definitions basically come from the kernel headers.
2235 + But the kernel header is not namespace clean. */
2238 +/* Protections are chosen from these bits, OR'd together. The
2239 + implementation does not necessarily support PROT_EXEC or PROT_WRITE
2240 + without PROT_READ. The only guarantees are that no writing will be
2241 + allowed without PROT_WRITE and no access will be allowed for PROT_NONE. */
2243 +#define PROT_READ 0x1 /* Page can be read. */
2244 +#define PROT_WRITE 0x2 /* Page can be written. */
2245 +#define PROT_EXEC 0x4 /* Page can be executed. */
2246 +#define PROT_NONE 0x0 /* Page can not be accessed. */
2247 +#define PROT_GROWSDOWN 0x01000000 /* Extend change to start of
2248 + growsdown vma (mprotect only). */
2249 +#define PROT_GROWSUP 0x02000000 /* Extend change to start of
2250 + growsup vma (mprotect only). */
2252 +/* Sharing types (must choose one and only one of these). */
2253 +#define MAP_SHARED 0x01 /* Share changes. */
2254 +#define MAP_PRIVATE 0x02 /* Changes are private. */
2256 +# define MAP_TYPE 0x0f /* Mask for type of mapping. */
2260 +#define MAP_FIXED 0x10 /* Interpret addr exactly. */
2262 +# define MAP_FILE 0
2263 +# define MAP_ANONYMOUS 0x20 /* Don't use a file. */
2264 +# define MAP_ANON MAP_ANONYMOUS
2267 +/* These are Linux-specific. */
2269 +# define MAP_GROWSDOWN 0x0100 /* Stack-like segment. */
2270 +# define MAP_DENYWRITE 0x0800 /* ETXTBSY */
2271 +# define MAP_EXECUTABLE 0x1000 /* Mark it as an executable. */
2272 +# define MAP_LOCKED 0x2000 /* Lock the mapping. */
2273 +# define MAP_NORESERVE 0x4000 /* Don't check for reservations. */
2274 +# define MAP_POPULATE 0x8000 /* populate (prefault) pagetables */
2275 +# define MAP_NONBLOCK 0x10000 /* do not block on IO */
2278 +/* Flags to `msync'. */
2279 +#define MS_ASYNC 1 /* Sync memory asynchronously. */
2280 +#define MS_SYNC 4 /* Synchronous memory sync. */
2281 +#define MS_INVALIDATE 2 /* Invalidate the caches. */
2283 +/* Flags for `mlockall'. */
2284 +#define MCL_CURRENT 1 /* Lock all currently mapped pages. */
2285 +#define MCL_FUTURE 2 /* Lock all additions to address
2288 +/* Flags for `mremap'. */
2290 +# define MREMAP_MAYMOVE 1
2291 +# define MREMAP_FIXED 2
2294 +/* Advise to `madvise'. */
2296 +# define MADV_NORMAL 0 /* No further special treatment. */
2297 +# define MADV_RANDOM 1 /* Expect random page references. */
2298 +# define MADV_SEQUENTIAL 2 /* Expect sequential page references. */
2299 +# define MADV_WILLNEED 3 /* Will need these pages. */
2300 +# define MADV_DONTNEED 4 /* Don't need these pages. */
2301 +# define MADV_REMOVE 9 /* Remove these pages and resources. */
2302 +# define MADV_DONTFORK 10 /* Do not inherit across fork. */
2303 +# define MADV_DOFORK 11 /* Do inherit across fork. */
2306 +/* The POSIX people had to invent similar names for the same things. */
2307 +#ifdef __USE_XOPEN2K
2308 +# define POSIX_MADV_NORMAL 0 /* No further special treatment. */
2309 +# define POSIX_MADV_RANDOM 1 /* Expect random page references. */
2310 +# define POSIX_MADV_SEQUENTIAL 2 /* Expect sequential page references. */
2311 +# define POSIX_MADV_WILLNEED 3 /* Will need these pages. */
2312 +# define POSIX_MADV_DONTNEED 4 /* Don't need these pages. */
2314 diff --git a/libc/sysdeps/linux/avr32/bits/setjmp.h b/libc/sysdeps/linux/avr32/bits/setjmp.h
2315 new file mode 100644
2316 index 0000000..78348a3
2318 +++ b/libc/sysdeps/linux/avr32/bits/setjmp.h
2321 + * Copyright (C) 2004-2005 Atmel Corporation
2323 + * This file is subject to the terms and conditions of the GNU Lesser General
2324 + * Public License. See the file "COPYING.LIB" in the main directory of this
2325 + * archive for more details.
2327 +#ifndef _BITS_SETJMP_H
2328 +#define _BITS_SETJMP_H 1
2330 +#if !defined _SETJMP_H && !defined _PTHREAD_H
2331 +# error "Never include <bits/setjmp.h> directly; use <setjmp.h> instead."
2336 + * The jump buffer contains r0-r7, sr, sp and lr. Other registers are
2339 +typedef int __jmp_buf[11];
2342 +#define __JMP_BUF_SP 4
2344 +/* Test if longjmp to JMPBUF would unwind the frame containing a local
2345 + variable at ADDRESS. */
2346 +#define _JMPBUF_UNWINDS(jmpbuf, address) \
2347 + ((void *)(address) < (void *)(jmpbuf[__JMP_BUF_SP]))
2349 +#endif /* _BITS_SETJMP_H */
2350 diff --git a/libc/sysdeps/linux/avr32/bits/stackinfo.h b/libc/sysdeps/linux/avr32/bits/stackinfo.h
2351 new file mode 100644
2352 index 0000000..29b8452
2354 +++ b/libc/sysdeps/linux/avr32/bits/stackinfo.h
2356 +/* Copyright (C) 1999 Free Software Foundation, Inc.
2357 + This file is part of the GNU C Library.
2359 + The GNU C Library is free software; you can redistribute it and/or
2360 + modify it under the terms of the GNU Lesser General Public
2361 + License as published by the Free Software Foundation; either
2362 + version 2.1 of the License, or (at your option) any later version.
2364 + The GNU C Library is distributed in the hope that it will be useful,
2365 + but WITHOUT ANY WARRANTY; without even the implied warranty of
2366 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2367 + Lesser General Public License for more details.
2369 + You should have received a copy of the GNU Lesser General Public
2370 + License along with the GNU C Library; if not, write to the Free
2371 + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
2372 + 02111-1307 USA. */
2374 +/* This file contains a bit of information about the stack allocation
2375 + of the processor. */
2377 +#ifndef _STACKINFO_H
2378 +#define _STACKINFO_H 1
2380 +/* On AVR32 the stack grows down. */
2381 +#define _STACK_GROWS_DOWN 1
2383 +#endif /* stackinfo.h */
2384 diff --git a/libc/sysdeps/linux/avr32/bits/syscalls.h b/libc/sysdeps/linux/avr32/bits/syscalls.h
2385 new file mode 100644
2386 index 0000000..22ac059
2388 +++ b/libc/sysdeps/linux/avr32/bits/syscalls.h
2390 +#ifndef _BITS_SYSCALLS_H
2391 +#define _BITS_SYSCALLS_H
2393 +# error "Never use <bits/syscalls.h> directly; include <sys/syscall.h> instead."
2397 + * This includes the `__NR_<name>' syscall numbers taken from the
2398 + * Linux kernel header files. It also defines the traditional
2399 + * `SYS_<name>' macros for older programs.
2401 +#include <bits/sysnum.h>
2403 +#ifndef __ASSEMBLER__
2407 +#define SYS_ify(syscall_name) (__NR_##syscall_name)
2410 +#define _syscall0(type,name) \
2413 + return (type)(INLINE_SYSCALL(name, 0)); \
2417 +#define _syscall1(type,name,type1,arg1) \
2418 + type name(type1 arg1) \
2420 + return (type)(INLINE_SYSCALL(name, 1, arg1)); \
2424 +#define _syscall2(type,name,type1,arg1,type2,arg2) \
2425 + type name(type1 arg1, type2 arg2) \
2427 + return (type)(INLINE_SYSCALL(name, 2, arg1, arg2)); \
2431 +#define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \
2432 + type name(type1 arg1, type2 arg2, type3 arg3) \
2434 + return (type)(INLINE_SYSCALL(name, 3, arg1, \
2439 +#define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3, \
2441 + type name(type1 arg1, type2 arg2, type3 arg3, type4 arg4) \
2443 + return (type)(INLINE_SYSCALL(name, 4, arg1, arg2, \
2448 +#define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3, \
2449 + type4,arg4,type5,arg5) \
2450 + type name(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \
2453 + return (type)(INLINE_SYSCALL(name, 5, arg1, arg2, \
2454 + arg3, arg4, arg5)); \
2458 +#define _syscall6(type,name,type1,arg1,type2,arg2,type3,arg3, \
2459 + type4,arg4,type5,arg5,type6,arg6) \
2460 + type name(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \
2461 + type5 arg5, type6 arg6) \
2463 + return (type)(INLINE_SYSCALL(name, 6, arg1, arg2, arg3, \
2464 + arg4, arg5, arg6)); \
2468 +#define unlikely(x) __builtin_expect((x), 0)
2470 +#undef INLINE_SYSCALL
2471 +#define INLINE_SYSCALL(name, nr, args...) \
2473 + unsigned _sys_result = INTERNAL_SYSCALL(name, , nr, args); \
2474 + if (unlikely(INTERNAL_SYSCALL_ERROR_P(_sys_result, ))) { \
2475 + __set_errno(INTERNAL_SYSCALL_ERRNO(_sys_result, )); \
2476 + _sys_result = (unsigned int) -1; \
2478 + (int) _sys_result; \
2481 +#undef INTERNAL_SYSCALL_DECL
2482 +#define INTERNAL_SYSCALL_DECL(err) do { } while(0)
2484 +#undef INTERNAL_SYSCALL
2485 +#define INTERNAL_SYSCALL(name, err, nr, args...) \
2487 + register int _a1 asm ("r12"); \
2488 + register int _scno asm("r8") = SYS_ify(name); \
2489 + LOAD_ARGS_##nr (args); \
2490 + asm volatile ("scall /* syscall " #name " */" \
2492 + : "r"(_scno) ASM_ARGS_##nr \
2493 + : "cc", "memory"); \
2497 +#undef INTERNAL_SYSCALL_ERROR_P
2498 +#define INTERNAL_SYSCALL_ERROR_P(val, err) \
2499 + ((unsigned int)(val) >= 0xfffff001U)
2501 +#undef INTERNAL_SYSCALL_ERRNO
2502 +#define INTERNAL_SYSCALL_ERRNO(val, errr) (-(val))
2504 +#define LOAD_ARGS_0() do { } while(0)
2506 +#define LOAD_ARGS_1(a1) \
2507 + _a1 = (int) (a1); \
2509 +#define ASM_ARGS_1 ASM_ARGS_0, "r"(_a1)
2510 +#define LOAD_ARGS_2(a1, a2) \
2511 + register int _a2 asm("r11") = (int)(a2); \
2513 +#define ASM_ARGS_2 ASM_ARGS_1, "r"(_a2)
2514 +#define LOAD_ARGS_3(a1, a2, a3) \
2515 + register int _a3 asm("r10") = (int)(a3); \
2516 + LOAD_ARGS_2(a1, a2)
2517 +#define ASM_ARGS_3 ASM_ARGS_2, "r"(_a3)
2518 +#define LOAD_ARGS_4(a1, a2, a3, a4) \
2519 + register int _a4 asm("r9") = (int)(a4); \
2520 + LOAD_ARGS_3(a1, a2, a3)
2521 +#define ASM_ARGS_4 ASM_ARGS_3, "r"(_a4)
2522 +#define LOAD_ARGS_5(a1, a2, a3, a4, a5) \
2523 + register int _a5 asm("r5") = (int)(a5); \
2524 + LOAD_ARGS_4(a1, a2, a3, a4)
2525 +#define ASM_ARGS_5 ASM_ARGS_4, "r"(_a5)
2526 +#define LOAD_ARGS_6(a1, a2, a3, a4, a5, a6) \
2527 + register int _a6 asm("r3") = (int)(a6); \
2528 + LOAD_ARGS_5(a1, a2, a3, a4, a5)
2529 +#define ASM_ARGS_6 ASM_ARGS_5, "r"(_a6)
2531 +#endif /* __ASSEMBLER__ */
2532 +#endif /* _BITS_SYSCALLS_H */
2533 diff --git a/libc/sysdeps/linux/avr32/bits/uClibc_arch_features.h b/libc/sysdeps/linux/avr32/bits/uClibc_arch_features.h
2534 new file mode 100644
2535 index 0000000..e95e8a5
2537 +++ b/libc/sysdeps/linux/avr32/bits/uClibc_arch_features.h
2540 + * Track misc arch-specific features that aren't config options
2543 +#ifndef _BITS_UCLIBC_ARCH_FEATURES_H
2544 +#define _BITS_UCLIBC_ARCH_FEATURES_H
2546 +/* instruction used when calling abort() to kill yourself */
2547 +/* trigger illegal instruction exception, same as BUG in Linux */
2548 +#define __UCLIBC_ABORT_INSTRUCTION__ ".short 0x5df0"
2550 +/* can your target use syscall6() for mmap ? */
2551 +#define __UCLIBC_MMAP_HAS_6_ARGS__
2553 +/* does your target use syscall4() for truncate64 ? (32bit arches only) */
2554 +#undef __UCLIBC_TRUNCATE64_HAS_4_ARGS__
2556 +/* does your target have a broken create_module() ? */
2557 +#undef __UCLIBC_BROKEN_CREATE_MODULE__
2559 +/* does your target have to worry about older [gs]etrlimit() ? */
2560 +#undef __UCLIBC_HANDLE_OLDER_RLIMIT__
2562 +/* does your target prefix all symbols with an _ ? */
2563 +#define __UCLIBC_NO_UNDERSCORES__
2565 +/* does your target have an asm .set ? */
2566 +#define __UCLIBC_HAVE_ASM_SET_DIRECTIVE__
2568 +/* define if target doesn't like .global */
2569 +#undef __UCLIBC_ASM_GLOBAL_DIRECTIVE__
2571 +/* define if target supports .weak */
2572 +#define __UCLIBC_HAVE_ASM_WEAK_DIRECTIVE__
2574 +/* define if target supports .weakext */
2575 +#undef __UCLIBC_HAVE_ASM_WEAKEXT_DIRECTIVE__
2577 +/* needed probably only for ppc64 */
2578 +#undef __UCLIBC_HAVE_ASM_GLOBAL_DOT_NAME__
2580 +/* define if target supports IEEE signed zero floats */
2581 +#define __UCLIBC_HAVE_SIGNED_ZERO__
2583 +#endif /* _BITS_UCLIBC_ARCH_FEATURES_H */
2584 diff --git a/libc/sysdeps/linux/avr32/bits/wordsize.h b/libc/sysdeps/linux/avr32/bits/wordsize.h
2585 new file mode 100644
2586 index 0000000..1b5842a
2588 +++ b/libc/sysdeps/linux/avr32/bits/wordsize.h
2590 +#define __WORDSIZE 32
2591 diff --git a/libc/sysdeps/linux/avr32/brk.c b/libc/sysdeps/linux/avr32/brk.c
2592 new file mode 100644
2593 index 0000000..a54b49a
2595 +++ b/libc/sysdeps/linux/avr32/brk.c
2598 + * Copyright (C) 2004-2007 Atmel Corporation
2600 + * This file is subject to the terms and conditions of the GNU Lesser General
2601 + * Public License. See the file "COPYING.LIB" in the main directory of this
2602 + * archive for more details.
2605 +#include <unistd.h>
2606 +#include <sys/syscall.h>
2608 +libc_hidden_proto(brk)
2610 +void *__curbrk attribute_hidden = 0;
2612 +int brk (void *addr)
2616 + newbrk = (void *)INLINE_SYSCALL(brk, 1, addr);
2618 + __curbrk = newbrk;
2620 + if (newbrk < addr) {
2621 + __set_errno (ENOMEM);
2627 +libc_hidden_def(brk)
2628 diff --git a/libc/sysdeps/linux/avr32/bsd-_setjmp.S b/libc/sysdeps/linux/avr32/bsd-_setjmp.S
2629 new file mode 100644
2630 index 0000000..be66a10
2632 +++ b/libc/sysdeps/linux/avr32/bsd-_setjmp.S
2635 + * Copyright (C) 2004-2007 Atmel Corporation
2637 + * This file is subject to the terms and conditions of the GNU Lesser General
2638 + * Public License. See the file "COPYING.LIB" in the main directory of this
2639 + * archive for more details.
2642 + /* This just does a tail-call to __sigsetjmp(env, 0) */
2644 + .type _setjmp,"function"
2648 + bral __GI___sigsetjmp
2649 + .size _setjmp, . - _setjmp
2650 diff --git a/libc/sysdeps/linux/avr32/bsd-setjmp.S b/libc/sysdeps/linux/avr32/bsd-setjmp.S
2651 new file mode 100644
2652 index 0000000..4635eeb
2654 +++ b/libc/sysdeps/linux/avr32/bsd-setjmp.S
2657 + * Copyright (C) 2004-2007 Atmel Corporation
2659 + * This file is subject to the terms and conditions of the GNU Lesser General
2660 + * Public License. See the file "COPYING.LIB" in the main directory of this
2661 + * archive for more details.
2664 + /* This just does a tail-call to __sigsetjmp(env, 1) */
2666 + .type setjmp,"function"
2670 + bral __GI___sigsetjmp
2671 + .size setjmp, . - setjmp
2672 diff --git a/libc/sysdeps/linux/avr32/clone.c b/libc/sysdeps/linux/avr32/clone.c
2673 new file mode 100644
2674 index 0000000..e43b0f3
2676 +++ b/libc/sysdeps/linux/avr32/clone.c
2679 + * Copyright (C) 2004 Atmel Corporation
2681 + * This file is subject to the terms and conditions of the GNU Lesser General
2682 + * Public License. See the file "COPYING.LIB" in the main directory of this
2683 + * archive for more details.
2686 +#include <sys/syscall.h>
2687 +#include <unistd.h>
2690 + * I don't know if we can be absolutely certain that the fn and arg
2691 + * parameters are preserved when returning as the child. If the
2692 + * compiler stores them in registers (r0-r7), they should be.
2694 +int clone(int (*fn)(void *arg), void *child_stack, int flags, void *arg)
2696 + register int (*_fn)(void *arg) = fn;
2697 + register void *_arg = arg;
2700 + /* Sanity check the arguments */
2703 + goto syscall_error;
2705 + goto syscall_error;
2707 + err = INLINE_SYSCALL(clone, 2, flags, child_stack);
2709 + goto syscall_error;
2710 + else if (err != 0)
2716 + __set_errno (-err);
2719 diff --git a/libc/sysdeps/linux/avr32/crt1.S b/libc/sysdeps/linux/avr32/crt1.S
2720 new file mode 100644
2721 index 0000000..ca1fa7a
2723 +++ b/libc/sysdeps/linux/avr32/crt1.S
2726 + * Copyright (C) 2004-2007 Atmel Corporation
2728 + * This file is subject to the terms and conditions of the GNU Lesser General
2729 + * Public License. See the file "COPYING.LIB" in the main directory of this
2730 + * archive for more details.
2732 + * When we enter _start, the stack looks like this:
2733 + * argc argument counter
2734 + * argv[0] pointer to program name
2735 + * argv[1..argc-1] pointers to program args
2737 + * env[0..N] pointers to environment variables
2740 + * r12 contains a function pointer to be registered with `atexit'.
2741 + * This is how the dynamic linker arranges to have DT_FINI functions
2742 + * called for shared libraries that have been loaded before this
2745 + * We're going to call the following function:
2746 + * __uClibc_main(int (*main)(int, char **, char **), int argc,
2747 + * char **argv, void (*app_init)(void), void (*app_fini)(void),
2748 + * void (*rtld_fini)(void), void *stack_end)
2750 + * So we need to set up things as follows:
2751 + * r12 = address of main
2754 + * r9 = address of _init
2755 + * r8 = address of _fini
2756 + * sp[0] = whatever we got passed in r12
2759 +#include <features.h>
2763 + .type _start, @function
2765 + /* Clear the frame pointer and link register since this is the outermost frame. */
2769 + ld.w r11, sp++ /* argc */
2770 + mov r10, sp /* &argv[0] */
2772 + st.w --sp, r10 /* stack_end */
2773 + st.w --sp, r12 /* rtld_fini */
2783 + /* Ok, now run uClibc's main() -- should not return */
2784 + call __uClibc_main
2788 + .long .L_RGOT - _GLOBAL_OFFSET_TABLE_
2790 + lddpc r9, __init_addr /* app_init */
2791 + lddpc r8, __fini_addr /* app_fini */
2792 + lddpc r12, __main_addr /* main */
2794 + /* Ok, now run uClibc's main() -- should not return */
2795 + lddpc pc, ___uClibc_main_addr
2804 +___uClibc_main_addr:
2805 + .long __uClibc_main
2807 + .size _start, . - _start
2810 + * The LSB says we need this.
2812 + .section ".note.ABI-tag", "a"
2814 + .long 2f - 1f /* namesz */
2815 + .long 4f - 3f /* descsz */
2816 + .long 1 /* type */
2817 +1: .asciz "GNU" /* name */
2819 +3: .long 0 /* Linux executable */
2820 + .long 2,6,0 /* Earliest compatible kernel */
2822 diff --git a/libc/sysdeps/linux/avr32/crti.S b/libc/sysdeps/linux/avr32/crti.S
2823 new file mode 100644
2824 index 0000000..660f47c
2826 +++ b/libc/sysdeps/linux/avr32/crti.S
2832 + .type _init, @function
2839 +2: .long 1b - _GLOBAL_OFFSET_TABLE_
2845 + .type _fini, @function
2852 +2: .long 1b - _GLOBAL_OFFSET_TABLE_
2854 diff --git a/libc/sysdeps/linux/avr32/crtn.S b/libc/sysdeps/linux/avr32/crtn.S
2855 new file mode 100644
2856 index 0000000..f7d1040
2858 +++ b/libc/sysdeps/linux/avr32/crtn.S
2864 + .type _init, @function
2866 + .size _init, . - _init
2871 + .type _fini, @function
2873 + .size _fini, . - _fini
2874 diff --git a/libc/sysdeps/linux/avr32/mmap.c b/libc/sysdeps/linux/avr32/mmap.c
2875 new file mode 100644
2876 index 0000000..2ee025a
2878 +++ b/libc/sysdeps/linux/avr32/mmap.c
2881 + * Copyright (C) 2004-2007 Atmel Corporation
2883 + * This file is subject to the terms and conditions of the GNU Lesser General
2884 + * Public License. See the file "COPYING.LIB" in the main directory of this
2885 + * archive for more details.
2889 +#include <unistd.h>
2890 +#include <sys/mman.h>
2891 +#include <sys/syscall.h>
2893 +libc_hidden_proto(mmap)
2895 +static _syscall6(__ptr_t, mmap2, __ptr_t, addr, size_t, len, int, prot,
2896 + int, flags, int, fd, __off_t, pgoff);
2898 +__ptr_t mmap(__ptr_t addr, size_t len, int prot, int flags, int fd, __off_t offset)
2900 + unsigned long page_size = sysconf(_SC_PAGESIZE);
2901 + unsigned long pgoff;
2903 + if (offset & (page_size - 1)) {
2904 + __set_errno(EINVAL);
2905 + return MAP_FAILED;
2908 + pgoff = (unsigned long)offset >> (31 - __builtin_clz(page_size));
2910 + return mmap2(addr, len, prot, flags, fd, pgoff);
2912 +libc_hidden_def(mmap)
2913 diff --git a/libc/sysdeps/linux/avr32/setjmp.S b/libc/sysdeps/linux/avr32/setjmp.S
2914 new file mode 100644
2915 index 0000000..7d0354b
2917 +++ b/libc/sysdeps/linux/avr32/setjmp.S
2920 + * Copyright (C) 2004-2007 Atmel Corporation
2922 + * This file is subject to the terms and conditions of the GNU Lesser General
2923 + * Public License. See the file "COPYING.LIB" in the main directory of this
2924 + * archive for more details.
2928 +#include <bits/setjmp.h>
2932 + .global __sigsetjmp
2933 + .type __sigsetjmp,"function"
2938 + stm r12, r0,r1,r2,r3,r4,r5,r6,r7,r8,sp,lr
2941 + * Make a tail call to __sigjmp_save; it takes the same args
2942 + * and is hidden so we don't need to mess around with the GOT.
2944 + rjmp __sigjmp_save
2945 + .size __sigsetjmp, . - __sigsetjmp
2947 +libc_hidden_def(__sigsetjmp)
2948 diff --git a/libc/sysdeps/linux/avr32/sigaction.c b/libc/sysdeps/linux/avr32/sigaction.c
2949 new file mode 100644
2950 index 0000000..a97ff3d
2952 +++ b/libc/sysdeps/linux/avr32/sigaction.c
2955 + * Copyright (C) 2004-2007 Atmel Corporation
2957 + * This file is subject to the terms and conditions of the GNU Lesser General
2958 + * Public License. See the file "COPYING.LIB" in the main directory of this
2959 + * archive for more details.
2962 +#include <signal.h>
2963 +#include <string.h>
2964 +#include <sys/syscall.h>
2965 +#include <bits/kernel_sigaction.h>
2967 +#define SA_RESTORER 0x04000000
2968 +extern void __default_rt_sa_restorer(void);
2970 +libc_hidden_proto(memcpy)
2973 + * If act is not NULL, change the action for sig to *act.
2974 + * If oact is not NULL, put the old action for sig in *oact.
2976 +int __libc_sigaction(int signum, const struct sigaction *act,
2977 + struct sigaction *oldact)
2979 + struct kernel_sigaction kact, koact;
2983 + kact.k_sa_handler = act->sa_handler;
2984 + memcpy(&kact.sa_mask, &act->sa_mask, sizeof (kact.sa_mask));
2985 + kact.sa_flags = act->sa_flags;
2986 + if (kact.sa_flags & (SA_RESTORER | SA_ONSTACK))
2987 + kact.sa_restorer = act->sa_restorer;
2989 + kact.sa_restorer = __default_rt_sa_restorer;
2990 + kact.sa_flags |= SA_RESTORER;
2993 + result = __syscall_rt_sigaction(signum, act ? __ptrvalue(&kact) : NULL,
2994 + oldact ? __ptrvalue(&koact) : NULL,
2997 + if (oldact && result >= 0) {
2998 + oldact->sa_handler = koact.k_sa_handler;
2999 + memcpy(&oldact->sa_mask, &koact.sa_mask,
3000 + sizeof(oldact->sa_mask));
3001 + oldact->sa_flags = koact.sa_flags;
3002 + oldact->sa_restorer = koact.sa_restorer;
3008 +#ifndef LIBC_SIGACTION
3009 +libc_hidden_proto(sigaction)
3010 +weak_alias(__libc_sigaction, sigaction)
3011 +libc_hidden_weak(sigaction)
3013 diff --git a/libc/sysdeps/linux/avr32/sigrestorer.S b/libc/sysdeps/linux/avr32/sigrestorer.S
3014 new file mode 100644
3015 index 0000000..df6a1ba
3017 +++ b/libc/sysdeps/linux/avr32/sigrestorer.S
3020 + * Copyright (C) 2004 Atmel Corporation
3022 + * This file is subject to the terms and conditions of the GNU Lesser General
3023 + * Public License. See the file "COPYING.LIB" in the main directory of this
3024 + * archive for more details.
3026 +#include <sys/syscall.h>
3028 + .global __default_rt_sa_restorer
3029 + .type __default_rt_sa_restorer,"function"
3031 +__default_rt_sa_restorer:
3032 + mov r8, __NR_rt_sigreturn
3034 diff --git a/libc/sysdeps/linux/avr32/sys/elf.h b/libc/sysdeps/linux/avr32/sys/elf.h
3035 new file mode 100644
3036 index 0000000..faa7310
3038 +++ b/libc/sysdeps/linux/avr32/sys/elf.h
3040 +/* Copyright (C) 1996, 1997, 1999, 2001 Free Software Foundation, Inc.
3041 + This file is part of the GNU C Library.
3043 + The GNU C Library is free software; you can redistribute it and/or
3044 + modify it under the terms of the GNU Lesser General Public
3045 + License as published by the Free Software Foundation; either
3046 + version 2.1 of the License, or (at your option) any later version.
3048 + The GNU C Library is distributed in the hope that it will be useful,
3049 + but WITHOUT ANY WARRANTY; without even the implied warranty of
3050 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3051 + Lesser General Public License for more details.
3053 + You should have received a copy of the GNU Lesser General Public
3054 + License along with the GNU C Library; if not, write to the Free
3055 + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
3056 + 02111-1307 USA. */
3059 +#define _SYS_ELF_H 1
3061 +#warning "This header is obsolete; use <sys/procfs.h> instead."
3063 +#include <sys/procfs.h>
3065 +#endif /* sys/elf.h */
3066 diff --git a/libc/sysdeps/linux/avr32/sys/procfs.h b/libc/sysdeps/linux/avr32/sys/procfs.h
3067 new file mode 100644
3068 index 0000000..3b37363
3070 +++ b/libc/sysdeps/linux/avr32/sys/procfs.h
3072 +/* Copyright (C) 1996, 1997, 1999, 2001 Free Software Foundation, Inc.
3073 + This file is part of the GNU C Library.
3075 + The GNU C Library is free software; you can redistribute it and/or
3076 + modify it under the terms of the GNU Lesser General Public
3077 + License as published by the Free Software Foundation; either
3078 + version 2.1 of the License, or (at your option) any later version.
3080 + The GNU C Library is distributed in the hope that it will be useful,
3081 + but WITHOUT ANY WARRANTY; without even the implied warranty of
3082 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3083 + Lesser General Public License for more details.
3085 + You should have received a copy of the GNU Lesser General Public
3086 + License along with the GNU C Library; if not, write to the Free
3087 + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
3088 + 02111-1307 USA. */
3090 +#ifndef _SYS_PROCFS_H
3091 +#define _SYS_PROCFS_H 1
3093 +/* This is somewhat modelled after the file of the same name on SVR4
3094 + systems. It provides a definition of the core file format for ELF
3095 + used on Linux. It doesn't have anything to do with the /proc file
3096 + system, even though Linux has one.
3098 + Anyway, the whole purpose of this file is for GDB and GDB only.
3099 + Don't read too much into it. Don't use it for anything other than
3100 + GDB unless you know what you are doing. */
3102 +#include <features.h>
3103 +#include <sys/time.h>
3104 +#include <sys/types.h>
3105 +#include <sys/user.h>
3109 +/* Type for a general-purpose register. */
3110 +typedef unsigned long elf_greg_t;
3112 +/* And the whole bunch of them. We could have used `struct
3113 + user_regs' directly in the typedef, but tradition says that
3114 + the register set is an array, which does have some peculiar
3115 + semantics, so leave it that way. */
3116 +#define ELF_NGREG (sizeof (struct user_regs) / sizeof(elf_greg_t))
3117 +typedef elf_greg_t elf_gregset_t[ELF_NGREG];
3119 +/* Register set for the floating-point registers. */
3120 +typedef struct user_fpregs elf_fpregset_t;
3125 + int si_signo; /* Signal number. */
3126 + int si_code; /* Extra code. */
3127 + int si_errno; /* Errno. */
3130 +/* Definitions to generate Intel SVR4-like core files. These mostly
3131 + have the same names as the SVR4 types with "elf_" tacked on the
3132 + front to prevent clashes with Linux definitions, and the typedef
3133 + forms have been avoided. This is mostly like the SVR4 structure,
3134 + but more Linuxy, with things that Linux does not support and which
3135 + GDB doesn't really use excluded. */
3137 +struct elf_prstatus
3139 + struct elf_siginfo pr_info; /* Info associated with signal. */
3140 + short int pr_cursig; /* Current signal. */
3141 + unsigned long int pr_sigpend; /* Set of pending signals. */
3142 + unsigned long int pr_sighold; /* Set of held signals. */
3147 + struct timeval pr_utime; /* User time. */
3148 + struct timeval pr_stime; /* System time. */
3149 + struct timeval pr_cutime; /* Cumulative user time. */
3150 + struct timeval pr_cstime; /* Cumulative system time. */
3151 + elf_gregset_t pr_reg; /* GP registers. */
3152 + int pr_fpvalid; /* True if math copro being used. */
3156 +#define ELF_PRARGSZ (80) /* Number of chars for args. */
3158 +struct elf_prpsinfo
3160 + char pr_state; /* Numeric process state. */
3161 + char pr_sname; /* Char for pr_state. */
3162 + char pr_zomb; /* Zombie. */
3163 + char pr_nice; /* Nice val. */
3164 + unsigned long int pr_flag; /* Flags. */
3165 + unsigned short int pr_uid;
3166 + unsigned short int pr_gid;
3167 + int pr_pid, pr_ppid, pr_pgrp, pr_sid;
3168 + /* Lots missing */
3169 + char pr_fname[16]; /* Filename of executable. */
3170 + char pr_psargs[ELF_PRARGSZ]; /* Initial part of arg list. */
3173 +/* The rest of this file provides the types for emulation of the
3174 + Solaris <proc_service.h> interfaces that should be implemented by
3175 + users of libthread_db. */
3178 +typedef void *psaddr_t;
3180 +/* Register sets. Linux has different names. */
3181 +typedef elf_gregset_t prgregset_t;
3182 +typedef elf_fpregset_t prfpregset_t;
3184 +/* We don't have any differences between processes and threads,
3185 + therefore have only one PID type. */
3186 +typedef __pid_t lwpid_t;
3188 +/* Process status and info. In the end we do provide typedefs for them. */
3189 +typedef struct elf_prstatus prstatus_t;
3190 +typedef struct elf_prpsinfo prpsinfo_t;
3194 +#endif /* sys/procfs.h */
3195 diff --git a/libc/sysdeps/linux/avr32/sys/ucontext.h b/libc/sysdeps/linux/avr32/sys/ucontext.h
3196 new file mode 100644
3197 index 0000000..82c7fe2
3199 +++ b/libc/sysdeps/linux/avr32/sys/ucontext.h
3201 +/* Copyright (C) 1998, 1999, 2001 Free Software Foundation, Inc.
3202 + This file is part of the GNU C Library.
3204 + The GNU C Library is free software; you can redistribute it and/or
3205 + modify it under the terms of the GNU Lesser General Public
3206 + License as published by the Free Software Foundation; either
3207 + version 2.1 of the License, or (at your option) any later version.
3209 + The GNU C Library is distributed in the hope that it will be useful,
3210 + but WITHOUT ANY WARRANTY; without even the implied warranty of
3211 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3212 + Lesser General Public License for more details.
3214 + You should have received a copy of the GNU Lesser General Public
3215 + License along with the GNU C Library; if not, write to the Free
3216 + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
3217 + 02111-1307 USA. */
3219 +/* Linux/AVR32 ABI compliant context switching support. */
3221 +#ifndef _SYS_UCONTEXT_H
3222 +#define _SYS_UCONTEXT_H 1
3224 +#include <features.h>
3225 +#include <signal.h>
3226 +#include <sys/procfs.h>
3227 +#include <bits/sigcontext.h>
3229 +typedef int greg_t;
3231 +/* Number of general registers. */
3234 +/* Container for all general registers. */
3235 +typedef elf_gregset_t gregset_t;
3237 +/* Number of each register is the `gregset_t' array. */
3274 +/* Structure to describe FPU registers. */
3275 +typedef elf_fpregset_t fpregset_t;
3277 +/* Context to describe whole processor state. */
3278 +typedef struct sigcontext mcontext_t;
3280 +/* Userlevel context. */
3281 +typedef struct ucontext
3283 + unsigned long uc_flags;
3284 + struct ucontext *uc_link;
3286 + mcontext_t uc_mcontext;
3287 + sigset_t uc_sigmask; /* mask last for extensibility */
3290 +#endif /* sys/ucontext.h */
3291 diff --git a/libc/sysdeps/linux/avr32/sys/user.h b/libc/sysdeps/linux/avr32/sys/user.h
3292 new file mode 100644
3293 index 0000000..c0b3d38
3295 +++ b/libc/sysdeps/linux/avr32/sys/user.h
3297 +#ifndef _SYS_USER_H
3298 +#define _SYS_USER_H
3311 + unsigned long r12;
3312 + unsigned long r11;
3313 + unsigned long r10;
3324 + unsigned long r12_orig;
3329 + struct user_regs regs; /* general registers */
3330 + size_t u_tsize; /* text size (pages) */
3331 + size_t u_dsize; /* data size (pages) */
3332 + size_t u_ssize; /* stack size (pages) */
3333 + unsigned long start_code; /* text starting address */
3334 + unsigned long start_data; /* data starting address */
3335 + unsigned long start_stack; /* stack starting address */
3336 + long int signal; /* signal causing core dump */
3337 + struct user_regs * u_ar0; /* help gdb find registers */
3338 + unsigned long magic; /* identifies a core file */
3339 + char u_comm[32]; /* user command name */
3342 +#endif /* _SYS_USER_H */
3343 diff --git a/libc/sysdeps/linux/avr32/syscall.S b/libc/sysdeps/linux/avr32/syscall.S
3344 new file mode 100644
3345 index 0000000..55c1b1f
3347 +++ b/libc/sysdeps/linux/avr32/syscall.S
3350 + * Copyright (C) 2004-2007 Atmel Corporation
3352 + * This file is subject to the terms and conditions of the GNU Lesser General
3353 + * Public License. See the file "COPYING.LIB" in the main directory of this
3354 + * archive for more details.
3356 +#include <features.h>
3361 + * long int syscall(long int sysno, ...)
3364 + .type syscall, @function
3367 + stm --sp, r3,r5,r6,lr
3370 + ldm lr, r3,r5,r9-r12
3379 +# ifdef __UCLIBC_HAS_THREADS__
3381 + mcall r6[__errno_location@got]
3384 + ld.w r3, r6[errno@got]
3389 +# ifdef __UCLIBC_HAS_THREADS__
3391 + mcall .Lerrno_location
3402 + ldm sp++, r3,r5,r6,pc
3407 + .long .Lgotcalc - _GLOBAL_OFFSET_TABLE_
3409 +# ifdef __UCLIBC_HAS_THREADS__
3411 + .long __errno_location
3419 + .size syscall, . - syscall
3420 diff --git a/libc/sysdeps/linux/avr32/vfork.S b/libc/sysdeps/linux/avr32/vfork.S
3421 new file mode 100644
3422 index 0000000..03ca99f
3424 +++ b/libc/sysdeps/linux/avr32/vfork.S
3427 + * Copyright (C) 2005 Atmel Corporation
3429 + * This file is subject to the terms and conditions of the GNU Lesser General
3430 + * Public License. See the file "COPYING.LIB" in the main directory of this
3431 + * archive for more details.
3435 + * Clone the process without copying the address space. The
3436 + * calling process is suspended until the child either exits
3437 + * or calls execve.
3439 + * This all means that we cannot rely on the stack to store
3440 + * away registers, since they will be overwritten by the child
3441 + * as soon as it makes another function call (e.g. execve()).
3442 + * Fortunately, the Linux kernel preserves LR across system calls.
3445 +#include <features.h>
3446 +#include <sys/syscall.h>
3449 + .type __vfork,@function
3452 + mov r8, __NR_vfork
3457 + /* vfork failed, so we may use the stack freely */
3464 + mcall r6[__errno_location@got]
3467 + mcall .L__errno_location
3470 + popm r4-r7,pc,r12=-1
3475 + .long .L_RGOT - _GLOBAL_OFFSET_TABLE_
3477 +.L__errno_location:
3478 + .long __errno_location
3480 + .size __vfork, . - __vfork
3482 +weak_alias(__vfork,vfork)
3483 +libc_hidden_weak(vfork)
3484 diff --git a/libpthread/linuxthreads.old/sysdeps/avr32/pt-machine.h b/libpthread/linuxthreads.old/sysdeps/avr32/pt-machine.h
3485 new file mode 100644
3486 index 0000000..eccf329
3488 +++ b/libpthread/linuxthreads.old/sysdeps/avr32/pt-machine.h
3490 +/* Machine-dependent pthreads configuration and inline functions.
3492 + * Copyright (C) 2005-2007 Atmel Corporation
3494 + * This file is subject to the terms and conditions of the GNU Lesser General
3495 + * Public License. See the file "COPYING.LIB" in the main directory of this
3496 + * archive for more details.
3498 +#ifndef _PT_MACHINE_H
3499 +#define _PT_MACHINE_H 1
3501 +#include <features.h>
3504 +_test_and_set (int *p, int v)
3508 + __asm__ __volatile__(
3509 + "/* Inline test and set */\n"
3510 + " xchg %[old], %[mem], %[new]"
3511 + : [old] "=&r"(result)
3512 + : [mem] "r"(p), [new] "r"(v)
3519 +# define PT_EI extern inline
3522 +extern long int testandset (int *spinlock);
3523 +extern int __compare_and_swap (long int *p, long int oldval, long int newval);
3525 +/* Spinlock implementation; required. */
3527 +testandset (int *spinlock)
3529 + return _test_and_set(spinlock, 1);
3533 +/* Get some notion of the current stack. Need not be exactly the top
3534 + of the stack, just something somewhere in the current frame. */
3535 +#define CURRENT_STACK_FRAME stack_pointer
3536 +register char * stack_pointer __asm__ ("sp");
3538 +/* Compare-and-swap for semaphores. */
3540 +#define HAS_COMPARE_AND_SWAP
3542 +__compare_and_swap(long int *p, long int oldval, long int newval)
3546 + __asm__ __volatile__(
3547 + "/* Inline compare and swap */\n"
3549 + " ld.w %[result], %[mem]\n"
3550 + " eor %[result], %[old]\n"
3552 + " stcond %[mem], %[new]\n"
3555 + : [result] "=&r"(result), [mem] "=m"(*p)
3556 + : "m"(*p), [new] "r"(newval), [old] "r"(oldval)
3557 + : "cc", "memory");
3559 + return result == 0;
3562 +#endif /* pt-machine.h */
3563 diff --git a/libpthread/linuxthreads/sysdeps/avr32/pt-machine.h b/libpthread/linuxthreads/sysdeps/avr32/pt-machine.h
3564 new file mode 100644
3565 index 0000000..fe12bf8
3567 +++ b/libpthread/linuxthreads/sysdeps/avr32/pt-machine.h
3569 +/* Machine-dependent pthreads configuration and inline functions.
3571 + * Copyright (C) 2005-2007 Atmel Corporation
3573 + * This file is subject to the terms and conditions of the GNU Lesser General
3574 + * Public License. See the file "COPYING.LIB" in the main directory of this
3575 + * archive for more details.
3577 +#ifndef _PT_MACHINE_H
3578 +#define _PT_MACHINE_H 1
3580 +#include <features.h>
3583 +_test_and_set (int *p, int v) __THROW
3587 + __asm__ __volatile__(
3588 + "/* Inline test and set */\n"
3589 + " xchg %[old], %[mem], %[new]"
3590 + : [old] "=&r"(result)
3591 + : [mem] "r"(p), [new] "r"(v)
3598 +# define PT_EI extern inline
3601 +extern long int testandset (int *spinlock);
3602 +extern int __compare_and_swap (long int *p, long int oldval, long int newval);
3604 +/* Spinlock implementation; required. */
3606 +testandset (int *spinlock)
3608 + return _test_and_set(spinlock, 1);
3612 +/* Get some notion of the current stack. Need not be exactly the top
3613 + of the stack, just something somewhere in the current frame. */
3614 +#define CURRENT_STACK_FRAME stack_pointer
3615 +register char * stack_pointer __asm__ ("sp");
3617 +/* Compare-and-swap for semaphores. */
3619 +#define HAS_COMPARE_AND_SWAP
3621 +__compare_and_swap(long int *p, long int oldval, long int newval)
3625 + __asm__ __volatile__(
3626 + "/* Inline compare and swap */\n"
3628 + " ld.w %[result], %[mem]\n"
3629 + " eor %[result], %[old]\n"
3631 + " stcond %[mem], %[new]\n"
3634 + : [result] "=&r"(result), [mem] "=m"(*p)
3635 + : "m"(*p), [new] "r"(newval), [old] "r"(oldval)
3636 + : "cc", "memory");
3638 + return result == 0;
3641 +#endif /* pt-machine.h */
3642 diff --git a/utils/ldd.c b/utils/ldd.c
3643 index 75ad628..e34acd9 100644
3647 #define ELFCLASSM ELFCLASS32
3650 +#if defined(__avr32__)
3651 +#define MATCH_MACHINE(x) (x == EM_AVR32)
3652 +#define ELFCLASSM ELFCLASS32
3655 #if defined(__s390__)
3656 #define MATCH_MACHINE(x) (x == EM_S390)
3657 #define ELFCLASSM ELFCLASS32