Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/compat/irix Added code to match and launch n32 binaries ...



details:   https://anonhg.NetBSD.org/src/rev/2e5869632487
branches:  trunk
changeset: 520336:2e5869632487
user:      manu <manu%NetBSD.org@localhost>
date:      Mon Jan 07 22:05:03 2002 +0000

description:
Added code to match and launch n32 binaries (there is no N32 support in the
kernel yet)

diffstat:

 sys/compat/irix/irix_exec.c |  126 +++++++++++++++++++++++++++++++++++++++----
 sys/compat/irix/irix_exec.h |   20 ++++--
 2 files changed, 125 insertions(+), 21 deletions(-)

diffs (239 lines):

diff -r e7c321c1ec47 -r 2e5869632487 sys/compat/irix/irix_exec.c
--- a/sys/compat/irix/irix_exec.c       Mon Jan 07 21:46:56 2002 +0000
+++ b/sys/compat/irix/irix_exec.c       Mon Jan 07 22:05:03 2002 +0000
@@ -1,7 +1,7 @@
-/*     $NetBSD: irix_exec.c,v 1.8 2001/12/08 18:08:04 manu Exp $ */
+/*     $NetBSD: irix_exec.c,v 1.9 2002/01/07 22:05:03 manu Exp $ */
 
 /*-
- * Copyright (c) 2001 The NetBSD Foundation, Inc.
+ * Copyright (c) 2001-2002 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
@@ -37,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: irix_exec.c,v 1.8 2001/12/08 18:08:04 manu Exp $");
+__KERNEL_RCSID(0, "$NetBSD: irix_exec.c,v 1.9 2002/01/07 22:05:03 manu Exp $");
 
 #ifndef ELFSIZE
 #define ELFSIZE                32      /* XXX should die */
@@ -60,6 +60,7 @@
 
 static int ELFNAME2(irix,mipsopt_signature) __P((struct proc *, 
     struct exec_package *epp, Elf_Ehdr *eh));
+static void setregs_n32 __P((struct proc *, struct exec_package *, u_long));
 
 extern struct sysent irix_sysent[];
 extern const char * const irix_syscallnames[];
@@ -71,8 +72,8 @@
 void irix_syscall_intern __P((struct proc *));
 #endif
 
-const struct emul emul_irix = {
-       "irix",
+const struct emul emul_irix_o32 = {
+       "irix o32",
        "/emul/irix",
 #ifndef __HAVE_MINIMAL_EMUL
        0,
@@ -90,7 +91,37 @@
        trapsignal,
        irix_sigcode,
        irix_esigcode,
-       setregs,
+       setregs_o32,
+       NULL,
+       NULL,
+       NULL,
+#ifdef __HAVE_SYSCALL_INTERN
+       irix_syscall_intern,
+#else
+       irix_syscall,
+#endif
+};
+
+const struct emul emul_irix_n32 = {
+       "irix n32",
+       "/emul/irix",
+#ifndef __HAVE_MINIMAL_EMUL
+       0,
+       native_to_irix_errno,
+       IRIX_SYS_syscall,
+       IRIX_SYS_MAXSYSCALL,
+#endif
+       irix_sysent,
+#ifdef SYSCALL_DEBUG
+       irix_syscallnames,
+#else
+       NULL,
+#endif
+       irix_sendsig,
+       trapsignal,
+       irix_sigcode,
+       irix_esigcode,
+       setregs_n32,
        NULL,
        NULL,
        NULL,
@@ -165,9 +196,12 @@
        return (error);
 }
 
-
+/*
+ * IRIX o32 ABI probe function
+ * Should be run after the IRIX n32 ABI probe function, see comment below
+ */
 int
-ELFNAME2(irix,probe)(p, epp, eh, itp, pos)
+ELFNAME2(irix,probe_o32)(p, epp, eh, itp, pos)
        struct proc *p;
        struct exec_package *epp;
        void *eh;
@@ -179,12 +213,13 @@
        size_t len;
 
 #ifdef DEBUG_IRIX
-       printf("irix_probe()\n");
+       printf("irix_probe_o32()\n");
 #endif
-       if ((error = ELFNAME2(irix,mipsopt_signature)(p, epp, eh)) != 0)
-       /*      return error; */ error = 0;
-
        if (itp[0]) {
+               /* o32 binaries use /lib/libc.so.1 */
+               if (strncmp(itp, "/lib/libc.so", 12) && 
+                   strncmp(itp, "/usr/lib/libc.so", 16))
+                       return ENOEXEC;
                if ((error = emul_find(p, NULL, epp->ep_esch->es_emul->e_path,
                    itp, &bp, 0)))
                        return error;
@@ -194,9 +229,74 @@
        }
        *pos = ELF_NO_ADDR;
 #ifdef DEBUG_IRIX
-       printf("irix_probe: returning 0\n");
+       printf("irix_probe_o32: returning 0\n");
        printf("epp->ep_vm_minaddr = 0x%lx\n", epp->ep_vm_minaddr);
 #endif
        epp->ep_vm_minaddr = epp->ep_vm_minaddr & ~0xfUL;
        return 0;
 }
