Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/arch Introduce a weak alias method of exporting differen...
details: https://anonhg.NetBSD.org/src/rev/a97d4e704a05
branches: trunk
changeset: 995436:a97d4e704a05
user: cherry <cherry%NetBSD.org@localhost>
date: Sat Dec 22 21:27:22 2018 +0000
description:
Introduce a weak alias method of exporting different implementations
of the same API.
For eg: the amd64 native implementation of invlpg() now becomes
amd64_invlpg() with a weak symbol export of invlpg(), while the XEN
implementation becomes xen_invlpg(), also weakly exported as invlpg()
Note that linking in both together without having an override function
named invlpg() would be a mistake, as we have limited control over
which of the two options would emerge as the finally exported invlpg()
resulting in a potential situation where the wrong function is finally
exported. This change avoids this situation.
We should however include an override function invlpg() in that case,
such that it is able to then pass on the call to the appropriate
backing function (amd64_invlpg() in the case of native, and
xen_invlpg() in the case of under XEN virtualisation) at runtime.
This change does not introduce such a function and therefore does not
alter builds to include native as well as XEN implementations in the
same binary. This will be done later, with the introduction of XEN
PVHVM mode, where precisely such a runtime switch is required.
There are no operational changes introduced by this change.
diffstat:
sys/arch/amd64/amd64/cpufunc.S | 133 +++++++++++++++++++++++++---------------
sys/arch/i386/i386/cpufunc.S | 24 +++++-
sys/arch/i386/i386/i386func.S | 129 ++++++++++++++++++++++++--------------
sys/arch/xen/x86/xenfunc.c | 118 ++++++++++++++++++++++++++++--------
4 files changed, 275 insertions(+), 129 deletions(-)
diffs (truncated from 822 to 300 lines):
diff -r 72a09378d109 -r a97d4e704a05 sys/arch/amd64/amd64/cpufunc.S
--- a/sys/arch/amd64/amd64/cpufunc.S Sat Dec 22 20:57:44 2018 +0000
+++ b/sys/arch/amd64/amd64/cpufunc.S Sat Dec 22 21:27:22 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cpufunc.S,v 1.33 2018/07/21 06:09:13 maxv Exp $ */
+/* $NetBSD: cpufunc.S,v 1.34 2018/12/22 21:27:22 cherry Exp $ */
/*
* Copyright (c) 1998, 2007, 2008 The NetBSD Foundation, Inc.
@@ -63,18 +63,53 @@
ret
END(x86_mfence)
+/*
+ * These functions below should always be accessed via the corresponding wrapper
+ * function names defined in x86/include/cpufunc.h and exported as WEAK_ALIAS()
+ *
+ * We use this rather roundabout method so that a runtime wrapper function may
+ * be made available for PVHVM, which could override both native and PV aliases
+ * and decide which to invoke at run time.
+ */
+
+WEAK_ALIAS(invlpg, amd64_invlpg)
+WEAK_ALIAS(lidt, amd64_lidt)
+WEAK_ALIAS(lldt, amd64_lldt)
+WEAK_ALIAS(ltr, amd64_ltr)
+WEAK_ALIAS(lcr0, amd64_lcr0)
+WEAK_ALIAS(rcr0, amd64_rcr0)
+WEAK_ALIAS(rcr2, amd64_rcr2)
+WEAK_ALIAS(lcr2, amd64_lcr2)
+WEAK_ALIAS(rcr3, amd64_rcr3)
+WEAK_ALIAS(lcr3, amd64_lcr3)
+WEAK_ALIAS(tlbflush, amd64_tlbflush)
+WEAK_ALIAS(tlbflushg, amd64_tlbflushg)
+WEAK_ALIAS(rdr0, amd64_rdr0)
+WEAK_ALIAS(ldr0, amd64_ldr0)
+WEAK_ALIAS(rdr1, amd64_rdr1)
+WEAK_ALIAS(ldr1, amd64_ldr1)
+WEAK_ALIAS(rdr2, amd64_rdr2)
+WEAK_ALIAS(ldr2, amd64_ldr2)
+WEAK_ALIAS(rdr3, amd64_rdr3)
+WEAK_ALIAS(ldr3, amd64_ldr3)
+WEAK_ALIAS(rdr6, amd64_rdr6)
+WEAK_ALIAS(ldr6, amd64_ldr6)
+WEAK_ALIAS(rdr7, amd64_rdr7)
+WEAK_ALIAS(ldr7, amd64_ldr7)
+WEAK_ALIAS(wbinvd, amd64_wbinvd)
+
#ifndef XEN
-ENTRY(invlpg)
+ENTRY(amd64_invlpg)
invlpg (%rdi)
ret
-END(invlpg)
+END(amd64_invlpg)
-ENTRY(lidt)
+ENTRY(amd64_lidt)
lidt (%rdi)
ret
-END(lidt)
+END(amd64_lidt)
-ENTRY(lldt)
+ENTRY(amd64_lldt)
cmpl %edi, CPUVAR(CURLDT)
jne 1f
ret
@@ -82,42 +117,42 @@
movl %edi, CPUVAR(CURLDT)
lldt %di
ret
-END(lldt)
+END(amd64_lldt)
-ENTRY(ltr)
+ENTRY(amd64_ltr)
ltr %di
ret
-END(ltr)
+END(amd64_ltr)
-ENTRY(lcr0)
+ENTRY(amd64_lcr0)
movq %rdi, %cr0
ret
-END(lcr0)
+END(amd64_lcr0)
-ENTRY(rcr0)
+ENTRY(amd64_rcr0)
movq %cr0, %rax
ret
-END(rcr0)
+END(amd64_rcr0)
-ENTRY(lcr2)
+ENTRY(amd64_lcr2)
movq %rdi, %cr2
ret
-END(lcr2)
+END(amd64_lcr2)
-ENTRY(rcr2)
+ENTRY(amd64_rcr2)
movq %cr2, %rax
ret
-END(rcr2)
+END(amd64_rcr2)
-ENTRY(lcr3)
+ENTRY(amd64_lcr3)
movq %rdi, %cr3
ret
-END(lcr3)
+END(amd64_lcr3)
-ENTRY(rcr3)
+ENTRY(amd64_rcr3)
movq %cr3, %rax
ret
-END(rcr3)
+END(amd64_rcr3)
#endif
ENTRY(lcr4)
@@ -159,7 +194,7 @@
* If PGE is not in use, we reload CR3.
*/
#ifndef XEN
-ENTRY(tlbflushg)
+ENTRY(amd64_tlbflushg)
movq %cr4, %rax
testq $CR4_PGE, %rax
jz 1f
@@ -168,74 +203,74 @@
movq %rdx, %cr4
movq %rax, %cr4
ret
-END(tlbflushg)
+END(amd64_tlbflushg)
-ENTRY(tlbflush)
+ENTRY(amd64_tlbflush)
1:
movq %cr3, %rax
movq %rax, %cr3
ret
-END(tlbflush)
+END(amd64_tlbflush)
-ENTRY(ldr0)
+ENTRY(amd64_ldr0)
movq %rdi, %dr0
ret
-END(ldr0)
+END(amd64_ldr0)
-ENTRY(rdr0)
+ENTRY(amd64_rdr0)
movq %dr0, %rax
ret
-END(rdr0)
+END(amd64_rdr0)
-ENTRY(ldr1)
+ENTRY(amd64_ldr1)
movq %rdi, %dr1
ret
-END(ldr1)
+END(amd64_ldr1)
-ENTRY(rdr1)
+ENTRY(amd64_rdr1)
movq %dr1, %rax
ret
-END(rdr1)
+END(amd64_rdr1)
-ENTRY(ldr2)
+ENTRY(amd64_ldr2)
movq %rdi, %dr2
ret
-END(ldr2)
+END(amd64_ldr2)
-ENTRY(rdr2)
+ENTRY(amd64_rdr2)
movq %dr2, %rax
ret
-END(rdr2)
+END(amd64_rdr2)
-ENTRY(ldr3)
+ENTRY(amd64_ldr3)
movq %rdi, %dr3
ret
-END(ldr3)
+END(amd64_ldr3)
-ENTRY(rdr3)
+ENTRY(amd64_rdr3)
movq %dr3, %rax
ret
-END(rdr3)
+END(amd64_rdr3)
-ENTRY(ldr6)
+ENTRY(amd64_ldr6)
movq %rdi, %dr6
ret
-END(ldr6)
+END(amd64_ldr6)
-ENTRY(rdr6)
+ENTRY(amd64_rdr6)
movq %dr6, %rax
ret
-END(rdr6)
+END(amd64_rdr6)
-ENTRY(ldr7)
+ENTRY(amd64_ldr7)
movq %rdi, %dr7
ret
-END(ldr7)
+END(amd64_ldr7)
-ENTRY(rdr7)
+ENTRY(amd64_rdr7)
movq %dr7, %rax
ret
-END(rdr7)
+END(amd64_rdr7)
ENTRY(x86_disable_intr)
cli
diff -r 72a09378d109 -r a97d4e704a05 sys/arch/i386/i386/cpufunc.S
--- a/sys/arch/i386/i386/cpufunc.S Sat Dec 22 20:57:44 2018 +0000
+++ b/sys/arch/i386/i386/cpufunc.S Sat Dec 22 21:27:22 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cpufunc.S,v 1.25 2018/10/18 04:11:14 cherry Exp $ */
+/* $NetBSD: cpufunc.S,v 1.26 2018/12/22 21:27:22 cherry Exp $ */
/*-
* Copyright (c) 1998, 2007 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
#include <sys/errno.h>
#include <machine/asm.h>
-__KERNEL_RCSID(0, "$NetBSD: cpufunc.S,v 1.25 2018/10/18 04:11:14 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpufunc.S,v 1.26 2018/12/22 21:27:22 cherry Exp $");
#include "opt_xen.h"
@@ -47,6 +47,18 @@
#include "assym.h"
+/*
+ * These functions below should always be accessed via the corresponding wrapper
+ * function names defined in x86/include/cpufunc.h and exported as WEAK_ALIAS()
+ *
+ * We use this rather roundabout method so that a runtime wrapper function may
+ * be made available for PVHVM, which could override both native and PV aliases
+ * and decide which to invoke at run time.
+ */
+
+WEAK_ALIAS(lidt, i386_lidt)
+WEAK_ALIAS(rcr3, i386_rcr3)
+
ENTRY(x86_lfence)
lock
addl $0, -4(%esp)
@@ -66,17 +78,17 @@
END(x86_mfence)
#ifndef XEN
-ENTRY(lidt)
+ENTRY(i386_lidt)
movl 4(%esp), %eax
lidt (%eax)
ret
-END(lidt)
+END(i386_lidt)
#endif /* XEN */
-ENTRY(rcr3)
+ENTRY(i386_rcr3)
movl %cr3, %eax
ret
-END(rcr3)
+END(i386_rcr3)
ENTRY(lcr4)
movl 4(%esp), %eax
diff -r 72a09378d109 -r a97d4e704a05 sys/arch/i386/i386/i386func.S
--- a/sys/arch/i386/i386/i386func.S Sat Dec 22 20:57:44 2018 +0000
+++ b/sys/arch/i386/i386/i386func.S Sat Dec 22 21:27:22 2018 +0000
@@ -1,4 +1,4 @@
Home |
Main Index |
Thread Index |
Old Index