[PATCH] added klibc version 0.82 (cvs tree) to the udev tree.

Not hooked up to the build yet.
This commit is contained in:
greg@kroah.com 2003-10-22 18:37:40 -07:00 committed by Greg KH
parent 6c0eae77a1
commit a41a0e28c2
364 changed files with 18233 additions and 2 deletions

41
klibc/MCONFIG Normal file
View File

@ -0,0 +1,41 @@
# -*- makefile -*-
#
# Makefile configuration, without explicit rules
#
ARCH = $(shell uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ -e s/arm.*/arm/ -e s/sa110/arm/)
CROSS =
CC = $(CROSS)gcc
LD = $(CROSS)ld
KLIBSRC = $(SRCROOT)/klibc
REQFLAGS = $(ARCHREQFLAGS) -nostdinc -iwithprefix include -I$(KLIBSRC) \
-I$(KLIBSRC)/arch/$(ARCH)/include \
-I$(KLIBSRC)/include/bits$(BITSIZE) \
-D__KLIBC__ -DBITSIZE=$(BITSIZE) -I$(KLIBSRC)/include \
-I$(SRCROOT)/linux/include
LDFLAGS =
AR = $(CROSS)ar
RANLIB = $(CROSS)ranlib
NM = $(CROSS)nm
PERL = perl
STRIP = $(CROSS)strip --strip-all -R .comment -R .note
HOST_CC = gcc
HOST_LDFLAGS = -s
HOST_LIBS =
CRT0 = $(KLIBSRC)/crt0.o
KLIBC = $(KLIBSRC)/libc.a
LIBGCC = $(shell $(CC) --print-libgcc)
#
# This indicates the location of the final version of the shared library.
# THIS MUST BE AN ABSOLUTE PATH WITH NO FINAL SLASH.
# Leave this empty to make it the root.
#
SHLIBDIR = /lib
#
# Include arch-specific rule fragments
#
include $(KLIBSRC)/arch/$(ARCH)/MCONFIG

View File

@ -1,3 +1,6 @@
SUBDIRS = klibc
clean:
@echo "all clean"
all:
%:
@set -e; for d in $(SUBDIRS); do $(MAKE) -C $$d $@; done

16
klibc/README Normal file
View File

@ -0,0 +1,16 @@
Please see klibc/README for how to set up the tree before building.
klibc is archived at:
ftp://ftp.zytor.com/pub/linux/libs/klibc/
There is a mailing list for klibc and early-userspace issues at:
http://www.zytor.com/mailman/listinfo/klibc/
There is also a cvsweb repository at:
http://www.zytor.com/cvsweb.cgi/klibc/
There is no direct public CVS access yet, however.

51
klibc/klibc/CAVEATS Normal file
View File

@ -0,0 +1,51 @@
-------------------------------------------------
Please note the following caveats to using klibc:
-------------------------------------------------
optimization:
-------------
Compiling with -O0 is not supported. It may or may not work; please
use -O1 if you want to do maximize debuggability.
Compiling with -O0 is more likely to work on gcc 3.
setjmp()/longjmp():
-------------------
setjmp() and longjmp() *do not* save signal state. sigsetjmp() and
siglongjmp() *do* save the signal mask -- regardless of the value of
the extra argument.
The standards actually state that if you pass longjmp() a final value
of zero the library should change that to a 1! Presumably the reason
is so people who write broken code can get away with writing
longjmp(buf); or something equally bad. If you pass longjmp() a final
value of 0 you get what you deserve -- setjmp() will happily return 0.
stdio:
------
Only a small subset of the stdio functions are implemented. Those
that are implemented do not buffer, although they *do* trap EINTR or
short read/writes and iterate.
_fread() and _fwrite(), which take only one size argument (like
read/write), but do handle EINTR/short return are also available.
namespaces:
-----------
klibc frequently includes headers in other headers in a way that
exposes more symbols than POSIX says they should. "Live with it."
theading:
---------
klibc is not thread-safe. Consequently, clone() or any of the
pthreads functions are not included.

73
klibc/klibc/LICENSE Normal file
View File

@ -0,0 +1,73 @@
This license applies to all files in directory and its subdirectories,
unless otherwise noted in individual files.
Some files are derived from files derived from the include/ directory
of the Linux kernel, and are licensed under the terms of the GNU
General Public License, version 2, as released by the Free Software
Foundation, Inc.; incorporated herein by reference.
-----
Some files are derived from files copyrighted by the Regents of The
University of California, and are available under the following
license:
Note: The advertising clause in the license appearing on BSD Unix
files was officially rescinded by the Director of the Office of
Technology Licensing of the University of California on July 22
1999. He states that clause 3 is "hereby deleted in its entirety."
* Copyright (c)
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
-----
For all remaining files, the following license applies:
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* Any copyright notice(s) and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

49
klibc/klibc/MCONFIG Normal file
View File

@ -0,0 +1,49 @@
# -*- makefile -*-
#
# Makefile configuration, without explicit rules
#
SRCROOT = ..
include ../MCONFIG
WARNFLAGS = -W -Wall -Wpointer-arith -Wwrite-strings -Wstrict-prototypes -Winline
CFLAGS = -Wp,-MD,$(dir $*).$(notdir $*).d $(OPTFLAGS) $(REQFLAGS) $(WARNFLAGS)
SOFLAGS = -fPIC
.SUFFIXES: .c .o .a .so .lo .i .S .s .ls .ss .lss
.c.o:
$(CC) $(CFLAGS) -c -o $@ $<
.c.i:
$(CC) $(CFLAGS) -E -o $@ $<
.c.s:
$(CC) $(CFLAGS) -S -o $@ $<
.S.o:
$(CC) $(CFLAGS) -D__ASSEMBLY__ -c -o $@ $<
.S.s:
$(CC) $(CFLAGS) -D__ASSEMBLY__ -E -o $@ $<
.S.lo:
$(CC) $(CFLAGS) $(SOFLAGS) -D__ASSEMBLY__ -c -o $@ $<
.S.ls:
$(CC) $(CFLAGS) $(SOFLAGS) -D__ASSEMBLY__ -E -o $@ $<
.s.o:
$(CC) $(CFLAGS) -x assembler -c -o $@ $<
.ls.lo:
$(CC) $(CFLAGS) $(SOFLAGS) -x assembler -c -o $@ $<
.c.lo:
$(CC) $(CFLAGS) $(SOFLAGS) -c -o $@ $<
.c.ls:
$(CC) $(CFLAGS) $(SOFLAGS) -S -o $@ $<

135
klibc/klibc/Makefile Normal file
View File

