ar71xx: disable CONFIG_{I2C,SPI}_GPIO
[openwrt.git] / toolchain / uClibc / patches-0.9.33 / 600-ubicom32-uClibc.patch
1 --- a/Rules.mak
2 +++ b/Rules.mak
3 @@ -524,6 +524,17 @@ ifeq ($(TARGET_ARCH),i960)
4 SYMBOL_PREFIX=_
5 endif
6
7 +ifeq ($(TARGET_ARCH),ubicom32)
8 + OPTIMIZATION+=-fstrict-aliasing
9 + CPU_CFLAGS-$(CONFIG_UBICOM32_V3)+=-march=ubicom32v3
10 + CPU_CFLAGS-$(CONFIG_UBICOM32_V4)+=-march=ubicom32v4
11 +ifeq ($(UCLIBC_FORMAT_FDPIC_ELF),y)
12 + CPU_CFLAGS-y:=-mfdpic
13 + CPU_LDFLAGS-y += -Wl,-melf32ubicom32fdpic
14 +endif
15 +
16 +endif
17 +
18 ifeq ($(TARGET_ARCH),v850)
19 SYMBOL_PREFIX=_
20 endif
21 --- a/extra/Configs/Config.in
22 +++ b/extra/Configs/Config.in
23 @@ -102,6 +102,9 @@ config TARGET_sh64
24 config TARGET_sparc
25 bool "sparc"
26
27 +config TARGET_ubicom32
28 + bool "ubicom32"
29 +
30 config TARGET_v850
31 bool "v850 (BROKEN)"
32
33 @@ -206,6 +209,10 @@ if TARGET_sparc
34 source "extra/Configs/Config.sparc"
35 endif
36
37 +if TARGET_ubicom32
38 +source "extra/Configs/Config.ubicom32"
39 +endif
40 +
41 if TARGET_v850
42 source "extra/Configs/Config.v850"
43 endif
44 --- a/extra/Configs/Config.in.arch
45 +++ b/extra/Configs/Config.in.arch
46 @@ -152,7 +152,7 @@ config UCLIBC_HAS_SOFT_FLOAT
47 config DO_C99_MATH
48 bool "Enable full C99 math library support"
49 depends on UCLIBC_HAS_FLOATS
50 - default n
51 + default y
52 help
53 If you want the uClibc math library to contain the full set C99
54 math library features, then answer Y. If you leave this set to
55 --- /dev/null
56 +++ b/extra/Configs/Config.ubicom32
57 @@ -0,0 +1,44 @@
58 +#
59 +# For a description of the syntax of this configuration file,
60 +# see extra/config/Kconfig-language.txt
61 +#
62 +
63 +config TARGET_ARCH
64 + string
65 + default "ubicom32"
66 +
67 +config FORCE_OPTIONS_FOR_ARCH
68 + bool
69 + default y
70 + select ARCH_BIG_ENDIAN
71 + select ARCH_HAS_NO_MMU
72 +
73 +choice
74 + prompt "Target Processor Architecture"
75 + default CONFIG_UC_UBICOM32_V3
76 + help
77 + This selects the instruction set architecture of your Ubicom32 CPU. This
78 + information is used for optimizing purposes. To build a library that
79 + will run on any Ubicom32 CPU, you can specify "v3" here.
80 + If you pick anything other than "v3," there is no
81 + guarantee that uClibc will even run on anything other than the
82 + selected processor type.
83 +
84 + You should probably select the Ubicom32 ISA that best matches the
85 + CPU you will be using on your device. uClibc will be tuned
86 + for that architecture.
87 +
88 + If you don't know what to do, choose "v3"
89 +
90 +config CONFIG_UC_UBICOM32_V3
91 + bool "ISA v3"
92 +
93 +config CONFIG_UC_UBICOM32_V4
94 + bool "ISA v4"
95 +endchoice
96 +
97 +config ARCH_CFLAGS
98 + string
99 +
100 +config CROSS
101 + string
102 --- a/include/elf.h
103 +++ b/include/elf.h
104 @@ -338,6 +338,8 @@ typedef struct
105
106 #define EM_XSTORMY16 0xad45
107
108 +#define EM_UBICOM32 0xde3d /* Ubicom32; no ABI */
109 +
110 /* FRV magic number - no EABI available??. */
111 #define EM_CYGNUS_FRV 0x5441
112
113 @@ -3141,6 +3143,55 @@ typedef Elf32_Addr Elf32_Conflict;
114 #define R_MICROBLAZE_COPY 21 /* runtime copy */
115 #define R_MICROBLAZE_NUM 22
116
117 +/* Ubicom32 ELF relocation types */
118 +#define R_UBICOM32_NONE 0
119 +#define R_UBICOM32_16 1
120 +#define R_UBICOM32_32 2
121 +#define R_UBICOM32_LO16 3
122 +#define R_UBICOM32_HI16 4
123 +#define R_UBICOM32_21_PCREL 5
124 +#define R_UBICOM32_24_PCREL 6
125 +#define R_UBICOM32_HI24 7
126 +#define R_UBICOM32_LO7_S 8
127 +#define R_UBICOM32_LO7_2_S 9
128 +#define R_UBICOM32_LO7_4_S 10
129 +#define R_UBICOM32_LO7_D 11
130 +#define R_UBICOM32_LO7_2_D 12
131 +#define R_UBICOM32_LO7_4_D 13
132 +#define R_UBICOM32_32_HARVARD 14
133 +#define R_UBICOM32_LO7_CALLI 15
134 +#define R_UBICOM32_LO16_CALLI 16
135 +#define R_UBICOM32_GOT_HI24 17
136 +#define R_UBICOM32_GOT_LO7_S 18
137 +#define R_UBICOM32_GOT_LO7_2_S 19
138 +#define R_UBICOM32_GOT_LO7_4_S 20
139 +#define R_UBICOM32_GOT_LO7_D 21
140 +#define R_UBICOM32_GOT_LO7_2_D 22
141 +#define R_UBICOM32_GOT_LO7_4_D 23
142 +#define R_UBICOM32_FUNCDESC_GOT_HI24 24
143 +#define R_UBICOM32_FUNCDESC_GOT_LO7_S 25
144 +#define R_UBICOM32_FUNCDESC_GOT_LO7_2_S 26
145 +#define R_UBICOM32_FUNCDESC_GOT_LO7_4_S 27
146 +#define R_UBICOM32_FUNCDESC_GOT_LO7_D 28
147 +#define R_UBICOM32_FUNCDESC_GOT_LO7_2_D 29
148 +#define R_UBICOM32_FUNCDESC_GOT_LO7_4_D 30
149 +#define R_UBICOM32_GOT_LO7_CALLI 31
150 +#define R_UBICOM32_FUNCDESC_GOT_LO7_CALLI 32
151 +#define R_UBICOM32_FUNCDESC_VALUE 33
152 +#define R_UBICOM32_FUNCDESC 34
153 +#define R_UBICOM32_GOTOFFSET_LO 35
154 +#define R_UBICOM32_GOTOFFSET_HI 36
155 +#define R_UBICOM32_FUNCDESC_GOTOFFSET_LO 37
156 +#define R_UBICOM32_FUNCDESC_GOTOFFSET_HI 38
157 +#define R_UBICOM32_GNU_VTINHERIT 200
158 +#define R_UBICOM32_GNU_VTENTRY 201
159 +
160 +/* Ubicom32 Flags. */
161 +#define EF_UBICOM32_V3 0x00000001 /* -fmarch=ubicom32v3 */
162 +#define EF_UBICOM32_V4 0x00000002 /* -fmarch=ubicom32v4 */
163 +#define EF_UBICOM32_PIC 0x80000000 /* -fpic */
164 +#define EF_UBICOM32_FDPIC 0x40000000 /* -mfdpic */
165 +
166 #ifdef __cplusplus
167 }
168 #endif
169 --- a/include/features.h
170 +++ b/include/features.h
171 @@ -448,4 +448,10 @@ uClibc was built without large file supp
172 # include <libc-internal.h>
173 #endif
174
175 +#ifndef libc_hidden_proto
176 +#define libc_hidden_proto(name, attrs...)
177 +#endif
178 +#ifndef libm_hidden_proto
179 +#define libm_hidden_proto(name, attrs...)
180 +#endif
181 #endif /* features.h */
182 --- /dev/null
183 +++ b/ldso/ldso/ubicom32/dl-debug.h
184 @@ -0,0 +1,72 @@
185 +/* vi: set sw=4 ts=4: */
186 +/* Ubicom32 ELF shared library loader suppport
187 + *
188 + * Copyright (c) 2009 Ubicom Inc.
189 + * Copyright (c) 1994-2000 Eric Youngdale, Peter MacDonald,
190 + * David Engel, Hongjiu Lu and Mitch D'Souza
191 + * Copyright (C) 2001-2004 Erik Andersen
192 + *
193 + * All rights reserved.
194 + *
195 + * Redistribution and use in source and binary forms, with or without
196 + * modification, are permitted provided that the following conditions
197 + * are met:
198 + * 1. Redistributions of source code must retain the above copyright
199 + * notice, this list of conditions and the following disclaimer.
200 + * 2. The name of the above contributors may not be
201 + * used to endorse or promote products derived from this software
202 + * without specific prior written permission.
203 + *
204 + * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND
205 + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
206 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
207 + * ARE DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE
208 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
209 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
210 + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
211 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
212 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
213 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
214 + * SUCH DAMAGE.
215 + */
216 +
217 +static const char *_dl_reltypes_tab[] =
218 +{
219 + "R_UBICOM32_NONE", /* 0 */
220 + "R_UBICOM32_16",
221 + "R_UBICOM32_32",
222 + "R_UBICOM32_LO16",
223 + "R_UBICOM32_HI16",
224 + "R_UBICOM32_21_PCREL", /* 5 */
225 + "R_UBICOM32_24_PCREL",
226 + "R_UBICOM32_HI24",
227 + "R_UBICOM32_LO7_S",
228 + "R_UBICOM32_LO7_2_S",
229 + "R_UBICOM32_LO7_4_S", /* 10 */
230 + "R_UBICOM32_LO7_D",
231 + "R_UBICOM32_LO7_2_D",
232 + "R_UBICOM32_LO7_4_D",
233 + "R_UBICOM32_32_HARVARD",
234 + "R_UBICOM32_LO7_CALLI", /* 15 */
235 + "R_UBICOM32_LO16_CALLI",
236 + "R_UBICOM32_GOT_HI24",
237 + "R_UBICOM32_GOT_LO7_S",
238 + "R_UBICOM32_GOT_LO7_2_S"
239 + "R_UBICOM32_GOT_LO7_4_S", /* 20 */
240 + "R_UBICOM32_GOT_LO7_D",
241 + "R_UBICOM32_GOT_LO7_2_D",
242 + "R_UBICOM32_GOT_LO7_4_D",
243 + "R_UBICOM32_FUNCDESC_GOT_HI24 24",
244 + "R_UBICOM32_FUNCDESC_GOT_LO7_S", /* 25 */
245 + "R_UBICOM32_FUNCDESC_GOT_LO7_2_S",
246 + "R_UBICOM32_FUNCDESC_GOT_LO7_4_S",
247 + "R_UBICOM32_FUNCDESC_GOT_LO7_D",
248 + "R_UBICOM32_FUNCDESC_GOT_LO7_2_D",
249 + "R_UBICOM32_FUNCDESC_GOT_LO7_4_D", /* 30 */
250 + "R_UBICOM32_GOT_LO7_CALLI",
251 + "R_UBICOM32_FUNCDESC_VALUE",
252 + "R_UBICOM32_FUNCDESC",
253 +#if 1
254 + [200] "R_UBICOM32_GNU_VTINHERIT" , "R_UBICOM32_GNU_VTENTRY"
255 +#endif
256 +};
257 --- /dev/null
258 +++ b/ldso/ldso/ubicom32/dl-inlines.h
259 @@ -0,0 +1,582 @@
260 + /* Copyright (C) 2003, 2004 Red Hat, Inc.
261 + Contributed by Alexandre Oliva <aoliva@redhat.com>
262 +
263 +This file is part of uClibc.
264 +
265 +uClibc is free software; you can redistribute it and/or modify it
266 +under the terms of the GNU Lesser General Public License as
267 +published by the Free Software Foundation; either version 2.1 of the
268 +License, or (at your option) any later version.
269 +
270 +uClibc is distributed in the hope that it will be useful, but WITHOUT
271 +ANY WARRANTY; without even the implied warranty of
272 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
273 +Library General Public License for more details.
274 +
275 +You should have received a copy of the GNU Lesser General Public
276 +License along with uClibc; see the file COPYING.LIB. If not, write to
277 +the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
278 +USA. */
279 +
280 +//#include <bfin_sram.h>
281 +#define SRAM_TEST(x) 0
282 +#ifndef _dl_assert
283 +# define _dl_assert(expr)
284 +#endif
285 +
286 +/* Initialize a DL_LOADADDR_TYPE given a got pointer and a complete
287 + load map. */
288 +static __always_inline void
289 +__dl_init_loadaddr_map (struct elf32_fdpic_loadaddr *loadaddr, Elf32_Addr dl_boot_got_pointer,
290 + struct elf32_fdpic_loadmap *map)
291 +{
292 + if (map->version != 0)
293 + {
294 + SEND_EARLY_STDERR ("Invalid loadmap version number\n");
295 + _dl_exit(-1);
296 + }
297 + if (map->nsegs == 0)
298 + {
299 + SEND_EARLY_STDERR ("Invalid segment count in loadmap\n");
300 + _dl_exit(-1);
301 + }
302 + loadaddr->got_value = (void*)dl_boot_got_pointer;
303 + loadaddr->map = map;
304 +}
305 +
306 +/* Figure out how many LOAD segments there are in the given headers,
307 + and allocate a block for the load map big enough for them.
308 + got_value will be properly initialized later on, with INIT_GOT. */
309 +static __always_inline int
310 +__dl_init_loadaddr (struct elf32_fdpic_loadaddr *loadaddr, Elf32_Phdr *ppnt,
311 + int pcnt)
312 +{
313 + int count = 0, i;
314 + size_t size;
315 +
316 + for (i = 0; i < pcnt; i++)
317 + if (ppnt[i].p_type == PT_LOAD)
318 + count++;
319 +
320 + loadaddr->got_value = 0;
321 +
322 + size = sizeof (struct elf32_fdpic_loadmap)
323 + + sizeof (struct elf32_fdpic_loadseg) * count;
324 + loadaddr->map = _dl_malloc (size);
325 + if (! loadaddr->map)
326 + _dl_exit (-1);
327 +
328 + loadaddr->map->version = 0;
329 + loadaddr->map->nsegs = 0;
330 +
331 + return count;
332 +}
333 +
334 +#if defined (__SUPPORT_LD_DEBUG__)
335 +extern char *_dl_debug;
336 +extern int _dl_debug_file;
337 +#endif
338 +
339 +/* Incrementally initialize a load map. */
340 +static __always_inline void
341 +__dl_init_loadaddr_hdr (struct elf32_fdpic_loadaddr loadaddr, void *addr,
342 + Elf32_Phdr *phdr, int maxsegs)
343 +{
344 + struct elf32_fdpic_loadseg *segdata;
345 +
346 + if (loadaddr.map->nsegs == maxsegs)
347 + _dl_exit (-1);
348 +
349 + segdata = &loadaddr.map->segs[loadaddr.map->nsegs++];
350 + segdata->addr = (Elf32_Addr) addr;
351 + segdata->p_vaddr = phdr->p_vaddr;
352 + segdata->p_memsz = phdr->p_memsz;
353 +
354 +#if defined (__SUPPORT_LD_DEBUG__)
355 + {
356 + if (_dl_debug)
357 + _dl_dprintf(_dl_debug_file, "%i: mapped %x at %x, size %x\n",
358 + loadaddr.map->nsegs-1,
359 + segdata->p_vaddr, segdata->addr, segdata->p_memsz);
360 + }
361 +#endif
362 +}
363 +
364 +static __always_inline void __dl_loadaddr_unmap
365 +(struct elf32_fdpic_loadaddr loadaddr, struct funcdesc_ht *funcdesc_ht);
366 +
367 +/* Figure out whether the given address is in one of the mapped
368 + segments. */
369 +static __always_inline int
370 +__dl_addr_in_loadaddr (void *p, struct elf32_fdpic_loadaddr loadaddr)
371 +{
372 + struct elf32_fdpic_loadmap *map = loadaddr.map;
373 + int c;
374 +
375 + for (c = 0; c < map->nsegs; c++)
376 + if ((void*)map->segs[c].addr <= p
377 + && (char*)p < (char*)map->segs[c].addr + map->segs[c].p_memsz)
378 + return 1;
379 +
380 + return 0;
381 +}
382 +
383 +static __always_inline void * _dl_funcdesc_for (void *entry_point, void *got_value);
384 +
385 +/* The hashcode handling code below is heavily inspired in libiberty's
386 + hashtab code, but with most adaptation points and support for
387 + deleting elements removed.
388 +
389 + Copyright (C) 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
390 + Contributed by Vladimir Makarov (vmakarov@cygnus.com). */
391 +
392 +static __always_inline unsigned long
393 +higher_prime_number (unsigned long n)
394 +{
395 + /* These are primes that are near, but slightly smaller than, a
396 + power of two. */
397 + static const unsigned long primes[] = {
398 + (unsigned long) 7,
399 + (unsigned long) 13,
400 + (unsigned long) 31,
401 + (unsigned long) 61,
402 + (unsigned long) 127,
403 + (unsigned long) 251,
404 + (unsigned long) 509,
405 + (unsigned long) 1021,
406 + (unsigned long) 2039,
407 + (unsigned long) 4093,
408 + (unsigned long) 8191,
409 + (unsigned long) 16381,
410 + (unsigned long) 32749,
411 + (unsigned long) 65521,
412 + (unsigned long) 131071,
413 + (unsigned long) 262139,
414 + (unsigned long) 524287,
415 + (unsigned long) 1048573,
416 + (unsigned long) 2097143,
417 + (unsigned long) 4194301,
418 + (unsigned long) 8388593,
419 + (unsigned long) 16777213,
420 + (unsigned long) 33554393,
421 + (unsigned long) 67108859,
422 + (unsigned long) 134217689,
423 + (unsigned long) 268435399,
424 + (unsigned long) 536870909,
425 + (unsigned long) 1073741789,
426 + (unsigned long) 2147483647,
427 + /* 4294967291L */
428 + ((unsigned long) 2147483647) + ((unsigned long) 2147483644),
429 + };
430 +
431 + const unsigned long *low = &primes[0];
432 + const unsigned long *high = &primes[sizeof(primes) / sizeof(primes[0])];
433 +
434 + while (low != high)
435 + {
436 + const unsigned long *mid = low + (high - low) / 2;
437 + if (n > *mid)
438 + low = mid + 1;
439 + else
440 + high = mid;
441 + }
442 +
443 +#if 0
444 + /* If we've run out of primes, abort. */
445 + if (n > *low)
446 + {
447 + fprintf (stderr, "Cannot find prime bigger than %lu\n", n);
448 + abort ();
449 + }
450 +#endif
451 +
452 + return *low;
453 +}
454 +
455 +struct funcdesc_ht
456 +{
457 + /* Table itself. */
458 + struct funcdesc_value **entries;
459 +
460 + /* Current size (in entries) of the hash table */
461 + size_t size;
462 +
463 + /* Current number of elements. */
464 + size_t n_elements;
465 +};
466 +
467 +static __always_inline int
468 +hash_pointer (const void *p)
469 +{
470 + return (int) ((long)p >> 3);
471 +}
472 +
473 +static __always_inline struct funcdesc_ht *
474 +htab_create (void)
475 +{
476 + struct funcdesc_ht *ht = _dl_malloc (sizeof (struct funcdesc_ht));
477 +
478 + if (! ht)
479 + return NULL;
480 + ht->size = 3;
481 + ht->entries = _dl_malloc (sizeof (struct funcdesc_ht_value *) * ht->size);
482 + if (! ht->entries)
483 + return NULL;
484 +
485 + ht->n_elements = 0;
486 +
487 + _dl_memset (ht->entries, 0, sizeof (struct funcdesc_ht_value *) * ht->size);
488 +
489 + return ht;
490 +}
491 +
492 +/* This is only called from _dl_loadaddr_unmap, so it's safe to call
493 + _dl_free(). See the discussion below. */
494 +static __always_inline void
495 +htab_delete (struct funcdesc_ht *htab)
496 +{
497 + int i;
498 +
499 + for (i = htab->size - 1; i >= 0; i--)
500 + if (htab->entries[i])
501 + _dl_free (htab->entries[i]);
502 +
503 + _dl_free (htab->entries);
504 + _dl_free (htab);
505 +}
506 +
507 +/* Similar to htab_find_slot, but without several unwanted side effects:
508 + - Does not call htab->eq_f when it finds an existing entry.
509 + - Does not change the count of elements/searches/collisions in the
510 + hash table.
511 + This function also assumes there are no deleted entries in the table.
512 + HASH is the hash value for the element to be inserted. */
513 +
514 +static __always_inline struct funcdesc_value **
515 +find_empty_slot_for_expand (struct funcdesc_ht *htab, int hash)
516 +{
517 + size_t size = htab->size;
518 + unsigned int index = hash % size;
519 + struct funcdesc_value **slot = htab->entries + index;
520 + int hash2;
521 +
522 + if (! *slot)
523 + return slot;
524 +
525 + hash2 = 1 + hash % (size - 2);
526 + for (;;)
527 + {
528 + index += hash2;
529 + if (index >= size)
530 + index -= size;
531 +
532 + slot = htab->entries + index;
533 + if (! *slot)
534 + return slot;
535 + }
536 +}
537 +
538 +/* The following function changes size of memory allocated for the
539 + entries and repeatedly inserts the table elements. The occupancy
540 + of the table after the call will be about 50%. Naturally the hash
541 + table must already exist. Remember also that the place of the
542 + table entries is changed. If memory allocation failures are allowed,
543 + this function will return zero, indicating that the table could not be
544 + expanded. If all goes well, it will return a non-zero value. */
545 +
546 +static __always_inline int
547 +htab_expand (struct funcdesc_ht *htab)
548 +{
549 + struct funcdesc_value **oentries;
550 + struct funcdesc_value **olimit;
551 + struct funcdesc_value **p;
552 + struct funcdesc_value **nentries;
553 + size_t nsize;
554 +
555 + oentries = htab->entries;
556 + olimit = oentries + htab->size;
557 +
558 + /* Resize only when table after removal of unused elements is either
559 + too full or too empty. */
560 + if (htab->n_elements * 2 > htab->size)
561 + nsize = higher_prime_number (htab->n_elements * 2);
562 + else
563 + nsize = htab->size;
564 +
565 + nentries = _dl_malloc (sizeof (struct funcdesc_value *) * nsize);
566 + _dl_memset (nentries, 0, sizeof (struct funcdesc_value *) * nsize);
567 + if (nentries == NULL)
568 + return 0;
569 + htab->entries = nentries;
570 + htab->size = nsize;
571 +
572 + p = oentries;
573 + do
574 + {
575 + if (*p)
576 + *find_empty_slot_for_expand (htab, hash_pointer ((*p)->entry_point))
577 + = *p;
578 +
579 + p++;
580 + }
581 + while (p < olimit);
582 +
583 +#if 0 /* We can't tell whether this was allocated by the _dl_malloc()
584 + built into ld.so or malloc() in the main executable or libc,
585 + and calling free() for something that wasn't malloc()ed could
586 + do Very Bad Things (TM). Take the conservative approach
587 + here, potentially wasting as much memory as actually used by
588 + the hash table, even if multiple growths occur. That's not
589 + so bad as to require some overengineered solution that would
590 + enable us to keep track of how it was allocated. */
591 + _dl_free (oentries);
592 +#endif
593 + return 1;
594 +}
595 +
596 +/* This function searches for a hash table slot containing an entry
597 + equal to the given element. To delete an entry, call this with
598 + INSERT = 0, then call htab_clear_slot on the slot returned (possibly
599 + after doing some checks). To insert an entry, call this with
600 + INSERT = 1, then write the value you want into the returned slot.
601 + When inserting an entry, NULL may be returned if memory allocation
602 + fails. */
603 +
604 +static __always_inline struct funcdesc_value **
605 +htab_find_slot (struct funcdesc_ht *htab, void *ptr, int insert)
606 +{
607 + unsigned int index;
608 + int hash, hash2;
609 + size_t size;
610 + struct funcdesc_value **entry;
611 +
612 + if (htab->size * 3 <= htab->n_elements * 4
613 + && htab_expand (htab) == 0)
614 + return NULL;
615 +
616 + hash = hash_pointer (ptr);
617 +
618 + size = htab->size;
619 + index = hash % size;
620 +
621 + entry = &htab->entries[index];
622 + if (!*entry)
623 + goto empty_entry;
624 + else if ((*entry)->entry_point == ptr)
625 + return entry;
626 +
627 + hash2 = 1 + hash % (size - 2);
628 + for (;;)
629 + {
630 + index += hash2;
631 + if (index >= size)
632 + index -= size;
633 +
634 + entry = &htab->entries[index];
635 + if (!*entry)
636 + goto empty_entry;
637 + else if ((*entry)->entry_point == ptr)
638 + return entry;
639 + }
640 +
641 + empty_entry:
642 + if (!insert)
643 + return NULL;
644 +
645 + htab->n_elements++;
646 + return entry;
647 +}
648 +
649 +void *
650 +_dl_funcdesc_for (void *entry_point, void *got_value)
651 +{
652 + struct elf_resolve *tpnt = ((void**)got_value)[2];
653 + struct funcdesc_ht *ht = tpnt->funcdesc_ht;
654 + struct funcdesc_value **entry;
655 +
656 + _dl_assert (got_value == tpnt->loadaddr.got_value);
657 +
658 + if (! ht)
659 + {
660 + ht = htab_create ();
661 + if (! ht)
662 + return (void*)-1;
663 + tpnt->funcdesc_ht = ht;
664 + }
665 +
666 + entry = htab_find_slot (ht, entry_point, 1);
667 + if (*entry)
668 + {
669 + _dl_assert ((*entry)->entry_point == entry_point);
670 + return _dl_stabilize_funcdesc (*entry);
671 + }
672 +
673 + *entry = _dl_malloc (sizeof (struct funcdesc_value));
674 + (*entry)->entry_point = entry_point;
675 + (*entry)->got_value = got_value;
676 +
677 + return _dl_stabilize_funcdesc (*entry);
678 +}
679 +
680 +static __always_inline void const *
681 +_dl_lookup_address (void const *address)
682 +{
683 + struct elf_resolve *rpnt;
684 + struct funcdesc_value const *fd;
685 +
686 + /* Make sure we don't make assumptions about its alignment. */
687 + __asm__ ("" : "+r" (address));
688 +
689 + if ((Elf32_Addr)address & 7)
690 + /* It's not a function descriptor. */
691 + return address;
692 +
693 + fd = (struct funcdesc_value const *)address;
694 +
695 + for (rpnt = _dl_loaded_modules; rpnt; rpnt = rpnt->next)
696 + {
697 + if (! rpnt->funcdesc_ht)
698 + continue;
699 +
700 + if (fd->got_value != rpnt->loadaddr.got_value)
701 + continue;
702 +
703 + address = htab_find_slot (rpnt->funcdesc_ht, (void*)fd->entry_point, 0);
704 +
705 + if (address && *(struct funcdesc_value *const*)address == fd)
706 + {
707 + address = (*(struct funcdesc_value *const*)address)->entry_point;
708 + break;
709 + }
710 + else
711 + address = fd;
712 + }
713 +
714 + return address;
715 +}
716 +
717 +void
718 +__dl_loadaddr_unmap (struct elf32_fdpic_loadaddr loadaddr,
719 + struct funcdesc_ht *funcdesc_ht)
720 +{
721 + int i;
722 +
723 + for (i = 0; i < loadaddr.map->nsegs; i++)
724 + {
725 + struct elf32_fdpic_loadseg *segdata;
726 + ssize_t offs;
727 + segdata = loadaddr.map->segs + i;
728 +
729 +#if 0 /* SRAM */
730 + /* FIXME:
731 + A more cleaner way is to add type for struct elf32_fdpic_loadseg,
732 + and release the memory according to the type.
733 + Currently, we hardcode the memory address of L1 SRAM. */
734 + if ((segdata->addr & 0xff800000) == 0xff800000)
735 + {
736 + _dl_sram_free ((void *)segdata->addr);
737 + continue;
738 + }
739 +#endif
740 + offs = (segdata->p_vaddr & ADDR_ALIGN);
741 + _dl_munmap ((void*)segdata->addr - offs,
742 + segdata->p_memsz + offs);
743 + }
744 + /* _dl_unmap is only called for dlopen()ed libraries, for which
745 + calling free() is safe, or before we've completed the initial
746 + relocation, in which case calling free() is probably pointless,
747 + but still safe. */
748 + _dl_free (loadaddr.map);
749 + if (funcdesc_ht)
750 + htab_delete (funcdesc_ht);
751 +}
752 +
753 +#if 0 /* XXX TODO will look at enabling this if we decide to add support for OCM
754 + * code/data */
755 +// OLD BLACKFIN CODE
756 +static __always_inline int
757 +__dl_is_special_segment (Elf32_Ehdr *epnt,
758 + Elf32_Phdr *ppnt)
759 +{
760 + if (ppnt->p_type != PT_LOAD)
761 + return 0;
762 +
763 + if ((epnt->e_flags & EF_BFIN_CODE_IN_L1)
764 + && !(ppnt->p_flags & PF_W)
765 + && (ppnt->p_flags & PF_X))
766 + return 1;
767 +
768 + if ((epnt->e_flags & EF_BFIN_DATA_IN_L1)
769 + && (ppnt->p_flags & PF_W)
770 + && !(ppnt->p_flags & PF_X))
771 + return 1;
772 +
773 + /* 0xff700000, 0xff800000, 0xff900000 and 0xffa00000 are also used in
774 + GNU ld and linux kernel. They need to be keep synchronized. */
775 + if (ppnt->p_vaddr == 0xff700000
776 + || ppnt->p_vaddr == 0xff800000
777 + || ppnt->p_vaddr == 0xff900000
778 + || ppnt->p_vaddr == 0xffa00000)
779 + return 1;
780 +
781 + return 0;
782 +}
783 +
784 +static __always_inline char *
785 +__dl_map_segment (Elf32_Ehdr *epnt,
786 + Elf32_Phdr *ppnt,
787 + int infile,
788 + int flags)
789 +{
790 + char *status, *tryaddr, *l1addr;
791 + size_t size;
792 +
793 +
794 + if (((epnt->e_flags & EF_BFIN_CODE_IN_L1) || ppnt->p_vaddr == 0xffa00000)
795 + && !(ppnt->p_flags & PF_W)
796 + && (ppnt->p_flags & PF_X)) {
797 + status = (char *) _dl_mmap
798 + (tryaddr = 0,
799 + size = (ppnt->p_vaddr & ADDR_ALIGN) + ppnt->p_filesz,
800 + LXFLAGS(ppnt->p_flags),
801 + flags | MAP_EXECUTABLE | MAP_DENYWRITE,
802 + infile, ppnt->p_offset & OFFS_ALIGN);
803 + if (_dl_mmap_check_error(status)
804 + || (tryaddr && tryaddr != status))
805 + return NULL;
806 + l1addr = (char *) _dl_sram_alloc (ppnt->p_filesz, L1_INST_SRAM);
807 + if (l1addr != NULL)
808 + _dl_dma_memcpy (l1addr, status + (ppnt->p_vaddr & ADDR_ALIGN), ppnt->p_filesz);
809 + _dl_munmap (status, size);
810 + if (l1addr == NULL)
811 + _dl_dprintf(2, "%s:%i: L1 allocation failed\n", _dl_progname, __LINE__);
812 + return l1addr;
813 + }
814 +
815 + if (((epnt->e_flags & EF_BFIN_DATA_IN_L1)
816 + || ppnt->p_vaddr == 0xff700000
817 + || ppnt->p_vaddr == 0xff800000
818 + || ppnt->p_vaddr == 0xff900000)
819 + && (ppnt->p_flags & PF_W)
820 + && !(ppnt->p_flags & PF_X)) {
821 + if (ppnt->p_vaddr == 0xff800000)
822 + l1addr = (char *) _dl_sram_alloc (ppnt->p_memsz, L1_DATA_A_SRAM);
823 + else if (ppnt->p_vaddr == 0xff900000)
824 + l1addr = (char *) _dl_sram_alloc (ppnt->p_memsz, L1_DATA_B_SRAM);
825 + else
826 + l1addr = (char *) _dl_sram_alloc (ppnt->p_memsz, L1_DATA_SRAM);
827 + if (l1addr == NULL) {
828 + _dl_dprintf(2, "%s:%i: L1 allocation failed\n", _dl_progname, __LINE__);
829 + } else {
830 + if (_DL_PREAD (infile, l1addr, ppnt->p_filesz, ppnt->p_offset) != ppnt->p_filesz) {
831 + _dl_sram_free (l1addr);
832 + return NULL;
833 + }
834 + if (ppnt->p_filesz < ppnt->p_memsz)
835 + _dl_memset (l1addr + ppnt->p_filesz, 0, ppnt->p_memsz - ppnt->p_filesz);
836 + }
837 + return l1addr;
838 + }
839 + return 0;
840 +}
841 +#endif
842 --- /dev/null
843 +++ b/ldso/ldso/ubicom32/dl-startup.h
844 @@ -0,0 +1,232 @@
845 +/*
846 + Copyright (C) 2009 Ubicom, Inc.
847 + Copyright (C) 2003 Red Hat, Inc.
848 + Contributed by Alexandre Oliva <aoliva@redhat.com>
849 +
850 +This file is part of uClibc.
851 +
852 +uClibc is free software; you can redistribute it and/or modify it
853 +under the terms of the GNU Lesser General Public License as
854 +published by the Free Software Foundation; either version 2.1 of the
855 +License, or (at your option) any later version.
856 +
857 +uClibc is distributed in the hope that it will be useful, but WITHOUT
858 +ANY WARRANTY; without even the implied warranty of
859 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
860 +Library General Public License for more details.
861 +
862 +You should have received a copy of the GNU Lesser General Public
863 +License along with uClibc; see the file COPYING.LIB. If not, write to
864 +the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
865 +USA. */
866 +
867 +/* Any assembly language/system dependent hacks needed to setup
868 + * boot1.c so it will work as expected and cope with whatever platform
869 + * specific wierdness is needed for this architecture.
870 +
871 + * We override the default _dl_boot function, and replace it with a
872 + * bit of asm. Then call the real _dl_boot function, which is now
873 + * named _dl_boot2. */
874 +
875 +/* At program start-up, p0 contains a pointer to a
876 + elf32_fdpic_loadmap that describes how the executable was loaded
877 + into memory. p1 contains a pointer to the interpreter (our!)
878 + loadmap, if there is an interpreter, or 0 if we're being run as an
879 + executable. p2 holds a pointer to the interpreter's dynamic
880 + section, if there is an interpreter, or to the executable's dynamic
881 + section, otherwise. If the executable is not dynamic, gr18 is 0.
882 +
883 + We rely on the fact that the linker adds a pointer to the
884 + _GLOBAL_OFFSET_TABLE_ as the last ROFIXUP entry, and that
885 + __self_reloc returns the relocated pointer to us, so that we can
886 + use this value to initialize the PIC register. */
887 +
888 +
889 +/*
890 + * _dl_boot is the entry point for ldso.
891 + *
892 + * The kernel leaves the main apps args on the stack (positive offsets), and
893 + * communicates the load maps as follows
894 + *
895 + * - d1 is set to the exec_map_addr (struct elf32_fdpic_loadmap *), which is the
896 + * current state of the mapped application.
897 + *
898 + * - d2 is set to interp_map_addr (struct elf32_fdpic_loadmap *), which is use
899 + * by ldso to relocate itself.
900 + *
901 + * - d3 is dynamic_addr which as far as I can tell is the stack pointer.
902 + *
903 + * - a1 is set to zero and will later be initialised to ldso _dl_fini funcdesc
904 + */
905 +
906 +__asm__(
907 + " .text \n\t"
908 + " .global _start \n\t"
909 + " .type _start,@function \n\t"
910 + "_start:\n\t"
911 + /*
912 + * Jump to .Lcall storing the location .Lcall in a5
913 + */
914 + " call a5, .Lcall \n\t"
915 + ".Lcall: \n\t"
916 + /*
917 + * Reserve and Push inputs to stack.
918 + * 32 byte stack layout as follows
919 + * offset 0 exec_map_addr
920 + * 4 interp_map_addr
921 + * 8 dynamic_addr
922 + * 12 not used
923 + * 16 dl_main_funcdesc structure for _dl_boot
924 + * (12 bytes sizeof funcdesc_value)
925 + * 28 reserved
926 + * 32 start of &original stack
927 + */
928 + " pdec sp, 32(sp); reserve stack space \n\t"
929 + " move.4 0(sp), d1 ; exec_map_addr \n\t"
930 + " move.4 4(sp), d2 ; interp_map_addr \n\t"
931 + " move.4 8(sp), d3; dynamic_addr \n\t"
932 +
933 + /*
934 + * Load linker version of .Lcall in to d0
935 + */
936 + " moveai a3, #%hi(.Lcall) \n\t"
937 + " lea.1 d0, %lo(.Lcall)(a3) \n\t"
938 +
939 + /*
940 + * Determine the offset from loaded .Lcall and put it in d0.
941 + */
942 + " sub.4 d0, a5, d0 \n\t"
943 +
944 + /*
945 + * Load linker version of __ROFIXUP_LIST__ and __ROFIXUP_END__ in to d1
946 + * and d2.
947 + */
948 + " moveai a3, #%hi(__ROFIXUP_LIST__) \n\t"
949 + " lea.1 d1, %lo(__ROFIXUP_LIST__)(a3) \n\t"
950 + " moveai a3, #%hi(__ROFIXUP_END__) \n\t"
951 + " lea.1 d2, %lo(__ROFIXUP_END__)(a3) \n\t"
952 + /*
953 + * Use offset determined above to find the loaded versions.
954 + */
955 + " add.4 d1, d1, d0 \n\t"
956 + " add.4 d2, d2, d0 \n\t"
957 +
958 + /*
959 + * Load interp_map_addr into d0, if interp_map_addr is null use
960 + * exec_map_addr.
961 + */
962 + " move.4 d0, 4(sp) ; load interp_map_addr \n\t"
963 + " cmpi d0, #0 \n\t"
964 + " jmpne.f 1f \n\t"
965 + " move.4 d0, 0(sp) ; load exec_map_addr \n\t"
966 +
967 + /*
968 + * call __self_reloc(map, void ***p, void ***e)
969 + * it returns the the GOT in d0.
970 + */
971 + "1: call a5, __self_reloc ; returns a0 in d0 \n\t"
972 + " move.4 a0, d0 ; set GOT \n\t"
973 + " move.4 a2, d0 ; save GOT \n\t"
974 +
975 + /*
976 + * now setup to call
977 + * _dl_start (Elf32_Addr dl_boot_got_pointer, (d0)
978 + * struct elf32_fdpic_loadmap *dl_boot_progmap, (d1)
979 + * struct elf32_fdpic_loadmap *dl_boot_ldsomap, (d2)
980 + * Elf32_Dyn *dl_boot_ldso_dyn_pointer, (d3)
981 + * struct funcdesc_value *dl_main_funcdesc, (d4)
982 + * unsigned long args (d5)
983 + *
984 + * NOTE: for dl_main_funcdesc we reserved space on the stack for this
985 + * structure.
986 + */
987 + " move.4 d1, 0(sp) ; d1 = exec_map_addr \n\t"
988 + " move.4 d2, 4(sp) ; d2 = interp_map_addr \n\t"
989 + " move.4 d3, 8(sp) ; d3 = dynamic_addr \n\t"
990 + " lea.1 d4, 16(sp) ; d4 = &dl_main_funcdesc \n\t"
991 + " lea.1 d5, 32(sp) ; d5 = original stack ptr (args)\n\t"
992 + " call a5, _dl_start \n\t"
993 +
994 + /*
995 + * Setup to call the main entry point, starting with passing our FINI
996 + * ptr() to the user in a1 (remember we saved the got in a2)
997 + */
998 + " movei d15, #%got_funcdesc_lo(_dl_fini) \n\t"
999 + " move.4 a1, (a2, d15) \n\t"
1000 +
1001 + /*
1002 + * restore the load map from the kernel.
1003 + */
1004 + " move.4 d1, 0(sp) ; restore exec_map_addr \n\t"
1005 + " move.4 d2, 4(sp) ; restore interp_map_addr \n\t"
1006 + " move.4 d3, 8(sp) ; restore dynamic_addr \n\t"
1007 +
1008 + /*
1009 + * _dl_start returned the main apps entry point in dl_main_funcdesc,
1010 + * load that information now.
1011 + */
1012 + " move.4 a5, 16(sp) ; a5 = dl_main_funcdesc.entry_point \n\t"
1013 + " move.4 a0, 20(sp) ; a0 = dl_main_funcdesc.got_value \n\t"
1014 + " lea.1 sp, 32(sp); restore original stack ptr (args) \n\t"
1015 + " calli a5, 0(a5) \n\t"
1016 + " bkpt -1; should never get here \n\t"
1017 + " .size _start, . - _start \n\t"
1018 +);
1019 +
1020 +#undef DL_START
1021 +#define DL_START(X) \
1022 +static void __attribute__ ((used)) \
1023 +_dl_start (Elf32_Addr dl_boot_got_pointer, \
1024 + struct elf32_fdpic_loadmap *dl_boot_progmap, \
1025 + struct elf32_fdpic_loadmap *dl_boot_ldsomap, \
1026 + Elf32_Dyn *dl_boot_ldso_dyn_pointer, \
1027 + struct funcdesc_value *dl_main_funcdesc, \
1028 + X)
1029 +
1030 +struct elf32_fdpic_loadmap;
1031 +
1032 +/*
1033 + * Get a pointer to the argv array. On many platforms this can be just
1034 + * the address if the first argument, on other platforms we need to
1035 + * do something a little more subtle here.
1036 + */
1037 +#define GET_ARGV(ARGVP, ARGS) ARGVP = (((unsigned long*) ARGS) + 1)
1038 +
1039 +/*
1040 + * Here is a macro to perform a relocation. This is only used when
1041 + * bootstrapping the dynamic loader. RELP is the relocation that we
1042 + * are performing, REL is the pointer to the address we are relocating.
1043 + * SYMBOL is the symbol involved in the relocation, and LOAD is the
1044 + * load address.
1045 + */
1046 +#define PERFORM_BOOTSTRAP_RELOC(RELP,REL,SYMBOL,LOAD,SYMTAB) \
1047 + switch(ELF32_R_TYPE((RELP)->r_info)){ \
1048 + case R_UBICOM32_32: \
1049 + *(REL) += (SYMBOL); \
1050 + break; \
1051 + case R_UBICOM32_FUNCDESC_VALUE: \
1052 + { \
1053 + struct funcdesc_value fv = { \
1054 + (void*)((SYMBOL) + *(REL)), \
1055 + (LOAD).got_value \
1056 + }; \
1057 + *(struct funcdesc_value volatile *)(REL) = fv; \
1058 + break; \
1059 + } \
1060 + default: \
1061 + _dl_exit(1); \
1062 + }
1063 +
1064 +/*
1065 + * Transfer control to the user's application, once the dynamic loader
1066 + * is done. We return the address of the function's entry point to
1067 + * _dl_boot, see boot1_arch.h.
1068 + */
1069 +#define START() do { \
1070 + struct elf_resolve *exec_mod = _dl_loaded_modules; \
1071 + dl_main_funcdesc->entry_point = _dl_elf_main; \
1072 + while (exec_mod->libtype != elf_executable) \
1073 + exec_mod = exec_mod->next; \
1074 + dl_main_funcdesc->got_value = exec_mod->loadaddr.got_value; \
1075 + return; \
1076 +} while (0)
1077 --- /dev/null
1078 +++ b/ldso/ldso/ubicom32/dl-syscalls.h
1079 @@ -0,0 +1,206 @@
1080 +/* Copyright (C) 2003, 2004 Red Hat, Inc.
1081 + Contributed by Alexandre Oliva <aoliva@redhat.com>
1082 +
1083 +This file is part of uClibc.
1084 +
1085 +uClibc is free software; you can redistribute it and/or modify it
1086 +under the terms of the GNU Lesser General Public License as
1087 +published by the Free Software Foundation; either version 2.1 of the
1088 +License, or (at your option) any later version.
1089 +
1090 +uClibc is distributed in the hope that it will be useful, but WITHOUT
1091 +ANY WARRANTY; without even the implied warranty of
1092 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1093 +Library General Public License for more details.
1094 +
1095 +You should have received a copy of the GNU Lesser General Public
1096 +License along with uClibc; see the file COPYING.LIB. If not, write to
1097 +the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
1098 +USA. */
1099 +
1100 +/* We can't use the real errno in ldso, since it has not yet
1101 + * been dynamicly linked in yet. */
1102 +#include "sys/syscall.h"
1103 +extern int _dl_errno;
1104 +#undef __set_errno
1105 +#define __set_errno(X) {(_dl_errno) = (X);}
1106 +#include <sys/mman.h>
1107 +
1108 +/* The code below is extracted from libc/sysdeps/linux/frv/_mmap.c */
1109 +
1110 +#if defined(DYNAMIC_LOADER_IN_SIMULATOR) && DYNAMIC_LOADER_IN_SIMULATOR
1111 +#define __NR___syscall_mmap2 __NR_mmap2
1112 +static __inline__ _syscall6(__ptr_t, __syscall_mmap2, __ptr_t, addr,
1113 + size_t, len, int, prot, int, flags, int, fd, off_t, offset);
1114 +
1115 +/* Make sure we don't get another definition of _dl_mmap from the
1116 + machine-independent code. */
1117 +#undef __NR_mmap
1118 +#undef __NR_mmap2
1119 +
1120 +/* This is always 12, even on architectures where PAGE_SHIFT != 12. */
1121 +# ifndef MMAP2_PAGE_SHIFT
1122 +# define MMAP2_PAGE_SHIFT 12
1123 +# endif
1124 +
1125 +#include <bits/uClibc_page.h> /* for PAGE_SIZE */
1126 +static __always_inline void *_dl_memset(void*,int,size_t);
1127 +static __always_inline ssize_t _dl_pread(int fd, void *buf, size_t count, off_t offset);
1128 +
1129 +static __ptr_t
1130 +_dl_mmap(__ptr_t addr, size_t len, int prot, int flags, int fd, __off_t offset)
1131 +{
1132 + size_t plen = (len + PAGE_SIZE - 1) & -PAGE_SIZE;
1133 +
1134 +/* This is a hack to enable the dynamic loader to run within a
1135 + simulator that doesn't support mmap, with a number of very ugly
1136 + tricks. Also, it's not as useful as it sounds, since only dynamic
1137 + executables without DT_NEEDED dependencies can be run. AFAIK, they
1138 + can only be created with -pie. This trick suffices to enable the
1139 + dynamic loader to obtain a blank page that it maps early in the
1140 + bootstrap. */
1141 + if ((flags & MAP_FIXED) == 0)
1142 + {
1143 + void *_dl_mmap_base = 0;
1144 + __ptr_t *ret = 0;
1145 +
1146 + if (! _dl_mmap_base)
1147 + {
1148 + void *stack;
1149 + __asm__ ("mov sp, %0" : "=r" (stack));
1150 + _dl_mmap_base = (void *)(((long)stack + 2 * PAGE_SIZE) & -PAGE_SIZE);
1151 + retry:
1152 + if (((void **)_dl_mmap_base)[0] == _dl_mmap_base
1153 + && ((void **)_dl_mmap_base)[1023] == _dl_mmap_base
1154 + && (((void **)_dl_mmap_base)[177]
1155 + == ((void **)_dl_mmap_base)[771]))
1156 + {
1157 + while (((void**)_dl_mmap_base)[177])
1158 + {
1159 + _dl_mmap_base = ((void**)_dl_mmap_base)[177];
1160 + if (!(((void **)_dl_mmap_base)[0] == _dl_mmap_base
1161 + && ((void **)_dl_mmap_base)[1023] == _dl_mmap_base
1162 + && (((void **)_dl_mmap_base)[177]
1163 + == ((void**)_dl_mmap_base)[771])))
1164 + ((void(*)())0)();
1165 + }
1166 + }
1167 + else
1168 + {
1169 + int i;
1170 + for (i = 0; i < (int)PAGE_SIZE; i++)
1171 + if (*(char*)(_dl_mmap_base + i))
1172 + break;
1173 + if (i != PAGE_SIZE)
1174 + {
1175 + _dl_mmap_base = (void*)((long)_dl_mmap_base + PAGE_SIZE);
1176 + goto retry;
1177 + }
1178 + ((void**)_dl_mmap_base)[-1] =
1179 + ((void**)_dl_mmap_base)[0] =
1180 + ((void**)_dl_mmap_base)[1023] =
1181 + _dl_mmap_base;
1182 + }
1183 + }
1184 +
1185 + if (_dl_mmap_base)
1186 + {
1187 + if (!(((void **)_dl_mmap_base)[0] == _dl_mmap_base
1188 + && ((void **)_dl_mmap_base)[1023] == _dl_mmap_base
1189 + && (((void **)_dl_mmap_base)[177]
1190 + == ((void**)_dl_mmap_base)[771])))
1191 + ((void(*)())0)();
1192 + ret = (__ptr_t)((char*)_dl_mmap_base + PAGE_SIZE);
1193 + _dl_mmap_base =
1194 + ((void**)_dl_mmap_base)[177] =
1195 + ((void**)_dl_mmap_base)[771] =
1196 + (char*)_dl_mmap_base + plen + PAGE_SIZE;
1197 + ((void**)_dl_mmap_base)[0] =
1198 + ((void**)_dl_mmap_base)[1023] =
1199 + _dl_mmap_base;
1200 + }
1201 +
1202 + if ((flags & MAP_ANONYMOUS) != 0)
1203 + {
1204 + _dl_memset (ret, 0, plen);
1205 + return ret;
1206 + }
1207 +
1208 + flags |= MAP_FIXED;
1209 + addr = ret;
1210 + }
1211 + if (offset & ((1 << MMAP2_PAGE_SHIFT) - 1)) {
1212 +#if 0
1213 + __set_errno (EINVAL);
1214 +#endif
1215 + return MAP_FAILED;
1216 + }
1217 + if ((flags & MAP_FIXED) != 0)
1218 + {
1219 + if (_dl_pread(fd, addr, len, offset) != (ssize_t)len)
1220 + return (void*)MAP_FAILED;
1221 + if (plen != len)
1222 + _dl_memset (addr + len, 0, plen - len);
1223 + return addr;
1224 + }
1225 + return(__syscall_mmap2(addr, len, prot, flags, fd, (off_t) (offset >> MMAP2_PAGE_SHIFT)));
1226 +}
1227 +#endif
1228 +
1229 +#ifdef __NR_pread64
1230 +#ifdef DYNAMIC_LOADER_IN_SIMULATOR
1231 +#include <unistd.h>
1232 +
1233 +#define __NR___syscall_lseek __NR_lseek
1234 +static __always_inline unsigned long _dl_read(int fd, const void *buf, unsigned long count);
1235 +
1236 +static __always_inline _syscall3(__off_t, __syscall_lseek, int, fd, __off_t, offset,
1237 + int, whence);
1238 +static __always_inline ssize_t
1239 +_dl_pread(int fd, void *buf, size_t count, off_t offset)
1240 +{
1241 + __off_t orig = __syscall_lseek (fd, 0, SEEK_CUR);
1242 + ssize_t ret;
1243 +
1244 + if (orig == -1)
1245 + return -1;
1246 +
1247 + if (__syscall_lseek (fd, offset, SEEK_SET) != offset)
1248 + return -1;
1249 +
1250 + ret = _dl_read (fd, buf, count);
1251 +
1252 + if (__syscall_lseek (fd, orig, SEEK_SET) != orig)
1253 + ((void(*)())0)();
1254 +
1255 + return ret;
1256 +}
1257 +#else
1258 +#define __NR___syscall_pread __NR_pread64
1259 +static __always_inline _syscall5(ssize_t, __syscall_pread, int, fd, void *, buf,
1260 + size_t, count, off_t, offset_hi, off_t, offset_lo);
1261 +
1262 +static __always_inline ssize_t
1263 +_dl_pread(int fd, void *buf, size_t count, off_t offset)
1264 +{
1265 + return(__syscall_pread(fd,buf,count,__LONG_LONG_PAIR (offset >> 31, offset)));
1266 +}
1267 +#endif
1268 +#endif
1269 +
1270 +#ifdef __NR_sram_alloc
1271 +#define __NR__dl_sram_alloc __NR_sram_alloc
1272 +static __always_inline _syscall2(__ptr_t, _dl_sram_alloc,
1273 + size_t, len, unsigned long, flags);
1274 +#endif
1275 +
1276 +#ifdef __NR_sram_free
1277 +#define __NR__dl_sram_free __NR_sram_free
1278 +static __always_inline _syscall1(int, _dl_sram_free, __ptr_t, addr);
1279 +#endif
1280 +
1281 +#ifdef __NR_dma_memcpy
1282 +#define __NR__dl_dma_memcpy __NR_dma_memcpy
1283 +static __always_inline _syscall3(__ptr_t, _dl_dma_memcpy,
1284 + __ptr_t, dest, __ptr_t, src, size_t, len);
1285 +#endif
1286 --- /dev/null
1287 +++ b/ldso/ldso/ubicom32/dl-sysdep.h
1288 @@ -0,0 +1,243 @@
1289 + /* Copyright (C) 2003, 2004 Red Hat, Inc.
1290 + Contributed by Alexandre Oliva <aoliva@redhat.com>
1291 + Based on ../i386/dl-sysdep.h
1292 +
1293 +This file is part of uClibc.
1294 +
1295 +uClibc is free software; you can redistribute it and/or modify it
1296 +under the terms of the GNU Lesser General Public License as
1297 +published by the Free Software Foundation; either version 2.1 of the
1298 +License, or (at your option) any later version.
1299 +
1300 +uClibc is distributed in the hope that it will be useful, but WITHOUT
1301 +ANY WARRANTY; without even the implied warranty of
1302 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1303 +Library General Public License for more details.
1304 +
1305 +You should have received a copy of the GNU Lesser General Public
1306 +License along with uClibc; see the file COPYING.LIB. If not, write to
1307 +the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
1308 +USA. */
1309 +
1310 +/*
1311 + * Various assembly language/system dependent hacks that are required
1312 + * so that we can minimize the amount of platform specific code.
1313 + */
1314 +
1315 +/*
1316 + * Define this if the system uses RELOCA.
1317 + */
1318 +#undef ELF_USES_RELOCA
1319 +
1320 +/* JMPREL relocs are inside the DT_RELA table. */
1321 +#define ELF_MACHINE_PLTREL_OVERLAP
1322 +
1323 +#define DL_NO_COPY_RELOCS
1324 +
1325 +#define HAVE_DL_INLINES_H
1326 +
1327 +/*
1328 + * Initialization sequence for a GOT. Copy the resolver function
1329 + * descriptor and the pointer to the elf_resolve/link_map data
1330 + * structure. Initialize the got_value in the module while at that.
1331 + */
1332 +#define INIT_GOT(GOT_BASE,MODULE) \
1333 +{ \
1334 + (MODULE)->loadaddr.got_value = (GOT_BASE); \
1335 + GOT_BASE[0] = ((unsigned long *)&_dl_linux_resolve)[0]; \
1336 + GOT_BASE[1] = ((unsigned long *)&_dl_linux_resolve)[1]; \
1337 + GOT_BASE[2] = (unsigned long) MODULE; \
1338 +}
1339 +
1340 +/* Here we define the magic numbers that this dynamic loader should accept */
1341 +#define MAGIC1 EM_UBICOM32
1342 +#undef MAGIC2
1343 +
1344 +/* Used for error messages */
1345 +#define ELF_TARGET "UBICOM32"
1346 +
1347 +struct elf_resolve;
1348 +
1349 +struct funcdesc_value
1350 +{
1351 + void *entry_point;
1352 + void *got_value;
1353 +/*int relocation; not sure if this required, but it does exist */
1354 +};
1355 +
1356 +extern int _dl_linux_resolve(void) __attribute__((__visibility__("hidden")));
1357 +extern struct funcdesc_value volatile *__attribute__((__visibility__("hidden")))
1358 + _dl_linux_resolver (struct elf_resolve *tpnt, int reloc_entry);
1359 +
1360 +/* 4KiB page alignment. Should perhaps be made dynamic using
1361 + getpagesize(), based on AT_PAGESZ from auxvt? */
1362 +#define PAGE_ALIGN 0xfffff000
1363 +#define ADDR_ALIGN 0xfff
1364 +#define OFFS_ALIGN 0x7ffff000
1365 +
1366 +struct funcdesc_ht;
1367 +
1368 +/*
1369 + * This asm does a quick relcation of string S (which is stored in the text
1370 + * section as thats all we can use
1371 + */
1372 +#undef SEND_EARLY_STDERR
1373 +#define SEND_EARLY_STDERR(S) \
1374 +do { \
1375 + static const char __attribute__((section(".text"))) __s[] = (S); \
1376 + const char *__p, *__scratch; \
1377 + __asm__ ( \
1378 + " call a3, 1f; \n\t" \
1379 + "1: movei %0, #%%got_lo(1b) \n\t" \
1380 + " move.4 %0, (%3, %0) \n\t" \
1381 + " sub.4 %1, a3, %0; \n\t" \
1382 + " add.4 %1, %1, %2; \n\t" \
1383 + : "=&d" (__scratch), "=&d" (__p) \
1384 + : "d" (__s), "a" (dl_boot_got_pointer) \
1385 + : "a3", "a4", "d15"); \
1386 + SEND_STDERR (__p); \
1387 + { int __t; \
1388 + for (__t = 0; __t < 0x100000; __t++) __asm__ __volatile__ (""); } \
1389 +} while (0)
1390 +
1391 +#define DL_LOADADDR_TYPE struct elf32_fdpic_loadaddr
1392 +
1393 +#define DL_RELOC_ADDR(LOADADDR, ADDR) \
1394 + ((ElfW(Addr))__reloc_pointer ((void*)(ADDR), (LOADADDR).map))
1395 +
1396 +#define DL_ADDR_TO_FUNC_PTR(ADDR, LOADADDR) \
1397 + ((void(*)(void)) _dl_funcdesc_for ((void*)(ADDR), (LOADADDR).got_value))
1398 +
1399 +#define _dl_stabilize_funcdesc(val) \
1400 + ({ __asm__ ("" : "+m" (*(val))); (val); })
1401 +
1402 +#define DL_CALL_FUNC_AT_ADDR(ADDR, LOADADDR, SIGNATURE, ...) \
1403 + ({ struct funcdesc_value fd = { (void*)(ADDR), (LOADADDR).got_value }; \
1404 + void (*pf)(void) = (void*) _dl_stabilize_funcdesc (&fd); \
1405 + (* SIGNATURE pf)(__VA_ARGS__); })
1406 +
1407 +#define DL_INIT_LOADADDR_BOOT(LOADADDR, BASEADDR) \
1408 + (__dl_init_loadaddr_map (&(LOADADDR), dl_boot_got_pointer, \
1409 + dl_boot_ldsomap ?: dl_boot_progmap))
1410 +
1411 +#define DL_INIT_LOADADDR_PROG(LOADADDR, BASEADDR) \
1412 + (__dl_init_loadaddr_map (&(LOADADDR), 0, dl_boot_progmap))
1413 +
1414 +#define DL_INIT_LOADADDR_EXTRA_DECLS \
1415 + int dl_init_loadaddr_load_count;
1416 +#define DL_INIT_LOADADDR(LOADADDR, BASEADDR, PHDR, PHDRCNT) \
1417 + (dl_init_loadaddr_load_count = \
1418 + __dl_init_loadaddr (&(LOADADDR), (PHDR), (PHDRCNT)))
1419 +#define DL_INIT_LOADADDR_HDR(LOADADDR, ADDR, PHDR) \
1420 + (__dl_init_loadaddr_hdr ((LOADADDR), (ADDR), (PHDR), \
1421 + dl_init_loadaddr_load_count))
1422 +#define DL_LOADADDR_UNMAP(LOADADDR, LEN) \
1423 + (__dl_loadaddr_unmap ((LOADADDR), (NULL)))
1424 +#define DL_LIB_UNMAP(LIB, LEN) \
1425 + (__dl_loadaddr_unmap ((LIB)->loadaddr, (LIB)->funcdesc_ht))
1426 +#define DL_LOADADDR_BASE(LOADADDR) \
1427 + ((LOADADDR).got_value)
1428 +
1429 +/* This is called from dladdr(), such that we map a function
1430 + descriptor's address to the function's entry point before trying to
1431 + find in which library it's defined. */
1432 +#define DL_LOOKUP_ADDRESS(ADDRESS) (_dl_lookup_address (ADDRESS))
1433 +
1434 +#define DL_ADDR_IN_LOADADDR(ADDR, TPNT, TFROM) \
1435 + (! (TFROM) && __dl_addr_in_loadaddr ((void*)(ADDR), (TPNT)->loadaddr))
1436 +
1437 +/*
1438 + * Compute the GOT address. On several platforms, we use assembly
1439 + * here. on FR-V FDPIC, there's no way to compute the GOT address,
1440 + * since the offset between text and data is not fixed, so we arrange
1441 + * for the assembly _dl_boot to pass this value as an argument to
1442 + * _dl_boot. */
1443 +#define DL_BOOT_COMPUTE_GOT(got) ((got) = dl_boot_got_pointer)
1444 +
1445 +#define DL_BOOT_COMPUTE_DYN(dpnt, got, load_addr) \
1446 + ((dpnt) = dl_boot_ldso_dyn_pointer)
1447 +
1448 +/* We only support loading FDPIC independently-relocatable shared
1449 + libraries. It probably wouldn't be too hard to support loading
1450 + shared libraries that require relocation by the same amount, but we
1451 + don't know that they exist or would be useful, and the dynamic
1452 + loader code could leak the whole-library map unless we keeping a
1453 + bit more state for DL_LOADADDR_UNMAP and DL_LIB_UNMAP, so let's
1454 + keep things simple for now. */
1455 +#define DL_CHECK_LIB_TYPE(epnt, piclib, _dl_progname, libname) \
1456 +do \
1457 +{ \
1458 + if (((epnt)->e_flags & EF_UBICOM32_FDPIC) && ! ((epnt)->e_flags & EF_UBICOM32_PIC)) \
1459 + (piclib) = 2; \
1460 + else \
1461 + { \
1462 + _dl_internal_error_number = LD_ERROR_NOTDYN; \
1463 + _dl_dprintf(2, "%s: '%s' is not an FDPIC shared library" \
1464 + "\n", (_dl_progname), (libname)); \
1465 + _dl_close(infile); \
1466 + return NULL; \
1467 + } \
1468 +\
1469 +} \
1470 +while (0)
1471 +
1472 +/* We want want to apply all relocations in the interpreter during
1473 + bootstrap. Because of this, we have to skip the interpreter
1474 + relocations in _dl_parse_relocation_information(), see
1475 + elfinterp.c. */
1476 +#define DL_SKIP_BOOTSTRAP_RELOC(SYMTAB, INDEX, STRTAB) 0
1477 +
1478 +#ifdef __NR_pread64
1479 +#define _DL_PREAD(FD, BUF, SIZE, OFFSET) \
1480 + (_dl_pread((FD), (BUF), (SIZE), (OFFSET)))
1481 +#endif
1482 +
1483 +/* We want to return to dlsym() a function descriptor if the symbol
1484 + turns out to be a function. */
1485 +#define DL_FIND_HASH_VALUE(TPNT, TYPE_CLASS, SYM) \
1486 + (((TYPE_CLASS) & ELF_RTYPE_CLASS_DLSYM) \
1487 + && ELF32_ST_TYPE((SYM)->st_info) == STT_FUNC \
1488 + ? _dl_funcdesc_for ((void *)DL_RELOC_ADDR ((TPNT)->loadaddr, (SYM)->st_value), \
1489 + (TPNT)->loadaddr.got_value) \
1490 + : DL_RELOC_ADDR ((TPNT)->loadaddr, (SYM)->st_value))
1491 +
1492 +#if 0 /* XXX TODO will look at enabling this if we decide to add support for OCM
1493 + * code/data */
1494 +
1495 +#define DL_IS_SPECIAL_SEGMENT(EPNT, PPNT) \
1496 + __dl_is_special_segment(EPNT, PPNT)
1497 +#define DL_MAP_SEGMENT(EPNT, PPNT, INFILE, FLAGS) \
1498 + __dl_map_segment (EPNT, PPNT, INFILE, FLAGS)
1499 +
1500 +#endif
1501 +
1502 +
1503 +#define DL_GET_READY_TO_RUN_EXTRA_PARMS \
1504 + , struct elf32_fdpic_loadmap *dl_boot_progmap, Elf32_Addr dl_boot_got_pointer
1505 +#define DL_GET_READY_TO_RUN_EXTRA_ARGS \
1506 + , dl_boot_progmap, dl_boot_got_pointer
1507 +
1508 +
1509 +#ifdef __USE_GNU
1510 +# include <link.h>
1511 +#else
1512 +# define __USE_GNU
1513 +# include <link.h>
1514 +# undef __USE_GNU
1515 +#endif
1516 +
1517 +#include <elf.h>
1518 +static __inline__ void
1519 +elf_machine_relative (DL_LOADADDR_TYPE load_off, const Elf32_Addr rel_addr,
1520 + Elf32_Word relative_count)
1521 +{
1522 +#if 0
1523 + Elf32_Rel * rpnt = (void *) rel_addr;
1524 + --rpnt;
1525 + do {
1526 + Elf32_Addr *const reloc_addr = (void *) (load_off + (++rpnt)->r_offset);
1527 +
1528 + *reloc_addr = DL_RELOC_ADDR (load_off, *reloc_addr);
1529 + } while (--relative_count);
1530 +#endif
1531 +}
1532 --- /dev/null
1533 +++ b/ldso/ldso/ubicom32/elfinterp.c
1534 @@ -0,0 +1,366 @@
1535 +/* Blackfin ELF shared library loader suppport
1536 + Copyright (C) 2003, 2004 Red Hat, Inc.
1537 + Contributed by Alexandre Oliva <aoliva@redhat.com>
1538 + Lots of code copied from ../i386/elfinterp.c, so:
1539 + Copyright (c) 1994-2000 Eric Youngdale, Peter MacDonald,
1540 + David Engel, Hongjiu Lu and Mitch D'Souza
1541 + Copyright (C) 2001-2002, Erik Andersen
1542 + All rights reserved.
1543 +
1544 +This file is part of uClibc.
1545 +
1546 +uClibc is free software; you can redistribute it and/or modify it
1547 +under the terms of the GNU Lesser General Public License as
1548 +published by the Free Software Foundation; either version 2.1 of the
1549 +License, or (at your option) any later version.
1550 +
1551 +uClibc is distributed in the hope that it will be useful, but WITHOUT
1552 +ANY WARRANTY; without even the implied warranty of
1553 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1554 +Library General Public License for more details.
1555 +
1556 +You should have received a copy of the GNU Lesser General Public
1557 +License along with uClibc; see the file COPYING.LIB. If not, write to
1558 +the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
1559 +USA. */
1560 +
1561 +#include <sys/cdefs.h> /* __attribute_used__ */
1562 +
1563 +/* Program to load an ELF binary on a linux system, and run it.
1564 + References to symbols in sharable libraries can be resolved by either
1565 + an ELF sharable library or a linux style of shared library. */
1566 +
1567 +/* Disclaimer: I have never seen any AT&T source code for SVr4, nor have
1568 + I ever taken any courses on internals. This program was developed using
1569 + information available through the book "UNIX SYSTEM V RELEASE 4,
1570 + Programmers guide: Ansi C and Programming Support Tools", which did
1571 + a more than adequate job of explaining everything required to get this
1572 + working. */
1573 +extern int _dl_ubicom32_resolve_pending(void) __attribute__((__visibility__("hidden")));
1574 +
1575 +struct funcdesc_value volatile *__attribute__((__visibility__("hidden")))
1576 +_dl_linux_resolver (struct elf_resolve *tpnt, int reloc_entry)
1577 +{
1578 + int reloc_type;
1579 + ELF_RELOC *this_reloc;
1580 + char *strtab;
1581 + ElfW(Sym) *symtab;
1582 + int symtab_index;
1583 + char *rel_addr;
1584 + struct elf_resolve *new_tpnt;
1585 + char *new_addr;
1586 + struct funcdesc_value funcval;
1587 + struct funcdesc_value volatile *got_entry;
1588 + char *symname;
1589 +
1590 + rel_addr = (char *)tpnt->dynamic_info[DT_JMPREL];
1591 +
1592 + this_reloc = (ELF_RELOC *)(intptr_t)(rel_addr + reloc_entry);
1593 + reloc_type = ELF_R_TYPE(this_reloc->r_info);
1594 + symtab_index = ELF_R_SYM(this_reloc->r_info);
1595 +
1596 + symtab = (Elf32_Sym *) tpnt->dynamic_info[DT_SYMTAB];
1597 + strtab = (char *) tpnt->dynamic_info[DT_STRTAB];
1598 + symname= strtab + symtab[symtab_index].st_name;
1599 +
1600 + if (reloc_type != R_UBICOM32_FUNCDESC_VALUE) {
1601 + _dl_dprintf(2, "%s: Incorrect relocation type in jump relocations\n",
1602 + _dl_progname);
1603 + _dl_exit(1);
1604 + }
1605 +
1606 + /* Address of GOT entry fix up */
1607 + got_entry = (struct funcdesc_value *) DL_RELOC_ADDR(tpnt->loadaddr, this_reloc->r_offset);
1608 +
1609 + /* Get the address to be used to fill in the GOT entry. */
1610 + new_addr = _dl_lookup_hash(symname, tpnt->symbol_scope, NULL, 0, &new_tpnt);
1611 + if (!new_addr) {
1612 + new_addr = _dl_lookup_hash(symname, NULL, NULL, 0, &new_tpnt);
1613 + if (!new_addr) {
1614 + _dl_dprintf(2, "%s: can't resolve symbol '%s'\n",
1615 + _dl_progname, symname);
1616 + _dl_exit(1);
1617 + }
1618 + }
1619 +
1620 + funcval.entry_point = new_addr;
1621 + funcval.got_value = new_tpnt->loadaddr.got_value;
1622 +
1623 +#if defined (__SUPPORT_LD_DEBUG__)
1624 + if (_dl_debug_bindings) {
1625 + _dl_dprintf(_dl_debug_file, "\nresolve function: %s", symname);
1626 + if (_dl_debug_detail)
1627 + _dl_dprintf(_dl_debug_file,
1628 + "\n\tpatched (%x,%x) ==> (%x,%x) @ %x\n",
1629 + got_entry->entry_point, got_entry->got_value,
1630 + funcval.entry_point, funcval.got_value,
1631 + got_entry);
1632 + }
1633 + if (1 || !_dl_debug_nofixups) {
1634 + got_entry->entry_point = ((unsigned long *)&_dl_ubicom32_resolve_pending)[0];
1635 + got_entry->got_value = funcval.got_value;
1636 + got_entry->entry_point = funcval.entry_point;
1637 + }
1638 +#else
1639 + /*
1640 + * initially set the entry point to resolve pending before starting
1641 + * the update. This has the effect of putting all other requests in a
1642 + * holding pattern until the resolution is completed.
1643 + */
1644 + got_entry->entry_point = ((unsigned long *)&_dl_ubicom32_resolve_pending)[0];
1645 + got_entry->got_value = funcval.got_value;
1646 + got_entry->entry_point = funcval.entry_point;
1647 +#endif
1648 +
1649 + return got_entry;
1650 +}
1651 +
1652 +static int
1653 +_dl_parse(struct elf_resolve *tpnt, struct dyn_elf *scope,
1654 + unsigned long rel_addr, unsigned long rel_size,
1655 + int (*reloc_fnc) (struct elf_resolve *tpnt, struct dyn_elf *scope,
1656 + ELF_RELOC *rpnt, ElfW(Sym) *symtab, char *strtab))
1657 +{
1658 + unsigned int i;
1659 + char *strtab;
1660 + ElfW(Sym) *symtab;
1661 + ELF_RELOC *rpnt;
1662 + int symtab_index;
1663 +
1664 + /* Now parse the relocation information */
1665 + rpnt = (ELF_RELOC *) rel_addr;
1666 + rel_size = rel_size / sizeof(ELF_RELOC);
1667 +
1668 + symtab = (ElfW(Sym) *) tpnt->dynamic_info[DT_SYMTAB];
1669 + strtab = (char *) tpnt->dynamic_info[DT_STRTAB];
1670 +
1671 + for (i = 0; i < rel_size; i++, rpnt++) {
1672 + int res;
1673 +
1674 + symtab_index = ELF_R_SYM(rpnt->r_info);
1675 + debug_sym(symtab,strtab,symtab_index);
1676 + debug_reloc(symtab,strtab,rpnt);
1677 +
1678 + res = reloc_fnc (tpnt, scope, rpnt, symtab, strtab);
1679 +
1680 + if (res==0) continue;
1681 +
1682 + _dl_dprintf(2, "\n%s: ",_dl_progname);
1683 +
1684 + if (symtab_index)
1685 + _dl_dprintf(2, "symbol '%s': ", strtab + symtab[symtab_index].st_name);
1686 +
1687 + if (res <0) {
1688 + int reloc_type = ELF_R_TYPE(rpnt->r_info);
1689 +#if defined (__SUPPORT_LD_DEBUG__)
1690 + _dl_dprintf(2, "can't handle reloc type %s\n ", _dl_reltypes(reloc_type));
1691 +#else
1692 + _dl_dprintf(2, "can't handle reloc type %x\n", reloc_type);
1693 +#endif
1694 + _dl_exit(-res);
1695 + } else if (res >0) {
1696 + _dl_dprintf(2, "can't resolve symbol\n");
1697 + return res;
1698 + }
1699 + }
1700 + return 0;
1701 +}
1702 +
1703 +static int
1704 +_dl_do_reloc (struct elf_resolve *tpnt,struct dyn_elf *scope,
1705 + ELF_RELOC *rpnt, ElfW(Sym) *symtab, char *strtab)
1706 +{
1707 + int reloc_type;
1708 + int symtab_index;
1709 + char *symname;
1710 + unsigned long reloc_value = 0, *reloc_addr;
1711 + struct { unsigned long v; } __attribute__((__packed__))
1712 + *reloc_addr_packed;
1713 + unsigned long symbol_addr;
1714 + struct elf_resolve *symbol_tpnt;
1715 + struct funcdesc_value funcval;
1716 +#if defined (__SUPPORT_LD_DEBUG__)
1717 + unsigned long old_val;
1718 +#endif
1719 +
1720 + reloc_addr = (unsigned long *) DL_RELOC_ADDR(tpnt->loadaddr, rpnt->r_offset);
1721 + __asm__ ("" : "=r" (reloc_addr_packed) : "0" (reloc_addr));
1722 + reloc_type = ELF_R_TYPE(rpnt->r_info);
1723 + symtab_index = ELF_R_SYM(rpnt->r_info);
1724 + symbol_addr = 0;
1725 + symname = strtab + symtab[symtab_index].st_name;
1726 +
1727 + if (ELF_ST_BIND (symtab[symtab_index].st_info) == STB_LOCAL) {
1728 + symbol_addr = (unsigned long) DL_RELOC_ADDR(tpnt->loadaddr, symtab[symtab_index].st_value);
1729 + symbol_tpnt = tpnt;
1730 + } else {
1731 +
1732 + symbol_addr = (unsigned long)
1733 + _dl_lookup_hash(symname, scope, NULL, 0, &symbol_tpnt);
1734 +
1735 + /*
1736 + * We want to allow undefined references to weak symbols - this might
1737 + * have been intentional. We should not be linking local symbols
1738 + * here, so all bases should be covered.
1739 + */
1740 +
1741 + if (!symbol_addr && ELF_ST_BIND(symtab[symtab_index].st_info) != STB_WEAK) {
1742 + _dl_dprintf (2, "%s: can't resolve symbol '%s'\n",
1743 + _dl_progname, strtab + symtab[symtab_index].st_name);
1744 + _dl_exit (1);
1745 + }
1746 + }
1747 +
1748 +#if defined (__SUPPORT_LD_DEBUG__)
1749 + if (_dl_debug_reloc && _dl_debug_detail)
1750 + {
1751 + if ((long)reloc_addr_packed & 3)
1752 + old_val = reloc_addr_packed->v;
1753 + else
1754 + old_val = *reloc_addr;
1755 + }
1756 + else
1757 + old_val = 0;
1758 +#endif
1759 + switch (reloc_type) {
1760 + case R_UBICOM32_NONE:
1761 + break;
1762 + case R_UBICOM32_32:
1763 + if ((long)reloc_addr_packed & 3)
1764 + reloc_value = reloc_addr_packed->v += symbol_addr;
1765 + else
1766 + reloc_value = *reloc_addr += symbol_addr;
1767 + break;
1768 + case R_UBICOM32_FUNCDESC_VALUE:
1769 + funcval.entry_point = (void*)symbol_addr;
1770 + /* The addend of FUNCDESC_VALUE
1771 + relocations referencing global
1772 + symbols must be ignored, because it
1773 + may hold the address of a lazy PLT
1774 + entry. */
1775 + if (ELF_ST_BIND(symtab[symtab_index].st_info) == STB_LOCAL)
1776 + funcval.entry_point += *reloc_addr;
1777 + reloc_value = (unsigned long)funcval.entry_point;
1778 + if (symbol_addr)
1779 + funcval.got_value
1780 + = symbol_tpnt->loadaddr.got_value;
1781 + else
1782 + funcval.got_value = 0;
1783 +
1784 +/// XXX this is my best guess as to what I should be doing, but I'm
1785 +/// putting a break-point here so I can inspect the first time this is
1786 +/// used.
1787 + __asm__ (
1788 + " move.4 4(%0), 4(%1) \n\t"
1789 + " move.4 0(%0), 0(%1) \n\t" /* Must to entry_point last */
1790 + :
1791 + : "a" (reloc_addr), "a" (&funcval)
1792 + : "memory" );
1793 + break;
1794 + case R_UBICOM32_FUNCDESC:
1795 + if ((long)reloc_addr_packed & 3)
1796 + reloc_value = reloc_addr_packed->v;
1797 + else
1798 + reloc_value = *reloc_addr;
1799 + if (symbol_addr)
1800 + reloc_value = (unsigned long)_dl_funcdesc_for
1801 + ((char *)symbol_addr + reloc_value,
1802 + symbol_tpnt->loadaddr.got_value);
1803 + else
1804 + reloc_value = 0;
1805 + if ((long)reloc_addr_packed & 3)
1806 + reloc_addr_packed->v = reloc_value;
1807 + else
1808 + *reloc_addr = reloc_value;
1809 + break;
1810 + default:
1811 + return -1;
1812 + }
1813 +#if defined (__SUPPORT_LD_DEBUG__)
1814 + if (_dl_debug_reloc && _dl_debug_detail) {
1815 + _dl_dprintf(_dl_debug_file, "\tpatched: %x ==> %x @ %x", old_val, reloc_value, reloc_addr);
1816 + switch (reloc_type) {
1817 + case R_UBICOM32_FUNCDESC_VALUE:
1818 + _dl_dprintf(_dl_debug_file, " got %x", ((struct funcdesc_value *)reloc_value)->got_value);
1819 + break;
1820 + case R_UBICOM32_FUNCDESC:
1821 + if (! reloc_value)
1822 + break;
1823 + _dl_dprintf(_dl_debug_file, " funcdesc (%x,%x)",
1824 + ((struct funcdesc_value *)reloc_value)->entry_point,
1825 + ((struct funcdesc_value *)reloc_value)->got_value);
1826 + break;
1827 + }
1828 + }
1829 +#endif
1830 +
1831 + return 0;
1832 +}
1833 +
1834 +static int
1835 +_dl_do_lazy_reloc (struct elf_resolve *tpnt,
1836 + struct dyn_elf *scope __attribute__((unused)),
1837 + ELF_RELOC *rpnt, ElfW(Sym) *symtab __attribute__((unused)),
1838 + char *strtab __attribute__((unused)))
1839 +{
1840 + int reloc_type;
1841 + struct funcdesc_value volatile *reloc_addr;
1842 + struct funcdesc_value funcval;
1843 +#if defined (__SUPPORT_LD_DEBUG__)
1844 + unsigned long old_val;
1845 +#endif
1846 +
1847 + reloc_addr = (struct funcdesc_value *) DL_RELOC_ADDR(tpnt->loadaddr, rpnt->r_offset);
1848 + reloc_type = ELF_R_TYPE(rpnt->r_info);
1849 +
1850 +#if defined (__SUPPORT_LD_DEBUG__)
1851 + old_val = (unsigned long)reloc_addr->entry_point;
1852 +#endif
1853 + switch (reloc_type) {
1854 + case R_UBICOM32_NONE:
1855 + break;
1856 + case R_UBICOM32_FUNCDESC_VALUE:
1857 + funcval = *reloc_addr;
1858 + funcval.entry_point = (void*)DL_RELOC_ADDR(tpnt->loadaddr, funcval.entry_point);
1859 + funcval.got_value = tpnt->loadaddr.got_value;
1860 + *reloc_addr = funcval;
1861 + break;
1862 + default:
1863 + return -1;
1864 + }
1865 +#if defined (__SUPPORT_LD_DEBUG__)
1866 + if (_dl_debug_reloc && _dl_debug_detail)
1867 + _dl_dprintf(_dl_debug_file, "\tpatched: %x ==> %x @ %x", old_val, reloc_addr->entry_point, reloc_addr);
1868 +#endif
1869 + return 0;
1870 +
1871 +}
1872 +
1873 +void
1874 +_dl_parse_lazy_relocation_information
1875 +(struct dyn_elf *rpnt, unsigned long rel_addr, unsigned long rel_size)
1876 +{
1877 + _dl_parse(rpnt->dyn, NULL, rel_addr, rel_size, _dl_do_lazy_reloc);
1878 +}
1879 +
1880 +int
1881 +_dl_parse_relocation_information
1882 +(struct dyn_elf *rpnt, unsigned long rel_addr, unsigned long rel_size)
1883 +{
1884 + return _dl_parse(rpnt->dyn, rpnt->dyn->symbol_scope, rel_addr, rel_size, _dl_do_reloc);
1885 +}
1886 +
1887 +#if 0
1888 +/* We don't have copy relocs. */
1889 +int
1890 +_dl_parse_copy_information
1891 +(struct dyn_elf *rpnt __attribute__((unused)),
1892 + unsigned long rel_addr __attribute__((unused)),
1893 + unsigned long rel_size __attribute__((unused)))
1894 +{
1895 + return 0;
1896 +}
1897 +#endif
1898 +#ifndef IS_IN_libdl
1899 +# include "../../libc/sysdeps/linux/ubicom32/crtreloc.c"
1900 +#endif
1901 --- /dev/null
1902 +++ b/ldso/ldso/ubicom32/resolve.S
1903 @@ -0,0 +1,161 @@
1904 + /* Copyright (C) 2003 Red Hat, Inc.
1905 + Contributed by Alexandre Oliva <aoliva@redhat.com>
1906 +
1907 + Copyright (C) 2009 Ubicom Inc.
1908 + Ported to Ubicom32 by Ubicom Inc.
1909 +
1910 +This file is part of uClibc.
1911 +
1912 +uClibc is free software; you can redistribute it and/or modify it
1913 +under the terms of the GNU Lesser General Public License as
1914 +published by the Free Software Foundation; either version 2.1 of the
1915 +License, or (at your option) any later version.
1916 +
1917 +uClibc is distributed in the hope that it will be useful, but WITHOUT
1918 +ANY WARRANTY; without even the implied warranty of
1919 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1920 +Library General Public License for more details.
1921 +
1922 +You should have received a copy of the GNU Lesser General Public
1923 +License along with uClibc; see the file COPYING.LIB. If not, write to
1924 +the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
1925 +USA. */
1926 +
1927 +
1928 +/*
1929 + * The function below is tail-called by resolver stubs when a lazily-bound *
1930 + * function is called. It must preserve all registers that could * be used to
1931 + * pass arguments to the actual function.
1932 + *
1933 + * On entry to the function d0-d13 contain parameters to the actual function of
1934 + * interest
1935 + *
1936 + * a5 contains the return address
1937 + * a0 is pointing to the GOT table for the original function
1938 + * (a0) _dl_linux_resolve
1939 + * 4(a0) GOT for _dl_linux_resolve
1940 + * 8(a0) is pointer to "structure elf_resolve" of the module where the call
1941 + * originated from
1942 + *
1943 + * a3 is pointing to the function descriptor in the GOT table, and 8(a3) the
1944 + * resolver lookup information.
1945 + *
1946 + * _dl_linux_resolve calls _dl_linux_resolver passing it pointer to
1947 + * struct elf_resolve and the relocation entry.
1948 + *
1949 + * _dl_linux_resolver() figures out where the jump symbol is _really_ supposed
1950 + * to have jumped to and returns that to us. Once we have that, we prepare to
1951 + * tail-call the actual function, clean up after ourselves, restoring the
1952 + * original arguments, then jump to the fixed up address.
1953 + */
1954 +
1955 +#if 0
1956 + /*
1957 + * Here is what the linker will use for the PLT.
1958 + */
1959 +sample_PLT_functionX: /* (at entry a0 contains GOT for this library) */
1960 + movei d15, # -%lo(got_funcdescX) ; load offset for GOT
1961 + lea.4 a3, (a0, d15) ; a4 is now the function descriptor
1962 + move.4 a4, 0(a3) ; get entry_point
1963 + move.4 a0, 4(a3) ; set new GOT
1964 +
1965 + /*
1966 + * jump to resovled function OR PLT_trampoline Nat had some code here
1967 + * that uses the stack instead of a3 to reduces hazards.
1968 + */
1969 + calli a4, 0(a4)
1970 +
1971 +
1972 +sample_PLT_trampoline:
1973 + /*
1974 + * find the old got by undoing what was done above. An alternative
1975 + * could have been to ‘save’ the old got in say d14 but that would add 1
1976 + * instruction to every PLT and there is only 1 PLT trampoline per library.
1977 + */
1978 + ret (a0) ; jump to _dl_linux_resolve
1979 +#endif
1980 +
1981 + .text
1982 + .p2align 4
1983 +
1984 + .hidden _dl_linux_resolve
1985 + .global _dl_linux_resolve
1986 + .type _dl_linux_resolve,@function
1987 +_dl_linux_resolve:
1988 + /* Preserve arguments and return address */
1989 + move.4 -4(sp)++, d0
1990 + move.4 -4(sp)++, d1
1991 + move.4 -4(sp)++, d2
1992 + move.4 -4(sp)++, d3
1993 + move.4 -4(sp)++, d4
1994 + move.4 -4(sp)++, d5
1995 + move.4 -4(sp)++, d6
1996 + move.4 -4(sp)++, d7
1997 + move.4 -4(sp)++, d8
1998 + move.4 -4(sp)++, d9
1999 + move.4 -4(sp)++, d10
2000 + move.4 -4(sp)++, d11
2001 + move.4 -4(sp)++, d12
2002 + move.4 -4(sp)++, d13
2003 + move.4 -4(sp)++, a5
2004 +
2005 + /* Prepare to call _dl_linux_resolver. */
2006 + move.4 d0, 8(a0) ; reference to elf_resolve
2007 + /* Not aligned for space reasons. */
2008 + move.4 d1, mac_hi ; reference to GOT table entry which
2009 + ; contains the relocation information.
2010 +
2011 + move.4 a0, 4(a0) ; switch to GOT for _dl_linux_resolve
2012 + call a5, _dl_linux_resolver;
2013 +
2014 + /* Move aside return value that contains the FUNCDESC_VALUE. */
2015 + ;P3 = R0;
2016 + move.4 a3, d0;
2017 +
2018 + /* Restore arguments. */
2019 + move.4 a5, (sp)4++
2020 + move.4 d13, (sp)4++
2021 + move.4 d12, (sp)4++
2022 + move.4 d11, (sp)4++
2023 + move.4 d10, (sp)4++
2024 + move.4 d9, (sp)4++
2025 + move.4 d8, (sp)4++
2026 + move.4 d7, (sp)4++
2027 + move.4 d6, (sp)4++
2028 + move.4 d5, (sp)4++
2029 + move.4 d4, (sp)4++
2030 + move.4 d3, (sp)4++
2031 + move.4 d2, (sp)4++
2032 + move.4 d1, (sp)4++
2033 + move.4 d0, (sp)4++
2034 +
2035 + /* Now jump to the actual function. */
2036 + /* a3 contains func_desc resolution */
2037 + move.4 a4, 0(a3) ; address of function X
2038 + move.4 a0, 4(a3) ; switch to GOT for function X
2039 + calli a4, 0(a4) ; call through a4, a5 remains
2040 +
2041 + .size _dl_linux_resolve, . - _dl_linux_resolve
2042 +
2043 + .hidden _dl_ubicom32_resolve_pending
2044 + .global _dl_ubicom32_resolve_pending
2045 + .type _dl_ubicom32_resolve_pending,@function
2046 +
2047 +_dl_ubicom32_resolve_pending:
2048 + /*
2049 + * A special function that is used to ensure thread saftly when the fd
2050 + * for a particular resolution is being updated.
2051 + *
2052 + * At entry, a3 must point to the FD. While the FD is being updated the
2053 + * entry_point will continue to point to _dl_ubicom32_resolve_pending so
2054 + * we will effectively spin until the resolver update is complete.
2055 + */
2056 +
2057 + move.4 a4, 0(a3) ; get entry_point
2058 + move.4 a0, 4(a3) ; set new GOT
2059 +
2060 + /*
2061 + * jump to resovled function or back to _dl_ubicom32_resolve_pending.
2062 + */
2063 + calli a4, 0(a4)
2064 + .size _dl_ubicom32_resolve_pending, . - _dl_ubicom32_resolve_pending
2065 --- a/libc/misc/Makefile.in
2066 +++ b/libc/misc/Makefile.in
2067 @@ -12,7 +12,9 @@ include $(top_srcdir)libc/misc/assert/Ma
2068 include $(top_srcdir)libc/misc/ctype/Makefile.in
2069 include $(top_srcdir)libc/misc/dirent/Makefile.in
2070 include $(top_srcdir)libc/misc/error/Makefile.in
2071 +ifneq ($(ARCH_HAS_NO_LDSO),y)
2072 include $(top_srcdir)libc/misc/elf/Makefile.in
2073 +endif
2074 include $(top_srcdir)libc/misc/file/Makefile.in
2075 include $(top_srcdir)libc/misc/fnmatch/Makefile.in
2076 include $(top_srcdir)libc/misc/ftw/Makefile.in
2077 --- a/libc/misc/elf/dl-iterate-phdr.c
2078 +++ b/libc/misc/elf/dl-iterate-phdr.c
2079 @@ -14,7 +14,7 @@
2080
2081 #include <link.h>
2082 #include <ldso.h>
2083 -
2084 +#include <memory.h>
2085 /* we want this in libc but nowhere else */
2086 #ifdef __USE_GNU
2087
2088 --- a/libc/stdlib/malloc/malloc.c
2089 +++ b/libc/stdlib/malloc/malloc.c
2090 @@ -23,7 +23,7 @@
2091
2092 /* The malloc heap. We provide a bit of initial static space so that
2093 programs can do a little mallocing without mmaping in more space. */
2094 -HEAP_DECLARE_STATIC_FREE_AREA (initial_fa, 256);
2095 +HEAP_DECLARE_STATIC_FREE_AREA (initial_fa, 32768);
2096 struct heap_free_area *__malloc_heap = HEAP_INIT_WITH_FA (initial_fa);
2097 #ifdef HEAP_USE_LOCKING
2098 malloc_mutex_t __malloc_heap_lock = PTHREAD_MUTEX_INITIALIZER;
2099 --- /dev/null
2100 +++ b/libc/string/ubicom32/Makefile
2101 @@ -0,0 +1,13 @@
2102 +# Makefile for uClibc
2103 +#
2104 +# Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
2105 +#
2106 +# Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
2107 +#
2108 +
2109 +top_srcdir:=../../../
2110 +top_builddir:=../../../
2111 +all: objs
2112 +include $(top_builddir)Rules.mak
2113 +include ../Makefile.in
2114 +include $(top_srcdir)Makerules
2115 --- /dev/null
2116 +++ b/libc/string/ubicom32/memcpy.c
2117 @@ -0,0 +1,152 @@
2118 +/* Copy memory to memory until the specified number of bytes
2119 + has been copied. Overlap is NOT handled correctly.
2120 + Copyright (C) 1991, 1997, 2003 Free Software Foundation, Inc.
2121 + This file is part of the GNU C Library.
2122 + Contributed by Torbjorn Granlund (tege@sics.se).
2123 +
2124 + The GNU C Library is free software; you can redistribute it and/or
2125 + modify it under the terms of the GNU Lesser General Public
2126 + License as published by the Free Software Foundation; either
2127 + version 2.1 of the License, or (at your option) any later version.
2128 +
2129 + The GNU C Library is distributed in the hope that it will be useful,
2130 + but WITHOUT ANY WARRANTY; without even the implied warranty of
2131 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2132 + Lesser General Public License for more details.
2133 +
2134 + You should have received a copy of the GNU Lesser General Public
2135 + License along with the GNU C Library; if not, write to the Free
2136 + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
2137 + 02111-1307 USA. */
2138 +
2139 +#include <string.h>
2140 +
2141 +typedef unsigned long addr_t;
2142 +
2143 +libc_hidden_proto(memcpy)
2144 +
2145 +void *memcpy (void *dest, const void *src, size_t n)
2146 +{
2147 + void *dest_ret = dest;
2148 + void *aligned_start;
2149 +
2150 + if (likely((((addr_t)dest ^ (addr_t)src) & 3) == 0) && likely(n > 6)) {
2151 + size_t m;
2152 + n -= (4 - (addr_t)dest) & 0x03;
2153 + m = n >> 2;
2154 + __asm__ volatile (
2155 + " call %4, 99f \n\t" // load %4 with address of 99
2156 + "99: movei d15, #%%lo(1f-99b) \n\t" // load d15 with offset to 1 from 99
2157 + " add.4 %4, %4, d15 \n\t" // add difference
2158 +
2159 + " sub.4 d15, #0, %2 \n\t" // set up for jump table
2160 + " and.4 d15, #(32-1), d15 \n\t" // d15 = (-m) & (32 - 1)
2161 + " lea.4 %4, (%4,d15) \n\t"
2162 +
2163 + " bfextu d15, %0, #2 \n\t" // d15 = (dest & 3)
2164 + " jmpne.w.f 100f \n\t"
2165 + " calli %4, 0(%4) \n\t" // 4-byte alignment
2166 +
2167 + "100: cmpi d15, #2 \n\t"
2168 + " jmpne.s.f 101f \n\t"
2169 + " move.2 (%0)2++, (%1)2++ \n\t"
2170 + " calli %4, 0(%4) \n\t" // 2-byte alignment
2171 +
2172 + "101: move.1 (%0)1++, (%1)1++ \n\t"
2173 + " jmpgt.s.f 102f \n\t" // 3-byte alignment
2174 + " move.2 (%0)2++, (%1)2++ \n\t" // 1-byte alignment
2175 + "102: calli %4, 0(%4) \n\t"
2176 +
2177 + "200: cmpi %3, #2 \n\t"
2178 + " jmplt.s.f 201f \n\t"
2179 + " move.2 (%0)2++, (%1)2++ \n\t"
2180 + " jmpeq.s.t 2f \n\t"
2181 + "201: move.1 (%0)1++, (%1)1++ \n\t"
2182 + " jmpt.w.t 2f \n\t"
2183 +
2184 + "1: .rept 25 \n\t"
2185 + " movea (%0)4++, (%1)4++ \n\t"
2186 + " .endr \n\t"
2187 + " .rept 7 \n\t"
2188 + " move.4 (%0)4++, (%1)4++ \n\t"
2189 + " .endr \n\t"
2190 + " add.4 %2, #-32, %2 \n\t"
2191 + " jmpgt.w.f 1b \n\t"
2192 +
2193 + " and.4 %3, #3, %3 \n\t" // check n
2194 + " jmpne.w.f 200b \n\t"
2195 + "2: \n\t"
2196 + : "+a"(dest), "+a"(src), "+d"(m), "+d"(n), "=a"(aligned_start)
2197 + :
2198 + : "d15", "memory", "cc"
2199 + );
2200 +
2201 + return dest_ret;
2202 + }
2203 +
2204 + if (likely((((addr_t)dest ^ (addr_t)src) & 1) == 0) && likely(n > 2)) {
2205 + size_t m;
2206 + n -= (addr_t)dest & 0x01;
2207 + m = n >> 1;
2208 + __asm__ volatile (
2209 + " call %4, 99f \n\t" // load %4 with address of 99
2210 + "99: movei d15, #%%lo(1f-99b) \n\t" // load d15 with offset to 1 from 99
2211 + " add.4 %4, %4, d15 \n\t" // add difference
2212 +
2213 + " sub.4 d15, #0, %2 \n\t" // set up for jump table
2214 + " and.4 d15, #(32-1), d15 \n\t" // d15 = (-m) & (32 - 1)
2215 + " lea.4 %4, (%4,d15) \n\t"
2216 +
2217 + " btst %0, #0 \n\t" // check bit 0
2218 + " jmpne.w.f 100f \n\t"
2219 + " calli %4, 0(%4) \n\t" // 4-byte alignment
2220 +
2221 + "100: move.1 (%0)1++, (%1)1++ \n\t"
2222 + " calli %4, 0(%4) \n\t"
2223 +
2224 + "200: move.1 (%0)1++, (%1)1++ \n\t"
2225 + " jmpt.w.t 2f \n\t"
2226 +
2227 + "1: .rept 32 \n\t"
2228 + " move.2 (%0)2++, (%1)2++ \n\t"
2229 + " .endr \n\t"
2230 + " add.4 %2, #-32, %2 \n\t"
2231 + " jmpgt.w.f 1b \n\t"
2232 +
2233 + " and.4 %3, #1, %3 \n\t" // check n
2234 + " jmpne.w.f 200b \n\t"
2235 + "2: \n\t"
2236 +
2237 + : "+a"(dest), "+a"(src), "+d"(m), "+d"(n), "=a"(aligned_start)
2238 + :
2239 + : "d15", "memory", "cc"
2240 + );
2241 + return dest_ret;
2242 + }
2243 +
2244 + __asm__ volatile (
2245 + " call %3, 99f \n\t" // load %3 with address of 99
2246 + "99: movei d15, #%%lo(1f-99b) \n\t" // load d15 with offset to 1 from 99
2247 + " add.4 %3, %3, d15 \n\t" // add difference
2248 +
2249 + " sub.4 d15, #0, %2 \n\t"
2250 + " jmpeq.w.f 2f \n\t"
2251 + " and.4 d15, #(16-1), d15 \n\t" // d15 = (-n) & (16 - 1)
2252 + " lea.4 %3, (%3,d15) \n\t"
2253 + " calli %3, 0(%3) \n\t"
2254 +
2255 + "1: .rept 16 \n\t"
2256 + " move.1 (%0)1++, (%1)1++ \n\t"
2257 + " .endr \n\t"
2258 + " add.4 %2, #-16, %2 \n\t"
2259 + " jmpgt.w.f 1b \n\t"
2260 + "2: \n\t"
2261 +
2262 + : "+a"(dest), "+a"(src), "+d"(n), "=a"(aligned_start)
2263 + :
2264 + : "d15", "memory", "cc"
2265 + );
2266 +
2267 + return dest_ret;
2268 +}
2269 +libc_hidden_def(memcpy)
2270 --- /dev/null
2271 +++ b/libc/string/ubicom32/memset.c
2272 @@ -0,0 +1,107 @@
2273 +/* Copyright (C) 1991, 1997, 2003 Free Software Foundation, Inc.
2274 + This file is part of the GNU C Library.
2275 +
2276 + The GNU C Library is free software; you can redistribute it and/or
2277 + modify it under the terms of the GNU Lesser General Public
2278 + License as published by the Free Software Foundation; either
2279 + version 2.1 of the License, or (at your option) any later version.
2280 +
2281 + The GNU C Library is distributed in the hope that it will be useful,
2282 + but WITHOUT ANY WARRANTY; without even the implied warranty of
2283 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2284 + Lesser General Public License for more details.
2285 +
2286 + You should have received a copy of the GNU Lesser General Public
2287 + License along with the GNU C Library; if not, write to the Free
2288 + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
2289 + 02111-1307 USA. */
2290 +
2291 +#include <string.h>
2292 +
2293 +typedef unsigned long addr_t;
2294 +
2295 +libc_hidden_proto(memset)
2296 +void *memset (void *s, int c, size_t n)
2297 +{
2298 + void *s_ret = s;
2299 + void *aligned_start;
2300 + if (likely(n > 6)) {
2301 + size_t m;
2302 + n -= (4 - (addr_t)s) & 0x03;
2303 + m = n >> 2;
2304 + __asm__ volatile (
2305 + " call %4, 99f \n\t" // load %4 with address of 99
2306 + "99: movei d15, #%%lo(1f-99b) \n\t" // load d15 with offset to 1 from 99
2307 + " add.4 %4, %4, d15 \n\t" // add difference
2308 +
2309 + " sub.4 d15, #0, %2 \n\t" // set up for jump table
2310 + " and.4 d15, #(32-1), d15 \n\t" // d15 = (-m) & (32 - 1)
2311 + " shmrg.1 %1, %1, %1 \n\t"
2312 + " shmrg.2 %1, %1, %1 \n\t" // %1 = (c<<24)|(c<<16)|(c<<8)|c
2313 + " lea.4 %4, (%4,d15) \n\t"
2314 +
2315 + " bfextu d15, %0, #2 \n\t" // d15 = (s & 3)
2316 + " jmpne.w.f 100f \n\t"
2317 + " calli %4, 0(%4) \n\t" // 4-byte alignment
2318 +
2319 + "100: cmpi d15, #2 \n\t"
2320 + " jmpne.s.f 101f \n\t"
2321 + " move.2 (%0)2++, %1 \n\t"
2322 + " calli %4, 0(%4) \n\t" // 2-byte alignment
2323 +
2324 + "101: move.1 (%0)1++, %1 \n\t"
2325 + " jmpgt.s.f 102f \n\t" // 3-byte alignment
2326 + " move.2 (%0)2++, %1 \n\t" // 1-byte alignment
2327 + "102: calli %4, 0(%4) \n\t"
2328 +
2329 + "200: cmpi %3, #2 \n\t"
2330 + " jmplt.s.f 201f \n\t"
2331 + " move.2 (%0)2++, %1 \n\t"
2332 + " jmpeq.s.t 2f \n\t"
2333 + "201: move.1 (%0)1++, %1 \n\t"
2334 + " jmpt.w.t 2f \n\t"
2335 +
2336 + "1: .rept 25 \n\t"
2337 + " movea (%0)4++, %1 \n\t"
2338 + " .endr \n\t"
2339 + " .rept 7 \n\t"
2340 + " move.4 (%0)4++, %1 \n\t"
2341 + " .endr \n\t"
2342 + " add.4 %2, #-32, %2 \n\t"
2343 + " jmpgt.w.f 1b \n\t"
2344 +
2345 + " and.4 %3, #3, %3 \n\t" // test bit 1 of n
2346 + " jmpne.w.f 200b \n\t"
2347 + "2: \n\t"
2348 + : "+a"(s), "+d"(c), "+d"(m), "+d"(n), "=a"(aligned_start)
2349 + :
2350 + : "d15", "memory", "cc"
2351 + );
2352 +
2353 + return s_ret;
2354 + }
2355 +
2356 + __asm__ volatile (
2357 + " call %3, 99f \n\t" // load %3 with address of 99
2358 + "99: movei d15, #%%lo(1f-99b) \n\t" // load d15 with offset to 1 from 99
2359 + " add.4 %3, %3, d15 \n\t" // add difference
2360 +
2361 + " sub.4 d15, #0, %2 \n\t"
2362 + " jmpeq.w.f 2f \n\t"
2363 + " and.4 d15, #(8-1), d15 \n\t" // d15 = (-%2) & (16 - 1)
2364 + " lea.4 %3, (%3,d15) \n\t"
2365 + " calli %3, 0(%3) \n\t"
2366 +
2367 + "1: .rept 8 \n\t"
2368 + " move.1 (%0)1++, %1 \n\t"
2369 + " .endr \n\t"
2370 + "2: \n\t"
2371 +
2372 + : "+a"(s), "+d"(c), "+d"(n), "=a"(aligned_start)
2373 + :
2374 + : "d15", "memory", "cc"
2375 + );
2376 +
2377 + return s_ret;
2378 +}
2379 +libc_hidden_def(memset)
2380 --- /dev/null
2381 +++ b/libc/sysdeps/linux/ubicom32/Makefile
2382 @@ -0,0 +1,13 @@
2383 +# Makefile for uClibc
2384 +#
2385 +# Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
2386 +#
2387 +# Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
2388 +#
2389 +
2390 +top_srcdir=../../../../
2391 +top_builddir=../../../../
2392 +all: objs
2393 +include $(top_builddir)Rules.mak
2394 +include Makefile.arch
2395 +include $(top_srcdir)Makerules
2396 --- /dev/null
2397 +++ b/libc/sysdeps/linux/ubicom32/Makefile.arch
2398 @@ -0,0 +1,28 @@
2399 +# Makefile for uClibc
2400 +#
2401 +# Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
2402 +#
2403 +# Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
2404 +#
2405 +
2406 +#CSRC := \
2407 +# brk.c \
2408 +# crtbegin.c \
2409 +# crtend.c
2410 +#
2411 +#SSRC := \
2412 +# __longjmp.S \
2413 +# bsd-_setjmp.S \
2414 +# bsd-setjmp.S \
2415 +# setjmp.S \
2416 +# clone.S \
2417 +# vfork.S
2418 +
2419 +CSRC := \
2420 + syscall.c __syscall_error.c
2421 +
2422 +SSRC := \
2423 + clone.S setjmp.S vfork.S
2424 +
2425 +ARCH_CFLAGS := $(CPU_CFLAGS-y)
2426 +include $(top_srcdir)libc/sysdeps/linux/Makefile.commonarch
2427 --- /dev/null
2428 +++ b/libc/sysdeps/linux/ubicom32/__syscall_error.c
2429 @@ -0,0 +1,11 @@
2430 +#include <errno.h>
2431 +#include <features.h>
2432 +
2433 +/* This routine is jumped to by some of the syscall handlers, to stash
2434 + * an error number into errno. */
2435 +int __syscall_error(int err_no) attribute_hidden;
2436 +int __syscall_error(int err_no)
2437 +{
2438 + __set_errno(err_no);
2439 + return -1;
2440 +}
2441 --- /dev/null
2442 +++ b/libc/sysdeps/linux/ubicom32/bits/elf-fdpic.h
2443 @@ -0,0 +1,115 @@
2444 +/* Copyright 2003, 2004 Free Software Foundation, Inc.
2445 +This file is part of the GNU C Library.
2446 +
2447 +The GNU C Library is free software; you can redistribute it and/or
2448 +modify it under the terms of the GNU Lesser General Public License as
2449 +published by the Free Software Foundation; either version 2.1 of the
2450 +License, or (at your option) any later version.
2451 +
2452 +In addition to the permissions in the GNU Lesser General Public
2453 +License, the Free Software Foundation gives you unlimited
2454 +permission to link the compiled version of this file with other
2455 +programs, and to distribute those programs without any restriction
2456 +coming from the use of this file. (The GNU Lesser General Public
2457 +License restrictions do apply in other respects; for example, they
2458 +cover modification of the file, and distribution when not linked
2459 +into another program.)
2460 +
2461 +The GNU C Library is distributed in the hope that it will be useful,
2462 +but WITHOUT ANY WARRANTY; without even the implied warranty of
2463 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2464 +Library General Public License for more details.
2465 +
2466 +You should have received a copy of the GNU Lesser General Public
2467 +License along with the GNU C Library; see the file COPYING.LIB. If
2468 +not, write to the Free Software Foundation, Inc., 675 Mass Ave,
2469 +Cambridge, MA 02139, USA. */
2470 +
2471 +#ifndef _BITS_ELF_FDPIC_H
2472 +#define _BITS_ELF_FDPIC_H
2473 +
2474 +/* These data structures are described in the FDPIC ABI extension.
2475 + The kernel passes a process a memory map, such that for every LOAD
2476 + segment there is an elf32_fdpic_loadseg entry. A pointer to an
2477 + elf32_fdpic_loadmap is passed in d8 at start-up, and a pointer to
2478 + an additional such map is passed in d9 for the interpreter, when
2479 + there is one. */
2480 +
2481 +#include <elf.h>
2482 +
2483 +/* This data structure represents a PT_LOAD segment. */
2484 +struct elf32_fdpic_loadseg
2485 +{
2486 + /* Core address to which the segment is mapped. */
2487 + Elf32_Addr addr;
2488 + /* VMA recorded in the program header. */
2489 + Elf32_Addr p_vaddr;
2490 + /* Size of this segment in memory. */
2491 + Elf32_Word p_memsz;
2492 +};
2493 +
2494 +struct elf32_fdpic_loadmap {
2495 + /* Protocol version number, must be zero. */
2496 + Elf32_Half version;
2497 + /* Number of segments in this map. */
2498 + Elf32_Half nsegs;
2499 + /* The actual memory map. */
2500 + struct elf32_fdpic_loadseg segs[/*nsegs*/];
2501 +};
2502 +
2503 +struct elf32_fdpic_loadaddr {
2504 + struct elf32_fdpic_loadmap *map;
2505 + void *got_value;
2506 +};
2507 +
2508 +/* Map a pointer's VMA to its corresponding address according to the
2509 + load map. */
2510 +static __always_inline void *
2511 +__reloc_pointer (void *p,
2512 + const struct elf32_fdpic_loadmap *map)
2513 +{
2514 + int c;
2515 +
2516 +#if 0
2517 + if (map->version != 0)
2518 + /* Crash. */
2519 + ((void(*)())0)();
2520 +#endif
2521 +
2522 + /* No special provision is made for NULL. We don't want NULL
2523 + addresses to go through relocation, so they shouldn't be in
2524 + .rofixup sections, and, if they're present in dynamic
2525 + relocations, they shall be mapped to the NULL address without
2526 + undergoing relocations. */
2527 +
2528 + for (c = 0;
2529 + /* Take advantage of the fact that the loadmap is ordered by
2530 + virtual addresses. In general there will only be 2 entries,
2531 + so it's not profitable to do a binary search. */
2532 + c < map->nsegs && p >= (void*)map->segs[c].p_vaddr;
2533 + c++)
2534 + {
2535 + /* This should be computed as part of the pointer comparison
2536 + above, but we want to use the carry in the comparison, so we
2537 + can't convert it to an integer type beforehand. */
2538 + unsigned long offset = p - (void*)map->segs[c].p_vaddr;
2539 + /* We only check for one-past-the-end for the last segment,
2540 + assumed to be the data segment, because other cases are
2541 + ambiguous in the absence of padding between segments, and
2542 + rofixup already serves as padding between text and data.
2543 + Unfortunately, unless we special-case the last segment, we
2544 + fail to relocate the _end symbol. */
2545 + if (offset < map->segs[c].p_memsz
2546 + || (offset == map->segs[c].p_memsz && c + 1 == map->nsegs))
2547 + return (char*)map->segs[c].addr + offset;
2548 + }
2549 +
2550 + /* We might want to crash instead. */
2551 + return (void*)-1;
2552 +}
2553 +
2554 +# define __RELOC_POINTER(ptr, loadaddr) \
2555 + (__reloc_pointer ((void*)(ptr), \
2556 + (loadaddr).map))
2557 +
2558 +#endif /* _BITS_ELF_FDPIC_H */
2559 --- /dev/null
2560 +++ b/libc/sysdeps/linux/ubicom32/bits/endian.h
2561 @@ -0,0 +1,7 @@
2562 +/* Ubicom32 is big-endian. */
2563 +
2564 +#ifndef _ENDIAN_H
2565 +# error "Never use <bits/endian.h> directly; include <endian.h> instead."
2566 +#endif
2567 +
2568 +#define __BYTE_ORDER __BIG_ENDIAN
2569 --- /dev/null
2570 +++ b/libc/sysdeps/linux/ubicom32/bits/fcntl.h
2571 @@ -0,0 +1,226 @@
2572 +/* O_*, F_*, FD_* bit values for Linux.
2573 + Copyright (C) 2000 Free Software Foundation, Inc.
2574 + This file is part of the GNU C Library.
2575 +
2576 + The GNU C Library is free software; you can redistribute it and/or
2577 + modify it under the terms of the GNU Lesser General Public
2578 + License as published by the Free Software Foundation; either
2579 + version 2.1 of the License, or (at your option) any later version.
2580 +
2581 + The GNU C Library is distributed in the hope that it will be useful,
2582 + but WITHOUT ANY WARRANTY; without even the implied warranty of
2583 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2584 + Lesser General Public License for more details.
2585 +
2586 + You should have received a copy of the GNU Lesser General Public
2587 + License along with the GNU C Library; if not, write to the Free
2588 + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
2589 + 02111-1307 USA. */
2590 +
2591 +#ifndef _FCNTL_H
2592 +# error "Never use <bits/fcntl.h> directly; include <fcntl.h> instead."
2593 +#endif
2594 +
2595 +
2596 +#include <sys/types.h>
2597 +#ifdef __USE_GNU
2598 +# include <bits/uio.h>
2599 +#endif
2600 +
2601 +/* open/fcntl - O_SYNC is only implemented on blocks devices and on files
2602 + located on an ext2 file system */
2603 +#define O_ACCMODE 0003
2604 +#define O_RDONLY 00
2605 +#define O_WRONLY 01
2606 +#define O_RDWR 02
2607 +#define O_CREAT 0100 /* not fcntl */
2608 +#define O_EXCL 0200 /* not fcntl */
2609 +#define O_NOCTTY 0400 /* not fcntl */
2610 +#define O_TRUNC 01000 /* not fcntl */
2611 +#define O_APPEND 02000
2612 +#define O_NONBLOCK 04000
2613 +#define O_NDELAY O_NONBLOCK
2614 +#define O_SYNC 010000
2615 +#define O_FSYNC O_SYNC
2616 +#define O_ASYNC 020000
2617 +
2618 +#ifdef __USE_GNU
2619 +# define O_DIRECTORY 040000 /* Must be a directory. */
2620 +# define O_NOFOLLOW 0100000 /* Do not follow links. */
2621 +# define O_DIRECT 0200000 /* Direct disk access. */
2622 +# define O_NOATIME 01000000 /* Do not set atime. */
2623 +# define O_CLOEXEC 02000000 /* set close_on_exec */
2624 +# define O_STREAMING 04000000 /* streaming access */
2625 +#endif
2626 +
2627 +/* For now Linux has synchronisity options for data and read operations.
2628 + We define the symbols here but let them do the same as O_SYNC since
2629 + this is a superset. */
2630 +#if defined __USE_POSIX199309 || defined __USE_UNIX98
2631 +# define O_DSYNC O_SYNC /* Synchronize data. */
2632 +# define O_RSYNC O_SYNC /* Synchronize read operations. */
2633 +#endif
2634 +
2635 +#ifdef __USE_LARGEFILE64
2636 +# define O_LARGEFILE 0400000
2637 +#endif
2638 +
2639 +/* Values for the second argument to `fcntl'. */
2640 +#define F_DUPFD 0 /* Duplicate file descriptor. */
2641 +#define F_GETFD 1 /* Get file descriptor flags. */
2642 +#define F_SETFD 2 /* Set file descriptor flags. */
2643 +#define F_GETFL 3 /* Get file status flags. */
2644 +#define F_SETFL 4 /* Set file status flags. */
2645 +#ifndef __USE_FILE_OFFSET64
2646 +# define F_GETLK 5 /* Get record locking info. */
2647 +# define F_SETLK 6 /* Set record locking info (non-blocking). */
2648 +# define F_SETLKW 7 /* Set record locking info (blocking). */
2649 +#else
2650 +# define F_GETLK F_GETLK64 /* Get record locking info. */
2651 +# define F_SETLK F_SETLK64 /* Set record locking info (non-blocking).*/
2652 +# define F_SETLKW F_SETLKW64 /* Set record locking info (blocking). */
2653 +#endif
2654 +#define F_GETLK64 12 /* Get record locking info. */
2655 +#define F_SETLK64 13 /* Set record locking info (non-blocking). */
2656 +#define F_SETLKW64 14 /* Set record locking info (blocking). */
2657 +
2658 +#if defined __USE_BSD || defined __USE_XOPEN2K
2659 +# define F_SETOWN 8 /* Get owner of socket (receiver of SIGIO). */
2660 +# define F_GETOWN 9 /* Set owner of socket (receiver of SIGIO). */
2661 +#endif
2662 +
2663 +#ifdef __USE_GNU
2664 +# define F_SETSIG 10 /* Set number of signal to be sent. */
2665 +# define F_GETSIG 11 /* Get number of signal to be sent. */
2666 +#endif
2667 +
2668 +#ifdef __USE_GNU
2669 +# define F_SETLEASE 1024 /* Set a lease. */
2670 +# define F_GETLEASE 1025 /* Enquire what lease is active. */
2671 +# define F_NOTIFY 1026 /* Request notfications on a directory. */
2672 +#endif
2673 +
2674 +/* For F_[GET|SET]FL. */
2675 +#define FD_CLOEXEC 1 /* actually anything with low bit set goes */
2676 +
2677 +/* For posix fcntl() and `l_type' field of a `struct flock' for lockf(). */
2678 +#define F_RDLCK 0 /* Read lock. */
2679 +#define F_WRLCK 1 /* Write lock. */
2680 +#define F_UNLCK 2 /* Remove lock. */
2681 +
2682 +/* For old implementation of bsd flock(). */
2683 +#define F_EXLCK 4 /* or 3 */
2684 +#define F_SHLCK 8 /* or 4 */
2685 +
2686 +#ifdef __USE_BSD
2687 +/* Operations for bsd flock(), also used by the kernel implementation. */
2688 +# define LOCK_SH 1 /* shared lock */
2689 +# define LOCK_EX 2 /* exclusive lock */
2690 +# define LOCK_NB 4 /* or'd with one of the above to prevent
2691 + blocking */
2692 +# define LOCK_UN 8 /* remove lock */
2693 +#endif
2694 +
2695 +#ifdef __USE_GNU
2696 +# define LOCK_MAND 32 /* This is a mandatory flock: */
2697 +# define LOCK_READ 64 /* ... which allows concurrent read operations. */
2698 +# define LOCK_WRITE 128 /* ... which allows concurrent write operations. */
2699 +# define LOCK_RW 192 /* ... Which allows concurrent read & write operations. */
2700 +#endif
2701 +
2702 +#ifdef __USE_GNU
2703 +/* Types of directory notifications that may be requested with F_NOTIFY. */
2704 +# define DN_ACCESS 0x00000001 /* File accessed. */
2705 +# define DN_MODIFY 0x00000002 /* File modified. */
2706 +# define DN_CREATE 0x00000004 /* File created. */
2707 +# define DN_DELETE 0x00000008 /* File removed. */
2708 +# define DN_RENAME 0x00000010 /* File renamed. */
2709 +# define DN_ATTRIB 0x00000020 /* File changed attibutes. */
2710 +# define DN_MULTISHOT 0x80000000 /* Don't remove notifier. */
2711 +#endif
2712 +
2713 +struct flock
2714 + {
2715 + short int l_type; /* Type of lock: F_RDLCK, F_WRLCK, or F_UNLCK. */
2716 + short int l_whence; /* Where `l_start' is relative to (like `lseek'). */
2717 +#ifndef __USE_FILE_OFFSET64
2718 + __off_t l_start; /* Offset where the lock begins. */
2719 + __off_t l_len; /* Size of the locked area; zero means until EOF. */
2720 +#else
2721 + __off64_t l_start; /* Offset where the lock begins. */
2722 + __off64_t l_len; /* Size of the locked area; zero means until EOF. */
2723 +#endif
2724 + __pid_t l_pid; /* Process holding the lock. */
2725 + };
2726 +
2727 +#ifdef __USE_LARGEFILE64
2728 +struct flock64
2729 + {
2730 + short int l_type; /* Type of lock: F_RDLCK, F_WRLCK, or F_UNLCK. */
2731 + short int l_whence; /* Where `l_start' is relative to (like `lseek'). */
2732 + __off64_t l_start; /* Offset where the lock begins. */
2733 + __off64_t l_len; /* Size of the locked area; zero means until EOF. */
2734 + __pid_t l_pid; /* Process holding the lock. */
2735 + };
2736 +#endif
2737 +
2738 +/* Define some more compatibility macros to be backward compatible with
2739 + BSD systems which did not managed to hide these kernel macros. */
2740 +#ifdef __USE_BSD
2741 +# define FAPPEND O_APPEND
2742 +# define FFSYNC O_FSYNC
2743 +# define FASYNC O_ASYNC
2744 +# define FNONBLOCK O_NONBLOCK
2745 +# define FNDELAY O_NDELAY
2746 +#endif /* Use BSD. */
2747 +
2748 +/* Advise to `posix_fadvise'. */
2749 +#ifdef __USE_XOPEN2K
2750 +# define POSIX_FADV_NORMAL 0 /* No further special treatment. */
2751 +# define POSIX_FADV_RANDOM 1 /* Expect random page references. */
2752 +# define POSIX_FADV_SEQUENTIAL 2 /* Expect sequential page references. */
2753 +# define POSIX_FADV_WILLNEED 3 /* Will need these pages. */
2754 +# define POSIX_FADV_DONTNEED 4 /* Don't need these pages. */
2755 +# define POSIX_FADV_NOREUSE 5 /* Data will be accessed once. */
2756 +#endif
2757 +
2758 +#ifdef __USE_GNU
2759 +# define SYNC_FILE_RANGE_WAIT_BEFORE 1 /* Wait upon writeout of all pages
2760 + in the range before performing the
2761 + write. */
2762 +# define SYNC_FILE_RANGE_WRITE 2 /* Initiate writeout of all those
2763 + dirty pages in the range which are
2764 + not presently under writeback. */
2765 +# define SYNC_FILE_RANGE_WAIT_AFTER 4 /* Wait upon writeout of all pages in
2766 + the range after performing the
2767 + write. */
2768 +#endif
2769 +
2770 +__BEGIN_DECLS
2771 +
2772 +#ifdef __USE_GNU
2773 +
2774 +/* Provide kernel hint to read ahead. */
2775 +extern ssize_t readahead (int __fd, __off64_t __offset, size_t __count)
2776 + __THROW;
2777 +
2778 +/* Selective file content synch'ing. */
2779 +extern int sync_file_range (int __fd, __off64_t __from, __off64_t __to,
2780 + unsigned int __flags);
2781 +
2782 +/* Splice address range into a pipe. */
2783 +extern ssize_t vmsplice (int __fdout, const struct iovec *__iov,
2784 + size_t __count, unsigned int __flags);
2785 +
2786 +/* Splice two files together. */
2787 +extern ssize_t splice (int __fdin, __off64_t *__offin, int __fdout,
2788 + __off64_t *__offout, size_t __len,
2789 + unsigned int __flags);
2790 +
2791 +/* In-kernel implementation of tee for pipe buffers. */
2792 +extern ssize_t tee (int __fdin, int __fdout, size_t __len,
2793 + unsigned int __flags);
2794 +
2795 +#endif
2796 +
2797 +__END_DECLS
2798 --- /dev/null
2799 +++ b/libc/sysdeps/linux/ubicom32/bits/kernel_stat.h
2800 @@ -0,0 +1,55 @@
2801 +#ifndef _BITS_STAT_STRUCT_H
2802 +#define _BITS_STAT_STRUCT_H
2803 +
2804 +#ifndef _LIBC
2805 +#error bits/kernel_stat.h is for internal uClibc use only!
2806 +#endif
2807 +
2808 +/* This file provides whatever this particular arch's kernel thinks
2809 + * struct kernel_stat should look like... It turns out each arch has a
2810 + * different opinion on the subject... */
2811 +
2812 +struct kernel_stat {
2813 + unsigned short st_dev;
2814 + unsigned short __pad1;
2815 + unsigned long st_ino;
2816 + unsigned short st_mode;
2817 + unsigned short st_nlink;
2818 + unsigned short st_uid;
2819 + unsigned short st_gid;
2820 + unsigned short st_rdev;
2821 + unsigned short __pad2;
2822 + unsigned long st_size;
2823 + unsigned long st_blksize;
2824 + unsigned long st_blocks;
2825 + struct timespec st_atim;
2826 + struct timespec st_mtim;
2827 + struct timespec st_ctim;
2828 + unsigned long __unused4;
2829 + unsigned long __unused5;
2830 +};
2831 +
2832 +struct kernel_stat64 {
2833 + unsigned char __pad0[6];
2834 + unsigned short st_dev;
2835 + unsigned char __pad1[4];
2836 +#define _HAVE_STAT64___ST_INO
2837 + unsigned long __st_ino;
2838 + unsigned int st_mode;
2839 + unsigned int st_nlink;
2840 + unsigned long st_uid;
2841 + unsigned long st_gid;
2842 + unsigned char __pad2[6];
2843 + unsigned short st_rdev;
2844 + unsigned char __pad3[4];
2845 + long long st_size;
2846 + unsigned long st_blksize;
2847 + unsigned long st_blocks; /* Number 512-byte blocks allocated. */
2848 + unsigned long __pad4; /* future possible st_blocks high bits */
2849 + struct timespec st_atim;
2850 + struct timespec st_mtim;
2851 + struct timespec st_ctim;
2852 + unsigned long long st_ino;
2853 +};
2854 +
2855 +#endif /* _BITS_STAT_STRUCT_H */
2856 --- /dev/null
2857 +++ b/libc/sysdeps/linux/ubicom32/bits/kernel_types.h
2858 @@ -0,0 +1,44 @@
2859 +/* Note that we use the exact same include guard #define names
2860 + * as asm/posix_types.h. This will avoid gratuitous conflicts
2861 + * with the posix_types.h kernel header, and will ensure that
2862 + * our private content, and not the kernel header, will win.
2863 + * -Erik
2864 + */
2865 +#ifndef __ARCH_UBICOM32_POSIX_TYPES_H
2866 +#define __ARCH_UBICOM32_POSIX_TYPES_H
2867 +
2868 +typedef unsigned long __kernel_dev_t;
2869 +typedef unsigned long __kernel_ino_t;
2870 +typedef unsigned short __kernel_mode_t;
2871 +typedef unsigned short __kernel_nlink_t;
2872 +typedef long __kernel_off_t;
2873 +typedef int __kernel_pid_t;
2874 +typedef unsigned short __kernel_ipc_pid_t;
2875 +typedef unsigned short __kernel_uid_t;
2876 +typedef unsigned short __kernel_gid_t;
2877 +typedef unsigned int __kernel_size_t;
2878 +typedef int __kernel_ssize_t;
2879 +typedef int __kernel_ptrdiff_t;
2880 +typedef long __kernel_time_t;
2881 +typedef long __kernel_suseconds_t;
2882 +typedef long __kernel_clock_t;
2883 +typedef int __kernel_daddr_t;
2884 +typedef char * __kernel_caddr_t;
2885 +typedef unsigned short __kernel_uid16_t;
2886 +typedef unsigned short __kernel_gid16_t;
2887 +typedef unsigned int __kernel_uid32_t;
2888 +typedef unsigned int __kernel_gid32_t;
2889 +typedef unsigned short __kernel_old_uid_t;
2890 +typedef unsigned short __kernel_old_gid_t;
2891 +typedef unsigned short __kernel_old_dev_t;
2892 +typedef long long __kernel_loff_t;
2893 +
2894 +typedef struct {
2895 +#ifdef __USE_ALL
2896 + int val[2];
2897 +#else
2898 + int __val[2];
2899 +#endif
2900 +} __kernel_fsid_t;
2901 +
2902 +#endif /* __ARCH_UBICOM32_POSIX_TYPES_H */
2903 --- /dev/null
2904 +++ b/libc/sysdeps/linux/ubicom32/bits/mman.h
2905 @@ -0,0 +1,103 @@
2906 +/* Definitions for POSIX memory map interface. Linux/m68k version.
2907 + Copyright (C) 1997, 2000, 2003, 2005 Free Software Foundation, Inc.
2908 + This file is part of the GNU C Library.
2909 +
2910 + The GNU C Library is free software; you can redistribute it and/or
2911 + modify it under the terms of the GNU Lesser General Public
2912 + License as published by the Free Software Foundation; either
2913 + version 2.1 of the License, or (at your option) any later version.
2914 +
2915 + The GNU C Library is distributed in the hope that it will be useful,
2916 + but WITHOUT ANY WARRANTY; without even the implied warranty of
2917 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2918 + Lesser General Public License for more details.
2919 +
2920 + You should have received a copy of the GNU Lesser General Public
2921 + License along with the GNU C Library; if not, write to the Free
2922 + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
2923 + 02111-1307 USA. */
2924 +
2925 +#ifndef _SYS_MMAN_H
2926 +# error "Never use <bits/mman.h> directly; include <sys/mman.h> instead."
2927 +#endif
2928 +
2929 +/* The following definitions basically come from the kernel headers.
2930 + But the kernel header is not namespace clean. */
2931 +
2932 +
2933 +/* Protections are chosen from these bits, OR'd together. The
2934 + implementation does not necessarily support PROT_EXEC or PROT_WRITE
2935 + without PROT_READ. The only guarantees are that no writing will be
2936 + allowed without PROT_WRITE and no access will be allowed for PROT_NONE. */
2937 +
2938 +#define PROT_READ 0x1 /* Page can be read. */
2939 +#define PROT_WRITE 0x2 /* Page can be written. */
2940 +#define PROT_EXEC 0x4 /* Page can be executed. */
2941 +#define PROT_NONE 0x0 /* Page can not be accessed. */
2942 +#define PROT_GROWSDOWN 0x01000000 /* Extend change to start of
2943 + growsdown vma (mprotect only). */
2944 +#define PROT_GROWSUP 0x02000000 /* Extend change to start of
2945 + growsup vma (mprotect only). */
2946 +
2947 +/* Sharing types (must choose one and only one of these). */
2948 +#define MAP_SHARED 0x01 /* Share changes. */
2949 +#define MAP_PRIVATE 0x02 /* Changes are private. */
2950 +#ifdef __USE_MISC
2951 +# define MAP_TYPE 0x0f /* Mask for type of mapping. */
2952 +#endif
2953 +
2954 +/* Other flags. */
2955 +#define MAP_FIXED 0x10 /* Interpret addr exactly. */
2956 +#ifdef __USE_MISC
2957 +# define MAP_FILE 0
2958 +# define MAP_ANONYMOUS 0x20 /* Don't use a file. */
2959 +# define MAP_ANON MAP_ANONYMOUS
2960 +#endif
2961 +
2962 +/* These are Linux-specific. */
2963 +#ifdef __USE_MISC
2964 +# define MAP_GROWSDOWN 0x0000100 /* Stack-like segment. */
2965 +# define MAP_DENYWRITE 0x0000800 /* ETXTBSY */
2966 +# define MAP_EXECUTABLE 0x0001000 /* Mark it as an executable. */
2967 +# define MAP_LOCKED 0x0002000 /* Lock the mapping. */
2968 +# define MAP_NORESERVE 0x0004000 /* Don't check for reservations. */
2969 +# define MAP_POPULATE 0x0008000 /* Populate (prefault) pagetables. */
2970 +# define MAP_NONBLOCK 0x0010000 /* Do not block on IO. */
2971 +# define MAP_UNINITIALIZE 0x4000000 /* For anonymous mmap, memory could be uninitialized. */
2972 +#endif
2973 +
2974 +/* Flags to `msync'. */
2975 +#define MS_ASYNC 1 /* Sync memory asynchronously. */
2976 +#define MS_SYNC 4 /* Synchronous memory sync. */
2977 +#define MS_INVALIDATE 2 /* Invalidate the caches. */
2978 +
2979 +/* Flags for `mlockall'. */
2980 +#define MCL_CURRENT 1 /* Lock all currently mapped pages. */
2981 +#define MCL_FUTURE 2 /* Lock all additions to address
2982 + space. */
2983 +
2984 +/* Flags for `mremap'. */
2985 +#ifdef __USE_GNU
2986 +# define MREMAP_MAYMOVE 1
2987 +# define MREMAP_FIXED 2
2988 +#endif
2989 +
2990 +/* Advice to `madvise'. */
2991 +#ifdef __USE_BSD
2992 +# define MADV_NORMAL 0 /* No further special treatment. */
2993 +# define MADV_RANDOM 1 /* Expect random page references. */
2994 +# define MADV_SEQUENTIAL 2 /* Expect sequential page references. */
2995 +# define MADV_WILLNEED 3 /* Will need these pages. */
2996 +# define MADV_DONTNEED 4 /* Don't need these pages. */
2997 +# define MADV_DONTFORK 10 /* Do not inherit across fork. */
2998 +# define MADV_DOFORK 11 /* Do inherit across fork. */
2999 +#endif
3000 +
3001 +/* The POSIX people had to invent similar names for the same things. */
3002 +#ifdef __USE_XOPEN2K
3003 +# define POSIX_MADV_NORMAL 0 /* No further special treatment. */
3004 +# define POSIX_MADV_RANDOM 1 /* Expect random page references. */
3005 +# define POSIX_MADV_SEQUENTIAL 2 /* Expect sequential page references. */
3006 +# define POSIX_MADV_WILLNEED 3 /* Will need these pages. */
3007 +# define POSIX_MADV_DONTNEED 4 /* Don't need these pages. */
3008 +#endif
3009 --- /dev/null
3010 +++ b/libc/sysdeps/linux/ubicom32/bits/setjmp.h
3011 @@ -0,0 +1,52 @@
3012 +/* Define the machine-dependent type `jmp_buf'. Ubicom32 version.
3013 + Copyright (C) 1992,93,95,97,2000 Free Software Foundation, Inc.
3014 + This file is part of the GNU C Library.
3015 +
3016 + The GNU C Library is free software; you can redistribute it and/or
3017 + modify it under the terms of the GNU Lesser General Public
3018 + License as published by the Free Software Foundation; either
3019 + version 2.1 of the License, or (at your option) any later version.
3020 +
3021 + The GNU C Library is distributed in the hope that it will be useful,
3022 + but WITHOUT ANY WARRANTY; without even the implied warranty of
3023 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3024 + Lesser General Public License for more details.
3025 +
3026 + You should have received a copy of the GNU Lesser General Public
3027 + License along with the GNU C Library; if not, write to the Free
3028 + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
3029 + 02111-1307 USA. */
3030 +
3031 +#ifndef _BITS_SETJMP_H
3032 +#define _BITS_SETJMP_H 1
3033 +
3034 +#if !defined _SETJMP_H && !defined _PTHREAD_H
3035 +# error "Never include <bits/setjmp.h> directly; use <setjmp.h> instead."
3036 +#endif
3037 +
3038 +#ifndef _ASM
3039 +/*
3040 + * This is the structure where we are going to save D10-D13, A0, A1, A2, A5, A6 and SP(A7).
3041 + * A5 is the return address. Call to setjmp will save these. Call to longjmp will return
3042 + * Control to the address in A5.
3043 + */
3044 +typedef struct setjmp_save_struct {
3045 + unsigned long d10; /* D10 */
3046 + unsigned long d11; /* D11 */
3047 + unsigned long d12; /* D12 */
3048 + unsigned long d13; /* D13 */
3049 + unsigned long a1; /* A1 */
3050 + unsigned long a2; /* A2 */
3051 + unsigned long a5; /* A5 return address. */
3052 + unsigned long a6; /* A6 */
3053 + unsigned long sp; /* A7 stack pointer. */
3054 +} __jmp_buf[1];
3055 +
3056 +#endif
3057 +
3058 +/* Test if longjmp to JMPBUF would unwind the frame
3059 + containing a local variable at ADDRESS. */
3060 +#define _JMPBUF_UNWINDS(jmpbuf, address) \
3061 + ((void *) (address) < (void*)(jmpbuf)->sp)
3062 +
3063 +#endif /* bits/setjmp.h */
3064 --- /dev/null
3065 +++ b/libc/sysdeps/linux/ubicom32/bits/stackinfo.h
3066 @@ -0,0 +1,28 @@
3067 +/* Copyright (C) 1999 Free Software Foundation, Inc.
3068 + This file is part of the GNU C Library.
3069 +
3070 + The GNU C Library is free software; you can redistribute it and/or
3071 + modify it under the terms of the GNU Lesser General Public
3072 + License as published by the Free Software Foundation; either
3073 + version 2.1 of the License, or (at your option) any later version.
3074 +
3075 + The GNU C Library is distributed in the hope that it will be useful,
3076 + but WITHOUT ANY WARRANTY; without even the implied warranty of
3077 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3078 + Lesser General Public License for more details.
3079 +
3080 + You should have received a copy of the GNU Lesser General Public
3081 + License along with the GNU C Library; if not, write to the Free
3082 + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
3083 + 02111-1307 USA. */
3084 +
3085 +/* This file contains a bit of information about the stack allocation
3086 + of the processor. */
3087 +
3088 +#ifndef _STACKINFO_H
3089 +#define _STACKINFO_H 1
3090 +
3091 +/* On Ubicom32 the stack grows down. */
3092 +#define _STACK_GROWS_DOWN 1
3093 +
3094 +#endif /* stackinfo.h */
3095 --- /dev/null
3096 +++ b/libc/sysdeps/linux/ubicom32/bits/syscalls.h
3097 @@ -0,0 +1,81 @@
3098 +#ifndef _BITS_SYSCALLS_H
3099 +#define _BITS_SYSCALLS_H
3100 +#ifndef _SYSCALL_H
3101 +# error "Never use <bits/syscalls.h> directly; include <sys/syscall.h> instead."
3102 +#endif
3103 +
3104 +/* m68k headers does stupid stuff with __NR_iopl / __NR_vm86:
3105 + * #define __NR_iopl not supported
3106 + * #define __NR_vm86 not supported
3107 + */
3108 +#undef __NR_iopl
3109 +#undef __NR_vm86
3110 +
3111 +#ifndef __ASSEMBLER__
3112 +
3113 +#include <errno.h>
3114 +
3115 +/* Linux takes system call arguments in registers:
3116 +
3117 + syscall number %d8
3118 + arg 1 %d0
3119 + arg 2 %d1
3120 + arg 3 %d2
3121 + arg 4 %d3
3122 + arg 5 %d4
3123 + arg 6 %d5
3124 +*/
3125 +
3126 +#define __loadargs_0(name, dummy) \
3127 + d8 = (long int)name
3128 +
3129 +#define __loadargs_1(name, __arg1) \
3130 + __loadargs_0(name, 0); \
3131 + d0_retval = (long int) __arg1
3132 +
3133 +#define __loadargs_2(name, __arg1, __arg2) \
3134 + __loadargs_1(name, __arg1); \
3135 + d1 = (long int) __arg2
3136 +
3137 +#define __loadargs_3(name, __arg1, __arg2, __arg3) \
3138 + __loadargs_2(name, __arg1, __arg2); \
3139 + d2 = (long int) __arg3
3140 +
3141 +#define __loadargs_4(name, __arg1, __arg2, __arg3, __arg4) \
3142 + __loadargs_3(name, __arg1, __arg2, __arg3); \
3143 + d3 = (long int)__arg4
3144 +
3145 +#define __loadargs_5(name, __arg1, __arg2, __arg3, __arg4, __arg5) \
3146 + __loadargs_4(name, __arg1, __arg2, __arg3, __arg4); \
3147 + d4 = (long int)__arg5
3148 +
3149 +#define __loadargs_6(name, __arg1, __arg2, __arg3, __arg4, __arg5, __arg6) \
3150 + __loadargs_5(name, __arg1, __arg2, __arg3, __arg4, __arg5); \
3151 + d5 = (long int)__arg6
3152 +
3153 +#define INTERNAL_SYSCALL_NCS(name, err, nr, args...) \
3154 +({ \
3155 + register long int d0_retval __asm__ ("d0"); \
3156 + register long int d1 __asm__ ("d1"); \
3157 + register long int d2 __asm__ ("d2"); \
3158 + register long int d3 __asm__ ("d3"); \
3159 + register long int d4 __asm__ ("d4"); \
3160 + register long int d5 __asm__ ("d5"); \
3161 + register long int d8 __asm__ ("d8"); \
3162 + __loadargs_##nr (name, args); \
3163 + __asm__ __volatile__ ( \
3164 + " moveai a5, #%%hi(0x40400000)\n\t" \
3165 + " calli a5, 16(a5)\n\t" \
3166 + : "+r" (d0_retval), "+r" (d1), "+r" (d2), "+r" (d3), \
3167 + "+r" (d4), "+r" (d5), "+r" (d8) : \
3168 + : "cc", "memory", \
3169 + "acc0_lo", "acc0_hi", "acc1_lo", "acc1_hi", \
3170 + "source3", \
3171 + "a0", "a3", "a4", "a5", \
3172 + "d6", "d7", "d9", "d14", "d15" \
3173 + ); \
3174 + d0_retval; \
3175 +})
3176 +
3177 +#endif /* __ASSEMBLER__ */
3178 +#endif /* _BITS_SYSCALLS_H */
3179 --- /dev/null
3180 +++ b/libc/sysdeps/linux/ubicom32/bits/uClibc_arch_features.h
3181 @@ -0,0 +1,45 @@
3182 +/*
3183 + * Track misc arch-specific features that aren't config options
3184 + */
3185 +
3186 +#ifndef _BITS_UCLIBC_ARCH_FEATURES_H
3187 +#define _BITS_UCLIBC_ARCH_FEATURES_H
3188 +
3189 +/* instruction used when calling abort() to kill yourself */
3190 +/*#define __UCLIBC_ABORT_INSTRUCTION__ "asm instruction"*/
3191 +#undef __UCLIBC_ABORT_INSTRUCTION__
3192 +
3193 +/* can your target use syscall6() for mmap ? */
3194 +#undef __UCLIBC_MMAP_HAS_6_ARGS__
3195 +
3196 +/* does your target use syscall4() for truncate64 ? (32bit arches only) */
3197 +#undef __UCLIBC_TRUNCATE64_HAS_4_ARGS__
3198 +
3199 +/* does your target have a broken create_module() ? */
3200 +#undef __UCLIBC_BROKEN_CREATE_MODULE__
3201 +
3202 +/* does your target have to worry about older [gs]etrlimit() ? */
3203 +#undef __UCLIBC_HANDLE_OLDER_RLIMIT__
3204 +
3205 +/* does your target prefix all symbols with an _ ? */
3206 +#define __UCLIBC_NO_UNDERSCORES__
3207 +
3208 +/* does your target have an asm .set ? */
3209 +#define __UCLIBC_HAVE_ASM_SET_DIRECTIVE__
3210 +
3211 +/* define if target doesn't like .global */
3212 +#undef __UCLIBC_ASM_GLOBAL_DIRECTIVE__
3213 +
3214 +/* define if target supports .weak */
3215 +#define __UCLIBC_HAVE_ASM_WEAK_DIRECTIVE__
3216 +
3217 +/* define if target supports .weakext */
3218 +#undef __UCLIBC_HAVE_ASM_WEAKEXT_DIRECTIVE__
3219 +
3220 +/* needed probably only for ppc64 */
3221 +#undef __UCLIBC_HAVE_ASM_GLOBAL_DOT_NAME__
3222 +
3223 +/* define if target supports IEEE signed zero floats */
3224 +#define __UCLIBC_HAVE_SIGNED_ZERO__
3225 +
3226 +#endif /* _BITS_UCLIBC_ARCH_FEATURES_H */
3227 --- /dev/null
3228 +++ b/libc/sysdeps/linux/ubicom32/bits/wordsize.h
3229 @@ -0,0 +1,19 @@
3230 +/* Copyright (C) 1999 Free Software Foundation, Inc.
3231 + This file is part of the GNU C Library.
3232 +
3233 + The GNU C Library is free software; you can redistribute it and/or
3234 + modify it under the terms of the GNU Lesser General Public
3235 + License as published by the Free Software Foundation; either
3236 + version 2.1 of the License, or (at your option) any later version.
3237 +
3238 + The GNU C Library is distributed in the hope that it will be useful,
3239 + but WITHOUT ANY WARRANTY; without even the implied warranty of
3240 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3241 + Lesser General Public License for more details.
3242 +
3243 + You should have received a copy of the GNU Lesser General Public
3244 + License along with the GNU C Library; if not, write to the Free
3245 + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
3246 + 02111-1307 USA. */
3247 +
3248 +#define __WORDSIZE 32
3249 --- /dev/null
3250 +++ b/libc/sysdeps/linux/ubicom32/clone.S
3251 @@ -0,0 +1,71 @@
3252 +#include <sys/syscall.h>
3253 +
3254 + .global __syscall_error
3255 +
3256 +/* int _clone(int (*fn)(void *arg), void *child_stack, int flags, void *arg); */
3257 + .text
3258 + .type clone,@function
3259 + .global clone
3260 +clone:
3261 + /* Sanity check arguments. */
3262 + sub.4 #0, #0, d0 /* Test if fn is zero. */
3263 + jmpeq.f 1f /* arg bad */
3264 + sub.4 #0, #0, d1 /* Test if child_stack is zero. */
3265 + jmpeq.f 1f /* arg bad */
3266 +
3267 + /* Set up child_stack frame.. arg and fn */
3268 + move.4 a3, d1
3269 + move.4 -4(a3)++, d3 /* push 'arg' to child stack */
3270 + move.4 -4(a3)++, d0 /* push fn to child stack, this will become a5
3271 + * on new child */
3272 + move.4 d1, a3
3273 + move.4 -4(sp)++, a5 /* push a5 to our stack */
3274 +
3275 + /*
3276 + * The syscall clone is clone(int flags, void *child_stack) so we set
3277 + * that up now
3278 + */
3279 + move.4 d0, d2 /* Move flags to d0 */
3280 +
3281 + /* Do Clone syscall */
3282 + movei d8, #__NR_clone
3283 + moveai a5, #%hi(0x40400000)
3284 + calli a5, 0x10(a5)
3285 + move.4 a5, (sp)4++ /* pop a5 from stack */
3286 +
3287 + /* Clone Complete */
3288 + cmpi d0, #0 /* Test if d0 is less than zero. If it is we
3289 + * return the error */
3290 + jmplt.f 2f /* If return is less than we had an error */
3291 + jmpeq.f 3f /* If return is 0 we are in the clone, jump to
3292 + * thread start */
3293 + ret a5 /* d0 is pid */
3294 +
3295 + /* Invalid Value */
3296 +1: movei d0, #-22 /* EINVAL */
3297 +
3298 + /* Call syscall Error */
3299 +2: sub.4 d0, #0, d0 /* d0 = -d0 */
3300 +#if defined(__UBICOM32_FDPIC__)
3301 + call a3, __syscall_error
3302 +#else
3303 + moveai a3, #%hi(__syscall_error)
3304 + calli a3, %lo(__syscall_error)(a3)
3305 +#endif
3306 + /* Child Thread Start */
3307 +3:
3308 +#if defined(__UBICOM32_FDPIC__)
3309 + /* a5 actually contains a function descriptor for fdpic */
3310 + move.4 a0, 4(a5) /* set GOT for this function */
3311 + move.4 a5, 0(a5) /* get address of entry point */
3312 +#endif
3313 + move.4 d0, (sp)4++ /* pop 'arg' to stack */
3314 + calli a5, 0(a5)
3315 + movei d8, #__NR_exit
3316 + moveai a3, #%hi(0x40400000)
3317 + calli a3, 0x10(a3)
3318 +
3319 + .size clone, . - clone
3320 + .global __GI_clone
3321 + .hidden __GI_clone
3322 + .set __GI_clone,clone
3323 --- /dev/null
3324 +++ b/libc/sysdeps/linux/ubicom32/crt1.S
3325 @@ -0,0 +1,179 @@
3326 +/* Startup code compliant to the ELF m68k ABI.
3327 + Copyright (C) 1996, 1997, 1998, 2001, 2002 Free Software Foundation, Inc.
3328 + This file is part of the GNU C Library.
3329 +
3330 + The GNU C Library is free software; you can redistribute it and/or
3331 + modify it under the terms of the GNU Lesser General Public
3332 + License as published by the Free Software Foundation; either
3333 + version 2.1 of the License, or (at your option) any later version.
3334 +
3335 + In addition to the permissions in the GNU Lesser General Public
3336 + License, the Free Software Foundation gives you unlimited
3337 + permission to link the compiled version of this file with other
3338 + programs, and to distribute those programs without any restriction
3339 + coming from the use of this file. (The GNU Lesser General Public
3340 + License restrictions do apply in other respects; for example, they
3341 + cover modification of the file, and distribution when not linked
3342 + into another program.)
3343 +
3344 + Note that people who make modified versions of this file are not
3345 + obligated to grant this special exception for their modified
3346 + versions; it is their choice whether to do so. The GNU Lesser
3347 + General Public License gives permission to release a modified
3348 + version without this exception; this exception also makes it
3349 + possible to release a modified version which carries forward this
3350 + exception.
3351 +
3352 + The GNU C Library is distributed in the hope that it will be useful,
3353 + but WITHOUT ANY WARRANTY; without even the implied warranty of
3354 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3355 + Lesser General Public License for more details.
3356 +
3357 + You should have received a copy of the GNU Lesser General Public
3358 + License along with the GNU C Library; if not, write to the Free
3359 + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
3360 + 02111-1307 USA. */
3361 +
3362 +#include <features.h>
3363 +
3364 +/* This is the canonical entry point, usually the first thing in the text
3365 + segment. The SVR4/m68k ABI says that when the entry point runs,
3366 + most registers' values are unspecified, except for:
3367 +
3368 + %a1 Contains a function pointer to be registered with `atexit'.
3369 + This is how the dynamic linker arranges to have DT_FINI
3370 + functions called for shared libraries that have been loaded
3371 + before this code runs.
3372 +
3373 + %sp The stack contains the arguments and environment:
3374 + 0(%sp) argc
3375 + 4(%sp) argv[0]
3376 + ...
3377 + (4*argc)(%sp) NULL
3378 + (4*(argc+1))(%sp) envp[0]
3379 + ...
3380 + NULL
3381 +
3382 + The uclinux conventions are different. %a1 is not defined on entry
3383 + and the stack is laid out as follows:
3384 +
3385 + 0(%sp) argc
3386 + 4(%sp) argv
3387 + 8(%sp) envp
3388 +*/
3389 +
3390 +
3391 + .text
3392 + .type main,@function
3393 + .type _init,%function
3394 + .type _fini,%function
3395 +#ifndef __UCLIBC_CTOR_DTOR__
3396 + .weak _init
3397 + .weak _fini
3398 +#endif
3399 + .globl _start
3400 + .global __uClibc_main;
3401 + .type __uClibc_main,@function;
3402 + .type _start,@function
3403 +_start:
3404 +
3405 +#if defined(__UBICOM32_FDPIC__) && !defined(L_Scrt1)
3406 + /* P0 contains a pointer to the program's load map. */
3407 + call a3, .Lcall;
3408 +.Lcall:
3409 + move.4 d0, d1 ; load exec_map_addr
3410 + moveai a4, #%hi(.Lcall)
3411 + lea.1 d15, %lo(.Lcall)(a4)
3412 + sub.4 d15, a3, d15 ; difference between .Lcall and actual address of .Lcall
3413 + moveai a3, #%hi(__ROFIXUP_LIST__)
3414 + lea.1 d1, %lo(__ROFIXUP_LIST__)(a3)
3415 + moveai a3, #%hi(__ROFIXUP_END__)
3416 + lea.1 d2, %lo(__ROFIXUP_END__)(a3)
3417 + add.4 d1, d1, d15
3418 + add.4 d2, d2, d15
3419 + call a5, __self_reloc ; returns GOT in d0
3420 + move.4 a0, d0 ; set GOT
3421 +#endif
3422 +
3423 +/*
3424 + all this is setup to make the following call.
3425 +
3426 + void __uClibc_main(
3427 + d0 - int (*main)(int, char **, char **),
3428 + d1 - int argc, (d1)
3429 + d2 - char **argv,
3430 + d3 - void (*app_init)(void),
3431 + d4 - void (*app_fini)(void),
3432 + d5 - void (*rtld_fini)(void),
3433 + d6 - void *stack_end
3434 + );
3435 + */
3436 +
3437 + /*
3438 + * Load pointer to main into d0
3439 + */
3440 +#ifdef __UBICOM32_FDPIC__
3441 + movei d0, #%got_funcdesc_lo(main)
3442 + move.4 d0, (a0, d0)
3443 +#else
3444 + moveai a3, #%hi(main)
3445 + lea.1 d0, %lo(main)(a3)
3446 +#endif
3447 +
3448 + /*
3449 + * Grab the environment stuff from stack and set up d1, d2 with it.
3450 + */
3451 + move.4 d1, (sp)
3452 +#ifdef __UBICOM32_FDPIC__
3453 + /* For FDPIC the calling convention is different than flat */
3454 + lea.1 d2, 4(sp)
3455 +#else
3456 + move.4 d2, 4(sp)
3457 +#endif
3458 +
3459 +#ifdef __UCLIBC_CTOR_DTOR__
3460 + /*
3461 + * Load pointer to _init into d3
3462 + */
3463 +#ifdef __UBICOM32_FDPIC__
3464 + movei d3, #%got_funcdesc_lo(_init)
3465 + move.4 d3, (a0, d3)
3466 +#else
3467 + moveai a3, #%hi(_init)
3468 + lea.1 d3, %lo(_init)(a3)
3469 +#endif
3470 +
3471 + /*
3472 + * Load pointer to _fini into d4
3473 + */
3474 +#ifdef __UBICOM32_FDPIC__
3475 + movei d4, #%got_funcdesc_lo(_fini)
3476 + move.4 d4, (a0, d4)
3477 +#else
3478 + moveai a3, #%hi(_fini)
3479 + lea.1 d4, %lo(_fini)(a3)
3480 +#endif
3481 +
3482 +#else /* !__UCLIBC_CTOR_DTOR__ */
3483 + move.4 d3, #0 ; _init
3484 + move.4 d4, #0 ; _fini
3485 +#endif
3486 +
3487 +#ifdef __UBICOM32_FDPIC__
3488 + move.4 d5, a1 ; ldso _fini funcdesc (see dl-startup.h)
3489 +#else
3490 + movei d5, #0 ; rtld_fini (not used)
3491 +#endif
3492 +
3493 + move.4 d6, sp ; Stack End.
3494 +
3495 + /* Call the user's main function, and exit with its value. But
3496 + let the libc call main. */
3497 +#ifdef __UBICOM32_FDPIC__
3498 + call a5, __uClibc_main
3499 +#else
3500 + moveai a5, #%hi(__uClibc_main)
3501 + calli a5, %lo(__uClibc_main)(a5)
3502 +#endif
3503 +
3504 + bkpt #-1 ; Crash if somehow `exit' does return.
3505 --- /dev/null
3506 +++ b/libc/sysdeps/linux/ubicom32/crti.S
3507 @@ -0,0 +1,54 @@
3508 +/* Specialized code needed to support construction and destruction of
3509 + file-scope objects in C++ and Java code, and to support exception handling.
3510 + Copyright (C) 1999 Free Software Foundation, Inc.
3511 + Contributed by Charles-Antoine Gauthier (charles.gauthier@iit.nrc.ca).
3512 +
3513 +This file is part of GCC.
3514 +
3515 +GCC is free software; you can redistribute it and/or modify
3516 +it under the terms of the GNU General Public License as published by
3517 +the Free Software Foundation; either version 2, or (at your option)
3518 +any later version.
3519 +
3520 +GCC is distributed in the hope that it will be useful,
3521 +but WITHOUT ANY WARRANTY; without even the implied warranty of
3522 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3523 +GNU General Public License for more details.
3524 +
3525 +You should have received a copy of the GNU General Public License
3526 +along with GCC; see the file COPYING. If not, write to
3527 +the Free Software Foundation, 59 Temple Place - Suite 330,
3528 +Boston, MA 02111-1307, USA. */
3529 +
3530 +/* As a special exception, if you link this library with files
3531 + compiled with GCC to produce an executable, this does not cause
3532 + the resulting executable to be covered by the GNU General Public License.
3533 + This exception does not however invalidate any other reasons why
3534 + the executable file might be covered by the GNU General Public License. */
3535 +
3536 +/*
3537 + * This file just supplies function prologues for the .init and .fini
3538 + * sections. It is linked in before crtbegin.o.
3539 + */
3540 + .file "crti.o"
3541 + .ident "GNU C crti.o"
3542 +
3543 + .section .init
3544 + .align 2
3545 + .globl _init
3546 + .type _init, @function
3547 +_init:
3548 + move.4 -4(sp)++, a5
3549 +#ifdef __UBICOM32_FDPIC__
3550 + move.4 -4(sp)++, a0
3551 +#endif
3552 +
3553 + .section .fini
3554 + .align 2
3555 + .globl _fini
3556 + .type _fini, @function
3557 +_fini:
3558 + move.4 -4(sp)++, a5
3559 +#ifdef __UBICOM32_FDPIC__
3560 + move.4 -4(sp)++, a0
3561 +#endif
3562 --- /dev/null
3563 +++ b/libc/sysdeps/linux/ubicom32/crtn.S
3564 @@ -0,0 +1,47 @@
3565 +/* Specialized code needed to support construction and destruction of
3566 + file-scope objects in C++ and Java code, and to support exception handling.
3567 + Copyright (C) 1999 Free Software Foundation, Inc.
3568 + Contributed by Charles-Antoine Gauthier (charles.gauthier@iit.nrc.ca).
3569 +
3570 +This file is part of GCC.
3571 +
3572 +GCC is free software; you can redistribute it and/or modify
3573 +it under the terms of the GNU General Public License as published by
3574 +the Free Software Foundation; either version 2, or (at your option)
3575 +any later version.
3576 +
3577 +GCC is distributed in the hope that it will be useful,
3578 +but WITHOUT ANY WARRANTY; without even the implied warranty of
3579 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3580 +GNU General Public License for more details.
3581 +
3582 +You should have received a copy of the GNU General Public License
3583 +along with GCC; see the file COPYING. If not, write to
3584 +the Free Software Foundation, 59 Temple Place - Suite 330,
3585 +Boston, MA 02111-1307, USA. */
3586 +
3587 +/* As a special exception, if you link this library with files
3588 + compiled with GCC to produce an executable, this does not cause
3589 + the resulting executable to be covered by the GNU General Public License.
3590 + This exception does not however invalidate any other reasons why
3591 + the executable file might be covered by the GNU General Public License. */
3592 +
3593 +/*
3594 + * This file supplies function epilogues for the .init and .fini sections.
3595 + * It is linked in after all other files.
3596 + */
3597 +
3598 + .file "crtn.o"
3599 + .ident "GNU C crtn.o"
3600 +
3601 + .section .init
3602 +#ifdef __UBICOM32_FDPIC__
3603 + move.4 a0, (sp)4++
3604 +#endif
3605 + ret (sp)4++
3606 +
3607 + .section .fini
3608 +#ifdef __UBICOM32_FDPIC__
3609 + move.4 a0, (sp)4++
3610 +#endif
3611 + ret (sp)4++
3612 --- /dev/null
3613 +++ b/libc/sysdeps/linux/ubicom32/crtreloc.c
3614 @@ -0,0 +1,145 @@
3615 +/* Copyright (C) 2003, 2004 Free Software Foundation, Inc.
3616 + written by Alexandre Oliva <aoliva@redhat.com>
3617 +This file is part of the GNU C Library.
3618 +
3619 +The GNU C Library is free software; you can redistribute it and/or
3620 +modify it under the terms of the GNU Lesser General Public License as
3621 +published by the Free Software Foundation; either version 2.1 of the
3622 +License, or (at your option) any later version.
3623 +
3624 +In addition to the permissions in the GNU Lesser General Public
3625 +License, the Free Software Foundation gives you unlimited
3626 +permission to link the compiled version of this file with other
3627 +programs, and to distribute those programs without any restriction
3628 +coming from the use of this file. (The GNU Lesser General Public
3629 +License restrictions do apply in other respects; for example, they
3630 +cover modification of the file, and distribution when not linked
3631 +into another program.)
3632 +
3633 +The GNU C Library is distributed in the hope that it will be useful,
3634 +but WITHOUT ANY WARRANTY; without even the implied warranty of
3635 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3636 +Library General Public License for more details.
3637 +
3638 +You should have received a copy of the GNU Lesser General Public
3639 +License along with the GNU C Library; see the file COPYING.LIB. If
3640 +not, write to the Free Software Foundation, Inc., 675 Mass Ave,
3641 +Cambridge, MA 02139, USA. */
3642 +
3643 +#ifdef __UBICOM32_FDPIC__
3644 +
3645 +#include <sys/types.h>
3646 +#include <link.h>
3647 +
3648 +/* This file is to be compiled into crt object files, to enable
3649 + executables to easily self-relocate. */
3650 +
3651 +union word {
3652 + char c[4];
3653 + void *v;
3654 +};
3655 +
3656 +/* Compute the runtime address of pointer in the range [p,e), and then
3657 + map the pointer pointed by it. */
3658 +static __always_inline void ***
3659 +reloc_range_indirect (void ***p, void ***e,
3660 + const struct elf32_fdpic_loadmap *map)
3661 +{
3662 + while (p < e)
3663 + {
3664 + if (*p != (void **)-1)
3665 + {
3666 + void *ptr = __reloc_pointer (*p, map);
3667 + if (ptr != (void *)-1)
3668 + {
3669 + void *pt;
3670 + if ((long)ptr & 3)
3671 + {
3672 + unsigned char *c = ptr;
3673 + int i;
3674 + unsigned long v = 0;
3675 + for (i = 0; i < 4; i++)
3676 + v |= c[i] << 8 * i;
3677 + pt = (void *)v;
3678 + }
3679 + else
3680 + pt = *(void**)ptr;
3681 + pt = __reloc_pointer (pt, map);
3682 + if ((long)ptr & 3)
3683 + {
3684 + unsigned char *c = ptr;
3685 + int i;
3686 + unsigned long v = (unsigned long)pt;
3687 + for (i = 0; i < 4; i++, v >>= 8)
3688 + c[i] = v;
3689 + }
3690 + else
3691 + *(void**)ptr = pt;
3692 + }
3693 + }
3694 + p++;
3695 + }
3696 + return p;
3697 +}
3698 +
3699 +/* Call __reloc_range_indirect for the given range except for the last
3700 + entry, whose contents are only relocated. It's expected to hold
3701 + the GOT value. */
3702 +void* attribute_hidden
3703 +__self_reloc (const struct elf32_fdpic_loadmap *map,
3704 + void ***p, void ***e)
3705 +{
3706 + p = reloc_range_indirect (p, e-1, map);
3707 +
3708 + if (p >= e)
3709 + return (void*)-1;
3710 +
3711 + return __reloc_pointer (*p, map);
3712 +}
3713 +
3714 +#if 0
3715 +/* These are other functions that might be useful, but that we don't
3716 + need. */
3717 +
3718 +/* Remap pointers in [p,e). */
3719 +static __always_inline void**
3720 +reloc_range (void **p, void **e,
3721 + const struct elf32_fdpic_loadmap *map)
3722 +{
3723 + while (p < e)
3724 + {
3725 + *p = __reloc_pointer (*p, map);
3726 + p++;
3727 + }
3728 + return p;
3729 +}
3730 +
3731 +/* Remap p, adjust e by the same offset, then map the pointers in the
3732 + range determined by them. */
3733 +void attribute_hidden
3734 +__reloc_range (const struct elf32_fdpic_loadmap *map,
3735 + void **p, void **e)
3736 +{
3737 + void **old = p;
3738 +
3739 + p = __reloc_pointer (p, map);
3740 + e += p - old;
3741 + reloc_range (p, e, map);
3742 +}
3743 +
3744 +/* Remap p, adjust e by the same offset, then map pointers referenced
3745 + by the (unadjusted) pointers in the range. Return the relocated
3746 + value of the last pointer in the range. */
3747 +void* attribute_hidden
3748 +__reloc_range_indirect (const struct elf32_fdpic_loadmap *map,
3749 + void ***p, void ***e)
3750 +{
3751 + void ***old = p;
3752 +
3753 + p = __reloc_pointer (p, map);
3754 + e += p - old;
3755 + return reloc_range_indirect (p, e, map);
3756 +}
3757 +#endif
3758 +
3759 +#endif /* __UBICOM32_FDPIC__ */
3760 --- /dev/null
3761 +++ b/libc/sysdeps/linux/ubicom32/setjmp.S
3762 @@ -0,0 +1,72 @@
3763 +/* Setjmp for Ubicom32 */
3764 + .text
3765 + .global _setjmp
3766 + .type _setjmp,@function
3767 +_setjmp:
3768 + movea a3, d0 ; A3 now holds the jmp buf that was passed in.
3769 + move.4 (a3)4++, d10
3770 + move.4 (a3)4++, d11
3771 + move.4 (a3)4++, d12
3772 + move.4 (a3)4++, d13
3773 + move.4 (a3)4++, a1
3774 + move.4 (a3)4++, a2
3775 + move.4 (a3)4++, a5
3776 + move.4 (a3)4++, a6
3777 + move.4 (a3)4++, a7
3778 + move.4 d0, #0
3779 +
3780 + calli a5, 0(a5)
3781 + .size _setjmp, . - _setjmp
3782 +
3783 +/*
3784 + * __sigsetjmp for Ubicom32
3785 + * d0 holds sigjmp_buf and d1 holds the savemask. We will save the frame and then just call __sigjmp_save to do the mask save.
3786 + */
3787 + .global __sigsetjmp
3788 + .type __sigsetjmp,@function
3789 +__sigsetjmp:
3790 + movea a3, d0 ; A3 now holds the jmp buf that was passed in.
3791 + move.4 (a3)4++, d10
3792 + move.4 (a3)4++, d11
3793 + move.4 (a3)4++, d12
3794 + move.4 (a3)4++, d13
3795 + move.4 (a3)4++, a1
3796 + move.4 (a3)4++, a2
3797 + move.4 (a3)4++, a5
3798 + move.4 (a3)4++, a6
3799 + move.4 (a3)4++, a7
3800 +
3801 + ;; The frame has been saved. Call _sigjmp_save to get sigmask saved. a5 still has the return address and it will go back to that.
3802 +#if defined(__UBICOM32_FDPIC__)
3803 + call a3, __sigjmp_save
3804 +#else
3805 + moveai a3, #%hi(__sigjmp_save)
3806 + calli a3, %lo(__sigjmp_save)(a3)
3807 +#endif
3808 + .size __sigjmp_save, . - __sigjmp_save
3809 +
3810 + .global __longjmp
3811 + .type __longjmp,@function
3812 +__longjmp:
3813 + movea a3, d0 ; A3 now holds the jmp buf that was passed in.
3814 + move.4 d10, (a3)4++
3815 + move.4 d11, (a3)4++
3816 + move.4 d12, (a3)4++
3817 + move.4 d13, (a3)4++
3818 + move.4 a1 , (a3)4++
3819 + move.4 a2 , (a3)4++
3820 + move.4 a5 , (a3)4++
3821 + move.4 a6 , (a3)4++
3822 + move.4 a7 , (a3)4++
3823 +
3824 + sub.4 #0, #0, d1 ; Test if d1 is zero. If it is we have to return 1 other wise return content of d1
3825 + jmpeq.t 2f
3826 + move.4 d0, d1 ; d1 is non zero load it into d0
3827 + jmpt.t 3f
3828 +
3829 +2: move.4 d0, #1
3830 +3: calli a5, 0(a5)
3831 + .size __longjmp, . - __longjmp
3832 + .global __GI___longjmp
3833 + .hidden __GI___longjmp
3834 + .set __GI___longjmp,__longjmp
3835 --- /dev/null
3836 +++ b/libc/sysdeps/linux/ubicom32/sys/procfs.h
3837 @@ -0,0 +1,122 @@
3838 +/* Copyright (C) 1996, 1997, 1999, 2000 Free Software Foundation, Inc.
3839 + This file is part of the GNU C Library.
3840 +
3841 + The GNU C Library is free software; you can redistribute it and/or
3842 + modify it under the terms of the GNU Lesser General Public
3843 + License as published by the Free Software Foundation; either
3844 + version 2.1 of the License, or (at your option) any later version.
3845 +
3846 + The GNU C Library is distributed in the hope that it will be useful,
3847 + but WITHOUT ANY WARRANTY; without even the implied warranty of
3848 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3849 + Lesser General Public License for more details.
3850 +
3851 + You should have received a copy of the GNU Lesser General Public
3852 + License along with the GNU C Library; if not, write to the Free
3853 + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
3854 + 02111-1307 USA. */
3855 +
3856 +#ifndef _SYS_PROCFS_H
3857 +#define _SYS_PROCFS_H 1
3858 +
3859 +/* This is somehow modelled after the file of the same name on SysVr4
3860 + systems. It provides a definition of the core file format for ELF
3861 + used on Linux. */
3862 +
3863 +#include <features.h>
3864 +#include <signal.h>
3865 +#include <sys/time.h>
3866 +#include <sys/types.h>
3867 +#include <sys/ucontext.h>
3868 +#include <bits/wordsize.h>
3869 +
3870 +__BEGIN_DECLS
3871 +
3872 +#define ELF_NGREG 38
3873 +
3874 +typedef struct
3875 + {
3876 + union
3877 + {
3878 + unsigned long pr_regs[32];
3879 + double pr_dregs[16];
3880 + } pr_fr;
3881 + unsigned long __unused;
3882 + unsigned long pr_fsr;
3883 + unsigned char pr_qcnt;
3884 + unsigned char pr_q_entrysize;
3885 + unsigned char pr_en;
3886 + unsigned int pr_q[64];
3887 + } elf_fpregset_t;
3888 +
3889 +typedef unsigned long elf_greg_t;
3890 +typedef elf_greg_t elf_gregset_t[ELF_NGREG];
3891 +
3892 +struct elf_siginfo
3893 + {
3894 + int si_signo; /* Signal number. */
3895 + int si_code; /* Extra code. */
3896 + int si_errno; /* Errno. */
3897 + };
3898 +
3899 +/* Definitions to generate Intel SVR4-like core files. These mostly
3900 + have the same names as the SVR4 types with "elf_" tacked on the
3901 + front to prevent clashes with linux definitions, and the typedef
3902 + forms have been avoided. This is mostly like the SVR4 structure,
3903 + but more Linuxy, with things that Linux does not support and which
3904 + gdb doesn't really use excluded. Fields present but not used are
3905 + marked with "XXX". */
3906 +struct elf_prstatus
3907 + {
3908 + struct elf_siginfo pr_info; /* Info associated with signal. */
3909 + short int pr_cursig; /* Current signal. */
3910 + unsigned long int pr_sigpend; /* Set of pending signals. */
3911 + unsigned long int pr_sighold; /* Set of held signals. */
3912 + __pid_t pr_pid;
3913 + __pid_t pr_ppid;
3914 + __pid_t pr_pgrp;
3915 + __pid_t pr_sid;
3916 + struct timeval pr_utime; /* User time. */
3917 + struct timeval pr_stime; /* System time. */
3918 + struct timeval pr_cutime; /* Cumulative user time. */
3919 + struct timeval pr_cstime; /* Cumulative system time. */
3920 + elf_gregset_t pr_reg; /* GP registers. */
3921 + int pr_fpvalid; /* True if math copro being used. */
3922 + };
3923 +
3924 +
3925 +#define ELF_PRARGSZ (80) /* Number of chars for args */
3926 +
3927 +struct elf_prpsinfo
3928 + {
3929 + char pr_state; /* Numeric process state. */
3930 + char pr_sname; /* Char for pr_state. */
3931 + char pr_zomb; /* Zombie. */
3932 + char pr_nice; /* Nice val. */
3933 + unsigned long int pr_flag; /* Flags. */
3934 + unsigned short int pr_uid;
3935 + unsigned short int pr_gid;
3936 + int pr_pid, pr_ppid, pr_pgrp, pr_sid;
3937 + /* Lots missing */
3938 + char pr_fname[16]; /* Filename of executable. */
3939 + char pr_psargs[ELF_PRARGSZ]; /* Initial part of arg list. */
3940 + };
3941 +
3942 +/* Addresses. */
3943 +typedef void *psaddr_t;
3944 +
3945 +/* Register sets. Linux has different names. */
3946 +typedef elf_gregset_t prgregset_t;
3947 +typedef elf_fpregset_t prfpregset_t;
3948 +
3949 +/* We don't have any differences between processes and threads,
3950 + therefore have only one PID type. */
3951 +typedef __pid_t lwpid_t;
3952 +
3953 +
3954 +typedef struct elf_prstatus prstatus_t;
3955 +typedef struct elf_prpsinfo prpsinfo_t;
3956 +
3957 +__END_DECLS
3958 +
3959 +#endif /* sys/procfs.h */
3960 --- /dev/null
3961 +++ b/libc/sysdeps/linux/ubicom32/sys/ucontext.h
3962 @@ -0,0 +1,104 @@
3963 +/* Copyright (C) 1998, 1999 Free Software Foundation, Inc.
3964 + This file is part of the GNU C Library.
3965 +
3966 + The GNU C Library is free software; you can redistribute it and/or
3967 + modify it under the terms of the GNU Lesser General Public
3968 + License as published by the Free Software Foundation; either
3969 + version 2.1 of the License, or (at your option) any later version.
3970 +
3971 + The GNU C Library is distributed in the hope that it will be useful,
3972 + but WITHOUT ANY WARRANTY; without even the implied warranty of
3973 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3974 + Lesser General Public License for more details.
3975 +
3976 + You should have received a copy of the GNU Lesser General Public
3977 + License along with the GNU C Library; if not, write to the Free
3978 + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
3979 + 02111-1307 USA. */
3980 +
3981 +#ifndef _SYS_UCONTEXT_H
3982 +#define _SYS_UCONTEXT_H 1
3983 +
3984 +#include <features.h>
3985 +#include <signal.h>
3986 +/*
3987 + * Location of the users' stored registers relative to R0.
3988 + * Usage is as an index into a gregset_t array or as u.u_ar0[XX].
3989 + */
3990 +#define REG_PSR (0)
3991 +#define REG_PC (1)
3992 +#define REG_SPARE (2)
3993 +#define REG_WVALID (3)
3994 +#define REG_G1 (4)
3995 +#define REG_G2 (5)
3996 +#define REG_G3 (6)
3997 +#define REG_G4 (7)
3998 +#define REG_G5 (8)
3999 +#define REG_G6 (9)
4000 +#define REG_G7 (10)
4001 +#define REG_O0 (11)
4002 +#define REG_O1 (12)
4003 +#define REG_O2 (13)
4004 +#define REG_O3 (14)
4005 +#define REG_O4 (15)
4006 +#define REG_O5 (16)
4007 +#define REG_O6 (17)
4008 +#define REG_O7 (18)
4009 +#define REG_GLOBALS (19)
4010 +
4011 +/*
4012 + * A gregset_t is defined as an array type for compatibility with the reference
4013 + * source. This is important due to differences in the way the C language
4014 + * treats arrays and structures as parameters.
4015 + *
4016 + * Note that NGREG is really (sizeof (struct regs) / sizeof (greg_t)),
4017 + * but that the ABI defines it absolutely to be 21 (resp. 19).
4018 + */
4019 +
4020 +#define NGREG 20
4021 +typedef int greg_t;
4022 +
4023 +typedef greg_t gregset_t[NGREG];
4024 +
4025 +/*
4026 + * The following structures define how a register window can appear on the
4027 + * stack. This structure is available (when required) through the `gwins'
4028 + * field of an mcontext (nested within ucontext). NIOS_MAXWINDOW is the
4029 + * maximum number of outstanding register windows defined in the NIOS
4030 + * architecture (*not* implementation).
4031 + */
4032 +#define NIOS_MAXREGWINDOW 31 /* max windows in NIOS arch. */
4033 +struct rwindow
4034 + {
4035 + greg_t rw_local[8]; /* locals */
4036 + greg_t rw_in[8]; /* ins */
4037 + };
4038 +
4039 +#define rw_fp rw_in[6] /* frame pointer */
4040 +#define rw_rtn rw_in[7] /* return address */
4041 +
4042 +typedef struct gwindows
4043 + {
4044 + int wbcnt;
4045 + int *spbuf[NIOS_MAXREGWINDOW];
4046 + struct rwindow wbuf[NIOS_MAXREGWINDOW];
4047 + } gwindows_t;
4048 +
4049 +typedef struct
4050 + {
4051 + gregset_t gregs; /* general register set */
4052 + gwindows_t *gwins; /* POSSIBLE pointer to register windows */
4053 + } mcontext_t;
4054 +
4055 +
4056 +/* Userlevel context. */
4057 +typedef struct ucontext
4058 + {
4059 + unsigned long uc_flags;
4060 + struct ucontext *uc_link;
4061 + __sigset_t uc_sigmask;
4062 + stack_t uc_stack;
4063 + mcontext_t uc_mcontext;
4064 + } ucontext_t;
4065 +
4066 +#endif /* sys/ucontext.h */
4067 --- /dev/null
4068 +++ b/libc/sysdeps/linux/ubicom32/syscall.c
4069 @@ -0,0 +1,32 @@
4070 +/* vi: set sw=4 ts=4: */
4071 +/* syscall for ubicom32/uClibc
4072 + *
4073 + * Copyright (C) 2008 by Ubicom Inc.
4074 + * Copyright (C) 2002 by Erik Andersen <andersen@uclibc.org>
4075 + *
4076 + * This program is free software; you can redistribute it and/or modify it
4077 + * under the terms of the GNU Library General Public License as published by
4078 + * the Free Software Foundation; either version 2 of the License, or (at your
4079 + * option) any later version.
4080 + *
4081 + * This program is distributed in the hope that it will be useful, but WITHOUT
4082 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4083 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License
4084 + * for more details.
4085 + *
4086 + * You should have received a copy of the GNU Library General Public License
4087 + * along with this program; if not, write to the Free Software Foundation,
4088 + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
4089 + */
4090 +
4091 +#include <features.h>
4092 +#include <errno.h>
4093 +#include <sys/types.h>
4094 +#include <sys/syscall.h>
4095 +
4096 +extern long syscall(long sysnum, long a, long b, long c, long d, long e, long f);
4097 +long syscall(long sysnum, long a, long b, long c, long d, long e, long f)
4098 +{
4099 + int __NR_syscall_number = sysnum;
4100 + return (long) INLINE_SYSCALL(syscall_number, 6, a, b, c, d, e, f);
4101 +}
4102 --- /dev/null
4103 +++ b/libc/sysdeps/linux/ubicom32/vfork.S
4104 @@ -0,0 +1,35 @@
4105 +#include <sys/syscall.h>
4106 +
4107 + .text
4108 + .type vfork,@function
4109 + .global vfork
4110 +vfork:
4111 + move.4 -4(sp)++, a5 ; Save return address on the stack.
4112 + movei d8, #__NR_vfork
4113 + moveai a3, #%hi(0x40400000)
4114 + calli a5, 0x10(a3)
4115 +
4116 + /*
4117 + * You get here only if the syscall bombed. If things had worked out the
4118 + * parent and child would have both returned to the instruction after
4119 + * the vfork call.
4120 + */
4121 + move.4 a5, (sp)4++ ; Pop the return address off the stack.
4122 + movei d1, #-125
4123 + sub.4 #0, d0, d1
4124 + jmplt.t 1f
4125 +
4126 + ;; We have an error.
4127 + sub.4 d0, #0, d0 ; d0 = -res. Call __set_errno with that.
4128 +#if defined(__UBICOM32_FDPIC__)
4129 + call a3, __syscall_error
4130 +#else
4131 + moveai a3, #%hi(__syscall_error)
4132 + calli a3, %lo(__syscall_error)(a3) ; __syscall_error will return -1 and not come back here.
4133 +#endif
4134 +1:
4135 + calli a5, 0(a5)
4136 + .size vfork, . - vfork
4137 + .global __GI_vfork
4138 + .hidden __GI_vfork
4139 + .set __GI_vfork,vfork
4140 --- a/libpthread/linuxthreads.old/pthread.c
4141 +++ b/libpthread/linuxthreads.old/pthread.c
4142 @@ -391,6 +391,10 @@ void __pthread_initialize_minimal(void)
4143 #endif
4144
4145 __libc_multiple_threads_ptr = __libc_pthread_init (ptr_pthread_functions);
4146 +#ifndef __ARCH_USE_MMU__
4147 + __pthread_initial_thread_tos =
4148 + (char *)(((long)CURRENT_STACK_FRAME + getpagesize()) & ~(getpagesize() - 1));
4149 +#endif /* __ARCH_USE_MMU__ */
4150 }
4151
4152
4153 @@ -467,7 +471,8 @@ static void pthread_initialize(void)
4154 * for a few more details.
4155 */
4156 __pthread_initial_thread_mid = CURRENT_STACK_FRAME;
4157 - __pthread_initial_thread_tos = (char *) -1;
4158 + if (__pthread_initial_thread_tos == NULL)
4159 + __pthread_initial_thread_tos = (char *) -1;
4160 __pthread_initial_thread_bos = (char *) 1; /* set it non-zero so we know we have been here */
4161 PDEBUG("initial thread stack bounds: bos=%p, tos=%p\n",
4162 __pthread_initial_thread_bos, __pthread_initial_thread_tos);
4163 --- /dev/null
4164 +++ b/libpthread/linuxthreads.old/sysdeps/ubicom32/pt-machine.h
4165 @@ -0,0 +1,68 @@
4166 +/* Machine-dependent pthreads configuration and inline functions.
4167 +
4168 + Copyright (C) 1996, 1997, 1998, 2000, 2002, 2003, 2004
4169 + Free Software Foundation, Inc.
4170 + This file is part of the GNU C Library.
4171 + Contributed by Ralf Baechle <ralf@gnu.org>.
4172 + Based on the Alpha version by Richard Henderson <rth@tamu.edu>.
4173 +
4174 + The GNU C Library is free software; you can redistribute it and/or
4175 + modify it under the terms of the GNU Lesser General Public License as
4176 + published by the Free Software Foundation; either version 2.1 of the
4177 + License, or (at your option) any later version.
4178 +
4179 + The GNU C Library is distributed in the hope that it will be useful,
4180 + but WITHOUT ANY WARRANTY; without even the implied warranty of
4181 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4182 + Lesser General Public License for more details.
4183 +
4184 + You should have received a copy of the GNU Lesser General Public
4185 + License along with the GNU C Library; see the file COPYING.LIB. If
4186 + not, write to the Free Software Foundation, Inc.,
4187 + 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
4188 +
4189 +#ifndef _PT_MACHINE_H
4190 +#define _PT_MACHINE_H 1
4191 +
4192 +#include <features.h>
4193 +
4194 +/*
4195 + * XXX try to make this inline
4196 + */
4197 +extern long int testandset (int *spinlock);
4198 +
4199 +#ifndef PT_EI
4200 +#define PT_EI
4201 +#else
4202 +/* Spinlock implementation; required. */
4203 +
4204 +/*
4205 + * testandset() is the basis for the pthread spin lock.
4206 + *
4207 + * This implementation only requires that we 'set' the state of *spinlock. As
4208 + * bset is allows us to atomically 'testandset' a single bit define our 'set' is
4209 + * such that we will set bit 0 (ignoring all other bits, which should also be
4210 + * zero).
4211 + * Return value of 1 implies that the bit was already set and is still
4212 + * set.
4213 + * Return value of 0 implies that the bit was not previously set but it
4214 + * now is.
4215 + */
4216 +long int
4217 +testandset (int *spinlock)
4218 +{
4219 + int ret;
4220 + __asm__ volatile (
4221 + " move.4 %0, #0 \n\t" /* Assume that the bit is not currently set */
4222 + " bset %1, %1, #0 \n\t" /* Attempt to 'set' bit 0 */
4223 + " jmpeq.t 1f \n\t"
4224 + " move.4 %0, #1 \n\t" /* Bit was already set, so return 1 */
4225 + " 1: \n\t"
4226 + : "=r"(ret), "+U4"(*spinlock)
4227 + :
4228 + : "memory", "cc"
4229 + );
4230 + return ret;
4231 +}
4232 +#endif
4233 +#endif /* pt-machine.h */
4234 --- /dev/null
4235 +++ b/libpthread/linuxthreads.old/sysdeps/ubicom32/tls.h
4236 @@ -0,0 +1,26 @@
4237 +/* Definitions for thread-local data handling. linuxthreads/MIPS version.
4238 + Copyright (C) 2005 Free Software Foundation, Inc.
4239 + This file is part of the GNU C Library.
4240 +
4241 + The GNU C Library is free software; you can redistribute it and/or
4242 + modify it under the terms of the GNU Lesser General Public
4243 + License as published by the Free Software Foundation; either
4244 + version 2.1 of the License, or (at your option) any later version.
4245 +
4246 + The GNU C Library is distributed in the hope that it will be useful,
4247 + but WITHOUT ANY WARRANTY; without even the implied warranty of
4248 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4249 + Lesser General Public License for more details.
4250 +
4251 + You should have received a copy of the GNU Lesser General Public
4252 + License along with the GNU C Library; if not, write to the Free
4253 + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
4254 + 02111-1307 USA. */
4255 +
4256 +#ifndef _TLS_H
4257 +#define _TLS_H
4258 +#ifdef HAVE_TLS_SUPPORT
4259 +#warning no tls support
4260 +#undef USE_TLS
4261 +#endif
4262 +#endif /* tls.h */
4263 --- /dev/null
4264 +++ b/libc/sysdeps/linux/ubicom32/sys/user.h
4265 @@ -0,0 +1,40 @@
4266 +/* Copyright (C) 1998 Free Software Foundation, Inc.
4267 + This file is part of the GNU C Library.
4268 +
4269 + The GNU C Library is free software; you can redistribute it and/or
4270 + modify it under the terms of the GNU Lesser General Public
4271 + License as published by the Free Software Foundation; either
4272 + version 2.1 of the License, or (at your option) any later version.
4273 +
4274 + The GNU C Library is distributed in the hope that it will be useful,
4275 + but WITHOUT ANY WARRANTY; without even the implied warranty of
4276 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4277 + Lesser General Public License for more details.
4278 +
4279 + You should have received a copy of the GNU Lesser General Public
4280 + License along with the GNU C Library; if not, write to the Free
4281 + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
4282 + 02111-1307 USA. */
4283 +
4284 +#ifndef _SYS_USER_H
4285 +#define _SYS_USER_H 1
4286 +
4287 +#include <features.h>
4288 +
4289 +#include <asm/ptrace.h>
4290 +
4291 +struct user {
4292 + struct pt_regs regs; /* entire machine state */
4293 + size_t u_tsize; /* text size (pages) */
4294 + size_t u_dsize; /* data size (pages) */
4295 + size_t u_ssize; /* stack size (pages) */
4296 + unsigned long start_code; /* text starting address */
4297 + unsigned long start_data; /* data starting address */
4298 + unsigned long start_stack; /* stack starting address */
4299 + long int signal; /* signal causing core dump */
4300 + struct regs * u_ar0; /* help gdb find registers */
4301 + unsigned long magic; /* identifies a core file */
4302 + char u_comm[32]; /* user command name */
4303 +};
4304 +
4305 +#endif /* _SYS_USER_H */
This page took 0.222747 seconds and 5 git commands to generate.