Module Name:    src
Committed By:   mgorny
Date:           Wed Jun 26 12:29:01 UTC 2019

Modified Files:
        src/sys/arch/x86/include: cpu.h specialreg.h
        src/sys/arch/x86/x86: identcpu.c

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.106 -r1.107 src/sys/arch/x86/include/cpu.h
cvs rdiff -u -r1.147 -r1.148 src/sys/arch/x86/include/specialreg.h
cvs rdiff -u -r1.91 -r1.92 src/sys/arch/x86/x86/identcpu.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/x86/include/cpu.h
diff -u src/sys/arch/x86/include/cpu.h:1.106 src/sys/arch/x86/include/cpu.h:1.107
--- src/sys/arch/x86/include/cpu.h:1.106	Mon May 27 17:32:36 2019
+++ src/sys/arch/x86/include/cpu.h	Wed Jun 26 12:29:00 2019
@@ -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 @@ extern int x86_fpu_save;
 #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;
 

Index: src/sys/arch/x86/include/specialreg.h
diff -u src/sys/arch/x86/include/specialreg.h:1.147 src/sys/arch/x86/include/specialreg.h:1.148
--- src/sys/arch/x86/include/specialreg.h:1.147	Wed May 29 16:54:41 2019
+++ src/sys/arch/x86/include/specialreg.h	Wed Jun 26 12:29:00 2019
@@ -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
  */
 

Index: src/sys/arch/x86/x86/identcpu.c
diff -u src/sys/arch/x86/x86/identcpu.c:1.91 src/sys/arch/x86/x86/identcpu.c:1.92
--- src/sys/arch/x86/x86/identcpu.c:1.91	Fri May 24 14:28:48 2019
+++ src/sys/arch/x86/x86/identcpu.c	Wed Jun 26 12:29:01 2019
@@ -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 @@ char cpu_brand_string[49];
 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 @@ static void
 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 @@ cpu_probe_fpu(struct cpu_info *ci)
 		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

Reply via email to