Source-Changes-HG archive

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

[src/trunk]: src/sys Allow architectures to define a macro PROC_MACHINE_ARCH(...



details:   https://anonhg.NetBSD.org/src/rev/9545750e6546
branches:  trunk
changeset: 357210:9545750e6546
user:      martin <martin%NetBSD.org@localhost>
date:      Tue Oct 31 12:37:23 2017 +0000

description:
Allow architectures to define a macro PROC_MACHINE_ARCH(P) and
PROC_MACHINE_ARCH32(P) to override the value for sysctl hw.machine_arch
(native and netbsd32 commpat resp.).

Use these for arm and mips instead of the (not working, noisy, in case
of arm) sysctl override and #ifdef __mips__ in architecture neutral
code.

diffstat:

 sys/arch/arm/arm32/arm32_machdep.c       |  25 +----------------------
 sys/arch/arm/include/netbsd32_machdep.h  |   5 +++-
 sys/arch/arm/include/proc.h              |   5 ++-
 sys/arch/mips/include/netbsd32_machdep.h |   9 +++++--
 sys/arch/mips/mips/netbsd32_machdep.c    |  15 +------------
 sys/compat/netbsd32/netbsd32_sysctl.c    |  33 +++++++++++++++++--------------
 sys/kern/init_sysctl_base.c              |  22 +++++++++++++++++---
 7 files changed, 53 insertions(+), 61 deletions(-)

diffs (275 lines):

diff -r da79d489f13c -r 9545750e6546 sys/arch/arm/arm32/arm32_machdep.c
--- a/sys/arch/arm/arm32/arm32_machdep.c        Tue Oct 31 12:02:20 2017 +0000
+++ b/sys/arch/arm/arm32/arm32_machdep.c        Tue Oct 31 12:37:23 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: arm32_machdep.c,v 1.114 2017/07/02 16:16:44 skrll Exp $        */
+/*     $NetBSD: arm32_machdep.c,v 1.115 2017/10/31 12:37:23 martin Exp $       */
 
 /*
  * Copyright (c) 1994-1998 Mark Brinicombe.
@@ -42,7 +42,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: arm32_machdep.c,v 1.114 2017/07/02 16:16:44 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: arm32_machdep.c,v 1.115 2017/10/31 12:37:23 martin Exp $");
 
 #include "opt_modular.h"
 #include "opt_md.h"
@@ -402,15 +402,6 @@
        return (0);
 }
 
-static int
-sysctl_hw_machine_arch(SYSCTLFN_ARGS)
-{
-       struct sysctlnode node = *rnode;
-       node.sysctl_data = l->l_proc->p_md.md_march;
-       node.sysctl_size = strlen(l->l_proc->p_md.md_march) + 1;
-       return sysctl_lookup(SYSCTLFN_CALL(&node));
-}
-
 SYSCTL_SETUP(sysctl_machdep_setup, "sysctl machdep subtree setup")
 {
 
@@ -532,18 +523,6 @@
                       SYSCTL_DESCR("Do SIGBUS for fixed unaligned accesses"),
                       NULL, 0, &cpu_unaligned_sigbus, 0,
                       CTL_MACHDEP, CTL_CREATE, CTL_EOL);
-
-
-       /*
-        * We need override the usual CTL_HW HW_MACHINE_ARCH so we
-        * return the right machine_arch based on the running executable.
-        */
-       sysctl_createv(clog, 0, NULL, NULL,
-                      CTLFLAG_PERMANENT|CTLFLAG_READONLY,
-                      CTLTYPE_STRING, "machine_arch",
-                      SYSCTL_DESCR("Machine CPU class"),
-                      sysctl_hw_machine_arch, 0, NULL, 0,
-                      CTL_HW, HW_MACHINE_ARCH, CTL_EOL);
 }
 
 void
diff -r da79d489f13c -r 9545750e6546 sys/arch/arm/include/netbsd32_machdep.h
--- a/sys/arch/arm/include/netbsd32_machdep.h   Tue Oct 31 12:02:20 2017 +0000
+++ b/sys/arch/arm/include/netbsd32_machdep.h   Tue Oct 31 12:37:23 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: netbsd32_machdep.h,v 1.1 2012/08/03 07:59:23 matt Exp $        */
+/*     $NetBSD: netbsd32_machdep.h,v 1.2 2017/10/31 12:37:23 martin Exp $      */
 
 /*-
  * Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -45,6 +45,9 @@
 
 typedef netbsd32_pointer_t                     netbsd32_sigcontextp_t;
 
+/* Support varying ABI names for netbsd32 */
+#define        PROC_MACHINE_ARCH32(P)  ((P)->p_md.md_march)
+
 /*
  * The sigcode is ABI neutral.
  */