@ -0,0 +1,135 @@
#
# Makefile
#
# Main makefile
#
# Include configuration rules
include MCONFIG
TESTS = $(patsubst %.c,%,$(wildcard tests/*.c)) \
$(patsubst %.c,%.shared,$(wildcard tests/*.c))
LIBOBJS = vsnprintf.o snprintf.o vsprintf.o sprintf.o \
vsscanf.o sscanf.o ctypes.o \
strntoumax.o strntoimax.o \
atoi.o atol.o atoll.o \
strtol.o strtoll.o strtoul.o strtoull.o \
strtoimax.o strtoumax.o \
globals.o exitc.o atexit.o onexit.o \
execl.o execle.o execv.o execvpe.o execvp.o execlp.o execlpe.o \
fork.o wait.o wait3.o waitpid.o system.o setpgrp.o \
printf.o vprintf.o fprintf.o vfprintf.o perror.o \
fopen.o fread.o fread2.o fgetc.o fgets.o \
fwrite.o fwrite2.o fputc.o fputs.o puts.o \
sleep.o usleep.o raise.o abort.o assert.o alarm.o pause.o \
__signal.o signal.o bsd_signal.o siglist.o siglongjmp.o \
sigaction.o sigpending.o sigprocmask.o sigsuspend.o \
brk.o sbrk.o malloc.o realloc.o calloc.o mmap.o \
memcpy.o memcmp.o memset.o memccpy.o memmem.o memswap.o \
memmove.o \
strcat.o strchr.o strcmp.o strcpy.o strdup.o strlen.o \
strncat.o strstr.o strncmp.o strncpy.o strrchr.o strspn.o \
strsep.o strtok.o \
gethostname.o getdomainname.o getcwd.o \
seteuid.o setegid.o setresuid.o setresgid.o \
getenv.o setenv.o unsetenv.o getopt.o readdir.o \
syslog.o closelog.o pty.o isatty.o reboot.o \
time.o utime.o fdatasync.o llseek.o select.o nice.o getpriority.o \
qsort.o lrand48.o srand48.o seed48.o \
inet/inet_ntoa.o inet/inet_aton.o inet/inet_addr.o \
inet/inet_ntop.o inet/inet_pton.o inet/bindresvport.o \
send.o recv.o
SOLIB = libc.so
SOHASH = klibc.so
CRT0 = crt0.o
LIB = libc.a
#all: tests $(CRT0) $(LIB) $(SOLIB) klibc.so
all: $(CRT0) $(LIB) $(SOLIB) klibc.so
# Add any architecture-specific rules
include arch/$(ARCH)/Makefile.inc
tests: $(TESTS)
tests/%.o : tests/%.c
$(CC) $(CFLAGS) -c -o $@ $<
tests/% : tests/%.o $(LIB) $(CRT0)
$(LD) $(LDFLAGS) -o $@ $(CRT0) $< $(LIB) $(LIBGCC)
cp $@ $@.stripped
$(STRIP) $@.stripped
tests/%.shared : tests/%.o interp.o $(SOLIB)
$(LD) $(LDFLAGS) -o $@ -e main interp.o tests/$*.o -R $(SOLIB) $(LIBGCC)
cp $@ $@.stripped
$(STRIP) $@.stripped
$(LIB): __static_init.o $(LIBOBJS) $(ARCHOBJS) syscalls/static.obj socketcalls/static.obj
rm -f $(LIB)
$(AR) cq $(LIB) __static_init.o $(LIBOBJS) $(ARCHOBJS) syscalls/*.o socketcalls/*.o
$(RANLIB) $(LIB)
$(SOLIB): $(CRT0) __shared_init.o $(LIBOBJS) $(ARCHOBJS) syscalls/static.obj socketcalls/static.obj
$(LD) $(LDFLAGS) $(SHAREDFLAGS) -o $@ \
$(CRT0) __shared_init.o $(LIBOBJS) $(ARCHOBJS) \
syscalls/*.o socketcalls/*.o \
$(LIBGCC)
sha1hash: sha1hash.c
$(HOST_CC) $(HOST_CFLAGS) $(HOST_LDFLAGS) -o $@ $<
$(SOLIB).hash: $(SOLIB) sha1hash
$(NM) $(SOLIB) | \
egrep '^[0-9a-fA-F]+ [ADRTW] ' | sort | ./sha1hash > $@
$(SOHASH): $(SOLIB) $(SOLIB).hash
cp -f $(SOLIB) $@
$(STRIP) $@
rm -f klibc-??????????????????????.so
ln -f $@ klibc-`cat $(SOLIB).hash`.so
interp.o: interp.S $(SOLIB).hash
$(CC) $(CFLAGS) -D__ASSEMBLY__ -DLIBDIR=\"$(SHLIBDIR)\" \
-DSOHASH=\"`cat $(SOLIB).hash`\" \
-c -o $@ $<
crt0.o: arch/$(ARCH)/crt0.o
cp arch/$(ARCH)/crt0.o .
syscalls.dir: SYSCALLS syscalls.pl syscommon.h
rm -rf syscalls
mkdir syscalls
$(PERL) syscalls.pl $(ARCH) SYSCALLS
touch $@
socketcalls.dir: SOCKETCALLS socketcalls.pl socketcommon.h
rm -rf socketcalls
mkdir socketcalls
$(PERL) socketcalls.pl $(ARCH) SOCKETCALLS
touch $@
%/static.obj: %.dir
$(MAKE) objects-$(basename $(notdir $@)) DIR=$*
STATIC = $(addsuffix .o,$(basename $(wildcard $(DIR)/*.[cS])))
objects-static: $(STATIC)
touch $(DIR)/static.obj
clean: archclean
find . -type f -a \( -name \*.[isoa] -o -name \*.l[iso] \) -print0 | xargs -0rt rm -f
rm -f *.a *.so *.hash *.syms *.stripped
rm -f $(TESTS) tests/*.stripped
rm -rf syscalls syscalls.dir
rm -rf socketcalls socketcalls.dir
rm -f sha1hash
spotless: clean
find . \( -name \*~ -o -name '.*.d' \) -not -type d -print0 | \
xargs -0rt rm -f
ifneq ($(wildcard $(DIR)/.*.d),)
include $(wildcard $(DIR)/.*.d)
endif

57
klibc/klibc/README Normal file
View File

@ -0,0 +1,57 @@
This is klibc, what is intended to be a minimalistic libc subset for
use with initramfs. It is deliberately written for small size,
minimal entaglement and portability, not speed. It is definitely a
work in progress, and a lot of things are still missing.
The build procedure is not very polished yet, but it should work like
this:
a) In the source root directory (the directory above the one in which
this file is found) create a symlink called "linux" pointing to a
reasonably recent Linux kernel tree (2.4 or 2.5 should be OK.)
This tree must have the include/asm symlink set up for the
architecture you're compiling for, and include/linux/autoconf.h
must exist. The easiest way to make sure of all of these is to do
a "make config" or any of its variants on the kernel tree is
question, followed by a "make dep".
b) If you're cross-compiling, change ARCH in the main MCONFIG file to
the appropriate architecture, and set CROSS to your toolchain
prefix.
IMPORTANT: if you're on a 64-bit machine with a 32-bit userland
(ia64, mips64, ppc64 sparc64, s390x or x86_64), and you want to
build the 32-bit version: you need to set ARCH to the 32-bit
architecture as well as set up the linux/include/asm symlink to
point to the 32-bit architecture. Building the 32-bit architecture
usually (but not always) produces smaller binaries, and is likely
to be better tested.
If you are on ARM, and want to build a thumb version of the library
(this is supported), change OPTFLAGS in arch/arm/MCONFIG to build
thumb code.
The following is the last known status of various architectures:
Known to work: alpha arm i386 s390 s390x sparc sparc64 x86_64*
Works static, not shared: mips* arm-thumb sh*
Need crt0.S updates: ppc
Missing setjmp: ppc64
Need porting work: cris ia64 m68k mips64 parisc
x86_64: requires a kernel header patch (to be created)
mips, sh: linker problem; might work with fixed linker
Shared library support for sparc/sparc64 requires binutils 2.13.90.0.4.
Note that even the "known to work" ones likely have bugs. Please
report them if you run into them.
c) Type "make" and pray...
d) Try the test programs in the tests/ directory. They should run...
Contact me at <hpa@zytor.com> for more info.
-hpa

21
klibc/klibc/SOCKETCALLS Normal file
View File

@ -0,0 +1,21 @@
# -*- fundamental -*-
#
# These are calls that are invoked via the socketcall mechanism
#
int socket(int, int, int)
int bind(int, struct sockaddr *, int)
int connect(int, struct sockaddr *, socklen_t)
int listen(int, int)
int accept(int, struct sockaddr *, socklen_t *)
int getsockname(int, struct sockaddr *, socklen_t *)
int getpeername(int, struct sockaddr *, socklen_t *)
int socketpair(int, int, int, int *)
# int send(int, const void *, size_t, unsigned int)
int sendto(int, const void *, size_t, int, const struct sockaddr *, socklen_t)
# int recv(int, void *, size_t, unsigned int)
int recvfrom(int, void *, size_t, unsigned int, struct sockaddr *, socklen_t *)
int shutdown(int, int)
int setsockopt(int, int, int, const void *, socklen_t)
int getsockopt(int, int, int, void *, socklen_t *)
int sendmsg(int, const struct msghdr *, unsigned int)
int recvmsg(int, struct msghdr *, unsigned int)

146
klibc/klibc/SYSCALLS Normal file
View File

@ -0,0 +1,146 @@
# -*- fundamental -*-
#
# This is a list of system calls we invoke "directly". These
# are generated into syscall stubs in their own C files, so the
# linker can do its job properly.
#
# The full description of a line is:
# [<[!]arch,...>] type sysname[@systype][::funcname](args)
#
#
# Process-related syscalls
#
<!mips,mips64,sparc> pid_t vfork()
<sparc> pid_t vfork@forkish()
<!alpha> pid_t getpid()
<alpha> pid_t getxpid@dual0::getpid()
int setpgid(pid_t, pid_t)
pid_t getpgid(pid_t)
<!alpha> pid_t getppid()
<alpha> pid_t getxpid@dual1::getppid()
<!ia64> pid_t getpgrp()
pid_t setsid()
pid_t getsid(pid_t)
pid_t wait4(pid_t, int *, int, struct rusage *)
int execve(const char *, char * const *, char * const *)
int setpriority(int, int, int)
int sched_setscheduler(pid_t, int, const struct sched_param *)
int sched_yield()
#
# User and group IDs
#
int setuid(uid_t)
int setgid(gid_t)
<!alpha> uid_t getuid()
<alpha> uid_t getxuid@dual0::getuid()
<!alpha> gid_t getgid()
<alpha> gid_t getxgid@dual0::getgid()
<!alpha> uid_t geteuid()
<alpha> uid_t getxuid@dual1::geteuid()
<!alpha> gid_t getegid()
<alpha> uid_t getxgid@dual1::getegid()
int getgroups(int, gid_t *)
int setgroups(size_t, const gid_t *)
int setreuid(uid_t, uid_t)
int setregid(gid_t, gid_t)
int setfsuid(uid_t)
int setfsgid(gid_t)
#
# Filesystem-related system calls
#
int mount(const char *, const char *, const char *, unsigned long, const void *)
<!alpha,ia64> int umount2(const char *, int)
<alpha,ia64> int umount::umount2(const char *, int)
<!m68k> int pivot_root(const char *, const char *)
int sync()
int statfs(const char *, struct statfs *)
int fstatfs(int, struct statfs *)
int swapon(const char *, int)
int swapoff(const char *)
#
# Inode-related system calls
#
int access(const char *, int)
int link(const char *, const char *)
int unlink(const char *)
int chdir(const char *)
int rename(const char *, const char *)
int mknod(const char *, mode_t, dev_t)
int chmod(const char *, mode_t)
int mkdir(const char *, mode_t)
int rmdir(const char *)
<!alpha,mips,mips64> int pipe(int *)
mode_t umask(mode_t)
int chroot(const char *)
int symlink(const char *, const char *)
int readlink(const char *, char *, size_t)
int stat(const char *, struct stat *)
int lstat(const char *, struct stat *)
int fstat(int, struct stat *)
int getdents(unsigned int, struct dirent *, unsigned int)
int chown(const char *, uid_t, gid_t)
int fchown(int, uid_t, gid_t)
int lchown(const char *, uid_t, gid_t)
#
# I/O operations
#
ssize_t read(int, void *, size_t)
ssize_t write(int, const void *, size_t)
int open(const char *, int, mode_t)
int close(int)
off_t lseek(int, off_t, int)
int dup(int)
int dup2(int, int)
int fcntl(int, int, long)
int ioctl(int, int, void *)
int flock(int, int)
int poll(struct pollfd *, nfds_t, long)
int fsync(int)
int readv(int, const struct iovec *, int)
int writev(int, const struct iovec *, int)
#
# Signal operations
#
int kill(pid_t, int)
int rt_sigaction(int, const struct sigaction *, struct sigaction *, size_t)
int rt_sigsuspend(const sigset_t *, size_t)
int rt_sigpending(sigset_t *, size_t)
int rt_sigprocmask(int, const sigset_t *, sigset_t *, size_t)
int getitimer(int, struct itimerval *)
int setitimer(int, const struct itimerval *, struct itimerval *)
#
# Time-related system calls
#
clock_t times(struct tms *)
int gettimeofday(struct timeval *, struct timezone *)
int settimeofday(const struct timeval *, const struct timezone *)
int nanosleep(const struct timespec *, struct timespec *)
#
# Memory
#
void * brk::__brk(void *)
int munmap(void *, size_t)
void * mremap(void *, size_t, size_t, unsigned long)
int msync(const void *, size_t, int)
int mprotect(const void *, size_t, int)
#
# System stuff
#
int uname(struct utsname *)
int setdomainname(const char *, size_t)
int sethostname(const char *, size_t)
int init_module(const char *, struct module *)
void * create_module(const char *, size_t)
int delete_module(const char *)
int query_module(const char *, int, void *, size_t, size_t)
int reboot::__reboot(int, int, int, void *)
int syslog::klogctl(int, char *, int)

View File

@ -0,0 +1,56 @@
/*
* __shared_init.c
*
* This function takes the raw data block set up by the ELF loader
* in the kernel and parses it. It is invoked by crt0.S which makes
* any necessary adjustments and passes calls this function using
* the standard C calling convention.
*
* The arguments are:
* uintptr_t *elfdata -- The ELF loader data block; usually from the stack.
* Basically a pointer to argc.
* void (*onexit)(void) -- Function to install into onexit
*/
#include <stddef.h>
#include <stdlib.h>
#include <stdint.h>
#include <klibc/compiler.h>
#include <elf.h>
char **environ;
__noreturn __libc_init(uintptr_t *elfdata, void (*onexit)(void))
{
int argc;
char **argv, **envp, **envend;
struct auxentry {
uintptr_t type;
uintptr_t v;
} *auxentry;
typedef int (*main_t)(int, char **, char **);
main_t main_ptr = NULL;
(void)onexit; /* For now, we ignore this... */
argc = (int)*elfdata++;
argv = (char **)elfdata;
envp = argv+(argc+1);
/* The auxillary entry vector is after all the environment vars */
for ( envend = envp ; *envend ; envend++ );
auxentry = (struct auxentry *)(envend+1);
while ( auxentry->type ) {
if ( auxentry->type == AT_ENTRY ) {
main_ptr = (main_t)(auxentry->v);
break;
}
auxentry++;
}
environ = envp;
exit(main_ptr(argc, argv, envp));
}

22
klibc/klibc/__signal.c Normal file
View File

@ -0,0 +1,22 @@
/*
* __signal.c
*/
#include <signal.h>
__sighandler_t __signal(int signum, __sighandler_t handler, int flags)
{
struct sigaction sa;
sa.sa_handler = handler;
sa.sa_flags = flags;
sigemptyset(&sa.sa_mask);
if ( sigaction(signum, &sa, &sa) ) {
return (__sighandler_t)SIG_ERR;
} else {
return (__sighandler_t)sa.sa_handler;
}
}

View File

@ -0,0 +1,40 @@
/*
* __static_init.c
*
* This function takes the raw data block set up by the ELF loader
* in the kernel and parses it. It is invoked by crt0.S which makes
* any necessary adjustments and passes calls this function using
* the standard C calling convention.
*
* The arguments are:
* uintptr_t *elfdata -- The ELF loader data block; usually from the stack.
* Basically a pointer to argc.
* void (*onexit)(void) -- Function to install into onexit
*/
#include <stddef.h>
#include <stdlib.h>
#include <stdint.h>
#include <klibc/compiler.h>
#include <elf.h>
char **environ;
extern int main(int, char **, char **);
__noreturn __libc_init(uintptr_t *elfdata, void (*onexit)(void))
{
int argc;
char **argv, **envp;
(void)onexit; /* For now, we ignore this... */
argc = (int)*elfdata++;
argv = (char **)elfdata;
envp = argv+(argc+1);
environ = envp;
exit(main(argc, argv, envp));
}

19
klibc/klibc/abort.c Normal file
View File

@ -0,0 +1,19 @@
/*
* abort.c
*/
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
void abort(void)
{
sigset_t set;
sigemptyset(&set);
sigaddset(&set, SIGABRT);
sigprocmask(SIG_UNBLOCK, &set, NULL);
raise(SIGABRT);
_exit(255); /* raise() should have killed us */
}

29
klibc/klibc/alarm.c Normal file
View File

@ -0,0 +1,29 @@
/*
* alarm.c
*/
#include <sys/time.h>
#include <sys/syscall.h>
#ifdef __NR_alarm
_syscall1(unsigned int,alarm,unsigned int,seconds);
#else
/* Emulate alarm() via setitimer() */
unsigned int alarm(unsigned int seconds)
{
struct itimerval iv;
iv.it_interval.tv_sec = iv.it_interval.tv_usec = 0;
iv.it_value.tv_sec = seconds;
iv.it_value.tv_usec = 0;
setitimer(ITIMER_REAL, &iv, &iv);
return iv.it_value.tv_sec + (iv.it_value.tv_usec ? 1 : 0);
}
#endif

67
klibc/klibc/arch/README Normal file
View File

@ -0,0 +1,67 @@
To port klibc to a new architecture, you need:
a) A directory structure
Each archtecture has an arch/ directory, which should include an
MCONFIG and a Makefile.inc file.
b) Startup code (arch/*/crt0.S)
The crt0.S assembly routine typically corresponds to the following
pseudo-C code. In addition, each architecture needs any support
routines that gcc-generated code expects to find in the system library
-- Alpha, for example, needs divide subroutines.
The "getenvtest" test program is a very good test for proper crt0.S
functionality.
extern __noreturn __libc_init(void *, void *);
__noreturn _start(void)
{
void *elf_data = get_elf_data_address(); /* Usually the stack address */
void *atexit_ptr = get_atexit_ptr(); /* Usually in a register */
/* Some architectures need this for debugging to work */
setup_null_stack_frame_if_necessary();
__libc_init(elf_data, atexit_ptr);
}
c) A setenv implementation (arch/*/setjmp.S, arch/*/include/klibc/archsetjmp.h)
On most (but not all!) architectures, this entails creating a setjmp
buffer big enough to hold all callee-saved registers, plus the stack
pointer and the return address. In setjmp.S you have:
* A "setjmp" function that writes out the callee-saved registers, the
stack pointer and the return address to the buffer pointed to by the
first argument, and then returns zero normally.
On some architectures you need to take some kind of action to make
sure the contents of the stack is actually manifest in memory and
not cached in the CPU. In some cases (e.g. on SPARC) this will
automatically spill the registers onto the stack; then they don't
need to be spilled into the jmp_buf.
* A "longjmp" function that read back these same registers from the
jmp_buf pointed to by the first argument, and returns the second
argument *to the address specified in the jmp_buf*.
On some architectures you need to take some kind of action to flush
any cached stack data or return stack.
d) Any support functions needed by gcc, *unless* they are in libgcc
*and* libgcc is usable for klibc on your particular platform. If
libgcc isn't usable for klibc (on MIPS, for example, libgcc is
compiled in a way that is not compatible with klibc) there are
reasonably good clones of most of the libgcc functions in the libgcc
directory. To use them, add them to ARCHOBJS in
arch/*/Makefile.inc.
e) A link location for the shared klibc. This should be specified in
SHAREDFLAGS in arch/*/MCONFIG.

View File

@ -0,0 +1,17 @@
# -*- makefile -*-
#
# arch/alpha/MCONFIG
#
# Build configuration for this architecture
#
OPTFLAGS = -Os -fomit-frame-pointer
BITSIZE = 64
# Extra linkflags when building the shared version of the library
# This address needs to be reachable using normal inter-module
# calls, and work on the memory models for this architecture
# 7 GB - normal binaries start at 4.5 GB, and the stack is below
# the binary.
SHAREDFLAGS = -Ttext 0x1c0000200

View File

@ -0,0 +1,93 @@
# -*- makefile -*-
#
# arch/alpha/Makefile.inc
#
# Special rules for this architecture. Note that this is actually
# included from the main Makefile, and that pathnames should be
# accordingly.
#
# Special CFLAGS for the divide code
DIVCFLAGS = $(REQFLAGS) \
-O3 -fomit-frame-pointer -fcall-saved-1 -fcall-saved-2 \
-fcall-saved-3 -fcall-saved-4 -fcall-saved-5 -fcall-saved-6 \
-fcall-saved-7 -fcall-saved-8 -fcall-saved-15 -fcall-saved-16 \
-fcall-saved-17 -fcall-saved-18 -fcall-saved-19 -fcall-saved-20 \
-fcall-saved-21 -fcall-saved-22 -ffixed-23 -fcall-saved-24 \
-ffixed-25 -ffixed-27
ARCHOBJS = \
arch/$(ARCH)/__divqu.o \
arch/$(ARCH)/__remqu.o \
arch/$(ARCH)/__divq.o \
arch/$(ARCH)/__remq.o \
arch/$(ARCH)/__divlu.o \
arch/$(ARCH)/__remlu.o \
arch/$(ARCH)/__divl.o \
arch/$(ARCH)/__reml.o \
arch/$(ARCH)/pipe.o \
arch/$(ARCH)/setjmp.o
ARCHSOOBJS = $(patsubst %.o,%.lo,$(ARCHOBJS))
arch/$(ARCH)/%.s: arch/$(ARCH)/%.ss
sed -e 's/\$$0\b/$$27/g' -e 's/\$$24\b/$$99/g' \
-e 's/\$$16\b/$$24/g' -e 's/\$$17\b/$$25/g' \
-e 's/\$$26\b/$$23/g' -e 's/\$$99\b/$$16/g' < $< > $@
arch/$(ARCH)/%.ls: arch/$(ARCH)/%.lss
sed -e 's/\$$0\b/$$27/g' -e 's/\$$24\b/$$99/g' \
-e 's/\$$16\b/$$24/g' -e 's/\$$17\b/$$25/g' \
-e 's/\$$26\b/$$23/g' -e 's/\$$99\b/$$16/g' < $< > $@
arch/$(ARCH)/__divqu.ss: arch/$(ARCH)/divide.c
$(CC) $(DIVCFLAGS) -DSIGNED=0 -DREM=0 -DBITS=64 -DNAME=__divqu -S -o $@ $<
arch/$(ARCH)/__remqu.ss: arch/$(ARCH)/divide.c
$(CC) $(DIVCFLAGS) -DSIGNED=0 -DREM=1 -DBITS=64 -DNAME=__remqu -S -o $@ $<
arch/$(ARCH)/__divq.ss: arch/$(ARCH)/divide.c
$(CC) $(DIVCFLAGS) -DSIGNED=1 -DREM=0 -DBITS=64 -DNAME=__divq -S -o $@ $<
arch/$(ARCH)/__remq.ss: arch/$(ARCH)/divide.c
$(CC) $(DIVCFLAGS) -DSIGNED=1 -DREM=1 -DBITS=64 -DNAME=__remq -S -o $@ $<
arch/$(ARCH)/__divlu.ss: arch/$(ARCH)/divide.c
$(CC) $(DIVCFLAGS) -DSIGNED=0 -DREM=0 -DBITS=32 -DNAME=__divlu -S -o $@ $<
arch/$(ARCH)/__remlu.ss: arch/$(ARCH)/divide.c
$(CC) $(DIVCFLAGS) -DSIGNED=0 -DREM=1 -DBITS=32 -DNAME=__remlu -S -o $@ $<
arch/$(ARCH)/__divl.ss: arch/$(ARCH)/divide.c
$(CC) $(DIVCFLAGS) -DSIGNED=1 -DREM=0 -DBITS=32 -DNAME=__divl -S -o $@ $<
arch/$(ARCH)/__reml.ss: arch/$(ARCH)/divide.c
$(CC) $(DIVCFLAGS) -DSIGNED=1 -DREM=1 -DBITS=32 -DNAME=__reml -S -o $@ $<
arch/$(ARCH)/__divqu.lss: arch/$(ARCH)/divide.c
$(CC) $(DIVCFLAGS) -fPIC -DSIGNED=0 -DREM=0 -DBITS=64 -DNAME=__divqu -S -o $@ $<
arch/$(ARCH)/__remqu.lss: arch/$(ARCH)/divide.c
$(CC) $(DIVCFLAGS) -fPIC -DSIGNED=0 -DREM=1 -DBITS=64 -DNAME=__remqu -S -o $@ $<
arch/$(ARCH)/__divq.lss: arch/$(ARCH)/divide.c
$(CC) $(DIVCFLAGS) -fPIC -DSIGNED=1 -DREM=0 -DBITS=64 -DNAME=__divq -S -o $@ $<
arch/$(ARCH)/__remq.lss: arch/$(ARCH)/divide.c
$(CC) $(DIVCFLAGS) -fPIC -DSIGNED=1 -DREM=1 -DBITS=64 -DNAME=__remq -S -o $@ $<
arch/$(ARCH)/__divlu.lss: arch/$(ARCH)/divide.c
$(CC) $(DIVCFLAGS) -fPIC -DSIGNED=0 -DREM=0 -DBITS=32 -DNAME=__divlu -S -o $@ $<
arch/$(ARCH)/__remlu.lss: arch/$(ARCH)/divide.c
$(CC) $(DIVCFLAGS) -fPIC -DSIGNED=0 -DREM=1 -DBITS=32 -DNAME=__remlu -S -o $@ $<
arch/$(ARCH)/__divl.lss: arch/$(ARCH)/divide.c
$(CC) $(DIVCFLAGS) -fPIC -DSIGNED=1 -DREM=0 -DBITS=32 -DNAME=__divl -S -o $@ $<
arch/$(ARCH)/__reml.lss: arch/$(ARCH)/divide.c
$(CC) $(DIVCFLAGS) -fPIC -DSIGNED=1 -DREM=1 -DBITS=32 -DNAME=__reml -S -o $@ $<
archclean:
rm -f arch/$(ARCH)/*.ss arch/$(ARCH)/*.lss

View File

@ -0,0 +1,23 @@
The current Alpha chips don't provide hardware for integer
division. The C compiler expects the functions
__divqu: 64-bit unsigned long divide
__remqu: 64-bit unsigned long remainder
__divq/__remq: signed 64-bit
__divlu/__remlu: unsigned 32-bit
__divl/__reml: signed 32-bit
These are not normal C functions: instead of the normal calling
sequence, these expect their arguments in registers t10 and t11, and
return the result in t12 (aka pv). Register AT may be clobbered
(assembly temporary), anything else must be saved.
Furthermore, the return address is in t9 instead of ra.
Normal function Divide functions
--------------- ----------------
v0 ($0) t12/pv ($27)
a0 ($16) t10 ($24)
a1 ($17) t11 ($25)
ra ($26) t9 ($23)

View File

@ -0,0 +1,21 @@
#
# arch/alpha/crt0.S
#
.text
.type __start,@function
.ent __start, 0
.globl __start
__start:
.frame $30, 0, $26, 0
mov $31, $15
br $29, 1f
1: ldgp $29, 0($29)
.prologue 0
lda $16, 0($30) # ELF data structure
lda $17, 0($0) # atexit pointer
jsr $26, __libc_init
.size __start,.-__start

View File

@ -0,0 +1,57 @@
#include <stdint.h>
#include <asm/gentrap.h>
#include <asm/pal.h>
#if BITS == 64
typedef uint64_t uint;
typedef int64_t sint;
#else
typedef uint32_t uint;
typedef int32_t sint;
#endif
#ifdef SIGNED
typedef sint xint;
#else
typedef uint xint;
#endif
xint NAME (uint num, uint den)
{
uint quot = 0, qbit = 1;
int minus = 0;
xint v;
if ( den == 0 ) {
/* This is really $16, but $16 and $24 are exchanged by a script */
register unsigned long cause asm("$24") = GEN_INTDIV;
asm volatile("call_pal %0" :: "i" (PAL_gentrap), "r" (cause));
return 0; /* If trap returns... */
}
#if SIGNED
if ( (sint)(num^den) < 0 )
minus = 1;
if ( (sint)num < 0 ) num = -num;
if ( (sint)den < 0 ) den = -den;
#endif
/* Left-justify denominator and count shift */
while ( (sint)den >= 0 ) {
den <<= 1;
qbit <<= 1;
}
while ( qbit ) {
if ( den <= num ) {
num -= den;
quot += qbit;
}
den >>= 1;
qbit >>= 1;
}
v = (xint)(REM ? num : quot);
if ( minus ) v = -v;
return v;
}

View File

@ -0,0 +1,33 @@
/*
* arch/alpha/include/klibc/archsetjmp.h
*/
#ifndef _KLIBC_ARCHSETJMP_H
#define _KLIBC_ARCHSETJMP_H
struct __jmp_buf {
unsigned long __s0;
unsigned long __s1;
unsigned long __s2;
unsigned long __s3;
unsigned long __s4;
unsigned long __s5;
unsigned long __fp;
unsigned long __ra;
unsigned long __gp;
unsigned long __sp;
unsigned long __f2;
unsigned long __f3;
unsigned long __f4;
unsigned long __f5;
unsigned long __f6;
unsigned long __f7;
unsigned long __f8;
unsigned long __f9;
};
/* Must be an array so it will decay to a pointer when a function is called */
typedef struct __jmp_buf jmp_buf[1];
#endif /* _KLIBC_ARCHSETJMP_H */

View File

@ -0,0 +1,53 @@
/*
* arch/alpha/include/klibc/archsys.h
*
* Architecture-specific syscall definitions
*/
#ifndef _KLIBC_ARCHSYS_H
#define _KLIBC_ARCHSYS_H
/* Alpha has some bizarre Tru64-derived system calls which return two
different values in $0 and $20(!), respectively. The standard
macros can't deal with these; even the ones that give the right
return value have the wrong clobbers. */
#define _syscall0_dual0(type, name) \
type name(void) \
{ \
long _sc_ret, _sc_err; \
{ \
register long _sc_0 __asm__("$0"); \
register long _sc_19 __asm__("$19"); \
register long _sc_20 __asm__("$20"); \
\
_sc_0 = __NR_##name; \
__asm__("callsys" \
: "=r"(_sc_0), "=r"(_sc_19), "=r" (_sc_20) \
: "0"(_sc_0) \
: _syscall_clobbers); \
_sc_ret = _sc_0, _sc_err = _sc_19; (void)(_sc_20); \
} \
_syscall_return(type); \
}
#define _syscall0_dual1(type, name) \
type name(void) \
{ \
long _sc_ret, _sc_err; \
{ \
register long _sc_0 __asm__("$0"); \
register long _sc_19 __asm__("$19"); \
register long _sc_20 __asm__("$20"); \
\
_sc_0 = __NR_##name; \
__asm__("callsys" \
: "=r"(_sc_0), "=r"(_sc_19), "=r" (_sc_20) \
: "0"(_sc_0) \
: _syscall_clobbers); \
_sc_ret = _sc_20, _sc_err = _sc_19; (void)(_sc_0); \
} \
_syscall_return(type); \
}
#endif /* _KLIBC_ARCHSYS_H */

View File

@ -0,0 +1,44 @@
/*
* machine/asm.h
*/
#ifndef _MACHINE_ASM_H
#define _MACHINE_ASM_H
/* Standard aliases for Alpha register names */
#define v0 $0
#define t0 $1
#define t1 $2
#define t2 $3
#define t3 $4
#define t4 $5
#define t5 $6
#define t6 $7
#define t7 $8
#define s0 $9
#define s1 $10
#define s2 $11
#define s3 $12
#define s4 $13
#define s5 $14
#define fp $15
#define a0 $16
#define a1 $17
#define a2 $18
#define a3 $19
#define a4 $20
#define a5 $21
#define t8 $22
#define t9 $23
#define t10 $24
#define t11 $25
#define ra $26
#define t12 $27 /* t12 and pv are both used for $27 */
#define pv $27 /* t12 and pv are both used for $27 */
#define at $28
#define gp $29
#define sp $30
#define zero $31
#endif /* _MACHINE_ASM_H */

View File

@ -0,0 +1,28 @@
#include <unistd.h>
#include <sys/syscall.h>
/* pipe() on alpha returns both file descriptors in registers --
$0 and $20 respectively. This is unlike any other system call,
as far as I can tell. */
int pipe(int *fds)
{
register long sc_0 __asm__("$0");
register long sc_19 __asm__("$19");
register long sc_20 __asm__("$20");
sc_0 = __NR_pipe;
asm volatile("callsys" : "=r" (sc_0), "=r" (sc_19), "=r" (sc_20)
: "0" (sc_0)
: _syscall_clobbers);
if ( sc_19 ) {
errno = sc_19;
return -1;
}
fds[0] = sc_0;
fds[1] = sc_20;
return 0;
}

View File

@ -0,0 +1,77 @@
#
# setjmp.S
#
#
# The jmp_buf looks like:
#
# s0..5
# fp
# ra
# gp
# sp
#
#include <machine/asm.h>
.text
.align 3
.type setjmp,@function
.ent setjmp, 0
.globl setjmp
setjmp:
lda v0, 0(zero)
stq s0, 0(a0)
stq s1, 8(a0)
stq s2, 16(a0)
stq s3, 24(a0)
stq s4, 32(a0)
stq s5, 40(a0)
stq fp, 48(a0)
stq ra, 56(a0)
stq gp, 64(a0)
stq sp, 72(a0)
stt f2, 80(a0)
stt f3, 88(a0)
stt f4, 96(a0)
stt f5, 104(a0)
stt f6, 112(a0)
stt f7, 120(a0)
stt f8, 128(a0)
stt f9, 136(a0)
ret zero,(ra),1
.size setjmp,.-setjmp
.end setjmp
.type longjmp,@function
.ent longjmp, 0
.globl longjmp
longjmp:
mov a1, v0
ldq s0, 0(a0)
ldq s1, 8(a0)
ldq s2, 16(a0)
ldq s3, 24(a0)
ldq s4, 32(a0)
ldq s5, 40(a0)
ldq fp, 48(a0)
ldq ra, 56(a0)
ldq gp, 64(a0)
ldq sp, 72(a0)
ldt f2, 80(a0)
ldt f3, 88(a0)
ldt f4, 96(a0)
ldt f5, 104(a0)
ldt f6, 112(a0)
ldt f7, 120(a0)
ldt f8, 128(a0)
ldt f9, 136(a0)
/* We're bound to get a mispredict here, but at least give us
a chance to get the return stack back in sync... */
ret zero,(ra),1
.size longjmp,.-longjmp
.end longjmp

View File

@ -0,0 +1,26 @@
# -*- makefile -*-
#
# arch/arm/MCONFIG
#
# Special rules for this architecture. Note that this is actually
# included from the main Makefile, and that pathnames should be
# accordingly.
#
THUMB = n
CPU_ARCH := armv4
CPU_TUNE := strongarm
OPTFLAGS = -Os -fomit-frame-pointer -march=$(CPU_ARCH) -mtune=$(CPU_TUNE)
BITSIZE = 32
ifeq ($(THUMB),y)
CPU_ARCH := $(CPU_ARCH)t
OPTFLAGS += -mthumb
LDFLAGS += --thumb-entry _start
endif
# Extra linkflags when building the shared version of the library
# This address needs to be reachable using normal inter-module
# calls, and work on the memory models for this architecture
SHAREDFLAGS = -Ttext 0x01000200

View File

@ -0,0 +1,31 @@
# -*- makefile -*-
#
# arch/arm/Makefile.inc
#
# Special rules for this architecture. Note that this is actually
# included from the main Makefile, and that pathnames should be
# accordingly.
#
ARCHOBJS = \
libgcc/__divsi3.o \
libgcc/__modsi3.o \
libgcc/__udivsi3.o \
libgcc/__umodsi3.o \
libgcc/__udivmodsi4.o \
libgcc/__divdi3.o \
libgcc/__moddi3.o \
libgcc/__udivdi3.o \
libgcc/__umoddi3.o \
libgcc/__udivmoddi4.o
ifeq ($(THUMB),y)
ARCHOBJS += arch/arm/setjmp-thumb.o
LIBGCC =
else
ARCHOBJS += arch/arm/setjmp-arm.o
endif
ARCHSOOBJS = $(patsubst %.o,%.lo,$(ARCHOBJS))
archclean:

View File

@ -0,0 +1,25 @@
#
# arch/arm/crt0.S
#
# void _start(void)
# {
# /* Divine up argc, argv, and envp */
# environ = envp;
# exit(main(argc, argv, envp));
# }
#
.text
.align 4
.type _start,#function
.globl _start
#ifdef __thumb__
.thumb_func
#endif
_start: mov r0, sp
mov r1, #0
bl __libc_init
.size _start,.-_start

View File

@ -0,0 +1,14 @@
/*
* arch/i386/include/klibc/archsetjmp.h
*/
#ifndef _KLIBC_ARCHSETJMP_H
#define _KLIBC_ARCHSETJMP_H
struct __jmp_buf {
unsigned int regs[10];
};
typedef struct __jmp_buf jmp_buf[1];
#endif /* _SETJMP_H */

View File

@ -0,0 +1,12 @@
/*
* arch/arm/include/klibc/archsys.h
*
* Architecture-specific syscall definitions
*/
#ifndef _KLIBC_ARCHSYS_H
#define _KLIBC_ARCHSYS_H
/* No special syscall definitions for this architecture */
#endif /* _KLIBC_ARCHSYS_H */

View File

@ -0,0 +1,40 @@
#
# arch/arm/setjmp.S
#
# setjmp/longjmp for the ARM architecture
#
#
# The jmp_buf is assumed to contain the following, in order:
# r4
# r5
# r6
# r7
# r8
# r9
# r10
# fp
# sp
# lr
#
.text
.align 4
.globl setjmp
.type setjmp, #function
setjmp:
stmia r0, {r4, r5, r6, r7, r8, r9, r10, fp, sp, lr}
mov r0, #0
mov pc, lr
.size setjmp,.-setjmp
.text
.align 4
.globl longjmp
.type longjmp, #function
longjmp:
ldmia r0, {r4, r5, r6, r7, r8, r9, r10, fp, sp, lr}
movs r0, r1
moveq r0, #1
mov pc, lr
.size longjmp,.-longjmp

