Subject: N32 support (patch proposal)
To: None <port-mips@netbsd.org>
From: Emmanuel Dreyfus <manu@netbsd.org>
List: port-mips
Date: 01/02/2002 19:11:01
Hi!

I've made some progress on the N32 front, and I'm now able to match and launch
IRIX N32 binaries. Some system calls work, some don't (system calls using 64
bit values or more than 4 arguments fail for now, we'll need to modify the
syscall handler to fix this)

This patch is for launching N32 binaries. Is it reasonable to commit it to the
tree?

Index: include/elf_machdep.h
===================================================================
RCS file: /cvsroot/syssrc/sys/arch/mips/include/elf_machdep.h,v
retrieving revision 1.8
diff -U4 -r1.8 elf_machdep.h
--- include/elf_machdep.h       2001/12/09 23:05:58     1.8
+++ include/elf_machdep.h       2002/01/01 22:06:50
@@ -91,5 +91,9 @@
  * (ld.so) for dynamically-linked ELF binaries.
  */
 #ifdef _KERNEL
 #define ELF_INTERP_NON_RELOCATABLE
+
+void setregs_o32 __P((struct proc*, struct exec_package*, u_long stack));
+void setregs_n32 __P((struct proc*, struct exec_package*, u_long stack));
+void setregs1 __P((struct proc*, struct exec_package*, u_long stack));
 #endif
Index: include/proc.h
===================================================================
RCS file: /cvsroot/syssrc/sys/arch/mips/include/proc.h,v
retrieving revision 1.13
diff -U4 -r1.13 proc.h
--- include/proc.h      2001/10/16 16:31:34     1.13
+++ include/proc.h      2002/01/01 22:06:50
@@ -58,8 +58,9 @@
 };
 
 /* md_flags */
 #define        MDP_FPUSED      0x0001  /* floating point coprocessor used */
+#define MDP_ABI_N32    0x0002  /* 0 for o32 ABI, 1 for n32 ABI */
 
 /*
  * MIPS trapframe
  */
Index: mips/mips_machdep.c
===================================================================
RCS file: /cvsroot/syssrc/sys/arch/mips/mips/mips_machdep.c,v
retrieving revision 1.120
diff -U4 -r1.120 mips_machdep.c
--- mips/mips_machdep.c 2001/11/14 18:15:24     1.120
+++ mips/mips_machdep.c 2002/01/01 22:06:55
@@ -80,8 +80,9 @@
 
 #include <mips/cache.h>
 #include <mips/regnum.h>               /* symbolic register indices */
 #include <mips/locore.h>
+#include <mips/elf_machdep.h>
 #include <mips/psl.h>
 #include <mips/pte.h>
 #include <machine/cpu.h>               /* declaration of of cpu_id */
 
@@ -609,17 +610,69 @@
                break;
        }
 }
 
-/*
+
+/* 
+ * Set registers on exec.
+ * This is a wrapper to the o32 ABI version 
+ * used for native NetBSD binaries
+ */
+void
+setregs(p, pack, stack)
+       struct proc *p;
+       struct exec_package *pack;
+       u_long stack;
+{
+       return setregs_o32(p, pack, stack);
+}
+
+/* 
+ * Set registers on exec.
+ * This is used for binaries using the o32 ABI.
+ */
+void
+setregs_o32(p, pack, stack)
+       struct proc *p;
+       struct exec_package *pack;
+       u_long stack;
+{
+       return setregs1(p, pack, stack);
+}
+
+/* 
  * Set registers on exec.
+ * This is used for binaries using the n32 ABI,
+ * for now, only IRIX n32 binaries use this
+ */ 
+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;
+       
+       setregs1(p, pack, stack);
+
+       /* Enable 64 bit instructions (eg: sd) */
+       f->f_regs[SR] |= (MIPS3_SR_XX | MIPS3_SR_UX); 
+
+       /* Remember this process uses the N32 ABI */
+       p->p_md.md_flags |= MDP_ABI_N32;
+
+       return;
+}
+
+/*
+ * Set register on exec code common to o32 ABI and n32 ABI.
  * Clear all registers except sp, pc, and t9.
  * $sp is set to the stack pointer passed in.  $pc is set to the entry
  * point given by the exec_package passed in, as is $t9 (used for PIC
  * code by the MIPS elf abi).
  */
 void
-setregs(p, pack, stack)
+setregs1(p, pack, stack)
        struct proc *p;
        struct exec_package *pack;
        u_long stack;
 {


-- 
Emmanuel Dreyfus.  
manu@netbsd.org