diff -r da79d489f13c -r 9545750e6546 sys/arch/arm/include/proc.h
--- a/sys/arch/arm/include/proc.h       Tue Oct 31 12:02:20 2017 +0000
+++ b/sys/arch/arm/include/proc.h       Tue Oct 31 12:37:23 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: proc.h,v 1.17 2014/02/24 16:57:57 christos Exp $       */
+/*     $NetBSD: proc.h,v 1.18 2017/10/31 12:37:23 martin Exp $ */
 
 /*
  * Copyright (c) 1994 Mark Brinicombe.
@@ -59,6 +59,7 @@
        char    md_march[12];           /* machine arch of executable */
 };
 
-#define        PROC0_MD_INITIALIZERS .p_md = { .md_march = MACHINE_ARCH },
+#define        PROC_MACHINE_ARCH(P)    ((P)->p_md.md_march)
+#define        PROC0_MD_INITIALIZERS   .p_md = { .md_march = MACHINE_ARCH },
 
 #endif /* _ARM_PROC_H_ */
diff -r da79d489f13c -r 9545750e6546 sys/arch/mips/include/netbsd32_machdep.h
--- a/sys/arch/mips/include/netbsd32_machdep.h  Tue Oct 31 12:02:20 2017 +0000
+++ b/sys/arch/mips/include/netbsd32_machdep.h  Tue Oct 31 12:37:23 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: netbsd32_machdep.h,v 1.4 2015/05/17 18:52:37 matt Exp $        */
+/*     $NetBSD: netbsd32_machdep.h,v 1.5 2017/10/31 12:37:23 martin Exp $      */
 
 /*-
  * Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -44,6 +44,11 @@
 
 typedef netbsd32_pointer_t                     netbsd32_sigcontextp_t;
 
+/* Support varying ABI names for netbsd32 */
+extern const char machine_arch32[];
+#define        PROC_MACHINE_ARCH32(P)  ((P)->p_md.md_abi == _MIPS_BSD_API_O32) ? \
+       __UNCONST(machine_arch32) : machine_arch
+
 /*
  * The sigcode is ABI neutral.
  */
@@ -69,6 +74,4 @@
        int ctl;
 };
 
-int cpu_machinearch32(SYSCTLFN_PROTO);
-
 #endif /* _MACHINE_NETBSD32_H_ */
