Skip to contentSkip to conversation

i386 support for klibc

PATCH In review H. Peter Anvin 1 participant 1 message Jun 26, 2006 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 24/43 i386 support for klibc

The parts of klibc specific to the i386 architecture.

---
commit bd0599e5290ca1a16bb7a68f7c362d395c612eb3
tree 8f33afdd02a14c22e7a3984da2bad13184e3f729
parent 84f6a72f42cf41e32daa59871a0b5424572093e4
author H. Peter Anvin <[email protected]> Sun, 25 Jun 2006 16:58:21 -0700 committer H. Peter Anvin <[email protected]> Sun, 25 Jun 2006 16:58:21 -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/archsys.h    |   12 +++
 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 ++++++
 25 files changed, 960 insertions(+), 0 deletions(-)
usr/include/arch/i386/klibc/archconfig.h new file +19 -0
new file mode 100644
index 0000000..4463d08
@@ -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 */
usr/include/arch/i386/klibc/archsetjmp.h new file +19 -0
new file mode 100644
index 0000000..ea1ba3d
@@ -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 */
usr/include/arch/i386/klibc/archsignal.h new file +114 -0

114 lines not on this page · raw message

usr/include/arch/i386/klibc/archstat.h new file +38 -0
new file mode 100644
index 0000000..c00f955
@@ -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
usr/include/arch/i386/klibc/archsys.h new file +12 -0
new file mode 100644
index 0000000..e655680
@@ -0,0 +1,12 @@
+/*
+ * arch/cris/include/klibc/archsys.h
+ *
+ * Architecture-specific syscall definitions
+ */
+
+#ifndef _KLIBC_ARCHSYS_H
+#define _KLIBC_ARCHSYS_H
+
+/* No special syscall definitions for this architecture */
+
+#endif				/* _KLIBC_ARCHSYS_H */
usr/include/arch/i386/klibc/diverr.h new file +15 -0
new file mode 100644
index 0000000..fa238ac
@@ -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 */
usr/include/arch/i386/sys/io.h new file +127 -0

127 lines not on this page · raw message

usr/include/arch/i386/sys/vm86.h new file +40 -0
new file mode 100644
index 0000000..c4651cd
@@ -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
usr/klibc/arch/i386/MCONFIG new file +33 -0
new file mode 100644
index 0000000..e173266
@@ -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
usr/klibc/arch/i386/Makefile.inc new file +30 -0
new file mode 100644
index 0000000..d13a28f
@@ -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:
usr/klibc/arch/i386/crt0.S new file +31 -0
new file mode 100644
index 0000000..8c6635e
@@ -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
usr/klibc/arch/i386/libgcc/__ashldi3.S new file +29 -0
new file mode 100644
index 0000000..7344142
@@ -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
usr/klibc/arch/i386/libgcc/__ashrdi3.S new file +29 -0
new file mode 100644
index 0000000..7666eb2
@@ -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
usr/klibc/arch/i386/libgcc/__lshrdi3.S new file +29 -0
new file mode 100644
index 0000000..6a63c52
@@ -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
usr/klibc/arch/i386/libgcc/__muldi3.S new file +34 -0
new file mode 100644
index 0000000..472c7cc
@@ -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
usr/klibc/arch/i386/libgcc/__negdi2.S new file +21 -0
new file mode 100644
index 0000000..147ad94
@@ -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
usr/klibc/arch/i386/open.S new file +29 -0
new file mode 100644
index 0000000..7cd136c
@@ -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
usr/klibc/arch/i386/openat.S new file +26 -0
new file mode 100644
index 0000000..2dfdfe2
@@ -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
usr/klibc/arch/i386/setjmp.S new file +58 -0

58 lines not on this page · raw message

usr/klibc/arch/i386/sigreturn.S new file +15 -0
new file mode 100644
index 0000000..f2a3241
@@ -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
usr/klibc/arch/i386/socketcall.S new file +55 -0

55 lines not on this page · raw message

usr/klibc/arch/i386/syscall.S new file +69 -0

69 lines not on this page · raw message

usr/klibc/arch/i386/sysstub.ph new file +26 -0
new file mode 100644
index 0000000..e73a3ff
@@ -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;
usr/klibc/arch/i386/varsyscall.S new file +36 -0
new file mode 100644
index 0000000..24329ea
@@ -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
usr/klibc/arch/i386/vfork.S new file +26 -0
new file mode 100644
index 0000000..c98ba3a
@@ -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