+
+/*
+ * IRIX n32 ABI probe function
+ * This should be run before the IRIX o32 ABI probe function, else 
+ * n32 static binaries will be matched as o32
+ */
+int
+ELFNAME2(irix,probe_n32)(p, epp, eh, itp, pos)
+       struct proc *p;
+       struct exec_package *epp;
+       void *eh;
+       char *itp; 
+       vaddr_t *pos; 
+{
+       const char *bp;
+       int error;
+       size_t len;
+
+#ifdef DEBUG_IRIX
+       printf("irix_probe_n32()\n");
+#endif
+       /* This eliminates o32 static binaries */
+       if ((error = ELFNAME2(irix,mipsopt_signature)(p, epp, eh)) != 0)
+               return error;
+
+       if (itp[0]) {
+               /* n32 binaries use /lib32/libc.so.1 */
+               if (strncmp(itp, "/lib32/libc.so", 14) &&
+                   strncmp(itp, "/usr/lib32/libc.so", 18))
+                       return ENOEXEC;
+               if ((error = emul_find(p, NULL, epp->ep_esch->es_emul->e_path,
+                   itp, &bp, 0)))
+                       return error;
+               if ((error = copystr(bp, itp, MAXPATHLEN, &len)))
+                       return error;
+               free((void *)bp, M_TEMP);
+       }
+       *pos = ELF_NO_ADDR;
+#ifdef DEBUG_IRIX
+       printf("irix_prob_n32e: returning 0\n");
+       printf("epp->ep_vm_minaddr = 0x%lx\n", epp->ep_vm_minaddr);
+#endif
+       epp->ep_vm_minaddr = epp->ep_vm_minaddr & ~0xfUL;
+       return 0;
+}
+
+/*
+ * set registers on exec for N32 applications 
+ */
+void
+setregs_n32(p, pack, stack)
+       struct proc *p;
+       struct exec_package *pack;
+       u_long stack;
+{
+       struct frame *f = (struct frame *)p->p_md.md_regs;
+       
+       /* Use regular setregs */
+       setregs(p, pack, stack);
+
+       /* Enable 64 bit instructions (eg: sd) */
+       f->f_regs[SR] |= MIPS3_SR_UX; 
+
+       return;
+}
diff -r e7c321c1ec47 -r 2e5869632487 sys/compat/irix/irix_exec.h
--- a/sys/compat/irix/irix_exec.h       Mon Jan 07 21:46:56 2002 +0000
+++ b/sys/compat/irix/irix_exec.h       Mon Jan 07 22:05:03 2002 +0000
@@ -1,7 +1,7 @@
-/*     $NetBSD: irix_exec.h,v 1.3 2001/12/04 22:13:41 manu Exp $ */
+/*     $NetBSD: irix_exec.h,v 1.4 2002/01/07 22:05:03 manu Exp $ */
 
 /*-
- * Copyright (c) 2001 The NetBSD Foundation, Inc.
+ * Copyright (c) 2001-2002 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
@@ -46,19 +46,22 @@
 #define IRIX_ELF_AUX_ENTRIES 7
 
 #ifdef EXEC_ELF32
-#define IRIX_AUX_ARGSIZ howmany(IRIX_ELF_AUX_ENTRIES * sizeof(Aux32Info), \
-    sizeof (Elf32_Addr))
+#define IRIX_AUX_ARGSIZ howmany(IRIX_ELF_AUX_ENTRIES * \
+    sizeof(Aux32Info), sizeof (Elf32_Addr))
 
 int irix_elf32_copyargs __P((struct exec_package *, struct ps_strings *,
     char **, void *));
 
-int irix_elf32_probe __P((struct proc *, struct exec_package *, void *,  
+int irix_elf32_probe_o32 __P((struct proc *, struct exec_package *, void *,  
+    char *, vaddr_t *));
+
+int irix_elf32_probe_n32 __P((struct proc *, struct exec_package *, void *,  
     char *, vaddr_t *));
 #endif
 
 #ifdef EXEC_ELF64
-#define IRIX_AUX_ARGSIZ howmany(IRIX_ELF_AUX_ENTRIES * sizeof(Aux64Info), \
-    sizeof (Elf64_Addr))
+/* #define IRIX_AUX_ARGSIZ howmany(IRIX_ELF_AUX_ENTRIES * \
+    sizeof(Aux64Info), sizeof (Elf64_Addr))  */
 
 int irix_elf64_copyargs __P((struct exec_package *, struct ps_strings *,
     char **, void *));
@@ -67,6 +70,7 @@
     char *, vaddr_t *));
 #endif
 
-extern const struct emul emul_irix;
+extern const struct emul emul_irix_n32;
+extern const struct emul emul_irix_o32;
 
 #endif /* !_IRIX_EXEC_H_ */



Home | Main Index | Thread Index | Old Index