diff -r da79d489f13c -r 9545750e6546 sys/arch/mips/mips/netbsd32_machdep.c
--- a/sys/arch/mips/mips/netbsd32_machdep.c     Tue Oct 31 12:02:20 2017 +0000
+++ b/sys/arch/mips/mips/netbsd32_machdep.c     Tue Oct 31 12:37:23 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: netbsd32_machdep.c,v 1.14 2017/03/16 16:13:20 chs Exp $        */
+/*     $NetBSD: netbsd32_machdep.c,v 1.15 2017/10/31 12:37:23 martin Exp $     */
 
 /*-
  * Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: netbsd32_machdep.c,v 1.14 2017/03/16 16:13:20 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: netbsd32_machdep.c,v 1.15 2017/10/31 12:37:23 martin Exp $");
 
 #include "opt_compat_netbsd.h"
 #include "opt_coredump.h"
@@ -343,14 +343,3 @@
            chdr->c_cpusize);
 }
 #endif
-
-int
-cpu_machinearch32(SYSCTLFN_ARGS)
-{
-       struct sysctlnode node = *rnode;
-       const char *march = l->l_proc->p_md.md_abi == _MIPS_BSD_API_O32
-           ? machine_arch32 : machine_arch;
-       node.sysctl_data = __UNCONST(march);
-       node.sysctl_size = strlen(march) + 1;
-       return sysctl_lookup(SYSCTLFN_CALL(&node));
-}
diff -r da79d489f13c -r 9545750e6546 sys/compat/netbsd32/netbsd32_sysctl.c
--- a/sys/compat/netbsd32/netbsd32_sysctl.c     Tue Oct 31 12:02:20 2017 +0000
+++ b/sys/compat/netbsd32/netbsd32_sysctl.c     Tue Oct 31 12:37:23 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: netbsd32_sysctl.c,v 1.36 2015/05/17 18:52:37 matt Exp $        */
+/*     $NetBSD: netbsd32_sysctl.c,v 1.37 2017/10/31 12:37:23 martin Exp $      */
 
 /*
  * Copyright (c) 2003 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: netbsd32_sysctl.c,v 1.36 2015/05/17 18:52:37 matt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: netbsd32_sysctl.c,v 1.37 2017/10/31 12:37:23 martin Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ddb.h"
@@ -104,13 +104,24 @@
        return (sysctl_lookup(SYSCTLFN_CALL(&node)));
 }
 
+static int
+sysctl_hw_machine_arch32(SYSCTLFN_ARGS)
+{
+       struct sysctlnode node = *rnode;
+#ifndef PROC_MACHINE_ARCH32
+       extern const char machine_arch32[];
+#define PROC_MACHINE_ARCH32(P) machine_arch32
+#endif
+
+       node.sysctl_data = PROC_MACHINE_ARCH32(l->l_proc);
+       node.sysctl_size = strlen(node.sysctl_data) + 1;
+       return sysctl_lookup(SYSCTLFN_CALL(&node));
+}
+
 void
 netbsd32_sysctl_init(void)
 {
        const struct sysctlnode *_root = &netbsd32_sysctl_root;
-#ifndef __mips__
-       extern const char machine_arch32[];
-#endif
        extern const char machine32[];
 
        sysctl_createv(&netbsd32_clog, 0, &_root, NULL,
@@ -152,19 +163,11 @@
                       CTLTYPE_STRING, "machine", NULL,
                       NULL, 0, __UNCONST(&machine32), 0,
                       CTL_HW, HW_MACHINE, CTL_EOL);
-#ifdef __mips__
        sysctl_createv(&netbsd32_clog, 0, &_root, NULL,
-                      CTLFLAG_PERMANENT,
+                      CTLFLAG_PERMANENT|CTLFLAG_READONLY,
                       CTLTYPE_STRING, "machine_arch", NULL,
-                      cpu_machinearch32, 0, NULL, 0,
+                      sysctl_hw_machine_arch32, 0, NULL, 0,
                       CTL_HW, HW_MACHINE_ARCH, CTL_EOL);
-#else
-       sysctl_createv(&netbsd32_clog, 0, &_root, NULL,
-                      CTLFLAG_PERMANENT,
-                      CTLTYPE_STRING, "machine_arch", NULL,
-                      NULL, 0, __UNCONST(&machine_arch32), 0,
-                      CTL_HW, HW_MACHINE_ARCH, CTL_EOL);
-#endif
 }
 
 void
diff -r da79d489f13c -r 9545750e6546 sys/kern/init_sysctl_base.c
--- a/sys/kern/init_sysctl_base.c       Tue Oct 31 12:02:20 2017 +0000
+++ b/sys/kern/init_sysctl_base.c       Tue Oct 31 12:37:23 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: init_sysctl_base.c,v 1.7 2015/08/25 14:52:31 pooka Exp $ */
+/*     $NetBSD: init_sysctl_base.c,v 1.8 2017/10/31 12:37:23 martin Exp $ */
 
 /*-
  * Copyright (c) 2003, 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -30,11 +30,12 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: init_sysctl_base.c,v 1.7 2015/08/25 14:52:31 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: init_sysctl_base.c,v 1.8 2017/10/31 12:37:23 martin Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
 #include <sys/sysctl.h>
+#include <sys/proc.h>
 #include <sys/cpu.h>
 #include <sys/kernel.h>
 #include <sys/disklabel.h>
@@ -183,6 +184,19 @@
                       CTL_KERN, KERN_RAWPARTITION, CTL_EOL);
 }
 
+static int
+sysctl_hw_machine_arch(SYSCTLFN_ARGS)
+{
+       struct sysctlnode node = *rnode;
+#ifndef PROC_MACHINE_ARCH
+#define PROC_MACHINE_ARCH(P)   machine_arch
+#endif
+
+       node.sysctl_data = PROC_MACHINE_ARCH(l->l_proc);
+       node.sysctl_size = strlen(node.sysctl_data) + 1;
+       return sysctl_lookup(SYSCTLFN_CALL(&node));
+}
+
 SYSCTL_SETUP(sysctl_hwbase_setup, "sysctl hw subtree base setup")
 {
        u_int u;
@@ -202,10 +216,10 @@
                       NULL, 0, machine, 0,
                       CTL_HW, HW_MACHINE, CTL_EOL);
        sysctl_createv(clog, 0, NULL, NULL,
-                      CTLFLAG_PERMANENT,
+                      CTLFLAG_PERMANENT|CTLFLAG_READONLY,
                       CTLTYPE_STRING, "machine_arch",
                       SYSCTL_DESCR("Machine CPU class"),
-                      NULL, 0, machine_arch, 0,
+                      sysctl_hw_machine_arch, 0, NULL, 0,
                       CTL_HW, HW_MACHINE_ARCH, CTL_EOL);
        sysctl_createv(clog, 0, NULL, NULL,
                       CTLFLAG_PERMANENT,



Home | Main Index | Thread Index | Old Index