View File

@ -0,0 +1,58 @@
#
# arch/arm/setjmp-thumb.S
#
# setjmp/longjmp for the ARM/thumb architecture
#
#
# The jmp_buf is assumed to contain the following, in order:
# lr
# r4
# r5
# r6
# r7
# r8
# r9
# r10
# fp
# sp
#
.text
.align 4
.globl setjmp
.type setjmp, #function
.thumb_func
setjmp:
mov r3, lr
stmia r0!, {r3, r4, r5, r6, r7}
mov r3, r8
mov r4, r9
mov r5, r10
mov r6, fp
mov r7, sp
stmia r0!, {r3, r4, r5, r6, r7}
mov r0, #0
mov pc, lr
.size setjmp,.-setjmp
.text
.align 4
.globl longjmp
.type longjmp, #function
.thumb_func
longjmp:
mov r2, r0
add r0, #5*4
ldmia r0!, {r3, r4, r5, r6, r7}
mov r8, r3
mov r9, r4
mov r10, r5
mov fp, r6
mov sp, r7
ldmia r2!, {r3, r4, r5, r6, r7}
mov r0, r1
bne 1f
mov r0, #1
1: mov pc, r3
.size longjmp,.-longjmp

View File

@ -0,0 +1,11 @@
# -*- makefile -*-
#
# arch/cris/MCONFIG
#
# Special rules for this architecture. Note that this is actually
# included from the main Makefile, and that pathnames should be
# accordingly.
#
OPTFLAGS = -Os -fomit-frame-pointer
BITSIZE = 32

View File

@ -0,0 +1,10 @@
# -*- makefile -*-
#
# arch/cris/Makefile.inc
#
# Special rules for this architecture. Note that this is actually
# included from the main Makefile, and that pathnames should be
# accordingly.
#
archclean:

View File

@ -0,0 +1,12 @@
/*
* arch/cris/include/klibc/archsys.h
*
* Architecture-specific syscall definitions
*/
#ifndef _KLIBC_ARCHSYS_H
#define _KLIBC_ARCHSYS_H
/* No special syscall definitions for this architecture */
#endif /* _KLIBC_ARCHSYS_H */

View File

@ -0,0 +1,32 @@
# -*- makefile -*-
#
# arch/i386/MCONFIG
#
# Special rules for this architecture. Note that this is actually
# included from the main Makefile, and that pathnames should be
# accordingly.
#
# Comment this out to compile with register parameter passing
# This doesn't work right now because gcc 3.2 (at least) calls
# libgcc with the default calling convention instead of forcing
# them to be cdecl
# REGPARM = -mregparm=3 -DREGPARM
gcc_major := $(shell $(CC) -v 2>&1 | awk '/gcc version/{print int($$3)}')
OPTFLAGS = $(REGPARM) -march=i386 -Os
ifeq ($(gcc_major),3)
OPTFLAGS += -falign-functions=0 -falign-jumps=0 -falign-loops=0
else
OPTFLAGS += -malign-functions=0 -malign-jumps=0 -malign-loops=0
endif
BITSIZE = 32
# Extra linkflags when building the shared version of the library
# This address needs to be reachable using normal inter-module
# calls, and work on the memory models for this architecture
# 96 MB - normal binaries start at 128 MB
SHAREDFLAGS = -Ttext 0x06000200

View File

@ -0,0 +1,27 @@
# -*- makefile -*-
#
# arch/i386/Makefile.inc
#
# Special rules for this architecture. Note that this is actually
# included from the main Makefile, and that pathnames should be
# accordingly.
#
ARCHOBJS = \
arch/$(ARCH)/exits.o \
arch/$(ARCH)/socketcall.o \
arch/$(ARCH)/setjmp.o \
arch/$(ARCH)/libgcc/__ashldi3.o \
arch/$(ARCH)/libgcc/__ashrdi3.o \
arch/$(ARCH)/libgcc/__lshrdi3.o \
arch/$(ARCH)/libgcc/__muldi3.o \
arch/$(ARCH)/libgcc/__negdi2.o \
libgcc/__divdi3.o \
libgcc/__moddi3.o \
libgcc/__udivdi3.o \
libgcc/__umoddi3.o \
libgcc/__udivmoddi4.o
ARCHSOOBJS = $(patsubst %.o,%.lo,$(ARCHOBJS))
archclean:

View File

@ -0,0 +1,33 @@
#
# arch/i386/crt0.S
#
# Does arch-specific initialization and invokes __libc_init
# with the appropriate arguments.
#
# See __static_init.c or __shared_init.c for the expected
# arguments.
#
.text
.align 4
.type _start,@function
.globl _start
_start:
# Save the address of the ELF argument array
movl %esp,%eax # Address of ELF arguments
# Set up a faux stack frame for the benefit of gdb
xorl %ebp,%ebp
push %ebp # Keep gdb from getting confused
push %ebp # Keep gdb from getting confused
# Push the arguments and called __libc_init()
#ifndef REGPARM
push %edx # atexit() function
push %eax # ELF array
#endif
call __libc_init
# If __libc_init returns, problem...
ud2
hlt
.size _start, .-_start

View File

@ -0,0 +1,45 @@
#
# exit and _exit get included in *every* program, and gcc generates
# horrible code for them. Yes, this only saves a few bytes, but
# it does it in every program.
#
#include <asm/unistd.h>
.data
.align 4
.globl __exit_handler
.type __exit_handler,@object
__exit_handler:
.long _exit
.size __exit_handler,4
.text
.align 4
.globl exit
.type exit,@function
exit:
jmp *(__exit_handler)
.size exit,.-exit
/* No need to save any registers... we're exiting! */
.text
.align 4
.globl _exit
.type _exit,@function
_exit:
#ifdef REGPARM
movl %eax,%ebx
#else
popl %ebx
popl %ebx
#endif
#if __NR_exit == 1
xorl %eax,%eax
incl %eax
#else
movl $__NR_exit,%eax
#endif
int $0x80
hlt
.size _exit,.-exit

View File

@ -0,0 +1,19 @@
/*
* arch/i386/include/klibc/archsetjmp.h
*/
#ifndef _KLIBC_ARCHSETJMP_H
#define _KLIBC_ARCHSETJMP_H
struct __jmp_buf {
unsigned int __ebx;
unsigned int __esp;
unsigned int __ebp;
unsigned int __esi;
unsigned int __edi;
unsigned int __eip;
};
typedef struct __jmp_buf jmp_buf[1];
#endif /* _SETJMP_H */

View File

