Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/x86 Fetch XSAVE area component offsets and sizes wh...



details:   https://anonhg.NetBSD.org/src/rev/5651c898b9a7
branches:  trunk
changeset: 452290:5651c898b9a7
user:      mgorny <mgorny%NetBSD.org@localhost>
date:      Wed Jun 26 12:29:00 2019 +0000

description:
Fetch XSAVE area component offsets and sizes when initializing x86 CPU

Introduce two new arrays, x86_xsave_offsets and x86_xsave_sizes,
and initialize them with XSAVE area component offsets and sizes queried
via CPUID.  This will be needed to implement getters and setters for
additional register types.

While at it, add XSAVE_* constants corresponding to specific XSAVE
components.

diffstat:

 sys/arch/x86/include/cpu.h        |   4 +++-
 sys/arch/x86/include/specialreg.h |  22 +++++++++++++++++++++-
 sys/arch/x86/x86/identcpu.c       |  16 ++++++++++++++--
 3 files changed, 38 insertions(+), 4 deletions(-)

diffs (105 lines):

diff -r 6c2640c6f972 -r 5651c898b9a7 sys/arch/x86/include/cpu.h
--- a/sys/arch/x86/include/cpu.h        Wed Jun 26 12:21:40 2019 +0000
+++ b/sys/arch/x86/include/cpu.h        Wed Jun 26 12:29:00 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cpu.h,v 1.106 2019/05/27 17:32:36 maxv Exp $   */
+/*     $NetBSD: cpu.h,v 1.107 2019/06/26 12:29:00 mgorny Exp $ */
 
 /*
  * Copyright (c) 1990 The Regents of the University of California.
@@ -459,6 +459,8 @@
 #define        FPU_SAVE_XSAVEOPT       3
 extern unsigned int x86_fpu_save_size;
 extern uint64_t x86_xsave_features;
+extern size_t x86_xsave_offsets[];
+extern size_t x86_xsave_sizes[];
 extern uint32_t x86_fpu_mxcsr_mask;
 extern bool x86_fpu_eager;
 
diff -r 6c2640c6f972 -r 5651c898b9a7 sys/arch/x86/include/specialreg.h
--- a/sys/arch/x86/include/specialreg.h Wed Jun 26 12:21:40 2019 +0000
+++ b/sys/arch/x86/include/specialreg.h Wed Jun 26 12:29:00 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: specialreg.h,v 1.147 2019/05/29 16:54:41 maxv Exp $    */
+/*     $NetBSD: specialreg.h,v 1.148 2019/06/26 12:29:00 mgorny Exp $  */
 
 /*
  * Copyright (c) 2014-2019 The NetBSD Foundation, Inc.
@@ -147,6 +147,26 @@
                         XCR0_Opmask | XCR0_ZMM_Hi256 | XCR0_Hi16_ZMM)
 
 /*
+ * XSAVE component indices.
+ */
+#define XSAVE_X87      0
+#define XSAVE_SSE      1
+#define XSAVE_YMM_Hi128        2
+#define XSAVE_BNDREGS  3
+#define XSAVE_BNDCSR   4
+#define XSAVE_Opmask   5
+#define XSAVE_ZMM_Hi256        6
+#define XSAVE_Hi16_ZMM 7
+#define XSAVE_PT       8
+#define XSAVE_PKRU     9
+#define XSAVE_HDC      10
+
+/*
+ * Highest XSAVE component enabled by XCR0_FPU.
+ */
+#define XSAVE_MAX_COMPONENT XSAVE_Hi16_ZMM
+
+/*
  * CPUID "features" bits
  */
 
diff -r 6c2640c6f972 -r 5651c898b9a7 sys/arch/x86/x86/identcpu.c
--- a/sys/arch/x86/x86/identcpu.c       Wed Jun 26 12:21:40 2019 +0000
+++ b/sys/arch/x86/x86/identcpu.c       Wed Jun 26 12:29:00 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: identcpu.c,v 1.91 2019/05/24 14:28:48 nonaka Exp $     */
+/*     $NetBSD: identcpu.c,v 1.92 2019/06/26 12:29:01 mgorny Exp $     */
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: identcpu.c,v 1.91 2019/05/24 14:28:48 nonaka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: identcpu.c,v 1.92 2019/06/26 12:29:01 mgorny Exp $");
 
 #include "opt_xen.h"
 
@@ -74,6 +74,8 @@
 int x86_fpu_save __read_mostly;
 unsigned int x86_fpu_save_size __read_mostly = sizeof(struct save87);
 uint64_t x86_xsave_features __read_mostly = 0;
+size_t x86_xsave_offsets[XSAVE_MAX_COMPONENT+1] __read_mostly;
+size_t x86_xsave_sizes[XSAVE_MAX_COMPONENT+1] __read_mostly;
 
 /*
  * Note: these are just the ones that may not have a cpuid instruction.
@@ -755,6 +757,7 @@
 cpu_probe_fpu(struct cpu_info *ci)
 {
        u_int descs[4];
+       int i;
 
        x86_fpu_eager = true;
        x86_fpu_save = FPU_SAVE_FSAVE;
@@ -816,6 +819,15 @@
                x86_fpu_save_size = descs[2];
 
        x86_xsave_features = (uint64_t)descs[3] << 32 | descs[0];
+
+       /* Get component offsets and sizes for the save area */
+       for (i = XSAVE_YMM_Hi128; i < __arraycount(x86_xsave_offsets); i++) {
+               if (x86_xsave_features & __BIT(i)) {
+                       x86_cpuid2(0xd, i, descs);
+                       x86_xsave_offsets[i] = descs[1];
+                       x86_xsave_sizes[i] = descs[0];
+               }
+       }
 }
 
 void



Home | Main Index | Thread Index | Old Index