fix uclibc compile on brcm-2.4
[openwrt.git] / toolchain / uClibc / patches / 007-avr32.patch
1 Rules.mak | 6 +
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 ++++++++
59 utils/ldd.c | 5 +
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
114 --- a/Rules.mak
115 +++ b/Rules.mak
116 @@ -313,6 +313,12 @@ ifeq ($(TARGET_ARCH),frv)
117 UCLIBC_LDSO=ld.so.1
118 endif
119
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
124 +endif
125 +
126 # Keep the check_gcc from being needlessly executed
127 ifndef PIEFLAG
128 ifneq ($(UCLIBC_BUILD_PIE),y)
129 diff --git a/extra/Configs/Config.avr32 b/extra/Configs/Config.avr32
130 new file mode 100644
131 index 0000000..8d70e6e
132 --- /dev/null
133 +++ b/extra/Configs/Config.avr32
134 @@ -0,0 +1,31 @@
135 +#
136 +# For a description of the syntax of this configuration file,
137 +# see extra/config/Kconfig-language.txt
138 +#
139 +
140 +config TARGET_ARCH
141 + string
142 + default "avr32"
143 +
144 +config FORCE_OPTIONS_FOR_ARCH
145 + bool
146 + default y
147 + select ARCH_BIG_ENDIAN
148 + select FORCE_SHAREABLE_TEXT_SEGMENTS
149 +
150 +config ARCH_CFLAGS
151 + string
152 +
153 +choice
154 + prompt "Target CPU Type"
155 + default CONFIG_AVR32_AP7
156 +
157 +config CONFIG_AVR32_AP7
158 + bool "AVR32 AP7"
159 + select ARCH_HAS_MMU
160 +
161 +endchoice
162 +
163 +config LINKRELAX
164 + bool "Enable linker optimizations"
165 + default y
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
171 config TARGET_arm
172 bool "arm"
173
174 +config TARGET_avr32
175 + bool "avr32"
176 +
177 config TARGET_bfin
178 bool "bfin"
179
180 @@ -92,6 +95,10 @@ if TARGET_arm
181 source "extra/Configs/Config.arm"
182 endif
183
184 +if TARGET_avr32
185 +source "extra/Configs/Config.avr32"
186 +endif
187 +
188 if TARGET_bfin
189 source "extra/Configs/Config.bfin"
190 endif
191 diff --git a/extra/Configs/defconfigs/avr32 b/extra/Configs/defconfigs/avr32
192 new file mode 100644
193 index 0000000..0b890a2
194 --- /dev/null
195 +++ b/extra/Configs/defconfigs/avr32
196 @@ -0,0 +1 @@
197 +TARGET_avr32=y
198 diff --git a/include/elf.h b/include/elf.h
199 index 19805d7..ab90160 100644
200 --- a/include/elf.h
201 +++ b/include/elf.h
202 @@ -354,6 +354,8 @@ typedef struct
203 /* NIOS magic number - no EABI available. */
204 #define EM_NIOS32 0xFEBB
205
206 +#define EM_AVR32 0x18ad
207 +
208 /* V850 backend magic number. Written in the absense of an ABI. */
209 #define EM_CYGNUS_V850 0x9080
210
211 @@ -2828,6 +2830,55 @@ typedef Elf32_Addr Elf32_Conflict;
212 /* Keep this the last entry. */
213 #define R_V850_NUM 25
214
215 +/* Atmel AVR32 relocations. */
216 +#define R_AVR32_NONE 0
217 +#define R_AVR32_32 1
218 +#define R_AVR32_16 2
219 +#define R_AVR32_8 3
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
261 +
262 +/* AVR32 dynamic tags */
263 +#define DT_AVR32_GOTSZ 0x70000001 /* Total size of GOT in bytes */
264
265 /* Renesas H8/300 Relocations */
266 #define R_H8_NONE 0
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__) || \
277 + defined(__avr32__)
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
285 @@ -55,69 +55,69 @@
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);
291
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);
295
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);
300
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);
305
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);
310
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);
315
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,
319 struct stat *, buf);
320
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);
324
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);
328
329 #ifdef __NR_getxuid
330 # define __NR_getuid __NR_getxuid
331 #endif
332 #define __NR__dl_getuid __NR_getuid
333 -static inline _syscall0(uid_t, _dl_getuid);
334 +static __always_inline _syscall0(uid_t, _dl_getuid);
335
336 #ifndef __NR_geteuid
337 # define __NR_geteuid __NR_getuid
338 #endif
339 #define __NR__dl_geteuid __NR_geteuid
340 -static inline _syscall0(uid_t, _dl_geteuid);
341 +static __always_inline _syscall0(uid_t, _dl_geteuid);
342
343 #ifdef __NR_getxgid
344 # define __NR_getgid __NR_getxgid
345 #endif
346 #define __NR__dl_getgid __NR_getgid
347 -static inline _syscall0(gid_t, _dl_getgid);
348 +static __always_inline _syscall0(gid_t, _dl_getgid);
349
350 #ifndef __NR_getegid
351 # define __NR_getegid __NR_getgid
352 #endif
353 #define __NR__dl_getegid __NR_getegid
354 -static inline _syscall0(gid_t, _dl_getegid);
355 +static __always_inline _syscall0(gid_t, _dl_getegid);
356
357 #ifdef __NR_getxpid
358 # define __NR_getpid __NR_getxpid
359 #endif
360 #define __NR__dl_getpid __NR_getpid
361 -static inline _syscall0(gid_t, _dl_getpid);
362 +static __always_inline _syscall0(gid_t, _dl_getpid);
363
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,
367 size_t, bufsiz);
368
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)
372
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);
377
378 /* then try mmap2() */
379 #elif defined(__NR_mmap2)
380
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);
385
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
389 #endif
390
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)
394 {
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)
398
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)
405 {
406 unsigned long buffer[6];
407 diff --git a/ldso/ldso/avr32/dl-debug.h b/ldso/ldso/avr32/dl-debug.h
408 new file mode 100644
409 index 0000000..fe35539
410 --- /dev/null
411 +++ b/ldso/ldso/avr32/dl-debug.h
412 @@ -0,0 +1,45 @@
413 +/*
414 + * AVR32 ELF shared libary loader support
415 + *
416 + * Copyright (C) 2005-2007 Atmel Corporation
417 + * All rights reserved.
418 + *
419 + * Redistribution and use in source and binary forms, with or without
420 + * modification, are permitted provided that the following conditions
421 + * are met:
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.
427 + *
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
438 + * SUCH DAMAGE.
439 + */
440 +
441 +static const char *_dl_reltypes_tab[] = {
442 + "R_AVR32_NONE",
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",
456 + "R_AVR32_ALIGN",
457 +};
458 diff --git a/ldso/ldso/avr32/dl-startup.h b/ldso/ldso/avr32/dl-startup.h
459 new file mode 100644
460 index 0000000..3b9a641
461 --- /dev/null
462 +++ b/ldso/ldso/avr32/dl-startup.h
463 @@ -0,0 +1,112 @@
464 +/*
465 + * Architecture specific code used by dl-startup.c
466 + *
467 + * Copyright (C) 2005-2007 Atmel Corporation
468 + *
469 + * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
470 + */
471 +
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
474 + * afterwards. */
475 +asm( " .text\n"
476 + " .global _start\n"
477 + " .type _start,@function\n"
478 + "_start:\n"
479 + /* All arguments are on the stack initially */
480 + " mov r12, sp\n"
481 + " rcall _dl_start\n"
482 + /* Returns user entry point in r12. Save it. */
483 + " mov r0, r12\n"
484 + /* We're PIC, so get the Global Offset Table */
485 + " lddpc r6, .L_GOT\n"
486 + ".L_RGOT:\n"
487 + " rsub r6, pc\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"
491 + " ld.w r2, sp++\n"
492 + " sub r2, r1\n"
493 + " add sp, sp, r1 << 2\n"
494 + " st.w --sp, r2\n"
495 + /* Load the finalizer function */
496 + " ld.w r12, r6[_dl_fini@got]\n"
497 + /* Jump to the user's entry point */
498 + " mov pc, r0\n\n"
499 +
500 + " .align 2\n"
501 + ".L_GOT:"
502 + " .long .L_RGOT - _GLOBAL_OFFSET_TABLE_\n"
503 + " .size _start, . - _start\n"
504 + " .previous\n");
505 +
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)
510 +
511 +
512 +/* We can't call functions before the GOT has been initialized */
513 +#define NO_FUNCS_BEFORE_BOOTSTRAP
514 +
515 +/*
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
519 + * GOT.
520 + */
521 +static __always_inline
522 +void PERFORM_BOOTSTRAP_GOT(struct elf_resolve *tpnt)
523 +{
524 + Elf32_Addr i, nr_got;
525 + register Elf32_Addr *__r6 __asm__("r6");
526 + Elf32_Addr *got = __r6;
527 +
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;
531 +}
532 +
533 +#define PERFORM_BOOTSTRAP_GOT(tpnt) PERFORM_BOOTSTRAP_GOT(tpnt)
534 +
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)
540 +{
541 + switch(ELF32_R_TYPE(rpnt->r_info)) {
542 + case R_AVR32_NONE:
543 + break;
544 + case R_AVR32_GLOB_DAT:
545 + case R_AVR32_JMP_SLOT:
546 + *reloc_addr = symbol_addr;
547 + break;
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;
554 + break;
555 + default:
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);
560 + SEND_STDERR(", ");
561 + SEND_ADDRESS_STDERR(symbol_addr, 0);
562 + SEND_STDERR(", ");
563 + SEND_ADDRESS_STDERR(load_addr, 1);
564 + _dl_exit(1);
565 + }
566 +}
567 +
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.
571 + *
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
574 + * call. */
575 +#define START() return _dl_elf_main;
576 diff --git a/ldso/ldso/avr32/dl-syscalls.h b/ldso/ldso/avr32/dl-syscalls.h
577 new file mode 100644
578 index 0000000..996bb87
579 --- /dev/null
580 +++ b/ldso/ldso/avr32/dl-syscalls.h
581 @@ -0,0 +1,6 @@
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;
586 +#undef __set_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
589 new file mode 100644
590 index 0000000..1a30172
591 --- /dev/null
592 +++ b/ldso/ldso/avr32/dl-sysdep.h
593 @@ -0,0 +1,105 @@
594 +/*
595 + * Various assembly language/system dependent hacks that are required
596 + * so that we can minimize the amount of platform specific code.
597 + *
598 + * Copyright (C) 2004-2007 Atmel Corporation
599 + *
600 + * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
601 + */
602 +
603 +/* Define this if the system uses RELOCA. */
604 +#define ELF_USES_RELOCA
605 +
606 +#include <elf.h>
607 +
608 +#define ARCH_NUM 1
609 +#define DT_AVR32_GOTSZ_IDX (DT_NUM + OS_NUM)
610 +
611 +#define ARCH_DYNAMIC_INFO(dpnt, dynamic, debug_addr) \
612 + do { \
613 + if (dpnt->d_tag == DT_AVR32_GOTSZ) \
614 + dynamic[DT_AVR32_GOTSZ_IDX] = dpnt->d_un.d_val; \
615 + } while (0)
616 +
617 +/* Initialization sequence for the application/library GOT. */
618 +#define INIT_GOT(GOT_BASE,MODULE) \
619 + do { \
620 + unsigned long i, nr_got; \
621 + \
622 + GOT_BASE[0] = (unsigned long) _dl_linux_resolve; \
623 + GOT_BASE[1] = (unsigned long) MODULE; \
624 + \
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; \
629 + } while (0)
630 +
631 +#define do_rem(result, n, base) ((result) = (n) % (base))
632 +
633 +/* Here we define the magic numbers that this dynamic loader should accept */
634 +#define MAGIC1 EM_AVR32
635 +#undef MAGIC2
636 +
637 +/* Used for error messages */
638 +#define ELF_TARGET "AVR32"
639 +
640 +unsigned long _dl_linux_resolver(unsigned long got_offset, unsigned long *got);
641 +
642 +/* 4096 bytes alignment */
643 +#define PAGE_ALIGN 0xfffff000
644 +#define ADDR_ALIGN 0xfff
645 +#define OFFS_ALIGN 0x7ffff000
646 +
647 +#define elf_machine_type_class(type) \
648 + ((type == R_AVR32_JMP_SLOT) * ELF_RTYPE_CLASS_PLT)
649 +
650 +/* AVR32 doesn't need any COPY relocs */
651 +#define DL_NO_COPY_RELOCS
652 +
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)
658 +{
659 + register Elf32_Addr *got asm ("r6");
660 + return *got;
661 +}
662 +
663 +/* Return the run-time load address of the shared object. */
664 +static inline Elf32_Addr
665 +elf_machine_load_address (void)
666 +{
667 + extern void __dl_start asm("_dl_start");
668 + Elf32_Addr got_addr = (Elf32_Addr) &__dl_start;
669 + Elf32_Addr pcrel_addr;
670 +
671 + asm (" lddpc %0, 2f\n"
672 + "1: add %0, pc\n"
673 + " rjmp 3f\n"
674 + " .align 2\n"
675 + "2: .long _dl_start - 1b\n"
676 + "3:\n"
677 + : "=r"(pcrel_addr) : : "cc");
678 +
679 + return pcrel_addr - got_addr;
680 +}
681 +
682 +/*
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).
686 + */
687 +static inline void
688 +elf_machine_relative (Elf32_Addr load_off, const Elf32_Addr rel_addr,
689 + Elf32_Word relative_count)
690 +{
691 + Elf32_Rela *rpnt = (void *)rel_addr;
692 +
693 + do {
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);
698 +}
699 diff --git a/ldso/ldso/avr32/elfinterp.c b/ldso/ldso/avr32/elfinterp.c
700 new file mode 100644
701 index 0000000..196292b
702 --- /dev/null
703 +++ b/ldso/ldso/avr32/elfinterp.c
704 @@ -0,0 +1,191 @@
705 +/*
706 + * AVR32 ELF shared library loader suppport
707 + *
708 + * Copyright (C) 2004-2006 Atmel Corporation
709 + *
710 + * All rights reserved.
711 + *
712 + * Redistribution and use in source and binary forms, with or without
713 + * modification, are permitted provided that the following conditions
714 + * are met:
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.
720 + *
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
731 + * SUCH DAMAGE.
732 + */
733 +
734 +unsigned long _dl_linux_resolver(unsigned long got_offset, unsigned long *got)
735 +{
736 + struct elf_resolve *tpnt = (struct elf_resolve *)got[1];
737 + Elf32_Sym *sym;
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;
744 +
745 +#if 0
746 + local_gotno = tpnt->dynamic_info[DT_AVR32_LOCAL_GOTNO];
747 + gotsym = tpnt->dynamic_info[DT_AVR32_GOTSYM];
748 +
749 + sym = ((Elf32_Sym *)(tpnt->dynamic_info[DT_SYMTAB] + tpnt->loadaddr))
750 + + sym_index;
751 + strtab = (char *)(tpnt->dynamic_info[DT_STRTAB] + tpnt->loadaddr);
752 + symname = strtab + sym->st_name;
753 +
754 +#if 0
755 + new_addr = (unsigned long) _dl_find_hash(strtab + sym->st_name,
756 + tpnt->symbol_scope, tpnt,
757 + resolver);
758 +#endif
759 +
760 + entry = (unsigned long *)(got + local_gotno + sym_index - gotsym);
761 + *entry = new_addr;
762 +#endif
763 +
764 + return new_addr;
765 +}
766 +
767 +static int
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))
772 +{
773 + Elf32_Sym *symtab;
774 + Elf32_Rela *rpnt;
775 + char *strtab;
776 + int i;
777 +
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];
782 +
783 + for (i = 0; i < rel_size; i++, rpnt++) {
784 + int symtab_index, res;
785 +
786 + symtab_index = ELF32_R_SYM(rpnt->r_info);
787 +
788 + debug_sym(symtab, strtab, symtab_index);
789 + debug_reloc(symtab, strtab, rpnt);
790 +
791 + res = reloc_func(tpnt, scope, rpnt, symtab, strtab);
792 +
793 + if (res == 0)
794 + continue;
795 +
796 + _dl_dprintf(2, "\n%s: ", _dl_progname);
797 +
798 + if (symtab_index)
799 + _dl_dprintf(2, "symbol '%s': ",
800 + strtab + symtab[symtab_index].st_name);
801 +
802 + if (res < 0) {
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));
807 +#else
808 + _dl_dprintf(2, "can't handle reloc type %x\n",
809 + reloc_type);
810 +#endif
811 + _dl_exit(-res);
812 + } else {
813 + _dl_dprintf(2, "can't resolve symbol\n");
814 + return res;
815 + }
816 + }
817 +
818 + return 0;
819 +}
820 +
821 +static int _dl_do_reloc(struct elf_resolve *tpnt, struct dyn_elf *scope,
822 + Elf32_Rela *rpnt, Elf32_Sym *symtab, char *strtab)
823 +{
824 + int reloc_type;
825 + int symtab_index;
826 + char *symname;
827 + unsigned long *reloc_addr;
828 + unsigned long symbol_addr;
829 +#if defined(__SUPPORT_LD_DEBUG__)
830 + unsigned long old_val;
831 +#endif
832 +
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);
836 + symbol_addr = 0;
837 + symname = strtab + symtab[symtab_index].st_name;
838 +
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));
844 +
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);
850 + return 0;
851 + }
852 + }
853 +
854 +#if defined(__SUPPORT_LD_DEBUG__)
855 + old_val = *reloc_addr;
856 +#endif
857 + switch (reloc_type) {
858 + case R_AVR32_NONE:
859 + break;
860 + case R_AVR32_GLOB_DAT:
861 + case R_AVR32_JMP_SLOT:
862 + *reloc_addr = symbol_addr + rpnt->r_addend;
863 + break;
864 + case R_AVR32_RELATIVE:
865 + *reloc_addr = (unsigned long)tpnt->loadaddr
866 + + rpnt->r_addend;
867 + break;
868 + default:
869 + return -1;
870 + }
871 +
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);
876 +#endif
877 +
878 + return 0;
879 +}
880 +
881 +void _dl_parse_lazy_relocation_information(struct dyn_elf *rpnt,
882 + unsigned long rel_addr,
883 + unsigned long rel_size)
884 +{
885 + /* TODO: Might want to support this in order to get faster
886 + * startup times... */
887 +}
888 +
889 +int _dl_parse_relocation_information(struct dyn_elf *rpnt,
890 + unsigned long rel_addr,
891 + unsigned long rel_size)
892 +{
893 + return _dl_parse(rpnt->dyn, rpnt->dyn->symbol_scope, rel_addr, rel_size,
894 + _dl_do_reloc);
895 +}
896 diff --git a/ldso/ldso/avr32/resolve.S b/ldso/ldso/avr32/resolve.S
897 new file mode 100644
898 index 0000000..e3cb7f4
899 --- /dev/null
900 +++ b/ldso/ldso/avr32/resolve.S
901 @@ -0,0 +1,28 @@
902 +/*
903 + * Linux dynamic resolving code for AVR32. Fixes up the GOT entry as
904 + * indicated in register r12 and jumps to the resolved address.
905 + *
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.
909 + *
910 + * Copyright (C) 2004-2007 Atmel Corporation
911 + */
912 +
913 +#define ip r5
914 +
915 + .text
916 + .global _dl_linux_resolve
917 + .type _dl_linux_resolve,@function
918 +_dl_linux_resolve:
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
923 + mov r11, r8
924 + sub r12, ip, r8
925 + rcall _dl_linux_resolver
926 + mov ip, r12
927 + popm r8-r12,lr
928 + mov pc, ip
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);
937
938 -#else
939 +#endif
940 +
941 +#if !defined(PERFORM_BOOTSTRAP_GOT) || defined(__avr32__)
942
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,
950 *result=result_buf;
951 ret=NETDB_SUCCESS;
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");
956 addr_list6[0] = in6;
957 addr_list6[1] = 0;
958 @@ -1658,8 +1658,8 @@ int attribute_hidden __read_etc_hosts_r(FILE * fp, const char * name, int type,
959 } else {
960 DPRINTF("Error\n");
961 ret=TRY_AGAIN;
962 - break; /* bad ip address */
963 - }
964 + continue; /* bad ip address, keep searching */
965 + }
966
967 if (action!=GETHOSTENT) {
968 fclose(fp);
969 diff --git a/libc/string/avr32/Makefile b/libc/string/avr32/Makefile
970 new file mode 100644
971 index 0000000..e19e9d9
972 --- /dev/null
973 +++ b/libc/string/avr32/Makefile
974 @@ -0,0 +1,26 @@
975 +# Makefile for uClibc
976 +#
977 +# Copyright (C) 2000-2003 Erik Andersen <andersen@uclibc.org>
978 +#
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
982 +# later version.
983 +#
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
987 +# details.
988 +#
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
992 +
993 +top_srcdir := ../../../
994 +top_builddir := ../../../
995 +
996 +all: objs
997 +
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
1004 --- /dev/null
1005 +++ b/libc/string/avr32/bcopy.S
1006 @@ -0,0 +1,26 @@
1007 +/*
1008 + * Copyright (C) 2004-2007 Atmel Corporation
1009 + *
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.
1013 + */
1014 +
1015 +#include <features.h>
1016 +
1017 +#ifdef __UCLIBC_SUSV3_LEGACY__
1018 +
1019 + .text
1020 + .global bcopy
1021 + .type bcopy, @function
1022 + .align 1
1023 +bcopy:
1024 + /* Swap the first two arguments */
1025 + eor r11, r12
1026 + eor r12, r11
1027 + eor r11, r12
1028 + rjmp __GI_memmove
1029 +
1030 + .size bcopy, . - bcopy
1031 +
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
1036 --- /dev/null
1037 +++ b/libc/string/avr32/bzero.S
1038 @@ -0,0 +1,22 @@
1039 +/*
1040 + * Copyright (C) 2004-2007 Atmel Corporation
1041 + *
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.
1045 + */
1046 +
1047 +#ifdef __UCLIBC_SUSV3_LEGACY__
1048 +
1049 + .text
1050 + .global bzero
1051 + .type bzero, @function
1052 + .align 1
1053 +bzero:
1054 + mov r10, r11
1055 + mov r11, 0
1056 + rjmp __memset
1057 +
1058 + .size bzero, . - bzero
1059 +
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
1064 --- /dev/null
1065 +++ b/libc/string/avr32/memcmp.S
1066 @@ -0,0 +1,61 @@
1067 +/*
1068 + * Copyright (C) 2004-2007 Atmel Corporation
1069 + *
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.
1073 + */
1074 +
1075 +#include <features.h>
1076 +
1077 +#define s1 r12
1078 +#define s2 r11
1079 +#define len r10
1080 +
1081 + .text
1082 + .global memcmp
1083 + .type memcmp, @function
1084 + .align 1
1085 +memcmp:
1086 + sub len, 4
1087 + brlt .Lless_than_4
1088 +
1089 +1: ld.w r8, s1++
1090 + ld.w r9, s2++
1091 + cp.w r8, r9
1092 + brne .Lfound_word
1093 + sub len, 4
1094 + brge 1b
1095 +
1096 +.Lless_than_4:
1097 + sub len, -4
1098 + reteq 0
1099 +
1100 +1: ld.ub r8, s1++
1101 + ld.ub r9, s2++
1102 + sub r8, r9
1103 + retne r8
1104 + sub len, 1
1105 + brgt 1b
1106 +
1107 + retal 0
1108 +
1109 +.Lfound_word:
1110 + mov len, 4
1111 +
1112 +2: bfextu r11, r9, 24, 8
1113 + bfextu r12, r8, 24, 8
1114 + sub r12, r11
1115 + retne r12
1116 + lsl r8, 8
1117 + lsl r9, 8
1118 + sub len, 1
1119 + brne 2b
1120 + retal r12
1121 +
1122 + .size memcmp, . - memcmp
1123 +
1124 +libc_hidden_def(memcmp)
1125 +#ifdef __UCLIBC_SUSV3_LEGACY__
1126 +strong_alias(memcmp,bcmp)
1127 +#endif
1128 diff --git a/libc/string/avr32/memcpy.S b/libc/string/avr32/memcpy.S
1129 new file mode 100644
1130 index 0000000..bf091ab
1131 --- /dev/null
1132 +++ b/libc/string/avr32/memcpy.S
1133 @@ -0,0 +1,111 @@
1134 +/*
1135 + * Copyright (C) 2004-2007 Atmel Corporation
1136 + *
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.
1140 + */
1141 +
1142 +/* Don't use r12 as dst since we must return it unmodified */
1143 +#define dst r9
1144 +#define src r11
1145 +#define len r10
1146 +
1147 + .text
1148 + .global memcpy
1149 + .type memcpy, @function
1150 +memcpy:
1151 + pref src[0]
1152 + mov dst, r12
1153 +
1154 + /* If we have less than 32 bytes, don't do anything fancy */
1155 + cp.w len, 32
1156 + brge .Lmore_than_31
1157 +
1158 + sub len, 1
1159 + retlt r12
1160 +1: ld.ub r8, src++
1161 + st.b dst++, r8
1162 + sub len, 1
1163 + brge 1b
1164 + retal r12
1165 +
1166 +.Lmore_than_31:
1167 + pushm r0-r7, lr
1168 +
1169 + /* Check alignment */
1170 + mov r8, src
1171 + andl r8, 31, COH
1172 + brne .Lunaligned_src
1173 + mov r8, dst
1174 + andl r8, 3, COH
1175 + brne .Lunaligned_dst
1176 +
1177 +.Laligned_copy:
1178 + sub len, 32
1179 + brlt .Lless_than_32
1180 +
1181 +1: /* Copy 32 bytes at a time */
1182 + ldm src, r0-r7
1183 + sub src, -32
1184 + stm dst, r0-r7
1185 + sub dst, -32
1186 + sub len, 32
1187 + brge 1b
1188 +
1189 +.Lless_than_32:
1190 + /* Copy 16 more bytes if possible */
1191 + sub len, -16
1192 + brlt .Lless_than_16
1193 + ldm src, r0-r3
1194 + sub src, -16
1195 + sub len, 16
1196 + stm dst, r0-r3
1197 + sub dst, -16
1198 +
1199 +.Lless_than_16:
1200 + /* Do the remaining as byte copies */
1201 + neg len
1202 + add pc, pc, len << 2
1203 + .rept 15
1204 + ld.ub r0, src++
1205 + st.b dst++, r0
1206 + .endr
1207 +
1208 + popm r0-r7, pc
1209 +
1210 +.Lunaligned_src:
1211 + /* Make src cacheline-aligned. r8 = (src & 31) */
1212 + rsub r8, r8, 32
1213 + sub len, r8
1214 +1: ld.ub r0, src++
1215 + st.b dst++, r0
1216 + sub r8, 1
1217 + brne 1b
1218 +
1219 + /* If dst is word-aligned, we're ready to go */
1220 + pref src[0]
1221 + mov r8, 3
1222 + tst dst, r8
1223 + breq .Laligned_copy
1224 +
1225 +.Lunaligned_dst:
1226 + /* src is aligned, but dst is not. Expect bad performance */
1227 + sub len, 4
1228 + brlt 2f
1229 +1: ld.w r0, src++
1230 + st.w dst++, r0
1231 + sub len, 4
1232 + brge 1b
1233 +
1234 +2: neg len
1235 + add pc, pc, len << 2
1236 + .rept 3
1237 + ld.ub r0, src++
1238 + st.b dst++, r0
1239 + .endr
1240 +
1241 + popm r0-r7, pc
1242 + .size memcpy, . - memcpy
1243 +
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
1248 --- /dev/null
1249 +++ b/libc/string/avr32/memmove.S
1250 @@ -0,0 +1,116 @@
1251 +/*
1252 + * Copyright (C) 2004-2007 Atmel Corporation
1253 + *
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.
1257 + */
1258 +
1259 +#define dst r12
1260 +#define src r11
1261 +#define len r10
1262 +
1263 + .text
1264 + .global memmove
1265 + .type memmove, @function
1266 +memmove:
1267 + cp.w src, dst
1268 + brge __GI_memcpy
1269 +
1270 + add dst, len
1271 + add src, len
1272 + pref src[-1]
1273 +
1274 + /*
1275 + * The rest is basically the same as in memcpy.S except that
1276 + * the direction is reversed.
1277 + */
1278 + cp.w len, 32
1279 + brge .Lmore_than_31
1280 +
1281 + sub len, 1
1282 + retlt r12
1283 +1: ld.ub r8, --src
1284 + st.b --dst, r8
1285 + sub len, 1
1286 + brge 1b
1287 + retal r12
1288 +
1289 +.Lmore_than_31:
1290 + pushm r0-r7, lr
1291 +
1292 + /* Check alignment */
1293 + mov r8, src
1294 + andl r8, 31, COH
1295 + brne .Lunaligned_src
1296 + mov r8, r12
1297 + andl r8, 3, COH
1298 + brne .Lunaligned_dst
1299 +
1300 +.Laligned_copy:
1301 + sub len, 32
1302 + brlt .Lless_than_32
1303 +
1304 +1: /* Copy 32 bytes at a time */
1305 + sub src, 32
1306 + ldm src, r0-r7
1307 + sub dst, 32
1308 + sub len, 32
1309 + stm dst, r0-r7
1310 + brge 1b
1311 +
1312 +.Lless_than_32:
1313 + /* Copy 16 more bytes if possible */
1314 + sub len, -16
1315 + brlt .Lless_than_16
1316 + sub src, 16
1317 + ldm src, r0-r3
1318 + sub dst, 16
1319 + sub len, 16
1320 + stm dst, r0-r3
1321 +
1322 +.Lless_than_16:
1323 + /* Do the remaining as byte copies */
1324 + sub len, -16
1325 + breq 2f
1326 +1: ld.ub r0, --src
1327 + st.b --dst, r0
1328 + sub len, 1
1329 + brne 1b
1330 +
1331 +2: popm r0-r7, pc
1332 +
1333 +.Lunaligned_src:
1334 + /* Make src cacheline-aligned. r8 = (src & 31) */
1335 + sub len, r8
1336 +1: ld.ub r0, --src
1337 + st.b --dst, r0
1338 + sub r8, 1
1339 + brne 1b
1340 +
1341 + /* If dst is word-aligned, we're ready to go */
1342 + pref src[-4]
1343 + mov r8, 3
1344 + tst dst, r8
1345 + breq .Laligned_copy
1346 +
1347 +.Lunaligned_dst:
1348 + /* src is aligned, but dst is not. Expect bad performance */
1349 + sub len, 4
1350 + brlt 2f
1351 +1: ld.w r0, --src
1352 + st.w --dst, r0
1353 + sub len, 4
1354 + brge 1b
1355 +
1356 +2: neg len
1357 + add pc, pc, len << 2
1358 + .rept 3
1359 + ld.ub r0, --src
1360 + st.b --dst, r0
1361 + .endr
1362 +
1363 + popm r0-r7, pc
1364 + .size memmove, . - memmove
1365 +
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
1370 --- /dev/null
1371 +++ b/libc/string/avr32/memset.S
1372 @@ -0,0 +1,70 @@
1373 +/*
1374 + * Copyright (C) 2004-2007 Atmel Corporation
1375 + *
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.
1379 + */
1380 +
1381 +#include <features.h>
1382 +
1383 +#define s r12
1384 +#define c r11
1385 +#define n r10
1386 +
1387 + .text
1388 + .global memset
1389 + .type memset, @function
1390 +
1391 + .global __memset
1392 + .hidden __memset
1393 + .type __memset, @function
1394 +
1395 + .align 1
1396 +memset:
1397 +__memset:
1398 + cp.w n, 32
1399 + mov r9, s
1400 + brge .Llarge_memset
1401 +
1402 + sub n, 1
1403 + retlt s
1404 +1: st.b s++, c
1405 + sub n, 1
1406 + brge 1b
1407 +
1408 + retal r9
1409 +
1410 +.Llarge_memset:
1411 + mov r8, r11
1412 + mov r11, 3
1413 + bfins r8, r8, 8, 8
1414 + bfins r8, r8, 16, 16
1415 + tst s, r11
1416 + breq 2f
1417 +
1418 +1: st.b s++, r8
1419 + sub n, 1
1420 + tst s, r11
1421 + brne 1b
1422 +
1423 +2: mov r11, r9
1424 + mov r9, r8
1425 + sub n, 8
1426 +
1427 +3: st.d s++, r8
1428 + sub n, 8
1429 + brge 3b
1430 +
1431 + /* If we are done, n == -8 and we'll skip all st.b insns below */
1432 + neg n
1433 + lsl n, 1
1434 + add pc, n
1435 + .rept 7
1436 + st.b s++, r8
1437 + .endr
1438 + retal r11
1439 +
1440 + .size memset, . - memset
1441 +
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
1446 --- /dev/null
1447 +++ b/libc/string/avr32/strcmp.S
1448 @@ -0,0 +1,91 @@
1449 +/*
1450 + * Copyright (C) 2004-2007 Atmel Corporation
1451 + *
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.
1455 + */
1456 +
1457 +#include <features.h>
1458 +
1459 +#define s1 r12
1460 +#define s2 r11
1461 +#define len r10
1462 +
1463 + .text
1464 + .global strcmp
1465 + .type strcmp, @function
1466 + .align 1
1467 +strcmp:
1468 + mov r8, 3
1469 + tst s1, r8
1470 + brne .Lunaligned_s1
1471 + tst s2, r8
1472 + brne .Lunaligned_s2
1473 +
1474 +1: ld.w r8, s1++
1475 + ld.w r9, s2++
1476 + cp.w r8, r9
1477 + brne 2f
1478 + tnbz r8
1479 + brne 1b
1480 + retal 0
1481 +
1482 +2: bfextu r12, r8, 24, 8
1483 + bfextu r11, r9, 24, 8
1484 + sub r12, r11
1485 + retne r12
1486 + cp.w r11, 0
1487 + reteq 0
1488 + bfextu r12, r8, 16, 8
1489 + bfextu r11, r9, 16, 8
1490 + sub r12, r11
1491 + retne r12
1492 + cp.w r11, 0
1493 + reteq 0
1494 + bfextu r12, r8, 8, 8
1495 + bfextu r11, r9, 8, 8
1496 + sub r12, r11
1497 + retne r12
1498 + cp.w r11, 0
1499 + reteq 0
1500 + bfextu r12, r8, 0, 8
1501 + bfextu r11, r9, 0, 8
1502 + sub r12, r11
1503 + retal r12
1504 +
1505 +.Lunaligned_s1:
1506 +3: tst s1, r8
1507 + breq 4f
1508 + ld.ub r10, s1++
1509 + ld.ub r9, s2++
1510 + sub r10, r9
1511 + retne r10
1512 + cp.w r9, 0
1513 + brne 3b
1514 + retal r10
1515 +
1516 +4: tst s2, r8
1517 + breq 1b
1518 +
1519 +.Lunaligned_s2:
1520 + /*
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...
1524 + */
1525 +1: ld.ub r8, s1++
1526 + ld.ub r9, s2++
1527 + sub r8, r9
1528 + retne r8
1529 + cp.w r9, 0
1530 + brne 1b
1531 + retal 0
1532 +
1533 + .size strcmp, . - strcmp
1534 +
1535 +libc_hidden_def(strcmp)
1536 +#ifndef __UCLIBC_HAS_LOCALE__
1537 +strong_alias(strcmp, strcoll)
1538 +libc_hidden_def(strcoll)
1539 +#endif
1540 diff --git a/libc/string/avr32/strlen.S b/libc/string/avr32/strlen.S
1541 new file mode 100644
1542 index 0000000..5223e53
1543 --- /dev/null
1544 +++ b/libc/string/avr32/strlen.S
1545 @@ -0,0 +1,62 @@
1546 +/*
1547 + * Copyright (C) 2004-2007 Atmel Corporation
1548 + *
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.
1552 + */
1553 +
1554 +#include <features.h>
1555 +
1556 +#define str r12
1557 +
1558 + .text
1559 + .global strlen
1560 + .type strlen, @function
1561 +strlen:
1562 + mov r11, r12
1563 +
1564 + mov r9, str
1565 + andl r9, 3, COH
1566 + brne .Lunaligned_str
1567 +
1568 +1: ld.w r8, str++
1569 + tnbz r8
1570 + brne 1b
1571 +
1572 + sub r12, r11
1573 + bfextu r9, r8, 24, 8
1574 + cp.w r9, 0
1575 + subeq r12, 4
1576 + reteq r12
1577 + bfextu r9, r8, 16, 8
1578 + cp.w r9, 0
1579 + subeq r12, 3
1580 + reteq r12
1581 + bfextu r9, r8, 8, 8
1582 + cp.w r9, 0
1583 + subeq r12, 2
1584 + reteq r12
1585 + sub r12, 1
1586 + retal r12
1587 +
1588 +.Lunaligned_str:
1589 + add pc, pc, r9 << 3
1590 + sub r0, r0, 0 /* 4-byte nop */
1591 + ld.ub r8, str++
1592 + sub r8, r8, 0
1593 + breq 1f
1594 + ld.ub r8, str++
1595 + sub r8, r8, 0
1596 + breq 1f
1597 + ld.ub r8, str++
1598 + sub r8, r8, 0
1599 + brne 1b
1600 +
1601 +1: sub r12, 1
1602 + sub r12, r11
1603 + retal r12
1604 +
1605 + .size strlen, . - strlen
1606 +
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
1611 --- /dev/null
1612 +++ b/libc/sysdeps/linux/avr32/Makefile
1613 @@ -0,0 +1,25 @@
1614 +# Makefile for uClibc
1615 +#
1616 +# Copyright (C) 2000-2003 Erik Andersen <andersen@uclibc.org>
1617 +#
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
1621 +# later version.
1622 +#
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
1626 +# details.
1627 +#
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
1631 +
1632 +top_srcdir=../../../../
1633 +top_builddir=../../../../
1634 +all: objs
1635 +
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
1642 --- /dev/null
1643 +++ b/libc/sysdeps/linux/avr32/Makefile.arch
1644 @@ -0,0 +1,13 @@
1645 +# Makefile for uClibc
1646 +#
1647 +# Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
1648 +#
1649 +# Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
1650 +#
1651 +
1652 +CSRC := brk.c clone.c mmap.c sigaction.c
1653 +
1654 +SSRC := __longjmp.S setjmp.S bsd-setjmp.S bsd-_setjmp.S \
1655 + sigrestorer.S syscall.S vfork.S
1656 +
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
1661 --- /dev/null
1662 +++ b/libc/sysdeps/linux/avr32/__longjmp.S
1663 @@ -0,0 +1,21 @@
1664 +/*
1665 + * Copyright (C) 2004-2007 Atmel Corporation
1666 + *
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.
1670 + */
1671 +
1672 + .global __longjmp
1673 + .type __longjmp,"function"
1674 + .align 1
1675 +__longjmp:
1676 + ldm r12++, r0-r8,sp,lr
1677 + mustr r8 /* restore status register (lower half) */
1678 + cp r11, 0 /* can't return zero */
1679 + frs
1680 + moveq r11, 1
1681 + retal r11
1682 + .size __longjmp, . - __longjmp
1683 +
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
1688 --- /dev/null
1689 +++ b/libc/sysdeps/linux/avr32/bits/atomic.h
1690 @@ -0,0 +1,120 @@
1691 +/*
1692 + * Copyright (C) 2007 Atmel Corporation
1693 + *
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.
1697 + */
1698 +#ifndef _AVR32_BITS_ATOMIC_H
1699 +#define _AVR32_BITS_ATOMIC_H 1
1700 +
1701 +#include <inttypes.h>
1702 +
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;
1707 +
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;
1712 +
1713 +#define __arch_compare_and_exchange_val_8_acq(mem, newval, oldval) \
1714 + (abort(), 0)
1715 +
1716 +#define __arch_compare_and_exchange_val_16_acq(mem, newval, oldval) \
1717 + (abort(), 0)
1718 +
1719 +#define __arch_compare_and_exchange_val_32_acq(mem, newval, oldval) \
1720 + ({ \
1721 + __typeof__(*(mem)) __prev; \
1722 + __asm__ __volatile__( \
1723 + "/* __arch_compare_and_exchange_val_32_acq */\n" \
1724 + "1: ssrf 5\n" \
1725 + " ld.w %[result], %[m]\n" \
1726 + " cp.w %[result], %[old]\n" \
1727 + " brne 2f\n" \
1728 + " stcond %[m], %[new]\n" \
1729 + " brne 1b\n" \
1730 + "2:" \
1731 + : [result] "=&r"(__result), [m] "=m"(*(mem)) \
1732 + : "m"(*(mem)), [old] "ir"(oldval), \
1733 + [new] "r"(newval) \
1734 + : "memory", "cc"); \
1735 + __prev; \
1736 + })
1737 +
1738 +#define __arch_compare_and_exchange_val_64_acq(mem, newval, oldval) \
1739 + (abort(), 0)
1740 +
1741 +#define __arch_exchange_32_acq(mem, newval) \
1742 + ({ \
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) \
1749 + : "memory"); \
1750 + __oldval; \
1751 + })
1752 +
1753 +#define __arch_atomic_exchange_and_add_32(mem, value) \
1754 + ({ \
1755 + __typeof__(*(mem)) __oldval, __tmp; \
1756 + __asm__ __volatile__( \
1757 + "/* __arch_atomic_exchange_and_add_32 */\n" \
1758 + "1: ssrf 5\n" \
1759 + " ld.w %[old], %[m]\n" \
1760 + " add %[tmp], %[old], %[val]\n" \
1761 + " stcond %[m], %[tmp]\n" \
1762 + " brne 1b" \
1763 + : [old] "=&r"(__oldval), [tmp] "=&r"(__tmp), \
1764 + [m] "=m"(*(mem)) \
1765 + : "m"(*(mem)), [val] "r"(value) \
1766 + : "memory", "cc"); \
1767 + __oldval; \
1768 + })
1769 +
1770 +#define __arch_atomic_decrement_if_positive_32(mem) \
1771 + ({ \
1772 + __typeof__(*(mem)) __oldval, __tmp; \
1773 + __asm__ __volatile__( \
1774 + "/* __arch_atomic_decrement_if_positive_32 */\n" \
1775 + "1: ssrf 5\n" \
1776 + " ld.w %[old], %[m]\n" \
1777 + " sub %[tmp], %[old], 1\n" \
1778 + " brlt 2f\n" \
1779 + " stcond %[m], %[tmp]\n" \
1780 + " brne 1b" \
1781 + "2:" \
1782 + : [old] "=&r"(__oldval), [tmp] "=&r"(__tmp), \
1783 + [m] "=m"(*(mem)) \
1784 + : "m"(*(mem)) \
1785 + : "memory", "cc"); \
1786 + __oldval; \
1787 + })
1788 +
1789 +#define atomic_exchange_acq(mem, newval) \
1790 + ({ \
1791 + if (sizeof(*(mem)) != 4) \
1792 + abort(); \
1793 + __arch_exchange_32_acq(mem, newval); \
1794 + })
1795 +
1796 +#define atomic_exchange_and_add(mem, newval) \
1797 + ({ \
1798 + if (sizeof(*(mem)) != 4) \
1799 + abort(); \
1800 + __arch_atomic_exchange_and_add_32(mem, newval); \
1801 + })
1802 +
1803 +#define atomic_decrement_if_positive(mem) \
1804 + ({ \
1805 + if (sizeof(*(mem)) != 4) \
1806 + abort(); \
1807 + __arch_atomic_decrement_if_positive_32(mem); \
1808 + })
1809 +
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
1814 --- /dev/null
1815 +++ b/libc/sysdeps/linux/avr32/bits/byteswap.h
1816 @@ -0,0 +1,70 @@
1817 +/*
1818 + * Copyright (C) 2005 Atmel Corporation
1819 + *
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.
1823 + */
1824 +
1825 +#if !defined _BYTESWAP_H && !defined _NETINET_IN_H
1826 +# error "Never use <bits/byteswap.h> directly; include <byteswap.h> instead."
1827 +#endif
1828 +
1829 +#ifndef _BITS_BYTESWAP_H
1830 +#define _BITS_BYTESWAP_H 1
1831 +
1832 +/* Swap bytes in 16 bit value. */
1833 +#if defined __GNUC__
1834 +# define __bswap_16(x) (__extension__ __builtin_bswap_16(x))
1835 +#else
1836 +/* This is better than nothing. */
1837 +static __inline unsigned short int
1838 +__bswap_16 (unsigned short int __bsx)
1839 +{
1840 + return ((((__bsx) >> 8) & 0xff) | (((__bsx) & 0xff) << 8));
1841 +}
1842 +#endif
1843 +
1844 +/* Swap bytes in 32 bit value. */
1845 +#if defined __GNUC__
1846 +# define __bswap_32(x) (__extension__ __builtin_bswap_32(x))
1847 +#else
1848 +static __inline unsigned int
1849 +__bswap_32 (unsigned int __bsx)
1850 +{
1851 + return ((((__bsx) & 0xff000000) >> 24) | (((__bsx) & 0x00ff0000) >> 8) |
1852 + (((__bsx) & 0x0000ff00) << 8) | (((__bsx) & 0x000000ff) << 24));
1853 +}
1854 +#endif
1855 +
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))
1867 +
1868 +# define __bswap_64(x) \
1869 + (__extension__ \
1870 + ({ \
1871 + union { \
1872 + __extension__ unsigned long long int __ll; \
1873 + unsigned int __l[2]; \
1874 + } __w, __r; \
1875 + if (__builtin_constant_p(x)) \
1876 + __r.__ll = __bswap_constant_64(x); \
1877 + else { \
1878 + __w.__ll = (x); \
1879 + __r.__l[0] = __bswap_32(__w.__l[1]); \
1880 + __r.__l[1] = __bswap_32(__w.__l[0]); \
1881 + } \
1882 + __r.__ll; \
1883 + }))
1884 +#endif
1885 +
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
1890 --- /dev/null
1891 +++ b/libc/sysdeps/linux/avr32/bits/endian.h
1892 @@ -0,0 +1,7 @@
1893 +/* AVR32 is big-endian */
1894 +
1895 +#ifndef _ENDIAN_H
1896 +# error "Never use <bits/endian.h> directly; include <endian.h> instead."
1897 +#endif
1898 +
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
1903 --- /dev/null
1904 +++ b/libc/sysdeps/linux/avr32/bits/fcntl.h
1905 @@ -0,0 +1,165 @@
1906 +#ifndef _FCNTL_H
1907 +# error "Never use <bits/fcntl.h> directly; include <fcntl.h> instead."
1908 +#endif
1909 +
1910 +#include <sys/types.h>
1911 +
1912 +/*
1913 + * open/fcntl - O_SYNC is only implemented on blocks devices and on files
1914 + * located on an ext2 file system
1915 + */
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
1929 +
1930 +#ifdef __USE_GNU
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 */
1935 +#endif
1936 +
1937 +#ifdef __USE_LARGEFILE64
1938 +# define O_LARGEFILE 00100000
1939 +#endif
1940 +
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. */
1947 +#endif
1948 +
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 */
1954 +
1955 +#ifndef __USE_FILE_OFFSET64
1956 +# define F_GETLK 5
1957 +# define F_SETLK 6
1958 +# define F_SETLKW 7
1959 +#else
1960 +# define F_GETLK F_GETLK64
1961 +# define F_SETLK F_SETLK64
1962 +# define F_SETLKW F_SETLKW64
1963 +#endif
1964 +#define F_GETLK64 12 /* using 'struct flock64' */
1965 +#define F_SETLK64 13
1966 +#define F_SETLKW64 14
1967 +
1968 +#if defined __USE_BSD || defined __USE_XOPEN2K
1969 +# define F_SETOWN 8 /* for sockets. */
1970 +# define F_GETOWN 9 /* for sockets. */
1971 +#endif
1972 +
1973 +#ifdef __USE_GNU
1974 +# define F_SETSIG 10 /* for sockets. */
1975 +# define F_GETSIG 11 /* for sockets. */
1976 +#endif
1977 +
1978 +#ifdef __USE_GNU
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. */
1982 +#endif
1983 +
1984 +/* for F_[GET|SET]FL */
1985 +#define FD_CLOEXEC 1 /* actually anything with low bit set goes */
1986 +
1987 +/* for posix fcntl() and lockf() */
1988 +#define F_RDLCK 0
1989 +#define F_WRLCK 1
1990 +#define F_UNLCK 2
1991 +
1992 +/* for old implementation of bsd flock () */
1993 +#define F_EXLCK 4 /* or 3 */
1994 +#define F_SHLCK 8 /* or 4 */
1995 +
1996 +/* for leases */
1997 +#define F_INPROGRESS 16
1998 +
1999 +#ifdef __USE_BSD
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
2004 + blocking */
2005 +# define LOCK_UN 8 /* remove lock */
2006 +#endif
2007 +
2008 +#ifdef __USE_GNU
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 */
2016 +#endif
2017 +
2018 +#ifdef __USE_GNU
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. */
2027 +#endif
2028 +
2029 +struct flock {
2030 + short l_type;
2031 + short l_whence;
2032 +#ifndef __USE_FILE_OFFSET64
2033 + __off_t l_start;
2034 + __off_t l_len;
2035 +#else
2036 + __off64_t l_start;
2037 + __off64_t l_len;
2038 +#endif
2039 + __pid_t l_pid;
2040 +};
2041 +
2042 +#ifdef __USE_LARGEFILE64
2043 +struct flock64 {
2044 + short l_type;
2045 + short l_whence;
2046 + __off64_t l_start;
2047 + __off64_t l_len;
2048 + __pid_t l_pid;
2049 +};
2050 +#endif
2051 +
2052 +/* Define some more compatibility macros to be backward compatible with
2053 + * BSD systems which did not managed to hide these kernel macros. */
2054 +#ifdef __USE_BSD
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. */
2061 +
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. */
2070 +#endif
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
2074 --- /dev/null
2075 +++ b/libc/sysdeps/linux/avr32/bits/kernel_stat.h
2076 @@ -0,0 +1,67 @@
2077 +#ifndef _BITS_STAT_STRUCT_H
2078 +#define _BITS_STAT_STRUCT_H
2079 +
2080 +#ifndef _LIBC
2081 +#error bits/kernel_stat.h is for internal uClibc use only!
2082 +#endif
2083 +
2084 +/*
2085 + * This file provides struct stat, taken from kernel 2.6.4. Verified
2086 + * to match kernel 2.6.22.
2087 + */
2088 +
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;
2108 +};
2109 +
2110 +#define STAT_HAVE_NSEC 1
2111 +
2112 +struct kernel_stat64 {
2113 + unsigned long long st_dev;
2114 +
2115 + unsigned long long st_ino;
2116 + unsigned int st_mode;
2117 + unsigned int st_nlink;
2118 +
2119 + unsigned long st_uid;
2120 + unsigned long st_gid;
2121 +
2122 + unsigned long long st_rdev;
2123 +
2124 + long long st_size;
2125 + unsigned long __pad1;
2126 + unsigned long st_blksize;
2127 +
2128 + unsigned long long st_blocks;
2129 +
2130 + unsigned long st_atime;
2131 + unsigned long st_atime_nsec;
2132 +
2133 + unsigned long st_mtime;
2134 + unsigned long st_mtime_nsec;
2135 +
2136 + unsigned long st_ctime;
2137 + unsigned long st_ctime_nsec;
2138 +
2139 + unsigned long __unused1;
2140 + unsigned long __unused2;
2141 +};
2142 +
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
2147 --- /dev/null
2148 +++ b/libc/sysdeps/linux/avr32/bits/kernel_types.h
2149 @@ -0,0 +1,55 @@
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.
2154 + * -Erik
2155 + */
2156 +#ifndef __ASM_AVR32_POSIX_TYPES_H
2157 +#define __ASM_AVR32_POSIX_TYPES_H
2158 +
2159 +/*
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.
2163 + */
2164 +
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;
2191 +
2192 +#ifdef __GNUC__
2193 +typedef long long __kernel_loff_t;
2194 +#endif
2195 +
2196 +typedef struct {
2197 +#if defined(__USE_ALL)
2198 + int val[2];
2199 +#else
2200 + int __val[2];
2201 +#endif
2202 +} __kernel_fsid_t;
2203 +
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
2208 --- /dev/null
2209 +++ b/libc/sysdeps/linux/avr32/bits/mman.h
2210 @@ -0,0 +1,103 @@
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.
2214 +
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.
2219 +
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.
2224 +
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. */
2229 +
2230 +#ifndef _SYS_MMAN_H
2231 +# error "Never include this file directly. Use <sys/mman.h> instead"
2232 +#endif
2233 +
2234 +/* The following definitions basically come from the kernel headers.
2235 + But the kernel header is not namespace clean. */
2236 +
2237 +
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. */
2242 +
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). */
2251 +
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. */
2255 +#ifdef __USE_MISC
2256 +# define MAP_TYPE 0x0f /* Mask for type of mapping. */
2257 +#endif
2258 +
2259 +/* Other flags. */
2260 +#define MAP_FIXED 0x10 /* Interpret addr exactly. */
2261 +#ifdef __USE_MISC
2262 +# define MAP_FILE 0
2263 +# define MAP_ANONYMOUS 0x20 /* Don't use a file. */
2264 +# define MAP_ANON MAP_ANONYMOUS
2265 +#endif
2266 +
2267 +/* These are Linux-specific. */
2268 +#ifdef __USE_MISC
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 */
2276 +#endif
2277 +
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. */
2282 +
2283 +/* Flags for `mlockall'. */
2284 +#define MCL_CURRENT 1 /* Lock all currently mapped pages. */
2285 +#define MCL_FUTURE 2 /* Lock all additions to address
2286 + space. */
2287 +
2288 +/* Flags for `mremap'. */
2289 +#ifdef __USE_GNU
2290 +# define MREMAP_MAYMOVE 1
2291 +# define MREMAP_FIXED 2
2292 +#endif
2293 +
2294 +/* Advise to `madvise'. */
2295 +#ifdef __USE_BSD
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. */
2304 +#endif
2305 +
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. */
2313 +#endif
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
2317 --- /dev/null
2318 +++ b/libc/sysdeps/linux/avr32/bits/setjmp.h
2319 @@ -0,0 +1,30 @@
2320 +/*
2321 + * Copyright (C) 2004-2005 Atmel Corporation
2322 + *
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.
2326 + */
2327 +#ifndef _BITS_SETJMP_H
2328 +#define _BITS_SETJMP_H 1
2329 +
2330 +#if !defined _SETJMP_H && !defined _PTHREAD_H
2331 +# error "Never include <bits/setjmp.h> directly; use <setjmp.h> instead."
2332 +#endif
2333 +
2334 +#ifndef _ASM
2335 +/*
2336 + * The jump buffer contains r0-r7, sr, sp and lr. Other registers are
2337 + * not saved.
2338 + */
2339 +typedef int __jmp_buf[11];
2340 +#endif
2341 +
2342 +#define __JMP_BUF_SP 4
2343 +
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]))
2348 +
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
2353 --- /dev/null
2354 +++ b/libc/sysdeps/linux/avr32/bits/stackinfo.h
2355 @@ -0,0 +1,28 @@
2356 +/* Copyright (C) 1999 Free Software Foundation, Inc.
2357 + This file is part of the GNU C Library.
2358 +
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.
2363 +
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.
2368 +
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. */
2373 +
2374 +/* This file contains a bit of information about the stack allocation
2375 + of the processor. */
2376 +
2377 +#ifndef _STACKINFO_H
2378 +#define _STACKINFO_H 1
2379 +
2380 +/* On AVR32 the stack grows down. */
2381 +#define _STACK_GROWS_DOWN 1
2382 +
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
2387 --- /dev/null
2388 +++ b/libc/sysdeps/linux/avr32/bits/syscalls.h
2389 @@ -0,0 +1,143 @@
2390 +#ifndef _BITS_SYSCALLS_H
2391 +#define _BITS_SYSCALLS_H
2392 +#ifndef _SYSCALL_H
2393 +# error "Never use <bits/syscalls.h> directly; include <sys/syscall.h> instead."
2394 +#endif
2395 +
2396 +/*
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.
2400 + */
2401 +#include <bits/sysnum.h>
2402 +
2403 +#ifndef __ASSEMBLER__
2404 +
2405 +#include <errno.h>
2406 +
2407 +#define SYS_ify(syscall_name) (__NR_##syscall_name)
2408 +
2409 +#undef _syscall0
2410 +#define _syscall0(type,name) \
2411 + type name(void) \
2412 + { \
2413 + return (type)(INLINE_SYSCALL(name, 0)); \
2414 + }
2415 +
2416 +#undef _syscall1
2417 +#define _syscall1(type,name,type1,arg1) \
2418 + type name(type1 arg1) \
2419 + { \
2420 + return (type)(INLINE_SYSCALL(name, 1, arg1)); \
2421 + }
2422 +
2423 +#undef _syscall2
2424 +#define _syscall2(type,name,type1,arg1,type2,arg2) \
2425 + type name(type1 arg1, type2 arg2) \
2426 + { \
2427 + return (type)(INLINE_SYSCALL(name, 2, arg1, arg2)); \
2428 + }
2429 +
2430 +#undef _syscall3
2431 +#define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \
2432 + type name(type1 arg1, type2 arg2, type3 arg3) \
2433 + { \
2434 + return (type)(INLINE_SYSCALL(name, 3, arg1, \
2435 + arg2, arg3)); \
2436 + }
2437 +
2438 +#undef _syscall4
2439 +#define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3, \
2440 + type4,arg4) \
2441 + type name(type1 arg1, type2 arg2, type3 arg3, type4 arg4) \
2442 + { \
2443 + return (type)(INLINE_SYSCALL(name, 4, arg1, arg2, \
2444 + arg3, arg4)); \
2445 + }
2446 +
2447 +#undef _syscall5
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, \
2451 + type5 arg5) \
2452 + { \
2453 + return (type)(INLINE_SYSCALL(name, 5, arg1, arg2, \
2454 + arg3, arg4, arg5)); \
2455 + }
2456 +
2457 +#undef _syscall6
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) \
2462 + { \
2463 + return (type)(INLINE_SYSCALL(name, 6, arg1, arg2, arg3, \
2464 + arg4, arg5, arg6)); \
2465 + }
2466 +
2467 +#undef unlikely
2468 +#define unlikely(x) __builtin_expect((x), 0)
2469 +
2470 +#undef INLINE_SYSCALL
2471 +#define INLINE_SYSCALL(name, nr, args...) \
2472 + ({ \
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; \
2477 + } \
2478 + (int) _sys_result; \
2479 + })
2480 +
2481 +#undef INTERNAL_SYSCALL_DECL
2482 +#define INTERNAL_SYSCALL_DECL(err) do { } while(0)
2483 +
2484 +#undef INTERNAL_SYSCALL
2485 +#define INTERNAL_SYSCALL(name, err, nr, args...) \
2486 + ({ \
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 " */" \
2491 + : "=r" (_a1) \
2492 + : "r"(_scno) ASM_ARGS_##nr \
2493 + : "cc", "memory"); \
2494 + _a1; \
2495 + })
2496 +
2497 +#undef INTERNAL_SYSCALL_ERROR_P
2498 +#define INTERNAL_SYSCALL_ERROR_P(val, err) \
2499 + ((unsigned int)(val) >= 0xfffff001U)
2500 +
2501 +#undef INTERNAL_SYSCALL_ERRNO
2502 +#define INTERNAL_SYSCALL_ERRNO(val, errr) (-(val))
2503 +
2504 +#define LOAD_ARGS_0() do { } while(0)
2505 +#define ASM_ARGS_0
2506 +#define LOAD_ARGS_1(a1) \
2507 + _a1 = (int) (a1); \
2508 + LOAD_ARGS_0()
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); \
2512 + LOAD_ARGS_1(a1)
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)
2530 +
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
2536 --- /dev/null
2537 +++ b/libc/sysdeps/linux/avr32/bits/uClibc_arch_features.h
2538 @@ -0,0 +1,45 @@
2539 +/*
2540 + * Track misc arch-specific features that aren't config options
2541 + */
2542 +
2543 +#ifndef _BITS_UCLIBC_ARCH_FEATURES_H
2544 +#define _BITS_UCLIBC_ARCH_FEATURES_H
2545 +
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"
2549 +
2550 +/* can your target use syscall6() for mmap ? */
2551 +#define __UCLIBC_MMAP_HAS_6_ARGS__
2552 +
2553 +/* does your target use syscall4() for truncate64 ? (32bit arches only) */
2554 +#undef __UCLIBC_TRUNCATE64_HAS_4_ARGS__
2555 +
2556 +/* does your target have a broken create_module() ? */
2557 +#undef __UCLIBC_BROKEN_CREATE_MODULE__
2558 +
2559 +/* does your target have to worry about older [gs]etrlimit() ? */
2560 +#undef __UCLIBC_HANDLE_OLDER_RLIMIT__
2561 +
2562 +/* does your target prefix all symbols with an _ ? */
2563 +#define __UCLIBC_NO_UNDERSCORES__
2564 +
2565 +/* does your target have an asm .set ? */
2566 +#define __UCLIBC_HAVE_ASM_SET_DIRECTIVE__
2567 +
2568 +/* define if target doesn't like .global */
2569 +#undef __UCLIBC_ASM_GLOBAL_DIRECTIVE__
2570 +
2571 +/* define if target supports .weak */
2572 +#define __UCLIBC_HAVE_ASM_WEAK_DIRECTIVE__
2573 +
2574 +/* define if target supports .weakext */
2575 +#undef __UCLIBC_HAVE_ASM_WEAKEXT_DIRECTIVE__
2576 +
2577 +/* needed probably only for ppc64 */
2578 +#undef __UCLIBC_HAVE_ASM_GLOBAL_DOT_NAME__
2579 +
2580 +/* define if target supports IEEE signed zero floats */
2581 +#define __UCLIBC_HAVE_SIGNED_ZERO__
2582 +
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
2587 --- /dev/null
2588 +++ b/libc/sysdeps/linux/avr32/bits/wordsize.h
2589 @@ -0,0 +1 @@
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
2594 --- /dev/null
2595 +++ b/libc/sysdeps/linux/avr32/brk.c
2596 @@ -0,0 +1,31 @@
2597 +/*
2598 + * Copyright (C) 2004-2007 Atmel Corporation
2599 + *
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.
2603 + */
2604 +#include <errno.h>
2605 +#include <unistd.h>
2606 +#include <sys/syscall.h>
2607 +
2608 +libc_hidden_proto(brk)
2609 +
2610 +void *__curbrk attribute_hidden = 0;
2611 +
2612 +int brk (void *addr)
2613 +{
2614 + void *newbrk;
2615 +
2616 + newbrk = (void *)INLINE_SYSCALL(brk, 1, addr);
2617 +
2618 + __curbrk = newbrk;
2619 +
2620 + if (newbrk < addr) {
2621 + __set_errno (ENOMEM);
2622 + return -1;
2623 + }
2624 +
2625 + return 0;
2626 +}
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
2631 --- /dev/null
2632 +++ b/libc/sysdeps/linux/avr32/bsd-_setjmp.S
2633 @@ -0,0 +1,16 @@
2634 +/*
2635 + * Copyright (C) 2004-2007 Atmel Corporation
2636 + *
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.
2640 + */
2641 +
2642 + /* This just does a tail-call to __sigsetjmp(env, 0) */
2643 + .global _setjmp
2644 + .type _setjmp,"function"
2645 + .align 1
2646 +_setjmp:
2647 + mov r11, 0
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
2653 --- /dev/null
2654 +++ b/libc/sysdeps/linux/avr32/bsd-setjmp.S
2655 @@ -0,0 +1,16 @@
2656 +/*
2657 + * Copyright (C) 2004-2007 Atmel Corporation
2658 + *
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.
2662 + */
2663 +
2664 + /* This just does a tail-call to __sigsetjmp(env, 1) */
2665 + .global setjmp
2666 + .type setjmp,"function"
2667 + .align 1
2668 +setjmp:
2669 + mov r11, 1
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
2675 --- /dev/null
2676 +++ b/libc/sysdeps/linux/avr32/clone.c
2677 @@ -0,0 +1,41 @@
2678 +/*
2679 + * Copyright (C) 2004 Atmel Corporation
2680 + *
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.
2684 + */
2685 +#include <errno.h>
2686 +#include <sys/syscall.h>
2687 +#include <unistd.h>
2688 +
2689 +/*
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.
2693 + */
2694 +int clone(int (*fn)(void *arg), void *child_stack, int flags, void *arg)
2695 +{
2696 + register int (*_fn)(void *arg) = fn;
2697 + register void *_arg = arg;
2698 + int err;
2699 +
2700 + /* Sanity check the arguments */
2701 + err = -EINVAL;
2702 + if (!fn)
2703 + goto syscall_error;
2704 + if (!child_stack)
2705 + goto syscall_error;
2706 +
2707 + err = INLINE_SYSCALL(clone, 2, flags, child_stack);
2708 + if (err < 0)
2709 + goto syscall_error;
2710 + else if (err != 0)
2711 + return err;
2712 +
2713 + _exit(_fn(_arg));
2714 +
2715 +syscall_error:
2716 + __set_errno (-err);
2717 + return -1;
2718 +}
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
2722 --- /dev/null
2723 +++ b/libc/sysdeps/linux/avr32/crt1.S
2724 @@ -0,0 +1,97 @@
2725 +/*
2726 + * Copyright (C) 2004-2007 Atmel Corporation
2727 + *
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.
2731 + *
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
2736 + * NULL
2737 + * env[0..N] pointers to environment variables
2738 + * NULL
2739 + *
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
2743 + * code runs.
2744 + *
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)
2749 + *
2750 + * So we need to set up things as follows:
2751 + * r12 = address of main
2752 + * r11 = argc
2753 + * r10 = &argv[0]
2754 + * r9 = address of _init
2755 + * r8 = address of _fini
2756 + * sp[0] = whatever we got passed in r12
2757 + */
2758 +
2759 +#include <features.h>
2760 +
2761 + .text
2762 + .global _start
2763 + .type _start, @function
2764 +_start:
2765 + /* Clear the frame pointer and link register since this is the outermost frame. */
2766 + mov r7, 0
2767 + mov lr, 0
2768 +
2769 + ld.w r11, sp++ /* argc */
2770 + mov r10, sp /* &argv[0] */
2771 +
2772 + st.w --sp, r10 /* stack_end */
2773 + st.w --sp, r12 /* rtld_fini */
2774 +
2775 +#ifdef __PIC__
2776 + lddpc r6, .L_GOT
2777 +.L_RGOT:
2778 + rsub r6, pc
2779 + lda.w r9, _init
2780 + lda.w r8, _fini
2781 + lda.w r12, main
2782 +
2783 + /* Ok, now run uClibc's main() -- should not return */
2784 + call __uClibc_main
2785 +
2786 + .align 2
2787 +.L_GOT:
2788 + .long .L_RGOT - _GLOBAL_OFFSET_TABLE_
2789 +#else
2790 + lddpc r9, __init_addr /* app_init */
2791 + lddpc r8, __fini_addr /* app_fini */
2792 + lddpc r12, __main_addr /* main */
2793 +
2794 + /* Ok, now run uClibc's main() -- should not return */
2795 + lddpc pc, ___uClibc_main_addr
2796 +
2797 + .align 2
2798 +__init_addr:
2799 + .long _init
2800 +__fini_addr:
2801 + .long _fini
2802 +__main_addr:
2803 + .long main
2804 +___uClibc_main_addr:
2805 + .long __uClibc_main
2806 +#endif
2807 + .size _start, . - _start
2808 +
2809 + /*
2810 + * The LSB says we need this.
2811 + */
2812 + .section ".note.ABI-tag", "a"
2813 + .align 4
2814 + .long 2f - 1f /* namesz */
2815 + .long 4f - 3f /* descsz */
2816 + .long 1 /* type */
2817 +1: .asciz "GNU" /* name */
2818 +2: .align 4
2819 +3: .long 0 /* Linux executable */
2820 + .long 2,6,0 /* Earliest compatible kernel */
2821 +4: .align 4
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
2825 --- /dev/null
2826 +++ b/libc/sysdeps/linux/avr32/crti.S
2827 @@ -0,0 +1,26 @@
2828 +
2829 + .section .init
2830 + .align 2
2831 + .global _init
2832 + .type _init, @function
2833 +_init:
2834 + stm --sp, r6, lr
2835 + lddpc r6, 2f
2836 +1: rsub r6, pc
2837 + rjmp 3f
2838 + .align 2
2839 +2: .long 1b - _GLOBAL_OFFSET_TABLE_
2840 +3:
2841 +
2842 + .section .fini
2843 + .align 2
2844 + .global _fini
2845 + .type _fini, @function
2846 +_fini:
2847 + stm --sp, r6, lr
2848 + lddpc r6, 2f
2849 +1: rsub r6, pc
2850 + rjmp 3f
2851 + .align 2
2852 +2: .long 1b - _GLOBAL_OFFSET_TABLE_
2853 +3:
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
2857 --- /dev/null
2858 +++ b/libc/sysdeps/linux/avr32/crtn.S
2859 @@ -0,0 +1,14 @@
2860 +
2861 + .section .init
2862 + .align 2
2863 + .global _init
2864 + .type _init, @function
2865 + ldm sp++, r6, pc
2866 + .size _init, . - _init
2867 +
2868 + .section .fini
2869 + .align 2
2870 + .global _fini
2871 + .type _fini, @function
2872 + ldm sp++, r6, pc
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
2877 --- /dev/null
2878 +++ b/libc/sysdeps/linux/avr32/mmap.c
2879 @@ -0,0 +1,33 @@
2880 +/*
2881 + * Copyright (C) 2004-2007 Atmel Corporation
2882 + *
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.
2886 + */
2887 +
2888 +#include <errno.h>
2889 +#include <unistd.h>
2890 +#include <sys/mman.h>
2891 +#include <sys/syscall.h>
2892 +
2893 +libc_hidden_proto(mmap)
2894 +
2895 +static _syscall6(__ptr_t, mmap2, __ptr_t, addr, size_t, len, int, prot,
2896 + int, flags, int, fd, __off_t, pgoff);
2897 +
2898 +__ptr_t mmap(__ptr_t addr, size_t len, int prot, int flags, int fd, __off_t offset)
2899 +{
2900 + unsigned long page_size = sysconf(_SC_PAGESIZE);
2901 + unsigned long pgoff;
2902 +
2903 + if (offset & (page_size - 1)) {
2904 + __set_errno(EINVAL);
2905 + return MAP_FAILED;
2906 + }
2907 +
2908 + pgoff = (unsigned long)offset >> (31 - __builtin_clz(page_size));
2909 +
2910 + return mmap2(addr, len, prot, flags, fd, pgoff);
2911 +}
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
2916 --- /dev/null
2917 +++ b/libc/sysdeps/linux/avr32/setjmp.S
2918 @@ -0,0 +1,29 @@
2919 +/*
2920 + * Copyright (C) 2004-2007 Atmel Corporation
2921 + *
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.
2925 + */
2926 +#define _SETJMP_H
2927 +#define _ASM
2928 +#include <bits/setjmp.h>
2929 +
2930 + .text
2931 +
2932 + .global __sigsetjmp
2933 + .type __sigsetjmp,"function"
2934 +
2935 + .align 1
2936 +__sigsetjmp:
2937 + mustr r8
2938 + stm r12, r0,r1,r2,r3,r4,r5,r6,r7,r8,sp,lr
2939 +
2940 + /*
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.
2943 + */
2944 + rjmp __sigjmp_save
2945 + .size __sigsetjmp, . - __sigsetjmp
2946 +
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
2951 --- /dev/null
2952 +++ b/libc/sysdeps/linux/avr32/sigaction.c
2953 @@ -0,0 +1,59 @@
2954 +/*
2955 + * Copyright (C) 2004-2007 Atmel Corporation
2956 + *
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.
2960 + */
2961 +#include <errno.h>
2962 +#include <signal.h>
2963 +#include <string.h>
2964 +#include <sys/syscall.h>
2965 +#include <bits/kernel_sigaction.h>
2966 +
2967 +#define SA_RESTORER 0x04000000
2968 +extern void __default_rt_sa_restorer(void);
2969 +
2970 +libc_hidden_proto(memcpy)
2971 +
2972 +/*
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.
2975 + */
2976 +int __libc_sigaction(int signum, const struct sigaction *act,
2977 + struct sigaction *oldact)
2978 +{
2979 + struct kernel_sigaction kact, koact;
2980 + int result;
2981 +
2982 + if (act) {
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;
2988 + else
2989 + kact.sa_restorer = __default_rt_sa_restorer;
2990 + kact.sa_flags |= SA_RESTORER;
2991 + }
2992 +
2993 + result = __syscall_rt_sigaction(signum, act ? __ptrvalue(&kact) : NULL,
2994 + oldact ? __ptrvalue(&koact) : NULL,
2995 + _NSIG / 8);
2996 +
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;
3003 + }
3004 +
3005 + return result;
3006 +}
3007 +
3008 +#ifndef LIBC_SIGACTION
3009 +libc_hidden_proto(sigaction)
3010 +weak_alias(__libc_sigaction, sigaction)
3011 +libc_hidden_weak(sigaction)
3012 +#endif
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
3016 --- /dev/null
3017 +++ b/libc/sysdeps/linux/avr32/sigrestorer.S
3018 @@ -0,0 +1,15 @@
3019 +/*
3020 + * Copyright (C) 2004 Atmel Corporation
3021 + *
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.
3025 + */
3026 +#include <sys/syscall.h>
3027 +
3028 + .global __default_rt_sa_restorer
3029 + .type __default_rt_sa_restorer,"function"
3030 + .align 1
3031 +__default_rt_sa_restorer:
3032 + mov r8, __NR_rt_sigreturn
3033 + scall
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
3037 --- /dev/null
3038 +++ b/libc/sysdeps/linux/avr32/sys/elf.h
3039 @@ -0,0 +1,26 @@
3040 +/* Copyright (C) 1996, 1997, 1999, 2001 Free Software Foundation, Inc.
3041 + This file is part of the GNU C Library.
3042 +
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.
3047 +
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.
3052 +
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. */
3057 +
3058 +#ifndef _SYS_ELF_H
3059 +#define _SYS_ELF_H 1
3060 +
3061 +#warning "This header is obsolete; use <sys/procfs.h> instead."
3062 +
3063 +#include <sys/procfs.h>
3064 +
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
3069 --- /dev/null
3070 +++ b/libc/sysdeps/linux/avr32/sys/procfs.h
3071 @@ -0,0 +1,123 @@
3072 +/* Copyright (C) 1996, 1997, 1999, 2001 Free Software Foundation, Inc.
3073 + This file is part of the GNU C Library.
3074 +
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.
3079 +
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.
3084 +
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. */
3089 +
3090 +#ifndef _SYS_PROCFS_H
3091 +#define _SYS_PROCFS_H 1
3092 +
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.
3097 +
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. */
3101 +
3102 +#include <features.h>
3103 +#include <sys/time.h>
3104 +#include <sys/types.h>
3105 +#include <sys/user.h>
3106 +
3107 +__BEGIN_DECLS
3108 +
3109 +/* Type for a general-purpose register. */
3110 +typedef unsigned long elf_greg_t;
3111 +
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];
3118 +
3119 +/* Register set for the floating-point registers. */
3120 +typedef struct user_fpregs elf_fpregset_t;
3121 +
3122 +/* Signal info. */
3123 +struct elf_siginfo
3124 + {
3125 + int si_signo; /* Signal number. */
3126 + int si_code; /* Extra code. */
3127 + int si_errno; /* Errno. */
3128 + };
3129 +
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. */
3136 +
3137 +struct elf_prstatus
3138 + {
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. */
3143 + __pid_t pr_pid;
3144 + __pid_t pr_ppid;
3145 + __pid_t pr_pgrp;
3146 + __pid_t pr_sid;
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. */
3153 + };
3154 +
3155 +
3156 +#define ELF_PRARGSZ (80) /* Number of chars for args. */
3157 +
3158 +struct elf_prpsinfo
3159 + {
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. */
3171 + };
3172 +
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. */
3176 +
3177 +/* Addresses. */
3178 +typedef void *psaddr_t;
3179 +
3180 +/* Register sets. Linux has different names. */
3181 +typedef elf_gregset_t prgregset_t;
3182 +typedef elf_fpregset_t prfpregset_t;
3183 +
3184 +/* We don't have any differences between processes and threads,
3185 + therefore have only one PID type. */
3186 +typedef __pid_t lwpid_t;
3187 +
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;
3191 +
3192 +__END_DECLS
3193 +
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
3198 --- /dev/null
3199 +++ b/libc/sysdeps/linux/avr32/sys/ucontext.h
3200 @@ -0,0 +1,90 @@
3201 +/* Copyright (C) 1998, 1999, 2001 Free Software Foundation, Inc.
3202 + This file is part of the GNU C Library.
3203 +
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.
3208 +
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.
3213 +
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. */
3218 +
3219 +/* Linux/AVR32 ABI compliant context switching support. */
3220 +
3221 +#ifndef _SYS_UCONTEXT_H
3222 +#define _SYS_UCONTEXT_H 1
3223 +
3224 +#include <features.h>
3225 +#include <signal.h>
3226 +#include <sys/procfs.h>
3227 +#include <bits/sigcontext.h>
3228 +
3229 +typedef int greg_t;
3230 +
3231 +/* Number of general registers. */
3232 +#define NGREG 16
3233 +
3234 +/* Container for all general registers. */
3235 +typedef elf_gregset_t gregset_t;
3236 +
3237 +/* Number of each register is the `gregset_t' array. */
3238 +enum
3239 +{
3240 + R0 = 0,
3241 +#define R0 R0
3242 + R1 = 1,
3243 +#define R1 R1
3244 + R2 = 2,
3245 +#define R2 R2
3246 + R3 = 3,
3247 +#define R3 R3
3248 + R4 = 4,
3249 +#define R4 R4
3250 + R5 = 5,
3251 +#define R5 R5
3252 + R6 = 6,
3253 +#define R6 R6
3254 + R7 = 7,
3255 +#define R7 R7
3256 + R8 = 8,
3257 +#define R8 R8
3258 + R9 = 9,
3259 +#define R9 R9
3260 + R10 = 10,
3261 +#define R10 R10
3262 + R11 = 11,
3263 +#define R11 R11
3264 + R12 = 12,
3265 +#define R12 R12
3266 + R13 = 13,
3267 +#define R13 R13
3268 + R14 = 14,
3269 +#define R14 R14
3270 + R15 = 15
3271 +#define R15 R15
3272 +};
3273 +
3274 +/* Structure to describe FPU registers. */
3275 +typedef elf_fpregset_t fpregset_t;
3276 +
3277 +/* Context to describe whole processor state. */
3278 +typedef struct sigcontext mcontext_t;
3279 +
3280 +/* Userlevel context. */
3281 +typedef struct ucontext
3282 +{
3283 + unsigned long uc_flags;
3284 + struct ucontext *uc_link;
3285 + stack_t uc_stack;
3286 + mcontext_t uc_mcontext;
3287 + sigset_t uc_sigmask; /* mask last for extensibility */
3288 +} ucontext_t;
3289 +
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
3294 --- /dev/null
3295 +++ b/libc/sysdeps/linux/avr32/sys/user.h
3296 @@ -0,0 +1,46 @@
3297 +#ifndef _SYS_USER_H
3298 +#define _SYS_USER_H
3299 +
3300 +struct user_fpregs
3301 +{
3302 +
3303 +};
3304 +
3305 +struct user_regs
3306 +{
3307 + unsigned long sr;
3308 + unsigned long pc;
3309 + unsigned long lr;
3310 + unsigned long sp;
3311 + unsigned long r12;
3312 + unsigned long r11;
3313 + unsigned long r10;
3314 + unsigned long r9;
3315 + unsigned long r8;
3316 + unsigned long r7;
3317 + unsigned long r6;
3318 + unsigned long r5;
3319 + unsigned long r4;
3320 + unsigned long r3;
3321 + unsigned long r2;
3322 + unsigned long r1;
3323 + unsigned long r0;
3324 + unsigned long r12_orig;
3325 +};
3326 +
3327 +struct user
3328 +{
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 */
3340 +};
3341 +
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
3346 --- /dev/null
3347 +++ b/libc/sysdeps/linux/avr32/syscall.S
3348 @@ -0,0 +1,71 @@
3349 +/*
3350 + * Copyright (C) 2004-2007 Atmel Corporation
3351 + *
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.
3355 + */
3356 +#include <features.h>
3357 +
3358 + .text
3359 +
3360 + /*
3361 + * long int syscall(long int sysno, ...)
3362 + */
3363 + .global syscall
3364 + .type syscall, @function
3365 + .align 2
3366 +syscall:
3367 + stm --sp, r3,r5,r6,lr
3368 + sub lr, sp, -16
3369 + mov r8, r12
3370 + ldm lr, r3,r5,r9-r12
3371 + scall
3372 + cp.w r12, -4095
3373 + brlo .Ldone
3374 +
3375 +#ifdef __PIC__
3376 + lddpc r6, .Lgot
3377 +.Lgotcalc:
3378 + rsub r6, pc
3379 +# ifdef __UCLIBC_HAS_THREADS__
3380 + rsub r3, r12, 0
3381 + mcall r6[__errno_location@got]
3382 + st.w r12[0], r3
3383 +# else
3384 + ld.w r3, r6[errno@got]
3385 + neg r12
3386 + st.w r3[0], r12
3387 +# endif
3388 +#else
3389 +# ifdef __UCLIBC_HAS_THREADS__
3390 + rsub r3, r12, 0
3391 + mcall .Lerrno_location
3392 + st.w r12[0], r3
3393 +# else
3394 + lddpc r3, .Lerrno
3395 + neg r12
3396 + st.w r3[0], r12
3397 +# endif
3398 +#endif
3399 + mov r12, -1
3400 +
3401 +.Ldone:
3402 + ldm sp++, r3,r5,r6,pc
3403 +
3404 + .align 2
3405 +#ifdef __PIC__
3406 +.Lgot:
3407 + .long .Lgotcalc - _GLOBAL_OFFSET_TABLE_
3408 +#else
3409 +# ifdef __UCLIBC_HAS_THREADS__
3410 +.Lerrno_location:
3411 + .long __errno_location
3412 +# else
3413 +.Lerrno:
3414 + .long errno
3415 +# endif
3416 +#endif
3417 +
3418 +
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
3423 --- /dev/null
3424 +++ b/libc/sysdeps/linux/avr32/vfork.S
3425 @@ -0,0 +1,58 @@
3426 +/*
3427 + * Copyright (C) 2005 Atmel Corporation
3428 + *
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.
3432 + */
3433 +
3434 +/*
3435 + * Clone the process without copying the address space. The
3436 + * calling process is suspended until the child either exits
3437 + * or calls execve.
3438 + *
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.
3443 + */
3444 +
3445 +#include <features.h>
3446 +#include <sys/syscall.h>
3447 +
3448 + .global __vfork
3449 + .type __vfork,@function
3450 + .align 1
3451 +__vfork:
3452 + mov r8, __NR_vfork
3453 + scall
3454 + cp.w r12, -4096
3455 + retls r12
3456 +
3457 + /* vfork failed, so we may use the stack freely */
3458 + pushm r4-r7,lr
3459 +#ifdef __PIC__
3460 + lddpc r6, .L_GOT
3461 + rsub r4, r12, 0
3462 +.L_RGOT:
3463 + rsub r6, pc
3464 + mcall r6[__errno_location@got]
3465 +#else
3466 + rsub r4, r12, 0
3467 + mcall .L__errno_location
3468 +#endif
3469 + st.w r12[0], r4
3470 + popm r4-r7,pc,r12=-1
3471 +
3472 + .align 2
3473 +#ifdef __PIC__
3474 +.L_GOT:
3475 + .long .L_RGOT - _GLOBAL_OFFSET_TABLE_
3476 +#else
3477 +.L__errno_location:
3478 + .long __errno_location
3479 +#endif
3480 + .size __vfork, . - __vfork
3481 +
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
3487 --- /dev/null
3488 +++ b/libpthread/linuxthreads.old/sysdeps/avr32/pt-machine.h
3489 @@ -0,0 +1,73 @@
3490 +/* Machine-dependent pthreads configuration and inline functions.
3491 + *
3492 + * Copyright (C) 2005-2007 Atmel Corporation
3493 + *
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.
3497 + */
3498 +#ifndef _PT_MACHINE_H
3499 +#define _PT_MACHINE_H 1
3500 +
3501 +#include <features.h>
3502 +
3503 +static inline int
3504 +_test_and_set (int *p, int v)
3505 +{
3506 + int result;
3507 +
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)
3513 + : "memory");
3514 +
3515 + return result;
3516 +}
3517 +
3518 +#ifndef PT_EI
3519 +# define PT_EI extern inline
3520 +#endif
3521 +
3522 +extern long int testandset (int *spinlock);
3523 +extern int __compare_and_swap (long int *p, long int oldval, long int newval);
3524 +
3525 +/* Spinlock implementation; required. */
3526 +PT_EI long int
3527 +testandset (int *spinlock)
3528 +{
3529 + return _test_and_set(spinlock, 1);
3530 +}
3531 +
3532 +
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");
3537 +
3538 +/* Compare-and-swap for semaphores. */
3539 +
3540 +#define HAS_COMPARE_AND_SWAP
3541 +PT_EI int
3542 +__compare_and_swap(long int *p, long int oldval, long int newval)
3543 +{
3544 + long int result;
3545 +
3546 + __asm__ __volatile__(
3547 + "/* Inline compare and swap */\n"
3548 + "1: ssrf 5\n"
3549 + " ld.w %[result], %[mem]\n"
3550 + " eor %[result], %[old]\n"
3551 + " brne 2f\n"
3552 + " stcond %[mem], %[new]\n"
3553 + " brne 1b\n"
3554 + "2:"
3555 + : [result] "=&r"(result), [mem] "=m"(*p)
3556 + : "m"(*p), [new] "r"(newval), [old] "r"(oldval)
3557 + : "cc", "memory");
3558 +
3559 + return result == 0;
3560 +}
3561 +
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
3566 --- /dev/null
3567 +++ b/libpthread/linuxthreads/sysdeps/avr32/pt-machine.h
3568 @@ -0,0 +1,73 @@
3569 +/* Machine-dependent pthreads configuration and inline functions.
3570 + *
3571 + * Copyright (C) 2005-2007 Atmel Corporation
3572 + *
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.
3576 + */
3577 +#ifndef _PT_MACHINE_H
3578 +#define _PT_MACHINE_H 1
3579 +
3580 +#include <features.h>
3581 +
3582 +static inline int
3583 +_test_and_set (int *p, int v) __THROW
3584 +{
3585 + int result;
3586 +
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)
3592 + : "memory");
3593 +
3594 + return result;
3595 +}
3596 +
3597 +#ifndef PT_EI
3598 +# define PT_EI extern inline
3599 +#endif
3600 +
3601 +extern long int testandset (int *spinlock);
3602 +extern int __compare_and_swap (long int *p, long int oldval, long int newval);
3603 +
3604 +/* Spinlock implementation; required. */
3605 +PT_EI long int
3606 +testandset (int *spinlock)
3607 +{
3608 + return _test_and_set(spinlock, 1);
3609 +}
3610 +
3611 +
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");
3616 +
3617 +/* Compare-and-swap for semaphores. */
3618 +
3619 +#define HAS_COMPARE_AND_SWAP
3620 +PT_EI int
3621 +__compare_and_swap(long int *p, long int oldval, long int newval)
3622 +{
3623 + int result;
3624 +
3625 + __asm__ __volatile__(
3626 + "/* Inline compare and swap */\n"
3627 + "1: ssrf 5\n"
3628 + " ld.w %[result], %[mem]\n"
3629 + " eor %[result], %[old]\n"
3630 + " brne 2f\n"
3631 + " stcond %[mem], %[new]\n"
3632 + " brne 1b\n"
3633 + "2:"
3634 + : [result] "=&r"(result), [mem] "=m"(*p)
3635 + : "m"(*p), [new] "r"(newval), [old] "r"(oldval)
3636 + : "cc", "memory");
3637 +
3638 + return result == 0;
3639 +}
3640 +
3641 +#endif /* pt-machine.h */
3642 diff --git a/utils/ldd.c b/utils/ldd.c
3643 index 75ad628..e34acd9 100644
3644 --- a/utils/ldd.c
3645 +++ b/utils/ldd.c
3646 @@ -44,6 +44,11 @@
3647 #define ELFCLASSM ELFCLASS32
3648 #endif
3649
3650 +#if defined(__avr32__)
3651 +#define MATCH_MACHINE(x) (x == EM_AVR32)
3652 +#define ELFCLASSM ELFCLASS32
3653 +#endif
3654 +
3655 #if defined(__s390__)
3656 #define MATCH_MACHINE(x) (x == EM_S390)
3657 #define ELFCLASSM ELFCLASS32
This page took 0.236897 seconds and 5 git commands to generate.