Skip to content
Permalink
Browse files

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.
  • Loading branch information...
mgorny committed Jun 26, 2019
1 parent b945d3a commit 581c569ad68f9fc81d2a310b7ef758e9895a9f40
Showing with 38 additions and 4 deletions.
  1. +3 −1 sys/arch/x86/include/cpu.h
  2. +21 −1 sys/arch/x86/include/specialreg.h
  3. +14 −2 sys/arch/x86/x86/identcpu.c
@@ -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;

@@ -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.
@@ -146,6 +146,26 @@
#define XCR0_FPU (XCR0_X87 | XCR0_SSE | XCR0_YMM_Hi128 | \
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
*/
@@ -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

0 comments on commit 581c569

Please sign in to comment.
You can’t perform that action at this time.