Skip to contentSkip to conversation

mips support for klibc

PATCH In review H. Peter Anvin 2 participants 3 messages Jun 26, 2006 – Jun 27, 2006 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 28/43 mips support for klibc

The parts of klibc specific to the mips architecture.

---
commit 8dc79563c06020d8844b9e9b821741828039b59e
tree b957c8fb1fddf486f5c26b1880726051d4f6aaad
parent bc9b363b31d301ab94c115cccc2e079c0d318498
author H. Peter Anvin <[email protected]> Sun, 25 Jun 2006 16:58:31 -0700 committer H. Peter Anvin <[email protected]> Sun, 25 Jun 2006 16:58:31 -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/klibc/archsys.h    |   12 ++
 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         |   30 ++++
 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 ++
 18 files changed, 680 insertions(+), 0 deletions(-)
usr/include/arch/mips/klibc/archconfig.h new file +15 -0
new file mode 100644
index 0000000..d9528b8
@@ -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 */
usr/include/arch/mips/klibc/archfcntl.h new file +86 -0

86 lines not on this page · raw message

usr/include/arch/mips/klibc/archsetjmp.h new file +39 -0
new file mode 100644
index 0000000..1fbe83e
@@ -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 */
usr/include/arch/mips/klibc/archsignal.h new file +14 -0
new file mode 100644
index 0000000..b9ca756
@@ -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
usr/include/arch/mips/klibc/archstat.h new file +40 -0
new file mode 100644
index 0000000..c1d60d9
@@ -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
usr/include/arch/mips/klibc/archsys.h new file +12 -0
new file mode 100644
index 0000000..252d80c
@@ -0,0 +1,12 @@
+/*
+ * arch/mips/include/klibc/archsys.h
+ *
+ * Architecture-specific syscall definitions
+ */
+
+#ifndef _KLIBC_ARCHSYS_H
+#define _KLIBC_ARCHSYS_H
+
+/* No special syscall definitions for this architecture */
+
+#endif				/* _KLIBC_ARCHSYS_H */
usr/include/arch/mips/machine/asm.h new file +11 -0
new file mode 100644
index 0000000..f524bc6
@@ -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 */
usr/include/arch/mips/sgidefs.h new file +20 -0
new file mode 100644
index 0000000..fba8ae8
@@ -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 */
usr/include/arch/mips/spaces.h new file +1 -0
new file mode 100644
index 0000000..b5f530b
@@ -0,0 +1 @@
+/* Included by <asm/page.h> but not actually needed */
usr/klibc/arch/mips/MCONFIG new file +15 -0
new file mode 100644
index 0000000..fd70500
@@ -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
usr/klibc/arch/mips/Makefile.inc new file +30 -0
new file mode 100644
index 0000000..311bdfc
@@ -0,0 +1,30 @@
+# -*- 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/__clzdi2.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:
usr/klibc/arch/mips/crt0.S new file +25 -0
new file mode 100644
index 0000000..142d9f2
@@ -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)
usr/klibc/arch/mips/klibc.ld new file +214 -0

214 lines not on this page · raw message

usr/klibc/arch/mips/pipe.S new file +16 -0
new file mode 100644
index 0000000..02b9405
@@ -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)
usr/klibc/arch/mips/setjmp.S new file +80 -0

80 lines not on this page · raw message

usr/klibc/arch/mips/syscall.S new file +16 -0
new file mode 100644
index 0000000..9f308df
@@ -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)
usr/klibc/arch/mips/sysstub.ph new file +30 -0
new file mode 100644
index 0000000..a71d5d0
@@ -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;
usr/klibc/arch/mips/vfork.S new file +16 -0
new file mode 100644
index 0000000..f9f035b
@@ -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)
#1 lore raw

usr/include/arch/mips/klibc/archfcntl.h line 82

Quoted 7 lines · H. Peter Anvin
usr/include/arch/mips/klibc/archfcntl.h new file +7 -0
+typedef struct flock {
+	short	l_type;
+	short	l_whence;
+	loff_t	l_start;
+	loff_t	l_len;
+	pid_t	l_pid;
+} flock_t;

32-bit MIPS uses this:

struct flock {
        short   l_type;
        short   l_whence;
        off_t   l_start;
        off_t   l_len;
        long    l_sysid;
        __kernel_pid_t l_pid;
        long    pad[4];
};
#2 lore raw
Quoted 12 lines · Ralf Baechle

usr/include/arch/mips/klibc/archfcntl.h line 82

Quoted 7 lines · H. Peter Anvin
usr/include/arch/mips/klibc/archfcntl.h new file +7 -0
+typedef struct flock {
+	short	l_type;
+	short	l_whence;
+	loff_t	l_start;
+	loff_t	l_len;
+	pid_t	l_pid;
+} flock_t;

32-bit MIPS uses this:

Quoted 9 lines
struct flock {
        short   l_type;
        short   l_whence;
        off_t   l_start;
        off_t   l_len;
        long    l_sysid;
        __kernel_pid_t l_pid;
        long    pad[4];
};

Does it use that for F_GETLK64 and friends? klibc overrides the definitions so that F_GETLK is really F_GETLK64 etc; thus, "struct flock" in klibc userspace is really "struct flock64". (To put it differently, klibc is always large-file compliant.)

As far as I can tell, MIPS uses the generic definition for struct flock64, which is the one I have above, so it should be correct.

-hpa