@ -0,0 +1,96 @@
/*
* arch/i386/include/klibc/archsys.h
*
* Architecture-specific syscall definitions
*/
#ifndef _KLIBC_ARCHSYS_H
#define _KLIBC_ARCHSYS_H
/*
* If we're compiling i386 in PIC mode, we need to treat %ebx
* specially. Most of these are copied from the equivalent file in
* newlib and were written by Werner Almesberger.
*/
#if defined(__PIC__)
/* _syscall0() is the same as non-PIC */
#undef _syscall1
#define _syscall1(type,name,type1,arg1) \
type name(type1 arg1) \
{ \
long __res; \
__asm__ __volatile__ ("push %%ebx; movl %2,%%ebx; int $0x80; pop %%ebx" \
: "=a" (__res) \
: "0" (__NR_##name),"r" ((long)(arg1))); \
__syscall_return(type,__res); \
}
#undef _syscall2
#define _syscall2(type,name,type1,arg1,type2,arg2) \
type name(type1 arg1,type2 arg2) \
{ \
long __res; \
__asm__ __volatile__ ("push %%ebx; movl %2,%%ebx; int $0x80; pop %%ebx" \
: "=a" (__res) \
: "0" (__NR_##name),"r" ((long)(arg1)),"c" ((long)(arg2))); \
__syscall_return(type,__res); \
}
#undef _syscall3
#define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \
type name(type1 arg1,type2 arg2,type3 arg3) \
{ \
long __res; \
__asm__ __volatile__ ("push %%ebx; movl %2,%%ebx; int $0x80; pop %%ebx" \
: "=a" (__res) \
: "0" (__NR_##name),"r" ((long)(arg1)),"c" ((long)(arg2)), \
"d" ((long)(arg3))); \
__syscall_return(type,__res); \
}
#undef _syscall4
#define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \
type name (type1 arg1, type2 arg2, type3 arg3, type4 arg4) \
{ \
long __res; \
__asm__ __volatile__ ("push %%ebx; movl %2,%%ebx; int $0x80; pop %%ebx" \
: "=a" (__res) \
: "0" (__NR_##name),"r" ((long)(arg1)),"c" ((long)(arg2)), \
"d" ((long)(arg3)),"S" ((long)(arg4))); \
__syscall_return(type,__res); \
}
#undef _syscall5
#define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
type5,arg5) \
type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5) \
{ \
long __res; \
__asm__ __volatile__ ("push %%ebx; movl %2,%%ebx; int $0x80; pop %%ebx" \
: "=a" (__res) \
: "0" (__NR_##name),"m" ((long)(arg1)),"c" ((long)(arg2)), \
"d" ((long)(arg3)),"S" ((long)(arg4)),"D" ((long)(arg5))); \
__syscall_return(type,__res); \
}
#undef _syscall6
#define _syscall6(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
type5,arg5,type6,arg6) \
type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5,type6 arg6) \
{ \
long __res; \
__asm__ __volatile__ ("push %%ebx; pushl %%ebp; movl %2,%%ebx; " \
"movl %%eax,%%ebp; movl %1,%%eax; int $0x80; " \
"pop %%ebp ; pop %%ebx" \
: "=a" (__res) \
: "i" (__NR_##name),"m" ((long)(arg1)),"c" ((long)(arg2)), \
"d" ((long)(arg3)),"S" ((long)(arg4)),"D" ((long)(arg5)), \
"a" ((long)(arg6))); \
__syscall_return(type,__res); \
}
#endif /* __PIC__ */
#endif /* _KLIBC_ARCHSYS_H */

View File

@ -0,0 +1,16 @@
/*
* arch/i386/include/klibc/diverr.h
*/
#ifndef _KLIBC_DIVERR_H
#define _KLIBC_DIVERR_H
#include <signal.h>
static __inline__ void
__divide_error(void)
{
asm volatile("divl %0" :: "rm" (0) : "eax", "edx");
}
#endif /* _KLIBC_DIVERR_H */

View File

@ -0,0 +1,29 @@
/*
* arch/i386/libgcc/__ashldi3.S
*
* 64-bit shl
*/
.text
.align 4
.globl __ashldi3
.type __ashldi3,@function
__ashldi3:
#ifndef REGPARM
movl 4(%esp),%eax
movl 8(%esp),%edx
movb 12(%esp),%cl
#endif
cmpb $32,%cl
jae 1f
shldl %cl,%eax,%edx
shl %cl,%eax
ret
1:
xorl %edx,%edx
shl %cl,%eax
xchgl %edx,%eax
ret
.size __ashldi3,.-__ashldi3

View File

@ -0,0 +1,29 @@
/*
* arch/i386/libgcc/__ashrdi3.S
*
* 64-bit sar
*/
.text
.align 4
.globl __ashrdi3
.type __ashrdi3,@function
__ashrdi3:
#ifndef REGPARM
movl 4(%esp),%eax
movl 8(%esp),%edx
movb 12(%esp),%cl
#endif
cmpb $32,%cl
jae 1f
shrdl %cl,%edx,%eax
sarl %cl,%edx
ret
1:
sarl %cl,%edx
movl %edx,%eax
cdq
ret
.size __ashrdi3,.-__ashrdi3

View File

@ -0,0 +1,29 @@
/*
* arch/i386/libgcc/__lshrdi3.S
*
* 64-bit shr
*/
.text
.align 4
.globl __lshrdi3
.type __lshrdi3,@function
__lshrdi3:
#ifndef REGPARM
movl 4(%esp),%eax
movl 8(%esp),%edx
movb 12(%esp),%cl
#endif
cmpb $32,%cl
jae 1f
shrdl %cl,%edx,%eax
shrl %cl,%edx
ret
1:
shrl %cl,%edx
xorl %eax,%eax
xchgl %edx,%eax
ret
.size __lshrdi3,.-__lshrdi3

View File

@ -0,0 +1,34 @@
/*
* arch/i386/libgcc/__muldi3.S
*
* 64*64 = 64 bit unsigned multiplication
*/
.text
.align 4
.globl __muldi3
.type __muldi3,@function
__muldi3:
push %esi
#ifndef REGPARM
movl 8(%esp),%eax
movl %eax,%esi
movl 16(%esp),%ecx
mull %ecx
imull 12(%esp),%ecx
imull 20(%esp),%esi
addl %ecx,%edx
addl %esi,%edx
#else
movl %eax,%esi
push %edx
mull %ecx
imull 8(%esp),%esi
addl %esi,%edx
pop %esi
imull %esi,%ecx
addl %ecx,%edx
#endif
pop %esi
ret
.size __muldi3,.-__muldi3

View File

@ -0,0 +1,21 @@
/*
* arch/i386/libgcc/__negdi2.S
*
* 64-bit negation
*/
.text
.align 4
.globl __negdi2
.type __negdi2,@function
__negdi2:
#ifndef REGPARM
movl 4(%esp),%eax
movl 8(%esp),%edx
#endif
negl %edx
negl %eax
sbbl $0,%edx
ret
.size __negdi2,.-__negdi2

View File

@ -0,0 +1,58 @@
#
# arch/i386/setjmp.S
#
# setjmp/longjmp for the i386 architecture
#
#
# The jmp_buf is assumed to contain the following, in order:
# %ebx
# %esp
# %ebp
# %esi
# %edi
# <return address>
#
.text
.align 4
.globl setjmp
.type setjmp, @function
setjmp:
#ifdef REGPARM
movl %eax,%edx
#else
movl 4(%esp),%edx
#endif
popl %ecx # Return address, and adjust the stack
xorl %eax,%eax # Return value
movl %ebx,(%edx)
movl %esp,4(%edx) # Post-return %esp!
pushl %ecx # Make the call/return stack happy
movl %ebp,8(%edx)
movl %esi,12(%edx)
movl %edi,16(%edx)
movl %ecx,20(%edx) # Return address
ret
.size setjmp,.-setjmp
.text
.align 4
.globl longjmp
.type longjmp, @function
longjmp:
#ifdef REGPARM
xchgl %eax,%edx
#else
movl 4(%esp),%edx # jmp_ptr address
movl 8(%esp),%eax # Return value
#endif
movl (%edx),%ebx
movl 4(%edx),%esp
movl 8(%edx),%ebp
movl 12(%edx),%esi
movl 16(%edx),%edi
jmp *20(%edx)
.size longjmp,.-longjmp

View File

@ -0,0 +1,38 @@
#
# socketcall.S
#
# On i386, the main (only?) user of socketcall(2), the memory array
# socketcall(2) needs is conveniently already assembled for us on
# the stack. Capitalize on that to make a common socketcall stub.
#
#include <asm/unistd.h>
#ifdef __i386__
.text
.align 4
.globl __socketcall_common
.type __socketcall_common, @function
__socketcall_common:
pushl %ebx
movzbl %al,%ebx # The socketcall number is passed in in %al
leal 8(%esp),%ecx # Argument pointer
movl $__NR_socketcall, %eax
int $0x80
cmpl $-125,%eax # Error return?
popl %ebx
jb 1f
neg %eax
movl %eax,errno
xorl %eax,%eax
decl %eax # Return = -1
1:
ret
.size __socketcall_common,.-__socketcall_common
#endif

View File

@ -0,0 +1,11 @@
# -*- makefile -*-
#
# arch/ia64/MCONFIG
#
# Special rules for this architecture. Note that this is actually
# included from the main Makefile, and that pathnames should be
# accordingly.
#
OPTFLAGS = -Os -fomit-frame-pointer
BITSIZE = 64

View File

@ -0,0 +1,10 @@
# -*- makefile -*-
#
# arch/ia64/Makefile.inc
#
# Special rules for this architecture. Note that this is actually
# included from the main Makefile, and that pathnames should be
# accordingly.
#
archclean:

View File

@ -0,0 +1,12 @@
/*
* arch/ia64/include/klibc/archsys.h
*
* Architecture-specific syscall definitions
*/
#ifndef _KLIBC_ARCHSYS_H
#define _KLIBC_ARCHSYS_H
/* No special syscall definitions for this architecture */
#endif /* _KLIBC_ARCHSYS_H */

View File

@ -0,0 +1,11 @@
# -*- makefile -*-
#
# arch/m68k/MCONFIG
#
# Special rules for this architecture. Note that this is actually
# included from the main Makefile, and that pathnames should be
# accordingly.
#
OPTFLAGS = -Os -fomit-frame-pointer
BITSIZE = 32

View File

@ -0,0 +1,10 @@
# -*- makefile -*-
#
# arch/m68k/Makefile.inc
#
# Special rules for this architecture. Note that this is actually
# included from the main Makefile, and that pathnames should be
# accordingly.
#
archclean:

View File

@ -0,0 +1,12 @@
/*
* arch/m68k/include/klibc/archsys.h
*
* Architecture-specific syscall definitions
*/
#ifndef _KLIBC_ARCHSYS_H
#define _KLIBC_ARCHSYS_H
/* No special syscall definitions for this architecture */
#endif /* _KLIBC_ARCHSYS_H */

View File

@ -0,0 +1,18 @@
# -*- makefile -*-
#
# arch/mips/MCONFIG
#
# Special rules for this architecture. Note that this is actually
# included from the main Makefile, and that pathnames should be
# accordingly.
#
ARCHREQFLAGS = -fno-pic -mno-abicalls
OPTFLAGS = -Os -fomit-frame-pointer
BITSIZE = 32
# Extra linkflags when building the shared version of the library
# This address needs to be reachable using normal inter-module
# calls, and work on the memory models for this architecture
# 2 MB -- the normal starting point for text is 4 MB.
SHAREDFLAGS = -Ttext 0x00200200

View File

@ -0,0 +1,24 @@
# -*- makefile -*-
#
# arch/mips/Makefile.inc
#
# Special rules for this architecture. Note that this is actually
# included from the main Makefile, and that pathnames should be
# accordingly.
#
ARCHOBJS = \
arch/$(ARCH)/pipe.o \
arch/$(ARCH)/vfork.o \
arch/$(ARCH)/setjmp.o \
libgcc/__divdi3.o \
libgcc/__moddi3.o \
libgcc/__udivdi3.o \
libgcc/__umoddi3.o \
libgcc/__udivmoddi4.o
ARCHSOOBJS = $(patsubst %.o,%.lo,$(ARCHOBJS))
archclean:

View File

@ -0,0 +1,25 @@
#
# arch/mips/crt0.S
#
# Does arch-specific initialization and invokes __libc_init
# with the appropriate arguments.
#
# See __static_init.c or __shared_init.c for the expected
# arguments.
#
#include <machine/asm.h>
NESTED(__start, 32, sp)
subu sp, 32
sw zero, 16(sp)
lui gp, %hi(_gp) # Initialize gp
addiu gp, gp, _gp
addiu a0, sp, 32 # Pointer to ELF entry structure
move a1, v0 # Kernel-provided atexit() pointer
jal __libc_init
END(__start)

View File

@ -0,0 +1,39 @@
/*
* arch/mips/include/klibc/archsetjmp.h
*/
#ifndef _KLIBC_ARCHSETJMP_H
#define _KLIBC_ARCHSETJMP_H
struct __jmp_buf {
unsigned long __s0;
unsigned long __s1;
unsigned long __s2;
unsigned long __s3;
unsigned long __s4;
unsigned long __s5;
unsigned long __s6;
unsigned long __s7;
unsigned long __gp;
unsigned long __sp;
unsigned long __s8;
unsigned long __ra;
unsigned long __f20;
unsigned long __f21;
unsigned long __f22;
unsigned long __f23;
unsigned long __f24;
unsigned long __f25;
unsigned long __f26;
unsigned long __f27;
unsigned long __f28;
unsigned long __f29;
unsigned long __f30;
unsigned long __f31;
unsigned long __fcr31;
unsigned long __unused;
} __attribute__((aligned(8)));
typedef struct __jmp_buf jmp_buf[1];
#endif /* _KLIBC_ARCHSETJMP_H */

View File

@ -0,0 +1,12 @@
/*
* arch/mips/include/klibc/archsys.h
*
* Architecture-specific syscall definitions
*/
#ifndef _KLIBC_ARCHSYS_H
#define _KLIBC_ARCHSYS_H
/* No special syscall definitions for this architecture */
#endif /* _KLIBC_ARCHSYS_H */

View File

@ -0,0 +1,11 @@
/*
* arch/mips/include/machine/asm.h
*/
#ifndef _MACHINE_ASM_H
#define _MACHINE_ASM_H
#include <asm/regdef.h>
#include <asm/asm.h>
#endif /* _MACHINE_ASM_H */

View File

@ -0,0 +1,20 @@
/*
* arch/mips/include/sgidefs.h
*/
/* Some ABI constants */
#ifndef _SGIDEFS_H
#define _SGIDEFS_H
#define _MIPS_ISA_MIPS1 1
#define _MIPS_ISA_MIPS2 2
#define _MIPS_ISA_MIPS3 3
#define _MIPS_ISA_MIPS4 4
#define _MIPS_ISA_MIPS5 5
#define _MIPS_SIM_ABI32 1
#define _MIPS_SIM_NABI32 2
#define _MIPS_SIM_ABI64 3
#endif /* _SGIDEFS_H */

View File

@ -0,0 +1,16 @@
#include <asm/asm.h>
#include <asm/regdef.h>
#include <asm/unistd.h>
LEAF(pipe)
li v0, __NR_pipe
syscall
bnez a3, 1f
sw v0, (a0)
sw v1, (a1)
li v0, 0
b 2f
1: sw v0, errno
li v0, -1
2: jr ra
END(pipe)

View File

@ -0,0 +1,82 @@
#
# arch/mips/setjmp.S
#
# setjmp/longjmp for the MIPS architecture
#
# The jmp_buf is assumed to contain the following, in order:
# s0..s7
# gp
# sp
# s8
# ra
# f20..f31
# fcr31
#
#include <machine/asm.h>
LEAF(setjmp)
sw s0, 0(a0)
sw s1, 4(a0)
sw s2, 8(a0)
sw s3, 12(a0)
sw s4, 16(a0)
sw s5, 20(a0)
sw s6, 24(a0)
sw s7, 28(a0)
sw gp, 32(a0)
sw sp, 36(a0)
sw s8, 40(a0)
sw ra, 44(a0)
cfc1 t0,$31
swc1 $f20,48(a0)
swc1 $f21,52(a0)
swc1 $f22,56(a0)
swc1 $f23,60(a0)
swc1 $f24,64(a0)
swc1 $f25,68(a0)
swc1 $f26,72(a0)
swc1 $f27,76(a0)
swc1 $f28,80(a0)
swc1 $f29,84(a0)
swc1 $f30,88(a0)
swc1 $f31,92(a0)
sw t0,96(a0)
move v0,zero
jr ra
END(setjmp)
LEAF(longjmp)
lw s0, 0(a0)
lw s1, 4(a0)
lw s2, 8(a0)
lw s3, 12(a0)
lw s4, 16(a0)
lw s5, 20(a0)
lw s6, 24(a0)
lw s7, 28(a0)
lw gp, 32(a0)
lw sp, 36(a0)
lw s8, 40(a0)
lw ra, 44(a0)
lw t0, 96(a0)
lwc1 $f20,48(a0)
lwc1 $f21,52(a0)
lwc1 $f22,56(a0)
lwc1 $f23,60(a0)
lwc1 $f24,64(a0)
lwc1 $f25,68(a0)
lwc1 $f26,72(a0)
lwc1 $f27,76(a0)
lwc1 $f28,80(a0)
lwc1 $f29,84(a0)
lwc1 $f30,88(a0)
lwc1 $f31,92(a0)
ctc1 t0,$31
move v0,a1
jr ra
END(longjmp)

View File

@ -0,0 +1,19 @@
#include <asm/asm.h>
#include <asm/regdef.h>
#include <asm/unistd.h>
#define CLONE_VM 0x00000100
#define CLONE_VFORK 0x00004000
#define SIGCHLD 18
LEAF(vfork)
li a0, CLONE_VFORK | CLONE_VM | SIGCHLD
li a1, 0
li v0, __NR_clone
syscall
bnez a3, 1f
b 2f
1: sw v0, errno
li v0, -1
2: jr ra
END(vfork)

View File

@ -0,0 +1,11 @@
# -*- makefile -*-
#
# arch/mips64/MCONFIG
#
# Special rules for this architecture. Note that this is actually
# included from the main Makefile, and that pathnames should be
# accordingly.
#
OPTFLAGS = -Os -fomit-frame-pointer
BITSIZE = 64

View File

@ -0,0 +1,10 @@
# -*- makefile -*-
#
# arch/mips64/Makefile.inc
#
# Special rules for this architecture. Note that this is actually
# included from the main Makefile, and that pathnames should be
# accordingly.
#
archclean:

View File

@ -0,0 +1,12 @@
/*
* arch/mips64/include/klibc/archsys.h
*
* Architecture-specific syscall definitions
*/
#ifndef _KLIBC_ARCHSYS_H
#define _KLIBC_ARCHSYS_H
/* No special syscall definitions for this architecture */
#endif /* _KLIBC_ARCHSYS_H */

View File

@ -0,0 +1,11 @@
# -*- makefile -*-
#
# arch/parisc/MCONFIG
#
# Special rules for this architecture. Note that this is actually
# included from the main Makefile, and that pathnames should be
# accordingly.
#
OPTFLAGS = -Os -fomit-frame-pointer
BITSIZE = 32

View File

@ -0,0 +1,10 @@
# -*- makefile -*-
#
# arch/parisc/Makefile.inc
#
# Special rules for this architecture. Note that this is actually
# included from the main Makefile, and that pathnames should be
# accordingly.
#
archclean:

View File

@ -0,0 +1,12 @@
/*
* arch/parisc/include/klibc/archsys.h
*
* Architecture-specific syscall definitions
*/
#ifndef _KLIBC_ARCHSYS_H
#define _KLIBC_ARCHSYS_H
/* No special syscall definitions for this architecture */
#endif /* _KLIBC_ARCHSYS_H */

View File

@ -0,0 +1,11 @@
# -*- makefile -*-
#
# arch/ppc/MCONFIG
#
# Special rules for this architecture. Note that this is actually
# included from the main Makefile, and that pathnames should be
# accordingly.
#
OPTFLAGS = -Os -fomit-frame-pointer
BITSIZE = 32

View File

@ -0,0 +1,15 @@
# -*- makefile -*-
#
# arch/ppc/Makefile.inc
#
# Special rules for this architecture. Note that this is actually
# included from the main Makefile, and that pathnames should be
# accordingly.
#
ARCHOBJS = \
arch/$(ARCH)/setjmp.o
ARCHSOOBJS = $(patsubst %.o,%.lo,$(ARCHOBJS))
archclean:

View File

@ -0,0 +1,29 @@
#
# arch/ppc/crt0.S
#
# void _start(void)
# {
# /* Divine up argc, argv, and envp */
# environ = envp;
# exit(main(argc, argv, envp));
# }
#
.text
.align 4
.type _start,@function
.globl _start
_start:
lwz 3,0(1)
addi 4,1,4
addi 5,1,8
slwi 0,3,2
add 5,5,0
li 0,0
stwu 0,-16(1)
lis 9,environ@ha
stw 5,environ@l(9)
bl main
bl exit
.size _start,.-_start

View File

@ -0,0 +1,36 @@
/*
* arch/ppc/include/klibc/archsetjmp.h
*/
#ifndef _KLIBC_ARCHSETJMP_H
#define _KLIBC_ARCHSETJMP_H
struct __jmp_buf {
unsigned long __r2;
unsigned long __sp;
unsigned long __lr;
unsigned long __cr;
unsigned long __r13;
unsigned long __r14;
unsigned long __r15;
unsigned long __r16;
unsigned long __r17;
unsigned long __r18;
unsigned long __r19;
unsigned long __r20;
unsigned long __r21;
unsigned long __r22;
unsigned long __r23;
unsigned long __r24;
unsigned long __r25;
unsigned long __r26;
unsigned long __r27;
unsigned long __r28;
unsigned long __r29;
unsigned long __r30;
unsigned long __r31;
};
typedef struct __jmp_buf jmp_buf[1];
#endif /* _SETJMP_H */

View File

@ -0,0 +1,55 @@
/*
* arch/ppc/include/klibc/archsys.h
*
* Architecture-specific syscall definitions
*/
#ifndef _KLIBC_ARCHSYS_H
#define _KLIBC_ARCHSYS_H
/* PowerPC seems to lack _syscall6() in its headers */
/* This seems to work on both 32- and 64-bit ppc */
#ifndef _syscall6
#define _syscall6(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
type5,arg5,type6,arg6) \
type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5,type6 arg6) \
{ \
unsigned long __sc_ret, __sc_err; \
{ \
register unsigned long __sc_0 __asm__ ("r0"); \
register unsigned long __sc_3 __asm__ ("r3"); \
register unsigned long __sc_4 __asm__ ("r4"); \
register unsigned long __sc_5 __asm__ ("r5"); \
register unsigned long __sc_6 __asm__ ("r6"); \
register unsigned long __sc_7 __asm__ ("r7"); \
register unsigned long __sc_8 __asm__ ("r8"); \
\
__sc_3 = (unsigned long) (arg1); \
__sc_4 = (unsigned long) (arg2); \
__sc_5 = (unsigned long) (arg3); \
__sc_6 = (unsigned long) (arg4); \
__sc_7 = (unsigned long) (arg5); \
__sc_8 = (unsigned long) (arg6); \
__sc_0 = __NR_##name; \
__asm__ __volatile__ \
("sc \n\t" \
"mfcr %1 " \
: "=&r" (__sc_3), "=&r" (__sc_0) \
: "0" (__sc_3), "1" (__sc_0), \
"r" (__sc_4), \
"r" (__sc_5), \
"r" (__sc_6), \
"r" (__sc_7), \
"r" (__sc_8) \
: __syscall_clobbers); \
__sc_ret = __sc_3; \
__sc_err = __sc_0; \
} \
__syscall_return (type); \
}
#endif /* _syscall6() missing */
#endif /* _KLIBC_ARCHSYS_H */

View File

@ -0,0 +1,35 @@
#
# arch/ppc/setjmp.S
#
# Basic setjmp/longjmp implementation
# This file was derived from the equivalent file in NetBSD
#
.text
.align 4
.type setjmp,@function
.globl setjmp
setjmp:
mflr %r11 /* save return address */
mfcr %r12 /* save condition register */
mr %r10,%r1 /* save stack pointer */
mr %r9,%r2 /* save GPR2 (not needed) */
stmw %r9,0(%r3) /* save r9..r31 */
li %r3,0 /* indicate success */
blr /* return */
.size setjmp,.-setjmp
.type longjmp,@function
.globl longjmp
longjmp:
lmw %r9,0(%r3) /* save r9..r31 */
mtlr %r11 /* restore LR */
mtcr %r12 /* restore CR */
mr %r2,%r9 /* restore GPR2 (not needed) */
mr %r1,%r10 /* restore stack */
mr %r3,%r4 /* get return value */
blr /* return */
.size longjmp,.-longjmp

View File

@ -0,0 +1,11 @@
# -*- makefile -*-
#
# arch/ppc64/MCONFIG
#
# Special rules for this architecture. Note that this is actually
# included from the main Makefile, and that pathnames should be
# accordingly.
#
OPTFLAGS = -Os -fomit-frame-pointer
BITSIZE = 64

View File

@ -0,0 +1,10 @@
# -*- makefile -*-
#
# arch/ppc64/Makefile.inc
#
# Special rules for this architecture. Note that this is actually
# included from the main Makefile, and that pathnames should be
# accordingly.
#
archclean:

View File

@ -0,0 +1,38 @@
#
# arch/ppc64/crt0.S
#
# void _start(void)
# {
# /* Divine up argc, argv, and envp */
# environ = envp;
# exit(main(argc, argv, envp));
# }
#
.section ".toc","aw"
.LC0: .tc environ[TC],environ
.section ".opd","aw"
.align 3
.globl _start
_start:
.quad ._start
.quad .TOC.@tocbase, 0
.text
.globl ._start
.type ._start,@function
._start:
ld 3,0(1)
ld 4,8(1)
ld 5,16(1)
li 0,0
stdu 0,-64(1)
ld 9,.LC0@toc(2)
std 5,0(9)
bl .main
nop
bl .exit
nop
.size _start,.-_start

View File

@ -0,0 +1,52 @@
/*
* arch/ppc64/include/klibc/archsys.h
*
* Architecture-specific syscall definitions
*/
#ifndef _KLIBC_ARCHSYS_H
#define _KLIBC_ARCHSYS_H
#ifndef _syscall6
#define _syscall6(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
type5,arg5,type6,arg6) \
type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5,type6 arg6) \
{ \
unsigned long __sc_ret, __sc_err; \
{ \
register unsigned long __sc_0 __asm__ ("r0"); \
register unsigned long __sc_3 __asm__ ("r3"); \
register unsigned long __sc_4 __asm__ ("r4"); \
register unsigned long __sc_5 __asm__ ("r5"); \
register unsigned long __sc_6 __asm__ ("r6"); \
register unsigned long __sc_7 __asm__ ("r7"); \
register unsigned long __sc_8 __asm__ ("r8"); \
\
__sc_3 = (unsigned long) (arg1); \
__sc_4 = (unsigned long) (arg2); \
__sc_5 = (unsigned long) (arg3); \
__sc_6 = (unsigned long) (arg4); \
__sc_7 = (unsigned long) (arg5); \
__sc_8 = (unsigned long) (arg6); \
__sc_0 = __NR_##name; \
__asm__ __volatile__ \
("sc \n\t" \
"mfcr %1 " \
: "=&r" (__sc_3), "=&r" (__sc_0) \
: "0" (__sc_3), "1" (__sc_0), \
"r" (__sc_4), \
"r" (__sc_5), \
"r" (__sc_6), \
"r" (__sc_7), \
"r" (__sc_8) \
: __syscall_clobbers); \
__sc_ret = __sc_3; \
__sc_err = __sc_0; \
} \
__syscall_return (type); \
}
#endif /* _syscall6() missing */
#endif /* _KLIBC_ARCHSYS_H */

