1/* $NetBSD: sysarch.h,v 1.9 2010/07/07 01:14:53 chs 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
99struct _X86_SYSARCH_L(get_ldt_args) {
100 int start;
101 union descriptor *desc;
102 int num;
103};
104
105struct _X86_SYSARCH_L(set_ldt_args) {
106 int start;
107 union descriptor *desc;
108 int num;
109};
110
111struct _X86_SYSARCH_L(get_mtrr_args) {
112 struct mtrr *mtrrp;
113 int *n;
114};
115
116struct _X86_SYSARCH_L(set_mtrr_args) {
117 struct mtrr *mtrrp;
118 int *n;
119};
120
121struct _X86_SYSARCH_L(iopl_args) {
122 int iopl;
123};
124
125struct _X86_SYSARCH_L(get_ioperm_args) {
126 u_long *iomap;
127};
128
129struct _X86_SYSARCH_L(set_ioperm_args) {
130 u_long *iomap;
131};
132
133struct _X86_SYSARCH_L(pmc_info_args) {
134 int type;
135 int flags;
136};
137
138#define PMC_TYPE_NONE 0
139#define PMC_TYPE_I586 1
140#define PMC_TYPE_I686 2
141#define PMC_TYPE_K7 3
142
143#define PMC_INFO_HASTSC 0x01
144
145#ifdef __i386__
146#define PMC_NCOUNTERS 4
147#else
148#define PMC_NCOUNTERS 2
149#endif
150
151struct _X86_SYSARCH_L(pmc_startstop_args) {
152 int counter;
153 uint64_t val;
154 uint8_t event;
155 uint8_t unit;
156 uint8_t compare;
157 uint8_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
165struct _X86_SYSARCH_L(pmc_read_args) {
166 int counter;
167 uint64_t val;
168 uint64_t time;
169};
170
171struct mtrr;
172
173#ifdef _KERNEL
174int x86_iopl(struct lwp *, void *, register_t *);
175int x86_get_mtrr(struct lwp *, void *, register_t *);
176int x86_set_mtrr(struct lwp *, void *, register_t *);
177int x86_get_ldt(struct lwp *, void *, register_t *);
178int x86_get_ldt1(struct lwp *, struct x86_get_ldt_args *, union descriptor *);
179int x86_set_ldt(struct lwp *, void *, register_t *);
180int x86_set_ldt1(struct lwp *, struct x86_set_ldt_args *, union descriptor *);
181int x86_set_sdbase(void *, char, lwp_t *, bool);
182int x86_get_sdbase(void *, char);
183#else
184#include <sys/cdefs.h>
185__BEGIN_DECLS
186int _X86_SYSARCH_L(get_ldt)(int, union descriptor *, int);
187int _X86_SYSARCH_L(set_ldt)(int, union descriptor *, int);
188int _X86_SYSARCH_L(iopl)(int);
189int _X86_SYSARCH_L(pmc_info)(struct _X86_SYSARCH_L(pmc_info_args *));
190int _X86_SYSARCH_L(pmc_startstop)(struct _X86_SYSARCH_L(pmc_startstop_args *));
191int _X86_SYSARCH_L(pmc_read)(struct _X86_SYSARCH_L(pmc_read_args *));
192int _X86_SYSARCH_L(set_mtrr)(struct mtrr *, int *);
193int _X86_SYSARCH_L(get_mtrr)(struct mtrr *, int *);
194int sysarch(int, void *);
195__END_DECLS
196#endif
197
198#endif /* !_X86_SYSARCH_H_ */
199