public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [klibc 00/31] klibc as a historyless patchset (updated and reorganized)
@ 2006-06-28  5:17 H. Peter Anvin
  2006-06-28  5:17 ` [klibc 01/31] Add klibc/kinit to MAINTAINERS file H. Peter Anvin
                   ` (30 more replies)
  0 siblings, 31 replies; 58+ messages in thread
From: H. Peter Anvin @ 2006-06-28  5:17 UTC (permalink / raw)
  To: linux-kernel, klibc, Linus Torvalds; +Cc: H. Peter Anvin

I have updated the klibc patchset based on feedback received.  In
particular, the patchset has been reorganized so as not to break
git-bisect.

Additionally, this updates the patch base to 2.6.17-git12
(d38b69689c349f35502b92e20dafb30c62d49d63) and klibc 1.4.8; the main
difference on the klibc side is removal of obsolete code.

This is also available as a git tree at:
git://git.kernel.org/pub/scm/linux/kernel/git/hpa/linux-2.6-klibc-clean.git

The full history klibc git tree is available at:
git://git.kernel.org/pub/scm/linux/kernel/git/hpa/linux-2.6-klibc.git

The files from the patchset are also available at:
http://www.kernel.org/pub/linux/kernel/people/hpa/klibc-patchset/

This patchset corresponds to version 1.4.8 of the standalone klibc
distribution.

Initial infrastructure:

01-add-klibckinit-to-maintainers-file.patch
02-main-makefile-changes-for-klibc.patch

Klibc proper (only added as inert files at this point):

03-core-klibc-code.patch
04-alpha-support-for-klibc.patch
05-arm-support-for-klibc.patch
06-cris-support-for-klibc.patch
07-i386-support-for-klibc.patch
08-ia64-support-for-klibc.patch
09-m32r-support-for-klibc.patch
10-m68k-support-for-klibc.patch
11-mips-support-for-klibc.patch
12-mips64-support-for-klibc.patch
13-parisc-support-for-klibc.patch
14-ppc-support-for-klibc.patch
15-ppc64-support-for-klibc.patch
16-s390-support-for-klibc.patch
17-sh-support-for-klibc.patch
18-sparc-support-for-klibc.patch
19-sparc64-support-for-klibc.patch
20-x86-64-support-for-klibc.patch
21-simple-test-suite-for-klibc.patch
22-zlib-for-klibc.patch

Kinit:

23-kinit-replacement-for-in-kernel-do-mount-ipconfig-nfsroot.patch

Kbuild support for klibc (this activates the klibc/kinit build):

24-klibc-basic-build-infrastructure.patch

Optional utilities (it should be possible to omit without breakage):

25-miscellaneous-utilities-for-klibc.patch
26-dash---a-small-posix-shell-for-klibc.patch
27-a-port-of-gzip-to-klibc.patch

SPARC-specific support (export variables from openprom):

28-sparc64-transmit-arch-specific-options-to-kinit-via-arch-cmd.patch
29-sparc32-transfer-arch-specific-options-to-arch-cmd.patch

Removal of kernel resume from disk and root-mounting code:

30-remove-in-kernel-resume-from-disk-invocation-code.patch
31-remove-in-kernel-root-mounting-code.patch

^ permalink raw reply	[flat|nested] 58+ messages in thread

* [klibc 01/31] Add klibc/kinit to MAINTAINERS file
  2006-06-28  5:17 [klibc 00/31] klibc as a historyless patchset (updated and reorganized) H. Peter Anvin
@ 2006-06-28  5:17 ` H. Peter Anvin
  2006-06-28  5:17 ` [klibc 02/31] Main Makefile changes for klibc H. Peter Anvin
                   ` (29 subsequent siblings)
  30 siblings, 0 replies; 58+ messages in thread
From: H. Peter Anvin @ 2006-06-28  5:17 UTC (permalink / raw)
  To: linux-kernel, klibc; +Cc: H. Peter Anvin

Signed-off-by: H. Peter Anvin <hpa@zytor.com>

---
commit 9371ae0abc260d3f87f243b364e86d837a3a23fd
tree 25d49641dc6ff9858056a5a19485602073a11166
parent d38b69689c349f35502b92e20dafb30c62d49d63
author H. Peter Anvin <hpa@zytor.com> Sat, 25 Mar 2006 16:36:59 -0800
committer H. Peter Anvin <hpa@zytor.com> Tue, 27 Jun 2006 20:50:19 -0700

 MAINTAINERS |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/MAINTAINERS b/MAINTAINERS
index 31a1372..393a7cc 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1651,6 +1651,13 @@ L:	linux-kernel@vger.kernel.org
 L:	fastboot@osdl.org
 S:	Maintained
 
+KLIBC/KINIT
+P:	H. Peter Anvin
+M:	hpa@zytor.com
+L:	klibc@zytor.com
+T:	git kernel.org:pub/scm/linux/kernel/git/hpa/linux-2.6-klibc.git
+S:	Maintained
+
 KPROBES
 P:	Prasanna S Panchamukhi
 M:	prasanna@in.ibm.com

^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [klibc 02/31] Main Makefile changes for klibc
  2006-06-28  5:17 [klibc 00/31] klibc as a historyless patchset (updated and reorganized) H. Peter Anvin
  2006-06-28  5:17 ` [klibc 01/31] Add klibc/kinit to MAINTAINERS file H. Peter Anvin
@ 2006-06-28  5:17 ` H. Peter Anvin
  2006-06-28  5:17 ` [klibc 03/31] Core klibc code H. Peter Anvin
                   ` (28 subsequent siblings)
  30 siblings, 0 replies; 58+ messages in thread
From: H. Peter Anvin @ 2006-06-28  5:17 UTC (permalink / raw)
  To: linux-kernel, klibc; +Cc: H. Peter Anvin

klibc requires that the main Makefile exports RANLIB, KLIBCARCH and
KLIBCARCHDIR.  KLIBCARCH and KLIBCARCHDIR are usually the same as
ARCH, but there are a few exceptions:

powerpc: KLIBCARCH is ppc or ppc64, KLIBCARCHDIR is powerpc
s390:	 KLIBCARCH is s390 or s390x, KLIBCARCHDIR is s390
um:      KLIBCARCH is the underlying architecture,
         KLIBCARCHDIR is set by that architecture.

s390 support by Heiko Carstens <heiko.carstens@de.ibm.com>.

Additionally, add support for building single files that have to be
built with klibc rules.  Support by Sam Ravnborg <sam@ravnborg.org>.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>

---
commit 6af9454fcd8dc22f657feff4f31923e3aa73c475
tree abf579fa4cca8e409474e9cd2a65201f8691bbb1
parent 9371ae0abc260d3f87f243b364e86d837a3a23fd
author H. Peter Anvin <hpa@zytor.com> Tue, 27 Jun 2006 20:50:21 -0700
committer H. Peter Anvin <hpa@zytor.com> Tue, 27 Jun 2006 20:50:21 -0700

 Makefile              |   32 +++++++++++++++++++++++---------
 arch/powerpc/Makefile |    1 +
 arch/s390/Makefile    |    4 ++++
 arch/um/Makefile      |    2 ++
 4 files changed, 30 insertions(+), 9 deletions(-)

diff --git a/Makefile b/Makefile
index e9560c6..6a4c559 100644
--- a/Makefile
+++ b/Makefile
@@ -176,7 +176,16 @@ ARCH		?= $(SUBARCH)
 CROSS_COMPILE	?=
 
 # Architecture as present in compile.h
-UTS_MACHINE := $(ARCH)
+UTS_MACHINE	:= $(ARCH)
+
+# Architecture used to compile user-space code
+KLIBCARCH	?= $(ARCH)
+KLIBCARCHDIR	?= $(KLIBCARCH)
+
+# klibc definitions
+export KLIBCINC := usr/include
+export KLIBCSRC := $(srctree)/usr/klibc
+export KLIBCOBJ := $(objtree)/usr/klibc
 
 KCONFIG_CONFIG	?= .config
 
@@ -278,6 +287,7 @@ LD		= $(CROSS_COMPILE)ld
 CC		= $(CROSS_COMPILE)gcc
 CPP		= $(CC) -E
 AR		= $(CROSS_COMPILE)ar
+RANLIB		= $(CROSS_COMPILE)ranlib
 NM		= $(CROSS_COMPILE)nm
 STRIP		= $(CROSS_COMPILE)strip
 OBJCOPY		= $(CROSS_COMPILE)objcopy
@@ -318,6 +328,7 @@ export VERSION PATCHLEVEL SUBLEVEL KERNE
 export ARCH CONFIG_SHELL HOSTCC HOSTCFLAGS CROSS_COMPILE AS LD CC
 export CPP AR NM STRIP OBJCOPY OBJDUMP MAKE AWK GENKSYMS PERL UTS_MACHINE
 export HOSTCXX HOSTCXXFLAGS LDFLAGS_MODULE CHECK CHECKFLAGS
+export RANLIB KLIBCARCH KLIBCARCHDIR
 
 export CPPFLAGS NOSTDINC_FLAGS LINUXINCLUDE OBJCOPYFLAGS LDFLAGS
 export CFLAGS CFLAGS_KERNEL CFLAGS_MODULE
@@ -1303,41 +1314,44 @@ # Single targets are compatible with:
 # - build whith mixed source and output
 # - build with separate output dir 'make O=...'
 # - external modules
+# - klibc library and klibc programs (everything under usr/)
 #
 #  target-dir => where to store outputfile
 #  build-dir  => directory in kernel source tree to use
 
 ifeq ($(KBUILD_EXTMOD),)
+        singlebld  = $(if $(filter usr/%,$(dir $@)),$(klibc),$(build))
         build-dir  = $(patsubst %/,%,$(dir $@))
         target-dir = $(dir $@)
 else
+        singlebld  = $(build)
         zap-slash=$(filter-out .,$(patsubst %/,%,$(dir $@)))
         build-dir  = $(KBUILD_EXTMOD)$(if $(zap-slash),/$(zap-slash))
         target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
 endif
 
 %.s: %.c prepare scripts FORCE
-	$(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
+	$(Q)$(MAKE) $(singlebld)=$(build-dir) $(target-dir)$(notdir $@)
 %.i: %.c prepare scripts FORCE
-	$(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
+	$(Q)$(MAKE) $(singlebld)=$(build-dir) $(target-dir)$(notdir $@)
 %.o: %.c prepare scripts FORCE
-	$(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
+	$(Q)$(MAKE) $(singlebld)=$(build-dir) $(target-dir)$(notdir $@)
 %.lst: %.c prepare scripts FORCE
-	$(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
+	$(Q)$(MAKE) $(singlebld)=$(build-dir) $(target-dir)$(notdir $@)
 %.s: %.S prepare scripts FORCE
-	$(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
+	$(Q)$(MAKE) $(singlebld)=$(build-dir) $(target-dir)$(notdir $@)
 %.o: %.S prepare scripts FORCE
-	$(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
+	$(Q)$(MAKE) $(singlebld)=$(build-dir) $(target-dir)$(notdir $@)
 %.symtypes: %.c prepare scripts FORCE
 	$(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
 
 # Modules
 / %/: prepare scripts FORCE
 	$(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
-	$(build)=$(build-dir)
+	$(singlebld)=$(build-dir)
 %.ko: prepare scripts FORCE
 	$(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1)   \
-	$(build)=$(build-dir) $(@:.ko=.o)
+	$(singlebld)=$(build-dir) $(@:.ko=.o)
 	$(Q)$(MAKE) -rR -f $(srctree)/scripts/Makefile.modpost
 
 # FIXME Should go into a make.lib or something 
diff --git a/arch/powerpc/Makefile b/arch/powerpc/Makefile
index 01667d1..db9e79c 100644
--- a/arch/powerpc/Makefile
+++ b/arch/powerpc/Makefile
@@ -51,6 +51,7 @@ SZ	:= 32
 endif
 
 UTS_MACHINE := $(OLDARCH)
+KLIBCARCH   := $(OLDARCH)
 
 ifeq ($(HAS_BIARCH),y)
 override AS	+= -a$(SZ)
diff --git a/arch/s390/Makefile b/arch/s390/Makefile
index b3791fb..30832b3 100644
--- a/arch/s390/Makefile
+++ b/arch/s390/Makefile
@@ -20,6 +20,7 @@ AFLAGS		+= -m31
 UTS_MACHINE	:= s390
 STACK_SIZE	:= 8192
 CHECKFLAGS	+= -D__s390__
+KLIBCARCH	:= s390
 else
 LDFLAGS		:= -m elf64_s390
 MODFLAGS	+= -fpic -D__PIC__
@@ -28,8 +29,11 @@ AFLAGS		+= -m64
 UTS_MACHINE	:= s390x
 STACK_SIZE	:= 16384
 CHECKFLAGS	+= -D__s390__ -D__s390x__
+KLIBCARCH	:= s390x
 endif
 
+KLIBCARCHDIR	:= s390
+
 cflags-$(CONFIG_MARCH_G5)   += $(call cc-option,-march=g5)
 cflags-$(CONFIG_MARCH_Z900) += $(call cc-option,-march=z900)
 cflags-$(CONFIG_MARCH_Z990) += $(call cc-option,-march=z990)
diff --git a/arch/um/Makefile b/arch/um/Makefile
index f6ad832..f8e96f2 100644
--- a/arch/um/Makefile
+++ b/arch/um/Makefile
@@ -50,6 +50,8 @@ ARCH_INCLUDE	+= -I$(srctree)/$(ARCH_DIR)
 endif
 SYS_DIR		:= $(ARCH_DIR)/include/sysdep-$(SUBARCH)
 
+KLIBCARCH	:= $(SUBARCH)
+
 # -Dvmap=kernel_vmap prevents anything from referencing the libpcap.o symbol so
 # named - it's a common symbol in libpcap, so we get a binary which crashes.
 #

^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [klibc 03/31] Core klibc code
  2006-06-28  5:17 [klibc 00/31] klibc as a historyless patchset (updated and reorganized) H. Peter Anvin
  2006-06-28  5:17 ` [klibc 01/31] Add klibc/kinit to MAINTAINERS file H. Peter Anvin
  2006-06-28  5:17 ` [klibc 02/31] Main Makefile changes for klibc H. Peter Anvin
@ 2006-06-28  5:17 ` H. Peter Anvin
  2006-06-28  5:17 ` [klibc 04/31] alpha support for klibc H. Peter Anvin
                   ` (27 subsequent siblings)
  30 siblings, 0 replies; 58+ messages in thread
From: H. Peter Anvin @ 2006-06-28  5:17 UTC (permalink / raw)
  To: linux-kernel, klibc; +Cc: H. Peter Anvin

[klibc] Core klibc code

The actual klibc library.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>

---
commit 7e8269dfd52a48d7b5017a1aaac410e9656c8139
tree 765b566dc009f529c44a7351bd1896478b9a90bd
parent 6af9454fcd8dc22f657feff4f31923e3aa73c475
author H. Peter Anvin <hpa@zytor.com> Tue, 27 Jun 2006 20:50:25 -0700
committer H. Peter Anvin <hpa@zytor.com> Tue, 27 Jun 2006 20:50:25 -0700

 usr/include/Kbuild                        |   11 +
 usr/include/alloca.h                      |   12 +
 usr/include/arpa/inet.h                   |   22 +
 usr/include/assert.h                      |   22 +
 usr/include/bits32/bitsize.h              |    3 
 usr/include/bits32/bitsize/limits.h       |   14 +
 usr/include/bits32/bitsize/stddef.h       |   18 +
 usr/include/bits32/bitsize/stdint.h       |   34 ++
 usr/include/bits32/bitsize/stdintconst.h  |   18 +
 usr/include/bits32/bitsize/stdintlimits.h |   22 +
 usr/include/bits64/bitsize.h              |    3 
 usr/include/bits64/bitsize/limits.h       |   14 +
 usr/include/bits64/bitsize/stddef.h       |   13 +
 usr/include/bits64/bitsize/stdint.h       |   34 ++
 usr/include/bits64/bitsize/stdintconst.h  |   18 +
 usr/include/bits64/bitsize/stdintlimits.h |   22 +
 usr/include/byteswap.h                    |   15 +
 usr/include/ctype.h                       |  140 ++++++++
 usr/include/dirent.h                      |   33 ++
 usr/include/elf.h                         |   11 +
 usr/include/endian.h                      |   15 +
 usr/include/errno.h                       |   13 +
 usr/include/fcntl.h                       |   47 +++
 usr/include/grp.h                         |   13 +
 usr/include/inttypes.h                    |  226 +++++++++++++
 usr/include/klibc/compiler.h              |  123 +++++++
 usr/include/klibc/diverr.h                |   15 +
 usr/include/klibc/endian.h                |   39 ++
 usr/include/klibc/extern.h                |   16 +
 usr/include/klibc/stathelp.h              |   24 +
 usr/include/klibc/sysconfig.h             |  166 ++++++++++
 usr/include/limits.h                      |   40 ++
 usr/include/malloc.h                      |   21 +
 usr/include/net/if.h                      |    7 
 usr/include/net/if_arp.h                  |    1 
 usr/include/net/if_packet.h               |    1 
 usr/include/net/route.h                   |    1 
 usr/include/netinet/if_ether.h            |    1 
 usr/include/netinet/in.h                  |   39 ++
 usr/include/netinet/in6.h                 |   10 +
 usr/include/netinet/ip.h                  |   13 +
 usr/include/netinet/tcp.h                 |   11 +
 usr/include/netinet/udp.h                 |   19 +
 usr/include/netpacket/packet.h            |    1 
 usr/include/paths.h                       |   74 ++++
 usr/include/poll.h                        |    1 
 usr/include/sched.h                       |   36 ++
 usr/include/setjmp.h                      |   43 +++
 usr/include/signal.h                      |   97 ++++++
 usr/include/stdarg.h                      |   14 +
 usr/include/stddef.h                      |   24 +
 usr/include/stdint.h                      |  116 +++++++
 usr/include/stdio.h                       |  128 ++++++++
 usr/include/stdlib.h                      |   94 ++++++
 usr/include/string.h                      |   47 +++
 usr/include/sys/dirent.h                  |   32 ++
 usr/include/sys/elf32.h                   |  113 +++++++
 usr/include/sys/elf64.h                   |  113 +++++++
 usr/include/sys/elfcommon.h               |  187 +++++++++++
 usr/include/sys/fsuid.h                   |   14 +
 usr/include/sys/inotify.h                 |   16 +
 usr/include/sys/ioctl.h                   |   14 +
 usr/include/sys/klog.h                    |   24 +
 usr/include/sys/md.h                      |   32 ++
 usr/include/sys/mman.h                    |   24 +
 usr/include/sys/mount.h                   |   71 ++++
 usr/include/sys/param.h                   |   11 +
 usr/include/sys/poll.h                    |   20 +
 usr/include/sys/reboot.h                  |   25 +
 usr/include/sys/resource.h                |   15 +
 usr/include/sys/select.h                  |   17 +
 usr/include/sys/sendfile.h                |   14 +
 usr/include/sys/socket.h                  |   44 +++
 usr/include/sys/socketcalls.h             |   28 ++
 usr/include/sys/splice.h                  |   19 +
 usr/include/sys/stat.h                    |   33 ++
 usr/include/sys/statfs.h                  |    1 
 usr/include/sys/syscall.h                 |   13 +
 usr/include/sys/sysinfo.h                 |   12 +
 usr/include/sys/sysmacros.h               |   34 ++
 usr/include/sys/time.h                    |   18 +
 usr/include/sys/times.h                   |   14 +
 usr/include/sys/types.h                   |  111 +++++++
 usr/include/sys/uio.h                     |   15 +
 usr/include/sys/un.h                      |   10 +
 usr/include/sys/utime.h                   |   10 +
 usr/include/sys/utsname.h                 |   23 +
 usr/include/sys/vfs.h                     |  115 +++++++
 usr/include/sys/wait.h                    |   28 ++
 usr/include/syslog.h                      |   62 ++++
 usr/include/termios.h                     |   91 +++++
 usr/include/time.h                        |   18 +
 usr/include/unistd.h                      |  159 +++++++++
 usr/include/utime.h                       |   14 +
 usr/klibc/CAVEATS                         |   60 ++++
 usr/klibc/Kbuild                          |  186 +++++++++++
 usr/klibc/LICENSE                         |   73 ++++
 usr/klibc/README                          |   80 +++++
 usr/klibc/SOCKETCALLS.def                 |   21 +
 usr/klibc/SYSCALLS.def                    |  260 +++++++++++++++
 usr/klibc/__put_env.c                     |   74 ++++
 usr/klibc/__shared_init.c                 |    2 
 usr/klibc/__signal.c                      |   20 +
 usr/klibc/__static_init.c                 |    2 
 usr/klibc/abort.c                         |   18 +
 usr/klibc/alarm.c                         |   25 +
 usr/klibc/arch/README                     |   81 +++++
 usr/klibc/asprintf.c                      |   30 ++
 usr/klibc/assert.c                        |   14 +
 usr/klibc/atexit.c                        |   10 +
 usr/klibc/atexit.h                        |   18 +
 usr/klibc/atoi.c                          |    3 
 usr/klibc/atol.c                          |    3 
 usr/klibc/atoll.c                         |    3 
 usr/klibc/atox.c                          |   14 +
 usr/klibc/brk.c                           |   24 +
 usr/klibc/bsd_signal.c                    |   11 +
 usr/klibc/bsearch.c                       |   26 ++
 usr/klibc/calloc.c                        |   20 +
 usr/klibc/clearenv.c                      |   17 +
 usr/klibc/closelog.c                      |   18 +
 usr/klibc/creat.c                         |   12 +
 usr/klibc/ctype/ctypefunc.h               |   13 +
 usr/klibc/ctype/isalnum.c                 |    2 
 usr/klibc/ctype/isalpha.c                 |    2 
 usr/klibc/ctype/isascii.c                 |    2 
 usr/klibc/ctype/isblank.c                 |    2 
 usr/klibc/ctype/iscntrl.c                 |    2 
 usr/klibc/ctype/isdigit.c                 |    2 
 usr/klibc/ctype/isgraph.c                 |    2 
 usr/klibc/ctype/islower.c                 |    2 
 usr/klibc/ctype/isprint.c                 |    2 
 usr/klibc/ctype/ispunct.c                 |    2 
 usr/klibc/ctype/isspace.c                 |    2 
 usr/klibc/ctype/isupper.c                 |    2 
 usr/klibc/ctype/isxdigit.c                |    2 
 usr/klibc/ctype/tolower.c                 |    2 
 usr/klibc/ctype/toupper.c                 |    2 
 usr/klibc/ctypes.c                        |  284 +++++++++++++++++
 usr/klibc/daemon.c                        |   35 ++
 usr/klibc/env.h                           |   10 +
 usr/klibc/exec_l.c                        |   59 ++++
 usr/klibc/execl.c                         |    8 
 usr/klibc/execle.c                        |    8 
 usr/klibc/execlp.c                        |    8 
 usr/klibc/execlpe.c                       |    8 
 usr/klibc/execv.c                         |   11 +
 usr/klibc/execvp.c                        |   11 +
 usr/klibc/execvpe.c                       |   75 ++++
 usr/klibc/exit.c                          |   30 ++
 usr/klibc/fgetc.c                         |   19 +
 usr/klibc/fgets.c                         |   31 ++
 usr/klibc/fopen.c                         |   39 ++
 usr/klibc/fork.c                          |   21 +
 usr/klibc/fprintf.c                       |   19 +
 usr/klibc/fputc.c                         |   14 +
 usr/klibc/fputs.c                         |   15 +
 usr/klibc/fread.c                         |   33 ++
 usr/klibc/fread2.c                        |   13 +
 usr/klibc/fstatfs.c                       |   19 +
 usr/klibc/fwrite.c                        |   33 ++
 usr/klibc/fwrite2.c                       |   13 +
 usr/klibc/getcwd.c                        |   15 +
 usr/klibc/getdomainname.c                 |   25 +
 usr/klibc/getenv.c                        |   24 +
 usr/klibc/gethostname.c                   |   25 +
 usr/klibc/getopt.c                        |   97 ++++++
 usr/klibc/getpgrp.c                       |   10 +
 usr/klibc/getpriority.c                   |   23 +
 usr/klibc/getpt.c                         |   17 +
 usr/klibc/globals.c                       |   10 +
 usr/klibc/inet/bindresvport.c             |   46 +++
 usr/klibc/inet/inet_addr.c                |   14 +
 usr/klibc/inet/inet_aton.c                |   22 +
 usr/klibc/inet/inet_ntoa.c                |   16 +
 usr/klibc/inet/inet_ntop.c                |   53 +++
 usr/klibc/inet/inet_pton.c                |   78 +++++
 usr/klibc/interp.S                        |   13 +
 usr/klibc/isatty.c                        |   20 +
 usr/klibc/jrand48.c                       |   24 +
 usr/klibc/libc_init.c                     |  107 ++++++
 usr/klibc/libgcc/__ashldi3.c              |   23 +
 usr/klibc/libgcc/__ashrdi3.c              |   23 +
 usr/klibc/libgcc/__clzsi2.c               |   36 ++
 usr/klibc/libgcc/__divdi3.c               |   29 ++
 usr/klibc/libgcc/__divsi3.c               |   29 ++
 usr/klibc/libgcc/__lshrdi3.c              |   23 +
 usr/klibc/libgcc/__moddi3.c               |   29 ++
 usr/klibc/libgcc/__modsi3.c               |   29 ++
 usr/klibc/libgcc/__udivdi3.c              |   13 +
 usr/klibc/libgcc/__udivmoddi4.c           |   32 ++
 usr/klibc/libgcc/__udivmodsi4.c           |   32 ++
 usr/klibc/libgcc/__udivsi3.c              |   13 +
 usr/klibc/libgcc/__umoddi3.c              |   16 +
 usr/klibc/libgcc/__umodsi3.c              |   16 +
 usr/klibc/llseek.c                        |   30 ++
 usr/klibc/lrand48.c                       |   13 +
 usr/klibc/makeerrlist.pl                  |   98 ++++++
 usr/klibc/malloc.c                        |  200 ++++++++++++
 usr/klibc/malloc.h                        |   47 +++
 usr/klibc/memccpy.c                       |   23 +
 usr/klibc/memchr.c                        |   19 +
 usr/klibc/memcmp.c                        |   19 +
 usr/klibc/memcpy.c                        |   29 ++
 usr/klibc/memmem.c                        |   52 +++
 usr/klibc/memmove.c                       |   36 ++
 usr/klibc/memrchr.c                       |   19 +
 usr/klibc/memset.c                        |   30 ++
 usr/klibc/memswap.c                       |   24 +
 usr/klibc/mmap.c                          |   40 ++
 usr/klibc/mrand48.c                       |   13 +
 usr/klibc/nice.c                          |   19 +
 usr/klibc/nrand48.c                       |   11 +
 usr/klibc/nullenv.c                       |    8 
 usr/klibc/onexit.c                        |   23 +
 usr/klibc/open.c                          |   22 +
 usr/klibc/openat.c                        |   22 +
 usr/klibc/pause.c                         |   17 +
 usr/klibc/perror.c                        |   13 +
 usr/klibc/ppoll.c                         |   19 +
 usr/klibc/printf.c                        |   19 +
 usr/klibc/pselect.c                       |   42 ++
 usr/klibc/pty.c                           |   31 ++
 usr/klibc/putchar.c                       |   15 +
 usr/klibc/putenv.c                        |   37 ++
 usr/klibc/puts.c                          |   13 +
 usr/klibc/qsort.c                         |   42 ++
 usr/klibc/raise.c                         |   11 +
 usr/klibc/readdir.c                       |   57 +++
 usr/klibc/realloc.c                       |   48 +++
 usr/klibc/reboot.c                        |   15 +
 usr/klibc/recv.c                          |   11 +
 usr/klibc/remove.c                        |   18 +
 usr/klibc/sbrk.c                          |   45 +++
 usr/klibc/seed48.c                        |   18 +
 usr/klibc/send.c                          |   11 +
 usr/klibc/setegid.c                       |   10 +
 usr/klibc/setenv.c                        |   42 ++
 usr/klibc/seteuid.c                       |   10 +
 usr/klibc/setpgrp.c                       |   10 +
 usr/klibc/sha1hash.c                      |  317 +++++++++++++++++++
 usr/klibc/sigabbrev.c                     |  121 +++++++
 usr/klibc/sigaction.c                     |   60 ++++
 usr/klibc/siglist.c                       |  121 +++++++
 usr/klibc/siglongjmp.c                    |   15 +
 usr/klibc/sigpending.c                    |   18 +
 usr/klibc/sigprocmask.c                   |   18 +
 usr/klibc/sigsuspend.c                    |   18 +
 usr/klibc/sleep.c                         |   20 +
 usr/klibc/snprintf.c                      |   16 +
 usr/klibc/socketcalls.pl                  |   88 +++++
 usr/klibc/socketcalls/Kbuild              |   50 +++
 usr/klibc/socketcalls/socketcommon.h      |   16 +
 usr/klibc/sprintf.c                       |   18 +
 usr/klibc/srand48.c                       |   15 +
 usr/klibc/sscanf.c                        |   17 +
 usr/klibc/statfs.c                        |   19 +
 usr/klibc/strcasecmp.c                    |   24 +
 usr/klibc/strcat.c                        |   11 +
 usr/klibc/strchr.c                        |   19 +
 usr/klibc/strcmp.c                        |   21 +
 usr/klibc/strcpy.c                        |   20 +
 usr/klibc/strcspn.c                       |   10 +
 usr/klibc/strdup.c                        |   17 +
 usr/klibc/strerror.c                      |   33 ++
 usr/klibc/strlcat.c                       |   31 ++
 usr/klibc/strlcpy.c                       |   27 ++
 usr/klibc/strlen.c                        |   13 +
 usr/klibc/strncasecmp.c                   |   24 +
 usr/klibc/strncat.c                       |   22 +
 usr/klibc/strncmp.c                       |   21 +
 usr/klibc/strncpy.c                       |   24 +
 usr/klibc/strndup.c                       |   17 +
 usr/klibc/strnlen.c                       |   18 +
 usr/klibc/strntoimax.c                    |   13 +
 usr/klibc/strntoumax.c                    |   76 +++++
 usr/klibc/strpbrk.c                       |   12 +
 usr/klibc/strrchr.c                       |   21 +
 usr/klibc/strsep.c                        |   21 +
 usr/klibc/strsignal.c                     |   26 ++
 usr/klibc/strspn.c                        |   10 +
 usr/klibc/strstr.c                        |   11 +
 usr/klibc/strtoimax.c                     |    3 
 usr/klibc/strtok.c                        |   15 +
 usr/klibc/strtol.c                        |    3 
 usr/klibc/strtoll.c                       |    3 
 usr/klibc/strtotimespec.c                 |    5 
 usr/klibc/strtotimeval.c                  |    5 
 usr/klibc/strtotimex.c                    |   39 ++
 usr/klibc/strtoul.c                       |    3 
 usr/klibc/strtoull.c                      |    3 
 usr/klibc/strtoumax.c                     |    3 
 usr/klibc/strtox.c                        |   13 +
 usr/klibc/strxspn.c                       |   29 ++
 usr/klibc/strxspn.h                       |   12 +
 usr/klibc/syscalls.pl                     |  286 +++++++++++++++++
 usr/klibc/syscalls/Kbuild                 |   94 ++++++
 usr/klibc/syscalls/syscommon.h            |   33 ++
 usr/klibc/syslog.c                        |   89 +++++
 usr/klibc/system.c                        |   61 ++++
 usr/klibc/sysv_signal.c                   |   11 +
 usr/klibc/time.c                          |   23 +
 usr/klibc/umount.c                        |   12 +
 usr/klibc/unsetenv.c                      |   44 +++
 usr/klibc/usleep.c                        |   15 +
 usr/klibc/utime.c                         |   24 +
 usr/klibc/vasprintf.c                     |   25 +
 usr/klibc/version                         |    1 
 usr/klibc/vfork.c                         |   13 +
 usr/klibc/vfprintf.c                      |   26 ++
 usr/klibc/vprintf.c                       |   11 +
 usr/klibc/vsnprintf.c                     |  488 +++++++++++++++++++++++++++++
 usr/klibc/vsprintf.c                      |   11 +
 usr/klibc/vsscanf.c                       |  378 ++++++++++++++++++++++
 usr/klibc/wait.c                          |   12 +
 usr/klibc/wait3.c                         |   12 +
 usr/klibc/waitpid.c                       |   12 +
 317 files changed, 11252 insertions(+), 0 deletions(-)

Patch suppressed due to size (324 K), available at:
http://www.kernel.org/pub/linux/kernel/people/hpa/klibc-patchset/03-core-klibc-code.patch

^ permalink raw reply	[flat|nested] 58+ messages in thread

* [klibc 04/31] alpha support for klibc
  2006-06-28  5:17 [klibc 00/31] klibc as a historyless patchset (updated and reorganized) H. Peter Anvin
                   ` (2 preceding siblings ...)
  2006-06-28  5:17 ` [klibc 03/31] Core klibc code H. Peter Anvin
@ 2006-06-28  5:17 ` H. Peter Anvin
  2006-06-28 15:43   ` Richard Henderson
  2006-06-28  5:17 ` [klibc 05/31] arm " H. Peter Anvin
                   ` (26 subsequent siblings)
  30 siblings, 1 reply; 58+ messages in thread
From: H. Peter Anvin @ 2006-06-28  5:17 UTC (permalink / raw)
  To: linux-kernel, klibc; +Cc: H. Peter Anvin

The parts of klibc specific to the alpha architecture.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>

---
commit c3fe3fde33e77fa6c09cb43ca3783e6bf36ef895
tree ab9ab1f40c31a5d430a3e6fbc6ef33640004c0f9
parent 7e8269dfd52a48d7b5017a1aaac410e9656c8139
author H. Peter Anvin <hpa@zytor.com> Tue, 27 Jun 2006 20:50:27 -0700
committer H. Peter Anvin <hpa@zytor.com> Tue, 27 Jun 2006 20:50:27 -0700

 usr/include/arch/alpha/klibc/archconfig.h |   15 ++++++
 usr/include/arch/alpha/klibc/archsetjmp.h |   33 +++++++++++++
 usr/include/arch/alpha/klibc/archsignal.h |   14 +++++
 usr/include/arch/alpha/klibc/archstat.h   |   28 +++++++++++
 usr/include/arch/alpha/machine/asm.h      |   44 +++++++++++++++++
 usr/klibc/arch/alpha/MCONFIG              |   16 ++++++
 usr/klibc/arch/alpha/Makefile.inc         |   60 +++++++++++++++++++++++
 usr/klibc/arch/alpha/README-gcc           |   22 +++++++++
 usr/klibc/arch/alpha/crt0.S               |   22 +++++++++
 usr/klibc/arch/alpha/divide.c             |   59 +++++++++++++++++++++++
 usr/klibc/arch/alpha/pipe.S               |   38 +++++++++++++++
 usr/klibc/arch/alpha/setjmp.S             |   75 +++++++++++++++++++++++++++++
 usr/klibc/arch/alpha/syscall.S            |   26 ++++++++++
 usr/klibc/arch/alpha/sysdual.S            |   33 +++++++++++++
 usr/klibc/arch/alpha/sysstub.ph           |   37 ++++++++++++++
 15 files changed, 522 insertions(+), 0 deletions(-)

diff --git a/usr/include/arch/alpha/klibc/archconfig.h b/usr/include/arch/alpha/klibc/archconfig.h
new file mode 100644
index 0000000..272fee0
--- /dev/null
+++ b/usr/include/arch/alpha/klibc/archconfig.h
@@ -0,0 +1,15 @@
+/*
+ * include/arch/alpha/klibc/archconfig.h
+ *
+ * See include/klibc/sysconfig.h for the options that can be set in
+ * this file.
+ *
+ */
+
+#ifndef _KLIBC_ARCHCONFIG_H
+#define _KLIBC_ARCHCONFIG_H
+
+#define _KLIBC_USE_RT_SIG 1
+#define _KLIBC_STATFS_F_TYPE_64 0
+
+#endif				/* _KLIBC_ARCHCONFIG_H */
diff --git a/usr/include/arch/alpha/klibc/archsetjmp.h b/usr/include/arch/alpha/klibc/archsetjmp.h
new file mode 100644
index 0000000..47638b3
--- /dev/null
+++ b/usr/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/usr/include/arch/alpha/klibc/archsignal.h b/usr/include/arch/alpha/klibc/archsignal.h
new file mode 100644
index 0000000..2193a35
--- /dev/null
+++ b/usr/include/arch/alpha/klibc/archsignal.h
@@ -0,0 +1,14 @@
+/*
+ * arch/alpha/include/klibc/archsignal.h
+ *
+ * Architecture-specific signal definitions
+ *
+ */
+
+#ifndef _KLIBC_ARCHSIGNAL_H
+#define _KLIBC_ARCHSIGNAL_H
+
+#include <asm/signal.h>
+/* No special stuff for this architecture */
+
+#endif
diff --git a/usr/include/arch/alpha/klibc/archstat.h b/usr/include/arch/alpha/klibc/archstat.h
new file mode 100644
index 0000000..66e29be
--- /dev/null
+++ b/usr/include/arch/alpha/klibc/archstat.h
@@ -0,0 +1,28 @@
+#ifndef _KLIBC_ARCHSTAT_H
+#define _KLIBC_ARCHSTAT_H
+
+#include <klibc/stathelp.h>
+
+#define _STATBUF_ST_NSEC
+
+struct stat {
+	__stdev64	(st_dev);
+	unsigned long	st_ino;
+	__stdev64	(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/usr/include/arch/alpha/machine/asm.h b/usr/include/arch/alpha/machine/asm.h
new file mode 100644
index 0000000..c2ae4ed
--- /dev/null
+++ b/usr/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/usr/klibc/arch/alpha/MCONFIG b/usr/klibc/arch/alpha/MCONFIG
new file mode 100644
index 0000000..4420cdb
--- /dev/null
+++ b/usr/klibc/arch/alpha/MCONFIG
@@ -0,0 +1,16 @@
+# -*- makefile -*-
+#
+# arch/alpha/MCONFIG
+#
+# Build configuration for this architecture
+#
+
+KLIBCOPTFLAGS = -Os
+KLIBCBITSIZE  = 64
+
+# Extra linkflags when building the shared version of the library
+# This address needs to be reachable using normal inter-module
+# calls, and work on the memory models for this architecture
+# 7 GB - normal binaries start at 4.5 GB, and the stack is below
+# the binary.
+KLIBCSHAREDFLAGS	= -Ttext 0x1c0000200
diff --git a/usr/klibc/arch/alpha/Makefile.inc b/usr/klibc/arch/alpha/Makefile.inc
new file mode 100644
index 0000000..9f51b7f
--- /dev/null
+++ b/usr/klibc/arch/alpha/Makefile.inc
@@ -0,0 +1,60 @@
+# -*- makefile -*-
+#
+# arch/alpha/Makefile.inc
+#
+# Special rules for this architecture.  Note that this is actually
+# included from the main Makefile, and that pathnames should be
+# accordingly.
+#
+
+# Special CFLAGS for the divide code
+DIVCFLAGS = $(KLIBCREQFLAGS) $(KLIBCARCHREQFLAGS) \
+	-O3 -fomit-frame-pointer -fcall-saved-1 -fcall-saved-2 \
+	-fcall-saved-3 -fcall-saved-4 -fcall-saved-5 -fcall-saved-6 \
+	-fcall-saved-7 -fcall-saved-8 -ffixed-15 -fcall-saved-16 \
+	-fcall-saved-17 -fcall-saved-18 -fcall-saved-19 -fcall-saved-20 \
+	-fcall-saved-21 -fcall-saved-22 -ffixed-23 -fcall-saved-24 \
+	-ffixed-25 -ffixed-27
+
+KLIBCARCHOBJS := arch/$(KLIBCARCH)/pipe.o     arch/$(KLIBCARCH)/setjmp.o
+KLIBCARCHOBJS += arch/$(KLIBCARCH)/syscall.o  arch/$(KLIBCARCH)/sysdual.o
+
+DIVOBJS += arch/$(KLIBCARCH)/__divqu.o \
+           arch/$(KLIBCARCH)/__remqu.o \
+           arch/$(KLIBCARCH)/__divq.o \
+           arch/$(KLIBCARCH)/__remq.o \
+           arch/$(KLIBCARCH)/__divlu.o \
+           arch/$(KLIBCARCH)/__remlu.o \
+           arch/$(KLIBCARCH)/__divl.o \
+           arch/$(KLIBCARCH)/__reml.o
+
+KLIBCARCHOBJS += $(DIVOBJS)
+
+quiet_cmd_regswap = REGSWAP $@
+      cmd_regswap = sed -e 's/\$$0\b/$$27/g'  -e 's/\$$24\b/$$99/g' \
+                        -e 's/\$$16\b/$$24/g' -e 's/\$$17\b/$$25/g' \
+                        -e 's/\$$26\b/$$23/g' -e 's/\$$99\b/$$16/g' < $< > $@
+
+# Use static pattern rule to avoid using a temporary file
+$(addprefix $(obj)/,$(DIVOBJS:.o=.S)): $(obj)/arch/$(KLIBCARCH)/%.S: \
+                                       $(obj)/arch/$(KLIBCARCH)/%.ss
+	$(call if_changed,regswap)
+
+quiet_cmd_genss = DIV-CC  $@
+      cmd_genss = $(CC) $(DIVCFLAGS) $(FILE_CFLAGS) \
+                        -DNAME=$(basename $(notdir $@)) -S -o $@ $<
+
+$(obj)/arch/$(KLIBCARCH)/%.ss: $(obj)/arch/$(KLIBCARCH)/divide.c
+	$(call if_changed,genss)
+
+$(obj)/arch/$(KLIBCARCH)/__divqu.ss: FILE_CFLAGS := -DSIGNED=0 -DREM=0 -DBITS=64
+$(obj)/arch/$(KLIBCARCH)/__remqu.ss: FILE_CFLAGS := -DSIGNED=0 -DREM=1 -DBITS=64
+$(obj)/arch/$(KLIBCARCH)/__divq.ss:  FILE_CFLAGS := -DSIGNED=1 -DREM=0 -DBITS=64
+$(obj)/arch/$(KLIBCARCH)/__remq.ss:  FILE_CFLAGS := -DSIGNED=1 -DREM=1 -DBITS=64
+$(obj)/arch/$(KLIBCARCH)/__divlu.ss: FILE_CFLAGS := -DSIGNED=0 -DREM=0 -DBITS=32
+$(obj)/arch/$(KLIBCARCH)/__remlu.ss: FILE_CFLAGS := -DSIGNED=0 -DREM=1 -DBITS=32
+$(obj)/arch/$(KLIBCARCH)/__divl.ss:  FILE_CFLAGS := -DSIGNED=1 -DREM=0 -DBITS=32
+$(obj)/arch/$(KLIBCARCH)/__reml.ss:  FILE_CFLAGS := -DSIGNED=1 -DREM=1 -DBITS=32
+
+targets     += $(DIVOBJS:.o=.S) $(DIVOBJS:.o=.ss)
+clean-files += $(DIVOBJS:.o=.S) $(DIVOBJS:.o=.ss)
diff --git a/usr/klibc/arch/alpha/README-gcc b/usr/klibc/arch/alpha/README-gcc
new file mode 100644
index 0000000..1d0052f
--- /dev/null
+++ b/usr/klibc/arch/alpha/README-gcc
@@ -0,0 +1,22 @@
+   The current Alpha chips don't provide hardware for integer
+   division.  The C compiler expects the functions
+
+        __divqu: 64-bit unsigned long divide
+        __remqu: 64-bit unsigned long remainder
+        __divq/__remq:   signed 64-bit
+        __divlu/__remlu: unsigned 32-bit
+        __divl/__reml:   signed 32-bit
+
+   These are not normal C functions: instead of the normal calling
+   sequence, these expect their arguments in registers t10 and t11, and
+   return the result in t12 (aka pv).  Register AT may be clobbered
+   (assembly temporary), anything else must be saved.
+
+   Furthermore, the return address is in t9 instead of ra.
+
+   Normal function	Divide functions
+   ---------------	----------------
+   v0 ($0)		t12/pv ($27)
+   a0 ($16)		t10 ($24)
+   a1 ($17)		t11 ($25)
+   ra ($26)		t9 ($23)
diff --git a/usr/klibc/arch/alpha/crt0.S b/usr/klibc/arch/alpha/crt0.S
new file mode 100644
index 0000000..5e2babb
--- /dev/null
+++ b/usr/klibc/arch/alpha/crt0.S
@@ -0,0 +1,22 @@
+#
+# arch/alpha/crt0.S
+#
+
+	.text
+	.type	_start,@function
+	.ent	_start, 0
+	.globl	_start
+_start:
+	.frame  $30, 0, $26, 0
+	mov	$31, $15
+	br	$29, 1f
+1:	ldgp	$29, 0($29)
+	.prologue 0
+
+	lda	$16, 0($30)		# ELF data structure
+	lda	$17, 0($0)		# atexit pointer
+
+	jsr	$26, __libc_init
+
+	.size	_start,.-_start
+	.end	_start
diff --git a/usr/klibc/arch/alpha/divide.c b/usr/klibc/arch/alpha/divide.c
new file mode 100644
index 0000000..c44254f
--- /dev/null
+++ b/usr/klibc/arch/alpha/divide.c
@@ -0,0 +1,59 @@
+#include <stdint.h>
+#include <asm/gentrap.h>
+#include <asm/pal.h>
+
+#if BITS == 64
+typedef uint64_t uint;
+typedef int64_t sint;
+#else
+typedef uint32_t uint;
+typedef int32_t sint;
+#endif
+
+#ifdef SIGNED
+typedef sint xint;
+#else
+typedef uint xint;
+#endif
+
+xint NAME(uint num, uint den)
+{
+	uint quot = 0, qbit = 1;
+	int minus = 0;
+	xint v;
+
+	if (den == 0) {
+		/* This is really $16, but $16 and $24 are exchanged by a script */
+		register unsigned long cause asm("$24") = GEN_INTDIV;
+		asm volatile ("call_pal %0"::"i" (PAL_gentrap), "r"(cause));
+		return 0;	/* If trap returns... */
+	}
+#if SIGNED
+	if ((sint) (num ^ den) < 0)
+		minus = 1;
+	if ((sint) num < 0)
+		num = -num;
+	if ((sint) den < 0)
+		den = -den;
+#endif
+
+	/* Left-justify denominator and count shift */
+	while ((sint) den >= 0) {
+		den <<= 1;
+		qbit <<= 1;
+	}
+
+	while (qbit) {
+		if (den <= num) {
+			num -= den;
+			quot += qbit;
+		}
+		den >>= 1;
+		qbit >>= 1;
+	}
+
+	v = (xint) (REM ? num : quot);
+	if (minus)
+		v = -v;
+	return v;
+}
diff --git a/usr/klibc/arch/alpha/pipe.S b/usr/klibc/arch/alpha/pipe.S
new file mode 100644
index 0000000..ee72413
--- /dev/null
+++ b/usr/klibc/arch/alpha/pipe.S
@@ -0,0 +1,38 @@
+#
+# arch/alpha/pipe.S
+#
+
+#
+# pipe() on alpha returns both file descriptors in registers --
+# $0 (v0) and $20 (a4) respectively.  This is unlike any other system call,
+# as far as I can tell.
+#
+
+#include <asm/unistd.h>
+#include <machine/asm.h>
+
+	.text
+	.align	3
+	.type	pipe, @function
+	.ent	pipe, 0
+	.globl	pipe
+pipe:
+	.frame	sp,0,ra,0
+	lda	v0, __NR_pipe
+	callsys
+	beq	a3, 1f
+	br	pv, 2f			# pv <- pc
+2:
+	ldgp	gp, 0(pv)
+	lda	a1, errno
+	lda	v0, -1(zero)
+	stl	a3, 0(a1)
+	ret	zero,(ra),1
+1:
+	stl	v0, 0(a0)
+	lda	v0, 0
+	stl	a4, 4(a0)
+	ret	zero,(ra),1
+
+	.size	pipe,.-pipe
+	.end	pipe
diff --git a/usr/klibc/arch/alpha/setjmp.S b/usr/klibc/arch/alpha/setjmp.S
new file mode 100644
index 0000000..ed604bd
--- /dev/null
+++ b/usr/klibc/arch/alpha/setjmp.S
@@ -0,0 +1,75 @@
+#
+# setjmp.S
+#
+
+#
+# The jmp_buf looks like:
+#
+#	s0..5
+#	fp
+#	ra
+#	gp
+#	sp
+#
+
+#include <machine/asm.h>
+
+	.text
+	.align	3
+	.type	setjmp,@function
+	.ent	setjmp, 0
+	.globl	setjmp
+setjmp:
+	lda	v0,   0(zero)
+	stq	s0,   0(a0)
+	stq	s1,   8(a0)
+	stq	s2,  16(a0)
+	stq	s3,  24(a0)
+	stq	s4,  32(a0)
+	stq	s5,  40(a0)
+	stq	fp,  48(a0)
+	stq	ra,  56(a0)
+	stq	gp,  64(a0)
+	stq	sp,  72(a0)
+	stt	$f2,  80(a0)
+	stt	$f3,  88(a0)
+	stt	$f4,  96(a0)
+	stt	$f5, 104(a0)
+	stt	$f6, 112(a0)
+	stt	$f7, 120(a0)
+	stt	$f8, 128(a0)
+	stt	$f9, 136(a0)
+	ret	zero,(ra),1
+
+	.size setjmp,.-setjmp
+	.end setjmp
+
+	.type	longjmp,@function
+	.ent	longjmp, 0
+	.globl	longjmp
+longjmp:
+	mov	a1, v0
+	ldq	s0,   0(a0)
+	ldq	s1,   8(a0)
+	ldq	s2,  16(a0)
+	ldq	s3,  24(a0)
+	ldq	s4,  32(a0)
+	ldq	s5,  40(a0)
+	ldq	fp,  48(a0)
+	ldq	ra,  56(a0)
+	ldq	gp,  64(a0)
+	ldq	sp,  72(a0)
+	ldt	$f2,  80(a0)
+	ldt	$f3,  88(a0)
+	ldt	$f4,  96(a0)
+	ldt	$f5, 104(a0)
+	ldt	$f6, 112(a0)
+	ldt	$f7, 120(a0)
+	ldt	$f8, 128(a0)
+	ldt	$f9, 136(a0)
+	/* We're bound to get a mispredict here, but at least give us
+	   a chance to get the return stack back in sync... */
+	ret	zero,(ra),1
+
+	.size longjmp,.-longjmp
+	.end longjmp
diff --git a/usr/klibc/arch/alpha/syscall.S b/usr/klibc/arch/alpha/syscall.S
new file mode 100644
index 0000000..ae69ef2
--- /dev/null
+++ b/usr/klibc/arch/alpha/syscall.S
@@ -0,0 +1,26 @@
+#
+# arch/alpha/syscall.S
+#
+
+#include <machine/asm.h>
+
+	.text
+	.align	3
+	.type	__syscall_common,@function
+	.ent	__syscall_common, 0
+	.globl	__syscall_common
+__syscall_common:
+	.frame	sp,0,ra,0
+	callsys
+	beq	a3, 1f
+	br	pv, 2f			# pv <- pc
+2:
+	ldgp	gp, 0(pv)
+	lda	a1, errno
+	stl	v0, 0(a1)
+	lda	v0, -1(zero)
+1:
+	ret	zero,(ra),1
+
+	.size	__syscall_common,.-__syscall_common
+	.end	__syscall_common
diff --git a/usr/klibc/arch/alpha/sysdual.S b/usr/klibc/arch/alpha/sysdual.S
new file mode 100644
index 0000000..1719e37
--- /dev/null
+++ b/usr/klibc/arch/alpha/sysdual.S
@@ -0,0 +1,33 @@
+#
+# arch/alpha/sysdual.S
+#
+
+#
+# Some system calls have an alternate return value in r20 (a4).
+# This system call stub is for system calls where that is
+# the "real" return value.
+#
+
+#include <machine/asm.h>
+
+	.text
+	.align	3
+	.type	__syscall_dual1,@function
+	.ent	__syscall_dual1, 0
+	.globl	__syscall_dual1
+__syscall_dual1:
+	.frame	sp,0,ra,0
+	callsys
+	mov	v0, a4
+	beq	a3, 1f
+	br	pv, 2f			# pv <- pc
+2:
+	ldgp	gp, 0(pv)
+	lda	a1, errno
+	lda	v0, -1(zero)
+	stl	a3, 0(a1)
+1:
+	ret	zero,(ra),1
+
+	.size	__syscall_dual1,.-__syscall_dual1
+	.end	__syscall_dual1
diff --git a/usr/klibc/arch/alpha/sysstub.ph b/usr/klibc/arch/alpha/sysstub.ph
new file mode 100644
index 0000000..08b97e8
--- /dev/null
+++ b/usr/klibc/arch/alpha/sysstub.ph
@@ -0,0 +1,37 @@
+# -*- perl -*-
+#
+# arch/alpha/sysstub.ph
+#
+# Script to generate system call stubs
+#
+
+# On Alpha, most system calls follow the standard convention, with the
+# system call number in r0 (v0), return an error value in r19 (a3) as
+# well as the return value in r0 (v0).
+#
+# A few system calls are dual-return with the second return value in
+# r20 (a4).
+
+sub make_sysstub($$$$$@) {
+    my($outputdir, $fname, $type, $sname, $stype, @args) = @_;
+
+    $stype = $stype || 'common';
+    $stype = 'common' if ( $stype eq 'dual0' );
+
+    open(OUT, '>', "${outputdir}/${fname}.S");
+    print OUT "#include <asm/unistd.h>\n";
+    print OUT "#include <machine/asm.h>\n";
+    print OUT "\n";
+    print OUT "\t.text\n";
+    print OUT "\t.type ${fname},\@function\n";
+    print OUT "\t.ent\t${fname}, 0\n"; # What is this?
+    print OUT "\t.globl ${fname}\n";
+    print OUT "${fname}:\n";
+    print OUT "\tlda\tv0, __NR_${sname}(zero)\n";
+    print OUT "\tbr __syscall_${stype}\n";
+    print OUT "\t.size\t${fname},.-${fname}\n";
+    print OUT "\t.end\t${fname}\n";
+    close(OUT);
+}
+
+1;

^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [klibc 05/31] arm support for klibc
  2006-06-28  5:17 [klibc 00/31] klibc as a historyless patchset (updated and reorganized) H. Peter Anvin
                   ` (3 preceding siblings ...)
  2006-06-28  5:17 ` [klibc 04/31] alpha support for klibc H. Peter Anvin
@ 2006-06-28  5:17 ` H. Peter Anvin
  2006-06-28  5:17 ` [klibc 06/31] cris " H. Peter Anvin
                   ` (25 subsequent siblings)
  30 siblings, 0 replies; 58+ messages in thread
From: H. Peter Anvin @ 2006-06-28  5:17 UTC (permalink / raw)
  To: linux-kernel, klibc; +Cc: H. Peter Anvin

The parts of klibc specific to the arm architecture.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>

---
commit 48a54d2c17e1e7e786aa842fecb0bd3046ecd9de
tree f7949076afb232f0d1dabff12221d1c724e641b6
parent c3fe3fde33e77fa6c09cb43ca3783e6bf36ef895
author H. Peter Anvin <hpa@zytor.com> Tue, 27 Jun 2006 20:50:30 -0700
committer H. Peter Anvin <hpa@zytor.com> Tue, 27 Jun 2006 20:50:30 -0700

 usr/include/arch/arm/klibc/archconfig.h |   14 ++++
 usr/include/arch/arm/klibc/archsetjmp.h |   14 ++++
 usr/include/arch/arm/klibc/archsignal.h |   14 ++++
 usr/include/arch/arm/klibc/archstat.h   |   40 ++++++++++++
 usr/include/arch/arm/klibc/asmmacros.h  |   30 +++++++++
 usr/klibc/arch/arm/MCONFIG              |   36 +++++++++++
 usr/klibc/arch/arm/Makefile.inc         |   23 +++++++
 usr/klibc/arch/arm/__muldi3.c           |   15 +++++
 usr/klibc/arch/arm/aeabi_nonsense.S     |    9 +++
 usr/klibc/arch/arm/crt0.S               |   23 +++++++
 usr/klibc/arch/arm/setjmp.S             |  102 +++++++++++++++++++++++++++++++
 usr/klibc/arch/arm/syscall.S            |   61 +++++++++++++++++++
 usr/klibc/arch/arm/sysstub.ph           |   58 ++++++++++++++++++
 usr/klibc/arch/arm/vfork.S              |   60 ++++++++++++++++++
 14 files changed, 499 insertions(+), 0 deletions(-)

diff --git a/usr/include/arch/arm/klibc/archconfig.h b/usr/include/arch/arm/klibc/archconfig.h
new file mode 100644
index 0000000..e34bdb7
--- /dev/null
+++ b/usr/include/arch/arm/klibc/archconfig.h
@@ -0,0 +1,14 @@
+/*
+ * include/arch/arm/klibc/archconfig.h
+ *
+ * See include/klibc/sysconfig.h for the options that can be set in
+ * this file.
+ *
+ */
+
+#ifndef _KLIBC_ARCHCONFIG_H
+#define _KLIBC_ARCHCONFIG_H
+
+/* All defaults */
+
+#endif				/* _KLIBC_ARCHCONFIG_H */
diff --git a/usr/include/arch/arm/klibc/archsetjmp.h b/usr/include/arch/arm/klibc/archsetjmp.h
new file mode 100644
index 0000000..88db8a1
--- /dev/null
+++ b/usr/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/usr/include/arch/arm/klibc/archsignal.h b/usr/include/arch/arm/klibc/archsignal.h
new file mode 100644
index 0000000..a589527
--- /dev/null
+++ b/usr/include/arch/arm/klibc/archsignal.h
@@ -0,0 +1,14 @@
+/*
+ * arch/arm/include/klibc/archsignal.h
+ *
+ * Architecture-specific signal definitions
+ *
+ */
+
+#ifndef _KLIBC_ARCHSIGNAL_H
+#define _KLIBC_ARCHSIGNAL_H
+
+#include <asm/signal.h>
+/* No special stuff for this architecture */
+
+#endif
diff --git a/usr/include/arch/arm/klibc/archstat.h b/usr/include/arch/arm/klibc/archstat.h
new file mode 100644
index 0000000..95bbc9e
--- /dev/null
+++ b/usr/include/arch/arm/klibc/archstat.h
@@ -0,0 +1,40 @@
+#ifndef _KLIBC_ARCHSTAT_H
+#define _KLIBC_ARCHSTAT_H
+
+#include <klibc/stathelp.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 {
+	__stdev64	(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;
+
+	__stdev64	(st_rdev);
+	unsigned char   __pad3[4];
+
+	long long	st_size;
+	unsigned long	st_blksize;
+
+	unsigned long 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/usr/include/arch/arm/klibc/asmmacros.h b/usr/include/arch/arm/klibc/asmmacros.h
new file mode 100644
index 0000000..8a21c94
--- /dev/null
+++ b/usr/include/arch/arm/klibc/asmmacros.h
@@ -0,0 +1,30 @@
+/*
+ * usr/include/arch/arm/klibc/asmmacros.h
+ *
+ * Assembly macros used by ARM system call stubs
+ */
+
+#ifndef _KLIBC_ASMMACROS_H
+#define _KLIBC_ASMMACROS_H
+
+/* An immediate in ARM can be any 8-bit value rotated by an even number of bits */
+
+#define ARM_VALID_IMM(x)	\
+	((((x) & ~0x000000ff) == 0) || \
+	 (((x) & ~0x000003fc) == 0) || \
+	 (((x) & ~0x00000ff0) == 0) || \
+	 (((x) & ~0x00003fc0) == 0) || \
+	 (((x) & ~0x0000ff00) == 0) || \
+	 (((x) & ~0x0003fc00) == 0) || \
+	 (((x) & ~0x000ff000) == 0) || \
+	 (((x) & ~0x003fc000) == 0) || \
+	 (((x) & ~0x00ff0000) == 0) || \
+	 (((x) & ~0x03fc0000) == 0) || \
+	 (((x) & ~0x0ff00000) == 0) || \
+	 (((x) & ~0x3fc00000) == 0) || \
+	 (((x) & ~0xff000000) == 0) || \
+	 (((x) & ~0xfc000003) == 0) || \
+	 (((x) & ~0xf000000f) == 0) || \
+	 (((x) & ~0xc000003f) == 0))
+
+#endif /* _KLIBC_ASMMACROS_H */
diff --git a/usr/klibc/arch/arm/MCONFIG b/usr/klibc/arch/arm/MCONFIG
new file mode 100644
index 0000000..0023eee
--- /dev/null
+++ b/usr/klibc/arch/arm/MCONFIG
@@ -0,0 +1,36 @@
+# -*- makefile -*-
+#
+# arch/arm/MCONFIG
+#
+# Special rules for this architecture.  Note that this is actually
+# included from the main Makefile, and that pathnames should be
+# accordingly.
+#
+
+CPU_ARCH := armv4
+CPU_TUNE := strongarm
+
+KLIBCOPTFLAGS = -Os -march=$(CPU_ARCH) -mtune=$(CPU_TUNE)
+KLIBCBITSIZE  = 32
+KLIBCREQFLAGS = -fno-exceptions
+KLIBCSTRIPFLAGS += -R .ARM.exidx
+
+ifeq ($(CONFIG_KLIBC_THUMB),y)
+CPU_ARCH := $(CPU_ARCH)t
+KLIBCREQFLAGS += -mthumb
+KLIBCLDFLAGS  += --thumb-entry _start
+KLIBCEMAIN     = --thumb-entry _start
+KLIBCREQFLAGS += -mabi=aapcs-linux
+KLIBCSHAREDFLAGS = -Ttext 0x380200
+else
+# Extra linkflags when building the shared version of the library
+# This address needs to be reachable using normal inter-module
+# calls, and work on the memory models for this architecture
+KLIBCSHAREDFLAGS = -Ttext 0x01800200
+ifeq ($(CONFIG_AEABI),y)
+KLIBCREQFLAGS += -mabi=aapcs-linux -mno-thumb-interwork
+else
+KLIBCREQFLAGS += -mabi=apcs-gnu -mno-thumb-interwork
+endif
+endif
+
diff --git a/usr/klibc/arch/arm/Makefile.inc b/usr/klibc/arch/arm/Makefile.inc
new file mode 100644
index 0000000..62065df
--- /dev/null
+++ b/usr/klibc/arch/arm/Makefile.inc
@@ -0,0 +1,23 @@
+# -*- makefile -*-
+#
+# arch/arm/Makefile.inc
+#
+# Special rules for this architecture.  Note that this is actually
+# included from the main Makefile, and that pathnames should be
+# accordingly.
+#
+
+KLIBCARCHOBJS = \
+	arch/arm/setjmp.o \
+	arch/arm/syscall.o \
+	arch/arm/vfork.o \
+	arch/arm/aeabi_nonsense.o \
+	libgcc/__udivmodsi4.o \
+	libgcc/__divdi3.o \
+	libgcc/__moddi3.o \
+	libgcc/__udivdi3.o \
+	libgcc/__umoddi3.o \
+	libgcc/__udivmoddi4.o \
+	libgcc/__clzsi2.o \
+
+
diff --git a/usr/klibc/arch/arm/__muldi3.c b/usr/klibc/arch/arm/__muldi3.c
new file mode 100644
index 0000000..3fdeb2b
--- /dev/null
+++ b/usr/klibc/arch/arm/__muldi3.c
@@ -0,0 +1,15 @@
+#include <stdint.h>
+
+uint64_t __muldi3(uint64_t a, uint64_t b)
+{
+	uint32_t al = (uint32_t)a;
+	uint32_t ah = (uint32_t)(a >> 32);
+	uint32_t bl = (uint32_t)b;
+	uint32_t bh = (uint32_t)(b >> 32);
+	uint64_t v;
+
+	v = (uint64_t)al * bl;
+	v += (uint64_t)(al*bh+ah*bl) << 32;
+
+	return v;
+}
diff --git a/usr/klibc/arch/arm/aeabi_nonsense.S b/usr/klibc/arch/arm/aeabi_nonsense.S
new file mode 100644
index 0000000..c69eb11
--- /dev/null
+++ b/usr/klibc/arch/arm/aeabi_nonsense.S
@@ -0,0 +1,9 @@
+	.text
+	.globl	__aeabi_unwind_cpp_pr0
+__aeabi_unwind_cpp_pr0:
+	.globl	__aeabi_unwind_cpp_pr1
+__aeabi_unwind_cpp_pr1:
+	.globl	__aeabi_unwind_cpp_pr2
+__aeabi_unwind_cpp_pr2:
+	.globl	__aeabi_unwind_cpp_pr3
+__aeabi_unwind_cpp_pr3:
diff --git a/usr/klibc/arch/arm/crt0.S b/usr/klibc/arch/arm/crt0.S
new file mode 100644
index 0000000..1e81f8e
--- /dev/null
+++ b/usr/klibc/arch/arm/crt0.S
@@ -0,0 +1,23 @@
+#
+# arch/arm/crt0.S
+#
+# void _start(void)
+# {
+#    __libc_init(elf_structure, atexit_ptr);
+# }
+#
+
+	.text
+	.balign 4
+	.type _start,#function
+	.globl _start
+
+#ifdef __thumb__
+	.thumb_func
+#endif
+
+_start:	mov	r0, sp
+	mov	r1, #0
+	bl	__libc_init
+
+	.size _start,.-_start
diff --git a/usr/klibc/arch/arm/setjmp.S b/usr/klibc/arch/arm/setjmp.S
new file mode 100644
index 0000000..1841bc7
--- /dev/null
+++ b/usr/klibc/arch/arm/setjmp.S
@@ -0,0 +1,102 @@
+#
+# arch/arm/setjmp.S
+#
+# setjmp/longjmp for the ARM architecture
+#
+
+#ifndef	__thumb__
+
+#
+# "Pure ARM" version		
+#
+# The jmp_buf is assumed to contain the following, in order:
+#		r4
+#		r5
+#		r6
+#		r7
+#		r8
+#		r9
+#		r10
+#		fp
+#		sp
+#		lr
+#
+
+	.text
+	.balign 4
+	.globl setjmp
+	.type setjmp, #function
+setjmp:
+	stmia	r0, {r4, r5, r6, r7, r8, r9, r10, fp, sp, lr}
+	mov	r0, #0
+	mov	pc, lr
+	.size setjmp,.-setjmp
+
+	.text
+	.balign 4
+	.globl longjmp
+	.type longjmp, #function
+longjmp:
+	ldmia	r0, {r4, r5, r6, r7, r8, r9, r10, fp, sp, lr}
+	mov	r0, r1
+	mov	pc, lr
+	.size longjmp,.-longjmp
+
+#else /* __thumb__ */
+
+#
+# Thumb version
+#
+# The jmp_buf is assumed to contain the following, in order:
+#		lr
+#		r4
+#		r5
+#		r6
+#		r7
+#		r8
+#		r9
+#		r10
+#		fp
+#		sp
+#
+
+	.text
+	.balign 4
+	.globl setjmp
+	.type setjmp, #function
+	.thumb_func
+setjmp:
+	mov	r3, lr
+	stmia	r0!, {r3, r4, r5, r6, r7}
+	mov	r3, r8
+	mov	r4, r9
+	mov	r5, r10
+	mov	r6, fp
+	mov	r7, sp
+	stmia	r0!, {r3, r4, r5, r6, r7}
+	mov	r0, #0
+	mov	pc, lr
+	.size setjmp,.-setjmp
+
+	.text
+	.balign 4
+	.globl longjmp
+	.type longjmp, #function
+	.thumb_func
+longjmp:
+	mov	r2, r0
+	add	r0, #5*4
+	ldmia	r0!, {r3, r4, r5, r6, r7}
+	mov	r8, r3
+	mov	r9, r4
+	mov	r10, r5
+	mov	fp, r6
+	mov	sp, r7
+	ldmia	r2!, {r3, r4, r5, r6, r7}
+	mov	r0, r1
+	bne	1f
+	mov	r0, #1
+1:	mov	pc, r3
+	.size longjmp,.-longjmp
+
+#endif /* __thumb__ */
diff --git a/usr/klibc/arch/arm/syscall.S b/usr/klibc/arch/arm/syscall.S
new file mode 100644
index 0000000..5bc291d
--- /dev/null
+++ b/usr/klibc/arch/arm/syscall.S
@@ -0,0 +1,61 @@
+/*
+ * arch/arm/syscall.S
+ *
+ * System call common handling
+ */
+
+	.type	__syscall_common,#function
+	.globl	__syscall_common
+#ifndef __thumb__
+	/* ARM version - this is executed after the swi, unless
+	   we are compiled in EABI mode */
+
+	.balign	4
+__syscall_common:
+#ifdef __ARM_EABI__
+	ldr	r4, [sp,#16]
+	ldr	r5, [sp,#20]
+	ldr	r7, [lr]
+	swi	0
+#endif
+        cmn     r0, #4096
+        rsbcs	r2, r0, #0
+        ldrcs	r3, 1f
+        mvncs	r0, #0
+        strcs	r2, [r3]
+	ldmfd	sp!,{r4,r5,r7,pc}
+
+	.balign 4
+1:
+	.word	errno
+
+#else
+	/* Thumb version - must still load r4 and r5 and run swi */
+
+	.thumb_func
+	.balign	2
+__syscall_common:
+	mov	r7, lr
+	ldr	r4, [sp,#16]
+	sub	r7, #1		/* Remove the Thumb bit */
+	ldr	r5, [sp,#20]
+	ldrh	r7, [r7]
+	swi	0
+	ldr	r1, 2f
+	cmp	r0, r1
+	bcc	1f
+	ldr	r1, 3f
+	neg	r2, r0
+	mov	r0, #1
+	str	r2, [r1]
+	neg	r0, r0
+1:
+	pop	{r4,r5,r7,pc}
+
+	.balign	4
+2:
+	.word	-4095
+3:
+	.word	errno
+
+#endif
diff --git a/usr/klibc/arch/arm/sysstub.ph b/usr/klibc/arch/arm/sysstub.ph
new file mode 100644
index 0000000..d51ace1
--- /dev/null
+++ b/usr/klibc/arch/arm/sysstub.ph
@@ -0,0 +1,58 @@
+# -*- perl -*-
+#
+# arch/arm/sysstub.ph
+#
+# Script to generate system call stubs
+#
+
+
+sub make_sysstub($$$$$@) {
+    my($outputdir, $fname, $type, $sname, $stype, @args) = @_;
+
+    open(OUT, '>', "${outputdir}/${fname}.S");
+    print  OUT "#include <asm/unistd.h>\n";
+    print  OUT "#include <klibc/asmmacros.h>\n";
+
+    print  OUT "	.text\n";
+    print  OUT "	.type	${fname}, #function\n";
+    print  OUT "	.globl	${fname}\n";
+
+    print  OUT "#ifndef __thumb__\n";
+
+    print  OUT "#ifndef __ARM_EABI__\n";
+
+    # ARM version first
+    print  OUT "	.balign	4\n";
+    print  OUT "${fname}:\n";
+    print  OUT "	stmfd	sp!,{r4,r5,lr}\n";
+    print  OUT "	ldr	r4,[sp,#12]\n";
+    print  OUT "	ldr	r5,[sp,#16]\n";
+    print  OUT "	swi	# __NR_${sname}\n";
+    print  OUT "	b	__syscall_common\n";
+
+    print  OUT "#else /* __ARM_EABI__ */\n";
+
+    # ARM EABI version
+    print  out "	.balign	4\n";
+    print  OUT "${fname}:\n";
+    print  OUT "	stmfd	sp!,{r4,r5,r7,lr}\n";
+    print  OUT "	bl	__syscall_common\n";
+    print  OUT "	.word	__NR_${sname}\n";
+
+    print  OUT "#endif /* __ARM_EABI__ */\n";
+    print  OUT "#else /* __thumb__ */\n";
+
+    # Thumb version
+    print  OUT "	.balign	8\n";
+    print  OUT "	.thumb_func\n";
+    print  OUT "${fname}:\n";
+    print  OUT "	push	{r4,r5,r7,lr}\n";
+    print  OUT "	bl	__syscall_common\n";
+    print  OUT "	.short	__NR_${sname}\n";
+
+    print  OUT "#endif /* __thumb__*/\n";
+
+    print  OUT "	.size	__syscall${i},.-__syscall${i}\n";
+}
+
+1;
diff --git a/usr/klibc/arch/arm/vfork.S b/usr/klibc/arch/arm/vfork.S
new file mode 100644
index 0000000..3b2d9f7
--- /dev/null
+++ b/usr/klibc/arch/arm/vfork.S
@@ -0,0 +1,60 @@
+/*
+ * arch/arm/vfork.S
+ *
+ * vfork - nasty system call which must not use the stack.
+ */
+
+#include <asm/unistd.h>
+
+	.type	vfork,#function
+	.globl	vfork
+#ifndef __thumb__
+
+	.balign	4
+vfork:
+#ifdef	__ARM_EABI__
+	mov	r3, r7
+	mov	r7, # __NR_vfork
+	swi	0
+	mov	r7, r3
+#else
+	swi	# __NR_vfork
+#endif
+        cmn     r0, #4096
+        rsbcs	r2, r0, #0
+        ldrcs	r3, 1f
+        mvncs	r0, #0
+        strcs	r2, [r3]
+	mov	pc, lr
+
+	.balign 4
+1:
+	.word	errno
+
+#else
+
+	.thumb_func
+	.balign	2
+vfork:
+	mov	r3, r7
+	mov	r7, # __NR_vfork
+	swi	0
+	mov	r7, r3
+	ldr	r1, 2f
+	cmp	r0, r1
+	bcc	1f
+	ldr	r1, 3f
+	neg	r2, r0
+	mov	r0, #1
+	str	r2, [r1]
+	neg	r0, r0
+1:
+	mov	pc, lr
+
+	.balign	4
+2:
+	.word	-4095
+3:
+	.word	errno
+
+#endif

^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [klibc 06/31] cris support for klibc
  2006-06-28  5:17 [klibc 00/31] klibc as a historyless patchset (updated and reorganized) H. Peter Anvin
                   ` (4 preceding siblings ...)
  2006-06-28  5:17 ` [klibc 05/31] arm " H. Peter Anvin
@ 2006-06-28  5:17 ` H. Peter Anvin
  2006-06-28  5:17 ` [klibc 07/31] i386 " H. Peter Anvin
                   ` (24 subsequent siblings)
  30 siblings, 0 replies; 58+ messages in thread
From: H. Peter Anvin @ 2006-06-28  5:17 UTC (permalink / raw)
  To: linux-kernel, klibc; +Cc: H. Peter Anvin

The parts of klibc specific to the cris architecture.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>

---
commit 5736f366a2df293571bcc779415f1d9b3a9aa6c1
tree 705889b0b164ac8b6b6638a1802ab429fb570185
parent 48a54d2c17e1e7e786aa842fecb0bd3046ecd9de
author H. Peter Anvin <hpa@zytor.com> Tue, 27 Jun 2006 20:50:31 -0700
committer H. Peter Anvin <hpa@zytor.com> Tue, 27 Jun 2006 20:50:31 -0700

 usr/include/arch/cris/klibc/archconfig.h |   15 +++++
 usr/include/arch/cris/klibc/archsetjmp.h |   24 +++++++
 usr/include/arch/cris/klibc/archsignal.h |   14 ++++
 usr/include/arch/cris/klibc/archstat.h   |   39 ++++++++++++
 usr/klibc/arch/cris/MCONFIG              |   26 ++++++++
 usr/klibc/arch/cris/Makefile.inc         |   34 ++++++++++
 usr/klibc/arch/cris/__negdi2.S           |   25 ++++++++
 usr/klibc/arch/cris/crt0.S               |   27 ++++++++
 usr/klibc/arch/cris/divide.c             |   99 ++++++++++++++++++++++++++++++
 usr/klibc/arch/cris/setjmp.S             |   37 +++++++++++
 usr/klibc/arch/cris/syscall.S            |   30 +++++++++
 usr/klibc/arch/cris/sysstub.ph           |   29 +++++++++
 usr/klibc/arch/cris/vfork.S              |   29 +++++++++
 13 files changed, 428 insertions(+), 0 deletions(-)

diff --git a/usr/include/arch/cris/klibc/archconfig.h b/usr/include/arch/cris/klibc/archconfig.h
new file mode 100644
index 0000000..0206078
--- /dev/null
+++ b/usr/include/arch/cris/klibc/archconfig.h
@@ -0,0 +1,15 @@
+/*
+ * include/arch/cris/klibc/archconfig.h
+ *
+ * See include/klibc/sysconfig.h for the options that can be set in
+ * this file.
+ *
+ */
+
+#ifndef _KLIBC_ARCHCONFIG_H
+#define _KLIBC_ARCHCONFIG_H
+
+/* cris uses 13 as the page shift factor for sys_mmap2 */
+#define _KLIBC_MMAP2_SHIFT	13
+
+#endif				/* _KLIBC_ARCHCONFIG_H */
diff --git a/usr/include/arch/cris/klibc/archsetjmp.h b/usr/include/arch/cris/klibc/archsetjmp.h
new file mode 100644
index 0000000..d345ccb
--- /dev/null
+++ b/usr/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/usr/include/arch/cris/klibc/archsignal.h b/usr/include/arch/cris/klibc/archsignal.h
new file mode 100644
index 0000000..7fa7454
--- /dev/null
+++ b/usr/include/arch/cris/klibc/archsignal.h
@@ -0,0 +1,14 @@
+/*
+ * arch/cris/include/klibc/archsignal.h
+ *
+ * Architecture-specific signal definitions
+ *
+ */
+
+#ifndef _KLIBC_ARCHSIGNAL_H
+#define _KLIBC_ARCHSIGNAL_H
+
+#include <asm/signal.h>
+/* No special stuff for this architecture */
+
+#endif
diff --git a/usr/include/arch/cris/klibc/archstat.h b/usr/include/arch/cris/klibc/archstat.h
new file mode 100644
index 0000000..09d3ade
--- /dev/null
+++ b/usr/include/arch/cris/klibc/archstat.h
@@ -0,0 +1,39 @@
+#ifndef _KLIBC_ARCHSTAT_H
+#define _KLIBC_ARCHSTAT_H
+
+#include <klibc/stathelp.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 {
+	__stdev64	(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;
+
+	__stdev64	(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/usr/klibc/arch/cris/MCONFIG b/usr/klibc/arch/cris/MCONFIG
new file mode 100644
index 0000000..659789b
--- /dev/null
+++ b/usr/klibc/arch/cris/MCONFIG
@@ -0,0 +1,26 @@
+# -*- makefile -*-
+#
+# arch/cris/MCONFIG
+#
+# Special rules for this architecture.  Note that this is actually
+# included from the main Makefile, and that pathnames should be
+# accordingly.
+#
+
+KLIBCOPTFLAGS = -Os -fomit-frame-pointer
+KLIBCBITSIZE  = 32
+
+# Extra linkflags when building the shared version of the library
+# This address needs to be reachable using normal inter-module
+# calls, and work on the memory models for this architecture
+# 224 MB - normal binaries start at 0
+# (lib?)gcc on cris seems to insist on producing .init and .fini sections
+KLIBCSHAREDFLAGS     = --section-start .init=0x0e000100
+
+# The CRIS compiler needs an -iprefix to find libgcc includes when
+# nostdinc is used. It also needs -mlinux to compile linux applications.
+INCLUDE_PREFIX  = $(shell $(CC) -print-libgcc-file-name | sed -e s/libgcc.a//)
+KLIBCARCHREQFLAGS = -iprefix $(INCLUDE_PREFIX) -mlinux
+
+# Special flags needed for linking
+KLIBCLDFLAGS 	+= -mcrislinux
diff --git a/usr/klibc/arch/cris/Makefile.inc b/usr/klibc/arch/cris/Makefile.inc
new file mode 100644
index 0000000..ac93d2d
--- /dev/null
+++ b/usr/klibc/arch/cris/Makefile.inc
@@ -0,0 +1,34 @@
+# -*- makefile -*-
+#
+# arch/cris/Makefile.inc
+#
+# Special rules for this architecture.  Note that this is actually
+# included from the main Makefile, and that pathnames should be
+# accordingly.
+#
+
+KLIBCARCHOBJS = \
+	arch/$(KLIBCARCH)/__Umod.o \
+	arch/$(KLIBCARCH)/__Udiv.o \
+	arch/$(KLIBCARCH)/__Mod.o \
+	arch/$(KLIBCARCH)/__Div.o \
+	arch/$(KLIBCARCH)/__negdi2.o \
+	arch/$(KLIBCARCH)/setjmp.o \
+	arch/$(KLIBCARCH)/syscall.o \
+	arch/$(KLIBCARCH)/vfork.o \
+	libgcc/__divdi3.o \
+	libgcc/__moddi3.o \
+	libgcc/__udivdi3.o \
+	libgcc/__umoddi3.o \
+	libgcc/__udivmoddi4.o
+
+arch/$(KLIBCARCH)/__Umod.o: arch/$(KLIBCARCH)/divide.c
+	$(CC) $(CFLAGS) -DSIGNED=0 -DREM=1 -DBITS=32 -DNAME=__Umod -c -o $@ $<
+arch/$(KLIBCARCH)/__Udiv.o: arch/$(KLIBCARCH)/divide.c
+	$(CC) $(CFLAGS) -DSIGNED=0 -DREM=0 -DBITS=32 -DNAME=__Udiv -c -o $@ $<
+arch/$(KLIBCARCH)/__Mod.o: arch/$(KLIBCARCH)/divide.c
+	$(CC) $(CFLAGS) -DSIGNED=1 -DREM=1 -DBITS=32 -DNAME=__Mod -c -o $@ $<
+arch/$(KLIBCARCH)/__Div.o: arch/$(KLIBCARCH)/divide.c
+	$(CC) $(CFLAGS) -DSIGNED=1 -DREM=0 -DBITS=32 -DNAME=__Div -c -o $@ $<
+
+archclean:
diff --git a/usr/klibc/arch/cris/__negdi2.S b/usr/klibc/arch/cris/__negdi2.S
new file mode 100644
index 0000000..3cca9ed
--- /dev/null
+++ b/usr/klibc/arch/cris/__negdi2.S
@@ -0,0 +1,25 @@
+/*
+ * arch/cris/__negdi2.c
+ */
+
+/*
+ * In 2's complement arithmetric, -x == (~x + 1), so
+ * -{h,l} = (~{h,l} + {0,1)
+ * -{h,l} = {~h,~l} + {0,1}
+ * -{h,l} = {~h + cy, ~l + 1}
+ * ... where cy = (l == 0)
+ * -{h,l} = {~h + cy, -l}
+ */
+
+	.text
+	.balign 4
+	.type	__negdi2,@function
+	.globl	__negdi2
+__negdi2:
+	neg.d	$r10,$r10
+	seq	$r12
+	not	$r11
+	ret
+	  add.d	$r12,$r11
+
+	.size __negdi2, .-__negdi2
diff --git a/usr/klibc/arch/cris/crt0.S b/usr/klibc/arch/cris/crt0.S
new file mode 100644
index 0000000..22cb9b4
--- /dev/null
+++ b/usr/klibc/arch/cris/crt0.S
@@ -0,0 +1,27 @@
+#
+# arch/cris/crt0.S
+#
+# Does arch-specific initialization and invokes __libc_init
+# with the appropriate arguments.
+#
+# See __static_init.c or __shared_init.c for the expected
+# arguments.
+#
+
+	.text
+	.balign 4
+	.type	_start,@function
+	.globl	_start
+_start:
+	/* Save the address of the ELF argument array */
+	move.d	$sp,$r10	/* Address of ELF arguments */
+
+	/* atexit() function (assume null) */
+	moveq	0,$r11
+
+	/* Set up a dummy stack frame to keep gcc from getting confused */
+	push	$r11
+	push	$r11
+	jump	__libc_init
+
+	.size _start, .-_start
diff --git a/usr/klibc/arch/cris/divide.c b/usr/klibc/arch/cris/divide.c
new file mode 100644
index 0000000..1d4ab23
--- /dev/null
+++ b/usr/klibc/arch/cris/divide.c
@@ -0,0 +1,99 @@
+#include <stdint.h>
+#include <signal.h>
+
+#if BITS == 64
+typedef uint64_t unum;
+typedef int64_t snum;
+#else
+typedef uint32_t unum;
+typedef int32_t snum;
+#endif
+
+#ifdef SIGNED
+typedef snum xnum;
+#else
+typedef unum xnum;
+#endif
+
+#ifdef __cris__
+static inline unum __attribute__ ((const))dstep(unum rs, unum rd)
+{
+	asm("dstep %1,%0": "+r"(rd):"r"(rs));
+	return rd;
+}
+
+static inline unum __attribute__ ((const))lz(unum rs)
+{
+	unum rd;
+	asm("lz %1,%0": "=r"(rd):"r"(rs));
+	return rd;
+}
+
+#else
+/* For testing */
+static inline unum __attribute__ ((const))dstep(unum rs, unum rd)
+{
+	rd <<= 1;
+	if (rd >= rs)
+		rd -= rs;
+
+	return rd;
+}
+
+static inline unum __attribute__ ((const))lz(unum rs)
+{
+	unum rd = 0;
+	while (rs >= 0x7fffffff) {
+		rd++;
+		rs <<= 1;
+	}
+	return rd;
+}
+
+#endif
+
+xnum NAME(unum num, unum den)
+{
+	unum quot = 0, qbit = 1;
+	int minus = 0;
+	xnum v;
+
+	if (den == 0) {
+		raise(SIGFPE);
+		return 0;	/* If signal ignored... */
+	}
+
+	if (den == 1)
+		return (xnum) (REM ? 0 : num);
+
+#if SIGNED
+	if ((snum) (num ^ den) < 0)
+		minus = 1;
+	if ((snum) num < 0)
+		num = -num;
+	if ((snum) den < 0)
+		den = -den;
+#endif
+
+	den--;
+
+	/* Left-justify denominator and count shift */
+	while ((snum) den >= 0) {
+		den <<= 1;
+		qbit <<= 1;
+	}
+
+	while (qbit) {
+		if (den <= num) {
+			num -= den;
+			quot += qbit;
+		}
+		den >>= 1;
+		qbit >>= 1;
+	}
+
+	v = (xnum) (REM ? num : quot);
+	if (minus)
+		v = -v;
+	return v;
+}
diff --git a/usr/klibc/arch/cris/setjmp.S b/usr/klibc/arch/cris/setjmp.S
new file mode 100644
index 0000000..2041b82
--- /dev/null
+++ b/usr/klibc/arch/cris/setjmp.S
@@ -0,0 +1,37 @@
+#
+# arch/cris/setjmp.S
+#
+# setjmp/longjmp for the cris architecture
+#
+
+#
+# The jmp_buf is assumed to contain the following, in order:
+#	$r8..$r0	(in that order)
+#	$sp	($r14)
+#	return address
+#
+
+	.text
+	.balign 4
+	.globl	setjmp
+	.type	setjmp, @function
+setjmp:
+	movem	$r8,[$r10+]		/* Save $r8..$r0 at $r10... */
+	move.d	$sp,[$r10+]
+	move	$srp,[$r10]
+	ret
+	  moveq	0,$r10
+
+	.size setjmp,.-setjmp
+
+	.text
+	.balign 4
+	.globl	longjmp
+	.type	longjmp, @function
+longjmp:
+	movem	[$r10+],$r8		/* Load $r8..$r0 from $r10... */
+	move.d	[$r10+],$sp
+	jump	[$r10]
+	move.d $r11,$r10
+
+	.size longjmp,.-longjmp
diff --git a/usr/klibc/arch/cris/syscall.S b/usr/klibc/arch/cris/syscall.S
new file mode 100644
index 0000000..d71495a
--- /dev/null
+++ b/usr/klibc/arch/cris/syscall.S
@@ -0,0 +1,30 @@
+/*
+ * arch/cris/syscall.S
+ *
+ * On cris, r9 contains the syscall number (set by generated stub);
+ * r10..r13 contain arguments 0-3 per the standard calling convention,
+ * and arguments 4-5 are passed in $mof and $srp; however, we have
+ * to save $srp around the system call.
+ */
+
+	.section ".text","ax"
+	.balign	4
+	.globl	__syscall_common
+	.type	__syscall_common,@function
+__syscall_common:
+	push	$srp
+	move	[$sp+4],$mof
+	move	[$sp+8],$srp
+	break	13
+
+	cmps.w	-4096,$r10
+	blo	1f
+	neg.d	$r10,$r11
+	move.d	$r11,[errno]
+	moveq	-1,$r10
+1:
+	pop	$srp
+	ret
+	nop
+
+	.size	__syscall_common,.-__syscall_common
diff --git a/usr/klibc/arch/cris/sysstub.ph b/usr/klibc/arch/cris/sysstub.ph
new file mode 100644
index 0000000..182ad73
--- /dev/null
+++ b/usr/klibc/arch/cris/sysstub.ph
@@ -0,0 +1,29 @@
+# -*- perl -*-
+#
+# arch/cris/sysstub.ph
+#
+# Script to generate system call stubs
+#
+
+sub make_sysstub($$$$$@) {
+    my($outputdir, $fname, $type, $sname, $stype, @args) = @_;
+
+    open(OUT, '>', "${outputdir}/${fname}.S");
+    print OUT "#include <asm/unistd.h>\n";
+    print OUT "\n";
+    print OUT "\t.text\n";
+    print OUT "\t.type\t${fname},\@function\n";
+    print OUT "\t.globl\t${fname}\n";
+    print OUT "\t.balign\t4\n";
+    print OUT "${fname}:\n";
+    print OUT "#if __NR_${sname} <= 31\n";
+    print OUT "\t  moveq\t__NR_${sname}, \$r9\n";
+    print OUT "#else\n";
+    print OUT "\t  move.d\t__NR_${sname}, \$r9\n";
+    print OUT "#endif\n";
+    print OUT "\tjump\t__syscall_common\n";
+    print OUT "\t.size ${fname},.-${fname}\n";
+    close(OUT);
+}
+
+1;
diff --git a/usr/klibc/arch/cris/vfork.S b/usr/klibc/arch/cris/vfork.S
new file mode 100644
index 0000000..ccdb36c
--- /dev/null
+++ b/usr/klibc/arch/cris/vfork.S
@@ -0,0 +1,29 @@
+/*
+ * arch/cris/vfork.S
+ *
+ * On cris, r9 contains the syscall number (set by generated stub);
+ * r10..r13 contain arguments 0-3 per the standard calling convention.
+ * The return address is in $srp; so we just need to avoid the stack
+ * usage of the normal syscall stubs.
+ */
+
+#include <asm/unistd.h>
+
+	.section ".text","ax"
+	.balign	4
+	.globl	vfork
+	.type	vfork,@function
+vfork:
+	move.d	__NR_vfork, $r9
+	break	13
+
+	cmps.w	-4096,$r10
+	blo	1f
+	neg.d	$r10,$r11
+	move.d	$r11,[errno]
+	moveq	-1,$r10
+1:
+	ret
+	nop
+
+	.size	vfork,.-vfork

^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [klibc 07/31] i386 support for klibc
  2006-06-28  5:17 [klibc 00/31] klibc as a historyless patchset (updated and reorganized) H. Peter Anvin
                   ` (5 preceding siblings ...)
  2006-06-28  5:17 ` [klibc 06/31] cris " H. Peter Anvin
@ 2006-06-28  5:17 ` H. Peter Anvin
  2006-06-28  7:37   ` Jan Engelhardt
  2006-06-28  5:17 ` [klibc 08/31] ia64 " H. Peter Anvin
                   ` (23 subsequent siblings)
  30 siblings, 1 reply; 58+ messages in thread
From: H. Peter Anvin @ 2006-06-28  5:17 UTC (permalink / raw)
  To: linux-kernel, klibc; +Cc: H. Peter Anvin

The parts of klibc specific to the i386 architecture.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>

---
commit 0b76ae4ad7c15cddd0d1202234f5dbc75e8dde56
tree 09f9c33da419b48d84b61d20463611179d26fbc1
parent 5736f366a2df293571bcc779415f1d9b3a9aa6c1
author H. Peter Anvin <hpa@zytor.com> Tue, 27 Jun 2006 20:50:34 -0700
committer H. Peter Anvin <hpa@zytor.com> Tue, 27 Jun 2006 20:50:34 -0700

 usr/include/arch/i386/klibc/archconfig.h |   19 ++++
 usr/include/arch/i386/klibc/archsetjmp.h |   19 ++++
 usr/include/arch/i386/klibc/archsignal.h |  114 +++++++++++++++++++++++++++
 usr/include/arch/i386/klibc/archstat.h   |   38 +++++++++
 usr/include/arch/i386/klibc/diverr.h     |   15 ++++
 usr/include/arch/i386/sys/io.h           |  127 ++++++++++++++++++++++++++++++
 usr/include/arch/i386/sys/vm86.h         |   40 +++++++++
 usr/klibc/arch/i386/MCONFIG              |   33 ++++++++
 usr/klibc/arch/i386/Makefile.inc         |   30 +++++++
 usr/klibc/arch/i386/crt0.S               |   31 +++++++
 usr/klibc/arch/i386/libgcc/__ashldi3.S   |   29 +++++++
 usr/klibc/arch/i386/libgcc/__ashrdi3.S   |   29 +++++++
 usr/klibc/arch/i386/libgcc/__lshrdi3.S   |   29 +++++++
 usr/klibc/arch/i386/libgcc/__muldi3.S    |   34 ++++++++
 usr/klibc/arch/i386/libgcc/__negdi2.S    |   21 +++++
 usr/klibc/arch/i386/open.S               |   29 +++++++
 usr/klibc/arch/i386/openat.S             |   26 ++++++
 usr/klibc/arch/i386/setjmp.S             |   58 ++++++++++++++
 usr/klibc/arch/i386/sigreturn.S          |   15 ++++
 usr/klibc/arch/i386/socketcall.S         |   55 +++++++++++++
 usr/klibc/arch/i386/syscall.S            |   69 ++++++++++++++++
 usr/klibc/arch/i386/sysstub.ph           |   26 ++++++
 usr/klibc/arch/i386/varsyscall.S         |   36 +++++++++
 usr/klibc/arch/i386/vfork.S              |   26 ++++++
 24 files changed, 948 insertions(+), 0 deletions(-)

diff --git a/usr/include/arch/i386/klibc/archconfig.h b/usr/include/arch/i386/klibc/archconfig.h
new file mode 100644
index 0000000..4463d08
--- /dev/null
+++ b/usr/include/arch/i386/klibc/archconfig.h
@@ -0,0 +1,19 @@
+/*
+ * include/arch/i386/klibc/archconfig.h
+ *
+ * See include/klibc/sysconfig.h for the options that can be set in
+ * this file.
+ *
+ */
+
+#ifndef _KLIBC_ARCHCONFIG_H
+#define _KLIBC_ARCHCONFIG_H
+
+/* On i386, only half the signals are accessible using the legacy calls. */
+#define _KLIBC_USE_RT_SIG 1
+
+/* The stock i386 kernel is fine, but a whole string of Fedora kernels
+   had a broken default restorer.  It's easier to enable this here. */
+#define _KLIBC_NEEDS_SA_RESTORER 1
+
+#endif				/* _KLIBC_ARCHCONFIG_H */
diff --git a/usr/include/arch/i386/klibc/archsetjmp.h b/usr/include/arch/i386/klibc/archsetjmp.h
new file mode 100644
index 0000000..ea1ba3d
--- /dev/null
+++ b/usr/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/usr/include/arch/i386/klibc/archsignal.h b/usr/include/arch/i386/klibc/archsignal.h
new file mode 100644
index 0000000..6c942db
--- /dev/null
+++ b/usr/include/arch/i386/klibc/archsignal.h
@@ -0,0 +1,114 @@
+/*
+ * arch/i386/include/klibc/archsignal.h
+ *
+ * Architecture-specific signal definitions
+ *
+ */
+
+#ifndef _KLIBC_ARCHSIGNAL_H
+#define _KLIBC_ARCHSIGNAL_H
+
+/* The in-kernel headers for i386 still have libc5
+   crap in them.  Reconsider using <asm/signal.h>
+   when/if it gets cleaned up; for now, duplicate
+   the definitions here. */
+
+#define _NSIG           64
+#define _NSIG_BPW       32
+#define _NSIG_WORDS     (_NSIG / _NSIG_BPW)
+
+typedef struct {
+	unsigned long sig[_NSIG_WORDS];
+} sigset_t;
+
+#define SIGHUP           1
+#define SIGINT           2
+#define SIGQUIT          3
+#define SIGILL           4
+#define SIGTRAP          5
+#define SIGABRT          6
+#define SIGIOT           6
+#define SIGBUS           7
+#define SIGFPE           8
+#define SIGKILL          9
+#define SIGUSR1         10
+#define SIGSEGV         11
+#define SIGUSR2         12
+#define SIGPIPE         13
+#define SIGALRM         14
+#define SIGTERM         15
+#define SIGSTKFLT       16
+#define SIGCHLD         17
+#define SIGCONT         18
+#define SIGSTOP         19
+#define SIGTSTP         20
+#define SIGTTIN         21
+#define SIGTTOU         22
+#define SIGURG          23
+#define SIGXCPU         24
+#define SIGXFSZ         25
+#define SIGVTALRM       26
+#define SIGPROF         27
+#define SIGWINCH        28
+#define SIGIO           29
+#define SIGPOLL         SIGIO
+#define SIGPWR          30
+#define SIGSYS          31
+#define SIGUNUSED       31
+
+#define SIGRTMIN        32
+#define SIGRTMAX        (_NSIG-1)
+
+/*
+ * SA_FLAGS values:
+ *
+ * SA_ONSTACK indicates that a registered stack_t will be used.
+ * SA_INTERRUPT is a no-op, but left due to historical reasons. Use the
+ * SA_RESTART flag to get restarting signals (which were the default long ago)
+ * SA_NOCLDSTOP flag to turn off SIGCHLD when children stop.
+ * SA_RESETHAND clears the handler when the signal is delivered.
+ * SA_NOCLDWAIT flag on SIGCHLD to inhibit zombies.
+ * SA_NODEFER prevents the current signal from being masked in the handler.
+ *
+ * SA_ONESHOT and SA_NOMASK are the historical Linux names for the Single
+ * Unix names RESETHAND and NODEFER respectively.
+ */
+#define SA_NOCLDSTOP	0x00000001u
+#define SA_NOCLDWAIT	0x00000002u
+#define SA_SIGINFO	0x00000004u
+#define SA_ONSTACK	0x08000000u
+#define SA_RESTART	0x10000000u
+#define SA_NODEFER	0x40000000u
+#define SA_RESETHAND	0x80000000u
+
+#define SA_NOMASK	SA_NODEFER
+#define SA_ONESHOT	SA_RESETHAND
+#define SA_INTERRUPT	0x20000000	/* dummy -- ignored */
+
+#define SA_RESTORER	0x04000000
+
+/*
+ * sigaltstack controls
+ */
+#define SS_ONSTACK	1
+#define SS_DISABLE	2
+
+#define MINSIGSTKSZ	2048
+#define SIGSTKSZ	8192
+
+#include <asm-generic/signal.h>
+
+/* This uses gcc anonymous union support... */
+struct siginfo;
+
+struct sigaction {
+	union {
+		__sighandler_t sa_handler;
+		void (*sa_sigaction)(int, struct siginfo *, void *);
+	};
+	unsigned long	sa_flags;
+	__sigrestore_t 	sa_restorer;
+	sigset_t	sa_mask;
+};
+
+#endif
diff --git a/usr/include/arch/i386/klibc/archstat.h b/usr/include/arch/i386/klibc/archstat.h
new file mode 100644
index 0000000..c00f955
--- /dev/null
+++ b/usr/include/arch/i386/klibc/archstat.h
@@ -0,0 +1,38 @@
+#ifndef _KLIBC_ARCHSTAT_H
+#define _KLIBC_ARCHSTAT_H
+
+#include <klibc/stathelp.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 {
+	__stdev64	(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;
+
+	__stdev64	(st_rdev);
+	unsigned char	__pad3[4];
+
+	long long	st_size;
+	unsigned long	st_blksize;
+
+	unsigned long 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/usr/include/arch/i386/klibc/diverr.h b/usr/include/arch/i386/klibc/diverr.h
new file mode 100644
index 0000000..fa238ac
--- /dev/null
+++ b/usr/include/arch/i386/klibc/diverr.h
@@ -0,0 +1,15 @@
+/*
+ * 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 ("int $0");
+}
+
+#endif				/* _KLIBC_DIVERR_H */
diff --git a/usr/include/arch/i386/sys/io.h b/usr/include/arch/i386/sys/io.h
new file mode 100644
index 0000000..cf31b97
--- /dev/null
+++ b/usr/include/arch/i386/sys/io.h
@@ -0,0 +1,127 @@
+/* ----------------------------------------------------------------------- *
+ *
+ *   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/usr/include/arch/i386/sys/vm86.h b/usr/include/arch/i386/sys/vm86.h
new file mode 100644
index 0000000..c4651cd
--- /dev/null
+++ b/usr/include/arch/i386/sys/vm86.h
@@ -0,0 +1,40 @@
+/* ----------------------------------------------------------------------- *
+ *
+ *   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/usr/klibc/arch/i386/MCONFIG b/usr/klibc/arch/i386/MCONFIG
new file mode 100644
index 0000000..e173266
--- /dev/null
+++ b/usr/klibc/arch/i386/MCONFIG
@@ -0,0 +1,33 @@
+# -*- makefile -*-
+#
+# arch/i386/MCONFIG
+#
+# Special rules for this architecture.  Note that this is actually
+# included from the main Makefile, and that pathnames should be
+# accordingly.
+#
+
+# Enable this to compile with register parameters; only safe for
+# gcc >= 3
+
+ifeq ($(CONFIG_REGPARM),y)
+REGPARM_OPT := -mregparm=3 -D_REGPARM=3
+endif
+
+gcc_align_option  := $(call cc-option, \
+		-falign-functions=0 -falign-jumps=0 -falign-loops=0, \
+		-malign-functions=0 -malign-jumps=0 -malign-loops=0)
+gcc_m32_option  := $(call cc-option, -m32, )
+
+KLIBCOPTFLAGS     = -march=i386 -Os -g -fomit-frame-pointer $(gcc_align_option)
+KLIBCLDFLAGS      = -m elf_i386
+KLIBCREQFLAGS	  += $(REGPARM_OPT)
+KLIBCARCHREQFLAGS += $(gcc_m32_option)
+
+KLIBCBITSIZE  = 32
+
+# Extra linkflags when building the shared version of the library
+# This address needs to be reachable using normal inter-module
+# calls, and work on the memory models for this architecture
+# 96 MB - normal binaries start at 128 MB
+KLIBCSHAREDFLAGS	= -Ttext 0x06000200
diff --git a/usr/klibc/arch/i386/Makefile.inc b/usr/klibc/arch/i386/Makefile.inc
new file mode 100644
index 0000000..d13a28f
--- /dev/null
+++ b/usr/klibc/arch/i386/Makefile.inc
@@ -0,0 +1,30 @@
+# -*- makefile -*-
+#
+# arch/i386/Makefile.inc
+#
+# Special rules for this architecture.  Note that this is actually
+# included from the main Makefile, and that pathnames should be
+# accordingly.
+#
+
+KLIBCARCHOBJS = \
+	arch/$(KLIBCARCH)/socketcall.o \
+	arch/$(KLIBCARCH)/setjmp.o \
+	arch/$(KLIBCARCH)/syscall.o \
+	arch/$(KLIBCARCH)/varsyscall.o \
+	arch/$(KLIBCARCH)/open.o \
+	arch/$(KLIBCARCH)/openat.o \
+	arch/$(KLIBCARCH)/sigreturn.o \
+	arch/$(KLIBCARCH)/vfork.o \
+	arch/$(KLIBCARCH)/libgcc/__ashldi3.o \
+	arch/$(KLIBCARCH)/libgcc/__ashrdi3.o \
+	arch/$(KLIBCARCH)/libgcc/__lshrdi3.o \
+	arch/$(KLIBCARCH)/libgcc/__muldi3.o \
+	arch/$(KLIBCARCH)/libgcc/__negdi2.o \
+	libgcc/__divdi3.o \
+	libgcc/__moddi3.o \
+	libgcc/__udivdi3.o \
+	libgcc/__umoddi3.o \
+	libgcc/__udivmoddi4.o
+
+archclean:
diff --git a/usr/klibc/arch/i386/crt0.S b/usr/klibc/arch/i386/crt0.S
new file mode 100644
index 0000000..8c6635e
--- /dev/null
+++ b/usr/klibc/arch/i386/crt0.S
@@ -0,0 +1,31 @@
+#
+# arch/i386/crt0.S
+#
+# Does arch-specific initialization and invokes __libc_init
+# with the appropriate arguments.
+#
+# See __static_init.c or __shared_init.c for the expected
+# arguments.
+#
+
+	.text
+	.align 4
+	.type _start,@function
+	.globl _start
+_start:
+	# Save the address of the ELF argument array
+	movl %esp,%eax		# Address of ELF arguments
+	# Set up a faux stack frame for the benefit of gdb
+	xorl %ebp,%ebp
+	push %ebp		# Keep gdb from getting confused
+	push %ebp		# Keep gdb from getting confused
+	# Push the arguments and called __libc_init()
+#ifndef _REGPARM
+	push %edx		# atexit() function
+	push %eax		# ELF array
+#endif
+	call __libc_init
+	# If __libc_init returns, problem...
+	hlt
+
+	.size _start, .-_start
diff --git a/usr/klibc/arch/i386/libgcc/__ashldi3.S b/usr/klibc/arch/i386/libgcc/__ashldi3.S
new file mode 100644
index 0000000..7344142
--- /dev/null
+++ b/usr/klibc/arch/i386/libgcc/__ashldi3.S
@@ -0,0 +1,29 @@
+/*
+ * arch/i386/libgcc/__ashldi3.S
+ *
+ * 64-bit shl
+ */
+	.text
+	.align 4
+	.globl __ashldi3
+	.type __ashldi3,@function
+__ashldi3:
+#ifndef _REGPARM
+	movl  4(%esp),%eax
+	movl  8(%esp),%edx
+	movb  12(%esp),%cl
+#endif
+	cmpb  $32,%cl
+	jae   1f
+
+	shldl %cl,%eax,%edx
+	shl   %cl,%eax
+	ret
+
+1:
+	xorl  %edx,%edx
+	shl   %cl,%eax
+	xchgl %edx,%eax
+	ret
+
+	.size __ashldi3,.-__ashldi3
diff --git a/usr/klibc/arch/i386/libgcc/__ashrdi3.S b/usr/klibc/arch/i386/libgcc/__ashrdi3.S
new file mode 100644
index 0000000..7666eb2
--- /dev/null
+++ b/usr/klibc/arch/i386/libgcc/__ashrdi3.S
@@ -0,0 +1,29 @@
+/*
+ * arch/i386/libgcc/__ashrdi3.S
+ *
+ * 64-bit sar
+ */
+	.text
+	.align 4
+	.globl __ashrdi3
+	.type __ashrdi3,@function
+__ashrdi3:
+#ifndef _REGPARM
+	movl  4(%esp),%eax
+	movl  8(%esp),%edx
+	movb  12(%esp),%cl
+#endif
+	cmpb  $32,%cl
+	jae   1f
+
+	shrdl %cl,%edx,%eax
+	sarl  %cl,%edx
+	ret
+
+1:
+	sarl  %cl,%edx
+	movl  %edx,%eax
+	cdq
+	ret
+
+	.size __ashrdi3,.-__ashrdi3
diff --git a/usr/klibc/arch/i386/libgcc/__lshrdi3.S b/usr/klibc/arch/i386/libgcc/__lshrdi3.S
new file mode 100644
index 0000000..6a63c52
--- /dev/null
+++ b/usr/klibc/arch/i386/libgcc/__lshrdi3.S
@@ -0,0 +1,29 @@
+/*
+ * arch/i386/libgcc/__lshrdi3.S
+ *
+ * 64-bit shr
+ */
+	.text
+	.align 4
+	.globl __lshrdi3
+	.type __lshrdi3,@function
+__lshrdi3:
+#ifndef _REGPARM
+	movl  4(%esp),%eax
+	movl  8(%esp),%edx
+	movb  12(%esp),%cl
+#endif
+	cmpb  $32,%cl
+	jae   1f
+
+	shrdl %cl,%edx,%eax
+	shrl  %cl,%edx
+	ret
+
+1:
+	shrl  %cl,%edx
+	xorl  %eax,%eax
+	xchgl %edx,%eax
+	ret
+
+	.size __lshrdi3,.-__lshrdi3
diff --git a/usr/klibc/arch/i386/libgcc/__muldi3.S b/usr/klibc/arch/i386/libgcc/__muldi3.S
new file mode 100644
index 0000000..472c7cc
--- /dev/null
+++ b/usr/klibc/arch/i386/libgcc/__muldi3.S
@@ -0,0 +1,34 @@
+/*
+ * arch/i386/libgcc/__muldi3.S
+ *
+ * 64*64 = 64 bit unsigned multiplication
+ */
+
+	.text
+	.align 4
+	.globl __muldi3
+	.type __muldi3,@function
+__muldi3:
+	push  %esi
+#ifndef _REGPARM
+	movl  8(%esp),%eax
+	movl  %eax,%esi
+	movl  16(%esp),%ecx
+	mull  %ecx
+	imull 12(%esp),%ecx
+	imull 20(%esp),%esi
+	addl  %ecx,%edx
+	addl  %esi,%edx
+#else
+	movl  %eax,%esi
+	push  %edx
+	mull  %ecx
+	imull 8(%esp),%esi
+	addl  %esi,%edx
+	pop   %esi
+	imull %esi,%ecx
+	addl  %ecx,%edx
+#endif
+	pop   %esi
+	ret
+	.size __muldi3,.-__muldi3
diff --git a/usr/klibc/arch/i386/libgcc/__negdi2.S b/usr/klibc/arch/i386/libgcc/__negdi2.S
new file mode 100644
index 0000000..147ad94
--- /dev/null
+++ b/usr/klibc/arch/i386/libgcc/__negdi2.S
@@ -0,0 +1,21 @@
+/*
+ * arch/i386/libgcc/__negdi2.S
+ *
+ * 64-bit negation
+ */
+
+	.text
+	.align 4
+	.globl __negdi2
+	.type __negdi2,@function
+__negdi2:
+#ifndef _REGPARM
+	movl 4(%esp),%eax
+	movl 8(%esp),%edx
+#endif
+	negl %edx
+	negl %eax
+	sbbl $0,%edx
+	ret
+
+	.size __negdi2,.-__negdi2
diff --git a/usr/klibc/arch/i386/open.S b/usr/klibc/arch/i386/open.S
new file mode 100644
index 0000000..7cd136c
--- /dev/null
+++ b/usr/klibc/arch/i386/open.S
@@ -0,0 +1,29 @@
+/*
+ * arch/i386/open.S
+ *
+ * Handle the open() system call - oddball due to the varadic
+ * prototype, which forces the use of the cdecl calling convention,
+ * and the need for O_LARGEFILE.
+ */
+
+#include <asm/unistd.h>
+
+/* <asm/fcntl.h>, despite the name, isn't assembly-safe */
+#define O_LARGEFILE     0100000
+
+	.globl	open
+	.type	open,@function
+
+open:
+#ifdef _REGPARM
+	movl	4(%esp),%eax
+	movl	8(%esp),%edx
+	movl	12(%esp),%ecx
+	orl	$O_LARGEFILE,%edx
+#else
+	orl	$O_LARGEFILE,8(%esp)
+#endif
+	pushl	$__NR_open
+	jmp	__syscall_common
+
+	.size	open,.-open
diff --git a/usr/klibc/arch/i386/openat.S b/usr/klibc/arch/i386/openat.S
new file mode 100644
index 0000000..2dfdfe2
--- /dev/null
+++ b/usr/klibc/arch/i386/openat.S
@@ -0,0 +1,26 @@
+/*
+ * arch/i386/openat.S
+ *
+ * Handle the openat() system call - oddball due to the varadic
+ * prototype, which forces the use of the cdecl calling convention,
+ * and the need for O_LARGEFILE.
+ */
+
+#include <asm/unistd.h>
+
+/* <asm/fcntl.h>, despite the name, isn't assembly-safe */
+#define O_LARGEFILE     0100000
+
+#ifdef __NR_openat		/* Don't build if kernel headers too old */
+
+	.globl	openat
+	.type	openat,@function
+
+openat:
+	orl	$O_LARGEFILE,12(%esp)
+	pushl	$__NR_openat
+	jmp	__syscall_varadic
+
+	.size	openat,.-openat
+
+#endif
diff --git a/usr/klibc/arch/i386/setjmp.S b/usr/klibc/arch/i386/setjmp.S
new file mode 100644
index 0000000..b766792
--- /dev/null
+++ b/usr/klibc/arch/i386/setjmp.S
@@ -0,0 +1,58 @@
+#
+# arch/i386/setjmp.S
+#
+# setjmp/longjmp for the i386 architecture
+#
+
+#
+# The jmp_buf is assumed to contain the following, in order:
+#	%ebx
+#	%esp
+#	%ebp
+#	%esi
+#	%edi
+#	<return address>
+#
+
+	.text
+	.align 4
+	.globl setjmp
+	.type setjmp, @function
+setjmp:
+#ifdef _REGPARM
+	movl %eax,%edx
+#else
+	movl 4(%esp),%edx
+#endif
+	popl %ecx			# Return address, and adjust the stack
+	xorl %eax,%eax			# Return value
+	movl %ebx,(%edx)
+	movl %esp,4(%edx)		# Post-return %esp!
+	pushl %ecx			# Make the call/return stack happy
+	movl %ebp,8(%edx)
+	movl %esi,12(%edx)
+	movl %edi,16(%edx)
+	movl %ecx,20(%edx)		# Return address
+	ret
+
+	.size setjmp,.-setjmp
+
+	.text
+	.align 4
+	.globl longjmp
+	.type longjmp, @function
+longjmp:
+#ifdef _REGPARM
+	xchgl %eax,%edx
+#else
+	movl 4(%esp),%edx		# jmp_ptr address
+	movl 8(%esp),%eax		# Return value
+#endif
+	movl (%edx),%ebx
+	movl 4(%edx),%esp
+	movl 8(%edx),%ebp
+	movl 12(%edx),%esi
+	movl 16(%edx),%edi
+	jmp *20(%edx)
+
+	.size longjmp,.-longjmp
diff --git a/usr/klibc/arch/i386/sigreturn.S b/usr/klibc/arch/i386/sigreturn.S
new file mode 100644
index 0000000..f2a3241
--- /dev/null
+++ b/usr/klibc/arch/i386/sigreturn.S
@@ -0,0 +1,15 @@
+#
+# arch/i386/sigreturn.S
+#
+
+#include <asm/unistd.h>
+
+	.text
+	.align 4
+	.globl __sigreturn
+	.type __sigreturn,@function
+__sigreturn:
+	pop	%eax		# Have no idea why this is needed...
+	movl	$__NR_sigreturn,%eax
+	int	$0x80
+	.size __sigreturn,.-__sigreturn
diff --git a/usr/klibc/arch/i386/socketcall.S b/usr/klibc/arch/i386/socketcall.S
new file mode 100644
index 0000000..816db34
--- /dev/null
+++ b/usr/klibc/arch/i386/socketcall.S
@@ -0,0 +1,55 @@
+#
+# socketcall.S
+#
+# Socketcalls use the following convention:
+# %eax = __NR_socketcall
+# %ebx = socketcall number
+# %ecx = pointer to arguments (up to 6)
+#
+	
+#include <asm/unistd.h>
+
+#ifdef __i386__
+
+	.text
+	.align 4
+	.globl __socketcall_common
+	.type __socketcall_common, @function
+
+__socketcall_common:
+	xchgl	%ebx,(%esp)	# The stub passes the socketcall # on stack
+
+#ifdef	_REGPARM
+	pushl	16(%esp)	# Arg 6
+	pushl	16(%esp)	# Arg 5
+	pushl	16(%esp)	# Arg 4
+	pushl	%ecx
+	pushl	%edx
+	pushl	%eax
+	movl	%esp,%ecx
+#else
+	leal	8(%esp),%ecx	# Arguments already contiguous on-stack
+#endif
+
+	movl	$__NR_socketcall,%eax
+	int	$0x80
+
+#ifdef	_REGPARM
+	addl	$6*4, %esp
+#endif
+	
+	cmpl	$-4095,%eax	# Error return?
+
+	popl	%ebx
+
+	jb	1f
+
+	negl	%eax
+	movl	%eax,errno
+	orl	$-1,%eax	# Return -1
+1:
+	ret
+
+	.size __socketcall_common,.-__socketcall_common
+
+#endif
diff --git a/usr/klibc/arch/i386/syscall.S b/usr/klibc/arch/i386/syscall.S
new file mode 100644
index 0000000..d28717b
--- /dev/null
+++ b/usr/klibc/arch/i386/syscall.S
@@ -0,0 +1,69 @@
+/*
+ * arch/i386/syscall.S
+ *
+ * Common tail-handling code for system calls.
+ *
+ * The arguments are on the stack; the system call number in %eax.
+ */
+
+#define ARG(n)	(4*n+20)(%esp)
+
+	.text
+	.align	4
+	.globl	__syscall_common
+	.type	__syscall_common,@function
+__syscall_common:
+#ifdef _REGPARM
+	xchgl	%ebx,(%esp)
+#else
+	popl	%eax
+	pushl	%ebx
+#endif
+	pushl	%esi
+	pushl	%edi
+	pushl	%ebp
+
+#ifdef _REGPARM
+	xchgl	%eax,%ebx
+	xchgl	%ecx,%edx
+	movl	ARG(0),%esi
+	movl	ARG(1),%edi
+	movl	ARG(2),%ebp
+#else
+	movl	ARG(0),%ebx		# Syscall arguments
+	movl	ARG(1),%ecx
+	movl	ARG(2),%edx
+	movl	ARG(3),%esi
+	movl	ARG(4),%edi
+	movl	ARG(5),%ebp
+#endif
+	.globl __syscall_common_tail
+__syscall_common_tail:
+	int	$0x80
+
+	cmpl	$-4095,%eax
+
+	popl	%ebp
+	popl	%edi
+	popl	%esi
+	popl	%ebx
+
+	jb	1f
+
+	# Error return, must set errno
+	negl	%eax
+	movl	%eax,errno
+	orl	$-1,%eax		# Return -1
+
+1:
+	ret
+
+	.size	__syscall_common,.-__syscall_common
+
+#ifndef _REGPARM
+
+	.globl	__syscall_varadic
+	.type	__syscall_varadic,@function
+__syscall_varadic = __syscall_common
+
+#endif
diff --git a/usr/klibc/arch/i386/sysstub.ph b/usr/klibc/arch/i386/sysstub.ph
new file mode 100644
index 0000000..e73a3ff
--- /dev/null
+++ b/usr/klibc/arch/i386/sysstub.ph
@@ -0,0 +1,26 @@
+# -*- perl -*-
+#
+# arch/i386/sysstub.ph
+#
+# Script to generate system call stubs
+#
+
+sub make_sysstub($$$$$@) {
+    my($outputdir, $fname, $type, $sname, $stype, @args) = @_;
+
+    open(OUT, '>', "${outputdir}/${fname}.S");
+    print OUT "#include <asm/unistd.h>\n";
+    print OUT "\n";
+    print OUT "\t.type ${fname},\@function\n";
+    print OUT "\t.globl ${fname}\n";
+    print OUT "${fname}:\n";
+
+    $stype = 'common' if ( $stype eq '' );
+
+    print OUT "\tpushl \$__NR_${sname}\n";
+    print OUT "\tjmp __syscall_$stype\n";
+    print OUT "\t.size ${fname},.-${fname}\n";
+    close(OUT);
+}
+
+1;
diff --git a/usr/klibc/arch/i386/varsyscall.S b/usr/klibc/arch/i386/varsyscall.S
new file mode 100644
index 0000000..24329ea
--- /dev/null
+++ b/usr/klibc/arch/i386/varsyscall.S
@@ -0,0 +1,36 @@
+/*
+ * arch/i386/varsyscall.S
+ *
+ * Common tail-handling code for varadic system calls (which always
+ * use the cdecl convention.)
+ *
+ * The arguments are on the stack; the system call number in %eax.
+ */
+
+#ifdef	_REGPARM
+
+#define ARG(n)	(4*n+20)(%esp)
+
+	.text
+	.align	4
+	.globl	__syscall_varadic
+	.type	__syscall_varadic,@function
+__syscall_varadic:
+	popl	%eax
+	pushl	%ebx
+	pushl	%esi
+	pushl	%edi
+	pushl	%ebp
+
+	movl	ARG(0),%ebx		# Syscall arguments
+	movl	ARG(1),%ecx
+	movl	ARG(2),%edx
+	movl	ARG(3),%esi
+	movl	ARG(4),%edi
+	movl	ARG(5),%ebp
+
+	jmp	__syscall_common_tail
+
+	.size	__syscall_varadic,.-__syscall_varadic
+
+#endif
diff --git a/usr/klibc/arch/i386/vfork.S b/usr/klibc/arch/i386/vfork.S
new file mode 100644
index 0000000..c98ba3a
--- /dev/null
+++ b/usr/klibc/arch/i386/vfork.S
@@ -0,0 +1,26 @@
+#
+# usr/klibc/arch/i386/vfork.S
+#
+# vfork is nasty - there must be nothing at all on the stack above
+# the stack frame of the enclosing function.
+#
+
+#include <asm/unistd.h>
+
+        .text
+        .align  4
+	.globl	vfork
+	.type	vfork, @function
+vfork:
+	popl	%edx			/* Return address */
+	movl	$__NR_vfork, %eax
+	int	$0x80
+	pushl	%edx
+	cmpl	$-4095, %eax
+	jae	1f
+	ret
+1:
+	negl	%eax
+	movl	%eax, errno
+	orl	$-1, %eax
+	ret

^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [klibc 08/31] ia64 support for klibc
  2006-06-28  5:17 [klibc 00/31] klibc as a historyless patchset (updated and reorganized) H. Peter Anvin
                   ` (6 preceding siblings ...)
  2006-06-28  5:17 ` [klibc 07/31] i386 " H. Peter Anvin
@ 2006-06-28  5:17 ` H. Peter Anvin
  2006-06-28  5:17 ` [klibc 09/31] m32r " H. Peter Anvin
                   ` (22 subsequent siblings)
  30 siblings, 0 replies; 58+ messages in thread
From: H. Peter Anvin @ 2006-06-28  5:17 UTC (permalink / raw)
  To: linux-kernel, klibc; +Cc: H. Peter Anvin

The parts of klibc specific to the ia64 architecture.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>

---
commit 2ddc0b5cb0056f213e6e279030e50c1bd223cef6
tree 7bbf2602b638130dc949cd1d23981da665f3bddd
parent 0b76ae4ad7c15cddd0d1202234f5dbc75e8dde56
author H. Peter Anvin <hpa@zytor.com> Tue, 27 Jun 2006 20:50:36 -0700
committer H. Peter Anvin <hpa@zytor.com> Tue, 27 Jun 2006 20:50:36 -0700

 usr/include/arch/ia64/klibc/archconfig.h |   17 +
 usr/include/arch/ia64/klibc/archsetjmp.h |   17 +
 usr/include/arch/ia64/klibc/archsignal.h |   32 +++
 usr/include/arch/ia64/klibc/archstat.h   |   26 ++
 usr/include/arch/ia64/klibc/archsys.h    |  217 +++++++++++++++++++
 usr/klibc/arch/ia64/MCONFIG              |   11 +
 usr/klibc/arch/ia64/Makefile.inc         |   26 ++
 usr/klibc/arch/ia64/crt0.S               |   27 ++
 usr/klibc/arch/ia64/pipe.c               |   41 ++++
 usr/klibc/arch/ia64/setjmp.S             |  343 ++++++++++++++++++++++++++++++
 usr/klibc/arch/ia64/syscall.S            |   20 ++
 usr/klibc/arch/ia64/sysstub.ph           |   29 +++
 usr/klibc/arch/ia64/vfork.S              |   42 ++++
 13 files changed, 848 insertions(+), 0 deletions(-)

diff --git a/usr/include/arch/ia64/klibc/archconfig.h b/usr/include/arch/ia64/klibc/archconfig.h
new file mode 100644
index 0000000..adbd1ee
--- /dev/null
+++ b/usr/include/arch/ia64/klibc/archconfig.h
@@ -0,0 +1,17 @@
+/*
+ * include/arch/ia64/klibc/archconfig.h
+ *
+ * See include/klibc/sysconfig.h for the options that can be set in
+ * this file.
+ *
+ */
+
+#ifndef _KLIBC_ARCHCONFIG_H
+#define _KLIBC_ARCHCONFIG_H
+
+/* IA64 doesn't have sys_fork, but it does have an MMU */
+#define _KLIBC_NO_MMU 0
+/* IA64 doesn't have sys_vfork, it has architecture-specific code */
+#define _KLIBC_REAL_VFORK 1
+
+#endif				/* _KLIBC_ARCHCONFIG_H */
diff --git a/usr/include/arch/ia64/klibc/archsetjmp.h b/usr/include/arch/ia64/klibc/archsetjmp.h
new file mode 100644
index 0000000..43564ee
--- /dev/null
+++ b/usr/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/usr/include/arch/ia64/klibc/archsignal.h b/usr/include/arch/ia64/klibc/archsignal.h
new file mode 100644
index 0000000..fbc961b
--- /dev/null
+++ b/usr/include/arch/ia64/klibc/archsignal.h
@@ -0,0 +1,32 @@
+/*
+ * arch/ia64/include/klibc/archsignal.h
+ *
+ * Architecture-specific signal definitions.
+ *
+ */
+
+#ifndef _KLIBC_ARCHSIGNAL_H
+#define _KLIBC_ARCHSIGNAL_H
+
+#include <asm/signal.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/usr/include/arch/ia64/klibc/archstat.h b/usr/include/arch/ia64/klibc/archstat.h
new file mode 100644
index 0000000..ff38e41
--- /dev/null
+++ b/usr/include/arch/ia64/klibc/archstat.h
@@ -0,0 +1,26 @@
+#ifndef _KLIBC_ARCHSTAT_H
+#define _KLIBC_ARCHSTAT_H
+
+#include <klibc/stathelp.h>
+
+#define _STATBUF_ST_NSEC
+
+struct stat {
+	__stdev64	(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;
+	__stdev64	(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/usr/include/arch/ia64/klibc/archsys.h b/usr/include/arch/ia64/klibc/archsys.h
new file mode 100644
index 0000000..6007821
--- /dev/null
+++ b/usr/include/arch/ia64/klibc/archsys.h
@@ -0,0 +1,217 @@
+/*
+ * 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/usr/klibc/arch/ia64/MCONFIG b/usr/klibc/arch/ia64/MCONFIG
new file mode 100644
index 0000000..99dd4a5
--- /dev/null
+++ b/usr/klibc/arch/ia64/MCONFIG
@@ -0,0 +1,11 @@
+# -*- makefile -*-
+#
+# arch/ia64/MCONFIG
+#
+# Special rules for this architecture.  Note that this is actually
+# included from the main Makefile, and that pathnames should be
+# accordingly.
+#
+
+KLIBCOPTFLAGS = -Os
+KLIBCBITSIZE  = 64
diff --git a/usr/klibc/arch/ia64/Makefile.inc b/usr/klibc/arch/ia64/Makefile.inc
new file mode 100644
index 0000000..8bd2910
--- /dev/null
+++ b/usr/klibc/arch/ia64/Makefile.inc
@@ -0,0 +1,26 @@
+# -*- makefile -*-
+#
+# arch/ia64/Makefile.inc
+#
+# Special rules for this architecture.  Note that this is actually
+# included from the main Makefile, and that pathnames should be
+# accordingly.
+#
+
+KLIBCARCHOBJS = \
+	arch/$(KLIBCARCH)/vfork.o \
+	arch/$(KLIBCARCH)/setjmp.o \
+	arch/$(KLIBCARCH)/pipe.o \
+	arch/$(KLIBCARCH)/syscall.o \
+	libgcc/__divdi3.o \
+	libgcc/__divsi3.o \
+	libgcc/__udivdi3.o \
+	libgcc/__udivsi3.o \
+	libgcc/__umodsi3.o \
+	libgcc/__umoddi3.o \
+	libgcc/__udivmodsi4.o \
+	libgcc/__udivmoddi4.o
+
+KLIBCARCHSOOBJS = $(patsubst %o,%.lo,%(KLIBCARCHOBJS))
+
+archclean:
diff --git a/usr/klibc/arch/ia64/crt0.S b/usr/klibc/arch/ia64/crt0.S
new file mode 100644
index 0000000..722276e
--- /dev/null
+++ b/usr/klibc/arch/ia64/crt0.S
@@ -0,0 +1,27 @@
+
+#include <asm/fpu.h>
+
+	.align 32
+	.global _start
+
+	.proc _start
+	.type _start,@function
+_start:
+	.prologue
+	.save rp, r0
+
+	alloc r2 = ar.pfs,0,0,2,0
+	movl r3 = FPSR_DEFAULT
+	;;
+	adds out0= 16,sp    /* argc pointer */
+	movl gp = @gprel(0f)
+0:	mov r9 = ip
+	;;
+	sub gp = r9, gp     /* back-compute gp value */
+
+	.body
+	br.call.sptk.few rp = __libc_init
+	;;
+	break 0             /* break miserably if we ever return */
+
+	.endp _start
diff --git a/usr/klibc/arch/ia64/pipe.c b/usr/klibc/arch/ia64/pipe.c
new file mode 100644
index 0000000..fa3a272
--- /dev/null
+++ b/usr/klibc/arch/ia64/pipe.c
@@ -0,0 +1,41 @@
+/*
+ * pipe.c
+ */
+
+#include <sys/syscall.h>
+#include <klibc/archsys.h>
+
+#define ASM_CLOBBERS ,"out2", "out3", "out4", "out5", "out6", "out7",    \
+   /* Non-stacked integer registers, minus r8, r9, r10, r15.  */	\
+  "r2", "r3", "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"
+
+int pipe(int *filedes)
+{
+	register long _r8 asm("r8");
+	register long _r9 asm("r9");
+	register long _r10 asm("r10");
+	register long _r15 asm("r15") = __NR_pipe;
+	register long _out0 asm("out0") = (long)filedes;
+	long _retval;
+	__asm __volatile(__IA64_BREAK:"=r"(_r8), "=r"(_r10), "=r"(_r15),
+			 "=r"(_out0), "=r"(_r9)
+			 :"2"(_r15), "3"(_out0)
+			 :"memory" ASM_CLOBBERS);
+	if (_r10 == -1) {
+		errno = _r8;
+		_retval = -1;
+	} else {
+		filedes[0] = _r8;
+		filedes[1] = _r9;
+		_retval = 0;
+	}
+	return _retval;
+}
diff --git a/usr/klibc/arch/ia64/setjmp.S b/usr/klibc/arch/ia64/setjmp.S
new file mode 100644
index 0000000..ab1cea2
--- /dev/null
+++ b/usr/klibc/arch/ia64/setjmp.S
@@ -0,0 +1,343 @@
+/*
+ * IA-64 specific setjmp/longjmp routines
+ *
+ * Inspired by setjmp.s from the FreeBSD kernel.
+ */
+
+#define	J_UNAT		0
+#define	J_NATS		0x8
+#define	J_PFS		0x10
+#define	J_BSP		0x18
+#define	J_RNAT		0x20
+#define	J_PREDS		0x28
+#define	J_LC		0x30
+#define	J_R4		0x38
+#define	J_R5		0x40
+#define	J_R6		0x48
+#define	J_R7		0x50
+#define	J_SP		0x58
+#define	J_F2		0x60
+#define	J_F3		0x70
+#define	J_F4		0x80
+#define	J_F5		0x90
+#define	J_F16		0xa0
+#define	J_F17		0xb0
+#define	J_F18		0xc0
+#define	J_F19		0xd0
+#define	J_F20		0xe0
+#define	J_F21		0xf0
+#define	J_F22		0x100
+#define	J_F23		0x110
+#define	J_F24		0x120
+#define	J_F25		0x130
+#define	J_F26		0x140
+#define	J_F27		0x150
+#define	J_F28		0x160
+#define	J_F29		0x170
+#define	J_F30		0x180
+#define	J_F31		0x190
+#define	J_FPSR		0x1a0
+#define	J_B0		0x1a8
+#define	J_B1		0x1b0
+#define	J_B2		0x1b8
+#define	J_B3		0x1c0
+#define	J_B4		0x1c8
+#define	J_B5		0x1d0
+#define	J_SIGMASK	0x1d8
+#define	J_SIGSET	0x1e0
+#define	J_GP		0x1f0
+
+// int setjmp(struct jmp_buffer *)
+//
+//  Setup a non-local goto.
+//
+// Description:
+//
+//  SetJump stores the current register set in the area pointed to
+//  by "save".  It returns zero.  Subsequent calls to "LongJump" will
+//  restore the registers and return non-zero to the same location.
+//
+// On entry, r32 contains the pointer to the jmp_buffer
+//
+	.align 32
+	.global setjmp
+	.proc setjmp
+setjmp:
+    //
+    //  Make sure buffer is aligned at 16byte boundary
+    //
+    add     r10 = -0x10,r0  ;;  // mask the lower 4 bits
+    and     r32 = r32, r10;;
+    add     r32 = 0x10, r32;;   // move to next 16 byte boundary
+
+    add     r10 = J_PREDS, r32  // skip Unats & pfs save area
+    add     r11 = J_BSP, r32
+    //
+    //  save immediate context
+    //
+    mov     r2 = ar.bsp         // save backing store pointer
+    mov     r3 = pr             // save predicates
+    flushrs
+    ;;
+    //
+    // save user Unat register
+    //
+    mov     r16 = ar.lc         // save loop count register
+    mov     r14 = ar.unat       // save user Unat register
+
+    st8     [r10] = r3, J_LC-J_PREDS
+    st8     [r11] = r2, J_R4-J_BSP
+    ;;
+    st8     [r10] = r16, J_R5-J_LC
+    st8     [r32] = r14, J_NATS // Note: Unat at the
+                                // beginning of the save area
+    mov     r15 = ar.pfs
+    ;;
+    //
+    //  save preserved general registers & NaT's
+    //
+    st8.spill   [r11] = r4, J_R6-J_R4
+    ;;
+    st8.spill   [r10] = r5, J_R7-J_R5
+    ;;
+    st8.spill   [r11] = r6, J_SP-J_R6
+    ;;
+    st8.spill   [r10] = r7, J_F3-J_R7
+    ;;
+    st8.spill   [r11] = sp, J_F2-J_SP
+    ;;
+    //
+    // save spilled Unat and pfs registers
+    //
+    mov     r2 = ar.unat        // save Unat register after spill
+    ;;
+    st8     [r32] = r2, J_PFS-J_NATS    // save unat for spilled regs
+    ;;
+    st8     [r32] = r15         // save pfs
+    //
+    //  save floating registers
+    //
+    stf.spill   [r11] = f2, J_F4-J_F2
+    stf.spill   [r10] = f3, J_F5-J_F3
+    ;;
+    stf.spill   [r11] = f4, J_F16-J_F4
+    stf.spill   [r10] = f5, J_F17-J_F5
+    ;;
+    stf.spill   [r11] = f16, J_F18-J_F16
+    stf.spill   [r10] = f17, J_F19-J_F17
+    ;;
+    stf.spill   [r11] = f18, J_F20-J_F18
+    stf.spill   [r10] = f19, J_F21-J_F19
+    ;;
+    stf.spill   [r11] = f20, J_F22-J_F20
+    stf.spill   [r10] = f21, J_F23-J_F21
+    ;;
+    stf.spill   [r11] = f22, J_F24-J_F22
+    stf.spill   [r10] = f23, J_F25-J_F23
+    ;;
+    stf.spill   [r11] = f24, J_F26-J_F24
+    stf.spill   [r10] = f25, J_F27-J_F25
+    ;;
+    stf.spill   [r11] = f26, J_F28-J_F26
+    stf.spill   [r10] = f27, J_F29-J_F27
+    ;;
+    stf.spill   [r11] = f28, J_F30-J_F28
+    stf.spill   [r10] = f29, J_F31-J_F29
+    ;;
+    stf.spill   [r11] = f30, J_FPSR-J_F30
+    stf.spill   [r10] = f31, J_B0-J_F31     // size of f31 + fpsr
+    //
+    // save FPSR register & branch registers
+    //
+    mov     r2 = ar.fpsr    // save fpsr register
+    mov     r3 = b0
+    ;;
+    st8     [r11] = r2, J_B1-J_FPSR
+    st8     [r10] = r3, J_B2-J_B0
+    mov     r2 = b1
+    mov     r3 = b2
+    ;;
+    st8     [r11] = r2, J_B3-J_B1
+    st8     [r10] = r3, J_B4-J_B2
+    mov     r2 = b3
+    mov     r3 = b4
+    ;;
+    st8     [r11] = r2, J_B5-J_B3
+    st8     [r10] = r3
+    mov     r2 = b5
+    ;;
+    st8     [r11] = r2
+    ;;
+    //
+    // return
+    //
+    mov     r8 = r0         // return 0 from setjmp
+    mov     ar.unat = r14   // restore unat
+    br.ret.sptk b0
+    .endp setjmp
+
+//
+// void longjmp(struct jmp_buffer *, int val)
+//
+//  Perform a non-local goto.
+//
+// Description:
+//
+//  LongJump initializes the register set to the values saved by a
+//  previous 'SetJump' and jumps to the return location saved by that
+//  'SetJump'.  This has the effect of unwinding the stack and returning
+//  for a second time to the 'SetJump'.
+//
+
+	.align 32
+	.global longjmp
+	.proc longjmp
+longjmp:
+    //
+    //  Make sure buffer is aligned at 16byte boundary
+    //
+    add     r10 = -0x10,r0  ;;  // mask the lower 4 bits
+    and     r32 = r32, r10;;
+    add     r32 = 0x10, r32;;   // move to next 16 byte boundary
+
+    //
+    // caching the return value as we do invala in the end
+    //
+    mov     r8 = r33            // return value
+
+    //
+    //  get immediate context
+    //
+    mov     r14 = ar.rsc        // get user RSC conf
+    add     r10 = J_PFS, r32    // get address of pfs
+    add     r11 = J_NATS, r32
+    ;;
+    ld8     r15 = [r10], J_BSP-J_PFS    // get pfs
+    ld8     r2 = [r11], J_LC-J_NATS     // get unat for spilled regs
+    ;;
+    mov     ar.unat = r2
+    ;;
+    ld8     r16 = [r10], J_PREDS-J_BSP  // get backing store pointer
+    mov     ar.rsc = r0         // put RSE in enforced lazy
+    mov     ar.pfs = r15
+    ;;
+
+    //
+    // while returning from longjmp the BSPSTORE and BSP needs to be
+    // same and discard all the registers allocated after we did
+    // setjmp. Also, we need to generate the RNAT register since we
+    // did not flushed the RSE on setjmp.
+    //
+    mov     r17 = ar.bspstore   // get current BSPSTORE
+    ;;
+    cmp.ltu p6,p7 = r17, r16    // is it less than BSP of
+(p6)    br.spnt.few .flush_rse
+    mov     r19 = ar.rnat       // get current RNAT
+    ;;
+    loadrs                      // invalidate dirty regs
+    br.sptk.many    .restore_rnat       // restore RNAT
+
+.flush_rse:
+    flushrs
+    ;;
+    mov     r19 = ar.rnat       // get current RNAT
+    mov     r17 = r16           // current BSPSTORE
+    ;;
+.restore_rnat:
+    //
+    // check if RNAT is saved between saved BSP and curr BSPSTORE
+    //
+    mov     r18 = 0x3f
+    ;;
+    dep     r18 = r18,r16,3,6   // get RNAT address
+    ;;
+    cmp.ltu p8,p9 = r18, r17    // RNAT saved on RSE
+    ;;
+(p8)    ld8     r19 = [r18]     // get RNAT from RSE
+    ;;
+    mov     ar.bspstore = r16   // set new BSPSTORE
+    ;;
+    mov     ar.rnat = r19       // restore RNAT
+    mov     ar.rsc = r14        // restore RSC conf
+
+
+    ld8     r3 = [r11], J_R4-J_LC       // get lc register
+    ld8     r2 = [r10], J_R5-J_PREDS    // get predicates
+    ;;
+    mov     pr = r2, -1
+    mov     ar.lc = r3
+    //
+    //  restore preserved general registers & NaT's
+    //
+    ld8.fill    r4 = [r11], J_R6-J_R4
+    ;;
+    ld8.fill    r5 = [r10], J_R7-J_R5
+    ld8.fill    r6 = [r11], J_SP-J_R6
+    ;;
+    ld8.fill    r7 = [r10], J_F2-J_R7
+    ld8.fill    sp = [r11], J_F3-J_SP
+    ;;
+    //
+    //  restore floating registers
+    //
+    ldf.fill    f2 = [r10], J_F4-J_F2
+    ldf.fill    f3 = [r11], J_F5-J_F3
+    ;;
+    ldf.fill    f4 = [r10], J_F16-J_F4
+    ldf.fill    f5 = [r11], J_F17-J_F5
+    ;;
+    ldf.fill    f16 = [r10], J_F18-J_F16
+    ldf.fill    f17 = [r11], J_F19-J_F17
+    ;;
+    ldf.fill    f18 = [r10], J_F20-J_F18
+    ldf.fill    f19 = [r11], J_F21-J_F19
+    ;;
+    ldf.fill    f20 = [r10], J_F22-J_F20
+    ldf.fill    f21 = [r11], J_F23-J_F21
+    ;;
+    ldf.fill    f22 = [r10], J_F24-J_F22
+    ldf.fill    f23 = [r11], J_F25-J_F23
+    ;;
+    ldf.fill    f24 = [r10], J_F26-J_F24
+    ldf.fill    f25 = [r11], J_F27-J_F25
+    ;;
+    ldf.fill    f26 = [r10], J_F28-J_F26
+    ldf.fill    f27 = [r11], J_F29-J_F27
+    ;;
+    ldf.fill    f28 = [r10], J_F30-J_F28
+    ldf.fill    f29 = [r11], J_F31-J_F29
+    ;;
+    ldf.fill    f30 = [r10], J_FPSR-J_F30
+    ldf.fill    f31 = [r11], J_B0-J_F31 ;;
+
+    //
+    // restore branch registers and fpsr
+    //
+    ld8     r16 = [r10], J_B1-J_FPSR    // get fpsr
+    ld8     r17 = [r11], J_B2-J_B0      // get return pointer
+    ;;
+    mov     ar.fpsr = r16
+    mov     b0 = r17
+    ld8     r2 = [r10], J_B3-J_B1
+    ld8     r3 = [r11], J_B4-J_B2
+    ;;
+    mov     b1 = r2
+    mov     b2 = r3
+    ld8     r2 = [r10], J_B5-J_B3
+    ld8     r3 = [r11]
+    ;;
+    mov     b3 = r2
+    mov     b4 = r3
+    ld8     r2 = [r10]
+    ld8     r21 = [r32]         // get user unat
+    ;;
+    mov     b5 = r2
+    mov     ar.unat = r21
+
+    //
+    // invalidate ALAT
+    //
+    invala ;;
+
+    br.ret.sptk b0
+    .endp longjmp
diff --git a/usr/klibc/arch/ia64/syscall.S b/usr/klibc/arch/ia64/syscall.S
new file mode 100644
index 0000000..9929618
--- /dev/null
+++ b/usr/klibc/arch/ia64/syscall.S
@@ -0,0 +1,20 @@
+#
+# arch/ia64/syscall.S
+#
+
+#include <asm/unistd.h>
+
+	.text
+	.align	32
+	.proc	__syscall_error
+	.globl	__syscall_error
+__syscall_error:
+	addl	r2 = @ltoffx(errno),gp
+	;;
+	ld8.mov	r3 = [r2],errno
+	;;
+	st4	[r3] = r8
+	mov	r8 = -1
+	br.ret.sptk.many b0
+	.size	__syscall_error, .-__syscall_error
+	.endp	__syscall_error
diff --git a/usr/klibc/arch/ia64/sysstub.ph b/usr/klibc/arch/ia64/sysstub.ph
new file mode 100644
index 0000000..8e686c6
--- /dev/null
+++ b/usr/klibc/arch/ia64/sysstub.ph
@@ -0,0 +1,29 @@
+# -*- perl -*-
+#
+# arch/ia64/sysstub.ph
+#
+# Script to generate system call stubs
+#
+
+sub make_sysstub($$$$$@) {
+    my($outputdir, $fname, $type, $sname, $stype, @args) = @_;
+
+    open(OUT, '>', "${outputdir}/${fname}.S");
+    print OUT "#include <asm/unistd.h>\n";
+    print OUT "\n";
+    print OUT "\t.text\n";
+    print OUT "\t.align 32\n";
+    print OUT "\t.proc ${fname}\n";
+    print OUT "\t.globl ${fname}\n";
+    print OUT "${fname}:\n";
+    print OUT "\tmov\tr15 = __NR_${sname}\n";
+    print OUT "\tbreak __BREAK_SYSCALL\n";
+    print OUT "\tcmp.eq p6,p0 = -1,r10\n";
+    print OUT "(p6)\tbr.few __syscall_error\n";
+    print OUT "\tbr.ret.sptk.many b0\n";
+    print OUT "\t.size\t${fname},.-${fname}\n";
+    print OUT "\t.endp\t${fname}\n";
+    close(OUT);
+}
+
+1;
diff --git a/usr/klibc/arch/ia64/vfork.S b/usr/klibc/arch/ia64/vfork.S
new file mode 100644
index 0000000..1a84902
--- /dev/null
+++ b/usr/klibc/arch/ia64/vfork.S
@@ -0,0 +1,42 @@
+/*
+ * ia64 specific vfork syscall
+ *
+ * Written By:	 Martin Hicks <mort@wildopensource.com>
+ *
+ */
+
+/* This syscall is a special case of the clone syscall */
+#include <asm/unistd.h>
+#include <asm/signal.h>
+#include <klibc/archsys.h>
+
+/* These are redefined here because linux/sched.h isn't safe for
+ * inclusion in asm.
+ */
+#define CLONE_VM    0x00000100 /* set if VM shared between processes */
+#define CLONE_VFORK 0x00004000 /* set if parent wants the child to wake it up on exit */
+
+/* pid_t vfork(void) */
+/* Implemented as clone(CLONE_VFORK | CLONE_VM | SIGCHLD, 0) */
+
+	.align 32
+	.proc vfork
+	.global vfork
+vfork:
+	alloc r2=ar.pfs,0,0,2,0
+	mov	r15=__NR_clone
+	mov	out0=CLONE_VM|CLONE_VFORK|SIGCHLD
+	mov     out1=0
+	;;
+	break 0x100000      // Do the syscall
+	;;
+	addl	r15=0,r1
+	cmp.eq  p7,p6 = -1,r10
+	;;
+	ld8	r14=[r15]
+	;;
+(p7)	st4	[r14]=r8
+	;;
+(p7)	mov	r8=-1
+	br.ret.sptk.many b0
+	.endp vfork

^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [klibc 09/31] m32r support for klibc
  2006-06-28  5:17 [klibc 00/31] klibc as a historyless patchset (updated and reorganized) H. Peter Anvin
                   ` (7 preceding siblings ...)
  2006-06-28  5:17 ` [klibc 08/31] ia64 " H. Peter Anvin
@ 2006-06-28  5:17 ` H. Peter Anvin
  2006-06-28  5:17 ` [klibc 10/31] m68k " H. Peter Anvin
                   ` (21 subsequent siblings)
  30 siblings, 0 replies; 58+ messages in thread
From: H. Peter Anvin @ 2006-06-28  5:17 UTC (permalink / raw)
  To: linux-kernel, klibc; +Cc: H. Peter Anvin

The parts of klibc specific to the m32r architecture.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>

---
commit b8481500fe4d3475857c7f8da022d6ac640b9420
tree a66da10e8168b9c82b0306657ecffd03154f14c5
parent 2ddc0b5cb0056f213e6e279030e50c1bd223cef6
author H. Peter Anvin <hpa@zytor.com> Tue, 27 Jun 2006 20:50:39 -0700
committer H. Peter Anvin <hpa@zytor.com> Tue, 27 Jun 2006 20:50:39 -0700

 usr/include/arch/m32r/klibc/archconfig.h |   14 +++++++++
 usr/include/arch/m32r/klibc/archsetjmp.h |   21 +++++++++++++
 usr/include/arch/m32r/klibc/archsignal.h |   14 +++++++++
 usr/include/arch/m32r/klibc/archstat.h   |   39 +++++++++++++++++++++++++
 usr/klibc/arch/m32r/MCONFIG              |   18 +++++++++++
 usr/klibc/arch/m32r/Makefile.inc         |   19 ++++++++++++
 usr/klibc/arch/m32r/crt0.S               |   24 +++++++++++++++
 usr/klibc/arch/m32r/setjmp.S             |   47 ++++++++++++++++++++++++++++++
 usr/klibc/arch/m32r/syscall.S            |   29 +++++++++++++++++++
 usr/klibc/arch/m32r/sysstub.ph           |   25 ++++++++++++++++
 10 files changed, 250 insertions(+), 0 deletions(-)

diff --git a/usr/include/arch/m32r/klibc/archconfig.h b/usr/include/arch/m32r/klibc/archconfig.h
new file mode 100644
index 0000000..9489877
--- /dev/null
+++ b/usr/include/arch/m32r/klibc/archconfig.h
@@ -0,0 +1,14 @@
+/*
+ * include/arch/m32r/klibc/archconfig.h
+ *
+ * See include/klibc/sysconfig.h for the options that can be set in
+ * this file.
+ *
+ */
+
+#ifndef _KLIBC_ARCHCONFIG_H
+#define _KLIBC_ARCHCONFIG_H
+
+/* All defaults */
+
+#endif				/* _KLIBC_ARCHCONFIG_H */
diff --git a/usr/include/arch/m32r/klibc/archsetjmp.h b/usr/include/arch/m32r/klibc/archsetjmp.h
new file mode 100644
index 0000000..d82df9c
--- /dev/null
+++ b/usr/include/arch/m32r/klibc/archsetjmp.h
@@ -0,0 +1,21 @@
+/*
+ * arch/m32r/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;
+};
+
+typedef struct __jmp_buf jmp_buf[1];
+
+#endif				/* _KLIBC_ARCHSETJMP_H */
diff --git a/usr/include/arch/m32r/klibc/archsignal.h b/usr/include/arch/m32r/klibc/archsignal.h
new file mode 100644
index 0000000..b753026
--- /dev/null
+++ b/usr/include/arch/m32r/klibc/archsignal.h
@@ -0,0 +1,14 @@
+/*
+ * arch/m32r/include/klibc/archsignal.h
+ *
+ * Architecture-specific signal definitions
+ *
+ */
+
+#ifndef _KLIBC_ARCHSIGNAL_H
+#define _KLIBC_ARCHSIGNAL_H
+
+#include <asm/signal.h>
+/* No special stuff for this architecture */
+
+#endif
diff --git a/usr/include/arch/m32r/klibc/archstat.h b/usr/include/arch/m32r/klibc/archstat.h
new file mode 100644
index 0000000..09d3ade
--- /dev/null
+++ b/usr/include/arch/m32r/klibc/archstat.h
@@ -0,0 +1,39 @@
+#ifndef _KLIBC_ARCHSTAT_H
+#define _KLIBC_ARCHSTAT_H
+
+#include <klibc/stathelp.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 {
+	__stdev64	(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;
+
+	__stdev64	(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/usr/klibc/arch/m32r/MCONFIG b/usr/klibc/arch/m32r/MCONFIG
new file mode 100644
index 0000000..2f9db0b
--- /dev/null
+++ b/usr/klibc/arch/m32r/MCONFIG
@@ -0,0 +1,18 @@
+# -*- makefile -*-
+#
+# arch/m32r/MCONFIG
+#
+# Special rules for this architecture.  Note that this is actually
+# included from the main Makefile, and that pathnames should be
+# accordingly.
+#
+
+KLIBCOPTFLAGS = -Os
+KLIBCBITSIZE  = 32
+
+# Extra linkflags when building the shared version of the library
+# This address needs to be reachable using normal inter-module
+# calls, and work on the memory models for this architecture
+# 224 MB - normal binaries start at 0 (?)
+# (lib?)gcc on cris seems to insist on producing .init and .fini sections
+KLIBCSHAREDFLAGS     = --section-start .init=0x0e000100
diff --git a/usr/klibc/arch/m32r/Makefile.inc b/usr/klibc/arch/m32r/Makefile.inc
new file mode 100644
index 0000000..794aec6
--- /dev/null
+++ b/usr/klibc/arch/m32r/Makefile.inc
@@ -0,0 +1,19 @@
+# -*- makefile -*-
+#
+# arch/m32r/Makefile.inc
+#
+# Special rules for this architecture.  Note that this is actually
+# included from the main Makefile, and that pathnames should be
+# accordingly.
+#
+
+KLIBCARCHOBJS = \
+	arch/$(KLIBCARCH)/setjmp.o \
+	arch/$(KLIBCARCH)/syscall.o \
+	libgcc/__divdi3.o \
+	libgcc/__moddi3.o \
+	libgcc/__udivdi3.o \
+	libgcc/__umoddi3.o \
+	libgcc/__udivmoddi4.o
+
+archclean:
diff --git a/usr/klibc/arch/m32r/crt0.S b/usr/klibc/arch/m32r/crt0.S
new file mode 100644
index 0000000..568e5d8
--- /dev/null
+++ b/usr/klibc/arch/m32r/crt0.S
@@ -0,0 +1,24 @@
+#
+# arch/m32r/crt0.S
+#
+# Does arch-specific initialization and invokes __libc_init
+# with the appropriate arguments.
+#
+# See __static_init.c or __shared_init.c for the expected
+# arguments.
+#
+
+	.text
+	.balign 4
+	.type	_start,@function
+	.globl	_start
+_start:
+	/* Save the address of the ELF argument array */
+	mv	r0, sp
+
+	/* atexit() function (assume null) */
+	xor	r1, r1
+
+	bl	__libc_init
+
+	.size _start, .-_start
diff --git a/usr/klibc/arch/m32r/setjmp.S b/usr/klibc/arch/m32r/setjmp.S
new file mode 100644
index 0000000..02a25e7
--- /dev/null
+++ b/usr/klibc/arch/m32r/setjmp.S
@@ -0,0 +1,47 @@
+#
+# arch/m32r/setjmp.S
+#
+# setjmp/longjmp for the M32R architecture
+#
+
+#
+# The jmp_buf is assumed to contain the following, in order:
+#	r8-r15
+#
+#	Note that r14 is the return address register and
+#	r15 is the stack pointer.
+#
+
+	.text
+	.balign 4
+	.globl	setjmp
+	.type	setjmp, @function
+setjmp:
+	st	r8, @r0
+	st	r9, @+r0
+	st	r10, @+r0
+	st	r11, @+r0
+	st	r12, @+r0
+	st	r13, @+r0
+	st	r14, @+r0
+	st	r15, @+r0
+	xor	r0, r0
+	jmp	r14
+	.size	setjmp,.-setjmp
+
+	.text
+	.balign 4
+	.globl	longjmp
+	.type	longjmp, @function
+longjmp:
+	ld	r8, @r0+
+	ld	r9, @r0+
+	ld	r10, @r0+
+	ld	r11, @r0+
+	ld	r12, @r0+
+	ld	r13, @r0+
+	ld	r14, @r0+
+	ld	r15, @r0
+	mv	r0, r1
+	jmp	r14
+	.size longjmp,.-longjmp
diff --git a/usr/klibc/arch/m32r/syscall.S b/usr/klibc/arch/m32r/syscall.S
new file mode 100644
index 0000000..a20a336
--- /dev/null
+++ b/usr/klibc/arch/m32r/syscall.S
@@ -0,0 +1,29 @@
+/*
+ * arch/m32r/syscall.S
+ *
+ *     r7 contains the syscall number (set by stub);
+ * r0..r3 contains arguments 0-3 per standard calling convention;
+ * r4..r5 contains arguments 4-5, but we have to get those from
+ *        the stack.
+ */
+
+	.section ".text","ax"
+	.balign	4
+	.globl	__syscall_common
+	.type	__syscall_common,@function
+__syscall_common:
+	ld	r4,@sp
+	ld	r5,@(4,sp)
+	trap	#2
+	cmpi	r0, #-4096
+	bnc	1f
+	jmp	r14
+1:
+	seth	r2,#high(errno)
+	or3	r2,r2,#low(errno)
+	neg	r1,r0
+	st	r1,@r7
+	ldi	r0,#-1
+	jmp	r14
+
+	.size	__syscall_common,.-__syscall_common
diff --git a/usr/klibc/arch/m32r/sysstub.ph b/usr/klibc/arch/m32r/sysstub.ph
new file mode 100644
index 0000000..98dfb9d
--- /dev/null
+++ b/usr/klibc/arch/m32r/sysstub.ph
@@ -0,0 +1,25 @@
+# -*- perl -*-
+#
+# arch/m32r/sysstub.ph
+#
+# Script to generate system call stubs
+#
+
+sub make_sysstub($$$$$@) {
+    my($outputdir, $fname, $type, $sname, $stype, @args) = @_;
+
+    open(OUT, '>', "${outputdir}/${fname}.S");
+    print OUT "#include <asm/unistd.h>\n";
+    print OUT "\n";
+    print OUT "\t.text\n";
+    print OUT "\t.type\t${fname},\@function\n";
+    print OUT "\t.globl\t${fname}\n";
+    print OUT "\t.balign\t4\n";
+    print OUT "${fname}:\n";
+    print OUT "\tldi\tr7,#__NR_${sname}\n";
+    print OUT "\tbra\t__syscall_common\n";
+    print OUT "\t.size ${fname},.-${fname}\n";
+    close(OUT);
+}
+
+1;

^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [klibc 10/31] m68k support for klibc
  2006-06-28  5:17 [klibc 00/31] klibc as a historyless patchset (updated and reorganized) H. Peter Anvin
                   ` (8 preceding siblings ...)
  2006-06-28  5:17 ` [klibc 09/31] m32r " H. Peter Anvin
@ 2006-06-28  5:17 ` H. Peter Anvin
  2006-06-28  5:17 ` [klibc 11/31] mips " H. Peter Anvin
                   ` (20 subsequent siblings)
  30 siblings, 0 replies; 58+ messages in thread
From: H. Peter Anvin @ 2006-06-28  5:17 UTC (permalink / raw)
  To: linux-kernel, klibc; +Cc: H. Peter Anvin

The parts of klibc specific to the m68k architecture.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>

---
commit 5d5bb97039eb8b54f57108cdcde55e4cb4bd5227
tree 23750d414b01bbf986e327313fb7c19f7da54a6e
parent b8481500fe4d3475857c7f8da022d6ac640b9420
author H. Peter Anvin <hpa@zytor.com> Tue, 27 Jun 2006 20:50:42 -0700
committer H. Peter Anvin <hpa@zytor.com> Tue, 27 Jun 2006 20:50:42 -0700

 usr/include/arch/m68k/klibc/archconfig.h |   15 ++++++++++
 usr/include/arch/m68k/klibc/archsetjmp.h |   26 ++++++++++++++++++
 usr/include/arch/m68k/klibc/archsignal.h |   14 ++++++++++
 usr/include/arch/m68k/klibc/archstat.h   |   38 +++++++++++++++++++++++++++
 usr/klibc/arch/m68k/MCONFIG              |   11 ++++++++
 usr/klibc/arch/m68k/Makefile.inc         |   25 +++++++++++++++++
 usr/klibc/arch/m68k/crt0.S               |   27 +++++++++++++++++++
 usr/klibc/arch/m68k/setjmp.S             |   43 ++++++++++++++++++++++++++++++
 usr/klibc/arch/m68k/syscall.S            |   27 +++++++++++++++++++
 usr/klibc/arch/m68k/sysstub.ph           |   26 ++++++++++++++++++
 usr/klibc/arch/m68k/vfork.S              |   28 ++++++++++++++++++++
 11 files changed, 280 insertions(+), 0 deletions(-)

diff --git a/usr/include/arch/m68k/klibc/archconfig.h b/usr/include/arch/m68k/klibc/archconfig.h
new file mode 100644
index 0000000..10ef62e
--- /dev/null
+++ b/usr/include/arch/m68k/klibc/archconfig.h
@@ -0,0 +1,15 @@
+/*
+ * include/arch/m68k/klibc/archconfig.h
+ *
+ * See include/klibc/sysconfig.h for the options that can be set in
+ * this file.
+ *
+ */
+
+#ifndef _KLIBC_ARCHCONFIG_H
+#define _KLIBC_ARCHCONFIG_H
+
+/* On m68k, sys_mmap2 uses the current page size as the shift factor */
+#define _KLIBC_MMAP2_SHIFT	__getpageshift()
+
+#endif				/* _KLIBC_ARCHCONFIG_H */
diff --git a/usr/include/arch/m68k/klibc/archsetjmp.h b/usr/include/arch/m68k/klibc/archsetjmp.h
new file mode 100644
index 0000000..e85c810
--- /dev/null
+++ b/usr/include/arch/m68k/klibc/archsetjmp.h
@@ -0,0 +1,26 @@
+/*
+ * usr/include/arch/m68k/klibc/archsetjmp.h
+ */
+
+#ifndef _KLIBC_ARCHSETJMP_H
+#define _KLIBC_ARCHSETJMP_H
+
+struct __jmp_buf {
+	unsigned int __d2;
+	unsigned int __d3;
+	unsigned int __d4;
+	unsigned int __d5;
+	unsigned int __d6;
+	unsigned int __d7;
+	unsigned int __a2;
+	unsigned int __a3;
+	unsigned int __a4;
+	unsigned int __a5;
+	unsigned int __fp;	/* a6 */
+	unsigned int __sp;	/* a7 */
+	unsigned int __retaddr;
+};
+
+typedef struct __jmp_buf jmp_buf[1];
+
+#endif				/* _KLBIC_ARCHSETJMP_H */
diff --git a/usr/include/arch/m68k/klibc/archsignal.h b/usr/include/arch/m68k/klibc/archsignal.h
new file mode 100644
index 0000000..bf7912a
--- /dev/null
+++ b/usr/include/arch/m68k/klibc/archsignal.h
@@ -0,0 +1,14 @@
+/*
+ * arch/m68k/include/klibc/archsignal.h
+ *
+ * Architecture-specific signal definitions
+ *
+ */
+
+#ifndef _KLIBC_ARCHSIGNAL_H
+#define _KLIBC_ARCHSIGNAL_H
+
+#include <asm/signal.h>
+/* No special stuff for this architecture */
+
+#endif
diff --git a/usr/include/arch/m68k/klibc/archstat.h b/usr/include/arch/m68k/klibc/archstat.h
new file mode 100644
index 0000000..dce25f9
--- /dev/null
+++ b/usr/include/arch/m68k/klibc/archstat.h
@@ -0,0 +1,38 @@
+#ifndef _KLIBC_ARCHSTAT_H
+#define _KLIBC_ARCHSTAT_H
+
+#include <klibc/stathelp.h>
+
+#define _STATBUF_ST_NSEC
+
+/* This matches struct stat64 in glibc2.1, hence the absolutely
+ * insane padding around dev_t's.
+ */
+struct stat {
+	__stdev64	(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;
+
+	__stdev64	(st_rdev);
+	unsigned char	__pad3[2];
+
+	long long	st_size;
+	unsigned long	st_blksize;
+
+	unsigned long 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/usr/klibc/arch/m68k/MCONFIG b/usr/klibc/arch/m68k/MCONFIG
new file mode 100644
index 0000000..4360408
--- /dev/null
+++ b/usr/klibc/arch/m68k/MCONFIG
@@ -0,0 +1,11 @@
+# -*- makefile -*-
+#
+# arch/m68k/MCONFIG
+#
+# Special rules for this architecture.  Note that this is actually
+# included from the main Makefile, and that pathnames should be
+# accordingly.
+#
+
+KLIBCOPTFLAGS = -Os -fomit-frame-pointer
+KLIBCBITSIZE  = 32
diff --git a/usr/klibc/arch/m68k/Makefile.inc b/usr/klibc/arch/m68k/Makefile.inc
new file mode 100644
index 0000000..a6f9827
--- /dev/null
+++ b/usr/klibc/arch/m68k/Makefile.inc
@@ -0,0 +1,25 @@
+# -*- makefile -*-
+#
+# arch/m68k/Makefile.inc
+#
+# Special rules for this architecture.  Note that this is actually
+# included from the main Makefile, and that pathnames should be
+# accordingly.
+#
+
+KLIBCARCHOBJS = \
+	arch/$(KLIBCARCH)/setjmp.o \
+	arch/$(KLIBCARCH)/syscall.o \
+	arch/$(KLIBCARCH)/vfork.o
+
+KLIBCBITSIZE  = 32
+
+# Extra linkflags when building the shared version of the library
+# This address needs to be reachable using normal inter-module
+# calls, and work on the memory models for this architecture
+# 2816 MB - normal binaries start at 2048 MB if I read the link
+# script right.  Not sure if there is a fundamental reason
+# to not duck below the halfway point...
+KLIBCSHAREDFLAGS        = -Ttext 0xb0000000
+
+archclean:
diff --git a/usr/klibc/arch/m68k/crt0.S b/usr/klibc/arch/m68k/crt0.S
new file mode 100644
index 0000000..fbf6f13
--- /dev/null
+++ b/usr/klibc/arch/m68k/crt0.S
@@ -0,0 +1,27 @@
+#
+# arch/m68k/crt0.S
+#
+# Does arch-specific initialization and invokes __libc_init
+# with the appropriate arguments.
+#
+# See __static_init.c or __shared_init.c for the expected
+# arguments.
+#
+
+	.text
+	.align 4
+	.type _start,@function
+	.globl _start
+_start:
+	# Zero out the frame pointer to be nice to the debugger
+	movea.l	#0,%a6
+	# Save the address of the ELF argument array
+	move.l	%a7, %d0
+	# Push a zero on the stack in lieu of atexit pointer
+	clr.l	-(%sp)
+	# Push ELF argument pointer on the stack
+	move.l	%d0, -(%a7)
+
+	jbsr	__libc_init
+
+	.size _start, .-_start
diff --git a/usr/klibc/arch/m68k/setjmp.S b/usr/klibc/arch/m68k/setjmp.S
new file mode 100644
index 0000000..1b3591e
--- /dev/null
+++ b/usr/klibc/arch/m68k/setjmp.S
@@ -0,0 +1,43 @@
+#
+# arch/m68k/setjmp.S
+#
+# setjmp/longjmp for the m68k architecture
+#
+
+#
+# The jmp_buf is assumed to contain the following, in order:
+#	%d2..%d7
+#	%a2..%a7
+#	return address
+#
+
+	.text
+	.align 2
+	.globl setjmp
+	.type setjmp, @function
+setjmp:
+	move.l	(%sp)+, %d0		| Return address
+	movea.l	(%sp), %a0		| Buffer address
+	| Postincrement mode is not permitted here...
+	movem.l	%d2-%d7/%a2-%a7, (%a0)
+	move.l	%d0, 48(%a0)		| Return address
+	move.l	%d0, -(%sp)		| Restore return address
+	clr.l	%d0			| Return value
+	movea.l	%d0, %a0		| Redundant return...
+	rts
+
+	.size setjmp,.-setjmp
+
+	.text
+	.align 2
+	.globl longjmp
+	.type longjmp, @function
+longjmp:
+	move.l	4(%sp), %a0		| Buffer address
+	move.l	8(%sp), %d0		| Return value
+	movem.l	(%a0)+, %d2-%d7/%a2-%a7
+	movea.l	(%a0), %a1
+	movea.l	%d0, %a0		| Redundant return...
+	jmp.l	(%a1)
+
+	.size longjmp,.-longjmp
diff --git a/usr/klibc/arch/m68k/syscall.S b/usr/klibc/arch/m68k/syscall.S
new file mode 100644
index 0000000..966c92d
--- /dev/null
+++ b/usr/klibc/arch/m68k/syscall.S
@@ -0,0 +1,27 @@
+/*
+ * arch/m68k/syscall.S
+ *
+ * Common tail-handling code for system calls.
+ *
+ * The arguments are on the stack; the system call number in %d0.
+ */
+
+	.text
+	.align	2
+	.globl	__syscall_common
+	.type	__syscall_common, @function
+__syscall_common:
+	movem.l %d2-%d6, -(%sp)	/* 5 registers saved */
+	movem.l	24(%sp), %d1-%d6
+	trap	#0
+	cmpi.l	#-4095, %d0
+	blt.l	1f
+	neg.l	%d0
+	move.l	%d0, (errno)
+	moveq	#-1, %d0
+1:
+	movea.l	%d0, %a0	/* Redundant return */
+	movem.l (%sp)+, %d2-%d6 /* Restore registers */
+	rts
+
+	.size	__syscall_common,.-__syscall_common
diff --git a/usr/klibc/arch/m68k/sysstub.ph b/usr/klibc/arch/m68k/sysstub.ph
new file mode 100644
index 0000000..78c239d
--- /dev/null
+++ b/usr/klibc/arch/m68k/sysstub.ph
@@ -0,0 +1,26 @@
+# -*- perl -*-
+#
+# arch/m68k/sysstub.ph
+#
+# Script to generate system call stubs
+#
+
+sub make_sysstub($$$$$@) {
+    my($outputdir, $fname, $type, $sname, $stype, @args) = @_;
+
+    open(OUT, '>', "${outputdir}/${fname}.S");
+    print OUT "#include <asm/unistd.h>\n";
+    print OUT "\n";
+    print OUT "\t.type ${fname},\@function\n";
+    print OUT "\t.globl ${fname}\n";
+    print OUT "${fname}:\n";
+
+    $stype = 'common' if ( $stype eq '' );
+
+    print OUT "\tmove.l\t# __NR_${sname}, %d0\n";
+    print OUT "\tbr\t__syscall_$stype\n";
+    print OUT "\t.size ${fname},.-${fname}\n";
+    close(OUT);
+}
+
+1;
diff --git a/usr/klibc/arch/m68k/vfork.S b/usr/klibc/arch/m68k/vfork.S
new file mode 100644
index 0000000..a3a7e44
--- /dev/null
+++ b/usr/klibc/arch/m68k/vfork.S
@@ -0,0 +1,28 @@
+#
+# usr/klibc/arch/m68k/vfork.S
+#
+# vfork is nasty - there must be nothing at all on the stack above
+# the stack frame of the enclosing function.
+#
+
+#include <asm/unistd.h>
+
+	.text
+	.align	2
+	.globl	vfork
+	.type	vfork, @function
+vfork:
+	move.l	(%sp)+, %d1		/* Return address */
+	move.l	# __NR_vfork, %d0
+	trap	#0
+	move.l	%d1, -(%sp)
+	cmpi.l	#-4095, %d0
+	blt.l	1f
+	neg.l	%d0
+	move.l	%d0, (errno)
+	moveq	#-1, %d0
+1:
+	movea.l	%d0, %a0
+	rts
+
+	.size	vfork, .-vfork

^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [klibc 11/31] mips support for klibc
  2006-06-28  5:17 [klibc 00/31] klibc as a historyless patchset (updated and reorganized) H. Peter Anvin
                   ` (9 preceding siblings ...)
  2006-06-28  5:17 ` [klibc 10/31] m68k " H. Peter Anvin
@ 2006-06-28  5:17 ` H. Peter Anvin
  2006-06-28  5:17 ` [klibc 12/31] mips64 " H. Peter Anvin
                   ` (19 subsequent siblings)
  30 siblings, 0 replies; 58+ messages in thread
From: H. Peter Anvin @ 2006-06-28  5:17 UTC (permalink / raw)
  To: linux-kernel, klibc; +Cc: H. Peter Anvin

The parts of klibc specific to the mips architecture.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>

---
commit de9abe3c88abea63b10e8935cff79211c5983c9e
tree 945cf16f33897d86e9230406cd4af6d312f57b61
parent 5d5bb97039eb8b54f57108cdcde55e4cb4bd5227
author H. Peter Anvin <hpa@zytor.com> Tue, 27 Jun 2006 20:50:43 -0700
committer H. Peter Anvin <hpa@zytor.com> Tue, 27 Jun 2006 20:50:43 -0700

 usr/include/arch/mips/klibc/archconfig.h |   15 ++
 usr/include/arch/mips/klibc/archfcntl.h  |   86 ++++++++++++
 usr/include/arch/mips/klibc/archsetjmp.h |   39 +++++
 usr/include/arch/mips/klibc/archsignal.h |   14 ++
 usr/include/arch/mips/klibc/archstat.h   |   40 ++++++
 usr/include/arch/mips/machine/asm.h      |   11 ++
 usr/include/arch/mips/sgidefs.h          |   20 +++
 usr/include/arch/mips/spaces.h           |    1 
 usr/klibc/arch/mips/MCONFIG              |   15 ++
 usr/klibc/arch/mips/Makefile.inc         |   29 ++++
 usr/klibc/arch/mips/crt0.S               |   25 ++++
 usr/klibc/arch/mips/klibc.ld             |  214 ++++++++++++++++++++++++++++++
 usr/klibc/arch/mips/pipe.S               |   16 ++
 usr/klibc/arch/mips/setjmp.S             |   80 +++++++++++
 usr/klibc/arch/mips/syscall.S            |   16 ++
 usr/klibc/arch/mips/sysstub.ph           |   30 ++++
 usr/klibc/arch/mips/vfork.S              |   16 ++
 17 files changed, 667 insertions(+), 0 deletions(-)

diff --git a/usr/include/arch/mips/klibc/archconfig.h b/usr/include/arch/mips/klibc/archconfig.h
new file mode 100644
index 0000000..d9528b8
--- /dev/null
+++ b/usr/include/arch/mips/klibc/archconfig.h
@@ -0,0 +1,15 @@
+/*
+ * include/arch/mips/klibc/archconfig.h
+ *
+ * See include/klibc/sysconfig.h for the options that can be set in
+ * this file.
+ *
+ */
+
+#ifndef _KLIBC_ARCHCONFIG_H
+#define _KLIBC_ARCHCONFIG_H
+
+/* MIPS has architecture-specific code for vfork() */
+#define _KLIBC_REAL_VFORK 1
+
+#endif				/* _KLIBC_ARCHCONFIG_H */
diff --git a/usr/include/arch/mips/klibc/archfcntl.h b/usr/include/arch/mips/klibc/archfcntl.h
new file mode 100644
index 0000000..1f61822
--- /dev/null
+++ b/usr/include/arch/mips/klibc/archfcntl.h
@@ -0,0 +1,86 @@
+/*
+ * 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/usr/include/arch/mips/klibc/archsetjmp.h b/usr/include/arch/mips/klibc/archsetjmp.h
new file mode 100644
index 0000000..1fbe83e
--- /dev/null
+++ b/usr/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/usr/include/arch/mips/klibc/archsignal.h b/usr/include/arch/mips/klibc/archsignal.h
new file mode 100644
index 0000000..b9ca756
--- /dev/null
+++ b/usr/include/arch/mips/klibc/archsignal.h
@@ -0,0 +1,14 @@
+/*
+ * arch/mips/include/klibc/archsignal.h
+ *
+ * Architecture-specific signal definitions
+ *
+ */
+
+#ifndef _KLIBC_ARCHSIGNAL_H
+#define _KLIBC_ARCHSIGNAL_H
+
+#include <asm/signal.h>
+/* No special stuff for this architecture */
+
+#endif
diff --git a/usr/include/arch/mips/klibc/archstat.h b/usr/include/arch/mips/klibc/archstat.h
new file mode 100644
index 0000000..c1d60d9
--- /dev/null
+++ b/usr/include/arch/mips/klibc/archstat.h
@@ -0,0 +1,40 @@
+#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, which makes this one of the sanest
+ * 32-bit struct stats.
+ */
+
+struct stat {
+	unsigned int	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 int	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/usr/include/arch/mips/machine/asm.h b/usr/include/arch/mips/machine/asm.h
new file mode 100644
index 0000000..f524bc6
--- /dev/null
+++ b/usr/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/usr/include/arch/mips/sgidefs.h b/usr/include/arch/mips/sgidefs.h
new file mode 100644
index 0000000..fba8ae8
--- /dev/null
+++ b/usr/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/usr/include/arch/mips/spaces.h b/usr/include/arch/mips/spaces.h
new file mode 100644
index 0000000..b5f530b
--- /dev/null
+++ b/usr/include/arch/mips/spaces.h
@@ -0,0 +1 @@
+/* Included by <asm/page.h> but not actually needed */
diff --git a/usr/klibc/arch/mips/MCONFIG b/usr/klibc/arch/mips/MCONFIG
new file mode 100644
index 0000000..fd70500
--- /dev/null
+++ b/usr/klibc/arch/mips/MCONFIG
@@ -0,0 +1,15 @@
+# -*- makefile -*-
+#
+# arch/mips/MCONFIG
+#
+# Special rules for this architecture.  Note that this is actually
+# included from the main Makefile, and that pathnames should be
+# accordingly.
+#
+
+KLIBCARCHREQFLAGS = -fno-pic -mno-abicalls -G 0
+KLIBCOPTFLAGS     = -Os
+KLIBCBITSIZE      = 32
+
+# Extra linkflags when building the shared version of the library
+KLIBCSHAREDFLAGS	= -T $(src)/arch/$(KLIBCARCH)/klibc.ld
diff --git a/usr/klibc/arch/mips/Makefile.inc b/usr/klibc/arch/mips/Makefile.inc
new file mode 100644
index 0000000..adbfc38
--- /dev/null
+++ b/usr/klibc/arch/mips/Makefile.inc
@@ -0,0 +1,29 @@
+# -*- makefile -*-
+#
+# arch/mips/Makefile.inc
+#
+# Special rules for this architecture.  Note that this is actually
+# included from the main Makefile, and that pathnames should be
+# accordingly.
+#
+
+KLIBCARCHOBJS = \
+	arch/$(KLIBCARCH)/pipe.o \
+	arch/$(KLIBCARCH)/vfork.o \
+	arch/$(KLIBCARCH)/setjmp.o \
+	arch/$(KLIBCARCH)/syscall.o \
+	libgcc/__clzsi2.o \
+	libgcc/__ashldi3.o \
+	libgcc/__ashrdi3.o \
+	libgcc/__lshrdi3.o \
+	libgcc/__divdi3.o \
+        libgcc/__moddi3.o \
+        libgcc/__udivdi3.o \
+	libgcc/__umoddi3.o \
+        libgcc/__udivmoddi4.o
+
+
+KLIBCARCHSOOBJS = $(patsubst %.o,%.lo,$(KLIBCARCHOBJS))
+
+
+archclean:
diff --git a/usr/klibc/arch/mips/crt0.S b/usr/klibc/arch/mips/crt0.S
new file mode 100644
index 0000000..142d9f2
--- /dev/null
+++ b/usr/klibc/arch/mips/crt0.S
@@ -0,0 +1,25 @@
+#
+# arch/mips/crt0.S
+#
+# Does arch-specific initialization and invokes __libc_init
+# with the appropriate arguments.
+#
+# See __static_init.c or __shared_init.c for the expected
+# arguments.
+#
+
+#include <machine/asm.h>
+
+NESTED(__start, 32, sp)
+	subu	sp, 32
+	sw	zero, 16(sp)
+
+	lui	gp, %hi(_gp)		# Initialize gp
+	addiu	gp, gp, _gp
+
+	addiu	a0, sp, 32		# Pointer to ELF entry structure
+	move	a1, v0			# Kernel-provided atexit() pointer
+
+	jal	__libc_init
+
+	END(__start)
diff --git a/usr/klibc/arch/mips/klibc.ld b/usr/klibc/arch/mips/klibc.ld
new file mode 100644
index 0000000..5a2a7a6
--- /dev/null
+++ b/usr/klibc/arch/mips/klibc.ld
@@ -0,0 +1,214 @@
+/* Linker script for klibc.so, needed because of the the damned
+   GNU ld script headers problem */
+
+ENTRY(__start)
+SECTIONS
+{
+  /* Read-only sections, merged into text segment: */
+  /* This address needs to be reachable using normal inter-module
+      calls, and work on the memory models for this architecture */
+  /* 2 MB -- the normal starting point for text is 4 MB */
+  . = 0x00200400;
+  .interp         : { *(.interp) }
+  .reginfo        : { *(.reginfo) }
+  .dynamic        : { *(.dynamic) }
+  .hash           : { *(.hash) }
+  .dynsym         : { *(.dynsym) }
+  .dynstr         : { *(.dynstr) }
+  .gnu.version    : { *(.gnu.version) }
+  .gnu.version_d  : { *(.gnu.version_d) }
+  .gnu.version_r  : { *(.gnu.version_r) }
+  .rel.dyn        :
+    {
+      *(.rel.init)
+      *(.rel.text .rel.text.* .rel.gnu.linkonce.t.*)
+      *(.rel.fini)
+      *(.rel.rodata .rel.rodata.* .rel.gnu.linkonce.r.*)
+      *(.rel.data .rel.data.* .rel.gnu.linkonce.d.*)
+      *(.rel.tdata .rel.tdata.* .rel.gnu.linkonce.td.*)
+      *(.rel.tbss .rel.tbss.* .rel.gnu.linkonce.tb.*)
+      *(.rel.ctors)
+      *(.rel.dtors)
+      *(.rel.got)
+      *(.rel.sdata .rel.sdata.* .rel.gnu.linkonce.s.*)
+      *(.rel.sbss .rel.sbss.* .rel.gnu.linkonce.sb.*)
+      *(.rel.sdata2 .rel.sdata2.* .rel.gnu.linkonce.s2.*)
+      *(.rel.sbss2 .rel.sbss2.* .rel.gnu.linkonce.sb2.*)
+      *(.rel.bss .rel.bss.* .rel.gnu.linkonce.b.*)
+    }
+  .rela.dyn       :
+    {
+      *(.rela.init)
+      *(.rela.text .rela.text.* .rela.gnu.linkonce.t.*)
+      *(.rela.fini)
+      *(.rela.rodata .rela.rodata.* .rela.gnu.linkonce.r.*)
+      *(.rela.data .rela.data.* .rela.gnu.linkonce.d.*)
+      *(.rela.tdata .rela.tdata.* .rela.gnu.linkonce.td.*)
+      *(.rela.tbss .rela.tbss.* .rela.gnu.linkonce.tb.*)
+      *(.rela.ctors)
+      *(.rela.dtors)
+      *(.rela.got)
+      *(.rela.sdata .rela.sdata.* .rela.gnu.linkonce.s.*)
+      *(.rela.sbss .rela.sbss.* .rela.gnu.linkonce.sb.*)
+      *(.rela.sdata2 .rela.sdata2.* .rela.gnu.linkonce.s2.*)
+      *(.rela.sbss2 .rela.sbss2.* .rela.gnu.linkonce.sb2.*)
+      *(.rela.bss .rela.bss.* .rela.gnu.linkonce.b.*)
+    }
+  .rel.plt        : { *(.rel.plt) }
+  .rela.plt       : { *(.rela.plt) }
+  .init           :
+  {
+    KEEP (*(.init))
+  } =0
+  .plt            : { *(.plt) }
+  .text           :
+  {
+    _ftext = . ;
+    *(.text .stub .text.* .gnu.linkonce.t.*)
+    /* .gnu.warning sections are handled specially by elf32.em.  */
+    *(.gnu.warning)
+    *(.mips16.fn.*) *(.mips16.call.*)
+  } =0
+  .fini           :
+  {
+    KEEP (*(.fini))
+  } =0
+  PROVIDE (__etext = .);
+  PROVIDE (_etext = .);
+  PROVIDE (etext = .);
+  .rodata         : { *(.rodata .rodata.* .gnu.linkonce.r.*) }
+  .rodata1        : { *(.rodata1) }
+  .sdata2         : { *(.sdata2 .sdata2.* .gnu.linkonce.s2.*) }
+  .sbss2          : { *(.sbss2 .sbss2.* .gnu.linkonce.sb2.*) }
+  .eh_frame_hdr : { *(.eh_frame_hdr) }
+  /* Adjust the address for the data segment.  We want to adjust up to
+     the same address within the page on the next page up.  */
+  . = ALIGN(8192);
+  /* Ensure the __preinit_array_start label is properly aligned.  We
+     could instead move the label definition inside the section, but
+     the linker would then create the section even if it turns out to
+     be empty, which isn't pretty.  */
+  . = ALIGN(32 / 8);
+  PROVIDE (__preinit_array_start = .);
+  .preinit_array     : { *(.preinit_array) }
+  PROVIDE (__preinit_array_end = .);
+  PROVIDE (__init_array_start = .);
+  .init_array     : { *(.init_array) }
+  PROVIDE (__init_array_end = .);
+  PROVIDE (__fini_array_start = .);
+  .fini_array     : { *(.fini_array) }
+  PROVIDE (__fini_array_end = .);
+  .data           :
+  {
+    _fdata = . ;
+    *(.data .data.* .gnu.linkonce.d.*)
+    SORT(CONSTRUCTORS)
+  }
+  .data1          : { *(.data1) }
+  .tdata	  : { *(.tdata .tdata.* .gnu.linkonce.td.*) }
+  .tbss		  : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) }
+  .eh_frame       : { KEEP (*(.eh_frame)) }
+  .gcc_except_table   : { *(.gcc_except_table) }
+  .ctors          :
+  {
+    /* gcc uses crtbegin.o to find the start of
+       the constructors, so we make sure it is
+       first.  Because this is a wildcard, it
+       doesn't matter if the user does not
+       actually link against crtbegin.o; the
+       linker won't look for a file to match a
+       wildcard.  The wildcard also means that it
+       doesn't matter which directory crtbegin.o
+       is in.  */
+    KEEP (*crtbegin*.o(.ctors))
+    /* We don't want to include the .ctor section from
+       from the crtend.o file until after the sorted ctors.
+       The .ctor section from the crtend file contains the
+       end of ctors marker and it must be last */
+    KEEP (*(EXCLUDE_FILE (*crtend*.o ) .ctors))
+    KEEP (*(SORT(.ctors.*)))
+    KEEP (*(.ctors))
+  }
+  .dtors          :
+  {
+    KEEP (*crtbegin*.o(.dtors))
+    KEEP (*(EXCLUDE_FILE (*crtend*.o ) .dtors))
+    KEEP (*(SORT(.dtors.*)))
+    KEEP (*(.dtors))
+  }
+  .jcr            : { KEEP (*(.jcr)) }
+  _gp = ALIGN(16) + 0x7ff0;
+  .got            : { *(.got.plt) *(.got) }
+  /* We want the small data sections together, so single-instruction offsets
+     can access them all, and initialized data all before uninitialized, so
+     we can shorten the on-disk segment size.  */
+  .sdata          :
+  {
+    *(.sdata .sdata.* .gnu.linkonce.s.*)
+  }
+  .lit8           : { *(.lit8) }
+  .lit4           : { *(.lit4) }
+  _edata = .;
+  PROVIDE (edata = .);
+  __bss_start = .;
+  _fbss = .;
+  .sbss           :
+  {
+    PROVIDE (__sbss_start = .);
+    PROVIDE (___sbss_start = .);
+    *(.dynsbss)
+    *(.sbss .sbss.* .gnu.linkonce.sb.*)
+    *(.scommon)
+    PROVIDE (__sbss_end = .);
+    PROVIDE (___sbss_end = .);
+  }
+  .bss            :
+  {
+   *(.dynbss)
+   *(.bss .bss.* .gnu.linkonce.b.*)
+   *(COMMON)
+   /* Align here to ensure that the .bss section occupies space up to
+      _end.  Align after .bss to ensure correct alignment even if the
+      .bss section disappears because there are no input sections.  */
+   . = ALIGN(32 / 8);
+  }
+  . = ALIGN(32 / 8);
+  _end = .;
+  PROVIDE (end = .);
+  /* Stabs debugging sections.  */
+  .stab          0 : { *(.stab) }
+  .stabstr       0 : { *(.stabstr) }
+  .stab.excl     0 : { *(.stab.excl) }
+  .stab.exclstr  0 : { *(.stab.exclstr) }
+  .stab.index    0 : { *(.stab.index) }
+  .stab.indexstr 0 : { *(.stab.indexstr) }
+  .comment       0 : { *(.comment) }
+  /* DWARF debug sections.
+     Symbols in the DWARF debugging sections are relative to the beginning
+     of the section so we begin them at 0.  */
+  /* DWARF 1 */
+  .debug          0 : { *(.debug) }
+  .line           0 : { *(.line) }
+  /* GNU DWARF 1 extensions */
+  .debug_srcinfo  0 : { *(.debug_srcinfo) }
+  .debug_sfnames  0 : { *(.debug_sfnames) }
+  /* DWARF 1.1 and DWARF 2 */
+  .debug_aranges  0 : { *(.debug_aranges) }
+  .debug_pubnames 0 : { *(.debug_pubnames) }
+  /* DWARF 2 */
+  .debug_info     0 : { *(.debug_info .gnu.linkonce.wi.*) }
+  .debug_abbrev   0 : { *(.debug_abbrev) }
+  .debug_line     0 : { *(.debug_line) }
+  .debug_frame    0 : { *(.debug_frame) }
+  .debug_str      0 : { *(.debug_str) }
+  .debug_loc      0 : { *(.debug_loc) }
+  .debug_macinfo  0 : { *(.debug_macinfo) }
+  /* SGI/MIPS DWARF 2 extensions */
+  .debug_weaknames 0 : { *(.debug_weaknames) }
+  .debug_funcnames 0 : { *(.debug_funcnames) }
+  .debug_typenames 0 : { *(.debug_typenames) }
+  .debug_varnames  0 : { *(.debug_varnames) }
+  .gptab.sdata : { *(.gptab.data) *(.gptab.sdata) }
+  .gptab.sbss : { *(.gptab.bss) *(.gptab.sbss) }
+  /DISCARD/ : { *(.note.GNU-stack) }
+}
diff --git a/usr/klibc/arch/mips/pipe.S b/usr/klibc/arch/mips/pipe.S
new file mode 100644
index 0000000..02b9405
--- /dev/null
+++ b/usr/klibc/arch/mips/pipe.S
@@ -0,0 +1,16 @@
+#include <asm/asm.h>
+#include <asm/regdef.h>
+#include <asm/unistd.h>
+
+LEAF(pipe)
+	li	v0, __NR_pipe
+	syscall
+	bnez	a3, 1f
+	sw	v0,  (a0)
+	sw	v1, 4(a0)
+	li	v0, 0
+	b	2f
+1:	sw	v0, errno
+	li	v0, -1
+2:	jr	ra
+	END(pipe)
diff --git a/usr/klibc/arch/mips/setjmp.S b/usr/klibc/arch/mips/setjmp.S
new file mode 100644
index 0000000..68eed19
--- /dev/null
+++ b/usr/klibc/arch/mips/setjmp.S
@@ -0,0 +1,80 @@
+#
+# arch/mips/setjmp.S
+#
+# setjmp/longjmp for the MIPS architecture
+#
+# The jmp_buf is assumed to contain the following, in order:
+#	s0..s7
+#	gp
+#	sp
+#	s8
+#	ra
+#	f20..f31
+#	fcr31
+#
+
+#include <machine/asm.h>
+
+LEAF(setjmp)
+	sw	s0,  0(a0)
+	sw	s1,  4(a0)
+	sw	s2,  8(a0)
+	sw	s3, 12(a0)
+	sw	s4, 16(a0)
+	sw	s5, 20(a0)
+	sw	s6, 24(a0)
+	sw	s7, 28(a0)
+	sw	gp, 32(a0)
+	sw	sp, 36(a0)
+	sw	s8, 40(a0)
+	sw	ra, 44(a0)
+	cfc1	t0,$31
+	swc1	$f20,48(a0)
+	swc1	$f21,52(a0)
+	swc1	$f22,56(a0)
+	swc1	$f23,60(a0)
+	swc1	$f24,64(a0)
+	swc1	$f25,68(a0)
+	swc1	$f26,72(a0)
+	swc1	$f27,76(a0)
+	swc1	$f28,80(a0)
+	swc1	$f29,84(a0)
+	swc1	$f30,88(a0)
+	swc1	$f31,92(a0)
+	sw	t0,96(a0)
+	move	v0,zero
+	jr	ra
+
+	END(setjmp)
+
+LEAF(longjmp)
+	lw	s0,  0(a0)
+	lw	s1,  4(a0)
+	lw	s2,  8(a0)
+	lw	s3, 12(a0)
+	lw	s4, 16(a0)
+	lw	s5, 20(a0)
+	lw	s6, 24(a0)
+	lw	s7, 28(a0)
+	lw	gp, 32(a0)
+	lw	sp, 36(a0)
+	lw	s8, 40(a0)
+	lw	ra, 44(a0)
+	lw	t0, 96(a0)
+	lwc1	$f20,48(a0)
+	lwc1	$f21,52(a0)
+	lwc1	$f22,56(a0)
+	lwc1	$f23,60(a0)
+	lwc1	$f24,64(a0)
+	lwc1	$f25,68(a0)
+	lwc1	$f26,72(a0)
+	lwc1	$f27,76(a0)
+	lwc1	$f28,80(a0)
+	lwc1	$f29,84(a0)
+	lwc1	$f30,88(a0)
+	lwc1	$f31,92(a0)
+	ctc1	t0,$31
+	move	v0,a1
+	jr	ra
+
+	END(longjmp)
diff --git a/usr/klibc/arch/mips/syscall.S b/usr/klibc/arch/mips/syscall.S
new file mode 100644
index 0000000..9f308df
--- /dev/null
+++ b/usr/klibc/arch/mips/syscall.S
@@ -0,0 +1,16 @@
+#include <asm/asm.h>
+#include <asm/regdef.h>
+#include <asm/unistd.h>
+
+	.set noreorder
+
+LEAF(__syscall_common)
+	syscall
+        beqz    a3, 1f
+	# sw is actually two instructions; the first one goes
+	# in the branch delay slot
+	# XXX: Break this up manually; as it is now it generates warnings.
+        sw      v0, errno
+        li      v0, -1
+1:      jr      ra
+	END(__syscall_common)
diff --git a/usr/klibc/arch/mips/sysstub.ph b/usr/klibc/arch/mips/sysstub.ph
new file mode 100644
index 0000000..a71d5d0
--- /dev/null
+++ b/usr/klibc/arch/mips/sysstub.ph
@@ -0,0 +1,30 @@
+# -*- perl -*-
+#
+# arch/mips/sysstub.ph
+#
+# Script to generate system call stubs
+#
+
+# On MIPS, most system calls follow the standard convention, with the
+# system call number in r0 (v0), return an error value in r19 (a3) as
+# well as the return value in r0 (v0).
+
+sub make_sysstub($$$$$@) {
+    my($outputdir, $fname, $type, $sname, $stype, @args) = @_;
+
+    $stype = $stype || 'common';
+    open(OUT, '>', "${outputdir}/${fname}.S");
+    print OUT "#include <asm/asm.h>\n";
+    print OUT "#include <asm/regdef.h>\n";
+    print OUT "#include <asm/unistd.h>\n";
+    print OUT "\n";
+    print OUT "\t.set noreorder\n";
+    print OUT "\n";
+    print OUT "LEAF(${fname})\n";
+    print OUT "\tj\t__syscall_${stype}\n";
+    print OUT "\t  li\tv0, __NR_${sname}\n";
+    print OUT "\tEND(${fname})\n";
+    close(OUT);
+}
+
+1;
diff --git a/usr/klibc/arch/mips/vfork.S b/usr/klibc/arch/mips/vfork.S
new file mode 100644
index 0000000..f9f035b
--- /dev/null
+++ b/usr/klibc/arch/mips/vfork.S
@@ -0,0 +1,16 @@
+#include <asm/asm.h>
+#include <asm/regdef.h>
+#include <asm/unistd.h>
+
+#define CLONE_VM	0x00000100
+#define CLONE_VFORK	0x00004000
+#define SIGCHLD		18
+
+	.set noreorder
+
+LEAF(vfork)
+	li	a0, CLONE_VFORK | CLONE_VM | SIGCHLD
+	li	a1, 0
+	j	__syscall_common
+	  li	v0, __NR_clone
+	END(vfork)

^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [klibc 12/31] mips64 support for klibc
  2006-06-28  5:17 [klibc 00/31] klibc as a historyless patchset (updated and reorganized) H. Peter Anvin
                   ` (10 preceding siblings ...)
  2006-06-28  5:17 ` [klibc 11/31] mips " H. Peter Anvin
@ 2006-06-28  5:17 ` H. Peter Anvin
  2006-06-28  5:17 ` [klibc 13/31] parisc " H. Peter Anvin
                   ` (18 subsequent siblings)
  30 siblings, 0 replies; 58+ messages in thread
From: H. Peter Anvin @ 2006-06-28  5:17 UTC (permalink / raw)
  To: linux-kernel, klibc; +Cc: H. Peter Anvin

The parts of klibc specific to the mips64 architecture.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>

---
commit 364ccece6cff9e5b99b6b5b94d2f781ebf6bdfb8
tree b1d0debd466a7a43ae4b686e7025bd83ebfa14ed
parent de9abe3c88abea63b10e8935cff79211c5983c9e
author H. Peter Anvin <hpa@zytor.com> Tue, 27 Jun 2006 20:50:46 -0700
committer H. Peter Anvin <hpa@zytor.com> Tue, 27 Jun 2006 20:50:46 -0700

 usr/include/arch/mips64/klibc/archconfig.h |   14 ++++++++++++
 usr/include/arch/mips64/klibc/archsignal.h |   14 ++++++++++++
 usr/include/arch/mips64/klibc/archstat.h   |   33 ++++++++++++++++++++++++++++
 usr/klibc/arch/mips64/MCONFIG              |   11 +++++++++
 usr/klibc/arch/mips64/Makefile.inc         |   10 ++++++++
 5 files changed, 82 insertions(+), 0 deletions(-)

diff --git a/usr/include/arch/mips64/klibc/archconfig.h b/usr/include/arch/mips64/klibc/archconfig.h
new file mode 100644
index 0000000..b440af1
--- /dev/null
+++ b/usr/include/arch/mips64/klibc/archconfig.h
@@ -0,0 +1,14 @@
+/*
+ * include/arch/mips64/klibc/archconfig.h
+ *
+ * See include/klibc/sysconfig.h for the options that can be set in
+ * this file.
+ *
+ */
+
+#ifndef _KLIBC_ARCHCONFIG_H
+#define _KLIBC_ARCHCONFIG_H
+
+/* All defaults */
+
+#endif				/* _KLIBC_ARCHCONFIG_H */
diff --git a/usr/include/arch/mips64/klibc/archsignal.h b/usr/include/arch/mips64/klibc/archsignal.h
new file mode 100644
index 0000000..f350af9
--- /dev/null
+++ b/usr/include/arch/mips64/klibc/archsignal.h
@@ -0,0 +1,14 @@
+/*
+ * arch/mips64/include/klibc/archsignal.h
+ *
+ * Architecture-specific signal definitions
+ *
+ */
+
+#ifndef _KLIBC_ARCHSIGNAL_H
+#define _KLIBC_ARCHSIGNAL_H
+
+#include <asm/signal.h>
+/* No special stuff for this architecture */
+
+#endif
diff --git a/usr/include/arch/mips64/klibc/archstat.h b/usr/include/arch/mips64/klibc/archstat.h
new file mode 100644
index 0000000..577f9ad
--- /dev/null
+++ b/usr/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/usr/klibc/arch/mips64/MCONFIG b/usr/klibc/arch/mips64/MCONFIG
new file mode 100644
index 0000000..3b55625
--- /dev/null
+++ b/usr/klibc/arch/mips64/MCONFIG
@@ -0,0 +1,11 @@
+# -*- makefile -*-
+#
+# arch/mips64/MCONFIG
+#
+# Special rules for this architecture.  Note that this is actually
+# included from the main Makefile, and that pathnames should be
+# accordingly.
+#
+
+KLIBCOPTFLAGS = -Os
+KLIBCBITSIZE  = 64
diff --git a/usr/klibc/arch/mips64/Makefile.inc b/usr/klibc/arch/mips64/Makefile.inc
new file mode 100644
index 0000000..4a9529a
--- /dev/null
+++ b/usr/klibc/arch/mips64/Makefile.inc
@@ -0,0 +1,10 @@
+# -*- makefile -*-
+#
+# arch/mips64/Makefile.inc
+#
+# Special rules for this architecture.  Note that this is actually
+# included from the main Makefile, and that pathnames should be
+# accordingly.
+#
+
+archclean:

^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [klibc 13/31] parisc support for klibc
  2006-06-28  5:17 [klibc 00/31] klibc as a historyless patchset (updated and reorganized) H. Peter Anvin
                   ` (11 preceding siblings ...)
  2006-06-28  5:17 ` [klibc 12/31] mips64 " H. Peter Anvin
@ 2006-06-28  5:17 ` H. Peter Anvin
  2006-06-28  5:17 ` [klibc 14/31] ppc " H. Peter Anvin
                   ` (17 subsequent siblings)
  30 siblings, 0 replies; 58+ messages in thread
From: H. Peter Anvin @ 2006-06-28  5:17 UTC (permalink / raw)
  To: linux-kernel, klibc; +Cc: H. Peter Anvin

The parts of klibc specific to the parisc architecture.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>

---
commit 72d9123910ed26d4d0f97641e0cfde3edcebf767
tree 9e20029aefe03571e8bfbfb414ae5d5c5df2fa9d
parent 364ccece6cff9e5b99b6b5b94d2f781ebf6bdfb8
author H. Peter Anvin <hpa@zytor.com> Tue, 27 Jun 2006 20:50:48 -0700
committer H. Peter Anvin <hpa@zytor.com> Tue, 27 Jun 2006 20:50:48 -0700

 usr/include/arch/parisc/klibc/archconfig.h |   14 ++++
 usr/include/arch/parisc/klibc/archsetjmp.h |   14 ++++
 usr/include/arch/parisc/klibc/archsignal.h |   25 ++++++++
 usr/include/arch/parisc/klibc/archstat.h   |   29 +++++++++
 usr/klibc/arch/parisc/MCONFIG              |   12 ++++
 usr/klibc/arch/parisc/Makefile.inc         |   16 +++++
 usr/klibc/arch/parisc/crt0.S               |   37 ++++++++++++
 usr/klibc/arch/parisc/setjmp.S             |   88 ++++++++++++++++++++++++++++
 usr/klibc/arch/parisc/syscall.S            |   36 +++++++++++
 usr/klibc/arch/parisc/sysstub.ph           |   28 +++++++++
 10 files changed, 299 insertions(+), 0 deletions(-)

diff --git a/usr/include/arch/parisc/klibc/archconfig.h b/usr/include/arch/parisc/klibc/archconfig.h
new file mode 100644
index 0000000..f8ba9e2
--- /dev/null
+++ b/usr/include/arch/parisc/klibc/archconfig.h
@@ -0,0 +1,14 @@
+/*
+ * include/arch/parisc/klibc/archconfig.h
+ *
+ * See include/klibc/sysconfig.h for the options that can be set in
+ * this file.
+ *
+ */
+
+#ifndef _KLIBC_ARCHCONFIG_H
+#define _KLIBC_ARCHCONFIG_H
+
+/* All defaults */
+
+#endif				/* _KLIBC_ARCHCONFIG_H */
diff --git a/usr/include/arch/parisc/klibc/archsetjmp.h b/usr/include/arch/parisc/klibc/archsetjmp.h
new file mode 100644
index 0000000..05e943e
--- /dev/null
+++ b/usr/include/arch/parisc/klibc/archsetjmp.h
@@ -0,0 +1,14 @@
+/*
+ * arch/parisc/include/klibc/archsetjmp.h
+ */
+
+#ifndef _KLIBC_ARCHSETJMP_H
+#define _KLIBC_ARCHSETJMP_H
+
+struct __jmp_buf {
+	double regs[21];
+};
+
+typedef struct __jmp_buf jmp_buf[1];
+
+#endif				/* _SETJMP_H */
diff --git a/usr/include/arch/parisc/klibc/archsignal.h b/usr/include/arch/parisc/klibc/archsignal.h
new file mode 100644
index 0000000..256aeea
--- /dev/null
+++ b/usr/include/arch/parisc/klibc/archsignal.h
@@ -0,0 +1,25 @@
+/*
+ * arch/parisc/include/klibc/archsignal.h
+ *
+ * Architecture-specific signal definitions
+ *
+ */
+
+#ifndef _KLIBC_ARCHSIGNAL_H
+#define _KLIBC_ARCHSIGNAL_H
+
+#include <asm/signal.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/usr/include/arch/parisc/klibc/archstat.h b/usr/include/arch/parisc/klibc/archstat.h
new file mode 100644
index 0000000..0b8ef8d
--- /dev/null
+++ b/usr/include/arch/parisc/klibc/archstat.h
@@ -0,0 +1,29 @@
+#ifndef _KLIBC_ARCHSTAT_H
+#define _KLIBC_ARCHSTAT_H
+
+#include <klibc/stathelp.h>
+
+#define _STATBUF_ST_NSEC
+
+struct stat {
+	__stdev64		(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;
+	__stdev64		(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/usr/klibc/arch/parisc/MCONFIG b/usr/klibc/arch/parisc/MCONFIG
new file mode 100644
index 0000000..83c2e9e
--- /dev/null
+++ b/usr/klibc/arch/parisc/MCONFIG
@@ -0,0 +1,12 @@
+# -*- makefile -*-
+#
+# arch/parisc/MCONFIG
+#
+# Special rules for this architecture.  Note that this is actually
+# included from the main Makefile, and that pathnames should be
+# accordingly.
+#
+
+KLIBCOPTFLAGS = -Os -fomit-frame-pointer
+KLIBCBITSIZE  = 32
+KLIBCSHAREDFLAGS	= -Ttext 0x40001000
diff --git a/usr/klibc/arch/parisc/Makefile.inc b/usr/klibc/arch/parisc/Makefile.inc
new file mode 100644
index 0000000..f479a6c
--- /dev/null
+++ b/usr/klibc/arch/parisc/Makefile.inc
@@ -0,0 +1,16 @@
+# -*- makefile -*-
+#
+# arch/parisc/Makefile.inc
+#
+# Special rules for this architecture.  Note that this is actually
+# included from the main Makefile, and that pathnames should be
+# accordingly.
+#
+
+KLIBCARCHOBJS = \
+	arch/$(KLIBCARCH)/setjmp.o \
+	arch/$(KLIBCARCH)/syscall.o
+
+KLIBCARCHOOBJS = $(patsubst %o,%.lo,%(KLIBCARCHOBJS))
+
+archclean:
diff --git a/usr/klibc/arch/parisc/crt0.S b/usr/klibc/arch/parisc/crt0.S
new file mode 100644
index 0000000..0922446
--- /dev/null
+++ b/usr/klibc/arch/parisc/crt0.S
@@ -0,0 +1,37 @@
+	.align 4
+
+	.import $global$, data
+	.import __libc_init, code
+
+	.global _start
+	.export _start, ENTRY
+	.type _start,@function
+
+	.proc
+	.callinfo
+
+_start:
+/* extend the stack by 64-bytes */
+	ldo	64(%sp), %sp
+
+/* %r25 = argc
+ * %r24 = argv
+ * envp = argv + (argc + 1)
+ * elfdata = (argv - 4)
+ */
+	ldo	-4(%r24), %r26
+
+/* load global data */
+	ldil	L%$global$, %dp
+	ldo	R%$global$(%dp), %dp
+
+/* parisc abi puts the atexit pointer in %r23, see ELF_PLAT_INIT() */
+	copy	%r23, %r25
+
+/* branch to __libc_init */
+	bl	__libc_init,%r2
+	nop
+/* break miserably if we ever return */
+	iitlbp	%r0,(%sr0,%r0) /* illegal instruction */
+	nop
+	.procend
diff --git a/usr/klibc/arch/parisc/setjmp.S b/usr/klibc/arch/parisc/setjmp.S
new file mode 100644
index 0000000..c8d766c
--- /dev/null
+++ b/usr/klibc/arch/parisc/setjmp.S
@@ -0,0 +1,88 @@
+/*
+ * parisc specific setjmp/longjmp routines
+ *
+ */
+
+        .text
+        .align 4
+        .global setjmp
+        .export setjmp, code
+        .proc
+        .callinfo
+setjmp:
+        stw     %r3,0(%r26)
+        stw     %r4,8(%r26)
+        stw     %r5,12(%r26)
+        stw     %r6,16(%r26)
+        stw     %r7,20(%r26)
+        stw     %r8,24(%r26)
+        stw     %r9,28(%r26)
+        stw     %r10,32(%r26)
+        stw     %r11,36(%r26)
+        stw     %r12,40(%r26)
+        stw     %r13,44(%r26)
+        stw     %r14,48(%r26)
+        stw     %r15,52(%r26)
+        stw     %r16,56(%r26)
+        stw     %r17,60(%r26)
+        stw     %r18,64(%r26)
+        stw     %r19,68(%r26)
+        stw     %r27,72(%r26)
+        stw     %r30,76(%r26)
+        stw     %rp,80(%r26)
+        ldo     88(%r26),%r19
+        fstd,ma %fr12,8(%r19)
+        fstd,ma %fr13,8(%r19)
+        fstd,ma %fr14,8(%r19)
+        fstd,ma %fr15,8(%r19)
+        fstd,ma %fr16,8(%r19)
+        fstd,ma %fr17,8(%r19)
+        fstd,ma %fr18,8(%r19)
+        fstd,ma %fr19,8(%r19)
+        fstd,ma %fr20,8(%r19)
+        fstd     %fr21,0(%r19)
+        bv       %r0(%rp)
+        copy     %r0,%r28
+	.procend
+
+	.text
+	.align 4
+	.global longjmp
+	.export longjmp, code
+	.proc
+	.callinfo
+longjmp:
+        ldw     0(%r26),%r3
+        ldw     8(%r26),%r4
+        ldw     12(%r26),%r5
+        ldw     16(%r26),%r6
+        ldw     20(%r26),%r7
+        ldw     24(%r26),%r8
+        ldw     28(%r26),%r9
+        ldw     32(%r26),%r10
+        ldw     36(%r26),%r11
+        ldw     40(%r26),%r12
+        ldw     44(%r26),%r13
+        ldw     48(%r26),%r14
+        ldw     52(%r26),%r15
+        ldw     56(%r26),%r16
+        ldw     60(%r26),%r17
+        ldw     64(%r26),%r18
+        ldw     68(%r26),%r19
+        ldw     72(%r26),%r27
+        ldw     76(%r26),%r30
+        ldw     80(%r26),%rp
+        ldo     88(%r26),%r20
+        fldd,ma 8(%r20),%fr12
+        fldd,ma 8(%r20),%fr13
+        fldd,ma 8(%r20),%fr14
+        fldd,ma 8(%r20),%fr15
+        fldd,ma 8(%r20),%fr16
+        fldd,ma 8(%r20),%fr17
+        fldd,ma 8(%r20),%fr18
+        fldd,ma 8(%r20),%fr19
+        fldd,ma 8(%r20),%fr20
+        fldd    0(%r20),%fr21
+        bv      %r0(%rp)
+        copy    %r25,%r28
+        .procend
diff --git a/usr/klibc/arch/parisc/syscall.S b/usr/klibc/arch/parisc/syscall.S
new file mode 100644
index 0000000..0ff2a65
--- /dev/null
+++ b/usr/klibc/arch/parisc/syscall.S
@@ -0,0 +1,36 @@
+/*
+ * arch/parisc/syscall.S
+ *
+ * %r20 contains the system call number, %r2 contains whence we came
+ *
+ */
+
+	.text
+	.align 64				; cache-width aligned
+	.globl	__syscall_common
+	.type	__syscall_common,@function
+__syscall_common:
+	ldo 		0x40(%sp),%sp
+	stw 		%rp,-0x54(%sp)		; save return pointer
+
+	ldw 		-0x74(%sp),%r22		; %arg4
+	ldw 		-0x78(%sp),%r21		; %arg5
+
+	ble		0x100(%sr2, %r0)	; jump to gateway page
+	nop					; can we move a load here?
+
+	ldi		-0x1000,%r19		; %r19 = -4096
+	sub		%r0,%ret0,%r22		; %r22 = -%ret0
+	cmpb,>>=,n	%r19,%ret0,1f		; if %ret0 >= -4096UL
+	ldi		-1,%ret0		; nullified on taken forward
+
+	/* store %r22 to errno... */
+	ldil		L%errno,%r1
+	ldo		R%errno(%r1),%r1
+	stw		%r22,0(%r1)
+1:
+	ldw 		-0x54(%sp),%rp		; restore return pointer
+	bv		%r0(%rp)		; jump back
+	ldo 		-0x40(%sp),%sp
+
+	.size __syscall_common,.-__syscall_common
diff --git a/usr/klibc/arch/parisc/sysstub.ph b/usr/klibc/arch/parisc/sysstub.ph
new file mode 100644
index 0000000..e2196ac
--- /dev/null
+++ b/usr/klibc/arch/parisc/sysstub.ph
@@ -0,0 +1,28 @@
+# -*- perl -*-
+#
+# arch/parisc/sysstub.ph
+#
+# Script to generate system call stubs
+#
+
+sub make_sysstub($$$$$@) {
+    my($outputdir, $fname, $type, $sname, $stype, @args) = @_;
+
+    open(OUT, '>', "${outputdir}/${fname}.S");
+    print OUT "#include <asm/unistd.h>\n";
+    print OUT "\n";
+    print OUT "\t.text\n";
+    print OUT "\t.align 4\n";
+    print OUT "\t.import __syscall_common, code\n";
+    print OUT "\t.global ${fname}\n";
+    print OUT "\t.export ${fname}, code\n";
+    print OUT "\t.proc\n";
+    print OUT "\.callinfo\n";
+    print OUT "${fname}:\n";
+    print OUT "\tb\t__syscall_common\n";
+    print OUT "\t  ldo\t__NR_${sname}(%r0),%r20\n";
+    print OUT "\t.procend\n";
+    close(OUT);
+}
+
+1;

^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [klibc 14/31] ppc support for klibc
  2006-06-28  5:17 [klibc 00/31] klibc as a historyless patchset (updated and reorganized) H. Peter Anvin
                   ` (12 preceding siblings ...)
  2006-06-28  5:17 ` [klibc 13/31] parisc " H. Peter Anvin
@ 2006-06-28  5:17 ` H. Peter Anvin
  2006-06-28  5:17 ` [klibc 15/31] ppc64 " H. Peter Anvin
                   ` (16 subsequent siblings)
  30 siblings, 0 replies; 58+ messages in thread
From: H. Peter Anvin @ 2006-06-28  5:17 UTC (permalink / raw)
  To: linux-kernel, klibc; +Cc: H. Peter Anvin

The parts of klibc specific to the ppc architecture.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>

---
commit 9a13243408e848d4e16962bc23bd955ac6222143
tree 94856a634268566f977b35ee865552fab47b9b27
parent 72d9123910ed26d4d0f97641e0cfde3edcebf767
author H. Peter Anvin <hpa@zytor.com> Tue, 27 Jun 2006 20:50:51 -0700
committer H. Peter Anvin <hpa@zytor.com> Tue, 27 Jun 2006 20:50:51 -0700

 usr/include/arch/ppc/klibc/archconfig.h |   14 ++++++++++++
 usr/include/arch/ppc/klibc/archsetjmp.h |   36 +++++++++++++++++++++++++++++++
 usr/include/arch/ppc/klibc/archsignal.h |   14 ++++++++++++
 usr/include/arch/ppc/klibc/archstat.h   |   30 ++++++++++++++++++++++++++
 usr/klibc/arch/ppc/MCONFIG              |   29 +++++++++++++++++++++++++
 usr/klibc/arch/ppc/Makefile.inc         |   22 +++++++++++++++++++
 usr/klibc/arch/ppc/crt0.S               |   23 ++++++++++++++++++++
 usr/klibc/arch/ppc/setjmp.S             |   34 +++++++++++++++++++++++++++++
 usr/klibc/arch/ppc/syscall.S            |   16 ++++++++++++++
 usr/klibc/arch/ppc/sysstub.ph           |   25 ++++++++++++++++++++++
 10 files changed, 243 insertions(+), 0 deletions(-)

diff --git a/usr/include/arch/ppc/klibc/archconfig.h b/usr/include/arch/ppc/klibc/archconfig.h
new file mode 100644
index 0000000..ce04eee
--- /dev/null
+++ b/usr/include/arch/ppc/klibc/archconfig.h
@@ -0,0 +1,14 @@
+/*
+ * include/arch/ppc/klibc/archconfig.h
+ *
+ * See include/klibc/sysconfig.h for the options that can be set in
+ * this file.
+ *
+ */
+
+#ifndef _KLIBC_ARCHCONFIG_H
+#define _KLIBC_ARCHCONFIG_H
+
+/* All defaults */
+
+#endif				/* _KLIBC_ARCHCONFIG_H */
diff --git a/usr/include/arch/ppc/klibc/archsetjmp.h b/usr/include/arch/ppc/klibc/archsetjmp.h
new file mode 100644
index 0000000..4be9ed6
--- /dev/null
+++ b/usr/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/usr/include/arch/ppc/klibc/archsignal.h b/usr/include/arch/ppc/klibc/archsignal.h
new file mode 100644
index 0000000..9c3ac92
--- /dev/null
+++ b/usr/include/arch/ppc/klibc/archsignal.h
@@ -0,0 +1,14 @@
+/*
+ * arch/ppc/include/klibc/archsignal.h
+ *
+ * Architecture-specific signal definitions
+ *
+ */
+
+#ifndef _KLIBC_ARCHSIGNAL_H
+#define _KLIBC_ARCHSIGNAL_H
+
+#include <asm/signal.h>
+/* No special stuff for this architecture */
+
+#endif
diff --git a/usr/include/arch/ppc/klibc/archstat.h b/usr/include/arch/ppc/klibc/archstat.h
new file mode 100644
index 0000000..9e31f4a
--- /dev/null
+++ b/usr/include/arch/ppc/klibc/archstat.h
@@ -0,0 +1,30 @@
+#ifndef _KLIBC_ARCHSTAT_H
+#define _KLIBC_ARCHSTAT_H
+
+#include <klibc/stathelp.h>
+
+#define _STATBUF_ST_NSEC
+
+/* This matches struct stat64 in glibc2.1.
+ */
+struct stat {
+	__stdev64 (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. */
+	__stdev64 (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/usr/klibc/arch/ppc/MCONFIG b/usr/klibc/arch/ppc/MCONFIG
new file mode 100644
index 0000000..5410933
--- /dev/null
+++ b/usr/klibc/arch/ppc/MCONFIG
@@ -0,0 +1,29 @@
+# -*- makefile -*-
+#
+# arch/ppc/MCONFIG
+#
+# Special rules for this architecture.  Note that this is actually
+# included from the main Makefile, and that pathnames should be
+# accordingly.
+#
+
+gcc_m32_option  := $(call cc-option, -m32, )
+
+KLIBCOPTFLAGS	   = -Os
+KLIBCLDFLAGS       = -m elf32ppclinux
+KLIBCARCHREQFLAGS += $(gcc_m32_option)
+
+KLIBCBITSIZE       = 32
+
+# Extra linkflags when building the shared version of the library
+# This address needs to be reachable using normal inter-module
+# calls, and work on the memory models for this architecture
+# 256-16 MB - normal binaries start at 256 MB, and jumps are limited
+# to +/- 16 MB
+KLIBCSHAREDFLAGS     = -Ttext 0x0f800200
+
+# The kernel so far has both asm-ppc* and asm-powerpc.
+KLIBCARCHINCFLAGS = -I$(KLIBCKERNELOBJ)arch/$(KLIBCARCH)/include
+
+# The asm include files live in asm-powerpc
+KLIBCASMARCH	= powerpc
diff --git a/usr/klibc/arch/ppc/Makefile.inc b/usr/klibc/arch/ppc/Makefile.inc
new file mode 100644
index 0000000..53d99c4
--- /dev/null
+++ b/usr/klibc/arch/ppc/Makefile.inc
@@ -0,0 +1,22 @@
+# -*- makefile -*-
+#
+# arch/ppc/Makefile.inc
+#
+# Special rules for this architecture.  Note that this is actually
+# included from the main Makefile, and that pathnames should be
+# accordingly.
+#
+
+KLIBCARCHOBJS = \
+	arch/$(KLIBCARCH)/setjmp.o \
+	arch/$(KLIBCARCH)/syscall.o \
+	libgcc/__divdi3.o \
+	libgcc/__moddi3.o \
+	libgcc/__udivdi3.o \
+	libgcc/__umoddi3.o \
+	libgcc/__udivmoddi4.o
+
+
+KLIBCARCHSOOBJS = $(patsubst %.o,%.lo,$(KLIBCARCHOBJS))
+
+archclean:
diff --git a/usr/klibc/arch/ppc/crt0.S b/usr/klibc/arch/ppc/crt0.S
new file mode 100644
index 0000000..85b6dca
--- /dev/null
+++ b/usr/klibc/arch/ppc/crt0.S
@@ -0,0 +1,23 @@
+#
+# arch/ppc/crt0.S
+#
+
+	.text
+	.align 4
+	.type _start,@function
+	.globl _start
+_start:
+	stwu	1,-16(1)
+	addi	3,1,16
+	/*
+	 * the SVR4abippc.pdf specifies r7 as a pointer to
+	 * a termination function point
+	 * However, Section 8.4.1 of the LSB API docs say that
+	 * The value to be placed into register r7, the termination
+	 * function pointer, is not passed to the process.
+	 * So we stub it out, instead.
+	 */
+	li	4,0
+	bl	__libc_init
+
+	.size _start,.-_start
diff --git a/usr/klibc/arch/ppc/setjmp.S b/usr/klibc/arch/ppc/setjmp.S
new file mode 100644
index 0000000..e02b7da
--- /dev/null
+++ b/usr/klibc/arch/ppc/setjmp.S
@@ -0,0 +1,34 @@
+#
+# arch/ppc/setjmp.S
+#
+# Basic setjmp/longjmp implementation
+# This file was derived from the equivalent file in NetBSD
+#
+
+	.text
+	.align 4
+	.type setjmp,@function
+	.globl setjmp
+setjmp:
+        mflr    %r11                    /* save return address */
+        mfcr    %r12                    /* save condition register */
+        mr      %r10,%r1                /* save stack pointer */
+        mr      %r9,%r2                 /* save GPR2 (not needed) */
+        stmw    %r9,0(%r3)              /* save r9..r31 */
+        li      %r3,0                   /* indicate success */
+        blr                             /* return */
+
+	.size setjmp,.-setjmp
+
+	.type longjmp,@function
+	.globl longjmp
+longjmp:
+        lmw     %r9,0(%r3)              /* save r9..r31 */
+        mtlr    %r11                    /* restore LR */
+        mtcr    %r12                    /* restore CR */
+        mr      %r2,%r9                 /* restore GPR2 (not needed) */
+        mr      %r1,%r10                /* restore stack */
+        mr      %r3,%r4                 /* get return value */
+        blr                             /* return */
+
+	.size longjmp,.-longjmp
diff --git a/usr/klibc/arch/ppc/syscall.S b/usr/klibc/arch/ppc/syscall.S
new file mode 100644
index 0000000..0a7c37c
--- /dev/null
+++ b/usr/klibc/arch/ppc/syscall.S
@@ -0,0 +1,16 @@
+/*
+ * arch/ppc/syscall.S
+ *
+ * Common error-handling path for system calls.
+ */
+
+	.text
+	.align	2
+	.globl	__syscall_error
+	.type	__syscall_error,@function
+__syscall_error:
+	lis	9,errno@ha
+	stw	3,errno@l(9)
+	li	3,-1
+	blr
+	.size	__syscall_error,.-__syscall_error
diff --git a/usr/klibc/arch/ppc/sysstub.ph b/usr/klibc/arch/ppc/sysstub.ph
new file mode 100644
index 0000000..3b3916c
--- /dev/null
+++ b/usr/klibc/arch/ppc/sysstub.ph
@@ -0,0 +1,25 @@
+# -*- perl -*-
+#
+# arch/ppc/sysstub.ph
+#
+# Script to generate system call stubs
+#
+
+sub make_sysstub($$$$$@) {
+    my($outputdir, $fname, $type, $sname, $stype, @args) = @_;
+
+    open(OUT, '>', "${outputdir}/${fname}.S");
+    print OUT "#include <asm/unistd.h>\n";
+    print OUT "\n";
+    print OUT "\t.type ${fname},\@function\n";
+    print OUT "\t.globl ${fname}\n";
+    print OUT "${fname}:\n";
+    print OUT "\tli 0,__NR_${sname}\n";
+    print OUT "\tsc\n";
+    print OUT "\tbnslr\n";
+    print OUT "\tb __syscall_error\n";
+    print OUT "\t.size ${fname},.-${fname}\n";
+    close(OUT);
+}
+
+1;

^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [klibc 15/31] ppc64 support for klibc
  2006-06-28  5:17 [klibc 00/31] klibc as a historyless patchset (updated and reorganized) H. Peter Anvin
                   ` (13 preceding siblings ...)
  2006-06-28  5:17 ` [klibc 14/31] ppc " H. Peter Anvin
@ 2006-06-28  5:17 ` H. Peter Anvin
  2006-06-28  5:17 ` [klibc 16/31] s390 " H. Peter Anvin
                   ` (15 subsequent siblings)
  30 siblings, 0 replies; 58+ messages in thread
From: H. Peter Anvin @ 2006-06-28  5:17 UTC (permalink / raw)
  To: linux-kernel, klibc; +Cc: H. Peter Anvin

The parts of klibc specific to the ppc64 architecture.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>

---
commit 951675b371b8e1b50a37f0f779e53b73316e9f11
tree 4619e41b5539f18140a0e972ce45cfb03707a091
parent 9a13243408e848d4e16962bc23bd955ac6222143
author H. Peter Anvin <hpa@zytor.com> Tue, 27 Jun 2006 20:50:52 -0700
committer H. Peter Anvin <hpa@zytor.com> Tue, 27 Jun 2006 20:50:52 -0700

 usr/include/arch/ppc64/klibc/archconfig.h |   12 ++++
 usr/include/arch/ppc64/klibc/archsetjmp.h |   36 ++++++++++++
 usr/include/arch/ppc64/klibc/archsignal.h |   14 +++++
 usr/include/arch/ppc64/klibc/archstat.h   |   27 +++++++++
 usr/klibc/arch/ppc64/MCONFIG              |   26 +++++++++
 usr/klibc/arch/ppc64/Makefile.inc         |   25 +++++++++
 usr/klibc/arch/ppc64/crt0.S               |   32 +++++++++++
 usr/klibc/arch/ppc64/setjmp.S             |   85 +++++++++++++++++++++++++++++
 usr/klibc/arch/ppc64/syscall.c            |   14 +++++
 usr/klibc/arch/ppc64/sysstub.ph           |   31 +++++++++++
 10 files changed, 302 insertions(+), 0 deletions(-)

diff --git a/usr/include/arch/ppc64/klibc/archconfig.h b/usr/include/arch/ppc64/klibc/archconfig.h
new file mode 100644
index 0000000..27c5630
--- /dev/null
+++ b/usr/include/arch/ppc64/klibc/archconfig.h
@@ -0,0 +1,12 @@
+/*
+ * include/arch/ppc64/klibc/archconfig.h
+ *
+ * See include/klibc/sysconfig.h for the options that can be set in this file.
+ */
+
+#ifndef _KLIBC_ARCHCONFIG_H
+#define _KLIBC_ARCHCONFIG_H
+
+#define _KLIBC_USE_RT_SIG 1
+
+#endif				/* _KLIBC_ARCHCONFIG_H */
diff --git a/usr/include/arch/ppc64/klibc/archsetjmp.h b/usr/include/arch/ppc64/klibc/archsetjmp.h
new file mode 100644
index 0000000..d227728
--- /dev/null
+++ b/usr/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/usr/include/arch/ppc64/klibc/archsignal.h b/usr/include/arch/ppc64/klibc/archsignal.h
new file mode 100644
index 0000000..2c4cef0
--- /dev/null
+++ b/usr/include/arch/ppc64/klibc/archsignal.h
@@ -0,0 +1,14 @@
+/*
+ * arch/ppc64/include/klibc/archsignal.h
+ *
+ * Architecture-specific signal definitions
+ *
+ */
+
+#ifndef _KLIBC_ARCHSIGNAL_H
+#define _KLIBC_ARCHSIGNAL_H
+
+#include <asm/signal.h>
+/* No special stuff for this architecture */
+
+#endif
diff --git a/usr/include/arch/ppc64/klibc/archstat.h b/usr/include/arch/ppc64/klibc/archstat.h
new file mode 100644
index 0000000..491316c
--- /dev/null
+++ b/usr/include/arch/ppc64/klibc/archstat.h
@@ -0,0 +1,27 @@
+#ifndef _KLIBC_ARCHSTAT_H
+#define _KLIBC_ARCHSTAT_H
+
+#include <klibc/stathelp.h>
+
+#define _STATBUF_ST_NSEC
+
+struct stat {
+	__stdev64	(st_dev);
+	ino_t		st_ino;
+	nlink_t		st_nlink;
+	mode_t		st_mode;
+	uid_t 		st_uid;
+	gid_t 		st_gid;
+	__stdev64	(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/usr/klibc/arch/ppc64/MCONFIG b/usr/klibc/arch/ppc64/MCONFIG
new file mode 100644
index 0000000..6d8e136
--- /dev/null
+++ b/usr/klibc/arch/ppc64/MCONFIG
@@ -0,0 +1,26 @@
+# -*- makefile -*-
+#
+# arch/ppc64/MCONFIG
+#
+# Special rules for this architecture.  Note that this is actually
+# included from the main Makefile, and that pathnames should be
+# accordingly.
+#
+
+KLIBCARCHREQFLAGS = -m64 -mcall-aixdesc
+KLIBCOPTFLAGS     = -Os
+KLIBCBITSIZE      = 64
+KLIBCLDFLAGS      = -m elf64ppc
+
+# Extra linkflags when building the shared version of the library
+# This address needs to be reachable using normal inter-module
+# calls, and work on the memory models for this architecture
+# 256-16 MB - normal binaries start at 256 MB, and jumps are limited
+# to +/- 16 MB
+KLIBCSHAREDFLAGS     = -Ttext 0x0f000200
+
+# The kernel so far has both asm-ppc* and asm-powerpc.
+KLIBCARCHINCFLAGS = -I$(KLIBCKERNELOBJ)arch/$(KLIBCARCH)/include
+
+# The asm include files live in asm-powerpc
+KLIBCASMARCH	= powerpc
diff --git a/usr/klibc/arch/ppc64/Makefile.inc b/usr/klibc/arch/ppc64/Makefile.inc
new file mode 100644
index 0000000..80f6be5
--- /dev/null
+++ b/usr/klibc/arch/ppc64/Makefile.inc
@@ -0,0 +1,25 @@
+# -*- makefile -*-
+#
+# arch/ppc64/Makefile.inc
+#
+# Special rules for this architecture.  Note that this is actually
+# included from the main Makefile, and that pathnames should be
+# accordingly.
+#
+
+KLIBCARCHOBJS = \
+	arch/$(KLIBCARCH)/setjmp.o \
+	arch/$(KLIBCARCH)/syscall.o
+
+KLIBCARCHSOOBJS = $(patsubst %.o,%.lo,$(KLIBCARCHOBJS))
+
+INTERP_O = interp1.o
+
+interp.o: interp1.o klibc.got
+	$(LD) $(KLIBCLDFLAGS) -r -o $@ interp1.o klibc.got
+
+klibc.got: $(SOHASH)
+	$(OBJCOPY) -j .got $< $@
+
+archclean:
+	rm -f klibc.got
diff --git a/usr/klibc/arch/ppc64/crt0.S b/usr/klibc/arch/ppc64/crt0.S
new file mode 100644
index 0000000..a7776a1
--- /dev/null
+++ b/usr/klibc/arch/ppc64/crt0.S
@@ -0,0 +1,32 @@
+#
+# arch/ppc64/crt0.S
+#
+# void _start(void)
+# {
+#    /* Divine up argc, argv, and envp */
+#    environ = envp;
+#    exit(main(argc, argv, envp));
+# }
+#
+
+	.section ".toc","aw"
+.LC0:	.tc	environ[TC],environ
+
+	.section ".opd","aw"
+	.align 3
+	.globl _start
+_start:
+	.quad	._start
+	.quad	.TOC.@tocbase, 0
+
+	.text
+	.globl	._start
+	.type	._start,@function
+._start:
+	stdu    %r1,-32(%r1)
+	addi    %r3,%r1,32
+	li	%r4,0		/* fini (unused) */
+	b 	.__libc_init
+	nop
+
+	.size _start,.-_start
diff --git a/usr/klibc/arch/ppc64/setjmp.S b/usr/klibc/arch/ppc64/setjmp.S
new file mode 100644
index 0000000..30db419
--- /dev/null
+++ b/usr/klibc/arch/ppc64/setjmp.S
@@ -0,0 +1,85 @@
+#
+# arch/ppc64/setjmp.S
+#
+# Basic setjmp/longjmp implementation
+#
+
+	.text
+	.align 4
+
+	.section ".opd","aw"
+setjmp:
+	.quad	.setjmp,.TOC.@tocbase,0
+	.previous
+	.size	setjmp,24
+	.type	.setjmp,@function
+	.globl	setjmp
+	.globl	.setjmp
+.setjmp:
+	mflr	%r11			/* save return address */
+	mfcr	%r12			/* save condition register */
+	std	%r2,0(%r3)		/* save TOC pointer (not needed) */
+	stdu	%r1,8(%r3)		/* save stack pointer */
+	stdu	%r11,8(%r3)
+	stdu	%r12,8(%r3)
+	stdu	%r13,8(%r3)		/* save caller saved regs */
+	stdu	%r14,8(%r3)
+	stdu	%r15,8(%r3)
+	stdu	%r16,8(%r3)
+	stdu	%r17,8(%r3)
+	stdu	%r18,8(%r3)
+	stdu	%r19,8(%r3)
+	stdu	%r20,8(%r3)
+	stdu	%r21,8(%r3)
+	stdu	%r22,8(%r3)
+	stdu	%r23,8(%r3)
+	stdu	%r24,8(%r3)
+	stdu	%r25,8(%r3)
+	stdu	%r26,8(%r3)
+	stdu	%r27,8(%r3)
+	stdu	%r28,8(%r3)
+	stdu	%r29,8(%r3)
+	stdu	%r30,8(%r3)
+	std	%r31,8(%r3)
+	li	%r3,0			/* indicate success */
+	blr				/* return */
+
+	.size .setjmp,.-.setjmp
+	.section ".opd","aw"
+longjmp:
+	.quad	.longjmp,.TOC.@tocbase,0
+	.previous
+	.size	longjmp,24
+	.type	.longjmp,@function
+	.globl	longjmp
+	.globl	.longjmp
+.longjmp:
+	ld	%r2,0(%r3)		/* restore TOC pointer (not needed) */
+	ldu	%r1,8(%r3)		/* restore stack */
+	ldu	%r11,8(%r3)
+	ldu	%r12,8(%r3)
+	ldu	%r13,8(%r3)		/* restore caller saved regs */
+	ldu	%r14,8(%r3)
+	ldu	%r15,8(%r3)
+	ldu	%r16,8(%r3)
+	ldu	%r17,8(%r3)
+	ldu	%r18,8(%r3)
+	ldu	%r19,8(%r3)
+	ldu	%r20,8(%r3)
+	ldu	%r21,8(%r3)
+	ldu	%r22,8(%r3)
+	ldu	%r23,8(%r3)
+	ldu	%r24,8(%r3)
+	ldu	%r25,8(%r3)
+	ldu	%r26,8(%r3)
+	ldu	%r27,8(%r3)
+	ldu	%r28,8(%r3)
+	ldu	%r29,8(%r3)
+	ldu	%r30,8(%r3)
+	ld	%r31,8(%r3)
+	mtlr	%r11			/* restore LR */
+	mtcr	%r12			/* restore CR */
+	mr	%r3,%r4			/* get return value */
+	blr				/* return */
+
+	.size .longjmp,.-.longjmp
diff --git a/usr/klibc/arch/ppc64/syscall.c b/usr/klibc/arch/ppc64/syscall.c
new file mode 100644
index 0000000..a5895fe
--- /dev/null
+++ b/usr/klibc/arch/ppc64/syscall.c
@@ -0,0 +1,14 @@
+/*
+ * arch/ppc64/syscall.c
+ *
+ * Common error-handling path for system calls.
+ * The return value from __syscall_error becomes the
+ * return value from the system call.
+ */
+#include <errno.h>
+
+long int __syscall_error(long int err)
+{
+	errno = err;
+	return -1;
+}
diff --git a/usr/klibc/arch/ppc64/sysstub.ph b/usr/klibc/arch/ppc64/sysstub.ph
new file mode 100644
index 0000000..9ee9370
--- /dev/null
+++ b/usr/klibc/arch/ppc64/sysstub.ph
@@ -0,0 +1,31 @@
+# -*- perl -*-
+#
+# arch/ppc64/sysstub.ph
+#
+# Script to generate system call stubs
+#
+
+sub make_sysstub($$$$$@) {
+    my($outputdir, $fname, $type, $sname, $stype, @args) = @_;
+
+    open(OUT, '>', "${outputdir}/${fname}.S");
+    print OUT "#include <asm/unistd.h>\n";
+    print OUT "\n";
+    print OUT "\t.globl ${fname}\n";
+    print OUT "\t.section \".opd\",\"aw\"\n";
+    print OUT "\t.align 3\n";
+    print OUT "${fname}:\n";
+    print OUT "\t.quad .${fname},.TOC.\@tocbase,0\n";
+    print OUT "\t.text\n";
+    print OUT "\t.type .${fname},\@function\n";
+    print OUT "\t.globl .${fname}\n";
+    print OUT ".${fname}:\n";
+    print OUT "\tli 0,__NR_${sname}\n";
+    print OUT "\tsc\n";
+    print OUT "\tbnslr\n";
+    print OUT "\tb .__syscall_error\n";
+    print OUT "\t.size .${fname},.-.${fname}\n";
+    close(OUT);
+}
+
+1;

^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [klibc 16/31] s390 support for klibc
  2006-06-28  5:17 [klibc 00/31] klibc as a historyless patchset (updated and reorganized) H. Peter Anvin
                   ` (14 preceding siblings ...)
  2006-06-28  5:17 ` [klibc 15/31] ppc64 " H. Peter Anvin
@ 2006-06-28  5:17 ` H. Peter Anvin
  2006-06-28  5:17 ` [klibc 17/31] sh " H. Peter Anvin
                   ` (14 subsequent siblings)
  30 siblings, 0 replies; 58+ messages in thread
From: H. Peter Anvin @ 2006-06-28  5:17 UTC (permalink / raw)
  To: linux-kernel, klibc; +Cc: H. Peter Anvin

The parts of klibc specific to the s390 architecture.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>

---
commit 271a450164027af5f0924e2e1d75ddec961a5c6d
tree 3b812c9e532f4ceaaf3a9ed64f0041c775ca69df
parent 951675b371b8e1b50a37f0f779e53b73316e9f11
author H. Peter Anvin <hpa@zytor.com> Tue, 27 Jun 2006 20:50:54 -0700
committer H. Peter Anvin <hpa@zytor.com> Tue, 27 Jun 2006 20:50:54 -0700

 usr/include/arch/s390/klibc/archconfig.h |   15 ++++++
 usr/include/arch/s390/klibc/archsetjmp.h |   26 ++++++++++
 usr/include/arch/s390/klibc/archsignal.h |   14 ++++++
 usr/include/arch/s390/klibc/archstat.h   |   56 ++++++++++++++++++++++
 usr/klibc/arch/s390/MCONFIG              |   23 +++++++++
 usr/klibc/arch/s390/Makefile.inc         |   38 +++++++++++++++
 usr/klibc/arch/s390/crt0.S               |   35 ++++++++++++++
 usr/klibc/arch/s390/mmap.c               |   75 ++++++++++++++++++++++++++++++
 usr/klibc/arch/s390/setjmp.S             |   66 ++++++++++++++++++++++++++
 usr/klibc/arch/s390/syscall.c            |   16 ++++++
 usr/klibc/arch/s390/sysstub.ph           |   40 ++++++++++++++++
 11 files changed, 404 insertions(+), 0 deletions(-)

diff --git a/usr/include/arch/s390/klibc/archconfig.h b/usr/include/arch/s390/klibc/archconfig.h
new file mode 100644
index 0000000..d7a71a4
--- /dev/null
+++ b/usr/include/arch/s390/klibc/archconfig.h
@@ -0,0 +1,15 @@
+/*
+ * include/arch/s390/klibc/archconfig.h
+ *
+ * See include/klibc/sysconfig.h for the options that can be set in
+ * this file.
+ *
+ */
+
+#ifndef _KLIBC_ARCHCONFIG_H
+#define _KLIBC_ARCHCONFIG_H
+
+/* Both s390 and s390x use the "32-bit" version of this structure */
+#define _KLIBC_STATFS_F_TYPE_64 0
+
+#endif				/* _KLIBC_ARCHCONFIG_H */
diff --git a/usr/include/arch/s390/klibc/archsetjmp.h b/usr/include/arch/s390/klibc/archsetjmp.h
new file mode 100644
index 0000000..728780a
--- /dev/null
+++ b/usr/include/arch/s390/klibc/archsetjmp.h
@@ -0,0 +1,26 @@
+/*
+ * arch/s390/include/klibc/archsetjmp.h
+ */
+
+#ifndef _KLIBC_ARCHSETJMP_H
+#define _KLIBC_ARCHSETJMP_H
+
+#ifndef __s390x__
+
+struct __jmp_buf {
+	uint32_t __gregs[10];	/* general registers r6-r15 */
+	uint64_t __fpregs[2];	/* fp registers f4 and f6   */
+};
+
+#else /* __s390x__ */
+
+struct __jmp_buf {
+	uint64_t __gregs[10]; /* general registers r6-r15 */
+	uint64_t __fpregs[4]; /* fp registers f1, f3, f5, f7 */
+};
+
+#endif /* __s390x__ */
+
+typedef struct __jmp_buf jmp_buf[1];
+
+#endif				/* _SETJMP_H */
diff --git a/usr/include/arch/s390/klibc/archsignal.h b/usr/include/arch/s390/klibc/archsignal.h
new file mode 100644
index 0000000..a16b977
--- /dev/null
+++ b/usr/include/arch/s390/klibc/archsignal.h
@@ -0,0 +1,14 @@
+/*
+ * arch/s390/include/klibc/archsignal.h
+ *
+ * Architecture-specific signal definitions
+ *
+ */
+
+#ifndef _KLIBC_ARCHSIGNAL_H
+#define _KLIBC_ARCHSIGNAL_H
+
+#include <asm/signal.h>
+/* No special stuff for this architecture */
+
+#endif
diff --git a/usr/include/arch/s390/klibc/archstat.h b/usr/include/arch/s390/klibc/archstat.h
new file mode 100644
index 0000000..de3a9da
--- /dev/null
+++ b/usr/include/arch/s390/klibc/archstat.h
@@ -0,0 +1,56 @@
+#ifndef _KLIBC_ARCHSTAT_H
+#define _KLIBC_ARCHSTAT_H
+
+#include <klibc/stathelp.h>
+
+#define _STATBUF_ST_NSEC
+
+#ifndef __s390x__
+
+/* This matches struct stat64 in glibc2.1, hence the absolutely
+ * insane amounts of padding around dev_t's.
+ */
+struct stat {
+	__stdev64	(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;
+	__stdev64	(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;
+};
+
+#else /* __s390x__ */
+
+struct stat {
+	__stdev64	(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;
+	__stdev64	(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 /* __s390x__ */
+#endif
diff --git a/usr/klibc/arch/s390/MCONFIG b/usr/klibc/arch/s390/MCONFIG
new file mode 100644
index 0000000..dd4495a
--- /dev/null
+++ b/usr/klibc/arch/s390/MCONFIG
@@ -0,0 +1,23 @@
+# -*- makefile -*-
+#
+# arch/s390/MCONFIG
+#
+# Special rules for this architecture.  Note that this is actually
+# included from the main Makefile, and that pathnames should be
+# accordingly.
+#
+
+KLIBCOPTFLAGS = -Os
+
+ifneq ("$(KLIBCARCH)", "s390x")
+	KLIBCBITSIZE	= 32
+	KLIBCCFLAGS	+= -m31
+	KLIBCLDFLAGS	+= -m elf_s390
+else
+	KLIBCBITSIZE	= 64
+	KLIBCCFLAGS	+= -m64
+	KLIBCLDFLAGS	+= -m elf64_s390
+endif
+
+KLIBCASMARCH		= s390
+KLIBCSHAREDFLAGS	= -Ttext 0x40000200
diff --git a/usr/klibc/arch/s390/Makefile.inc b/usr/klibc/arch/s390/Makefile.inc
new file mode 100644
index 0000000..8a35d73
--- /dev/null
+++ b/usr/klibc/arch/s390/Makefile.inc
@@ -0,0 +1,38 @@
+# -*- makefile -*-
+#
+# arch/s390/Makefile.inc
+#
+# Special rules for this architecture.  Note that this is actually
+# included from the main Makefile, and that pathnames should be
+# accordingly.
+#
+
+ifneq ("$(KLIBCARCH)", "s390x")
+
+KLIBCARCHOBJS = \
+	arch/$(KLIBCARCHDIR)/setjmp.o \
+	arch/$(KLIBCARCHDIR)/mmap.o \
+	arch/$(KLIBCARCHDIR)/syscall.o \
+	libgcc/__clzsi2.o \
+	libgcc/__ashldi3.o \
+	libgcc/__ashrdi3.o \
+	libgcc/__lshrdi3.o \
+	libgcc/__divdi3.o \
+	libgcc/__moddi3.o \
+	libgcc/__udivdi3.o \
+	libgcc/__umoddi3.o \
+	libgcc/__udivmoddi4.o
+
+else
+
+KLIBCARCHOBJS = \
+	arch/$(KLIBCARCHDIR)/setjmp.o \
+	arch/$(KLIBCARCHDIR)/mmap.o \
+	arch/$(KLIBCARCHDIR)/syscall.o
+
+endif
+
+KLIBCARCHSOOBJS = $(patsubst %.o,%.lo,$(KLIBCARCHOBJS))
+
+
+archclean:
diff --git a/usr/klibc/arch/s390/crt0.S b/usr/klibc/arch/s390/crt0.S
new file mode 100644
index 0000000..fd9237e
--- /dev/null
+++ b/usr/klibc/arch/s390/crt0.S
@@ -0,0 +1,35 @@
+#
+# arch/s390/crt0.S
+#
+# Does arch-specific initialization and invokes __libc_init
+# with the appropriate arguments.
+#
+# See __static_init.c or __shared_init.c for the expected
+# arguments.
+#
+	.text
+	.align 4
+	.type _start,@function
+	.globl _start
+
+#ifndef __s390x__
+
+_start:
+	lr	%r2,%r15
+	lhi	%r3,0
+	ahi	%r15,-96
+	bras	%r1,.L0
+.L0:
+	l	%r1,.L1-.L0(%r1)
+	br	%r1
+.L1:
+	.long	__libc_init
+#else
+
+_start:
+	lgr	%r2,%r15
+	lghi	%r3,0
+	aghi	%r15,-160
+	jg	__libc_init
+#endif
+	.size _start,.-_start
diff --git a/usr/klibc/arch/s390/mmap.c b/usr/klibc/arch/s390/mmap.c
new file mode 100644
index 0000000..4c43779
--- /dev/null
+++ b/usr/klibc/arch/s390/mmap.c
@@ -0,0 +1,75 @@
+#include <errno.h>
+#include <sys/types.h>
+#include <linux/unistd.h>
+
+struct mmap_arg_struct {
+	unsigned long addr;
+	unsigned long len;
+	unsigned long prot;
+	unsigned long flags;
+	unsigned long fd;
+	unsigned long offset;
+};
+
+#ifndef __s390x__
+
+void *__mmap2(void *addr, size_t len, int prot, int flags, int fd, long offset)
+{
+	struct mmap_arg_struct args = {
+		(unsigned long)addr,
+		(unsigned long)len,
+		(unsigned long)prot,
+		(unsigned long)flags,
+		(unsigned long)fd,
+		(unsigned long)offset,
+	};
+
+	register struct mmap_arg_struct *__arg1 asm("2") = &args;
+	register long __svcres asm("2");
+	unsigned long __res;
+
+	__asm__ __volatile__("    svc %b1\n"
+			     : "=d"(__svcres)
+			     : "i"(__NR_mmap2), "0"(__arg1)
+			     : "1", "cc", "memory");
+	__res = __svcres;
+	if (__res >= (unsigned long)-4095) {
+		errno = -__res;
+		__res = -1;
+	}
+	return (void *)__res;
+}
+
+#else /* __s390x__ */
+
+void * mmap(void * addr, size_t len, int prot, int flags,
+						 int fd, off_t offset)
+{
+	struct mmap_arg_struct args = {
+		(unsigned long) addr,
+		(unsigned long) len,
+		(unsigned long) prot,
+		(unsigned long) flags,
+		(unsigned long) fd,
+		(unsigned long) offset,
+	};
+
+	register struct mmap_arg_struct *__arg1 asm("2") = &args;
+	register long __svcres asm("2");
+	unsigned long __res;
+
+	__asm__ __volatile__ (
+		"    svc %b1\n"
+		: "=d" (__svcres)
+		: "i" (__NR_mmap),
+		  "0" (__arg1)
+		: "1", "cc", "memory");
+	__res = __svcres;
+	if (__res >= (unsigned long)-4095) {
+		errno = -__res;
+		__res = -1;
+	}
+	return (void *)__res;
+}
+
+#endif /* __s390x__ */
diff --git a/usr/klibc/arch/s390/setjmp.S b/usr/klibc/arch/s390/setjmp.S
new file mode 100644
index 0000000..c36a051
--- /dev/null
+++ b/usr/klibc/arch/s390/setjmp.S
@@ -0,0 +1,66 @@
+#
+# arch/s390/setjmp.S
+#
+# setjmp/longjmp for the s390 architecture
+#
+
+	.text
+	.align 4
+	.globl setjmp
+	.type setjmp, @function
+
+#ifndef __s390x__
+
+setjmp:
+	stm	%r6,%r15,0(%r2)		# save all general registers
+	std	%f4,40(%r2)		# save fp registers f4 and f6
+	std	%f6,48(%r2)
+	lhi	%r2,0			# return 0
+	br	%r14
+
+	.size setjmp,.-setjmp
+
+	.text
+	.align 4
+	.globl longjmp
+	.type longjmp, @function
+longjmp:
+	lr	%r1,%r2			# jmp_buf
+	lr	%r2,%r3			# return value
+	ld	%f6,48(%r1)		# restore all saved registers
+	ld	%f4,40(%r1)
+	lm	%r6,%r15,0(%r1)
+	br	%r14			# return to restored address
+
+	.size longjmp,.-longjmp
+
+#else
+
+setjmp:
+	stmg	%r6,%r15,0(%r2)		# save all general registers
+	std	%f1,80(%r2)		# save fp registers f4 and f6
+	std	%f3,88(%r2)
+	std	%f5,96(%r2)
+	std	%f7,104(%r2)
+	lghi	%r2,0			# return 0
+	br	%r14
+
+	.size setjmp,.-setjmp
+
+	.text
+	.align 4
+	.globl longjmp
+	.type longjmp, @function
+longjmp:
+	lgr	%r1,%r2			# jmp_buf
+	lgr	%r2,%r3			# return value
+	ld	%f7,104(%r1)		# restore all saved registers
+	ld	%f5,96(%r1)
+	ld	%f3,88(%r1)
+	ld	%f1,80(%r1)
+	lmg	%r6,%r15,0(%r1)
+	br	%r14			# return to restored address
+
+	.size longjmp,.-longjmp
+
+#endif
diff --git a/usr/klibc/arch/s390/syscall.c b/usr/klibc/arch/s390/syscall.c
new file mode 100644
index 0000000..e1d201d
--- /dev/null
+++ b/usr/klibc/arch/s390/syscall.c
@@ -0,0 +1,16 @@
+/*
+ * arch/s390/syscall.c
+ *
+ * Common error-handling path for system calls.
+ * The return value from __syscall_common becomes the
+ * return value from the system call.
+ */
+#include <errno.h>
+
+unsigned long __syscall_common(unsigned long err)
+{
+	if (err < -4095UL)
+		return err;
+	errno = -err;
+	return -1;
+}
diff --git a/usr/klibc/arch/s390/sysstub.ph b/usr/klibc/arch/s390/sysstub.ph
new file mode 100644
index 0000000..880a0da
--- /dev/null
+++ b/usr/klibc/arch/s390/sysstub.ph
@@ -0,0 +1,40 @@
+# -*- perl -*-
+#
+# arch/s390/sysstub.ph
+#
+# Script to generate system call stubs
+#
+
+sub make_sysstub($$$$$@) {
+    my($outputdir, $fname, $type, $sname, $stype, @args) = @_;
+
+    open(OUT, '>', "${outputdir}/${fname}.S");
+    print OUT "#include <asm/unistd.h>\n";
+    print OUT "\n";
+    print OUT "\t.type ${fname},\@function\n";
+    print OUT "\t.globl ${fname}\n";
+    print OUT "${fname}:\n";
+    print OUT ".if __NR_${sname} < 256\n";
+    print OUT "\tsvc __NR_${sname}\n";
+    print OUT ".else\n";
+    print OUT "\tla %r1,__NR_${sname}\n";
+    print OUT "\tsvc 0\n";
+    print OUT ".endif\n";
+
+    print OUT "#ifndef __s390x__\n";
+
+    print OUT "\tbras %r3,1f\n";
+    print OUT "\t.long __syscall_common\n";
+    print OUT "1:\tl %r3,0(%r3)\n";
+    print OUT "\tbr %r3\n";
+
+    print OUT "#else\n";
+
+    print OUT "\tbrasl %r3,__syscall_common\n";
+
+    print OUT "#endif\n";
+    print OUT "\t.size ${fname},.-${fname}\n";
+    close(OUT);
+}
+
+1;

^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [klibc 17/31] sh support for klibc
  2006-06-28  5:17 [klibc 00/31] klibc as a historyless patchset (updated and reorganized) H. Peter Anvin
                   ` (15 preceding siblings ...)
  2006-06-28  5:17 ` [klibc 16/31] s390 " H. Peter Anvin
@ 2006-06-28  5:17 ` H. Peter Anvin
  2006-06-28  5:17 ` [klibc 18/31] sparc " H. Peter Anvin
                   ` (13 subsequent siblings)
  30 siblings, 0 replies; 58+ messages in thread
From: H. Peter Anvin @ 2006-06-28  5:17 UTC (permalink / raw)
  To: linux-kernel, klibc; +Cc: H. Peter Anvin

The parts of klibc specific to the sh architecture.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>

---
commit f3d2864f8dd665446cb0a96b9811e77138ba8f6b
tree e991a52f0572bbeaf97ee2f909f5b294d24e36e3
parent 271a450164027af5f0924e2e1d75ddec961a5c6d
author H. Peter Anvin <hpa@zytor.com> Tue, 27 Jun 2006 20:50:56 -0700
committer H. Peter Anvin <hpa@zytor.com> Tue, 27 Jun 2006 20:50:56 -0700

 usr/include/arch/sh/klibc/archconfig.h |   14 +++++++
 usr/include/arch/sh/klibc/archsetjmp.h |   22 +++++++++++
 usr/include/arch/sh/klibc/archsignal.h |   14 +++++++
 usr/include/arch/sh/klibc/archstat.h   |   38 +++++++++++++++++++
 usr/klibc/arch/sh/MCONFIG              |   18 +++++++++
 usr/klibc/arch/sh/Makefile.inc         |   15 ++++++++
 usr/klibc/arch/sh/crt0.S               |   27 ++++++++++++++
 usr/klibc/arch/sh/setjmp.S             |   64 ++++++++++++++++++++++++++++++++
 usr/klibc/arch/sh/syscall.S            |   35 ++++++++++++++++++
 usr/klibc/arch/sh/sysstub.ph           |   34 +++++++++++++++++
 10 files changed, 281 insertions(+), 0 deletions(-)

diff --git a/usr/include/arch/sh/klibc/archconfig.h b/usr/include/arch/sh/klibc/archconfig.h
new file mode 100644
index 0000000..9c9e3d8
--- /dev/null
+++ b/usr/include/arch/sh/klibc/archconfig.h
@@ -0,0 +1,14 @@
+/*
+ * include/arch/sh/klibc/archconfig.h
+ *
+ * See include/klibc/sysconfig.h for the options that can be set in
+ * this file.
+ *
+ */
+
+#ifndef _KLIBC_ARCHCONFIG_H
+#define _KLIBC_ARCHCONFIG_H
+
+/* All defaults */
+
+#endif				/* _KLIBC_ARCHCONFIG_H */
diff --git a/usr/include/arch/sh/klibc/archsetjmp.h b/usr/include/arch/sh/klibc/archsetjmp.h
new file mode 100644
index 0000000..bb97167
--- /dev/null
+++ b/usr/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/usr/include/arch/sh/klibc/archsignal.h b/usr/include/arch/sh/klibc/archsignal.h
new file mode 100644
index 0000000..8e48e51
--- /dev/null
+++ b/usr/include/arch/sh/klibc/archsignal.h
@@ -0,0 +1,14 @@
+/*
+ * arch/sh/include/klibc/archsignal.h
+ *
+ * Architecture-specific signal definitions
+ *
+ */
+
+#ifndef _KLIBC_ARCHSIGNAL_H
+#define _KLIBC_ARCHSIGNAL_H
+
+#include <asm/signal.h>
+/* No special stuff for this architecture */
+
+#endif
diff --git a/usr/include/arch/sh/klibc/archstat.h b/usr/include/arch/sh/klibc/archstat.h
new file mode 100644
index 0000000..f4c65ea
--- /dev/null
+++ b/usr/include/arch/sh/klibc/archstat.h
@@ -0,0 +1,38 @@
+#ifndef _KLIBC_ARCHSTAT_H
+#define _KLIBC_ARCHSTAT_H
+
+#include <klibc/stathelp.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 {
+	__stdev64	(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;
+
+	__stdev64	(st_rdev);
+	unsigned char	__pad3[4];
+
+	long long	st_size;
+	unsigned long	st_blksize;
+
+	unsigned long long st_blocks;
+
+	struct timespec	st_atim;
+	struct timespec st_mtim;
+	struct timespec st_ctim;
+
+	unsigned long	__unused1;
+	unsigned long	__unused2;
+};
+
+#endif
diff --git a/usr/klibc/arch/sh/MCONFIG b/usr/klibc/arch/sh/MCONFIG
new file mode 100644
index 0000000..f0106e1
--- /dev/null
+++ b/usr/klibc/arch/sh/MCONFIG
@@ -0,0 +1,18 @@
+# -*- makefile -*-
+#
+# arch/sh/MCONFIG
+#
+# Special rules for this architecture.  Note that this is actually
+# included from the main Makefile, and that pathnames should be
+# accordingly.
+#
+
+ARCHREGFLAGS = -m4 -mno-implicit-fp
+KLIBCOPTFLAGS     = -Os -fomit-frame-pointer
+KLIBCBITSIZE      = 32
+
+# Extra linkflags when building the shared version of the library
+# This address needs to be reachable using normal inter-module
+# calls, and work on the memory models for this architecture
+# 2 MB -- the normal starting point for text is 4 MB.
+KLIBCSHAREDFLAGS	= -Ttext 0x00200200
diff --git a/usr/klibc/arch/sh/Makefile.inc b/usr/klibc/arch/sh/Makefile.inc
new file mode 100644
index 0000000..ccabfa4
--- /dev/null
+++ b/usr/klibc/arch/sh/Makefile.inc
@@ -0,0 +1,15 @@
+# -*- makefile -*-
+#
+# arch/sh/Makefile.inc
+#
+# Special rules for this architecture.  Note that this is actually
+# included from the main Makefile, and that pathnames should be
+# accordingly.
+#
+
+ARCHOBJS = arch/sh/setjmp.o \
+	   arch/sh/syscall.o
+
+ARCHSOOBJS = $(patsubst %.o,%.lo,$(ARCHOBJS))
+
+archclean:
diff --git a/usr/klibc/arch/sh/crt0.S b/usr/klibc/arch/sh/crt0.S
new file mode 100644
index 0000000..7f0a649
--- /dev/null
+++ b/usr/klibc/arch/sh/crt0.S
@@ -0,0 +1,27 @@
+#
+# arch/sh/crt0.S
+#
+# Does arch-specific initialization and invokes __libc_init
+# with the appropriate arguments.
+#
+# See __static_init.c or __shared_init.c for the expected
+# arguments.
+#
+
+	.text
+	.align 2
+	.type _start,#function
+	.globl _start
+
+_start:
+	mov	r15, r4
+	mov	#0, r5
+	mov.l	1f, r0
+
+	jsr	@r0
+	 nop
+
+	.align 2
+1:	.long	__libc_init
+
+	.size _start,.-_start
diff --git a/usr/klibc/arch/sh/setjmp.S b/usr/klibc/arch/sh/setjmp.S
new file mode 100644
index 0000000..2552358
--- /dev/null
+++ b/usr/klibc/arch/sh/setjmp.S
@@ -0,0 +1,64 @@
+#
+# arch/sh/setjmp.S
+#
+# setjmp/longjmp for the SuperH architecture
+#
+
+#
+# The jmp_buf is assumed to contain the following, in order:
+#
+#		r8
+#		r9
+#		r10
+#		r11
+#		r12
+#		r13
+#		r14
+#		r15
+#		pr
+#
+
+	.text
+	.align 2
+
+	.globl setjmp
+	.type setjmp, #function
+
+setjmp:
+	add	#(9*4), r4
+	sts.l	pr, @-r4
+	mov.l	r15, @-r4
+	mov.l	r14, @-r4
+	mov.l	r13, @-r4
+	mov.l	r12, @-r4
+	mov.l	r11, @-r4
+	mov.l	r10, @-r4
+	mov.l	r9, @-r4
+	mov.l	r8, @-r4
+	rts
+	 mov	#0, r0
+
+	.size setjmp,.-setjmp
+
+	.align 2
+	.globl longjmp
+	.type setjmp, #function
+
+longjmp:
+	mov.l	@r4+, r8
+	mov.l	@r4+, r9
+	mov.l	@r4+, r10
+	mov.l	@r4+, r11
+	mov.l	@r4+, r12
+	mov.l	@r4+, r13
+	mov.l	@r4+, r14
+	mov.l	@r4+, r15
+	lds.l	@r4+, pr
+	mov	r5, r0
+	tst	r0, r0
+	bf	1f
+	mov	#1, r0	! in case val==0
+1:	rts
+	 nop
+
+	.size longjmp,.-longjmp
diff --git a/usr/klibc/arch/sh/syscall.S b/usr/klibc/arch/sh/syscall.S
new file mode 100644
index 0000000..41a0486
--- /dev/null
+++ b/usr/klibc/arch/sh/syscall.S
@@ -0,0 +1,35 @@
+/*
+ * arch/sh/syscall.S
+ *
+ * On sh, r3 contains the syscall number (set by generated stub);
+ * r4..r7 contain arguments 0-3 per the standard calling convention,
+ * and arguments 4-5 are passed in r0 and r1.
+ *
+ * The return value is in r3 rather than standard r0.
+ */
+
+	.section ".text.syscall","ax"
+	.align	2
+	.globl	___syscall_common
+	.type	___syscall_common,@function
+___syscall_common:
+	mov.l	@(sp),r0
+	mov.l	@(4,sp),r1
+	trapa	#0x15
+	mov.l	1f,r0
+	cmp/hs	r0,r3
+	bt/s	3f
+	  neg	r3,r4
+	mov.l	2f,r5
+	mov.l	r4,@r5
+	rts
+	  mov	#-1,r0
+3:
+	rts
+	  mov	r3,r0
+
+	.align 2
+1:	.long	-4096		/* Errno limit */
+2:	.long	errno
+
+	.size	___syscall_common,.-___syscall_common
diff --git a/usr/klibc/arch/sh/sysstub.ph b/usr/klibc/arch/sh/sysstub.ph
new file mode 100644
index 0000000..ce04b73
--- /dev/null
+++ b/usr/klibc/arch/sh/sysstub.ph
@@ -0,0 +1,34 @@
+# -*- perl -*-
+#
+# arch/sh/sysstub.ph
+#
+# Script to generate system call stubs
+#
+
+sub make_sysstub($$$$$@) {
+    my($outputdir, $fname, $type, $sname, $stype, @args) = @_;
+
+    open(OUT, '>', "${outputdir}/${fname}.S");
+    print OUT "#include <asm/unistd.h>\n";
+    print OUT "\n";
+    print OUT "\t.section\t\".text.syscall\",\"ax\"\n";
+    print OUT "\t.type\t${fname},\#function\n";
+    print OUT "\t.globl\t${fname}\n";
+    print OUT "\t.align\t2\n";
+    print OUT "${fname}:\n";
+    print OUT "\tbra\t__syscall_common\n";
+    print OUT "#if __NR_${sname} >= 128\n";
+    print OUT "\t  mov.l\t1f, r3\n";
+    print OUT "#else\n";
+    print OUT "\t  mov\t# __NR_${sname}, r3\n";
+    print OUT "#endif\n";
+    print OUT "\t.size ${fname},.-${fname}\n";
+    print OUT "\n";
+    print OUT "#if __NR_${sname} >= 128\n";
+    print OUT "\t.align\t2\n";
+    print OUT "1:\t.long\t__NR_${sname}\n";
+    print OUT "#endif\n";
+    close(OUT);
+}
+
+1;

^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [klibc 18/31] sparc support for klibc
  2006-06-28  5:17 [klibc 00/31] klibc as a historyless patchset (updated and reorganized) H. Peter Anvin
                   ` (16 preceding siblings ...)
  2006-06-28  5:17 ` [klibc 17/31] sh " H. Peter Anvin
@ 2006-06-28  5:17 ` H. Peter Anvin
  2006-06-28  5:17 ` [klibc 19/31] sparc64 " H. Peter Anvin
                   ` (12 subsequent siblings)
  30 siblings, 0 replies; 58+ messages in thread
From: H. Peter Anvin @ 2006-06-28  5:17 UTC (permalink / raw)
  To: linux-kernel, klibc; +Cc: H. Peter Anvin

The parts of klibc specific to the sparc architecture.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>

---
commit 0b300030e6549258be2bf57cb5ac4d6cedd05786
tree 512a8f450f6df25913512f8c66d54464b4668248
parent f3d2864f8dd665446cb0a96b9811e77138ba8f6b
author H. Peter Anvin <hpa@zytor.com> Tue, 27 Jun 2006 20:50:59 -0700
committer H. Peter Anvin <hpa@zytor.com> Tue, 27 Jun 2006 20:50:59 -0700

 usr/include/arch/sparc/klibc/archconfig.h |   14 +
 usr/include/arch/sparc/klibc/archsetjmp.h |   16 ++
 usr/include/arch/sparc/klibc/archsignal.h |   24 +++
 usr/include/arch/sparc/klibc/archstat.h   |   37 ++++
 usr/include/arch/sparc/machine/asm.h      |  191 ++++++++++++++++++++
 usr/include/arch/sparc/machine/frame.h    |  146 +++++++++++++++
 usr/include/arch/sparc/machine/trap.h     |  140 +++++++++++++++
 usr/klibc/arch/sparc/MCONFIG              |   19 ++
 usr/klibc/arch/sparc/Makefile.inc         |   48 +++++
 usr/klibc/arch/sparc/__muldi3.S           |   27 +++
 usr/klibc/arch/sparc/crt0.S               |    2 
 usr/klibc/arch/sparc/crt0i.S              |  100 +++++++++++
 usr/klibc/arch/sparc/divrem.m4            |  276 +++++++++++++++++++++++++++++
 usr/klibc/arch/sparc/pipe.S               |   30 +++
 usr/klibc/arch/sparc/setjmp.S             |   38 ++++
 usr/klibc/arch/sparc/smul.S               |  160 +++++++++++++++++
 usr/klibc/arch/sparc/syscall.S            |   19 ++
 usr/klibc/arch/sparc/sysfork.S            |   25 +++
 usr/klibc/arch/sparc/sysstub.ph           |   25 +++
 usr/klibc/arch/sparc/umul.S               |  193 ++++++++++++++++++++
 20 files changed, 1530 insertions(+), 0 deletions(-)

diff --git a/usr/include/arch/sparc/klibc/archconfig.h b/usr/include/arch/sparc/klibc/archconfig.h
new file mode 100644
index 0000000..90a6c49
--- /dev/null
+++ b/usr/include/arch/sparc/klibc/archconfig.h
@@ -0,0 +1,14 @@
+/*
+ * include/arch/sparc/klibc/archconfig.h
+ *
+ * See include/klibc/sysconfig.h for the options that can be set in
+ * this file.
+ *
+ */
+
+#ifndef _KLIBC_ARCHCONFIG_H
+#define _KLIBC_ARCHCONFIG_H
+
+#define _KLIBC_USE_RT_SIG 1	/* Use rt_* signals */
+
+#endif				/* _KLIBC_ARCHCONFIG_H */
diff --git a/usr/include/arch/sparc/klibc/archsetjmp.h b/usr/include/arch/sparc/klibc/archsetjmp.h
new file mode 100644
index 0000000..9b4d6a2
--- /dev/null
+++ b/usr/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/usr/include/arch/sparc/klibc/archsignal.h b/usr/include/arch/sparc/klibc/archsignal.h
new file mode 100644
index 0000000..6e845a8
--- /dev/null
+++ b/usr/include/arch/sparc/klibc/archsignal.h
@@ -0,0 +1,24 @@
+/*
+ * arch/sparc/include/klibc/archsignal.h
+ *
+ * Architecture-specific signal definitions
+ *
+ */
+
+#ifndef _KLIBC_ARCHSIGNAL_H
+#define _KLIBC_ARCHSIGNAL_H
+
+#define __WANT_POSIX1B_SIGNALS__
+#include <asm/signal.h>
+
+struct sigaction {
+	__sighandler_t	sa_handler;
+	unsigned long	sa_flags;
+	void		(*sa_restorer)(void);	/* Not used by Linux/SPARC */
+	sigset_t	sa_mask;
+};
+
+/* Not actually used by the kernel... */
+#define SA_RESTORER	0x80000000
+
+#endif
diff --git a/usr/include/arch/sparc/klibc/archstat.h b/usr/include/arch/sparc/klibc/archstat.h
new file mode 100644
index 0000000..203d40b
--- /dev/null
+++ b/usr/include/arch/sparc/klibc/archstat.h
@@ -0,0 +1,37 @@
+#ifndef _KLIBC_ARCHSTAT_H
+#define _KLIBC_ARCHSTAT_H
+
+#include <klibc/stathelp.h>
+
+#define _STATBUF_ST_NSEC
+
+struct stat {
+	__stdev64	(st_dev);
+
+	unsigned long long st_ino;
+
+	unsigned int	st_mode;
+	unsigned int	st_nlink;
+
+	unsigned int	st_uid;
+	unsigned int	st_gid;
+
+	__stdev64	(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/usr/include/arch/sparc/machine/asm.h b/usr/include/arch/sparc/machine/asm.h
new file mode 100644
index 0000000..04fe9b1
--- /dev/null
+++ b/usr/include/arch/sparc/machine/asm.h
@@ -0,0 +1,191 @@
+/*	$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/usr/include/arch/sparc/machine/frame.h b/usr/include/arch/sparc/machine/frame.h
new file mode 100644
index 0000000..6fb9c45
--- /dev/null
+++ b/usr/include/arch/sparc/machine/frame.h
@@ -0,0 +1,146 @@
+/*	$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
+ */
+
+#ifndef _MACHINE_FRAME_H
+#define _MACHINE_FRAME_H
+
+#ifdef __ASSEMBLY__
+# define _LOCORE
+#endif
+
+#ifndef _LOCORE
+# include <stdint.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) */
+	uint32_t fr_fp;	/* space to save frame pointer (%i6) */
+	uint32_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) */
+	uint64_t fr_fp;		/* space to save frame pointer (%i6) */
+	uint64_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)
+
+#endif /* _MACHINE_FRAME_H */
diff --git a/usr/include/arch/sparc/machine/trap.h b/usr/include/arch/sparc/machine/trap.h
new file mode 100644
index 0000000..5c378c5
--- /dev/null
+++ b/usr/include/arch/sparc/machine/trap.h
@@ -0,0 +1,140 @@
+/*	$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/usr/klibc/arch/sparc/MCONFIG b/usr/klibc/arch/sparc/MCONFIG
new file mode 100644
index 0000000..9bb7592
--- /dev/null
+++ b/usr/klibc/arch/sparc/MCONFIG
@@ -0,0 +1,19 @@
+# -*- makefile -*-
+#
+# arch/sparc/MCONFIG
+#
+# Special rules for this architecture.  Note that this is actually
+# included from the main Makefile, and that pathnames should be
+# accordingly.
+#
+
+KLIBCOPTFLAGS		 = -Os -m32 -mptr32
+KLIBCBITSIZE		 = 32
+KLIBCARCHREQFLAGS	+= -D__sparc32__
+
+# Extra linkflags when building the shared version of the library
+# This address needs to be reachable using normal inter-module
+# calls, and work on the memory models for this architecture
+# Normal binaries start at 64K; the linker wants 64K alignment,
+# and call instructions have a 30-bit signed offset, << 2.
+KLIBCSHAREDFLAGS	 = -Ttext 0x40000100
diff --git a/usr/klibc/arch/sparc/Makefile.inc b/usr/klibc/arch/sparc/Makefile.inc
new file mode 100644
index 0000000..6fa9327
--- /dev/null
+++ b/usr/klibc/arch/sparc/Makefile.inc
@@ -0,0 +1,48 @@
+# -*- makefile -*-
+#
+# arch/sparc/Makefile.inc
+#
+# Special rules for this architecture.  Note that this is actually
+# included from the main Makefile, and that pathnames should be
+# accordingly.
+#
+
+m4-targets := arch/$(KLIBCARCH)/sdiv.o arch/$(KLIBCARCH)/srem.o \
+              arch/$(KLIBCARCH)/udiv.o arch/$(KLIBCARCH)/urem.o
+
+KLIBCARCHOBJS = $(m4-targets) \
+	arch/$(KLIBCARCH)/smul.o \
+	arch/$(KLIBCARCH)/umul.o \
+	arch/$(KLIBCARCH)/__muldi3.o \
+	arch/$(KLIBCARCH)/setjmp.o \
+	arch/$(KLIBCARCH)/pipe.o \
+	arch/$(KLIBCARCH)/syscall.o \
+	arch/$(KLIBCARCH)/sysfork.o \
+	libgcc/__ashldi3.o \
+	libgcc/__ashrdi3.o \
+	libgcc/__lshrdi3.o \
+	libgcc/__divdi3.o \
+	libgcc/__moddi3.o \
+	libgcc/__udivdi3.o \
+	libgcc/__umoddi3.o \
+	libgcc/__udivmoddi4.o \
+	libgcc/__clzsi2.o \
+
+
+adir := $(obj)/arch/$(KLIBCARCH)
+
+$(adir)/sdiv.S: m4 := define(NAME,\`.div')define(OP,\`div')define(S,\`true')
+$(adir)/srem.S: m4 := define(NAME,\`.rem')define(OP,\`rem')define(S,\`true')
+$(adir)/udiv.S: m4 := define(NAME,\`.udiv')define(OP,\`div')define(S,\`false')
+$(adir)/urem.S: m4 := define(NAME,\`.urem')define(OP,\`rem')define(S,\`false')
+
+targets += $(m4-targets) $(m4-targets:.o=.S)
+
+quiet_cmd_m4 = M4      $@
+      cmd_m4 = (echo "$(m4)"; cat $^) | m4 > $@
+
+# build .o from .S
+$(addprefix $(obj)/,$(m4-targets)): $(adir)/%.o : $(adir)/%.S
+# build .S from .m4
+$(addprefix $(obj)/,$(m4-targets:.o=.S)): $(src)/arch/$(KLIBCARCH)/divrem.m4
+	$(call if_changed,m4)
diff --git a/usr/klibc/arch/sparc/__muldi3.S b/usr/klibc/arch/sparc/__muldi3.S
new file mode 100644
index 0000000..e53848a
--- /dev/null
+++ b/usr/klibc/arch/sparc/__muldi3.S
@@ -0,0 +1,27 @@
+	.global .umul
+	.section	".text"
+	.align 4
+	.global __muldi3
+	.type	__muldi3, #function
+	.proc	017
+__muldi3:
+	save	%sp, -104, %sp
+	mov	%i1, %o0
+	call	.umul, 0
+	 mov	%i3, %o1
+	mov	%o0, %l2
+	mov	%o1, %l3
+	mov	%i1, %o0
+	call	.umul, 0
+	 mov	%i2, %o1
+	mov	%i0, %o1
+	mov	%o0, %l0
+	call	.umul, 0
+	 mov	%i3, %o0
+	mov	0, %l1
+	add	%l0, %o0, %l0
+	addcc	%l3, %l1, %i1
+	addx	%l2, %l0, %i0
+	jmp	%i7+8
+	 restore
+	.size	__muldi3, .-__muldi3
diff --git a/usr/klibc/arch/sparc/crt0.S b/usr/klibc/arch/sparc/crt0.S
new file mode 100644
index 0000000..63db188
--- /dev/null
+++ b/usr/klibc/arch/sparc/crt0.S
@@ -0,0 +1,2 @@
+#define TARGET_PTR_SIZE	32
+#include "crt0i.S"
diff --git a/usr/klibc/arch/sparc/crt0i.S b/usr/klibc/arch/sparc/crt0i.S
new file mode 100644
index 0000000..0220b01
--- /dev/null
+++ b/usr/klibc/arch/sparc/crt0i.S
@@ -0,0 +1,100 @@
+! This file derived from the equivalent in newlib
+!
+! C run time start off
+
+! This file supports:
+!
+! - both 32bit pointer and 64bit pointer environments (at compile time)
+! - an imposed stack bias (of 2047) (at run time)
+! - medium/low and medium/anywhere code models (at run time)
+
+! Initial stack setup:
+!
+!    bottom of stack (higher memory address)
+! 	...
+!	text of environment strings
+!	text of argument strings
+!	envp[envc] = 0 (4/8 bytes)
+!	...
+!	env[0] (4/8 bytes)
+!	argv[argc] = 0 (4/8 bytes)
+!	...
+!	argv[0] (4/8 bytes)
+!	argc (4/8 bytes)
+!	register save area (64 bits by 16 registers = 128 bytes)
+!	top of stack (%sp)
+
+! Stack Bias:
+!
+! It is the responsibility of the o/s to set this up.
+! We handle both a 0 and 2047 value for the stack bias.
+
+! Medium/Anywhere code model support:
+!
+! In this model %g4 points to the start of the data segment.
+! The text segment can go anywhere, but %g4 points to the *data* segment.
+! It is up to the compiler/linker to get this right.
+!
+! Since this model is statically linked the start of the data segment
+! is known at link time.  Eg:
+!
+!	sethi	%hh(data_start), %g1
+!	sethi	%lm(data_start), %g4
+!	or	%g1, %hm(data_start), %g1
+!	or	%g4, %lo(data_start), %g4
+!	sllx	%g1, 32, %g1
+!	or	%g4, %g1, %g4
+!
+! FIXME: For now we just assume 0.
+
+! FIXME: if %g1 contains a non-zero value, atexit() should be invoked
+! with this value.
+
+
+	.text
+	.align 4
+	.globl _start
+	.type _start, @function
+_start:
+	clr	%fp
+
+! We use %g4 even if the code model is Medium/Low (simplifies the code).
+
+	clr	%g4			! Medium/Anywhere base reg
+
+! If there is a stack bias in effect, account for it in %g5.  Then always
+! add %g5 to stack references below.  This way the code can be used with
+! or without an imposed bias.
+
+	andcc	%sp, 1, %g5
+	bz,a .LNoBias
+	 nop
+	mov	2047, %g5
+.LNoBias:
+	add	%sp, %g5, %g5
+
+! On entry, the kernel leaves room for one register frame, but
+! the C API wants more free space.  Thus, we need to drop the stack
+! pointer additionally.
+
+#if TARGET_PTR_SIZE == 32
+	sub	%sp, 32, %sp		! make room for incoming arguments
+#else /* TARGET_PTR_SIZE == 64 */
+	sub	%sp, 64, %sp		! make room for incoming arguments
+#endif
+
+! Set up pointers to the ELF data structure (argc, argv, ...)
+! Pass as the first argument to __libc_init
+#if TARGET_PTR_SIZE == 32
+	add	%g5, 0x40, %o0
+#else /* TARGET_PTR_SIZE == 64 */
+	add	%g5, 0x80, %o0
+#endif
+
+	call	__libc_init
+	 mov	%g1, %o1	! This is the "atexit" pointer;
+				! pass as the second argument to __libc_init
+
+! If __libc_init returns, something is hosed.  Try an illegal insn.
+! If that does not work, the o/s is hosed more than we are.
+	.long 0
diff --git a/usr/klibc/arch/sparc/divrem.m4 b/usr/klibc/arch/sparc/divrem.m4
new file mode 100644
index 0000000..aa4171d
--- /dev/null
+++ b/usr/klibc/arch/sparc/divrem.m4
@@ -0,0 +1,276 @@
+/*
+ * 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.
+ *
+ * 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.
+ *
+ * from: Header: divrem.m4,v 1.4 92/06/25 13:23:57 torek Exp
+ * $NetBSD: divrem.m4,v 1.4 1997/10/09 10:07:54 lukem Exp $
+ */
+
+/*
+ * Division and remainder, from Appendix E of the Sparc Version 8
+ * Architecture Manual, with fixes from Gordon Irlam.
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+	.asciz "@(#)divrem.m4	8.1 (Berkeley) 6/4/93"
+#endif /* LIBC_SCCS and not lint */
+
+/*
+ * Input: dividend and divisor in %o0 and %o1 respectively.
+ *
+ * m4 parameters:
+ *  NAME	name of function to generate
+ *  OP		OP=div => %o0 / %o1; OP=rem => %o0 % %o1
+ *  S		S=true => signed; S=false => unsigned
+ *
+ * Algorithm parameters:
+ *  N		how many bits per iteration we try to get (4)
+ *  WORDSIZE	total number of bits (32)
+ *
+ * Derived constants:
+ *  TWOSUPN	2^N, for label generation (m4 exponentiation currently broken)
+ *  TOPBITS	number of bits in the top `decade' of a number
+ *
+ * Important variables:
+ *  Q		the partial quotient under development (initially 0)
+ *  R		the remainder so far, initially the dividend
+ *  ITER	number of main division loop iterations required;
+ *		equal to ceil(log2(quotient) / N).  Note that this
+ *		is the log base (2^N) of the quotient.
+ *  V		the current comparand, initially divisor*2^(ITER*N-1)
+ *
+ * Cost:
+ *  Current estimate for non-large dividend is
+ *	ceil(log2(quotient) / N) * (10 + 7N/2) + C
+ *  A large dividend is one greater than 2^(31-TOPBITS) and takes a
+ *  different path, as the upper bits of the quotient must be developed
+ *  one bit at a time.
+ */
+
+define(N, `4')
+define(TWOSUPN, `16')
+define(WORDSIZE, `32')
+define(TOPBITS, eval(WORDSIZE - N*((WORDSIZE-1)/N)))
+
+define(dividend, `%o0')
+define(divisor, `%o1')
+define(Q, `%o2')
+define(R, `%o3')
+define(ITER, `%o4')
+define(V, `%o5')
+
+/* m4 reminder: ifelse(a,b,c,d) => if a is b, then c, else d */
+define(T, `%g1')
+define(SC, `%g7')
+ifelse(S, `true', `define(SIGN, `%g6')')
+
+/*
+ * This is the recursive definition for developing quotient digits.
+ *
+ * Parameters:
+ *  $1	the current depth, 1 <= $1 <= N
+ *  $2	the current accumulation of quotient bits
+ *  N	max depth
+ *
+ * We add a new bit to $2 and either recurse or insert the bits in
+ * the quotient.  R, Q, and V are inputs and outputs as defined above;
+ * the condition codes are expected to reflect the input R, and are
+ * modified to reflect the output R.
+ */
+define(DEVELOP_QUOTIENT_BITS,
+`	! depth $1, accumulated bits $2
+	bl	L.$1.eval(TWOSUPN+$2)
+	srl	V,1,V
+	! remainder is positive
+	subcc	R,V,R
+	ifelse($1, N,
+	`	b	9f
+		add	Q, ($2*2+1), Q
+	', `	DEVELOP_QUOTIENT_BITS(incr($1), `eval(2*$2+1)')')
+L.$1.eval(TWOSUPN+$2):
+	! remainder is negative
+	addcc	R,V,R
+	ifelse($1, N,
+	`	b	9f
+		add	Q, ($2*2-1), Q
+	', `	DEVELOP_QUOTIENT_BITS(incr($1), `eval(2*$2-1)')')
+	ifelse($1, 1, `9:')')
+
+#include <machine/asm.h>
+#include <machine/trap.h>
+
+FUNC(NAME)
+ifelse(S, `true',
+`	! compute sign of result; if neither is negative, no problem
+	orcc	divisor, dividend, %g0	! either negative?
+	bge	2f			! no, go do the divide
+	ifelse(OP, `div',
+		`xor	divisor, dividend, SIGN',
+		`mov	dividend, SIGN')	! compute sign in any case
+	tst	divisor
+	bge	1f
+	tst	dividend
+	! divisor is definitely negative; dividend might also be negative
+	bge	2f			! if dividend not negative...
+	neg	divisor			! in any case, make divisor nonneg
+1:	! dividend is negative, divisor is nonnegative
+	neg	dividend		! make dividend nonnegative
+2:
+')
+	! Ready to divide.  Compute size of quotient; scale comparand.
+	orcc	divisor, %g0, V
+	bnz	1f
+	mov	dividend, R
+
+		! Divide by zero trap.  If it returns, return 0 (about as
+		! wrong as possible, but that is what SunOS does...).
+		t	ST_DIV0
+		retl
+		clr	%o0
+
+1:
+	cmp	R, V			! if divisor exceeds dividend, done
+	blu	Lgot_result		! (and algorithm fails otherwise)
+	clr	Q
+	sethi	%hi(1 << (WORDSIZE - TOPBITS - 1)), T
+	cmp	R, T
+	blu	Lnot_really_big
+	clr	ITER
+
+	! `Here the dividend is >= 2^(31-N) or so.  We must be careful here,
+	! as our usual N-at-a-shot divide step will cause overflow and havoc.
+	! The number of bits in the result here is N*ITER+SC, where SC <= N.
+	! Compute ITER in an unorthodox manner: know we need to shift V into
+	! the top decade: so do not even bother to compare to R.'
+	1:
+		cmp	V, T
+		bgeu	3f
+		mov	1, SC
+		sll	V, N, V
+		b	1b
+		inc	ITER
+
+	! Now compute SC.
+	2:	addcc	V, V, V
+		bcc	Lnot_too_big
+		inc	SC
+
+		! We get here if the divisor overflowed while shifting.
+		! This means that R has the high-order bit set.
+		! Restore V and subtract from R.
+		sll	T, TOPBITS, T	! high order bit
+		srl	V, 1, V		! rest of V
+		add	V, T, V
+		b	Ldo_single_div
+		dec	SC
+
+	Lnot_too_big:
+	3:	cmp	V, R
+		blu	2b
+		nop
+		be	Ldo_single_div
+		nop
+	/* NB: these are commented out in the V8-Sparc manual as well */
+	/* (I do not understand this) */
+	! V > R: went too far: back up 1 step
+	!	srl	V, 1, V
+	!	dec	SC
+	! do single-bit divide steps
+	!
+	! We have to be careful here.  We know that R >= V, so we can do the
+	! first divide step without thinking.  BUT, the others are conditional,
+	! and are only done if R >= 0.  Because both R and V may have the high-
+	! order bit set in the first step, just falling into the regular
+	! division loop will mess up the first time around.
+	! So we unroll slightly...
+	Ldo_single_div:
+		deccc	SC
+		bl	Lend_regular_divide
+		nop
+		sub	R, V, R
+		mov	1, Q
+		b	Lend_single_divloop
+		nop
+	Lsingle_divloop:
+		sll	Q, 1, Q
+		bl	1f
+		srl	V, 1, V
+		! R >= 0
+		sub	R, V, R
+		b	2f
+		inc	Q
+	1:	! R < 0
+		add	R, V, R
+		dec	Q
+	2:
+	Lend_single_divloop:
+		deccc	SC
+		bge	Lsingle_divloop
+		tst	R
+		b,a	Lend_regular_divide
+
+Lnot_really_big:
+1:
+	sll	V, N, V
+	cmp	V, R
+	bleu	1b
+	inccc	ITER
+	be	Lgot_result
+	dec	ITER
+
+	tst	R	! set up for initial iteration
+Ldivloop:
+	sll	Q, N, Q
+	DEVELOP_QUOTIENT_BITS(1, 0)
+Lend_regular_divide:
+	deccc	ITER
+	bge	Ldivloop
+	tst	R
+	bl,a	Lgot_result
+	! non-restoring fixup here (one instruction only!)
+ifelse(OP, `div',
+`	dec	Q
+', `	add	R, divisor, R
+')
+
+Lgot_result:
+ifelse(S, `true',
+`	! check to see if answer should be < 0
+	tst	SIGN
+	bl,a	1f
+	ifelse(OP, `div', `neg Q', `neg R')
+1:')
+	retl
+	ifelse(OP, `div', `mov Q, %o0', `mov R, %o0')
diff --git a/usr/klibc/arch/sparc/pipe.S b/usr/klibc/arch/sparc/pipe.S
new file mode 100644
index 0000000..a8abf3c
--- /dev/null
+++ b/usr/klibc/arch/sparc/pipe.S
@@ -0,0 +1,30 @@
+/*
+ * arch/sparc/pipe.S
+ *
+ * The pipe system call are special on sparc[64]:
+ * they return the two file descriptors in %o0 and %o1.
+ */
+
+#include <asm/unistd.h>
+
+	.globl	pipe
+	.type	pipe,#function
+       	.align	4
+pipe:
+	mov	__NR_pipe, %g1
+	or	%o0, 0, %g4
+	t	0x10
+	bcc	1f
+	  nop
+	sethi	%hi(errno), %g4
+	or	%g4, %lo(errno), %g4
+	st	%o0,[%g4]
+	retl
+	  mov	-1, %o0
+1:
+	st	%o0,[%g4]
+	st	%o1,[%g4+4]
+	retl
+	  mov	0, %o0
+
+	.size pipe,.-pipe
diff --git a/usr/klibc/arch/sparc/setjmp.S b/usr/klibc/arch/sparc/setjmp.S
new file mode 100644
index 0000000..038ea78
--- /dev/null
+++ b/usr/klibc/arch/sparc/setjmp.S
@@ -0,0 +1,38 @@
+!
+! setjmp.S
+!
+! Basic setjmp/longjmp
+!
+! This code was based on the equivalent code in NetBSD
+!
+
+#include <machine/asm.h>
+#include <machine/trap.h>
+
+!
+! The jmp_buf contains the following entries:
+!   sp
+!   fp
+!   pc
+!
+ENTRY(setjmp)
+	st	%sp,[%o0+0]	! Callers stack pointer
+	st	%o7,[%o0+4]	! Return pc
+	st	%fp,[%o0+8]	! Frame pointer
+	retl			! Return
+	 clr	%o0		!  ...0
+
+ENTRY(longjmp)
+	sub	%sp, 64, %sp	! set up a local stack frame
+0:
+	t	ST_FLUSHWIN	! flush register windows out to memory
+	!
+	! We restore the saved stack pointer to %fp, then issue
+	! a restore instruction which will reload the register
+	! window from the stack.
+	!
+        ld      [%o0+4], %o7    /* restore return pc */
+        ld      [%o0+0], %fp    /* and stack pointer */
+
+        retl                    ! success, return %g6
+         restore        %o1, 0, %o0
diff --git a/usr/klibc/arch/sparc/smul.S b/usr/klibc/arch/sparc/smul.S
new file mode 100644
index 0000000..544ff6e
--- /dev/null
+++ b/usr/klibc/arch/sparc/smul.S
@@ -0,0 +1,160 @@
+/*	$NetBSD: mul.S,v 1.3 1997/07/16 14:37:42 christos 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.
+ *
+ * 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.
+ *
+ * from: Header: mul.s,v 1.5 92/06/25 13:24:03 torek Exp
+ */
+
+#include <machine/asm.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
+	.asciz "@(#)mul.s	8.1 (Berkeley) 6/4/93"
+#else
+	RCSID("$NetBSD: mul.S,v 1.3 1997/07/16 14:37:42 christos Exp $")
+#endif
+#endif /* LIBC_SCCS and not lint */
+
+/*
+ * Signed multiply, from Appendix E of the Sparc Version 8
+ * Architecture Manual.
+ *
+ * Returns %o0 * %o1 in %o1%o0 (i.e., %o1 holds the upper 32 bits of
+ * the 64-bit product).
+ *
+ * This code optimizes short (less than 13-bit) multiplies.
+ */
+
+FUNC(.mul)
+	mov	%o0, %y		! multiplier -> Y
+	andncc	%o0, 0xfff, %g0	! test bits 12..31
+	be	Lmul_shortway	! if zero, can do it the short way
+	andcc	%g0, %g0, %o4	! zero the partial product and clear N and V
+
+	/*
+	 * Long multiply.  32 steps, followed by a final shift step.
+	 */
+	mulscc	%o4, %o1, %o4	! 1
+	mulscc	%o4, %o1, %o4	! 2
+	mulscc	%o4, %o1, %o4	! 3
+	mulscc	%o4, %o1, %o4	! 4
+	mulscc	%o4, %o1, %o4	! 5
+	mulscc	%o4, %o1, %o4	! 6
+	mulscc	%o4, %o1, %o4	! 7
+	mulscc	%o4, %o1, %o4	! 8
+	mulscc	%o4, %o1, %o4	! 9
+	mulscc	%o4, %o1, %o4	! 10
+	mulscc	%o4, %o1, %o4	! 11
+	mulscc	%o4, %o1, %o4	! 12
+	mulscc	%o4, %o1, %o4	! 13
+	mulscc	%o4, %o1, %o4	! 14
+	mulscc	%o4, %o1, %o4	! 15
+	mulscc	%o4, %o1, %o4	! 16
+	mulscc	%o4, %o1, %o4	! 17
+	mulscc	%o4, %o1, %o4	! 18
+	mulscc	%o4, %o1, %o4	! 19
+	mulscc	%o4, %o1, %o4	! 20
+	mulscc	%o4, %o1, %o4	! 21
+	mulscc	%o4, %o1, %o4	! 22
+	mulscc	%o4, %o1, %o4	! 23
+	mulscc	%o4, %o1, %o4	! 24
+	mulscc	%o4, %o1, %o4	! 25
+	mulscc	%o4, %o1, %o4	! 26
+	mulscc	%o4, %o1, %o4	! 27
+	mulscc	%o4, %o1, %o4	! 28
+	mulscc	%o4, %o1, %o4	! 29
+	mulscc	%o4, %o1, %o4	! 30
+	mulscc	%o4, %o1, %o4	! 31
+	mulscc	%o4, %o1, %o4	! 32
+	mulscc	%o4, %g0, %o4	! final shift
+
+	! If %o0 was negative, the result is
+	!	(%o0 * %o1) + (%o1 << 32))
+	! We fix that here.
+
+	tst	%o0
+	bge	1f
+	rd	%y, %o0
+
+	! %o0 was indeed negative; fix upper 32 bits of result by subtracting
+	! %o1 (i.e., return %o4 - %o1 in %o1).
+	retl
+	sub	%o4, %o1, %o1
+
+1:
+	retl
+	mov	%o4, %o1
+
+Lmul_shortway:
+	/*
+	 * Short multiply.  12 steps, followed by a final shift step.
+	 * The resulting bits are off by 12 and (32-12) = 20 bit positions,
+	 * but there is no problem with %o0 being negative (unlike above).
+	 */
+	mulscc	%o4, %o1, %o4	! 1
+	mulscc	%o4, %o1, %o4	! 2
+	mulscc	%o4, %o1, %o4	! 3
+	mulscc	%o4, %o1, %o4	! 4
+	mulscc	%o4, %o1, %o4	! 5
+	mulscc	%o4, %o1, %o4	! 6
+	mulscc	%o4, %o1, %o4	! 7
+	mulscc	%o4, %o1, %o4	! 8
+	mulscc	%o4, %o1, %o4	! 9
+	mulscc	%o4, %o1, %o4	! 10
+	mulscc	%o4, %o1, %o4	! 11
+	mulscc	%o4, %o1, %o4	! 12
+	mulscc	%o4, %g0, %o4	! final shift
+
+	/*
+	 *  %o4 has 20 of the bits that should be in the low part of the
+	 * result; %y has the bottom 12 (as %y's top 12).  That is:
+	 *
+	 *	  %o4		    %y
+	 * +----------------+----------------+
+	 * | -12- |   -20-  | -12- |   -20-  |
+	 * +------(---------+------)---------+
+	 *  --hi-- ----low-part----
+	 *
+	 * The upper 12 bits of %o4 should be sign-extended to form the
+	 * high part of the product (i.e., highpart = %o4 >> 20).
+	 */
+
+	rd	%y, %o5
+	sll	%o4, 12, %o0	! shift middle bits left 12
+	srl	%o5, 20, %o5	! shift low bits right 20, zero fill at left
+	or	%o5, %o0, %o0	! construct low part of result
+	retl
+	sra	%o4, 20, %o1	! ... and extract high part of result
diff --git a/usr/klibc/arch/sparc/syscall.S b/usr/klibc/arch/sparc/syscall.S
new file mode 100644
index 0000000..c0273f7
--- /dev/null
+++ b/usr/klibc/arch/sparc/syscall.S
@@ -0,0 +1,19 @@
+/*
+ * arch/sparc/syscall.S
+ *
+ * Common system-call stub; %g1 already set to syscall number
+ */
+
+	.globl	__syscall_common
+	.type	__syscall_common,#function
+       	.align	4
+__syscall_common:
+	t	0x10
+	bcc	1f
+	  sethi	%hi(errno), %g4
+	or	%g4, %lo(errno), %g4
+	st	%o0,[%g4]
+	mov	-1, %o0
+1:
+       	retl
+	  nop
diff --git a/usr/klibc/arch/sparc/sysfork.S b/usr/klibc/arch/sparc/sysfork.S
new file mode 100644
index 0000000..a66c76e
--- /dev/null
+++ b/usr/klibc/arch/sparc/sysfork.S
@@ -0,0 +1,25 @@
+/*
+ * arch/sparc/sysfork.S
+ *
+ * The fork and vfork system calls are special on sparc[64]:
+ * they return the "other process" pid in %o0 and the
+ * "is child" flag in %o1
+ *
+ * Common system-call stub; %g1 already set to syscall number
+ */
+
+	.globl	__syscall_forkish
+	.type	__syscall_forkish,#function
+       	.align	4
+__syscall_forkish:
+	t	0x10
+	sub	%o1, 1, %o1
+	bcc,a	1f
+	  and	%o0, %o1, %o0
+	sethi	%hi(errno), %g4
+	or	%g4, %lo(errno), %g4
+	st	%o0,[%g4]
+	mov	-1, %o0
+1:
+       	retl
+	  nop
diff --git a/usr/klibc/arch/sparc/sysstub.ph b/usr/klibc/arch/sparc/sysstub.ph
new file mode 100644
index 0000000..d8cedb5
--- /dev/null
+++ b/usr/klibc/arch/sparc/sysstub.ph
@@ -0,0 +1,25 @@
+# -*- perl -*-
+#
+# arch/sparc32/sysstub.ph
+#
+# Script to generate system call stubs
+#
+
+sub make_sysstub($$$$$@) {
+    my($outputdir, $fname, $type, $sname, $stype, @args) = @_;
+
+    $stype = $stype || 'common';
+
+    open(OUT, '>', "${outputdir}/${fname}.S");
+    print OUT "#include <asm/unistd.h>\n";
+    print OUT "\n";
+    print OUT "\t.type ${fname},\@function\n";
+    print OUT "\t.globl ${fname}\n";
+    print OUT "${fname}:\n";
+    print OUT "\tb __syscall_${stype}\n";
+    print OUT "\t  mov\t__NR_${sname}, %g1\n";
+    print OUT "\t.size ${fname},.-${fname}\n";
+    close(OUT);
+}
+
+1;
diff --git a/usr/klibc/arch/sparc/umul.S b/usr/klibc/arch/sparc/umul.S
new file mode 100644
index 0000000..6a7193d
--- /dev/null
+++ b/usr/klibc/arch/sparc/umul.S
@@ -0,0 +1,193 @@
+/*	$NetBSD: umul.S,v 1.3 1997/07/16 14:37:44 christos 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.
+ *
+ * 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.
+ *
+ * from: Header: umul.s,v 1.4 92/06/25 13:24:05 torek Exp
+ */
+
+#include <machine/asm.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
+	.asciz "@(#)umul.s	8.1 (Berkeley) 6/4/93"
+#else
+	RCSID("$NetBSD: umul.S,v 1.3 1997/07/16 14:37:44 christos Exp $")
+#endif
+#endif /* LIBC_SCCS and not lint */
+
+/*
+ * Unsigned multiply.  Returns %o0 * %o1 in %o1%o0 (i.e., %o1 holds the
+ * upper 32 bits of the 64-bit product).
+ *
+ * This code optimizes short (less than 13-bit) multiplies.  Short
+ * multiplies require 25 instruction cycles, and long ones require
+ * 45 instruction cycles.
+ *
+ * On return, overflow has occurred (%o1 is not zero) if and only if
+ * the Z condition code is clear, allowing, e.g., the following:
+ *
+ *	call	.umul
+ *	nop
+ *	bnz	overflow	(or tnz)
+ */
+
+FUNC(.umul)
+	or	%o0, %o1, %o4
+	mov	%o0, %y		! multiplier -> Y
+	andncc	%o4, 0xfff, %g0	! test bits 12..31 of *both* args
+	be	Lmul_shortway	! if zero, can do it the short way
+	andcc	%g0, %g0, %o4	! zero the partial product and clear N and V
+
+	/*
+	 * Long multiply.  32 steps, followed by a final shift step.
+	 */
+	mulscc	%o4, %o1, %o4	! 1
+	mulscc	%o4, %o1, %o4	! 2
+	mulscc	%o4, %o1, %o4	! 3
+	mulscc	%o4, %o1, %o4	! 4
+	mulscc	%o4, %o1, %o4	! 5
+	mulscc	%o4, %o1, %o4	! 6
+	mulscc	%o4, %o1, %o4	! 7
+	mulscc	%o4, %o1, %o4	! 8
+	mulscc	%o4, %o1, %o4	! 9
+	mulscc	%o4, %o1, %o4	! 10
+	mulscc	%o4, %o1, %o4	! 11
+	mulscc	%o4, %o1, %o4	! 12
+	mulscc	%o4, %o1, %o4	! 13
+	mulscc	%o4, %o1, %o4	! 14
+	mulscc	%o4, %o1, %o4	! 15
+	mulscc	%o4, %o1, %o4	! 16
+	mulscc	%o4, %o1, %o4	! 17
+	mulscc	%o4, %o1, %o4	! 18
+	mulscc	%o4, %o1, %o4	! 19
+	mulscc	%o4, %o1, %o4	! 20
+	mulscc	%o4, %o1, %o4	! 21
+	mulscc	%o4, %o1, %o4	! 22
+	mulscc	%o4, %o1, %o4	! 23
+	mulscc	%o4, %o1, %o4	! 24
+	mulscc	%o4, %o1, %o4	! 25
+	mulscc	%o4, %o1, %o4	! 26
+	mulscc	%o4, %o1, %o4	! 27
+	mulscc	%o4, %o1, %o4	! 28
+	mulscc	%o4, %o1, %o4	! 29
+	mulscc	%o4, %o1, %o4	! 30
+	mulscc	%o4, %o1, %o4	! 31
+	mulscc	%o4, %o1, %o4	! 32
+	mulscc	%o4, %g0, %o4	! final shift
+
+
+	/*
+	 * Normally, with the shift-and-add approach, if both numbers are
+	 * positive you get the correct result.  WIth 32-bit two's-complement
+	 * numbers, -x is represented as
+	 *
+	 *		  x		    32
+	 *	( 2  -  ------ ) mod 2  *  2
+	 *		   32
+	 *		  2
+	 *
+	 * (the `mod 2' subtracts 1 from 1.bbbb).  To avoid lots of 2^32s,
+	 * we can treat this as if the radix point were just to the left
+	 * of the sign bit (multiply by 2^32), and get
+	 *
+	 *	-x  =  (2 - x) mod 2
+	 *
+	 * Then, ignoring the `mod 2's for convenience:
+	 *
+	 *   x *  y	= xy
+	 *  -x *  y	= 2y - xy
+	 *   x * -y	= 2x - xy
+	 *  -x * -y	= 4 - 2x - 2y + xy
+	 *
+	 * For signed multiplies, we subtract (x << 32) from the partial
+	 * product to fix this problem for negative multipliers (see mul.s).
+	 * Because of the way the shift into the partial product is calculated
+	 * (N xor V), this term is automatically removed for the multiplicand,
+	 * so we don't have to adjust.
+	 *
+	 * But for unsigned multiplies, the high order bit wasn't a sign bit,
+	 * and the correction is wrong.  So for unsigned multiplies where the
+	 * high order bit is one, we end up with xy - (y << 32).  To fix it
+	 * we add y << 32.
+	 */
+	tst	%o1
+	bl,a	1f		! if %o1 < 0 (high order bit = 1),
+	add	%o4, %o0, %o4	! %o4 += %o0 (add y to upper half)
+1:	rd	%y, %o0		! get lower half of product
+	retl
+	addcc	%o4, %g0, %o1	! put upper half in place and set Z for %o1==0
+
+Lmul_shortway:
+	/*
+	 * Short multiply.  12 steps, followed by a final shift step.
+	 * The resulting bits are off by 12 and (32-12) = 20 bit positions,
+	 * but there is no problem with %o0 being negative (unlike above),
+	 * and overflow is impossible (the answer is at most 24 bits long).
+	 */
+	mulscc	%o4, %o1, %o4	! 1
+	mulscc	%o4, %o1, %o4	! 2
+	mulscc	%o4, %o1, %o4	! 3
+	mulscc	%o4, %o1, %o4	! 4
+	mulscc	%o4, %o1, %o4	! 5
+	mulscc	%o4, %o1, %o4	! 6
+	mulscc	%o4, %o1, %o4	! 7
+	mulscc	%o4, %o1, %o4	! 8
+	mulscc	%o4, %o1, %o4	! 9
+	mulscc	%o4, %o1, %o4	! 10
+	mulscc	%o4, %o1, %o4	! 11
+	mulscc	%o4, %o1, %o4	! 12
+	mulscc	%o4, %g0, %o4	! final shift
+
+	/*
+	 * %o4 has 20 of the bits that should be in the result; %y has
+	 * the bottom 12 (as %y's top 12).  That is:
+	 *
+	 *	  %o4		    %y
+	 * +----------------+----------------+
+	 * | -12- |   -20-  | -12- |   -20-  |
+	 * +------(---------+------)---------+
+	 *	   -----result-----
+	 *
+	 * The 12 bits of %o4 left of the `result' area are all zero;
+	 * in fact, all top 20 bits of %o4 are zero.
+	 */
+
+	rd	%y, %o5
+	sll	%o4, 12, %o0	! shift middle bits left 12
+	srl	%o5, 20, %o5	! shift low bits right 20
+	or	%o5, %o0, %o0
+	retl
+	addcc	%g0, %g0, %o1	! %o1 = zero, and set Z

^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [klibc 19/31] sparc64 support for klibc
  2006-06-28  5:17 [klibc 00/31] klibc as a historyless patchset (updated and reorganized) H. Peter Anvin
                   ` (17 preceding siblings ...)
  2006-06-28  5:17 ` [klibc 18/31] sparc " H. Peter Anvin
@ 2006-06-28  5:17 ` H. Peter Anvin
  2006-06-28  5:17 ` [klibc 20/31] x86_64 " H. Peter Anvin
                   ` (11 subsequent siblings)
  30 siblings, 0 replies; 58+ messages in thread
From: H. Peter Anvin @ 2006-06-28  5:17 UTC (permalink / raw)
  To: linux-kernel, klibc; +Cc: H. Peter Anvin

The parts of klibc specific to the sparc64 architecture.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>

---
commit 7c310aab57acc9d134a8d07158d65f74b98a5649
tree 172bc41c395a16e0e3abd9a4b3166c6894d50eb5
parent 0b300030e6549258be2bf57cb5ac4d6cedd05786
author H. Peter Anvin <hpa@zytor.com> Tue, 27 Jun 2006 20:51:01 -0700
committer H. Peter Anvin <hpa@zytor.com> Tue, 27 Jun 2006 20:51:01 -0700

 usr/include/arch/sparc64/klibc/archconfig.h |   15 +++++++
 usr/include/arch/sparc64/klibc/archsetjmp.h |   16 ++++++++
 usr/include/arch/sparc64/klibc/archsignal.h |   17 ++++++++
 usr/include/arch/sparc64/klibc/archstat.h   |   30 +++++++++++++++
 usr/klibc/arch/sparc64/MCONFIG              |   21 ++++++++++
 usr/klibc/arch/sparc64/Makefile.inc         |   16 ++++++++
 usr/klibc/arch/sparc64/crt0.S               |    2 +
 usr/klibc/arch/sparc64/pipe.S               |   30 +++++++++++++++
 usr/klibc/arch/sparc64/setjmp.S             |   55 +++++++++++++++++++++++++++
 usr/klibc/arch/sparc64/syscall.S            |   18 +++++++++
 usr/klibc/arch/sparc64/sysfork.S            |   26 +++++++++++++
 usr/klibc/arch/sparc64/sysstub.ph           |   25 ++++++++++++
 12 files changed, 271 insertions(+), 0 deletions(-)

diff --git a/usr/include/arch/sparc64/klibc/archconfig.h b/usr/include/arch/sparc64/klibc/archconfig.h
new file mode 100644
index 0000000..bb0c003
--- /dev/null
+++ b/usr/include/arch/sparc64/klibc/archconfig.h
@@ -0,0 +1,15 @@
+/*
+ * include/arch/sparc64/klibc/archconfig.h
+ *
+ * See include/klibc/sysconfig.h for the options that can be set in
+ * this file.
+ *
+ */
+
+#ifndef _KLIBC_ARCHCONFIG_H
+#define _KLIBC_ARCHCONFIG_H
+
+#define _KLIBC_USE_RT_SIG 1	/* Use rt_* signals */
+#define _KLIBC_NEEDS_SA_RESTORER 1 /* Need a restorer function */
+
+#endif				/* _KLIBC_ARCHCONFIG_H */
diff --git a/usr/include/arch/sparc64/klibc/archsetjmp.h b/usr/include/arch/sparc64/klibc/archsetjmp.h
new file mode 100644
index 0000000..9e825bd
--- /dev/null
+++ b/usr/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/usr/include/arch/sparc64/klibc/archsignal.h b/usr/include/arch/sparc64/klibc/archsignal.h
new file mode 100644
index 0000000..bb0a5ce
--- /dev/null
+++ b/usr/include/arch/sparc64/klibc/archsignal.h
@@ -0,0 +1,17 @@
+/*
+ * arch/sparc64/include/klibc/archsignal.h
+ *
+ * Architecture-specific signal definitions
+ *
+ */
+
+#ifndef _KLIBC_ARCHSIGNAL_H
+#define _KLIBC_ARCHSIGNAL_H
+
+#define __WANT_POSIX1B_SIGNALS__
+#include <asm/signal.h>
+
+/* Not actually used by the kernel... */
+#define SA_RESTORER	0x80000000
+
+#endif
diff --git a/usr/include/arch/sparc64/klibc/archstat.h b/usr/include/arch/sparc64/klibc/archstat.h
new file mode 100644
index 0000000..56fb2a4
--- /dev/null
+++ b/usr/include/arch/sparc64/klibc/archstat.h
@@ -0,0 +1,30 @@
+#ifndef _KLIBC_ARCHSTAT_H
+#define _KLIBC_ARCHSTAT_H
+
+#include <klibc/stathelp.h>
+
+#define _STATBUF_ST_NSEC
+
+struct stat {
+	__stdev64	(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;
+
+	__stdev64 (st_rdev);
+	long		st_size;
+	long		st_blksize;
+	long		st_blocks;
+
+	struct timespec st_atim;
+	struct timespec st_mtim;
+	struct timespec st_ctim;
+
+	unsigned long __unused[3];
+};
+
+#endif
diff --git a/usr/klibc/arch/sparc64/MCONFIG b/usr/klibc/arch/sparc64/MCONFIG
new file mode 100644
index 0000000..443250a
--- /dev/null
+++ b/usr/klibc/arch/sparc64/MCONFIG
@@ -0,0 +1,21 @@
+# -*- makefile -*-
+#
+# arch/sparc64/MCONFIG
+#
+# Special rules for this architecture.  Note that this is actually
+# included from the main Makefile, and that pathnames should be
+# accordingly.
+#
+
+KLIBCARCHREQFLAGS = -m64 -mptr64 -D__sparc64__
+KLIBCOPTFLAGS     = -Os
+KLIBCBITSIZE      = 64
+
+KLIBCLDFLAGS      = -m elf64_sparc
+
+# Extra linkflags when building the shared version of the library
+# This address needs to be reachable using normal inter-module
+# calls, and work on the memory models for this architecture
+# Normal binaries start at 1 MB; the linker wants 1 MB alignment,
+# and call instructions have a 30-bit signed offset, << 2.
+KLIBCSHAREDFLAGS	= -Ttext 0x80000200
diff --git a/usr/klibc/arch/sparc64/Makefile.inc b/usr/klibc/arch/sparc64/Makefile.inc
new file mode 100644
index 0000000..1641f51
--- /dev/null
+++ b/usr/klibc/arch/sparc64/Makefile.inc
@@ -0,0 +1,16 @@
+# -*- makefile -*-
+#
+# arch/sparc64/Makefile.inc
+#
+# Special rules for this architecture.  Note that this is actually
+# included from the main Makefile, and that pathnames should be
+# accordingly.
+#
+
+KLIBCARCHOBJS = \
+	arch/$(KLIBCARCH)/pipe.o \
+	arch/$(KLIBCARCH)/setjmp.o \
+	arch/$(KLIBCARCH)/syscall.o \
+	arch/$(KLIBCARCH)/sysfork.o
+
+archclean:
diff --git a/usr/klibc/arch/sparc64/crt0.S b/usr/klibc/arch/sparc64/crt0.S
new file mode 100644
index 0000000..5faee7c
--- /dev/null
+++ b/usr/klibc/arch/sparc64/crt0.S
@@ -0,0 +1,2 @@
+#define TARGET_PTR_SIZE 64
+#include "../sparc/crt0i.S"
diff --git a/usr/klibc/arch/sparc64/pipe.S b/usr/klibc/arch/sparc64/pipe.S
new file mode 100644
index 0000000..c63b20f
--- /dev/null
+++ b/usr/klibc/arch/sparc64/pipe.S
@@ -0,0 +1,30 @@
+/*
+ * arch/sparc64/pipe.S
+ *
+ * The pipe system call are special on sparc[64]:
+ * they return the two file descriptors in %o0 and %o1.
+ */
+
+#include <asm/unistd.h>
+
+	.globl	pipe
+	.type	pipe,#function
+       	.align	4
+pipe:
+	mov	__NR_pipe, %g1
+	or	%o0, 0, %g4
+	t	0x6d
+	bcc	%xcc, 1f
+	  nop
+	sethi	%hi(errno), %g4
+	or	%g4, %lo(errno), %g4
+	st	%o0,[%g4]
+	retl
+	  mov	-1, %o0
+1:
+	st	%o0,[%g4]
+	st	%o1,[%g4+4]
+	retl
+	  mov	0, %o0
+
+	.size pipe,.-pipe
diff --git a/usr/klibc/arch/sparc64/setjmp.S b/usr/klibc/arch/sparc64/setjmp.S
new file mode 100644
index 0000000..75a6a68
--- /dev/null
+++ b/usr/klibc/arch/sparc64/setjmp.S
@@ -0,0 +1,55 @@
+!
+! setjmp.S
+!
+! Basic setjmp/longjmp
+!
+! This code was based on the equivalent code in NetBSD
+!
+
+!
+! The jmp_buf contains the following entries:
+!   sp
+!   fp
+!   pc
+!
+	.text
+	.align	4
+	.global	setjmp
+	.type	setjmp, @function
+setjmp:
+	stx	%sp,[%o0+0]	! Callers stack pointer
+	stx	%o7,[%o0+8]	! Return pc
+	stx	%fp,[%o0+16]	! Frame pointer
+	retl			! Return
+	 clr	%o0		!  ...0
+
+	.size	setjmp,.-setjmp
+
+
+       	.globl	longjmp
+	.type	longjmp, @function
+longjmp:
+	mov	%o1, %g4	! save return value
+	mov	%o0, %g1	! save target
+	ldx	[%g1+16],%g5	! get callers frame
+1:
+	cmp	%fp, %g5	! compare against desired frame
+	bl,a	1b		! if below...
+	 restore		! pop frame and loop
+	be,a	2f		! if there...
+       	 ldx	[%g1+0],%o2	! fetch return %sp
+
+.Lbotch:
+	unimp	0		! ... error ...
+
+2:
+       	cmp	%o2, %sp	! %sp must not decrease
+	bl	.Lbotch
+	 nop
+	mov	%o2, %sp	! it is OK, put it in place
+
+	ldx	[%g1+8],%o3	! fetch %pc
+	jmp	%o3 + 8		! if sucess...
+	 mov	%g4,%o0		!   return %g4
+
+	.size	longjmp,.-longjmp
diff --git a/usr/klibc/arch/sparc64/syscall.S b/usr/klibc/arch/sparc64/syscall.S
new file mode 100644
index 0000000..7ab9d95
--- /dev/null
+++ b/usr/klibc/arch/sparc64/syscall.S
@@ -0,0 +1,18 @@
+/*
+ * arch/sparc64/syscall.S
+ *
+ * Common system-call stub; %g1 already set to syscall number
+ */
+
+	.globl	__syscall_common
+	.type	__syscall_common,#function
+       	.align	4
+__syscall_common:
+	t	0x6d
+	bcc	%xcc, 1f
+	  sethi	%hi(errno), %g4
+	or	%g4, %lo(errno), %g4
+	st	%o0,[%g4]
+1:
+       	retl
+	  movcs	%xcc, -1, %o0
diff --git a/usr/klibc/arch/sparc64/sysfork.S b/usr/klibc/arch/sparc64/sysfork.S
new file mode 100644
index 0000000..2eed659
--- /dev/null
+++ b/usr/klibc/arch/sparc64/sysfork.S
@@ -0,0 +1,26 @@
+/*
+ * arch/sparc64/sysfork.S
+ *
+ * The fork and vfork system calls are special on sparc[64]:
+ * they return the "other process" pid in %o0 and the
+ * "is child" flag in %o1
+ *
+ * Common system-call stub; %g1 already set to syscall number
+ */
+
+	.globl	__syscall_forkish
+	.type	__syscall_forkish,#function
+       	.align	4
+__syscall_forkish:
+	t	0x6d
+	sub	%o1, 1, %o1
+	bcc,a	%xcc, 1f
+	  and	%o0, %o1, %o0
+	sethi	%hi(errno), %g4
+	or	%g4, %lo(errno), %g4
+	st	%o0, [%g4]
+	retl
+	  mov	-1, %o0
+1:
+       	retl
+	  nop
diff --git a/usr/klibc/arch/sparc64/sysstub.ph b/usr/klibc/arch/sparc64/sysstub.ph
new file mode 100644
index 0000000..deeb88c
--- /dev/null
+++ b/usr/klibc/arch/sparc64/sysstub.ph
@@ -0,0 +1,25 @@
+# -*- perl -*-
+#
+# arch/sparc64/sysstub.ph
+#
+# Script to generate system call stubs
+#
+
+sub make_sysstub($$$$$@) {
+    my($outputdir, $fname, $type, $sname, $stype, @args) = @_;
+
+    $stype = $stype || 'common';
+
+    open(OUT, '>', "${outputdir}/${fname}.S");
+    print OUT "#include <asm/unistd.h>\n";
+    print OUT "\n";
+    print OUT "\t.type ${fname},\@function\n";
+    print OUT "\t.globl ${fname}\n";
+    print OUT "${fname}:\n";
+    print OUT "\tb __syscall_${stype}\n";
+    print OUT "\t  mov\t__NR_${sname}, %g1\n";
+    print OUT "\t.size ${fname},.-${fname}\n";
+    close(OUT);
+}
+
+1;

^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [klibc 20/31] x86_64 support for klibc
  2006-06-28  5:17 [klibc 00/31] klibc as a historyless patchset (updated and reorganized) H. Peter Anvin
                   ` (18 preceding siblings ...)
  2006-06-28  5:17 ` [klibc 19/31] sparc64 " H. Peter Anvin
@ 2006-06-28  5:17 ` H. Peter Anvin
  2006-06-28  5:17 ` [klibc 21/31] Simple test suite " H. Peter Anvin
                   ` (10 subsequent siblings)
  30 siblings, 0 replies; 58+ messages in thread
From: H. Peter Anvin @ 2006-06-28  5:17 UTC (permalink / raw)
  To: linux-kernel, klibc; +Cc: H. Peter Anvin

The parts of klibc specific to the x86_64 architecture.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>

---
commit d82530df7a105851818935b622e20165f994d3f1
tree 977f0df743a96d23675b3504d4837ca3b3d5a92a
parent 7c310aab57acc9d134a8d07158d65f74b98a5649
author H. Peter Anvin <hpa@zytor.com> Tue, 27 Jun 2006 20:51:03 -0700
committer H. Peter Anvin <hpa@zytor.com> Tue, 27 Jun 2006 20:51:03 -0700

 usr/include/arch/x86_64/klibc/archconfig.h |   15 +++
 usr/include/arch/x86_64/klibc/archsetjmp.h |   21 +++++
 usr/include/arch/x86_64/klibc/archsignal.h |   18 ++++
 usr/include/arch/x86_64/klibc/archstat.h   |   28 ++++++
 usr/include/arch/x86_64/sys/io.h           |  127 ++++++++++++++++++++++++++++
 usr/klibc/arch/x86_64/MCONFIG              |   35 ++++++++
 usr/klibc/arch/x86_64/Makefile.inc         |   18 ++++
 usr/klibc/arch/x86_64/crt0.S               |   22 +++++
 usr/klibc/arch/x86_64/setjmp.S             |   54 ++++++++++++
 usr/klibc/arch/x86_64/sigreturn.S          |   15 +++
 usr/klibc/arch/x86_64/syscall.S            |   28 ++++++
 usr/klibc/arch/x86_64/sysstub.ph           |   23 +++++
 usr/klibc/arch/x86_64/vfork.S              |   26 ++++++
 13 files changed, 430 insertions(+), 0 deletions(-)

diff --git a/usr/include/arch/x86_64/klibc/archconfig.h b/usr/include/arch/x86_64/klibc/archconfig.h
new file mode 100644
index 0000000..b8a2a6d
--- /dev/null
+++ b/usr/include/arch/x86_64/klibc/archconfig.h
@@ -0,0 +1,15 @@
+/*
+ * include/arch/x86_64/klibc/archconfig.h
+ *
+ * See include/klibc/sysconfig.h for the options that can be set in
+ * this file.
+ *
+ */
+
+#ifndef _KLIBC_ARCHCONFIG_H
+#define _KLIBC_ARCHCONFIG_H
+
+/* x86-64 doesn't provide a default sigreturn. */
+#define _KLIBC_NEEDS_SA_RESTORER 1
+
+#endif				/* _KLIBC_ARCHCONFIG_H */
diff --git a/usr/include/arch/x86_64/klibc/archsetjmp.h b/usr/include/arch/x86_64/klibc/archsetjmp.h
new file mode 100644
index 0000000..454fc60
--- /dev/null
+++ b/usr/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/usr/include/arch/x86_64/klibc/archsignal.h b/usr/include/arch/x86_64/klibc/archsignal.h
new file mode 100644
index 0000000..6c8ec77
--- /dev/null
+++ b/usr/include/arch/x86_64/klibc/archsignal.h
@@ -0,0 +1,18 @@
+/*
+ * arch/x86_64/include/klibc/archsignal.h
+ *
+ * Architecture-specific signal definitions
+ *
+ */
+
+#ifndef _KLIBC_ARCHSIGNAL_H
+#define _KLIBC_ARCHSIGNAL_H
+
+#include <asm/signal.h>
+/* The x86-64 headers defines NSIG 32, but it's actually 64 */
+#undef  _NSIG
+#undef  NSIG
+#define _NSIG 64
+#define NSIG  _NSIG
+
+#endif
diff --git a/usr/include/arch/x86_64/klibc/archstat.h b/usr/include/arch/x86_64/klibc/archstat.h
new file mode 100644
index 0000000..de168ac
--- /dev/null
+++ b/usr/include/arch/x86_64/klibc/archstat.h
@@ -0,0 +1,28 @@
+#ifndef _KLIBC_ARCHSTAT_H
+#define _KLIBC_ARCHSTAT_H
+
+#include <klibc/stathelp.h>
+
+#define _STATBUF_ST_NSEC
+
+struct stat {
+	__stdev64	(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;
+	__stdev64	(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/usr/include/arch/x86_64/sys/io.h b/usr/include/arch/x86_64/sys/io.h
new file mode 100644
index 0000000..2a0ca48
--- /dev/null
+++ b/usr/include/arch/x86_64/sys/io.h
@@ -0,0 +1,127 @@
+/* ----------------------------------------------------------------------- *
+ *
+ *   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/usr/klibc/arch/x86_64/MCONFIG b/usr/klibc/arch/x86_64/MCONFIG
new file mode 100644
index 0000000..edcd638
--- /dev/null
+++ b/usr/klibc/arch/x86_64/MCONFIG
@@ -0,0 +1,35 @@
+# -*- makefile -*-
+#
+# arch/x86-64/MCONFIG
+#
+# Special rules for this architecture.  Note that this is actually
+# included from the main Makefile, and that pathnames should be
+# accordingly.
+#
+# Blatantly copied and modified from i386 version by Mats Petersson, AMD.
+#
+
+#
+# NOTE: -fno-asynchronous-unwind-tables produce significantly smaller
+# binaries (20% smaller), but makes the code completely useless for
+# debugging using gdb.
+#
+KLIBCARCHREQFLAGS = -m64
+ifeq ($(DEBUG),y)
+KLIBCOPTFLAGS     = -Os -fomit-frame-pointer \
+		-falign-functions=1 -falign-jumps=1 -falign-loops=1
+else
+KLIBCOPTFLAGS     = -Os -fno-asynchronous-unwind-tables -fomit-frame-pointer \
+		-falign-functions=1 -falign-jumps=1 -falign-loops=1
+endif
+KLIBCBITSIZE      = 64
+KLIBCLDFLAGS      = -m elf_x86_64
+
+# Extra linkflags when building the shared version of the library
+# This address needs to be reachable using normal inter-module
+# calls, and work on the memory models for this architecture
+# 2 MB - normal binaries start at 4 MB
+KLIBCSHAREDFLAGS     = -Ttext 0x00200200
+
+# Additional asm- directories needed during installation
+ASMARCH = asm-i386
diff --git a/usr/klibc/arch/x86_64/Makefile.inc b/usr/klibc/arch/x86_64/Makefile.inc
new file mode 100644
index 0000000..4bfe56a
--- /dev/null
+++ b/usr/klibc/arch/x86_64/Makefile.inc
@@ -0,0 +1,18 @@
+# -*- makefile -*-
+#
+# arch/x86_64/Makefile.inc
+#
+# Special rules for this architecture.  Note that this is actually
+# included from the main Makefile, and that pathnames should be
+# accordingly.
+#
+
+KLIBCARCHOBJS = \
+	arch/$(KLIBCARCH)/setjmp.o \
+	arch/$(KLIBCARCH)/syscall.o \
+	arch/$(KLIBCARCH)/sigreturn.o \
+	arch/$(KLIBCARCH)/vfork.o
+
+KLIBCARCHSOOBJS = $(patsubst %.o,%.lo,$(KLIBCARCHOBJS))
+
+archclean:
diff --git a/usr/klibc/arch/x86_64/crt0.S b/usr/klibc/arch/x86_64/crt0.S
new file mode 100644
index 0000000..6a5f335
--- /dev/null
+++ b/usr/klibc/arch/x86_64/crt0.S
@@ -0,0 +1,22 @@
+#
+# arch/x86_64/crt0.S
+#
+# Does arch-specific initialization and invokes __libc_init
+# with the appropriate arguments.
+#
+# See __static_init.c or __shared_init.c for the expected
+# arguments.
+#
+
+	.text
+	.align 4
+	.type _start,@function
+	.globl _start
+_start:
+	movq %rsp,%rdi			# Offset of the ELF data structure
+	movq %rdx,%rsi			# The atexit() pointer (if any)
+	call __libc_init
+	# We should never get here...
+	hlt
+
+	.size _start,.-_start
diff --git a/usr/klibc/arch/x86_64/setjmp.S b/usr/klibc/arch/x86_64/setjmp.S
new file mode 100644
index 0000000..45f547b
--- /dev/null
+++ b/usr/klibc/arch/x86_64/setjmp.S
@@ -0,0 +1,54 @@
+#
+# arch/x86_64/setjmp.S
+#
+# setjmp/longjmp for the x86-64 architecture
+#
+
+#
+# The jmp_buf is assumed to contain the following, in order:
+#	%rbx
+#	%rsp (post-return)
+#	%rbp
+#	%r12
+#	%r13
+#	%r14
+#	%r15
+#	<return address>
+#
+
+	.text
+	.align 4
+	.globl setjmp
+	.type setjmp, @function
+setjmp:
+	pop  %rsi			# Return address, and adjust the stack
+	xorl %eax,%eax			# Return value
+	movq %rbx,(%rdi)
+	movq %rsp,8(%rdi)		# Post-return %rsp!
+	push %rsi			# Make the call/return stack happy
+	movq %rbp,16(%rdi)
+	movq %r12,24(%rdi)
+	movq %r13,32(%rdi)
+	movq %r14,40(%rdi)
+	movq %r15,48(%rdi)
+	movq %rsi,56(%rdi)		# Return address
+	ret
+
+	.size setjmp,.-setjmp
+
+	.text
+	.align 4
+	.globl longjmp
+	.type longjmp, @function
+longjmp:
+	movl %esi,%eax			# Return value (int)
+	movq (%rdi),%rbx
+	movq 8(%rdi),%rsp
+	movq 16(%rdi),%rbp
+	movq 24(%rdi),%r12
+	movq 32(%rdi),%r13
+	movq 40(%rdi),%r14
+	movq 48(%rdi),%r15
+	jmp *56(%rdi)
+
+	.size longjmp,.-longjmp
diff --git a/usr/klibc/arch/x86_64/sigreturn.S b/usr/klibc/arch/x86_64/sigreturn.S
new file mode 100644
index 0000000..46a5a0b
--- /dev/null
+++ b/usr/klibc/arch/x86_64/sigreturn.S
@@ -0,0 +1,15 @@
+/*
+ * arch/x86_64/sigreturn.S
+ */
+
+#include <asm/unistd.h>
+
+	.text
+	.align	4
+	.globl	__sigreturn
+	.type	__sigreturn,@function
+__sigreturn:
+	movl	$__NR_rt_sigreturn,%eax
+	syscall
+
+	.size	__sigreturn,.-__sigreturn
diff --git a/usr/klibc/arch/x86_64/syscall.S b/usr/klibc/arch/x86_64/syscall.S
new file mode 100644
index 0000000..1797797
--- /dev/null
+++ b/usr/klibc/arch/x86_64/syscall.S
@@ -0,0 +1,28 @@
+/*
+ * arch/x86-64/syscall.S
+ *
+ * Common tail-handling code for system calls.
+ *
+ * The arguments are in the standard argument registers; the system
+ * call number in %eax.
+ */
+	.text
+	.align	4
+	.globl	__syscall_common
+	.type	__syscall_common,@function
+__syscall_common:
+	movq	%rcx,%r10		# The kernel uses %r10 istf %rcx
+	syscall
+
+	cmpq	$-4095,%rax
+	jnb	1f
+	ret
+
+	# Error return, must set errno
+1:
+	negl	%eax
+	movl	%eax,errno(%rip)	# errno is type int, so 32 bits
+	orq	$-1,%rax		# orq $-1 smaller than movq $-1
+	ret
+
+	.size	__syscall_common,.-__syscall_common
diff --git a/usr/klibc/arch/x86_64/sysstub.ph b/usr/klibc/arch/x86_64/sysstub.ph
new file mode 100644
index 0000000..e2d797b
--- /dev/null
+++ b/usr/klibc/arch/x86_64/sysstub.ph
@@ -0,0 +1,23 @@
+# -*- perl -*-
+#
+# arch/x86_64/sysstub.ph
+#
+# Script to generate system call stubs
+#
+
+sub make_sysstub($$$$$@) {
+    my($outputdir, $fname, $type, $sname, $stype, @args) = @_;
+
+    open(OUT, '>', "${outputdir}/${fname}.S");
+    print OUT "#include <asm/unistd.h>\n";
+    print OUT "\n";
+    print OUT "\t.type ${fname},\@function\n";
+    print OUT "\t.globl ${fname}\n";
+    print OUT "${fname}:\n";
+    print OUT "\tmovl \$__NR_${sname},%eax\n"; # Zero-extends to 64 bits
+    print OUT "\tjmp __syscall_common\n";
+    print OUT "\t.size ${fname},.-${fname}\n";
+    close(OUT);
+}
+
+1;
diff --git a/usr/klibc/arch/x86_64/vfork.S b/usr/klibc/arch/x86_64/vfork.S
new file mode 100644
index 0000000..e1c8090
--- /dev/null
+++ b/usr/klibc/arch/x86_64/vfork.S
@@ -0,0 +1,26 @@
+#
+# usr/klibc/arch/x86_64/vfork.S
+#
+# vfork is nasty - there must be nothing at all on the stack above
+# the stack frame of the enclosing function.
+#
+
+#include <asm/unistd.h>
+
+	.text
+	.align	4
+	.globl	vfork
+	.type	vfork, @function
+vfork:
+	pop	%rdx			/* Return address */
+	movl	$__NR_vfork, %eax
+	syscall
+	push	%rdx
+	cmpq	$-4095, %rax
+	jae	1f
+	ret
+1:
+	negl	%eax
+	movl	%eax, errno(%rip)
+	orq	$-1, %rax
+	ret

^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [klibc 21/31] Simple test suite for klibc
  2006-06-28  5:17 [klibc 00/31] klibc as a historyless patchset (updated and reorganized) H. Peter Anvin
                   ` (19 preceding siblings ...)
  2006-06-28  5:17 ` [klibc 20/31] x86_64 " H. Peter Anvin
@ 2006-06-28  5:17 ` H. Peter Anvin
  2006-06-28  5:17 ` [klibc 22/31] zlib " H. Peter Anvin
                   ` (9 subsequent siblings)
  30 siblings, 0 replies; 58+ messages in thread
From: H. Peter Anvin @ 2006-06-28  5:17 UTC (permalink / raw)
  To: linux-kernel, klibc; +Cc: H. Peter Anvin

[klibc] Simple test suite for klibc

A very simple handful of tests for klibc.  This is not by any
means an exhaustive test suite, nor are most of the tests
auto-verifying, but they are very useful to spot common porting
problems.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>

---
commit 24b7d25b39c484b6d39bc39003c1c1e315a04398
tree eb533c6e9ab6bbfeb94b4d82d299655e816f01b2
parent d82530df7a105851818935b622e20165f994d3f1
author H. Peter Anvin <hpa@zytor.com> Tue, 27 Jun 2006 20:51:04 -0700
committer H. Peter Anvin <hpa@zytor.com> Tue, 27 Jun 2006 20:51:04 -0700

 usr/klibc/tests/Kbuild        |   47 
 usr/klibc/tests/environ.c     |   24 
 usr/klibc/tests/fcntl.c       |   50 
 usr/klibc/tests/getopttest.c  |   32 
 usr/klibc/tests/getpagesize.c |   10 
 usr/klibc/tests/hello.c       |    7 
 usr/klibc/tests/idtest.c      |   14 
 usr/klibc/tests/malloctest.c  | 4146 +++++++++++++++++++++++++++++++++++++++++
 usr/klibc/tests/malloctest2.c |   62 +
 usr/klibc/tests/memstrtest.c  |   28 
 usr/klibc/tests/microhello.c  |    9 
 usr/klibc/tests/minihello.c   |    7 
 usr/klibc/tests/mmaptest.c    |   73 +
 usr/klibc/tests/opentest.c    |   15 
 usr/klibc/tests/pipetest.c    |   39 
 usr/klibc/tests/rtsig.c       |   12 
 usr/klibc/tests/setenvtest.c  |   39 
 usr/klibc/tests/setjmptest.c  |   38 
 usr/klibc/tests/sigint.c      |   53 +
 usr/klibc/tests/stat.c        |   63 +
 usr/klibc/tests/statfs.c      |   42 
 usr/klibc/tests/strlcpycat.c  |  111 +
 usr/klibc/tests/strtoimax.c   |   23 
 usr/klibc/tests/strtotime.c   |   25 
 usr/klibc/tests/testrand48.c  |   19 
 usr/klibc/tests/testvsnp.c    |  119 +
 usr/klibc/tests/vfork.c       |   45 
 27 files changed, 5152 insertions(+), 0 deletions(-)

Patch suppressed due to size (64 K), available at:
http://www.kernel.org/pub/linux/kernel/people/hpa/klibc-patchset/21-simple-test-suite-for-klibc.patch

^ permalink raw reply	[flat|nested] 58+ messages in thread

* [klibc 22/31] zlib for klibc
  2006-06-28  5:17 [klibc 00/31] klibc as a historyless patchset (updated and reorganized) H. Peter Anvin
                   ` (20 preceding siblings ...)
  2006-06-28  5:17 ` [klibc 21/31] Simple test suite " H. Peter Anvin
@ 2006-06-28  5:17 ` H. Peter Anvin
  2006-06-28  5:17 ` [klibc 23/31] kinit: replacement for in-kernel do_mount, ipconfig, nfsroot H. Peter Anvin
                   ` (8 subsequent siblings)
  30 siblings, 0 replies; 58+ messages in thread
From: H. Peter Anvin @ 2006-06-28  5:17 UTC (permalink / raw)
  To: linux-kernel, klibc; +Cc: H. Peter Anvin

[klibc] zlib for klibc

Add zlib for klibc.  kinit needs this to decompress compressed
ramdisks.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>

---
commit 8c5226a0f242be0fc40dad16236b511292115e1b
tree 22fe60571cc2d116c48305ab38a1b83c04d47c97
parent 24b7d25b39c484b6d39bc39003c1c1e315a04398
author H. Peter Anvin <hpa@zytor.com> Tue, 27 Jun 2006 20:51:06 -0700
committer H. Peter Anvin <hpa@zytor.com> Tue, 27 Jun 2006 20:51:06 -0700

 usr/include/zconf.h          |  332 ++++++++
 usr/include/zlib.h           | 1357 +++++++++++++++++++++++++++++++++
 usr/klibc/zlib/FAQ           |  339 ++++++++
 usr/klibc/zlib/INDEX         |   51 +
 usr/klibc/zlib/README        |  125 +++
 usr/klibc/zlib/adler32.c     |  149 ++++
 usr/klibc/zlib/algorithm.txt |  209 +++++
 usr/klibc/zlib/compress.c    |   79 ++
 usr/klibc/zlib/crc32.c       |  423 ++++++++++
 usr/klibc/zlib/crc32.h       |  441 +++++++++++
 usr/klibc/zlib/deflate.c     | 1736 ++++++++++++++++++++++++++++++++++++++++++
 usr/klibc/zlib/deflate.h     |  331 ++++++++
 usr/klibc/zlib/gzio.c        | 1029 +++++++++++++++++++++++++
 usr/klibc/zlib/infback.c     |  623 +++++++++++++++
 usr/klibc/zlib/inffast.c     |  318 ++++++++
 usr/klibc/zlib/inffast.h     |   11 
 usr/klibc/zlib/inffixed.h    |   94 ++
 usr/klibc/zlib/inflate.c     | 1368 +++++++++++++++++++++++++++++++++
 usr/klibc/zlib/inflate.h     |  115 +++
 usr/klibc/zlib/inftrees.c    |  329 ++++++++
 usr/klibc/zlib/inftrees.h    |   55 +
 usr/klibc/zlib/trees.c       | 1219 +++++++++++++++++++++++++++++
 usr/klibc/zlib/trees.h       |  127 +++
 usr/klibc/zlib/uncompr.c     |   61 +
 usr/klibc/zlib/zconf.in.h    |  332 ++++++++
 usr/klibc/zlib/zlib.3        |  159 ++++
 usr/klibc/zlib/zutil.c       |  318 ++++++++
 usr/klibc/zlib/zutil.h       |  269 +++++++
 28 files changed, 11999 insertions(+), 0 deletions(-)

Patch suppressed due to size (468 K), available at:
http://www.kernel.org/pub/linux/kernel/people/hpa/klibc-patchset/22-zlib-for-klibc.patch

^ permalink raw reply	[flat|nested] 58+ messages in thread

* [klibc 23/31] kinit: replacement for in-kernel do_mount, ipconfig, nfsroot
  2006-06-28  5:17 [klibc 00/31] klibc as a historyless patchset (updated and reorganized) H. Peter Anvin
                   ` (21 preceding siblings ...)
  2006-06-28  5:17 ` [klibc 22/31] zlib " H. Peter Anvin
@ 2006-06-28  5:17 ` H. Peter Anvin
  2006-06-28  5:17 ` [klibc 24/31] klibc basic build infrastructure H. Peter Anvin
                   ` (7 subsequent siblings)
  30 siblings, 0 replies; 58+ messages in thread
From: H. Peter Anvin @ 2006-06-28  5:17 UTC (permalink / raw)
  To: linux-kernel, klibc; +Cc: H. Peter Anvin

[klibc] kinit: replacement for in-kernel do_mount, ipconfig, nfsroot

kinit provides the default root-mounting code.  It should be
compatible with the in-kernel root-mounting code (modulo bugs); it
also provides a few minor enhancements.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>

---
commit b202cbd956d9433d6e00cabb63546773c10680a9
tree 6fb0cdbd124476c88d5711add5f4a6c4bc0770f3
parent 8c5226a0f242be0fc40dad16236b511292115e1b
author H. Peter Anvin <hpa@zytor.com> Tue, 27 Jun 2006 20:51:07 -0700
committer H. Peter Anvin <hpa@zytor.com> Tue, 27 Jun 2006 20:51:07 -0700

 usr/kinit/Kbuild                    |   28 +
 usr/kinit/README                    |    9 
 usr/kinit/devname.c                 |  114 +++++
 usr/kinit/do_mounts.c               |  221 ++++++++++
 usr/kinit/do_mounts.h               |   48 ++
 usr/kinit/do_mounts_md.c            |  398 ++++++++++++++++++
 usr/kinit/do_mounts_mtd.c           |   44 ++
 usr/kinit/fstype/Kbuild             |   25 +
 usr/kinit/fstype/cramfs_fs.h        |   85 ++++
 usr/kinit/fstype/ext2_fs.h          |   79 ++++
 usr/kinit/fstype/ext3_fs.h          |   92 ++++
 usr/kinit/fstype/fstype.c           |  296 ++++++++++++++
 usr/kinit/fstype/fstype.h           |   23 +
 usr/kinit/fstype/jfs_superblock.h   |  114 +++++
 usr/kinit/fstype/luks_fs.h          |   44 ++
 usr/kinit/fstype/lvm2_sb.h          |   18 +
 usr/kinit/fstype/main.c             |   58 +++
 usr/kinit/fstype/minix_fs.h         |   85 ++++
 usr/kinit/fstype/reiserfs_fs.h      |   69 +++
 usr/kinit/fstype/romfs_fs.h         |   56 +++
 usr/kinit/fstype/swap_fs.h          |   18 +
 usr/kinit/fstype/xfs_sb.h           |   16 +
 usr/kinit/getarg.c                  |   57 +++
 usr/kinit/getintfile.c              |   30 +
 usr/kinit/initrd.c                  |  199 +++++++++
 usr/kinit/ipconfig/Kbuild           |   31 +
 usr/kinit/ipconfig/README           |  103 +++++
 usr/kinit/ipconfig/bootp_packet.h   |   34 ++
 usr/kinit/ipconfig/bootp_proto.c    |  213 ++++++++++
 usr/kinit/ipconfig/bootp_proto.h    |    8 
 usr/kinit/ipconfig/dhcp_proto.c     |  212 ++++++++++
 usr/kinit/ipconfig/dhcp_proto.h     |   18 +
 usr/kinit/ipconfig/ipconfig.h       |   35 ++
 usr/kinit/ipconfig/main.c           |  758 +++++++++++++++++++++++++++++++++++
 usr/kinit/ipconfig/netdev.c         |  251 ++++++++++++
 usr/kinit/ipconfig/netdev.h         |   83 ++++
 usr/kinit/ipconfig/packet.c         |  286 +++++++++++++
 usr/kinit/ipconfig/packet.h         |    9 
 usr/kinit/kinit.c                   |  330 +++++++++++++++
 usr/kinit/kinit.h                   |   73 +++
 usr/kinit/name_to_dev.c             |  202 +++++++++
 usr/kinit/nfsmount/Kbuild           |   27 +
 usr/kinit/nfsmount/README.locking   |   26 +
 usr/kinit/nfsmount/dummypmap.c      |  188 +++++++++
 usr/kinit/nfsmount/dummypmap.h      |   13 +
 usr/kinit/nfsmount/dummypmap_test.c |    2 
 usr/kinit/nfsmount/main.c           |  263 ++++++++++++
 usr/kinit/nfsmount/mount.c          |  357 ++++++++++++++++
 usr/kinit/nfsmount/nfsmount.h       |   39 ++
 usr/kinit/nfsmount/portmap.c        |   73 +++
 usr/kinit/nfsmount/sunrpc.c         |  253 ++++++++++++
 usr/kinit/nfsmount/sunrpc.h         |   99 +++++
 usr/kinit/nfsroot.c                 |  113 +++++
 usr/kinit/open.c                    |   18 +
 usr/kinit/ramdisk_load.c            |  271 +++++++++++++
 usr/kinit/readfile.c                |   86 ++++
 usr/kinit/resume.c                  |   75 +++
 usr/kinit/run-init/Kbuild           |   25 +
 usr/kinit/run-init/run-init.c       |   95 ++++
 usr/kinit/run-init/run-init.h       |   38 ++
 usr/kinit/run-init/runinitlib.c     |  216 ++++++++++
 usr/kinit/xpio.c                    |   51 ++
 usr/kinit/xpio.h                    |   11 +
 63 files changed, 7211 insertions(+), 0 deletions(-)

Patch suppressed due to size (185 K), available at:
http://www.kernel.org/pub/linux/kernel/people/hpa/klibc-patchset/23-kinit-replacement-for-in-kernel-do-mount-ipconfig-nfsroot.patch

^ permalink raw reply	[flat|nested] 58+ messages in thread

* [klibc 24/31] klibc basic build infrastructure
  2006-06-28  5:17 [klibc 00/31] klibc as a historyless patchset (updated and reorganized) H. Peter Anvin
                   ` (22 preceding siblings ...)
  2006-06-28  5:17 ` [klibc 23/31] kinit: replacement for in-kernel do_mount, ipconfig, nfsroot H. Peter Anvin
@ 2006-06-28  5:17 ` H. Peter Anvin
  2006-06-28  5:17 ` [klibc 25/31] Miscellaneous utilities for klibc H. Peter Anvin
                   ` (6 subsequent siblings)
  30 siblings, 0 replies; 58+ messages in thread
From: H. Peter Anvin @ 2006-06-28  5:17 UTC (permalink / raw)
  To: linux-kernel, klibc; +Cc: H. Peter Anvin

Basic infrastructure for building klibc.
Mostly written by Sam Ravnborg <sam@ravnborg.org>.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>

---
commit 412867937f3298c6ab1b4a3d6fc8050214a1b7c0
tree 077c26fc13a808e6b0d7cad04e5898081da5a4ac
parent b202cbd956d9433d6e00cabb63546773c10680a9
author H. Peter Anvin <hpa@zytor.com> Tue, 27 Jun 2006 20:51:09 -0700
committer H. Peter Anvin <hpa@zytor.com> Tue, 27 Jun 2006 20:51:09 -0700

 scripts/Kbuild.include        |    5 +
 scripts/Kbuild.klibc          |  358 +++++++++++++++++++++++++++++++++++++++++
 scripts/gen_initramfs_list.sh |   51 ++----
 usr/Kbuild                    |   75 +++++++++
 usr/Kconfig                   |   21 ++
 usr/Makefile                  |   47 -----
 usr/initramfs.default         |    9 +
 7 files changed, 488 insertions(+), 78 deletions(-)

diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include
index b0d067b..3c90468 100644
--- a/scripts/Kbuild.include
+++ b/scripts/Kbuild.include
@@ -87,6 +87,11 @@ # Usage:
 # $(Q)$(MAKE) $(build)=dir
 build := -f $(if $(KBUILD_SRC),$(srctree)/)scripts/Makefile.build obj
 
+# Shorthand for $(Q)$(MAKE) -f scripts/Kbuild.klibc obj=
+# Usage:
+# $(Q)$(MAKE) $(klibc)=dir
+klibc := -f $(srctree)/scripts/Kbuild.klibc obj
+
 # Prefix -I with $(srctree) if it is not an absolute path
 addtree = $(if $(filter-out -I/%,$(1)),$(patsubst -I%,-I$(srctree)/%,$(1))) $(1)
 # Find all -I options and call addtree
diff --git a/scripts/Kbuild.klibc b/scripts/Kbuild.klibc
new file mode 100644
index 0000000..ac0439e
--- /dev/null
+++ b/scripts/Kbuild.klibc
@@ -0,0 +1,358 @@
+# ==========================================================================
+# Support for building klibc and related programs
+# ==========================================================================
+#
+# To create a kbuild file for a userspace program do the following:
+#
+# Kbuild:
+#
+# static-y := cat
+# # This will compile a file named cat.c -> the executable 'cat'
+# # The executable will be linked statically
+#
+# shared-y := cats
+# # This will compile a file named cats.c -> the executable 'cats'
+# # The executable will be linked shared
+#
+# If the userspace program consist of more files do the following:
+# Kbuild:
+#
+# static-y   := ipconfig
+# ipconfig-y := main.o netdev.c
+# So ipconfig will be linked statically using the two .o files
+# specified with ipconfig-y.
+#
+# To set directory wide CFLAGS use:
+# EXTRA_KLIBCCFLAGS := -DDEBUG
+# To set directory wide AFLAGS use:
+# EXTRA_KLIBCAFLAGS := -DDEBUG
+#
+# To set target specific CFLAGS (for .c files) use
+# KLIBCCFLAGS-main.o := -DDEBUG=3
+# To set target specific AFLAGS (for .s files) use
+# KLIBCAFLAGS-main.o := -DDEBUG=3
+
+src := $(obj)
+# Preset target and make sure it is a ':=' variable
+targets :=
+
+.phony: __build
+__build:
+
+# Read .config if it exist, otherwise ignore
+-include .config
+
+# Generic Kbuild routines
+include $(srctree)/scripts/Kbuild.include
+
+# Defines used when compiling early userspace (klibc programs)
+# ---------------------------------------------------------------------------
+
+KLIBCREQFLAGS     :=
+KLIBCARCHREQFLAGS :=
+KLIBCOPTFLAGS     :=
+KLIBCWARNFLAGS    := -W -Wall -Wno-sign-compare -Wno-unused-parameter
+KLIBCSHAREDFLAGS  :=
+KLIBCBITSIZE      :=
+KLIBCLDFLAGS      :=
+KLIBCCFLAGS       :=
+
+# Arch specific definitions for klibc
+include $(KLIBCSRC)/arch/$(KLIBCARCHDIR)/MCONFIG
+
+# include/asm-* architecture
+KLIBCASMARCH	  ?= $(KLIBCARCH)
+
+# klibc version
+KLIBCMAJOR        := $(shell cut -d. -f1 $(srctree)/usr/klibc/version)
+KLIBCMINOR        := $(shell cut -d. -f2 $(srctree)/usr/klibc/version)
+
+# binutils
+KLIBCLD          := $(LD)
+KLIBCCC          := $(CC)
+KLIBCAR          := $(AR)
+KLIBCRANLIB      := $(RANLIB)
+KLIBCSTRIP       := $(STRIP)
+KLIBCNM          := $(NM)
+KLIBCOBJCOPY	 := $(OBJCOPY)
+KLIBCOBJDUMP	 := $(OBJDUMP)
+
+# klibc include paths
+KLIBCCPPFLAGS    := -I$(KLIBCINC)/arch/$(KLIBCARCHDIR)	\
+                    -I$(KLIBCINC)/bits$(KLIBCBITSIZE)	\
+		    -I$(KLIBCOBJ)/../include		\
+                    -I$(KLIBCINC)
+# kernel include paths
+KLIBCKERNELSRC	 ?= $(srctree)/
+KLIBCCPPFLAGS    += -I$(KLIBCKERNELSRC)include		\
+                     $(if $(KBUILD_SRC),-I$(KLIBCKERNELOBJ)include2 -I$(KLIBCKERNELOBJ)include -I$(srctree)/include)    \
+		     $(KLIBCARCHINCFLAGS)
+
+# klibc definitions
+KLIBCDEFS        += -D__KLIBC__=$(KLIBCMAJOR)          \
+		    -D__KLIBC_MINOR__=$(KLIBCMINOR)    \
+		    -D_BITSIZE=$(KLIBCBITSIZE)
+KLIBCCPPFLAGS    += $(KLIBCDEFS)
+KLIBCCFLAGS      += $(KLIBCCPPFLAGS) $(KLIBCREQFLAGS) $(KLIBCARCHREQFLAGS)  \
+                    $(KLIBCOPTFLAGS) $(KLIBCWARNFLAGS)
+KLIBCAFLAGS      += -D__ASSEMBLY__ $(KLIBCCFLAGS)
+KLIBCSTRIPFLAGS  += --strip-all -R .comment -R .note
+
+KLIBCLIBGCC_DEF  := $(shell $(KLIBCCC) $(KLIBCCFLAGS) --print-libgcc)
+KLIBCLIBGCC	 ?= $(KLIBCLIBGCC_DEF)
+KLIBCCRT0        := $(KLIBCOBJ)/arch/$(KLIBCARCHDIR)/crt0.o
+KLIBCLIBC        := $(KLIBCOBJ)/libc.a
+KLIBCCRTSHARED   := $(KLIBCOBJ)/interp.o
+KLIBCLIBCSHARED  := $(KLIBCOBJ)/libc.so
+# How to tell the linker main() is the entrypoint
+KLIBCEMAIN	 ?= -e main
+
+#
+# This indicates the location of the final version of the shared library.
+# THIS MUST BE AN ABSOLUTE PATH WITH NO FINAL SLASH.
+# Leave this empty to make it the root.
+#
+SHLIBDIR = /lib
+
+export KLIBCLD KLIBCCC KLIBCAR KLIBCSTRIP KLIBCNM
+export KLIBCCFLAGS KLIBCAFLAGS KLIBCLIBGCC KLIBCSHAREDFLAGS KLIBCSTRIPFLAGS
+export KLIBCCRT0 KLIBCLIBC SHLIBDIR
+
+# kernel configuration
+include .config
+
+# Add $(obj)/ for paths that is not absolute
+objectify = $(foreach o,$(1),$(if $(filter /%,$(o)),$(o),$(obj)/$(o)))
+
+# Kbuild file in the directory that is being build
+include $(obj)/Kbuild
+
+#####
+# static-y + shared-y handling
+klibc-progs := $(static-y) $(shared-y)
+# klibc-progs based on a single .o file (with same name + .o)
+klibc-objs := $(foreach p, $(klibc-progs), $(if $($(p)-y),,$(p)))
+klibc-objs := $(addsuffix .o, $(klibc-objs))
+# klibc-progs which is based on several .o files
+klibc-multi := $(foreach p, $(klibc-progs), $(if $($(p)-y),$(p)))
+# objects used for klibc-progs with more then one .o file
+klibc-objs += $(foreach p, $(klibc-multi), $($(p)-y))
+# objects build in this dir
+klibc-real-objs := $(patsubst %/,,$(klibc-objs))
+# Directories we need to visit before klibc-objs are up-to-date
+klibc-dirs :=  $(patsubst %/,%,$(filter %/, $(klibc-objs)))
+# replace all dir/ with dir/lib.a
+klibc-objs := $(patsubst %/, %/lib.a, $(klibc-objs))
+
+targets += $(static-y) $(shared-y)
+
+# $(output-dirs) are a list of directories that contain object files
+output-dirs := $(dir $(klibc-dirs) $(klibc-objs))
+output-dirs += $(foreach f, $(hostprogs-y) $(targets), \
+               $(if $(dir $(f)), $(dir $(f))))
+output-dirs := $(strip $(sort $(filter-out ./,$(output-dirs))))
+
+# prefix so we get full dir
+static-y        := $(addprefix $(obj)/,$(static-y))
+shared-y        := $(addprefix $(obj)/,$(shared-y))
+klibc-objs      := $(addprefix $(obj)/,$(klibc-objs))
+klibc-real-objs := $(addprefix $(obj)/,$(klibc-real-objs))
+output-dirs     := $(addprefix $(obj)/,$(output-dirs))
+klibc-dirs      := $(addprefix $(obj)/,$(klibc-dirs))
+subdir-y        := $(addprefix $(obj)/,$(subdir-y))
+lib-y           := $(addprefix $(obj)/,$(lib-y))
+always          := $(addprefix $(obj)/,$(always))
+targets         := $(addprefix $(obj)/,$(targets))
+
+#####
+# Handle options to gcc. Support building with separate output directory
+
+__klibccflags    = $(KLIBCCFLAGS) $(EXTRA_KLIBCCFLAGS) $(KLIBCCFLAGS_$(*F).o)
+__klibcaflags    = $(KLIBCAFLAGS) $(EXTRA_KLIBCAFLAGS) $(KLIBCAFLAGS_$(*F).o)
+
+ifeq ($(KBUILD_SRC),)
+_klibccflags    = $(__klibccflags)
+_klibcaflags    = $(__klibcaflags)
+else
+_klibccflags    = $(call flags,__klibccflags)
+_klibcaflags    = $(call flags,__klibcaflags)
+endif
+
+klibccflags     = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(_klibccflags)
+klibcaflags     = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(_klibcaflags)
+
+# Create output directory if not already present
+_dummy := $(shell [ -d $(obj) ] || mkdir -p $(obj))
+
+# Create directories for object files if directory does not exist
+# Needed when lib-y := dir/file.o syntax is used
+_dummy := $(foreach d,$(output-dirs), $(shell [ -d $(d) ] || mkdir -p $(d)))
+
+# Do we have to make a lib.a in this dir?
+ifneq ($(strip $(lib-y) $(lib-n) $(lib-)),)
+lib-target := $(obj)/lib.a
+endif
+
+__build: $(subdir-y) $(lib-target) $(always)
+	@:
+
+# Compile C sources (.c)
+# ---------------------------------------------------------------------------
+
+quiet_cmd_cc_s_c = KLIBCCC $@
+      cmd_cc_s_c = $(KLIBCCC) $(klibccflags) -S -o $@ $<
+
+%.s: %.c FORCE
+	$(call if_changed_dep,cc_s_c)
+
+quiet_cmd_cc_o_c = KLIBCCC $@
+      cmd_cc_o_c = $(KLIBCCC) $(klibccflags) -c -o $@ $<
+
+%.o: %.c FORCE
+	$(call if_changed_dep,cc_o_c)
+
+quiet_cmd_cc_i_c = CPP     $@
+      cmd_cc_i_c = $(KLIBCCC) -E $(klibccflags) -o $@ $<
+%.i: %.c FORCE
+	$(call if_changed_dep,cc_i_c)
+
+# Compile assembler sources (.S)
+# ---------------------------------------------------------------------------
+
+quiet_cmd_as_o_S = KLIBCAS $@
+      cmd_as_o_S = $(KLIBCCC) $(klibcaflags) -c -o $@ $<
+
+%.o: %.S FORCE
+	$(call if_changed_dep,as_o_S)
+
+targets += $(real-objs-y)
+
+#
+# Rule to compile a set of .o files into one .o file
+#
+ifdef lib-target
+quiet_cmd_link_o_target = LD      $@
+# If the list of objects to link is empty, just create an empty lib.a
+cmd_link_o_target = $(if $(strip $(lib-y)),\
+                    rm -f $@; $(KLIBCAR) cru $@ $(filter $(lib-y), $^),\
+                    rm -f $@; $(KLIBCAR) crs $@)
+
+$(lib-target): $(lib-y) FORCE
+	$(call if_changed,link_o_target)
+targets += $(lib-target) $(lib-y)
+endif # lib-target
+
+
+ifdef klibc-progs
+# Compile klibcspace programs for the target
+# ===========================================================================
+
+__build : $(klibc-dirs) $(static-y) $(shared-y)
+
+# Descend if needed
+$(sort $(addsuffix /lib.a,$(klibc-dirs))): $(klibc-dirs) ;
+
+# Define dependencies for link of progs
+# For the simple program:
+#	file.o => file
+# A program with multiple objects
+#	filea.o, fileb.o => file
+# A program with .o files in another dir
+#	dir/lib.a filea.o => file
+
+stripobj  = $(subst $(obj)/,,$@)
+addliba   = $(addprefix $(obj)/, $(patsubst %/, %/lib.a, $(1)))
+link-deps = $(if $($(stripobj)-y), $(call addliba, $($(stripobj)-y)), $@.o)
+
+quiet_cmd_ld-static = KLIBCLD $@
+      cmd_ld-static = $(KLIBCLD) $(KLIBCLDFLAGS) -o $@    	\
+                       $(EXTRA_KLIBCLDFLAGS)              	\
+                       $(KLIBCCRT0)                       	\
+                       $(link-deps)                       	\
+                       --start-group $(KLIBCLIBC) 	  	\
+		       $(KLIBCLIBGCC) --end-group ;       	\
+                      cp -f $@ $@.g ;                     	\
+                      $(KLIBCSTRIP) $(KLIBCSTRIPFLAGS) $@
+
+
+$(static-y): $(klibc-objs) $(lib-target) $(KLIBCCRT0) $(KLIBCLIBC) FORCE
+	$(call if_changed,ld-static)
+
+quiet_cmd_ld-shared = KLIBCLD $@
+      cmd_ld-shared = $(KLIBCLD) $(KLIBCLDFLAGS) -o $@    	\
+                       $(EXTRA_KLIBCLDFLAGS)              	\
+                       $(KLIBCEMAIN) $(KLIBCCRTSHARED)    	\
+                       $(link-deps)                       	\
+                       --start-group -R $(KLIBCLIBCSHARED) 	\
+	               $(KLIBCLIBGCC) --end-group ;		\
+                      cp -f $@ $@.g ;                     	\
+                      $(KLIBCSTRIP) $(KLIBCSTRIPFLAGS) $@
+
+
+$(shared-y): $(klibc-objs) $(lib-target) $(KLIBCCRTSHARED) \
+                                         $(KLIBCLIBCSHARED) FORCE
+	$(call if_changed,ld-shared)
+
+# Do not try to build KLIBC libaries if we are building klibc
+ifeq ($(klibc-build),)
+$(KLIBCCRT0) $(KLIBCLIBC): ;
+$(KLIBCCRTSHARED) $(KLIBCLIBCSHARED): ;
+endif
+
+targets += $(klibc-real-objs)
+endif
+
+# Compile programs on the host
+# ===========================================================================
+ifdef hostprogs-y
+include $(srctree)/scripts/Makefile.host
+endif
+
+# Descending
+# ---------------------------------------------------------------------------
+
+.PHONY: $(subdir-y) $(klibc-dirs)
+$(subdir-y) $(klibc-dirs):
+	$(Q)$(MAKE) $(klibc)=$@
+
+# Add FORCE to the prequisites of a target to force it to be always rebuilt.
+# ---------------------------------------------------------------------------
+
+.PHONY: FORCE
+
+FORCE:
+
+# Linking
+# Create a reloctable composite object file
+# ---------------------------------------------------------------------------
+quiet_cmd_klibcld = KLIBCLD $@
+      cmd_klibcld = $(KLIBCLD) -r $(KLIBCLDFLAGS) \
+                                $(EXTRA_KLIBCLDFLAGS) $(KLIBCLDFLAGS_$(@F)) \
+                                $(filter-out FORCE,$^) -o $@
+
+
+# Link target to a new name
+# ---------------------------------------------------------------------------
+quiet_cmd_ln = LN      $@
+      cmd_ln = rm -f $@ && ln $< $@
+
+# Strip target (remove all debugging info)
+quiet_cmd_strip = STRIP   $@
+      cmd_strip = $(KLIBCSTRIP) $(KLIBCSTRIPFLAGS) $< -o $@
+
+
+# Read all saved command lines and dependencies for the $(targets) we
+# may be building above, using $(if_changed{,_dep}). As an
+# optimization, we don't need to read them if the target does not
+# exist, we will rebuild anyway in that case.
+targets := $(wildcard $(sort $(targets)))
+cmd_files := $(wildcard $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd))
+
+ifneq ($(cmd_files),)
+  include $(cmd_files)
+endif
+
+# Shorthand for $(Q)$(MAKE) -f scripts/Kbuild.klibc obj
+# Usage:
+# $(Q)$(MAKE) $(klibc)=dir
+klibc := -rR -f $(if $(KBUILD_SRC),$(srctree)/)scripts/Kbuild.klibc obj
diff --git a/scripts/gen_initramfs_list.sh b/scripts/gen_initramfs_list.sh
index 331c079..624015c 100644
--- a/scripts/gen_initramfs_list.sh
+++ b/scripts/gen_initramfs_list.sh
@@ -15,7 +15,7 @@ set -e
 usage() {
 cat << EOF
 Usage:
-$0 [-o <file>] [-u <uid>] [-g <gid>] {-d | <cpio_source>} ...
+$0 [-o <file>] [-u <uid>] [-g <gid>] <cpio_source> ...
 	-o <file>      Create gzipped initramfs file named <file> using
 	               gen_init_cpio and gzip
 	-u <uid>       User ID to map to user ID 0 (root).
@@ -27,7 +27,6 @@ Usage:
 	<cpio_source>  File list or directory for cpio archive.
 	               If <cpio_source> is a .cpio file it will be used
 		       as direct input to initramfs.
-	-d             Output the default cpio list.
 
 All options except -o and -l may be repeated and are interpreted
 sequentially and immediately.  -u and -g states are preserved across
@@ -36,23 +35,6 @@ to reset the root/group mapping.
 EOF
 }
 
-list_default_initramfs() {
-	# echo usr/kinit/kinit
-	:
-}
-
-default_initramfs() {
-	cat <<-EOF >> ${output}
-		# This is a very simple, default initramfs
-
-		dir /dev 0755 0 0
-		nod /dev/console 0600 0 0 c 5 1
-		dir /root 0700 0 0
-		# file /kinit usr/kinit/kinit 0755 0 0
-		# slink /init kinit 0755 0 0
-	EOF
-}
-
 filetype() {
 	local argv1="$1"
 
@@ -167,8 +149,6 @@ header() {
 
 # process one directory (incl sub-directories)
 dir_filelist() {
-	${dep_list}header "$1"
-
 	srcdir=$(echo "$1" | sed -e 's://*:/:g')
 	dirlist=$(find "${srcdir}" -printf "%p %m %U %G\n" 2>/dev/null)
 
@@ -187,9 +167,7 @@ # if only one file is specified and it i
 # if a directory is specified then add all files in given direcotry to fs
 # if a regular file is specified assume it is in gen_initramfs format
 input_file() {
-	source="$1"
 	if [ -f "$1" ]; then
-		${dep_list}header "$1"
 		is_cpio="$(echo "$1" | sed 's/^.*\.cpio/cpio/')"
 		if [ $2 -eq 0 -a ${is_cpio} == "cpio" ]; then
 			cpio_file=$1
@@ -214,6 +192,15 @@ input_file() {
 	fi
 }
 
+# input file/dir - process it
+process_file() {
+	if [ -z ${print_header} ]; then
+		${dep_list}header "$1"
+	fi
+	print_header=y
+	input_file "$1" "$2"
+}
+
 prog=$0
 root_uid=0
 root_gid=0
@@ -249,27 +236,29 @@ while [ $# -gt 0 ]; do
 			root_gid="$1"
 			shift
 			;;
-		"-d")	# display default initramfs list
-			default_list="$arg"
-			${dep_list}default_initramfs
-			;;
 		"-h")
 			usage
 			exit 0
 			;;
 		*)
 			case "$arg" in
-				"-"*)
-					unknown_option
+				"-"*)	unknown_option
 					;;
-				*)	# input file/dir - process it
-					input_file "$arg" "$#"
+				*)	process_file "$arg" "$#"
 					;;
 			esac
 			;;
 	esac
 done
 
+# trailer of dependency list
+if [ ! -z ${dep_list} ]; then
+	echo ""
+	echo "initramfs: \$(deps_initramfs)"
+	echo "\$(deps_initramfs): ;"
+	echo ""
+fi
+
 # If output_file is set we will generate cpio archive and gzip it
 # we are carefull to delete tmp files
 if [ ! -z ${output_file} ]; then
diff --git a/usr/Kbuild b/usr/Kbuild
new file mode 100644
index 0000000..4b2be06
--- /dev/null
+++ b/usr/Kbuild
@@ -0,0 +1,75 @@
+#
+# kbuild file for usr/ - including initramfs image and klibc
+#
+
+CONFIG_KLIBC := 1
+
+include-subdir := include
+klibc-subdir := klibc
+usr-subdirs  := kinit
+subdir-      := $(include-subdir) $(klibc-subdir) $(usr-subdirs)
+
+usr-subdirs  := $(addprefix _usr_,$(usr-subdirs))
+klibc-subdir := $(addprefix _usr_,$(klibc-subdir))
+
+# Klibc binaries
+ifdef CONFIG_KLIBC
+
+# .initramfs_data.cpio.gz.d is used to identify all files included
+# in initramfs and to detect if any files are added/removed.
+# Removed files are identified by directory timestamp being updated
+# The dependency list is generated by gen_initramfs.sh -l
+ifneq ($(wildcard $(obj)/.initramfs_data.cpio.gz.d),)
+	include $(obj)/.initramfs_data.cpio.gz.d
+endif
+
+# build klibc library before the klibc programs
+# build klibc programs before cpio.gz
+.PHONY: initramfs $(usr-subdirs) $(klibc-subdir) $(include-subdir)
+initramfs:         $(usr-subdirs) $(klibc-subdir) $(include-subdir)
+$(deps_initramfs): $(usr-subdirs) $(klibc-subdir) $(include-subdir)
+
+$(usr-subdirs): $(klibc-subdir)
+	$(Q)$(MAKE) $(klibc)=$(src)/$(patsubst _usr_%,%,$(@))
+
+$(klibc-subdir): $(include-subdir)
+	$(Q)$(MAKE) $(klibc)=$(src)/$(patsubst _usr_%,%,$(@))
+
+$(include-subdir):
+	$(Q)$(MAKE) $(klibc)=$(src)/$(patsubst _usr_%,%,$(@))
+endif
+
+
+# Generate builtin.o based on initramfs_data.o
+obj-y := initramfs_data.o
+
+# initramfs_data.o contains the initramfs_data.cpio.gz image.
+# The image is included using .incbin, a dependency which is not
+# tracked automatically.
+$(obj)/initramfs_data.o: $(obj)/initramfs_data.cpio.gz FORCE
+
+#####
+# Generate the initramfs cpio archive
+
+hostprogs-y := gen_init_cpio
+ginitramfs  := $(CONFIG_SHELL) $(srctree)/scripts/gen_initramfs_list.sh
+ramfs-def   := $(srctree)/$(src)/initramfs.default
+ramfs-input := $(shell echo $(CONFIG_INITRAMFS_SOURCE))
+ramfs-input := $(if $(ramfs-input), $(ramfs-input), $(ramfs-def))
+
+ramfs-args  := \
+        $(if $(CONFIG_INITRAMFS_ROOT_UID), -u $(CONFIG_INITRAMFS_ROOT_UID)) \
+        $(if $(CONFIG_INITRAMFS_ROOT_GID), -g $(CONFIG_INITRAMFS_ROOT_GID))
+
+quiet_cmd_initfs = GEN     $@
+      cmd_initfs = $(ginitramfs) -o $@ $(ramfs-args) $(ramfs-input)
+
+targets := initramfs_data.cpio.gz
+# We rebuild initramfs_data.cpio.gz if:
+# 1) Any included file is newer then initramfs_data.cpio.gz
+# 2) There are changes in which files are included (added or deleted)
+# 3) If gen_init_cpio are newer than initramfs_data.cpio.gz
+# 4) arguments to gen_initramfs.sh changes
+$(obj)/initramfs_data.cpio.gz: $(obj)/gen_init_cpio $(deps_initramfs) initramfs
+	$(Q)$(ginitramfs) -l $(ramfs-input) > $(obj)/.initramfs_data.cpio.gz.d
+	$(call if_changed,initfs)
diff --git a/usr/Kconfig b/usr/Kconfig
index 07727f3..cf6bad6 100644
--- a/usr/Kconfig
+++ b/usr/Kconfig
@@ -44,3 +44,24 @@ config INITRAMFS_ROOT_GID
 	  owned by group root in the initial ramdisk image.
 
 	  If you are not sure, leave it set to "0".
+
+config KLIBC_ERRLIST
+	bool "Early userspace real error messages" if EMBEDDED
+	default y
+	help
+	  If this is set, kinit (and other klibc-derived binaries)
+	  will have the standard list of error messages built in, and
+	  thus will report, for example, "No such file or directory"
+	  instead of "Error 1".  Leaving it out will save
+	  approximately 4K from each static binary (one, unless you
+	  have a different initramfs_source.txt) or the shared
+	  library.
+
+	  If you are not sure, "Y" is highly recommended.
+
+config KLIBC_ZLIB
+	bool
+	default y
+	help
+	  This builds the zlib portion of klibc.  This is currently
+	  required.
diff --git a/usr/Makefile b/usr/Makefile
deleted file mode 100644
index e938242..0000000
--- a/usr/Makefile
+++ /dev/null
@@ -1,47 +0,0 @@
-#
-# kbuild file for usr/ - including initramfs image
-#
-
-klibcdirs:;
-
-# Generate builtin.o based on initramfs_data.o
-obj-y := initramfs_data.o
-
-# initramfs_data.o contains the initramfs_data.cpio.gz image.
-# The image is included using .incbin, a dependency which is not
-# tracked automatically.
-$(obj)/initramfs_data.o: $(obj)/initramfs_data.cpio.gz FORCE
-
-#####
-# Generate the initramfs cpio archive
-
-hostprogs-y := gen_init_cpio
-initramfs   := $(CONFIG_SHELL) $(srctree)/scripts/gen_initramfs_list.sh
-ramfs-input := $(if $(filter-out "",$(CONFIG_INITRAMFS_SOURCE)), \
-                    $(CONFIG_INITRAMFS_SOURCE),-d)
-ramfs-args  := \
-        $(if $(CONFIG_INITRAMFS_ROOT_UID), -u $(CONFIG_INITRAMFS_ROOT_UID)) \
-        $(if $(CONFIG_INITRAMFS_ROOT_GID), -g $(CONFIG_INITRAMFS_ROOT_GID))
-
-# .initramfs_data.cpio.gz.d is used to identify all files included
-# in initramfs and to detect if any files are added/removed.
-# Removed files are identified by directory timestamp being updated
-# The dependency list is generated by gen_initramfs.sh -l
-ifneq ($(wildcard $(obj)/.initramfs_data.cpio.gz.d),)
-	include $(obj)/.initramfs_data.cpio.gz.d
-endif
-
-quiet_cmd_initfs = GEN     $@
-      cmd_initfs = $(initramfs) -o $@ $(ramfs-args) $(ramfs-input)
-
-targets := initramfs_data.cpio.gz
-$(deps_initramfs): klibcdirs
-# We rebuild initramfs_data.cpio.gz if:
-# 1) Any included file is newer then initramfs_data.cpio.gz
-# 2) There are changes in which files are included (added or deleted)
-# 3) If gen_init_cpio are newer than initramfs_data.cpio.gz
-# 4) arguments to gen_initramfs.sh changes
-$(obj)/initramfs_data.cpio.gz: $(obj)/gen_init_cpio $(deps_initramfs) klibcdirs
-	$(Q)$(initramfs) -l $(ramfs-input) > $(obj)/.initramfs_data.cpio.gz.d
-	$(call if_changed,initfs)
-
diff --git a/usr/initramfs.default b/usr/initramfs.default
new file mode 100644
index 0000000..d23437a
--- /dev/null
+++ b/usr/initramfs.default
@@ -0,0 +1,9 @@
+#####################
+# This is a very simple, default initramfs
+# See gen_init_cpio for syntax
+
+dir dev 0755 0 0
+nod dev/console 0600 0 0 c 5 1
+dir root 0700 0 0
+file kinit usr/kinit/kinit 0755 0 0
+slink init kinit 0755 0 0

^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [klibc 25/31] Miscellaneous utilities for klibc
  2006-06-28  5:17 [klibc 00/31] klibc as a historyless patchset (updated and reorganized) H. Peter Anvin
                   ` (23 preceding siblings ...)
  2006-06-28  5:17 ` [klibc 24/31] klibc basic build infrastructure H. Peter Anvin
@ 2006-06-28  5:17 ` H. Peter Anvin
  2006-06-28  5:17 ` [klibc 26/31] dash - a small POSIX shell " H. Peter Anvin
                   ` (5 subsequent siblings)
  30 siblings, 0 replies; 58+ messages in thread
From: H. Peter Anvin @ 2006-06-28  5:17 UTC (permalink / raw)
  To: linux-kernel, klibc; +Cc: H. Peter Anvin

[klibc] Miscellaneous utilities for klibc

A collection of minor utilities for klibc.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>

---
commit 99753ec67ac082f5f4fdb07e7b985bba84cf4b4c
tree 758bb62c89686ff8a71f6022c15be6f02723a9d4
parent 412867937f3298c6ab1b4a3d6fc8050214a1b7c0
author H. Peter Anvin <hpa@zytor.com> Tue, 27 Jun 2006 20:51:10 -0700
committer H. Peter Anvin <hpa@zytor.com> Tue, 27 Jun 2006 20:51:10 -0700

 usr/Kbuild             |    2 
 usr/utils/Kbuild       |   62 ++++++
 usr/utils/cat.c        |  329 ++++++++++++++++++++++++++++++
 usr/utils/chroot.c     |   25 ++
 usr/utils/dd.c         |  533 ++++++++++++++++++++++++++++++++++++++++++++++++
 usr/utils/false.c      |    4 
 usr/utils/file_mode.c  |  143 +++++++++++++
 usr/utils/file_mode.h  |    1 
 usr/utils/halt.c       |   55 +++++
 usr/utils/insmod.c     |  140 +++++++++++++
 usr/utils/ln.c         |   77 +++++++
 usr/utils/minips.c     |  508 ++++++++++++++++++++++++++++++++++++++++++++++
 usr/utils/mkdir.c      |  150 ++++++++++++++
 usr/utils/mkfifo.c     |   71 ++++++
 usr/utils/mknod.c      |   58 +++++
 usr/utils/mount_main.c |  105 +++++++++
 usr/utils/mount_opts.c |   94 ++++++++
 usr/utils/mount_opts.h |   21 ++
 usr/utils/nuke.c       |  134 ++++++++++++
 usr/utils/pivot_root.c |   19 ++
 usr/utils/sleep.c      |   25 ++
 usr/utils/true.c       |    4 
 usr/utils/umount.c     |   45 ++++
 usr/utils/uname.c      |  154 ++++++++++++++
 24 files changed, 2758 insertions(+), 1 deletions(-)

Patch suppressed due to size (65 K), available at:
http://www.kernel.org/pub/linux/kernel/people/hpa/klibc-patchset/25-miscellaneous-utilities-for-klibc.patch

^ permalink raw reply	[flat|nested] 58+ messages in thread

* [klibc 26/31] dash - a small POSIX shell for klibc
  2006-06-28  5:17 [klibc 00/31] klibc as a historyless patchset (updated and reorganized) H. Peter Anvin
                   ` (24 preceding siblings ...)
  2006-06-28  5:17 ` [klibc 25/31] Miscellaneous utilities for klibc H. Peter Anvin
@ 2006-06-28  5:17 ` H. Peter Anvin
  2006-06-28  5:17 ` [klibc 27/31] A port of gzip to klibc H. Peter Anvin
                   ` (4 subsequent siblings)
  30 siblings, 0 replies; 58+ messages in thread
From: H. Peter Anvin @ 2006-06-28  5:17 UTC (permalink / raw)
  To: linux-kernel, klibc; +Cc: H. Peter Anvin

[klibc] dash - a small POSIX shell for klibc

A port of dash, a size-optimized version of ash by Herbert Xu, for
klibc.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>

---
commit a359e7a5083122cf32f9b4dabd63af25a60646d9
tree a8684b9b4068c50296ee594e1c75ac0a4f6fcbf9
parent 99753ec67ac082f5f4fdb07e7b985bba84cf4b4c
author H. Peter Anvin <hpa@zytor.com> Tue, 27 Jun 2006 20:51:11 -0700
committer H. Peter Anvin <hpa@zytor.com> Tue, 27 Jun 2006 20:51:11 -0700

 usr/Kbuild               |    2 
 usr/dash/Kbuild          |  146 +++
 usr/dash/README.klibc    |    7 
 usr/dash/TOUR            |  356 +++++++
 usr/dash/alias.c         |  227 ++++
 usr/dash/alias.h         |   52 +
 usr/dash/arith.y         |  155 +++
 usr/dash/arith_yylex.c   |  163 +++
 usr/dash/bltin/bltin.h   |   89 ++
 usr/dash/bltin/echo.1    |  109 ++
 usr/dash/bltin/printf.1  |  354 +++++++
 usr/dash/bltin/printf.c  |  476 +++++++++
 usr/dash/bltin/test.1    |  309 ++++++
 usr/dash/bltin/test.c    |  500 ++++++++++
 usr/dash/builtins.def.in |   92 ++
 usr/dash/cd.c            |  303 ++++++
 usr/dash/cd.h            |   35 +
 usr/dash/config.h        |   85 ++
 usr/dash/error.c         |  233 +++++
 usr/dash/error.h         |  145 +++
 usr/dash/eval.c          | 1100 ++++++++++++++++++++++
 usr/dash/eval.h          |   62 +
 usr/dash/exec.c          |  869 +++++++++++++++++
 usr/dash/exec.h          |   77 ++
 usr/dash/expand.c        | 1744 ++++++++++++++++++++++++++++++++++
 usr/dash/expand.h        |   83 ++
 usr/dash/funcs/cmv       |   47 +
 usr/dash/funcs/dirs      |   71 +
 usr/dash/funcs/kill      |   47 +
 usr/dash/funcs/login     |   36 +
 usr/dash/funcs/newgrp    |   35 +
 usr/dash/funcs/popd      |   71 +
 usr/dash/funcs/pushd     |   71 +
 usr/dash/funcs/suspend   |   39 +
 usr/dash/gendeps.pl      |   38 +
 usr/dash/hetio.c         |  397 ++++++++
 usr/dash/hetio.h         |   22 
 usr/dash/histedit.c      |  492 ++++++++++
 usr/dash/init.h          |   39 +
 usr/dash/input.c         |  563 +++++++++++
 usr/dash/input.h         |   68 +
 usr/dash/jobs.c          | 1499 ++++++++++++++++++++++++++++++
 usr/dash/jobs.h          |  109 ++
 usr/dash/machdep.h       |   53 +
 usr/dash/mail.c          |  112 ++
 usr/dash/mail.h          |   38 +
 usr/dash/main.c          |  349 +++++++
 usr/dash/main.h          |   54 +
 usr/dash/memalloc.c      |  329 ++++++
 usr/dash/memalloc.h      |   97 ++
 usr/dash/miscbltin.c     |  457 +++++++++
 usr/dash/miscbltin.h     |   31 +
 usr/dash/mkbuiltins      |  101 ++
 usr/dash/mkinit.c        |  476 +++++++++
 usr/dash/mknodes.c       |  448 +++++++++
 usr/dash/mksyntax.c      |  315 ++++++
 usr/dash/mktokens        |   92 ++
 usr/dash/myhistedit.h    |   45 +
 usr/dash/mystring.c      |  209 ++++
 usr/dash/mystring.h      |   58 +
 usr/dash/nodes.c.pat     |  166 +++
 usr/dash/nodetypes       |  144 +++
 usr/dash/options.c       |  547 +++++++++++
 usr/dash/options.h       |   86 ++
 usr/dash/output.c        |  385 ++++++++
 usr/dash/output.h        |  112 ++
 usr/dash/parser.c        | 1556 +++++++++++++++++++++++++++++++
 usr/dash/parser.h        |   96 ++
 usr/dash/redir.c         |  475 +++++++++
 usr/dash/redir.h         |   49 +
 usr/dash/sh.1            | 2332 ++++++++++++++++++++++++++++++++++++++++++++++
 usr/dash/shell.h         |   94 ++
 usr/dash/show.c          |  403 ++++++++
 usr/dash/show.h          |   45 +
 usr/dash/system.c        |  191 ++++
 usr/dash/system.h        |   91 ++
 usr/dash/trap.c          |  443 +++++++++
 usr/dash/trap.h          |   52 +
 usr/dash/var.c           |  676 +++++++++++++
 usr/dash/var.h           |  146 +++
 80 files changed, 22769 insertions(+), 1 deletions(-)

Patch suppressed due to size (577 K), available at:
http://www.kernel.org/pub/linux/kernel/people/hpa/klibc-patchset/26-dash---a-small-posix-shell-for-klibc.patch

^ permalink raw reply	[flat|nested] 58+ messages in thread

* [klibc 27/31] A port of gzip to klibc
  2006-06-28  5:17 [klibc 00/31] klibc as a historyless patchset (updated and reorganized) H. Peter Anvin
                   ` (25 preceding siblings ...)
  2006-06-28  5:17 ` [klibc 26/31] dash - a small POSIX shell " H. Peter Anvin
@ 2006-06-28  5:17 ` H. Peter Anvin
  2006-06-28  5:17 ` [klibc 28/31] sparc64: transmit arch-specific options to kinit via /arch.cmd H. Peter Anvin
                   ` (3 subsequent siblings)
  30 siblings, 0 replies; 58+ messages in thread
From: H. Peter Anvin @ 2006-06-28  5:17 UTC (permalink / raw)
  To: linux-kernel, klibc; +Cc: H. Peter Anvin

[klibc] A port of gzip to klibc

A port of the gzip utility to klibc.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>

---
commit 973116495f231a6775ef098df4481a34a38bfff7
tree 90eee8941bc6fbffcfb0ca49cbe924b85641a70a
parent a359e7a5083122cf32f9b4dabd63af25a60646d9
author H. Peter Anvin <hpa@zytor.com> Tue, 27 Jun 2006 20:51:13 -0700
committer H. Peter Anvin <hpa@zytor.com> Tue, 27 Jun 2006 20:51:13 -0700

 usr/Kbuild          |    2 
 usr/gzip/COPYING    |  339 ++++++++++++++
 usr/gzip/Kbuild     |   25 +
 usr/gzip/README     |  144 ++++++
 usr/gzip/bits.c     |  200 ++++++++
 usr/gzip/deflate.c  |  759 ++++++++++++++++++++++++++++++++
 usr/gzip/gzip.c     | 1214 +++++++++++++++++++++++++++++++++++++++++++++++++++
 usr/gzip/gzip.h     |  298 +++++++++++++
 usr/gzip/inflate.c  |  950 ++++++++++++++++++++++++++++++++++++++++
 usr/gzip/revision.h |   11 
 usr/gzip/tailor.h   |   50 ++
 usr/gzip/trees.c    | 1075 +++++++++++++++++++++++++++++++++++++++++++++
 usr/gzip/unzip.c    |   77 +++
 usr/gzip/util.c     |  372 ++++++++++++++++
 usr/gzip/zip.c      |  110 +++++
 15 files changed, 5625 insertions(+), 1 deletions(-)

Patch suppressed due to size (203 K), available at:
http://www.kernel.org/pub/linux/kernel/people/hpa/klibc-patchset/27-a-port-of-gzip-to-klibc.patch

^ permalink raw reply	[flat|nested] 58+ messages in thread

* [klibc 28/31] sparc64: transmit arch-specific options to kinit via /arch.cmd
  2006-06-28  5:17 [klibc 00/31] klibc as a historyless patchset (updated and reorganized) H. Peter Anvin
                   ` (26 preceding siblings ...)
  2006-06-28  5:17 ` [klibc 27/31] A port of gzip to klibc H. Peter Anvin
@ 2006-06-28  5:17 ` H. Peter Anvin
  2006-06-28  5:17 ` [klibc 29/31] sparc32: transfer arch-specific options to /arch.cmd H. Peter Anvin
                   ` (2 subsequent siblings)
  30 siblings, 0 replies; 58+ messages in thread
From: H. Peter Anvin @ 2006-06-28  5:17 UTC (permalink / raw)
  To: linux-kernel, klibc; +Cc: H. Peter Anvin

Sparc64 has support for a bunch of architecture-specific options
taken from the PROM.  Convert them to kernel command line form and
write the file /arch.cmd in the rootfs, which can be recovered by
kinit and processed.  The kinit support has already been committed.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>

---
commit 921aaa1bc54bbcdc3a91d3ea4f23b2b13d42699d
tree 7e25561f0762b93f3793b8593276c58898d4b8da
parent 973116495f231a6775ef098df4481a34a38bfff7
author H. Peter Anvin <hpa@zytor.com> Wed, 24 May 2006 22:44:55 -0700
committer H. Peter Anvin <hpa@zytor.com> Tue, 27 Jun 2006 20:51:15 -0700

 arch/sparc64/kernel/setup.c |   92 +++++++++++++++++++++++++++++--------------
 1 files changed, 61 insertions(+), 31 deletions(-)

diff --git a/arch/sparc64/kernel/setup.c b/arch/sparc64/kernel/setup.c
index a6a7d81..4bdfd22 100644
--- a/arch/sparc64/kernel/setup.c
+++ b/arch/sparc64/kernel/setup.c
@@ -32,6 +32,7 @@ #include <linux/root_dev.h>
 #include <linux/interrupt.h>
 #include <linux/cpu.h>
 #include <linux/initrd.h>
+#include <linux/fcntl.h>
 
 #include <asm/system.h>
 #include <asm/io.h>
@@ -102,7 +103,7 @@ int obp_system_intr(void)
 	return 0;
 }
 
-/* 
+/*
  * Process kernel command line switches that are specific to the
  * SPARC or that require special low-level processing.
  */
@@ -214,8 +215,6 @@ #define RAMDISK_IMAGE_START_MASK	0x07FF
 #define RAMDISK_PROMPT_FLAG		0x8000
 #define RAMDISK_LOAD_FLAG		0x4000
 
-extern int root_mountflags;
-
 char reboot_command[COMMAND_LINE_SIZE];
 
 static struct pt_regs fake_swapper_regs = { { 0, }, 0, 0, 0, 0 };
@@ -315,6 +314,64 @@ void __init sun4v_patch(void)
 	}
 }
 
+/*
+ * Platform-specific configuration commands which don't come from
+ * the actual kernel command line.  Write them into a file in rootfs
+ * so kinit can pick them up.
+ */
+static int __init set_arch_init_commands(void)
+{
+	int fd = sys_open("/arch.cmd", O_WRONLY|O_CREAT|O_APPEND, 0666);
+	int chosen;
+	u32 cl, sv, gw;
+	char buffer[256];
+	int len = 0;
+
+	if (fd < 0)
+		return fd;
+
+	buffer[0] = 'r';
+	buffer[1] = root_flags ? 'o' : 'w';
+	buffer[2] = '\n';
+	len = 3;
+
+#ifdef CONFIG_BLK_DEV_RAM
+	len += min((int)(sizeof buffer - 1 - len),
+		   snprintf(buffer+len, sizeof buffer - len,
+			    "ramdisk_start=%u\n"
+			    "prompt_ramdisk=%d\n"
+			    "load_ramdisk=%d\n",
+			    ram_flags & RAMDISK_IMAGE_START_MASK,
+			    !!(ram_flags & RAMDISK_PROMPT_FLAG),
+			    !!(ram_flags & RAMDISK_LOAD_FLAG)));
+#endif
+
+	chosen = prom_finddevice("/chosen");
+	cl = prom_getintdefault(chosen, "client-ip", 0);
+	sv = prom_getintdefault(chosen, "server-ip", 0);
+	gw = prom_getintdefault(chosen, "gateway-ip", 0);
+
+	if (cl && sv) {
+		len += min((int)(sizeof buffer - 1 - len),
+			   snprintf(buffer+len, sizeof buffer - len,
+				    "ip=%u.%u.%u.%u:%u.%u.%u.%u:"
+				    "%u.%u.%u.%u\n",
+				    (u8)(cl >> 24), (u8)(cl >> 16),
+				    (u8)(cl >> 8), (u8)cl,
+				    (u8)(sv >> 24), (u8)(sv >> 16),
+				    (u8)(sv >> 8), (u8)sv,
+				    (u8)(gw >> 24), (u8)(gw >> 16),
+				    (u8)(gw >> 8), (u8)gw));
+	}
+
+	sys_write(fd, buffer, len);
+	sys_close(fd);
+
+	return 0;
+}
+
+late_initcall(set_arch_init_commands);
+
 #ifdef CONFIG_SMP
 void __init boot_cpu_id_too_large(int cpu)
 {
@@ -345,37 +402,10 @@ #endif
 
 	idprom_init();
 
-	if (!root_flags)
-		root_mountflags &= ~MS_RDONLY;
 	ROOT_DEV = old_decode_dev(root_dev);
-#ifdef CONFIG_BLK_DEV_RAM
-	rd_image_start = ram_flags & RAMDISK_IMAGE_START_MASK;
-	rd_prompt = ((ram_flags & RAMDISK_PROMPT_FLAG) != 0);
-	rd_doload = ((ram_flags & RAMDISK_LOAD_FLAG) != 0);	
-#endif
 
 	task_thread_info(&init_task)->kregs = &fake_swapper_regs;
 
-#ifdef CONFIG_IP_PNP
-	if (!ic_set_manually) {
-		int chosen = prom_finddevice ("/chosen");
-		u32 cl, sv, gw;
-		
-		cl = prom_getintdefault (chosen, "client-ip", 0);
-		sv = prom_getintdefault (chosen, "server-ip", 0);
-		gw = prom_getintdefault (chosen, "gateway-ip", 0);
-		if (cl && sv) {
-			ic_myaddr = cl;
-			ic_servaddr = sv;
-			if (gw)
-				ic_gateway = gw;
-#if defined(CONFIG_IP_PNP_BOOTP) || defined(CONFIG_IP_PNP_RARP)
-			ic_proto_enabled = 0;
-#endif
-		}
-	}
-#endif
-
 	/* Get boot processor trap_block[] setup.  */
 	init_cur_cpu_trap(current_thread_info());
 
@@ -438,7 +468,7 @@ static int ncpus_probed;
 
 static int show_cpuinfo(struct seq_file *m, void *__unused)
 {
-	seq_printf(m, 
+	seq_printf(m,
 		   "cpu\t\t: %s\n"
 		   "fpu\t\t: %s\n"
 		   "prom\t\t: %s\n"

^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [klibc 29/31] sparc32: transfer arch-specific options to /arch.cmd
  2006-06-28  5:17 [klibc 00/31] klibc as a historyless patchset (updated and reorganized) H. Peter Anvin
                   ` (27 preceding siblings ...)
  2006-06-28  5:17 ` [klibc 28/31] sparc64: transmit arch-specific options to kinit via /arch.cmd H. Peter Anvin
@ 2006-06-28  5:17 ` H. Peter Anvin
  2006-06-28  5:17 ` [klibc 30/31] Remove in-kernel resume-from-disk invocation code H. Peter Anvin
  2006-06-28  5:17 ` [klibc 31/31] Remove in-kernel root-mounting code H. Peter Anvin
  30 siblings, 0 replies; 58+ messages in thread
From: H. Peter Anvin @ 2006-06-28  5:17 UTC (permalink / raw)
  To: linux-kernel, klibc; +Cc: H. Peter Anvin

Boot options which have been obtained in an architecture-specific
fashion have to be copied to /arch.cmd in the rootfs.  This implements
that functionality for sparc32; the code is identical to sparc64 minus
the openprom support for obtaining nfsroot options.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>

---
commit 15d00a4525e5127f0cb4ff31fae3c80c87d3212e
tree c55726dfc288f0ceee45ae53aa47978a0a9a0f99
parent 921aaa1bc54bbcdc3a91d3ea4f23b2b13d42699d
author H. Peter Anvin <hpa@zytor.com> Thu, 25 May 2006 22:34:47 -0700
committer H. Peter Anvin <hpa@zytor.com> Tue, 27 Jun 2006 20:51:17 -0700

 arch/sparc/kernel/setup.c |   47 ++++++++++++++++++++++++++++++++++++---------
 1 files changed, 38 insertions(+), 9 deletions(-)

diff --git a/arch/sparc/kernel/setup.c b/arch/sparc/kernel/setup.c
index a893a9c..f7c4673 100644
--- a/arch/sparc/kernel/setup.c
+++ b/arch/sparc/kernel/setup.c
@@ -241,8 +241,6 @@ #define RAMDISK_IMAGE_START_MASK	0x07FF
 #define RAMDISK_PROMPT_FLAG		0x8000
 #define RAMDISK_LOAD_FLAG		0x4000
 
-extern int root_mountflags;
-
 char reboot_command[COMMAND_LINE_SIZE];
 enum sparc_cpu sparc_cpu_model;
 
@@ -329,14 +327,7 @@ #endif
 	}
 	pfn_base = phys_base >> PAGE_SHIFT;
 
-	if (!root_flags)
-		root_mountflags &= ~MS_RDONLY;
 	ROOT_DEV = old_decode_dev(root_dev);
-#ifdef CONFIG_BLK_DEV_RAM
-	rd_image_start = ram_flags & RAMDISK_IMAGE_START_MASK;
-	rd_prompt = ((ram_flags & RAMDISK_PROMPT_FLAG) != 0);
-	rd_doload = ((ram_flags & RAMDISK_LOAD_FLAG) != 0);	
-#endif
 
 	prom_setsync(prom_sync_me);
 
@@ -389,6 +380,44 @@ static int __init set_preferred_console(
 }
 console_initcall(set_preferred_console);
 
+/*
+ * Platform-specific configuration commands which don't come from
+ * the actual kernel command line.  Write them into a file in rootfs
+ * so kinit can pick them up.
+ */
+static int __init set_arch_init_commands(void)
+{
+	int fd = sys_open("/arch.cmd", O_WRONLY|O_CREAT|O_APPEND, 0666);
+	char buffer[256];
+	int len = 0;
+
+	if (fd < 0)
+		return fd;
+
+	buffer[0] = 'r';
+	buffer[1] = root_flags ? 'o' : 'w';
+	buffer[2] = '\n';
+	len = 3;
+
+#ifdef CONFIG_BLK_DEV_RAM
+	len += min((int)(sizeof buffer - 1 - len),
+		   snprintf(buffer+len, sizeof buffer - len,
+			    "ramdisk_start=%u\n"
+			    "prompt_ramdisk=%d\n"
+			    "load_ramdisk=%d\n",
+			    ram_flags & RAMDISK_IMAGE_START_MASK,
+			    !!(ram_flags & RAMDISK_PROMPT_FLAG),
+			    !!(ram_flags & RAMDISK_LOAD_FLAG)));
+#endif
+
+	sys_write(fd, buffer, len);
+	sys_close(fd);
+
+	return 0;
+}
+
+late_initcall(set_arch_init_commands);
+
 extern char *sparc_cpu_type;
 extern char *sparc_fpu_type;
 

^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [klibc 30/31] Remove in-kernel resume-from-disk invocation code
  2006-06-28  5:17 [klibc 00/31] klibc as a historyless patchset (updated and reorganized) H. Peter Anvin
                   ` (28 preceding siblings ...)
  2006-06-28  5:17 ` [klibc 29/31] sparc32: transfer arch-specific options to /arch.cmd H. Peter Anvin
@ 2006-06-28  5:17 ` H. Peter Anvin
  2006-07-05 23:40   ` Nigel Cunningham
  2006-06-28  5:17 ` [klibc 31/31] Remove in-kernel root-mounting code H. Peter Anvin
  30 siblings, 1 reply; 58+ messages in thread
From: H. Peter Anvin @ 2006-06-28  5:17 UTC (permalink / raw)
  To: linux-kernel, klibc; +Cc: H. Peter Anvin

This removes the part of resume from disk that have been replaced by
functionality in kinit.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>

---
commit 72226912c1128958df215fcfc10b91f4e27bfa79
tree d46fecb176127faa119520ff7b066d5e05a927d1
parent 15d00a4525e5127f0cb4ff31fae3c80c87d3212e
author H. Peter Anvin <hpa@zytor.com> Tue, 27 Jun 2006 20:51:20 -0700
committer H. Peter Anvin <hpa@zytor.com> Tue, 27 Jun 2006 20:51:20 -0700

 kernel/power/disk.c |   45 ++++-----------------------------------------
 1 files changed, 4 insertions(+), 41 deletions(-)

diff --git a/kernel/power/disk.c b/kernel/power/disk.c
index e13e740..a8115c3 100644
--- a/kernel/power/disk.c
+++ b/kernel/power/disk.c
@@ -22,8 +22,6 @@ #include <linux/pm.h>
 #include "power.h"
 
 
-static int noresume = 0;
-char resume_file[256] = CONFIG_PM_STD_PARTITION;
 dev_t swsusp_resume_device;
 
 /**
@@ -166,26 +164,13 @@ static int software_resume(void)
 
 	down(&pm_sem);
 	if (!swsusp_resume_device) {
-		if (!strlen(resume_file)) {
-			up(&pm_sem);
-			return -ENOENT;
-		}
-		swsusp_resume_device = name_to_dev_t(resume_file);
-		pr_debug("swsusp: Resume From Partition %s\n", resume_file);
-	} else {
-		pr_debug("swsusp: Resume From Partition %d:%d\n",
-			 MAJOR(swsusp_resume_device), MINOR(swsusp_resume_device));
-	}
-
-	if (noresume) {
-		/**
-		 * FIXME: If noresume is specified, we need to find the partition
-		 * and reset it back to normal swap space.
-		 */
-		up(&pm_sem);
+		pr_debug("swsusp: No device given!\n");
 		return 0;
 	}
 
+	pr_debug("swsusp: Resume From Partition %d:%d\n",
+		 MAJOR(swsusp_resume_device), MINOR(swsusp_resume_device));
+
 	pr_debug("PM: Checking swsusp image.\n");
 
 	if ((error = swsusp_check()))
@@ -228,8 +213,6 @@ static int software_resume(void)
 	return 0;
 }
 
-late_initcall(software_resume);
-
 
 static const char * const pm_disk_modes[] = {
 	[PM_DISK_FIRMWARE]	= "firmware",
@@ -333,7 +316,6 @@ static ssize_t resume_store(struct subsy
 	swsusp_resume_device = res;
 	up(&pm_sem);
 	printk("Attempting manual resume\n");
-	noresume = 0;
 	software_resume();
 	ret = n;
 out:
@@ -380,22 +362,3 @@ static int __init pm_disk_init(void)
 }
 
 core_initcall(pm_disk_init);
-
-
-static int __init resume_setup(char *str)
-{
-	if (noresume)
-		return 1;
-
-	strncpy( resume_file, str, 255 );
-	return 1;
-}
-
-static int __init noresume_setup(char *str)
-{
-	noresume = 1;
-	return 1;
-}
-
-__setup("noresume", noresume_setup);
-__setup("resume=", resume_setup);

^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [klibc 31/31] Remove in-kernel root-mounting code
  2006-06-28  5:17 [klibc 00/31] klibc as a historyless patchset (updated and reorganized) H. Peter Anvin
                   ` (29 preceding siblings ...)
  2006-06-28  5:17 ` [klibc 30/31] Remove in-kernel resume-from-disk invocation code H. Peter Anvin
@ 2006-06-28  5:17 ` H. Peter Anvin
  30 siblings, 0 replies; 58+ messages in thread
From: H. Peter Anvin @ 2006-06-28  5:17 UTC (permalink / raw)
  To: linux-kernel, klibc; +Cc: H. Peter Anvin

[klibc] Remove in-kernel root-mounting code

This removes the root mounting code from the kernel proper.  This
includes ip autoconfiguration, nfsroot, and name_to_dev_t().

Signed-off-by: H. Peter Anvin <hpa@zytor.com>

---
commit 8a5ac82c851f56902095db4b78150bac5ea532a6
tree d62b2a5763d9becb8bd37ddc0e69d65eb477b3c5
parent 72226912c1128958df215fcfc10b91f4e27bfa79
author H. Peter Anvin <hpa@zytor.com> Tue, 27 Jun 2006 20:51:23 -0700
committer H. Peter Anvin <hpa@zytor.com> Tue, 27 Jun 2006 20:51:23 -0700

 arch/i386/kernel/setup.c   |    8 
 arch/x86_64/kernel/setup.c |    7 
 fs/Kconfig                 |   14 
 fs/nfs/Makefile            |    1 
 fs/nfs/mount_clnt.c        |  191 ------
 fs/nfs/nfsroot.c           |  525 ---------------
 include/linux/mount.h      |    1 
 init/Makefile              |    8 
 init/do_mounts.c           |  437 -------------
 init/do_mounts.h           |   91 ---
 init/do_mounts_devfs.c     |  137 ----
 init/do_mounts_initrd.c    |  125 ----
 init/do_mounts_md.c        |  286 --------
 init/do_mounts_rd.c        |  429 -------------
 init/initramfs.c           |    3 
 init/main.c                |   45 -
 net/ipv4/Makefile          |    1 
 net/ipv4/ipconfig.c        | 1510 --------------------------------------------
 18 files changed, 21 insertions(+), 3798 deletions(-)

Patch suppressed due to size (103 K), available at:
http://www.kernel.org/pub/linux/kernel/people/hpa/klibc-patchset/31-remove-in-kernel-root-mounting-code.patch

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [klibc 07/31] i386 support for klibc
  2006-06-28  5:17 ` [klibc 07/31] i386 " H. Peter Anvin
@ 2006-06-28  7:37   ` Jan Engelhardt
  2006-06-28 15:33     ` H. Peter Anvin
  0 siblings, 1 reply; 58+ messages in thread
From: Jan Engelhardt @ 2006-06-28  7:37 UTC (permalink / raw)
  To: H. Peter Anvin; +Cc: linux-kernel, klibc


> usr/klibc/arch/i386/libgcc/__ashldi3.S   |   29 +++++++
> usr/klibc/arch/i386/libgcc/__ashrdi3.S   |   29 +++++++
> usr/klibc/arch/i386/libgcc/__lshrdi3.S   |   29 +++++++
> usr/klibc/arch/i386/libgcc/__muldi3.S    |   34 ++++++++
> usr/klibc/arch/i386/libgcc/__negdi2.S    |   21 +++++

No divdi3?



Jan Engelhardt
-- 

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [klibc 07/31] i386 support for klibc
  2006-06-28  7:37   ` Jan Engelhardt
@ 2006-06-28 15:33     ` H. Peter Anvin
  2006-06-28 16:44       ` H. Peter Anvin
  2006-06-29  0:14       ` Roman Zippel
  0 siblings, 2 replies; 58+ messages in thread
From: H. Peter Anvin @ 2006-06-28 15:33 UTC (permalink / raw)
  To: Jan Engelhardt; +Cc: linux-kernel, klibc

Jan Engelhardt wrote:
>> usr/klibc/arch/i386/libgcc/__ashldi3.S   |   29 +++++++
>> usr/klibc/arch/i386/libgcc/__ashrdi3.S   |   29 +++++++
>> usr/klibc/arch/i386/libgcc/__lshrdi3.S   |   29 +++++++
>> usr/klibc/arch/i386/libgcc/__muldi3.S    |   34 ++++++++
>> usr/klibc/arch/i386/libgcc/__negdi2.S    |   21 +++++
> 
> No divdi3?

The i386 ones are a bit special... usually the reason I have added 
libgcc functions is that on some architectures, gcc has various problems 
linking with libgcc in some configurations.  That is not the case on 
i386, but some of the libgcc functions are *way* bigger than the need to 
be (overall, the quality of code in libgcc seems horrid, across 
architectures.)

Since i386 is such an important architecture I added a handful of 
assembly functions for stuff that could be done in a very small amount 
of space.

	-hpa

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [klibc 04/31] alpha support for klibc
  2006-06-28  5:17 ` [klibc 04/31] alpha support for klibc H. Peter Anvin
@ 2006-06-28 15:43   ` Richard Henderson
  2006-06-28 15:51     ` H. Peter Anvin
  0 siblings, 1 reply; 58+ messages in thread
From: Richard Henderson @ 2006-06-28 15:43 UTC (permalink / raw)
  To: H. Peter Anvin; +Cc: linux-kernel, klibc

On Tue, Jun 27, 2006 at 10:17:04PM -0700, H. Peter Anvin wrote:
> +# Special CFLAGS for the divide code
> +DIVCFLAGS = $(KLIBCREQFLAGS) $(KLIBCARCHREQFLAGS) \
> +	-O3 -fomit-frame-pointer -fcall-saved-1 -fcall-saved-2 \
> +	-fcall-saved-3 -fcall-saved-4 -fcall-saved-5 -fcall-saved-6 \
> +	-fcall-saved-7 -fcall-saved-8 -ffixed-15 -fcall-saved-16 \
> +	-fcall-saved-17 -fcall-saved-18 -fcall-saved-19 -fcall-saved-20 \
> +	-fcall-saved-21 -fcall-saved-22 -ffixed-23 -fcall-saved-24 \
> +	-ffixed-25 -ffixed-27

These routines absolutely cannot be written in C.  The return value
goes in a different register, which you cannot modify via compiler
flags.  Please use the hand-coded assembly from linux/arch/alpha/lib/.


r~

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [klibc 04/31] alpha support for klibc
  2006-06-28 15:43   ` Richard Henderson
@ 2006-06-28 15:51     ` H. Peter Anvin
  0 siblings, 0 replies; 58+ messages in thread
From: H. Peter Anvin @ 2006-06-28 15:51 UTC (permalink / raw)
  To: H. Peter Anvin, linux-kernel, klibc

Richard Henderson wrote:
> On Tue, Jun 27, 2006 at 10:17:04PM -0700, H. Peter Anvin wrote:
>> +# Special CFLAGS for the divide code
>> +DIVCFLAGS = $(KLIBCREQFLAGS) $(KLIBCARCHREQFLAGS) \
>> +	-O3 -fomit-frame-pointer -fcall-saved-1 -fcall-saved-2 \
>> +	-fcall-saved-3 -fcall-saved-4 -fcall-saved-5 -fcall-saved-6 \
>> +	-fcall-saved-7 -fcall-saved-8 -ffixed-15 -fcall-saved-16 \
>> +	-fcall-saved-17 -fcall-saved-18 -fcall-saved-19 -fcall-saved-20 \
>> +	-fcall-saved-21 -fcall-saved-22 -ffixed-23 -fcall-saved-24 \
>> +	-ffixed-25 -ffixed-27
> 
> These routines absolutely cannot be written in C.  The return value
> goes in a different register, which you cannot modify via compiler
> flags.  Please use the hand-coded assembly from linux/arch/alpha/lib/.
> 

Funny, we had this discussion a couple of years ago...

What the above does is generate a calling convention with the right 
number of (various types of) registers.  Then the Makefile swaps the 
registers that the compiler outputs.  It's a bit of a hack, but it's 
reliable and works.  The resulting code isn't as compact at divide.S, 
though.

However, I've tried to keep the code under the BSD license, mostly for 
the benefit of the standalone klibc version (static linkage being the 
norm, after all); so I don't want to crib kernel code unless the owner 
consents to relicensing.  I have cribbed some NetBSD code in some 
places, though.

	-hpa

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [klibc 07/31] i386 support for klibc
  2006-06-28 15:33     ` H. Peter Anvin
@ 2006-06-28 16:44       ` H. Peter Anvin
  2006-06-29  0:14       ` Roman Zippel
  1 sibling, 0 replies; 58+ messages in thread
From: H. Peter Anvin @ 2006-06-28 16:44 UTC (permalink / raw)
  To: H. Peter Anvin; +Cc: Jan Engelhardt, linux-kernel, klibc

H. Peter Anvin wrote:
> Jan Engelhardt wrote:
>>> usr/klibc/arch/i386/libgcc/__ashldi3.S   |   29 +++++++
>>> usr/klibc/arch/i386/libgcc/__ashrdi3.S   |   29 +++++++
>>> usr/klibc/arch/i386/libgcc/__lshrdi3.S   |   29 +++++++
>>> usr/klibc/arch/i386/libgcc/__muldi3.S    |   34 ++++++++
>>> usr/klibc/arch/i386/libgcc/__negdi2.S    |   21 +++++
>>
>> No divdi3?
> 
> The i386 ones are a bit special... usually the reason I have added 
> libgcc functions is that on some architectures, gcc has various problems 
> linking with libgcc in some configurations.  That is not the case on 
> i386, but some of the libgcc functions are *way* bigger than the need to 
> be (overall, the quality of code in libgcc seems horrid, across 
> architectures.)
> 
> Since i386 is such an important architecture I added a handful of 
> assembly functions for stuff that could be done in a very small amount 
> of space.
> 

Correction... divdi3, moddi3, udivdi3, umoddi3 and udivmoddi4 are also 
provided, but are implemented as generic subroutines in C instead of 
assembly:

KLIBCARCHOBJS = \
         arch/$(KLIBCARCH)/socketcall.o \
         arch/$(KLIBCARCH)/setjmp.o \
         arch/$(KLIBCARCH)/syscall.o \
         arch/$(KLIBCARCH)/varsyscall.o \
         arch/$(KLIBCARCH)/open.o \
         arch/$(KLIBCARCH)/openat.o \
         arch/$(KLIBCARCH)/sigreturn.o \
         arch/$(KLIBCARCH)/vfork.o \
         arch/$(KLIBCARCH)/libgcc/__ashldi3.o \
         arch/$(KLIBCARCH)/libgcc/__ashrdi3.o \
         arch/$(KLIBCARCH)/libgcc/__lshrdi3.o \
         arch/$(KLIBCARCH)/libgcc/__muldi3.o \
         arch/$(KLIBCARCH)/libgcc/__negdi2.o \
         libgcc/__divdi3.o \
         libgcc/__moddi3.o \
         libgcc/__udivdi3.o \
         libgcc/__umoddi3.o \
         libgcc/__udivmoddi4.o

It probably would be more efficient if i386's native division 
instructions could be exploited, but it hasn't been a pressing issue.

	-hpa

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [klibc 07/31] i386 support for klibc
  2006-06-28 15:33     ` H. Peter Anvin
  2006-06-28 16:44       ` H. Peter Anvin
@ 2006-06-29  0:14       ` Roman Zippel
  2006-06-29  0:45         ` H. Peter Anvin
  1 sibling, 1 reply; 58+ messages in thread
From: Roman Zippel @ 2006-06-29  0:14 UTC (permalink / raw)
  To: H. Peter Anvin; +Cc: Jan Engelhardt, linux-kernel, klibc

Hi,

On Wed, 28 Jun 2006, H. Peter Anvin wrote:

> The i386 ones are a bit special... usually the reason I have added libgcc
> functions is that on some architectures, gcc has various problems linking with
> libgcc in some configurations.

If gcc has problems to link its own libgcc you really have a serious 
problem...
The standard libgcc may not be as small as you like, but it still should 
be the first choice. If there is a problem with it, the gcc people do 
accept patches.

bye, Roman

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [klibc 07/31] i386 support for klibc
  2006-06-29  0:14       ` Roman Zippel
@ 2006-06-29  0:45         ` H. Peter Anvin
  2006-06-29 23:43           ` Roman Zippel
  0 siblings, 1 reply; 58+ messages in thread
From: H. Peter Anvin @ 2006-06-29  0:45 UTC (permalink / raw)
  To: Roman Zippel; +Cc: Jan Engelhardt, linux-kernel, klibc

Roman Zippel wrote:
> Hi,
> 
> On Wed, 28 Jun 2006, H. Peter Anvin wrote:
> 
>> The i386 ones are a bit special... usually the reason I have added libgcc
>> functions is that on some architectures, gcc has various problems linking with
>> libgcc in some configurations.
> 
> If gcc has problems to link its own libgcc you really have a serious 
> problem...

The way libgcc is handled inside gcc is, indeed, completely screwed up; 
even the gcc people admit that.  They pretty much don't have a way to 
handle the effects of compiler options on libgcc, especially the ones 
that affect binary compatibility.

However, that affects only a small minority of configurations (MIPS is one.)

> The standard libgcc may not be as small as you like, but it still should 
> be the first choice. If there is a problem with it, the gcc people do 
> accept patches.

That's just an asinine statement.  Under that logic we should just 
forget about the kernel and go hack the gcc bugs du jour; we certainly 
have enough workarounds for gcc bugs in the kernel.

There is absolutely nothing wrong with providing an override for a 
function which has well-defined semantics.  If new functions are needed, 
they are pulled from libgcc.

	-hpa

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [klibc 07/31] i386 support for klibc
  2006-06-29  0:45         ` H. Peter Anvin
@ 2006-06-29 23:43           ` Roman Zippel
  2006-06-29 23:54             ` H. Peter Anvin
  0 siblings, 1 reply; 58+ messages in thread
From: Roman Zippel @ 2006-06-29 23:43 UTC (permalink / raw)
  To: H. Peter Anvin; +Cc: Jan Engelhardt, linux-kernel, klibc

Hi,

On Wed, 28 Jun 2006, H. Peter Anvin wrote:

> > On Wed, 28 Jun 2006, H. Peter Anvin wrote:
> > 
> > > The i386 ones are a bit special... usually the reason I have added libgcc
> > > functions is that on some architectures, gcc has various problems linking
> > > with
> > > libgcc in some configurations.
> > 
> > If gcc has problems to link its own libgcc you really have a serious
> > problem...
> 
> The way libgcc is handled inside gcc is, indeed, completely screwed up; even
> the gcc people admit that.  They pretty much don't have a way to handle the
> effects of compiler options on libgcc, especially the ones that affect binary
> compatibility.

Nobody said it's perfect. Especially the last point speaks against 
multiple versions of the same library, as it makes it hard to mix 
binaries/libraries. With a single kinit binary it's not really a problem 
yet, but will it stay this way?

> > The standard libgcc may not be as small as you like, but it still should be
> > the first choice. If there is a problem with it, the gcc people do accept
> > patches.
> 
> That's just an asinine statement.  Under that logic we should just forget
> about the kernel and go hack the gcc bugs du jour; we certainly have enough
> workarounds for gcc bugs in the kernel.

Sorry, but I can't follow this logic.

bye, Roman

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [klibc 07/31] i386 support for klibc
  2006-06-29 23:43           ` Roman Zippel
@ 2006-06-29 23:54             ` H. Peter Anvin
  2006-06-30  0:23               ` Roman Zippel
  0 siblings, 1 reply; 58+ messages in thread
From: H. Peter Anvin @ 2006-06-29 23:54 UTC (permalink / raw)
  To: Roman Zippel; +Cc: Jan Engelhardt, linux-kernel, klibc

Roman Zippel wrote:

>> The way libgcc is handled inside gcc is, indeed, completely screwed up; even
>> the gcc people admit that.  They pretty much don't have a way to handle the
>> effects of compiler options on libgcc, especially the ones that affect binary
>> compatibility.
> 
> Nobody said it's perfect. Especially the last point speaks against 
> multiple versions of the same library, as it makes it hard to mix 
> binaries/libraries. With a single kinit binary it's not really a problem 
> yet, but will it stay this way?

What on earth are you talking about?

a. The semantics of these functions are well-defined, stable, and 
documented in the gcc documentation.  It's not like they have 
compiler-version-specific definitions that could change.

b. For static binaries, this is no issue.  klibc is shared, not dynamic 
(thus eliminating the need for a space-consuming dynamic linker), but it 
also means that there is no cross-version calling; each build of the 
shared klibc library has a hashed filename, thus allowing multiple 
versions of klibc to coexist if absolutely necessary.

Either way, this is a red herring.

>>> The standard libgcc may not be as small as you like, but it still should be
>>> the first choice. If there is a problem with it, the gcc people do accept
>>> patches.
>> That's just an asinine statement.  Under that logic we should just forget
>> about the kernel and go hack the gcc bugs du jour; we certainly have enough
>> workarounds for gcc bugs in the kernel.
> 
> Sorry, but I can't follow this logic.

I'm not entirely surprised.

	-hpa

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [klibc 07/31] i386 support for klibc
  2006-06-29 23:54             ` H. Peter Anvin
@ 2006-06-30  0:23               ` Roman Zippel
  2006-06-30  1:28                 ` [klibc] " Aaron Griffin
  0 siblings, 1 reply; 58+ messages in thread
From: Roman Zippel @ 2006-06-30  0:23 UTC (permalink / raw)
  To: H. Peter Anvin; +Cc: Jan Engelhardt, linux-kernel, klibc

Hi,

On Thu, 29 Jun 2006, H. Peter Anvin wrote:

> a. The semantics of these functions are well-defined, stable, and documented
> in the gcc documentation.  It's not like they have compiler-version-specific
> definitions that could change.

It's documented in the internals section for gcc's own purposes. This
doesn't make it a public API.

> b. For static binaries, this is no issue.  klibc is shared, not dynamic (thus
> eliminating the need for a space-consuming dynamic linker), but it also means
> that there is no cross-version calling; each build of the shared klibc library
> has a hashed filename, thus allowing multiple versions of klibc to coexist if
> absolutely necessary.
> 
> Either way, this is a red herring.

Since you don't explain your plans, it's hard to tell.

> > > > The standard libgcc may not be as small as you like, but it still should
> > > > be
> > > > the first choice. If there is a problem with it, the gcc people do
> > > > accept
> > > > patches.
> > > That's just an asinine statement.  Under that logic we should just forget
> > > about the kernel and go hack the gcc bugs du jour; we certainly have
> > > enough
> > > workarounds for gcc bugs in the kernel.
> > 
> > Sorry, but I can't follow this logic.
> 
> I'm not entirely surprised.

So instead of arguments you try it now with insults... :-(

bye, Roman

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [klibc] [klibc 07/31] i386 support for klibc
  2006-06-30  0:23               ` Roman Zippel
@ 2006-06-30  1:28                 ` Aaron Griffin
  2006-06-30 13:56                   ` Jan Engelhardt
  0 siblings, 1 reply; 58+ messages in thread
From: Aaron Griffin @ 2006-06-30  1:28 UTC (permalink / raw)
  To: Roman Zippel; +Cc: H. Peter Anvin, klibc, Jan Engelhardt, linux-kernel

Hooray! Bickering! Fun times had by all

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [klibc] [klibc 07/31] i386 support for klibc
  2006-06-30  1:28                 ` [klibc] " Aaron Griffin
@ 2006-06-30 13:56                   ` Jan Engelhardt
  0 siblings, 0 replies; 58+ messages in thread
From: Jan Engelhardt @ 2006-06-30 13:56 UTC (permalink / raw)
  To: Aaron Griffin; +Cc: Roman Zippel, H. Peter Anvin, klibc, linux-kernel

>
> Hooray! Bickering! Fun times had by all
>
Yep, it's becoming like the cdrecord threads...


Jan Engelhardt
-- 

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [klibc 30/31] Remove in-kernel resume-from-disk invocation code
  2006-06-28  5:17 ` [klibc 30/31] Remove in-kernel resume-from-disk invocation code H. Peter Anvin
@ 2006-07-05 23:40   ` Nigel Cunningham
  2006-07-05 23:58     ` Joshua Hudson
  2006-07-06  0:11     ` H. Peter Anvin
  0 siblings, 2 replies; 58+ messages in thread
From: Nigel Cunningham @ 2006-07-05 23:40 UTC (permalink / raw)
  To: H. Peter Anvin, Pavel Machek; +Cc: linux-kernel, klibc

[-- Attachment #1: Type: text/plain, Size: 830 bytes --]

Hi.

Sorry for coming late to the party. I received a request to provide a Suspend2 
patch for current -mm this morning, so I've only just had impetus to look at 
the impact of klibc.

On Wednesday 28 June 2006 15:17, H. Peter Anvin wrote:
> This removes the part of resume from disk that have been replaced by
> functionality in kinit.
>
> Signed-off-by: H. Peter Anvin <hpa@zytor.com>

This patch doesn't look right to me. After it is applied, the user will have 
no way of saying that they don't want to resume (noresume). I assume the 
removal of resume= isn't a problem because you're expecting them to use that 
other undocumented way of setting resume= that Pavel mentioned a while ago?

Regards,

Nigel
-- 
Nigel, Michelle and Alisdair Cunningham
5 Mitchell Street
Cobden 3266
Victoria, Australia

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [klibc 30/31] Remove in-kernel resume-from-disk invocation code
  2006-07-05 23:40   ` Nigel Cunningham
@ 2006-07-05 23:58     ` Joshua Hudson
  2006-07-06  0:11     ` H. Peter Anvin
  1 sibling, 0 replies; 58+ messages in thread
From: Joshua Hudson @ 2006-07-05 23:58 UTC (permalink / raw)
  To: linux-kernel

I'll take my own guess that kinit reads the kernel command line and
handles both resume= and noresume itself. I've done that with a few
other cases, so it is certainly possible.

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [klibc 30/31] Remove in-kernel resume-from-disk invocation code
  2006-07-05 23:40   ` Nigel Cunningham
  2006-07-05 23:58     ` Joshua Hudson
@ 2006-07-06  0:11     ` H. Peter Anvin
  2006-07-06  0:37       ` Nigel Cunningham
  2006-07-06  8:31       ` [klibc] " maximilian attems
  1 sibling, 2 replies; 58+ messages in thread
From: H. Peter Anvin @ 2006-07-06  0:11 UTC (permalink / raw)
  To: Nigel Cunningham; +Cc: Pavel Machek, linux-kernel, klibc

Nigel Cunningham wrote:
> 
> This patch doesn't look right to me. After it is applied, the user will have 
> no way of saying that they don't want to resume (noresume). I assume the 
> removal of resume= isn't a problem because you're expecting them to use that 
> other undocumented way of setting resume= that Pavel mentioned a while ago?
> 

Yes, they have.  The handing of resume= and noresume are now done in 
kinit; resume is invoked from userspace by direct command only.

There is nothing undocumented about it.

	-hpa

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [klibc 30/31] Remove in-kernel resume-from-disk invocation code
  2006-07-06  0:11     ` H. Peter Anvin
@ 2006-07-06  0:37       ` Nigel Cunningham
  2006-07-06  0:54         ` H. Peter Anvin
  2006-07-06  8:31       ` [klibc] " maximilian attems
  1 sibling, 1 reply; 58+ messages in thread
From: Nigel Cunningham @ 2006-07-06  0:37 UTC (permalink / raw)
  To: H. Peter Anvin; +Cc: Pavel Machek, linux-kernel, klibc

[-- Attachment #1: Type: text/plain, Size: 1020 bytes --]

Hi.

On Thursday 06 July 2006 10:11, H. Peter Anvin wrote:
> Nigel Cunningham wrote:
> > This patch doesn't look right to me. After it is applied, the user will
> > have no way of saying that they don't want to resume (noresume). I assume
> > the removal of resume= isn't a problem because you're expecting them to
> > use that other undocumented way of setting resume= that Pavel mentioned a
> > while ago?
>
> Yes, they have.  The handing of resume= and noresume are now done in
> kinit; resume is invoked from userspace by direct command only.

Ah. So it's still valid to have resume= and noresume on the commandline, and 
klibc greps /proc/cmdline?

So, for Suspend2, would I be ok just leaving people to add the echo 
> /proc/suspend2/do_resume, as we currently do for initrds and initramfses?

> There is nothing undocumented about it.

Ok. I guess my memory is stale :).

Regards,

Nigel
-- 
Nigel, Michelle and Alisdair Cunningham
5 Mitchell Street
Cobden 3266
Victoria, Australia

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [klibc 30/31] Remove in-kernel resume-from-disk invocation code
  2006-07-06  0:37       ` Nigel Cunningham
@ 2006-07-06  0:54         ` H. Peter Anvin
  2006-07-06  1:45           ` Nigel Cunningham
  0 siblings, 1 reply; 58+ messages in thread
From: H. Peter Anvin @ 2006-07-06  0:54 UTC (permalink / raw)
  To: Nigel Cunningham; +Cc: Pavel Machek, linux-kernel, klibc

Nigel Cunningham wrote:
> 
> Ah. So it's still valid to have resume= and noresume on the commandline, and 
> klibc greps /proc/cmdline?
> 

Correct.

> So, for Suspend2, would I be ok just leaving people to add the echo 
>>/proc/suspend2/do_resume, as we currently do for initrds and initramfses?

Well, presumably you want to adjust kinit so that it invokes 
/proc/suspend2/do_resume, instead of or in addition to 
/sys/power/resume; see usr/kinit/resume.c (the code should be bloody 
obvious, I hope...)

	-hpa

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [klibc 30/31] Remove in-kernel resume-from-disk invocation code
  2006-07-06  0:54         ` H. Peter Anvin
@ 2006-07-06  1:45           ` Nigel Cunningham
  2006-07-06  2:18             ` Nigel Cunningham
                               ` (2 more replies)
  0 siblings, 3 replies; 58+ messages in thread
From: Nigel Cunningham @ 2006-07-06  1:45 UTC (permalink / raw)
  To: H. Peter Anvin; +Cc: Pavel Machek, linux-kernel, klibc

[-- Attachment #1: Type: text/plain, Size: 1703 bytes --]

Hi.

On Thursday 06 July 2006 10:54, H. Peter Anvin wrote:
> Nigel Cunningham wrote:
> > Ah. So it's still valid to have resume= and noresume on the commandline,
> > and klibc greps /proc/cmdline?
>
> Correct.
>
> > So, for Suspend2, would I be ok just leaving people to add the echo
> >
> >>/proc/suspend2/do_resume, as we currently do for initrds and initramfses?
>
> Well, presumably you want to adjust kinit so that it invokes
> /proc/suspend2/do_resume, instead of or in addition to
> /sys/power/resume; see usr/kinit/resume.c (the code should be bloody
> obvious, I hope...)

It is.

Is there a klibc howto somewhere? I tried googling for 'klibc howto', reading 
the files in Documentation/ and browsing your klibc mailing list archive 
before asking!

What I'm wondering specifically is: Say a user needs to run some commands to 
set up access to encrypted storage before they can resume. At the moment, 
we'd tell them to put these commands and the echo > do_resume in their 
linuxrc (or init) script prior to mounting their root filesystem. Forgive me 
if I'm asking a stupid question but it's not immediately obvious to me how 
they would now do that. I'd much rather follow a simple howto than spend a 
good amount of time tracing function calls etc. I still see init/initramfs.c, 
and it mentions both CONFIG_BLK_DEV_INITRD and CONFIG_BLK_DEV_RAM. Would I be 
right in surmising that you can still have an initrd or ramfs to do such 
things as the above, after klibc has done its work? If not, is there some 
other way I'm ignorant of?

Regards,

Nigel
-- 
Nigel, Michelle and Alisdair Cunningham
5 Mitchell Street
Cobden 3266
Victoria, Australia

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [klibc 30/31] Remove in-kernel resume-from-disk invocation code
  2006-07-06  1:45           ` Nigel Cunningham
@ 2006-07-06  2:18             ` Nigel Cunningham
  2006-07-06  3:11               ` H. Peter Anvin
  2006-07-06 10:26             ` Pavel Machek
       [not found]             ` <200607061028.k66AS8UB012207@smtp.micromuse.com>
  2 siblings, 1 reply; 58+ messages in thread
From: Nigel Cunningham @ 2006-07-06  2:18 UTC (permalink / raw)
  To: H. Peter Anvin; +Cc: Pavel Machek, linux-kernel, klibc

[-- Attachment #1: Type: text/plain, Size: 1468 bytes --]

Hi again.

(Excuse me replying to myself, but this might help someone else).

On Thursday 06 July 2006 11:45, Nigel Cunningham wrote:
> Is there a klibc howto somewhere? I tried googling for 'klibc howto',
> reading the files in Documentation/ and browsing your klibc mailing list
> archive before asking!

> What I'm wondering specifically is: Say a user needs to run some commands
> to set up access to encrypted storage before they can resume. At the
> moment, we'd tell them to put these commands and the echo > do_resume in
> their linuxrc (or init) script prior to mounting their root filesystem.
> Forgive me if I'm asking a stupid question but it's not immediately obvious
> to me how they would now do that. I'd much rather follow a simple howto
> than spend a good amount of time tracing function calls etc. I still see
> init/initramfs.c, and it mentions both CONFIG_BLK_DEV_INITRD and
> CONFIG_BLK_DEV_RAM. Would I be right in surmising that you can still have
> an initrd or ramfs to do such things as the above, after klibc has done its
> work? If not, is there some other way I'm ignorant of?

For the record, I've since discovered that what you really want is an 
initramfs howto. I think I stuck with those old-fangled initrds for too long. 
Better update my desktop from Mandrake 10 too :)... is there a pattern here?

Nigel
-- 
Nigel, Michelle and Alisdair Cunningham
5 Mitchell Street
Cobden 3266
Victoria, Australia

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [klibc 30/31] Remove in-kernel resume-from-disk invocation code
  2006-07-06  2:18             ` Nigel Cunningham
@ 2006-07-06  3:11               ` H. Peter Anvin
  2006-07-06  3:28                 ` Nigel Cunningham
  0 siblings, 1 reply; 58+ messages in thread
From: H. Peter Anvin @ 2006-07-06  3:11 UTC (permalink / raw)
  To: Nigel Cunningham; +Cc: Pavel Machek, linux-kernel, klibc

Nigel Cunningham wrote:
> Hi again.
> 
> (Excuse me replying to myself, but this might help someone else).
> 
> On Thursday 06 July 2006 11:45, Nigel Cunningham wrote:
>> Is there a klibc howto somewhere? I tried googling for 'klibc howto',
>> reading the files in Documentation/ and browsing your klibc mailing list
>> archive before asking!
> 
>> What I'm wondering specifically is: Say a user needs to run some commands
>> to set up access to encrypted storage before they can resume. At the
>> moment, we'd tell them to put these commands and the echo > do_resume in
>> their linuxrc (or init) script prior to mounting their root filesystem.
>> Forgive me if I'm asking a stupid question but it's not immediately obvious
>> to me how they would now do that. I'd much rather follow a simple howto
>> than spend a good amount of time tracing function calls etc. I still see
>> init/initramfs.c, and it mentions both CONFIG_BLK_DEV_INITRD and
>> CONFIG_BLK_DEV_RAM. Would I be right in surmising that you can still have
>> an initrd or ramfs to do such things as the above, after klibc has done its
>> work? If not, is there some other way I'm ignorant of?
> 
> For the record, I've since discovered that what you really want is an 
> initramfs howto. I think I stuck with those old-fangled initrds for too long. 
> Better update my desktop from Mandrake 10 too :)... is there a pattern here?
> 

Okay, let's try to start from the beginning...

initramfs is, indeed, a replacement for initrd, but it's not a 1:1 map. 
  Instead, initramfs contents -- which can come from multiple sources! 
-- is simply extracted right into rootfs.

kinit is a replacement for the in-kernel root-handling code, as well as 
other related in-kernel code like resume from disk.  It is compiled as a 
monolithic binary for size reasons.

klibc is a very small C library which *can* be used to produce initramfs 
binaries; in particular, it's used to produce kinit, and is small enough 
that it can be realistically included with the kernel distribution.

If you provide your own /init in an initramfs, it will override the 
default, which is /init -> /kinit.  You can then choose to invoke kinit 
if you want to; for example, you could try to resume from suspend2, and 
invoke kinit if that fails.

	-hpa

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [klibc 30/31] Remove in-kernel resume-from-disk invocation code
  2006-07-06  3:11               ` H. Peter Anvin
@ 2006-07-06  3:28                 ` Nigel Cunningham
  0 siblings, 0 replies; 58+ messages in thread
From: Nigel Cunningham @ 2006-07-06  3:28 UTC (permalink / raw)
  To: H. Peter Anvin; +Cc: Pavel Machek, linux-kernel, klibc

[-- Attachment #1: Type: text/plain, Size: 2611 bytes --]

Hi.

On Thursday 06 July 2006 13:11, H. Peter Anvin wrote:
> Nigel Cunningham wrote:
> > Hi again.
> >
> > (Excuse me replying to myself, but this might help someone else).
> >
> > On Thursday 06 July 2006 11:45, Nigel Cunningham wrote:
> >> Is there a klibc howto somewhere? I tried googling for 'klibc howto',
> >> reading the files in Documentation/ and browsing your klibc mailing list
> >> archive before asking!
> >>
> >> What I'm wondering specifically is: Say a user needs to run some
> >> commands to set up access to encrypted storage before they can resume.
> >> At the moment, we'd tell them to put these commands and the echo >
> >> do_resume in their linuxrc (or init) script prior to mounting their root
> >> filesystem. Forgive me if I'm asking a stupid question but it's not
> >> immediately obvious to me how they would now do that. I'd much rather
> >> follow a simple howto than spend a good amount of time tracing function
> >> calls etc. I still see init/initramfs.c, and it mentions both
> >> CONFIG_BLK_DEV_INITRD and CONFIG_BLK_DEV_RAM. Would I be right in
> >> surmising that you can still have an initrd or ramfs to do such things
> >> as the above, after klibc has done its work? If not, is there some other
> >> way I'm ignorant of?
> >
> > For the record, I've since discovered that what you really want is an
> > initramfs howto. I think I stuck with those old-fangled initrds for too
> > long. Better update my desktop from Mandrake 10 too :)... is there a
> > pattern here?
>
> Okay, let's try to start from the beginning...
>
> initramfs is, indeed, a replacement for initrd, but it's not a 1:1 map.
>   Instead, initramfs contents -- which can come from multiple sources!
> -- is simply extracted right into rootfs.
>
> kinit is a replacement for the in-kernel root-handling code, as well as
> other related in-kernel code like resume from disk.  It is compiled as a
> monolithic binary for size reasons.
>
> klibc is a very small C library which *can* be used to produce initramfs
> binaries; in particular, it's used to produce kinit, and is small enough
> that it can be realistically included with the kernel distribution.
>
> If you provide your own /init in an initramfs, it will override the
> default, which is /init -> /kinit.  You can then choose to invoke kinit
> if you want to; for example, you could try to resume from suspend2, and
> invoke kinit if that fails.

Ah... ok. That helps a lot.

Thanks!

Nigel
-- 
Nigel, Michelle and Alisdair Cunningham
5 Mitchell Street
Cobden 3266
Victoria, Australia

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [klibc] [klibc 30/31] Remove in-kernel resume-from-disk invocation code
  2006-07-06  0:11     ` H. Peter Anvin
  2006-07-06  0:37       ` Nigel Cunningham
@ 2006-07-06  8:31       ` maximilian attems
  2006-07-06  8:37         ` H. Peter Anvin
  1 sibling, 1 reply; 58+ messages in thread
From: maximilian attems @ 2006-07-06  8:31 UTC (permalink / raw)
  To: H. Peter Anvin; +Cc: Nigel Cunningham, klibc, linux-kernel, Pavel Machek

On Wed, Jul 05, 2006 at 05:11:07PM -0700, H. Peter Anvin wrote:
> Nigel Cunningham wrote:
> > 
> > This patch doesn't look right to me. After it is applied, the user will have 
> > no way of saying that they don't want to resume (noresume). I assume the 
> > removal of resume= isn't a problem because you're expecting them to use that 
> > other undocumented way of setting resume= that Pavel mentioned a while ago?
> > 
> 
> Yes, they have.  The handing of resume= and noresume are now done in 
> kinit; resume is invoked from userspace by direct command only.

the grumble on kinit is that it is a big monolithic bin.
You have no scriptability and it is not modular.
Very useful pieces out of kinit are not build standalone:
initrd_load, ramdisk_load, do_mounts_md, ..

-- 
maks

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [klibc] [klibc 30/31] Remove in-kernel resume-from-disk invocation code
  2006-07-06  8:31       ` [klibc] " maximilian attems
@ 2006-07-06  8:37         ` H. Peter Anvin
  0 siblings, 0 replies; 58+ messages in thread
From: H. Peter Anvin @ 2006-07-06  8:37 UTC (permalink / raw)
  To: maximilian attems; +Cc: Nigel Cunningham, klibc, linux-kernel, Pavel Machek

maximilian attems wrote:
>>>
>> Yes, they have.  The handing of resume= and noresume are now done in 
>> kinit; resume is invoked from userspace by direct command only.
> 
> the grumble on kinit is that it is a big monolithic bin.
> You have no scriptability and it is not modular.
> Very useful pieces out of kinit are not build standalone:
> initrd_load, ramdisk_load, do_mounts_md, ..
> 

Some of that is due to data structures, but most certainly could be 
factored out, and really should be.  Since, apparently, klibc got 
rejected for 2.6.18 we have some time to improve that situation.

For total size reasons I'm pretty sure we need to still provide a single 
binary.  The trunk code, however, needs to be clean enough that it can 
be easily modified, too.

	-hpa

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [klibc 30/31] Remove in-kernel resume-from-disk invocation code
  2006-07-06  1:45           ` Nigel Cunningham
  2006-07-06  2:18             ` Nigel Cunningham
@ 2006-07-06 10:26             ` Pavel Machek
       [not found]             ` <200607061028.k66AS8UB012207@smtp.micromuse.com>
  2 siblings, 0 replies; 58+ messages in thread
From: Pavel Machek @ 2006-07-06 10:26 UTC (permalink / raw)
  To: Nigel Cunningham; +Cc: H. Peter Anvin, linux-kernel, klibc

Hi!

> > > Ah. So it's still valid to have resume= and noresume on the commandline,
> > > and klibc greps /proc/cmdline?
> >
> > Correct.
> >
> > > So, for Suspend2, would I be ok just leaving people to add the echo
> > >
> > >>/proc/suspend2/do_resume, as we currently do for initrds and initramfses?
> >
> > Well, presumably you want to adjust kinit so that it invokes
> > /proc/suspend2/do_resume, instead of or in addition to
> > /sys/power/resume; see usr/kinit/resume.c (the code should be bloody
> > obvious, I hope...)
> 
> It is.
> 
> Is there a klibc howto somewhere? I tried googling for 'klibc howto', reading 
> the files in Documentation/ and browsing your klibc mailing list archive 
> before asking!
> 
> What I'm wondering specifically is: Say a user needs to run some commands to 
> set up access to encrypted storage before they can resume. At the moment, 
> we'd tell them to put these commands and the echo > do_resume in their 
> linuxrc (or init) script prior to mounting their root filesystem. Forgive me 
> if I'm asking a stupid question but it's not immediately obvious to me how 
> they would now do that. I'd much rather follow a simple howto than
> spend a 

Same way as they did it before....? klibc is supposed to be
backward-compatible, as far as userland can tell.
									Pavel
-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

^ permalink raw reply	[flat|nested] 58+ messages in thread

* IBM spam Re: Re: [klibc 30/31] Remove in-kernel resume-from-disk invocation code
       [not found]             ` <200607061028.k66AS8UB012207@smtp.micromuse.com>
@ 2006-07-06 10:58               ` Pavel Machek
  2006-07-06 13:02                 ` Sean Young
  0 siblings, 1 reply; 58+ messages in thread
From: Pavel Machek @ 2006-07-06 10:58 UTC (permalink / raw)
  To: do-not-reply
  Cc: kernel list, fubar, brking, shaggy, vgoyal, prasanna, hbabu,
	ananth, paulus, anton, linas, schwidefsky, linux390, fpavlic,
	aherrman, sri, kjhall

So IBM is now spamming anyone that posts to lkml? I do not care how
much many you have, or who you bought, but you apparently have not
learned to use e-mail, yet. FIX IT.

It is not funny, noone from IBM even was in To/Cc of original mail.

I'm tired. Every time I mail to someone at IBM, I get some bogus error
back, and now this.
							Pavel 


On Thu 2006-07-06 11:28:08, do-not-reply@micromuse.com wrote:
> 
> 
> 				            ***** Micromuse are now IBM *****
> 
> Micromuse were acquired in February 2006 by IBM.  We are sorry, but the address you are trying to email no longer exists.  Please refer to your account manager, or attempt to search for the person you are contacting at http://www.ibm.com/contact/us/
> 
> Alternatively, you may locate your local IBM Office at http://www.ibm.com/planetwide/
> 
> 

> To: Nigel Cunningham <ncunningham@linuxmail.org>
> Cc: "H. Peter Anvin" <hpa@zytor.com>, linux-kernel@vger.kernel.org,
> 	klibc@zytor.com
> Subject: Re: [klibc 30/31] Remove in-kernel resume-from-disk invocation code
> X-Warning: Reading this can be dangerous to your mental health.
> 
> Hi!
> 
> > > > Ah. So it's still valid to have resume= and noresume on the commandline,
> > > > and klibc greps /proc/cmdline?
> > >
> > > Correct.
> > >
> > > > So, for Suspend2, would I be ok just leaving people to add the echo
> > > >
> > > >>/proc/suspend2/do_resume, as we currently do for initrds and initramfses?
> > >
> > > Well, presumably you want to adjust kinit so that it invokes
> > > /proc/suspend2/do_resume, instead of or in addition to
> > > /sys/power/resume; see usr/kinit/resume.c (the code should be bloody
> > > obvious, I hope...)
> > 
> > It is.
> > 
> > Is there a klibc howto somewhere? I tried googling for 'klibc howto', reading 
> > the files in Documentation/ and browsing your klibc mailing list archive 
> > before asking!
> > 
> > What I'm wondering specifically is: Say a user needs to run some commands to 
> > set up access to encrypted storage before they can resume. At the moment, 
> > we'd tell them to put these commands and the echo > do_resume in their 
> > linuxrc (or init) script prior to mounting their root filesystem. Forgive me 
> > if I'm asking a stupid question but it's not immediately obvious to me how 
> > they would now do that. I'd much rather follow a simple howto than
> > spend a 
> 
> Same way as they did it before....? klibc is supposed to be
> backward-compatible, as far as userland can tell.
> 									Pavel


-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: IBM spam Re: Re: [klibc 30/31] Remove in-kernel resume-from-disk invocation code
  2006-07-06 10:58               ` IBM spam Re: " Pavel Machek
@ 2006-07-06 13:02                 ` Sean Young
  0 siblings, 0 replies; 58+ messages in thread
From: Sean Young @ 2006-07-06 13:02 UTC (permalink / raw)
  To: Pavel Machek
  Cc: linux-kernel, fubar, brking, shaggy, vgoyal, prasanna, hbabu,
	ananth, paulus, anton, linas, schwidefsky, linux390, fpavlic,
	aherrman, sri, kjhall

On Thu, Jul 06, 2006 at 12:58:17PM +0200, Pavel Machek wrote:
> So IBM is now spamming anyone that posts to lkml? I do not care how
> much many you have, or who you bought, but you apparently have not
> learned to use e-mail, yet. FIX IT.

This is a problem at Micromuse where the micromuse.com email domain is 
being decomissioned. I've spoken to MIS any they've disabled this 
auto-reply fluff until it is fixed properly. 

Sorry about this. 


Sean 
(Speaking as himself)

^ permalink raw reply	[flat|nested] 58+ messages in thread

end of thread, other threads:[~2006-07-06 13:02 UTC | newest]

Thread overview: 58+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-06-28  5:17 [klibc 00/31] klibc as a historyless patchset (updated and reorganized) H. Peter Anvin
2006-06-28  5:17 ` [klibc 01/31] Add klibc/kinit to MAINTAINERS file H. Peter Anvin
2006-06-28  5:17 ` [klibc 02/31] Main Makefile changes for klibc H. Peter Anvin
2006-06-28  5:17 ` [klibc 03/31] Core klibc code H. Peter Anvin
2006-06-28  5:17 ` [klibc 04/31] alpha support for klibc H. Peter Anvin
2006-06-28 15:43   ` Richard Henderson
2006-06-28 15:51     ` H. Peter Anvin
2006-06-28  5:17 ` [klibc 05/31] arm " H. Peter Anvin
2006-06-28  5:17 ` [klibc 06/31] cris " H. Peter Anvin
2006-06-28  5:17 ` [klibc 07/31] i386 " H. Peter Anvin
2006-06-28  7:37   ` Jan Engelhardt
2006-06-28 15:33     ` H. Peter Anvin
2006-06-28 16:44       ` H. Peter Anvin
2006-06-29  0:14       ` Roman Zippel
2006-06-29  0:45         ` H. Peter Anvin
2006-06-29 23:43           ` Roman Zippel
2006-06-29 23:54             ` H. Peter Anvin
2006-06-30  0:23               ` Roman Zippel
2006-06-30  1:28                 ` [klibc] " Aaron Griffin
2006-06-30 13:56                   ` Jan Engelhardt
2006-06-28  5:17 ` [klibc 08/31] ia64 " H. Peter Anvin
2006-06-28  5:17 ` [klibc 09/31] m32r " H. Peter Anvin
2006-06-28  5:17 ` [klibc 10/31] m68k " H. Peter Anvin
2006-06-28  5:17 ` [klibc 11/31] mips " H. Peter Anvin
2006-06-28  5:17 ` [klibc 12/31] mips64 " H. Peter Anvin
2006-06-28  5:17 ` [klibc 13/31] parisc " H. Peter Anvin
2006-06-28  5:17 ` [klibc 14/31] ppc " H. Peter Anvin
2006-06-28  5:17 ` [klibc 15/31] ppc64 " H. Peter Anvin
2006-06-28  5:17 ` [klibc 16/31] s390 " H. Peter Anvin
2006-06-28  5:17 ` [klibc 17/31] sh " H. Peter Anvin
2006-06-28  5:17 ` [klibc 18/31] sparc " H. Peter Anvin
2006-06-28  5:17 ` [klibc 19/31] sparc64 " H. Peter Anvin
2006-06-28  5:17 ` [klibc 20/31] x86_64 " H. Peter Anvin
2006-06-28  5:17 ` [klibc 21/31] Simple test suite " H. Peter Anvin
2006-06-28  5:17 ` [klibc 22/31] zlib " H. Peter Anvin
2006-06-28  5:17 ` [klibc 23/31] kinit: replacement for in-kernel do_mount, ipconfig, nfsroot H. Peter Anvin
2006-06-28  5:17 ` [klibc 24/31] klibc basic build infrastructure H. Peter Anvin
2006-06-28  5:17 ` [klibc 25/31] Miscellaneous utilities for klibc H. Peter Anvin
2006-06-28  5:17 ` [klibc 26/31] dash - a small POSIX shell " H. Peter Anvin
2006-06-28  5:17 ` [klibc 27/31] A port of gzip to klibc H. Peter Anvin
2006-06-28  5:17 ` [klibc 28/31] sparc64: transmit arch-specific options to kinit via /arch.cmd H. Peter Anvin
2006-06-28  5:17 ` [klibc 29/31] sparc32: transfer arch-specific options to /arch.cmd H. Peter Anvin
2006-06-28  5:17 ` [klibc 30/31] Remove in-kernel resume-from-disk invocation code H. Peter Anvin
2006-07-05 23:40   ` Nigel Cunningham
2006-07-05 23:58     ` Joshua Hudson
2006-07-06  0:11     ` H. Peter Anvin
2006-07-06  0:37       ` Nigel Cunningham
2006-07-06  0:54         ` H. Peter Anvin
2006-07-06  1:45           ` Nigel Cunningham
2006-07-06  2:18             ` Nigel Cunningham
2006-07-06  3:11               ` H. Peter Anvin
2006-07-06  3:28                 ` Nigel Cunningham
2006-07-06 10:26             ` Pavel Machek
     [not found]             ` <200607061028.k66AS8UB012207@smtp.micromuse.com>
2006-07-06 10:58               ` IBM spam Re: " Pavel Machek
2006-07-06 13:02                 ` Sean Young
2006-07-06  8:31       ` [klibc] " maximilian attems
2006-07-06  8:37         ` H. Peter Anvin
2006-06-28  5:17 ` [klibc 31/31] Remove in-kernel root-mounting code H. Peter Anvin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox