summaryrefslogtreecommitdiff
path: root/klibc
diff options
context:
space:
mode:
authorgreg@kroah.com <greg@kroah.com>2004-10-05 18:51:53 -0700
committerGreg KH <gregkh@suse.de>2005-04-26 21:37:02 -0700
commit60d1e263f0da2976938fa54efec88ab777a6b3c3 (patch)
tree94bfcc4279827a68f90f8b63c0d458ddc753c69b /klibc
parenta0622777688ad84ef3d789e0171cfb0ca3dc21d2 (diff)
[PATCH] oops forgot to add the new klibc/include directory
Diffstat (limited to 'klibc')
-rw-r--r--klibc/include/alloca.h13
-rw-r--r--klibc/include/arch/alpha/klibc/archsetjmp.h33
-rw-r--r--klibc/include/arch/alpha/klibc/archsignal.h13
-rw-r--r--klibc/include/arch/alpha/klibc/archstat.h26
-rw-r--r--klibc/include/arch/alpha/klibc/archsys.h53
-rw-r--r--klibc/include/arch/alpha/machine/asm.h44
-rw-r--r--klibc/include/arch/arm/klibc/archsetjmp.h14
-rw-r--r--klibc/include/arch/arm/klibc/archsignal.h13
-rw-r--r--klibc/include/arch/arm/klibc/archstat.h45
-rw-r--r--klibc/include/arch/arm/klibc/archsys.h12
-rw-r--r--klibc/include/arch/cris/klibc/archsetjmp.h24
-rw-r--r--klibc/include/arch/cris/klibc/archsignal.h13
-rw-r--r--klibc/include/arch/cris/klibc/archstat.h37
-rw-r--r--klibc/include/arch/cris/klibc/archsys.h12
-rw-r--r--klibc/include/arch/i386/klibc/archsetjmp.h19
-rw-r--r--klibc/include/arch/i386/klibc/archsignal.h13
-rw-r--r--klibc/include/arch/i386/klibc/archstat.h37
-rw-r--r--klibc/include/arch/i386/klibc/archsys.h12
-rw-r--r--klibc/include/arch/i386/klibc/diverr.h16
-rw-r--r--klibc/include/arch/i386/sys/io.h126
-rw-r--r--klibc/include/arch/i386/sys/vm86.h41
-rw-r--r--klibc/include/arch/ia64/klibc/archsetjmp.h17
-rw-r--r--klibc/include/arch/ia64/klibc/archsignal.h31
-rw-r--r--klibc/include/arch/ia64/klibc/archstat.h24
-rw-r--r--klibc/include/arch/ia64/klibc/archsys.h218
-rw-r--r--klibc/include/arch/m68k/klibc/archsignal.h13
-rw-r--r--klibc/include/arch/m68k/klibc/archstat.h37
-rw-r--r--klibc/include/arch/m68k/klibc/archsys.h12
-rw-r--r--klibc/include/arch/mips/klibc/archfcntl.h87
-rw-r--r--klibc/include/arch/mips/klibc/archsetjmp.h39
-rw-r--r--klibc/include/arch/mips/klibc/archsignal.h13
-rw-r--r--klibc/include/arch/mips/klibc/archstat.h39
-rw-r--r--klibc/include/arch/mips/klibc/archsys.h12
-rw-r--r--klibc/include/arch/mips/machine/asm.h11
-rw-r--r--klibc/include/arch/mips/sgidefs.h20
-rw-r--r--klibc/include/arch/mips/spaces.h1
-rw-r--r--klibc/include/arch/mips64/klibc/archsignal.h13
-rw-r--r--klibc/include/arch/mips64/klibc/archstat.h33
-rw-r--r--klibc/include/arch/mips64/klibc/archsys.h12
-rw-r--r--klibc/include/arch/parisc/klibc/archsignal.h24
-rw-r--r--klibc/include/arch/parisc/klibc/archstat.h27
-rw-r--r--klibc/include/arch/parisc/klibc/archsys.h12
-rw-r--r--klibc/include/arch/ppc/klibc/archsetjmp.h36
-rw-r--r--klibc/include/arch/ppc/klibc/archsignal.h13
-rw-r--r--klibc/include/arch/ppc/klibc/archstat.h28
-rw-r--r--klibc/include/arch/ppc/klibc/archsys.h61
-rw-r--r--klibc/include/arch/ppc64/klibc/archsetjmp.h36
-rw-r--r--klibc/include/arch/ppc64/klibc/archsignal.h13
-rw-r--r--klibc/include/arch/ppc64/klibc/archstat.h25
-rw-r--r--klibc/include/arch/ppc64/klibc/archsys.h52
-rw-r--r--klibc/include/arch/s390/klibc/archsetjmp.h15
-rw-r--r--klibc/include/arch/s390/klibc/archsignal.h13
-rw-r--r--klibc/include/arch/s390/klibc/archstat.h31
-rw-r--r--klibc/include/arch/s390/klibc/archsys.h41
-rw-r--r--klibc/include/arch/s390x/klibc/archsetjmp.h15
-rw-r--r--klibc/include/arch/s390x/klibc/archsignal.h13
-rw-r--r--klibc/include/arch/s390x/klibc/archstat.h24
-rw-r--r--klibc/include/arch/s390x/klibc/archsys.h41
-rw-r--r--klibc/include/arch/sh/klibc/archsetjmp.h22
-rw-r--r--klibc/include/arch/sh/klibc/archsignal.h13
-rw-r--r--klibc/include/arch/sh/klibc/archstat.h45
-rw-r--r--klibc/include/arch/sh/klibc/archsys.h12
-rw-r--r--klibc/include/arch/sparc/klibc/archsetjmp.h16
-rw-r--r--klibc/include/arch/sparc/klibc/archsignal.h13
-rw-r--r--klibc/include/arch/sparc/klibc/archstat.h35
-rw-r--r--klibc/include/arch/sparc/klibc/archsys.h10
-rw-r--r--klibc/include/arch/sparc/machine/asm.h192
-rw-r--r--klibc/include/arch/sparc/machine/frame.h138
-rw-r--r--klibc/include/arch/sparc/machine/trap.h141
-rw-r--r--klibc/include/arch/sparc64/klibc/archsetjmp.h16
-rw-r--r--klibc/include/arch/sparc64/klibc/archsignal.h13
-rw-r--r--klibc/include/arch/sparc64/klibc/archstat.h22
-rw-r--r--klibc/include/arch/sparc64/klibc/archsys.h10
-rw-r--r--klibc/include/arch/x86_64/klibc/archsetjmp.h21
-rw-r--r--klibc/include/arch/x86_64/klibc/archsignal.h13
-rw-r--r--klibc/include/arch/x86_64/klibc/archstat.h26
-rw-r--r--klibc/include/arch/x86_64/klibc/archsys.h109
-rw-r--r--klibc/include/arch/x86_64/sys/io.h126
-rw-r--r--klibc/include/arpa/inet.h24
-rw-r--r--klibc/include/assert.h22
-rw-r--r--klibc/include/bits32/bitsize/limits.h14
-rw-r--r--klibc/include/bits32/bitsize/stddef.h18
-rw-r--r--klibc/include/bits32/bitsize/stdint.h34
-rw-r--r--klibc/include/bits32/bitsize/stdintconst.h18
-rw-r--r--klibc/include/bits32/bitsize/stdintlimits.h22
-rw-r--r--klibc/include/bits64/bitsize/limits.h14
-rw-r--r--klibc/include/bits64/bitsize/stddef.h13
-rw-r--r--klibc/include/bits64/bitsize/stdint.h36
-rw-r--r--klibc/include/bits64/bitsize/stdintconst.h18
-rw-r--r--klibc/include/bits64/bitsize/stdintlimits.h22
-rw-r--r--klibc/include/ctype.h119
-rw-r--r--klibc/include/dirent.h32
-rw-r--r--klibc/include/elf.h12
-rw-r--r--klibc/include/endian.h42
-rw-r--r--klibc/include/errno.h8
-rw-r--r--klibc/include/fcntl.h46
-rw-r--r--klibc/include/grp.h13
-rw-r--r--klibc/include/inttypes.h226
-rw-r--r--klibc/include/klibc/compiler.h119
-rw-r--r--klibc/include/klibc/diverr.h16
-rw-r--r--klibc/include/klibc/extern.h14
-rw-r--r--klibc/include/klibc/sysconfig.h34
-rw-r--r--klibc/include/limits.h40
-rw-r--r--klibc/include/net/if.h1
-rw-r--r--klibc/include/net/if_arp.h1
-rw-r--r--klibc/include/net/if_ether.h1
-rw-r--r--klibc/include/net/if_packet.h1
-rw-r--r--klibc/include/netinet/in.h39
-rw-r--r--klibc/include/netinet/in6.h10
-rw-r--r--klibc/include/netinet/ip.h13
-rw-r--r--klibc/include/netinet/tcp.h11
-rw-r--r--klibc/include/netinet/udp.h19
-rw-r--r--klibc/include/paths.h74
-rw-r--r--klibc/include/poll.h16
-rw-r--r--klibc/include/sched.h34
-rw-r--r--klibc/include/setjmp.h43
-rw-r--r--klibc/include/signal.h81
-rw-r--r--klibc/include/stdarg.h14
-rw-r--r--klibc/include/stddef.h24
-rw-r--r--klibc/include/stdint.h116
-rw-r--r--klibc/include/stdio.h123
-rw-r--r--klibc/include/stdlib.h90
-rw-r--r--klibc/include/string.h43
-rw-r--r--klibc/include/sys/dirent.h21
-rw-r--r--klibc/include/sys/elf32.h115
-rw-r--r--klibc/include/sys/elf64.h115
-rw-r--r--klibc/include/sys/elfcommon.h188
-rw-r--r--klibc/include/sys/fsuid.h14
-rw-r--r--klibc/include/sys/ioctl.h14
-rw-r--r--klibc/include/sys/klog.h24
-rw-r--r--klibc/include/sys/mman.h25
-rw-r--r--klibc/include/sys/mount.h55
-rw-r--r--klibc/include/sys/param.h11
-rw-r--r--klibc/include/sys/reboot.h25
-rw-r--r--klibc/include/sys/resource.h15
-rw-r--r--klibc/include/sys/select.h13
-rw-r--r--klibc/include/sys/socket.h50
-rw-r--r--klibc/include/sys/socketcalls.h28
-rw-r--r--klibc/include/sys/stat.h31
-rw-r--r--klibc/include/sys/statfs.h1
-rw-r--r--klibc/include/sys/syscall.h17
-rw-r--r--klibc/include/sys/sysinfo.h12
-rw-r--r--klibc/include/sys/sysmacros.h31
-rw-r--r--klibc/include/sys/time.h18
-rw-r--r--klibc/include/sys/times.h14
-rw-r--r--klibc/include/sys/types.h104
-rw-r--r--klibc/include/sys/uio.h15
-rw-r--r--klibc/include/sys/un.h10
-rw-r--r--klibc/include/sys/utime.h10
-rw-r--r--klibc/include/sys/utsname.h23
-rw-r--r--klibc/include/sys/vfs.h111
-rw-r--r--klibc/include/sys/wait.h28
-rw-r--r--klibc/include/syslog.h55
-rw-r--r--klibc/include/termios.h86
-rw-r--r--klibc/include/time.h18
-rw-r--r--klibc/include/unistd.h140
-rw-r--r--klibc/include/utime.h15
157 files changed, 5943 insertions, 0 deletions
diff --git a/klibc/include/alloca.h b/klibc/include/alloca.h
new file mode 100644
index 0000000000..41a4d94d44
--- /dev/null
+++ b/klibc/include/alloca.h
@@ -0,0 +1,13 @@
+/*
+ * 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/include/arch/alpha/klibc/archsetjmp.h b/klibc/include/arch/alpha/klibc/archsetjmp.h
new file mode 100644
index 0000000000..9dc570a6f5
--- /dev/null
+++ b/klibc/include/arch/alpha/klibc/archsetjmp.h
@@ -0,0 +1,33 @@
+/*
+ * arch/alpha/include/klibc/archsetjmp.h
+ */
+
+#ifndef _KLIBC_ARCHSETJMP_H
+#define _KLIBC_ARCHSETJMP_H
+
+struct __jmp_buf {
+ unsigned long __s0;
+ unsigned long __s1;
+ unsigned long __s2;
+ unsigned long __s3;
+ unsigned long __s4;
+ unsigned long __s5;
+ unsigned long __fp;
+ unsigned long __ra;
+ unsigned long __gp;
+ unsigned long __sp;
+
+ unsigned long __f2;
+ unsigned long __f3;
+ unsigned long __f4;
+ unsigned long __f5;
+ unsigned long __f6;
+ unsigned long __f7;
+ unsigned long __f8;
+ unsigned long __f9;
+};
+
+/* Must be an array so it will decay to a pointer when a function is called */
+typedef struct __jmp_buf jmp_buf[1];
+
+#endif /* _KLIBC_ARCHSETJMP_H */
diff --git a/klibc/include/arch/alpha/klibc/archsignal.h b/klibc/include/arch/alpha/klibc/archsignal.h
new file mode 100644
index 0000000000..b870a05131
--- /dev/null
+++ b/klibc/include/arch/alpha/klibc/archsignal.h
@@ -0,0 +1,13 @@
+/*
+ * 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/include/arch/alpha/klibc/archstat.h b/klibc/include/arch/alpha/klibc/archstat.h
new file mode 100644
index 0000000000..23302d737d
--- /dev/null
+++ b/klibc/include/arch/alpha/klibc/archstat.h
@@ -0,0 +1,26 @@
+#ifndef _KLIBC_ARCHSTAT_H
+#define _KLIBC_ARCHSTAT_H
+
+#define _STATBUF_ST_NSEC
+
+struct stat {
+ unsigned long st_dev;
+ unsigned long st_ino;
+ unsigned long st_rdev;
+ long st_size;
+ unsigned long st_blocks;
+
+ unsigned int st_mode;
+ unsigned int st_uid;
+ unsigned int st_gid;
+ unsigned int st_blksize;
+ unsigned int st_nlink;
+ unsigned int __pad0;
+
+ struct timespec st_atim;
+ struct timespec st_mtim;
+ struct timespec st_ctim;
+ long __unused[3];
+};
+
+#endif
diff --git a/klibc/include/arch/alpha/klibc/archsys.h b/klibc/include/arch/alpha/klibc/archsys.h
new file mode 100644
index 0000000000..16ed658987
--- /dev/null
+++ b/klibc/include/arch/alpha/klibc/archsys.h
@@ -0,0 +1,53 @@
+/*
+ * arch/alpha/include/klibc/archsys.h
+ *
+ * Architecture-specific syscall definitions
+ */
+
+#ifndef _KLIBC_ARCHSYS_H
+#define _KLIBC_ARCHSYS_H
+
+/* Alpha has some bizarre Tru64-derived system calls which return two
+ different values in $0 and $20(!), respectively. The standard
+ macros can't deal with these; even the ones that give the right
+ return value have the wrong clobbers. */
+
+#define _syscall0_dual0(type, name) \
+type name(void) \
+{ \
+ long _sc_ret, _sc_err; \
+ { \
+ register long _sc_0 __asm__("$0"); \
+ register long _sc_19 __asm__("$19"); \
+ register long _sc_20 __asm__("$20"); \
+ \
+ _sc_0 = __NR_##name; \
+ __asm__("callsys" \
+ : "=r"(_sc_0), "=r"(_sc_19), "=r" (_sc_20) \
+ : "0"(_sc_0) \
+ : _syscall_clobbers); \
+ _sc_ret = _sc_0, _sc_err = _sc_19; (void)(_sc_20); \
+ } \
+ _syscall_return(type); \
+}
+
+#define _syscall0_dual1(type, name) \
+type name(void) \
+{ \
+ long _sc_ret, _sc_err; \
+ { \
+ register long _sc_0 __asm__("$0"); \
+ register long _sc_19 __asm__("$19"); \
+ register long _sc_20 __asm__("$20"); \
+ \
+ _sc_0 = __NR_##name; \
+ __asm__("callsys" \
+ : "=r"(_sc_0), "=r"(_sc_19), "=r" (_sc_20) \
+ : "0"(_sc_0) \
+ : _syscall_clobbers); \
+ _sc_ret = _sc_20, _sc_err = _sc_19; (void)(_sc_0); \
+ } \
+ _syscall_return(type); \
+}
+
+#endif /* _KLIBC_ARCHSYS_H */
diff --git a/klibc/include/arch/alpha/machine/asm.h b/klibc/include/arch/alpha/machine/asm.h
new file mode 100644
index 0000000000..e22db90412
--- /dev/null
+++ b/klibc/include/arch/alpha/machine/asm.h
@@ -0,0 +1,44 @@
+/*
+ * machine/asm.h
+ */
+
+#ifndef _MACHINE_ASM_H
+#define _MACHINE_ASM_H
+
+/* Standard aliases for Alpha register names */
+
+#define v0 $0
+#define t0 $1
+#define t1 $2
+#define t2 $3
+#define t3 $4
+#define t4 $5
+#define t5 $6
+#define t6 $7
+#define t7 $8
+#define s0 $9
+#define s1 $10
+#define s2 $11
+#define s3 $12
+#define s4 $13
+#define s5 $14
+#define fp $15
+#define a0 $16
+#define a1 $17
+#define a2 $18
+#define a3 $19
+#define a4 $20
+#define a5 $21
+#define t8 $22
+#define t9 $23
+#define t10 $24
+#define t11 $25
+#define ra $26
+#define t12 $27 /* t12 and pv are both used for $27 */
+#define pv $27 /* t12 and pv are both used for $27 */
+#define at $28
+#define gp $29
+#define sp $30
+#define zero $31
+
+#endif /* _MACHINE_ASM_H */
diff --git a/klibc/include/arch/arm/klibc/archsetjmp.h b/klibc/include/arch/arm/klibc/archsetjmp.h
new file mode 100644
index 0000000000..c956b50a90
--- /dev/null
+++ b/klibc/include/arch/arm/klibc/archsetjmp.h
@@ -0,0 +1,14 @@
+/*
+ * arch/i386/include/klibc/archsetjmp.h
+ */
+
+#ifndef _KLIBC_ARCHSETJMP_H
+#define _KLIBC_ARCHSETJMP_H
+
+struct __jmp_buf {
+ unsigned int regs[10];
+};
+
+typedef struct __jmp_buf jmp_buf[1];
+
+#endif /* _SETJMP_H */
diff --git a/klibc/include/arch/arm/klibc/archsignal.h b/klibc/include/arch/arm/klibc/archsignal.h
new file mode 100644
index 0000000000..77685e62f0
--- /dev/null
+++ b/klibc/include/arch/arm/klibc/archsignal.h
@@ -0,0 +1,13 @@
+/*
+ * 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/include/arch/arm/klibc/archstat.h b/klibc/include/arch/arm/klibc/archstat.h
new file mode 100644
index 0000000000..42b1409f67
--- /dev/null
+++ b/klibc/include/arch/arm/klibc/archstat.h
@@ -0,0 +1,45 @@
+#ifndef _KLIBC_ARCHSTAT_H
+#define _KLIBC_ARCHSTAT_H
+
+#include <endian.h>
+
+#define _STATBUF_ST_NSEC
+
+/* This matches struct stat64 in glibc2.1, hence the absolutely
+ * insane amounts of padding around dev_t's.
+ * Note: The kernel zero's the padded region because glibc might read them
+ * in the hope that the kernel has stretched to using larger sizes.
+ */
+struct stat {
+ unsigned long long st_dev;
+ unsigned char __pad0[4];
+
+ unsigned long __st_ino;
+ unsigned int st_mode;
+ unsigned int st_nlink;
+
+ unsigned long st_uid;
+ unsigned long st_gid;
+
+ unsigned long long st_rdev;
+ unsigned char __pad3[4];
+
+ long long st_size;
+ unsigned long st_blksize;
+
+#if __BYTE_ORDER == __BIG_ENDIAN
+ unsigned long __pad4; /* Future possible st_blocks hi bits */
+ unsigned long st_blocks; /* Number 512-byte blocks allocated. */
+#else /* Must be little */
+ unsigned long st_blocks; /* Number 512-byte blocks allocated. */
+ unsigned long __pad4; /* Future possible st_blocks hi bits */
+#endif
+
+ struct timespec st_atim;
+ struct timespec st_mtim;
+ struct timespec st_ctim;
+
+ unsigned long long st_ino;
+};
+
+#endif
diff --git a/klibc/include/arch/arm/klibc/archsys.h b/klibc/include/arch/arm/klibc/archsys.h
new file mode 100644
index 0000000000..dfdc70a6de
--- /dev/null
+++ b/klibc/include/arch/arm/klibc/archsys.h
@@ -0,0 +1,12 @@
+/*
+ * arch/cris/include/klibc/archsys.h
+ *
+ * Architecture-specific syscall definitions
+ */
+
+#ifndef _KLIBC_ARCHSYS_H
+#define _KLIBC_ARCHSYS_H
+
+/* No special syscall definitions for this architecture */
+
+#endif /* _KLIBC_ARCHSYS_H */
diff --git a/klibc/include/arch/cris/klibc/archsetjmp.h b/klibc/include/arch/cris/klibc/archsetjmp.h
new file mode 100644
index 0000000000..8d20800609
--- /dev/null
+++ b/klibc/include/arch/cris/klibc/archsetjmp.h
@@ -0,0 +1,24 @@
+/*
+ * arch/cris/include/klibc/archsetjmp.h
+ */
+
+#ifndef _KLIBC_ARCHSETJMP_H
+#define _KLIBC_ARCHSETJMP_H
+
+struct __jmp_buf {
+ unsigned long __r0;
+ unsigned long __r1;
+ unsigned long __r2;
+ unsigned long __r3;
+ unsigned long __r4;
+ unsigned long __r5;
+ unsigned long __r6;
+ unsigned long __r7;
+ unsigned long __r8;
+ unsigned long __sp;
+ unsigned long __srp;
+};
+
+typedef struct __jmp_buf jmp_buf[1];
+
+#endif /* _KLIBC_ARCHSETJMP_H */
diff --git a/klibc/include/arch/cris/klibc/archsignal.h b/klibc/include/arch/cris/klibc/archsignal.h
new file mode 100644
index 0000000000..73b2e196c9
--- /dev/null
+++ b/klibc/include/arch/cris/klibc/archsignal.h
@@ -0,0 +1,13 @@
+/*
+ * 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/include/arch/cris/klibc/archstat.h b/klibc/include/arch/cris/klibc/archstat.h
new file mode 100644
index 0000000000..154820755f
--- /dev/null
+++ b/klibc/include/arch/cris/klibc/archstat.h
@@ -0,0 +1,37 @@
+#ifndef _KLIBC_ARCHSTAT_H
+#define _KLIBC_ARCHSTAT_H
+
+#define _STATBUF_ST_NSEC
+
+/* This matches struct stat64 in glibc2.1, hence the absolutely
+ * insane amounts of padding around dev_t's.
+ */
+struct stat {
+ unsigned long long st_dev;
+ unsigned char __pad0[4];
+
+ unsigned long __st_ino;
+
+ unsigned int st_mode;
+ unsigned int st_nlink;
+
+ unsigned long st_uid;
+ unsigned long st_gid;
+
+ unsigned long long st_rdev;
+ unsigned char __pad3[4];
+
+ long long st_size;
+ unsigned long st_blksize;
+
+ unsigned long st_blocks; /* Number 512-byte blocks allocated. */
+ unsigned long __pad4; /* future possible st_blocks high bits */
+
+ struct timespec st_atim;
+ struct timespec st_mtim;
+ struct timespec st_ctim;
+
+ unsigned long long st_ino;
+};
+
+#endif
diff --git a/klibc/include/arch/cris/klibc/archsys.h b/klibc/include/arch/cris/klibc/archsys.h
new file mode 100644
index 0000000000..dfdc70a6de
--- /dev/null
+++ b/klibc/include/arch/cris/klibc/archsys.h
@@ -0,0 +1,12 @@
+/*
+ * arch/cris/include/klibc/archsys.h
+ *
+ * Architecture-specific syscall definitions
+ */
+
+#ifndef _KLIBC_ARCHSYS_H
+#define _KLIBC_ARCHSYS_H
+
+/* No special syscall definitions for this architecture */
+
+#endif /* _KLIBC_ARCHSYS_H */
diff --git a/klibc/include/arch/i386/klibc/archsetjmp.h b/klibc/include/arch/i386/klibc/archsetjmp.h
new file mode 100644
index 0000000000..db04314b8c
--- /dev/null
+++ b/klibc/include/arch/i386/klibc/archsetjmp.h
@@ -0,0 +1,19 @@
+/*
+ * arch/i386/include/klibc/archsetjmp.h
+ */
+
+#ifndef _KLIBC_ARCHSETJMP_H
+#define _KLIBC_ARCHSETJMP_H
+
+struct __jmp_buf {
+ unsigned int __ebx;
+ unsigned int __esp;
+ unsigned int __ebp;
+ unsigned int __esi;
+ unsigned int __edi;
+ unsigned int __eip;
+};
+
+typedef struct __jmp_buf jmp_buf[1];
+
+#endif /* _SETJMP_H */
diff --git a/klibc/include/arch/i386/klibc/archsignal.h b/klibc/include/arch/i386/klibc/archsignal.h
new file mode 100644
index 0000000000..b092ba6d3a
--- /dev/null
+++ b/klibc/include/arch/i386/klibc/archsignal.h
@@ -0,0 +1,13 @@
+/*
+ * 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/include/arch/i386/klibc/archstat.h b/klibc/include/arch/i386/klibc/archstat.h
new file mode 100644
index 0000000000..154820755f
--- /dev/null
+++ b/klibc/include/arch/i386/klibc/archstat.h
@@ -0,0 +1,37 @@
+#ifndef _KLIBC_ARCHSTAT_H
+#define _KLIBC_ARCHSTAT_H
+
+#define _STATBUF_ST_NSEC
+
+/* This matches struct stat64 in glibc2.1, hence the absolutely
+ * insane amounts of padding around dev_t's.
+ */
+struct stat {
+ unsigned long long st_dev;
+ unsigned char __pad0[4];
+
+ unsigned long __st_ino;
+
+ unsigned int st_mode;
+ unsigned int st_nlink;
+
+ unsigned long st_uid;
+ unsigned long st_gid;
+
+ unsigned long long st_rdev;
+ unsigned char __pad3[4];
+
+ long long st_size;
+ unsigned long st_blksize;
+
+ unsigned long st_blocks; /* Number 512-byte blocks allocated. */
+ unsigned long __pad4; /* future possible st_blocks high bits */
+
+ struct timespec st_atim;
+ struct timespec st_mtim;
+ struct timespec st_ctim;
+
+ unsigned long long st_ino;
+};
+
+#endif
diff --git a/klibc/include/arch/i386/klibc/archsys.h b/klibc/include/arch/i386/klibc/archsys.h
new file mode 100644
index 0000000000..dfdc70a6de
--- /dev/null
+++ b/klibc/include/arch/i386/klibc/archsys.h
@@ -0,0 +1,12 @@
+/*
+ * arch/cris/include/klibc/archsys.h
+ *
+ * Architecture-specific syscall definitions
+ */
+
+#ifndef _KLIBC_ARCHSYS_H
+#define _KLIBC_ARCHSYS_H
+
+/* No special syscall definitions for this architecture */
+
+#endif /* _KLIBC_ARCHSYS_H */
diff --git a/klibc/include/arch/i386/klibc/diverr.h b/klibc/include/arch/i386/klibc/diverr.h
new file mode 100644
index 0000000000..410aba06d3
--- /dev/null
+++ b/klibc/include/arch/i386/klibc/diverr.h
@@ -0,0 +1,16 @@
+/*
+ * arch/i386/include/klibc/diverr.h
+ */
+
+#ifndef _KLIBC_DIVERR_H
+#define _KLIBC_DIVERR_H
+
+#include <signal.h>
+
+static __inline__ void
+__divide_error(void)
+{
+ asm volatile("divl %0" :: "rm" (0) : "eax", "edx");
+}
+
+#endif /* _KLIBC_DIVERR_H */
diff --git a/klibc/include/arch/i386/sys/io.h b/klibc/include/arch/i386/sys/io.h
new file mode 100644
index 0000000000..b051464dfc
--- /dev/null
+++ b/klibc/include/arch/i386/sys/io.h
@@ -0,0 +1,126 @@
+#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/include/arch/i386/sys/vm86.h b/klibc/include/arch/i386/sys/vm86.h
new file mode 100644
index 0000000000..d3272393dc
--- /dev/null
+++ b/klibc/include/arch/i386/sys/vm86.h
@@ -0,0 +1,41 @@
+#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/include/arch/ia64/klibc/archsetjmp.h b/klibc/include/arch/ia64/klibc/archsetjmp.h
new file mode 100644
index 0000000000..bd639c0b00
--- /dev/null
+++ b/klibc/include/arch/ia64/klibc/archsetjmp.h
@@ -0,0 +1,17 @@
+/*
+ * 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/include/arch/ia64/klibc/archsignal.h b/klibc/include/arch/ia64/klibc/archsignal.h
new file mode 100644
index 0000000000..5b01f19bc2
--- /dev/null
+++ b/klibc/include/arch/ia64/klibc/archsignal.h
@@ -0,0 +1,31 @@
+/*
+ * 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/include/arch/ia64/klibc/archstat.h b/klibc/include/arch/ia64/klibc/archstat.h
new file mode 100644
index 0000000000..9475c0b797
--- /dev/null
+++ b/klibc/include/arch/ia64/klibc/archstat.h
@@ -0,0 +1,24 @@
+#ifndef _KLIBC_ARCHSTAT_H
+#define _KLIBC_ARCHSTAT_H
+
+#define _STATBUF_ST_NSEC
+
+struct stat {
+ unsigned long st_dev;
+ unsigned long st_ino;
+ unsigned long st_nlink;
+ unsigned int st_mode;
+ unsigned int st_uid;
+ unsigned int st_gid;
+ unsigned int __pad0;
+ unsigned long st_rdev;
+ unsigned long st_size;
+ struct timespec st_atim;
+ struct timespec st_mtim;
+ struct timespec st_ctim;
+ unsigned long st_blksize;
+ long st_blocks;
+ unsigned long __unused[3];
+};
+
+#endif
diff --git a/klibc/include/arch/ia64/klibc/archsys.h b/klibc/include/arch/ia64/klibc/archsys.h
new file mode 100644
index 0000000000..4c795a43ca
--- /dev/null
+++ b/klibc/include/arch/ia64/klibc/archsys.h
@@ -0,0 +1,218 @@
+/*
+ * 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 (type)_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 (type)_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 (type)_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 (type)_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 (type)_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 (type)_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 (type)_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/include/arch/m68k/klibc/archsignal.h b/klibc/include/arch/m68k/klibc/archsignal.h
new file mode 100644
index 0000000000..714527f6b0
--- /dev/null
+++ b/klibc/include/arch/m68k/klibc/archsignal.h
@@ -0,0 +1,13 @@
+/*
+ * 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/include/arch/m68k/klibc/archstat.h b/klibc/include/arch/m68k/klibc/archstat.h
new file mode 100644
index 0000000000..9c0a05da09
--- /dev/null
+++ b/klibc/include/arch/m68k/klibc/archstat.h
@@ -0,0 +1,37 @@
+#ifndef _KLIBC_ARCHSTAT_H
+#define _KLIBC_ARCHSTAT_H
+
+#define _STATBUF_ST_NSEC
+
+/* This matches struct stat64 in glibc2.1, hence the absolutely
+ * insane amounts of padding around dev_t's.
+ */
+struct stat {
+ unsigned long long st_dev;
+ unsigned char __pad1[2];
+
+ unsigned long __st_ino;
+
+ unsigned int st_mode;
+ unsigned int st_nlink;
+
+ unsigned long st_uid;
+ unsigned long st_gid;
+
+ unsigned long long st_rdev;
+ unsigned char __pad3[2];
+
+ long long st_size;
+ unsigned long st_blksize;
+
+ unsigned long __pad4; /* future possible st_blocks high bits */
+ unsigned long st_blocks; /* Number 512-byte blocks allocated. */
+
+ struct timespec st_atim;
+ struct timespec st_mtim;
+ struct timespec st_ctim;
+
+ unsigned long long st_ino;
+};
+
+#endif
diff --git a/klibc/include/arch/m68k/klibc/archsys.h b/klibc/include/arch/m68k/klibc/archsys.h
new file mode 100644
index 0000000000..8f6bed8e94
--- /dev/null
+++ b/klibc/include/arch/m68k/klibc/archsys.h
@@ -0,0 +1,12 @@
+/*
+ * arch/m68k/include/klibc/archsys.h
+ *
+ * Architecture-specific syscall definitions
+ */
+
+#ifndef _KLIBC_ARCHSYS_H
+#define _KLIBC_ARCHSYS_H
+
+/* No special syscall definitions for this architecture */
+
+#endif /* _KLIBC_ARCHSYS_H */
diff --git a/klibc/include/arch/mips/klibc/archfcntl.h b/klibc/include/arch/mips/klibc/archfcntl.h
new file mode 100644
index 0000000000..54462ea69f
--- /dev/null
+++ b/klibc/include/arch/mips/klibc/archfcntl.h
@@ -0,0 +1,87 @@
+/*
+ * arch/mips/include/klibc/archfcntl.h
+ *
+ * On MIPS, <asm/fcntl.h> isn't usable (compiling struct stat with
+ * the correct definitions doesn't "just work"), so we need to provide
+ * our own definitions.
+ */
+
+#ifndef _KLIBC_ARCHFCNTL_H
+#define _KLIBC_ARCHFCNTL_H
+
+#ifdef _ASM_FCNTL_H /* We were too late! */
+# error "<asm/fcntl.h> included before <klibc/archfcntl.h>"
+#endif
+#define _ASM_FCNTL_H /* Keep <asm/fcntl.h> from getting included */
+
+#define O_ACCMODE 0x0003
+#define O_RDONLY 0x0000
+#define O_WRONLY 0x0001
+#define O_RDWR 0x0002
+#define O_APPEND 0x0008
+#define O_SYNC 0x0010
+#define O_NONBLOCK 0x0080
+#define O_CREAT 0x0100
+#define O_TRUNC 0x0200
+#define O_EXCL 0x0400
+#define O_NOCTTY 0x0800
+#define FASYNC 0x1000
+#define O_LARGEFILE 0x2000
+#define O_DIRECT 0x8000
+#define O_DIRECTORY 0x10000
+#define O_NOFOLLOW 0x20000
+#define O_NOATIME 0x40000
+
+#define O_NDELAY O_NONBLOCK
+
+#define F_DUPFD 0
+#define F_GETFD 1
+#define F_SETFD 2
+#define F_GETFL 3
+#define F_SETFL 4
+#define F_GETLK 14
+#define F_SETLK 6
+#define F_SETLKW 7
+
+#define F_SETOWN 24
+#define F_GETOWN 23
+#define F_SETSIG 10
+#define F_GETSIG 11
+
+#define F_GETLK64 33
+#define F_SETLK64 34
+#define F_SETLKW64 35
+
+#define FD_CLOEXEC 1
+
+#define F_RDLCK 0
+#define F_WRLCK 1
+#define F_UNLCK 2
+
+#define F_EXLCK 4
+#define F_SHLCK 8
+
+#define F_INPROGRESS 16
+
+#define LOCK_SH 1
+#define LOCK_EX 2
+#define LOCK_NB 4
+#define LOCK_UN 8
+
+#define LOCK_MAND 32
+#define LOCK_READ 64
+#define LOCK_WRITE 128
+#define LOCK_RW 192
+
+typedef struct flock {
+ short l_type;
+ short l_whence;
+ loff_t l_start;
+ loff_t l_len;
+ pid_t l_pid;
+} flock_t;
+
+#define F_LINUX_SPECIFIC_BASE 1024
+
+#endif /* _KLIBC_ARCHFCNTL_H */
+
diff --git a/klibc/include/arch/mips/klibc/archsetjmp.h b/klibc/include/arch/mips/klibc/archsetjmp.h
new file mode 100644
index 0000000000..40e5be2736
--- /dev/null
+++ b/klibc/include/arch/mips/klibc/archsetjmp.h
@@ -0,0 +1,39 @@
+/*
+ * arch/mips/include/klibc/archsetjmp.h
+ */
+
+#ifndef _KLIBC_ARCHSETJMP_H
+#define _KLIBC_ARCHSETJMP_H
+
+struct __jmp_buf {
+ unsigned long __s0;
+ unsigned long __s1;
+ unsigned long __s2;
+ unsigned long __s3;
+ unsigned long __s4;
+ unsigned long __s5;
+ unsigned long __s6;
+ unsigned long __s7;
+ unsigned long __gp;
+ unsigned long __sp;
+ unsigned long __s8;
+ unsigned long __ra;
+ unsigned long __f20;
+ unsigned long __f21;
+ unsigned long __f22;
+ unsigned long __f23;
+ unsigned long __f24;
+ unsigned long __f25;
+ unsigned long __f26;
+ unsigned long __f27;
+ unsigned long __f28;
+ unsigned long __f29;
+ unsigned long __f30;
+ unsigned long __f31;
+ unsigned long __fcr31;
+ unsigned long __unused;
+} __attribute__((aligned(8)));
+
+typedef struct __jmp_buf jmp_buf[1];
+
+#endif /* _KLIBC_ARCHSETJMP_H */
diff --git a/klibc/include/arch/mips/klibc/archsignal.h b/klibc/include/arch/mips/klibc/archsignal.h
new file mode 100644
index 0000000000..3b72908636
--- /dev/null
+++ b/klibc/include/arch/mips/klibc/archsignal.h
@@ -0,0 +1,13 @@
+/*
+ * 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/include/arch/mips/klibc/archstat.h b/klibc/include/arch/mips/klibc/archstat.h
new file mode 100644
index 0000000000..612bbfa85b
--- /dev/null
+++ b/klibc/include/arch/mips/klibc/archstat.h
@@ -0,0 +1,39 @@
+#ifndef _KLIBC_ARCHSTAT_H
+#define _KLIBC_ARCHSTAT_H
+
+#define _STATBUF_ST_NSEC
+
+/*
+ * This matches struct stat64 in glibc2.1, hence the absolutely insane
+ * amounts of padding around dev_t's. The memory layout is the same as of
+ * struct stat of the 64-bit kernel.
+ */
+
+struct stat {
+ unsigned long st_dev;
+ unsigned long st_pad0[3]; /* Reserved for st_dev expansion */
+
+ unsigned long long st_ino;
+
+ mode_t st_mode;
+ nlink_t st_nlink;
+
+ uid_t st_uid;
+ gid_t st_gid;
+
+ unsigned long st_rdev;
+ unsigned long st_pad1[3]; /* Reserved for st_rdev expansion */
+
+ long long st_size;
+
+ struct timespec st_atim;
+ struct timespec st_mtim;
+ struct timespec st_ctim;
+
+ unsigned long st_blksize;
+ unsigned long st_pad2;
+
+ long long st_blocks;
+};
+
+#endif
diff --git a/klibc/include/arch/mips/klibc/archsys.h b/klibc/include/arch/mips/klibc/archsys.h
new file mode 100644
index 0000000000..f696cdfaa7
--- /dev/null
+++ b/klibc/include/arch/mips/klibc/archsys.h
@@ -0,0 +1,12 @@
+/*
+ * arch/mips/include/klibc/archsys.h
+ *
+ * Architecture-specific syscall definitions
+ */
+
+#ifndef _KLIBC_ARCHSYS_H
+#define _KLIBC_ARCHSYS_H
+
+/* No special syscall definitions for this architecture */
+
+#endif /* _KLIBC_ARCHSYS_H */
diff --git a/klibc/include/arch/mips/machine/asm.h b/klibc/include/arch/mips/machine/asm.h
new file mode 100644
index 0000000000..e5239a6cef
--- /dev/null
+++ b/klibc/include/arch/mips/machine/asm.h
@@ -0,0 +1,11 @@
+/*
+ * arch/mips/include/machine/asm.h
+ */
+
+#ifndef _MACHINE_ASM_H
+#define _MACHINE_ASM_H
+
+#include <asm/regdef.h>
+#include <asm/asm.h>
+
+#endif /* _MACHINE_ASM_H */
diff --git a/klibc/include/arch/mips/sgidefs.h b/klibc/include/arch/mips/sgidefs.h
new file mode 100644
index 0000000000..eb103ace2c
--- /dev/null
+++ b/klibc/include/arch/mips/sgidefs.h
@@ -0,0 +1,20 @@
+/*
+ * arch/mips/include/sgidefs.h
+ */
+
+/* Some ABI constants */
+
+#ifndef _SGIDEFS_H
+#define _SGIDEFS_H
+
+#define _MIPS_ISA_MIPS1 1
+#define _MIPS_ISA_MIPS2 2
+#define _MIPS_ISA_MIPS3 3
+#define _MIPS_ISA_MIPS4 4
+#define _MIPS_ISA_MIPS5 5
+
+#define _MIPS_SIM_ABI32 1
+#define _MIPS_SIM_NABI32 2
+#define _MIPS_SIM_ABI64 3
+
+#endif /* _SGIDEFS_H */
diff --git a/klibc/include/arch/mips/spaces.h b/klibc/include/arch/mips/spaces.h
new file mode 100644
index 0000000000..b5f530b753
--- /dev/null
+++ b/klibc/include/arch/mips/spaces.h
@@ -0,0 +1 @@
+/* Included by <asm/page.h> but not actually needed */
diff --git a/klibc/include/arch/mips64/klibc/archsignal.h b/klibc/include/arch/mips64/klibc/archsignal.h
new file mode 100644
index 0000000000..56b0fd323e
--- /dev/null
+++ b/klibc/include/arch/mips64/klibc/archsignal.h
@@ -0,0 +1,13 @@
+/*
+ * 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/include/arch/mips64/klibc/archstat.h b/klibc/include/arch/mips64/klibc/archstat.h
new file mode 100644
index 0000000000..d237e3a3e8
--- /dev/null
+++ b/klibc/include/arch/mips64/klibc/archstat.h
@@ -0,0 +1,33 @@
+#ifndef _KLIBC_ARCHSTAT_H
+#define _KLIBC_ARCHSTAT_H
+
+#define _STATBUF_ST_NSEC
+
+struct stat {
+ unsigned int st_dev;
+ unsigned int st_pad0[3]; /* Reserved for st_dev expansion */
+
+ unsigned long st_ino;
+
+ mode_t st_mode;
+ nlink_t st_nlink;
+
+ uid_t st_uid;
+ gid_t st_gid;
+
+ unsigned int st_rdev;
+ unsigned int st_pad1[3]; /* Reserved for st_rdev expansion */
+
+ off_t st_size;
+
+ struct timespec st_atim;
+ struct timespec st_mtim;
+ struct timespec st_ctim;
+
+ unsigned int st_blksize;
+ unsigned int st_pad2;
+
+ unsigned long st_blocks;
+};
+
+#endif
diff --git a/klibc/include/arch/mips64/klibc/archsys.h b/klibc/include/arch/mips64/klibc/archsys.h
new file mode 100644
index 0000000000..81e5106e16
--- /dev/null
+++ b/klibc/include/arch/mips64/klibc/archsys.h
@@ -0,0 +1,12 @@
+/*
+ * arch/mips64/include/klibc/archsys.h
+ *
+ * Architecture-specific syscall definitions
+ */
+
+#ifndef _KLIBC_ARCHSYS_H
+#define _KLIBC_ARCHSYS_H
+
+/* No special syscall definitions for this architecture */
+
+#endif /* _KLIBC_ARCHSYS_H */
diff --git a/klibc/include/arch/parisc/klibc/archsignal.h b/klibc/include/arch/parisc/klibc/archsignal.h
new file mode 100644
index 0000000000..3190e8528e
--- /dev/null
+++ b/klibc/include/arch/parisc/klibc/archsignal.h
@@ -0,0 +1,24 @@
+/*
+ * 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/include/arch/parisc/klibc/archstat.h b/klibc/include/arch/parisc/klibc/archstat.h
new file mode 100644
index 0000000000..7d28f459ee
--- /dev/null
+++ b/klibc/include/arch/parisc/klibc/archstat.h
@@ -0,0 +1,27 @@
+#ifndef _KLIBC_ARCHSTAT_H
+#define _KLIBC_ARCHSTAT_H
+
+#define _STATBUF_ST_NSEC
+
+struct stat {
+ unsigned long long st_dev;
+ unsigned int __pad1;
+
+ unsigned int __st_ino; /* Not actually filled in */
+ unsigned int st_mode;
+ unsigned int st_nlink;
+ unsigned int st_uid;
+ unsigned int st_gid;
+ unsigned long long st_rdev;
+ unsigned int __pad2;
+ signed long long st_size;
+ signed int st_blksize;
+
+ signed long long st_blocks;
+ struct timespec st_atim;
+ struct timespec st_mtim;
+ struct timespec st_ctim;
+ unsigned long long st_ino;
+};
+
+#endif
diff --git a/klibc/include/arch/parisc/klibc/archsys.h b/klibc/include/arch/parisc/klibc/archsys.h
new file mode 100644
index 0000000000..5013ba8794
--- /dev/null
+++ b/klibc/include/arch/parisc/klibc/archsys.h
@@ -0,0 +1,12 @@
+/*
+ * arch/parisc/include/klibc/archsys.h
+ *
+ * Architecture-specific syscall definitions
+ */
+
+#ifndef _KLIBC_ARCHSYS_H
+#define _KLIBC_ARCHSYS_H
+
+/* No special syscall definitions for this architecture */
+
+#endif /* _KLIBC_ARCHSYS_H */
diff --git a/klibc/include/arch/ppc/klibc/archsetjmp.h b/klibc/include/arch/ppc/klibc/archsetjmp.h
new file mode 100644
index 0000000000..53e2fccc3b
--- /dev/null
+++ b/klibc/include/arch/ppc/klibc/archsetjmp.h
@@ -0,0 +1,36 @@
+/*
+ * arch/ppc/include/klibc/archsetjmp.h
+ */
+
+#ifndef _KLIBC_ARCHSETJMP_H
+#define _KLIBC_ARCHSETJMP_H
+
+struct __jmp_buf {
+ unsigned long __r2;
+ unsigned long __sp;
+ unsigned long __lr;
+ unsigned long __cr;
+ unsigned long __r13;
+ unsigned long __r14;
+ unsigned long __r15;
+ unsigned long __r16;
+ unsigned long __r17;
+ unsigned long __r18;
+ unsigned long __r19;
+ unsigned long __r20;
+ unsigned long __r21;
+ unsigned long __r22;
+ unsigned long __r23;
+ unsigned long __r24;
+ unsigned long __r25;
+ unsigned long __r26;
+ unsigned long __r27;
+ unsigned long __r28;
+ unsigned long __r29;
+ unsigned long __r30;
+ unsigned long __r31;
+};
+
+typedef struct __jmp_buf jmp_buf[1];
+
+#endif /* _SETJMP_H */
diff --git a/klibc/include/arch/ppc/klibc/archsignal.h b/klibc/include/arch/ppc/klibc/archsignal.h
new file mode 100644
index 0000000000..567a547ef9
--- /dev/null
+++ b/klibc/include/arch/ppc/klibc/archsignal.h
@@ -0,0 +1,13 @@
+/*
+ * 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/include/arch/ppc/klibc/archstat.h b/klibc/include/arch/ppc/klibc/archstat.h
new file mode 100644
index 0000000000..1d0487b47f
--- /dev/null
+++ b/klibc/include/arch/ppc/klibc/archstat.h
@@ -0,0 +1,28 @@
+#ifndef _KLIBC_ARCHSTAT_H
+#define _KLIBC_ARCHSTAT_H
+
+#define _STATBUF_ST_NSEC
+
+/* This matches struct stat64 in glibc2.1.
+ */
+struct stat {
+ unsigned long long st_dev; /* Device. */
+ unsigned long long st_ino; /* File serial number. */
+ unsigned int st_mode; /* File mode. */
+ unsigned int st_nlink; /* Link count. */
+ unsigned int st_uid; /* User ID of the file's owner. */
+ unsigned int st_gid; /* Group ID of the file's group. */
+ unsigned long long st_rdev; /* Device number, if device. */
+ unsigned short int __pad2;
+ long long st_size; /* Size of file, in bytes. */
+ long st_blksize; /* Optimal block size for I/O. */
+
+ long long st_blocks; /* Number 512-byte blocks allocated. */
+ struct timespec st_atim; /* Time of last access. */
+ struct timespec st_mtim; /* Time of last modification. */
+ struct timespec st_ctim; /* Time of last status change. */
+ unsigned long int __unused4;
+ unsigned long int __unused5;
+};
+
+#endif
diff --git a/klibc/include/arch/ppc/klibc/archsys.h b/klibc/include/arch/ppc/klibc/archsys.h
new file mode 100644
index 0000000000..17a28859e5
--- /dev/null
+++ b/klibc/include/arch/ppc/klibc/archsys.h
@@ -0,0 +1,61 @@
+/*
+ * 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/include/arch/ppc64/klibc/archsetjmp.h b/klibc/include/arch/ppc64/klibc/archsetjmp.h
new file mode 100644
index 0000000000..006a2e27be
--- /dev/null
+++ b/klibc/include/arch/ppc64/klibc/archsetjmp.h
@@ -0,0 +1,36 @@
+/*
+ * 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/include/arch/ppc64/klibc/archsignal.h b/klibc/include/arch/ppc64/klibc/archsignal.h
new file mode 100644
index 0000000000..8452f6e4bc
--- /dev/null
+++ b/klibc/include/arch/ppc64/klibc/archsignal.h
@@ -0,0 +1,13 @@
+/*
+ * 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/include/arch/ppc64/klibc/archstat.h b/klibc/include/arch/ppc64/klibc/archstat.h
new file mode 100644
index 0000000000..71f4748690
--- /dev/null
+++ b/klibc/include/arch/ppc64/klibc/archstat.h
@@ -0,0 +1,25 @@
+#ifndef _KLIBC_ARCHSTAT_H
+#define _KLIBC_ARCHSTAT_H
+
+#define _STATBUF_ST_NSEC
+
+struct stat {
+ unsigned long st_dev;
+ ino_t st_ino;
+ nlink_t st_nlink;
+ mode_t st_mode;
+ uid_t st_uid;
+ gid_t st_gid;
+ unsigned long st_rdev;
+ off_t st_size;
+ unsigned long st_blksize;
+ unsigned long st_blocks;
+ struct timespec st_atim; /* Time of last access. */
+ struct timespec st_mtim; /* Time of last modification. */
+ struct timespec st_ctim; /* Time of last status change. */
+ unsigned long __unused4;
+ unsigned long __unused5;
+ unsigned long __unused6;
+};
+
+#endif
diff --git a/klibc/include/arch/ppc64/klibc/archsys.h b/klibc/include/arch/ppc64/klibc/archsys.h
new file mode 100644
index 0000000000..4f81fee00d
--- /dev/null
+++ b/klibc/include/arch/ppc64/klibc/archsys.h
@@ -0,0 +1,52 @@
+/*
+ * arch/ppc64/include/klibc/archsys.h
+ *
+ * Architecture-specific syscall definitions
+ */
+
+#ifndef _KLIBC_ARCHSYS_H
+#define _KLIBC_ARCHSYS_H
+
+#ifndef _syscall6
+
+#define _syscall6(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
+ type5,arg5,type6,arg6) \
+type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5,type6 arg6) \
+{ \
+ unsigned long __sc_ret, __sc_err; \
+ { \
+ register unsigned long __sc_0 __asm__ ("r0"); \
+ register unsigned long __sc_3 __asm__ ("r3"); \
+ register unsigned long __sc_4 __asm__ ("r4"); \
+ register unsigned long __sc_5 __asm__ ("r5"); \
+ register unsigned long __sc_6 __asm__ ("r6"); \
+ register unsigned long __sc_7 __asm__ ("r7"); \
+ register unsigned long __sc_8 __asm__ ("r8"); \
+ \
+ __sc_3 = (unsigned long) (arg1); \
+ __sc_4 = (unsigned long) (arg2); \
+ __sc_5 = (unsigned long) (arg3); \
+ __sc_6 = (unsigned long) (arg4); \
+ __sc_7 = (unsigned long) (arg5); \
+ __sc_8 = (unsigned long) (arg6); \
+ __sc_0 = __NR_##name; \
+ __asm__ __volatile__ \
+ ("sc \n\t" \
+ "mfcr %1 " \
+ : "=&r" (__sc_3), "=&r" (__sc_0) \
+ : "0" (__sc_3), "1" (__sc_0), \
+ "r" (__sc_4), \
+ "r" (__sc_5), \
+ "r" (__sc_6), \
+ "r" (__sc_7), \
+ "r" (__sc_8) \
+ : __syscall_clobbers); \
+ __sc_ret = __sc_3; \
+ __sc_err = __sc_0; \
+ } \
+ __syscall_return (type); \
+}
+
+#endif /* _syscall6() missing */
+
+#endif /* _KLIBC_ARCHSYS_H */
diff --git a/klibc/include/arch/s390/klibc/archsetjmp.h b/klibc/include/arch/s390/klibc/archsetjmp.h
new file mode 100644
index 0000000000..11a641ed5a
--- /dev/null
+++ b/klibc/include/arch/s390/klibc/archsetjmp.h
@@ -0,0 +1,15 @@
+/*
+ * arch/s390/include/klibc/archsetjmp.h
+ */
+
+#ifndef _KLIBC_ARCHSETJMP_H
+#define _KLIBC_ARCHSETJMP_H
+
+struct __jmp_buf {
+ uint32_t __gregs[10]; /* general registers r6-r15 */
+ uint64_t __fpregs[2]; /* fp registers f4 and f6 */
+};
+
+typedef struct __jmp_buf jmp_buf[1];
+
+#endif /* _SETJMP_H */
diff --git a/klibc/include/arch/s390/klibc/archsignal.h b/klibc/include/arch/s390/klibc/archsignal.h
new file mode 100644
index 0000000000..1f8de28b4b
--- /dev/null
+++ b/klibc/include/arch/s390/klibc/archsignal.h
@@ -0,0 +1,13 @@
+/*
+ * 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/include/arch/s390/klibc/archstat.h b/klibc/include/arch/s390/klibc/archstat.h
new file mode 100644
index 0000000000..866c3d4f4c
--- /dev/null
+++ b/klibc/include/arch/s390/klibc/archstat.h
@@ -0,0 +1,31 @@
+#ifndef _KLIBC_ARCHSTAT_H
+#define _KLIBC_ARCHSTAT_H
+
+#define _STATBUF_ST_NSEC
+
+/* This matches struct stat64 in glibc2.1, hence the absolutely
+ * insane amounts of padding around dev_t's.
+ */
+struct stat {
+ unsigned long long st_dev;
+ unsigned int __pad1;
+#define STAT64_HAS_BROKEN_ST_INO 1
+ unsigned long __st_ino;
+ unsigned int st_mode;
+ unsigned int st_nlink;
+ unsigned long st_uid;
+ unsigned long st_gid;
+ unsigned long long st_rdev;
+ unsigned int __pad3;
+ long long st_size;
+ unsigned long st_blksize;
+ unsigned char __pad4[4];
+ unsigned long __pad5; /* future possible st_blocks high bits */
+ unsigned long st_blocks; /* Number 512-byte blocks allocated. */
+ struct timespec st_atim;
+ struct timespec st_mtim;
+ struct timespec st_ctim;
+ unsigned long long st_ino;
+};
+
+#endif
diff --git a/klibc/include/arch/s390/klibc/archsys.h b/klibc/include/arch/s390/klibc/archsys.h
new file mode 100644
index 0000000000..1cd0948f3c
--- /dev/null
+++ b/klibc/include/arch/s390/klibc/archsys.h
@@ -0,0 +1,41 @@
+/*
+ * arch/s390/include/klibc/archsys.h
+ *
+ * Architecture-specific syscall definitions
+ */
+
+#ifndef _KLIBC_ARCHSYS_H
+#define _KLIBC_ARCHSYS_H
+
+/* S/390 only has five syscall parameters, and uses a structure for
+ 6-argument syscalls. */
+
+#ifndef _syscall6
+
+#define _syscall6(type,name,type1,arg1,type2,arg2,type3,arg3,\
+ type4,arg4,type5,arg5,type6,arg6) \
+type name(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \
+ type5 arg5, type6 arg6) { \
+ unsigned long __arg[6] = { \
+ (unsigned long) arg1, \
+ (unsigned long) arg2, \
+ (unsigned long) arg3, \
+ (unsigned long) arg4, \
+ (unsigned long) arg5, \
+ (unsigned long) arg6 \
+ }; \
+ register void *__argp asm("2") = &__arg; \
+ long __res; \
+ __asm__ __volatile__ ( \
+ " svc %b1\n" \
+ " lr %0,2" \
+ : "=d" (__res) \
+ : "i" (__NR_##name), \
+ "d" (__argp) \
+ : _svc_clobber); \
+ __syscall_return(type, __res); \
+}
+
+#endif /* _syscall6() missing */
+
+#endif /* _KLIBC_ARCHSYS_H */
diff --git a/klibc/include/arch/s390x/klibc/archsetjmp.h b/klibc/include/arch/s390x/klibc/archsetjmp.h
new file mode 100644
index 0000000000..dd3ed0d47c
--- /dev/null
+++ b/klibc/include/arch/s390x/klibc/archsetjmp.h
@@ -0,0 +1,15 @@
+/*
+ * arch/s390x/include/klibc/archsetjmp.h
+ */
+
+#ifndef _KLIBC_ARCHSETJMP_H
+#define _KLIBC_ARCHSETJMP_H
+
+struct __jmp_buf {
+ uint64_t __gregs[10]; /* general registers r6-r15 */
+ uint64_t __fpregs[4]; /* fp registers f1, f3, f5, f7 */
+};
+
+typedef struct __jmp_buf jmp_buf[1];
+
+#endif /* _SETJMP_H */
diff --git a/klibc/include/arch/s390x/klibc/archsignal.h b/klibc/include/arch/s390x/klibc/archsignal.h
new file mode 100644
index 0000000000..08c9a0073a
--- /dev/null
+++ b/klibc/include/arch/s390x/klibc/archsignal.h
@@ -0,0 +1,13 @@
+/*
+ * 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/include/arch/s390x/klibc/archstat.h b/klibc/include/arch/s390x/klibc/archstat.h
new file mode 100644
index 0000000000..0de73cb2b6
--- /dev/null
+++ b/klibc/include/arch/s390x/klibc/archstat.h
@@ -0,0 +1,24 @@
+#ifndef _KLIBC_ARCHSTAT_H
+#define _KLIBC_ARCHSTAT_H
+
+#define _STATBUF_ST_NSEC
+
+struct stat {
+ unsigned long st_dev;
+ unsigned long st_ino;
+ unsigned long st_nlink;
+ unsigned int st_mode;
+ unsigned int st_uid;
+ unsigned int st_gid;
+ unsigned int __pad1;
+ unsigned long st_rdev;
+ unsigned long st_size;
+ struct timespec st_atim;
+ struct timespec st_mtim;
+ struct timespec st_ctim;
+ unsigned long st_blksize;
+ long st_blocks;
+ unsigned long __unused[3];
+};
+
+#endif
diff --git a/klibc/include/arch/s390x/klibc/archsys.h b/klibc/include/arch/s390x/klibc/archsys.h
new file mode 100644
index 0000000000..15f7113bb4
--- /dev/null
+++ b/klibc/include/arch/s390x/klibc/archsys.h
@@ -0,0 +1,41 @@
+/*
+ * arch/s390x/include/klibc/archsys.h
+ *
+ * Architecture-specific syscall definitions
+ */
+
+#ifndef _KLIBC_ARCHSYS_H
+#define _KLIBC_ARCHSYS_H
+
+/* S/390X only has five syscall parameters, and uses a structure for
+ 6-argument syscalls. */
+
+#ifndef _syscall6
+
+#define _syscall6(type,name,type1,arg1,type2,arg2,type3,arg3,\
+ type4,arg4,type5,arg5,type6,arg6) \
+type name(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \
+ type5 arg5, type6 arg6) { \
+ unsigned long __arg[6] = { \
+ (unsigned long) arg1, \
+ (unsigned long) arg2, \
+ (unsigned long) arg3, \
+ (unsigned long) arg4, \
+ (unsigned long) arg5, \
+ (unsigned long) arg6 \
+ }; \
+ register void *__argp asm("2") = &__arg; \
+ long __res; \
+ __asm__ __volatile__ ( \
+ " svc %b1\n" \
+ " lgr %0,2" \
+ : "=d" (__res) \
+ : "i" (__NR_##name), \
+ "d" (__argp) \
+ : _svc_clobber); \
+ __syscall_return(type, __res); \
+}
+
+#endif /* _syscall6() missing */
+
+#endif /* _KLIBC_ARCHSYS_H */
diff --git a/klibc/include/arch/sh/klibc/archsetjmp.h b/klibc/include/arch/sh/klibc/archsetjmp.h
new file mode 100644
index 0000000000..28dd932fbc
--- /dev/null
+++ b/klibc/include/arch/sh/klibc/archsetjmp.h
@@ -0,0 +1,22 @@
+/*
+ * arch/sh/include/klibc/archsetjmp.h
+ */
+
+#ifndef _KLIBC_ARCHSETJMP_H
+#define _KLIBC_ARCHSETJMP_H
+
+struct __jmp_buf {
+ unsigned long r8;
+ unsigned long r9;
+ unsigned long r10;
+ unsigned long r11;
+ unsigned long r12;
+ unsigned long r13;
+ unsigned long r14;
+ unsigned long r15;
+ unsigned long pr;
+};
+
+typedef struct __jmp_buf jmp_buf[1];
+
+#endif /* _KLIBC_ARCHSETJMP_H */
diff --git a/klibc/include/arch/sh/klibc/archsignal.h b/klibc/include/arch/sh/klibc/archsignal.h
new file mode 100644
index 0000000000..6c4e5976ad
--- /dev/null
+++ b/klibc/include/arch/sh/klibc/archsignal.h
@@ -0,0 +1,13 @@
+/*
+ * 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/include/arch/sh/klibc/archstat.h b/klibc/include/arch/sh/klibc/archstat.h
new file mode 100644
index 0000000000..73caceb593
--- /dev/null
+++ b/klibc/include/arch/sh/klibc/archstat.h
@@ -0,0 +1,45 @@
+#ifndef _KLIBC_ARCHSTAT_H
+#define _KLIBC_ARCHSTAT_H
+
+#include <endian.h>
+
+#define _STATBUF_ST_NSEC
+
+/* This matches struct stat64 in glibc2.1, hence the absolutely
+ * insane amounts of padding around dev_t's.
+ */
+struct stat64 {
+ unsigned long long st_dev;
+ unsigned char __pad0[4];
+
+ unsigned long st_ino;
+ unsigned int st_mode;
+ unsigned int st_nlink;
+
+ unsigned long st_uid;
+ unsigned long st_gid;
+
+ unsigned long long st_rdev;
+ unsigned char __pad3[4];
+
+ long long st_size;
+ unsigned long st_blksize;
+
+#if __BYTE_ORDER == __BIG_ENDIAN
+ unsigned long __pad4; /* Future possible st_blocks hi bits */
+ unsigned long st_blocks; /* Number 512-byte blocks allocated. */
+#else /* Must be little */
+ unsigned long st_blocks; /* Number 512-byte blocks allocated. */
+ unsigned long __pad4; /* Future possible st_blocks hi bits */
+#endif
+
+ struct timespec st_atim;
+ struct timespec st_mtim;
+ struct timespec st_ctim;
+
+ unsigned long __unused1;
+ unsigned long __unused2;
+};
+
+#endif
+
diff --git a/klibc/include/arch/sh/klibc/archsys.h b/klibc/include/arch/sh/klibc/archsys.h
new file mode 100644
index 0000000000..5f8050a536
--- /dev/null
+++ b/klibc/include/arch/sh/klibc/archsys.h
@@ -0,0 +1,12 @@
+/*
+ * arch/sh/include/klibc/archsys.h
+ *
+ * Architecture-specific syscall definitions
+ */
+
+#ifndef _KLIBC_ARCHSYS_H
+#define _KLIBC_ARCHSYS_H
+
+/* No special syscall definitions for this architecture */
+
+#endif /* _KLIBC_ARCHSYS_H */
diff --git a/klibc/include/arch/sparc/klibc/archsetjmp.h b/klibc/include/arch/sparc/klibc/archsetjmp.h
new file mode 100644
index 0000000000..92c1c74c9d
--- /dev/null
+++ b/klibc/include/arch/sparc/klibc/archsetjmp.h
@@ -0,0 +1,16 @@
+/*
+ * 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/include/arch/sparc/klibc/archsignal.h b/klibc/include/arch/sparc/klibc/archsignal.h
new file mode 100644
index 0000000000..6af3709033
--- /dev/null
+++ b/klibc/include/arch/sparc/klibc/archsignal.h
@@ -0,0 +1,13 @@
+/*
+ * 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/include/arch/sparc/klibc/archstat.h b/klibc/include/arch/sparc/klibc/archstat.h
new file mode 100644
index 0000000000..0ff68785e5
--- /dev/null
+++ b/klibc/include/arch/sparc/klibc/archstat.h
@@ -0,0 +1,35 @@
+#ifndef _KLIBC_ARCHSTAT_H
+#define _KLIBC_ARCHSTAT_H
+
+#define _STATBUF_ST_NSEC
+
+struct stat {
+ unsigned long long st_dev;
+
+ unsigned long long st_ino;
+
+ unsigned int st_mode;
+ unsigned int st_nlink;
+
+ unsigned int st_uid;
+ unsigned int st_gid;
+
+ unsigned long long st_rdev;
+
+ unsigned char __pad3[8];
+
+ long long st_size;
+ unsigned int st_blksize;
+
+ unsigned char __pad4[8];
+ unsigned int st_blocks;
+
+ struct timespec st_atim;
+ struct timespec st_mtim;
+ struct timespec st_ctim;
+
+ unsigned int __unused4;
+ unsigned int __unused5;
+};
+
+#endif
diff --git a/klibc/include/arch/sparc/klibc/archsys.h b/klibc/include/arch/sparc/klibc/archsys.h
new file mode 100644
index 0000000000..20de8a8b44
--- /dev/null
+++ b/klibc/include/arch/sparc/klibc/archsys.h
@@ -0,0 +1,10 @@
+/*
+ * arch/sparc/include/klibc/archsys.h
+ *
+ * Architecture-specific syscall definitions
+ */
+
+#ifndef _KLIBC_ARCHSYS_H
+#define _KLIBC_ARCHSYS_H
+
+#endif /* _KLIBC_ARCHSYS_H */
diff --git a/klibc/include/arch/sparc/machine/asm.h b/klibc/include/arch/sparc/machine/asm.h
new file mode 100644
index 0000000000..b622bd8cf1
--- /dev/null
+++ b/klibc/include/arch/sparc/machine/asm.h
@@ -0,0 +1,192 @@
+/* $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/include/arch/sparc/machine/frame.h b/klibc/include/arch/sparc/machine/frame.h
new file mode 100644
index 0000000000..b09175c7f4
--- /dev/null
+++ b/klibc/include/arch/sparc/machine/frame.h
@@ -0,0 +1,138 @@
+/* $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/include/arch/sparc/machine/trap.h b/klibc/include/arch/sparc/machine/trap.h
new file mode 100644
index 0000000000..42c3ef6ae2
--- /dev/null
+++ b/klibc/include/arch/sparc/machine/trap.h
@@ -0,0 +1,141 @@
+/* $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/include/arch/sparc64/klibc/archsetjmp.h b/klibc/include/arch/sparc64/klibc/archsetjmp.h
new file mode 100644
index 0000000000..022a31e542
--- /dev/null
+++ b/klibc/include/arch/sparc64/klibc/archsetjmp.h
@@ -0,0 +1,16 @@
+/*
+ * 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/include/arch/sparc64/klibc/archsignal.h b/klibc/include/arch/sparc64/klibc/archsignal.h
new file mode 100644
index 0000000000..f81bd668bb
--- /dev/null
+++ b/klibc/include/arch/sparc64/klibc/archsignal.h
@@ -0,0 +1,13 @@
+/*
+ * 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/include/arch/sparc64/klibc/archstat.h b/klibc/include/arch/sparc64/klibc/archstat.h
new file mode 100644
index 0000000000..c22905d30c
--- /dev/null
+++ b/klibc/include/arch/sparc64/klibc/archstat.h
@@ -0,0 +1,22 @@
+#ifndef _KLIBC_ARCHSTAT_H
+#define _KLIBC_ARCHSTAT_H
+
+/* No nsec fields?! */
+struct stat {
+ unsigned st_dev;
+ ino_t st_ino;
+ mode_t st_mode;
+ short st_nlink;
+ uid_t st_uid;
+ gid_t st_gid;
+ unsigned st_rdev;
+ off_t st_size;
+ time_t st_atime;
+ time_t st_mtime;
+ time_t st_ctime;
+ off_t st_blksize;
+ off_t st_blocks;
+ unsigned long __unused4[2];
+};
+
+#endif
diff --git a/klibc/include/arch/sparc64/klibc/archsys.h b/klibc/include/arch/sparc64/klibc/archsys.h
new file mode 100644
index 0000000000..6a3a7b25bc
--- /dev/null
+++ b/klibc/include/arch/sparc64/klibc/archsys.h
@@ -0,0 +1,10 @@
+/*
+ * arch/sparc64/include/klibc/archsys.h
+ *
+ * Architecture-specific syscall definitions
+ */
+
+#ifndef _KLIBC_ARCHSYS_H
+#define _KLIBC_ARCHSYS_H
+
+#endif /* _KLIBC_ARCHSYS_H */
diff --git a/klibc/include/arch/x86_64/klibc/archsetjmp.h b/klibc/include/arch/x86_64/klibc/archsetjmp.h
new file mode 100644
index 0000000000..90d0a0d263
--- /dev/null
+++ b/klibc/include/arch/x86_64/klibc/archsetjmp.h
@@ -0,0 +1,21 @@
+/*
+ * 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/include/arch/x86_64/klibc/archsignal.h b/klibc/include/arch/x86_64/klibc/archsignal.h
new file mode 100644
index 0000000000..74e82e1dd0
--- /dev/null
+++ b/klibc/include/arch/x86_64/klibc/archsignal.h
@@ -0,0 +1,13 @@
+/*
+ * 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/include/arch/x86_64/klibc/archstat.h b/klibc/include/arch/x86_64/klibc/archstat.h
new file mode 100644
index 0000000000..53e141daea
--- /dev/null
+++ b/klibc/include/arch/x86_64/klibc/archstat.h
@@ -0,0 +1,26 @@
+#ifndef _KLIBC_ARCHSTAT_H
+#define _KLIBC_ARCHSTAT_H
+
+#define _STATBUF_ST_NSEC
+
+struct stat {
+ unsigned long st_dev;
+ unsigned long st_ino;
+ unsigned long st_nlink;
+
+ unsigned int st_mode;
+ unsigned int st_uid;
+ unsigned int st_gid;
+ unsigned int __pad0;
+ unsigned long st_rdev;
+ long st_size;
+ long st_blksize;
+ long st_blocks; /* Number 512-byte blocks allocated. */
+
+ struct timespec st_atim;
+ struct timespec st_mtim;
+ struct timespec st_ctim;
+ long __unused[3];
+};
+
+#endif
diff --git a/klibc/include/arch/x86_64/klibc/archsys.h b/klibc/include/arch/x86_64/klibc/archsys.h
new file mode 100644
index 0000000000..2ec72cd397
--- /dev/null
+++ b/klibc/include/arch/x86_64/klibc/archsys.h
@@ -0,0 +1,109 @@
+/*
+ * 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/include/arch/x86_64/sys/io.h b/klibc/include/arch/x86_64/sys/io.h
new file mode 100644
index 0000000000..4a0ae44985
--- /dev/null
+++ b/klibc/include/arch/x86_64/sys/io.h
@@ -0,0 +1,126 @@
+#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/include/arpa/inet.h b/klibc/include/arpa/inet.h
new file mode 100644
index 0000000000..043b148e17
--- /dev/null
+++ b/klibc/include/arpa/inet.h
@@ -0,0 +1,24 @@
+/*
+ * 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/include/assert.h b/klibc/include/assert.h
new file mode 100644
index 0000000000..58cc37c487
--- /dev/null
+++ b/klibc/include/assert.h
@@ -0,0 +1,22 @@
+/*
+ * 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/include/bits32/bitsize/limits.h b/klibc/include/bits32/bitsize/limits.h
new file mode 100644
index 0000000000..f90e524b2b
--- /dev/null
+++ b/klibc/include/bits32/bitsize/limits.h
@@ -0,0 +1,14 @@
+/*
+ * 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/include/bits32/bitsize/stddef.h b/klibc/include/bits32/bitsize/stddef.h
new file mode 100644
index 0000000000..c486041fe0
--- /dev/null
+++ b/klibc/include/bits32/bitsize/stddef.h
@@ -0,0 +1,18 @@
+/*
+ * 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/include/bits32/bitsize/stdint.h b/klibc/include/bits32/bitsize/stdint.h
new file mode 100644
index 0000000000..40b464961c
--- /dev/null
+++ b/klibc/include/bits32/bitsize/stdint.h
@@ -0,0 +1,34 @@
+/*
+ * 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/include/bits32/bitsize/stdintconst.h b/klibc/include/bits32/bitsize/stdintconst.h
new file mode 100644
index 0000000000..8157dd06e0
--- /dev/null
+++ b/klibc/include/bits32/bitsize/stdintconst.h
@@ -0,0 +1,18 @@
+/*
+ * 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/include/bits32/bitsize/stdintlimits.h b/klibc/include/bits32/bitsize/stdintlimits.h
new file mode 100644
index 0000000000..b44fe01186
--- /dev/null
+++ b/klibc/include/bits32/bitsize/stdintlimits.h
@@ -0,0 +1,22 @@
+/*
+ * 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/include/bits64/bitsize/limits.h b/klibc/include/bits64/bitsize/limits.h
new file mode 100644
index 0000000000..7b20da085b
--- /dev/null
+++ b/klibc/include/bits64/bitsize/limits.h
@@ -0,0 +1,14 @@
+/*
+ * 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/include/bits64/bitsize/stddef.h b/klibc/include/bits64/bitsize/stddef.h
new file mode 100644
index 0000000000..3e72621862
--- /dev/null
+++ b/klibc/include/bits64/bitsize/stddef.h
@@ -0,0 +1,13 @@
+/*
+ * 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/include/bits64/bitsize/stdint.h b/klibc/include/bits64/bitsize/stdint.h
new file mode 100644
index 0000000000..8e16cf0909
--- /dev/null
+++ b/klibc/include/bits64/bitsize/stdint.h
@@ -0,0 +1,36 @@
+/*
+ * 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 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/include/bits64/bitsize/stdintconst.h b/klibc/include/bits64/bitsize/stdintconst.h
new file mode 100644
index 0000000000..65f2db0501
--- /dev/null
+++ b/klibc/include/bits64/bitsize/stdintconst.h
@@ -0,0 +1,18 @@
+/*
+ * 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/include/bits64/bitsize/stdintlimits.h b/klibc/include/bits64/bitsize/stdintlimits.h
new file mode 100644
index 0000000000..d110d17d2d
--- /dev/null
+++ b/klibc/include/bits64/bitsize/stdintlimits.h
@@ -0,0 +1,22 @@
+/*
+ * 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/include/ctype.h b/klibc/include/ctype.h
new file mode 100644
index 0000000000..daa6a8eff4
--- /dev/null
+++ b/klibc/include/ctype.h
@@ -0,0 +1,119 @@
+/*
+ * 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),
+ __ctype_cntrl = (1 << 7),
+};
+
+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 __ctypes[__c+1] & __ctype_cntrl;
+}
+
+__ctype_inline int isdigit(int __c)
+{
+ return ((unsigned)__c - '0') <= 9;
+}
+
+__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/include/dirent.h b/klibc/include/dirent.h
new file mode 100644
index 0000000000..4db479592b
--- /dev/null
+++ b/klibc/include/dirent.h
@@ -0,0 +1,32 @@
+/*
+ * dirent.h
+ */
+
+#ifndef _DIRENT_H
+#define _DIRENT_H
+
+#include <klibc/extern.h>
+#include <sys/dirent.h>
+
+struct _IO_dir {
+ int __fd;
+
+#ifdef __KLIBC_DIRENT_INTERNALS
+ /* These fields for internal use only */
+
+ size_t bytes_left;
+ struct dirent *next;
+ /* Declaring this as an array of struct enforces correct alignment */
+ struct dirent buffer[15]; /* 15 times max dirent size =~ 4K */
+#endif
+};
+typedef struct _IO_dir DIR;
+
+__extern DIR *opendir(const char *);
+__extern struct dirent *readdir(DIR *);
+__extern int closedir(DIR *);
+static __inline__ int dirfd (DIR *__d) {
+ return __d->__fd;
+}
+
+#endif /* _DIRENT_H */
diff --git a/klibc/include/elf.h b/klibc/include/elf.h
new file mode 100644
index 0000000000..52f47d042e
--- /dev/null
+++ b/klibc/include/elf.h
@@ -0,0 +1,12 @@
+/*
+ * elf.h
+ */
+
+#ifndef _ELF_H
+#define _ELF_H
+
+#include <sys/elf32.h>
+#include <sys/elf64.h>
+
+#endif /* _ELF_H */
+
diff --git a/klibc/include/endian.h b/klibc/include/endian.h
new file mode 100644
index 0000000000..44f89ccbbc
--- /dev/null
+++ b/klibc/include/endian.h
@@ -0,0 +1,42 @@
+/*
+ * 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/include/errno.h b/klibc/include/errno.h
new file mode 100644
index 0000000000..b2e666504d
--- /dev/null
+++ b/klibc/include/errno.h
@@ -0,0 +1,8 @@
+/*
+ * errno.h
+ */
+
+#include <klibc/extern.h>
+#include <asm/errno.h>
+
+__extern int errno;
diff --git a/klibc/include/fcntl.h b/klibc/include/fcntl.h
new file mode 100644
index 0000000000..c9650f76b5
--- /dev/null
+++ b/klibc/include/fcntl.h
@@ -0,0 +1,46 @@
+/*
+ * fcntl.h
+ */
+
+#ifndef _FCNTL_H
+#define _FCNTL_H
+
+#include <klibc/extern.h>
+#include <klibc/compiler.h>
+#include <sys/types.h>
+#if defined(__mips__) && !defined(__mips64__)
+# include <klibc/archfcntl.h>
+#endif
+#include <linux/fcntl.h>
+
+/* This is ugly, but "struct flock" has actually been defined with
+ a long off_t, so it's really "struct flock64". It just happens
+ to work. Gag. Barf.
+
+ This happens to work on all 32-bit architectures except MIPS. */
+
+#ifdef F_GETLK64
+# undef F_GETLK
+# define F_GETLK F_GETLK64
+#endif
+
+#ifdef F_SETLK64
+# undef F_SETLK
+# define F_SETLK F_SETLK64
+#endif
+
+#ifdef F_SETLKW64
+# undef F_SETLKW
+# define F_SETLKW F_SETLKW64
+#endif
+
+/* This is defined here as well as in <unistd.h> since old-style code
+ would still include <fcntl.h> when using open(), and open() being
+ a varadic function changes its calling convention on some architectures. */
+#ifndef _KLIBC_IN_OPEN_C
+__extern int open(const char *, int, ...);
+#endif
+
+__extern int fcntl(int, int, ...);
+
+#endif /* _FCNTL_H */
diff --git a/klibc/include/grp.h b/klibc/include/grp.h
new file mode 100644
index 0000000000..03ceb31560
--- /dev/null
+++ b/klibc/include/grp.h
@@ -0,0 +1,13 @@
+/*
+ * 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/include/inttypes.h b/klibc/include/inttypes.h
new file mode 100644
index 0000000000..e00fa63160
--- /dev/null
+++ b/klibc/include/inttypes.h
@@ -0,0 +1,226 @@
+/*
+ * 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/include/klibc/compiler.h b/klibc/include/klibc/compiler.h
new file mode 100644
index 0000000000..823996e777
--- /dev/null
+++ b/klibc/include/klibc/compiler.h
@@ -0,0 +1,119 @@
+/*
+ * 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
+
+/* "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 __constfunc __attribute__((const))
+#else
+# define __constfunc
+#endif
+#undef __attribute_const__
+#define __attribute_const__ __constfunc
+
+/* "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 __purefunc __attribute__((pure))
+#else
+# define __purefunc
+#endif
+#undef __attribute_pure__
+#define __attribute_pure__ __purefunc
+
+/* Format attribute */
+#ifdef __GNUC__
+# define __formatfunc(t,f,a) __attribute__((format(t,f,a)))
+#else
+# define __formatfunc(t,f,a)
+#endif
+
+/* malloc() function (returns unaliased pointer) */
+#if defined(__GNUC__) && (__GNUC_MAJOR__ >= 3)
+# define __mallocfunc __attribute__((malloc))
+#else
+# define __mallocfunc
+#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
+
+/* It's all user space... */
+#define __user
+
+/* The bitwise attribute: disallow arithmetric operations */
+#ifdef __CHECKER__ /* sparse only */
+# define __bitwise __attribute__((bitwise))
+#else
+# define __bitwise
+#endif
+
+#endif
diff --git a/klibc/include/klibc/diverr.h b/klibc/include/klibc/diverr.h
new file mode 100644
index 0000000000..4d8c8d36c2
--- /dev/null
+++ b/klibc/include/klibc/diverr.h
@@ -0,0 +1,16 @@
+/*
+ * 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/include/klibc/extern.h b/klibc/include/klibc/extern.h
new file mode 100644
index 0000000000..f9c3467211
--- /dev/null
+++ b/klibc/include/klibc/extern.h
@@ -0,0 +1,14 @@
+/*
+ * 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/include/klibc/sysconfig.h b/klibc/include/klibc/sysconfig.h
new file mode 100644
index 0000000000..ce01c23593
--- /dev/null
+++ b/klibc/include/klibc/sysconfig.h
@@ -0,0 +1,34 @@
+/*
+ * klibc/sysconfig.h
+ *
+ * Allows for definitions of some things which may be system-dependent
+ */
+
+#ifndef _KLIBC_SYSCONFIG_H
+#define _KLIBC_SYSCONFIG_H
+
+/*
+ * Define this to obtain memory using sbrk() instead
+ * of mmap(). This should make it friendlier on
+ * non-MMU architectures. This should become a
+ * per-architecture configurable.
+ */
+#undef MALLOC_USING_SBRK
+
+/*
+ * This is the minimum chunk size we will ask the kernel for using
+ * malloc(); 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)
+
+/*
+ * This is the minimum alignment for the memory returned by sbrk().
+ * It must be a power of 2. If MALLOC_USING_SBRK is defined it should
+ * be no smaller than the size of struct arena_header in malloc.h (4
+ * pointers.)
+ */
+#define SBRK_ALIGNMENT 32
+
+#endif /* _KLIBC_SYSCONFIG_H */
diff --git a/klibc/include/limits.h b/klibc/include/limits.h
new file mode 100644
index 0000000000..f1532e5323
--- /dev/null
+++ b/klibc/include/limits.h
@@ -0,0 +1,40 @@
+/*
+ * 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/include/net/if.h b/klibc/include/net/if.h
new file mode 100644
index 0000000000..1aa8e7b90c
--- /dev/null
+++ b/klibc/include/net/if.h
@@ -0,0 +1 @@
+#include <linux/if.h>
diff --git a/klibc/include/net/if_arp.h b/klibc/include/net/if_arp.h
new file mode 100644
index 0000000000..a25f1b4759
--- /dev/null
+++ b/klibc/include/net/if_arp.h
@@ -0,0 +1 @@
+#include <linux/if_arp.h>
diff --git a/klibc/include/net/if_ether.h b/klibc/include/net/if_ether.h
new file mode 100644
index 0000000000..060ef22070
--- /dev/null
+++ b/klibc/include/net/if_ether.h
@@ -0,0 +1 @@
+#include <linux/if_ether.h>
diff --git a/klibc/include/net/if_packet.h b/klibc/include/net/if_packet.h
new file mode 100644
index 0000000000..b5e8e0e11f
--- /dev/null
+++ b/klibc/include/net/if_packet.h
@@ -0,0 +1 @@
+#include <linux/if_packet.h>
diff --git a/klibc/include/netinet/in.h b/klibc/include/netinet/in.h
new file mode 100644
index 0000000000..27b778700e
--- /dev/null
+++ b/klibc/include/netinet/in.h
@@ -0,0 +1,39 @@
+/*
+ * 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
+#ifndef htonq
+# define htonq(x) __cpu_to_be64(x)
+#endif
+#ifndef ntohq
+# define ntohq(x) __be64_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/include/netinet/in6.h b/klibc/include/netinet/in6.h
new file mode 100644
index 0000000000..46584ca627
--- /dev/null
+++ b/klibc/include/netinet/in6.h
@@ -0,0 +1,10 @@
+/*
+ * netinet/in6.h
+ */
+
+#ifndef _NETINET_IN6_H
+#define _NETINET_IN6_H
+
+#include <linux/in6.h>
+
+#endif /* _NETINET_IN6_H */
diff --git a/klibc/include/netinet/ip.h b/klibc/include/netinet/ip.h
new file mode 100644
index 0000000000..8aecbe66a3
--- /dev/null
+++ b/klibc/include/netinet/ip.h
@@ -0,0 +1,13 @@
+/*
+ * 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/include/netinet/tcp.h b/klibc/include/netinet/tcp.h
new file mode 100644
index 0000000000..bb5d307e98
--- /dev/null
+++ b/klibc/include/netinet/tcp.h
@@ -0,0 +1,11 @@
+/*
+ * 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/include/netinet/udp.h b/klibc/include/netinet/udp.h
new file mode 100644
index 0000000000..b809b4ee6e
--- /dev/null
+++ b/klibc/include/netinet/udp.h
@@ -0,0 +1,19 @@
+/*
+ * 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/include/paths.h b/klibc/include/paths.h
new file mode 100644
index 0000000000..a87831e74a
--- /dev/null
+++ b/klibc/include/paths.h
@@ -0,0 +1,74 @@
+/*
+ * Copyright (c) 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 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.
+ *
+ * @(#)paths.h 8.1 (Berkeley) 6/2/93
+ */
+
+#ifndef _PATHS_H_
+#define _PATHS_H_
+
+/* Default search path. */
+#define _PATH_DEFPATH "/usr/bin:/bin"
+/* All standard utilities path. */
+#define _PATH_STDPATH \
+ "/usr/bin:/bin:/usr/sbin:/sbin"
+
+#define _PATH_BSHELL "/bin/sh"
+#define _PATH_CONSOLE "/dev/console"
+#define _PATH_CSHELL "/bin/csh"
+#define _PATH_DEVDB "/var/run/dev.db"
+#define _PATH_DEVNULL "/dev/null"
+#define _PATH_DRUM "/dev/drum"
+#define _PATH_KLOG "/proc/kmsg"
+#define _PATH_KMEM "/dev/kmem"
+#define _PATH_LASTLOG "/var/log/lastlog"
+#define _PATH_MAILDIR "/var/mail"
+#define _PATH_MAN "/usr/share/man"
+#define _PATH_MEM "/dev/mem"
+#define _PATH_MNTTAB "/etc/fstab"
+#define _PATH_MOUNTED "/etc/mtab"
+#define _PATH_NOLOGIN "/etc/nologin"
+#define _PATH_PRESERVE "/var/lib"
+#define _PATH_RWHODIR "/var/spool/rwho"
+#define _PATH_SENDMAIL "/usr/sbin/sendmail"
+#define _PATH_SHADOW "/etc/shadow"
+#define _PATH_SHELLS "/etc/shells"
+#define _PATH_TTY "/dev/tty"
+#define _PATH_UNIX "/boot/vmlinux"
+#define _PATH_UTMP "/var/run/utmp"
+#define _PATH_VI "/bin/vi"
+#define _PATH_WTMP "/var/log/wtmp"
+
+/* Provide trailing slash, since mostly used for building pathnames. */
+#define _PATH_DEV "/dev/"
+#define _PATH_TMP "/tmp/"
+#define _PATH_VARDB "/var/db/"
+#define _PATH_VARRUN "/var/run/"
+#define _PATH_VARTMP "/var/tmp/"
+
+#endif /* !_PATHS_H_ */
diff --git a/klibc/include/poll.h b/klibc/include/poll.h
new file mode 100644
index 0000000000..8710d92ebd
--- /dev/null
+++ b/klibc/include/poll.h
@@ -0,0 +1,16 @@
+/*
+ * 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/include/sched.h b/klibc/include/sched.h
new file mode 100644
index 0000000000..fcf62a6e4f
--- /dev/null
+++ b/klibc/include/sched.h
@@ -0,0 +1,34 @@
+/*
+ * 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_setscheduler(pid_t, int, const struct sched_param *);
+__extern int sched_yield(void);
+
+/* Raw interfaces to clone(2); only actually usable for non-VM-cloning */
+#ifdef __ia64__
+__extern pid_t __clone2(int, void *, void *);
+static __inline__ pid_t __clone(int _f, void *_sp)
+{
+ return __clone2(_f, _sp, 0);
+}
+#else
+__extern pid_t __clone(int, void *);
+#endif
+
+#endif /* _SCHED_H */
diff --git a/klibc/include/setjmp.h b/klibc/include/setjmp.h
new file mode 100644
index 0000000000..b504eb6d08
--- /dev/null
+++ b/klibc/include/setjmp.h
@@ -0,0 +1,43 @@
+/*
+ * 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/include/signal.h b/klibc/include/signal.h
new file mode 100644
index 0000000000..1b439077f2
--- /dev/null
+++ b/klibc/include/signal.h
@@ -0,0 +1,81 @@
+/*
+ * signal.h
+ */
+
+#ifndef _SIGNAL_H
+#define _SIGNAL_H
+
+#include <klibc/compiler.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/include/stdarg.h b/klibc/include/stdarg.h
new file mode 100644
index 0000000000..cc324b825d
--- /dev/null
+++ b/klibc/include/stdarg.h
@@ -0,0 +1,14 @@
+/*
+ * 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/include/stddef.h b/klibc/include/stddef.h
new file mode 100644
index 0000000000..125d2352ec
--- /dev/null
+++ b/klibc/include/stddef.h
@@ -0,0 +1,24 @@
+/*
+ * 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/include/stdint.h b/klibc/include/stdint.h
new file mode 100644
index 0000000000..47fec18594
--- /dev/null
+++ b/klibc/include/stdint.h
@@ -0,0 +1,116 @@
+/*
+ * 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/include/stdio.h b/klibc/include/stdio.h
new file mode 100644
index 0000000000..e00fac4d5e
--- /dev/null
+++ b/klibc/include/stdio.h
@@ -0,0 +1,123 @@
+/*
+ * 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);
+
+/* No buffering, so no flushing needed */
+extern __inline__ int
+fflush(FILE *__f)
+{
+ (void)__f;
+ return 0;
+}
+
+__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/include/stdlib.h b/klibc/include/stdlib.h
new file mode 100644
index 0000000000..be4e76ed9f
--- /dev/null
+++ b/klibc/include/stdlib.h
@@ -0,0 +1,90 @@
+/*
+ * 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;
+}
+
+__extern __mallocfunc void *malloc(size_t);
+__extern __mallocfunc void *calloc(size_t, size_t);
+__extern __mallocfunc 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/include/string.h b/klibc/include/string.h
new file mode 100644
index 0000000000..3bbb217e98
--- /dev/null
+++ b/klibc/include/string.h
@@ -0,0 +1,43 @@
+/*
+ * 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 size_t strnlen(const char *, size_t);
+__extern char *strncat(char *, const char *, size_t);
+__extern size_t strlcat(char *, const char *, size_t);
+__extern int strncmp(const char *, const char *, size_t);
+__extern char *strncpy(char *, const char *, size_t);
+__extern size_t strlcpy(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/include/sys/dirent.h b/klibc/include/sys/dirent.h
new file mode 100644
index 0000000000..eec470ce1a
--- /dev/null
+++ b/klibc/include/sys/dirent.h
@@ -0,0 +1,21 @@
+/*
+ * sys/dirent.h
+ */
+
+#ifndef _SYS_DIRENT_H
+#define _SYS_DIRENT_H
+
+#include <stdint.h>
+
+/* The kernel calls this struct dirent64 */
+struct dirent {
+ uint64_t d_ino;
+ int64_t d_off;
+ unsigned short d_reclen;
+ unsigned char d_type;
+ char d_name[256];
+};
+
+__extern int getdents(unsigned int, struct dirent *, unsigned int);
+
+#endif /* _SYS_DIRENT_H */
diff --git a/klibc/include/sys/elf32.h b/klibc/include/sys/elf32.h
new file mode 100644
index 0000000000..652de5bc5f
--- /dev/null
+++ b/klibc/include/sys/elf32.h
@@ -0,0 +1,115 @@
+/*
+ * 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/include/sys/elf64.h b/klibc/include/sys/elf64.h
new file mode 100644
index 0000000000..750ddac4d9
--- /dev/null
+++ b/klibc/include/sys/elf64.h
@@ -0,0 +1,115 @@
+/*
+ * 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/include/sys/elfcommon.h b/klibc/include/sys/elfcommon.h
new file mode 100644
index 0000000000..d25804e483
--- /dev/null
+++ b/klibc/include/sys/elfcommon.h
@@ -0,0 +1,188 @@
+/*
+ * sys/elfcommon.h
+ */
+
+#ifndef _SYS_ELFCOMMON_H
+#define _SYS_ELFCOMMON_H
+
+#include <stdint.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/include/sys/fsuid.h b/klibc/include/sys/fsuid.h
new file mode 100644
index 0000000000..823486b776
--- /dev/null
+++ b/klibc/include/sys/fsuid.h
@@ -0,0 +1,14 @@
+/*
+ * 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/include/sys/ioctl.h b/klibc/include/sys/ioctl.h
new file mode 100644
index 0000000000..b0cee4c02c
--- /dev/null
+++ b/klibc/include/sys/ioctl.h
@@ -0,0 +1,14 @@
+/*
+ * 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/include/sys/klog.h b/klibc/include/sys/klog.h
new file mode 100644
index 0000000000..0fc5f5d945
--- /dev/null
+++ b/klibc/include/sys/klog.h
@@ -0,0 +1,24 @@
+/*
+ * 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/include/sys/mman.h b/klibc/include/sys/mman.h
new file mode 100644
index 0000000000..7f8f3e2f96
--- /dev/null
+++ b/klibc/include/sys/mman.h
@@ -0,0 +1,25 @@
+/*
+ * 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);
+__extern int mlockall(int);
+__extern int munlockall(void);
+__extern int mlock(const void *, size_t);
+__extern int munlock(const void *, size_t);
+
+#endif /* _SYS_MMAN_H */
diff --git a/klibc/include/sys/mount.h b/klibc/include/sys/mount.h
new file mode 100644
index 0000000000..313c90ec0e
--- /dev/null
+++ b/klibc/include/sys/mount.h
@@ -0,0 +1,55 @@
+/*
+ * 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/include/sys/param.h b/klibc/include/sys/param.h
new file mode 100644
index 0000000000..63a0661f43
--- /dev/null
+++ b/klibc/include/sys/param.h
@@ -0,0 +1,11 @@
+/*
+ * 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/include/sys/reboot.h b/klibc/include/sys/reboot.h
new file mode 100644
index 0000000000..eaf56610d7
--- /dev/null
+++ b/klibc/include/sys/reboot.h
@@ -0,0 +1,25 @@
+/*
+ * 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/include/sys/resource.h b/klibc/include/sys/resource.h
new file mode 100644
index 0000000000..ef14bde9f6
--- /dev/null
+++ b/klibc/include/sys/resource.h
@@ -0,0 +1,15 @@
+/*
+ * 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/include/sys/select.h b/klibc/include/sys/select.h
new file mode 100644
index 0000000000..7caf8c931b
--- /dev/null
+++ b/klibc/include/sys/select.h
@@ -0,0 +1,13 @@
+/*
+ * 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/include/sys/socket.h b/klibc/include/sys/socket.h
new file mode 100644
index 0000000000..cbc2b89591
--- /dev/null
+++ b/klibc/include/sys/socket.h
@@ -0,0 +1,50 @@
+/*
+ * 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/include/sys/socketcalls.h b/klibc/include/sys/socketcalls.h
new file mode 100644
index 0000000000..dac9f9aab6
--- /dev/null
+++ b/klibc/include/sys/socketcalls.h
@@ -0,0 +1,28 @@
+/*
+ * 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/include/sys/stat.h b/klibc/include/sys/stat.h
new file mode 100644
index 0000000000..1bf6a75f79
--- /dev/null
+++ b/klibc/include/sys/stat.h
@@ -0,0 +1,31 @@
+/*
+ * sys/stat.h
+ */
+
+#ifndef _SYS_STAT_H
+#define _SYS_STAT_H
+
+#include <klibc/extern.h>
+#include <sys/types.h>
+#include <sys/time.h> /* For struct timespec */
+#include <klibc/archstat.h>
+#include <linux/stat.h>
+
+#ifdef _STATBUF_ST_NSEC
+ /* struct stat has struct timespec instead of time_t */
+# define st_atime st_atim.tv_sec
+# define st_mtime st_mtim.tv_sec
+# define st_ctime st_ctim.tv_sec
+#endif
+
+__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/include/sys/statfs.h b/klibc/include/sys/statfs.h
new file mode 100644
index 0000000000..53b3b5e4da
--- /dev/null
+++ b/klibc/include/sys/statfs.h
@@ -0,0 +1 @@
+#include <sys/vfs.h>
diff --git a/klibc/include/sys/syscall.h b/klibc/include/sys/syscall.h
new file mode 100644
index 0000000000..c2c7684c4a
--- /dev/null
+++ b/klibc/include/sys/syscall.h
@@ -0,0 +1,17 @@
+/*
+ * sys/syscall.h
+ *
+ * Generic system call interface macros
+ */
+#ifndef _SYS_SYSCALL_H
+#define _SYS_SYSCALL_H
+
+#include <errno.h>
+#include <sys/types.h>
+#include <asm/unistd.h>
+
+/* Many architectures have incomplete, defective or non-applicable
+ syscall macros */
+#include <klibc/archsys.h>
+
+#endif /* _SYS_SYSCALL_H */
diff --git a/klibc/include/sys/sysinfo.h b/klibc/include/sys/sysinfo.h
new file mode 100644
index 0000000000..4051c6897a
--- /dev/null
+++ b/klibc/include/sys/sysinfo.h
@@ -0,0 +1,12 @@
+/*
+ * 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/include/sys/sysmacros.h b/klibc/include/sys/sysmacros.h
new file mode 100644
index 0000000000..7f1e0822b3
--- /dev/null
+++ b/klibc/include/sys/sysmacros.h
@@ -0,0 +1,31 @@
+/*
+ * 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/include/sys/time.h b/klibc/include/sys/time.h
new file mode 100644
index 0000000000..2767a1bce3
--- /dev/null
+++ b/klibc/include/sys/time.h
@@ -0,0 +1,18 @@
+/*
+ * 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 *);
+__extern int utimes(const char *, const struct timeval *);
+
+#endif /* _SYS_TIME_H */
diff --git a/klibc/include/sys/times.h b/klibc/include/sys/times.h
new file mode 100644
index 0000000000..657f9c4b1c
--- /dev/null
+++ b/klibc/include/sys/times.h
@@ -0,0 +1,14 @@
+/*
+ * sys/times.h
+ */
+
+#ifndef _SYS_TIMES_H
+#define _SYS_TIMES_H
+
+#include <linux/times.h>
+
+__extern clock_t times(struct tms *);
+__extern int gettimeofday(struct timeval *, struct timezone *);
+__extern int settimeofday(const struct timeval *, const struct timezone *);
+
+#endif /* _SYS_TIMES_H */
diff --git a/klibc/include/sys/types.h b/klibc/include/sys/types.h
new file mode 100644
index 0000000000..ddec242922
--- /dev/null
+++ b/klibc/include/sys/types.h
@@ -0,0 +1,104 @@
+/*
+ * sys/types.h
+ */
+
+#ifndef _SYS_TYPES_H
+#define _SYS_TYPES_H
+
+#include <klibc/compiler.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_loff_t off_t;
+typedef __kernel_loff_t 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 int timer_t;
+
+typedef __kernel_uid32_t uid_t;
+typedef __kernel_gid32_t gid_t;
+
+typedef __kernel_fsid_t fsid_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;
+
+typedef uint16_t __bitwise __le16;
+typedef uint16_t __bitwise __be16;
+typedef uint32_t __bitwise __le32;
+typedef uint32_t __bitwise __be32;
+typedef uint64_t __bitwise __le64;
+typedef uint64_t __bitwise __be64;
+
+/*
+ * Some apps want this in <sys/types.h>
+ */
+#include <sys/sysmacros.h>
+
+#endif
diff --git a/klibc/include/sys/uio.h b/klibc/include/sys/uio.h
new file mode 100644
index 0000000000..fc2525d11a
--- /dev/null
+++ b/klibc/include/sys/uio.h
@@ -0,0 +1,15 @@
+/*
+ * 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/include/sys/un.h b/klibc/include/sys/un.h
new file mode 100644
index 0000000000..df42d719f7
--- /dev/null
+++ b/klibc/include/sys/un.h
@@ -0,0 +1,10 @@
+/*
+ * <sys/un.h>
+ */
+
+#ifndef _SYS_UN_H
+#define _SYS_UN_H
+
+#include <linux/un.h>
+
+#endif /* _SYS_UN_H */
diff --git a/klibc/include/sys/utime.h b/klibc/include/sys/utime.h
new file mode 100644
index 0000000000..d1d635d242
--- /dev/null
+++ b/klibc/include/sys/utime.h
@@ -0,0 +1,10 @@
+/*
+ * sys/utime.h
+ */
+
+#ifndef _SYS_UTIME_H
+#define _SYS_UTIME_H
+
+#include <linux/utime.h>
+
+#endif /* _SYS_UTIME_H */
diff --git a/klibc/include/sys/utsname.h b/klibc/include/sys/utsname.h
new file mode 100644
index 0000000000..f2990f5711
--- /dev/null
+++ b/klibc/include/sys/utsname.h
@@ -0,0 +1,23 @@
+/*
+ * 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/include/sys/vfs.h b/klibc/include/sys/vfs.h
new file mode 100644
index 0000000000..b60d1a572f
--- /dev/null
+++ b/klibc/include/sys/vfs.h
@@ -0,0 +1,111 @@
+/*
+ * sys/vfs.h
+ */
+
+#ifndef _SYS_VFS_H
+#define _SYS_VFS_H
+
+#include <stdint.h>
+#include <klibc/extern.h>
+#include <sys/types.h>
+
+/* struct statfs64 -- there seems to be two standards -
+ one for 32 and one for 64 bits, and they're incompatible... */
+
+#if BITSIZE == 32 || defined(__s390__)
+
+struct statfs {
+ uint32_t f_type;
+ uint32_t f_bsize;
+ uint64_t f_blocks;
+ uint64_t f_bfree;
+ uint64_t f_bavail;
+ uint64_t f_files;
+ uint64_t f_ffree;
+ __kernel_fsid_t f_fsid;
+ uint32_t f_namelen;
+ uint32_t f_frsize;
+ uint32_t f_spare[5];
+};
+
+#else /* BITSIZE == 64 */
+
+struct statfs {
+ uint64_t f_type;
+ uint64_t f_bsize;
+ uint64_t f_blocks;
+ uint64_t f_bfree;
+ uint64_t f_bavail;
+ uint64_t f_files;
+ uint64_t f_ffree;
+ __kernel_fsid_t f_fsid;
+ uint64_t f_namelen;
+ uint64_t f_frsize;
+ uint64_t f_spare[5];
+};
+
+#endif /* BITSIZE */
+
+__extern int statfs(const char *, struct statfs *);
+__extern int fstatfs(int, struct statfs *);
+
+/* Various filesystem types */
+#define ADFS_SUPER_MAGIC 0xadf5
+#define AFFS_SUPER_MAGIC 0xadff
+#define AFS_FS_MAGIC 0x6B414653 /* 'kAFS' */
+#define AUTOFS_SUPER_MAGIC 0x0187
+#define BFS_MAGIC 0x1BADFACE
+#define CAPIFS_SUPER_MAGIC 0x434e
+#define CIFS_MAGIC_NUMBER 0xFF534D42
+#define CODA_SUPER_MAGIC 0x73757245
+#define CRAMFS_MAGIC 0x28cd3d45
+#define DEVFS_SUPER_MAGIC 0x1373
+#define DEVPTS_SUPER_MAGIC 0x1cd1
+#define EFS_SUPER_MAGIC 0x414A53
+#define EVENTPOLLFS_MAGIC 0x03111965
+#define EXT2_SUPER_MAGIC 0xEF53
+#define EXT3_SUPER_MAGIC 0xEF53
+#define GADGETFS_MAGIC 0xaee71ee7
+#define HFSPLUS_SUPER_MAGIC 0x482b
+#define HFS_MFS_SUPER_MAGIC 0xD2D7 /* MFS MDB (super block) */
+#define HFS_SUPER_MAGIC 0x4244 /* "BD": HFS MDB (super block) */
+#define HPFS_SUPER_MAGIC 0xf995e849
+#define HUGETLBFS_MAGIC 0x958458f6
+#define HWGFS_MAGIC 0x12061983
+#define IBMASMFS_MAGIC 0x66726f67
+#define ISOFS_SUPER_MAGIC 0x9660
+#define JFFS2_SUPER_MAGIC 0x72b6
+#define JFFS_MAGIC_BITMASK 0x34383931 /* "1984" */
+#define JFFS_MAGIC_SB_BITMASK 0x07c0 /* 1984 */
+#define JFS_SUPER_MAGIC 0x3153464a /* "JFS1" */
+#define MINIX2_SUPER_MAGIC 0x2468 /* minix V2 fs */
+#define MINIX2_SUPER_MAGIC2 0x2478 /* minix V2 fs, 30 char names */
+#define MINIX_SUPER_MAGIC 0x137F /* original minix fs */
+#define MINIX_SUPER_MAGIC2 0x138F /* minix fs, 30 char names */
+#define MSDOS_SUPER_MAGIC 0x4d44 /* MD */
+#define NCP_SUPER_MAGIC 0x564c
+#define NFS_SUPER_MAGIC 0x6969
+#define NFS_SUPER_MAGIC 0x6969
+#define OPENPROM_SUPER_MAGIC 0x9fa1
+#define OPROFILEFS_MAGIC 0x6f70726f
+#define PFMFS_MAGIC 0xa0b4d889
+#define PIPEFS_MAGIC 0x50495045
+#define PROC_SUPER_MAGIC 0x9fa0
+#define QNX4_SUPER_MAGIC 0x002f /* qnx4 fs detection */
+#define RAMFS_MAGIC 0x858458f6
+#define REISERFS_SUPER_MAGIC 0x52654973
+#define ROMFS_MAGIC 0x7275
+#define SMB_SUPER_MAGIC 0x517B
+#define SOCKFS_MAGIC 0x534F434B
+#define SYSFS_MAGIC 0x62656572
+#define TMPFS_MAGIC 0x01021994
+#define UDF_SUPER_MAGIC 0x15013346
+#define UFS_MAGIC 0x00011954
+#define UFS_MAGIC_4GB 0x05231994 /* fs > 4 GB && fs_featurebits */
+#define UFS_MAGIC_FEA 0x00195612 /* fs_featurebits supported */
+#define UFS_MAGIC_LFN 0x00095014 /* fs supports filenames > 14 chars */
+#define UFS_MAGIC_SEC 0x00612195 /* B1 security fs */
+#define USBDEVICE_SUPER_MAGIC 0x9fa2
+#define VXFS_SUPER_MAGIC 0xa501FCF5
+
+#endif /* _SYS_VFS_H */
diff --git a/klibc/include/sys/wait.h b/klibc/include/sys/wait.h
new file mode 100644
index 0000000000..4cfafc9408
--- /dev/null
+++ b/klibc/include/sys/wait.h
@@ -0,0 +1,28 @@
+/*
+ * 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/include/syslog.h b/klibc/include/syslog.h
new file mode 100644
index 0000000000..551527a042
--- /dev/null
+++ b/klibc/include/syslog.h
@@ -0,0 +1,55 @@
+/*
+ * 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/include/termios.h b/klibc/include/termios.h
new file mode 100644
index 0000000000..08a5e56855
--- /dev/null
+++ b/klibc/include/termios.h
@@ -0,0 +1,86 @@
+/*
+ * 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/include/time.h b/klibc/include/time.h
new file mode 100644
index 0000000000..0f094c2806
--- /dev/null
+++ b/klibc/include/time.h
@@ -0,0 +1,18 @@
+/*
+ * 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 *);
+
+/* klibc-specific but useful since we don't have floating point */
+__extern char *strtotimeval(const char *str, struct timeval *tv);
+__extern char *strtotimespec(const char *str, struct timespec *tv);
+
+#endif /* _TIME_H */
diff --git a/klibc/include/unistd.h b/klibc/include/unistd.h
new file mode 100644
index 0000000000..51fd7b769e
--- /dev/null
+++ b/klibc/include/unistd.h
@@ -0,0 +1,140 @@
+/*
+ * 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 fchdir(int);
+__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);
+
+/* Also in <fcntl.h> */
+#ifndef _KLIBC_IN_OPEN_C
+__extern int open(const char *, int, ...);
+#endif
+__extern int close(int);
+__extern off_t lseek(int, off_t, int);
+/* off_t is 64 bits now even on 32-bit platforms; see llseek.c */
+static __inline__ off_t llseek(int __f, off_t __o, int __w) {
+ return lseek(__f, __o, __w);
+}
+
+__extern ssize_t read(int, void *, size_t);
+__extern ssize_t write(int, const void *, size_t);
+__extern ssize_t pread(int, void *, size_t, off_t);
+__extern ssize_t pwrite(int, void *, size_t, off_t);
+
+__extern int dup(int);
+__extern int dup2(int, int);
+__extern int fcntl(int, int, ...);
+__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);
+
+static __inline__ int getpagesize(void) {
+ extern unsigned int __page_size;
+ return __page_size;
+}
+static __inline__ int __getpageshift(void) {
+ extern unsigned int __page_shift;
+ return __page_shift;
+}
+
+__extern int daemon(int, int);
+
+/* Standard file descriptor numbers. */
+#define STDIN_FILENO 0
+#define STDOUT_FILENO 1
+#define STDERR_FILENO 2
+
+#endif /* _UNISTD_H */
diff --git a/klibc/include/utime.h b/klibc/include/utime.h
new file mode 100644
index 0000000000..3dfa03a14a
--- /dev/null
+++ b/klibc/include/utime.h
@@ -0,0 +1,15 @@
+/*
+ * 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 */
+