Module Name:    src
Committed By:   matt
Date:           Fri Aug 21 17:38:24 UTC 2009

Modified Files:
        src/sys/arch/mips/mips [matt-nb5-mips64]: cpu_exec.c

Log Message:
Add mips_netbsd_elfXX_probe routines.
Add coredump_elfXX_setup routines


To generate a diff of this commit:
cvs rdiff -u -r1.50.54.1.4.1 -r1.50.54.1.4.2 \
    src/sys/arch/mips/mips/cpu_exec.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/mips/mips/cpu_exec.c
diff -u src/sys/arch/mips/mips/cpu_exec.c:1.50.54.1.4.1 src/sys/arch/mips/mips/cpu_exec.c:1.50.54.1.4.2
--- src/sys/arch/mips/mips/cpu_exec.c:1.50.54.1.4.1	Thu Aug 20 21:49:24 2009
+++ src/sys/arch/mips/mips/cpu_exec.c	Fri Aug 21 17:38:23 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu_exec.c,v 1.50.54.1.4.1 2009/08/20 21:49:24 matt Exp $	*/
+/*	$NetBSD: cpu_exec.c,v 1.50.54.1.4.2 2009/08/21 17:38:23 matt Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cpu_exec.c,v 1.50.54.1.4.1 2009/08/20 21:49:24 matt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu_exec.c,v 1.50.54.1.4.2 2009/08/21 17:38:23 matt Exp $");
 
 #include "opt_compat_netbsd.h"
 #include "opt_compat_ultrix.h"
@@ -308,3 +308,176 @@
 
 	return 0;
 }
+
+#if EXEC_ELF32
+int
+mips_netbsd_elf32_probe(struct lwp *l, struct exec_package *epp, void *eh0,
+	char *idt, vaddr_t *entry_p)
+{
+	struct proc * const p = l->l_proc;
+	const Elf32_Ehdr * const eh = eh0;
+
+	/*
+	 * Verify we can support the architecture.
+	 */
+	switch (eh->e_flags & EF_MIPS_ARCH) {
+	case EF_MIPS_ARCH_1:
+		break;
+	case EF_MIPS_ARCH_2:
+		if (cpu_arch < CPU_ARCH_MIPS2)
+			return ENOEXEC;
+		break;
+	case EF_MIPS_ARCH_3:
+		if (cpu_arch < CPU_ARCH_MIPS4)
+			return ENOEXEC;
+		break;
+	case EF_MIPS_ARCH_4:
+		if (cpu_arch < CPU_ARCH_MIPS3)
+			return ENOEXEC;
+		break;
+	case EF_MIPS_ARCH_5:
+		if (cpu_arch < CPU_ARCH_MIPS5)
+			return ENOEXEC;
+		break;
+	case EF_MIPS_ARCH_32:
+	case EF_MIPS_ARCH_64:
+		if (!CPUISMIPSNN)
+			return ENOEXEC;
+		break;
+	}
+
+	switch (eh->e_flags & (EF_MIPS_ABI|EF_MIPS_ABI2)) {
+#if !defined(__mips_o32)
+	case EF_MIPS_ABI2:
+		p->p_md.md_abi = _MIPS_BSD_API_N32;
+		printf("pid %d(%p): ABI set to N32 (e_flags=%#x)\n", p->p_pid, p, eh->e_flags);
+		return 0;
+#endif
+	case EF_MIPS_ABI_O32:
+		p->p_md.md_abi = _MIPS_BSD_API_O32;
+		printf("pid %d(%p): ABI set to O32 (e_flags=%#x)\n", p->p_pid, p, eh->e_flags);
+		return 0;
+	default:
+		return ENOEXEC;
+	}
+}
+
+void
+coredump_elf32_setup(struct lwp *l, void *eh0)
+{
+	struct proc * const p = l->l_proc;
+	Elf32_Ehdr * const eh = eh0;
+
+	/*
+	 * Mark the type of CPU that the dump happened on.
+	 */
+	if (cpu_arch & CPU_ARCH_MIPS64) {
+		eh->e_flags |= EF_MIPS_ARCH_64;
+	} else if (cpu_arch & CPU_ARCH_MIPS32) {
+		eh->e_flags |= EF_MIPS_ARCH_32;
+	} else if (cpu_arch & CPU_ARCH_MIPS5) {
+		eh->e_flags |= EF_MIPS_ARCH_5;
+	} else if (cpu_arch & CPU_ARCH_MIPS4) {
+		eh->e_flags |= EF_MIPS_ARCH_4;
+	} else if (cpu_arch & CPU_ARCH_MIPS3) {
+		eh->e_flags |= EF_MIPS_ARCH_3;
+	} else if (cpu_arch & CPU_ARCH_MIPS2) {
+		eh->e_flags |= EF_MIPS_ARCH_2;
+	} else {
+		eh->e_flags |= EF_MIPS_ARCH_1;
+	}
+
+	switch (p->p_md.md_abi) {
+	case _MIPS_BSD_API_N32:
+		eh->e_flags |= EF_MIPS_ABI2;
+		break;
+	case _MIPS_BSD_API_O32:
+		eh->e_flags |=EF_MIPS_ABI_O32; 
+		break;
+	}
+}
+#endif
+
+#if EXEC_ELF64
+int
+mips_netbsd_elf64_probe(struct lwp *l, struct exec_package *epp, void *eh0,
+	char *idt, vaddr_t *entry_p)
+{
+	struct proc * const p = l->l_proc;
+	const Elf64_Ehdr * const eh = eh0;
+
+	switch (eh->e_flags & EF_MIPS_ARCH) {
+	case EF_MIPS_ARCH_1:
+		return ENOEXEC;
+	case EF_MIPS_ARCH_2:
+		if (cpu_arch < CPU_ARCH_MIPS2)
+			return ENOEXEC;
+		break;
+	case EF_MIPS_ARCH_3:
+		if (cpu_arch < CPU_ARCH_MIPS4)
+			return ENOEXEC;
+		break;
+	case EF_MIPS_ARCH_4:
+		if (cpu_arch < CPU_ARCH_MIPS3)
+			return ENOEXEC;
+		break;
+	case EF_MIPS_ARCH_5:
+		if (cpu_arch < CPU_ARCH_MIPS5)
+			return ENOEXEC;
+		break;
+	case EF_MIPS_ARCH_32:
+		return ENOEXEC;
+	case EF_MIPS_ARCH_64:
+		if (!CPUISMIPS64)
+			return ENOEXEC;
+		break;
+	}
+
+	switch (eh->e_flags & EF_MIPS_ARCH) {
+	case 0:
+		p->p_md.md_abi = _MIPS_BSD_API_N64;
+		printf("pid %d(%p): ABI set to N64 (e_flags=%#x)\n", p->p_pid, p, eh->e_flags);
+		return 0;
+	case EF_MIPS_ABI_O64:
+		p->p_md.md_abi = _MIPS_BSD_API_O64;
+		printf("pid %d(%p): ABI set to O64 (e_flags=%#x)\n", p->p_pid, p, eh->e_flags);
+		return 0;
+	default:
+		return ENOEXEC;
+	}
+}
+
+void
+coredump_elf64_setup(struct lwp *l, void *eh0)
+{
+	struct proc * const p = l->l_proc;
+	Elf64_Ehdr * const eh = eh0;
+
+	/*
+	 * Mark the type of CPU that the dump happened on.
+	 */
+	if (cpu_arch & CPU_ARCH_MIPS64) {
+		eh->e_flags |= EF_MIPS_ARCH_64;
+	} else if (cpu_arch & CPU_ARCH_MIPS32) {
+		eh->e_flags |= EF_MIPS_ARCH_32;
+	} else if (cpu_arch & CPU_ARCH_MIPS5) {
+		eh->e_flags |= EF_MIPS_ARCH_5;
+	} else if (cpu_arch & CPU_ARCH_MIPS4) {
+		eh->e_flags |= EF_MIPS_ARCH_4;
+	} else if (cpu_arch & CPU_ARCH_MIPS3) {
+		eh->e_flags |= EF_MIPS_ARCH_3;
+	} else if (cpu_arch & CPU_ARCH_MIPS2) {
+		eh->e_flags |= EF_MIPS_ARCH_2;
+	} else {
+		eh->e_flags |= EF_MIPS_ARCH_1;
+	}
+	switch (p->p_md.md_abi) {
+	case _MIPS_BSD_API_N64:
+		eh->e_flags |= EF_MIPS_ABI2;
+		break;
+	case _MIPS_BSD_API_O64:
+		eh->e_flags |= EF_MIPS_ABI_O64;
+		break;
+	}
+}
+#endif

Reply via email to