View File

@ -0,0 +1,13 @@
# -*- makefile -*-
#
# arch/s390/MCONFIG
#
# Special rules for this architecture. Note that this is actually
# included from the main Makefile, and that pathnames should be
# accordingly.
#
OPTFLAGS = -Os -fomit-frame-pointer
BITSIZE = 32
SHAREDFLAGS = -Ttext 0x40000200

View File

@ -0,0 +1,16 @@
# -*- makefile -*-
#
# arch/s390/Makefile.inc
#
# Special rules for this architecture. Note that this is actually
# included from the main Makefile, and that pathnames should be
# accordingly.
#
ARCHOBJS = \
arch/$(ARCH)/setjmp.o
ARCHSOOBJS = $(patsubst %.o,%.lo,$(ARCHOBJS))
archclean:

View File

@ -0,0 +1,25 @@
#
# arch/s390/crt0.S
#
# Does arch-specific initialization and invokes __libc_init
# with the appropriate arguments.
#
# See __static_init.c or __shared_init.c for the expected
# arguments.
#
.text
.align 4
.type _start,@function
.globl _start
_start:
lr %r2,%r15
lhi %r3,0
ahi %r15,-96
bras %r1,.L0
.L0:
l %r1,.L1-.L0(%r1)
br %r1
.L1:
.long __libc_init
.size _start,.-_start

