summaryrefslogtreecommitdiff
path: root/klibc
diff options
context:
space:
mode:
authorgreg@kroah.com <greg@kroah.com>2004-10-05 18:32:12 -0700
committerGreg KH <gregkh@suse.de>2005-04-26 21:37:01 -0700
commita0622777688ad84ef3d789e0171cfb0ca3dc21d2 (patch)
treea723bb7d0849194260a5a009fb98b09ba79cd22b /klibc
parent9e8a3a095d955538acbdf28dba02582f6b2330e5 (diff)
[PATCH] update klibc to version 0.181
Diffstat (limited to 'klibc')
-rw-r--r--klibc/MCONFIG33
-rw-r--r--klibc/Makefile2
-rw-r--r--klibc/README3
-rw-r--r--klibc/klibc.spec157
-rw-r--r--klibc/klibc.spec.in48
-rw-r--r--klibc/klibc/MCONFIG5
-rw-r--r--klibc/klibc/Makefile70
-rw-r--r--klibc/klibc/README48
-rw-r--r--klibc/klibc/SOCKETCALLS21
-rw-r--r--klibc/klibc/SOCKETCALLS.def21
-rw-r--r--klibc/klibc/SYSCALLS153
-rw-r--r--klibc/klibc/SYSCALLS.def207
-rw-r--r--klibc/klibc/__shared_init.c58
-rw-r--r--klibc/klibc/__static_init.c40
-rw-r--r--klibc/klibc/alarm.c6
-rw-r--r--klibc/klibc/arch/alpha/Makefile.inc6
-rw-r--r--klibc/klibc/arch/alpha/crt0.S11
-rw-r--r--klibc/klibc/arch/alpha/include/klibc/archsetjmp.h33
-rw-r--r--klibc/klibc/arch/alpha/include/klibc/archsignal.h13
-rw-r--r--klibc/klibc/arch/alpha/include/klibc/archsys.h53
-rw-r--r--klibc/klibc/arch/alpha/include/machine/asm.h44
-rw-r--r--klibc/klibc/arch/alpha/setjmp.S32
-rw-r--r--klibc/klibc/arch/alpha/syscall.S26
-rw-r--r--klibc/klibc/arch/alpha/sysdual.S33
-rw-r--r--klibc/klibc/arch/alpha/sysstub.ph37
-rw-r--r--klibc/klibc/arch/arm/Makefile.inc14
-rw-r--r--klibc/klibc/arch/arm/crt0.S6
-rw-r--r--klibc/klibc/arch/arm/include/klibc/archsetjmp.h14
-rw-r--r--klibc/klibc/arch/arm/include/klibc/archsignal.h13
-rw-r--r--klibc/klibc/arch/arm/include/klibc/archsys.h12
-rw-r--r--klibc/klibc/arch/arm/setjmp-arm.S3
-rw-r--r--klibc/klibc/arch/arm/syscall.S50
-rw-r--r--klibc/klibc/arch/arm/sysstub.ph44
-rw-r--r--klibc/klibc/arch/cris/MCONFIG15
-rw-r--r--klibc/klibc/arch/cris/Makefile.inc23
-rw-r--r--klibc/klibc/arch/cris/__negdi2.S25
-rw-r--r--klibc/klibc/arch/cris/crt0.S28
-rw-r--r--klibc/klibc/arch/cris/divide.c92
-rw-r--r--klibc/klibc/arch/cris/include/klibc/archsignal.h13
-rw-r--r--klibc/klibc/arch/cris/include/klibc/archsys.h12
-rw-r--r--klibc/klibc/arch/cris/setjmp.S37
-rw-r--r--klibc/klibc/arch/cris/syscall.S30
-rw-r--r--klibc/klibc/arch/cris/sysstub.ph29
-rw-r--r--klibc/klibc/arch/i386/MCONFIG6
-rw-r--r--klibc/klibc/arch/i386/Makefile.inc4
-rw-r--r--klibc/klibc/arch/i386/include/klibc/archsetjmp.h19
-rw-r--r--klibc/klibc/arch/i386/include/klibc/archsignal.h13
-rw-r--r--klibc/klibc/arch/i386/include/klibc/archsys.h96
-rw-r--r--klibc/klibc/arch/i386/include/klibc/diverr.h16
-rw-r--r--klibc/klibc/arch/i386/include/sys/io.h126
-rw-r--r--klibc/klibc/arch/i386/include/sys/vm86.h41
-rw-r--r--klibc/klibc/arch/i386/open.S29
-rw-r--r--klibc/klibc/arch/i386/socketcall.S28
-rw-r--r--klibc/klibc/arch/i386/syscall.S60
-rw-r--r--klibc/klibc/arch/i386/sysstub.ph32
-rw-r--r--klibc/klibc/arch/ia64/Makefile.inc1
-rw-r--r--klibc/klibc/arch/ia64/include/klibc/archsetjmp.h17
-rw-r--r--klibc/klibc/arch/ia64/include/klibc/archsignal.h31
-rw-r--r--klibc/klibc/arch/ia64/include/klibc/archsys.h218
-rw-r--r--klibc/klibc/arch/ia64/pipe.c2
-rw-r--r--klibc/klibc/arch/ia64/syscall.S20
-rw-r--r--klibc/klibc/arch/ia64/sysstub.ph29
-rw-r--r--klibc/klibc/arch/ia64/vfork.S4
-rw-r--r--klibc/klibc/arch/m68k/include/klibc/archsignal.h13
-rw-r--r--klibc/klibc/arch/m68k/include/klibc/archsys.h12
-rw-r--r--klibc/klibc/arch/mips/MCONFIG7
-rw-r--r--klibc/klibc/arch/mips/Makefile.inc1
-rw-r--r--klibc/klibc/arch/mips/include/klibc/archsetjmp.h39
-rw-r--r--klibc/klibc/arch/mips/include/klibc/archsignal.h13
-rw-r--r--klibc/klibc/arch/mips/include/klibc/archsys.h12
-rw-r--r--klibc/klibc/arch/mips/include/machine/asm.h11
-rw-r--r--klibc/klibc/arch/mips/include/sgidefs.h20
-rw-r--r--klibc/klibc/arch/mips/klibc.ld217
-rw-r--r--klibc/klibc/arch/mips/syscall.S15
-rw-r--r--klibc/klibc/arch/mips/sysstub.ph30
-rw-r--r--klibc/klibc/arch/mips/vfork.S11
-rw-r--r--klibc/klibc/arch/mips64/include/klibc/archsignal.h13
-rw-r--r--klibc/klibc/arch/mips64/include/klibc/archsys.h12
-rw-r--r--klibc/klibc/arch/parisc/Makefile.inc6
-rw-r--r--klibc/klibc/arch/parisc/include/klibc/archsignal.h24
-rw-r--r--klibc/klibc/arch/parisc/include/klibc/archsys.h12
-rw-r--r--klibc/klibc/arch/parisc/syscall.c29
-rw-r--r--klibc/klibc/arch/parisc/sysstub.ph29
-rw-r--r--klibc/klibc/arch/ppc/MCONFIG7
-rw-r--r--klibc/klibc/arch/ppc/Makefile.inc1
-rw-r--r--klibc/klibc/arch/ppc/include/klibc/archsetjmp.h36
-rw-r--r--klibc/klibc/arch/ppc/include/klibc/archsignal.h13
-rw-r--r--klibc/klibc/arch/ppc/include/klibc/archsys.h61
-rw-r--r--klibc/klibc/arch/ppc/syscall.S16
-rw-r--r--klibc/klibc/arch/ppc/sysstub.ph25
-rw-r--r--klibc/klibc/arch/ppc64/MCONFIG7
-rw-r--r--klibc/klibc/arch/ppc64/Makefile.inc12
-rw-r--r--klibc/klibc/arch/ppc64/include/klibc/archsetjmp.h36
-rw-r--r--klibc/klibc/arch/ppc64/include/klibc/archsignal.h13
-rw-r--r--klibc/klibc/arch/ppc64/include/klibc/archsys.h52
-rw-r--r--klibc/klibc/arch/ppc64/setjmp.S69
-rw-r--r--klibc/klibc/arch/ppc64/syscall.c14
-rw-r--r--klibc/klibc/arch/ppc64/sysstub.ph34
-rw-r--r--klibc/klibc/arch/s390/Makefile.inc2
-rw-r--r--klibc/klibc/arch/s390/include/klibc/archsetjmp.h15
-rw-r--r--klibc/klibc/arch/s390/include/klibc/archsignal.h13
-rw-r--r--klibc/klibc/arch/s390/include/klibc/archsys.h41
-rw-r--r--klibc/klibc/arch/s390/mmap.c41
-rw-r--r--klibc/klibc/arch/s390/syscall.c16
-rw-r--r--klibc/klibc/arch/s390/sysstub.ph31
-rw-r--r--klibc/klibc/arch/s390x/Makefile.inc4
-rw-r--r--klibc/klibc/arch/s390x/include/klibc/archsetjmp.h15
-rw-r--r--klibc/klibc/arch/s390x/include/klibc/archsignal.h13
-rw-r--r--klibc/klibc/arch/s390x/include/klibc/archsys.h41
-rw-r--r--klibc/klibc/arch/s390x/mmap.c41
-rw-r--r--klibc/klibc/arch/s390x/syscall.c16
-rw-r--r--klibc/klibc/arch/s390x/sysstub.ph28
-rw-r--r--klibc/klibc/arch/sh/Makefile.inc3
-rw-r--r--klibc/klibc/arch/sh/crt0.S11
-rw-r--r--klibc/klibc/arch/sh/include/klibc/archsetjmp.h22
-rw-r--r--klibc/klibc/arch/sh/include/klibc/archsignal.h13
-rw-r--r--klibc/klibc/arch/sh/include/klibc/archsys.h12
-rw-r--r--klibc/klibc/arch/sh/syscall.S35
-rw-r--r--klibc/klibc/arch/sh/sysstub.ph34
-rw-r--r--klibc/klibc/arch/sparc/Makefile.inc4
-rw-r--r--klibc/klibc/arch/sparc/include/klibc/archsetjmp.h16
-rw-r--r--klibc/klibc/arch/sparc/include/klibc/archsignal.h13
-rw-r--r--klibc/klibc/arch/sparc/include/klibc/archsys.h65
-rw-r--r--klibc/klibc/arch/sparc/include/machine/asm.h192
-rw-r--r--klibc/klibc/arch/sparc/include/machine/frame.h138
-rw-r--r--klibc/klibc/arch/sparc/include/machine/trap.h141
-rw-r--r--klibc/klibc/arch/sparc/syscall.S19
-rw-r--r--klibc/klibc/arch/sparc/sysfork.S25
-rw-r--r--klibc/klibc/arch/sparc/sysstub.ph25
-rw-r--r--klibc/klibc/arch/sparc64/Makefile.inc4
-rw-r--r--klibc/klibc/arch/sparc64/include/klibc/archsetjmp.h16
-rw-r--r--klibc/klibc/arch/sparc64/include/klibc/archsignal.h13
-rw-r--r--klibc/klibc/arch/sparc64/include/klibc/archsys.h157
-rw-r--r--klibc/klibc/arch/sparc64/syscall.S18
-rw-r--r--klibc/klibc/arch/sparc64/sysfork.S26
-rw-r--r--klibc/klibc/arch/sparc64/sysstub.ph25
-rw-r--r--klibc/klibc/arch/x86_64/MCONFIG8
-rw-r--r--klibc/klibc/arch/x86_64/Makefile.inc3
-rw-r--r--klibc/klibc/arch/x86_64/include/klibc/archsetjmp.h21
-rw-r--r--klibc/klibc/arch/x86_64/include/klibc/archsignal.h13
-rw-r--r--klibc/klibc/arch/x86_64/include/klibc/archsys.h109
-rw-r--r--klibc/klibc/arch/x86_64/include/sys/io.h126
-rw-r--r--klibc/klibc/arch/x86_64/syscall.S28
-rw-r--r--klibc/klibc/arch/x86_64/sysstub.ph23
-rw-r--r--klibc/klibc/asprintf.c30
-rw-r--r--klibc/klibc/ctypes.c386
-rw-r--r--klibc/klibc/daemon.c38
-rw-r--r--klibc/klibc/fdatasync.c15
-rw-r--r--klibc/klibc/fork.c14
-rw-r--r--klibc/klibc/fstatfs.c19
-rw-r--r--klibc/klibc/getcwd.c5
-rw-r--r--klibc/klibc/getpagesize.c26
-rw-r--r--klibc/klibc/getpriority.c12
-rw-r--r--klibc/klibc/include/alloca.h13
-rw-r--r--klibc/klibc/include/arpa/inet.h24
-rw-r--r--klibc/klibc/include/assert.h22
-rw-r--r--klibc/klibc/include/bits32/bitsize/limits.h14
-rw-r--r--klibc/klibc/include/bits32/bitsize/stddef.h18
-rw-r--r--klibc/klibc/include/bits32/bitsize/stdint.h34
-rw-r--r--klibc/klibc/include/bits32/bitsize/stdintconst.h18
-rw-r--r--klibc/klibc/include/bits32/bitsize/stdintlimits.h22
-rw-r--r--klibc/klibc/include/bits64/bitsize/limits.h14
-rw-r--r--klibc/klibc/include/bits64/bitsize/stddef.h13
-rw-r--r--klibc/klibc/include/bits64/bitsize/stdint.h36
-rw-r--r--klibc/klibc/include/bits64/bitsize/stdintconst.h18
-rw-r--r--klibc/klibc/include/bits64/bitsize/stdintlimits.h22
-rw-r--r--klibc/klibc/include/ctype.h118
-rw-r--r--klibc/klibc/include/dirent.h20
-rw-r--r--klibc/klibc/include/elf.h12
-rw-r--r--klibc/klibc/include/endian.h42
-rw-r--r--klibc/klibc/include/errno.h8
-rw-r--r--klibc/klibc/include/fcntl.h11
-rw-r--r--klibc/klibc/include/grp.h13
-rw-r--r--klibc/klibc/include/inttypes.h226
-rw-r--r--klibc/klibc/include/klibc/compiler.h106
-rw-r--r--klibc/klibc/include/klibc/diverr.h16
-rw-r--r--klibc/klibc/include/klibc/extern.h14
-rw-r--r--klibc/klibc/include/limits.h40
-rw-r--r--klibc/klibc/include/net/if.h1
-rw-r--r--klibc/klibc/include/net/if_arp.h1
-rw-r--r--klibc/klibc/include/net/if_ether.h1
-rw-r--r--klibc/klibc/include/net/if_packet.h1
-rw-r--r--klibc/klibc/include/netinet/in.h33
-rw-r--r--klibc/klibc/include/netinet/in6.h10
-rw-r--r--klibc/klibc/include/netinet/ip.h13
-rw-r--r--klibc/klibc/include/netinet/tcp.h11
-rw-r--r--klibc/klibc/include/netinet/udp.h19
-rw-r--r--klibc/klibc/include/poll.h16
-rw-r--r--klibc/klibc/include/sched.h23
-rw-r--r--klibc/klibc/include/setjmp.h43
-rw-r--r--klibc/klibc/include/signal.h80
-rw-r--r--klibc/klibc/include/stdarg.h14
-rw-r--r--klibc/klibc/include/stddef.h24
-rw-r--r--klibc/klibc/include/stdint.h116
-rw-r--r--klibc/klibc/include/stdio.h115
-rw-r--r--klibc/klibc/include/stdlib.h96
-rw-r--r--klibc/klibc/include/string.h40
-rw-r--r--klibc/klibc/include/sys/dirent.h13
-rw-r--r--klibc/klibc/include/sys/elf32.h115
-rw-r--r--klibc/klibc/include/sys/elf64.h115
-rw-r--r--klibc/klibc/include/sys/elfcommon.h186
-rw-r--r--klibc/klibc/include/sys/fsuid.h14
-rw-r--r--klibc/klibc/include/sys/ioctl.h14
-rw-r--r--klibc/klibc/include/sys/klog.h24
-rw-r--r--klibc/klibc/include/sys/mman.h21
-rw-r--r--klibc/klibc/include/sys/mount.h55
-rw-r--r--klibc/klibc/include/sys/param.h11
-rw-r--r--klibc/klibc/include/sys/reboot.h25
-rw-r--r--klibc/klibc/include/sys/resource.h15
-rw-r--r--klibc/klibc/include/sys/select.h13
-rw-r--r--klibc/klibc/include/sys/socket.h50
-rw-r--r--klibc/klibc/include/sys/socketcalls.h28
-rw-r--r--klibc/klibc/include/sys/stat.h23
-rw-r--r--klibc/klibc/include/sys/syscall.h15
-rw-r--r--klibc/klibc/include/sys/sysinfo.h12
-rw-r--r--klibc/klibc/include/sys/sysmacros.h31
-rw-r--r--klibc/klibc/include/sys/time.h17
-rw-r--r--klibc/klibc/include/sys/types.h125
-rw-r--r--klibc/klibc/include/sys/uio.h15
-rw-r--r--klibc/klibc/include/sys/un.h10
-rw-r--r--klibc/klibc/include/sys/utime.h10
-rw-r--r--klibc/klibc/include/sys/utsname.h23
-rw-r--r--klibc/klibc/include/sys/vfs.h14
-rw-r--r--klibc/klibc/include/sys/wait.h28
-rw-r--r--klibc/klibc/include/syslog.h55
-rw-r--r--klibc/klibc/include/termios.h86
-rw-r--r--klibc/klibc/include/time.h14
-rw-r--r--klibc/klibc/include/unistd.h122
-rw-r--r--klibc/klibc/include/utime.h15
-rw-r--r--klibc/klibc/inet/bindresvport.c21
-rw-r--r--klibc/klibc/interp.S4
-rw-r--r--klibc/klibc/jrand48.c24
-rw-r--r--klibc/klibc/libc_init.c86
-rw-r--r--klibc/klibc/llseek.c25
-rw-r--r--klibc/klibc/lrand48.c32
-rw-r--r--klibc/klibc/makeerrlist.pl21
-rw-r--r--klibc/klibc/malloc.c7
-rw-r--r--klibc/klibc/malloc.h8
-rw-r--r--klibc/klibc/mmap.c34
-rw-r--r--klibc/klibc/mrand48.c13
-rw-r--r--klibc/klibc/nice.c6
-rw-r--r--klibc/klibc/nrand48.c11
-rw-r--r--klibc/klibc/open.c22
-rw-r--r--klibc/klibc/pause.c6
-rw-r--r--klibc/klibc/perror.c3
-rw-r--r--klibc/klibc/putchar.c15
-rw-r--r--klibc/klibc/qsort.c4
-rw-r--r--klibc/klibc/readdir.c23
-rw-r--r--klibc/klibc/sbrk.c30
-rw-r--r--klibc/klibc/seed48.c2
-rw-r--r--klibc/klibc/select.c9
-rw-r--r--klibc/klibc/setresgid.c29
-rw-r--r--klibc/klibc/setresuid.c30
-rw-r--r--klibc/klibc/sha1hash.c2
-rw-r--r--klibc/klibc/sigaction.c6
-rw-r--r--klibc/klibc/sigpending.c6
-rw-r--r--klibc/klibc/sigprocmask.c6
-rw-r--r--klibc/klibc/sigsuspend.c6
-rw-r--r--klibc/klibc/socketcalls.pl61
-rw-r--r--klibc/klibc/socketcommon.h11
-rw-r--r--klibc/klibc/srand48.c3
-rw-r--r--klibc/klibc/statfs.c19
-rw-r--r--klibc/klibc/strerror.c20
-rw-r--r--klibc/klibc/strlcat.c31
-rw-r--r--klibc/klibc/strlcpy.c26
-rw-r--r--klibc/klibc/strncat.c16
-rw-r--r--klibc/klibc/strncpy.c8
-rw-r--r--klibc/klibc/strnlen.c19
-rw-r--r--klibc/klibc/strtotimespec.c5
-rw-r--r--klibc/klibc/strtotimeval.c5
-rw-r--r--klibc/klibc/strtotimex.c39
-rw-r--r--klibc/klibc/syscalls.pl129
-rw-r--r--klibc/klibc/syslog.c19
-rw-r--r--klibc/klibc/tests/fcntl.c53
-rw-r--r--klibc/klibc/tests/getpagesize.c11
-rw-r--r--klibc/klibc/tests/malloctest2.c60
-rw-r--r--klibc/klibc/tests/microhello.c2
-rw-r--r--klibc/klibc/tests/minips.c453
-rw-r--r--klibc/klibc/tests/mmaptest.c28
-rw-r--r--klibc/klibc/tests/opentest.c17
-rw-r--r--klibc/klibc/tests/stat.c65
-rw-r--r--klibc/klibc/tests/statfs.c43
-rw-r--r--klibc/klibc/tests/strtoimax.c24
-rw-r--r--klibc/klibc/tests/strtotime.c27
-rw-r--r--klibc/klibc/time.c6
-rw-r--r--klibc/klibc/utime.c8
-rw-r--r--klibc/klibc/vasprintf.c25
-rw-r--r--klibc/version2
288 files changed, 3419 insertions, 6726 deletions
diff --git a/klibc/MCONFIG b/klibc/MCONFIG
index ec8b65c0e4..d2aa23626c 100644
--- a/klibc/MCONFIG
+++ b/klibc/MCONFIG
@@ -3,22 +3,29 @@
# Makefile configuration, without explicit rules
#
+# Eventually support separate compilation, but we don't have it yet...
+OBJROOT = $(SRCROOT)
+
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$(KERNEL_DIR)/include
+KLIBOBJ = $(OBJROOT)/klibc
+REQFLAGS = $(ARCHREQFLAGS) -nostdinc -iwithprefix include \
+ -D__KLIBC__ -DBITSIZE=$(BITSIZE) \
+ -I$(SRCROOT)/include/arch/$(ARCH) \
+ -I$(SRCROOT)/include/bits$(BITSIZE) \
+ -I$(SRCROOT)/include \
+ -I$(SRCROOT)/linux/include -I$(SRCROOT)/linux/include2
+
LDFLAGS =
AR = $(CROSS)ar
RANLIB = $(CROSS)ranlib
NM = $(CROSS)nm
PERL = perl
STRIP = $(CROSS)strip --strip-all -R .comment -R .note
+OBJCOPY = $(CROSS)objcopy
HOST_CC = gcc
HOST_CFLAGS = -g -O
@@ -26,13 +33,13 @@ HOST_LDFLAGS =
HOST_LIBS =
# Static library paths
-CRT0 = $(KLIBSRC)/crt0.o
-KLIBC = $(KLIBSRC)/libc.a
+CRT0 = $(KLIBOBJ)/crt0.o
+KLIBC = $(KLIBOBJ)/libc.a
LIBGCC = $(shell $(CC) --print-libgcc)
# Shared library paths
-CRTSHARED = $(KLIBSRC)/interp.o
-LIBSHARED = $(KLIBSRC)/libc.so
+CRTSHARED = $(KLIBOBJ)/interp.o
+LIBSHARED = $(KLIBOBJ)/libc.so
#
# This indicates the location of the final version of the shared library.
@@ -41,7 +48,15 @@ LIBSHARED = $(KLIBSRC)/libc.so
#
SHLIBDIR = /lib
+# Enable this to make perror/strerror return real error messages
+# This makes klibc.so and any static binary which uses these functions
+# about 4K bigger.
+ERRLIST = 1
+
#
# Include arch-specific rule fragments
#
include $(KLIBSRC)/arch/$(ARCH)/MCONFIG
+
+# How to tell the linker main() is the entrypoint
+EMAIN ?= -e main
diff --git a/klibc/Makefile b/klibc/Makefile
index ef5fbabff8..8823a33bfd 100644
--- a/klibc/Makefile
+++ b/klibc/Makefile
@@ -10,7 +10,7 @@ klibc.spec: klibc.spec.in version
.PHONY: rpm
rpm: klibc.spec
- +$(rpmbuild) -bb klibc.spec
+ +$(rpmbuild) -bb klibc.spec --target=$(ARCH)
%:
@set -e; for d in $(SUBDIRS); do $(MAKE) -C $$d $@; done
diff --git a/klibc/README b/klibc/README
index 4381364874..eb72e1c239 100644
--- a/klibc/README
+++ b/klibc/README
@@ -1,4 +1,5 @@
-Please see klibc/README for build instructions.
+Please see klibc/README for build instructions and for the status of
+various platforms.
diff --git a/klibc/klibc.spec b/klibc/klibc.spec
new file mode 100644
index 0000000000..6166a35c4d
--- /dev/null
+++ b/klibc/klibc.spec
@@ -0,0 +1,157 @@
+Summary: A minimal libc subset for use with initramfs.
+Name: klibc
+Version: 0.181
+Release: 1
+License: BSD/GPL
+Group: Development/Libraries
+URL: http://www.zytor.com/mailman/listinfo/klibc
+Source: http://www.kernel.org/pub/linux/libs/klibc-%{version}.tar.gz
+BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-buildroot
+BuildRequires: kernel-source >= 2.6.0
+Packager: H. Peter Anvin <hpa@zytor.com>
+Prefix: /usr
+Vendor: Starving Linux Artists
+
+%description
+%{name} is intended to be a minimalistic libc subset for use with
+initramfs. It is deliberately written for small size, minimal
+entanglement, and portability, not speed. It is definitely a work in
+progress, and a lot of things are still missing.
+
+%package kernheaders
+Summary: Kernel headers used during the build of klibc.
+Group: Development/Libraries
+
+%description kernheaders
+This package contains the set of kernel headers that were required to
+build %{name} and the utilities that ship with it. This may or may
+not be a complete enough set to build other programs that link against
+%{name}. If in doubt, use real kernel headers instead.
+
+%package utils
+Summary: Small statically-linked utilities built with klibc.
+Group: Utilities/System
+
+%description utils
+
+This package contains a collection of programs that are statically
+linked against klibc. These duplicate some of the functionality of a
+regular Linux toolset, but are typically much smaller than their
+full-function counterparts. They are intended for inclusion in
+initramfs images and embedded systems.
+
+%prep
+%setup -q
+cp -as /usr/src/linux-`rpm -q kernel-source | tail -1 | cut -d- -f3-` ./linux
+make -C linux defconfig ARCH=%{_target_cpu}
+make -C linux prepare ARCH=%{_target_cpu}
+# Deal with braindamage in RedHat's kernel-source RPM
+rm -f linux/include/linux/config.h
+cat <<EOF > linux/include/linux/config.h
+#ifndef _LINUX_CONFIG_H
+#define _LINUX_CONFIG_H
+
+#include <linux/autoconf.h>
+
+#endif
+EOF
+mkdir -p %{buildroot}
+
+%build
+make ARCH=%{_target_cpu}
+
+%install
+rm -rf %{buildroot}
+
+dest=%{buildroot}/%{prefix}
+lib=$dest/%{_lib}/klibc
+inc=$dest/include/klibc
+exe=$dest/libexec/klibc
+doc=$dest/share/doc/%{name}-%{version}
+udoc=$dest/share/doc/%{name}-utils-%{version}
+
+# First, the library.
+
+install -dD -m 755 $lib $inc/kernel $exe $doc $udoc
+install -m 755 klibc/klibc.so $lib
+install -m 644 klibc/libc.a $lib
+install -m 644 klibc/crt0.o $lib
+install -m 644 klibc/libc.so.hash $lib
+ln $lib/klibc.so $lib/libc.so
+ln $lib/klibc.so $lib/klibc-$(cat $lib/libc.so.hash).so
+
+# Next, the generated binaries.
+# These are currently static binaries, should we go for shared?
+
+install -m 755 ash/sh $exe
+install -m 755 gzip/gzip $exe
+ln $exe/gzip $exe/gunzip
+ln $exe/gzip $exe/zcat
+install -m 755 ipconfig/ipconfig $exe
+install -m 755 kinit/kinit $exe
+install -m 755 nfsmount/nfsmount $exe
+install -m 755 utils/static/* $exe
+
+# The docs.
+
+install -m 444 README $doc
+install -m 444 klibc/README $doc/README.klibc
+install -m 444 klibc/arch/README $doc/README.klibc.arch
+
+install -m 444 gzip/COPYING $udoc/COPYING.gzip
+install -m 444 gzip/README $udoc/README.gzip
+install -m 444 ipconfig/README $udoc/README.ipconfig
+install -m 444 kinit/README $udoc/README.kinit
+
+# Finally, the include files.
+
+bitsize=$(make --no-print-directory -C klibc bitsize ARCH=%{_target_cpu})
+cp --parents $(find klibc/include \( -name CVS -o -name SCCS \) -prune \
+ -o -name '*.h' -print) $inc
+mv $inc/klibc $inc/klibc.$$
+mv $inc/klibc.$$/include/* $inc
+mv $inc/bits$bitsize/bitsize $inc
+rm -rf $inc/klibc.$$ $inc/bits[0-9]*
+pushd klibc/arch/%{_arch}/include
+cp --parents -f $(find . \( -name CVS -o -name SCCS \) -prune \
+ -o -name '*.h' -print) $inc
+popd
+
+# Yeugh. Find the transitive closure over all kernel headers included
+# by klibc, and copy them into place.
+
+find . -name '.*.d' | xargs -r sed -e 's,[ \t][ \t]*,\n,g' | sed -n -e 's,^\.\./linux/include/,,p' | sort | uniq | (cd linux/include && xargs -ri cp --parents '{}' $inc/kernel)
+
+%clean
+rm -rf $RPM_BUILD_ROOT
+
+%files
+%defattr(-,root,root,-)
+%docdir %{prefix}/share/doc/%{name}-%{version}
+%{prefix}/%{_lib}/klibc
+%dir %{prefix}/include/klibc
+%{prefix}/include/klibc/*.h
+%{prefix}/include/klibc/arpa
+%{prefix}/include/klibc/bitsize
+%{prefix}/include/klibc/klibc
+%{prefix}/include/klibc/net
+%{prefix}/include/klibc/netinet
+%{prefix}/include/klibc/sys
+%{prefix}/share/doc/%{name}-%{version}
+
+%files kernheaders
+%defattr(-,root,root,-)
+%{prefix}/include/klibc/kernel
+
+%files utils
+%defattr(-,root,root,-)
+%{prefix}/libexec/klibc
+%docdir %{prefix}/share/doc/%{name}-utils-%{version}
+%{prefix}/share/doc/%{name}-utils-%{version}
+
+%changelog
+* Tue Jul 6 2004 H. Peter Anvin <hpa@zytor.com>
+- Update to use kernel-source RPM for the kernel symlink.
+
+* Sat Nov 29 2003 Bryan O'Sullivan <bos@serpentine.com> -
+- Initial build.
diff --git a/klibc/klibc.spec.in b/klibc/klibc.spec.in
index f8bccc390e..8f5b2618d0 100644
--- a/klibc/klibc.spec.in
+++ b/klibc/klibc.spec.in
@@ -1,16 +1,14 @@
-%define _rpmdir rpms
-%define _builddir .
-
Summary: A minimal libc subset for use with initramfs.
Name: klibc
-Version: 0.89
+Version: @@VERSION@@
Release: 1
License: BSD/GPL
Group: Development/Libraries
-URL: http://www.zytor.com/klibc
-Source: /dev/null
+URL: http://www.zytor.com/mailman/listinfo/klibc
+Source: http://www.kernel.org/pub/linux/libs/klibc-%{version}.tar.gz
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-buildroot
-Packager: Bryan O'Sullivan <bos@serpentine.com>
+BuildRequires: kernel-source >= 2.6.0
+Packager: H. Peter Anvin <hpa@zytor.com>
Prefix: /usr
Vendor: Starving Linux Artists
@@ -43,18 +41,24 @@ full-function counterparts. They are intended for inclusion in
initramfs images and embedded systems.
%prep
-if [ ! -L linux ]; then
- echo "*** You must have a symlink named linux to build klibc" 1>&2
- exit 1
-fi
-if [ ! -f linux/include/asm/page.h ]; then
- echo "*** You need to 'make prepare' in the linux tree before building klibc" 1>&2
- exit 1
-fi
-mkdir -p %{buildroot} %{_rpmdir}
+%setup -q
+cp -as /usr/src/linux-`rpm -q kernel-source | tail -1 | cut -d- -f3-` ./linux
+make -C linux defconfig ARCH=%{_target_cpu}
+make -C linux prepare ARCH=%{_target_cpu}
+# Deal with braindamage in RedHat's kernel-source RPM
+rm -f linux/include/linux/config.h
+cat <<EOF > linux/include/linux/config.h
+#ifndef _LINUX_CONFIG_H
+#define _LINUX_CONFIG_H
+
+#include <linux/autoconf.h>
+
+#endif
+EOF
+mkdir -p %{buildroot}
%build
-make
+make ARCH=%{_target_cpu}
%install
rm -rf %{buildroot}
@@ -77,6 +81,7 @@ ln $lib/klibc.so $lib/libc.so
ln $lib/klibc.so $lib/klibc-$(cat $lib/libc.so.hash).so
# Next, the generated binaries.
+# These are currently static binaries, should we go for shared?
install -m 755 ash/sh $exe
install -m 755 gzip/gzip $exe
@@ -85,9 +90,7 @@ ln $exe/gzip $exe/zcat
install -m 755 ipconfig/ipconfig $exe
install -m 755 kinit/kinit $exe
install -m 755 nfsmount/nfsmount $exe
-for i in chroot dd fstype mkdir mkfifo mount umount; do
- install -m 755 utils/$i $exe
-done
+install -m 755 utils/static/* $exe
# The docs.
@@ -102,7 +105,7 @@ install -m 444 kinit/README $udoc/README.kinit
# Finally, the include files.
-bitsize=$(make --no-print-directory -C klibc bitsize)
+bitsize=$(make --no-print-directory -C klibc bitsize ARCH=%{_target_cpu})
cp --parents $(find klibc/include \( -name CVS -o -name SCCS \) -prune \
-o -name '*.h' -print) $inc
mv $inc/klibc $inc/klibc.$$
@@ -147,5 +150,8 @@ rm -rf $RPM_BUILD_ROOT
%{prefix}/share/doc/%{name}-utils-%{version}
%changelog
+* Tue Jul 6 2004 H. Peter Anvin <hpa@zytor.com>
+- Update to use kernel-source RPM for the kernel symlink.
+
* Sat Nov 29 2003 Bryan O'Sullivan <bos@serpentine.com> -
- Initial build.
diff --git a/klibc/klibc/MCONFIG b/klibc/klibc/MCONFIG
index 253a9461b7..5b6eecd037 100644
--- a/klibc/klibc/MCONFIG
+++ b/klibc/klibc/MCONFIG
@@ -8,6 +8,11 @@ include ../MCONFIG
include ../MRULES
WARNFLAGS = -W -Wall -Wpointer-arith -Wwrite-strings -Wstrict-prototypes -Winline
+
+ifeq ($(ERRLIST),1)
+REQFLAGS += -DWITH_ERRLIST
+endif
+
CFLAGS = -Wp,-MD,$(dir $*).$(notdir $*).d $(OPTFLAGS) $(REQFLAGS) $(WARNFLAGS)
SOFLAGS = -fPIC
diff --git a/klibc/klibc/Makefile b/klibc/klibc/Makefile
index 7ed03a8e87..d7e75f1814 100644
--- a/klibc/klibc/Makefile
+++ b/klibc/klibc/Makefile
@@ -10,6 +10,7 @@ include MCONFIG
TESTS = $(patsubst %.c,%,$(wildcard tests/*.c)) \
$(patsubst %.c,%.shared,$(wildcard tests/*.c))
LIBOBJS = vsnprintf.o snprintf.o vsprintf.o sprintf.o \
+ asprintf.o vasprintf.o \
vsscanf.o sscanf.o ctypes.o \
strntoumax.o strntoimax.o \
atoi.o atol.o atoll.o \
@@ -18,41 +19,51 @@ LIBOBJS = vsnprintf.o snprintf.o vsprintf.o sprintf.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 getpgrp.o \
- open.o \
+ daemon.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 \
+ statfs.o fstatfs.o umount.o \
+ open.o fopen.o fread.o fread2.o fgetc.o fgets.o \
+ fwrite.o fwrite2.o fputc.o fputs.o puts.o putchar.o \
+ sleep.o usleep.o strtotimespec.o strtotimeval.o \
+ raise.o abort.o assert.o alarm.o pause.o \
__signal.o sysv_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 getpagesize.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 \
+ memmove.o memchr.o \
strcasecmp.o strncasecmp.o strndup.o strerror.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 \
+ strcat.o strchr.o strcmp.o strcpy.o strdup.o strlen.o strnlen.o \
+ strncat.o strlcpy.o strlcat.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 \
+ seteuid.o setegid.o \
getenv.o setenv.o putenv.o __put_env.o unsetenv.o \
getopt.o readdir.o \
syslog.o closelog.o pty.o getpt.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 \
+ time.o utime.o llseek.o nice.o getpriority.o \
+ qsort.o \
+ lrand48.o jrand48.o mrand48.o nrand48.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
+ifeq ($(ERRLIST),1)
+LIBOBJS += errlist.o
+endif
+
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
+INTERP_O = interp.o
+
+all: tests $(CRT0) $(LIB) $(SOLIB) klibc.so
# Add any architecture-specific rules
include arch/$(ARCH)/Makefile.inc
+EMAIN ?= -e main
tests: $(TESTS)
@@ -71,19 +82,20 @@ tests/% : tests/%.o $(LIB) $(CRT0)
$(STRIP) $@.stripped
tests/%.shared : tests/%.o interp.o $(SOLIB)
- $(LD) $(LDFLAGS) -o $@ -e main interp.o tests/$*.o -R $(SOLIB) $(LIBGCC)
+ $(LD) $(LDFLAGS) -o $@ $(EMAIN) 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
+ $(AR) cq $(LIB) __static_init.o $(LIBOBJS) $(ARCHOBJS) \
+ $(wildcard syscalls/*.o) $(wildcard 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 \
+ $(wildcard syscalls/*.o) $(wildcard socketcalls/*.o) \
$(LIBGCC)
sha1hash: sha1hash.c
@@ -99,7 +111,7 @@ $(SOHASH): $(SOLIB) $(SOLIB).hash
rm -f klibc-??????????????????????.so
ln -f $@ klibc-`cat $(SOLIB).hash`.so
-interp.o: interp.S $(SOLIB).hash
+$(INTERP_O): interp.S $(SOLIB).hash
$(CC) $(CFLAGS) -D__ASSEMBLY__ -DLIBDIR=\"$(SHLIBDIR)\" \
-DSOHASH=\"`cat $(SOLIB).hash`\" \
-c -o $@ $<
@@ -107,16 +119,29 @@ interp.o: interp.S $(SOLIB).hash
crt0.o: arch/$(ARCH)/crt0.o
cp arch/$(ARCH)/crt0.o .
-syscalls.dir: SYSCALLS syscalls.pl syscommon.h
+errlist.c:
+ $(PERL) makeerrlist.pl -errlist > $@ || rm -f $@
+
+# We pass -ansi to keep cpp from define e.g. "i386" as well as "__i386__"
+SYSCALLS.i: SYSCALLS.def
+ $(CC) $(CFLAGS) -D__ASSEMBLY__ -ansi -x assembler-with-cpp -E -o $@ $<
+
+syscalls.nrs: ../include/sys/syscall.h ../include/arch/$(ARCH)/klibc/archsys.h ../linux/include/asm/unistd.h
+ $(CC) $(CFLAGS) -Wp,-dM -x c -E -o $@ ../include/sys/syscall.h
+
+syscalls.dir: SYSCALLS.i syscalls.pl arch/$(ARCH)/sysstub.ph syscommon.h syscalls.nrs
rm -rf syscalls
mkdir syscalls
- $(PERL) syscalls.pl $(ARCH) SYSCALLS
+ $(PERL) syscalls.pl SYSCALLS.i $(ARCH) $(BITSIZE) syscalls.nrs ../include/klibc/havesyscall.h
touch $@
-socketcalls.dir: SOCKETCALLS socketcalls.pl socketcommon.h
+../include/klibc/havesyscall.h: syscalls.dir
+ : Generated by side effect
+
+socketcalls.dir: SOCKETCALLS.def socketcalls.pl socketcommon.h
rm -rf socketcalls
mkdir socketcalls
- $(PERL) socketcalls.pl $(ARCH) SOCKETCALLS
+ $(PERL) socketcalls.pl SOCKETCALLS.def $(ARCH)
touch $@
%/static.obj: %.dir
@@ -133,9 +158,10 @@ clean: archclean
rm -f $(TESTS) tests/*.stripped
rm -rf syscalls syscalls.dir
rm -rf socketcalls socketcalls.dir
- rm -f sha1hash
+ rm -f sha1hash errlist.c
spotless: clean
+ rm -f ../include/klibc/havesyscall.h syscalls.nrs
find . \( -name \*~ -o -name '.*.d' \) -not -type d -print0 | \
xargs -0rt rm -f
diff --git a/klibc/klibc/README b/klibc/klibc/README
index d69fa8de41..edc8524f22 100644
--- a/klibc/klibc/README
+++ b/klibc/klibc/README
@@ -1,6 +1,6 @@
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
+minimal entaglement, and portability, not speed. It is definitely a
work in progress, and a lot of things are still missing.
@@ -34,20 +34,38 @@ b) If you're cross-compiling, change ARCH in the main MCONFIG file to
The following is the last known status of various architectures:
- Known to work: alpha arm ia64 i386 ppc s390 s390x sparc
- sparc64 x86_64*
- Works static, not shared: mips* arm-thumb sh* parisc
- Might work: ppc64
- Need porting work: cris m68k mips64 v850
-
- x86_64: requires a kernel header patch (to be created)
- mips, sh: linker problem; might work with fixed linker
-
- Shared library support requires binutils 2.13.90.0.4 or later on
- many architectures.
-
- Note that even the "known to work" ones likely have bugs. Please
- report them if you run into them.
+ alpha: Working static, shared untested
+ arm-thumb: Untested
+ arm26: Not yet ported
+ arm: Working
+ cris: Untested
+ h8300: Not yet ported
+ i386: Working
+ ia64: Working
+ m68k: Not yet ported
+ mips64: Not yet ported
+ mips: Working
+ parisc: Untested
+ ppc64: Working
+ ppc: Working
+ s390: Working static, shared untested
+ s390x: Working
+ sh: Untested
+ sparc64: sigaction() fails in ash for unknown reason
+ sparc: Working
+ v850: Not yet ported
+ x86-64: Working
+
+ Shared library support requires recent binutils on many
+ architectures.
+
+ "Need sysstub.ph" means the architectural changes first implemented
+ in klibc-0.117 has not yet been implemented; klibc-0.116 did,
+ however, work. "Not yet ported" means no porting work has been
+ done on this architecture.
+
+ Note that even the "working" ones likely have bugs. Please report
+ them if you run into them.
c) Type "make" and pray...
diff --git a/klibc/klibc/SOCKETCALLS b/klibc/klibc/SOCKETCALLS
deleted file mode 100644
index 1ab4e367a2..0000000000
--- a/klibc/klibc/SOCKETCALLS
+++ /dev/null
@@ -1,21 +0,0 @@
-# -*- 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)
diff --git a/klibc/klibc/SOCKETCALLS.def b/klibc/klibc/SOCKETCALLS.def
new file mode 100644
index 0000000000..e70b3fc16e
--- /dev/null
+++ b/klibc/klibc/SOCKETCALLS.def
@@ -0,0 +1,21 @@
+; -*- fundamental -*-
+;
+; These are calls that are invoked via the socketcall mechanism
+; Note that on most architectures this is simply #included into
+; SYSCALLS.def.
+;
+<?> 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 sendto(int, const void *, size_t, int, const struct sockaddr *, socklen_t)
+<?> 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)
diff --git a/klibc/klibc/SYSCALLS b/klibc/klibc/SYSCALLS
deleted file mode 100644
index 82081201b4..0000000000
--- a/klibc/klibc/SYSCALLS
+++ /dev/null
@@ -1,153 +0,0 @@
-# -*- 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,ia64> 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()
-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 fchmod(int, mode_t)
-int mkdir(const char *, mode_t)
-int rmdir(const char *)
-<!alpha,ia64,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 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)
-int ftruncate(int, off_t)
-
-#
-# 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)
-long init_module(void *, unsigned long, const char *)
-long delete_module(const char *, unsigned int)
-<!ia64> int query_module(const char *, int, void *, size_t, size_t)
-int reboot::__reboot(int, int, int, void *)
-int syslog::klogctl(int, char *, int)
-int sysinfo(struct sysinfo *)
-
-#
-# Low-level I/O (generally architecture-specific)
-#
-<i386,x86_64> int iopl(int)
-<i386,x86_64> int ioperm(unsigned long, unsigned long, int)
-<i386> int vm86(struct vm86_struct *)
diff --git a/klibc/klibc/SYSCALLS.def b/klibc/klibc/SYSCALLS.def
new file mode 100644
index 0000000000..dbd7dc8434
--- /dev/null
+++ b/klibc/klibc/SYSCALLS.def
@@ -0,0 +1,207 @@
+; -*- fundamental -*-
+;
+; This is a list of system calls we invoke "directly". These
+; are generated into syscall stubs in their own files, so the
+; linker can do its job properly.
+;
+; The full description of a line is:
+; [<[?][!]arch,...>] type [sysname,...][@systype][::funcname](args)
+;
+; ? means only instantiate this system call if present in asm/unistd.h
+;
+
+#include <asm/unistd.h>
+
+;
+; Process-related syscalls
+;
+<?!ia64> pid_t clone::__clone(unsigned long, void *)
+<?ia64> pid_t clone::__clone2(unsigned long, void *, void *)
+<?!sparc> pid_t fork()
+<sparc> pid_t fork@forkish()
+<!mips,mips64,sparc,ia64> 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()
+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 nice(int)
+<alpha,ia64> int getpriority(int, int)
+<!alpha,ia64> int getpriority::__getpriority(int, int)
+int setpriority(int, int, int)
+int sched_setscheduler(pid_t, int, const struct sched_param *)
+int sched_yield()
+
+;
+; User and group IDs
+;
+int setuid32,setuid::setuid(uid_t)
+int setgid32,setgid::setgid(gid_t)
+<!alpha> uid_t getuid32,getuid::getuid()
+<alpha> uid_t getxuid@dual0::getuid()
+<!alpha> gid_t getgid32,getgid::getgid()
+<alpha> gid_t getxgid@dual0::getgid()
+<!alpha> uid_t geteuid32,geteuid::geteuid()
+<alpha> uid_t getxuid@dual1::geteuid()
+<!alpha> gid_t getegid32,getegid::getegid()
+<alpha> gid_t getxgid@dual1::getegid()
+int getgroups32,getgroups::getgroups(int, gid_t *)
+int setgroups32,setgroups::setgroups(size_t, const gid_t *)
+int setreuid32,setreuid::setreuid(uid_t, uid_t)
+int setregid32,setregid::setregid(gid_t, gid_t)
+int setfsuid32,setfsuid::setfsuid(uid_t)
+int setfsgid32,setfsgid::setfsgid(gid_t)
+int setresuid32,setresuid::setresuid(int, uid_t, uid, uid_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()
+#ifdef __NR_statfs64
+int statfs64::__statfs64(const char *, size_t, struct statfs *)
+#else
+int statfs(const char *, struct statfs *)
+#endif
+#ifdef __NR_fstatfs64
+int fstatfs64::__fstatfs64(int, size_t, struct statfs *)
+#else
+int fstatfs(int, struct statfs *)
+#endif
+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 fchdir(int)
+int rename(const char *, const char *)
+int mknod(const char *, mode_t, dev_t)
+int chmod(const char *, mode_t)
+int fchmod(int, mode_t)
+int mkdir(const char *, mode_t)
+int rmdir(const char *)
+<!alpha,ia64,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 stat64,stat::stat(const char *, struct stat *)
+int lstat64,lstat::lstat(const char *, struct stat *)
+int fstat64,fstat::fstat(int, struct stat *)
+int getdents64,getdents::getdents(unsigned int, struct dirent *, unsigned int)
+int chown32,chown::chown(const char *, uid_t, gid_t)
+int fchown32,fchown::fchown(int, uid_t, gid_t)
+int lchown32,lchown::lchown(const char *, uid_t, gid_t)
+int getcwd::__getcwd(char *, size_t)
+<?> int utime(const char *, const struct utimbuf *)
+<?> int utimes(const char *, const struct timeval *)
+
+;
+; I/O operations
+;
+<!i386,64> int open::__open(const char *, int, mode_t)
+<64> int open(const char *, int, mode_t)
+ssize_t read(int, void *, size_t)
+ssize_t write(int, const void *, size_t)
+int close(int)
+<64> off_t lseek(int, off_t, int)
+<32> int _llseek::__llseek(int, unsigned long, unsigned long, off_t *, int)
+int dup(int)
+int dup2(int, int)
+<i386> int fcntl64@varadic::fcntl(int, int, unsigned long)
+<!i386> int fcntl64,fcntl::fcntl(int, int, unsigned long)
+int ioctl(int, int, void *)
+int flock(int, int)
+int _newselect,select::select(int, fd_set *, fd_set *, fd_set *, struct timeval *)
+int poll(struct pollfd *, nfds_t, long)
+int fsync(int)
+int fdatasync,fsync::fdatasync(int)
+int readv(int, const struct iovec *, int)
+int writev(int, const struct iovec *, int)
+int ftruncate64,ftruncate::ftruncate(int, off_t)
+ssize_t pread64,pread::pread(int, void *, size_t, off_t)
+ssize_t pwrite64,pwrite::pwrite(int, void *, size_t, off_t)
+
+;
+; Signal operations
+;
+int kill(pid_t, int)
+<?> int sigaction(int, const struct sigaction *, struct sigaction *)
+int rt_sigaction(int, const struct sigaction *, struct sigaction *, size_t)
+<?> int sigsuspend(const sigset_t *)
+int rt_sigsuspend(const sigset_t *, size_t)
+<?> int sigpending(sigset_t)
+int rt_sigpending(sigset_t *, size_t)
+<?> int sigprocmask(int, const sigset_t *, sigset_t *)
+int rt_sigprocmask(int, const sigset_t *, sigset_t *, size_t)
+<?> unsigned int alarm(unsigned int)
+int getitimer(int, struct itimerval *)
+int setitimer(int, const struct itimerval *, struct itimerval *)
+
+;
+; Time-related system calls
+;
+<?> time_t time(time_t *)
+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 *)
+<?> int pause()
+
+;
+; 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)
+#if (BITSIZE == 32 && defined(__NR_mmap2)) || (BITSIZE == 64 && !defined(__NR_mmap))
+<!s390> void * mmap2::__mmap2(void *, size_t, int, int, int, long)
+#else
+<!s390x> void * mmap(void *, size_t, int, int, int, long)
+#endif
+int mlockall(int)
+int munlockall()
+int mlock(const void *, size_t)
+int munlock(const void *, size_t)
+
+;
+; System stuff
+;
+int uname(struct utsname *)
+int setdomainname(const char *, size_t)
+int sethostname(const char *, size_t)
+long init_module(void *, unsigned long, const char *)
+long delete_module(const char *, unsigned int)
+int reboot::__reboot(int, int, int, void *)
+int syslog::klogctl(int, char *, int)
+int sysinfo(struct sysinfo *)
+
+;
+; Low-level I/O (generally architecture-specific)
+;
+<i386,x86_64> int iopl(int)
+<i386,x86_64> int ioperm(unsigned long, unsigned long, int)
+<i386> int vm86(struct vm86_struct *)
+
+;
+; Most architectures have the socket interfaces using regular
+; system calls.
+;
+<?!i386> long socketcall::__socketcall(int, const unsigned long *)
+#include "SOCKETCALLS.def"
diff --git a/klibc/klibc/__shared_init.c b/klibc/klibc/__shared_init.c
index 63e3f4644e..592a3db6f5 100644
--- a/klibc/klibc/__shared_init.c
+++ b/klibc/klibc/__shared_init.c
@@ -1,56 +1,2 @@
-/*
- * __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));
-}
-
-
+#define SHARED 1
+#include "libc_init.c"
diff --git a/klibc/klibc/__static_init.c b/klibc/klibc/__static_init.c
index 5a90b5cd88..0b59eedaa7 100644
--- a/klibc/klibc/__static_init.c
+++ b/klibc/klibc/__static_init.c
@@ -1,38 +1,2 @@
-/*
- * __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));
-}
+#define SHARED 0
+#include "libc_init.c"
diff --git a/klibc/klibc/alarm.c b/klibc/klibc/alarm.c
index ca7bb37f92..40c0969432 100644
--- a/klibc/klibc/alarm.c
+++ b/klibc/klibc/alarm.c
@@ -5,11 +5,7 @@
#include <sys/time.h>
#include <sys/syscall.h>
-#ifdef __NR_alarm
-
-_syscall1(unsigned int,alarm,unsigned int,seconds);
-
-#else
+#ifndef __NR_alarm
/* Emulate alarm() via setitimer() */
diff --git a/klibc/klibc/arch/alpha/Makefile.inc b/klibc/klibc/arch/alpha/Makefile.inc
index 2a1100f962..62fce9dc28 100644
--- a/klibc/klibc/arch/alpha/Makefile.inc
+++ b/klibc/klibc/arch/alpha/Makefile.inc
@@ -11,7 +11,7 @@
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-7 -fcall-saved-8 -ffixed-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
@@ -26,7 +26,9 @@ ARCHOBJS = \
arch/$(ARCH)/__divl.o \
arch/$(ARCH)/__reml.o \
arch/$(ARCH)/pipe.o \
- arch/$(ARCH)/setjmp.o
+ arch/$(ARCH)/setjmp.o \
+ arch/$(ARCH)/syscall.o \
+ arch/$(ARCH)/sysdual.o
ARCHSOOBJS = $(patsubst %.o,%.lo,$(ARCHOBJS))
diff --git a/klibc/klibc/arch/alpha/crt0.S b/klibc/klibc/arch/alpha/crt0.S
index 6c2958117d..904b539741 100644
--- a/klibc/klibc/arch/alpha/crt0.S
+++ b/klibc/klibc/arch/alpha/crt0.S
@@ -3,10 +3,10 @@
#
.text
- .type __start,@function
- .ent __start, 0
- .globl __start
-__start:
+ .type _start,@function
+ .ent _start, 0
+ .globl _start
+_start:
.frame $30, 0, $26, 0
mov $31, $15
br $29, 1f
@@ -18,4 +18,5 @@ __start:
jsr $26, __libc_init
- .size __start,.-__start
+ .size _start,.-_start
+ .end _start
diff --git a/klibc/klibc/arch/alpha/include/klibc/archsetjmp.h b/klibc/klibc/arch/alpha/include/klibc/archsetjmp.h
deleted file mode 100644
index 9dc570a6f5..0000000000
--- a/klibc/klibc/arch/alpha/include/klibc/archsetjmp.h
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * 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 */
diff --git a/klibc/klibc/arch/alpha/include/klibc/archsignal.h b/klibc/klibc/arch/alpha/include/klibc/archsignal.h
deleted file mode 100644
index b870a05131..0000000000
--- a/klibc/klibc/arch/alpha/include/klibc/archsignal.h
+++ /dev/null
@@ -1,13 +0,0 @@
-/*
- * arch/alpha/include/klibc/archsignal.h
- *
- * Architecture-specific signal definitions
- *
- */
-
-#ifndef _KLIBC_ARCHSIGNAL_H
-#define _KLIBC_ARCHSIGNAL_H
-
-/* No special stuff for this architecture */
-
-#endif
diff --git a/klibc/klibc/arch/alpha/include/klibc/archsys.h b/klibc/klibc/arch/alpha/include/klibc/archsys.h
deleted file mode 100644
index 16ed658987..0000000000
--- a/klibc/klibc/arch/alpha/include/klibc/archsys.h
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * 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 */
diff --git a/klibc/klibc/arch/alpha/include/machine/asm.h b/klibc/klibc/arch/alpha/include/machine/asm.h
deleted file mode 100644
index e22db90412..0000000000
--- a/klibc/klibc/arch/alpha/include/machine/asm.h
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * 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 */
diff --git a/klibc/klibc/arch/alpha/setjmp.S b/klibc/klibc/arch/alpha/setjmp.S
index e1ad642539..5d915f2dbe 100644
--- a/klibc/klibc/arch/alpha/setjmp.S
+++ b/klibc/klibc/arch/alpha/setjmp.S
@@ -31,14 +31,14 @@ setjmp:
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)
+ 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
@@ -59,14 +59,14 @@ longjmp:
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)
+ 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
diff --git a/klibc/klibc/arch/alpha/syscall.S b/klibc/klibc/arch/alpha/syscall.S
new file mode 100644
index 0000000000..0c87414b1a
--- /dev/null
+++ b/klibc/klibc/arch/alpha/syscall.S
@@ -0,0 +1,26 @@
+#
+# arch/alpha/syscall.S
+#
+
+#include <machine/asm.h>
+
+ .text
+ .align 3
+ .type __syscall_common,@function
+ .ent __syscall_common, 0
+ .globl __syscall_common
+__syscall_common:
+ .frame sp,0,ra,0
+ callsys
+ beq a3, 1f
+ br pv, 2f # pv <- pc
+2:
+ ldgp gp, 0(pv)
+ lda a1, errno
+ lda v0, -1(zero)
+ stl a3, 0(a1)
+1:
+ ret zero,(ra),1
+
+ .size __syscall_common,.-__syscall_common
+ .end __syscall_common
diff --git a/klibc/klibc/arch/alpha/sysdual.S b/klibc/klibc/arch/alpha/sysdual.S
new file mode 100644
index 0000000000..c00db88960
--- /dev/null
+++ b/klibc/klibc/arch/alpha/sysdual.S
@@ -0,0 +1,33 @@
+#
+# arch/alpha/sysdual.S
+#
+
+#
+# Some system calls have an alternate return value in r20 (a4).
+# This system call stub is for system calls where that is
+# the "real" return value.
+#
+
+#include <machine/asm.h>
+
+ .text
+ .align 3
+ .type __syscall_dual1,@function
+ .ent __syscall_dual1, 0
+ .globl __syscall_dual1
+__syscall_dual1:
+ .frame sp,0,ra,0
+ callsys
+ mov v0, a4
+ beq a3, 1f
+ br pv, 2f # pv <- pc
+2:
+ ldgp gp, 0(pv)
+ lda a1, errno
+ lda v0, -1(zero)
+ stl a3, 0(a1)
+1:
+ ret zero,(ra),1
+
+ .size __syscall_dual1,.-__syscall_dual1
+ .end __syscall_dual1
diff --git a/klibc/klibc/arch/alpha/sysstub.ph b/klibc/klibc/arch/alpha/sysstub.ph
new file mode 100644
index 0000000000..a24b6c07dc
--- /dev/null
+++ b/klibc/klibc/arch/alpha/sysstub.ph
@@ -0,0 +1,37 @@
+# -*- perl -*-
+#
+# arch/alpha/sysstub.ph
+#
+# Script to generate system call stubs
+#
+
+# On Alpha, most system calls follow the standard convention, with the
+# system call number in r0 (v0), return an error value in r19 (a3) as
+# well as the return value in r0 (v0).
+#
+# A few system calls are dual-return with the second return value in
+# r20 (a4).
+
+sub make_sysstub($$$$@) {
+ my($fname, $type, $sname, $stype, @args) = @_;
+
+ $stype = $stype || 'common';
+ $stype = 'common' if ( $stype eq 'dual0' );
+
+ open(OUT, '>', "syscalls/${fname}.S");
+ print OUT "#include <asm/unistd.h>\n";
+ print OUT "#include <machine/asm.h>\n";
+ print OUT "\n";
+ print OUT "\t.text\n";
+ print OUT "\t.type ${fname},\@function\n";
+ print OUT "\t.ent\t${fname}, 0\n"; # What is this?
+ print OUT "\t.globl ${fname}\n";
+ print OUT "${fname}:\n";
+ print OUT "\tlda\tv0, __NR_${sname}(zero)\n";
+ print OUT "\tbr __syscall_${stype}\n";
+ print OUT "\t.size\t${fname},.-${fname}\n";
+ print OUT "\t.end\t${fname}\n";
+ close(OUT);
+}
+
+1;
diff --git a/klibc/klibc/arch/arm/Makefile.inc b/klibc/klibc/arch/arm/Makefile.inc
index 3ec8c051b2..0603d850bd 100644
--- a/klibc/klibc/arch/arm/Makefile.inc
+++ b/klibc/klibc/arch/arm/Makefile.inc
@@ -17,7 +17,8 @@ ARCHOBJS = \
libgcc/__moddi3.o \
libgcc/__udivdi3.o \
libgcc/__umoddi3.o \
- libgcc/__udivmoddi4.o
+ libgcc/__udivmoddi4.o \
+ arch/arm/syscall.o
ifeq ($(THUMB),y)
ARCHOBJS += arch/arm/setjmp-thumb.o
@@ -26,6 +27,17 @@ else
ARCHOBJS += arch/arm/setjmp-arm.o
endif
+arch/arm/sysstubs.a: arch/arm/sysstubs.pl
+ mkdir -p arch/arm/sysstubs
+ $(PERL) $< arch/arm/sysstubs
+ $(MAKE) $(patsubst %.S,%.o,$(wildcard arch/arm/sysstubs/*.S))
+ -rm -f $@
+ $(AR) cq $@ arch/arm/sysstubs/*.o
+ $(RANLIB) $@
+
+
ARCHSOOBJS = $(patsubst %.o,%.lo,$(ARCHOBJS))
archclean:
+ -rm -rf arch/arm/sysstubs
+ -rm -f arch/arm/sysstubs.a
diff --git a/klibc/klibc/arch/arm/crt0.S b/klibc/klibc/arch/arm/crt0.S
index 8cd3640c30..fc1104ef0e 100644
--- a/klibc/klibc/arch/arm/crt0.S
+++ b/klibc/klibc/arch/arm/crt0.S
@@ -3,10 +3,8 @@
#
# void _start(void)
# {
-# /* Divine up argc, argv, and envp */
-# environ = envp;
-# exit(main(argc, argv, envp));
-# }
+# __libc_init(elf_structure, atexit_ptr);
+# }
#
.text
diff --git a/klibc/klibc/arch/arm/include/klibc/archsetjmp.h b/klibc/klibc/arch/arm/include/klibc/archsetjmp.h
deleted file mode 100644
index c956b50a90..0000000000
--- a/klibc/klibc/arch/arm/include/klibc/archsetjmp.h
+++ /dev/null
@@ -1,14 +0,0 @@
-/*
- * 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 */
diff --git a/klibc/klibc/arch/arm/include/klibc/archsignal.h b/klibc/klibc/arch/arm/include/klibc/archsignal.h
deleted file mode 100644
index 77685e62f0..0000000000
--- a/klibc/klibc/arch/arm/include/klibc/archsignal.h
+++ /dev/null
@@ -1,13 +0,0 @@
-/*
- * arch/arm/include/klibc/archsignal.h
- *
- * Architecture-specific signal definitions
- *
- */
-
-#ifndef _KLIBC_ARCHSIGNAL_H
-#define _KLIBC_ARCHSIGNAL_H
-
-/* No special stuff for this architecture */
-
-#endif
diff --git a/klibc/klibc/arch/arm/include/klibc/archsys.h b/klibc/klibc/arch/arm/include/klibc/archsys.h
deleted file mode 100644
index 1a77e53a65..0000000000
--- a/klibc/klibc/arch/arm/include/klibc/archsys.h
+++ /dev/null
@@ -1,12 +0,0 @@
-/*
- * 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 */
diff --git a/klibc/klibc/arch/arm/setjmp-arm.S b/klibc/klibc/arch/arm/setjmp-arm.S
index bcb30b4221..1a29ee7f71 100644
--- a/klibc/klibc/arch/arm/setjmp-arm.S
+++ b/klibc/klibc/arch/arm/setjmp-arm.S
@@ -34,7 +34,6 @@ setjmp:
.type longjmp, #function
longjmp:
ldmia r0, {r4, r5, r6, r7, r8, r9, r10, fp, sp, lr}
- movs r0, r1
- moveq r0, #1
+ mov r0, r1
mov pc, lr
.size longjmp,.-longjmp
diff --git a/klibc/klibc/arch/arm/syscall.S b/klibc/klibc/arch/arm/syscall.S
new file mode 100644
index 0000000000..0e73f68ed0
--- /dev/null
+++ b/klibc/klibc/arch/arm/syscall.S
@@ -0,0 +1,50 @@
+/*
+ * arch/arm/syscall.S
+ *
+ * System call common handling
+ */
+
+ .type __syscall_common,#function
+ .globl __syscall_common
+#ifndef __thumb__
+ /* ARM version - this is executed after the swi */
+
+ .align 4
+__syscall_common:
+ cmn r0, #4096
+ rsbcs r2, r0, #0
+ ldrcs r3, 1f
+ mvncs r0, #0
+ strcs r2, [r3]
+ ldmfd sp!,{r4,r5,pc}
+
+ .align 4
+1:
+ .word errno
+
+#else
+ /* Thumb version - must still load r4 and r5 and run swi */
+
+ .thumb_func
+ .align 2
+__syscall_common:
+ ldr r4, [sp #12]
+ ldr r5, [sp #16]
+ swi 0
+ ldr r1, 2f
+ cmp r0, r1
+ bcc 1f
+ ldr r1, 3f
+ neg r2, r0
+ mvn r0, #0
+ str r2, [r1]
+1:
+ pop {r4,r5,r7,pc}
+
+ .align 4
+2:
+ .word #-4095
+3:
+ .word errno
+
+#endif
diff --git a/klibc/klibc/arch/arm/sysstub.ph b/klibc/klibc/arch/arm/sysstub.ph
new file mode 100644
index 0000000000..bf953ccd80
--- /dev/null
+++ b/klibc/klibc/arch/arm/sysstub.ph
@@ -0,0 +1,44 @@
+# -*- perl -*-
+#
+# arch/arm/sysstub.ph
+#
+# Script to generate system call stubs
+#
+
+
+sub make_sysstub($$$$@) {
+ my($fname, $type, $sname, $stype, @args) = @_;
+
+ open(OUT, '>', "syscalls/${fname}.S");
+ print OUT "#include <asm/unistd.h>\n";
+
+ print OUT "\t.text\n";
+ print OUT "\t.type\t${fname}, #function\n";
+ print OUT "\t.globl ${fname}\n";
+ print OUT "\t.align\t4\n";
+
+ print OUT "#ifndef __thumb__\n";
+
+ # ARM version first
+ print OUT "${fname}:\n";
+ print OUT "\tstmfd\tsp!,{r4,r5,lr}\n";
+ print OUT "\tldr\tr4,[sp,#12]\n";
+ print OUT "\tldr\tr5,[sp,#16]\n";
+ print OUT "\tswi\t# __NR_${sname}\n";
+ print OUT "\tb\t__syscall_common\n";
+
+ print OUT "#else\n";
+
+ # Thumb version
+ print OUT "\t.thumb_func\n";
+ print OUT "${fname}:\n";
+ print OUT "\tpush\t{r4,r5,r7,pc}\n";
+ print OUT "\tmov\tr7, # __NR_${sname}\n";
+ print OUT "\tb\t__syscall_common\n";
+
+ print OUT "#endif\n";
+
+ print OUT "\t.size\t__syscall${i},.-__syscall${i}\n";
+}
+
+1;
diff --git a/klibc/klibc/arch/cris/MCONFIG b/klibc/klibc/arch/cris/MCONFIG
index 27809ebbe7..2762494a30 100644
--- a/klibc/klibc/arch/cris/MCONFIG
+++ b/klibc/klibc/arch/cris/MCONFIG
@@ -9,3 +9,18 @@
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
+# 224 MB - normal binaries start at 0
+# (lib?)gcc on cris seems to insist on producing .init and .fini sections
+SHAREDFLAGS = --section-start .init=0x0e000100
+
+# The CRIS compiler needs an -iprefix to find libgcc includes when
+# nostdinc is used. It also needs -mlinux to compile linux applications.
+INCLUDE_PREFIX = $(shell $(CC) -print-libgcc-file-name | sed -e s/libgcc.a//)
+ARCHREQFLAGS = -iprefix $(INCLUDE_PREFIX) -mlinux
+
+# Special flags needed for linking
+LDFLAGS += -mcrislinux
diff --git a/klibc/klibc/arch/cris/Makefile.inc b/klibc/klibc/arch/cris/Makefile.inc
index 41183fd64b..75fa17ba99 100644
--- a/klibc/klibc/arch/cris/Makefile.inc
+++ b/klibc/klibc/arch/cris/Makefile.inc
@@ -7,4 +7,27 @@
# accordingly.
#
+ARCHOBJS = \
+ arch/$(ARCH)/__Umod.o \
+ arch/$(ARCH)/__Udiv.o \
+ arch/$(ARCH)/__Mod.o \
+ arch/$(ARCH)/__Div.o \
+ arch/$(ARCH)/__negdi2.o \
+ arch/$(ARCH)/setjmp.o \
+ arch/$(ARCH)/syscall.o \
+ libgcc/__divdi3.o \
+ libgcc/__moddi3.o \
+ libgcc/__udivdi3.o \
+ libgcc/__umoddi3.o \
+ libgcc/__udivmoddi4.o
+
+arch/$(ARCH)/__Umod.o: arch/$(ARCH)/divide.c
+ $(CC) $(CFLAGS) -DSIGNED=0 -DREM=1 -DBITS=32 -DNAME=__Umod -c -o $@ $<
+arch/$(ARCH)/__Udiv.o: arch/$(ARCH)/divide.c
+ $(CC) $(CFLAGS) -DSIGNED=0 -DREM=0 -DBITS=32 -DNAME=__Udiv -c -o $@ $<
+arch/$(ARCH)/__Mod.o: arch/$(ARCH)/divide.c
+ $(CC) $(CFLAGS) -DSIGNED=1 -DREM=1 -DBITS=32 -DNAME=__Mod -c -o $@ $<
+arch/$(ARCH)/__Div.o: arch/$(ARCH)/divide.c
+ $(CC) $(CFLAGS) -DSIGNED=1 -DREM=0 -DBITS=32 -DNAME=__Div -c -o $@ $<
+
archclean:
diff --git a/klibc/klibc/arch/cris/__negdi2.S b/klibc/klibc/arch/cris/__negdi2.S
new file mode 100644
index 0000000000..3cca9edfa8
--- /dev/null
+++ b/klibc/klibc/arch/cris/__negdi2.S
@@ -0,0 +1,25 @@
+/*
+ * arch/cris/__negdi2.c
+ */
+
+/*
+ * In 2's complement arithmetric, -x == (~x + 1), so
+ * -{h,l} = (~{h,l} + {0,1)
+ * -{h,l} = {~h,~l} + {0,1}
+ * -{h,l} = {~h + cy, ~l + 1}
+ * ... where cy = (l == 0)
+ * -{h,l} = {~h + cy, -l}
+ */
+
+ .text
+ .balign 4
+ .type __negdi2,@function
+ .globl __negdi2
+__negdi2:
+ neg.d $r10,$r10
+ seq $r12
+ not $r11
+ ret
+ add.d $r12,$r11
+
+ .size __negdi2, .-__negdi2
diff --git a/klibc/klibc/arch/cris/crt0.S b/klibc/klibc/arch/cris/crt0.S
new file mode 100644
index 0000000000..989c82b2ba
--- /dev/null
+++ b/klibc/klibc/arch/cris/crt0.S
@@ -0,0 +1,28 @@
+#
+# arch/cris/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
+ .balign 4
+ .type _start,@function
+ .globl _start
+_start:
+ /* Save the address of the ELF argument array */
+ move.d $sp,$r10 /* Address of ELF arguments */
+
+ /* atexit() function (assume null) */
+ moveq 0,$r11
+
+ /* Set up a dummy stack frame to keep gcc from getting confused */
+ push $r11
+ push $r11
+ jump __libc_init
+
+ .size _start, .-_start
+
diff --git a/klibc/klibc/arch/cris/divide.c b/klibc/klibc/arch/cris/divide.c
new file mode 100644
index 0000000000..29081dc953
--- /dev/null
+++ b/klibc/klibc/arch/cris/divide.c
@@ -0,0 +1,92 @@
+#include <stdint.h>
+#include <signal.h>
+
+#if BITS == 64
+typedef uint64_t unum;
+typedef int64_t snum;
+#else
+typedef uint32_t unum;
+typedef int32_t snum;
+#endif
+
+#ifdef SIGNED
+typedef snum xnum;
+#else
+typedef unum xnum;
+#endif
+
+#ifdef __cris__
+static inline unum __attribute__((const)) dstep(unum rs, unum rd) {
+ asm("dstep %1,%0" : "+r" (rd) : "r" (rs));
+ return rd;
+}
+
+static inline unum __attribute__((const)) lz(unum rs) {
+ unum rd;
+ asm("lz %1,%0" : "=r" (rd) : "r" (rs));
+ return rd;
+}
+
+#else
+/* For testing */
+static inline unum __attribute__ ((const)) dstep(unum rs, unum rd) {
+ rd <<= 1;
+ if ( rd >= rs )
+ rd -= rs;
+
+ return rd;
+}
+
+static inline unum __attribute__((const)) lz(unum rs) {
+ unum rd = 0;
+ while ( rs >= 0x7fffffff ) {
+ rd++;
+ rs <<= 1;
+ }
+ return rd;
+}
+
+#endif
+
+xnum NAME (unum num, unum den)
+{
+ unum quot = 0, qbit = 1;
+ int minus = 0;
+ xnum v;
+
+ if ( den == 0 ) {
+ raise(SIGFPE);
+ return 0; /* If signal ignored... */
+ }
+
+ if (den == 1) return (xnum)(REM ? 0 : num);
+
+#if SIGNED
+ if ( (snum)(num^den) < 0 )
+ minus = 1;
+ if ( (snum)num < 0 ) num = -num;
+ if ( (snum)den < 0 ) den = -den;
+#endif
+
+ den--;
+
+
+ /* Left-justify denominator and count shift */
+ while ( (snum)den >= 0 ) {
+ den <<= 1;
+ qbit <<= 1;
+ }
+
+ while ( qbit ) {
+ if ( den <= num ) {
+ num -= den;
+ quot += qbit;
+ }
+ den >>= 1;
+ qbit >>= 1;
+ }
+
+ v = (xnum)(REM ? num : quot);
+ if ( minus ) v = -v;
+ return v;
+}
diff --git a/klibc/klibc/arch/cris/include/klibc/archsignal.h b/klibc/klibc/arch/cris/include/klibc/archsignal.h
deleted file mode 100644
index 73b2e196c9..0000000000
--- a/klibc/klibc/arch/cris/include/klibc/archsignal.h
+++ /dev/null
@@ -1,13 +0,0 @@
-/*
- * arch/cris/include/klibc/archsignal.h
- *
- * Architecture-specific signal definitions
- *
- */
-
-#ifndef _KLIBC_ARCHSIGNAL_H
-#define _KLIBC_ARCHSIGNAL_H
-
-/* No special stuff for this architecture */
-
-#endif
diff --git a/klibc/klibc/arch/cris/include/klibc/archsys.h b/klibc/klibc/arch/cris/include/klibc/archsys.h
deleted file mode 100644
index dfdc70a6de..0000000000
--- a/klibc/klibc/arch/cris/include/klibc/archsys.h
+++ /dev/null
@@ -1,12 +0,0 @@
-/*
- * 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 */
diff --git a/klibc/klibc/arch/cris/setjmp.S b/klibc/klibc/arch/cris/setjmp.S
new file mode 100644
index 0000000000..43162418af
--- /dev/null
+++ b/klibc/klibc/arch/cris/setjmp.S
@@ -0,0 +1,37 @@
+#
+# arch/cris/setjmp.S
+#
+# setjmp/longjmp for the cris architecture
+#
+
+#
+# The jmp_buf is assumed to contain the following, in order:
+# $r8..$r0 (in that order)
+# $sp ($r14)
+# return address
+#
+
+ .text
+ .balign 4
+ .globl setjmp
+ .type setjmp, @function
+setjmp:
+ movem $r8,[$r10+] /* Save $r8..$r0 at $r10... */
+ move.d $sp,[$r10+]
+ move $srp,[$r10]
+ ret
+ moveq 0,$r10
+
+ .size setjmp,.-setjmp
+
+ .text
+ .balign 4
+ .globl longjmp
+ .type longjmp, @function
+longjmp:
+ movem [$r10+],$r8 /* Load $r8..$r0 from $r10... */
+ move.d [$r10+],$sp
+ jump [$r10]
+ move.d $r11,$r10
+
+ .size longjmp,.-longjmp
diff --git a/klibc/klibc/arch/cris/syscall.S b/klibc/klibc/arch/cris/syscall.S
new file mode 100644
index 0000000000..d71495aba2
--- /dev/null
+++ b/klibc/klibc/arch/cris/syscall.S
@@ -0,0 +1,30 @@
+/*
+ * arch/cris/syscall.S
+ *
+ * On cris, r9 contains the syscall number (set by generated stub);
+ * r10..r13 contain arguments 0-3 per the standard calling convention,
+ * and arguments 4-5 are passed in $mof and $srp; however, we have
+ * to save $srp around the system call.
+ */
+
+ .section ".text","ax"
+ .balign 4
+ .globl __syscall_common
+ .type __syscall_common,@function
+__syscall_common:
+ push $srp
+ move [$sp+4],$mof
+ move [$sp+8],$srp
+ break 13
+
+ cmps.w -4096,$r10
+ blo 1f
+ neg.d $r10,$r11
+ move.d $r11,[errno]
+ moveq -1,$r10
+1:
+ pop $srp
+ ret
+ nop
+
+ .size __syscall_common,.-__syscall_common
diff --git a/klibc/klibc/arch/cris/sysstub.ph b/klibc/klibc/arch/cris/sysstub.ph
new file mode 100644
index 0000000000..6c894f62f5
--- /dev/null
+++ b/klibc/klibc/arch/cris/sysstub.ph
@@ -0,0 +1,29 @@
+# -*- perl -*-
+#
+# arch/cris/sysstub.ph
+#
+# Script to generate system call stubs
+#
+
+sub make_sysstub($$$$@) {
+ my($fname, $type, $sname, $stype, @args) = @_;
+
+ open(OUT, '>', "syscalls/${fname}.S");
+ print OUT "#include <asm/unistd.h>\n";
+ print OUT "\n";
+ print OUT "\t.text\n";
+ print OUT "\t.type\t${fname},\@function\n";
+ print OUT "\t.globl\t${fname}\n";
+ print OUT "\t.balign\t4\n";
+ print OUT "${fname}:\n";
+ print OUT "#if __NR_${sname} <= 31\n";
+ print OUT "\t moveq\t__NR_${sname}, \$r9\n";
+ print OUT "#else\n";
+ print OUT "\t move.d\t__NR_${sname}, \$r9\n";
+ print OUT "#endif\n";
+ print OUT "\tjump\t__syscall_common\n";
+ print OUT "\t.size ${fname},.-${fname}\n";
+ close(OUT);
+}
+
+1;
diff --git a/klibc/klibc/arch/i386/MCONFIG b/klibc/klibc/arch/i386/MCONFIG
index 516b1b6738..2421452eea 100644
--- a/klibc/klibc/arch/i386/MCONFIG
+++ b/klibc/klibc/arch/i386/MCONFIG
@@ -9,11 +9,11 @@
# Enable this to compile with register parameters; only safe for
# gcc > 3
-REGPARM_OPT := -mregparm=3 -DREGPARM
+REGPARM_OPT := -mregparm=3 -DREGPARM=3
-gcc_major := $(shell $(CC) -v 2>&1 | awk '/gcc version/{print int($$3)}')
+gcc_major := $(shell echo __GNUC__ | $(CC) -E -xc - | tail -n 1)
-OPTFLAGS = $(REGPARM) -march=i386 -Os
+OPTFLAGS = $(REGPARM) -march=i386 -Os -g
ifeq ($(gcc_major),3)
REGPARM := $(REGPARM_OPT)
diff --git a/klibc/klibc/arch/i386/Makefile.inc b/klibc/klibc/arch/i386/Makefile.inc
index 171248a796..5c320cb453 100644
--- a/klibc/klibc/arch/i386/Makefile.inc
+++ b/klibc/klibc/arch/i386/Makefile.inc
@@ -11,6 +11,8 @@ ARCHOBJS = \
arch/$(ARCH)/exits.o \
arch/$(ARCH)/socketcall.o \
arch/$(ARCH)/setjmp.o \
+ arch/$(ARCH)/syscall.o \
+ arch/$(ARCH)/open.o \
arch/$(ARCH)/libgcc/__ashldi3.o \
arch/$(ARCH)/libgcc/__ashrdi3.o \
arch/$(ARCH)/libgcc/__lshrdi3.o \
@@ -22,6 +24,4 @@ ARCHOBJS = \
libgcc/__umoddi3.o \
libgcc/__udivmoddi4.o
-ARCHSOOBJS = $(patsubst %.o,%.lo,$(ARCHOBJS))
-
archclean:
diff --git a/klibc/klibc/arch/i386/include/klibc/archsetjmp.h b/klibc/klibc/arch/i386/include/klibc/archsetjmp.h
deleted file mode 100644
index db04314b8c..0000000000
--- a/klibc/klibc/arch/i386/include/klibc/archsetjmp.h
+++ /dev/null
@@ -1,19 +0,0 @@
-/*
- * 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 */
diff --git a/klibc/klibc/arch/i386/include/klibc/archsignal.h b/klibc/klibc/arch/i386/include/klibc/archsignal.h
deleted file mode 100644
index b092ba6d3a..0000000000
--- a/klibc/klibc/arch/i386/include/klibc/archsignal.h
+++ /dev/null
@@ -1,13 +0,0 @@
-/*
- * arch/i386/include/klibc/archsignal.h
- *
- * Architecture-specific signal definitions
- *
- */
-
-#ifndef _KLIBC_ARCHSIGNAL_H
-#define _KLIBC_ARCHSIGNAL_H
-
-/* No special stuff for this architecture */
-
-#endif
diff --git a/klibc/klibc/arch/i386/include/klibc/archsys.h b/klibc/klibc/arch/i386/include/klibc/archsys.h
deleted file mode 100644
index e21487b256..0000000000
--- a/klibc/klibc/arch/i386/include/klibc/archsys.h
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * 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 */
diff --git a/klibc/klibc/arch/i386/include/klibc/diverr.h b/klibc/klibc/arch/i386/include/klibc/diverr.h
deleted file mode 100644
index 410aba06d3..0000000000
--- a/klibc/klibc/arch/i386/include/klibc/diverr.h
+++ /dev/null
@@ -1,16 +0,0 @@
-/*
- * 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 */
diff --git a/klibc/klibc/arch/i386/include/sys/io.h b/klibc/klibc/arch/i386/include/sys/io.h
deleted file mode 100644
index b051464dfc..0000000000
--- a/klibc/klibc/arch/i386/include/sys/io.h
+++ /dev/null
@@ -1,126 +0,0 @@
-#ident "$Id: io.h,v 1.2 2004/01/25 07:49:39 hpa Exp $"
-/* ----------------------------------------------------------------------- *
- *
- * Copyright 2004 H. Peter Anvin - All Rights Reserved
- *
- * 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:
- *
- * The above copyright notice 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.
- *
- * ----------------------------------------------------------------------- */
-
-/*
- * sys/io.h for the i386 architecture
- *
- * Basic I/O macros
- */
-
-#ifndef _SYS_IO_H
-#define _SYS_IO_H 1
-
-/* I/O-related system calls */
-
-int iopl(int);
-int ioperm(unsigned long, unsigned long, int);
-
-/* Basic I/O macros */
-
-static __inline__ void
-outb(unsigned char __v, unsigned short __p)
-{
- asm volatile("outb %0,%1" : : "a" (__v), "dN" (__p));
-}
-
-static __inline__ void
-outw(unsigned short __v, unsigned short __p)
-{
- asm volatile("outw %0,%1" : : "a" (__v), "dN" (__p));
-}
-
-static __inline__ void
-outl(unsigned int __v, unsigned short __p)
-{
- asm volatile("outl %0,%1" : : "a" (__v), "dN" (__p));
-}
-
-static __inline__ unsigned char
-inb(unsigned short __p)
-{
- unsigned char __v;
- asm volatile("inb %1,%0" : "=a" (__v) : "dN" (__p));
- return __v;
-}
-
-static __inline__ unsigned short
-inw(unsigned short __p)
-{
- unsigned short __v;
- asm volatile("inw %1,%0" : "=a" (__v) : "dN" (__p));
- return __v;
-}
-
-static __inline__ unsigned int
-inl(unsigned short __p)
-{
- unsigned int __v;
- asm volatile("inl %1,%0" : "=a" (__v) : "dN" (__p));
- return __v;
-}
-
-/* String I/O macros */
-
-static __inline__ void
-outsb (unsigned short __p, const void *__d, unsigned long __n)
-{
- asm volatile("cld; rep; outsb" : "+S" (__d), "+c" (__n) : "d" (__p));
-}
-
-static __inline__ void
-outsw (unsigned short __p, const void *__d, unsigned long __n)
-{
- asm volatile("cld; rep; outsw" : "+S" (__d), "+c" (__n) : "d" (__p));
-}
-
-static __inline__ void
-outsl (unsigned short __p, const void *__d, unsigned long __n)
-{
- asm volatile("cld; rep; outsl" : "+S" (__d), "+c" (__n) : "d" (__p));
-}
-
-
-static __inline__ void
-insb (unsigned short __p, void *__d, unsigned long __n)
-{
- asm volatile("cld; rep; insb" : "+D" (__d), "+c" (__n) : "d" (__p));
-}
-
-static __inline__ void
-insw (unsigned short __p, void *__d, unsigned long __n)
-{
- asm volatile("cld; rep; insw" : "+D" (__d), "+c" (__n) : "d" (__p));
-}
-
-static __inline__ void
-insl (unsigned short __p, void *__d, unsigned long __n)
-{
- asm volatile("cld; rep; insl" : "+D" (__d), "+c" (__n) : "d" (__p));
-}
-
-#endif /* _SYS_IO_H */
diff --git a/klibc/klibc/arch/i386/include/sys/vm86.h b/klibc/klibc/arch/i386/include/sys/vm86.h
deleted file mode 100644
index d3272393dc..0000000000
--- a/klibc/klibc/arch/i386/include/sys/vm86.h
+++ /dev/null
@@ -1,41 +0,0 @@
-#ident "$Id: vm86.h,v 1.1 2004/01/25 01:34:28 hpa Exp $"
-/* ----------------------------------------------------------------------- *
- *
- * Copyright 2004 H. Peter Anvin - All Rights Reserved
- *
- * 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:
- *
- * The above copyright notice 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.
- *
- * ----------------------------------------------------------------------- */
-
-/*
- * sys/vm86.h for i386
- */
-
-#ifndef _SYS_VM86_H
-#define _SYS_VM86_H 1
-
-#include <asm/vm86.h>
-
-/* Actual system call */
-int vm86(struct vm86_struct *);
-
-#endif
diff --git a/klibc/klibc/arch/i386/open.S b/klibc/klibc/arch/i386/open.S
new file mode 100644
index 0000000000..4f492a1566
--- /dev/null
+++ b/klibc/klibc/arch/i386/open.S
@@ -0,0 +1,29 @@
+/*
+ * arch/i386/open.S
+ *
+ * Handle the open() system call - oddball due to the varadic
+ * prototype, which forces the use of the cdecl calling convention,
+ * and the need for O_LARGEFILE.
+ */
+
+#include <asm/unistd.h>
+
+/* <asm/fcntl.h>, despite the name, isn't assembly-safe */
+#define O_LARGEFILE 0100000
+
+ .globl open
+ .type open,@function
+
+open:
+#ifdef REGPARM
+ movl 4(%esp),%eax
+ movl 8(%esp),%edx
+ movl 12(%esp),%ecx
+ orl $O_LARGEFILE,%edx
+#else
+ orl $O_LARGEFILE,8(%esp)
+#endif
+ pushl $__NR_open
+ jmp __syscall_common
+
+ .size open,.-open
diff --git a/klibc/klibc/arch/i386/socketcall.S b/klibc/klibc/arch/i386/socketcall.S
index 6bac1e6913..b13d204c32 100644
--- a/klibc/klibc/arch/i386/socketcall.S
+++ b/klibc/klibc/arch/i386/socketcall.S
@@ -16,18 +16,22 @@
.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
+ 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 $-4096,%eax # Error return?
+
+ popl %ebx
+
+ jb 1f
+
+ negl %eax
+ movl %eax,errno
+ orl $-1,%eax # Return -1
1:
ret
diff --git a/klibc/klibc/arch/i386/syscall.S b/klibc/klibc/arch/i386/syscall.S
new file mode 100644
index 0000000000..f8fa7b4dd3
--- /dev/null
+++ b/klibc/klibc/arch/i386/syscall.S
@@ -0,0 +1,60 @@
+/*
+ * arch/i386/syscall.S
+ *
+ * Common tail-handling code for system calls. Because of __syscalldecl
+ * we are using the stack even on if we are compiling with regparm.
+ *
+ * The arguments are on the stack; the system call number in %eax.
+ */
+
+#define ARG(n) (4*n+20)(%esp)
+
+ .text
+ .align 4
+ .globl __syscall_common
+ .type __syscall_common,@function
+__syscall_common:
+#ifdef REGPARM
+ xchgl %ebx,(%esp)
+#else
+ popl %eax
+ pushl %ebx
+#endif
+ pushl %esi
+ pushl %edi
+ pushl %ebp
+
+#ifdef REGPARM
+ xchgl %eax,%ebx
+ xchgl %ecx,%edx
+ movl ARG(0),%esi
+ movl ARG(1),%edi
+ movl ARG(2),%ebp
+#else
+ movl ARG(0),%ebx # Syscall arguments
+ movl ARG(1),%ecx
+ movl ARG(2),%edx
+ movl ARG(3),%esi
+ movl ARG(4),%edi
+ movl ARG(5),%ebp
+#endif
+ int $0x80
+
+ cmpl $-4096,%eax
+
+ popl %ebp
+ popl %edi
+ popl %esi
+ popl %ebx
+
+ jb 1f
+
+ # Error return, must set errno
+ negl %eax
+ movl %eax,errno
+ orl $-1,%eax # Return -1
+
+1:
+ ret
+
+ .size __syscall_common,.-__syscall_common
diff --git a/klibc/klibc/arch/i386/sysstub.ph b/klibc/klibc/arch/i386/sysstub.ph
new file mode 100644
index 0000000000..eaa8180911
--- /dev/null
+++ b/klibc/klibc/arch/i386/sysstub.ph
@@ -0,0 +1,32 @@
+# -*- perl -*-
+#
+# arch/i386/sysstub.ph
+#
+# Script to generate system call stubs
+#
+
+sub make_sysstub($$$$@) {
+ my($fname, $type, $sname, $stype, @args) = @_;
+
+ open(OUT, '>', "syscalls/${fname}.S");
+ print OUT "#include <asm/unistd.h>\n";
+ print OUT "\n";
+ print OUT "\t.type ${fname},\@function\n";
+ print OUT "\t.globl ${fname}\n";
+ print OUT "${fname}:\n";
+
+ if ( $stype eq 'varadic' ) {
+ print OUT "#ifdef REGPARM\n";
+ print OUT "\tmovl 4(%esp),%eax\n";
+ print OUT "\tmovl 8(%esp),%edx\n";
+ print OUT "\tmovl 12(%esp),%ecx\n";
+ print OUT "#endif\n";
+ }
+
+ print OUT "\tpushl \$__NR_${sname}\n";
+ print OUT "\tjmp __syscall_common\n";
+ print OUT "\t.size ${fname},.-${fname}\n";
+ close(OUT);
+}
+
+1;
diff --git a/klibc/klibc/arch/ia64/Makefile.inc b/klibc/klibc/arch/ia64/Makefile.inc
index 781448770e..6363c1f948 100644
--- a/klibc/klibc/arch/ia64/Makefile.inc
+++ b/klibc/klibc/arch/ia64/Makefile.inc
@@ -11,6 +11,7 @@ ARCHOBJS = \
arch/$(ARCH)/vfork.o \
arch/$(ARCH)/setjmp.o \
arch/$(ARCH)/pipe.o \
+ arch/$(ARCH)/syscall.o \
libgcc/__divdi3.o \
libgcc/__divsi3.o \
libgcc/__udivdi3.o \
diff --git a/klibc/klibc/arch/ia64/include/klibc/archsetjmp.h b/klibc/klibc/arch/ia64/include/klibc/archsetjmp.h
deleted file mode 100644
index bd639c0b00..0000000000
--- a/klibc/klibc/arch/ia64/include/klibc/archsetjmp.h
+++ /dev/null
@@ -1,17 +0,0 @@
-/*
- * arch/ia64/include/klibc/archsetjmp.h
- *
- * Code borrowed from the FreeBSD kernel.
- *
- */
-
-#ifndef _KLIBC_ARCHSETJMP_H
-#define _KLIBC_ARCHSETJMP_H
-
-/* User code must not depend on the internal representation of jmp_buf. */
-#define _JBLEN 0x200
-
-/* guaranteed 128-bit alignment! */
-typedef char jmp_buf[_JBLEN] __attribute__ ((aligned (16)));
-
-#endif
diff --git a/klibc/klibc/arch/ia64/include/klibc/archsignal.h b/klibc/klibc/arch/ia64/include/klibc/archsignal.h
deleted file mode 100644
index 5b01f19bc2..0000000000
--- a/klibc/klibc/arch/ia64/include/klibc/archsignal.h
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * arch/ia64/include/klibc/archsignal.h
- *
- * Architecture-specific signal definitions.
- *
- */
-
-#ifndef _KLIBC_ARCHSIGNAL_H
-#define _KLIBC_ARCHSIGNAL_H
-
-#define _NSIG 64
-#define _NSIG_BPW 64
-#define _NSIG_WORDS (_NSIG / _NSIG_BPW)
-
-typedef struct {
- unsigned long sig[_NSIG_WORDS];
-} sigset_t;
-
-struct sigaction {
- union {
- __sighandler_t _sa_handler;
- void (*_sa_sigaction)(int, struct siginfo *, void *);
- } _u;
- sigset_t sa_mask;
- int sa_flags;
-};
-
-#define sa_handler _u._sa_handler
-#define sa_sigaction _u._sa_sigaction
-
-#endif
diff --git a/klibc/klibc/arch/ia64/include/klibc/archsys.h b/klibc/klibc/arch/ia64/include/klibc/archsys.h
deleted file mode 100644
index fe331acf55..0000000000
--- a/klibc/klibc/arch/ia64/include/klibc/archsys.h
+++ /dev/null
@@ -1,218 +0,0 @@
-/*
- * arch/ia64/include/klibc/archsys.h
- *
- * Architecture-specific syscall definitions
- */
-
-#ifndef _KLIBC_ARCHSYS_H
-#define _KLIBC_ARCHSYS_H
-
-#define __IA64_BREAK "break 0x100000;;\n\t"
-
-#define _syscall0(type,name) \
-type \
-name (void) \
-{ \
- register long _r8 asm ("r8"); \
- register long _r10 asm ("r10"); \
- register long _r15 asm ("r15") = __NR_##name; \
- long _retval; \
- __asm __volatile (__IA64_BREAK \
- : "=r" (_r8), "=r" (_r10), "=r" (_r15) \
- : "2" (_r15) ASM_ARGS_0 \
- : "memory" ASM_CLOBBERS_0); \
- _retval = _r8; \
- if (_r10 == -1) { \
- errno = (_retval); \
- _retval = -1; \
- } \
- return _retval; \
-}
-
-#define _syscall1(type,name,type1,arg1) \
-type \
-name (type1 arg1) \
-{ \
- register long _r8 asm ("r8"); \
- register long _r10 asm ("r10"); \
- register long _r15 asm ("r15") = __NR_##name; \
- long _retval; \
- LOAD_ARGS_1(arg1); \
- __asm __volatile (__IA64_BREAK \
- : "=r" (_r8), "=r" (_r10), "=r" (_r15), \
- ASM_OUTARGS_1 \
- : "2" (_r15) ASM_ARGS_1 \
- : "memory" ASM_CLOBBERS_1); \
- _retval = _r8; \
- if (_r10 == -1) { \
- errno = (_retval); \
- _retval = -1; \
- } \
- return _retval; \
-}
-
-#define _syscall2(type,name,type1,arg1,type2,arg2) \
-type \
-name (type1 arg1, type2 arg2) \
-{ \
- register long _r8 asm ("r8"); \
- register long _r10 asm ("r10"); \
- register long _r15 asm ("r15") = __NR_##name; \
- long _retval; \
- LOAD_ARGS_2(arg1, arg2); \
- __asm __volatile (__IA64_BREAK \
- : "=r" (_r8), "=r" (_r10), "=r" (_r15), \
- ASM_OUTARGS_2 \
- : "2" (_r15) ASM_ARGS_2 \
- : "memory" ASM_CLOBBERS_2); \
- _retval = _r8; \
- if (_r10 == -1) { \
- errno = (_retval); \
- _retval = -1; \
- } \
- return _retval; \
-}
-
-#define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \
-type \
-name (type1 arg1, type2 arg2, type3 arg3) \
-{ \
- register long _r8 asm ("r8"); \
- register long _r10 asm ("r10"); \
- register long _r15 asm ("r15") = __NR_##name; \
- long _retval; \
- LOAD_ARGS_3(arg1, arg2, arg3); \
- __asm __volatile (__IA64_BREAK \
- : "=r" (_r8), "=r" (_r10), "=r" (_r15), \
- ASM_OUTARGS_3 \
- : "2" (_r15) ASM_ARGS_3 \
- : "memory" ASM_CLOBBERS_3); \
- _retval = _r8; \
- if (_r10 == -1) { \
- errno = (_retval); \
- _retval = -1; \
- } \
- return _retval; \
-}
-
-#define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \
-type \
-name (type1 arg1, type2 arg2, type3 arg3, type4 arg4) \
-{ \
- register long _r8 asm ("r8"); \
- register long _r10 asm ("r10"); \
- register long _r15 asm ("r15") = __NR_##name; \
- long _retval; \
- LOAD_ARGS_4(arg1, arg2, arg3, arg4); \
- __asm __volatile (__IA64_BREAK \
- : "=r" (_r8), "=r" (_r10), "=r" (_r15), \
- ASM_OUTARGS_4 \
- : "2" (_r15) ASM_ARGS_4 \
- : "memory" ASM_CLOBBERS_4); \
- _retval = _r8; \
- if (_r10 == -1) { \
- errno = (_retval); \
- _retval = -1; \
- } \
- return _retval; \
-}
-
-#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) \
-{ \
- register long _r8 asm ("r8"); \
- register long _r10 asm ("r10"); \
- register long _r15 asm ("r15") = __NR_##name; \
- long _retval; \
- LOAD_ARGS_5(arg1, arg2, arg3, arg4, arg5); \
- __asm __volatile (__IA64_BREAK \
- : "=r" (_r8), "=r" (_r10), "=r" (_r15), \
- ASM_OUTARGS_5 \
- : "2" (_r15) ASM_ARGS_5 \
- : "memory" ASM_CLOBBERS_5); \
- _retval = _r8; \
- if (_r10 == -1) { \
- errno = (_retval); \
- _retval = -1; \
- } \
- return _retval; \
-}
-
-#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) \
-{ \
- register long _r8 asm ("r8"); \
- register long _r10 asm ("r10"); \
- register long _r15 asm ("r15") = __NR_##name; \
- long _retval; \
- LOAD_ARGS_6(arg1, arg2, arg3, arg4, arg5, arg6); \
- __asm __volatile (__IA64_BREAK \
- : "=r" (_r8), "=r" (_r10), "=r" (_r15), \
- ASM_OUTARGS_6 \
- : "2" (_r15) ASM_ARGS_6 \
- : "memory" ASM_CLOBBERS_6); \
- _retval = _r8; \
- if (_r10 == -1) { \
- errno = (_retval); \
- _retval = -1; \
- } \
- return _retval; \
-}
-
-
-#define LOAD_ARGS_0() do { } while (0)
-#define LOAD_ARGS_1(out0) \
- register long _out0 asm ("out0") = (long) (out0); \
- LOAD_ARGS_0 ()
-#define LOAD_ARGS_2(out0, out1) \
- register long _out1 asm ("out1") = (long) (out1); \
- LOAD_ARGS_1 (out0)
-#define LOAD_ARGS_3(out0, out1, out2) \
- register long _out2 asm ("out2") = (long) (out2); \
- LOAD_ARGS_2 (out0, out1)
-#define LOAD_ARGS_4(out0, out1, out2, out3) \
- register long _out3 asm ("out3") = (long) (out3); \
- LOAD_ARGS_3 (out0, out1, out2)
-#define LOAD_ARGS_5(out0, out1, out2, out3, out4) \
- register long _out4 asm ("out4") = (long) (out4); \
- LOAD_ARGS_4 (out0, out1, out2, out3)
-#define LOAD_ARGS_6(out0, out1, out2, out3, out4, out5) \
- register long _out5 asm ("out5") = (long) (out5); \
- LOAD_ARGS_5 (out0, out1, out2, out3, out4)
-
-#define ASM_OUTARGS_1 "=r" (_out0)
-#define ASM_OUTARGS_2 ASM_OUTARGS_1, "=r" (_out1)
-#define ASM_OUTARGS_3 ASM_OUTARGS_2, "=r" (_out2)
-#define ASM_OUTARGS_4 ASM_OUTARGS_3, "=r" (_out3)
-#define ASM_OUTARGS_5 ASM_OUTARGS_4, "=r" (_out4)
-#define ASM_OUTARGS_6 ASM_OUTARGS_5, "=r" (_out5)
-
-#define ASM_ARGS_0
-#define ASM_ARGS_1 ASM_ARGS_0, "3" (_out0)
-#define ASM_ARGS_2 ASM_ARGS_1, "4" (_out1)
-#define ASM_ARGS_3 ASM_ARGS_2, "5" (_out2)
-#define ASM_ARGS_4 ASM_ARGS_3, "6" (_out3)
-#define ASM_ARGS_5 ASM_ARGS_4, "7" (_out4)
-#define ASM_ARGS_6 ASM_ARGS_5, "8" (_out5)
-
-#define ASM_CLOBBERS_0 ASM_CLOBBERS_1, "out0"
-#define ASM_CLOBBERS_1 ASM_CLOBBERS_2, "out1"
-#define ASM_CLOBBERS_2 ASM_CLOBBERS_3, "out2"
-#define ASM_CLOBBERS_3 ASM_CLOBBERS_4, "out3"
-#define ASM_CLOBBERS_4 ASM_CLOBBERS_5, "out4"
-#define ASM_CLOBBERS_5 ASM_CLOBBERS_6, "out5"
-#define ASM_CLOBBERS_6 , "out6", "out7", \
- /* Non-stacked integer registers, minus r8, r10, r15. */ \
- "r2", "r3", "r9", "r11", "r12", "r13", "r14", "r16", "r17", "r18", \
- "r19", "r20", "r21", "r22", "r23", "r24", "r25", "r26", "r27", \
- "r28", "r29", "r30", "r31", \
- /* Predicate registers. */ \
- "p6", "p7", "p8", "p9", "p10", "p11", "p12", "p13", "p14", "p15", \
- /* Non-rotating fp registers. */ \
- "f6", "f7", "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15", \
- /* Branch registers. */ \
- "b6", "b7"
-
-#endif /* _KLIBC_ARCHSYS_H */
diff --git a/klibc/klibc/arch/ia64/pipe.c b/klibc/klibc/arch/ia64/pipe.c
index 5f5dd05727..0b641e8702 100644
--- a/klibc/klibc/arch/ia64/pipe.c
+++ b/klibc/klibc/arch/ia64/pipe.c
@@ -27,7 +27,7 @@ int pipe(int *filedes)
long _retval;
__asm __volatile (__IA64_BREAK
: "=r" (_r8), "=r" (_r10), "=r" (_r15),
- "=r" (_out0)
+ "=r" (_out0), "=r" (_r9)
: "2" (_r15), "3" (_out0)
: "memory" ASM_CLOBBERS);
if (_r10 == -1) {
diff --git a/klibc/klibc/arch/ia64/syscall.S b/klibc/klibc/arch/ia64/syscall.S
new file mode 100644
index 0000000000..e3f264c0e4
--- /dev/null
+++ b/klibc/klibc/arch/ia64/syscall.S
@@ -0,0 +1,20 @@
+#
+# arch/ia64/syscall.S
+#
+
+#include <asm/unistd.h>
+
+ .text
+ .align 32
+ .proc __syscall_error
+ .globl __syscall_error
+__syscall_error:
+ addl r2 = @ltoffx(errno),gp
+ ;;
+ ld8.mov r3 = [r2],errno
+ ;;
+ st4 [r3] = r8
+ mov r8 = -1
+ br.ret.sptk.many b0
+ .size __syscall_error, .-__syscall_error
+ .endp __syscall_error
diff --git a/klibc/klibc/arch/ia64/sysstub.ph b/klibc/klibc/arch/ia64/sysstub.ph
new file mode 100644
index 0000000000..34031a29ae
--- /dev/null
+++ b/klibc/klibc/arch/ia64/sysstub.ph
@@ -0,0 +1,29 @@
+# -*- perl -*-
+#
+# arch/ia64/sysstub.ph
+#
+# Script to generate system call stubs
+#
+
+sub make_sysstub($$$$@) {
+ my($fname, $type, $sname, $stype, @args) = @_;
+
+ open(OUT, '>', "syscalls/${fname}.S");
+ print OUT "#include <asm/unistd.h>\n";
+ print OUT "\n";
+ print OUT "\t.text\n";
+ print OUT "\t.align 32\n";
+ print OUT "\t.proc ${fname}\n";
+ print OUT "\t.globl ${fname}\n";
+ print OUT "${fname}:\n";
+ print OUT "\tmov\tr15 = __NR_${sname}\n";
+ print OUT "\tbreak __BREAK_SYSCALL\n";
+ print OUT "\tcmp.eq p6,p0 = -1,r10\n";
+ print OUT "(p6)\tbr.few __syscall_error\n";
+ print OUT "\tbr.ret.sptk.many b0\n";
+ print OUT "\t.size\t${fname},.-${fname}\n";
+ print OUT "\t.endp\t${fname}\n";
+ close(OUT);
+}
+
+1;
diff --git a/klibc/klibc/arch/ia64/vfork.S b/klibc/klibc/arch/ia64/vfork.S
index 0354fa9ef7..efcd03f7f1 100644
--- a/klibc/klibc/arch/ia64/vfork.S
+++ b/klibc/klibc/arch/ia64/vfork.S
@@ -27,8 +27,8 @@ vfork:
mov out0=CLONE_VM|CLONE_VFORK|SIGCHLD
mov out1=0
;;
- __IA64_BREAK // Do the syscall
-
+ break 0x100000 // Do the syscall
+ ;;
addl r15=0,r1
cmp.eq p7,p6 = -1,r10
;;
diff --git a/klibc/klibc/arch/m68k/include/klibc/archsignal.h b/klibc/klibc/arch/m68k/include/klibc/archsignal.h
deleted file mode 100644
index 714527f6b0..0000000000
--- a/klibc/klibc/arch/m68k/include/klibc/archsignal.h
+++ /dev/null
@@ -1,13 +0,0 @@
-/*
- * arch/m68k/include/klibc/archsignal.h
- *
- * Architecture-specific signal definitions
- *
- */
-
-#ifndef _KLIBC_ARCHSIGNAL_H
-#define _KLIBC_ARCHSIGNAL_H
-
-/* No special stuff for this architecture */
-
-#endif
diff --git a/klibc/klibc/arch/m68k/include/klibc/archsys.h b/klibc/klibc/arch/m68k/include/klibc/archsys.h
deleted file mode 100644
index 8f6bed8e94..0000000000
--- a/klibc/klibc/arch/m68k/include/klibc/archsys.h
+++ /dev/null
@@ -1,12 +0,0 @@
-/*
- * 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 */
diff --git a/klibc/klibc/arch/mips/MCONFIG b/klibc/klibc/arch/mips/MCONFIG
index 52b518461f..a248973815 100644
--- a/klibc/klibc/arch/mips/MCONFIG
+++ b/klibc/klibc/arch/mips/MCONFIG
@@ -7,12 +7,9 @@
# accordingly.
#
-ARCHREQFLAGS = -fno-pic -mno-abicalls
+ARCHREQFLAGS = -fno-pic -mno-abicalls -G 0
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
+SHAREDFLAGS = -T arch/$(ARCH)/klibc.ld
diff --git a/klibc/klibc/arch/mips/Makefile.inc b/klibc/klibc/arch/mips/Makefile.inc
index 09a2d2f736..e257023f34 100644
--- a/klibc/klibc/arch/mips/Makefile.inc
+++ b/klibc/klibc/arch/mips/Makefile.inc
@@ -11,6 +11,7 @@ ARCHOBJS = \
arch/$(ARCH)/pipe.o \
arch/$(ARCH)/vfork.o \
arch/$(ARCH)/setjmp.o \
+ arch/$(ARCH)/syscall.o \
libgcc/__divdi3.o \
libgcc/__moddi3.o \
libgcc/__udivdi3.o \
diff --git a/klibc/klibc/arch/mips/include/klibc/archsetjmp.h b/klibc/klibc/arch/mips/include/klibc/archsetjmp.h
deleted file mode 100644
index 40e5be2736..0000000000
--- a/klibc/klibc/arch/mips/include/klibc/archsetjmp.h
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * 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 */
diff --git a/klibc/klibc/arch/mips/include/klibc/archsignal.h b/klibc/klibc/arch/mips/include/klibc/archsignal.h
deleted file mode 100644
index 3b72908636..0000000000
--- a/klibc/klibc/arch/mips/include/klibc/archsignal.h
+++ /dev/null
@@ -1,13 +0,0 @@
-/*
- * arch/mips/include/klibc/archsignal.h
- *
- * Architecture-specific signal definitions
- *
- */
-
-#ifndef _KLIBC_ARCHSIGNAL_H
-#define _KLIBC_ARCHSIGNAL_H
-
-/* No special stuff for this architecture */
-
-#endif
diff --git a/klibc/klibc/arch/mips/include/klibc/archsys.h b/klibc/klibc/arch/mips/include/klibc/archsys.h
deleted file mode 100644
index f696cdfaa7..0000000000
--- a/klibc/klibc/arch/mips/include/klibc/archsys.h
+++ /dev/null
@@ -1,12 +0,0 @@
-/*
- * 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 */
diff --git a/klibc/klibc/arch/mips/include/machine/asm.h b/klibc/klibc/arch/mips/include/machine/asm.h
deleted file mode 100644
index e5239a6cef..0000000000
--- a/klibc/klibc/arch/mips/include/machine/asm.h
+++ /dev/null
@@ -1,11 +0,0 @@
-/*
- * 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 */
diff --git a/klibc/klibc/arch/mips/include/sgidefs.h b/klibc/klibc/arch/mips/include/sgidefs.h
deleted file mode 100644
index eb103ace2c..0000000000
--- a/klibc/klibc/arch/mips/include/sgidefs.h
+++ /dev/null
@@ -1,20 +0,0 @@
-/*
- * 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 */
diff --git a/klibc/klibc/arch/mips/klibc.ld b/klibc/klibc/arch/mips/klibc.ld
new file mode 100644
index 0000000000..d75c9de70c
--- /dev/null
+++ b/klibc/klibc/arch/mips/klibc.ld
@@ -0,0 +1,217 @@
+/* Linker script for klibc.so, needed because of the the damned
+ GNU ld script headers problem */
+
+OUTPUT_FORMAT("elf32-tradbigmips", "elf32-tradbigmips",
+ "elf32-tradlittlemips")
+OUTPUT_ARCH(mips)
+ENTRY(__start)
+SECTIONS
+{
+ /* Read-only sections, merged into text segment: */
+ /* 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 */
+ . = 0x00200400;
+ .interp : { *(.interp) }
+ .reginfo : { *(.reginfo) }
+ .dynamic : { *(.dynamic) }
+ .hash : { *(.hash) }
+ .dynsym : { *(.dynsym) }
+ .dynstr : { *(.dynstr) }
+ .gnu.version : { *(.gnu.version) }
+ .gnu.version_d : { *(.gnu.version_d) }
+ .gnu.version_r : { *(.gnu.version_r) }
+ .rel.dyn :
+ {
+ *(.rel.init)
+ *(.rel.text .rel.text.* .rel.gnu.linkonce.t.*)
+ *(.rel.fini)
+ *(.rel.rodata .rel.rodata.* .rel.gnu.linkonce.r.*)
+ *(.rel.data .rel.data.* .rel.gnu.linkonce.d.*)
+ *(.rel.tdata .rel.tdata.* .rel.gnu.linkonce.td.*)
+ *(.rel.tbss .rel.tbss.* .rel.gnu.linkonce.tb.*)
+ *(.rel.ctors)
+ *(.rel.dtors)
+ *(.rel.got)
+ *(.rel.sdata .rel.sdata.* .rel.gnu.linkonce.s.*)
+ *(.rel.sbss .rel.sbss.* .rel.gnu.linkonce.sb.*)
+ *(.rel.sdata2 .rel.sdata2.* .rel.gnu.linkonce.s2.*)
+ *(.rel.sbss2 .rel.sbss2.* .rel.gnu.linkonce.sb2.*)
+ *(.rel.bss .rel.bss.* .rel.gnu.linkonce.b.*)
+ }
+ .rela.dyn :
+ {
+ *(.rela.init)
+ *(.rela.text .rela.text.* .rela.gnu.linkonce.t.*)
+ *(.rela.fini)
+ *(.rela.rodata .rela.rodata.* .rela.gnu.linkonce.r.*)
+ *(.rela.data .rela.data.* .rela.gnu.linkonce.d.*)
+ *(.rela.tdata .rela.tdata.* .rela.gnu.linkonce.td.*)
+ *(.rela.tbss .rela.tbss.* .rela.gnu.linkonce.tb.*)
+ *(.rela.ctors)
+ *(.rela.dtors)
+ *(.rela.got)
+ *(.rela.sdata .rela.sdata.* .rela.gnu.linkonce.s.*)
+ *(.rela.sbss .rela.sbss.* .rela.gnu.linkonce.sb.*)
+ *(.rela.sdata2 .rela.sdata2.* .rela.gnu.linkonce.s2.*)
+ *(.rela.sbss2 .rela.sbss2.* .rela.gnu.linkonce.sb2.*)
+ *(.rela.bss .rela.bss.* .rela.gnu.linkonce.b.*)
+ }
+ .rel.plt : { *(.rel.plt) }
+ .rela.plt : { *(.rela.plt) }
+ .init :
+ {
+ KEEP (*(.init))
+ } =0
+ .plt : { *(.plt) }
+ .text :
+ {
+ _ftext = . ;
+ *(.text .stub .text.* .gnu.linkonce.t.*)
+ /* .gnu.warning sections are handled specially by elf32.em. */
+ *(.gnu.warning)
+ *(.mips16.fn.*) *(.mips16.call.*)
+ } =0
+ .fini :
+ {
+ KEEP (*(.fini))
+ } =0
+ PROVIDE (__etext = .);
+ PROVIDE (_etext = .);
+ PROVIDE (etext = .);
+ .rodata : { *(.rodata .rodata.* .gnu.linkonce.r.*) }
+ .rodata1 : { *(.rodata1) }
+ .sdata2 : { *(.sdata2 .sdata2.* .gnu.linkonce.s2.*) }
+ .sbss2 : { *(.sbss2 .sbss2.* .gnu.linkonce.sb2.*) }
+ .eh_frame_hdr : { *(.eh_frame_hdr) }
+ /* Adjust the address for the data segment. We want to adjust up to
+ the same address within the page on the next page up. */
+ . = ALIGN(8192);
+ /* Ensure the __preinit_array_start label is properly aligned. We
+ could instead move the label definition inside the section, but
+ the linker would then create the section even if it turns out to
+ be empty, which isn't pretty. */
+ . = ALIGN(32 / 8);
+ PROVIDE (__preinit_array_start = .);
+ .preinit_array : { *(.preinit_array) }
+ PROVIDE (__preinit_array_end = .);
+ PROVIDE (__init_array_start = .);
+ .init_array : { *(.init_array) }
+ PROVIDE (__init_array_end = .);
+ PROVIDE (__fini_array_start = .);
+ .fini_array : { *(.fini_array) }
+ PROVIDE (__fini_array_end = .);
+ .data :
+ {
+ _fdata = . ;
+ *(.data .data.* .gnu.linkonce.d.*)
+ SORT(CONSTRUCTORS)
+ }
+ .data1 : { *(.data1) }
+ .tdata : { *(.tdata .tdata.* .gnu.linkonce.td.*) }
+ .tbss : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) }
+ .eh_frame : { KEEP (*(.eh_frame)) }
+ .gcc_except_table : { *(.gcc_except_table) }
+ .ctors :
+ {
+ /* gcc uses crtbegin.o to find the start of
+ the constructors, so we make sure it is
+ first. Because this is a wildcard, it
+ doesn't matter if the user does not
+ actually link against crtbegin.o; the
+ linker won't look for a file to match a
+ wildcard. The wildcard also means that it
+ doesn't matter which directory crtbegin.o
+ is in. */
+ KEEP (*crtbegin*.o(.ctors))
+ /* We don't want to include the .ctor section from
+ from the crtend.o file until after the sorted ctors.
+ The .ctor section from the crtend file contains the
+ end of ctors marker and it must be last */
+ KEEP (*(EXCLUDE_FILE (*crtend*.o ) .ctors))
+ KEEP (*(SORT(.ctors.*)))
+ KEEP (*(.ctors))
+ }
+ .dtors :
+ {
+ KEEP (*crtbegin*.o(.dtors))
+ KEEP (*(EXCLUDE_FILE (*crtend*.o ) .dtors))
+ KEEP (*(SORT(.dtors.*)))
+ KEEP (*(.dtors))
+ }
+ .jcr : { KEEP (*(.jcr)) }
+ _gp = ALIGN(16) + 0x7ff0;
+ .got : { *(.got.plt) *(.got) }
+ /* We want the small data sections together, so single-instruction offsets
+ can access them all, and initialized data all before uninitialized, so
+ we can shorten the on-disk segment size. */
+ .sdata :
+ {
+ *(.sdata .sdata.* .gnu.linkonce.s.*)
+ }
+ .lit8 : { *(.lit8) }
+ .lit4 : { *(.lit4) }
+ _edata = .;
+ PROVIDE (edata = .);
+ __bss_start = .;
+ _fbss = .;
+ .sbss :
+ {
+ PROVIDE (__sbss_start = .);
+ PROVIDE (___sbss_start = .);
+ *(.dynsbss)
+ *(.sbss .sbss.* .gnu.linkonce.sb.*)
+ *(.scommon)
+ PROVIDE (__sbss_end = .);
+ PROVIDE (___sbss_end = .);
+ }
+ .bss :
+ {
+ *(.dynbss)
+ *(.bss .bss.* .gnu.linkonce.b.*)
+ *(COMMON)
+ /* Align here to ensure that the .bss section occupies space up to
+ _end. Align after .bss to ensure correct alignment even if the
+ .bss section disappears because there are no input sections. */
+ . = ALIGN(32 / 8);
+ }
+ . = ALIGN(32 / 8);
+ _end = .;
+ PROVIDE (end = .);
+ /* Stabs debugging sections. */
+ .stab 0 : { *(.stab) }
+ .stabstr 0 : { *(.stabstr) }
+ .stab.excl 0 : { *(.stab.excl) }
+ .stab.exclstr 0 : { *(.stab.exclstr) }
+ .stab.index 0 : { *(.stab.index) }
+ .stab.indexstr 0 : { *(.stab.indexstr) }
+ .comment 0 : { *(.comment) }
+ /* DWARF debug sections.
+ Symbols in the DWARF debugging sections are relative to the beginning
+ of the section so we begin them at 0. */
+ /* DWARF 1 */
+ .debug 0 : { *(.debug) }
+ .line 0 : { *(.line) }
+ /* GNU DWARF 1 extensions */
+ .debug_srcinfo 0 : { *(.debug_srcinfo) }
+ .debug_sfnames 0 : { *(.debug_sfnames) }
+ /* DWARF 1.1 and DWARF 2 */
+ .debug_aranges 0 : { *(.debug_aranges) }
+ .debug_pubnames 0 : { *(.debug_pubnames) }
+ /* DWARF 2 */
+ .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }
+ .debug_abbrev 0 : { *(.debug_abbrev) }
+ .debug_line 0 : { *(.debug_line) }
+ .debug_frame 0 : { *(.debug_frame) }
+ .debug_str 0 : { *(.debug_str) }
+ .debug_loc 0 : { *(.debug_loc) }
+ .debug_macinfo 0 : { *(.debug_macinfo) }
+ /* SGI/MIPS DWARF 2 extensions */
+ .debug_weaknames 0 : { *(.debug_weaknames) }
+ .debug_funcnames 0 : { *(.debug_funcnames) }
+ .debug_typenames 0 : { *(.debug_typenames) }
+ .debug_varnames 0 : { *(.debug_varnames) }
+ .gptab.sdata : { *(.gptab.data) *(.gptab.sdata) }
+ .gptab.sbss : { *(.gptab.bss) *(.gptab.sbss) }
+ /DISCARD/ : { *(.note.GNU-stack) }
+}
diff --git a/klibc/klibc/arch/mips/syscall.S b/klibc/klibc/arch/mips/syscall.S
new file mode 100644
index 0000000000..d5c1fe1c7d
--- /dev/null
+++ b/klibc/klibc/arch/mips/syscall.S
@@ -0,0 +1,15 @@
+#include <asm/asm.h>
+#include <asm/regdef.h>
+#include <asm/unistd.h>
+
+ .set noreorder
+
+LEAF(__syscall_common)
+ syscall
+ beqz a3, 1f
+ # sw is actually two instructions; the first one goes
+ # in the branch delay slot
+ sw v0, errno
+ li v0, -1
+1: jr ra
+ END(__syscall_common)
diff --git a/klibc/klibc/arch/mips/sysstub.ph b/klibc/klibc/arch/mips/sysstub.ph
new file mode 100644
index 0000000000..abe599c17d
--- /dev/null
+++ b/klibc/klibc/arch/mips/sysstub.ph
@@ -0,0 +1,30 @@
+# -*- perl -*-
+#
+# arch/mips/sysstub.ph
+#
+# Script to generate system call stubs
+#
+
+# On MIPS, most system calls follow the standard convention, with the
+# system call number in r0 (v0), return an error value in r19 (a3) as
+# well as the return value in r0 (v0).
+
+sub make_sysstub($$$$@) {
+ my($fname, $type, $sname, $stype, @args) = @_;
+
+ $stype = $stype || 'common';
+ open(OUT, '>', "syscalls/${fname}.S");
+ print OUT "#include <asm/asm.h>\n";
+ print OUT "#include <asm/regdef.h>\n";
+ print OUT "#include <asm/unistd.h>\n";
+ print OUT "\n";
+ print OUT "\t.set noreorder\n";
+ print OUT "\n";
+ print OUT "LEAF(${fname})\n";
+ print OUT "\tj\t__syscall_${stype}\n";
+ print OUT "\t li\tv0, __NR_${sname}\n";
+ print OUT "\tEND(${fname})\n";
+ close(OUT);
+}
+
+1;
diff --git a/klibc/klibc/arch/mips/vfork.S b/klibc/klibc/arch/mips/vfork.S
index aca8083aa4..9829867fab 100644
--- a/klibc/klibc/arch/mips/vfork.S
+++ b/klibc/klibc/arch/mips/vfork.S
@@ -6,14 +6,11 @@
#define CLONE_VFORK 0x00004000
#define SIGCHLD 18
+ .set noreorder
+
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
+ j __syscall_common
+ li v0, __NR_clone
END(vfork)
diff --git a/klibc/klibc/arch/mips64/include/klibc/archsignal.h b/klibc/klibc/arch/mips64/include/klibc/archsignal.h
deleted file mode 100644
index 56b0fd323e..0000000000
--- a/klibc/klibc/arch/mips64/include/klibc/archsignal.h
+++ /dev/null
@@ -1,13 +0,0 @@
-/*
- * arch/mips64/include/klibc/archsignal.h
- *
- * Architecture-specific signal definitions
- *
- */
-
-#ifndef _KLIBC_ARCHSIGNAL_H
-#define _KLIBC_ARCHSIGNAL_H
-
-/* No special stuff for this architecture */
-
-#endif
diff --git a/klibc/klibc/arch/mips64/include/klibc/archsys.h b/klibc/klibc/arch/mips64/include/klibc/archsys.h
deleted file mode 100644
index 81e5106e16..0000000000
--- a/klibc/klibc/arch/mips64/include/klibc/archsys.h
+++ /dev/null
@@ -1,12 +0,0 @@
-/*
- * 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 */
diff --git a/klibc/klibc/arch/parisc/Makefile.inc b/klibc/klibc/arch/parisc/Makefile.inc
index abe9155bf4..980a543ed2 100644
--- a/klibc/klibc/arch/parisc/Makefile.inc
+++ b/klibc/klibc/arch/parisc/Makefile.inc
@@ -8,8 +8,12 @@
#
ARCHOBJS = \
- arch/$(ARCH)/setjmp.o
+ arch/$(ARCH)/setjmp.o \
+ arch/$(ARCH)/syscall.o
ARCHOOBJS = $(patsubst %o,%.lo,%(ARCHOBJS))
archclean:
+
+arch/$(ARCH)/syscall.o: arch/$(ARCH)/syscall.c
+ $(CC) $(CFLAGS) -ffixed-r20 -c -o $@ $<
diff --git a/klibc/klibc/arch/parisc/include/klibc/archsignal.h b/klibc/klibc/arch/parisc/include/klibc/archsignal.h
deleted file mode 100644
index 3190e8528e..0000000000
--- a/klibc/klibc/arch/parisc/include/klibc/archsignal.h
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * arch/parisc/include/klibc/archsignal.h
- *
- * Architecture-specific signal definitions
- *
- */
-
-#ifndef _KLIBC_ARCHSIGNAL_H
-#define _KLIBC_ARCHSIGNAL_H
-
-#define _NSIG 64
-#define _NSIG_SZ (_NSIG / LONG_BIT)
-
-typedef struct {
- unsigned long sig[_NSIG_SZ];
-} sigset_t;
-
-struct sigaction {
- __sighandler_t sa_handler;
- unsigned long sa_flags;
- sigset_t sa_mask;
-};
-
-#endif
diff --git a/klibc/klibc/arch/parisc/include/klibc/archsys.h b/klibc/klibc/arch/parisc/include/klibc/archsys.h
deleted file mode 100644
index 5013ba8794..0000000000
--- a/klibc/klibc/arch/parisc/include/klibc/archsys.h
+++ /dev/null
@@ -1,12 +0,0 @@
-/*
- * 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 */
diff --git a/klibc/klibc/arch/parisc/syscall.c b/klibc/klibc/arch/parisc/syscall.c
new file mode 100644
index 0000000000..99ef5fe103
--- /dev/null
+++ b/klibc/klibc/arch/parisc/syscall.c
@@ -0,0 +1,29 @@
+/*
+ * arch/parisc/syscall.c
+ *
+ * This function is called from a stub with %r20 already set up.
+ * Compile this function with -ffixed-r20 so that it doesn't clobber
+ * this register by mistake.
+ */
+
+#include <klibc/compiler.h>
+#include <errno.h>
+
+long __syscall_common(long a0, long a1, long a2, long a3, long a4, long a5)
+{
+ register unsigned long rv asm ("r28");
+
+ asm volatile("\tble 0x100(%%sr2, %%r0)\n"
+ : "=r" (rv)
+ : "r" (a0), "r" (a1), "r" (a2), "r" (a3), "r" (a4), "r" (a5)
+ : "%r1", "%r2", "%r29", "%r31");
+
+ if ( __unlikely(rv >= -4095UL) ) {
+ errno = -rv;
+ return -1L;
+ } else {
+ return (long)rv;
+ }
+}
+
+
diff --git a/klibc/klibc/arch/parisc/sysstub.ph b/klibc/klibc/arch/parisc/sysstub.ph
new file mode 100644
index 0000000000..eb6b5dd92a
--- /dev/null
+++ b/klibc/klibc/arch/parisc/sysstub.ph
@@ -0,0 +1,29 @@
+# -*- perl -*-
+#
+# arch/parisc/sysstub.ph
+#
+# Script to generate system call stubs
+#
+
+sub make_sysstub($$$$@) {
+ my($fname, $type, $sname, $stype, @args) = @_;
+
+ open(OUT, '>', "syscalls/${fname}.S");
+ print OUT "#include <asm/unistd.h>\n";
+ print OUT "\n";
+ print OUT "\t.text\n";
+ print OUT "\t.align 4\n";
+ print OUT "\t.import __syscall_common, code\n";
+ print OUT "\t.global ${fname}\n";
+ print OUT "\t.export ${fname}, code\n";
+ print OUT "\t.type ${fname}, @function\n";
+ print OUT "\t.proc\n";
+ print OUT "\.callinfo\n";
+ print OUT "${fname}:\n";
+ print OUT "\tb\t__syscall_common\n";
+ print OUT "\t ldo\t__NR_${sname}(%r0),%r20\n";
+ print OUT "\t.procend\n";
+ close(OUT);
+}
+
+1;
diff --git a/klibc/klibc/arch/ppc/MCONFIG b/klibc/klibc/arch/ppc/MCONFIG
index fcb0992150..ff7c44db9a 100644
--- a/klibc/klibc/arch/ppc/MCONFIG
+++ b/klibc/klibc/arch/ppc/MCONFIG
@@ -9,3 +9,10 @@
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
+# 256-16 MB - normal binaries start at 256 MB, and jumps are limited
+# to +/- 16 MB
+SHAREDFLAGS = -Ttext 0x0f000200
diff --git a/klibc/klibc/arch/ppc/Makefile.inc b/klibc/klibc/arch/ppc/Makefile.inc
index 3bd2c0643c..c6bb975f0f 100644
--- a/klibc/klibc/arch/ppc/Makefile.inc
+++ b/klibc/klibc/arch/ppc/Makefile.inc
@@ -9,6 +9,7 @@
ARCHOBJS = \
arch/$(ARCH)/setjmp.o \
+ arch/$(ARCH)/syscall.o \
libgcc/__divdi3.o \
libgcc/__moddi3.o \
libgcc/__udivdi3.o \
diff --git a/klibc/klibc/arch/ppc/include/klibc/archsetjmp.h b/klibc/klibc/arch/ppc/include/klibc/archsetjmp.h
deleted file mode 100644
index 53e2fccc3b..0000000000
--- a/klibc/klibc/arch/ppc/include/klibc/archsetjmp.h
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * 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 */
diff --git a/klibc/klibc/arch/ppc/include/klibc/archsignal.h b/klibc/klibc/arch/ppc/include/klibc/archsignal.h
deleted file mode 100644
index 567a547ef9..0000000000
--- a/klibc/klibc/arch/ppc/include/klibc/archsignal.h
+++ /dev/null
@@ -1,13 +0,0 @@
-/*
- * arch/ppc/include/klibc/archsignal.h
- *
- * Architecture-specific signal definitions
- *
- */
-
-#ifndef _KLIBC_ARCHSIGNAL_H
-#define _KLIBC_ARCHSIGNAL_H
-
-/* No special stuff for this architecture */
-
-#endif
diff --git a/klibc/klibc/arch/ppc/include/klibc/archsys.h b/klibc/klibc/arch/ppc/include/klibc/archsys.h
deleted file mode 100644
index 17a28859e5..0000000000
--- a/klibc/klibc/arch/ppc/include/klibc/archsys.h
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * 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), \
- "+r" (__sc_4), \
- "+r" (__sc_5), \
- "+r" (__sc_6), \
- "+r" (__sc_7), \
- "+r" (__sc_8) \
- : : "cr0", "ctr", "memory", \
- "r9", "r10", "r11", "r12"); \
- __sc_ret = __sc_3; \
- __sc_err = __sc_0; \
- } \
- if (__sc_err & 0x10000000) \
- { \
- errno = (int)__sc_ret; \
- __sc_ret = -1; \
- } \
- return (type)__sc_ret; \
-}
-
-#endif /* _syscall6() missing */
-
-#endif /* _KLIBC_ARCHSYS_H */
diff --git a/klibc/klibc/arch/ppc/syscall.S b/klibc/klibc/arch/ppc/syscall.S
new file mode 100644
index 0000000000..0a7c37c903
--- /dev/null
+++ b/klibc/klibc/arch/ppc/syscall.S
@@ -0,0 +1,16 @@
+/*
+ * arch/ppc/syscall.S
+ *
+ * Common error-handling path for system calls.
+ */
+
+ .text
+ .align 2
+ .globl __syscall_error
+ .type __syscall_error,@function
+__syscall_error:
+ lis 9,errno@ha
+ stw 3,errno@l(9)
+ li 3,-1
+ blr
+ .size __syscall_error,.-__syscall_error
diff --git a/klibc/klibc/arch/ppc/sysstub.ph b/klibc/klibc/arch/ppc/sysstub.ph
new file mode 100644
index 0000000000..542ab5575c
--- /dev/null
+++ b/klibc/klibc/arch/ppc/sysstub.ph
@@ -0,0 +1,25 @@
+# -*- perl -*-
+#
+# arch/ppc/sysstub.ph
+#
+# Script to generate system call stubs
+#
+
+sub make_sysstub($$$$@) {
+ my($fname, $type, $sname, $stype, @args) = @_;
+
+ open(OUT, '>', "syscalls/${fname}.S");
+ print OUT "#include <asm/unistd.h>\n";
+ print OUT "\n";
+ print OUT "\t.type ${fname},\@function\n";
+ print OUT "\t.globl ${fname}\n";
+ print OUT "${fname}:\n";
+ print OUT "\tli 0,__NR_${sname}\n";
+ print OUT "\tsc\n";
+ print OUT "\tbnslr\n";
+ print OUT "\tb __syscall_error\n";
+ print OUT "\t.size ${fname},.-${fname}\n";
+ close(OUT);
+}
+
+1;
diff --git a/klibc/klibc/arch/ppc64/MCONFIG b/klibc/klibc/arch/ppc64/MCONFIG
index 6997693e99..86526f895c 100644
--- a/klibc/klibc/arch/ppc64/MCONFIG
+++ b/klibc/klibc/arch/ppc64/MCONFIG
@@ -9,3 +9,10 @@
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
+# 256-16 MB - normal binaries start at 256 MB, and jumps are limited
+# to +/- 16 MB
+SHAREDFLAGS = -Ttext 0x0f000200
diff --git a/klibc/klibc/arch/ppc64/Makefile.inc b/klibc/klibc/arch/ppc64/Makefile.inc
index 3ab3a8c8e6..928df1aeb7 100644
--- a/klibc/klibc/arch/ppc64/Makefile.inc
+++ b/klibc/klibc/arch/ppc64/Makefile.inc
@@ -8,8 +8,18 @@
#
ARCHOBJS = \
- arch/$(ARCH)/setjmp.o
+ arch/$(ARCH)/setjmp.o \
+ arch/$(ARCH)/syscall.o
ARCHSOOBJS = $(patsubst %.o,%.lo,$(ARCHOBJS))
+INTERP_O = interp1.o
+
+interp.o: interp1.o klibc.got
+ $(LD) $(LDFLAGS) -r -o $@ interp1.o klibc.got
+
+klibc.got: $(SOHASH)
+ $(OBJCOPY) -j.got $< $@
+
archclean:
+ rm -f klibc.got
diff --git a/klibc/klibc/arch/ppc64/include/klibc/archsetjmp.h b/klibc/klibc/arch/ppc64/include/klibc/archsetjmp.h
deleted file mode 100644
index 006a2e27be..0000000000
--- a/klibc/klibc/arch/ppc64/include/klibc/archsetjmp.h
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * arch/ppc64/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 */
diff --git a/klibc/klibc/arch/ppc64/include/klibc/archsignal.h b/klibc/klibc/arch/ppc64/include/klibc/archsignal.h
deleted file mode 100644
index 8452f6e4bc..0000000000
--- a/klibc/klibc/arch/ppc64/include/klibc/archsignal.h
+++ /dev/null
@@ -1,13 +0,0 @@
-/*
- * arch/ppc64/include/klibc/archsignal.h
- *
- * Architecture-specific signal definitions
- *
- */
-
-#ifndef _KLIBC_ARCHSIGNAL_H
-#define _KLIBC_ARCHSIGNAL_H
-
-/* No special stuff for this architecture */
-
-#endif
diff --git a/klibc/klibc/arch/ppc64/include/klibc/archsys.h b/klibc/klibc/arch/ppc64/include/klibc/archsys.h
deleted file mode 100644
index 4f81fee00d..0000000000
--- a/klibc/klibc/arch/ppc64/include/klibc/archsys.h
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * 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 */
diff --git a/klibc/klibc/arch/ppc64/setjmp.S b/klibc/klibc/arch/ppc64/setjmp.S
index 1dcc67035e..30db419140 100644
--- a/klibc/klibc/arch/ppc64/setjmp.S
+++ b/klibc/klibc/arch/ppc64/setjmp.S
@@ -2,7 +2,6 @@
# arch/ppc64/setjmp.S
#
# Basic setjmp/longjmp implementation
-# This file was derived from the equivalent file in NetBSD
#
.text
@@ -17,13 +16,33 @@ setjmp:
.globl setjmp
.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 */
+ mflr %r11 /* save return address */
+ mfcr %r12 /* save condition register */
+ std %r2,0(%r3) /* save TOC pointer (not needed) */
+ stdu %r1,8(%r3) /* save stack pointer */
+ stdu %r11,8(%r3)
+ stdu %r12,8(%r3)
+ stdu %r13,8(%r3) /* save caller saved regs */
+ stdu %r14,8(%r3)
+ stdu %r15,8(%r3)
+ stdu %r16,8(%r3)
+ stdu %r17,8(%r3)
+ stdu %r18,8(%r3)
+ stdu %r19,8(%r3)
+ stdu %r20,8(%r3)
+ stdu %r21,8(%r3)
+ stdu %r22,8(%r3)
+ stdu %r23,8(%r3)
+ stdu %r24,8(%r3)
+ stdu %r25,8(%r3)
+ stdu %r26,8(%r3)
+ stdu %r27,8(%r3)
+ stdu %r28,8(%r3)
+ stdu %r29,8(%r3)
+ stdu %r30,8(%r3)
+ std %r31,8(%r3)
+ li %r3,0 /* indicate success */
+ blr /* return */
.size .setjmp,.-.setjmp
.section ".opd","aw"
@@ -35,12 +54,32 @@ longjmp:
.globl longjmp
.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 */
+ ld %r2,0(%r3) /* restore TOC pointer (not needed) */
+ ldu %r1,8(%r3) /* restore stack */
+ ldu %r11,8(%r3)
+ ldu %r12,8(%r3)
+ ldu %r13,8(%r3) /* restore caller saved regs */
+ ldu %r14,8(%r3)
+ ldu %r15,8(%r3)
+ ldu %r16,8(%r3)
+ ldu %r17,8(%r3)
+ ldu %r18,8(%r3)
+ ldu %r19,8(%r3)
+ ldu %r20,8(%r3)
+ ldu %r21,8(%r3)
+ ldu %r22,8(%r3)
+ ldu %r23,8(%r3)
+ ldu %r24,8(%r3)
+ ldu %r25,8(%r3)
+ ldu %r26,8(%r3)
+ ldu %r27,8(%r3)
+ ldu %r28,8(%r3)
+ ldu %r29,8(%r3)
+ ldu %r30,8(%r3)
+ ld %r31,8(%r3)
+ mtlr %r11 /* restore LR */
+ mtcr %r12 /* restore CR */
+ mr %r3,%r4 /* get return value */
+ blr /* return */
.size .longjmp,.-.longjmp
diff --git a/klibc/klibc/arch/ppc64/syscall.c b/klibc/klibc/arch/ppc64/syscall.c
new file mode 100644
index 0000000000..a5895fe88e
--- /dev/null
+++ b/klibc/klibc/arch/ppc64/syscall.c
@@ -0,0 +1,14 @@
+/*
+ * arch/ppc64/syscall.c
+ *
+ * Common error-handling path for system calls.
+ * The return value from __syscall_error becomes the
+ * return value from the system call.
+ */
+#include <errno.h>
+
+long int __syscall_error(long int err)
+{
+ errno = err;
+ return -1;
+}
diff --git a/klibc/klibc/arch/ppc64/sysstub.ph b/klibc/klibc/arch/ppc64/sysstub.ph
new file mode 100644
index 0000000000..1469cc6071
--- /dev/null
+++ b/klibc/klibc/arch/ppc64/sysstub.ph
@@ -0,0 +1,34 @@
+# -*- perl -*-
+#
+# arch/ppc64/sysstub.ph
+#
+# Script to generate system call stubs
+#
+
+sub make_sysstub($$$$@) {
+ my($fname, $type, $sname, $stype, @args) = @_;
+
+ open(OUT, '>', "syscalls/${fname}.S");
+ print OUT "#include <asm/unistd.h>\n";
+ print OUT "\n";
+ print OUT "\t.globl ${fname}\n";
+ print OUT "\t.section \".opd\",\"aw\"\n";
+ print OUT "\t.align 3\n";
+ print OUT "${fname}:\n";
+ print OUT "\t.quad .${fname},.TOC.\@tocbase,0\n";
+ print OUT "\t.size ${fname},24\n";
+ print OUT "\t.text\n";
+ print OUT "\t.type .${fname},\@function\n";
+ print OUT "\t.globl .${fname}\n";
+ print OUT ".${fname}:\n";
+ print OUT "\tli 0,__NR_${sname}\n";
+ print OUT "\tsc\n";
+ print OUT "\tmfcr 0\n";
+ print OUT "\trldicl. 9,0,36,63\n";
+ print OUT "\tbeqlr- 0\n";
+ print OUT "\tb .__syscall_error\n";
+ print OUT "\t.size .${fname},.-.${fname}\n";
+ close(OUT);
+}
+
+1;
diff --git a/klibc/klibc/arch/s390/Makefile.inc b/klibc/klibc/arch/s390/Makefile.inc
index c50f4f2886..49b64ddbc6 100644
--- a/klibc/klibc/arch/s390/Makefile.inc
+++ b/klibc/klibc/arch/s390/Makefile.inc
@@ -9,6 +9,8 @@
ARCHOBJS = \
arch/$(ARCH)/setjmp.o \
+ arch/$(ARCH)/mmap.o \
+ arch/$(ARCH)/syscall.o \
libgcc/__divdi3.o \
libgcc/__moddi3.o \
libgcc/__udivdi3.o \
diff --git a/klibc/klibc/arch/s390/include/klibc/archsetjmp.h b/klibc/klibc/arch/s390/include/klibc/archsetjmp.h
deleted file mode 100644
index 11a641ed5a..0000000000
--- a/klibc/klibc/arch/s390/include/klibc/archsetjmp.h
+++ /dev/null
@@ -1,15 +0,0 @@
-/*
- * 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 */
diff --git a/klibc/klibc/arch/s390/include/klibc/archsignal.h b/klibc/klibc/arch/s390/include/klibc/archsignal.h
deleted file mode 100644
index 1f8de28b4b..0000000000
--- a/klibc/klibc/arch/s390/include/klibc/archsignal.h
+++ /dev/null
@@ -1,13 +0,0 @@
-/*
- * arch/s390/include/klibc/archsignal.h
- *
- * Architecture-specific signal definitions
- *
- */
-
-#ifndef _KLIBC_ARCHSIGNAL_H
-#define _KLIBC_ARCHSIGNAL_H
-
-/* No special stuff for this architecture */
-
-#endif
diff --git a/klibc/klibc/arch/s390/include/klibc/archsys.h b/klibc/klibc/arch/s390/include/klibc/archsys.h
deleted file mode 100644
index 1cd0948f3c..0000000000
--- a/klibc/klibc/arch/s390/include/klibc/archsys.h
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * 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 */
diff --git a/klibc/klibc/arch/s390/mmap.c b/klibc/klibc/arch/s390/mmap.c
new file mode 100644
index 0000000000..51ff07f44c
--- /dev/null
+++ b/klibc/klibc/arch/s390/mmap.c
@@ -0,0 +1,41 @@
+#include <sys/types.h>
+#include <linux/unistd.h>
+
+struct mmap_arg_struct {
+ unsigned long addr;
+ unsigned long len;
+ unsigned long prot;
+ unsigned long flags;
+ unsigned long fd;
+ unsigned long offset;
+};
+
+void * __mmap2(void * addr, size_t len, int prot, int flags,
+ int fd, long offset)
+{
+ struct mmap_arg_struct args = {
+ (unsigned long) addr,
+ (unsigned long) len,
+ (unsigned long) prot,
+ (unsigned long) flags,
+ (unsigned long) fd,
+ (unsigned long) offset,
+ };
+
+ register struct mmap_arg_struct *__arg1 asm("2") = &args;
+ register long __svcres asm("2");
+ unsigned long __res;
+
+ __asm__ __volatile__ (
+ " svc %b1\n"
+ : "=d" (__svcres)
+ : "i" (__NR_mmap2),
+ "0" (__arg1)
+ : "1", "cc", "memory");
+ __res = __svcres;
+ if (__res >= (unsigned long)-125) {
+ errno = -__res;
+ __res = -1;
+ }
+ return (void *)__res;
+}
diff --git a/klibc/klibc/arch/s390/syscall.c b/klibc/klibc/arch/s390/syscall.c
new file mode 100644
index 0000000000..c0f17c453c
--- /dev/null
+++ b/klibc/klibc/arch/s390/syscall.c
@@ -0,0 +1,16 @@
+/*
+ * arch/s390/syscall.c
+ *
+ * Common error-handling path for system calls.
+ * The return value from __syscall_common becomes the
+ * return value from the system call.
+ */
+#include <errno.h>
+
+long int __syscall_common(long int err)
+{
+ if ((unsigned long)(err) < (unsigned long)(-125))
+ return err;
+ errno = err;
+ return -1;
+}
diff --git a/klibc/klibc/arch/s390/sysstub.ph b/klibc/klibc/arch/s390/sysstub.ph
new file mode 100644
index 0000000000..3838a1f1b2
--- /dev/null
+++ b/klibc/klibc/arch/s390/sysstub.ph
@@ -0,0 +1,31 @@
+# -*- perl -*-
+#
+# arch/s390/sysstub.ph
+#
+# Script to generate system call stubs
+#
+
+sub make_sysstub($$$$@) {
+ my($fname, $type, $sname, $stype, @args) = @_;
+
+ open(OUT, '>', "syscalls/${fname}.S");
+ print OUT "#include <asm/unistd.h>\n";
+ print OUT "\n";
+ print OUT "\t.type ${fname},\@function\n";
+ print OUT "\t.globl ${fname}\n";
+ print OUT "${fname}:\n";
+ print OUT ".if __NR_${sname} < 256\n";
+ print OUT "\tsvc __NR_${sname}\n";
+ print OUT ".else\n";
+ print OUT "\tlhi %r1,__NR_${sname}\n";
+ print OUT "\tsvc 0\n";
+ print OUT ".endif\n";
+ print OUT "\tbras %r3,1f\n";
+ print OUT "\t.long __syscall_common\n";
+ print OUT "1:\tl %r3,0(%r3)\n";
+ print OUT "\tbr %r3\n";
+ print OUT "\t.size ${fname},.-${fname}\n";
+ close(OUT);
+}
+
+1;
diff --git a/klibc/klibc/arch/s390x/Makefile.inc b/klibc/klibc/arch/s390x/Makefile.inc
index eff8f951ac..9d614e07b2 100644
--- a/klibc/klibc/arch/s390x/Makefile.inc
+++ b/klibc/klibc/arch/s390x/Makefile.inc
@@ -8,7 +8,9 @@
#
ARCHOBJS = \
- arch/$(ARCH)/setjmp.o
+ arch/$(ARCH)/setjmp.o \
+ arch/$(ARCH)/mmap.o \
+ arch/$(ARCH)/syscall.o
ARCHSOOBJS = $(patsubst %.o,%.lo,$(ARCHOBJS))
diff --git a/klibc/klibc/arch/s390x/include/klibc/archsetjmp.h b/klibc/klibc/arch/s390x/include/klibc/archsetjmp.h
deleted file mode 100644
index dd3ed0d47c..0000000000
--- a/klibc/klibc/arch/s390x/include/klibc/archsetjmp.h
+++ /dev/null
@@ -1,15 +0,0 @@
-/*
- * 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 */
diff --git a/klibc/klibc/arch/s390x/include/klibc/archsignal.h b/klibc/klibc/arch/s390x/include/klibc/archsignal.h
deleted file mode 100644
index 08c9a0073a..0000000000
--- a/klibc/klibc/arch/s390x/include/klibc/archsignal.h
+++ /dev/null
@@ -1,13 +0,0 @@
-/*
- * arch/s390x/include/klibc/archsignal.h
- *
- * Architecture-specific signal definitions
- *
- */
-
-#ifndef _KLIBC_ARCHSIGNAL_H
-#define _KLIBC_ARCHSIGNAL_H
-
-/* No special stuff for this architecture */
-
-#endif
diff --git a/klibc/klibc/arch/s390x/include/klibc/archsys.h b/klibc/klibc/arch/s390x/include/klibc/archsys.h
deleted file mode 100644
index 15f7113bb4..0000000000
--- a/klibc/klibc/arch/s390x/include/klibc/archsys.h
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * 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 */
diff --git a/klibc/klibc/arch/s390x/mmap.c b/klibc/klibc/arch/s390x/mmap.c
new file mode 100644
index 0000000000..158f0933a4
--- /dev/null
+++ b/klibc/klibc/arch/s390x/mmap.c
@@ -0,0 +1,41 @@
+#include <sys/types.h>
+#include <linux/unistd.h>
+
+struct mmap_arg_struct {
+ unsigned long addr;
+ unsigned long len;
+ unsigned long prot;
+ unsigned long flags;
+ unsigned long fd;
+ unsigned long offset;
+};
+
+void * mmap(void * addr, size_t len, int prot, int flags,
+ int fd, off_t offset)
+{
+ struct mmap_arg_struct args = {
+ (unsigned long) addr,
+ (unsigned long) len,
+ (unsigned long) prot,
+ (unsigned long) flags,
+ (unsigned long) fd,
+ (unsigned long) offset,
+ };
+
+ register struct mmap_arg_struct *__arg1 asm("2") = &args;
+ register long __svcres asm("2");
+ unsigned long __res;
+
+ __asm__ __volatile__ (
+ " svc %b1\n"
+ : "=d" (__svcres)
+ : "i" (__NR_mmap),
+ "0" (__arg1)
+ : "1", "cc", "memory");
+ __res = __svcres;
+ if (__res >= (unsigned long)-125) {
+ errno = -__res;
+ __res = -1;
+ }
+ return (void *)__res;
+}
diff --git a/klibc/klibc/arch/s390x/syscall.c b/klibc/klibc/arch/s390x/syscall.c
new file mode 100644
index 0000000000..c0f17c453c
--- /dev/null
+++ b/klibc/klibc/arch/s390x/syscall.c
@@ -0,0 +1,16 @@
+/*
+ * arch/s390/syscall.c
+ *
+ * Common error-handling path for system calls.
+ * The return value from __syscall_common becomes the
+ * return value from the system call.
+ */
+#include <errno.h>
+
+long int __syscall_common(long int err)
+{
+ if ((unsigned long)(err) < (unsigned long)(-125))
+ return err;
+ errno = err;
+ return -1;
+}
diff --git a/klibc/klibc/arch/s390x/sysstub.ph b/klibc/klibc/arch/s390x/sysstub.ph
new file mode 100644
index 0000000000..10a47f7b07
--- /dev/null
+++ b/klibc/klibc/arch/s390x/sysstub.ph
@@ -0,0 +1,28 @@
+# -*- perl -*-
+#
+# arch/s390x/sysstub.ph
+#
+# Script to generate system call stubs
+#
+
+sub make_sysstub($$$$@) {
+ my($fname, $type, $sname, $stype, @args) = @_;
+
+ open(OUT, '>', "syscalls/${fname}.S");
+ print OUT "#include <asm/unistd.h>\n";
+ print OUT "\n";
+ print OUT "\t.type ${fname},\@function\n";
+ print OUT "\t.globl ${fname}\n";
+ print OUT "${fname}:\n";
+ print OUT ".if __NR_${sname} < 256\n";
+ print OUT "\tsvc __NR_${sname}\n";
+ print OUT ".else\n";
+ print OUT "\tlghi %r1,__NR_${sname}\n";
+ print OUT "\tsvc 0\n";
+ print OUT ".endif\n";
+ print OUT "\tbrasl %r3,__syscall_common\n";
+ print OUT "\t.size ${fname},.-${fname}\n";
+ close(OUT);
+}
+
+1;
diff --git a/klibc/klibc/arch/sh/Makefile.inc b/klibc/klibc/arch/sh/Makefile.inc
index 16d7ea1e18..ccabfa496b 100644
--- a/klibc/klibc/arch/sh/Makefile.inc
+++ b/klibc/klibc/arch/sh/Makefile.inc
@@ -7,7 +7,8 @@
# accordingly.
#
-ARCHOBJS = arch/sh/setjmp.o
+ARCHOBJS = arch/sh/setjmp.o \
+ arch/sh/syscall.o
ARCHSOOBJS = $(patsubst %.o,%.lo,$(ARCHOBJS))
diff --git a/klibc/klibc/arch/sh/crt0.S b/klibc/klibc/arch/sh/crt0.S
index c9938a5612..21a37655f2 100644
--- a/klibc/klibc/arch/sh/crt0.S
+++ b/klibc/klibc/arch/sh/crt0.S
@@ -1,12 +1,11 @@
#
# arch/sh/crt0.S
#
-# void _start(void)
-# {
-# /* Divine up argc, argv, and envp */
-# environ = envp;
-# exit(main(argc, argv, envp));
-# }
+# 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
diff --git a/klibc/klibc/arch/sh/include/klibc/archsetjmp.h b/klibc/klibc/arch/sh/include/klibc/archsetjmp.h
deleted file mode 100644
index 28dd932fbc..0000000000
--- a/klibc/klibc/arch/sh/include/klibc/archsetjmp.h
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * 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 */
diff --git a/klibc/klibc/arch/sh/include/klibc/archsignal.h b/klibc/klibc/arch/sh/include/klibc/archsignal.h
deleted file mode 100644
index 6c4e5976ad..0000000000
--- a/klibc/klibc/arch/sh/include/klibc/archsignal.h
+++ /dev/null
@@ -1,13 +0,0 @@
-/*
- * arch/sh/include/klibc/archsignal.h
- *
- * Architecture-specific signal definitions
- *
- */
-
-#ifndef _KLIBC_ARCHSIGNAL_H
-#define _KLIBC_ARCHSIGNAL_H
-
-/* No special stuff for this architecture */
-
-#endif
diff --git a/klibc/klibc/arch/sh/include/klibc/archsys.h b/klibc/klibc/arch/sh/include/klibc/archsys.h
deleted file mode 100644
index 5f8050a536..0000000000
--- a/klibc/klibc/arch/sh/include/klibc/archsys.h
+++ /dev/null
@@ -1,12 +0,0 @@
-/*
- * 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 */
diff --git a/klibc/klibc/arch/sh/syscall.S b/klibc/klibc/arch/sh/syscall.S
new file mode 100644
index 0000000000..41a0486679
--- /dev/null
+++ b/klibc/klibc/arch/sh/syscall.S
@@ -0,0 +1,35 @@
+/*
+ * arch/sh/syscall.S
+ *
+ * On sh, r3 contains the syscall number (set by generated stub);
+ * r4..r7 contain arguments 0-3 per the standard calling convention,
+ * and arguments 4-5 are passed in r0 and r1.
+ *
+ * The return value is in r3 rather than standard r0.
+ */
+
+ .section ".text.syscall","ax"
+ .align 2
+ .globl ___syscall_common
+ .type ___syscall_common,@function
+___syscall_common:
+ mov.l @(sp),r0
+ mov.l @(4,sp),r1
+ trapa #0x15
+ mov.l 1f,r0
+ cmp/hs r0,r3
+ bt/s 3f
+ neg r3,r4
+ mov.l 2f,r5
+ mov.l r4,@r5
+ rts
+ mov #-1,r0
+3:
+ rts
+ mov r3,r0
+
+ .align 2
+1: .long -4096 /* Errno limit */
+2: .long errno
+
+ .size ___syscall_common,.-___syscall_common
diff --git a/klibc/klibc/arch/sh/sysstub.ph b/klibc/klibc/arch/sh/sysstub.ph
new file mode 100644
index 0000000000..add5d35892
--- /dev/null
+++ b/klibc/klibc/arch/sh/sysstub.ph
@@ -0,0 +1,34 @@
+# -*- perl -*-
+#
+# arch/sh/sysstub.ph
+#
+# Script to generate system call stubs
+#
+
+sub make_sysstub($$$$@) {
+ my($fname, $type, $sname, $stype, @args) = @_;
+
+ open(OUT, '>', "syscalls/${fname}.S");
+ print OUT "#include <asm/unistd.h>\n";
+ print OUT "\n";
+ print OUT "\t.section\t\".text.syscall\",\"ax\"\n";
+ print OUT "\t.type\t${fname},\#function\n";
+ print OUT "\t.globl\t${fname}\n";
+ print OUT "\t.align\t2\n";
+ print OUT "${fname}:\n";
+ print OUT "\tbra\t__syscall_common\n";
+ print OUT "#if __NR_${sname} >= 128\n";
+ print OUT "\t mov.l\t1f, r3\n";
+ print OUT "#else\n";
+ print OUT "\t mov\t# __NR_${sname}, r3\n";
+ print OUT "#endif\n";
+ print OUT "\t.size ${fname},.-${fname}\n";
+ print OUT "\n";
+ print OUT "#if __NR_${sname} >= 128\n";
+ print OUT "\t.align\t2\n";
+ print OUT "1:\t.long\t__NR_${sname}\n";
+ print OUT "#endif\n";
+ close(OUT);
+}
+
+1;
diff --git a/klibc/klibc/arch/sparc/Makefile.inc b/klibc/klibc/arch/sparc/Makefile.inc
index 0186810aca..6ea66114fa 100644
--- a/klibc/klibc/arch/sparc/Makefile.inc
+++ b/klibc/klibc/arch/sparc/Makefile.inc
@@ -14,7 +14,9 @@ ARCHOBJS = \
arch/$(ARCH)/urem.o \
arch/$(ARCH)/smul.o \
arch/$(ARCH)/umul.o \
- arch/$(ARCH)/setjmp.o
+ arch/$(ARCH)/setjmp.o \
+ arch/$(ARCH)/syscall.o \
+ arch/$(ARCH)/sysfork.o
arch/$(ARCH)/sdiv.S: arch/$(ARCH)/divrem.m4
@echo 'building $@ from $^'
diff --git a/klibc/klibc/arch/sparc/include/klibc/archsetjmp.h b/klibc/klibc/arch/sparc/include/klibc/archsetjmp.h
deleted file mode 100644
index 92c1c74c9d..0000000000
--- a/klibc/klibc/arch/sparc/include/klibc/archsetjmp.h
+++ /dev/null
@@ -1,16 +0,0 @@
-/*
- * arch/sparc/include/klibc/archsetjmp.h
- */
-
-#ifndef _KLIBC_ARCHSETJMP_H
-#define _KLIBC_ARCHSETJMP_H
-
-struct __jmp_buf {
- unsigned long __sp;
- unsigned long __fp;
- unsigned long __pc;
-};
-
-typedef struct __jmp_buf jmp_buf[1];
-
-#endif /* _SETJMP_H */
diff --git a/klibc/klibc/arch/sparc/include/klibc/archsignal.h b/klibc/klibc/arch/sparc/include/klibc/archsignal.h
deleted file mode 100644
index 6af3709033..0000000000
--- a/klibc/klibc/arch/sparc/include/klibc/archsignal.h
+++ /dev/null
@@ -1,13 +0,0 @@
-/*
- * arch/sparc/include/klibc/archsignal.h
- *
- * Architecture-specific signal definitions
- *
- */
-
-#ifndef _KLIBC_ARCHSIGNAL_H
-#define _KLIBC_ARCHSIGNAL_H
-
-/* No special stuff for this architecture */
-
-#endif
diff --git a/klibc/klibc/arch/sparc/include/klibc/archsys.h b/klibc/klibc/arch/sparc/include/klibc/archsys.h
deleted file mode 100644
index fe6e68df8a..0000000000
--- a/klibc/klibc/arch/sparc/include/klibc/archsys.h
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * arch/sparc/include/klibc/archsys.h
- *
- * Architecture-specific syscall definitions
- */
-
-#ifndef _KLIBC_ARCHSYS_H
-#define _KLIBC_ARCHSYS_H
-
-/* fork and vfork return the "other process" pid in %o0 and an
- "is child" flag in %o1... */
-
-#define _syscall0_forkish(type,name) \
-type name(void) \
-{ \
-register long __g1 __asm__ ("g1") = __NR_##name; \
-register unsigned long __o0 __asm__ ("o0"); \
-register unsigned long __o1 __asm__ ("o1"); \
-__asm__ __volatile__ ("t 0x10\n\t" \
- "bcc 1f\n\t" \
- "mov %%o0, %0\n\t" \
- "sub %%g0, %%o0, %0\n\t" \
- "1:\n\t" \
- : "=r" (__o0), "=r" (__o1)\
- : "r" (__g1) \
- : "cc"); \
-if ((unsigned long)__o0 < (unsigned long)-255) \
- return (type)(__o0 & (__o1-1)); \
-errno = (int)-__o0; \
-return -1; \
-}
-
-/* SPARC seems to lack _syscall6() in its headers */
-
-#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) \
-{ \
-long __res; \
-register long __g1 __asm__ ("g1") = __NR_##name; \
-register long __o0 __asm__ ("o0") = (long)(arg1); \
-register long __o1 __asm__ ("o1") = (long)(arg2); \
-register long __o2 __asm__ ("o2") = (long)(arg3); \
-register long __o3 __asm__ ("o3") = (long)(arg4); \
-register long __o4 __asm__ ("o4") = (long)(arg5); \
-register long __o5 __asm__ ("o5") = (long)(arg6); \
-__asm__ __volatile__ ("t 0x10\n\t" \
- "bcc 1f\n\t" \
- "mov %%o0, %0\n\t" \
- "sub %%g0, %%o0, %0\n\t" \
- "1:\n\t" \
- : "=r" (__res), "=&r" (__o0) \
- : "1" (__o0), "r" (__o1), "r" (__o2), "r" (__o3), "r" (__o4), "r" (__o5), "r" (__g1) \
- : "cc"); \
-if (__res < -255 || __res>=0) \
-return (type) __res; \
-errno = -__res; \
-return (type)-1; \
-}
-
-#endif /* _syscall6 missing */
-
-#endif /* _KLIBC_ARCHSYS_H */
diff --git a/klibc/klibc/arch/sparc/include/machine/asm.h b/klibc/klibc/arch/sparc/include/machine/asm.h
deleted file mode 100644
index b622bd8cf1..0000000000
--- a/klibc/klibc/arch/sparc/include/machine/asm.h
+++ /dev/null
@@ -1,192 +0,0 @@
-/* $NetBSD: asm.h,v 1.14 2002/07/20 08:37:30 mrg Exp $ */
-
-/*
- * Copyright (c) 1994 Allen Briggs
- * All rights reserved.
- *
- * Gleaned from locore.s and sun3 asm.h which had the following copyrights:
- * locore.s:
- * Copyright (c) 1988 University of Utah.
- * Copyright (c) 1982, 1990 The Regents of the University of California.
- * sun3/include/asm.h:
- * Copyright (c) 1993 Adam Glass
- * Copyright (c) 1990 The Regents of the University of California.
- *
- * 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.
- */
-
-#ifndef _ASM_H_
-#define _ASM_H_
-
-/* Pull in CCFSZ, CC64FSZ, and BIAS from frame.h */
-#ifndef _LOCORE
-#define _LOCORE
-#endif
-#include <machine/frame.h>
-
-#ifdef __ELF__
-#define _C_LABEL(name) name
-#else
-#ifdef __STDC__
-#define _C_LABEL(name) _ ## name
-#else
-#define _C_LABEL(name) _/**/name
-#endif
-#endif
-#define _ASM_LABEL(name) name
-
-#ifdef PIC
-/*
- * PIC_PROLOGUE() is akin to the compiler generated function prologue for
- * PIC code. It leaves the address of the Global Offset Table in DEST,
- * clobbering register TMP in the process.
- *
- * We can use two code sequences. We can read the %pc or use the call
- * instruction that saves the pc in %o7. Call requires the branch unit and
- * IEU1, and clobbers %o7 which needs to be restored. This instruction
- * sequence takes about 4 cycles due to instruction interdependence. Reading
- * the pc takes 4 cycles to dispatch and is always dispatched alone. That
- * sequence takes 7 cycles.
- */
-#ifdef __arch64__
-#define PIC_PROLOGUE(dest,tmp) \
- mov %o7, tmp; \
- sethi %hi(_GLOBAL_OFFSET_TABLE_-4),dest; \
- call 0f; \
- or dest,%lo(_GLOBAL_OFFSET_TABLE_+4),dest; \
-0: \
- add dest,%o7,dest; \
- mov tmp, %o7
-#else
-#define PIC_PROLOGUE(dest,tmp) \
- mov %o7,tmp; 3: call 4f; nop; 4: \
- sethi %hi(_C_LABEL(_GLOBAL_OFFSET_TABLE_)-(3b-.)),dest; \
- or dest,%lo(_C_LABEL(_GLOBAL_OFFSET_TABLE_)-(3b-.)),dest; \
- add dest,%o7,dest; mov tmp,%o7
-#endif
-
-/*
- * PICCY_SET() does the equivalent of a `set var, %dest' instruction in
- * a PIC-like way, but without involving the Global Offset Table. This
- * only works for VARs defined in the same file *and* in the text segment.
- */
-#ifdef __arch64__
-#define PICCY_SET(var,dest,tmp) \
- 3: rd %pc, tmp; add tmp,(var-3b),dest
-#else
-#define PICCY_SET(var,dest,tmp) \
- mov %o7,tmp; 3: call 4f; nop; 4: \
- add %o7,(var-3b),dest; mov tmp,%o7
-#endif
-#else
-#define PIC_PROLOGUE(dest,tmp)
-#define PICCY_OFFSET(var,dest,tmp)
-#endif
-
-#define FTYPE(x) .type x,@function
-#define OTYPE(x) .type x,@object
-
-#define _ENTRY(name) \
- .align 4; .globl name; .proc 1; FTYPE(name); name:
-
-#ifdef GPROF
-/* see _MCOUNT_ENTRY in profile.h */
-#ifdef __ELF__
-#ifdef __arch64__
-#define _PROF_PROLOGUE \
- .data; .align 8; 1: .uaword 0; .uaword 0; \
- .text; save %sp,-CC64FSZ,%sp; sethi %hi(1b),%o0; call _mcount; \
- or %o0,%lo(1b),%o0; restore
-#else
-#define _PROF_PROLOGUE \
- .data; .align 4; 1: .long 0; \
- .text; save %sp,-96,%sp; sethi %hi(1b),%o0; call _mcount; \
- or %o0,%lo(1b),%o0; restore
-#endif
-#else
-#ifdef __arch64__
-#define _PROF_PROLOGUE \
- .data; .align 8; 1: .uaword 0; .uaword 0; \
- .text; save %sp,-CC64FSZ,%sp; sethi %hi(1b),%o0; call mcount; \
- or %o0,%lo(1b),%o0; restore
-#else
-#define _PROF_PROLOGUE \
- .data; .align 4; 1: .long 0; \
- .text; save %sp,-96,%sp; sethi %hi(1b),%o0; call mcount; \
- or %o0,%lo(1b),%o0; restore
-#endif
-#endif
-#else
-#define _PROF_PROLOGUE
-#endif
-
-#define ENTRY(name) _ENTRY(_C_LABEL(name)); _PROF_PROLOGUE
-#define ENTRY_NOPROFILE(name) _ENTRY(_C_LABEL(name))
-#define ASENTRY(name) _ENTRY(_ASM_LABEL(name)); _PROF_PROLOGUE
-#define FUNC(name) ASENTRY(name)
-#define RODATA(name) .align 4; .text; .globl _C_LABEL(name); \
- OTYPE(_C_LABEL(name)); _C_LABEL(name):
-
-
-#define ASMSTR .asciz
-
-#define RCSID(name) .asciz name
-
-#ifdef __ELF__
-#define WEAK_ALIAS(alias,sym) \
- .weak alias; \
- alias = sym
-#endif
-
-/*
- * WARN_REFERENCES: create a warning if the specified symbol is referenced.
- */
-#ifdef __ELF__
-#ifdef __STDC__
-#define WARN_REFERENCES(_sym,_msg) \
- .section .gnu.warning. ## _sym ; .ascii _msg ; .text
-#else
-#define WARN_REFERENCES(_sym,_msg) \
- .section .gnu.warning./**/_sym ; .ascii _msg ; .text
-#endif /* __STDC__ */
-#else
-#ifdef __STDC__
-#define __STRING(x) #x
-#define WARN_REFERENCES(sym,msg) \
- .stabs msg ## ,30,0,0,0 ; \
- .stabs __STRING(_ ## sym) ## ,1,0,0,0
-#else
-#define __STRING(x) "x"
-#define WARN_REFERENCES(sym,msg) \
- .stabs msg,30,0,0,0 ; \
- .stabs __STRING(_/**/sym),1,0,0,0
-#endif /* __STDC__ */
-#endif /* __ELF__ */
-
-#endif /* _ASM_H_ */
diff --git a/klibc/klibc/arch/sparc/include/machine/frame.h b/klibc/klibc/arch/sparc/include/machine/frame.h
deleted file mode 100644
index b09175c7f4..0000000000
--- a/klibc/klibc/arch/sparc/include/machine/frame.h
+++ /dev/null
@@ -1,138 +0,0 @@
-/* $NetBSD: frame.h,v 1.4 2001/12/04 00:05:05 darrenr Exp $ */
-
-/*
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This software was developed by the Computer Systems Engineering group
- * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
- * contributed to Berkeley.
- *
- * 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, Lawrence Berkeley Laboratory.
- *
- * 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.
- *
- * @(#)frame.h 8.1 (Berkeley) 6/11/93
- */
-
-#if defined(_KERNEL_OPT)
-#include "opt_sparc_arch.h"
-#endif
-
-/*
- * Sparc stack frame format.
- *
- * Note that the contents of each stack frame may be held only in
- * machine register windows. In order to get an accurate picture
- * of the frame, you must first force the kernel to write any such
- * windows to the stack.
- */
-#ifndef _LOCORE
-#ifndef SUN4U
-struct frame {
- int32_t fr_local[8]; /* space to save locals (%l0..%l7) */
- int32_t fr_arg[6]; /* space to save arguments (%i0..%i5) */
- struct frame *fr_fp; /* space to save frame pointer (%i6) */
- int32_t fr_pc; /* space to save return pc (%i7) */
- /*
- * SunOS reserves another 8 words here; this is pointless
- * but we do it for compatibility.
- */
- int32_t fr_xxx; /* `structure return pointer' (unused) */
- int32_t fr_argd[6]; /* `arg dump area' (lunacy) */
- int32_t fr_argx[1]; /* arg extension (args 7..n; variable size) */
-};
-#else
-struct frame32 {
- int32_t fr_local[8]; /* space to save locals (%l0..%l7) */
- int32_t fr_arg[6]; /* space to save arguments (%i0..%i5) */
- u_int32_t fr_fp; /* space to save frame pointer (%i6) */
- u_int32_t fr_pc; /* space to save return pc (%i7) */
- /*
- * SunOS reserves another 8 words here; this is pointless
- * but we do it for compatibility.
- */
- int32_t fr_xxx; /* `structure return pointer' (unused) */
- int32_t fr_argd[6]; /* `arg dump area' (lunacy) */
- int32_t fr_argx[1]; /* arg extension (args 7..n; variable size) */
-};
-#endif
-#endif
-
-/*
- * CCFSZ (C Compiler Frame SiZe) is the size of a stack frame required if
- * a function is to call C code. It should be just 64, but Sun defined
- * their frame with space to hold arguments 0 through 5 (plus some junk),
- * and varargs routines (such as kprintf) demand this, and gcc uses this
- * area at times anyway.
- */
-#define CCFSZ 96
-
-/*
- * Sparc v9 stack frame format.
- *
- * Note that the contents of each stack frame may be held only in
- * machine register windows. In order to get an accurate picture
- * of the frame, you must first force the kernel to write any such
- * windows to the stack.
- *
- * V9 frames have an odd bias, so you can tall a v9 frame from
- * a v8 frame by testing the stack pointer's lsb.
- */
-#if !defined(_LOCORE) && !defined(_LIBC)
-struct frame64 {
- int64_t fr_local[8]; /* space to save locals (%l0..%l7) */
- int64_t fr_arg[6]; /* space to save arguments (%i0..%i5) */
- u_int64_t fr_fp; /* space to save frame pointer (%i6) */
- u_int64_t fr_pc; /* space to save return pc (%i7) */
- /*
- * SVR4 reserves a bunch of extra stuff.
- */
- int64_t fr_argd[6]; /* `register save area' (lunacy) */
- int64_t fr_argx[0]; /* arg extension (args 7..n; variable size) */
-};
-
-#define v9next_frame(f) ((struct frame64*)(f->fr_fp+BIAS))
-#endif
-
-/*
- * CC64FSZ (C Compiler 64-bit Frame SiZe) is the size of a stack frame used
- * by the compiler in 64-bit mode. It is (16)*8; space for 8 ins, 8 outs.
- */
-#define CC64FSZ 176
-
-/*
- * v9 stacks all have a bias of 2047 added to the %sp and %fp, so you can easily
- * detect it by testing the register for an odd value. Why 2K-1 I don't know.
- */
-#define BIAS (2048-1)
-
diff --git a/klibc/klibc/arch/sparc/include/machine/trap.h b/klibc/klibc/arch/sparc/include/machine/trap.h
deleted file mode 100644
index 42c3ef6ae2..0000000000
--- a/klibc/klibc/arch/sparc/include/machine/trap.h
+++ /dev/null
@@ -1,141 +0,0 @@
-/* $NetBSD: trap.h,v 1.11 1999/01/20 00:15:08 pk Exp $ */
-
-/*
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This software was developed by the Computer Systems Engineering group
- * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
- * contributed to Berkeley.
- *
- * 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, Lawrence Berkeley Laboratory.
- *
- * 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.
- *
- * @(#)trap.h 8.1 (Berkeley) 6/11/93
- */
-/*
- * Sun4m support by Aaron Brown, Harvard University.
- * Changes Copyright (c) 1995 The President and Fellows of Harvard College.
- * All rights reserved.
- */
-
-#ifndef _MACHINE_TRAP_H
-#define _MACHINE_TRAP_H
-
-/* trap vec (pri) description */
-#define T_RESET 0x00 /* (1) not actually vectored; jumps to 0 */
-#define T_TEXTFAULT 0x01 /* (2) address fault during instr fetch */
-#define T_ILLINST 0x02 /* (3) illegal instruction */
-#define T_PRIVINST 0x03 /* (4) privileged instruction */
-#define T_FPDISABLED 0x04 /* (5) fp instr while fp disabled */
-#define T_WINOF 0x05 /* (6) register window overflow */
-#define T_WINUF 0x06 /* (7) register window underflow */
-#define T_ALIGN 0x07 /* (8) address not properly aligned */
-#define T_FPE 0x08 /* (9) floating point exception */
-#define T_DATAFAULT 0x09 /* (10) address fault during data fetch */
-#define T_TAGOF 0x0a /* (11) tag overflow */
-/* 0x0b unused */
-/* 0x0c unused */
-/* 0x0d unused */
-/* 0x0e unused */
-/* 0x0f unused */
-/* 0x10 unused */
-#define T_L1INT 0x11 /* (27) level 1 interrupt */
-#define T_L2INT 0x12 /* (26) level 2 interrupt */
-#define T_L3INT 0x13 /* (25) level 3 interrupt */
-#define T_L4INT 0x14 /* (24) level 4 interrupt */
-#define T_L5INT 0x15 /* (23) level 5 interrupt */
-#define T_L6INT 0x16 /* (22) level 6 interrupt */
-#define T_L7INT 0x17 /* (21) level 7 interrupt */
-#define T_L8INT 0x18 /* (20) level 8 interrupt */
-#define T_L9INT 0x19 /* (19) level 9 interrupt */
-#define T_L10INT 0x1a /* (18) level 10 interrupt */
-#define T_L11INT 0x1b /* (17) level 11 interrupt */
-#define T_L12INT 0x1c /* (16) level 12 interrupt */
-#define T_L13INT 0x1d /* (15) level 13 interrupt */
-#define T_L14INT 0x1e /* (14) level 14 interrupt */
-#define T_L15INT 0x1f /* (13) level 15 interrupt */
-/* 0x20 unused */
-/* through 0x23 unused */
-#define T_CPDISABLED 0x24 /* (5) coprocessor instr while disabled */
-#define T_UNIMPLFLUSH 0x25 /* Unimplemented FLUSH */
-/* through 0x27 unused */
-#define T_CPEXCEPTION 0x28 /* (9) coprocessor exception */
-/* 0x29 unused */
-#define T_IDIV0 0x2a /* divide by zero (from hw [su]div instr) */
-#define T_STOREBUFFAULT 0x2b /* SuperSPARC: Store buffer copy-back fault */
-/* 0x2c unused */
-/* through 0x7f unused */
-
-/* beginning of `user' vectors (from trap instructions) - all priority 12 */
-#define T_SUN_SYSCALL 0x80 /* system call */
-#define T_BREAKPOINT 0x81 /* breakpoint `instruction' */
-#define T_DIV0 0x82 /* division routine was handed 0 */
-#define T_FLUSHWIN 0x83 /* flush windows */
-#define T_CLEANWIN 0x84 /* provide clean windows */
-#define T_RANGECHECK 0x85 /* ? */
-#define T_FIXALIGN 0x86 /* fix up unaligned accesses */
-#define T_INTOF 0x87 /* integer overflow ? */
-#define T_SVR4_SYSCALL 0x88 /* SVR4 system call */
-#define T_BSD_SYSCALL 0x89 /* BSD system call */
-#define T_KGDB_EXEC 0x8a /* for kernel gdb */
-
-/* 0x8b..0xff are currently unallocated, except the following */
-#define T_SVR4_GETCC 0xa0
-#define T_SVR4_SETCC 0xa1
-#define T_SVR4_GETPSR 0xa2
-#define T_SVR4_SETPSR 0xa3
-#define T_SVR4_GETHRTIME 0xa4
-#define T_SVR4_GETHRVTIME 0xa5
-#define T_SVR4_GETHRESTIME 0xa7
-
-
-#ifdef _KERNEL /* pseudo traps for locore.s */
-#define T_RWRET -1 /* need first user window for trap return */
-#define T_AST -2 /* no-op, just needed reschedule or profile */
-#endif
-
-/* flags to system call (flags in %g1 along with syscall number) */
-#define SYSCALL_G2RFLAG 0x400 /* on success, return to %g2 rather than npc */
-#define SYSCALL_G7RFLAG 0x800 /* use %g7 as above (deprecated) */
-
-/*
- * `software trap' macros to keep people happy (sparc v8 manual says not
- * to set the upper bits).
- */
-#define ST_BREAKPOINT (T_BREAKPOINT & 0x7f)
-#define ST_DIV0 (T_DIV0 & 0x7f)
-#define ST_FLUSHWIN (T_FLUSHWIN & 0x7f)
-#define ST_SYSCALL (T_SUN_SYSCALL & 0x7f)
-
-#endif /* _MACHINE_TRAP_H_ */
diff --git a/klibc/klibc/arch/sparc/syscall.S b/klibc/klibc/arch/sparc/syscall.S
new file mode 100644
index 0000000000..c0273f77ca
--- /dev/null
+++ b/klibc/klibc/arch/sparc/syscall.S
@@ -0,0 +1,19 @@
+/*
+ * arch/sparc/syscall.S
+ *
+ * Common system-call stub; %g1 already set to syscall number
+ */
+
+ .globl __syscall_common
+ .type __syscall_common,#function
+ .align 4
+__syscall_common:
+ t 0x10
+ bcc 1f
+ sethi %hi(errno), %g4
+ or %g4, %lo(errno), %g4
+ st %o0,[%g4]
+ mov -1, %o0
+1:
+ retl
+ nop
diff --git a/klibc/klibc/arch/sparc/sysfork.S b/klibc/klibc/arch/sparc/sysfork.S
new file mode 100644
index 0000000000..a66c76e9db
--- /dev/null
+++ b/klibc/klibc/arch/sparc/sysfork.S
@@ -0,0 +1,25 @@
+/*
+ * arch/sparc/sysfork.S
+ *
+ * The fork and vfork system calls are special on sparc[64]:
+ * they return the "other process" pid in %o0 and the
+ * "is child" flag in %o1
+ *
+ * Common system-call stub; %g1 already set to syscall number
+ */
+
+ .globl __syscall_forkish
+ .type __syscall_forkish,#function
+ .align 4
+__syscall_forkish:
+ t 0x10
+ sub %o1, 1, %o1
+ bcc,a 1f
+ and %o0, %o1, %o0
+ sethi %hi(errno), %g4
+ or %g4, %lo(errno), %g4
+ st %o0,[%g4]
+ mov -1, %o0
+1:
+ retl
+ nop
diff --git a/klibc/klibc/arch/sparc/sysstub.ph b/klibc/klibc/arch/sparc/sysstub.ph
new file mode 100644
index 0000000000..baad9e3d82
--- /dev/null
+++ b/klibc/klibc/arch/sparc/sysstub.ph
@@ -0,0 +1,25 @@
+# -*- perl -*-
+#
+# arch/sparc32/sysstub.ph
+#
+# Script to generate system call stubs
+#
+
+sub make_sysstub($$$$@) {
+ my($fname, $type, $sname, $stype, @args) = @_;
+
+ $stype = $stype || 'common';
+
+ open(OUT, '>', "syscalls/${fname}.S");
+ print OUT "#include <asm/unistd.h>\n";
+ print OUT "\n";
+ print OUT "\t.type ${fname},\@function\n";
+ print OUT "\t.globl ${fname}\n";
+ print OUT "${fname}:\n";
+ print OUT "\tb __syscall_${stype}\n";
+ print OUT "\t mov\t__NR_${sname}, %g1\n";
+ print OUT "\t.size ${fname},.-${fname}\n";
+ close(OUT);
+}
+
+1;
diff --git a/klibc/klibc/arch/sparc64/Makefile.inc b/klibc/klibc/arch/sparc64/Makefile.inc
index d59f9878e9..06b79537a3 100644
--- a/klibc/klibc/arch/sparc64/Makefile.inc
+++ b/klibc/klibc/arch/sparc64/Makefile.inc
@@ -8,6 +8,8 @@
#
ARCHOBJS = \
- arch/$(ARCH)/setjmp.o
+ arch/$(ARCH)/setjmp.o \
+ arch/$(ARCH)/syscall.o \
+ arch/$(ARCH)/sysfork.o
archclean:
diff --git a/klibc/klibc/arch/sparc64/include/klibc/archsetjmp.h b/klibc/klibc/arch/sparc64/include/klibc/archsetjmp.h
deleted file mode 100644
index 022a31e542..0000000000
--- a/klibc/klibc/arch/sparc64/include/klibc/archsetjmp.h
+++ /dev/null
@@ -1,16 +0,0 @@
-/*
- * arch/sparc64/include/klibc/archsetjmp.h
- */
-
-#ifndef _KLIBC_ARCHSETJMP_H
-#define _KLIBC_ARCHSETJMP_H
-
-struct __jmp_buf {
- unsigned long __sp;
- unsigned long __fp;
- unsigned long __pc;
-};
-
-typedef struct __jmp_buf jmp_buf[1];
-
-#endif /* _SETJMP_H */
diff --git a/klibc/klibc/arch/sparc64/include/klibc/archsignal.h b/klibc/klibc/arch/sparc64/include/klibc/archsignal.h
deleted file mode 100644
index f81bd668bb..0000000000
--- a/klibc/klibc/arch/sparc64/include/klibc/archsignal.h
+++ /dev/null
@@ -1,13 +0,0 @@
-/*
- * arch/sparc64/include/klibc/archsignal.h
- *
- * Architecture-specific signal definitions
- *
- */
-
-#ifndef _KLIBC_ARCHSIGNAL_H
-#define _KLIBC_ARCHSIGNAL_H
-
-/* No special stuff for this architecture */
-
-#endif
diff --git a/klibc/klibc/arch/sparc64/include/klibc/archsys.h b/klibc/klibc/arch/sparc64/include/klibc/archsys.h
deleted file mode 100644
index 651e4f7f09..0000000000
--- a/klibc/klibc/arch/sparc64/include/klibc/archsys.h
+++ /dev/null
@@ -1,157 +0,0 @@
-/*
- * arch/sparc64/include/klibc/archsys.h
- *
- * Architecture-specific syscall definitions
- */
-
-#ifndef _KLIBC_ARCHSYS_H
-#define _KLIBC_ARCHSYS_H
-
-/* The Linux 2.5.31 SPARC64 syscall macros are just plain broken */
-
-#undef _syscall0
-#undef _syscall1
-#undef _syscall2
-#undef _syscall3
-#undef _syscall4
-#undef _syscall5
-#undef _syscall6
-
-#define _syscall0(type,name) \
-type name (void) \
-{ \
- register unsigned long __g1 __asm__ ("g1") = __NR_##name; \
- register unsigned long __ret __asm__("o0"); \
- __asm__ __volatile__ ("t 0x6d\n\t" \
- "bcs,a %%xcc, 1f\n\t" \
- " st %0,%1\n\t" \
- "1:" \
- "movcs %%xcc,-1,%0\n" \
- : "=&r" (__ret), "+m" (errno) \
- : "r" (__g1) \
- : "cc"); \
- return (type) __ret; \
-}
-
-#define _syscall1(type,name,type1,arg1) \
-type name (type1 arg1) \
-{ \
- register unsigned long __g1 __asm__ ("g1") = __NR_##name; \
- register unsigned long __ret __asm__("o0"); \
- type1 __o0 = (arg1); \
- __asm__ __volatile__ ("t 0x6d\n\t" \
- "bcs,a %%xcc, 1f\n\t" \
- " st %0,%1\n\t" \
- "1:" \
- "movcs %%xcc,-1,%0\n" \
- : "=&r" (__ret), "+m" (errno) \
- : "0" (__o0), "r" (__g1) \
- : "cc"); \
- return (type) __ret; \
-}
-
-#define _syscall2(type,name,type1,arg1,type2,arg2) \
-type name (type1 arg1,type2 arg2) \
-{ \
- register unsigned long __g1 __asm__ ("g1") = __NR_##name; \
- register unsigned long __ret __asm__("o0"); \
- type1 __o0 = (arg1); \
- register type2 __o1 __asm__ ("o1") = (arg2); \
- __asm__ __volatile__ ("t 0x6d\n\t" \
- "bcs,a %%xcc, 1f\n\t" \
- " st %0,%1\n\t" \
- "1:" \
- "movcs %%xcc,-1,%0\n" \
- : "=&r" (__ret), "+m" (errno) \
- : "0" (__o0), "r" (__o1), "r" (__g1) \
- : "cc"); \
- return (type) __ret; \
-}
-
-#define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \
-type name (type1 arg1,type2 arg2,type3 arg3) \
-{ \
- register unsigned long __g1 __asm__ ("g1") = __NR_##name; \
- register unsigned long __ret __asm__("o0"); \
- type1 __o0 = (arg1); \
- register type2 __o1 __asm__ ("o1") = (arg2); \
- register type3 __o2 __asm__ ("o2") = (arg3); \
- __asm__ __volatile__ ("t 0x6d\n\t" \
- "bcs,a %%xcc, 1f\n\t" \
- " st %0,%1\n\t" \
- "1:" \
- "movcs %%xcc,-1,%0\n" \
- : "=&r" (__ret), "+m" (errno) \
- : "0" (__o0), "r" (__o1), "r" (__o2), "r" (__g1) \
- : "cc"); \
- return (type) __ret; \
-}
-
-#define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \
-type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4) \
-{ \
- register unsigned long __g1 __asm__ ("g1") = __NR_##name; \
- register unsigned long __ret __asm__("o0"); \
- type1 __o0 = (arg1); \
- register type2 __o1 __asm__ ("o1") = (arg2); \
- register type3 __o2 __asm__ ("o2") = (arg3); \
- register type4 __o3 __asm__ ("o3") = (arg4); \
- __asm__ __volatile__ ("t 0x6d\n\t" \
- "bcs,a %%xcc, 1f\n\t" \
- " st %0,%1\n\t" \
- "1:" \
- "movcs %%xcc,-1,%0\n" \
- : "=&r" (__ret), "+m" (errno) \
- : "0" (__o0), "r" (__o1), "r" (__o2), "r" (__o3), "r" (__g1) \
- : "cc"); \
- return (type) __ret; \
-}
-
-#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) \
-{ \
- register unsigned long __g1 __asm__ ("g1") = __NR_##name; \
- register unsigned long __ret __asm__("o0"); \
- type1 __o0 = (arg1); \
- register type2 __o1 __asm__ ("o1") = (arg2); \
- register type3 __o2 __asm__ ("o2") = (arg3); \
- register type4 __o3 __asm__ ("o3") = (arg4); \
- register type5 __o4 __asm__ ("o4") = (arg5); \
- __asm__ __volatile__ ("t 0x6d\n\t" \
- "bcs,a %%xcc, 1f\n\t" \
- " st %0,%1\n\t" \
- "1:" \
- "movcs %%xcc,-1,%0\n" \
- : "=&r" (__ret), "+m" (errno) \
- : "0" (__o0), "r" (__o1), "r" (__o2), "r" (__o3), "r" (__o4), \
- "r" (__g1) \
- : "cc"); \
- return (type) __ret; \
-}
-
-#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) \
-{ \
- register unsigned long __g1 __asm__ ("g1") = __NR_##name; \
- register unsigned long __ret __asm__("o0"); \
- type1 __o0 = (arg1); \
- register type2 __o1 __asm__ ("o1") = (arg2); \
- register type3 __o2 __asm__ ("o2") = (arg3); \
- register type4 __o3 __asm__ ("o3") = (arg4); \
- register type5 __o4 __asm__ ("o4") = (arg5); \
- register type6 __o5 __asm__ ("o5") = (arg6); \
- __asm__ __volatile__ ("t 0x6d\n\t" \
- "bcs,a %%xcc, 1f\n\t" \
- " st %0,%1\n\t" \
- "1:" \
- "movcs %%xcc,-1,%0\n" \
- : "=&r" (__ret), "+m" (errno) \
- : "0" (__o0), "r" (__o1), "r" (__o2), "r" (__o3), "r" (__o4), \
- "r" (__o5), "r" (__g1) \
- : "cc"); \
- return (type) __ret; \
-}
-
-#endif /* _KLIBC_ARCHSYS_H */
diff --git a/klibc/klibc/arch/sparc64/syscall.S b/klibc/klibc/arch/sparc64/syscall.S
new file mode 100644
index 0000000000..7ab9d95f11
--- /dev/null
+++ b/klibc/klibc/arch/sparc64/syscall.S
@@ -0,0 +1,18 @@
+/*
+ * arch/sparc64/syscall.S
+ *
+ * Common system-call stub; %g1 already set to syscall number
+ */
+
+ .globl __syscall_common
+ .type __syscall_common,#function
+ .align 4
+__syscall_common:
+ t 0x6d
+ bcc %xcc, 1f
+ sethi %hi(errno), %g4
+ or %g4, %lo(errno), %g4
+ st %o0,[%g4]
+1:
+ retl
+ movcs %xcc, -1, %o0
diff --git a/klibc/klibc/arch/sparc64/sysfork.S b/klibc/klibc/arch/sparc64/sysfork.S
new file mode 100644
index 0000000000..739c35ede3
--- /dev/null
+++ b/klibc/klibc/arch/sparc64/sysfork.S
@@ -0,0 +1,26 @@
+/*
+ * arch/sparc64/sysfork.S
+ *
+ * The fork and vfork system calls are special on sparc[64]:
+ * they return the "other process" pid in %o0 and the
+ * "is child" flag in %o1
+ *
+ * Common system-call stub; %g1 already set to syscall number
+ *
+ * IS THIS CORRECT FOR SPARC64?
+ */
+
+ .globl __syscall_forkish
+ .type __syscall_forkish,#function
+ .align 4
+__syscall_forkish:
+ t 0x6d
+ sub %o1, 1, %o1
+ bcc,a %xcc, 1f
+ and %o0, %o1, %o0
+ sethi %hi(errno), %g4
+ or %g4, %lo(errno), %g4
+ st %o0,[%g4]
+1:
+ retl
+ movcs %xcc, -1, %o0
diff --git a/klibc/klibc/arch/sparc64/sysstub.ph b/klibc/klibc/arch/sparc64/sysstub.ph
new file mode 100644
index 0000000000..2ef2c6b66e
--- /dev/null
+++ b/klibc/klibc/arch/sparc64/sysstub.ph
@@ -0,0 +1,25 @@
+# -*- perl -*-
+#
+# arch/sparc64/sysstub.ph
+#
+# Script to generate system call stubs
+#
+
+sub make_sysstub($$$$@) {
+ my($fname, $type, $sname, $stype, @args) = @_;
+
+ $stype = $stype || 'common';
+
+ open(OUT, '>', "syscalls/${fname}.S");
+ print OUT "#include <asm/unistd.h>\n";
+ print OUT "\n";
+ print OUT "\t.type ${fname},\@function\n";
+ print OUT "\t.globl ${fname}\n";
+ print OUT "${fname}:\n";
+ print OUT "\tb __syscall_${stype}\n";
+ print OUT "\t mov\t__NR_${sname}, %g1\n";
+ print OUT "\t.size ${fname},.-${fname}\n";
+ close(OUT);
+}
+
+1;
diff --git a/klibc/klibc/arch/x86_64/MCONFIG b/klibc/klibc/arch/x86_64/MCONFIG
index ecb14ccb70..f3c87410a6 100644
--- a/klibc/klibc/arch/x86_64/MCONFIG
+++ b/klibc/klibc/arch/x86_64/MCONFIG
@@ -9,8 +9,14 @@
# Blatantly copied and modified from i386 version by Mats Petersson, AMD.
#
+#
+# NOTE: -fno-asynchronous-unwind-tables produce significantly smaller
+# binaries (20% smaller), but makes the code completely useless for
+# debugging using gdb.
+#
ARCHREQFLAGS = -m64
-OPTFLAGS = -Os -fomit-frame-pointer -falign-functions=0 -falign-jumps=0 -falign-loops=0
+OPTFLAGS = -Os -fno-asynchronous-unwind-tables -fomit-frame-pointer \
+ -falign-functions=0 -falign-jumps=0 -falign-loops=0
BITSIZE = 64
LDFLAGS = -m elf_x86_64
diff --git a/klibc/klibc/arch/x86_64/Makefile.inc b/klibc/klibc/arch/x86_64/Makefile.inc
index c84443f4e1..d6cc1204e4 100644
--- a/klibc/klibc/arch/x86_64/Makefile.inc
+++ b/klibc/klibc/arch/x86_64/Makefile.inc
@@ -9,7 +9,8 @@
ARCHOBJS = \
arch/$(ARCH)/exits.o \
- arch/$(ARCH)/setjmp.o
+ arch/$(ARCH)/setjmp.o \
+ arch/$(ARCH)/syscall.o
ARCHSOOBJS = $(patsubst %.o,%.lo,$(ARCHOBJS))
diff --git a/klibc/klibc/arch/x86_64/include/klibc/archsetjmp.h b/klibc/klibc/arch/x86_64/include/klibc/archsetjmp.h
deleted file mode 100644
index 90d0a0d263..0000000000
--- a/klibc/klibc/arch/x86_64/include/klibc/archsetjmp.h
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * arch/x86_64/include/klibc/archsetjmp.h
- */
-
-#ifndef _KLIBC_ARCHSETJMP_H
-#define _KLIBC_ARCHSETJMP_H
-
-struct __jmp_buf {
- unsigned long __rbx;
- unsigned long __rsp;
- unsigned long __rbp;
- unsigned long __r12;
- unsigned long __r13;
- unsigned long __r14;
- unsigned long __r15;
- unsigned long __rip;
-};
-
-typedef struct __jmp_buf jmp_buf[1];
-
-#endif /* _SETJMP_H */
diff --git a/klibc/klibc/arch/x86_64/include/klibc/archsignal.h b/klibc/klibc/arch/x86_64/include/klibc/archsignal.h
deleted file mode 100644
index 74e82e1dd0..0000000000
--- a/klibc/klibc/arch/x86_64/include/klibc/archsignal.h
+++ /dev/null
@@ -1,13 +0,0 @@
-/*
- * arch/x86_64/include/klibc/archsignal.h
- *
- * Architecture-specific signal definitions
- *
- */
-
-#ifndef _KLIBC_ARCHSIGNAL_H
-#define _KLIBC_ARCHSIGNAL_H
-
-/* No special stuff for this architecture */
-
-#endif
diff --git a/klibc/klibc/arch/x86_64/include/klibc/archsys.h b/klibc/klibc/arch/x86_64/include/klibc/archsys.h
deleted file mode 100644
index 2ec72cd397..0000000000
--- a/klibc/klibc/arch/x86_64/include/klibc/archsys.h
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * arch/x86_64/include/klibc/archsys.h
- *
- * Architecture-specific syscall definitions
- */
-
-#ifndef _KLIBC_ARCHSYS_H
-#define _KLIBC_ARCHSYS_H
-
-/* The x86-64 syscall headers are needlessly inefficient */
-
-#undef _syscall0
-#undef _syscall1
-#undef _syscall2
-#undef _syscall3
-#undef _syscall4
-#undef _syscall5
-#undef _syscall6
-
-#define _syscall0(type,name) \
-type name (void) \
-{ \
-long __res; \
-__asm__ volatile (__syscall \
- : "=a" (__res) \
- : "0" (__NR_##name) \
- : __syscall_clobber); \
-__syscall_return(type,__res); \
-}
-
-#define _syscall1(type,name,type1,arg1) \
-type name (type1 arg1) \
-{ \
-long __res; \
-__asm__ volatile (__syscall \
- : "=a" (__res) \
- : "0" (__NR_##name),"D" (arg1) \
- : __syscall_clobber); \
-__syscall_return(type,__res); \
-}
-
-#define _syscall2(type,name,type1,arg1,type2,arg2) \
-type name (type1 arg1,type2 arg2) \
-{ \
-long __res; \
-__asm__ volatile (__syscall \
- : "=a" (__res) \
- : "0" (__NR_##name),"D" (arg1),"S" (arg2) \
- : __syscall_clobber); \
-__syscall_return(type,__res); \
-}
-
-#define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \
-type name (type1 arg1,type2 arg2,type3 arg3) \
-{ \
-long __res; \
-__asm__ volatile (__syscall \
- : "=a" (__res) \
- : "0" (__NR_##name),"D" (arg1),"S" (arg2), \
- "d" (arg3) \
- : __syscall_clobber); \
-__syscall_return(type,__res); \
-}
-
-#define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \
-type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4) \
-{ \
-long __res; \
-register type4 __r10 asm("%r10") = arg4; \
-__asm__ volatile (__syscall \
- : "=a" (__res) \
- : "0" (__NR_##name),"D" (arg1),"S" (arg2), \
- "d" (arg3),"r" (__r10) \
- : __syscall_clobber); \
-__syscall_return(type,__res); \
-}
-
-#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; \
-register type4 __r10 asm("%r10") = arg4; \
-register type5 __r8 asm("%r8") = arg5; \
-__asm__ volatile (__syscall \
- : "=a" (__res) \
- : "0" (__NR_##name),"D" (arg1),"S" (arg2), \
- "d" (arg3),"r" (__r10),"r" (__r8) \
- : __syscall_clobber); \
-__syscall_return(type,__res); \
-}
-
-#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; \
-register type4 __r10 asm("%r10") = arg4; \
-register type5 __r8 asm("%r8") = arg5; \
-register type6 __r9 asm("%r9") = arg6; \
-__asm__ volatile (__syscall \
- : "=a" (__res) \
- : "0" (__NR_##name),"D" (arg1),"S" (arg2), \
- "d" (arg3),"r" (__r10),"r" (__r8), "r" (__r9) \
- : __syscall_clobber); \
-__syscall_return(type,__res); \
-}
-
-#endif /* _KLIBC_ARCHSYS_H */
diff --git a/klibc/klibc/arch/x86_64/include/sys/io.h b/klibc/klibc/arch/x86_64/include/sys/io.h
deleted file mode 100644
index 4a0ae44985..0000000000
--- a/klibc/klibc/arch/x86_64/include/sys/io.h
+++ /dev/null
@@ -1,126 +0,0 @@
-#ident "$Id: io.h,v 1.1 2004/01/25 01:34:29 hpa Exp $"
-/* ----------------------------------------------------------------------- *
- *
- * Copyright 2004 H. Peter Anvin - All Rights Reserved
- *
- * 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:
- *
- * The above copyright notice 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.
- *
- * ----------------------------------------------------------------------- */
-
-/*
- * sys/io.h for the i386 architecture
- *
- * Basic I/O macros
- */
-
-#ifndef _SYS_IO_H
-#define _SYS_IO_H 1
-
-/* I/O-related system calls */
-
-int iopl(int);
-int ioperm(unsigned long, unsigned long, int);
-
-/* Basic I/O macros */
-
-static __inline__ void
-outb(unsigned char __v, unsigned short __p)
-{
- asm volatile("outb %0,%1" : : "a" (__v), "dN" (__p));
-}
-
-static __inline__ void
-outw(unsigned short __v, unsigned short __p)
-{
- asm volatile("outw %0,%1" : : "a" (__v), "dN" (__p));
-}
-
-static __inline__ void
-outl(unsigned int __v, unsigned short __p)
-{
- asm volatile("outl %0,%1" : : "a" (__v), "dN" (__p));
-}
-
-static __inline__ unsigned char
-inb(unsigned short __p)
-{
- unsigned char __v;
- asm volatile("inb %1,%0" : "=a" (__v) : "dN" (__p));
- return v;
-}
-
-static __inline__ unsigned short
-inw(unsigned short __p)
-{
- unsigned short __v;
- asm volatile("inw %1,%0" : "=a" (__v) : "dN" (__p));
- return v;
-}
-
-static __inline__ unsigned int
-inl(unsigned short __p)
-{
- unsigned int __v;
- asm volatile("inl %1,%0" : "=a" (__v) : "dN" (__p));
- return v;
-}
-
-/* String I/O macros */
-
-static __inline__ void
-outsb (unsigned short __p, const void *__d, unsigned long __n)
-{
- asm volatile("cld; rep; outsb" : "+S" (__d), "+c" (__n) : "d" (__p));
-}
-
-static __inline__ void
-outsw (unsigned short __p, const void *__d, unsigned long __n)
-{
- asm volatile("cld; rep; outsw" : "+S" (__d), "+c" (__n) : "d" (__p));
-}
-
-static __inline__ void
-outsl (unsigned short __p, const void *__d, unsigned long __n)
-{
- asm volatile("cld; rep; outsl" : "+S" (__d), "+c" (__n) : "d" (__p));
-}
-
-
-static __inline__ void
-insb (unsigned short __p, void *__d, unsigned long __n)
-{
- asm volatile("cld; rep; insb" : "+D" (__d), "+c" (__n) : "d" (__p));
-}
-
-static __inline__ void
-insw (unsigned short __p, void *__d, unsigned long __n)
-{
- asm volatile("cld; rep; insw" : "+D" (__d), "+c" (__n) : "d" (__p));
-}
-
-static __inline__ void
-insl (unsigned short __p, void *__d, unsigned long __n)
-{
- asm volatile("cld; rep; insl" : "+D" (__d), "+c" (__n) : "d" (__p));
-}
-
-#endif /* _SYS_IO_H */
diff --git a/klibc/klibc/arch/x86_64/syscall.S b/klibc/klibc/arch/x86_64/syscall.S
new file mode 100644
index 0000000000..f2c74ae974
--- /dev/null
+++ b/klibc/klibc/arch/x86_64/syscall.S
@@ -0,0 +1,28 @@
+/*
+ * arch/x86-64/syscall.S
+ *
+ * Common tail-handling code for system calls.
+ *
+ * The arguments are in the standard argument registers; the system
+ * call number in %eax.
+ */
+ .text
+ .align 4
+ .globl __syscall_common
+ .type __syscall_common,@function
+__syscall_common:
+ movq %rcx,%r10 # The kernel uses %r10 istf %rcx
+ syscall
+
+ cmpq $-4095,%rax
+ jb 1f
+
+ # Error return, must set errno
+ negl %eax
+ movl %eax,errno(%rip) # errno is type int, so 32 bits
+ orq $-1,%rax # orq $-1 smaller than movq $-1
+
+1:
+ ret
+
+ .size __syscall_common,.-__syscall_common
diff --git a/klibc/klibc/arch/x86_64/sysstub.ph b/klibc/klibc/arch/x86_64/sysstub.ph
new file mode 100644
index 0000000000..07af1227ca
--- /dev/null
+++ b/klibc/klibc/arch/x86_64/sysstub.ph
@@ -0,0 +1,23 @@
+# -*- perl -*-
+#
+# arch/x86_64/sysstub.ph
+#
+# Script to generate system call stubs
+#
+
+sub make_sysstub($$$$@) {
+ my($fname, $type, $sname, $stype, @args) = @_;
+
+ open(OUT, '>', "syscalls/${fname}.S");
+ print OUT "#include <asm/unistd.h>\n";
+ print OUT "\n";
+ print OUT "\t.type ${fname},\@function\n";
+ print OUT "\t.globl ${fname}\n";
+ print OUT "${fname}:\n";
+ print OUT "\tmovl \$__NR_${sname},%eax\n"; # Zero-extends to 64 bits
+ print OUT "\tjmp __syscall_common\n";
+ print OUT "\t.size ${fname},.-${fname}\n";
+ close(OUT);
+}
+
+1;
diff --git a/klibc/klibc/asprintf.c b/klibc/klibc/asprintf.c
new file mode 100644
index 0000000000..457d34bb15
--- /dev/null
+++ b/klibc/klibc/asprintf.c
@@ -0,0 +1,30 @@
+/*
+ * asprintf.c
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+
+int asprintf(char **bufp, const char *format, ...)
+{
+ va_list ap, ap1;
+ int rv;
+ int bytes;
+ char *p;
+
+ va_start(ap, format);
+ va_copy(ap1, ap);
+
+ bytes = vsnprintf(NULL, 0, format, ap1);
+ va_end(ap1);
+
+ *bufp = p = malloc(bytes+1);
+ if ( !p )
+ return -1;
+
+ rv = vsnprintf(p, bytes, format, ap);
+ va_end(ap);
+
+ return rv;
+}
diff --git a/klibc/klibc/ctypes.c b/klibc/klibc/ctypes.c
index c7adc9882c..acfa05ab65 100644
--- a/klibc/klibc/ctypes.c
+++ b/klibc/klibc/ctypes.c
@@ -10,41 +10,41 @@
const unsigned char __ctypes[257] = {
0, /* EOF */
- 0, /* control character */
- 0, /* control character */
- 0, /* control character */
- 0, /* control character */
- 0, /* control character */
- 0, /* control character */
- 0, /* control character */
- 0, /* control character */
- __ctype_space, /* BS */
- __ctype_space, /* TAB */
- __ctype_space, /* LF */
- __ctype_space, /* VT */
- __ctype_space, /* FF */
- __ctype_space, /* CR */
- 0, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl|__ctype_space, /* BS */
+ __ctype_cntrl|__ctype_space, /* TAB */
+ __ctype_cntrl|__ctype_space, /* LF */
+ __ctype_cntrl|__ctype_space, /* VT */
+ __ctype_cntrl|__ctype_space, /* FF */
+ __ctype_cntrl|__ctype_space, /* CR */
+ __ctype_cntrl, /* control character */
- 0, /* control character */
- 0, /* control character */
- 0, /* control character */
- 0, /* control character */
- 0, /* control character */
- 0, /* control character */
- 0, /* control character */
- 0, /* control character */
- 0, /* control character */
- 0, /* control character */
- 0, /* control character */
- 0, /* control character */
- 0, /* control character */
- 0, /* control character */
- 0, /* control character */
- 0, /* control character */
- 0, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
- __ctype_space|__ctype_print, /* space */
+ __ctype_print|__ctype_space, /* space */
__ctype_print|__ctype_punct, /* punctuation */
__ctype_print|__ctype_punct, /* punctuation */
__ctype_print|__ctype_punct, /* punctuation */
@@ -61,16 +61,16 @@ const unsigned char __ctypes[257] = {
__ctype_print|__ctype_punct, /* punctuation */
__ctype_print|__ctype_punct, /* punctuation */
- __ctype_digit|__ctype_xdigit|__ctype_print, /* digit */
- __ctype_digit|__ctype_xdigit|__ctype_print, /* digit */
- __ctype_digit|__ctype_xdigit|__ctype_print, /* digit */
- __ctype_digit|__ctype_xdigit|__ctype_print, /* digit */
- __ctype_digit|__ctype_xdigit|__ctype_print, /* digit */
- __ctype_digit|__ctype_xdigit|__ctype_print, /* digit */
- __ctype_digit|__ctype_xdigit|__ctype_print, /* digit */
- __ctype_digit|__ctype_xdigit|__ctype_print, /* digit */
- __ctype_digit|__ctype_xdigit|__ctype_print, /* digit */
- __ctype_digit|__ctype_xdigit|__ctype_print, /* digit */
+ __ctype_print|__ctype_digit|__ctype_xdigit, /* digit */
+ __ctype_print|__ctype_digit|__ctype_xdigit, /* digit */
+ __ctype_print|__ctype_digit|__ctype_xdigit, /* digit */
+ __ctype_print|__ctype_digit|__ctype_xdigit, /* digit */
+ __ctype_print|__ctype_digit|__ctype_xdigit, /* digit */
+ __ctype_print|__ctype_digit|__ctype_xdigit, /* digit */
+ __ctype_print|__ctype_digit|__ctype_xdigit, /* digit */
+ __ctype_print|__ctype_digit|__ctype_xdigit, /* digit */
+ __ctype_print|__ctype_digit|__ctype_xdigit, /* digit */
+ __ctype_print|__ctype_digit|__ctype_xdigit, /* digit */
__ctype_print|__ctype_punct, /* punctuation */
__ctype_print|__ctype_punct, /* punctuation */
__ctype_print|__ctype_punct, /* punctuation */
@@ -79,33 +79,33 @@ const unsigned char __ctypes[257] = {
__ctype_print|__ctype_punct, /* punctuation */
__ctype_print|__ctype_punct, /* punctuation */
- __ctype_upper|__ctype_print|__ctype_xdigit, /* A-F */
- __ctype_upper|__ctype_print|__ctype_xdigit, /* A-F */
- __ctype_upper|__ctype_print|__ctype_xdigit, /* A-F */
- __ctype_upper|__ctype_print|__ctype_xdigit, /* A-F */
- __ctype_upper|__ctype_print|__ctype_xdigit, /* A-F */
- __ctype_upper|__ctype_print|__ctype_xdigit, /* A-F */
- __ctype_upper|__ctype_print, /* G-Z */
- __ctype_upper|__ctype_print, /* G-Z */
- __ctype_upper|__ctype_print, /* G-Z */
- __ctype_upper|__ctype_print, /* G-Z */
- __ctype_upper|__ctype_print, /* G-Z */
- __ctype_upper|__ctype_print, /* G-Z */
- __ctype_upper|__ctype_print, /* G-Z */
- __ctype_upper|__ctype_print, /* G-Z */
- __ctype_upper|__ctype_print, /* G-Z */
+ __ctype_print|__ctype_upper|__ctype_xdigit, /* A-F */
+ __ctype_print|__ctype_upper|__ctype_xdigit, /* A-F */
+ __ctype_print|__ctype_upper|__ctype_xdigit, /* A-F */
+ __ctype_print|__ctype_upper|__ctype_xdigit, /* A-F */
+ __ctype_print|__ctype_upper|__ctype_xdigit, /* A-F */
+ __ctype_print|__ctype_upper|__ctype_xdigit, /* A-F */
+ __ctype_print|__ctype_upper, /* G-Z */
+ __ctype_print|__ctype_upper, /* G-Z */
+ __ctype_print|__ctype_upper, /* G-Z */
+ __ctype_print|__ctype_upper, /* G-Z */
+ __ctype_print|__ctype_upper, /* G-Z */
+ __ctype_print|__ctype_upper, /* G-Z */
+ __ctype_print|__ctype_upper, /* G-Z */
+ __ctype_print|__ctype_upper, /* G-Z */
+ __ctype_print|__ctype_upper, /* G-Z */
- __ctype_upper|__ctype_print, /* G-Z */
- __ctype_upper|__ctype_print, /* G-Z */
- __ctype_upper|__ctype_print, /* G-Z */
- __ctype_upper|__ctype_print, /* G-Z */
- __ctype_upper|__ctype_print, /* G-Z */
- __ctype_upper|__ctype_print, /* G-Z */
- __ctype_upper|__ctype_print, /* G-Z */
- __ctype_upper|__ctype_print, /* G-Z */
- __ctype_upper|__ctype_print, /* G-Z */
- __ctype_upper|__ctype_print, /* G-Z */
- __ctype_upper|__ctype_print, /* G-Z */
+ __ctype_print|__ctype_upper, /* G-Z */
+ __ctype_print|__ctype_upper, /* G-Z */
+ __ctype_print|__ctype_upper, /* G-Z */
+ __ctype_print|__ctype_upper, /* G-Z */
+ __ctype_print|__ctype_upper, /* G-Z */
+ __ctype_print|__ctype_upper, /* G-Z */
+ __ctype_print|__ctype_upper, /* G-Z */
+ __ctype_print|__ctype_upper, /* G-Z */
+ __ctype_print|__ctype_upper, /* G-Z */
+ __ctype_print|__ctype_upper, /* G-Z */
+ __ctype_print|__ctype_upper, /* G-Z */
__ctype_print|__ctype_punct, /* punctuation */
__ctype_print|__ctype_punct, /* punctuation */
__ctype_print|__ctype_punct, /* punctuation */
@@ -113,74 +113,74 @@ const unsigned char __ctypes[257] = {
__ctype_print|__ctype_punct, /* punctuation */
__ctype_print|__ctype_punct, /* punctuation */
- __ctype_lower|__ctype_print|__ctype_xdigit, /* a-f */
- __ctype_lower|__ctype_print|__ctype_xdigit, /* a-f */
- __ctype_lower|__ctype_print|__ctype_xdigit, /* a-f */
- __ctype_lower|__ctype_print|__ctype_xdigit, /* a-f */
- __ctype_lower|__ctype_print|__ctype_xdigit, /* a-f */
- __ctype_lower|__ctype_print|__ctype_xdigit, /* a-f */
- __ctype_lower|__ctype_print, /* g-z */
- __ctype_lower|__ctype_print, /* g-z */
- __ctype_lower|__ctype_print, /* g-z */
- __ctype_lower|__ctype_print, /* g-z */
- __ctype_lower|__ctype_print, /* g-z */
- __ctype_lower|__ctype_print, /* g-z */
- __ctype_lower|__ctype_print, /* g-z */
- __ctype_lower|__ctype_print, /* g-z */
- __ctype_lower|__ctype_print, /* g-z */
+ __ctype_print|__ctype_lower|__ctype_xdigit, /* a-f */
+ __ctype_print|__ctype_lower|__ctype_xdigit, /* a-f */
+ __ctype_print|__ctype_lower|__ctype_xdigit, /* a-f */
+ __ctype_print|__ctype_lower|__ctype_xdigit, /* a-f */
+ __ctype_print|__ctype_lower|__ctype_xdigit, /* a-f */
+ __ctype_print|__ctype_lower|__ctype_xdigit, /* a-f */
+ __ctype_print|__ctype_lower, /* g-z */
+ __ctype_print|__ctype_lower, /* g-z */
+ __ctype_print|__ctype_lower, /* g-z */
+ __ctype_print|__ctype_lower, /* g-z */
+ __ctype_print|__ctype_lower, /* g-z */
+ __ctype_print|__ctype_lower, /* g-z */
+ __ctype_print|__ctype_lower, /* g-z */
+ __ctype_print|__ctype_lower, /* g-z */
+ __ctype_print|__ctype_lower, /* g-z */
- __ctype_lower|__ctype_print, /* g-z */
- __ctype_lower|__ctype_print, /* g-z */
- __ctype_lower|__ctype_print, /* g-z */
- __ctype_lower|__ctype_print, /* g-z */
- __ctype_lower|__ctype_print, /* g-z */
- __ctype_lower|__ctype_print, /* g-z */
- __ctype_lower|__ctype_print, /* g-z */
- __ctype_lower|__ctype_print, /* g-z */
- __ctype_lower|__ctype_print, /* g-z */
- __ctype_lower|__ctype_print, /* g-z */
- __ctype_lower|__ctype_print, /* g-z */
+ __ctype_print|__ctype_lower, /* g-z */
+ __ctype_print|__ctype_lower, /* g-z */
+ __ctype_print|__ctype_lower, /* g-z */
+ __ctype_print|__ctype_lower, /* g-z */
+ __ctype_print|__ctype_lower, /* g-z */
+ __ctype_print|__ctype_lower, /* g-z */
+ __ctype_print|__ctype_lower, /* g-z */
+ __ctype_print|__ctype_lower, /* g-z */
+ __ctype_print|__ctype_lower, /* g-z */
+ __ctype_print|__ctype_lower, /* g-z */
+ __ctype_print|__ctype_lower, /* g-z */
__ctype_print|__ctype_punct, /* punctuation */
__ctype_print|__ctype_punct, /* punctuation */
__ctype_print|__ctype_punct, /* punctuation */
__ctype_print|__ctype_punct, /* punctuation */
- 0, /* control character */
+ __ctype_cntrl, /* control character */
- 0, /* control character */
- 0, /* control character */
- 0, /* control character */
- 0, /* control character */
- 0, /* control character */
- 0, /* control character */
- 0, /* control character */
- 0, /* control character */
- 0, /* control character */
- 0, /* control character */
- 0, /* control character */
- 0, /* control character */
- 0, /* control character */
- 0, /* control character */
- 0, /* control character */
- 0, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
- 0, /* control character */
- 0, /* control character */
- 0, /* control character */
- 0, /* control character */
- 0, /* control character */
- 0, /* control character */
- 0, /* control character */
- 0, /* control character */
- 0, /* control character */
- 0, /* control character */
- 0, /* control character */
- 0, /* control character */
- 0, /* control character */
- 0, /* control character */
- 0, /* control character */
- 0, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
- __ctype_space|__ctype_print, /* NBSP */
+ __ctype_print|__ctype_space, /* NBSP */
__ctype_print|__ctype_punct, /* punctuation */
__ctype_print|__ctype_punct, /* punctuation */
__ctype_print|__ctype_punct, /* punctuation */
@@ -214,71 +214,71 @@ const unsigned char __ctypes[257] = {
__ctype_print|__ctype_punct, /* punctuation */
__ctype_print|__ctype_punct, /* punctuation */
- __ctype_upper|__ctype_print, /* upper accented */
- __ctype_upper|__ctype_print, /* upper accented */
- __ctype_upper|__ctype_print, /* upper accented */
- __ctype_upper|__ctype_print, /* upper accented */
- __ctype_upper|__ctype_print, /* upper accented */
- __ctype_upper|__ctype_print, /* upper accented */
- __ctype_upper|__ctype_print, /* upper accented */
- __ctype_upper|__ctype_print, /* upper accented */
- __ctype_upper|__ctype_print, /* upper accented */
- __ctype_upper|__ctype_print, /* upper accented */
- __ctype_upper|__ctype_print, /* upper accented */
- __ctype_upper|__ctype_print, /* upper accented */
- __ctype_upper|__ctype_print, /* upper accented */
- __ctype_upper|__ctype_print, /* upper accented */
- __ctype_upper|__ctype_print, /* upper accented */
- __ctype_upper|__ctype_print, /* upper accented */
+ __ctype_print|__ctype_upper, /* upper accented */
+ __ctype_print|__ctype_upper, /* upper accented */
+ __ctype_print|__ctype_upper, /* upper accented */
+ __ctype_print|__ctype_upper, /* upper accented */
+ __ctype_print|__ctype_upper, /* upper accented */
+ __ctype_print|__ctype_upper, /* upper accented */
+ __ctype_print|__ctype_upper, /* upper accented */
+ __ctype_print|__ctype_upper, /* upper accented */
+ __ctype_print|__ctype_upper, /* upper accented */
+ __ctype_print|__ctype_upper, /* upper accented */
+ __ctype_print|__ctype_upper, /* upper accented */
+ __ctype_print|__ctype_upper, /* upper accented */
+ __ctype_print|__ctype_upper, /* upper accented */
+ __ctype_print|__ctype_upper, /* upper accented */
+ __ctype_print|__ctype_upper, /* upper accented */
+ __ctype_print|__ctype_upper, /* upper accented */
- __ctype_upper|__ctype_print, /* upper accented */
- __ctype_upper|__ctype_print, /* upper accented */
- __ctype_upper|__ctype_print, /* upper accented */
- __ctype_upper|__ctype_print, /* upper accented */
- __ctype_upper|__ctype_print, /* upper accented */
- __ctype_upper|__ctype_print, /* upper accented */
- __ctype_upper|__ctype_print, /* upper accented */
- __ctype_print|__ctype_punct, /* punctuation */
- __ctype_upper|__ctype_print, /* upper accented */
- __ctype_upper|__ctype_print, /* upper accented */
- __ctype_upper|__ctype_print, /* upper accented */
- __ctype_upper|__ctype_print, /* upper accented */
- __ctype_upper|__ctype_print, /* upper accented */
- __ctype_upper|__ctype_print, /* upper accented */
- __ctype_upper|__ctype_print, /* upper accented */
- __ctype_lower|__ctype_print, /* lower accented */
+ __ctype_print|__ctype_upper, /* upper accented */
+ __ctype_print|__ctype_upper, /* upper accented */
+ __ctype_print|__ctype_upper, /* upper accented */
+ __ctype_print|__ctype_upper, /* upper accented */
+ __ctype_print|__ctype_upper, /* upper accented */
+ __ctype_print|__ctype_upper, /* upper accented */
+ __ctype_print|__ctype_upper, /* upper accented */
+ __ctype_print|__ctype_punct, /* punctuation */
+ __ctype_print|__ctype_upper, /* upper accented */
+ __ctype_print|__ctype_upper, /* upper accented */
+ __ctype_print|__ctype_upper, /* upper accented */
+ __ctype_print|__ctype_upper, /* upper accented */
+ __ctype_print|__ctype_upper, /* upper accented */
+ __ctype_print|__ctype_upper, /* upper accented */
+ __ctype_print|__ctype_upper, /* upper accented */
+ __ctype_print|__ctype_lower, /* lower accented */
- __ctype_lower|__ctype_print, /* lower accented */
- __ctype_lower|__ctype_print, /* lower accented */
- __ctype_lower|__ctype_print, /* lower accented */
- __ctype_lower|__ctype_print, /* lower accented */
- __ctype_lower|__ctype_print, /* lower accented */
- __ctype_lower|__ctype_print, /* lower accented */
- __ctype_lower|__ctype_print, /* lower accented */
- __ctype_lower|__ctype_print, /* lower accented */
- __ctype_lower|__ctype_print, /* lower accented */
- __ctype_lower|__ctype_print, /* lower accented */
- __ctype_lower|__ctype_print, /* lower accented */
- __ctype_lower|__ctype_print, /* lower accented */
- __ctype_lower|__ctype_print, /* lower accented */
- __ctype_lower|__ctype_print, /* lower accented */
- __ctype_lower|__ctype_print, /* lower accented */
- __ctype_lower|__ctype_print, /* lower accented */
+ __ctype_print|__ctype_lower, /* lower accented */
+ __ctype_print|__ctype_lower, /* lower accented */
+ __ctype_print|__ctype_lower, /* lower accented */
+ __ctype_print|__ctype_lower, /* lower accented */
+ __ctype_print|__ctype_lower, /* lower accented */
+ __ctype_print|__ctype_lower, /* lower accented */
+ __ctype_print|__ctype_lower, /* lower accented */
+ __ctype_print|__ctype_lower, /* lower accented */
+ __ctype_print|__ctype_lower, /* lower accented */
+ __ctype_print|__ctype_lower, /* lower accented */
+ __ctype_print|__ctype_lower, /* lower accented */
+ __ctype_print|__ctype_lower, /* lower accented */
+ __ctype_print|__ctype_lower, /* lower accented */
+ __ctype_print|__ctype_lower, /* lower accented */
+ __ctype_print|__ctype_lower, /* lower accented */
+ __ctype_print|__ctype_lower, /* lower accented */
- __ctype_lower|__ctype_print, /* lower accented */
- __ctype_lower|__ctype_print, /* lower accented */
- __ctype_lower|__ctype_print, /* lower accented */
- __ctype_lower|__ctype_print, /* lower accented */
- __ctype_lower|__ctype_print, /* lower accented */
- __ctype_lower|__ctype_print, /* lower accented */
- __ctype_lower|__ctype_print, /* lower accented */
- __ctype_print|__ctype_punct, /* punctuation */
- __ctype_lower|__ctype_print, /* lower accented */
- __ctype_lower|__ctype_print, /* lower accented */
- __ctype_lower|__ctype_print, /* lower accented */
- __ctype_lower|__ctype_print, /* lower accented */
- __ctype_lower|__ctype_print, /* lower accented */
- __ctype_lower|__ctype_print, /* lower accented */
- __ctype_lower|__ctype_print, /* lower accented */
- __ctype_lower|__ctype_print, /* lower accented */
+ __ctype_print|__ctype_lower, /* lower accented */
+ __ctype_print|__ctype_lower, /* lower accented */
+ __ctype_print|__ctype_lower, /* lower accented */
+ __ctype_print|__ctype_lower, /* lower accented */
+ __ctype_print|__ctype_lower, /* lower accented */
+ __ctype_print|__ctype_lower, /* lower accented */
+ __ctype_print|__ctype_lower, /* lower accented */
+ __ctype_print|__ctype_punct, /* punctuation */
+ __ctype_print|__ctype_lower, /* lower accented */
+ __ctype_print|__ctype_lower, /* lower accented */
+ __ctype_print|__ctype_lower, /* lower accented */
+ __ctype_print|__ctype_lower, /* lower accented */
+ __ctype_print|__ctype_lower, /* lower accented */
+ __ctype_print|__ctype_lower, /* lower accented */
+ __ctype_print|__ctype_lower, /* lower accented */
+ __ctype_print|__ctype_lower, /* lower accented */
};
diff --git a/klibc/klibc/daemon.c b/klibc/klibc/daemon.c
new file mode 100644
index 0000000000..75d7146205
--- /dev/null
+++ b/klibc/klibc/daemon.c
@@ -0,0 +1,38 @@
+/*
+ * daemon.c - "daemonize" a process
+ */
+
+#include <stdlib.h>
+#include <unistd.h>
+#include <fcntl.h>
+
+int daemon(int nochdir, int noclose)
+{
+ int nullfd;
+ pid_t f;
+
+ if ( !nochdir ) {
+ if ( chdir("/") )
+ return -1;
+ }
+
+ if ( !noclose ) {
+ if ( (nullfd = open("/dev/null", O_RDWR)) < 0 ||
+ dup2(nullfd, 0) < 0 ||
+ dup2(nullfd, 1) < 0 ||
+ dup2(nullfd, 2) < 0 )
+ return -1;
+ close(nullfd);
+ }
+
+ f = fork();
+ if ( f < 0 )
+ return -1;
+ else if ( f > 0 )
+ _exit(0);
+
+
+ return setsid();
+}
+
+
diff --git a/klibc/klibc/fdatasync.c b/klibc/klibc/fdatasync.c
deleted file mode 100644
index 53079b09d6..0000000000
--- a/klibc/klibc/fdatasync.c
+++ /dev/null
@@ -1,15 +0,0 @@
-/*
- * fdatasync.c
- *
- * Some systems don't have this (alpha?) ... this is really a bug,
- * but mimic using fsync()
- */
-
-#include <unistd.h>
-#include <sys/syscall.h>
-
-#ifndef __NR_fdatasync
-#define __NR_fdatasync __NR_fsync
-#endif
-
-_syscall1(int,fdatasync,int,fd);
diff --git a/klibc/klibc/fork.c b/klibc/klibc/fork.c
index d7e4db89a1..daf313eaf2 100644
--- a/klibc/klibc/fork.c
+++ b/klibc/klibc/fork.c
@@ -9,21 +9,13 @@
#include <signal.h>
#include <unistd.h>
-#ifdef __NR_fork
+#ifndef __NR_fork
-#ifdef _syscall0_forkish
-_syscall0_forkish(pid_t,fork);
-#else
-_syscall0(pid_t,fork);
-#endif
-
-#else /* __NR_fork */
-
-static inline _syscall2(pid_t,clone,unsigned long,flags,void *,newsp);
+extern pid_t __clone(unsigned long flags, void * newsp);
pid_t fork(void)
{
- return clone(SIGCHLD, 0);
+ return __clone(SIGCHLD, 0);
}
#endif /* __NR_fork */
diff --git a/klibc/klibc/fstatfs.c b/klibc/klibc/fstatfs.c
new file mode 100644
index 0000000000..09e4674947
--- /dev/null
+++ b/klibc/klibc/fstatfs.c
@@ -0,0 +1,19 @@
+/*
+ * fstatfs.c
+ *
+ * On architectures which do fstatfs64, wrap the system call
+ */
+
+#include <sys/syscall.h>
+#include <sys/vfs.h>
+
+#ifdef __NR_fstatfs64
+
+extern int __fstatfs64(int, size_t, struct statfs *);
+
+int fstatfs(int fd, struct statfs *buf)
+{
+ return __fstatfs64(fd, sizeof *buf, buf);
+}
+
+#endif
diff --git a/klibc/klibc/getcwd.c b/klibc/klibc/getcwd.c
index 350ec69a63..613ca0529c 100644
--- a/klibc/klibc/getcwd.c
+++ b/klibc/klibc/getcwd.c
@@ -1,12 +1,13 @@
/*
* getcwd.c
+ *
+ * The system call behaves differently than the library function.
*/
#include <unistd.h>
#include <sys/syscall.h>
-#define __NR___getcwd __NR_getcwd
-static inline _syscall2(int,__getcwd,char *,buf,size_t,size);
+extern int __getcwd(char * buf, size_t size);
char *getcwd(char *buf, size_t size)
{
diff --git a/klibc/klibc/getpagesize.c b/klibc/klibc/getpagesize.c
deleted file mode 100644
index 2d975b1586..0000000000
--- a/klibc/klibc/getpagesize.c
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * getpagesize.c
- */
-
-#include <sys/syscall.h>
-#include <asm/page.h>
-
-/* Presumably there is a better way to do this... */
-#ifdef __ia64__
-# define __NR_getpagesize 1171
-#endif
-
-#ifdef __NR_getpagesize
-
-_syscall0(int,getpagesize);
-
-#else
-
-int getpagesize(void)
-{
- return PAGE_SIZE;
-}
-
-#endif
-
-
diff --git a/klibc/klibc/getpriority.c b/klibc/klibc/getpriority.c
index d6db2cc6b9..4ea630487d 100644
--- a/klibc/klibc/getpriority.c
+++ b/klibc/klibc/getpriority.c
@@ -10,16 +10,14 @@
#include <sys/resource.h>
#include <sys/syscall.h>
-#define __NR__getpriority __NR_getpriority
+#if !defined(__alpha__) && !defined(__ia64__)
-static inline _syscall2(int,_getpriority,int,which,int,who);
+extern int __getpriority(int, int);
int getpriority(int which, int who)
{
-#if defined(__alpha__) || defined(__ia64__)
- return _getpriority(which, who);
-#else
- int rv = _getpriority(which, who);
+ int rv = __getpriority(which, who);
return ( rv < 0 ) ? rv : 20-rv;
-#endif
}
+
+#endif
diff --git a/klibc/klibc/include/alloca.h b/klibc/klibc/include/alloca.h
deleted file mode 100644
index 41a4d94d44..0000000000
--- a/klibc/klibc/include/alloca.h
+++ /dev/null
@@ -1,13 +0,0 @@
-/*
- * alloca.h
- *
- * Just call the builtin alloca() function
- */
-
-#ifndef _ALLOCA_H
-#define _ALLOCA_H
-
-#define alloca(size) __builtin_alloca(size)
-
-#endif /* _ALLOCA_H */
-
diff --git a/klibc/klibc/include/arpa/inet.h b/klibc/klibc/include/arpa/inet.h
deleted file mode 100644
index 043b148e17..0000000000
--- a/klibc/klibc/include/arpa/inet.h
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * arpa/inet.h
- */
-
-#ifndef _ARPA_INET_H
-#define _ARPA_INET_H
-
-#include <klibc/extern.h>
-#include <stdint.h>
-#include <sys/types.h>
-#include <netinet/in.h>
-#include <netinet/in6.h>
-
-__extern uint32_t inet_addr(const char *);
-__extern int inet_aton(const char *, struct in_addr *);
-__extern char *inet_ntoa(struct in_addr);
-__extern int inet_pton(int, const char *, void *);
-__extern const char *inet_ntop(int, const void *, char *, size_t);
-__extern unsigned int inet_nsap_addr(const char *, unsigned char *, int);
-__extern char *inet_nsap_ntoa(int, const unsigned char *, char *);
-
-#endif /* _ARPA_INET_H */
-
-
diff --git a/klibc/klibc/include/assert.h b/klibc/klibc/include/assert.h
deleted file mode 100644
index 58cc37c487..0000000000
--- a/klibc/klibc/include/assert.h
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * assert.h
- */
-
-#ifndef _ASSERT_H
-#define _ASSERT_H
-
-#ifdef NDEBUG
-
-#define assert(x) ((void)(x))
-
-#else
-
-extern void __assert_fail(const char *, const char *,
- unsigned int);
-
-#define assert(x) ((x) ? (void)0 : __assert_fail(#x, __FILE__, __LINE__))
-
-#endif
-
-#endif /* _ASSERT_H */
-
diff --git a/klibc/klibc/include/bits32/bitsize/limits.h b/klibc/klibc/include/bits32/bitsize/limits.h
deleted file mode 100644
index f90e524b2b..0000000000
--- a/klibc/klibc/include/bits32/bitsize/limits.h
+++ /dev/null
@@ -1,14 +0,0 @@
-/*
- * bits32/limits.h
- */
-
-#ifndef _BITSIZE_LIMITS_H
-#define _BITSIZE_LIMITS_H
-
-#define LONG_BIT 32
-
-#define LONG_MIN (-2147483647L-1)
-#define LONG_MAX 2147483647L
-#define ULONG_MAX 4294967295UL
-
-#endif /* _BITSIZE_LIMITS_H */
diff --git a/klibc/klibc/include/bits32/bitsize/stddef.h b/klibc/klibc/include/bits32/bitsize/stddef.h
deleted file mode 100644
index bf6e695ed3..0000000000
--- a/klibc/klibc/include/bits32/bitsize/stddef.h
+++ /dev/null
@@ -1,18 +0,0 @@
-/*
- * bits32/stddef.h
- */
-
-#ifndef _BITSIZE_STDDEF_H
-#define _BITSIZE_STDDEF_H
-
-#define _SIZE_T
-#if (defined(__s390__) || defined(__hppa__) || defined(__cris__))
-typedef unsigned long size_t;
-#else
-typedef unsigned int size_t;
-#endif
-
-#define _PTRDIFF_T
-typedef signed int ptrdiff_t;
-
-#endif /* _BITSIZE_STDDEF_H */
diff --git a/klibc/klibc/include/bits32/bitsize/stdint.h b/klibc/klibc/include/bits32/bitsize/stdint.h
deleted file mode 100644
index 40b464961c..0000000000
--- a/klibc/klibc/include/bits32/bitsize/stdint.h
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * bits32/stdint.h
- */
-
-#ifndef _BITSIZE_STDINT_H
-#define _BITSIZE_STDINT_H
-
-typedef signed char int8_t;
-typedef short int int16_t;
-typedef int int32_t;
-typedef long long int int64_t;
-
-typedef unsigned char uint8_t;
-typedef unsigned short int uint16_t;
-typedef unsigned int uint32_t;
-typedef unsigned long long int uint64_t;
-
-typedef int int_fast16_t;
-typedef int int_fast32_t;
-
-typedef unsigned int uint_fast16_t;
-typedef unsigned int uint_fast32_t;
-
-typedef int intptr_t;
-typedef unsigned int uintptr_t;
-
-#define __INT64_C(c) c ## LL
-#define __UINT64_C(c) c ## ULL
-
-#define __PRI64_RANK "ll"
-#define __PRIFAST_RANK ""
-#define __PRIPTR_RANK ""
-
-#endif /* _BITSIZE_STDINT_H */
diff --git a/klibc/klibc/include/bits32/bitsize/stdintconst.h b/klibc/klibc/include/bits32/bitsize/stdintconst.h
deleted file mode 100644
index 8157dd06e0..0000000000
--- a/klibc/klibc/include/bits32/bitsize/stdintconst.h
+++ /dev/null
@@ -1,18 +0,0 @@
-/*
- * bits32/stdintconst.h
- */
-
-#ifndef _BITSIZE_STDINTCONST_H
-#define _BITSIZE_STDINTCONST_H
-
-#define INT_FAST16_C(c) INT32_C(c)
-#define INT_FAST32_C(c) INT32_C(c)
-
-#define UINT_FAST16_C(c) UINT32_C(c)
-#define UINT_FAST32_C(c) UINT32_C(c)
-
-#define INTPTR_C(c) INT32_C(c)
-#define UINTPTR_C(c) UINT32_C(c)
-#define PTRDIFF_C(c) INT32_C(c)
-
-#endif /* _BITSIZE_STDINTCONST_H */
diff --git a/klibc/klibc/include/bits32/bitsize/stdintlimits.h b/klibc/klibc/include/bits32/bitsize/stdintlimits.h
deleted file mode 100644
index b44fe01186..0000000000
--- a/klibc/klibc/include/bits32/bitsize/stdintlimits.h
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * bits32/stdintlimits.h
- */
-
-#ifndef _BITSIZE_STDINTLIMITS_H
-#define _BITSIZE_STDINTLIMITS_H
-
-#define INT_FAST16_MIN INT32_MIN
-#define INT_FAST32_MIN INT32_MIN
-#define INT_FAST16_MAX INT32_MAX
-#define INT_FAST32_MAX INT32_MAX
-#define UINT_FAST16_MAX UINT32_MAX
-#define UINT_FAST32_MAX UINT32_MAX
-
-#define INTPTR_MIN INT32_MIN
-#define INTPTR_MAX INT32_MAX
-#define UINTPTR_MAX UINT32_MAX
-
-#define PTRDIFF_MIN INT32_MIN
-#define PTRDIFF_MAX INT32_MAX
-
-#endif /* _BITSIZE_STDINTLIMITS_H */
diff --git a/klibc/klibc/include/bits64/bitsize/limits.h b/klibc/klibc/include/bits64/bitsize/limits.h
deleted file mode 100644
index 7b20da085b..0000000000
--- a/klibc/klibc/include/bits64/bitsize/limits.h
+++ /dev/null
@@ -1,14 +0,0 @@
-/*
- * bits64/limits.h
- */
-
-#ifndef _BITSIZE_LIMITS_H
-#define _BITSIZE_LIMITS_H
-
-#define LONG_BIT 64
-
-#define LONG_MIN (-9223372036854775807L-1)
-#define LONG_MAX 9223372036854775807L
-#define ULONG_MAX 18446744073709551615UL
-
-#endif /* _BITSIZE_LIMITS_H */
diff --git a/klibc/klibc/include/bits64/bitsize/stddef.h b/klibc/klibc/include/bits64/bitsize/stddef.h
deleted file mode 100644
index 3e72621862..0000000000
--- a/klibc/klibc/include/bits64/bitsize/stddef.h
+++ /dev/null
@@ -1,13 +0,0 @@
-/*
- * bits64/stddef.h
- */
-
-#ifndef _BITSIZE_STDDEF_H
-#define _BITSIZE_STDDEF_H
-
-#define _SIZE_T
-typedef unsigned long size_t;
-#define _PTRDIFF_T
-typedef signed long ptrdiff_t;
-
-#endif /* _BITSIZE_STDDEF_H */
diff --git a/klibc/klibc/include/bits64/bitsize/stdint.h b/klibc/klibc/include/bits64/bitsize/stdint.h
deleted file mode 100644
index f569f526b6..0000000000
--- a/klibc/klibc/include/bits64/bitsize/stdint.h
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * bits64/stdint.h
- */
-
-#ifndef _BITSIZE_STDINT_H
-#define _BITSIZE_STDINT_H
-
-typedef signed char int8_t;
-typedef short int int16_t;
-typedef int int32_t;
-typedef long long int int64_t;
-
-typedef unsigned char uint8_t;
-typedef unsigned short int uint16_t;
-typedef unsigned int uint32_t;
-typedef unsigned long int uint64_t;
-
-typedef long int int_fast16_t;
-typedef long int int_fast32_t;
-
-typedef unsigned long int uint_fast16_t;
-typedef unsigned long int uint_fast32_t;
-
-typedef long int intptr_t;
-typedef unsigned long int uintptr_t;
-
-#define __INT64_C(c) c ## L
-#define __UINT64_C(c) c ## UL
-
-#define __PRI64_RANK "l"
-#define __PRIFAST_RANK "l"
-#define __PRIPTR_RANK "l"
-
-#endif /* _BITSIZE_STDINT_H */
-
-
diff --git a/klibc/klibc/include/bits64/bitsize/stdintconst.h b/klibc/klibc/include/bits64/bitsize/stdintconst.h
deleted file mode 100644
index 65f2db0501..0000000000
--- a/klibc/klibc/include/bits64/bitsize/stdintconst.h
+++ /dev/null
@@ -1,18 +0,0 @@
-/*
- * bits64/stdintconst.h
- */
-
-#ifndef _BITSIZE_STDINTCONST_H
-#define _BITSIZE_STDINTCONST_H
-
-#define INT_FAST16_C(c) INT64_C(c)
-#define INT_FAST32_C(c) INT64_C(c)
-
-#define UINT_FAST16_C(c) UINT64_C(c)
-#define UINT_FAST32_C(c) UINT64_C(c)
-
-#define INTPTR_C(c) INT64_C(c)
-#define UINTPTR_C(c) UINT64_C(c)
-#define PTRDIFF_C(c) INT64_C(c)
-
-#endif /* _BITSIZE_STDINTCONST_H */
diff --git a/klibc/klibc/include/bits64/bitsize/stdintlimits.h b/klibc/klibc/include/bits64/bitsize/stdintlimits.h
deleted file mode 100644
index d110d17d2d..0000000000
--- a/klibc/klibc/include/bits64/bitsize/stdintlimits.h
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * bits64/stdintlimits.h
- */
-
-#ifndef _BITSIZE_STDINTLIMITS_H
-#define _BITSIZE_STDINTLIMITS_H
-
-#define INT_FAST16_MIN INT64_MIN
-#define INT_FAST32_MIN INT64_MIN
-#define INT_FAST16_MAX INT64_MAX
-#define INT_FAST32_MAX INT64_MAX
-#define UINT_FAST16_MAX UINT64_MAX
-#define UINT_FAST32_MAX UINT64_MAX
-
-#define INTPTR_MIN INT64_MIN
-#define INTPTR_MAX INT64_MAX
-#define UINTPTR_MAX UINT64_MAX
-
-#define PTRDIFF_MIN INT64_MIN
-#define PTRDIFF_MAX INT64_MAX
-
-#endif /* _BITSIZE_STDINTLIMITS_H */
diff --git a/klibc/klibc/include/ctype.h b/klibc/klibc/include/ctype.h
deleted file mode 100644
index 3f5cfad558..0000000000
--- a/klibc/klibc/include/ctype.h
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
- * ctype.h
- *
- * This assumes ISO 8859-1, being a reasonable superset of ASCII.
- */
-
-#ifndef _CTYPE_H
-#define _CTYPE_H
-
-#ifndef __CTYPE_NO_INLINE
-# define __ctype_inline extern __inline__
-#else
-# define __ctype_inline
-#endif
-
-/*
- * This relies on the following definitions:
- *
- * cntrl = !print
- * alpha = upper|lower
- * graph = punct|alpha|digit
- * blank = '\t' || ' ' (per POSIX requirement)
- */
-enum {
- __ctype_upper = (1 << 0),
- __ctype_lower = (1 << 1),
- __ctype_digit = (1 << 2),
- __ctype_xdigit = (1 << 3),
- __ctype_space = (1 << 4),
- __ctype_print = (1 << 5),
- __ctype_punct = (1 << 6)
-};
-
-extern const unsigned char __ctypes[];
-
-__ctype_inline int isalnum(int __c)
-{
- return __ctypes[__c+1] &
- (__ctype_upper|__ctype_lower|__ctype_digit);
-}
-
-__ctype_inline int isalpha(int __c)
-{
- return __ctypes[__c+1] &
- (__ctype_upper|__ctype_lower);
-}
-
-__ctype_inline int isascii(int __c)
-{
- return !(__c & ~0x7f);
-}
-
-__ctype_inline int isblank(int __c)
-{
- return (__c == '\t') || (__c == ' ');
-}
-
-__ctype_inline int iscntrl(int __c)
-{
- return (__c >= 0) && !(__ctypes[__c+1] & __ctype_print);
-}
-
-__ctype_inline int isdigit(int __c)
-{
- return __ctypes[__c+1] & __ctype_digit;
-}
-
-__ctype_inline int isgraph(int __c)
-{
- return __ctypes[__c+1] &
- (__ctype_upper|__ctype_lower|__ctype_digit|__ctype_punct);
-}
-
-__ctype_inline int islower(int __c)
-{
- return __ctypes[__c+1] & __ctype_lower;
-}
-
-__ctype_inline int isprint(int __c)
-{
- return __ctypes[__c+1] & __ctype_print;
-}
-
-__ctype_inline int ispunct(int __c)
-{
- return __ctypes[__c+1] & __ctype_punct;
-}
-
-__ctype_inline int isspace(int __c)
-{
- return __ctypes[__c+1] & __ctype_space;
-}
-
-__ctype_inline int isupper(int __c)
-{
- return __ctypes[__c+1] & __ctype_upper;
-}
-
-__ctype_inline int isxdigit(int __c)
-{
- return __ctypes[__c+1] & __ctype_xdigit;
-}
-
-/* Note: this is decimal, not hex, to avoid accidental promotion to unsigned */
-#define _toupper(__c) ((__c) & ~32)
-#define _tolower(__c) ((__c) | 32)
-
-__ctype_inline int toupper(int __c)
-{
- return islower(__c) ? _toupper(__c) : __c;
-}
-
-__ctype_inline int tolower(int __c)
-{
- return isupper(__c) ? _tolower(__c) : __c;
-}
-
-#endif /* _CTYPE_H */
diff --git a/klibc/klibc/include/dirent.h b/klibc/klibc/include/dirent.h
deleted file mode 100644
index 10dd138ee5..0000000000
--- a/klibc/klibc/include/dirent.h
+++ /dev/null
@@ -1,20 +0,0 @@
-/*
- * dirent.h
- */
-
-#ifndef _DIRENT_H
-#define _DIRENT_H
-
-#include <klibc/extern.h>
-#include <sys/dirent.h>
-
-#ifndef __IO_DIR_DEFINED
-struct _IO_dir;
-#endif
-typedef struct _IO_dir DIR;
-
-__extern DIR *opendir(const char *);
-__extern struct dirent *readdir(DIR *);
-__extern int closedir(DIR *);
-
-#endif /* _DIRENT_H */
diff --git a/klibc/klibc/include/elf.h b/klibc/klibc/include/elf.h
deleted file mode 100644
index 52f47d042e..0000000000
--- a/klibc/klibc/include/elf.h
+++ /dev/null
@@ -1,12 +0,0 @@
-/*
- * elf.h
- */
-
-#ifndef _ELF_H
-#define _ELF_H
-
-#include <sys/elf32.h>
-#include <sys/elf64.h>
-
-#endif /* _ELF_H */
-
diff --git a/klibc/klibc/include/endian.h b/klibc/klibc/include/endian.h
deleted file mode 100644
index 44f89ccbbc..0000000000
--- a/klibc/klibc/include/endian.h
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * endian.h
- */
-
-#ifndef _ENDIAN_H
-#define _ENDIAN_H
-
-#include <klibc/compiler.h>
-#include <asm/byteorder.h>
-
-/* Linux' asm/byteorder.h defines either __LITTLE_ENDIAN or
- __BIG_ENDIAN, but the glibc/BSD-ish macros expect both to be
- defined with __BYTE_ORDER defining which is actually used... */
-
-#if defined(__LITTLE_ENDIAN)
-# undef __LITTLE_ENDIAN
-# define __LITTLE_ENDIAN 1234
-# define __BIG_ENDIAN 4321
-# define __PDP_ENDIAN 3412
-# define __BYTE_ORDER __LITTLE_ENDIAN
-#elif defined(__BIG_ENDIAN)
-# undef __BIG_ENDIAN
-# define __LITTLE_ENDIAN 1234
-# define __BIG_ENDIAN 4321
-# define __PDP_ENDIAN 3412
-# define __BYTE_ORDER __BIG_ENDIAN
-#elif defined(__PDP_ENDIAN)
-# undef __PDP_ENDIAN
-# define __LITTLE_ENDIAN 1234
-# define __BIG_ENDIAN 4321
-# define __PDP_ENDIAN 3412
-# define __BYTE_ORDER __PDP_ENDIAN
-#else
-# error "Unknown byte order!"
-#endif
-
-#define LITTLE_ENDIAN __LITTLE_ENDIAN
-#define BIG_ENDIAN __BIG_ENDIAN
-#define PDP_ENDIAN __PDP_ENDIAN
-#define BYTE_ORDER __BYTE_ORDER
-
-#endif /* _ENDIAN_H */
diff --git a/klibc/klibc/include/errno.h b/klibc/klibc/include/errno.h
deleted file mode 100644
index b2e666504d..0000000000
--- a/klibc/klibc/include/errno.h
+++ /dev/null
@@ -1,8 +0,0 @@
-/*
- * errno.h
- */
-
-#include <klibc/extern.h>
-#include <asm/errno.h>
-
-__extern int errno;
diff --git a/klibc/klibc/include/fcntl.h b/klibc/klibc/include/fcntl.h
deleted file mode 100644
index e90959c7e9..0000000000
--- a/klibc/klibc/include/fcntl.h
+++ /dev/null
@@ -1,11 +0,0 @@
-/*
- * fcntl.h
- */
-
-#ifndef _FCNTL_H
-#define _FCNTL_H
-
-#include <sys/types.h>
-#include <linux/fcntl.h>
-
-#endif /* _FCNTL_H */
diff --git a/klibc/klibc/include/grp.h b/klibc/klibc/include/grp.h
deleted file mode 100644
index 03ceb31560..0000000000
--- a/klibc/klibc/include/grp.h
+++ /dev/null
@@ -1,13 +0,0 @@
-/*
- * grp.h
- */
-
-#ifndef _GRP_H
-#define _GRP_H
-
-#include <klibc/extern.h>
-#include <sys/types.h>
-
-__extern int setgroups(size_t, const gid_t *);
-
-#endif /* _GRP_H */
diff --git a/klibc/klibc/include/inttypes.h b/klibc/klibc/include/inttypes.h
deleted file mode 100644
index e00fa63160..0000000000
--- a/klibc/klibc/include/inttypes.h
+++ /dev/null
@@ -1,226 +0,0 @@
-/*
- * inttypes.h
- */
-
-#ifndef _INTTYPES_H
-#define _INTTYPES_H
-
-#include <klibc/extern.h>
-#include <stdint.h>
-#include <stddef.h>
-
-static __inline__ intmax_t imaxabs(intmax_t __n)
-{
- return (__n < (intmax_t)0) ? -__n : __n;
-}
-
-__extern intmax_t strtoimax(const char *, char **, int);
-__extern uintmax_t strtoumax(const char *, char **, int);
-
-/* extensions */
-__extern intmax_t strntoimax(const char *, char **, int, size_t);
-__extern uintmax_t strntoumax(const char *, char **, int, size_t);
-
-#if !defined(__cplusplus) || defined(__STDC_FORMAT_MACROS)
-
-#define PRId8 "d"
-#define PRId16 "d"
-#define PRId32 "d"
-#define PRId64 __PRI64_RANK "d"
-
-#define PRIdLEAST8 "d"
-#define PRIdLEAST16 "d"
-#define PRIdLEAST32 "d"
-#define PRIdLEAST64 __PRI64_RANK "d"
-
-#define PRIdFAST8 "d"
-#define PRIdFAST16 __PRIFAST_RANK "d"
-#define PRIdFAST32 __PRIFAST_RANK "d"
-#define PRIdFAST64 __PRI64_RANK "d"
-
-#define PRIdMAX __PRI64_RANK "d"
-#define PRIdPTR __PRIPTR_RANK "d"
-
-#define PRIi8 "i"
-#define PRIi16 "i"
-#define PRIi32 "i"
-#define PRIi64 __PRI64_RANK "i"
-
-#define PRIiLEAST8 "i"
-#define PRIiLEAST16 "i"
-#define PRIiLEAST32 "i"
-#define PRIiLEAST64 __PRI64_RANK "i"
-
-#define PRIiFAST8 "i"
-#define PRIiFAST16 __PRIFAST_RANK "i"
-#define PRIiFAST32 __PRIFAST_RANK "i"
-#define PRIiFAST64 __PRI64_RANK "i"
-
-#define PRIiMAX __PRI64_RANK "i"
-#define PRIiPTR __PRIPTR_RANK "i"
-
-#define PRIo8 "o"
-#define PRIo16 "o"
-#define PRIo32 "o"
-#define PRIo64 __PRI64_RANK "o"
-
-#define PRIoLEAST8 "o"
-#define PRIoLEAST16 "o"
-#define PRIoLEAST32 "o"
-#define PRIoLEAST64 __PRI64_RANK "o"
-
-#define PRIoFAST8 "o"
-#define PRIoFAST16 __PRIFAST_RANK "o"
-#define PRIoFAST32 __PRIFAST_RANK "o"
-#define PRIoFAST64 __PRI64_RANK "o"
-
-#define PRIoMAX __PRI64_RANK "o"
-#define PRIoPTR __PRIPTR_RANK "o"
-
-#define PRIu8 "u"
-#define PRIu16 "u"
-#define PRIu32 "u"
-#define PRIu64 __PRI64_RANK "u"
-
-#define PRIuLEAST8 "u"
-#define PRIuLEAST16 "u"
-#define PRIuLEAST32 "u"
-#define PRIuLEAST64 __PRI64_RANK "u"
-
-#define PRIuFAST8 "u"
-#define PRIuFAST16 __PRIFAST_RANK "u"
-#define PRIuFAST32 __PRIFAST_RANK "u"
-#define PRIuFAST64 __PRI64_RANK "u"
-
-#define PRIuMAX __PRI64_RANK "u"
-#define PRIuPTR __PRIPTR_RANK "u"
-
-#define PRIx8 "x"
-#define PRIx16 "x"
-#define PRIx32 "x"
-#define PRIx64 __PRI64_RANK "x"
-
-#define PRIxLEAST8 "x"
-#define PRIxLEAST16 "x"
-#define PRIxLEAST32 "x"
-#define PRIxLEAST64 __PRI64_RANK "x"
-
-#define PRIxFAST8 "x"
-#define PRIxFAST16 __PRIFAST_RANK "x"
-#define PRIxFAST32 __PRIFAST_RANK "x"
-#define PRIxFAST64 __PRI64_RANK "x"
-
-#define PRIxMAX __PRI64_RANK "x"
-#define PRIxPTR __PRIPTR_RANK "x"
-
-#define PRIX8 "X"
-#define PRIX16 "X"
-#define PRIX32 "X"
-#define PRIX64 __PRI64_RANK "X"
-
-#define PRIXLEAST8 "X"
-#define PRIXLEAST16 "X"
-#define PRIXLEAST32 "X"
-#define PRIXLEAST64 __PRI64_RANK "X"
-
-#define PRIXFAST8 "X"
-#define PRIXFAST16 __PRIFAST_RANK "X"
-#define PRIXFAST32 __PRIFAST_RANK "X"
-#define PRIXFAST64 __PRI64_RANK "X"
-
-#define PRIXMAX __PRI64_RANK "X"
-#define PRIXPTR __PRIPTR_RANK "X"
-
-#define SCNd8 "hhd"
-#define SCNd16 "hd"
-#define SCNd32 "d"
-#define SCNd64 __PRI64_RANK "d"
-
-#define SCNdLEAST8 "hhd"
-#define SCNdLEAST16 "hd"
-#define SCNdLEAST32 "d"
-#define SCNdLEAST64 __PRI64_RANK "d"
-
-#define SCNdFAST8 "hhd"
-#define SCNdFAST16 __PRIFAST_RANK "d"
-#define SCNdFAST32 __PRIFAST_RANK "d"
-#define SCNdFAST64 __PRI64_RANK "d"
-
-#define SCNdMAX __PRI64_RANK "d"
-#define SCNdPTR __PRIPTR_RANK "d"
-
-#define SCNi8 "hhi"
-#define SCNi16 "hi"
-#define SCNi32 "i"
-#define SCNi64 __PRI64_RANK "i"
-
-#define SCNiLEAST8 "hhi"
-#define SCNiLEAST16 "hi"
-#define SCNiLEAST32 "i"
-#define SCNiLEAST64 __PRI64_RANK "i"
-
-#define SCNiFAST8 "hhi"
-#define SCNiFAST16 __PRIFAST_RANK "i"
-#define SCNiFAST32 __PRIFAST_RANK "i"
-#define SCNiFAST64 __PRI64_RANK "i"
-
-#define SCNiMAX __PRI64_RANK "i"
-#define SCNiPTR __PRIPTR_RANK "i"
-
-#define SCNo8 "hho"
-#define SCNo16 "ho"
-#define SCNo32 "o"
-#define SCNo64 __PRI64_RANK "o"
-
-#define SCNoLEAST8 "hho"
-#define SCNoLEAST16 "ho"
-#define SCNoLEAST32 "o"
-#define SCNoLEAST64 __PRI64_RANK "o"
-
-#define SCNoFAST8 "hho"
-#define SCNoFAST16 __PRIFAST_RANK "o"
-#define SCNoFAST32 __PRIFAST_RANK "o"
-#define SCNoFAST64 __PRI64_RANK "o"
-
-#define SCNoMAX __PRI64_RANK "o"
-#define SCNoPTR __PRIPTR_RANK "o"
-
-#define SCNu8 "hhu"
-#define SCNu16 "hu"
-#define SCNu32 "u"
-#define SCNu64 __PRI64_RANK "u"
-
-#define SCNuLEAST8 "hhu"
-#define SCNuLEAST16 "hu"
-#define SCNuLEAST32 "u"
-#define SCNuLEAST64 __PRI64_RANK "u"
-
-#define SCNuFAST8 "hhu"
-#define SCNuFAST16 __PRIFAST_RANK "u"
-#define SCNuFAST32 __PRIFAST_RANK "u"
-#define SCNuFAST64 __PRI64_RANK "u"
-
-#define SCNuMAX __PRI64_RANK "u"
-#define SCNuPTR __PRIPTR_RANK "u"
-
-#define SCNx8 "hhx"
-#define SCNx16 "hx"
-#define SCNx32 "x"
-#define SCNx64 __PRI64_RANK "x"
-
-#define SCNxLEAST8 "hhx"
-#define SCNxLEAST16 "hx"
-#define SCNxLEAST32 "x"
-#define SCNxLEAST64 __PRI64_RANK "x"
-
-#define SCNxFAST8 "hhx"
-#define SCNxFAST16 __PRIFAST_RANK "x"
-#define SCNxFAST32 __PRIFAST_RANK "x"
-#define SCNxFAST64 __PRI64_RANK "x"
-
-#define SCNxMAX __PRI64_RANK "x"
-#define SCNxPTR __PRIPTR_RANK "x"
-
-#endif
-
-#endif /* _INTTYPES_H */
diff --git a/klibc/klibc/include/klibc/compiler.h b/klibc/klibc/include/klibc/compiler.h
deleted file mode 100644
index 6c01474cc1..0000000000
--- a/klibc/klibc/include/klibc/compiler.h
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * klibc/compiler.h
- *
- * Various compiler features
- */
-
-#ifndef _KLIBC_COMPILER_H
-#define _KLIBC_COMPILER_H
-
-/* Specific calling conventions */
-/* __cdecl is used when we want varadic and non-varadic functions to have
- the same binary calling convention. */
-#ifdef __i386__
-# ifdef __GNUC__
-# define __cdecl __attribute__((cdecl,regparm(0)))
-# else
- /* Most other C compilers have __cdecl as a keyword */
-# endif
-#else
-# define __cdecl /* Meaningless on non-i386 */
-#endif
-
-/* How to declare a function that *must* be inlined */
-#ifdef __GNUC__
-# if __GNUC_MAJOR__ >= 3
-# define __must_inline static __inline__ __attribute__((always_inline))
-# else
-# define __must_inline extern __inline__
-# endif
-#else
-# define __must_inline inline /* Just hope this works... */
-#endif
-
-/* How to declare a function that does not return */
-#ifdef __GNUC__
-# define __noreturn void __attribute__((noreturn))
-#else
-# define __noreturn void
-#endif
-
-/* How to declare a "constant" function (a function in the
- mathematical sense) */
-#ifdef __GNUC__
-# define __constfunc __attribute__((const))
-#else
-# define __constfunc
-#endif
-
-/* Format attribute */
-#ifdef __GNUC__
-# define __formatfunc(t,f,a) __attribute__((format(t,f,a)))
-#else
-# define __formatfunc(t,f,a)
-#endif
-
-/* likely/unlikely */
-#if defined(__GNUC__) && (__GNUC_MAJOR__ > 2 || (__GNUC_MAJOR__ == 2 && __GNUC_MINOR__ >= 95))
-# define __likely(x) __builtin_expect((x), 1)
-# define __unlikely(x) __builtin_expect((x), 0)
-#else
-# define __likely(x) (x)
-# define __unlikely(x) (x)
-#endif
-
-/* Possibly unused function */
-#ifdef __GNUC__
-# define __unusedfunc __attribute__((unused))
-#else
-# define __unusedfunc
-#endif
-
-/* "pure" function:
-
- Many functions have no effects except the return value and their
- return value depends only on the parameters and/or global
- variables. Such a function can be subject to common subexpression
- elimination and loop optimization just as an arithmetic operator
- would be. These functions should be declared with the attribute
- `pure'.
-*/
-#ifdef __GNUC__
-# define __attribute_pure__ __attribute__((pure))
-#else
-# define __attribute_pure__
-#endif
-
-/* "const" function:
-
- Many functions do not examine any values except their arguments,
- and have no effects except the return value. Basically this is
- just slightly more strict class than the `pure' attribute above,
- since function is not allowed to read global memory.
-
- Note that a function that has pointer arguments and examines the
- data pointed to must _not_ be declared `const'. Likewise, a
- function that calls a non-`const' function usually must not be
- `const'. It does not make sense for a `const' function to return
- `void'.
-*/
-#ifdef __GNUC__
-# define __attribute_const__ __attribute__((const))
-#else
-# define __attribute_const__
-#endif
-
-#endif
diff --git a/klibc/klibc/include/klibc/diverr.h b/klibc/klibc/include/klibc/diverr.h
deleted file mode 100644
index 4d8c8d36c2..0000000000
--- a/klibc/klibc/include/klibc/diverr.h
+++ /dev/null
@@ -1,16 +0,0 @@
-/*
- * klibc/diverr.h
- */
-
-#ifndef _KLIBC_DIVERR_H
-#define _KLIBC_DIVERR_H
-
-#include <signal.h>
-
-static __inline__ void
-__divide_error(void)
-{
- raise(SIGFPE);
-}
-
-#endif /* _KLIBC_DIVERR_H */
diff --git a/klibc/klibc/include/klibc/extern.h b/klibc/klibc/include/klibc/extern.h
deleted file mode 100644
index f9c3467211..0000000000
--- a/klibc/klibc/include/klibc/extern.h
+++ /dev/null
@@ -1,14 +0,0 @@
-/*
- * klibc/extern.h
- */
-
-#ifndef _KLIBC_EXTERN_H
-#define _KLIBC_EXTERN_H
-
-#ifdef __cplusplus
-#define __extern extern "C"
-#else
-#define __extern extern
-#endif
-
-#endif /* _KLIBC_EXTERN_H */
diff --git a/klibc/klibc/include/limits.h b/klibc/klibc/include/limits.h
deleted file mode 100644
index f1532e5323..0000000000
--- a/klibc/klibc/include/limits.h
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * limits.h
- */
-
-#ifndef _LIMITS_H
-#define _LIMITS_H
-
-#define CHAR_BIT 8
-#define SHRT_BIT 16
-#define INT_BIT 32
-#define LONGLONG_BIT 64
-
-#define SCHAR_MIN (-128)
-#define SCHAR_MAX 127
-#define UCHAR_MAX 255
-
-#ifdef __CHAR_UNSIGNED__
-# define CHAR_MIN 0
-# define CHAR_MAX UCHAR_MAX
-#else
-# define CHAR_MIN SCHAR_MIN
-# define CHAR_MAX SCHAR_MAX
-#endif
-
-#define SHRT_MIN (-32768)
-#define SHRT_MAX 32767
-#define USHRT_MAX 65535
-
-#define INT_MIN (-2147483647-1)
-#define INT_MAX 2147483647
-#define UINT_MAX 4294967295U
-
-#define LONGLONG_MIN (-9223372036854775807LL-1)
-#define LONGLONG_MAX 9223372036854775807LL
-#define ULONGLONG_MAX 18446744073709551615ULL
-
-#include <bitsize/limits.h>
-#include <linux/limits.h>
-
-#endif /* _LIMITS_H */
diff --git a/klibc/klibc/include/net/if.h b/klibc/klibc/include/net/if.h
deleted file mode 100644
index 1aa8e7b90c..0000000000
--- a/klibc/klibc/include/net/if.h
+++ /dev/null
@@ -1 +0,0 @@
-#include <linux/if.h>
diff --git a/klibc/klibc/include/net/if_arp.h b/klibc/klibc/include/net/if_arp.h
deleted file mode 100644
index a25f1b4759..0000000000
--- a/klibc/klibc/include/net/if_arp.h
+++ /dev/null
@@ -1 +0,0 @@
-#include <linux/if_arp.h>
diff --git a/klibc/klibc/include/net/if_ether.h b/klibc/klibc/include/net/if_ether.h
deleted file mode 100644
index 060ef22070..0000000000
--- a/klibc/klibc/include/net/if_ether.h
+++ /dev/null
@@ -1 +0,0 @@
-#include <linux/if_ether.h>
diff --git a/klibc/klibc/include/net/if_packet.h b/klibc/klibc/include/net/if_packet.h
deleted file mode 100644
index b5e8e0e11f..0000000000
--- a/klibc/klibc/include/net/if_packet.h
+++ /dev/null
@@ -1 +0,0 @@
-#include <linux/if_packet.h>
diff --git a/klibc/klibc/include/netinet/in.h b/klibc/klibc/include/netinet/in.h
deleted file mode 100644
index 92dc843bb1..0000000000
--- a/klibc/klibc/include/netinet/in.h
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * netinet/in.h
- */
-
-#ifndef _NETINET_IN_H
-#define _NETINET_IN_H
-
-/* added this include by Mats Petersson */
-#include <linux/socket.h>
-
-#include <klibc/extern.h>
-#include <stdint.h>
-#include <endian.h> /* Must be included *before* <linux/in.h> */
-#include <linux/in.h>
-
-#ifndef htons
-# define htons(x) __cpu_to_be16(x)
-#endif
-#ifndef ntohs
-# define ntohs(x) __be16_to_cpu(x)
-#endif
-#ifndef htonl
-# define htonl(x) __cpu_to_be32(x)
-#endif
-#ifndef ntohl
-# define ntohl(x) __be32_to_cpu(x)
-#endif
-
-#define IPPORT_RESERVED 1024
-
-__extern int bindresvport (int sd, struct sockaddr_in *sin);
-
-#endif /* _NETINET_IN_H */
diff --git a/klibc/klibc/include/netinet/in6.h b/klibc/klibc/include/netinet/in6.h
deleted file mode 100644
index 46584ca627..0000000000
--- a/klibc/klibc/include/netinet/in6.h
+++ /dev/null
@@ -1,10 +0,0 @@
-/*
- * netinet/in6.h
- */
-
-#ifndef _NETINET_IN6_H
-#define _NETINET_IN6_H
-
-#include <linux/in6.h>
-
-#endif /* _NETINET_IN6_H */
diff --git a/klibc/klibc/include/netinet/ip.h b/klibc/klibc/include/netinet/ip.h
deleted file mode 100644
index 8aecbe66a3..0000000000
--- a/klibc/klibc/include/netinet/ip.h
+++ /dev/null
@@ -1,13 +0,0 @@
-/*
- * netinet/ip.h
- */
-
-#ifndef _NETINET_IP_H
-#define _NETINET_IP_H
-
-#include <endian.h>
-#include <linux/ip.h>
-
-#define IP_DF 0x4000 /* Flag: "Don't Fragment" */
-
-#endif /* _NETINET_IP_H */
diff --git a/klibc/klibc/include/netinet/tcp.h b/klibc/klibc/include/netinet/tcp.h
deleted file mode 100644
index bb5d307e98..0000000000
--- a/klibc/klibc/include/netinet/tcp.h
+++ /dev/null
@@ -1,11 +0,0 @@
-/*
- * netinet/tcp.h
- */
-
-#ifndef _NETINET_TCP_H
-#define _NETINET_TCP_H
-
-#include <endian.h> /* Include *before* linux/tcp.h */
-#include <linux/tcp.h>
-
-#endif /* _NETINET_TCP_H */
diff --git a/klibc/klibc/include/netinet/udp.h b/klibc/klibc/include/netinet/udp.h
deleted file mode 100644
index b809b4ee6e..0000000000
--- a/klibc/klibc/include/netinet/udp.h
+++ /dev/null
@@ -1,19 +0,0 @@
-/*
- * netinet/udp.h
- */
-
-#ifndef _NETINET_UDP_H
-#define _NETINET_UDP_H
-
-/*
- * We would include linux/udp.h, but it brings in too much other stuff
- */
-
-struct udphdr {
- __u16 source;
- __u16 dest;
- __u16 len;
- __u16 check;
-};
-
-#endif /* _NETINET_UDP_H */
diff --git a/klibc/klibc/include/poll.h b/klibc/klibc/include/poll.h
deleted file mode 100644
index 8710d92ebd..0000000000
--- a/klibc/klibc/include/poll.h
+++ /dev/null
@@ -1,16 +0,0 @@
-/*
- * poll.h
- */
-
-#ifndef _POLL_H
-#define _POLL_H
-
-#include <klibc/extern.h>
-#include <linux/poll.h>
-
-/* POSIX specifies "int" for the timeout, Linux seems to use long... */
-
-typedef unsigned int nfds_t;
-__extern int poll(struct pollfd *, nfds_t, long);
-
-#endif /* _POLL_H */
diff --git a/klibc/klibc/include/sched.h b/klibc/klibc/include/sched.h
deleted file mode 100644
index 5e6103965f..0000000000
--- a/klibc/klibc/include/sched.h
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * sched.h
- */
-
-#ifndef _SCHED_H
-#define _SCHED_H
-
-#include <klibc/extern.h>
-
-/* linux/sched.h is unusable; put the declarations we need here... */
-
-#define SCHED_NORMAL 0
-#define SCHED_FIFO 1
-#define SCHED_RR 2
-
-struct sched_param {
- int sched_priority;
-};
-
-__extern int sched_setschedule(pid_t, int, const struct sched_param *);
-__extern int sched_yield(void);
-
-#endif /* _SCHED_H */
diff --git a/klibc/klibc/include/setjmp.h b/klibc/klibc/include/setjmp.h
deleted file mode 100644
index b504eb6d08..0000000000
--- a/klibc/klibc/include/setjmp.h
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * setjmp.h
- */
-
-#ifndef _SETJMP_H
-#define _SETJMP_H
-
-#include <klibc/extern.h>
-#include <klibc/compiler.h>
-#include <stddef.h>
-#include <signal.h>
-
-#include <klibc/archsetjmp.h>
-
-__extern int setjmp(jmp_buf);
-__extern __noreturn longjmp(jmp_buf, int);
-
-/*
- Whose bright idea was it to add unrelated functionality to just about
- the only function in the standard C library (setjmp) which cannot be
- wrapped by an ordinary function wrapper? Anyway, the damage is done,
- and therefore, this wrapper *must* be inline. However, gcc will
- complain if this is an inline function for unknown reason, and
- therefore sigsetjmp() needs to be a macro.
-*/
-
-struct __sigjmp_buf {
- jmp_buf __jmpbuf;
- sigset_t __sigs;
-};
-
-typedef struct __sigjmp_buf sigjmp_buf[1];
-
-#define sigsetjmp(__env, __save) \
-({ \
- struct __sigjmp_buf *__e = (__env); \
- sigprocmask(0, NULL, &__e->__sigs); \
- setjmp(__e->__jmpbuf); \
-})
-
-__extern __noreturn siglongjmp(sigjmp_buf, int);
-
-#endif /* _SETJMP_H */
diff --git a/klibc/klibc/include/signal.h b/klibc/klibc/include/signal.h
deleted file mode 100644
index 513b4e5a04..0000000000
--- a/klibc/klibc/include/signal.h
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * signal.h
- */
-
-#ifndef _SIGNAL_H
-#define _SIGNAL_H
-
-#include <klibc/extern.h>
-#include <string.h> /* For memset() */
-#include <limits.h> /* For LONG_BIT */
-#include <sys/types.h>
-#include <asm/signal.h>
-
-#include <klibc/archsignal.h>
-
-/* glibc seems to use sig_atomic_t as "int" pretty much on all architectures.
- Do the same, but allow the architecture to override. */
-#ifdef _KLIBC_HAS_ARCH_SIG_ATOMIC_T
-typedef int sig_atomic_t;
-#endif
-
-/* Some architectures don't define these */
-#ifndef SA_RESETHAND
-# define SA_RESETHAND SA_ONESHOT
-#endif
-#ifndef SA_NODEFER
-# define SA_NODEFER SA_NOMASK
-#endif
-#ifndef NSIG
-# define NSIG _NSIG
-#endif
-
-__extern const char * const sys_siglist[];
-
-/* This assumes sigset_t is either an unsigned long or an array of such,
- and that _NSIG_BPW in the kernel is always LONG_BIT */
-
-static __inline__ int sigemptyset(sigset_t *__set)
-{
- memset(__set, 0, sizeof *__set);
- return 0;
-}
-static __inline__ int sigfillset(sigset_t *__set)
-{
- memset(__set, ~0, sizeof *__set);
- return 0;
-}
-static __inline__ int sigaddset(sigset_t *__set, int __signum)
-{
- unsigned long *__lset = (unsigned long *)__set;
- __lset[__signum/LONG_BIT] |= 1UL << (__signum%LONG_BIT);
- return 0;
-}
-static __inline__ int sigdelset(sigset_t *__set, int __signum)
-{
- unsigned long *__lset = (unsigned long *)__set;
- __lset[__signum/LONG_BIT] &= ~(1UL << (__signum%LONG_BIT));
- return 0;
-}
-static __inline__ int sigismember(sigset_t *__set, int __signum)
-{
- unsigned long *__lset = (unsigned long *)__set;
- return (int)((__lset[__signum/LONG_BIT] >> (__signum%LONG_BIT)) & 1);
-}
-
-__extern __sighandler_t __signal(int, __sighandler_t, int);
-__extern __sighandler_t sysv_signal(int, __sighandler_t);
-__extern __sighandler_t bsd_signal(int, __sighandler_t);
-__extern int sigaction(int, const struct sigaction *, struct sigaction *);
-__extern int sigprocmask(int, const sigset_t *, sigset_t *);
-__extern int sigpending(sigset_t *);
-__extern int sigsuspend(const sigset_t *);
-__extern int rt_sigaction(int, const struct sigaction *, struct sigaction *, size_t);
-__extern int rt_sigprocmask(int, const sigset_t *, sigset_t *, size_t);
-__extern int rt_sigpending(sigset_t *, size_t);
-__extern int rt_sigsuspend(const sigset_t *, size_t);
-__extern int raise(int);
-__extern int kill(pid_t, int);
-
-#endif /* _SIGNAL_H */
diff --git a/klibc/klibc/include/stdarg.h b/klibc/klibc/include/stdarg.h
deleted file mode 100644
index cc324b825d..0000000000
--- a/klibc/klibc/include/stdarg.h
+++ /dev/null
@@ -1,14 +0,0 @@
-/*
- * stdarg.h
- *
- * This is just a wrapper for the gcc one, but defines va_copy()
- * even if gcc doesn't.
- */
-
-/* Note: the _STDARG_H macro belongs to the gcc header... */
-#include_next <stdarg.h>
-
-/* Older gcc considers this an extension, so it's double underbar only */
-#ifndef va_copy
-#define va_copy(d,s) __va_copy(d,s)
-#endif
diff --git a/klibc/klibc/include/stddef.h b/klibc/klibc/include/stddef.h
deleted file mode 100644
index 125d2352ec..0000000000
--- a/klibc/klibc/include/stddef.h
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * stddef.h
- */
-
-#ifndef _STDDEF_H
-#define _STDDEF_H
-
-#ifndef __KLIBC__
-# define __KLIBC__ 1
-#endif
-
-#include <bitsize/stddef.h>
-
-#undef NULL
-#ifdef __cplusplus
-# define NULL 0
-#else
-# define NULL ((void *)0)
-#endif
-
-#undef offsetof
-#define offsetof(t,m) ((size_t)&((t *)0)->m)
-
-#endif /* _STDDEF_H */
diff --git a/klibc/klibc/include/stdint.h b/klibc/klibc/include/stdint.h
deleted file mode 100644
index 47fec18594..0000000000
--- a/klibc/klibc/include/stdint.h
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
- * stdint.h
- */
-
-#ifndef _STDINT_H
-#define _STDINT_H
-
-#include <bitsize/stdint.h>
-
-typedef int8_t int_least8_t;
-typedef int16_t int_least16_t;
-typedef int32_t int_least32_t;
-typedef int64_t int_least64_t;
-
-typedef uint8_t uint_least8_t;
-typedef uint16_t uint_least16_t;
-typedef uint32_t uint_least32_t;
-typedef uint64_t uint_least64_t;
-
-typedef int8_t int_fast8_t;
-typedef int64_t int_fast64_t;
-
-typedef uint8_t uint_fast8_t;
-typedef uint64_t uint_fast64_t;
-
-typedef int64_t intmax_t;
-typedef uint64_t uintmax_t;
-
-#if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS)
-
-#define INT8_MIN (-128)
-#define INT16_MIN (-32768)
-#define INT32_MIN (-2147483647-1)
-#define INT64_MIN (__INT64_C(-9223372036854775807)-1)
-
-#define INT8_MAX (127)
-#define INT16_MAX (32767)
-#define INT32_MAX (2147483647)
-#define INT64_MAX (__INT64_C(9223372036854775807))
-
-#define UINT8_MAX (255U)
-#define UINT16_MAX (65535U)
-#define UINT32_MAX (4294967295U)
-#define UINT64_MAX (__UINT64_C(18446744073709551615))
-
-#define INT_LEAST8_MIN INT8_MIN
-#define INT_LEAST16_MIN INT16_MIN
-#define INT_LEAST32_MIN INT32_MIN
-#define INT_LEAST64_MIN INT64_MIN
-
-#define INT_LEAST8_MAX INT8_MAX
-#define INT_LEAST16_MAX INT16_MAX
-#define INT_LEAST32_MAX INT32_MAX
-#define INT_LEAST64_MAX INT64_MAX
-
-#define UINT_LEAST8_MAX UINT8_MAX
-#define UINT_LEAST16_MAX UINT16_MAX
-#define UINT_LEAST32_MAX UINT32_MAX
-#define UINT_LEAST64_MAX UINT64_MAX
-
-#define INT_FAST8_MIN INT8_MIN
-#define INT_FAST64_MIN INT64_MIN
-
-#define INT_FAST8_MAX INT8_MAX
-#define INT_FAST64_MAX INT64_MAX
-
-#define UINT_FAST8_MAX UINT8_MAX
-#define UINT_FAST64_MAX UINT64_MAX
-
-#define INTMAX_MIN INT64_MIN
-#define INTMAX_MAX INT64_MAX
-#define UINTMAX_MAX UINT64_MAX
-
-#include <bitsize/stdintlimits.h>
-
-#endif
-
-#if !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS)
-
-#define INT8_C(c) c
-#define INT16_C(c) c
-#define INT32_C(c) c
-#define INT64_C(c) __INT64_C(c)
-
-#define UINT8_C(c) c ## U
-#define UINT16_C(c) c ## U
-#define UINT32_C(c) c ## U
-#define UINT64_C(c) __UINT64_C(c)
-
-#define INT_LEAST8_C(c) INT8_C(c)
-#define INT_LEAST16_C(c) INT16_C(c)
-#define INT_LEAST32_C(c) INT32_C(c)
-#define INT_LEAST64_C(c) INT64_C(c)
-
-#define UINT_LEAST8_C(c) UINT8_C(c)
-#define UINT_LEAST16_C(c) UINT16_C(c)
-#define UINT_LEAST32_C(c) UINT32_C(c)
-#define UINT_LEAST64_C(c) UINT64_C(c)
-
-#define INT_FAST8_C(c) INT8_C(c)
-#define INT_FAST64_C(c) INT64_C(c)
-
-#define UINT_FAST8_C(c) UINT8_C(c)
-#define UINT_FAST64_C(c) UINT64_C(c)
-
-#define INTMAX_C(c) INT64_C(c)
-#define UINTMAX_C(c) UINT64_C(c)
-
-#include <bitsize/stdintconst.h>
-
-#endif
-
-/* Keep the kernel from trying to define these types... */
-#define __BIT_TYPES_DEFINED__
-
-#endif /* _STDINT_H */
diff --git a/klibc/klibc/include/stdio.h b/klibc/klibc/include/stdio.h
deleted file mode 100644
index fba1e30746..0000000000
--- a/klibc/klibc/include/stdio.h
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- * stdio.h
- */
-
-#ifndef _STDIO_H
-#define _STDIO_H
-
-#include <klibc/extern.h>
-#include <stdarg.h>
-#include <stddef.h>
-#include <unistd.h>
-
-/* This structure doesn't really exist, but it gives us something
- to define FILE * with */
-struct _IO_file;
-typedef struct _IO_file FILE;
-
-#ifndef EOF
-# define EOF (-1)
-#endif
-
-#ifndef BUFSIZ
-# define BUFSIZ 4096
-#endif
-
-#define SEEK_SET 0
-#define SEEK_CUR 1
-#define SEEK_END 2
-
-/*
- * Convert between a FILE * and a file descriptor. We don't actually
- * have any in-memory data, so we just abuse the pointer itself to
- * hold the data. Note, however, that for file descriptors, -1 is
- * error and 0 is a valid value; for FILE *, NULL (0) is error and
- * non-NULL are valid.
- */
-static __inline__ int fileno(FILE *__f)
-{
- /* This should really be intptr_t, but size_t should be the same size */
- return (int)(size_t)__f - 1;
-}
-
-/* This is a macro so it can be used as initializer */
-#define __create_file(__fd) ((FILE *)(size_t)((__fd) + 1))
-
-#define stdin __create_file(0)
-#define stdout __create_file(1)
-#define stderr __create_file(2)
-
-__extern FILE *fopen(const char *, const char *);
-
-static __inline__ FILE *fdopen(int __fd, const char *__m)
-{
- (void)__m; return __create_file(__fd);
-}
-static __inline__ int fclose(FILE *__f)
-{
- extern int close(int);
- return close(fileno(__f));
-}
-static __inline__ int fseek(FILE *__f, off_t __o, int __w)
-{
- extern off_t lseek(int, off_t, int);
- return (lseek(fileno(__f), __o, __w) == (off_t)-1) ? -1 : 0;
-}
-static __inline__ off_t ftell(FILE *__f)
-{
- extern off_t lseek(int, off_t, int);
- return lseek(fileno(__f), 0, SEEK_CUR);
-}
-
-__extern int fputs(const char *, FILE *);
-__extern int puts(const char *);
-__extern int fputc(int, FILE *);
-#define putc(c,f) fputc((c),(f))
-#define putchar(c) fputc((c),stdout)
-
-__extern int fgetc(FILE *);
-__extern char * fgets(char *, int, FILE *);
-#define getc(f) fgetc(f)
-
-__extern size_t _fread(void *, size_t, FILE *);
-__extern size_t _fwrite(const void *, size_t, FILE *);
-
-#ifndef __NO_FREAD_FWRITE_INLINES
-extern __inline__ size_t
-fread(void *__p, size_t __s, size_t __n, FILE *__f)
-{
- return _fread(__p, __s*__n, __f)/__s;
-}
-
-extern __inline__ size_t
-fwrite(void *__p, size_t __s, size_t __n, FILE *__f)
-{
- return _fwrite(__p, __s*__n, __f)/__s;
-}
-#endif
-
-__extern int printf(const char *, ...);
-__extern int vprintf(const char *, va_list);
-__extern int fprintf(FILE *, const char *, ...);
-__extern int vfprintf(FILE *, const char *, va_list);
-__extern int sprintf(char *, const char *, ...);
-__extern int vsprintf(char *, const char *, va_list);
-__extern int snprintf(char *, size_t n, const char *, ...);
-__extern int vsnprintf(char *, size_t n, const char *, va_list);
-
-__extern int sscanf(const char *, const char *, ...);
-__extern int vsscanf(const char *, const char *, va_list);
-
-__extern void perror(const char *);
-
-__extern int rename(const char *, const char *);
-
-#endif /* _STDIO_H */
diff --git a/klibc/klibc/include/stdlib.h b/klibc/klibc/include/stdlib.h
deleted file mode 100644
index af97eea636..0000000000
--- a/klibc/klibc/include/stdlib.h
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * stdlib.h
- */
-
-#ifndef _STDLIB_H
-#define _STDLIB_H
-
-#include <klibc/extern.h>
-#include <klibc/compiler.h>
-#include <stddef.h>
-
-#define EXIT_FAILURE 1
-#define EXIT_SUCCESS 0
-
-static __inline__ __noreturn _Exit(int __n) {
- __extern __noreturn _exit(int);
- _exit(__n);
- for(;;); /* Some gcc versions are stupid */
-}
-__extern __noreturn abort(void);
-static __inline__ int abs(int __n) {
- return (__n < 0) ? -__n : __n;
-}
-__extern int atexit(void (*)(void));
-__extern int on_exit(void (*)(int, void *), void *);
-__extern int atoi(const char *);
-__extern long atol(const char *);
-__extern long long atoll(const char *);
-__extern __noreturn exit(int);
-__extern void free(void *);
-static __inline__ long labs(long __n) {
- return (__n < 0L) ? -__n : __n;
-}
-
-static __inline__ long long llabs(long long __n) {
- return (__n < 0LL) ? -__n : __n;
-}
-
-#if defined(__GNUC__) && __GNUC_MAJOR__ >= 3
-# define __attribute_malloc __attribute__((malloc))
-#else
-# define __attribute_malloc
-#endif
-
-__extern __attribute_malloc void *malloc(size_t);
-__extern __attribute_malloc void *calloc(size_t, size_t);
-__extern void *realloc(void *, size_t);
-__extern long strtol(const char *, char **, int);
-__extern long long strtoll(const char *, char **, int);
-__extern unsigned long strtoul(const char *, char **, int);
-__extern unsigned long long strtoull(const char *, char **, int);
-
-__extern char *getenv(const char *);
-__extern int putenv(const char *);
-__extern int setenv(const char *, const char *, int);
-__extern int unsetenv(const char *);
-
-__extern void qsort(void *, size_t, size_t, int (*)(const void *, const void *));
-
-
-__extern long jrand48(unsigned short *);
-__extern long mrand48(void);
-__extern long nrand48(unsigned short *);
-__extern long lrand48(void);
-__extern unsigned short *seed48(const unsigned short *);
-__extern void srand48(long);
-
-#define RAND_MAX 0x7fffffff
-static __inline__ int rand(void) {
- return (int)lrand48();
-}
-static __inline__ void srand(unsigned int __s) {
- srand48(__s);
-}
-static __inline__ long random(void)
-{
- return lrand48();
-}
-static __inline__ void srandom(unsigned int __s)
-{
- srand48(__s);
-}
-
-/* Basic PTY functions. These only work if devpts is mounted! */
-
-__extern int unlockpt(int);
-__extern char *ptsname(int);
-__extern int getpt(void);
-
-static __inline__ int grantpt(int __fd)
-{
- (void)__fd;
- return 0; /* devpts does this all for us! */
-}
-
-#endif /* _STDLIB_H */
diff --git a/klibc/klibc/include/string.h b/klibc/klibc/include/string.h
deleted file mode 100644
index 1debb55af0..0000000000
--- a/klibc/klibc/include/string.h
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * string.h
- */
-
-#ifndef _STRING_H
-#define _STRING_H
-
-#include <klibc/extern.h>
-#include <stddef.h>
-
-__extern void *memccpy(void *, const void *, int, size_t);
-__extern void *memchr(const void *, int, size_t);
-__extern int memcmp(const void *, const void *, size_t);
-__extern void *memcpy(void *, const void *, size_t);
-__extern void *memmove(void *, const void *, size_t);
-__extern void *memset(void *, int, size_t);
-__extern void *memmem(const void *, size_t, const void *, size_t);
-__extern void memswap(void *, void *, size_t);
-__extern int strcasecmp(const char *, const char *);
-__extern int strncasecmp(const char *, const char *, size_t);
-__extern char *strcat(char *, const char *);
-__extern char *strchr(const char *, int);
-__extern int strcmp(const char *, const char *);
-__extern char *strcpy(char *, const char *);
-__extern size_t strcspn(const char *, const char *);
-__extern char *strdup(const char *);
-__extern char *strndup(const char *, size_t);
-__extern char *strerror(int);
-__extern size_t strlen(const char *);
-__extern char *strncat(char *, const char *, size_t);
-__extern int strncmp(const char *, const char *, size_t);
-__extern char *strncpy(char *, const char *, size_t);
-__extern char *strpbrk(const char *, const char *);
-__extern char *strrchr(const char *, int);
-__extern char *strsep(char **, const char *);
-__extern size_t strspn(const char *, const char *);
-__extern char *strstr(const char *, const char *);
-__extern char *strtok(char *, const char *);
-
-#endif /* _STRING_H */
diff --git a/klibc/klibc/include/sys/dirent.h b/klibc/klibc/include/sys/dirent.h
deleted file mode 100644
index 0700f4b561..0000000000
--- a/klibc/klibc/include/sys/dirent.h
+++ /dev/null
@@ -1,13 +0,0 @@
-/*
- * sys/dirent.h
- */
-
-#ifndef _SYS_DIRENT_H
-#define _SYS_DIRENT_H
-
-#include <sys/types.h>
-#include <linux/dirent.h>
-
-__extern int getdents(unsigned int, struct dirent *, unsigned int);
-
-#endif /* _SYS_DIRENT_H */
diff --git a/klibc/klibc/include/sys/elf32.h b/klibc/klibc/include/sys/elf32.h
deleted file mode 100644
index 652de5bc5f..0000000000
--- a/klibc/klibc/include/sys/elf32.h
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- * sys/elf32.h
- */
-
-#ifndef _SYS_ELF32_H
-#define _SYS_ELF32_H
-
-#include <sys/elfcommon.h>
-
-/* ELF standard typedefs (yet more proof that <stdint.h> was way overdue) */
-typedef uint16_t Elf32_Half;
-typedef int16_t Elf32_SHalf;
-typedef uint32_t Elf32_Word;
-typedef int32_t Elf32_Sword;
-typedef uint64_t Elf32_Xword;
-typedef int64_t Elf32_Sxword;
-
-typedef uint32_t Elf32_Off;
-typedef uint32_t Elf32_Addr;
-typedef uint16_t Elf32_Section;
-
-/* Dynamic header */
-
-typedef struct elf32_dyn {
- Elf32_Sword d_tag;
- union{
- Elf32_Sword d_val;
- Elf32_Addr d_ptr;
- } d_un;
-} Elf32_Dyn;
-
-/* Relocations */
-
-#define ELF32_R_SYM(x) ((x) >> 8)
-#define ELF32_R_TYPE(x) ((x) & 0xff)
-
-typedef struct elf32_rel {
- Elf32_Addr r_offset;
- Elf32_Word r_info;
-} Elf32_Rel;
-
-typedef struct elf32_rela {
- Elf32_Addr r_offset;
- Elf32_Word r_info;
- Elf32_Sword r_addend;
-} Elf32_Rela;
-
-/* Symbol */
-
-typedef struct elf32_sym {
- Elf32_Word st_name;
- Elf32_Addr st_value;
- Elf32_Word st_size;
- unsigned char st_info;
- unsigned char st_other;
- Elf32_Half st_shndx;
-} Elf32_Sym;
-
-/* Main file header */
-
-typedef struct elf32_hdr {
- unsigned char e_ident[EI_NIDENT];
- Elf32_Half e_type;
- Elf32_Half e_machine;
- Elf32_Word e_version;
- Elf32_Addr e_entry;
- Elf32_Off e_phoff;
- Elf32_Off e_shoff;
- Elf32_Word e_flags;
- Elf32_Half e_ehsize;
- Elf32_Half e_phentsize;
- Elf32_Half e_phnum;
- Elf32_Half e_shentsize;
- Elf32_Half e_shnum;
- Elf32_Half e_shstrndx;
-} Elf32_Ehdr;
-
-/* Program header */
-
-typedef struct elf32_phdr {
- Elf32_Word p_type;
- Elf32_Off p_offset;
- Elf32_Addr p_vaddr;
- Elf32_Addr p_paddr;
- Elf32_Word p_filesz;
- Elf32_Word p_memsz;
- Elf32_Word p_flags;
- Elf32_Word p_align;
-} Elf32_Phdr;
-
-
-/* Section header */
-
-typedef struct elf32_shdr {
- Elf32_Word sh_name;
- Elf32_Word sh_type;
- Elf32_Word sh_flags;
- Elf32_Addr sh_addr;
- Elf32_Off sh_offset;
- Elf32_Word sh_size;
- Elf32_Word sh_link;
- Elf32_Word sh_info;
- Elf32_Word sh_addralign;
- Elf32_Word sh_entsize;
-} Elf32_Shdr;
-
-/* Note header */
-typedef struct elf32_note {
- Elf32_Word n_namesz; /* Name size */
- Elf32_Word n_descsz; /* Content size */
- Elf32_Word n_type; /* Content type */
-} Elf32_Nhdr;
-
-#endif /* _SYS_ELF32_H */
-
diff --git a/klibc/klibc/include/sys/elf64.h b/klibc/klibc/include/sys/elf64.h
deleted file mode 100644
index 750ddac4d9..0000000000
--- a/klibc/klibc/include/sys/elf64.h
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- * sys/elf64.h
- */
-
-#ifndef _SYS_ELF64_H
-#define _SYS_ELF64_H
-
-#include <sys/elfcommon.h>
-
-/* ELF standard typedefs (yet more proof that <stdint.h> was way overdue) */
-typedef uint16_t Elf64_Half;
-typedef int16_t Elf64_SHalf;
-typedef uint32_t Elf64_Word;
-typedef int32_t Elf64_Sword;
-typedef uint64_t Elf64_Xword;
-typedef int64_t Elf64_Sxword;
-
-typedef uint64_t Elf64_Off;
-typedef uint64_t Elf64_Addr;
-typedef uint16_t Elf64_Section;
-
-/* Dynamic header */
-
-typedef struct elf64_dyn {
- Elf64_Sxword d_tag;
- union{
- Elf64_Xword d_val;
- Elf64_Addr d_ptr;
- } d_un;
-} Elf64_Dyn;
-
-/* Relocations */
-
-#define ELF64_R_SYM(x) ((x) >> 32)
-#define ELF64_R_TYPE(x) ((x) & 0xffffffff)
-
-typedef struct elf64_rel {
- Elf64_Addr r_offset;
- Elf64_Xword r_info;
-} Elf64_Rel;
-
-typedef struct elf64_rela {
- Elf64_Addr r_offset;
- Elf64_Xword r_info;
- Elf64_Sxword r_addend;
-} Elf64_Rela;
-
-/* Symbol */
-
-typedef struct elf64_sym {
- Elf64_Word st_name;
- unsigned char st_info;
- unsigned char st_other;
- Elf64_Half st_shndx;
- Elf64_Addr st_value;
- Elf64_Xword st_size;
-} Elf64_Sym;
-
-/* Main file header */
-
-typedef struct elf64_hdr {
- unsigned char e_ident[EI_NIDENT];
- Elf64_Half e_type;
- Elf64_Half e_machine;
- Elf64_Word e_version;
- Elf64_Addr e_entry;
- Elf64_Off e_phoff;
- Elf64_Off e_shoff;
- Elf64_Word e_flags;
- Elf64_Half e_ehsize;
- Elf64_Half e_phentsize;
- Elf64_Half e_phnum;
- Elf64_Half e_shentsize;
- Elf64_Half e_shnum;
- Elf64_Half e_shstrndx;
-} Elf64_Ehdr;
-
-/* Program header */
-
-typedef struct elf64_phdr {
- Elf64_Word p_type;
- Elf64_Word p_flags;
- Elf64_Off p_offset;
- Elf64_Addr p_vaddr;
- Elf64_Addr p_paddr;
- Elf64_Xword p_filesz;
- Elf64_Xword p_memsz;
- Elf64_Xword p_align;
-} Elf64_Phdr;
-
-
-/* Section header */
-
-typedef struct elf64_shdr {
- Elf64_Word sh_name;
- Elf64_Word sh_type;
- Elf64_Xword sh_flags;
- Elf64_Addr sh_addr;
- Elf64_Off sh_offset;
- Elf64_Xword sh_size;
- Elf64_Word sh_link;
- Elf64_Word sh_info;
- Elf64_Xword sh_addralign;
- Elf64_Xword sh_entsize;
-} Elf64_Shdr;
-
-/* Note header */
-typedef struct elf64_note {
- Elf64_Word n_namesz; /* Name size */
- Elf64_Word n_descsz; /* Content size */
- Elf64_Word n_type; /* Content type */
-} Elf64_Nhdr;
-
-#endif /* _SYS_ELF64_H */
-
diff --git a/klibc/klibc/include/sys/elfcommon.h b/klibc/klibc/include/sys/elfcommon.h
deleted file mode 100644
index f984f6a56b..0000000000
--- a/klibc/klibc/include/sys/elfcommon.h
+++ /dev/null
@@ -1,186 +0,0 @@
-/*
- * sys/elfcommon.h
- */
-
-#ifndef _SYS_ELFCOMMON_H
-#define _SYS_ELFCOMMON_H
-
-/* Segment types */
-#define PT_NULL 0
-#define PT_LOAD 1
-#define PT_DYNAMIC 2
-#define PT_INTERP 3
-#define PT_NOTE 4
-#define PT_SHLIB 5
-#define PT_PHDR 6
-#define PT_LOOS 0x60000000
-#define PT_HIOS 0x6fffffff
-#define PT_LOPROC 0x70000000
-#define PT_HIPROC 0x7fffffff
-#define PT_GNU_EH_FRAME 0x6474e550 /* Extension, eh? */
-
-/* ELF file types */
-#define ET_NONE 0
-#define ET_REL 1
-#define ET_EXEC 2
-#define ET_DYN 3
-#define ET_CORE 4
-#define ET_LOPROC 0xff00
-#define ET_HIPROC 0xffff
-
-/* ELF machine types */
-#define EM_NONE 0
-#define EM_M32 1
-#define EM_SPARC 2
-#define EM_386 3
-#define EM_68K 4
-#define EM_88K 5
-#define EM_486 6 /* Not used in Linux at least */
-#define EM_860 7
-#define EM_MIPS 8 /* R3k, bigendian(?) */
-#define EM_MIPS_RS4_BE 10 /* R4k BE */
-#define EM_PARISC 15
-#define EM_SPARC32PLUS 18
-#define EM_PPC 20
-#define EM_PPC64 21
-#define EM_S390 22
-#define EM_SH 42
-#define EM_SPARCV9 43 /* v9 = SPARC64 */
-#define EM_H8_300H 47
-#define EM_H8S 48
-#define EM_IA_64 50 /* Itanic */
-#define EM_X86_64 62
-#define EM_CRIS 76
-#define EM_V850 87
-#define EM_ALPHA 0x9026 /* Interrim Alpha that stuck around */
-#define EM_CYGNUS_V850 0x9080 /* Old v850 ID used by Cygnus */
-#define EM_S390_OLD 0xA390 /* Obsolete interrim value for S/390 */
-
-/* Dynamic type values */
-#define DT_NULL 0
-#define DT_NEEDED 1
-#define DT_PLTRELSZ 2
-#define DT_PLTGOT 3
-#define DT_HASH 4
-#define DT_STRTAB 5
-#define DT_SYMTAB 6
-#define DT_RELA 7
-#define DT_RELASZ 8
-#define DT_RELAENT 9
-#define DT_STRSZ 10
-#define DT_SYMENT 11
-#define DT_INIT 12
-#define DT_FINI 13
-#define DT_SONAME 14
-#define DT_RPATH 15
-#define DT_SYMBOLIC 16
-#define DT_REL 17
-#define DT_RELSZ 18
-#define DT_RELENT 19
-#define DT_PLTREL 20
-#define DT_DEBUG 21
-#define DT_TEXTREL 22
-#define DT_JMPREL 23
-#define DT_LOPROC 0x70000000
-#define DT_HIPROC 0x7fffffff
-
-/* Auxilliary table entries */
-#define AT_NULL 0 /* end of vector */
-#define AT_IGNORE 1 /* entry should be ignored */
-#define AT_EXECFD 2 /* file descriptor of program */
-#define AT_PHDR 3 /* program headers for program */
-#define AT_PHENT 4 /* size of program header entry */
-#define AT_PHNUM 5 /* number of program headers */
-#define AT_PAGESZ 6 /* system page size */
-#define AT_BASE 7 /* base address of interpreter */
-#define AT_FLAGS 8 /* flags */
-#define AT_ENTRY 9 /* entry point of program */
-#define AT_NOTELF 10 /* program is not ELF */
-#define AT_UID 11 /* real uid */
-#define AT_EUID 12 /* effective uid */
-#define AT_GID 13 /* real gid */
-#define AT_EGID 14 /* effective gid */
-#define AT_PLATFORM 15 /* string identifying CPU for optimizations */
-#define AT_HWCAP 16 /* arch dependent hints at CPU capabilities */
-#define AT_CLKTCK 17 /* frequency at which times() increments */
-/* 18..22 = ? */
-#define AT_SECURE 23 /* secure mode boolean */
-
-/* Program header permission flags */
-#define PF_X 0x1
-#define PF_W 0x2
-#define PF_R 0x4
-
-/* Section header types */
-#define SHT_NULL 0
-#define SHT_PROGBITS 1
-#define SHT_SYMTAB 2
-#define SHT_STRTAB 3
-#define SHT_RELA 4
-#define SHT_HASH 5
-#define SHT_DYNAMIC 6
-#define SHT_NOTE 7
-#define SHT_NOBITS 8
-#define SHT_REL 9
-#define SHT_SHLIB 10
-#define SHT_DYNSYM 11
-#define SHT_NUM 12
-#define SHT_LOPROC 0x70000000
-#define SHT_HIPROC 0x7fffffff
-#define SHT_LOUSER 0x80000000
-#define SHT_HIUSER 0xffffffff
-
-/* Section header flags */
-#define SHF_WRITE 0x1
-#define SHF_ALLOC 0x2
-#define SHF_EXECINSTR 0x4
-#define SHF_MASKPROC 0xf0000000
-
-/* Special section numbers */
-#define SHN_UNDEF 0
-#define SHN_LORESERVE 0xff00
-#define SHN_LOPROC 0xff00
-#define SHN_HIPROC 0xff1f
-#define SHN_ABS 0xfff1
-#define SHN_COMMON 0xfff2
-#define SHN_HIRESERVE 0xffff
-
-/* Lenght of magic at the start of a file */
-#define EI_NIDENT 16
-
-/* Magic number constants... */
-#define EI_MAG0 0 /* e_ident[] indexes */
-#define EI_MAG1 1
-#define EI_MAG2 2
-#define EI_MAG3 3
-#define EI_CLASS 4
-#define EI_DATA 5
-#define EI_VERSION 6
-#define EI_OSABI 7
-#define EI_PAD 8
-
-#define ELFMAG0 0x7f /* EI_MAG */
-#define ELFMAG1 'E'
-#define ELFMAG2 'L'
-#define ELFMAG3 'F'
-#define ELFMAG "\177ELF"
-#define SELFMAG 4
-
-#define ELFCLASSNONE 0 /* EI_CLASS */
-#define ELFCLASS32 1
-#define ELFCLASS64 2
-#define ELFCLASSNUM 3
-
-#define ELFDATANONE 0 /* e_ident[EI_DATA] */
-#define ELFDATA2LSB 1
-#define ELFDATA2MSB 2
-
-#define EV_NONE 0 /* e_version, EI_VERSION */
-#define EV_CURRENT 1
-#define EV_NUM 2
-
-#define ELFOSABI_NONE 0
-#define ELFOSABI_LINUX 3
-
-#endif /* _SYS_ELFCOMMON_H */
-
diff --git a/klibc/klibc/include/sys/fsuid.h b/klibc/klibc/include/sys/fsuid.h
deleted file mode 100644
index 823486b776..0000000000
--- a/klibc/klibc/include/sys/fsuid.h
+++ /dev/null
@@ -1,14 +0,0 @@
-/*
- * sys/fsuid.h
- */
-
-#ifndef _SYS_FSUID_H
-#define _SYS_FSUID_H
-
-#include <klibc/extern.h>
-#include <sys/types.h>
-
-__extern int setfsuid(uid_t);
-__extern int setfsgid(gid_t);
-
-#endif /* _SYS_FSUID_H */
diff --git a/klibc/klibc/include/sys/ioctl.h b/klibc/klibc/include/sys/ioctl.h
deleted file mode 100644
index b0cee4c02c..0000000000
--- a/klibc/klibc/include/sys/ioctl.h
+++ /dev/null
@@ -1,14 +0,0 @@
-/*
- * sys/ioctl.h
- */
-
-#ifndef _SYS_IOCTL_H
-#define _SYS_IOCTL_H
-
-#include <klibc/extern.h>
-#include <linux/ioctl.h>
-#include <asm/ioctls.h>
-
-__extern int ioctl(int, int, void *);
-
-#endif /* _SYS_IOCTL_H */
diff --git a/klibc/klibc/include/sys/klog.h b/klibc/klibc/include/sys/klog.h
deleted file mode 100644
index 0fc5f5d945..0000000000
--- a/klibc/klibc/include/sys/klog.h
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * sys/klog.h
- */
-
-#ifndef _SYS_KLOG_H
-#define _SYS_KLOG_H
-
-#include <klibc/extern.h>
-
-#define KLOG_CLOSE 0
-#define KLOG_OPEN 1
-#define KLOG_READ 2
-#define KLOG_READ_ALL 3
-#define KLOG_READ_CLEAR 4
-#define KLOG_CLEAR 5
-#define KLOG_DISABLE 6
-#define KLOG_ENABLE 7
-#define KLOG_SETLEVEL 8
-#define KLOG_UNREADSIZE 9
-#define KLOG_WRITE 10
-
-__extern int klogctl(int, char *, int);
-
-#endif /* _SYS_KLOG_H */
diff --git a/klibc/klibc/include/sys/mman.h b/klibc/klibc/include/sys/mman.h
deleted file mode 100644
index 3d8a2f63c2..0000000000
--- a/klibc/klibc/include/sys/mman.h
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * sys/mman.h
- */
-
-#ifndef _SYS_MMAN_H
-#define _SYS_MMAN_H
-
-#include <klibc/extern.h>
-#include <sys/types.h>
-#include <asm/mman.h>
-#include <asm/page.h> /* For PAGE_SIZE */
-
-#define MAP_FAILED ((void *)-1)
-
-__extern void *mmap(void *, size_t, int, int, int, off_t);
-__extern int munmap(void *, size_t);
-__extern void *mremap(void *, size_t, size_t, unsigned long);
-__extern int msync(const void *, size_t, int);
-__extern int mprotect(const void *, size_t, int);
-
-#endif /* _SYS_MMAN_H */
diff --git a/klibc/klibc/include/sys/mount.h b/klibc/klibc/include/sys/mount.h
deleted file mode 100644
index 313c90ec0e..0000000000
--- a/klibc/klibc/include/sys/mount.h
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * sys/mount.h
- */
-
-#ifndef _SYS_MOUNT_H
-#define _SYS_MOUNT_H
-
-#include <klibc/extern.h>
-
-/*
- * These are the fs-independent mount-flags: up to 32 flags are supported
- */
-#define MS_RDONLY 1 /* Mount read-only */
-#define MS_NOSUID 2 /* Ignore suid and sgid bits */
-#define MS_NODEV 4 /* Disallow access to device special files */
-#define MS_NOEXEC 8 /* Disallow program execution */
-#define MS_SYNCHRONOUS 16 /* Writes are synced at once */
-#define MS_REMOUNT 32 /* Alter flags of a mounted FS */
-#define MS_MANDLOCK 64 /* Allow mandatory locks on an FS */
-#define MS_DIRSYNC 128 /* Directory modifications are synchronous */
-#define MS_NOATIME 1024 /* Do not update access times. */
-#define MS_NODIRATIME 2048 /* Do not update directory access times */
-#define MS_BIND 4096
-#define MS_MOVE 8192
-#define MS_REC 16384
-#define MS_VERBOSE 32768
-#define MS_NOUSER (1<<31)
-
-/*
- * Superblock flags that can be altered by MS_REMOUNT
- */
-#define MS_RMT_MASK (MS_RDONLY|MS_SYNCHRONOUS|MS_MANDLOCK|MS_NOATIME|MS_NODIRATIME)
-
-/*
- * Old magic mount flag and mask
- */
-#define MS_MGC_VAL 0xC0ED0000
-#define MS_MGC_MSK 0xffff0000
-
-/*
- * umount2() flags
- */
-#define MNT_FORCE 1
-
-/*
- * Prototypes
- */
-__extern int mount(const char *, const char *,
- const char *, unsigned long,
- const void *);
-__extern int umount(const char *);
-__extern int umount2(const char *, int);
-__extern int pivot_root(const char *, const char *);
-
-#endif /* _SYS_MOUNT_H */
diff --git a/klibc/klibc/include/sys/param.h b/klibc/klibc/include/sys/param.h
deleted file mode 100644
index 63a0661f43..0000000000
--- a/klibc/klibc/include/sys/param.h
+++ /dev/null
@@ -1,11 +0,0 @@
-/*
- * sys/param.h
- */
-
-#ifndef _SYS_PARAM_H
-#define _SYS_PARAM_H
-
-#include <limits.h>
-#include <linux/param.h>
-
-#endif /* _SYS_PARAM_H */
diff --git a/klibc/klibc/include/sys/reboot.h b/klibc/klibc/include/sys/reboot.h
deleted file mode 100644
index eaf56610d7..0000000000
--- a/klibc/klibc/include/sys/reboot.h
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * sys/reboot.h
- */
-
-#ifndef _SYS_REBOOT_H
-#define _SYS_REBOOT_H
-
-#include <klibc/extern.h>
-#include <linux/reboot.h>
-
-/* glibc names these constants differently; allow both versions */
-
-#define RB_AUTOBOOT LINUX_REBOOT_CMD_RESTART
-#define RB_HALT_SYSTEM LINUX_REBOOT_CMD_HALT
-#define RB_ENABLE_CAD LINUX_REBOOT_CMD_CAD_ON
-#define RB_DISABLE_CAD LINUX_REBOOT_CMD_CAD_OFF
-#define RB_POWER_OFF LINUX_REBOOT_CMD_POWER_OFF
-
-/* glibc-ish one-argument version */
-__extern int reboot(int);
-
-/* Native four-argument system call */
-__extern int __reboot(int, int, int, void *);
-
-#endif /* _SYS_REBOOT_H */
diff --git a/klibc/klibc/include/sys/resource.h b/klibc/klibc/include/sys/resource.h
deleted file mode 100644
index ef14bde9f6..0000000000
--- a/klibc/klibc/include/sys/resource.h
+++ /dev/null
@@ -1,15 +0,0 @@
-/*
- * sys/resource.h
- */
-
-#ifndef _SYS_RESOURCE_H
-#define _SYS_RESOURCE_H
-
-#include <klibc/extern.h>
-#include <sys/types.h> /* MUST be included before linux/resource.h */
-#include <linux/resource.h>
-
-__extern int getpriority(int, int);
-__extern int setpriority(int, int, int);
-
-#endif /* _SYS_RESOURCE_H */
diff --git a/klibc/klibc/include/sys/select.h b/klibc/klibc/include/sys/select.h
deleted file mode 100644
index 7caf8c931b..0000000000
--- a/klibc/klibc/include/sys/select.h
+++ /dev/null
@@ -1,13 +0,0 @@
-/*
- * sys/select.h
- */
-
-#ifndef _SYS_SELECT_H
-#define _SYS_SELECT_H
-
-#include <sys/time.h>
-#include <sys/types.h>
-
-__extern int select(int, fd_set *, fd_set *, fd_set *, struct timeval *);
-
-#endif /* _SYS_SELECT_H */
diff --git a/klibc/klibc/include/sys/socket.h b/klibc/klibc/include/sys/socket.h
deleted file mode 100644
index cbc2b89591..0000000000
--- a/klibc/klibc/include/sys/socket.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * sys/socket.h
- */
-
-#ifndef _SYS_SOCKET_H
-#define _SYS_SOCKET_H
-
-#include <klibc/extern.h>
-#include <klibc/compiler.h>
-#include <linux/socket.h>
-
-/* For some reason these may be protected by __KERNEL__ in asm/socket.h */
-#ifndef SOCK_STREAM
-# define SOCK_STREAM 1
-# define SOCK_DGRAM 2
-# define SOCK_RAW 3
-# define SOCK_RDM 4
-# define SOCK_SEQPACKET 5
-# define SOCK_PACKET 10
-#endif
-
-#ifdef __i386__
-# define __socketcall __extern __cdecl
-#else
-# define __socketcall __extern
-#endif
-
-typedef int socklen_t;
-
-__socketcall int socket(int, int, int);
-__socketcall int bind(int, struct sockaddr *, int);
-__socketcall int connect(int, struct sockaddr *, socklen_t);
-__socketcall int listen(int, int);
-__socketcall int accept(int, struct sockaddr *, socklen_t *);
-__socketcall int getsockname(int, struct sockaddr *, socklen_t *);
-__socketcall int getpeername(int, struct sockaddr *, socklen_t *);
-__socketcall int socketpair(int, int, int, int *);
-__extern int send(int, const void *, size_t, unsigned int);
-__socketcall int sendto(int, const void *, size_t, int, const struct sockaddr *, socklen_t);
-__extern int recv(int, void *, size_t, unsigned int);
-__socketcall int recvfrom(int, void *, size_t, unsigned int, struct sockaddr *, socklen_t *);
-__socketcall int shutdown(int, int);
-__socketcall int setsockopt(int, int, int, const void *, socklen_t);
-__socketcall int getsockopt(int, int, int, void *, socklen_t *);
-__socketcall int sendmsg(int, const struct msghdr *, unsigned int);
-__socketcall int recvmsg(int, struct msghdr *, unsigned int);
-
-#undef __socketcall
-
-#endif /* _SYS_SOCKET_H */
diff --git a/klibc/klibc/include/sys/socketcalls.h b/klibc/klibc/include/sys/socketcalls.h
deleted file mode 100644
index dac9f9aab6..0000000000
--- a/klibc/klibc/include/sys/socketcalls.h
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * sys/socketcalls.h
- */
-
-#ifndef _SYS_SOCKETCALLS_H
-#define _SYS_SOCKETCALLS_H
-
-/* socketcalls by number, since <linux/net.h> isn't usable for assembly */
-
-#define SYS_SOCKET 1 /* sys_socket(2) */
-#define SYS_BIND 2 /* sys_bind(2) */
-#define SYS_CONNECT 3 /* sys_connect(2) */
-#define SYS_LISTEN 4 /* sys_listen(2) */
-#define SYS_ACCEPT 5 /* sys_accept(2) */
-#define SYS_GETSOCKNAME 6 /* sys_getsockname(2) */
-#define SYS_GETPEERNAME 7 /* sys_getpeername(2) */
-#define SYS_SOCKETPAIR 8 /* sys_socketpair(2) */
-#define SYS_SEND 9 /* sys_send(2) */
-#define SYS_RECV 10 /* sys_recv(2) */
-#define SYS_SENDTO 11 /* sys_sendto(2) */
-#define SYS_RECVFROM 12 /* sys_recvfrom(2) */
-#define SYS_SHUTDOWN 13 /* sys_shutdown(2) */
-#define SYS_SETSOCKOPT 14 /* sys_setsockopt(2) */
-#define SYS_GETSOCKOPT 15 /* sys_getsockopt(2) */
-#define SYS_SENDMSG 16 /* sys_sendmsg(2) */
-#define SYS_RECVMSG 17 /* sys_recvmsg(2) */
-
-#endif /* _SYS_SOCKETCALLS_H */
diff --git a/klibc/klibc/include/sys/stat.h b/klibc/klibc/include/sys/stat.h
deleted file mode 100644
index f7bb5aacc5..0000000000
--- a/klibc/klibc/include/sys/stat.h
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * sys/stat.h
- */
-
-#ifndef _SYS_STAT_H
-#define _SYS_STAT_H
-
-#include <klibc/extern.h>
-#include <sys/types.h>
-#include <asm/stat.h>
-#include <linux/stat.h>
-
-__extern int stat(const char *, struct stat *);
-__extern int fstat(int, struct stat *);
-__extern int lstat(const char *, struct stat *);
-__extern mode_t umask(mode_t);
-__extern int mknod(const char *, mode_t, dev_t);
-static __inline__ int mkfifo(const char *__p, mode_t __m)
-{
- return mknod(__p, (__m & ~S_IFMT) | S_IFIFO, (dev_t)0);
-}
-
-#endif /* _SYS_STAT_H */
diff --git a/klibc/klibc/include/sys/syscall.h b/klibc/klibc/include/sys/syscall.h
deleted file mode 100644
index 907c7f9b9a..0000000000
--- a/klibc/klibc/include/sys/syscall.h
+++ /dev/null
@@ -1,15 +0,0 @@
-/*
- * sys/syscall.h
- *
- * Generic system call interface macros
- */
-#ifndef _SYS_SYSCALL_H
-#define _SYS_SYSCALL_H
-
-#include <errno.h>
-#include <asm/unistd.h>
-
-/* Many architectures have incomplete or defective syscall macros */
-#include <klibc/archsys.h>
-
-#endif /* _SYS_SYSCALL_H */
diff --git a/klibc/klibc/include/sys/sysinfo.h b/klibc/klibc/include/sys/sysinfo.h
deleted file mode 100644
index 4051c6897a..0000000000
--- a/klibc/klibc/include/sys/sysinfo.h
+++ /dev/null
@@ -1,12 +0,0 @@
-/*
- * sys/sysinfo.h
- */
-
-#ifndef _SYS_SYSINFO_H
-#define _SYS_SYSINFO_H
-
-#include <linux/kernel.h>
-
-extern int sysinfo (struct sysinfo *info);
-
-#endif /* _SYS_SYSINFO_H */
diff --git a/klibc/klibc/include/sys/sysmacros.h b/klibc/klibc/include/sys/sysmacros.h
deleted file mode 100644
index 7f1e0822b3..0000000000
--- a/klibc/klibc/include/sys/sysmacros.h
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * sys/sysmacros.h
- *
- * Constructs to create and pick apart dev_t. This applies to the Linux 2.6
- * 32-bit dev_t format.
- */
-
-#ifndef _SYS_SYSMACROS_H
-#define _SYS_SYSMACROS_H
-
-#ifndef _SYS_TYPES_H
-# include <sys/types.h>
-#endif
-
-static __inline__ int major(dev_t __d)
-{
- return (__d >> 8) & 0xfff;
-}
-
-static __inline__ int minor(dev_t __d)
-{
- return (__d & 0xff) | ((__d >> 12) & 0xfff00);
-}
-
-static __inline__ dev_t makedev(int __ma, int __mi)
-{
- return ((__ma & 0xfff) << 8) | (__mi & 0xff) | ((__mi & 0xfff00) << 12);
-}
-
-#endif /* _SYS_SYSMACROS_H */
-
diff --git a/klibc/klibc/include/sys/time.h b/klibc/klibc/include/sys/time.h
deleted file mode 100644
index b503d21076..0000000000
--- a/klibc/klibc/include/sys/time.h
+++ /dev/null
@@ -1,17 +0,0 @@
-/*
- * sys/time.h
- */
-
-#ifndef _SYS_TIME_H
-#define _SYS_TIME_H
-
-#include <klibc/extern.h>
-#include <sys/types.h>
-#include <linux/time.h>
-
-__extern int gettimeofday(struct timeval *, struct timezone *);
-__extern int settimeofday(const struct timeval *, const struct timezone *);
-__extern int getitimer(int, struct itimerval *);
-__extern int setitimer(int, const struct itimerval *, struct itimerval *);
-
-#endif /* _SYS_TIME_H */
diff --git a/klibc/klibc/include/sys/types.h b/klibc/klibc/include/sys/types.h
deleted file mode 100644
index 0aaeeb1612..0000000000
--- a/klibc/klibc/include/sys/types.h
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
- * sys/types.h
- */
-
-#ifndef _SYS_TYPES_H
-#define _SYS_TYPES_H
-
-#include <stddef.h>
-#include <stdint.h>
-
-#define _SSIZE_T
-typedef ptrdiff_t ssize_t;
-
-#include <linux/posix_types.h>
-#include <asm/types.h>
-
-/* Keeps linux/types.h from getting included elsewhere */
-#define _LINUX_TYPES_H
-
-typedef __kernel_fd_set fd_set;
-typedef uint32_t dev_t;
-typedef __kernel_ino_t ino_t;
-typedef __kernel_mode_t mode_t;
-typedef __kernel_nlink_t nlink_t;
-typedef __kernel_off_t off_t; /* Should become __kernel_loff_t... */
-typedef __kernel_pid_t pid_t;
-typedef __kernel_daddr_t daddr_t;
-typedef __kernel_key_t key_t;
-typedef __kernel_suseconds_t suseconds_t;
-typedef __kernel_timer_t timer_t;
-
-typedef __kernel_uid32_t uid_t;
-typedef __kernel_gid32_t gid_t;
-
-typedef __kernel_loff_t loff_t;
-
-/*
- * The following typedefs are also protected by individual ifdefs for
- * historical reasons:
- */
-#ifndef _SIZE_T
-#define _SIZE_T
-typedef __kernel_size_t size_t;
-#endif
-
-#ifndef _SSIZE_T
-#define _SSIZE_T
-typedef __kernel_ssize_t ssize_t;
-#endif
-
-#ifndef _PTRDIFF_T
-#define _PTRDIFF_T
-typedef __kernel_ptrdiff_t ptrdiff_t;
-#endif
-
-#ifndef _TIME_T
-#define _TIME_T
-typedef __kernel_time_t time_t;
-#endif
-
-#ifndef _CLOCK_T
-#define _CLOCK_T
-typedef __kernel_clock_t clock_t;
-#endif
-
-#ifndef _CADDR_T
-#define _CADDR_T
-typedef __kernel_caddr_t caddr_t;
-#endif
-
-/* bsd */
-typedef unsigned char u_char;
-typedef unsigned short u_short;
-typedef unsigned int u_int;
-typedef unsigned long u_long;
-
-/* sysv */
-typedef unsigned char unchar;
-typedef unsigned short ushort;
-typedef unsigned int uint;
-typedef unsigned long ulong;
-
-/* Linux-specific? */
-typedef uint8_t u_int8_t;
-typedef uint16_t u_int16_t;
-typedef uint32_t u_int32_t;
-typedef uint64_t u_int64_t;
-
-/*
- * transition to 64-bit sector_t, possibly making it an option...
- */
-#undef BLK_64BIT_SECTOR
-
-#ifdef BLK_64BIT_SECTOR
-typedef u64 sector_t;
-#else
-typedef unsigned long sector_t;
-#endif
-
-/*
- * The type of an index into the pagecache. Use a #define so asm/types.h
- * can override it.
- */
-#ifndef pgoff_t
-#define pgoff_t unsigned long
-#endif
-
-/*
- * Below are truly Linux-specific types that should never collide with
- * any application/library that wants linux/types.h.
- */
-
-struct ustat {
- __kernel_daddr_t f_tfree;
- __kernel_ino_t f_tinode;
- char f_fname[6];
- char f_fpack[6];
-};
-
-/*
- * Some apps want this in <sys/types.h>
- */
-#include <sys/sysmacros.h>
-
-#endif
diff --git a/klibc/klibc/include/sys/uio.h b/klibc/klibc/include/sys/uio.h
deleted file mode 100644
index fc2525d11a..0000000000
--- a/klibc/klibc/include/sys/uio.h
+++ /dev/null
@@ -1,15 +0,0 @@
-/*
- * sys/uio.h
- */
-
-#ifndef _SYS_UIO_H
-#define _SYS_UIO_H
-
-#include <klibc/extern.h>
-#include <sys/types.h>
-#include <linux/uio.h>
-
-__extern int readv(int, const struct iovec *, int);
-__extern int writev(int, const struct iovec *, int);
-
-#endif /* _SYS_UIO_H */
diff --git a/klibc/klibc/include/sys/un.h b/klibc/klibc/include/sys/un.h
deleted file mode 100644
index df42d719f7..0000000000
--- a/klibc/klibc/include/sys/un.h
+++ /dev/null
@@ -1,10 +0,0 @@
-/*
- * <sys/un.h>
- */
-
-#ifndef _SYS_UN_H
-#define _SYS_UN_H
-
-#include <linux/un.h>
-
-#endif /* _SYS_UN_H */
diff --git a/klibc/klibc/include/sys/utime.h b/klibc/klibc/include/sys/utime.h
deleted file mode 100644
index d1d635d242..0000000000
--- a/klibc/klibc/include/sys/utime.h
+++ /dev/null
@@ -1,10 +0,0 @@
-/*
- * sys/utime.h
- */
-
-#ifndef _SYS_UTIME_H
-#define _SYS_UTIME_H
-
-#include <linux/utime.h>
-
-#endif /* _SYS_UTIME_H */
diff --git a/klibc/klibc/include/sys/utsname.h b/klibc/klibc/include/sys/utsname.h
deleted file mode 100644
index f2990f5711..0000000000
--- a/klibc/klibc/include/sys/utsname.h
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * sys/utsname.h
- */
-
-#ifndef _SYS_UTSNAME_H
-#define _SYS_UTSNAME_H
-
-#include <klibc/extern.h>
-
-#define SYS_NMLN 65
-
-struct utsname {
- char sysname[SYS_NMLN];
- char nodename[SYS_NMLN];
- char release[SYS_NMLN];
- char version[SYS_NMLN];
- char machine[SYS_NMLN];
- char domainname[SYS_NMLN];
-};
-
-__extern int uname(struct utsname *);
-
-#endif /* _SYS_UTSNAME_H */
diff --git a/klibc/klibc/include/sys/vfs.h b/klibc/klibc/include/sys/vfs.h
deleted file mode 100644
index 8c1577c4bf..0000000000
--- a/klibc/klibc/include/sys/vfs.h
+++ /dev/null
@@ -1,14 +0,0 @@
-/*
- * sys/vfs.h
- */
-
-#ifndef _SYS_VFS_H
-#define _SYS_VFS_H
-
-#include <klibc/extern.h>
-#include <linux/vfs.h>
-
-__extern int statfs(const char *, struct statfs *);
-__extern int fstatfs(int, struct statfs *);
-
-#endif /* _SYS_VFS_H */
diff --git a/klibc/klibc/include/sys/wait.h b/klibc/klibc/include/sys/wait.h
deleted file mode 100644
index 4cfafc9408..0000000000
--- a/klibc/klibc/include/sys/wait.h
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * sys/wait.h
- */
-
-#ifndef _SYS_WAIT_H
-#define _SYS_WAIT_H
-
-#include <klibc/extern.h>
-#include <sys/types.h>
-#include <sys/resource.h>
-
-#include <linux/wait.h>
-
-#define WEXITSTATUS(s) (((s) & 0xff00) >> 8)
-#define WTERMSIG(s) ((s) & 0x7f)
-#define WIFEXITED(s) (WTERMSIG(s) == 0)
-#define WIFSTOPPED(s) (WTERMSIG(s) == 0x7f)
-/* Ugly hack to avoid multiple evaluation of "s" */
-#define WIFSIGNALED(s) (WTERMSIG((s)+1) >= 2)
-#define WCOREDUMP(s) ((s) & 0x80)
-#define WSTOPSIG(s) WEXITSTATUS(s)
-
-__extern pid_t wait(int *);
-__extern pid_t waitpid(pid_t, int *, int);
-__extern pid_t wait3(int *, int, struct rusage *);
-__extern pid_t wait4(pid_t, int *, int, struct rusage *);
-
-#endif /* _SYS_WAIT_H */
diff --git a/klibc/klibc/include/syslog.h b/klibc/klibc/include/syslog.h
deleted file mode 100644
index 551527a042..0000000000
--- a/klibc/klibc/include/syslog.h
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * syslog.h
- */
-
-#ifndef _SYSLOG_H
-#define _SYSLOG_H
-
-#include <stdio.h>
-#include <klibc/extern.h>
-
-/* Alert levels */
-#define LOG_EMERG 0
-#define LOG_ALERT 1
-#define LOG_CRIT 2
-#define LOG_ERR 3
-#define LOG_WARNING 4
-#define LOG_NOTICE 5
-#define LOG_INFO 6
-#define LOG_DEBUG 7
-
-#define LOG_PRIMASK 7
-#define LOG_PRI(x) ((x) & LOG_PRIMASK)
-
-
-/* Facilities; not actually used */
-#define LOG_KERN 0000
-#define LOG_USER 0010
-#define LOG_MAIL 0020
-#define LOG_DAEMON 0030
-#define LOG_AUTH 0040
-#define LOG_SYSLOG 0050
-#define LOG_LPR 0060
-#define LOG_NEWS 0070
-#define LOG_UUCP 0100
-#define LOG_CRON 0110
-#define LOG_AUTHPRIV 0120
-#define LOG_FTP 0130
-#define LOG_LOCAL0 0200
-#define LOG_LOCAL1 0210
-#define LOG_LOCAL2 0220
-#define LOG_LOCAL3 0230
-#define LOG_LOCAL4 0240
-#define LOG_LOCAL5 0250
-#define LOG_LOCAL6 0260
-#define LOG_LOCAL7 0270
-
-#define LOG_FACMASK 01770
-#define LOG_FAC(x) (((x) >> 3) & (LOG_FACMASK >> 3))
-
-__extern void openlog(const char *, int, int);
-__extern void syslog(int, const char *, ...);
-__extern void vsyslog(int, const char *, va_list);
-__extern void closelog(void);
-
-#endif /* _SYSLOG_H */
diff --git a/klibc/klibc/include/termios.h b/klibc/klibc/include/termios.h
deleted file mode 100644
index 08a5e56855..0000000000
--- a/klibc/klibc/include/termios.h
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * termios.h
- */
-
-#ifndef _TERMIOS_H
-#define _TERMIOS_H
-
-#include <klibc/extern.h>
-#include <stdint.h>
-#include <sys/ioctl.h>
-#include <sys/types.h>
-#include <linux/termios.h>
-
-/* Redefine these so the magic constants == the ioctl number to use. */
-#undef TCSANOW
-#undef TCSADRAIN
-#undef TCSAFLUSH
-#define TCSANOW TCSETS
-#define TCSADRAIN TCSETSW
-#define TCSAFLUSH TCSETSF
-
-static __inline__ int tcgetattr(int __fd, struct termios *__s)
-{
- return ioctl(__fd, TCGETS, __s);
-}
-
-static __inline__ int tcsetattr(int __fd, int __opt, const struct termios *__s)
-{
- return ioctl(__fd, __opt, (void *)__s);
-}
-
-static __inline__ int tcflow(int __fd, int __action)
-{
- return ioctl(__fd, TCXONC, (void *)(intptr_t)__action);
-}
-
-static __inline__ int tcflush(int __fd, int __queue)
-{
- return ioctl(__fd, TCFLSH, (void *)(intptr_t)__queue);
-}
-
-static __inline__ pid_t tcgetpgrp(int __fd)
-{
- pid_t __p;
- return ioctl(__fd, TIOCGPGRP, &__p) ? (pid_t)-1 : __p;
-}
-
-static __inline__ pid_t tcgetsid(int __fd)
-{
- pid_t __p;
- return ioctl(__fd, TIOCGSID, &__p) ? (pid_t)-1 : __p;
-}
-
-static __inline__ int tcsendbreak(int __fd, int __duration)
-{
- return ioctl(__fd, TCSBRKP, (void *)(uintptr_t)__duration);
-}
-
-static __inline__ int tcsetpgrp(int __fd, pid_t __p)
-{
- return ioctl(__fd, TIOCSPGRP, &__p);
-}
-
-static __inline__ speed_t cfgetospeed(const struct termios *__s)
-{
- return (speed_t)(__s->c_cflag & CBAUD);
-}
-
-static __inline__ speed_t cfgetispeed(const struct termios *__s)
-{
- return (speed_t)(__s->c_cflag & CBAUD);
-}
-
-static __inline__ int cfsetospeed(struct termios *__s, speed_t __v)
-{
- __s->c_cflag = (__s->c_cflag & ~CBAUD) | (__v & CBAUD);
- return 0;
-}
-
-static __inline__ int cfsetispeed(struct termios *__s, speed_t __v)
-{
- __s->c_cflag = (__s->c_cflag & ~CBAUD) | (__v & CBAUD);
- return 0;
-}
-
-#endif /* _TERMIOS_H */
diff --git a/klibc/klibc/include/time.h b/klibc/klibc/include/time.h
deleted file mode 100644
index c69c231ec8..0000000000
--- a/klibc/klibc/include/time.h
+++ /dev/null
@@ -1,14 +0,0 @@
-/*
- * time.h
- */
-
-#ifndef _TIME_H
-#define _TIME_H
-
-#include <klibc/extern.h>
-#include <sys/time.h>
-
-__extern time_t time(time_t *);
-__extern int nanosleep(const struct timespec *, struct timespec *);
-
-#endif /* _TIME_H */
diff --git a/klibc/klibc/include/unistd.h b/klibc/klibc/include/unistd.h
deleted file mode 100644
index 13ff03b012..0000000000
--- a/klibc/klibc/include/unistd.h
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- * unistd.h
- */
-
-#ifndef _UNISTD_H
-#define _UNISTD_H
-
-#include <klibc/extern.h>
-#include <klibc/compiler.h>
-#include <stddef.h>
-#include <sys/types.h>
-#include <sys/select.h>
-
-__extern char **environ;
-__extern __noreturn _exit(int);
-
-__extern pid_t fork(void);
-__extern pid_t vfork(void);
-__extern pid_t getpid(void);
-__extern pid_t getpgid(pid_t);
-__extern int setpgid(pid_t, pid_t);
-__extern pid_t getppid(void);
-__extern pid_t getpgrp(void);
-__extern int setpgrp(void);
-__extern pid_t setsid(void);
-__extern pid_t getsid(pid_t);
-__extern int execv(const char *, char * const *);
-__extern int execvp(const char *, char * const *);
-__extern int execve(const char *, char * const *, char * const *);
-__extern int execvpe(const char *, char * const *, char * const *);
-__extern int execl(const char *, const char *, ...);
-__extern int execlp(const char *, const char *, ...);
-__extern int execle(const char *, const char *, ...);
-__extern int execlpe(const char *, const char *, ...);
-
-__extern int setuid(uid_t);
-__extern uid_t getuid(void);
-__extern int seteuid(uid_t);
-__extern uid_t geteuid(void);
-__extern int setgid(gid_t);
-__extern gid_t getgid(void);
-__extern int setegid(gid_t);
-__extern gid_t getegid(void);
-__extern int getgroups(int, gid_t *);
-__extern int setgroups(size_t, const gid_t *);
-__extern int setreuid(uid_t, uid_t);
-__extern int setregid(gid_t, gid_t);
-__extern int setresuid(uid_t, uid_t, uid_t);
-__extern int setresgid(gid_t, gid_t, gid_t);
-__extern int getfsuid(uid_t);
-__extern int setfsuid(uid_t);
-
-/* Macros for access() */
-#define R_OK 4 /* Read */
-#define W_OK 2 /* Write */
-#define X_OK 1 /* Execute */
-#define F_OK 0 /* Existence */
-
-__extern int access(const char *, int);
-__extern int link(const char *, const char *);
-__extern int unlink(const char *);
-__extern int chdir(const char *);
-__extern int chmod(const char *, mode_t);
-__extern int fchmod(int, mode_t);
-__extern int mkdir(const char *, mode_t);
-__extern int rmdir(const char *);
-__extern int pipe(int *);
-__extern int chroot(const char *);
-__extern int symlink(const char *, const char *);
-__extern int readlink(const char *, char *, size_t);
-__extern int chown(const char *, uid_t, gid_t);
-__extern int fchown(int, uid_t, gid_t);
-__extern int lchown(const char *, uid_t, gid_t);
-__extern char *getcwd(char *, size_t);
-
-__extern int sync(void);
-
-__extern ssize_t read(int, void *, size_t);
-__extern ssize_t write(int, const void *, size_t);
-#ifndef __IN_OPEN_C
-__extern __cdecl int open(const char *, int, ...);
-#endif
-__extern int close(int);
-__extern off_t lseek(int, off_t, int);
-__extern loff_t llseek(int, loff_t, int);
-__extern int dup(int);
-__extern int dup2(int, int);
-__extern int fcntl(int, int, long);
-__extern int ioctl(int, int, void *);
-__extern int flock(int, int);
-__extern int fsync(int);
-__extern int fdatasync(int);
-__extern int ftruncate(int, off_t);
-
-__extern int pause(void);
-__extern unsigned int alarm(unsigned int);
-__extern unsigned int sleep(unsigned int);
-__extern void usleep(unsigned long);
-
-__extern int gethostname(char *, size_t);
-__extern int sethostname(const char *, size_t);
-__extern int getdomainname(char *, size_t);
-__extern int setdomainname(const char *, size_t);
-
-__extern void *__brk(void *);
-__extern int brk(void *);
-__extern void *sbrk(ptrdiff_t);
-
-__extern int getopt(int, char * const *, const char *);
-__extern char *optarg;
-__extern int optind, opterr, optopt;
-
-__extern int isatty(int);
-
-__extern int getpagesize(void);
-
-/* Standard file descriptor numbers. */
-#define STDIN_FILENO 0
-#define STDOUT_FILENO 1
-#define STDERR_FILENO 2
-
-#endif /* _UNISTD_H */
diff --git a/klibc/klibc/include/utime.h b/klibc/klibc/include/utime.h
deleted file mode 100644
index 3dfa03a14a..0000000000
--- a/klibc/klibc/include/utime.h
+++ /dev/null
@@ -1,15 +0,0 @@
-/*
- * utime.h
- */
-
-#ifndef _UTIME_H
-#define _UTIME_H
-
-#include <klibc/extern.h>
-#include <sys/types.h>
-#include <linux/utime.h>
-
-__extern int utime(const char *, const struct utimbuf *);
-
-#endif /* _UTIME_H */
-
diff --git a/klibc/klibc/inet/bindresvport.c b/klibc/klibc/inet/bindresvport.c
index c30054edfd..750bd709c4 100644
--- a/klibc/klibc/inet/bindresvport.c
+++ b/klibc/klibc/inet/bindresvport.c
@@ -9,8 +9,8 @@
#include <string.h>
#include <unistd.h>
-#define START_PORT 600
-#define END_PORT (IPPORT_RESERVED - 1)
+#define START_PORT 768
+#define END_PORT IPPORT_RESERVED
#define NUM_PORTS (END_PORT - START_PORT)
int bindresvport(int sd, struct sockaddr_in *sin)
@@ -21,14 +21,12 @@ int bindresvport(int sd, struct sockaddr_in *sin)
int i;
if (sin == NULL) {
+ memset(&me, 0, sizeof(me));
sin = &me;
- memset(sin, 0, sizeof(me));
- sin->sin_port = AF_INET;
- }
- else if (sin->sin_family != AF_INET) {
+ sin->sin_family = AF_INET;
+ } else if (sin->sin_family != AF_INET) {
errno = EPFNOSUPPORT;
- ret = -1;
- goto bail;
+ return -1;
}
if (port == 0) {
@@ -36,13 +34,12 @@ int bindresvport(int sd, struct sockaddr_in *sin)
}
for (i = 0; i < NUM_PORTS; i++, port++) {
- sin->sin_port = htons(port);
- if ((ret = bind(sd, (struct sockaddr *)&sin, sizeof(*sin))) != -1)
- break;
if (port == END_PORT)
port = START_PORT;
+ sin->sin_port = htons(port);
+ if ((ret = bind(sd, (struct sockaddr *)sin, sizeof(*sin))) != -1)
+ break;
}
- bail:
return ret;
}
diff --git a/klibc/klibc/interp.S b/klibc/klibc/interp.S
index 303943697b..b1a2701999 100644
--- a/klibc/klibc/interp.S
+++ b/klibc/klibc/interp.S
@@ -2,7 +2,9 @@
# This is a hack to generate the .intrp section, which then
# ld turns into an PT_INTERP header.
#
-
+# NOTE: The .interp section needs to be "a", or it doesnt work...
+#
+
.section ".interp","a"
.ascii LIBDIR
.ascii "/klibc-"
diff --git a/klibc/klibc/jrand48.c b/klibc/klibc/jrand48.c
new file mode 100644
index 0000000000..a2ead11e5f
--- /dev/null
+++ b/klibc/klibc/jrand48.c
@@ -0,0 +1,24 @@
+/*
+ * jrand48.c
+ */
+
+#include <stdlib.h>
+#include <stdint.h>
+
+long jrand48(unsigned short xsubi[3])
+{
+ uint64_t x;
+
+ /* The xsubi[] array is littleendian by spec */
+ x = (uint64_t)xsubi[0] +
+ ((uint64_t)xsubi[1] << 16) +
+ ((uint64_t)xsubi[2] << 32);
+
+ x = (0x5deece66dULL * x) + 0xb;
+
+ xsubi[0] = (unsigned short)x;
+ xsubi[1] = (unsigned short)(x >> 16);
+ xsubi[2] = (unsigned short)(x >> 32);
+
+ return (long)(int32_t)(x >> 16);
+}
diff --git a/klibc/klibc/libc_init.c b/klibc/klibc/libc_init.c
new file mode 100644
index 0000000000..e91edc44a3
--- /dev/null
+++ b/klibc/klibc/libc_init.c
@@ -0,0 +1,86 @@
+/*
+ * libc_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>
+
+/* This file is included from __static_init.c or __shared_init.c */
+#ifndef SHARED
+# error "SHARED should be defined to 0 or 1"
+#endif
+
+char **environ;
+unsigned int __page_size, __page_shift;
+
+struct auxentry {
+ uintptr_t type;
+ uintptr_t v;
+};
+
+__noreturn __libc_init(uintptr_t *elfdata, void (*onexit)(void))
+{
+ int argc;
+ char **argv, **envp, **envend;
+ struct auxentry *auxentry;
+#if SHARED
+ typedef int (*main_t)(int, char **, char **);
+ main_t MAIN = NULL;
+#else
+ extern int main(int, char **, char **);
+#define MAIN main
+#endif
+ unsigned int page_size = 0, page_shift = 0;
+
+ (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 ) {
+ switch ( auxentry->type ) {
+#if SHARED
+ case AT_ENTRY:
+ MAIN = (main_t)(auxentry->v);
+ break;
+#endif
+ case AT_PAGESZ:
+ page_size = (int)(auxentry->v);
+ break;
+ }
+ auxentry++;
+ }
+
+ __page_size = page_size;
+
+#if defined(__i386__) || defined(__x86_64__)
+ asm("bsrl %1,%0" : "=r" (page_shift) : "rm" (page_size));
+#else
+ while ( page_size > 1 ) {
+ page_shift++;
+ page_size >>= 1;
+ }
+#endif
+ __page_shift = page_shift;
+
+ environ = envp;
+ exit(MAIN(argc, argv, envp));
+}
diff --git a/klibc/klibc/llseek.c b/klibc/klibc/llseek.c
index fdffc16e2c..2102a503e9 100644
--- a/klibc/klibc/llseek.c
+++ b/klibc/klibc/llseek.c
@@ -1,8 +1,10 @@
/*
* llseek.c
*
- * On 32-bit platforms, we need llseek() as well as lseek() to be
- * able to handle large disks
+ * On 32-bit platforms, we need to use the _llseek() system call
+ * rather than lseek(), to be able to handle large disks. _llseek()
+ * isn't just a normal syscall which takes a 64-bit argument; it needs
+ * to return a 64-bit value and so takes an extra pointer.
*/
#include <unistd.h>
@@ -10,24 +12,17 @@
#if BITSIZE == 32
-static inline _syscall5(int, _llseek, int, fd, unsigned long, hi, unsigned long, lo, loff_t *,res, int, whence);
+extern int __llseek(int fd, unsigned long hi, unsigned long lo, off_t *res, int whence);
-loff_t llseek(int fd, loff_t offset, int whence)
+off_t lseek(int fd, off_t offset, int whence)
{
- loff_t result;
+ off_t result;
int rv;
- rv = _llseek(fd, (unsigned long)(offset >> 32),
- (unsigned long)offset, &result, whence);
+ rv = __llseek(fd, (unsigned long)(offset >> 32), (unsigned long)offset,
+ &result, whence);
- return rv ? (loff_t)-1 : result;
-}
-
-#else
-
-loff_t llseek(int fd, loff_t offset, int whence)
-{
- return lseek(fd, offset, whence);
+ return rv ? (off_t)-1 : result;
}
#endif
diff --git a/klibc/klibc/lrand48.c b/klibc/klibc/lrand48.c
index 4d05de2e89..8c0a3de176 100644
--- a/klibc/klibc/lrand48.c
+++ b/klibc/klibc/lrand48.c
@@ -5,38 +5,10 @@
#include <stdlib.h>
#include <stdint.h>
-unsigned short __rand48_seed[3];
-
-long jrand48(unsigned short xsubi[3])
-{
- uint64_t x;
-
- /* The xsubi[] array is littleendian by spec */
- x = (uint64_t)xsubi[0] +
- ((uint64_t)xsubi[1] << 16) +
- ((uint64_t)xsubi[2] << 32);
-
- x = (0x5deece66dULL * x) + 0xb;
-
- xsubi[0] = (unsigned short)x;
- xsubi[1] = (unsigned short)(x >> 16);
- xsubi[2] = (unsigned short)(x >> 32);
-
- return (long)(int32_t)(x >> 16);
-}
-
-long mrand48(void)
-{
- return jrand48(__rand48_seed);
-}
-
-long nrand48(unsigned short xsubi[3])
-{
- return (long)((uint32_t)jrand48(xsubi) >> 1);
-}
+unsigned short __rand48_seed[3]; /* Common with mrand48.c, srand48.c */
long lrand48(void)
{
- return (long)((uint32_t)(mrand48() >> 1));
+ return (uint32_t)jrand48(__rand48_seed) >> 1;
}
diff --git a/klibc/klibc/makeerrlist.pl b/klibc/klibc/makeerrlist.pl
index 00acb8a3d5..f42704f88a 100644
--- a/klibc/klibc/makeerrlist.pl
+++ b/klibc/klibc/makeerrlist.pl
@@ -20,7 +20,7 @@ sub parse_file($) {
$file = $rootdir.$file;
- print STDERR "opening $file\n";
+ print STDERR "opening $file\n" unless ( $quiet );
if ( !($fh->open("< ".$file)) ) {
die "$0: cannot open $file\n";
@@ -38,7 +38,7 @@ sub parse_file($) {
$error = $1;
$errno = $2+0;
$msg = $3;
- print STDERR "$error ($errno) => \"$msg\"\n";
+ print STDERR "$error ($errno) => \"$msg\"\n" unless ( $quiet );
$errors{$errno} = $error;
$errmsg{$errno} = $msg;
$maxerr = $errno if ( $errno > $maxerr );
@@ -50,12 +50,23 @@ sub parse_file($) {
}
}
close($fh);
- print STDERR "closing $file\n";
+ print STDERR "closing $file\n" unless ( $quiet );
}
-parse_file('linux/errno.h');
+$v = $ENV{'KBUILD_VERBOSE'};
+$quiet = defined($v) ? !$v : 0;
-($type) = @ARGV;
+foreach $arg ( @ARGV ) {
+ if ( $arg eq '-q' ) {
+ $quiet = 1;
+ } elsif ( $arg =~ /^-(errlist|errnos|maxerr)$/ ) {
+ $type = $arg;
+ } else {
+ die "$0: Unknown option: $arg\n";
+ }
+}
+
+parse_file('linux/errno.h');
if ( $type eq '-errlist' ) {
print "#include <errno.h>\n";
diff --git a/klibc/klibc/malloc.c b/klibc/klibc/malloc.c
index 20a2350d71..976353c201 100644
--- a/klibc/klibc/malloc.c
+++ b/klibc/klibc/malloc.c
@@ -133,9 +133,14 @@ void *malloc(size_t size)
}
/* Nothing found... need to request a block from the kernel */
- fsize = (size+MALLOC_CHUNK_MASK) & ~MALLOC_CHUNK_MASK;
+ fsize = (size+MALLOC_CHUNK_MASK) & ~MALLOC_CHUNK_MASK;
+
+#ifdef MALLOC_USING_SBRK
+ fp = (struct free_arena_header *) sbrk(fsize);
+#else
fp = (struct free_arena_header *)
mmap(NULL, fsize, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, 0, 0);
+#endif
if ( fp == (struct free_arena_header *)MAP_FAILED ) {
return NULL; /* Failed to get a block */
diff --git a/klibc/klibc/malloc.h b/klibc/klibc/malloc.h
index e053f71401..456295069a 100644
--- a/klibc/klibc/malloc.h
+++ b/klibc/klibc/malloc.h
@@ -6,13 +6,7 @@
#include <stdint.h>
#include <stddef.h>
-
-/*
- * This is the minimum chunk size we will ask the kernel for; this should
- * be a multiple of the page size on all architectures.
- */
-#define MALLOC_CHUNK_SIZE 65536
-#define MALLOC_CHUNK_MASK (MALLOC_CHUNK_SIZE-1)
+#include <klibc/sysconfig.h>
/*
* This structure should be a power of two. This becomes the
diff --git a/klibc/klibc/mmap.c b/klibc/klibc/mmap.c
index 89cf3a6a8f..196f1c088f 100644
--- a/klibc/klibc/mmap.c
+++ b/klibc/klibc/mmap.c
@@ -6,46 +6,44 @@
#include <errno.h>
#include <sys/syscall.h>
#include <sys/mman.h>
+#include <unistd.h>
#include <asm/page.h> /* For PAGE_SHIFT */
#if defined(__sparc__)
# define MMAP2_SHIFT 12 /* Fixed by syscall definition */
+#elif defined(__mips__) || defined(__powerpc__)
+# define MMAP2_SHIFT __getpageshift() /* Variable */
#else
# define MMAP2_SHIFT PAGE_SHIFT
#endif
-#define MMAP2_MASK ((1UL << MMAP2_SHIFT)-1)
/*
- * Prefer mmap2() over mmap(), except on the architectures listed
+ * Set in SYSCALLS whether or not we should use an unadorned mmap() system
+ * call (typical on 64-bit architectures).
*/
+#if (BITSIZE == 32 && defined(__NR_mmap2)) || (BITSIZE == 64 && !defined(__NR_mmap))
-#if defined(__NR_mmap2) && !defined(__sparc__) && !defined(__ia64__) && !defined(__powerpc__) && !defined(__powerpc64__)
+/* This architecture uses mmap2(). The Linux mmap2() system call takes
+ a page offset as the offset argument. We need to make sure we have
+ the proper conversion in place. */
-/* This architecture uses mmap2() */
-
-static inline _syscall6(void *,mmap2,void *,start,size_t,length,int,prot,int,flags,int,fd,off_t,offset);
-
-/* The Linux mmap2() system call takes a page offset as the offset argument.
- We need to make sure we have the proper conversion in place. */
+extern void *__mmap2(void *, size_t, int, int, int, size_t);
void *mmap(void *start, size_t length, int prot, int flags, int fd, off_t offset)
{
- if ( offset & MMAP2_MASK ) {
+ const int mmap2_shift = MMAP2_SHIFT;
+ const unsigned long mmap2_mask = (1UL << mmap2_shift) - 1;
+
+ if ( offset & mmap2_mask ) {
errno = EINVAL;
return MAP_FAILED;
}
- return mmap2(start, length, prot, flags, fd, (size_t)offset >> MMAP2_SHIFT);
+ return __mmap2(start, length, prot, flags, fd, (size_t)offset >> mmap2_shift);
}
-#else
-
-/* This architecture uses a plain mmap() system call */
-/* Only use this for architectures where mmap() is a real 6-argument system call! */
-
-_syscall6(void *,mmap,void *,start,size_t,length,int,prot,int,flags,int,fd,off_t,offset)
-
#endif
+
diff --git a/klibc/klibc/mrand48.c b/klibc/klibc/mrand48.c
new file mode 100644
index 0000000000..886ae9f03c
--- /dev/null
+++ b/klibc/klibc/mrand48.c
@@ -0,0 +1,13 @@
+/*
+ * mrand48.c
+ */
+
+#include <stdlib.h>
+#include <stdint.h>
+
+unsigned short __rand48_seed[3]; /* Common with lrand48.c, srand48.c */
+
+long mrand48(void)
+{
+ return jrand48(__rand48_seed);
+}
diff --git a/klibc/klibc/nice.c b/klibc/klibc/nice.c
index f0d97a3cd0..5a18de9091 100644
--- a/klibc/klibc/nice.c
+++ b/klibc/klibc/nice.c
@@ -7,11 +7,7 @@
#include <sys/resource.h>
#include <sys/syscall.h>
-#ifdef __NR_nice
-
-_syscall1(int,nice,int,inc);
-
-#else
+#ifndef __NR_nice
int nice(int inc)
{
diff --git a/klibc/klibc/nrand48.c b/klibc/klibc/nrand48.c
new file mode 100644
index 0000000000..fb7c5772fd
--- /dev/null
+++ b/klibc/klibc/nrand48.c
@@ -0,0 +1,11 @@
+/*
+ * nrand48.c
+ */
+
+#include <stdlib.h>
+#include <stdint.h>
+
+long nrand48(unsigned short xsubi[3])
+{
+ return (long)((uint32_t)jrand48(xsubi) >> 1);
+}
diff --git a/klibc/klibc/open.c b/klibc/klibc/open.c
index 0d7db10c4a..d52b53a699 100644
--- a/klibc/klibc/open.c
+++ b/klibc/klibc/open.c
@@ -1,17 +1,21 @@
/*
* open.c
*
- * The open syscall is weird, because it's defined as a varadic
- * function, but implementing it as such generally sucks for
- * performance. Thus we generate it as a 3-argument function,
- * but with explicit __cdecl assuming the __cdecl convention is
- * independent of being varadic.
+ * On 32-bit platforms we need to pass O_LARGEFILE to the open()
+ * system call, to indicate that we're 64-bit safe.
*/
-#define __IN_OPEN_C
+#define _KLIBC_IN_OPEN_C
#include <unistd.h>
#include <fcntl.h>
-#include <sys/stat.h>
-#include <sys/syscall.h>
-__cdecl _syscall3(int,open,const char *,file,int,flags,mode_t,mode)
+#if BITSIZE == 32 && !defined(__i386__)
+
+extern int __open(const char *, int, mode_t);
+
+int open(const char *pathname, int flags, mode_t mode)
+{
+ return __open(pathname, flags|O_LARGEFILE, mode);
+}
+
+#endif
diff --git a/klibc/klibc/pause.c b/klibc/klibc/pause.c
index 5748728472..1f7b9342de 100644
--- a/klibc/klibc/pause.c
+++ b/klibc/klibc/pause.c
@@ -7,11 +7,7 @@
#include <sys/time.h>
#include <sys/syscall.h>
-#ifdef __NR_pause
-
-_syscall0(int,pause);
-
-#else
+#ifndef __NR_pause
int pause(void)
{
diff --git a/klibc/klibc/perror.c b/klibc/klibc/perror.c
index 45585cd577..26f8ce8f6d 100644
--- a/klibc/klibc/perror.c
+++ b/klibc/klibc/perror.c
@@ -8,5 +8,6 @@
void perror(const char *s)
{
- fprintf(stderr, "%s: error %d\n", s, errno);
+ int e = errno;
+ fprintf(stderr, "%s: %s\n", s, strerror(e));
}
diff --git a/klibc/klibc/putchar.c b/klibc/klibc/putchar.c
new file mode 100644
index 0000000000..0e35adda17
--- /dev/null
+++ b/klibc/klibc/putchar.c
@@ -0,0 +1,15 @@
+/*
+ * putchar.c
+ *
+ * - gcc wants this
+ */
+
+#include <stdio.h>
+
+#undef putchar /* Defined as a macro */
+int putchar(int);
+
+int putchar(int c)
+{
+ return fputc(c, stdout);
+}
diff --git a/klibc/klibc/qsort.c b/klibc/klibc/qsort.c
index e2197ea2ae..185f4dac69 100644
--- a/klibc/klibc/qsort.c
+++ b/klibc/klibc/qsort.c
@@ -23,14 +23,14 @@ void qsort(void *base, size_t nmemb, size_t size, int (*compar)(const void *, co
{
size_t gap = nmemb;
size_t i, j;
- void *p1, *p2;
+ char *p1, *p2;
int swapped;
do {
gap = newgap(gap);
swapped = 0;
- for ( i = 0, p1 = base ; i < nmemb-gap ; i++, (char *)p1 += size ) {
+ for ( i = 0, p1 = base ; i < nmemb-gap ; i++, p1 += size ) {
j = i+gap;
if ( compar(p1, p2 = (char *)base+j*size) > 0 ) {
memswap(p1, p2, size);
diff --git a/klibc/klibc/readdir.c b/klibc/klibc/readdir.c
index bb216a1951..acfe588713 100644
--- a/klibc/klibc/readdir.c
+++ b/klibc/klibc/readdir.c
@@ -1,21 +1,12 @@
/*
- * opendir/readdir/closedir
+ * readdir.c: opendir/readdir/closedir
*/
#include <unistd.h>
#include <fcntl.h>
#include <stdlib.h>
-#include <sys/dirent.h>
-#include <stdio.h>
-
-#define __IO_DIR_DEFINED
-struct _IO_dir {
- int fd;
- size_t bytes_left;
- struct dirent *next;
- struct dirent buffer[15]; /* 15 times max dirent size =~ 4K */
-};
+#define __KLIBC_DIRENT_INTERNALS
#include <dirent.h>
DIR *opendir(const char *name)
@@ -25,9 +16,9 @@ DIR *opendir(const char *name)
if ( !dp )
return NULL;
- dp->fd = open(name, O_DIRECTORY|O_RDONLY);
+ dp->__fd = open(name, O_DIRECTORY|O_RDONLY);
- if ( dp->fd < 0 ) {
+ if ( dp->__fd < 0 ) {
free(dp);
return NULL;
}
@@ -43,7 +34,7 @@ struct dirent *readdir(DIR *dir)
int rv;
if ( !dir->bytes_left ) {
- rv = getdents(dir->fd, dir->buffer, sizeof(dir->buffer));
+ rv = getdents(dir->__fd, dir->buffer, sizeof(dir->buffer));
if ( rv <= 0 )
return NULL;
dir->bytes_left = rv;
@@ -51,7 +42,7 @@ struct dirent *readdir(DIR *dir)
}
dent = dir->next;
- ((char *)dir->next) += dent->d_reclen;
+ dir->next = (struct dirent *)((char *)dir->next + dent->d_reclen);
dir->bytes_left -= dent->d_reclen;
return dent;
@@ -60,7 +51,7 @@ struct dirent *readdir(DIR *dir)
int closedir(DIR *dir)
{
int rv;
- rv = close(dir->fd);
+ rv = close(dir->__fd);
free(dir);
return rv;
}
diff --git a/klibc/klibc/sbrk.c b/klibc/klibc/sbrk.c
index 03ab3c14bb..f7401dcfe2 100644
--- a/klibc/klibc/sbrk.c
+++ b/klibc/klibc/sbrk.c
@@ -1,23 +1,41 @@
/* sbrk.c - Change data segment size */
/* Written 2000 by Werner Almesberger */
+/* Modified 2003-2004 for klibc by H. Peter Anvin */
#include <stddef.h>
#include <unistd.h>
-#include <sys/types.h>
+#include <inttypes.h>
+#include <errno.h>
+#include "malloc.h"
char *__current_brk; /* Common with brk.c */
+/* p is an address, a is alignment; must be a power of 2 */
+static inline void *align_up(void *p, uintptr_t a)
+{
+ return (void *) (((uintptr_t)p + a-1) & ~(a-1));
+}
+
void *sbrk(ptrdiff_t increment)
{
- char *old_brk, *new_brk;
+ char *start, *end, *new_brk;
if (!__current_brk)
__current_brk = __brk(NULL);
- new_brk = __brk(__current_brk+increment);
- if (new_brk != __current_brk+increment)
+
+ start = align_up(__current_brk, SBRK_ALIGNMENT);
+ end = start + increment;
+
+ new_brk = __brk(end);
+
+ if (new_brk == (void *)-1)
+ return (void *)-1;
+ else if (new_brk < end) {
+ errno = ENOMEM;
return (void *) -1;
- old_brk = __current_brk;
+ }
+
__current_brk = new_brk;
- return old_brk;
+ return end;
}
diff --git a/klibc/klibc/seed48.c b/klibc/klibc/seed48.c
index f8353c8715..ac916d6165 100644
--- a/klibc/klibc/seed48.c
+++ b/klibc/klibc/seed48.c
@@ -6,7 +6,7 @@
#include <stdint.h>
#include <string.h>
-extern unsigned short __rand48_seed[3];
+unsigned short __rand48_seed[3];
unsigned short *seed48(const unsigned short xsubi[3])
{
diff --git a/klibc/klibc/select.c b/klibc/klibc/select.c
deleted file mode 100644
index 2404bb1e64..0000000000
--- a/klibc/klibc/select.c
+++ /dev/null
@@ -1,9 +0,0 @@
-#include <unistd.h>
-#include <sys/syscall.h>
-
-#ifdef __NR__newselect
-#undef __NR_select
-#define __NR_select __NR__newselect
-#endif
-
-_syscall5(int,select,int,a0,fd_set *,a1,fd_set *,a2,fd_set *,a3,struct timeval *,a4);
diff --git a/klibc/klibc/setresgid.c b/klibc/klibc/setresgid.c
deleted file mode 100644
index f1a8c6b45c..0000000000
--- a/klibc/klibc/setresgid.c
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * setresgid.c
- */
-
-#include <unistd.h>
-#include <sys/syscall.h>
-
-#ifdef __NR_setresgid
-
-_syscall3(int,setresgid,gid_t,a0,gid_t,a1,gid_t,a2);
-
-#elif defined(__NR_setresgid32)
-
-static inline _syscall3(int,setresgid32,gid_t,a0,gid_t,a1,gid_t,a2);
-
-int setresgid(gid_t a0, gid_t a1, gid_t a2)
-{
- if ( sizeof(gid_t) == sizeof(uint32_t) ) {
- return setresgid32(a0,a1,a2);
- } else {
- uint32_t x0 = (a0 == (gid_t)-1) ? (uint32_t)-1 : a0;
- uint32_t x1 = (a1 == (gid_t)-1) ? (uint32_t)-1 : a1;
- uint32_t x2 = (a2 == (gid_t)-1) ? (uint32_t)-1 : a2;
-
- return setresgid32(x0,x1,x2);
- }
-}
-
-#endif
diff --git a/klibc/klibc/setresuid.c b/klibc/klibc/setresuid.c
deleted file mode 100644
index a587acbae3..0000000000
--- a/klibc/klibc/setresuid.c
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * setresuid.c
- */
-
-#include <unistd.h>
-#include <sys/syscall.h>
-
-#ifdef __NR_setresuid
-
-_syscall3(int,setresuid,uid_t,a0,uid_t,a1,uid_t,a2);
-
-#elif defined(__NR_setresuid32)
-
-static inline _syscall3(int,setresuid32,uid_t,a0,uid_t,a1,uid_t,a2);
-
-int setresuid(uid_t a0, uid_t a1, uid_t a2)
-{
- if ( sizeof(uid_t) == sizeof(uint32_t) ) {
- return setresuid32(a0,a1,a2);
- } else {
- uint32_t x0 = (a0 == (uid_t)-1) ? (uint32_t)-1 : a0;
- uint32_t x1 = (a1 == (uid_t)-1) ? (uint32_t)-1 : a1;
- uint32_t x2 = (a2 == (uid_t)-1) ? (uint32_t)-1 : a2;
-
- return setresuid32(x0,x1,x2);
- }
-}
-
-#endif
-
diff --git a/klibc/klibc/sha1hash.c b/klibc/klibc/sha1hash.c
index 600d51248c..f81e08b17c 100644
--- a/klibc/klibc/sha1hash.c
+++ b/klibc/klibc/sha1hash.c
@@ -289,7 +289,7 @@ char *mybase64(uint8_t digest[20])
int main(int argc, char** argv)
{
- int i, j;
+ int i;
SHA1_CTX context;
uint8_t digest[20], buffer[16384];
FILE* file;
diff --git a/klibc/klibc/sigaction.c b/klibc/klibc/sigaction.c
index ebd34710f1..885bc6a4a4 100644
--- a/klibc/klibc/sigaction.c
+++ b/klibc/klibc/sigaction.c
@@ -5,11 +5,7 @@
#include <signal.h>
#include <sys/syscall.h>
-#ifdef __NR_sigaction
-
-_syscall3(int,sigaction,int,sig,const struct sigaction *,act,struct sigaction *,oact);
-
-#else
+#if !defined(__NR_sigaction)
int sigaction(int sig, const struct sigaction *act, struct sigaction *oact)
{
diff --git a/klibc/klibc/sigpending.c b/klibc/klibc/sigpending.c
index afbcf3cf34..76d2b1a7f6 100644
--- a/klibc/klibc/sigpending.c
+++ b/klibc/klibc/sigpending.c
@@ -5,11 +5,7 @@
#include <signal.h>
#include <sys/syscall.h>
-#ifdef __NR_sigpending
-
-_syscall1(int,sigpending,sigset_t *,set);
-
-#else
+#ifndef __NR_sigpending
int sigpending(sigset_t *set)
{
diff --git a/klibc/klibc/sigprocmask.c b/klibc/klibc/sigprocmask.c
index 3a90f67732..b5e58b28b8 100644
--- a/klibc/klibc/sigprocmask.c
+++ b/klibc/klibc/sigprocmask.c
@@ -5,11 +5,7 @@
#include <signal.h>
#include <sys/syscall.h>
-#ifdef __NR_sigprocmask
-
-_syscall3(int,sigprocmask,int,how,const sigset_t *,set,sigset_t *,oset);
-
-#else
+#ifndef __NR_sigprocmask
int sigprocmask(int how, const sigset_t *set, sigset_t *oset)
{
diff --git a/klibc/klibc/sigsuspend.c b/klibc/klibc/sigsuspend.c
index 85cdea20ca..a927999ae6 100644
--- a/klibc/klibc/sigsuspend.c
+++ b/klibc/klibc/sigsuspend.c
@@ -5,11 +5,7 @@
#include <signal.h>
#include <sys/syscall.h>
-#ifdef __NR_sigsuspend
-
-_syscall1(int,sigsuspend,const sigset_t *,mask);
-
-#else
+#ifndef __NR_sigsuspend
int sigsuspend(const sigset_t *mask)
{
diff --git a/klibc/klibc/socketcalls.pl b/klibc/klibc/socketcalls.pl
index cf4daf6036..fd82b2b49f 100644
--- a/klibc/klibc/socketcalls.pl
+++ b/klibc/klibc/socketcalls.pl
@@ -1,17 +1,32 @@
#!/usr/bin/perl
-($arch, $file) = @ARGV;
+
+$v = $ENV{'KBUILD_VERBOSE'};
+$quiet = defined($v) ? !$v : 0;
+
+@args = ();
+for $arg ( @ARGV ) {
+ if ( $arg =~ /^-/ ) {
+ if ( $arg eq '-q' ) {
+ $quiet = 1;
+ } else {
+ die "$0: Unknown option: $arg\n";
+ }
+ } else {
+ push(@args, $arg);
+ }
+}
+($file, $arch) = @args;
if (!open(FILE, "< $file")) {
- print STDERR "$file: $!\n";
- exit(1);
+ die "$file: $!\n";
}
while ( defined($line = <FILE>) ) {
chomp $line;
- $line =~ s/\s*\#.*$//; # Strip comments and trailing blanks
+ $line =~ s/\s*[\#\;].*$//; # Strip comments and trailing blanks
next unless $line;
- if ( $line =~ /^\s*(.*)\s+([_a-zA-Z][_a-zA-Z0-9]+)\s*\((.*)\)$/ ) {
+ if ( $line =~ /^\s*\<\?\>\s*(.*)\s+([_a-zA-Z][_a-zA-Z0-9]+)\s*\((.*)\)$/ ) {
$type = $1;
$name = $2;
$argv = $3;
@@ -26,7 +41,7 @@ while ( defined($line = <FILE>) ) {
$nargs = $i;
if ( $arch eq 'i386' ) {
- open(OUT, "> socketcalls/${name}.S")
+ open(OUT, '>', "socketcalls/${name}.S")
or die "$0: Cannot open socketcalls/${name}.S\n";
print OUT "#include <sys/socketcalls.h>\n";
@@ -39,33 +54,31 @@ while ( defined($line = <FILE>) ) {
print OUT "\tmovb \$SYS_\U${name}\E,%al\n";
print OUT "\tjmp __socketcall_common\n";
print OUT "\t.size ${name},.-${name}\n";
+ close(OUT);
} else {
- open(OUT, "> socketcalls/${name}.c")
+ open(OUT, '>', "socketcalls/${name}.c")
or die "$0: Cannot open socketcalls/${name}.c\n";
- print OUT "#include \"socketcommon.h\"\n\n";
-
- print OUT "#ifdef __NR_$name\n\n";
- print OUT "_syscall", scalar(@args), "(", $type, ',', $name;
- $i = 0;
- foreach $arg ( @args ) {
- print OUT ",", $arg, ",a",$i++;
- }
- print OUT ");\n";
- print OUT "\n#else\n\n";
-
+
+ print OUT "#include \"../socketcommon.h\"\n";
+ print OUT "\n";
+ print OUT "#ifndef __NR_${name}\n\n";
+
+ print OUT "extern long __socketcall(int, const unsigned long *);\n\n";
+
print OUT "$type $name (", join(', ', @cargs), ")\n";
print OUT "{\n";
print OUT " unsigned long args[$nargs];\n";
for ( $i = 0 ; $i < $nargs ; $i++ ) {
print OUT " args[$i] = (unsigned long)a$i;\n";
}
- print OUT " return ($type) socketcall(SYS_\U${name}\E, args);\n";
- print OUT "}\n";
- print OUT "\n#endif\n";
+ print OUT " return ($type) __socketcall(SYS_\U${name}\E, args);\n";
+ print OUT "}\n\n";
+
+ print OUT "#endif\n";
+
+ close(OUT);
}
- close(OUT);
} else {
- print STDERR "$file:$.: Could not parse input\n";
- exit(1);
+ die "$file:$.: Could not parse input\n";
}
}
diff --git a/klibc/klibc/socketcommon.h b/klibc/klibc/socketcommon.h
index 7a5acaadaf..9c4b11fab8 100644
--- a/klibc/klibc/socketcommon.h
+++ b/klibc/klibc/socketcommon.h
@@ -13,13 +13,4 @@
#include <sys/time.h>
#include <sys/socket.h>
#include <linux/net.h>
-
-/*
- * Some architectures have socketcall(), some have real syscalls,
- * and some have both, but the syscall version is always preferred.
- * Look for __NR_<call> to probe for the existence of a syscall.
- */
-
-#ifdef __NR_socketcall
-static inline _syscall2(int,socketcall,int,call,unsigned long *,args);
-#endif
+#include <sys/socketcalls.h>
diff --git a/klibc/klibc/srand48.c b/klibc/klibc/srand48.c
index a3df16d95c..5f201d2047 100644
--- a/klibc/klibc/srand48.c
+++ b/klibc/klibc/srand48.c
@@ -5,8 +5,7 @@
#include <stdlib.h>
#include <stdint.h>
-extern unsigned short __rand48_seed[3];
-
+unsigned short __rand48_seed[3]; /* Common with mrand48.c, lrand48.c */
void srand48(long seedval)
{
diff --git a/klibc/klibc/statfs.c b/klibc/klibc/statfs.c
new file mode 100644
index 0000000000..60e9188a09
--- /dev/null
+++ b/klibc/klibc/statfs.c
@@ -0,0 +1,19 @@
+/*
+ * statfs.c
+ *
+ * On architectures which do statfs64, wrap the system call
+ */
+
+#include <sys/syscall.h>
+#include <sys/vfs.h>
+
+#ifdef __NR_statfs64
+
+extern int __statfs64(const char *, size_t, struct statfs *);
+
+int statfs(const char *path, struct statfs *buf)
+{
+ return __statfs64(path, sizeof *buf, buf);
+}
+
+#endif
diff --git a/klibc/klibc/strerror.c b/klibc/klibc/strerror.c
index 62705553a6..c8e3eac793 100644
--- a/klibc/klibc/strerror.c
+++ b/klibc/klibc/strerror.c
@@ -7,18 +7,28 @@
char *strerror(int errnum)
{
static char message[32] = "error "; /* enough for error 2^63-1 */
-
char numbuf[32];
char *p;
+ unsigned int e = (unsigned int)errnum;
+
+#ifdef WITH_ERRLIST
+ extern const int sys_nerr;
+ extern const char * const sys_errlist[];
+
+ if ( e < (unsigned int)sys_nerr && sys_errlist[e] )
+ return (char *)sys_errlist[e];
+#endif
p = numbuf+sizeof numbuf;
*--p = '\0';
do {
- *--p = (errnum % 10) + '0';
- errnum /= 10;
- } while ( errnum );
+ *--p = (e % 10) + '0';
+ e /= 10;
+ } while ( e );
+
+ memcpy(message+6, p, (numbuf+sizeof numbuf)-p);
- return (char *)memcpy(message+6, p, (numbuf+sizeof numbuf)-p);
+ return message;
}
diff --git a/klibc/klibc/strlcat.c b/klibc/klibc/strlcat.c
new file mode 100644
index 0000000000..6111445f06
--- /dev/null
+++ b/klibc/klibc/strlcat.c
@@ -0,0 +1,31 @@
+/*
+ * strlcat.c
+ */
+
+#include <string.h>
+#include <klibc/compiler.h>
+
+size_t strlcat(char *dst, const char *src, size_t size)
+{
+ size_t bytes = 0;
+ char *q = dst;
+ const char *p = src;
+ char ch;
+
+ while ( bytes < size && *q ) {
+ q++;
+ bytes++;
+ }
+
+ while ( (ch = *p++) ) {
+ if ( bytes < size )
+ *q++ = ch;
+
+ bytes++;
+ }
+
+ *q = '\0';
+ return bytes;
+}
+
+
diff --git a/klibc/klibc/strlcpy.c b/klibc/klibc/strlcpy.c
new file mode 100644
index 0000000000..eb384c9885
--- /dev/null
+++ b/klibc/klibc/strlcpy.c
@@ -0,0 +1,26 @@
+/*
+ * strlcpy.c
+ */
+
+#include <string.h>
+#include <klibc/compiler.h>
+
+size_t strlcpy(char *dst, const char *src, size_t size)
+{
+ size_t bytes = 0;
+ char *q = dst;
+ const char *p = src;
+ char ch;
+
+ while ( (ch = *p++) ) {
+ if ( bytes < size )
+ *q++ = ch;
+
+ bytes++;
+ }
+
+ *q = '\0';
+ return bytes;
+}
+
+
diff --git a/klibc/klibc/strncat.c b/klibc/klibc/strncat.c
index 99d957594c..0dd9deb984 100644
--- a/klibc/klibc/strncat.c
+++ b/klibc/klibc/strncat.c
@@ -3,9 +3,23 @@
*/
#include <string.h>
+#include <klibc/compiler.h>
char *strncat(char *dst, const char *src, size_t n)
{
- strncpy(strchr(dst, '\0'), src, n);
+ char *q = strchr(dst, '\0');
+ const char *p = src;
+ char ch;
+ size_t nn = q-dst;
+
+ if ( __likely(nn <= n) )
+ n -= nn;
+
+ while (n--) {
+ *q++ = ch = *p++;
+ if ( !ch )
+ break;
+ }
+
return dst;
}
diff --git a/klibc/klibc/strncpy.c b/klibc/klibc/strncpy.c
index a8fe45fcbb..06964f31d6 100644
--- a/klibc/klibc/strncpy.c
+++ b/klibc/klibc/strncpy.c
@@ -1,7 +1,5 @@
/*
* strncpy.c
- *
- * strncpy()
*/
#include <string.h>
@@ -12,11 +10,15 @@ char *strncpy(char *dst, const char *src, size_t n)
const char *p = src;
char ch;
- while ( n-- ) {
+ while (n) {
+ n--;
*q++ = ch = *p++;
if ( !ch )
break;
}
+ /* The specs say strncpy() fills the entire buffer with NUL. Sigh. */
+ memset(q, 0, n);
+
return dst;
}
diff --git a/klibc/klibc/strnlen.c b/klibc/klibc/strnlen.c
new file mode 100644
index 0000000000..06b54c3189
--- /dev/null
+++ b/klibc/klibc/strnlen.c
@@ -0,0 +1,19 @@
+/*
+ * strnlen()
+ */
+
+#include <string.h>
+
+size_t strnlen(const char *s, size_t maxlen)
+{
+ const char *ss = s;
+
+ /* Important: the maxlen test must precede the reference through ss;
+ since the byte beyond the maximum may segfault */
+ while ((maxlen > 0) && *ss) {
+ ss++;
+ maxlen--;
+ }
+ return ss-s;
+}
+
diff --git a/klibc/klibc/strtotimespec.c b/klibc/klibc/strtotimespec.c
new file mode 100644
index 0000000000..b426bf8d0f
--- /dev/null
+++ b/klibc/klibc/strtotimespec.c
@@ -0,0 +1,5 @@
+#define NAME strtotimespec
+#define TIMEX struct timespec
+#define FSEC tv_nsec
+#define DECIMALS 9
+#include "strtotimex.c"
diff --git a/klibc/klibc/strtotimeval.c b/klibc/klibc/strtotimeval.c
new file mode 100644
index 0000000000..280d4bcd3a
--- /dev/null
+++ b/klibc/klibc/strtotimeval.c
@@ -0,0 +1,5 @@
+#define NAME strtotimeval
+#define TIMEX struct timeval
+#define FSEC tv_usec
+#define DECIMALS 6
+#include "strtotimex.c"
diff --git a/klibc/klibc/strtotimex.c b/klibc/klibc/strtotimex.c
new file mode 100644
index 0000000000..0f6c2f9181
--- /dev/null
+++ b/klibc/klibc/strtotimex.c
@@ -0,0 +1,39 @@
+/*
+ * strtotimex.c
+ *
+ * Nonstandard function which takes a string and converts it to a
+ * struct timespec/timeval. Returns a pointer to the first non-numeric
+ * character in the string.
+ *
+ */
+
+#include <ctype.h>
+#include <inttypes.h>
+#include <stdlib.h>
+#include <sys/time.h>
+
+char * NAME (const char *str, TIMEX *ts)
+{
+ int n;
+ char *s, *s0;
+ __typeof__(ts->FSEC) fs; /* Fractional seconds */
+
+ ts->tv_sec = strntoumax(str, &s, 10, ~(size_t)0);
+ fs = 0;
+
+ if ( *s == '.' ) {
+ s0 = s+1;
+
+ fs = strntoumax(s0, &s, 10, DECIMALS);
+ n = s-s0;
+
+ while ( isdigit(*s) )
+ s++;
+
+ for ( ; n < DECIMALS ; n++ )
+ fs *= 10;
+ }
+
+ ts->FSEC = fs;
+ return s;
+}
diff --git a/klibc/klibc/syscalls.pl b/klibc/klibc/syscalls.pl
index b530a9b8c7..1c48ce58ff 100644
--- a/klibc/klibc/syscalls.pl
+++ b/klibc/klibc/syscalls.pl
@@ -1,46 +1,99 @@
#!/usr/bin/perl
-($arch, $file) = @ARGV;
+#
+# Script to parse the SYSCALLS file and generate appropriate
+# stubs.
-if (!open(FILE, "< $file")) {
- print STDERR "$file: $!\n";
- exit(1);
+$v = $ENV{'KBUILD_VERBOSE'};
+$quiet = defined($v) ? !$v : 0;
+
+@args = ();
+for $arg ( @ARGV ) {
+ if ( $arg =~ /^-/ ) {
+ if ( $arg eq '-q' ) {
+ $quiet = 1;
+ } else {
+ die "$0: Unknown option: $arg\n";
+ }
+ } else {
+ push(@args, $arg);
+ }
+}
+($file, $arch, $bits, $unistd, $havesyscall) = @args;
+
+require "arch/$arch/sysstub.ph";
+
+if (!open(UNISTD, '<', $unistd)) {
+ die "$0: $unistd: $!\n";
+}
+while ( defined($line = <UNISTD>) ) {
+ chomp $line;
+
+ if ( $line =~ /^\#\s*define\s+__NR_([A-Za-z0-9_]+)\s+(.*\S)\s*$/ ) {
+ $syscalls{$1} = $2;
+ print STDERR "SYSCALL FOUND: $1\n" unless ( $quiet );
+ }
+}
+close(UNISTD);
+
+if (!open(HAVESYS, '>', $havesyscall)) {
+ die "$0: $havesyscall: $!\n";
+}
+
+print HAVESYS "#ifndef _KLIBC_HAVESYSCALL_H\n";
+print HAVESYS "#define _KLIBC_HAVESYSCALL_H 1\n\n";
+
+if (!open(FILE, '<', $file)) {
+ die "$0: $file: $!\n";
}
while ( defined($line = <FILE>) ) {
chomp $line;
- $line =~ s/\s*\#.*$//; # Strip comments and trailing blanks
+ $line =~ s/\s*(|[\#;].*)$//; # Strip comments and trailing blanks
next unless $line;
- if ( $line =~ /^\s*(\<[^\>]+\>\s+|)([^\(\<\>]+[^\@\:A-Za-z0-9_])([A-Za-z0-9_]+)(|\@[A-Za-z0-9_]+)(|\:\:[A-Za-z0-9_]+)\s*\(([^\:\)]*)\)\s*$/ ) {
- $archs = $1;
- $type = $2;
- $sname = $3;
- $stype = $4;
- $fname = $5;
- $argv = $6;
+ if ( $line =~ /^\s*(\<[^\>]+\>\s+|)([A-Za-z0-9_\*\s]+)\s+([A-Za-z0-9_,]+)(|\@[A-Za-z0-9_]+)(|\:\:[A-Za-z0-9_]+)\s*\(([^\:\)]*)\)\s*$/ ) {
+ $archs = $1;
+ $type = $2;
+ $snames = $3;
+ $stype = $4;
+ $fname = $5;
+ $argv = $6;
- $doit = 1;
+ $doit = 1;
+ $maybe = 0;
if ( $archs ne '' ) {
- die "$0: Internal error"
- unless ( $archs =~ /^\<(|\!)([^\>\!]+)\>/ );
- $not = $1;
- $list = $2;
+ die "$file:$.: Invalid architecture spec: <$archs>\n"
+ unless ( $archs =~ /^\<(|\?)(|\!)([^\>\!\?]*)\>/ );
+ $maybe = $1 ne '';
+ $not = $2 ne '';
+ $list = $3;
- $doit = ($not eq '') ? 0 : 1;
+ $doit = $not || ($list eq '');
@list = split(/,/, $list);
foreach $a ( @list ) {
- if ( $a eq $arch ) {
- $doit = ($not eq '') ? 1 : 0;
+ if ( $a eq $arch || $a eq $bits ) {
+ $doit = !$not;
last;
}
}
}
next if ( ! $doit );
- $type =~ s/\s*$//;
+ undef $sname;
+ foreach $sn ( split(/,/, $snames) ) {
+ if ( defined $syscalls{$sn} ) {
+ $sname = $sn;
+ last;
+ }
+ }
+ if ( !defined($sname) ) {
+ next if ( $maybe );
+ die "$file:$.: Undefined system call: $snames\n";
+ }
- $stype =~ s/^\@/_/;
+ $type =~ s/\s*$//;
+ $stype =~ s/^\@//;
if ( $fname eq '' ) {
$fname = $sname;
@@ -50,32 +103,12 @@ while ( defined($line = <FILE>) ) {
@args = split(/\s*\,\s*/, $argv);
- open(OUT, "> syscalls/${fname}.c")
- or die "$0: Cannot open syscalls/${fname}.c\n";
-
- if ( $fname eq "rt_sigaction") {
- print OUT "#ifdef __x86_64__\n\n";
- print OUT "struct sigaction;\n\n";
- print OUT "#endif\n\n"
- }
-
- print OUT "#include \"syscommon.h\"\n\n";
-
- if ( $fname ne $sname ) {
- print OUT "#undef __NR_${fname}\n";
- print OUT "#define __NR_${fname} __NR_${sname}\n\n";
- }
-
- print OUT "_syscall", scalar(@args), $stype, "(", $type, ',', $fname;
-
- $i = 0;
- foreach $arg ( @args ) {
- print OUT ",", $arg, ",a",$i++;
- }
- print OUT ");\n";
- close(OUT);
+ print HAVESYS "#define _KLIBC_HAVE_SYSCALL_${fname} ${sname}\n";
+ make_sysstub($fname, $type, $sname, $stype, @args);
} else {
- print STDERR "$file:$.: Could not parse input\n";
- exit(1);
+ die "$file:$.: Could not parse input: \"$line\"\n";
}
}
+
+print HAVESYS "\n#endif\n";
+close(HAVESYS);
diff --git a/klibc/klibc/syslog.c b/klibc/klibc/syslog.c
index 10a2dce405..592992ba6b 100644
--- a/klibc/klibc/syslog.c
+++ b/klibc/klibc/syslog.c
@@ -18,7 +18,7 @@
#define LOGDEV "/dev/kmsg"
/* Max length of ID string */
-#define MAXID 31
+#define MAXID 31 /* MAXID+6 must be < BUFLEN */
int __syslog_fd = -1;
static char id[MAXID+1];
@@ -43,16 +43,12 @@ void openlog(const char *ident, int option, int facility)
void vsyslog(int prio, const char *format, va_list ap)
{
char buf[BUFLEN];
- int rv, len;
+ int len;
int fd;
if ( __syslog_fd == -1 )
openlog(NULL, 0, 0);
- fd = __syslog_fd;
- if ( fd == -1 )
- fd = 2; /* Failed to open log, write to stderr */
-
buf[0] = '<';
buf[1] = LOG_PRI(prio)+'0';
buf[2] = '>';
@@ -61,13 +57,16 @@ void vsyslog(int prio, const char *format, va_list ap)
if ( *id )
len += sprintf(buf+3, "%s: ", id);
- rv = vsnprintf(buf+len, BUFLEN-len, format, ap);
+ len += vsnprintf(buf+len, BUFLEN-len, format, ap);
- len += rv;
if ( len > BUFLEN-1 ) len = BUFLEN-1;
- buf[len] = '\n';
+ buf[len++] = '\n';
+
+ fd = __syslog_fd;
+ if ( fd == -1 )
+ fd = 2; /* Failed to open log, write to stderr */
- write(fd, buf, len+1);
+ write(fd, buf, len);
}
void syslog(int prio, const char *format, ...)
diff --git a/klibc/klibc/tests/fcntl.c b/klibc/klibc/tests/fcntl.c
new file mode 100644
index 0000000000..f504ad90f7
--- /dev/null
+++ b/klibc/klibc/tests/fcntl.c
@@ -0,0 +1,53 @@
+/*
+ * Simple test of fcntl
+ */
+
+#include <stdio.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+
+int main(int argc, char *argv[])
+{
+ int fd = open(argv[0], O_RDONLY);
+ struct flock l;
+ long flags;
+
+ (void)argc;
+
+ if ( fd < 0 ) {
+ perror("open");
+ exit(1);
+ }
+
+ /* Get the flags on this FD */
+
+ if ( (flags = fcntl(fd, F_GETFL)) == -1 ) {
+ perror("F_GETFL");
+ exit(1);
+ }
+
+ if ( flags != (O_RDONLY|O_LARGEFILE) )
+ fprintf(stderr, "flags = %#lx\n", flags);
+
+ /* Set a lock on this FD */
+ memset(&l, 0, sizeof l);
+ l.l_type = F_RDLCK;
+ l.l_whence = SEEK_SET;
+ l.l_start = 123;
+ l.l_len = 456;
+
+ if ( fcntl(fd, F_SETLK, &l) == -1 ) {
+ perror("F_SETLK");
+ exit(1);
+ }
+
+ /* Eventually, fork and try to conflict with this lock... */
+
+ return 0;
+}
+
+
+
diff --git a/klibc/klibc/tests/getpagesize.c b/klibc/klibc/tests/getpagesize.c
new file mode 100644
index 0000000000..bda37e1f6b
--- /dev/null
+++ b/klibc/klibc/tests/getpagesize.c
@@ -0,0 +1,11 @@
+#include <unistd.h>
+#include <stdio.h>
+
+int main(void)
+{
+ printf("getpagesize() = %d\n"
+ "__getpageshift() = %d\n",
+ getpagesize(), __getpageshift());
+
+ return 0;
+}
diff --git a/klibc/klibc/tests/malloctest2.c b/klibc/klibc/tests/malloctest2.c
new file mode 100644
index 0000000000..b392046929
--- /dev/null
+++ b/klibc/klibc/tests/malloctest2.c
@@ -0,0 +1,60 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#define NCYCLES 32768
+#define NSLOTS 4096
+
+struct slot {
+ char *ptr;
+ size_t size;
+};
+
+struct slot s[NSLOTS];
+
+int main(void)
+{
+ size_t sp, sq;
+ char *p, *ep, *q, *eq;
+ int r, i, j;
+ int ok;
+ int err = 0;
+
+ for ( r = 0 ; r < NCYCLES ; r++ ) {
+ i = lrand48() % NSLOTS;
+
+ if ( s[i].ptr ) {
+ free(s[i].ptr);
+ printf("Freed %8zu bytes at %p\n", s[i].size, s[i].ptr);
+ s[i].ptr = NULL;
+ s[i].size = 0;
+ } else {
+ sp = lrand48(); /* 32-bit random number */
+ sp >>= 12+(lrand48() % 20);
+
+ s[i].size = sp;
+ s[i].ptr = p = malloc(sp);
+ ep = p+sp;
+ ok = 1;
+ for ( j = 0 ; j < NSLOTS ; j++ ) {
+ q = s[j].ptr;
+ if ( i != j && q ) {
+ sq = s[j].size;
+ eq = q+sq;
+
+ if ( (p < q && ep > q) || (p >= q && p < eq) ) {
+ ok = 0;
+ err = 1;
+ break;
+ }
+ }
+ }
+ printf("Allocated %8zu bytes at %p, ok = %d\n", sp, p, ok);
+
+ if ( p )
+ memset(p, 0xee, sp); /* Poison this memory */
+ }
+ }
+ return err;
+}
+
diff --git a/klibc/klibc/tests/microhello.c b/klibc/klibc/tests/microhello.c
index e57cd05a50..f0f5a40379 100644
--- a/klibc/klibc/tests/microhello.c
+++ b/klibc/klibc/tests/microhello.c
@@ -3,7 +3,7 @@
int main(void)
{
- const char hello[] = "Hello, World!\n";
+ static const char hello[] = "Hello, World!\n";
_fwrite(hello, sizeof hello-1, stdout);
return 0;
}
diff --git a/klibc/klibc/tests/minips.c b/klibc/klibc/tests/minips.c
deleted file mode 100644
index 20898270f4..0000000000
--- a/klibc/klibc/tests/minips.c
+++ /dev/null
@@ -1,453 +0,0 @@
-/*
- * Copyright 1998 by Albert Cahalan; all rights reserved.
- * This file may be used subject to the terms and conditions of the
- * GNU Library General Public License Version 2, or any later version
- * at your option, as published by the Free Software Foundation.
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Library General Public License for more details.
- */
-
-/* This is a minimal /bin/ps, designed to be smaller than the old ps
- * while still supporting some of the more important features of the
- * new ps. (for total size, note that this ps does not need libproc)
- * It is suitable for Linux-on-a-floppy systems only.
- *
- * Maintainers: do not compile or install for normal systems.
- * Anyone needing this will want to tweak their compiler anyway.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/ioctl.h>
-#include <sys/types.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <dirent.h>
-
-#include <asm/param.h> /* HZ */
-#include <asm/page.h> /* PAGE_SIZE */
-
-static int P_euid;
-static int P_pid;
-static char P_cmd[16];
-static char P_state;
-static int P_ppid, P_pgrp, P_session, P_tty, P_tpgid;
-static unsigned long P_flags, P_min_flt, P_cmin_flt, P_maj_flt, P_cmaj_flt, P_utime, P_stime;
-static long P_cutime, P_cstime, P_priority, P_nice, P_timeout, P_it_real_value;
-static unsigned long P_start_time, P_vsize;
-static long P_rss;
-static unsigned long P_rss_rlim, P_start_code, P_end_code, P_start_stack, P_kstk_esp, P_kstk_eip;
-static unsigned P_signal, P_blocked, P_sigignore, P_sigcatch;
-static unsigned long P_wchan, P_nswap, P_cnswap;
-
-
-#if 0
-static int screen_cols = 80;
-static int w_count;
-#endif
-
-static int want_one_pid;
-static const char *want_one_command;
-static int select_notty;
-static int select_all;
-
-static int ps_format;
-static int old_h_option;
-
-/* we only pretend to support this */
-static int show_args; /* implicit with -f and all BSD options */
-static int bsd_c_option; /* this option overrides the above */
-
-static int ps_argc; /* global argc */
-static char **ps_argv; /* global argv */
-static int thisarg; /* index into ps_argv */
-static char *flagptr; /* current location in ps_argv[thisarg] */
-
-
-#ifndef PAGE_SIZE
-#warning PAGE_SIZE not defined, assuming it is 4096
-#define PAGE_SIZE 4096
-#endif
-
-#ifndef HZ
-#warning HZ not defined, assuming it is 100
-#define HZ 100
-#endif
-
-
-
-static void usage(void){
- fprintf(stderr,
- "-C select by command name (minimal ps only accepts one)\n"
- "-p select by process ID (minimal ps only accepts one)\n"
- "-e all processes (same as ax)\n"
- "a all processes w/ tty, including other users\n"
- "x processes w/o controlling ttys\n"
- "-f full format\n"
- "-j,j job control format\n"
- "v virtual memory format\n"
- "-l,l long format\n"
- "u user-oriented format\n"
- "-o user-defined format (limited support, only \"ps -o pid=\")\n"
- "h no header\n"
-/*
- "-A all processes (same as ax)\n"
- "c true command name\n"
- "-w,w wide output\n"
-*/
- );
- exit(1);
-}
-
-/*
- * Return the next argument, or call the usage function.
- * This handles both: -oFOO -o FOO
- */
-static const char *get_opt_arg(void){
- const char *ret;
- ret = flagptr+1; /* assume argument is part of ps_argv[thisarg] */
- if(*ret) return ret;
- if(++thisarg >= ps_argc) usage(); /* there is nothing left */
- /* argument is the new ps_argv[thisarg] */
- ret = ps_argv[thisarg];
- if(!ret || !*ret) usage();
- return ret;
-}
-
-
-/* return the PID, or 0 if nothing good */
-static void parse_pid(const char *str){
- char *endp;
- int num;
- if(!str) goto bad;
- num = strtol(str, &endp, 0);
- if(*endp != '\0') goto bad;
- if(num<1) goto bad;
- if(want_one_pid) goto bad;
- want_one_pid = num;
- return;
-bad:
- usage();
-}
-
-/***************** parse SysV options, including Unix98 *****************/
-static void parse_sysv_option(void){
- do{
- switch(*flagptr){
- /**** selection ****/
- case 'C': /* end */
- if(want_one_command) usage();
- want_one_command = get_opt_arg();
- return; /* can't have any more options */
- case 'p': /* end */
- parse_pid(get_opt_arg());
- return; /* can't have any more options */
- case 'A':
- case 'e':
- select_all++;
- select_notty++;
-case 'w': /* here for now, since the real one is not used */
- break;
- /**** output format ****/
- case 'f':
- show_args = 1;
- /* FALL THROUGH */
- case 'j':
- case 'l':
- if(ps_format) usage();
- ps_format = *flagptr;
- break;
- case 'o': /* end */
- /* We only support a limited form: "ps -o pid=" (yes, just "pid=") */
- if(strcmp(get_opt_arg(),"pid=")) usage();
- if(ps_format) usage();
- ps_format = 'o';
- old_h_option++;
- return; /* can't have any more options */
- /**** other stuff ****/
-#if 0
- case 'w':
- w_count++;
- break;
-#endif
- default:
- usage();
- } /* switch */
- }while(*++flagptr);
-}
-
-/************************* parse BSD options **********************/
-static void parse_bsd_option(void){
- do{
- switch(*flagptr){
- /**** selection ****/
- case 'a':
- select_all++;
- break;
- case 'x':
- select_notty++;
- break;
- case 'p': /* end */
- parse_pid(get_opt_arg());
- return; /* can't have any more options */
- /**** output format ****/
- case 'j':
- case 'l':
- case 'u':
- case 'v':
- if(ps_format) usage();
- ps_format = 0x80 | *flagptr; /* use 0x80 to tell BSD from SysV */
- break;
- /**** other stuff ****/
- case 'c':
- bsd_c_option++;
-#if 0
- break;
-#endif
- case 'w':
-#if 0
- w_count++;
-#endif
- break;
- case 'h':
- old_h_option++;
- break;
- default:
- usage();
- } /* switch */
- }while(*++flagptr);
-}
-
-#if 0
-/* not used yet */
-static void choose_dimensions(void){
- struct winsize ws;
- char *columns;
- /* screen_cols is 80 by default */
- if(ioctl(1, TIOCGWINSZ, &ws) != -1 && ws.ws_col>30) screen_cols = ws.ws_col;
- columns = getenv("COLUMNS");
- if(columns && *columns){
- long t;
- char *endptr;
- t = strtol(columns, &endptr, 0);
- if(!*endptr && (t>30) && (t<(long)999999999)) screen_cols = (int)t;
- }
- if(w_count && (screen_cols<132)) screen_cols=132;
- if(w_count>1) screen_cols=999999999;
-}
-#endif
-
-static void arg_parse(int argc, char *argv[]){
- int sel = 0; /* to verify option sanity */
- ps_argc = argc;
- ps_argv = argv;
- thisarg = 0;
- /**** iterate over the args ****/
- while(++thisarg < ps_argc){
- flagptr = ps_argv[thisarg];
- switch(*flagptr){
- case '0' ... '9':
- show_args = 1;
- parse_pid(flagptr);
- break;
- case '-':
- flagptr++;
- parse_sysv_option();
- break;
- default:
- show_args = 1;
- parse_bsd_option();
- break;
- }
- }
- /**** sanity check and clean-up ****/
- if(want_one_pid) sel++;
- if(want_one_command) sel++;
- if(select_notty || select_all) sel++;
- if(sel>1 || select_notty>1 || select_all>1 || bsd_c_option>1 || old_h_option>1) usage();
- if(bsd_c_option) show_args = 0;
-}
-
-/* return 1 if it works, or 0 for failure */
-static int stat2proc(int pid) {
- char buf[800]; /* about 40 fields, 64-bit decimal is about 20 chars */
- int num;
- int fd;
- char* tmp;
- struct stat sb; /* stat() used to get EUID */
- snprintf(buf, 32, "/proc/%d/stat", pid);
- if ( (fd = open(buf, O_RDONLY, 0) ) == -1 ) return 0;
- num = read(fd, buf, sizeof buf - 1);
- fstat(fd, &sb);
- P_euid = sb.st_uid;
- close(fd);
- if(num<80) return 0;
- buf[num] = '\0';
- tmp = strrchr(buf, ')'); /* split into "PID (cmd" and "<rest>" */
- *tmp = '\0'; /* replace trailing ')' with NUL */
- /* parse these two strings separately, skipping the leading "(". */
- memset(P_cmd, 0, sizeof P_cmd); /* clear */
- sscanf(buf, "%d (%15c", &P_pid, P_cmd); /* comm[16] in kernel */
- num = sscanf(tmp + 2, /* skip space after ')' too */
- "%c "
- "%d %d %d %d %d "
- "%lu %lu %lu %lu %lu %lu %lu "
- "%ld %ld %ld %ld %ld %ld "
- "%lu %lu "
- "%ld "
- "%lu %lu %lu %lu %lu %lu "
- "%u %u %u %u " /* no use for RT signals */
- "%lu %lu %lu",
- &P_state,
- &P_ppid, &P_pgrp, &P_session, &P_tty, &P_tpgid,
- &P_flags, &P_min_flt, &P_cmin_flt, &P_maj_flt, &P_cmaj_flt, &P_utime, &P_stime,
- &P_cutime, &P_cstime, &P_priority, &P_nice, &P_timeout, &P_it_real_value,
- &P_start_time, &P_vsize,
- &P_rss,
- &P_rss_rlim, &P_start_code, &P_end_code, &P_start_stack, &P_kstk_esp, &P_kstk_eip,
- &P_signal, &P_blocked, &P_sigignore, &P_sigcatch,
- &P_wchan, &P_nswap, &P_cnswap
- );
-/* fprintf(stderr, "stat2proc converted %d fields.\n",num); */
- P_vsize /= 1024;
- P_rss *= (PAGE_SIZE/1024);
- if(num < 30) return 0;
- if(P_pid != pid) return 0;
- return 1;
-}
-
-static const char *do_time(unsigned long t){
- int hh,mm,ss;
- static char buf[32];
- int cnt = 0;
- t /= HZ;
- ss = t%60;
- t /= 60;
- mm = t%60;
- t /= 60;
- hh = t%24;
- t /= 24;
- if(t) cnt = snprintf(buf, sizeof buf, "%d-", (int)t);
- snprintf(cnt + buf, sizeof(buf)-cnt, "%02d:%02d:%02d", hh, mm, ss);
- return buf;
-}
-
-static void print_proc(void){
- char tty[16];
- snprintf(tty, sizeof tty, "%3d,%-3d", (P_tty>>8)&0xff, P_tty&0xff);
- switch(ps_format){
- case 0:
- printf("%5d %s %s", P_pid, tty, do_time(P_utime+P_stime));
- break;
- case 'o':
- printf("%d\n", P_pid);
- return; /* don't want the command */
- case 'l':
- printf(
- "%03x %c %5d %5d %5d - %3d %3d - "
- "%5ld %06x %s %s",
- (unsigned)P_flags&0x777, P_state, P_euid, P_pid, P_ppid,
- (int)P_priority, (int)P_nice, P_vsize/(PAGE_SIZE/1024),
- (unsigned)(P_wchan&0xffffff), tty, do_time(P_utime+P_stime)
- );
- break;
- case 'f':
- printf(
- "%5d %5d %5d - - %s %s",
- P_euid, P_pid, P_ppid, tty, do_time(P_utime+P_stime)
- );
- break;
- case 'j':
- printf(
- "%5d %5d %5d %s %s",
- P_pid, P_pgrp, P_session, tty, do_time(P_utime+P_stime)
- );
- break;
- case 'u'|0x80:
- printf(
- "%5d %5d - - %5ld %5ld %s %c - %s",
- P_euid, P_pid, P_vsize, P_rss, tty, P_state,
- do_time(P_utime+P_stime)
- );
- break;
- case 'v'|0x80:
- printf(
- "%5d %s %c %s %6d - - %5d -",
- P_pid, tty, P_state, do_time(P_utime+P_stime), (int)P_maj_flt,
- (int)P_rss
- );
- break;
- case 'j'|0x80:
- printf(
- "%5d %5d %5d %5d %s %5d %c %5d %s",
- P_ppid, P_pid, P_pgrp, P_session, tty, P_tpgid, P_state, P_euid, do_time(P_utime+P_stime)
- );
- break;
- case 'l'|0x80:
- printf(
- "%03x %5d %5d %5d %3d %3d "
- "%5ld %4ld %06x %c %s %s",
- (unsigned)P_flags&0x777, P_euid, P_pid, P_ppid, (int)P_priority, (int)P_nice,
- P_vsize, P_rss, (unsigned)(P_wchan&0xffffff), P_state, tty, do_time(P_utime+P_stime)
- );
- break;
- default:
- break;
- }
- if(show_args) printf(" [%s]\n", P_cmd);
- else printf(" %s\n", P_cmd);
-}
-
-
-int main(int argc, char *argv[]){
- arg_parse(argc, argv);
-#if 0
- choose_dimensions();
-#endif
- if(!old_h_option){
- const char *head;
- switch(ps_format){
- default: /* can't happen */
- case 0: head = " PID TTY TIME CMD"; break;
- case 'l': head = " F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD"; break;
- case 'f': head = " UID PID PPID C STIME TTY TIME CMD"; break;
- case 'j': head = " PID PGID SID TTY TIME CMD"; break;
- case 'u'|0x80: head = " UID PID %CPU %MEM VSZ RSS TTY S START TIME COMMAND"; break;
- case 'v'|0x80: head = " PID TTY S TIME MAJFL TRS DRS RSS %MEM COMMAND"; break;
- case 'j'|0x80: head = " PPID PID PGID SID TTY TPGID S UID TIME COMMAND"; break;
- case 'l'|0x80: head = " F UID PID PPID PRI NI VSZ RSS WCHAN S TTY TIME COMMAND"; break;
- }
- printf("%s\n",head);
- }
- if(want_one_pid){
- if(stat2proc(want_one_pid)) print_proc();
- else exit(1);
- }else{
- struct dirent *ent; /* dirent handle */
- DIR *dir;
- int ouruid;
- int found_a_proc;
- found_a_proc = 0;
- ouruid = getuid();
- dir = opendir("/proc");
- while(( ent = readdir(dir) )){
- if(*ent->d_name<'0' || *ent->d_name>'9') continue;
- if(!stat2proc(atoi(ent->d_name))) continue;
- if(want_one_command){
- if(strcmp(want_one_command,P_cmd)) continue;
- }else{
- if(!select_notty && P_tty==-1) continue;
- if(!select_all && P_euid!=ouruid) continue;
- }
- found_a_proc++;
- print_proc();
- }
- closedir(dir);
- exit(!found_a_proc);
- }
- return 0;
-}
diff --git a/klibc/klibc/tests/mmaptest.c b/klibc/klibc/tests/mmaptest.c
new file mode 100644
index 0000000000..a654affb83
--- /dev/null
+++ b/klibc/klibc/tests/mmaptest.c
@@ -0,0 +1,28 @@
+/*
+ * mmaptest.c
+ *
+ * Test some simple cases of mmap()
+ */
+
+#include <sys/mman.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <errno.h>
+#include <stdint.h>
+#include <sys/syscall.h>
+
+int main(int argc, char *argv[])
+{
+ void *foo;
+
+ (void)argc; (void)argv;
+
+ /* Important case, this is how we get memory for malloc() */
+ errno = 0;
+ foo = mmap(0, 65536, PROT_READ|PROT_WRITE,
+ MAP_PRIVATE|MAP_ANONYMOUS, 0, 0);
+
+ printf("mmap() returned %p, errno = %d\n", foo, errno);
+
+ return 0;
+}
diff --git a/klibc/klibc/tests/opentest.c b/klibc/klibc/tests/opentest.c
new file mode 100644
index 0000000000..5a54d2fce2
--- /dev/null
+++ b/klibc/klibc/tests/opentest.c
@@ -0,0 +1,17 @@
+#include <stdio.h>
+
+int main(void)
+{
+ char buffer[1024];
+ FILE *f;
+
+ f = fopen("/etc/passwd", "r");
+ fgets(buffer, 1024, f);
+ fclose(f);
+
+ printf("Line 1 = %s", buffer);
+
+ return 0;
+}
+
+
diff --git a/klibc/klibc/tests/stat.c b/klibc/klibc/tests/stat.c
new file mode 100644
index 0000000000..74b0bddf44
--- /dev/null
+++ b/klibc/klibc/tests/stat.c
@@ -0,0 +1,65 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <sys/stat.h>
+#include <sys/sysmacros.h>
+#include <sys/types.h>
+
+static void do_stat(const char *path)
+{
+ struct stat st;
+
+ if ( stat(path, &st) ) {
+ perror(path);
+ exit(1);
+ }
+
+ printf("Path = %s\n"
+ " st_dev = %#jx (%u,%u)\n"
+ " st_ino = %ju\n"
+ " st_mode = %#jo\n"
+ " st_nlink = %ju\n"
+ " st_uid = %ju\n"
+ " st_gid = %ju\n"
+ " st_rdev = %#jx (%u,%u)\n"
+ " st_size = %ju\n"
+ " st_blksize = %ju\n"
+ " st_blocks = %ju\n",
+ path,
+ (uintmax_t)st.st_dev, major(st.st_dev), minor(st.st_dev),
+ (uintmax_t)st.st_ino,
+ (uintmax_t)st.st_mode,
+ (uintmax_t)st.st_nlink,
+ (uintmax_t)st.st_uid,
+ (uintmax_t)st.st_gid,
+ (uintmax_t)st.st_rdev, major(st.st_rdev), minor(st.st_rdev),
+ (uintmax_t)st.st_size,
+ (uintmax_t)st.st_blksize,
+ (uintmax_t)st.st_blocks);
+
+#ifdef _STATBUF_ST_NSEC
+ printf(" st_atim = %jd.%09u\n"
+ " st.mtim = %jd.%09u\n"
+ " st.ctim = %jd.%09u\n",
+ (uintmax_t)st.st_atim.tv_sec, (unsigned int)st.st_atim.tv_nsec,
+ (uintmax_t)st.st_mtim.tv_sec, (unsigned int)st.st_mtim.tv_nsec,
+ (uintmax_t)st.st_ctim.tv_sec, (unsigned int)st.st_ctim.tv_nsec);
+#else
+ printf(" st_atime = %jd\n"
+ " st.mtime = %jd\n"
+ " st.ctime = %jd\n",
+ (uintmax_t)st.st_atime,
+ (uintmax_t)st.st_mtime,
+ (uintmax_t)st.st_ctime);
+#endif
+}
+
+int main(int argc, char *argv[])
+{
+ int i;
+
+ for ( i = 1 ; i < argc ; i++ )
+ do_stat(argv[i]);
+
+ return 0;
+}
diff --git a/klibc/klibc/tests/statfs.c b/klibc/klibc/tests/statfs.c
new file mode 100644
index 0000000000..9b7a26d916
--- /dev/null
+++ b/klibc/klibc/tests/statfs.c
@@ -0,0 +1,43 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <sys/vfs.h>
+
+static void do_statfs(const char *path)
+{
+ struct statfs sfs;
+
+ if ( statfs(path, &sfs) ) {
+ perror(path);
+ exit(1);
+ }
+
+ printf("Path = %s\n"
+ " f_type = %#jx\n"
+ " f_bsize = %jd\n"
+ " f_blocks = %jd\n"
+ " f_bfree = %jd\n"
+ " f_bavail = %jd\n"
+ " f_files = %jd\n"
+ " f_ffree = %jd\n"
+ " f_namelen = %jd\n",
+ path,
+ (uintmax_t)sfs.f_type,
+ (intmax_t)sfs.f_bsize,
+ (intmax_t)sfs.f_blocks,
+ (intmax_t)sfs.f_bfree,
+ (intmax_t)sfs.f_bavail,
+ (intmax_t)sfs.f_files,
+ (intmax_t)sfs.f_ffree,
+ (intmax_t)sfs.f_namelen);
+}
+
+int main(int argc, char *argv[])
+{
+ int i;
+
+ for ( i = 1 ; i < argc ; i++ )
+ do_statfs(argv[i]);
+
+ return 0;
+}
diff --git a/klibc/klibc/tests/strtoimax.c b/klibc/klibc/tests/strtoimax.c
new file mode 100644
index 0000000000..5af0d7912b
--- /dev/null
+++ b/klibc/klibc/tests/strtoimax.c
@@ -0,0 +1,24 @@
+/*
+ * strtoimaxtest.c
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <inttypes.h>
+
+int main(int argc, char *argv[])
+{
+ int i;
+ char *ep;
+ intmax_t iv;
+
+ for ( i = 1 ; i < argc ; i++ ) {
+ iv = strtoimax(argv[i], &ep, 0);
+ printf("strtoimax(\"%s\") = %jd\n", argv[i], iv);
+ if ( *ep )
+ printf(" ep = \"%s\"\n", ep);
+ }
+
+ return 0;
+}
+
diff --git a/klibc/klibc/tests/strtotime.c b/klibc/klibc/tests/strtotime.c
new file mode 100644
index 0000000000..815d40da99
--- /dev/null
+++ b/klibc/klibc/tests/strtotime.c
@@ -0,0 +1,27 @@
+#include <stdio.h>
+#include <time.h>
+
+int main(int argc, char *argv[])
+{
+ struct timeval tv;
+ struct timespec ts;
+ int i;
+ const char *rv, *rs;
+
+ for ( i = 1 ; i < argc ; i++ ) {
+ rs = strtotimespec(argv[i], &ts);
+ rv = strtotimeval(argv[i], &tv);
+ printf("String: \"%s\"\n"
+ "Timespec: %ld.%09ld\n"
+ "Residual: \"%s\"\n"
+ "Timeval: %ld.%06ld\n"
+ "Residual: \"%s\"\n",
+ argv[i],
+ (long)ts.tv_sec, (long)ts.tv_nsec, rs,
+ (long)tv.tv_sec, (long)tv.tv_usec, rv);
+ }
+
+ return 0;
+}
+
+
diff --git a/klibc/klibc/time.c b/klibc/klibc/time.c
index 8f6e89738d..92f82ccee0 100644
--- a/klibc/klibc/time.c
+++ b/klibc/klibc/time.c
@@ -6,11 +6,7 @@
#include <sys/time.h>
#include <sys/syscall.h>
-#ifdef __NR_time
-
-_syscall1(time_t,time,time_t *,t);
-
-#else
+#ifndef __NR_time
time_t time(time_t *t)
{
diff --git a/klibc/klibc/utime.c b/klibc/klibc/utime.c
index a00b589629..2c8607756a 100644
--- a/klibc/klibc/utime.c
+++ b/klibc/klibc/utime.c
@@ -7,13 +7,7 @@
#include <sys/types.h>
#include <sys/syscall.h>
-#ifdef __NR_utime
-
-_syscall2(int,utime,const char *,filename,const struct utimbuf *,buf);
-
-#else
-
-static inline _syscall2(int,utimes,const char *,filename, const struct timeval *,tvp);
+#ifndef __NR_utime
int utime(const char *filename, const struct utimbuf *buf)
{
diff --git a/klibc/klibc/vasprintf.c b/klibc/klibc/vasprintf.c
new file mode 100644
index 0000000000..5066dbbfaf
--- /dev/null
+++ b/klibc/klibc/vasprintf.c
@@ -0,0 +1,25 @@
+/*
+ * vasprintf.c
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+
+int vasprintf(char **bufp, const char *format, va_list ap)
+{
+ va_list ap1;
+ int bytes;
+ char *p;
+
+ va_copy(ap1, ap);
+
+ bytes = vsnprintf(NULL, 0, format, ap1);
+ va_end(ap1);
+
+ *bufp = p = malloc(bytes+1);
+ if ( !p )
+ return -1;
+
+ return vsnprintf(p, bytes, format, ap);
+}
diff --git a/klibc/version b/klibc/version
index 31ba1bdaa5..30a3f4aab8 100644
--- a/klibc/version
+++ b/klibc/version
@@ -1 +1 @@
-0.117
+0.181