Home | History | Annotate | Line # | Download | only in include
sysarch.h revision 1.9.40.1
      1 /*	$NetBSD: sysarch.h,v 1.9.40.1 2017/03/20 06:57:22 pgoyette Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 2007 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Andrew Doran.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  *
     19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  * POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 
     32 #ifndef _X86_SYSARCH_H_
     33 #define _X86_SYSARCH_H_
     34 
     35 #define X86_GET_LDT		0
     36 #define X86_SET_LDT		1
     37 #define X86_IOPL		2
     38 #define X86_GET_IOPERM		3
     39 #define X86_SET_IOPERM		4
     40 #define X86_OLD_VM86		5
     41 #define X86_PMC_INFO		8
     42 #define X86_PMC_STARTSTOP	9
     43 #define X86_PMC_READ		10
     44 #define X86_GET_MTRR		11
     45 #define X86_SET_MTRR		12
     46 #define X86_VM86		13
     47 #define X86_GET_GSBASE		14
     48 #define X86_GET_FSBASE		15
     49 #define X86_SET_GSBASE		16
     50 #define X86_SET_FSBASE		17
     51 
     52 #ifdef _KERNEL
     53 #define _X86_SYSARCH_L(x)	x86_##x
     54 #define _X86_SYSARCH_U(x)	X86_##x
     55 #elif defined(__i386__)
     56 #define _X86_SYSARCH_L(x)	i386_##x
     57 #define _X86_SYSARCH_U(x)	I386_##x
     58 #define I386_GET_LDT		X86_GET_LDT
     59 #define I386_SET_LDT		X86_SET_LDT
     60 #define I386_IOPL		X86_IOPL
     61 #define I386_GET_IOPERM		X86_GET_IOPERM
     62 #define I386_SET_IOPERM		X86_SET_IOPERM
     63 #define I386_OLD_VM86		X86_OLD_VM86
     64 #define I386_PMC_INFO		X86_PMC_INFO
     65 #define I386_PMC_STARTSTOP	X86_PMC_STARTSTOP
     66 #define I386_PMC_READ		X86_PMC_READ
     67 #define I386_GET_MTRR		X86_GET_MTRR
     68 #define I386_SET_MTRR		X86_SET_MTRR
     69 #define I386_VM86		X86_VM86
     70 #define I386_GET_GSBASE		X86_GET_GSBASE
     71 #define I386_GET_FSBASE		X86_GET_FSBASE
     72 #define I386_SET_GSBASE		X86_SET_GSBASE
     73 #define I386_SET_FSBASE		X86_SET_FSBASE
     74 #else
     75 #define _X86_SYSARCH_L(x)	x86_64_##x
     76 #define _X86_SYSARCH_U(x)	X86_64_##x
     77 #define X86_64_GET_LDT		X86_GET_LDT
     78 #define X86_64_SET_LDT		X86_SET_LDT
     79 #define X86_64_IOPL		X86_IOPL
     80 #define X86_64_GET_IOPERM	X86_GET_IOPERM
     81 #define X86_64_SET_IOPERM	X86_SET_IOPERM
     82 #define X86_64_OLD_VM86		X86_OLD_VM86
     83 #define X86_64_PMC_INFO		X86_PMC_INFO
     84 #define X86_64_PMC_STARTSTOP	X86_PMC_STARTSTOP
     85 #define X86_64_PMC_READ		X86_PMC_READ
     86 #define X86_64_GET_MTRR		X86_GET_MTRR
     87 #define X86_64_SET_MTRR		X86_SET_MTRR
     88 #define X86_64_VM86		X86_VM86
     89 #define X86_64_GET_GSBASE	X86_GET_GSBASE
     90 #define X86_64_GET_FSBASE	X86_GET_FSBASE
     91 #define X86_64_SET_GSBASE	X86_SET_GSBASE
     92 #define X86_64_SET_FSBASE	X86_SET_FSBASE
     93 #endif
     94 
     95 /*
     96  * Architecture specific syscalls (x86)
     97  */
     98 
     99 struct _X86_SYSARCH_L(get_ldt_args) {
    100 	int start;
    101 	union descriptor *desc;
    102 	int num;
    103 };
    104 
    105 struct _X86_SYSARCH_L(set_ldt_args) {
    106 	int start;
    107 	union descriptor *desc;
    108 	int num;
    109 };
    110 
    111 struct _X86_SYSARCH_L(get_mtrr_args) {
    112 	struct mtrr *mtrrp;
    113 	int *n;
    114 };
    115 
    116 struct _X86_SYSARCH_L(set_mtrr_args) {
    117 	struct mtrr *mtrrp;
    118 	int *n;
    119 };
    120 
    121 struct _X86_SYSARCH_L(iopl_args) {
    122 	int iopl;
    123 };
    124 
    125 struct _X86_SYSARCH_L(get_ioperm_args) {
    126 	u_long *iomap;
    127 };
    128 
    129 struct _X86_SYSARCH_L(set_ioperm_args) {
    130 	u_long *iomap;
    131 };
    132 
    133 struct _X86_SYSARCH_L(pmc_info_args) {
    134 	int vers;
    135 	int type;
    136 	uint32_t nctrs;
    137 };
    138 
    139 #define	PMC_VERSION		1
    140 
    141 #define	PMC_TYPE_NONE		0
    142 #define	PMC_TYPE_I586		1
    143 #define	PMC_TYPE_I686		2
    144 #define	PMC_TYPE_K7		3
    145 #define	PMC_TYPE_F10H		4
    146 
    147 #define	PMC_INFO_HASTSC		0x01
    148 
    149 #define	PMC_NCOUNTERS		4
    150 
    151 struct _X86_SYSARCH_L(pmc_startstop_args) {
    152 	uint32_t counter;
    153 	uint64_t val;
    154 	uint32_t event;
    155 	uint32_t unit;
    156 	uint32_t compare;
    157 	uint32_t flags;
    158 };
    159 
    160 #define	PMC_SETUP_KERNEL	0x01
    161 #define	PMC_SETUP_USER		0x02
    162 #define	PMC_SETUP_EDGE		0x04
    163 #define	PMC_SETUP_INV		0x08
    164 
    165 typedef struct {
    166 	uint64_t ctrval;
    167 	uint32_t overfl;
    168 } x86_pmc_cpuval_t;
    169 
    170 struct _X86_SYSARCH_L(pmc_read_args) {
    171 	uint32_t counter;
    172 	x86_pmc_cpuval_t *values;
    173 	uint32_t nval;
    174 };
    175 
    176 struct mtrr;
    177 
    178 #ifdef _KERNEL
    179 int x86_iopl(struct lwp *, void *, register_t *);
    180 int x86_get_mtrr(struct lwp *, void *, register_t *);
    181 int x86_set_mtrr(struct lwp *, void *, register_t *);
    182 int x86_get_ldt(struct lwp *, void *, register_t *);
    183 int x86_get_ldt1(struct lwp *, struct x86_get_ldt_args *, union descriptor *);
    184 int x86_set_ldt(struct lwp *, void *, register_t *);
    185 int x86_set_ldt1(struct lwp *, struct x86_set_ldt_args *, union descriptor *);
    186 int x86_set_sdbase(void *, char, lwp_t *, bool);
    187 int x86_get_sdbase(void *, char);
    188 #else
    189 #include <sys/cdefs.h>
    190 __BEGIN_DECLS
    191 int _X86_SYSARCH_L(get_ldt)(int, union descriptor *, int);
    192 int _X86_SYSARCH_L(set_ldt)(int, union descriptor *, int);
    193 int _X86_SYSARCH_L(iopl)(int);
    194 int _X86_SYSARCH_L(pmc_info)(struct _X86_SYSARCH_L(pmc_info_args *));
    195 int _X86_SYSARCH_L(pmc_startstop)(struct _X86_SYSARCH_L(pmc_startstop_args *));
    196 int _X86_SYSARCH_L(pmc_read)(struct _X86_SYSARCH_L(pmc_read_args *));
    197 int _X86_SYSARCH_L(set_mtrr)(struct mtrr *, int *);
    198 int _X86_SYSARCH_L(get_mtrr)(struct mtrr *, int *);
    199 int sysarch(int, void *);
    200 __END_DECLS
    201 #endif
    202 
    203 #endif /* !_X86_SYSARCH_H_ */
    204