View File

@ -0,0 +1,15 @@
/*
* arch/s390/include/klibc/archsetjmp.h
*/
#ifndef _KLIBC_ARCHSETJMP_H
#define _KLIBC_ARCHSETJMP_H
struct __jmp_buf {
uint32_t __gregs[10]; /* general registers r6-r15 */
uint64_t __fpregs[2]; /* fp registers f4 and f6 */
};
typedef struct __jmp_buf jmp_buf[1];
#endif /* _SETJMP_H */

View File

@ -0,0 +1,41 @@
/*
* arch/s390/include/klibc/archsys.h
*
* Architecture-specific syscall definitions
*/
#ifndef _KLIBC_ARCHSYS_H
#define _KLIBC_ARCHSYS_H
/* S/390 only has five syscall parameters, and uses a structure for
6-argument syscalls. */
#ifndef _syscall6
#define _syscall6(type,name,type1,arg1,type2,arg2,type3,arg3,\
type4,arg4,type5,arg5,type6,arg6) \
type name(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \
type5 arg5, type6 arg6) { \
unsigned long __arg[6] = { \
(unsigned long) arg1, \
(unsigned long) arg2, \
(unsigned long) arg3, \
(unsigned long) arg4, \
(unsigned long) arg5, \
(unsigned long) arg6 \
}; \
register void *__argp asm("2") = &__arg; \
long __res; \
__asm__ __volatile__ ( \
" svc %b1\n" \
" lr %0,2" \
: "=d" (__res) \
: "i" (__NR_##name), \
"d" (__argp) \
: _svc_clobber); \
__syscall_return(type, __res); \
}
#endif /* _syscall6() missing */
#endif /* _KLIBC_ARCHSYS_H */

View File

@ -0,0 +1,32 @@
#
# arch/s390/setjmp.S
#
# setjmp/longjmp for the s390 architecture
#
.text
.align 4
.globl setjmp
.type setjmp, @function
setjmp:
stm %r6,%r15,0(%r2) # save all general registers
std %f4,40(%r2) # save fp registers f4 and f6
std %f6,48(%r2)
lhi %r2,0 # return 0
br %r14
.size setjmp,.-setjmp
.text
.align 4
.globl longjmp
.type longjmp, @function
longjmp:
lr %r1,%r2 # jmp_buf
lr %r2,%r3 # return value
ld %f6,48(%r1) # restore all saved registers
ld %f4,40(%r1)
lm %r6,%r15,0(%r1)
br %r14 # return to restored address
.size longjmp,.-longjmp

View File

@ -0,0 +1,13 @@
# -*- makefile -*-
#
# arch/s390x/MCONFIG
#
# Special rules for this architecture. Note that this is actually
# included from the main Makefile, and that pathnames should be
# accordingly.
#
OPTFLAGS = -Os -fomit-frame-pointer
BITSIZE = 64
SHAREDFLAGS = -Ttext 0x40000200

View File

@ -0,0 +1,16 @@
# -*- makefile -*-
#
# arch/s390x/Makefile.inc
#
# Special rules for this architecture. Note that this is actually
# included from the main Makefile, and that pathnames should be
# accordingly.
#
ARCHOBJS = \
arch/$(ARCH)/setjmp.o
ARCHSOOBJS = $(patsubst %.o,%.lo,$(ARCHOBJS))
archclean:

View File

@ -0,0 +1,21 @@
#
# arch/s390/crt0.S
#
# Does arch-specific initialization and invokes __libc_init
# with the appropriate arguments.
#
# See __static_init.c or __shared_init.c for the expected
# arguments.
#
.text
.align 4
.type _start,@function
.globl _start
_start:
lgr %r2,%r15
lghi %r3,0
aghi %r15,-160
jg __libc_init
.size _start,.-_start

View File

@ -0,0 +1,15 @@
/*
* arch/s390x/include/klibc/archsetjmp.h
*/
#ifndef _KLIBC_ARCHSETJMP_H
#define _KLIBC_ARCHSETJMP_H
struct __jmp_buf {
uint64_t __gregs[10]; /* general registers r6-r15 */
uint64_t __fpregs[4]; /* fp registers f1, f3, f5, f7 */
};
typedef struct __jmp_buf jmp_buf[1];
#endif /* _SETJMP_H */

View File

@ -0,0 +1,41 @@
/*
* arch/s390x/include/klibc/archsys.h
*
* Architecture-specific syscall definitions
*/
#ifndef _KLIBC_ARCHSYS_H
#define _KLIBC_ARCHSYS_H
/* S/390X only has five syscall parameters, and uses a structure for
6-argument syscalls. */
#ifndef _syscall6
#define _syscall6(type,name,type1,arg1,type2,arg2,type3,arg3,\
type4,arg4,type5,arg5,type6,arg6) \
type name(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \
type5 arg5, type6 arg6) { \
unsigned long __arg[6] = { \
(unsigned long) arg1, \
(unsigned long) arg2, \
(unsigned long) arg3, \
(unsigned long) arg4, \
(unsigned long) arg5, \
(unsigned long) arg6 \
}; \
register void *__argp asm("2") = &__arg; \
long __res; \
__asm__ __volatile__ ( \
" svc %b1\n" \
" lgr %0,2" \
: "=d" (__res) \
: "i" (__NR_##name), \
"d" (__argp) \
: _svc_clobber); \
__syscall_return(type, __res); \
}
#endif /* _syscall6() missing */
#endif /* _KLIBC_ARCHSYS_H */

View File

@ -0,0 +1,36 @@
#
# arch/s390x/setjmp.S
#
# setjmp/longjmp for the s390x architecture
#
.text
.align 4
.globl setjmp
.type setjmp, @function
setjmp:
stmg %r6,%r15,0(%r2) # save all general registers
std %f1,80(%r2) # save fp registers f4 and f6
std %f3,88(%r2)
std %f5,96(%r2)
std %f7,104(%r2)
lghi %r2,0 # return 0
br %r14
.size setjmp,.-setjmp
.text
.align 4
.globl longjmp
.type longjmp, @function
longjmp:
lgr %r1,%r2 # jmp_buf
lgr %r2,%r3 # return value
ld %f7,104(%r1) # restore all saved registers
ld %f5,96(%r1)
ld %f3,88(%r1)
ld %f1,80(%r1)
lmg %r6,%r15,0(%r1)
br %r14 # return to restored address
.size longjmp,.-longjmp

View File

@ -0,0 +1,19 @@
# -*- makefile -*-
#
# arch/sh/MCONFIG
#
# Special rules for this architecture. Note that this is actually
# included from the main Makefile, and that pathnames should be
# accordingly.
#
ARCHREGFLAGS = -m4 -mno-implicit-fp
OPTFLAGS = -Os -fomit-frame-pointer
BITSIZE = 32
# Extra linkflags when building the shared version of the library
# This address needs to be reachable using normal inter-module
# calls, and work on the memory models for this architecture
# 2 MB -- the normal starting point for text is 4 MB.
SHAREDFLAGS = -Ttext 0x00200200

View File

@ -0,0 +1,14 @@
# -*- makefile -*-
#
# arch/sh/Makefile.inc
#
# Special rules for this architecture. Note that this is actually
# included from the main Makefile, and that pathnames should be
# accordingly.
#
ARCHOBJS = arch/sh/setjmp.o
ARCHSOOBJS = $(patsubst %.o,%.lo,$(ARCHOBJS))
archclean:

View File

@ -0,0 +1,28 @@
#
# arch/sh/crt0.S
#
# void _start(void)
# {
# /* Divine up argc, argv, and envp */
# environ = envp;
# exit(main(argc, argv, envp));
# }
#
.text
.align 2
.type _start,#function
.globl _start
_start:
mov r15, r4
mov #0, r5
mov.l 1f, r0
jsr @r0
nop
.align 2
1: .long __libc_init
.size _start,.-_start

View File

@ -0,0 +1,22 @@
/*
* arch/sh/include/klibc/archsetjmp.h
*/
#ifndef _KLIBC_ARCHSETJMP_H
#define _KLIBC_ARCHSETJMP_H
struct __jmp_buf {
unsigned long r8;
unsigned long r9;
unsigned long r10;
unsigned long r11;
unsigned long r12;
unsigned long r13;
unsigned long r14;
unsigned long r15;
unsigned long pr;
};
typedef struct __jmp_buf jmp_buf[1];
#endif /* _KLIBC_ARCHSETJMP_H */

View File

@ -0,0 +1,12 @@
/*
* arch/sh/include/klibc/archsys.h
*
* Architecture-specific syscall definitions
*/
#ifndef _KLIBC_ARCHSYS_H
#define _KLIBC_ARCHSYS_H
/* No special syscall definitions for this architecture */
#endif /* _KLIBC_ARCHSYS_H */

View File

@ -0,0 +1,65 @@
#
# arch/sh/setjmp.S
#
# setjmp/longjmp for the SuperH architecture
#
#
# The jmp_buf is assumed to contain the following, in order:
#
# r8
# r9
# r10
# r11
# r12
# r13
# r14
# r15
# pr
#
.text
.align 2
.globl setjmp
.type setjmp, #function
setjmp:
add #(9*4), r4
sts.l pr, @-r4
mov.l r15, @-r4
mov.l r14, @-r4
mov.l r13, @-r4
mov.l r12, @-r4
mov.l r11, @-r4
mov.l r10, @-r4
mov.l r9, @-r4
mov.l r8, @-r4
rts
mov #0, r0
.size setjmp,.-setjmp
.align 2
.globl longjmp
.type setjmp, #function
longjmp:
mov.l @r4+, r8
mov.l @r4+, r9
mov.l @r4+, r10
mov.l @r4+, r11
mov.l @r4+, r12
mov.l @r4+, r13
mov.l @r4+, r14
mov.l @r4+, r15
lds.l @r4+, pr
mov r5, r0
tst r0, r0
bf 1f
mov #1, r0 ! in case val==0
1: rts
nop
.size longjmp,.-longjmp

Some files were not shown because too many files have changed in this diff Show More