remove broken status from uml target
[openwrt.git] / toolchain / uClibc / patches / 007-avr32.patch
1 diff --git a/Rules.mak b/Rules.mak
2 index d054bbb..55381cf 100644
3 --- a/Rules.mak
4 +++ b/Rules.mak
5 @@ -313,6 +313,12 @@ ifeq ($(TARGET_ARCH),frv)
6 UCLIBC_LDSO=ld.so.1
7 endif
8
9 +ifeq ($(strip $(TARGET_ARCH)),avr32)
10 + CPU_CFLAGS-$(CONFIG_AVR32_AP7) += -march=ap
11 + CPU_CFLAGS-$(CONFIG_LINKRELAX) += -mrelax
12 + CPU_LDFLAGS-$(CONFIG_LINKRELAX) += --relax
13 +endif
14 +
15 # Keep the check_gcc from being needlessly executed
16 ifndef PIEFLAG
17 ifneq ($(UCLIBC_BUILD_PIE),y)
18 diff --git a/extra/Configs/Config.avr32 b/extra/Configs/Config.avr32
19 new file mode 100644
20 index 0000000..8d70e6e
21 --- /dev/null
22 +++ b/extra/Configs/Config.avr32
23 @@ -0,0 +1,31 @@
24 +#
25 +# For a description of the syntax of this configuration file,
26 +# see extra/config/Kconfig-language.txt
27 +#
28 +
29 +config TARGET_ARCH
30 + string
31 + default "avr32"
32 +
33 +config FORCE_OPTIONS_FOR_ARCH
34 + bool
35 + default y
36 + select ARCH_BIG_ENDIAN
37 + select FORCE_SHAREABLE_TEXT_SEGMENTS
38 +
39 +config ARCH_CFLAGS
40 + string
41 +
42 +choice
43 + prompt "Target CPU Type"
44 + default CONFIG_AVR32_AP7
45 +
46 +config CONFIG_AVR32_AP7
47 + bool "AVR32 AP7"
48 + select ARCH_HAS_MMU
49 +
50 +endchoice
51 +
52 +config LINKRELAX
53 + bool "Enable linker optimizations"
54 + default y
55 diff --git a/extra/Configs/Config.in b/extra/Configs/Config.in
56 index 8eab394..10c9f7b 100644
57 --- a/extra/Configs/Config.in
58 +++ b/extra/Configs/Config.in
59 @@ -16,6 +16,9 @@ config TARGET_alpha
60 config TARGET_arm
61 bool "arm"
62
63 +config TARGET_avr32
64 + bool "avr32"
65 +
66 config TARGET_bfin
67 bool "bfin"
68
69 @@ -92,6 +95,10 @@ if TARGET_arm
70 source "extra/Configs/Config.arm"
71 endif
72
73 +if TARGET_avr32
74 +source "extra/Configs/Config.avr32"
75 +endif
76 +
77 if TARGET_bfin
78 source "extra/Configs/Config.bfin"
79 endif
80 diff --git a/extra/Configs/defconfigs/avr32 b/extra/Configs/defconfigs/avr32
81 new file mode 100644
82 index 0000000..0b890a2
83 --- /dev/null
84 +++ b/extra/Configs/defconfigs/avr32
85 @@ -0,0 +1 @@
86 +TARGET_avr32=y
87 diff --git a/include/elf.h b/include/elf.h
88 index 19805d7..ab90160 100644
89 --- a/include/elf.h
90 +++ b/include/elf.h
91 @@ -354,6 +354,8 @@ typedef struct
92 /* NIOS magic number - no EABI available. */
93 #define EM_NIOS32 0xFEBB
94
95 +#define EM_AVR32 0x18ad
96 +
97 /* V850 backend magic number. Written in the absense of an ABI. */
98 #define EM_CYGNUS_V850 0x9080
99
100 @@ -2828,6 +2830,55 @@ typedef Elf32_Addr Elf32_Conflict;
101 /* Keep this the last entry. */
102 #define R_V850_NUM 25
103
104 +/* Atmel AVR32 relocations. */
105 +#define R_AVR32_NONE 0
106 +#define R_AVR32_32 1
107 +#define R_AVR32_16 2
108 +#define R_AVR32_8 3
109 +#define R_AVR32_32_PCREL 4
110 +#define R_AVR32_16_PCREL 5
111 +#define R_AVR32_8_PCREL 6
112 +#define R_AVR32_DIFF32 7
113 +#define R_AVR32_DIFF16 8
114 +#define R_AVR32_DIFF8 9
115 +#define R_AVR32_GOT32 10
116 +#define R_AVR32_GOT16 11
117 +#define R_AVR32_GOT8 12
118 +#define R_AVR32_21S 13
119 +#define R_AVR32_16U 14
120 +#define R_AVR32_16S 15
121 +#define R_AVR32_8S 16
122 +#define R_AVR32_8S_EXT 17
123 +#define R_AVR32_22H_PCREL 18
124 +#define R_AVR32_18W_PCREL 19
125 +#define R_AVR32_16B_PCREL 20
126 +#define R_AVR32_16N_PCREL 21
127 +#define R_AVR32_14UW_PCREL 22
128 +#define R_AVR32_11H_PCREL 23
129 +#define R_AVR32_10UW_PCREL 24
130 +#define R_AVR32_9H_PCREL 25
131 +#define R_AVR32_9UW_PCREL 26
132 +#define R_AVR32_HI16 27
133 +#define R_AVR32_LO16 28
134 +#define R_AVR32_GOTPC 29
135 +#define R_AVR32_GOTCALL 30
136 +#define R_AVR32_LDA_GOT 31
137 +#define R_AVR32_GOT21S 32
138 +#define R_AVR32_GOT18SW 33
139 +#define R_AVR32_GOT16S 34
140 +#define R_AVR32_GOT7UW 35
141 +#define R_AVR32_32_CPENT 36
142 +#define R_AVR32_CPCALL 37
143 +#define R_AVR32_16_CP 38
144 +#define R_AVR32_9W_CP 39
145 +#define R_AVR32_RELATIVE 40
146 +#define R_AVR32_GLOB_DAT 41
147 +#define R_AVR32_JMP_SLOT 42
148 +#define R_AVR32_ALIGN 43
149 +#define R_AVR32_NUM 44
150 +
151 +/* AVR32 dynamic tags */
152 +#define DT_AVR32_GOTSZ 0x70000001 /* Total size of GOT in bytes */
153
154 /* Renesas H8/300 Relocations */
155 #define R_H8_NONE 0
156 diff --git a/ldso/include/dl-string.h b/ldso/include/dl-string.h
157 index 32c5bf8..eb43bd9 100644
158 --- a/ldso/include/dl-string.h
159 +++ b/ldso/include/dl-string.h
160 @@ -285,7 +285,8 @@ static __always_inline char * _dl_simple_ltoahex(char * local, unsigned long i)
161 /* On some arches constant strings are referenced through the GOT.
162 * This requires that load_addr must already be defined... */
163 #if defined(mc68000) || defined(__arm__) || defined(__thumb__) || \
164 - defined(__mips__) || defined(__sh__) || defined(__powerpc__)
165 + defined(__mips__) || defined(__sh__) || defined(__powerpc__) || \
166 + defined(__avr32__)
167 # define CONSTANT_STRING_GOT_FIXUP(X) \
168 if ((X) < (const char *) load_addr) (X) += load_addr
169 # define NO_EARLY_SEND_STDERR
170 diff --git a/ldso/include/dl-syscall.h b/ldso/include/dl-syscall.h
171 index b42416a..4404219 100644
172 --- a/ldso/include/dl-syscall.h
173 +++ b/ldso/include/dl-syscall.h
174 @@ -55,69 +55,69 @@
175 dynamic linking at all, so we cannot return any error codes.
176 We just punt if there is an error. */
177 #define __NR__dl_exit __NR_exit
178 -static inline _syscall1(void, _dl_exit, int, status);
179 +static __always_inline _syscall1(void, _dl_exit, int, status);
180
181 #define __NR__dl_close __NR_close
182 -static inline _syscall1(int, _dl_close, int, fd);
183 +static __always_inline _syscall1(int, _dl_close, int, fd);
184
185 #define __NR__dl_open __NR_open
186 -static inline _syscall3(int, _dl_open, const char *, fn, int, flags,
187 +static __always_inline _syscall3(int, _dl_open, const char *, fn, int, flags,
188 __kernel_mode_t, mode);
189
190 #define __NR__dl_write __NR_write
191 -static inline _syscall3(unsigned long, _dl_write, int, fd,
192 +static __always_inline _syscall3(unsigned long, _dl_write, int, fd,
193 const void *, buf, unsigned long, count);
194
195 #define __NR__dl_read __NR_read
196 -static inline _syscall3(unsigned long, _dl_read, int, fd,
197 +static __always_inline _syscall3(unsigned long, _dl_read, int, fd,
198 const void *, buf, unsigned long, count);
199
200 #define __NR__dl_mprotect __NR_mprotect
201 -static inline _syscall3(int, _dl_mprotect, const void *, addr,
202 +static __always_inline _syscall3(int, _dl_mprotect, const void *, addr,
203 unsigned long, len, int, prot);
204
205 #define __NR__dl_stat __NR_stat
206 -static inline _syscall2(int, _dl_stat, const char *, file_name,
207 +static __always_inline _syscall2(int, _dl_stat, const char *, file_name,
208 struct stat *, buf);
209
210 #define __NR__dl_fstat __NR_fstat
211 -static inline _syscall2(int, _dl_fstat, int, fd, struct stat *, buf);
212 +static __always_inline _syscall2(int, _dl_fstat, int, fd, struct stat *, buf);
213
214 #define __NR__dl_munmap __NR_munmap
215 -static inline _syscall2(int, _dl_munmap, void *, start, unsigned long, length);
216 +static __always_inline _syscall2(int, _dl_munmap, void *, start, unsigned long, length);
217
218 #ifdef __NR_getxuid
219 # define __NR_getuid __NR_getxuid
220 #endif
221 #define __NR__dl_getuid __NR_getuid
222 -static inline _syscall0(uid_t, _dl_getuid);
223 +static __always_inline _syscall0(uid_t, _dl_getuid);
224
225 #ifndef __NR_geteuid
226 # define __NR_geteuid __NR_getuid
227 #endif
228 #define __NR__dl_geteuid __NR_geteuid
229 -static inline _syscall0(uid_t, _dl_geteuid);
230 +static __always_inline _syscall0(uid_t, _dl_geteuid);
231
232 #ifdef __NR_getxgid
233 # define __NR_getgid __NR_getxgid
234 #endif
235 #define __NR__dl_getgid __NR_getgid
236 -static inline _syscall0(gid_t, _dl_getgid);
237 +static __always_inline _syscall0(gid_t, _dl_getgid);
238
239 #ifndef __NR_getegid
240 # define __NR_getegid __NR_getgid
241 #endif
242 #define __NR__dl_getegid __NR_getegid
243 -static inline _syscall0(gid_t, _dl_getegid);
244 +static __always_inline _syscall0(gid_t, _dl_getegid);
245
246 #ifdef __NR_getxpid
247 # define __NR_getpid __NR_getxpid
248 #endif
249 #define __NR__dl_getpid __NR_getpid
250 -static inline _syscall0(gid_t, _dl_getpid);
251 +static __always_inline _syscall0(gid_t, _dl_getpid);
252
253 #define __NR__dl_readlink __NR_readlink
254 -static inline _syscall3(int, _dl_readlink, const char *, path, char *, buf,
255 +static __always_inline _syscall3(int, _dl_readlink, const char *, path, char *, buf,
256 size_t, bufsiz);
257
258 #ifdef __UCLIBC_HAS_SSP__
259 @@ -146,14 +146,14 @@ static inline _syscall2(int, _dl_gettimeofday, struct timeval *, tv,
260 #if defined(__UCLIBC_MMAP_HAS_6_ARGS__) && defined(__NR_mmap)
261
262 # define __NR__dl_mmap __NR_mmap
263 -static inline _syscall6(void *, _dl_mmap, void *, start, size_t, length,
264 +static __always_inline _syscall6(void *, _dl_mmap, void *, start, size_t, length,
265 int, prot, int, flags, int, fd, off_t, offset);
266
267 /* then try mmap2() */
268 #elif defined(__NR_mmap2)
269
270 # define __NR___syscall_mmap2 __NR_mmap2
271 -static inline _syscall6(__ptr_t, __syscall_mmap2, __ptr_t, addr, size_t, len,
272 +static __always_inline _syscall6(__ptr_t, __syscall_mmap2, __ptr_t, addr, size_t, len,
273 int, prot, int, flags, int, fd, off_t, offset);
274
275 /* Some architectures always use 12 as page shift for mmap2() eventhough the
276 @@ -164,7 +164,7 @@ static inline _syscall6(__ptr_t, __syscall_mmap2, __ptr_t, addr, size_t, len,
277 # define MMAP2_PAGE_SHIFT 12
278 #endif
279
280 -static inline void * _dl_mmap(void * addr, unsigned long size, int prot,
281 +static __always_inline void * _dl_mmap(void * addr, unsigned long size, int prot,
282 int flags, int fd, unsigned long offset)
283 {
284 if (offset & ((1 << MMAP2_PAGE_SHIFT) - 1))
285 @@ -177,8 +177,8 @@ static inline void * _dl_mmap(void * addr, unsigned long size, int prot,
286 #elif defined(__NR_mmap)
287
288 # define __NR__dl_mmap_real __NR_mmap
289 -static inline _syscall1(void *, _dl_mmap_real, unsigned long *, buffer);
290 -static inline void * _dl_mmap(void * addr, unsigned long size, int prot,
291 +static __always_inline _syscall1(void *, _dl_mmap_real, unsigned long *, buffer);
292 +static __always_inline void * _dl_mmap(void * addr, unsigned long size, int prot,
293 int flags, int fd, unsigned long offset)
294 {
295 unsigned long buffer[6];
296 diff --git a/ldso/ldso/avr32/dl-debug.h b/ldso/ldso/avr32/dl-debug.h
297 new file mode 100644
298 index 0000000..fe35539
299 --- /dev/null
300 +++ b/ldso/ldso/avr32/dl-debug.h
301 @@ -0,0 +1,45 @@
302 +/*
303 + * AVR32 ELF shared libary loader support
304 + *
305 + * Copyright (C) 2005-2007 Atmel Corporation
306 + * All rights reserved.
307 + *
308 + * Redistribution and use in source and binary forms, with or without
309 + * modification, are permitted provided that the following conditions
310 + * are met:
311 + * 1. Redistributions of source code must retain the above copyright
312 + * notice, this list of conditions and the following disclaimer.
313 + * 2. The name of the above contributors may not be
314 + * used to endorse or promote products derived from this software
315 + * without specific prior written permission.
316 + *
317 + * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND
318 + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
319 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
320 + * ARE DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE
321 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
322 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
323 + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
324 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
325 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
326 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
327 + * SUCH DAMAGE.
328 + */
329 +
330 +static const char *_dl_reltypes_tab[] = {
331 + "R_AVR32_NONE",
332 + "R_AVR32_32", "R_AVR32_16", "R_AVR32_8",
333 + "R_AVR32_32_PCREL", "R_AVR32_16_PCREL", "R_AVR32_8_PCREL",
334 + "R_AVR32_DIFF32", "R_AVR32_DIFF16", "R_AVR32_DIFF8",
335 + "R_AVR32_GOT32", "R_AVR32_GOT16", "R_AVR32_GOT8",
336 + "R_AVR32_21S", "R_AVR32_16U", "R_AVR32_16S", "R_AVR32_8S", "R_AVR32_8S_EXT",
337 + "R_AVR32_22H_PCREL", "R_AVR32_18W_PCREL", "R_AVR32_16B_PCREL",
338 + "R_AVR32_16N_PCREL", "R_AVR32_14UW_PCREL", "R_AVR32_11H_PCREL",
339 + "R_AVR32_10UW_PCREL", "R_AVR32_9H_PCREL", "R_AVR32_9UW_PCREL",
340 + "R_AVR32_HI16", "R_AVR32_LO16",
341 + "R_AVR32_GOTPC", "R_AVR32_GOTCALL", "R_AVR32_LDA_GOT",
342 + "R_AVR32_GOT21S", "R_AVR32_GOT18SW", "R_AVR32_GOT16S", "R_AVR32_GOT7UW",
343 + "R_AVR32_32_CPENT", "R_AVR32_CPCALL", "R_AVR32_16_CP", "R_AVR32_9W_CP",
344 + "R_AVR32_RELATIVE", "R_AVR32_GLOB_DAT", "R_AVR32_JMP_SLOT",
345 + "R_AVR32_ALIGN",
346 +};
347 diff --git a/ldso/ldso/avr32/dl-startup.h b/ldso/ldso/avr32/dl-startup.h
348 new file mode 100644
349 index 0000000..3b9a641
350 --- /dev/null
351 +++ b/ldso/ldso/avr32/dl-startup.h
352 @@ -0,0 +1,112 @@
353 +/*
354 + * Architecture specific code used by dl-startup.c
355 + *
356 + * Copyright (C) 2005-2007 Atmel Corporation
357 + *
358 + * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
359 + */
360 +
361 +/* This is the library loader's main entry point. Let _dl_boot2 do its
362 + * initializations and jump to the application's entry point
363 + * afterwards. */
364 +asm( " .text\n"
365 + " .global _start\n"
366 + " .type _start,@function\n"
367 + "_start:\n"
368 + /* All arguments are on the stack initially */
369 + " mov r12, sp\n"
370 + " rcall _dl_start\n"
371 + /* Returns user entry point in r12. Save it. */
372 + " mov r0, r12\n"
373 + /* We're PIC, so get the Global Offset Table */
374 + " lddpc r6, .L_GOT\n"
375 + ".L_RGOT:\n"
376 + " rsub r6, pc\n"
377 + /* Adjust argc and argv according to _dl_skip_args */
378 + " ld.w r1, r6[_dl_skip_args@got]\n"
379 + " ld.w r1, r1[0]\n"
380 + " ld.w r2, sp++\n"
381 + " sub r2, r1\n"
382 + " add sp, sp, r1 << 2\n"
383 + " st.w --sp, r2\n"
384 + /* Load the finalizer function */
385 + " ld.w r12, r6[_dl_fini@got]\n"
386 + /* Jump to the user's entry point */
387 + " mov pc, r0\n\n"
388 +
389 + " .align 2\n"
390 + ".L_GOT:"
391 + " .long .L_RGOT - _GLOBAL_OFFSET_TABLE_\n"
392 + " .size _start, . - _start\n"
393 + " .previous\n");
394 +
395 +/* Get a pointer to the argv array. On many platforms this can be just
396 + * the address if the first argument, on other platforms we need to
397 + * do something a little more subtle here. */
398 +#define GET_ARGV(ARGVP, ARGS) ARGVP = ((unsigned long *)ARGS + 1)
399 +
400 +
401 +/* We can't call functions before the GOT has been initialized */
402 +#define NO_FUNCS_BEFORE_BOOTSTRAP
403 +
404 +/*
405 + * Relocate the GOT during dynamic loader bootstrap. This will add
406 + * the load address to all entries in the GOT, which is necessary
407 + * because the linker doesn't generate R_AVR32_RELATIVE relocs for the
408 + * GOT.
409 + */
410 +static __always_inline
411 +void PERFORM_BOOTSTRAP_GOT(struct elf_resolve *tpnt)
412 +{
413 + Elf32_Addr i, nr_got;
414 + register Elf32_Addr *__r6 __asm__("r6");
415 + Elf32_Addr *got = __r6;
416 +
417 + nr_got = tpnt->dynamic_info[DT_AVR32_GOTSZ_IDX] / sizeof(*got);
418 + for (i = 2; i < nr_got; i++)
419 + got[i] += tpnt->loadaddr;
420 +}
421 +
422 +#define PERFORM_BOOTSTRAP_GOT(tpnt) PERFORM_BOOTSTRAP_GOT(tpnt)
423 +
424 +/* Handle relocation of the symbols in the dynamic loader. */
425 +static __always_inline
426 +void PERFORM_BOOTSTRAP_RELOC(ELF_RELOC *rpnt, unsigned long *reloc_addr,
427 + unsigned long symbol_addr,
428 + unsigned long load_addr, Elf32_Sym *symtab)
429 +{
430 + switch(ELF32_R_TYPE(rpnt->r_info)) {
431 + case R_AVR32_NONE:
432 + break;
433 + case R_AVR32_GLOB_DAT:
434 + case R_AVR32_JMP_SLOT:
435 + *reloc_addr = symbol_addr;
436 + break;
437 + case R_AVR32_RELATIVE:
438 + SEND_STDERR_DEBUG("Applying RELATIVE relocation: ");
439 + SEND_ADDRESS_STDERR_DEBUG(load_addr, 0);
440 + SEND_STDERR_DEBUG(" + ");
441 + SEND_ADDRESS_STDERR_DEBUG(rpnt->r_addend, 1);
442 + *reloc_addr = load_addr + rpnt->r_addend;
443 + break;
444 + default:
445 + SEND_STDERR("BOOTSTRAP_RELOC: unhandled reloc_type ");
446 + SEND_NUMBER_STDERR(ELF32_R_TYPE(rpnt->r_info), 1);
447 + SEND_STDERR("REL, SYMBOL, LOAD: ");
448 + SEND_ADDRESS_STDERR(reloc_addr, 0);
449 + SEND_STDERR(", ");
450 + SEND_ADDRESS_STDERR(symbol_addr, 0);
451 + SEND_STDERR(", ");
452 + SEND_ADDRESS_STDERR(load_addr, 1);
453 + _dl_exit(1);
454 + }
455 +}
456 +
457 +/* Transfer control to the user's application, once the dynamic loader
458 + * is done. This routine has to exit the current function, then call
459 + * the _dl_elf_main function.
460 + *
461 + * Since our _dl_boot will simply call whatever is returned by
462 + * _dl_boot2, we can just return the address we're supposed to
463 + * call. */
464 +#define START() return _dl_elf_main;
465 diff --git a/ldso/ldso/avr32/dl-syscalls.h b/ldso/ldso/avr32/dl-syscalls.h
466 new file mode 100644
467 index 0000000..996bb87
468 --- /dev/null
469 +++ b/ldso/ldso/avr32/dl-syscalls.h
470 @@ -0,0 +1,6 @@
471 +/* We can't use the real errno in ldso, since it has not yet
472 + * been dynamicly linked in yet. */
473 +#include "sys/syscall.h"
474 +extern int _dl_errno;
475 +#undef __set_errno
476 +#define __set_errno(X) {(_dl_errno) = (X);}
477 diff --git a/ldso/ldso/avr32/dl-sysdep.h b/ldso/ldso/avr32/dl-sysdep.h
478 new file mode 100644
479 index 0000000..1a30172
480 --- /dev/null
481 +++ b/ldso/ldso/avr32/dl-sysdep.h
482 @@ -0,0 +1,105 @@
483 +/*
484 + * Various assembly language/system dependent hacks that are required
485 + * so that we can minimize the amount of platform specific code.
486 + *
487 + * Copyright (C) 2004-2007 Atmel Corporation
488 + *
489 + * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
490 + */
491 +
492 +/* Define this if the system uses RELOCA. */
493 +#define ELF_USES_RELOCA
494 +
495 +#include <elf.h>
496 +
497 +#define ARCH_NUM 1
498 +#define DT_AVR32_GOTSZ_IDX (DT_NUM + OS_NUM)
499 +
500 +#define ARCH_DYNAMIC_INFO(dpnt, dynamic, debug_addr) \
501 + do { \
502 + if (dpnt->d_tag == DT_AVR32_GOTSZ) \
503 + dynamic[DT_AVR32_GOTSZ_IDX] = dpnt->d_un.d_val; \
504 + } while (0)
505 +
506 +/* Initialization sequence for the application/library GOT. */
507 +#define INIT_GOT(GOT_BASE,MODULE) \
508 + do { \
509 + unsigned long i, nr_got; \
510 + \
511 + GOT_BASE[0] = (unsigned long) _dl_linux_resolve; \
512 + GOT_BASE[1] = (unsigned long) MODULE; \
513 + \
514 + /* Add load address displacement to all GOT entries */ \
515 + nr_got = MODULE->dynamic_info[DT_AVR32_GOTSZ_IDX] / 4; \
516 + for (i = 2; i < nr_got; i++) \
517 + GOT_BASE[i] += (unsigned long)MODULE->loadaddr; \
518 + } while (0)
519 +
520 +#define do_rem(result, n, base) ((result) = (n) % (base))
521 +
522 +/* Here we define the magic numbers that this dynamic loader should accept */
523 +#define MAGIC1 EM_AVR32
524 +#undef MAGIC2
525 +
526 +/* Used for error messages */
527 +#define ELF_TARGET "AVR32"
528 +
529 +unsigned long _dl_linux_resolver(unsigned long got_offset, unsigned long *got);
530 +
531 +/* 4096 bytes alignment */
532 +#define PAGE_ALIGN 0xfffff000
533 +#define ADDR_ALIGN 0xfff
534 +#define OFFS_ALIGN 0x7ffff000
535 +
536 +#define elf_machine_type_class(type) \
537 + ((type == R_AVR32_JMP_SLOT) * ELF_RTYPE_CLASS_PLT)
538 +
539 +/* AVR32 doesn't need any COPY relocs */
540 +#define DL_NO_COPY_RELOCS
541 +
542 +/* Return the link-time address of _DYNAMIC. Conveniently, this is the
543 + first element of the GOT. This must be inlined in a function which
544 + uses global data. */
545 +static inline Elf32_Addr
546 +elf_machine_dynamic (void)
547 +{
548 + register Elf32_Addr *got asm ("r6");
549 + return *got;
550 +}
551 +
552 +/* Return the run-time load address of the shared object. */
553 +static inline Elf32_Addr
554 +elf_machine_load_address (void)
555 +{
556 + extern void __dl_start asm("_dl_start");
557 + Elf32_Addr got_addr = (Elf32_Addr) &__dl_start;
558 + Elf32_Addr pcrel_addr;
559 +
560 + asm (" lddpc %0, 2f\n"
561 + "1: add %0, pc\n"
562 + " rjmp 3f\n"
563 + " .align 2\n"
564 + "2: .long _dl_start - 1b\n"
565 + "3:\n"
566 + : "=r"(pcrel_addr) : : "cc");
567 +
568 + return pcrel_addr - got_addr;
569 +}
570 +
571 +/*
572 + * Perform any RELATIVE relocations specified by DT_RELCOUNT.
573 + * Currently, we don't use that tag, but we might in the future as
574 + * this would reduce the startup time somewhat (although probably not by much).
575 + */
576 +static inline void
577 +elf_machine_relative (Elf32_Addr load_off, const Elf32_Addr rel_addr,
578 + Elf32_Word relative_count)
579 +{
580 + Elf32_Rela *rpnt = (void *)rel_addr;
581 +
582 + do {
583 + Elf32_Addr *reloc_addr;
584 + reloc_addr = (void *)(load_off + (rpnt++)->r_offset);
585 + *reloc_addr = load_off + rpnt->r_addend;
586 + } while (--relative_count);
587 +}
588 diff --git a/ldso/ldso/avr32/elfinterp.c b/ldso/ldso/avr32/elfinterp.c
589 new file mode 100644
590 index 0000000..196292b
591 --- /dev/null
592 +++ b/ldso/ldso/avr32/elfinterp.c
593 @@ -0,0 +1,191 @@
594 +/*
595 + * AVR32 ELF shared library loader suppport
596 + *
597 + * Copyright (C) 2004-2006 Atmel Corporation
598 + *
599 + * All rights reserved.
600 + *
601 + * Redistribution and use in source and binary forms, with or without
602 + * modification, are permitted provided that the following conditions
603 + * are met:
604 + * 1. Redistributions of source code must retain the above copyright
605 + * notice, this list of conditions and the following disclaimer.
606 + * 2. The name of the above contributors may not be
607 + * used to endorse or promote products derived from this software
608 + * without specific prior written permission.
609 + *
610 + * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND
611 + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
612 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
613 + * ARE DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE
614 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
615 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
616 + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
617 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
618 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
619 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
620 + * SUCH DAMAGE.
621 + */
622 +
623 +unsigned long _dl_linux_resolver(unsigned long got_offset, unsigned long *got)
624 +{
625 + struct elf_resolve *tpnt = (struct elf_resolve *)got[1];
626 + Elf32_Sym *sym;
627 + unsigned long local_gotno;
628 + unsigned long gotsym;
629 + unsigned long new_addr;
630 + char *strtab, *symname;
631 + unsigned long *entry;
632 + unsigned long sym_index = got_offset / 4;
633 +
634 +#if 0
635 + local_gotno = tpnt->dynamic_info[DT_AVR32_LOCAL_GOTNO];
636 + gotsym = tpnt->dynamic_info[DT_AVR32_GOTSYM];
637 +
638 + sym = ((Elf32_Sym *)(tpnt->dynamic_info[DT_SYMTAB] + tpnt->loadaddr))
639 + + sym_index;
640 + strtab = (char *)(tpnt->dynamic_info[DT_STRTAB] + tpnt->loadaddr);
641 + symname = strtab + sym->st_name;
642 +
643 +#if 0
644 + new_addr = (unsigned long) _dl_find_hash(strtab + sym->st_name,
645 + tpnt->symbol_scope, tpnt,
646 + resolver);
647 +#endif
648 +
649 + entry = (unsigned long *)(got + local_gotno + sym_index - gotsym);
650 + *entry = new_addr;
651 +#endif
652 +
653 + return new_addr;
654 +}
655 +
656 +static int
657 +_dl_parse(struct elf_resolve *tpnt, struct dyn_elf *scope,
658 + unsigned long rel_addr, unsigned long rel_size,
659 + int (*reloc_func)(struct elf_resolve *tpnt, struct dyn_elf *scope,
660 + Elf32_Rela *rpnt, Elf32_Sym *symtab, char *strtab))
661 +{
662 + Elf32_Sym *symtab;
663 + Elf32_Rela *rpnt;
664 + char *strtab;
665 + int i;
666 +
667 + rpnt = (Elf32_Rela *)rel_addr;
668 + rel_size /= sizeof(Elf32_Rela);
669 + symtab = (Elf32_Sym *)tpnt->dynamic_info[DT_SYMTAB];
670 + strtab = (char *)tpnt->dynamic_info[DT_STRTAB];
671 +
672 + for (i = 0; i < rel_size; i++, rpnt++) {
673 + int symtab_index, res;
674 +
675 + symtab_index = ELF32_R_SYM(rpnt->r_info);
676 +
677 + debug_sym(symtab, strtab, symtab_index);
678 + debug_reloc(symtab, strtab, rpnt);
679 +
680 + res = reloc_func(tpnt, scope, rpnt, symtab, strtab);
681 +
682 + if (res == 0)
683 + continue;
684 +
685 + _dl_dprintf(2, "\n%s: ", _dl_progname);
686 +
687 + if (symtab_index)
688 + _dl_dprintf(2, "symbol '%s': ",
689 + strtab + symtab[symtab_index].st_name);
690 +
691 + if (res < 0) {
692 + int reloc_type = ELF32_R_TYPE(rpnt->r_info);
693 +#if defined(__SUPPORT_LD_DEBUG__)
694 + _dl_dprintf(2, "can't handle reloc type %s\n",
695 + _dl_reltypes(reloc_type));
696 +#else
697 + _dl_dprintf(2, "can't handle reloc type %x\n",
698 + reloc_type);
699 +#endif
700 + _dl_exit(-res);
701 + } else {
702 + _dl_dprintf(2, "can't resolve symbol\n");
703 + return res;
704 + }
705 + }
706 +
707 + return 0;
708 +}
709 +
710 +static int _dl_do_reloc(struct elf_resolve *tpnt, struct dyn_elf *scope,
711 + Elf32_Rela *rpnt, Elf32_Sym *symtab, char *strtab)
712 +{
713 + int reloc_type;
714 + int symtab_index;
715 + char *symname;
716 + unsigned long *reloc_addr;
717 + unsigned long symbol_addr;
718 +#if defined(__SUPPORT_LD_DEBUG__)
719 + unsigned long old_val;
720 +#endif
721 +
722 + reloc_addr = (unsigned long *)(tpnt->loadaddr + rpnt->r_offset);
723 + reloc_type = ELF32_R_TYPE(rpnt->r_info);
724 + symtab_index = ELF32_R_SYM(rpnt->r_info);
725 + symbol_addr = 0;
726 + symname = strtab + symtab[symtab_index].st_name;
727 +
728 + if (symtab_index) {
729 + symbol_addr = (unsigned long)
730 + _dl_find_hash(strtab + symtab[symtab_index].st_name,
731 + tpnt->symbol_scope, tpnt,
732 + elf_machine_type_class(reloc_type));
733 +
734 + /* Allow undefined references to weak symbols */
735 + if (!symbol_addr &&
736 + ELF32_ST_BIND(symtab[symtab_index].st_info) != STB_WEAK) {
737 + _dl_dprintf(2, "%s: can't resolve symbol '%s'\n",
738 + _dl_progname, symname);
739 + return 0;
740 + }
741 + }
742 +
743 +#if defined(__SUPPORT_LD_DEBUG__)
744 + old_val = *reloc_addr;
745 +#endif
746 + switch (reloc_type) {
747 + case R_AVR32_NONE:
748 + break;
749 + case R_AVR32_GLOB_DAT:
750 + case R_AVR32_JMP_SLOT:
751 + *reloc_addr = symbol_addr + rpnt->r_addend;
752 + break;
753 + case R_AVR32_RELATIVE:
754 + *reloc_addr = (unsigned long)tpnt->loadaddr
755 + + rpnt->r_addend;
756 + break;
757 + default:
758 + return -1;
759 + }
760 +
761 +#if defined(__SUPPORT_LD_DEBUG__)
762 + if (_dl_debug_reloc && _dl_debug_detail)
763 + _dl_dprintf(_dl_debug_file, "\tpatched: %x ==> %x @ %x\n",
764 + old_val, *reloc_addr);
765 +#endif
766 +
767 + return 0;
768 +}
769 +
770 +void _dl_parse_lazy_relocation_information(struct dyn_elf *rpnt,
771 + unsigned long rel_addr,
772 + unsigned long rel_size)
773 +{
774 + /* TODO: Might want to support this in order to get faster
775 + * startup times... */
776 +}
777 +
778 +int _dl_parse_relocation_information(struct dyn_elf *rpnt,
779 + unsigned long rel_addr,
780 + unsigned long rel_size)
781 +{
782 + return _dl_parse(rpnt->dyn, rpnt->dyn->symbol_scope, rel_addr, rel_size,
783 + _dl_do_reloc);
784 +}
785 diff --git a/ldso/ldso/avr32/resolve.S b/ldso/ldso/avr32/resolve.S
786 new file mode 100644
787 index 0000000..e3cb7f4
788 --- /dev/null
789 +++ b/ldso/ldso/avr32/resolve.S
790 @@ -0,0 +1,28 @@
791 +/*
792 + * Linux dynamic resolving code for AVR32. Fixes up the GOT entry as
793 + * indicated in register r12 and jumps to the resolved address.
794 + *
795 + * This file is subject to the terms and conditions of the GNU Lesser General
796 + * Public License. See the file "COPYING.LIB" in the main directory of this
797 + * archive for more details.
798 + *
799 + * Copyright (C) 2004-2007 Atmel Corporation
800 + */
801 +
802 +#define ip r5
803 +
804 + .text
805 + .global _dl_linux_resolve
806 + .type _dl_linux_resolve,@function
807 +_dl_linux_resolve:
808 + /* The PLT code pushed r8 for us. It contains the address of this
809 + function's GOT entry, that is entry 0. ip contains the address
810 + of the GOT entry of the function we wanted to call. */
811 + stm --sp, r9-r12, lr
812 + mov r11, r8
813 + sub r12, ip, r8
814 + rcall _dl_linux_resolver
815 + mov ip, r12
816 + popm r8-r12,lr
817 + mov pc, ip
818 + .size _dl_linux_resolve, . - _dl_linux_resolve
819 diff --git a/ldso/ldso/dl-startup.c b/ldso/ldso/dl-startup.c
820 index 5cf1d04..d4294ec 100644
821 --- a/ldso/ldso/dl-startup.c
822 +++ b/ldso/ldso/dl-startup.c
823 @@ -217,7 +217,9 @@ DL_START(unsigned long args)
824 /* some arches (like MIPS) we have to tweak the GOT before relocations */
825 PERFORM_BOOTSTRAP_GOT(tpnt);
826
827 -#else
828 +#endif
829 +
830 +#if !defined(PERFORM_BOOTSTRAP_GOT) || defined(__avr32__)
831
832 /* OK, now do the relocations. We do not do a lazy binding here, so
833 that once we are done, we have considerably more flexibility. */
834 diff --git a/libc/inet/resolv.c b/libc/inet/resolv.c
835 index f4e6cac..9cdc3fe 100644
836 --- a/libc/inet/resolv.c
837 +++ b/libc/inet/resolv.c
838 @@ -1643,7 +1643,7 @@ int attribute_hidden __read_etc_hosts_r(FILE * fp, const char * name, int type,
839 *result=result_buf;
840 ret=NETDB_SUCCESS;
841 #ifdef __UCLIBC_HAS_IPV6__
842 - } else if (type == AF_INET6 && inet_pton(AF_INET6, alias[0], in6) > 0) {
843 + } else if (type == AF_INET6 && inet_pton(AF_INET6, alias[0], in6) > 0) {
844 DPRINTF("Found INET6\n");
845 addr_list6[0] = in6;
846 addr_list6[1] = 0;
847 @@ -1658,8 +1658,8 @@ int attribute_hidden __read_etc_hosts_r(FILE * fp, const char * name, int type,
848 } else {
849 DPRINTF("Error\n");
850 ret=TRY_AGAIN;
851 - break; /* bad ip address */
852 - }
853 + continue; /* bad ip address, keep searching */
854 + }
855
856 if (action!=GETHOSTENT) {
857 fclose(fp);
858 diff --git a/libc/string/avr32/Makefile b/libc/string/avr32/Makefile
859 new file mode 100644
860 index 0000000..e19e9d9
861 --- /dev/null
862 +++ b/libc/string/avr32/Makefile
863 @@ -0,0 +1,26 @@
864 +# Makefile for uClibc
865 +#
866 +# Copyright (C) 2000-2003 Erik Andersen <andersen@uclibc.org>
867 +#
868 +# This program is free software; you can redistribute it and/or modify it under
869 +# the terms of the GNU Library General Public License as published by the Free
870 +# Software Foundation; either version 2 of the License, or (at your option) any
871 +# later version.
872 +#
873 +# This program is distributed in the hope that it will be useful, but WITHOUT
874 +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
875 +# FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more
876 +# details.
877 +#
878 +# You should have received a copy of the GNU Library General Public License
879 +# along with this program; if not, write to the Free Software Foundation, Inc.,
880 +# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
881 +
882 +top_srcdir := ../../../
883 +top_builddir := ../../../
884 +
885 +all: objs
886 +
887 +include $(top_builddir)Rules.mak
888 +include ../Makefile.in
889 +include $(top_srcdir)Makerules
890 diff --git a/libc/string/avr32/bcopy.S b/libc/string/avr32/bcopy.S
891 new file mode 100644
892 index 0000000..87c1e04
893 --- /dev/null
894 +++ b/libc/string/avr32/bcopy.S
895 @@ -0,0 +1,26 @@
896 +/*
897 + * Copyright (C) 2004-2007 Atmel Corporation
898 + *
899 + * This file is subject to the terms and conditions of the GNU Lesser General
900 + * Public License. See the file "COPYING.LIB" in the main directory of this
901 + * archive for more details.
902 + */
903 +
904 +#include <features.h>
905 +
906 +#ifdef __UCLIBC_SUSV3_LEGACY__
907 +
908 + .text
909 + .global bcopy
910 + .type bcopy, @function
911 + .align 1
912 +bcopy:
913 + /* Swap the first two arguments */
914 + eor r11, r12
915 + eor r12, r11
916 + eor r11, r12
917 + rjmp __GI_memmove
918 +
919 + .size bcopy, . - bcopy
920 +
921 +#endif /* __UCLIBC_SUSV3_LEGACY__ */
922 diff --git a/libc/string/avr32/bzero.S b/libc/string/avr32/bzero.S
923 new file mode 100644
924 index 0000000..c999e65
925 --- /dev/null
926 +++ b/libc/string/avr32/bzero.S
927 @@ -0,0 +1,22 @@
928 +/*
929 + * Copyright (C) 2004-2007 Atmel Corporation
930 + *
931 + * This file is subject to the terms and conditions of the GNU Lesser General
932 + * Public License. See the file "COPYING.LIB" in the main directory of this
933 + * archive for more details.
934 + */
935 +
936 +#ifdef __UCLIBC_SUSV3_LEGACY__
937 +
938 + .text
939 + .global bzero
940 + .type bzero, @function
941 + .align 1
942 +bzero:
943 + mov r10, r11
944 + mov r11, 0
945 + rjmp __memset
946 +
947 + .size bzero, . - bzero
948 +
949 +#endif /* __UCLIBC_SUSV3_LEGACY__ */
950 diff --git a/libc/string/avr32/memcmp.S b/libc/string/avr32/memcmp.S
951 new file mode 100644
952 index 0000000..ae6cc91
953 --- /dev/null
954 +++ b/libc/string/avr32/memcmp.S
955 @@ -0,0 +1,61 @@
956 +/*
957 + * Copyright (C) 2004-2007 Atmel Corporation
958 + *
959 + * This file is subject to the terms and conditions of the GNU Lesser General
960 + * Public License. See the file "COPYING.LIB" in the main directory of this
961 + * archive for more details.
962 + */
963 +
964 +#include <features.h>
965 +
966 +#define s1 r12
967 +#define s2 r11
968 +#define len r10
969 +
970 + .text
971 + .global memcmp
972 + .type memcmp, @function
973 + .align 1
974 +memcmp:
975 + sub len, 4
976 + brlt .Lless_than_4
977 +
978 +1: ld.w r8, s1++
979 + ld.w r9, s2++
980 + cp.w r8, r9
981 + brne .Lfound_word
982 + sub len, 4
983 + brge 1b
984 +
985 +.Lless_than_4:
986 + sub len, -4
987 + reteq 0
988 +
989 +1: ld.ub r8, s1++
990 + ld.ub r9, s2++
991 + sub r8, r9
992 + retne r8
993 + sub len, 1
994 + brgt 1b
995 +
996 + retal 0
997 +
998 +.Lfound_word:
999 + mov len, 4
1000 +
1001 +2: bfextu r11, r9, 24, 8
1002 + bfextu r12, r8, 24, 8
1003 + sub r12, r11
1004 + retne r12
1005 + lsl r8, 8
1006 + lsl r9, 8
1007 + sub len, 1
1008 + brne 2b
1009 + retal r12
1010 +
1011 + .size memcmp, . - memcmp
1012 +
1013 +libc_hidden_def(memcmp)
1014 +#ifdef __UCLIBC_SUSV3_LEGACY__
1015 +strong_alias(memcmp,bcmp)
1016 +#endif
1017 diff --git a/libc/string/avr32/memcpy.S b/libc/string/avr32/memcpy.S
1018 new file mode 100644
1019 index 0000000..bf091ab
1020 --- /dev/null
1021 +++ b/libc/string/avr32/memcpy.S
1022 @@ -0,0 +1,111 @@
1023 +/*
1024 + * Copyright (C) 2004-2007 Atmel Corporation
1025 + *
1026 + * This file is subject to the terms and conditions of the GNU Lesser General
1027 + * Public License. See the file "COPYING.LIB" in the main directory of this
1028 + * archive for more details.
1029 + */
1030 +
1031 +/* Don't use r12 as dst since we must return it unmodified */
1032 +#define dst r9
1033 +#define src r11
1034 +#define len r10
1035 +
1036 + .text
1037 + .global memcpy
1038 + .type memcpy, @function
1039 +memcpy:
1040 + pref src[0]
1041 + mov dst, r12
1042 +
1043 + /* If we have less than 32 bytes, don't do anything fancy */
1044 + cp.w len, 32
1045 + brge .Lmore_than_31
1046 +
1047 + sub len, 1
1048 + retlt r12
1049 +1: ld.ub r8, src++
1050 + st.b dst++, r8
1051 + sub len, 1
1052 + brge 1b
1053 + retal r12
1054 +
1055 +.Lmore_than_31:
1056 + pushm r0-r7, lr
1057 +
1058 + /* Check alignment */
1059 + mov r8, src
1060 + andl r8, 31, COH
1061 + brne .Lunaligned_src
1062 + mov r8, dst
1063 + andl r8, 3, COH
1064 + brne .Lunaligned_dst
1065 +
1066 +.Laligned_copy:
1067 + sub len, 32
1068 + brlt .Lless_than_32
1069 +
1070 +1: /* Copy 32 bytes at a time */
1071 + ldm src, r0-r7
1072 + sub src, -32
1073 + stm dst, r0-r7
1074 + sub dst, -32
1075 + sub len, 32
1076 + brge 1b
1077 +
1078 +.Lless_than_32:
1079 + /* Copy 16 more bytes if possible */
1080 + sub len, -16
1081 + brlt .Lless_than_16
1082 + ldm src, r0-r3
1083 + sub src, -16
1084 + sub len, 16
1085 + stm dst, r0-r3
1086 + sub dst, -16
1087 +
1088 +.Lless_than_16:
1089 + /* Do the remaining as byte copies */
1090 + neg len
1091 + add pc, pc, len << 2
1092 + .rept 15
1093 + ld.ub r0, src++
1094 + st.b dst++, r0
1095 + .endr
1096 +
1097 + popm r0-r7, pc
1098 +
1099 +.Lunaligned_src:
1100 + /* Make src cacheline-aligned. r8 = (src & 31) */
1101 + rsub r8, r8, 32
1102 + sub len, r8
1103 +1: ld.ub r0, src++
1104 + st.b dst++, r0
1105 + sub r8, 1
1106 + brne 1b
1107 +
1108 + /* If dst is word-aligned, we're ready to go */
1109 + pref src[0]
1110 + mov r8, 3
1111 + tst dst, r8
1112 + breq .Laligned_copy
1113 +
1114 +.Lunaligned_dst:
1115 + /* src is aligned, but dst is not. Expect bad performance */
1116 + sub len, 4
1117 + brlt 2f
1118 +1: ld.w r0, src++
1119 + st.w dst++, r0
1120 + sub len, 4
1121 + brge 1b
1122 +
1123 +2: neg len
1124 + add pc, pc, len << 2
1125 + .rept 3
1126 + ld.ub r0, src++
1127 + st.b dst++, r0
1128 + .endr
1129 +
1130 + popm r0-r7, pc
1131 + .size memcpy, . - memcpy
1132 +
1133 +libc_hidden_def(memcpy)
1134 diff --git a/libc/string/avr32/memmove.S b/libc/string/avr32/memmove.S
1135 new file mode 100644
1136 index 0000000..98287c5
1137 --- /dev/null
1138 +++ b/libc/string/avr32/memmove.S
1139 @@ -0,0 +1,116 @@
1140 +/*
1141 + * Copyright (C) 2004-2007 Atmel Corporation
1142 + *
1143 + * This file is subject to the terms and conditions of the GNU Lesser General
1144 + * Public License. See the file "COPYING.LIB" in the main directory of this
1145 + * archive for more details.
1146 + */
1147 +
1148 +#define dst r12
1149 +#define src r11
1150 +#define len r10
1151 +
1152 + .text
1153 + .global memmove
1154 + .type memmove, @function
1155 +memmove:
1156 + cp.w src, dst
1157 + brge __GI_memcpy
1158 +
1159 + add dst, len
1160 + add src, len
1161 + pref src[-1]
1162 +
1163 + /*
1164 + * The rest is basically the same as in memcpy.S except that
1165 + * the direction is reversed.
1166 + */
1167 + cp.w len, 32
1168 + brge .Lmore_than_31
1169 +
1170 + sub len, 1
1171 + retlt r12
1172 +1: ld.ub r8, --src
1173 + st.b --dst, r8
1174 + sub len, 1
1175 + brge 1b
1176 + retal r12
1177 +
1178 +.Lmore_than_31:
1179 + pushm r0-r7, lr
1180 +
1181 + /* Check alignment */
1182 + mov r8, src
1183 + andl r8, 31, COH
1184 + brne .Lunaligned_src
1185 + mov r8, r12
1186 + andl r8, 3, COH
1187 + brne .Lunaligned_dst
1188 +
1189 +.Laligned_copy:
1190 + sub len, 32
1191 + brlt .Lless_than_32
1192 +
1193 +1: /* Copy 32 bytes at a time */
1194 + sub src, 32
1195 + ldm src, r0-r7
1196 + sub dst, 32
1197 + sub len, 32
1198 + stm dst, r0-r7
1199 + brge 1b
1200 +
1201 +.Lless_than_32:
1202 + /* Copy 16 more bytes if possible */
1203 + sub len, -16
1204 + brlt .Lless_than_16
1205 + sub src, 16
1206 + ldm src, r0-r3
1207 + sub dst, 16
1208 + sub len, 16
1209 + stm dst, r0-r3
1210 +
1211 +.Lless_than_16:
1212 + /* Do the remaining as byte copies */
1213 + sub len, -16
1214 + breq 2f
1215 +1: ld.ub r0, --src
1216 + st.b --dst, r0
1217 + sub len, 1
1218 + brne 1b
1219 +
1220 +2: popm r0-r7, pc
1221 +
1222 +.Lunaligned_src:
1223 + /* Make src cacheline-aligned. r8 = (src & 31) */
1224 + sub len, r8
1225 +1: ld.ub r0, --src
1226 + st.b --dst, r0
1227 + sub r8, 1
1228 + brne 1b
1229 +
1230 + /* If dst is word-aligned, we're ready to go */
1231 + pref src[-4]
1232 + mov r8, 3
1233 + tst dst, r8
1234 + breq .Laligned_copy
1235 +
1236 +.Lunaligned_dst:
1237 + /* src is aligned, but dst is not. Expect bad performance */
1238 + sub len, 4
1239 + brlt 2f
1240 +1: ld.w r0, --src
1241 + st.w --dst, r0
1242 + sub len, 4
1243 + brge 1b
1244 +
1245 +2: neg len
1246 + add pc, pc, len << 2
1247 + .rept 3
1248 + ld.ub r0, --src
1249 + st.b --dst, r0
1250 + .endr
1251 +
1252 + popm r0-r7, pc
1253 + .size memmove, . - memmove
1254 +
1255 +libc_hidden_def(memmove)
1256 diff --git a/libc/string/avr32/memset.S b/libc/string/avr32/memset.S
1257 new file mode 100644
1258 index 0000000..33cfaed
1259 --- /dev/null
1260 +++ b/libc/string/avr32/memset.S
1261 @@ -0,0 +1,70 @@
1262 +/*
1263 + * Copyright (C) 2004-2007 Atmel Corporation
1264 + *
1265 + * This file is subject to the terms and conditions of the GNU Lesser General
1266 + * Public License. See the file "COPYING.LIB" in the main directory of this
1267 + * archive for more details.
1268 + */
1269 +
1270 +#include <features.h>
1271 +
1272 +#define s r12
1273 +#define c r11
1274 +#define n r10
1275 +
1276 + .text
1277 + .global memset
1278 + .type memset, @function
1279 +
1280 + .global __memset
1281 + .hidden __memset
1282 + .type __memset, @function
1283 +
1284 + .align 1
1285 +memset:
1286 +__memset:
1287 + cp.w n, 32
1288 + mov r9, s
1289 + brge .Llarge_memset
1290 +
1291 + sub n, 1
1292 + retlt s
1293 +1: st.b s++, c
1294 + sub n, 1
1295 + brge 1b
1296 +
1297 + retal r9
1298 +
1299 +.Llarge_memset:
1300 + mov r8, r11
1301 + mov r11, 3
1302 + bfins r8, r8, 8, 8
1303 + bfins r8, r8, 16, 16
1304 + tst s, r11
1305 + breq 2f
1306 +
1307 +1: st.b s++, r8
1308 + sub n, 1
1309 + tst s, r11
1310 + brne 1b
1311 +
1312 +2: mov r11, r9
1313 + mov r9, r8
1314 + sub n, 8
1315 +
1316 +3: st.d s++, r8
1317 + sub n, 8
1318 + brge 3b
1319 +
1320 + /* If we are done, n == -8 and we'll skip all st.b insns below */
1321 + neg n
1322 + lsl n, 1
1323 + add pc, n
1324 + .rept 7
1325 + st.b s++, r8
1326 + .endr
1327 + retal r11
1328 +
1329 + .size memset, . - memset
1330 +
1331 +libc_hidden_def(memset)
1332 diff --git a/libc/string/avr32/strcmp.S b/libc/string/avr32/strcmp.S
1333 new file mode 100644
1334 index 0000000..f73bd43
1335 --- /dev/null
1336 +++ b/libc/string/avr32/strcmp.S
1337 @@ -0,0 +1,91 @@
1338 +/*
1339 + * Copyright (C) 2004-2007 Atmel Corporation
1340 + *
1341 + * This file is subject to the terms and conditions of the GNU Lesser General
1342 + * Public License. See the file "COPYING.LIB" in the main directory of this
1343 + * archive for more details.
1344 + */
1345 +
1346 +#include <features.h>
1347 +
1348 +#define s1 r12
1349 +#define s2 r11
1350 +#define len r10
1351 +
1352 + .text
1353 + .global strcmp
1354 + .type strcmp, @function
1355 + .align 1
1356 +strcmp:
1357 + mov r8, 3
1358 + tst s1, r8
1359 + brne .Lunaligned_s1
1360 + tst s2, r8
1361 + brne .Lunaligned_s2
1362 +
1363 +1: ld.w r8, s1++
1364 + ld.w r9, s2++
1365 + cp.w r8, r9
1366 + brne 2f
1367 + tnbz r8
1368 + brne 1b
1369 + retal 0
1370 +
1371 +2: bfextu r12, r8, 24, 8
1372 + bfextu r11, r9, 24, 8
1373 + sub r12, r11
1374 + retne r12
1375 + cp.w r11, 0
1376 + reteq 0
1377 + bfextu r12, r8, 16, 8
1378 + bfextu r11, r9, 16, 8
1379 + sub r12, r11
1380 + retne r12
1381 + cp.w r11, 0
1382 + reteq 0
1383 + bfextu r12, r8, 8, 8
1384 + bfextu r11, r9, 8, 8
1385 + sub r12, r11
1386 + retne r12
1387 + cp.w r11, 0
1388 + reteq 0
1389 + bfextu r12, r8, 0, 8
1390 + bfextu r11, r9, 0, 8
1391 + sub r12, r11
1392 + retal r12
1393 +
1394 +.Lunaligned_s1:
1395 +3: tst s1, r8
1396 + breq 4f
1397 + ld.ub r10, s1++
1398 + ld.ub r9, s2++
1399 + sub r10, r9
1400 + retne r10
1401 + cp.w r9, 0
1402 + brne 3b
1403 + retal r10
1404 +
1405 +4: tst s2, r8
1406 + breq 1b
1407 +
1408 +.Lunaligned_s2:
1409 + /*
1410 + * s1 and s2 can't both be aligned, and unaligned word loads
1411 + * can trigger spurious exceptions if we cross a page boundary.
1412 + * Do it the slow way...
1413 + */
1414 +1: ld.ub r8, s1++
1415 + ld.ub r9, s2++
1416 + sub r8, r9
1417 + retne r8
1418 + cp.w r9, 0
1419 + brne 1b
1420 + retal 0
1421 +
1422 + .size strcmp, . - strcmp
1423 +
1424 +libc_hidden_def(strcmp)
1425 +#ifndef __UCLIBC_HAS_LOCALE__
1426 +strong_alias(strcmp, strcoll)
1427 +libc_hidden_def(strcoll)
1428 +#endif
1429 diff --git a/libc/string/avr32/strlen.S b/libc/string/avr32/strlen.S
1430 new file mode 100644
1431 index 0000000..5223e53
1432 --- /dev/null
1433 +++ b/libc/string/avr32/strlen.S
1434 @@ -0,0 +1,62 @@
1435 +/*
1436 + * Copyright (C) 2004-2007 Atmel Corporation
1437 + *
1438 + * This file is subject to the terms and conditions of the GNU Lesser General
1439 + * Public License. See the file "COPYING.LIB" in the main directory of this
1440 + * archive for more details.
1441 + */
1442 +
1443 +#include <features.h>
1444 +
1445 +#define str r12
1446 +
1447 + .text
1448 + .global strlen
1449 + .type strlen, @function
1450 +strlen:
1451 + mov r11, r12
1452 +
1453 + mov r9, str
1454 + andl r9, 3, COH
1455 + brne .Lunaligned_str
1456 +
1457 +1: ld.w r8, str++
1458 + tnbz r8
1459 + brne 1b
1460 +
1461 + sub r12, r11
1462 + bfextu r9, r8, 24, 8
1463 + cp.w r9, 0
1464 + subeq r12, 4
1465 + reteq r12
1466 + bfextu r9, r8, 16, 8
1467 + cp.w r9, 0
1468 + subeq r12, 3
1469 + reteq r12
1470 + bfextu r9, r8, 8, 8
1471 + cp.w r9, 0
1472 + subeq r12, 2
1473 + reteq r12
1474 + sub r12, 1
1475 + retal r12
1476 +
1477 +.Lunaligned_str:
1478 + add pc, pc, r9 << 3
1479 + sub r0, r0, 0 /* 4-byte nop */
1480 + ld.ub r8, str++
1481 + sub r8, r8, 0
1482 + breq 1f
1483 + ld.ub r8, str++
1484 + sub r8, r8, 0
1485 + breq 1f
1486 + ld.ub r8, str++
1487 + sub r8, r8, 0
1488 + brne 1b
1489 +
1490 +1: sub r12, 1
1491 + sub r12, r11
1492 + retal r12
1493 +
1494 + .size strlen, . - strlen
1495 +
1496 +libc_hidden_def(strlen)
1497 diff --git a/libc/sysdeps/linux/avr32/Makefile b/libc/sysdeps/linux/avr32/Makefile
1498 new file mode 100644
1499 index 0000000..338abc0
1500 --- /dev/null
1501 +++ b/libc/sysdeps/linux/avr32/Makefile
1502 @@ -0,0 +1,25 @@
1503 +# Makefile for uClibc
1504 +#
1505 +# Copyright (C) 2000-2003 Erik Andersen <andersen@uclibc.org>
1506 +#
1507 +# This program is free software; you can redistribute it and/or modify it under
1508 +# the terms of the GNU Library General Public License as published by the Free
1509 +# Software Foundation; either version 2 of the License, or (at your option) any
1510 +# later version.
1511 +#
1512 +# This program is distributed in the hope that it will be useful, but WITHOUT
1513 +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
1514 +# FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more
1515 +# details.
1516 +#
1517 +# You should have received a copy of the GNU Library General Public License
1518 +# along with this program; if not, write to the Free Software Foundation, Inc.,
1519 +# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1520 +
1521 +top_srcdir=../../../../
1522 +top_builddir=../../../../
1523 +all: objs
1524 +
1525 +include $(top_builddir)Rules.mak
1526 +include Makefile.arch
1527 +include $(top_srcdir)Makerules
1528 diff --git a/libc/sysdeps/linux/avr32/Makefile.arch b/libc/sysdeps/linux/avr32/Makefile.arch
1529 new file mode 100644
1530 index 0000000..44fc01e
1531 --- /dev/null
1532 +++ b/libc/sysdeps/linux/avr32/Makefile.arch
1533 @@ -0,0 +1,13 @@
1534 +# Makefile for uClibc
1535 +#
1536 +# Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
1537 +#
1538 +# Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
1539 +#
1540 +
1541 +CSRC := brk.c clone.c mmap.c sigaction.c
1542 +
1543 +SSRC := __longjmp.S setjmp.S bsd-setjmp.S bsd-_setjmp.S \
1544 + sigrestorer.S syscall.S vfork.S
1545 +
1546 +include $(top_srcdir)/libc/sysdeps/linux/Makefile.commonarch
1547 diff --git a/libc/sysdeps/linux/avr32/__longjmp.S b/libc/sysdeps/linux/avr32/__longjmp.S
1548 new file mode 100644
1549 index 0000000..6154bb2
1550 --- /dev/null
1551 +++ b/libc/sysdeps/linux/avr32/__longjmp.S
1552 @@ -0,0 +1,21 @@
1553 +/*
1554 + * Copyright (C) 2004-2007 Atmel Corporation
1555 + *
1556 + * This file is subject to the terms and conditions of the GNU Lesser General
1557 + * Public License. See the file "COPYING.LIB" in the main directory of this
1558 + * archive for more details.
1559 + */
1560 +
1561 + .global __longjmp
1562 + .type __longjmp,"function"
1563 + .align 1
1564 +__longjmp:
1565 + ldm r12++, r0-r8,sp,lr
1566 + mustr r8 /* restore status register (lower half) */
1567 + cp r11, 0 /* can't return zero */
1568 + frs
1569 + moveq r11, 1
1570 + retal r11
1571 + .size __longjmp, . - __longjmp
1572 +
1573 +libc_hidden_def(__longjmp)
1574 diff --git a/libc/sysdeps/linux/avr32/bits/atomic.h b/libc/sysdeps/linux/avr32/bits/atomic.h
1575 new file mode 100644
1576 index 0000000..e6be41f
1577 --- /dev/null
1578 +++ b/libc/sysdeps/linux/avr32/bits/atomic.h
1579 @@ -0,0 +1,120 @@
1580 +/*
1581 + * Copyright (C) 2007 Atmel Corporation
1582 + *
1583 + * This file is subject to the terms and conditions of the GNU Lesser General
1584 + * Public License. See the file "COPYING.LIB" in the main directory of this
1585 + * archive for more details.
1586 + */
1587 +#ifndef _AVR32_BITS_ATOMIC_H
1588 +#define _AVR32_BITS_ATOMIC_H 1
1589 +
1590 +#include <inttypes.h>
1591 +
1592 +typedef int32_t atomic32_t;
1593 +typedef uint32_t uatomic32_t;
1594 +typedef int_fast32_t atomic_fast32_t;
1595 +typedef uint_fast32_t uatomic_fast32_t;
1596 +
1597 +typedef intptr_t atomicptr_t;
1598 +typedef uintptr_t uatomicptr_t;
1599 +typedef intmax_t atomic_max_t;
1600 +typedef uintmax_t uatomic_max_t;
1601 +
1602 +#define __arch_compare_and_exchange_val_8_acq(mem, newval, oldval) \
1603 + (abort(), 0)
1604 +
1605 +#define __arch_compare_and_exchange_val_16_acq(mem, newval, oldval) \
1606 + (abort(), 0)
1607 +
1608 +#define __arch_compare_and_exchange_val_32_acq(mem, newval, oldval) \
1609 + ({ \
1610 + __typeof__(*(mem)) __prev; \
1611 + __asm__ __volatile__( \
1612 + "/* __arch_compare_and_exchange_val_32_acq */\n" \
1613 + "1: ssrf 5\n" \
1614 + " ld.w %[result], %[m]\n" \
1615 + " cp.w %[result], %[old]\n" \
1616 + " brne 2f\n" \
1617 + " stcond %[m], %[new]\n" \
1618 + " brne 1b\n" \
1619 + "2:" \
1620 + : [result] "=&r"(__result), [m] "=m"(*(mem)) \
1621 + : "m"(*(mem)), [old] "ir"(oldval), \
1622 + [new] "r"(newval) \
1623 + : "memory", "cc"); \
1624 + __prev; \
1625 + })
1626 +
1627 +#define __arch_compare_and_exchange_val_64_acq(mem, newval, oldval) \
1628 + (abort(), 0)
1629 +
1630 +#define __arch_exchange_32_acq(mem, newval) \
1631 + ({ \
1632 + __typeof__(*(mem)) __oldval; \
1633 + __asm__ __volatile__( \
1634 + "/*__arch_exchange_32_acq */\n" \
1635 + " xchg %[old], %[m], %[new]" \
1636 + : [old] "=&r"(__oldval) \
1637 + : [m] "r"(mem), [new] "r"(newval) \
1638 + : "memory"); \
1639 + __oldval; \
1640 + })
1641 +
1642 +#define __arch_atomic_exchange_and_add_32(mem, value) \
1643 + ({ \
1644 + __typeof__(*(mem)) __oldval, __tmp; \
1645 + __asm__ __volatile__( \
1646 + "/* __arch_atomic_exchange_and_add_32 */\n" \
1647 + "1: ssrf 5\n" \
1648 + " ld.w %[old], %[m]\n" \
1649 + " add %[tmp], %[old], %[val]\n" \
1650 + " stcond %[m], %[tmp]\n" \
1651 + " brne 1b" \
1652 + : [old] "=&r"(__oldval), [tmp] "=&r"(__tmp), \
1653 + [m] "=m"(*(mem)) \
1654 + : "m"(*(mem)), [val] "r"(value) \
1655 + : "memory", "cc"); \
1656 + __oldval; \
1657 + })
1658 +
1659 +#define __arch_atomic_decrement_if_positive_32(mem) \
1660 + ({ \
1661 + __typeof__(*(mem)) __oldval, __tmp; \
1662 + __asm__ __volatile__( \
1663 + "/* __arch_atomic_decrement_if_positive_32 */\n" \
1664 + "1: ssrf 5\n" \
1665 + " ld.w %[old], %[m]\n" \
1666 + " sub %[tmp], %[old], 1\n" \
1667 + " brlt 2f\n" \
1668 + " stcond %[m], %[tmp]\n" \
1669 + " brne 1b" \
1670 + "2:" \
1671 + : [old] "=&r"(__oldval), [tmp] "=&r"(__tmp), \
1672 + [m] "=m"(*(mem)) \
1673 + : "m"(*(mem)) \
1674 + : "memory", "cc"); \
1675 + __oldval; \
1676 + })
1677 +
1678 +#define atomic_exchange_acq(mem, newval) \
1679 + ({ \
1680 + if (sizeof(*(mem)) != 4) \
1681 + abort(); \
1682 + __arch_exchange_32_acq(mem, newval); \
1683 + })
1684 +
1685 +#define atomic_exchange_and_add(mem, newval) \
1686 + ({ \
1687 + if (sizeof(*(mem)) != 4) \
1688 + abort(); \
1689 + __arch_atomic_exchange_and_add_32(mem, newval); \
1690 + })
1691 +
1692 +#define atomic_decrement_if_positive(mem) \
1693 + ({ \
1694 + if (sizeof(*(mem)) != 4) \
1695 + abort(); \
1696 + __arch_atomic_decrement_if_positive_32(mem); \
1697 + })
1698 +
1699 +#endif /* _AVR32_BITS_ATOMIC_H */
1700 diff --git a/libc/sysdeps/linux/avr32/bits/byteswap.h b/libc/sysdeps/linux/avr32/bits/byteswap.h
1701 new file mode 100644
1702 index 0000000..1c030b9
1703 --- /dev/null
1704 +++ b/libc/sysdeps/linux/avr32/bits/byteswap.h
1705 @@ -0,0 +1,70 @@
1706 +/*
1707 + * Copyright (C) 2005 Atmel Corporation
1708 + *
1709 + * This file is subject to the terms and conditions of the GNU Lesser General
1710 + * Public License. See the file "COPYING.LIB" in the main directory of this
1711 + * archive for more details.
1712 + */
1713 +
1714 +#if !defined _BYTESWAP_H && !defined _NETINET_IN_H
1715 +# error "Never use <bits/byteswap.h> directly; include <byteswap.h> instead."
1716 +#endif
1717 +
1718 +#ifndef _BITS_BYTESWAP_H
1719 +#define _BITS_BYTESWAP_H 1
1720 +
1721 +/* Swap bytes in 16 bit value. */
1722 +#if defined __GNUC__
1723 +# define __bswap_16(x) (__extension__ __builtin_bswap_16(x))
1724 +#else
1725 +/* This is better than nothing. */
1726 +static __inline unsigned short int
1727 +__bswap_16 (unsigned short int __bsx)
1728 +{
1729 + return ((((__bsx) >> 8) & 0xff) | (((__bsx) & 0xff) << 8));
1730 +}
1731 +#endif
1732 +
1733 +/* Swap bytes in 32 bit value. */
1734 +#if defined __GNUC__
1735 +# define __bswap_32(x) (__extension__ __builtin_bswap_32(x))
1736 +#else
1737 +static __inline unsigned int
1738 +__bswap_32 (unsigned int __bsx)
1739 +{
1740 + return ((((__bsx) & 0xff000000) >> 24) | (((__bsx) & 0x00ff0000) >> 8) |
1741 + (((__bsx) & 0x0000ff00) << 8) | (((__bsx) & 0x000000ff) << 24));
1742 +}
1743 +#endif
1744 +
1745 +#if defined __GNUC__
1746 +/* Swap bytes in 64 bit value. */
1747 +# define __bswap_constant_64(x) \
1748 + ((((x) & 0xff00000000000000ull) >> 56) \
1749 + | (((x) & 0x00ff000000000000ull) >> 40) \
1750 + | (((x) & 0x0000ff0000000000ull) >> 24) \
1751 + | (((x) & 0x000000ff00000000ull) >> 8) \
1752 + | (((x) & 0x00000000ff000000ull) << 8) \
1753 + | (((x) & 0x0000000000ff0000ull) << 24) \
1754 + | (((x) & 0x000000000000ff00ull) << 40) \
1755 + | (((x) & 0x00000000000000ffull) << 56))
1756 +
1757 +# define __bswap_64(x) \
1758 + (__extension__ \
1759 + ({ \
1760 + union { \
1761 + __extension__ unsigned long long int __ll; \
1762 + unsigned int __l[2]; \
1763 + } __w, __r; \
1764 + if (__builtin_constant_p(x)) \
1765 + __r.__ll = __bswap_constant_64(x); \
1766 + else { \
1767 + __w.__ll = (x); \
1768 + __r.__l[0] = __bswap_32(__w.__l[1]); \
1769 + __r.__l[1] = __bswap_32(__w.__l[0]); \
1770 + } \
1771 + __r.__ll; \
1772 + }))
1773 +#endif
1774 +
1775 +#endif /* _BITS_BYTESWAP_H */
1776 diff --git a/libc/sysdeps/linux/avr32/bits/endian.h b/libc/sysdeps/linux/avr32/bits/endian.h
1777 new file mode 100644
1778 index 0000000..7bb6358
1779 --- /dev/null
1780 +++ b/libc/sysdeps/linux/avr32/bits/endian.h
1781 @@ -0,0 +1,7 @@
1782 +/* AVR32 is big-endian */
1783 +
1784 +#ifndef _ENDIAN_H
1785 +# error "Never use <bits/endian.h> directly; include <endian.h> instead."
1786 +#endif
1787 +
1788 +#define __BYTE_ORDER __BIG_ENDIAN
1789 diff --git a/libc/sysdeps/linux/avr32/bits/fcntl.h b/libc/sysdeps/linux/avr32/bits/fcntl.h
1790 new file mode 100644
1791 index 0000000..1abff17
1792 --- /dev/null
1793 +++ b/libc/sysdeps/linux/avr32/bits/fcntl.h
1794 @@ -0,0 +1,165 @@
1795 +#ifndef _FCNTL_H
1796 +# error "Never use <bits/fcntl.h> directly; include <fcntl.h> instead."
1797 +#endif
1798 +
1799 +#include <sys/types.h>
1800 +
1801 +/*
1802 + * open/fcntl - O_SYNC is only implemented on blocks devices and on files
1803 + * located on an ext2 file system
1804 + */
1805 +#define O_ACCMODE 00000003
1806 +#define O_RDONLY 00000000
1807 +#define O_WRONLY 00000001
1808 +#define O_RDWR 00000002
1809 +#define O_CREAT 00000100 /* not fcntl */
1810 +#define O_EXCL 00000200 /* not fcntl */
1811 +#define O_NOCTTY 00000400 /* not fcntl */
1812 +#define O_TRUNC 00001000 /* not fcntl */
1813 +#define O_APPEND 00002000
1814 +#define O_NONBLOCK 00004000
1815 +#define O_NDELAY O_NONBLOCK
1816 +#define O_SYNC 00010000
1817 +#define O_ASYNC 00020000
1818 +
1819 +#ifdef __USE_GNU
1820 +# define O_DIRECT 00040000 /* must be a directory */
1821 +# define O_DIRECTORY 00200000 /* direct disk access */
1822 +# define O_NOFOLLOW 00400000 /* don't follow links */
1823 +# define O_NOATIME 01000000 /* don't set atime */
1824 +#endif
1825 +
1826 +#ifdef __USE_LARGEFILE64
1827 +# define O_LARGEFILE 00100000
1828 +#endif
1829 +
1830 +/* For now Linux has synchronisity options for data and read operations.
1831 + We define the symbols here but let them do the same as O_SYNC since
1832 + this is a superset. */
1833 +#if defined __USE_POSIX199309 || defined __USE_UNIX98
1834 +# define O_DSYNC O_SYNC /* Synchronize data. */
1835 +# define O_RSYNC O_SYNC /* Synchronize read operations. */
1836 +#endif
1837 +
1838 +#define F_DUPFD 0 /* dup */
1839 +#define F_GETFD 1 /* get close_on_exec */
1840 +#define F_SETFD 2 /* set/clear close_on_exec */
1841 +#define F_GETFL 3 /* get file->f_flags */
1842 +#define F_SETFL 4 /* set file->f_flags */
1843 +
1844 +#ifndef __USE_FILE_OFFSET64
1845 +# define F_GETLK 5
1846 +# define F_SETLK 6
1847 +# define F_SETLKW 7
1848 +#else
1849 +# define F_GETLK F_GETLK64
1850 +# define F_SETLK F_SETLK64
1851 +# define F_SETLKW F_SETLKW64
1852 +#endif
1853 +#define F_GETLK64 12 /* using 'struct flock64' */
1854 +#define F_SETLK64 13
1855 +#define F_SETLKW64 14
1856 +
1857 +#if defined __USE_BSD || defined __USE_XOPEN2K
1858 +# define F_SETOWN 8 /* for sockets. */
1859 +# define F_GETOWN 9 /* for sockets. */
1860 +#endif
1861 +
1862 +#ifdef __USE_GNU
1863 +# define F_SETSIG 10 /* for sockets. */
1864 +# define F_GETSIG 11 /* for sockets. */
1865 +#endif
1866 +
1867 +#ifdef __USE_GNU
1868 +# define F_SETLEASE 1024 /* Set a lease. */
1869 +# define F_GETLEASE 1025 /* Enquire what lease is active. */
1870 +# define F_NOTIFY 1026 /* Request notfications on a directory. */
1871 +#endif
1872 +
1873 +/* for F_[GET|SET]FL */
1874 +#define FD_CLOEXEC 1 /* actually anything with low bit set goes */
1875 +
1876 +/* for posix fcntl() and lockf() */
1877 +#define F_RDLCK 0
1878 +#define F_WRLCK 1
1879 +#define F_UNLCK 2
1880 +
1881 +/* for old implementation of bsd flock () */
1882 +#define F_EXLCK 4 /* or 3 */
1883 +#define F_SHLCK 8 /* or 4 */
1884 +
1885 +/* for leases */
1886 +#define F_INPROGRESS 16
1887 +
1888 +#ifdef __USE_BSD
1889 +/* operations for bsd flock(), also used by the kernel implementation */
1890 +# define LOCK_SH 1 /* shared lock */
1891 +# define LOCK_EX 2 /* exclusive lock */
1892 +# define LOCK_NB 4 /* or'd with one of the above to prevent
1893 + blocking */
1894 +# define LOCK_UN 8 /* remove lock */
1895 +#endif
1896 +
1897 +#ifdef __USE_GNU
1898 +# define LOCK_MAND 32 /* This is a mandatory flock */
1899 +# define LOCK_READ 64 /* ... Which allows concurrent
1900 + read operations */
1901 +# define LOCK_WRITE 128 /* ... Which allows concurrent
1902 + write operations */
1903 +# define LOCK_RW 192 /* ... Which allows concurrent
1904 + read & write ops */
1905 +#endif
1906 +
1907 +#ifdef __USE_GNU
1908 +/* Types of directory notifications that may be requested with F_NOTIFY. */
1909 +# define DN_ACCESS 0x00000001 /* File accessed. */
1910 +# define DN_MODIFY 0x00000002 /* File modified. */
1911 +# define DN_CREATE 0x00000004 /* File created. */
1912 +# define DN_DELETE 0x00000008 /* File removed. */
1913 +# define DN_RENAME 0x00000010 /* File renamed. */
1914 +# define DN_ATTRIB 0x00000020 /* File changed attibutes. */
1915 +# define DN_MULTISHOT 0x80000000 /* Don't remove notifier. */
1916 +#endif
1917 +
1918 +struct flock {
1919 + short l_type;
1920 + short l_whence;
1921 +#ifndef __USE_FILE_OFFSET64
1922 + __off_t l_start;
1923 + __off_t l_len;
1924 +#else
1925 + __off64_t l_start;
1926 + __off64_t l_len;
1927 +#endif
1928 + __pid_t l_pid;
1929 +};
1930 +
1931 +#ifdef __USE_LARGEFILE64
1932 +struct flock64 {
1933 + short l_type;
1934 + short l_whence;
1935 + __off64_t l_start;
1936 + __off64_t l_len;
1937 + __pid_t l_pid;
1938 +};
1939 +#endif
1940 +
1941 +/* Define some more compatibility macros to be backward compatible with
1942 + * BSD systems which did not managed to hide these kernel macros. */
1943 +#ifdef __USE_BSD
1944 +# define FAPPEND O_APPEND
1945 +# define FFSYNC O_FSYNC
1946 +# define FASYNC O_ASYNC
1947 +# define FNONBLOCK O_NONBLOCK
1948 +# define FNDELAY O_NDELAY
1949 +#endif /* Use BSD. */
1950 +
1951 +/* Advise to `posix_fadvise'. */
1952 +#ifdef __USE_XOPEN2K
1953 +# define POSIX_FADV_NORMAL 0 /* No further special treatment. */
1954 +# define POSIX_FADV_RANDOM 1 /* Expect random page references. */
1955 +# define POSIX_FADV_SEQUENTIAL 2 /* Expect sequential page references. */
1956 +# define POSIX_FADV_WILLNEED 3 /* Will need these pages. */
1957 +# define POSIX_FADV_DONTNEED 4 /* Don't need these pages. */
1958 +# define POSIX_FADV_NOREUSE 5 /* Data will be accessed once. */
1959 +#endif
1960 diff --git a/libc/sysdeps/linux/avr32/bits/kernel_stat.h b/libc/sysdeps/linux/avr32/bits/kernel_stat.h
1961 new file mode 100644
1962 index 0000000..f97d23b
1963 --- /dev/null
1964 +++ b/libc/sysdeps/linux/avr32/bits/kernel_stat.h
1965 @@ -0,0 +1,67 @@
1966 +#ifndef _BITS_STAT_STRUCT_H
1967 +#define _BITS_STAT_STRUCT_H
1968 +
1969 +#ifndef _LIBC
1970 +#error bits/kernel_stat.h is for internal uClibc use only!
1971 +#endif
1972 +
1973 +/*
1974 + * This file provides struct stat, taken from kernel 2.6.4. Verified
1975 + * to match kernel 2.6.22.
1976 + */
1977 +
1978 +struct kernel_stat {
1979 + unsigned long st_dev;
1980 + unsigned long st_ino;
1981 + unsigned short st_mode;
1982 + unsigned short st_nlink;
1983 + unsigned short st_uid;
1984 + unsigned short st_gid;
1985 + unsigned long st_rdev;
1986 + unsigned long st_size;
1987 + unsigned long st_blksize;
1988 + unsigned long st_blocks;
1989 + unsigned long st_atime;
1990 + unsigned long st_atime_nsec;
1991 + unsigned long st_mtime;
1992 + unsigned long st_mtime_nsec;
1993 + unsigned long st_ctime;
1994 + unsigned long st_ctime_nsec;
1995 + unsigned long __unused4;
1996 + unsigned long __unused5;
1997 +};
1998 +
1999 +#define STAT_HAVE_NSEC 1
2000 +
2001 +struct kernel_stat64 {
2002 + unsigned long long st_dev;
2003 +
2004 + unsigned long long st_ino;
2005 + unsigned int st_mode;
2006 + unsigned int st_nlink;
2007 +
2008 + unsigned long st_uid;
2009 + unsigned long st_gid;
2010 +
2011 + unsigned long long st_rdev;
2012 +
2013 + long long st_size;
2014 + unsigned long __pad1;
2015 + unsigned long st_blksize;
2016 +
2017 + unsigned long long st_blocks;
2018 +
2019 + unsigned long st_atime;
2020 + unsigned long st_atime_nsec;
2021 +
2022 + unsigned long st_mtime;
2023 + unsigned long st_mtime_nsec;
2024 +
2025 + unsigned long st_ctime;
2026 + unsigned long st_ctime_nsec;
2027 +
2028 + unsigned long __unused1;
2029 + unsigned long __unused2;
2030 +};
2031 +
2032 +#endif /* _BITS_STAT_STRUCT_H */
2033 diff --git a/libc/sysdeps/linux/avr32/bits/kernel_types.h b/libc/sysdeps/linux/avr32/bits/kernel_types.h
2034 new file mode 100644
2035 index 0000000..f7d8b52
2036 --- /dev/null
2037 +++ b/libc/sysdeps/linux/avr32/bits/kernel_types.h
2038 @@ -0,0 +1,55 @@
2039 +/* Note that we use the exact same include guard #define names
2040 + * as asm/posix_types.h. This will avoid gratuitous conflicts
2041 + * with the posix_types.h kernel header, and will ensure that
2042 + * our private content, and not the kernel header, will win.
2043 + * -Erik
2044 + */
2045 +#ifndef __ASM_AVR32_POSIX_TYPES_H
2046 +#define __ASM_AVR32_POSIX_TYPES_H
2047 +
2048 +/*
2049 + * This file is generally used by user-level software, so you need to
2050 + * be a little careful about namespace pollution etc. Also, we cannot
2051 + * assume GCC is being used.
2052 + */
2053 +
2054 +typedef unsigned long __kernel_dev_t;
2055 +typedef unsigned long __kernel_ino_t;
2056 +typedef unsigned short __kernel_mode_t;
2057 +typedef unsigned short __kernel_nlink_t;
2058 +typedef long __kernel_off_t;
2059 +typedef int __kernel_pid_t;
2060 +typedef unsigned short __kernel_ipc_pid_t;
2061 +typedef unsigned int __kernel_uid_t;
2062 +typedef unsigned int __kernel_gid_t;
2063 +typedef unsigned long __kernel_size_t;
2064 +typedef long __kernel_ssize_t;
2065 +typedef int __kernel_ptrdiff_t;
2066 +typedef long __kernel_time_t;
2067 +typedef long __kernel_suseconds_t;
2068 +typedef long __kernel_clock_t;
2069 +typedef int __kernel_timer_t;
2070 +typedef int __kernel_clockid_t;
2071 +typedef int __kernel_daddr_t;
2072 +typedef char * __kernel_caddr_t;
2073 +typedef unsigned short __kernel_uid16_t;
2074 +typedef unsigned short __kernel_gid16_t;
2075 +typedef unsigned int __kernel_uid32_t;
2076 +typedef unsigned int __kernel_gid32_t;
2077 +typedef unsigned short __kernel_old_uid_t;
2078 +typedef unsigned short __kernel_old_gid_t;
2079 +typedef unsigned short __kernel_old_dev_t;
2080 +
2081 +#ifdef __GNUC__
2082 +typedef long long __kernel_loff_t;
2083 +#endif
2084 +
2085 +typedef struct {
2086 +#if defined(__USE_ALL)
2087 + int val[2];
2088 +#else
2089 + int __val[2];
2090 +#endif
2091 +} __kernel_fsid_t;
2092 +
2093 +#endif /* __ASM_AVR32_POSIX_TYPES_H */
2094 diff --git a/libc/sysdeps/linux/avr32/bits/mman.h b/libc/sysdeps/linux/avr32/bits/mman.h
2095 new file mode 100644
2096 index 0000000..5f6e3c3
2097 --- /dev/null
2098 +++ b/libc/sysdeps/linux/avr32/bits/mman.h
2099 @@ -0,0 +1,103 @@
2100 +/* Definitions for POSIX memory map interface. Linux/AVR32 version.
2101 + Copyright (C) 1997, 2000 Free Software Foundation, Inc.
2102 + This file is part of the GNU C Library.
2103 +
2104 + The GNU C Library is free software; you can redistribute it and/or
2105 + modify it under the terms of the GNU Lesser General Public
2106 + License as published by the Free Software Foundation; either
2107 + version 2.1 of the License, or (at your option) any later version.
2108 +
2109 + The GNU C Library is distributed in the hope that it will be useful,
2110 + but WITHOUT ANY WARRANTY; without even the implied warranty of
2111 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2112 + Lesser General Public License for more details.
2113 +
2114 + You should have received a copy of the GNU Lesser General Public
2115 + License along with the GNU C Library; if not, write to the Free
2116 + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
2117 + 02111-1307 USA. */
2118 +
2119 +#ifndef _SYS_MMAN_H
2120 +# error "Never include this file directly. Use <sys/mman.h> instead"
2121 +#endif
2122 +
2123 +/* The following definitions basically come from the kernel headers.
2124 + But the kernel header is not namespace clean. */
2125 +
2126 +
2127 +/* Protections are chosen from these bits, OR'd together. The
2128 + implementation does not necessarily support PROT_EXEC or PROT_WRITE
2129 + without PROT_READ. The only guarantees are that no writing will be
2130 + allowed without PROT_WRITE and no access will be allowed for PROT_NONE. */
2131 +
2132 +#define PROT_READ 0x1 /* Page can be read. */
2133 +#define PROT_WRITE 0x2 /* Page can be written. */
2134 +#define PROT_EXEC 0x4 /* Page can be executed. */
2135 +#define PROT_NONE 0x0 /* Page can not be accessed. */
2136 +#define PROT_GROWSDOWN 0x01000000 /* Extend change to start of
2137 + growsdown vma (mprotect only). */
2138 +#define PROT_GROWSUP 0x02000000 /* Extend change to start of
2139 + growsup vma (mprotect only). */
2140 +
2141 +/* Sharing types (must choose one and only one of these). */
2142 +#define MAP_SHARED 0x01 /* Share changes. */
2143 +#define MAP_PRIVATE 0x02 /* Changes are private. */
2144 +#ifdef __USE_MISC
2145 +# define MAP_TYPE 0x0f /* Mask for type of mapping. */
2146 +#endif
2147 +
2148 +/* Other flags. */
2149 +#define MAP_FIXED 0x10 /* Interpret addr exactly. */
2150 +#ifdef __USE_MISC
2151 +# define MAP_FILE 0
2152 +# define MAP_ANONYMOUS 0x20 /* Don't use a file. */
2153 +# define MAP_ANON MAP_ANONYMOUS
2154 +#endif
2155 +
2156 +/* These are Linux-specific. */
2157 +#ifdef __USE_MISC
2158 +# define MAP_GROWSDOWN 0x0100 /* Stack-like segment. */
2159 +# define MAP_DENYWRITE 0x0800 /* ETXTBSY */
2160 +# define MAP_EXECUTABLE 0x1000 /* Mark it as an executable. */
2161 +# define MAP_LOCKED 0x2000 /* Lock the mapping. */
2162 +# define MAP_NORESERVE 0x4000 /* Don't check for reservations. */
2163 +# define MAP_POPULATE 0x8000 /* populate (prefault) pagetables */
2164 +# define MAP_NONBLOCK 0x10000 /* do not block on IO */
2165 +#endif
2166 +
2167 +/* Flags to `msync'. */
2168 +#define MS_ASYNC 1 /* Sync memory asynchronously. */
2169 +#define MS_SYNC 4 /* Synchronous memory sync. */
2170 +#define MS_INVALIDATE 2 /* Invalidate the caches. */
2171 +
2172 +/* Flags for `mlockall'. */
2173 +#define MCL_CURRENT 1 /* Lock all currently mapped pages. */
2174 +#define MCL_FUTURE 2 /* Lock all additions to address
2175 + space. */
2176 +
2177 +/* Flags for `mremap'. */
2178 +#ifdef __USE_GNU
2179 +# define MREMAP_MAYMOVE 1
2180 +# define MREMAP_FIXED 2
2181 +#endif
2182 +
2183 +/* Advise to `madvise'. */
2184 +#ifdef __USE_BSD
2185 +# define MADV_NORMAL 0 /* No further special treatment. */
2186 +# define MADV_RANDOM 1 /* Expect random page references. */
2187 +# define MADV_SEQUENTIAL 2 /* Expect sequential page references. */
2188 +# define MADV_WILLNEED 3 /* Will need these pages. */
2189 +# define MADV_DONTNEED 4 /* Don't need these pages. */
2190 +# define MADV_REMOVE 9 /* Remove these pages and resources. */
2191 +# define MADV_DONTFORK 10 /* Do not inherit across fork. */
2192 +# define MADV_DOFORK 11 /* Do inherit across fork. */
2193 +#endif
2194 +
2195 +/* The POSIX people had to invent similar names for the same things. */
2196 +#ifdef __USE_XOPEN2K
2197 +# define POSIX_MADV_NORMAL 0 /* No further special treatment. */
2198 +# define POSIX_MADV_RANDOM 1 /* Expect random page references. */
2199 +# define POSIX_MADV_SEQUENTIAL 2 /* Expect sequential page references. */
2200 +# define POSIX_MADV_WILLNEED 3 /* Will need these pages. */
2201 +# define POSIX_MADV_DONTNEED 4 /* Don't need these pages. */
2202 +#endif
2203 diff --git a/libc/sysdeps/linux/avr32/bits/setjmp.h b/libc/sysdeps/linux/avr32/bits/setjmp.h
2204 new file mode 100644
2205 index 0000000..78348a3
2206 --- /dev/null
2207 +++ b/libc/sysdeps/linux/avr32/bits/setjmp.h
2208 @@ -0,0 +1,30 @@
2209 +/*
2210 + * Copyright (C) 2004-2005 Atmel Corporation
2211 + *
2212 + * This file is subject to the terms and conditions of the GNU Lesser General
2213 + * Public License. See the file "COPYING.LIB" in the main directory of this
2214 + * archive for more details.
2215 + */
2216 +#ifndef _BITS_SETJMP_H
2217 +#define _BITS_SETJMP_H 1
2218 +
2219 +#if !defined _SETJMP_H && !defined _PTHREAD_H
2220 +# error "Never include <bits/setjmp.h> directly; use <setjmp.h> instead."
2221 +#endif
2222 +
2223 +#ifndef _ASM
2224 +/*
2225 + * The jump buffer contains r0-r7, sr, sp and lr. Other registers are
2226 + * not saved.
2227 + */
2228 +typedef int __jmp_buf[11];
2229 +#endif
2230 +
2231 +#define __JMP_BUF_SP 4
2232 +
2233 +/* Test if longjmp to JMPBUF would unwind the frame containing a local
2234 + variable at ADDRESS. */
2235 +#define _JMPBUF_UNWINDS(jmpbuf, address) \
2236 + ((void *)(address) < (void *)(jmpbuf[__JMP_BUF_SP]))
2237 +
2238 +#endif /* _BITS_SETJMP_H */
2239 diff --git a/libc/sysdeps/linux/avr32/bits/stackinfo.h b/libc/sysdeps/linux/avr32/bits/stackinfo.h
2240 new file mode 100644
2241 index 0000000..29b8452
2242 --- /dev/null
2243 +++ b/libc/sysdeps/linux/avr32/bits/stackinfo.h
2244 @@ -0,0 +1,28 @@
2245 +/* Copyright (C) 1999 Free Software Foundation, Inc.
2246 + This file is part of the GNU C Library.
2247 +
2248 + The GNU C Library is free software; you can redistribute it and/or
2249 + modify it under the terms of the GNU Lesser General Public
2250 + License as published by the Free Software Foundation; either
2251 + version 2.1 of the License, or (at your option) any later version.
2252 +
2253 + The GNU C Library is distributed in the hope that it will be useful,
2254 + but WITHOUT ANY WARRANTY; without even the implied warranty of
2255 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2256 + Lesser General Public License for more details.
2257 +
2258 + You should have received a copy of the GNU Lesser General Public
2259 + License along with the GNU C Library; if not, write to the Free
2260 + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
2261 + 02111-1307 USA. */
2262 +
2263 +/* This file contains a bit of information about the stack allocation
2264 + of the processor. */
2265 +
2266 +#ifndef _STACKINFO_H
2267 +#define _STACKINFO_H 1
2268 +
2269 +/* On AVR32 the stack grows down. */
2270 +#define _STACK_GROWS_DOWN 1
2271 +
2272 +#endif /* stackinfo.h */
2273 diff --git a/libc/sysdeps/linux/avr32/bits/syscalls.h b/libc/sysdeps/linux/avr32/bits/syscalls.h
2274 new file mode 100644
2275 index 0000000..22ac059
2276 --- /dev/null
2277 +++ b/libc/sysdeps/linux/avr32/bits/syscalls.h
2278 @@ -0,0 +1,143 @@
2279 +#ifndef _BITS_SYSCALLS_H
2280 +#define _BITS_SYSCALLS_H
2281 +#ifndef _SYSCALL_H
2282 +# error "Never use <bits/syscalls.h> directly; include <sys/syscall.h> instead."
2283 +#endif
2284 +
2285 +/*
2286 + * This includes the `__NR_<name>' syscall numbers taken from the
2287 + * Linux kernel header files. It also defines the traditional
2288 + * `SYS_<name>' macros for older programs.
2289 + */
2290 +#include <bits/sysnum.h>
2291 +
2292 +#ifndef __ASSEMBLER__
2293 +
2294 +#include <errno.h>
2295 +
2296 +#define SYS_ify(syscall_name) (__NR_##syscall_name)
2297 +
2298 +#undef _syscall0
2299 +#define _syscall0(type,name) \
2300 + type name(void) \
2301 + { \
2302 + return (type)(INLINE_SYSCALL(name, 0)); \
2303 + }
2304 +
2305 +#undef _syscall1
2306 +#define _syscall1(type,name,type1,arg1) \
2307 + type name(type1 arg1) \
2308 + { \
2309 + return (type)(INLINE_SYSCALL(name, 1, arg1)); \
2310 + }
2311 +
2312 +#undef _syscall2
2313 +#define _syscall2(type,name,type1,arg1,type2,arg2) \
2314 + type name(type1 arg1, type2 arg2) \
2315 + { \
2316 + return (type)(INLINE_SYSCALL(name, 2, arg1, arg2)); \
2317 + }
2318 +
2319 +#undef _syscall3
2320 +#define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \
2321 + type name(type1 arg1, type2 arg2, type3 arg3) \
2322 + { \
2323 + return (type)(INLINE_SYSCALL(name, 3, arg1, \
2324 + arg2, arg3)); \
2325 + }
2326 +
2327 +#undef _syscall4
2328 +#define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3, \
2329 + type4,arg4) \
2330 + type name(type1 arg1, type2 arg2, type3 arg3, type4 arg4) \
2331 + { \
2332 + return (type)(INLINE_SYSCALL(name, 4, arg1, arg2, \
2333 + arg3, arg4)); \
2334 + }
2335 +
2336 +#undef _syscall5
2337 +#define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3, \
2338 + type4,arg4,type5,arg5) \
2339 + type name(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \
2340 + type5 arg5) \
2341 + { \
2342 + return (type)(INLINE_SYSCALL(name, 5, arg1, arg2, \
2343 + arg3, arg4, arg5)); \
2344 + }
2345 +
2346 +#undef _syscall6
2347 +#define _syscall6(type,name,type1,arg1,type2,arg2,type3,arg3, \
2348 + type4,arg4,type5,arg5,type6,arg6) \
2349 + type name(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \
2350 + type5 arg5, type6 arg6) \
2351 + { \
2352 + return (type)(INLINE_SYSCALL(name, 6, arg1, arg2, arg3, \
2353 + arg4, arg5, arg6)); \
2354 + }
2355 +
2356 +#undef unlikely
2357 +#define unlikely(x) __builtin_expect((x), 0)
2358 +
2359 +#undef INLINE_SYSCALL
2360 +#define INLINE_SYSCALL(name, nr, args...) \
2361 + ({ \
2362 + unsigned _sys_result = INTERNAL_SYSCALL(name, , nr, args); \
2363 + if (unlikely(INTERNAL_SYSCALL_ERROR_P(_sys_result, ))) { \
2364 + __set_errno(INTERNAL_SYSCALL_ERRNO(_sys_result, )); \
2365 + _sys_result = (unsigned int) -1; \
2366 + } \
2367 + (int) _sys_result; \
2368 + })
2369 +
2370 +#undef INTERNAL_SYSCALL_DECL
2371 +#define INTERNAL_SYSCALL_DECL(err) do { } while(0)
2372 +
2373 +#undef INTERNAL_SYSCALL
2374 +#define INTERNAL_SYSCALL(name, err, nr, args...) \
2375 + ({ \
2376 + register int _a1 asm ("r12"); \
2377 + register int _scno asm("r8") = SYS_ify(name); \
2378 + LOAD_ARGS_##nr (args); \
2379 + asm volatile ("scall /* syscall " #name " */" \
2380 + : "=r" (_a1) \
2381 + : "r"(_scno) ASM_ARGS_##nr \
2382 + : "cc", "memory"); \
2383 + _a1; \
2384 + })
2385 +
2386 +#undef INTERNAL_SYSCALL_ERROR_P
2387 +#define INTERNAL_SYSCALL_ERROR_P(val, err) \
2388 + ((unsigned int)(val) >= 0xfffff001U)
2389 +
2390 +#undef INTERNAL_SYSCALL_ERRNO
2391 +#define INTERNAL_SYSCALL_ERRNO(val, errr) (-(val))
2392 +
2393 +#define LOAD_ARGS_0() do { } while(0)
2394 +#define ASM_ARGS_0
2395 +#define LOAD_ARGS_1(a1) \
2396 + _a1 = (int) (a1); \
2397 + LOAD_ARGS_0()
2398 +#define ASM_ARGS_1 ASM_ARGS_0, "r"(_a1)
2399 +#define LOAD_ARGS_2(a1, a2) \
2400 + register int _a2 asm("r11") = (int)(a2); \
2401 + LOAD_ARGS_1(a1)
2402 +#define ASM_ARGS_2 ASM_ARGS_1, "r"(_a2)
2403 +#define LOAD_ARGS_3(a1, a2, a3) \
2404 + register int _a3 asm("r10") = (int)(a3); \
2405 + LOAD_ARGS_2(a1, a2)
2406 +#define ASM_ARGS_3 ASM_ARGS_2, "r"(_a3)
2407 +#define LOAD_ARGS_4(a1, a2, a3, a4) \
2408 + register int _a4 asm("r9") = (int)(a4); \
2409 + LOAD_ARGS_3(a1, a2, a3)
2410 +#define ASM_ARGS_4 ASM_ARGS_3, "r"(_a4)
2411 +#define LOAD_ARGS_5(a1, a2, a3, a4, a5) \
2412 + register int _a5 asm("r5") = (int)(a5); \
2413 + LOAD_ARGS_4(a1, a2, a3, a4)
2414 +#define ASM_ARGS_5 ASM_ARGS_4, "r"(_a5)
2415 +#define LOAD_ARGS_6(a1, a2, a3, a4, a5, a6) \
2416 + register int _a6 asm("r3") = (int)(a6); \
2417 + LOAD_ARGS_5(a1, a2, a3, a4, a5)
2418 +#define ASM_ARGS_6 ASM_ARGS_5, "r"(_a6)
2419 +
2420 +#endif /* __ASSEMBLER__ */
2421 +#endif /* _BITS_SYSCALLS_H */
2422 diff --git a/libc/sysdeps/linux/avr32/bits/uClibc_arch_features.h b/libc/sysdeps/linux/avr32/bits/uClibc_arch_features.h
2423 new file mode 100644
2424 index 0000000..e95e8a5
2425 --- /dev/null
2426 +++ b/libc/sysdeps/linux/avr32/bits/uClibc_arch_features.h
2427 @@ -0,0 +1,45 @@
2428 +/*
2429 + * Track misc arch-specific features that aren't config options
2430 + */
2431 +
2432 +#ifndef _BITS_UCLIBC_ARCH_FEATURES_H
2433 +#define _BITS_UCLIBC_ARCH_FEATURES_H
2434 +
2435 +/* instruction used when calling abort() to kill yourself */
2436 +/* trigger illegal instruction exception, same as BUG in Linux */
2437 +#define __UCLIBC_ABORT_INSTRUCTION__ ".short 0x5df0"
2438 +
2439 +/* can your target use syscall6() for mmap ? */
2440 +#define __UCLIBC_MMAP_HAS_6_ARGS__
2441 +
2442 +/* does your target use syscall4() for truncate64 ? (32bit arches only) */
2443 +#undef __UCLIBC_TRUNCATE64_HAS_4_ARGS__
2444 +
2445 +/* does your target have a broken create_module() ? */
2446 +#undef __UCLIBC_BROKEN_CREATE_MODULE__
2447 +
2448 +/* does your target have to worry about older [gs]etrlimit() ? */
2449 +#undef __UCLIBC_HANDLE_OLDER_RLIMIT__
2450 +
2451 +/* does your target prefix all symbols with an _ ? */
2452 +#define __UCLIBC_NO_UNDERSCORES__
2453 +
2454 +/* does your target have an asm .set ? */
2455 +#define __UCLIBC_HAVE_ASM_SET_DIRECTIVE__
2456 +
2457 +/* define if target doesn't like .global */
2458 +#undef __UCLIBC_ASM_GLOBAL_DIRECTIVE__
2459 +
2460 +/* define if target supports .weak */
2461 +#define __UCLIBC_HAVE_ASM_WEAK_DIRECTIVE__
2462 +
2463 +/* define if target supports .weakext */
2464 +#undef __UCLIBC_HAVE_ASM_WEAKEXT_DIRECTIVE__
2465 +
2466 +/* needed probably only for ppc64 */
2467 +#undef __UCLIBC_HAVE_ASM_GLOBAL_DOT_NAME__
2468 +
2469 +/* define if target supports IEEE signed zero floats */
2470 +#define __UCLIBC_HAVE_SIGNED_ZERO__
2471 +
2472 +#endif /* _BITS_UCLIBC_ARCH_FEATURES_H */
2473 diff --git a/libc/sysdeps/linux/avr32/bits/wordsize.h b/libc/sysdeps/linux/avr32/bits/wordsize.h
2474 new file mode 100644
2475 index 0000000..1b5842a
2476 --- /dev/null
2477 +++ b/libc/sysdeps/linux/avr32/bits/wordsize.h
2478 @@ -0,0 +1 @@
2479 +#define __WORDSIZE 32
2480 diff --git a/libc/sysdeps/linux/avr32/brk.c b/libc/sysdeps/linux/avr32/brk.c
2481 new file mode 100644
2482 index 0000000..a54b49a
2483 --- /dev/null
2484 +++ b/libc/sysdeps/linux/avr32/brk.c
2485 @@ -0,0 +1,31 @@
2486 +/*
2487 + * Copyright (C) 2004-2007 Atmel Corporation
2488 + *
2489 + * This file is subject to the terms and conditions of the GNU Lesser General
2490 + * Public License. See the file "COPYING.LIB" in the main directory of this
2491 + * archive for more details.
2492 + */
2493 +#include <errno.h>
2494 +#include <unistd.h>
2495 +#include <sys/syscall.h>
2496 +
2497 +libc_hidden_proto(brk)
2498 +
2499 +void *__curbrk attribute_hidden = 0;
2500 +
2501 +int brk (void *addr)
2502 +{
2503 + void *newbrk;
2504 +
2505 + newbrk = (void *)INLINE_SYSCALL(brk, 1, addr);
2506 +
2507 + __curbrk = newbrk;
2508 +
2509 + if (newbrk < addr) {
2510 + __set_errno (ENOMEM);
2511 + return -1;
2512 + }
2513 +
2514 + return 0;
2515 +}
2516 +libc_hidden_def(brk)
2517 diff --git a/libc/sysdeps/linux/avr32/bsd-_setjmp.S b/libc/sysdeps/linux/avr32/bsd-_setjmp.S
2518 new file mode 100644
2519 index 0000000..be66a10
2520 --- /dev/null
2521 +++ b/libc/sysdeps/linux/avr32/bsd-_setjmp.S
2522 @@ -0,0 +1,16 @@
2523 +/*
2524 + * Copyright (C) 2004-2007 Atmel Corporation
2525 + *
2526 + * This file is subject to the terms and conditions of the GNU Lesser General
2527 + * Public License. See the file "COPYING.LIB" in the main directory of this
2528 + * archive for more details.
2529 + */
2530 +
2531 + /* This just does a tail-call to __sigsetjmp(env, 0) */
2532 + .global _setjmp
2533 + .type _setjmp,"function"
2534 + .align 1
2535 +_setjmp:
2536 + mov r11, 0
2537 + bral __GI___sigsetjmp
2538 + .size _setjmp, . - _setjmp
2539 diff --git a/libc/sysdeps/linux/avr32/bsd-setjmp.S b/libc/sysdeps/linux/avr32/bsd-setjmp.S
2540 new file mode 100644
2541 index 0000000..4635eeb
2542 --- /dev/null
2543 +++ b/libc/sysdeps/linux/avr32/bsd-setjmp.S
2544 @@ -0,0 +1,16 @@
2545 +/*
2546 + * Copyright (C) 2004-2007 Atmel Corporation
2547 + *
2548 + * This file is subject to the terms and conditions of the GNU Lesser General
2549 + * Public License. See the file "COPYING.LIB" in the main directory of this
2550 + * archive for more details.
2551 + */
2552 +
2553 + /* This just does a tail-call to __sigsetjmp(env, 1) */
2554 + .global setjmp
2555 + .type setjmp,"function"
2556 + .align 1
2557 +setjmp:
2558 + mov r11, 1
2559 + bral __GI___sigsetjmp
2560 + .size setjmp, . - setjmp
2561 diff --git a/libc/sysdeps/linux/avr32/clone.c b/libc/sysdeps/linux/avr32/clone.c
2562 new file mode 100644
2563 index 0000000..e43b0f3
2564 --- /dev/null
2565 +++ b/libc/sysdeps/linux/avr32/clone.c
2566 @@ -0,0 +1,41 @@
2567 +/*
2568 + * Copyright (C) 2004 Atmel Corporation
2569 + *
2570 + * This file is subject to the terms and conditions of the GNU Lesser General
2571 + * Public License. See the file "COPYING.LIB" in the main directory of this
2572 + * archive for more details.
2573 + */
2574 +#include <errno.h>
2575 +#include <sys/syscall.h>
2576 +#include <unistd.h>
2577 +
2578 +/*
2579 + * I don't know if we can be absolutely certain that the fn and arg
2580 + * parameters are preserved when returning as the child. If the
2581 + * compiler stores them in registers (r0-r7), they should be.
2582 + */
2583 +int clone(int (*fn)(void *arg), void *child_stack, int flags, void *arg)
2584 +{
2585 + register int (*_fn)(void *arg) = fn;
2586 + register void *_arg = arg;
2587 + int err;
2588 +
2589 + /* Sanity check the arguments */
2590 + err = -EINVAL;
2591 + if (!fn)
2592 + goto syscall_error;
2593 + if (!child_stack)
2594 + goto syscall_error;
2595 +
2596 + err = INLINE_SYSCALL(clone, 2, flags, child_stack);
2597 + if (err < 0)
2598 + goto syscall_error;
2599 + else if (err != 0)
2600 + return err;
2601 +
2602 + _exit(_fn(_arg));
2603 +
2604 +syscall_error:
2605 + __set_errno (-err);
2606 + return -1;
2607 +}
2608 diff --git a/libc/sysdeps/linux/avr32/crt1.S b/libc/sysdeps/linux/avr32/crt1.S
2609 new file mode 100644
2610 index 0000000..ca1fa7a
2611 --- /dev/null
2612 +++ b/libc/sysdeps/linux/avr32/crt1.S
2613 @@ -0,0 +1,97 @@
2614 +/*
2615 + * Copyright (C) 2004-2007 Atmel Corporation
2616 + *
2617 + * This file is subject to the terms and conditions of the GNU Lesser General
2618 + * Public License. See the file "COPYING.LIB" in the main directory of this
2619 + * archive for more details.
2620 + *
2621 + * When we enter _start, the stack looks like this:
2622 + * argc argument counter
2623 + * argv[0] pointer to program name
2624 + * argv[1..argc-1] pointers to program args
2625 + * NULL
2626 + * env[0..N] pointers to environment variables
2627 + * NULL
2628 + *
2629 + * r12 contains a function pointer to be registered with `atexit'.
2630 + * This is how the dynamic linker arranges to have DT_FINI functions
2631 + * called for shared libraries that have been loaded before this
2632 + * code runs.
2633 + *
2634 + * We're going to call the following function:
2635 + * __uClibc_main(int (*main)(int, char **, char **), int argc,
2636 + * char **argv, void (*app_init)(void), void (*app_fini)(void),
2637 + * void (*rtld_fini)(void), void *stack_end)
2638 + *
2639 + * So we need to set up things as follows:
2640 + * r12 = address of main
2641 + * r11 = argc
2642 + * r10 = &argv[0]
2643 + * r9 = address of _init
2644 + * r8 = address of _fini
2645 + * sp[0] = whatever we got passed in r12
2646 + */
2647 +
2648 +#include <features.h>
2649 +
2650 + .text
2651 + .global _start
2652 + .type _start, @function
2653 +_start:
2654 + /* Clear the frame pointer and link register since this is the outermost frame. */
2655 + mov r7, 0
2656 + mov lr, 0
2657 +
2658 + ld.w r11, sp++ /* argc */
2659 + mov r10, sp /* &argv[0] */
2660 +
2661 + st.w --sp, r10 /* stack_end */
2662 + st.w --sp, r12 /* rtld_fini */
2663 +
2664 +#ifdef __PIC__
2665 + lddpc r6, .L_GOT
2666 +.L_RGOT:
2667 + rsub r6, pc
2668 + lda.w r9, _init
2669 + lda.w r8, _fini
2670 + lda.w r12, main
2671 +
2672 + /* Ok, now run uClibc's main() -- should not return */
2673 + call __uClibc_main
2674 +
2675 + .align 2
2676 +.L_GOT:
2677 + .long .L_RGOT - _GLOBAL_OFFSET_TABLE_
2678 +#else
2679 + lddpc r9, __init_addr /* app_init */
2680 + lddpc r8, __fini_addr /* app_fini */
2681 + lddpc r12, __main_addr /* main */
2682 +
2683 + /* Ok, now run uClibc's main() -- should not return */
2684 + lddpc pc, ___uClibc_main_addr
2685 +
2686 + .align 2
2687 +__init_addr:
2688 + .long _init
2689 +__fini_addr:
2690 + .long _fini
2691 +__main_addr:
2692 + .long main
2693 +___uClibc_main_addr:
2694 + .long __uClibc_main
2695 +#endif
2696 + .size _start, . - _start
2697 +
2698 + /*
2699 + * The LSB says we need this.
2700 + */
2701 + .section ".note.ABI-tag", "a"
2702 + .align 4
2703 + .long 2f - 1f /* namesz */
2704 + .long 4f - 3f /* descsz */
2705 + .long 1 /* type */
2706 +1: .asciz "GNU" /* name */
2707 +2: .align 4
2708 +3: .long 0 /* Linux executable */
2709 + .long 2,6,0 /* Earliest compatible kernel */
2710 +4: .align 4
2711 diff --git a/libc/sysdeps/linux/avr32/crti.S b/libc/sysdeps/linux/avr32/crti.S
2712 new file mode 100644
2713 index 0000000..660f47c
2714 --- /dev/null
2715 +++ b/libc/sysdeps/linux/avr32/crti.S
2716 @@ -0,0 +1,26 @@
2717 +
2718 + .section .init
2719 + .align 2
2720 + .global _init
2721 + .type _init, @function
2722 +_init:
2723 + stm --sp, r6, lr
2724 + lddpc r6, 2f
2725 +1: rsub r6, pc
2726 + rjmp 3f
2727 + .align 2
2728 +2: .long 1b - _GLOBAL_OFFSET_TABLE_
2729 +3:
2730 +
2731 + .section .fini
2732 + .align 2
2733 + .global _fini
2734 + .type _fini, @function
2735 +_fini:
2736 + stm --sp, r6, lr
2737 + lddpc r6, 2f
2738 +1: rsub r6, pc
2739 + rjmp 3f
2740 + .align 2
2741 +2: .long 1b - _GLOBAL_OFFSET_TABLE_
2742 +3:
2743 diff --git a/libc/sysdeps/linux/avr32/crtn.S b/libc/sysdeps/linux/avr32/crtn.S
2744 new file mode 100644
2745 index 0000000..f7d1040
2746 --- /dev/null
2747 +++ b/libc/sysdeps/linux/avr32/crtn.S
2748 @@ -0,0 +1,14 @@
2749 +
2750 + .section .init
2751 + .align 2
2752 + .global _init
2753 + .type _init, @function
2754 + ldm sp++, r6, pc
2755 + .size _init, . - _init
2756 +
2757 + .section .fini
2758 + .align 2
2759 + .global _fini
2760 + .type _fini, @function
2761 + ldm sp++, r6, pc
2762 + .size _fini, . - _fini
2763 diff --git a/libc/sysdeps/linux/avr32/mmap.c b/libc/sysdeps/linux/avr32/mmap.c
2764 new file mode 100644
2765 index 0000000..2ee025a
2766 --- /dev/null
2767 +++ b/libc/sysdeps/linux/avr32/mmap.c
2768 @@ -0,0 +1,33 @@
2769 +/*
2770 + * Copyright (C) 2004-2007 Atmel Corporation
2771 + *
2772 + * This file is subject to the terms and conditions of the GNU Lesser General
2773 + * Public License. See the file "COPYING.LIB" in the main directory of this
2774 + * archive for more details.
2775 + */
2776 +
2777 +#include <errno.h>
2778 +#include <unistd.h>
2779 +#include <sys/mman.h>
2780 +#include <sys/syscall.h>
2781 +
2782 +libc_hidden_proto(mmap)
2783 +
2784 +static _syscall6(__ptr_t, mmap2, __ptr_t, addr, size_t, len, int, prot,
2785 + int, flags, int, fd, __off_t, pgoff);
2786 +
2787 +__ptr_t mmap(__ptr_t addr, size_t len, int prot, int flags, int fd, __off_t offset)
2788 +{
2789 + unsigned long page_size = sysconf(_SC_PAGESIZE);
2790 + unsigned long pgoff;
2791 +
2792 + if (offset & (page_size - 1)) {
2793 + __set_errno(EINVAL);
2794 + return MAP_FAILED;
2795 + }
2796 +
2797 + pgoff = (unsigned long)offset >> (31 - __builtin_clz(page_size));
2798 +
2799 + return mmap2(addr, len, prot, flags, fd, pgoff);
2800 +}
2801 +libc_hidden_def(mmap)
2802 diff --git a/libc/sysdeps/linux/avr32/setjmp.S b/libc/sysdeps/linux/avr32/setjmp.S
2803 new file mode 100644
2804 index 0000000..7d0354b
2805 --- /dev/null
2806 +++ b/libc/sysdeps/linux/avr32/setjmp.S
2807 @@ -0,0 +1,29 @@
2808 +/*
2809 + * Copyright (C) 2004-2007 Atmel Corporation
2810 + *
2811 + * This file is subject to the terms and conditions of the GNU Lesser General
2812 + * Public License. See the file "COPYING.LIB" in the main directory of this
2813 + * archive for more details.
2814 + */
2815 +#define _SETJMP_H
2816 +#define _ASM
2817 +#include <bits/setjmp.h>
2818 +
2819 + .text
2820 +
2821 + .global __sigsetjmp
2822 + .type __sigsetjmp,"function"
2823 +
2824 + .align 1
2825 +__sigsetjmp:
2826 + mustr r8
2827 + stm r12, r0,r1,r2,r3,r4,r5,r6,r7,r8,sp,lr
2828 +
2829 + /*
2830 + * Make a tail call to __sigjmp_save; it takes the same args
2831 + * and is hidden so we don't need to mess around with the GOT.
2832 + */
2833 + rjmp __sigjmp_save
2834 + .size __sigsetjmp, . - __sigsetjmp
2835 +
2836 +libc_hidden_def(__sigsetjmp)
2837 diff --git a/libc/sysdeps/linux/avr32/sigaction.c b/libc/sysdeps/linux/avr32/sigaction.c
2838 new file mode 100644
2839 index 0000000..a97ff3d
2840 --- /dev/null
2841 +++ b/libc/sysdeps/linux/avr32/sigaction.c
2842 @@ -0,0 +1,59 @@
2843 +/*
2844 + * Copyright (C) 2004-2007 Atmel Corporation
2845 + *
2846 + * This file is subject to the terms and conditions of the GNU Lesser General
2847 + * Public License. See the file "COPYING.LIB" in the main directory of this
2848 + * archive for more details.
2849 + */
2850 +#include <errno.h>
2851 +#include <signal.h>
2852 +#include <string.h>
2853 +#include <sys/syscall.h>
2854 +#include <bits/kernel_sigaction.h>
2855 +
2856 +#define SA_RESTORER 0x04000000
2857 +extern void __default_rt_sa_restorer(void);
2858 +
2859 +libc_hidden_proto(memcpy)
2860 +
2861 +/*
2862 + * If act is not NULL, change the action for sig to *act.
2863 + * If oact is not NULL, put the old action for sig in *oact.
2864 + */
2865 +int __libc_sigaction(int signum, const struct sigaction *act,
2866 + struct sigaction *oldact)
2867 +{
2868 + struct kernel_sigaction kact, koact;
2869 + int result;
2870 +
2871 + if (act) {
2872 + kact.k_sa_handler = act->sa_handler;
2873 + memcpy(&kact.sa_mask, &act->sa_mask, sizeof (kact.sa_mask));
2874 + kact.sa_flags = act->sa_flags;
2875 + if (kact.sa_flags & (SA_RESTORER | SA_ONSTACK))
2876 + kact.sa_restorer = act->sa_restorer;
2877 + else
2878 + kact.sa_restorer = __default_rt_sa_restorer;
2879 + kact.sa_flags |= SA_RESTORER;
2880 + }
2881 +
2882 + result = __syscall_rt_sigaction(signum, act ? __ptrvalue(&kact) : NULL,
2883 + oldact ? __ptrvalue(&koact) : NULL,
2884 + _NSIG / 8);
2885 +
2886 + if (oldact && result >= 0) {
2887 + oldact->sa_handler = koact.k_sa_handler;
2888 + memcpy(&oldact->sa_mask, &koact.sa_mask,
2889 + sizeof(oldact->sa_mask));
2890 + oldact->sa_flags = koact.sa_flags;
2891 + oldact->sa_restorer = koact.sa_restorer;
2892 + }
2893 +
2894 + return result;
2895 +}
2896 +
2897 +#ifndef LIBC_SIGACTION
2898 +libc_hidden_proto(sigaction)
2899 +weak_alias(__libc_sigaction, sigaction)
2900 +libc_hidden_weak(sigaction)
2901 +#endif
2902 diff --git a/libc/sysdeps/linux/avr32/sigrestorer.S b/libc/sysdeps/linux/avr32/sigrestorer.S
2903 new file mode 100644
2904 index 0000000..df6a1ba
2905 --- /dev/null
2906 +++ b/libc/sysdeps/linux/avr32/sigrestorer.S
2907 @@ -0,0 +1,15 @@
2908 +/*
2909 + * Copyright (C) 2004 Atmel Corporation
2910 + *
2911 + * This file is subject to the terms and conditions of the GNU Lesser General
2912 + * Public License. See the file "COPYING.LIB" in the main directory of this
2913 + * archive for more details.
2914 + */
2915 +#include <sys/syscall.h>
2916 +
2917 + .global __default_rt_sa_restorer
2918 + .type __default_rt_sa_restorer,"function"
2919 + .align 1
2920 +__default_rt_sa_restorer:
2921 + mov r8, __NR_rt_sigreturn
2922 + scall
2923 diff --git a/libc/sysdeps/linux/avr32/sys/elf.h b/libc/sysdeps/linux/avr32/sys/elf.h
2924 new file mode 100644
2925 index 0000000..faa7310
2926 --- /dev/null
2927 +++ b/libc/sysdeps/linux/avr32/sys/elf.h
2928 @@ -0,0 +1,26 @@
2929 +/* Copyright (C) 1996, 1997, 1999, 2001 Free Software Foundation, Inc.
2930 + This file is part of the GNU C Library.
2931 +
2932 + The GNU C Library is free software; you can redistribute it and/or
2933 + modify it under the terms of the GNU Lesser General Public
2934 + License as published by the Free Software Foundation; either
2935 + version 2.1 of the License, or (at your option) any later version.
2936 +
2937 + The GNU C Library is distributed in the hope that it will be useful,
2938 + but WITHOUT ANY WARRANTY; without even the implied warranty of
2939 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2940 + Lesser General Public License for more details.
2941 +
2942 + You should have received a copy of the GNU Lesser General Public
2943 + License along with the GNU C Library; if not, write to the Free
2944 + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
2945 + 02111-1307 USA. */
2946 +
2947 +#ifndef _SYS_ELF_H
2948 +#define _SYS_ELF_H 1
2949 +
2950 +#warning "This header is obsolete; use <sys/procfs.h> instead."
2951 +
2952 +#include <sys/procfs.h>
2953 +
2954 +#endif /* sys/elf.h */
2955 diff --git a/libc/sysdeps/linux/avr32/sys/procfs.h b/libc/sysdeps/linux/avr32/sys/procfs.h
2956 new file mode 100644
2957 index 0000000..3b37363
2958 --- /dev/null
2959 +++ b/libc/sysdeps/linux/avr32/sys/procfs.h
2960 @@ -0,0 +1,123 @@
2961 +/* Copyright (C) 1996, 1997, 1999, 2001 Free Software Foundation, Inc.
2962 + This file is part of the GNU C Library.
2963 +
2964 + The GNU C Library is free software; you can redistribute it and/or
2965 + modify it under the terms of the GNU Lesser General Public
2966 + License as published by the Free Software Foundation; either
2967 + version 2.1 of the License, or (at your option) any later version.
2968 +
2969 + The GNU C Library is distributed in the hope that it will be useful,
2970 + but WITHOUT ANY WARRANTY; without even the implied warranty of
2971 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2972 + Lesser General Public License for more details.
2973 +
2974 + You should have received a copy of the GNU Lesser General Public
2975 + License along with the GNU C Library; if not, write to the Free
2976 + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
2977 + 02111-1307 USA. */
2978 +
2979 +#ifndef _SYS_PROCFS_H
2980 +#define _SYS_PROCFS_H 1
2981 +
2982 +/* This is somewhat modelled after the file of the same name on SVR4
2983 + systems. It provides a definition of the core file format for ELF
2984 + used on Linux. It doesn't have anything to do with the /proc file
2985 + system, even though Linux has one.
2986 +
2987 + Anyway, the whole purpose of this file is for GDB and GDB only.
2988 + Don't read too much into it. Don't use it for anything other than
2989 + GDB unless you know what you are doing. */
2990 +
2991 +#include <features.h>
2992 +#include <sys/time.h>
2993 +#include <sys/types.h>
2994 +#include <sys/user.h>
2995 +
2996 +__BEGIN_DECLS
2997 +
2998 +/* Type for a general-purpose register. */
2999 +typedef unsigned long elf_greg_t;
3000 +
3001 +/* And the whole bunch of them. We could have used `struct
3002 + user_regs' directly in the typedef, but tradition says that
3003 + the register set is an array, which does have some peculiar
3004 + semantics, so leave it that way. */
3005 +#define ELF_NGREG (sizeof (struct user_regs) / sizeof(elf_greg_t))
3006 +typedef elf_greg_t elf_gregset_t[ELF_NGREG];
3007 +
3008 +/* Register set for the floating-point registers. */
3009 +typedef struct user_fpregs elf_fpregset_t;
3010 +
3011 +/* Signal info. */
3012 +struct elf_siginfo
3013 + {
3014 + int si_signo; /* Signal number. */
3015 + int si_code; /* Extra code. */
3016 + int si_errno; /* Errno. */
3017 + };
3018 +
3019 +/* Definitions to generate Intel SVR4-like core files. These mostly
3020 + have the same names as the SVR4 types with "elf_" tacked on the
3021 + front to prevent clashes with Linux definitions, and the typedef
3022 + forms have been avoided. This is mostly like the SVR4 structure,
3023 + but more Linuxy, with things that Linux does not support and which
3024 + GDB doesn't really use excluded. */
3025 +
3026 +struct elf_prstatus
3027 + {
3028 + struct elf_siginfo pr_info; /* Info associated with signal. */
3029 + short int pr_cursig; /* Current signal. */
3030 + unsigned long int pr_sigpend; /* Set of pending signals. */
3031 + unsigned long int pr_sighold; /* Set of held signals. */
3032 + __pid_t pr_pid;
3033 + __pid_t pr_ppid;
3034 + __pid_t pr_pgrp;
3035 + __pid_t pr_sid;
3036 + struct timeval pr_utime; /* User time. */
3037 + struct timeval pr_stime; /* System time. */
3038 + struct timeval pr_cutime; /* Cumulative user time. */
3039 + struct timeval pr_cstime; /* Cumulative system time. */
3040 + elf_gregset_t pr_reg; /* GP registers. */
3041 + int pr_fpvalid; /* True if math copro being used. */
3042 + };
3043 +
3044 +
3045 +#define ELF_PRARGSZ (80) /* Number of chars for args. */
3046 +
3047 +struct elf_prpsinfo
3048 + {
3049 + char pr_state; /* Numeric process state. */
3050 + char pr_sname; /* Char for pr_state. */
3051 + char pr_zomb; /* Zombie. */
3052 + char pr_nice; /* Nice val. */
3053 + unsigned long int pr_flag; /* Flags. */
3054 + unsigned short int pr_uid;
3055 + unsigned short int pr_gid;
3056 + int pr_pid, pr_ppid, pr_pgrp, pr_sid;
3057 + /* Lots missing */
3058 + char pr_fname[16]; /* Filename of executable. */
3059 + char pr_psargs[ELF_PRARGSZ]; /* Initial part of arg list. */
3060 + };
3061 +
3062 +/* The rest of this file provides the types for emulation of the
3063 + Solaris <proc_service.h> interfaces that should be implemented by
3064 + users of libthread_db. */
3065 +
3066 +/* Addresses. */
3067 +typedef void *psaddr_t;
3068 +
3069 +/* Register sets. Linux has different names. */
3070 +typedef elf_gregset_t prgregset_t;
3071 +typedef elf_fpregset_t prfpregset_t;
3072 +
3073 +/* We don't have any differences between processes and threads,
3074 + therefore have only one PID type. */
3075 +typedef __pid_t lwpid_t;
3076 +
3077 +/* Process status and info. In the end we do provide typedefs for them. */
3078 +typedef struct elf_prstatus prstatus_t;
3079 +typedef struct elf_prpsinfo prpsinfo_t;
3080 +
3081 +__END_DECLS
3082 +
3083 +#endif /* sys/procfs.h */
3084 diff --git a/libc/sysdeps/linux/avr32/sys/ucontext.h b/libc/sysdeps/linux/avr32/sys/ucontext.h
3085 new file mode 100644
3086 index 0000000..82c7fe2
3087 --- /dev/null
3088 +++ b/libc/sysdeps/linux/avr32/sys/ucontext.h
3089 @@ -0,0 +1,90 @@
3090 +/* Copyright (C) 1998, 1999, 2001 Free Software Foundation, Inc.
3091 + This file is part of the GNU C Library.
3092 +
3093 + The GNU C Library is free software; you can redistribute it and/or
3094 + modify it under the terms of the GNU Lesser General Public
3095 + License as published by the Free Software Foundation; either
3096 + version 2.1 of the License, or (at your option) any later version.
3097 +
3098 + The GNU C Library is distributed in the hope that it will be useful,
3099 + but WITHOUT ANY WARRANTY; without even the implied warranty of
3100 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3101 + Lesser General Public License for more details.
3102 +
3103 + You should have received a copy of the GNU Lesser General Public
3104 + License along with the GNU C Library; if not, write to the Free
3105 + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
3106 + 02111-1307 USA. */
3107 +
3108 +/* Linux/AVR32 ABI compliant context switching support. */
3109 +
3110 +#ifndef _SYS_UCONTEXT_H
3111 +#define _SYS_UCONTEXT_H 1
3112 +
3113 +#include <features.h>
3114 +#include <signal.h>
3115 +#include <sys/procfs.h>
3116 +#include <bits/sigcontext.h>
3117 +
3118 +typedef int greg_t;
3119 +
3120 +/* Number of general registers. */
3121 +#define NGREG 16
3122 +
3123 +/* Container for all general registers. */
3124 +typedef elf_gregset_t gregset_t;
3125 +
3126 +/* Number of each register is the `gregset_t' array. */
3127 +enum
3128 +{
3129 + R0 = 0,
3130 +#define R0 R0
3131 + R1 = 1,
3132 +#define R1 R1
3133 + R2 = 2,
3134 +#define R2 R2
3135 + R3 = 3,
3136 +#define R3 R3
3137 + R4 = 4,
3138 +#define R4 R4
3139 + R5 = 5,
3140 +#define R5 R5
3141 + R6 = 6,
3142 +#define R6 R6
3143 + R7 = 7,
3144 +#define R7 R7
3145 + R8 = 8,
3146 +#define R8 R8
3147 + R9 = 9,
3148 +#define R9 R9
3149 + R10 = 10,
3150 +#define R10 R10
3151 + R11 = 11,
3152 +#define R11 R11
3153 + R12 = 12,
3154 +#define R12 R12
3155 + R13 = 13,
3156 +#define R13 R13
3157 + R14 = 14,
3158 +#define R14 R14
3159 + R15 = 15
3160 +#define R15 R15
3161 +};
3162 +
3163 +/* Structure to describe FPU registers. */
3164 +typedef elf_fpregset_t fpregset_t;
3165 +
3166 +/* Context to describe whole processor state. */
3167 +typedef struct sigcontext mcontext_t;
3168 +
3169 +/* Userlevel context. */
3170 +typedef struct ucontext
3171 +{
3172 + unsigned long uc_flags;
3173 + struct ucontext *uc_link;
3174 + stack_t uc_stack;
3175 + mcontext_t uc_mcontext;
3176 + sigset_t uc_sigmask; /* mask last for extensibility */
3177 +} ucontext_t;
3178 +
3179 +#endif /* sys/ucontext.h */
3180 diff --git a/libc/sysdeps/linux/avr32/sys/user.h b/libc/sysdeps/linux/avr32/sys/user.h
3181 new file mode 100644
3182 index 0000000..c0b3d38
3183 --- /dev/null
3184 +++ b/libc/sysdeps/linux/avr32/sys/user.h
3185 @@ -0,0 +1,46 @@
3186 +#ifndef _SYS_USER_H
3187 +#define _SYS_USER_H
3188 +
3189 +struct user_fpregs
3190 +{
3191 +
3192 +};
3193 +
3194 +struct user_regs
3195 +{
3196 + unsigned long sr;
3197 + unsigned long pc;
3198 + unsigned long lr;
3199 + unsigned long sp;
3200 + unsigned long r12;
3201 + unsigned long r11;
3202 + unsigned long r10;
3203 + unsigned long r9;
3204 + unsigned long r8;
3205 + unsigned long r7;
3206 + unsigned long r6;
3207 + unsigned long r5;
3208 + unsigned long r4;
3209 + unsigned long r3;
3210 + unsigned long r2;
3211 + unsigned long r1;
3212 + unsigned long r0;
3213 + unsigned long r12_orig;
3214 +};
3215 +
3216 +struct user
3217 +{
3218 + struct user_regs regs; /* general registers */
3219 + size_t u_tsize; /* text size (pages) */
3220 + size_t u_dsize; /* data size (pages) */
3221 + size_t u_ssize; /* stack size (pages) */
3222 + unsigned long start_code; /* text starting address */
3223 + unsigned long start_data; /* data starting address */
3224 + unsigned long start_stack; /* stack starting address */
3225 + long int signal; /* signal causing core dump */
3226 + struct user_regs * u_ar0; /* help gdb find registers */
3227 + unsigned long magic; /* identifies a core file */
3228 + char u_comm[32]; /* user command name */
3229 +};
3230 +
3231 +#endif /* _SYS_USER_H */
3232 diff --git a/libc/sysdeps/linux/avr32/syscall.S b/libc/sysdeps/linux/avr32/syscall.S
3233 new file mode 100644
3234 index 0000000..55c1b1f
3235 --- /dev/null
3236 +++ b/libc/sysdeps/linux/avr32/syscall.S
3237 @@ -0,0 +1,71 @@
3238 +/*
3239 + * Copyright (C) 2004-2007 Atmel Corporation
3240 + *
3241 + * This file is subject to the terms and conditions of the GNU Lesser General
3242 + * Public License. See the file "COPYING.LIB" in the main directory of this
3243 + * archive for more details.
3244 + */
3245 +#include <features.h>
3246 +
3247 + .text
3248 +
3249 + /*
3250 + * long int syscall(long int sysno, ...)
3251 + */
3252 + .global syscall
3253 + .type syscall, @function
3254 + .align 2
3255 +syscall:
3256 + stm --sp, r3,r5,r6,lr
3257 + sub lr, sp, -16
3258 + mov r8, r12
3259 + ldm lr, r3,r5,r9-r12
3260 + scall
3261 + cp.w r12, -4095
3262 + brlo .Ldone
3263 +
3264 +#ifdef __PIC__
3265 + lddpc r6, .Lgot
3266 +.Lgotcalc:
3267 + rsub r6, pc
3268 +# ifdef __UCLIBC_HAS_THREADS__
3269 + rsub r3, r12, 0
3270 + mcall r6[__errno_location@got]
3271 + st.w r12[0], r3
3272 +# else
3273 + ld.w r3, r6[errno@got]
3274 + neg r12
3275 + st.w r3[0], r12
3276 +# endif
3277 +#else
3278 +# ifdef __UCLIBC_HAS_THREADS__
3279 + rsub r3, r12, 0
3280 + mcall .Lerrno_location
3281 + st.w r12[0], r3
3282 +# else
3283 + lddpc r3, .Lerrno
3284 + neg r12
3285 + st.w r3[0], r12
3286 +# endif
3287 +#endif
3288 + mov r12, -1
3289 +
3290 +.Ldone:
3291 + ldm sp++, r3,r5,r6,pc
3292 +
3293 + .align 2
3294 +#ifdef __PIC__
3295 +.Lgot:
3296 + .long .Lgotcalc - _GLOBAL_OFFSET_TABLE_
3297 +#else
3298 +# ifdef __UCLIBC_HAS_THREADS__
3299 +.Lerrno_location:
3300 + .long __errno_location
3301 +# else
3302 +.Lerrno:
3303 + .long errno
3304 +# endif
3305 +#endif
3306 +
3307 +
3308 + .size syscall, . - syscall
3309 diff --git a/libc/sysdeps/linux/avr32/vfork.S b/libc/sysdeps/linux/avr32/vfork.S
3310 new file mode 100644
3311 index 0000000..03ca99f
3312 --- /dev/null
3313 +++ b/libc/sysdeps/linux/avr32/vfork.S
3314 @@ -0,0 +1,58 @@
3315 +/*
3316 + * Copyright (C) 2005 Atmel Corporation
3317 + *
3318 + * This file is subject to the terms and conditions of the GNU Lesser General
3319 + * Public License. See the file "COPYING.LIB" in the main directory of this
3320 + * archive for more details.
3321 + */
3322 +
3323 +/*
3324 + * Clone the process without copying the address space. The
3325 + * calling process is suspended until the child either exits
3326 + * or calls execve.
3327 + *
3328 + * This all means that we cannot rely on the stack to store
3329 + * away registers, since they will be overwritten by the child
3330 + * as soon as it makes another function call (e.g. execve()).
3331 + * Fortunately, the Linux kernel preserves LR across system calls.
3332 + */
3333 +
3334 +#include <features.h>
3335 +#include <sys/syscall.h>
3336 +
3337 + .global __vfork
3338 + .type __vfork,@function
3339 + .align 1
3340 +__vfork:
3341 + mov r8, __NR_vfork
3342 + scall
3343 + cp.w r12, -4096
3344 + retls r12
3345 +
3346 + /* vfork failed, so we may use the stack freely */
3347 + pushm r4-r7,lr
3348 +#ifdef __PIC__
3349 + lddpc r6, .L_GOT
3350 + rsub r4, r12, 0
3351 +.L_RGOT:
3352 + rsub r6, pc
3353 + mcall r6[__errno_location@got]
3354 +#else
3355 + rsub r4, r12, 0
3356 + mcall .L__errno_location
3357 +#endif
3358 + st.w r12[0], r4
3359 + popm r4-r7,pc,r12=-1
3360 +
3361 + .align 2
3362 +#ifdef __PIC__
3363 +.L_GOT:
3364 + .long .L_RGOT - _GLOBAL_OFFSET_TABLE_
3365 +#else
3366 +.L__errno_location:
3367 + .long __errno_location
3368 +#endif
3369 + .size __vfork, . - __vfork
3370 +
3371 +weak_alias(__vfork,vfork)
3372 +libc_hidden_weak(vfork)
3373 diff --git a/libpthread/linuxthreads.old/sysdeps/avr32/pt-machine.h b/libpthread/linuxthreads.old/sysdeps/avr32/pt-machine.h
3374 new file mode 100644
3375 index 0000000..eccf329
3376 --- /dev/null
3377 +++ b/libpthread/linuxthreads.old/sysdeps/avr32/pt-machine.h
3378 @@ -0,0 +1,73 @@
3379 +/* Machine-dependent pthreads configuration and inline functions.
3380 + *
3381 + * Copyright (C) 2005-2007 Atmel Corporation
3382 + *
3383 + * This file is subject to the terms and conditions of the GNU Lesser General
3384 + * Public License. See the file "COPYING.LIB" in the main directory of this
3385 + * archive for more details.
3386 + */
3387 +#ifndef _PT_MACHINE_H
3388 +#define _PT_MACHINE_H 1
3389 +
3390 +#include <features.h>
3391 +
3392 +static inline int
3393 +_test_and_set (int *p, int v)
3394 +{
3395 + int result;
3396 +
3397 + __asm__ __volatile__(
3398 + "/* Inline test and set */\n"
3399 + " xchg %[old], %[mem], %[new]"
3400 + : [old] "=&r"(result)
3401 + : [mem] "r"(p), [new] "r"(v)
3402 + : "memory");
3403 +
3404 + return result;
3405 +}
3406 +
3407 +#ifndef PT_EI
3408 +# define PT_EI extern inline
3409 +#endif
3410 +
3411 +extern long int testandset (int *spinlock);
3412 +extern int __compare_and_swap (long int *p, long int oldval, long int newval);
3413 +
3414 +/* Spinlock implementation; required. */
3415 +PT_EI long int
3416 +testandset (int *spinlock)
3417 +{
3418 + return _test_and_set(spinlock, 1);
3419 +}
3420 +
3421 +
3422 +/* Get some notion of the current stack. Need not be exactly the top
3423 + of the stack, just something somewhere in the current frame. */
3424 +#define CURRENT_STACK_FRAME stack_pointer
3425 +register char * stack_pointer __asm__ ("sp");
3426 +
3427 +/* Compare-and-swap for semaphores. */
3428 +
3429 +#define HAS_COMPARE_AND_SWAP
3430 +PT_EI int
3431 +__compare_and_swap(long int *p, long int oldval, long int newval)
3432 +{
3433 + long int result;
3434 +
3435 + __asm__ __volatile__(
3436 + "/* Inline compare and swap */\n"
3437 + "1: ssrf 5\n"
3438 + " ld.w %[result], %[mem]\n"
3439 + " eor %[result], %[old]\n"
3440 + " brne 2f\n"
3441 + " stcond %[mem], %[new]\n"
3442 + " brne 1b\n"
3443 + "2:"
3444 + : [result] "=&r"(result), [mem] "=m"(*p)
3445 + : "m"(*p), [new] "r"(newval), [old] "r"(oldval)
3446 + : "cc", "memory");
3447 +
3448 + return result == 0;
3449 +}
3450 +
3451 +#endif /* pt-machine.h */
3452 diff --git a/libpthread/linuxthreads/sysdeps/avr32/pt-machine.h b/libpthread/linuxthreads/sysdeps/avr32/pt-machine.h
3453 new file mode 100644
3454 index 0000000..fe12bf8
3455 --- /dev/null
3456 +++ b/libpthread/linuxthreads/sysdeps/avr32/pt-machine.h
3457 @@ -0,0 +1,73 @@
3458 +/* Machine-dependent pthreads configuration and inline functions.
3459 + *
3460 + * Copyright (C) 2005-2007 Atmel Corporation
3461 + *
3462 + * This file is subject to the terms and conditions of the GNU Lesser General
3463 + * Public License. See the file "COPYING.LIB" in the main directory of this
3464 + * archive for more details.
3465 + */
3466 +#ifndef _PT_MACHINE_H
3467 +#define _PT_MACHINE_H 1
3468 +
3469 +#include <features.h>
3470 +
3471 +static inline int
3472 +_test_and_set (int *p, int v) __THROW
3473 +{
3474 + int result;
3475 +
3476 + __asm__ __volatile__(
3477 + "/* Inline test and set */\n"
3478 + " xchg %[old], %[mem], %[new]"
3479 + : [old] "=&r"(result)
3480 + : [mem] "r"(p), [new] "r"(v)
3481 + : "memory");
3482 +
3483 + return result;
3484 +}
3485 +
3486 +#ifndef PT_EI
3487 +# define PT_EI extern inline
3488 +#endif
3489 +
3490 +extern long int testandset (int *spinlock);
3491 +extern int __compare_and_swap (long int *p, long int oldval, long int newval);
3492 +
3493 +/* Spinlock implementation; required. */
3494 +PT_EI long int
3495 +testandset (int *spinlock)
3496 +{
3497 + return _test_and_set(spinlock, 1);
3498 +}
3499 +
3500 +
3501 +/* Get some notion of the current stack. Need not be exactly the top
3502 + of the stack, just something somewhere in the current frame. */
3503 +#define CURRENT_STACK_FRAME stack_pointer
3504 +register char * stack_pointer __asm__ ("sp");
3505 +
3506 +/* Compare-and-swap for semaphores. */
3507 +
3508 +#define HAS_COMPARE_AND_SWAP
3509 +PT_EI int
3510 +__compare_and_swap(long int *p, long int oldval, long int newval)
3511 +{
3512 + int result;
3513 +
3514 + __asm__ __volatile__(
3515 + "/* Inline compare and swap */\n"
3516 + "1: ssrf 5\n"
3517 + " ld.w %[result], %[mem]\n"
3518 + " eor %[result], %[old]\n"
3519 + " brne 2f\n"
3520 + " stcond %[mem], %[new]\n"
3521 + " brne 1b\n"
3522 + "2:"
3523 + : [result] "=&r"(result), [mem] "=m"(*p)
3524 + : "m"(*p), [new] "r"(newval), [old] "r"(oldval)
3525 + : "cc", "memory");
3526 +
3527 + return result == 0;
3528 +}
3529 +
3530 +#endif /* pt-machine.h */
3531 diff --git a/utils/ldd.c b/utils/ldd.c
3532 index 75ad628..e34acd9 100644
3533 --- a/utils/ldd.c
3534 +++ b/utils/ldd.c
3535 @@ -44,6 +44,11 @@
3536 #define ELFCLASSM ELFCLASS32
3537 #endif
3538
3539 +#if defined(__avr32__)
3540 +#define MATCH_MACHINE(x) (x == EM_AVR32)
3541 +#define ELFCLASSM ELFCLASS32
3542 +#endif
3543 +
3544 #if defined(__s390__)
3545 #define MATCH_MACHINE(x) (x == EM_S390)
3546 #define ELFCLASSM ELFCLASS32
This page took 0.229422 seconds and 5 git commands to generate.