sysarch.h revision 1.2 1 /* $NetBSD: sysarch.h,v 1.2 2007/04/16 19:25:04 ad 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 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 #ifndef _X86_SYSARCH_H_
40 #define _X86_SYSARCH_H_
41
42 #define X86_GET_LDT 0
43 #define X86_SET_LDT 1
44 #define X86_IOPL 2
45 #define X86_GET_IOPERM 3
46 #define X86_SET_IOPERM 4
47 #define X86_OLD_VM86 5
48 #define X86_PMC_INFO 8
49 #define X86_PMC_STARTSTOP 9
50 #define X86_PMC_READ 10
51 #define X86_GET_MTRR 11
52 #define X86_SET_MTRR 12
53 #define X86_VM86 13
54
55 #ifdef _KERNEL
56 #define _X86_SYSARCH_L(x) x86_##x
57 #define _X86_SYSARCH_U(x) X86_##x
58 #elif defined(i386)
59 #define _X86_SYSARCH_L(x) i386_##x
60 #define _X86_SYSARCH_U(x) I386_##x
61 #define I386_GET_LDT X86_GET_LDT
62 #define I386_SET_LDT X86_SET_LDT
63 #define I386_IOPL X86_IOPL
64 #define I386_GET_IOPERM X86_GET_IOPERM
65 #define I386_SET_IOPERM X86_SET_IOPERM
66 #define I386_OLD_VM86 X86_OLD_VM86
67 #define I386_PMC_INFO X86_PMC_INFO
68 #define I386_PMC_STARTSTOP X86_PMC_STARTSTOP
69 #define I386_PMC_READ X86_PMC_READ
70 #define I386_GET_MTRR X86_GET_MTRR
71 #define I386_SET_MTRR X86_SET_MTRR
72 #define I386_VM86 X86_VM86
73 #else
74 #define _X86_SYSARCH_L(x) x86_64_##x
75 #define _X86_SYSARCH_U(x) X86_64_##x
76 #define X86_64_GET_LDT X86_GET_LDT
77 #define X86_64_SET_LDT X86_SET_LDT
78 #define X86_64_IOPL X86_IOPL
79 #define X86_64_GET_IOPERM X86_GET_IOPERM
80 #define X86_64_SET_IOPERM X86_SET_IOPERM
81 #define X86_64_OLD_VM86 X86_OLD_VM86
82 #define X86_64_PMC_INFO X86_PMC_INFO
83 #define X86_64_PMC_STARTSTOP X86_PMC_STARTSTOP
84 #define X86_64_PMC_READ X86_PMC_READ
85 #define X86_64_GET_MTRR X86_GET_MTRR
86 #define X86_64_SET_MTRR X86_SET_MTRR
87 #define X86_64_VM86 X86_VM86
88 #endif
89
90 /*
91 * Architecture specific syscalls (x86)
92 */
93
94 struct _X86_SYSARCH_L(get_ldt_args) {
95 int start;
96 union descriptor *desc;
97 int num;
98 };
99
100 struct _X86_SYSARCH_L(set_ldt_args) {
101 int start;
102 union descriptor *desc;
103 int num;
104 };
105
106 struct _X86_SYSARCH_L(get_mtrr_args) {
107 struct mtrr *mtrrp;
108 int *n;
109 };
110
111 struct _X86_SYSARCH_L(set_mtrr_args) {
112 struct mtrr *mtrrp;
113 int *n;
114 };
115
116 struct _X86_SYSARCH_L(iopl_args) {
117 int iopl;
118 };
119
120 struct _X86_SYSARCH_L(get_ioperm_args) {
121 u_long *iomap;
122 };
123
124 struct _X86_SYSARCH_L(set_ioperm_args) {
125 u_long *iomap;
126 };
127
128 struct _X86_SYSARCH_L(pmc_info_args) {
129 int type;
130 int flags;
131 };
132
133 #define PMC_TYPE_NONE 0
134 #define PMC_TYPE_I586 1
135 #define PMC_TYPE_I686 2
136 #define PMC_TYPE_K7 3
137
138 #define PMC_INFO_HASTSC 0x01
139
140 #ifdef i386
141 #define PMC_NCOUNTERS 4
142 #else
143 #define PMC_NCOUNTERS 2
144 #endif
145
146 struct _X86_SYSARCH_L(pmc_startstop_args) {
147 int counter;
148 uint64_t val;
149 uint8_t event;
150 uint8_t unit;
151 uint8_t compare;
152 uint8_t flags;
153 };
154
155 #define PMC_SETUP_KERNEL 0x01
156 #define PMC_SETUP_USER 0x02
157 #define PMC_SETUP_EDGE 0x04
158 #define PMC_SETUP_INV 0x08
159
160 struct _X86_SYSARCH_L(pmc_read_args) {
161 int counter;
162 uint64_t val;
163 uint64_t time;
164 };
165
166 struct mtrr;
167
168 #ifdef _KERNEL
169 int x86_iopl(struct lwp *, void *, register_t *);
170 int x86_get_mtrr(struct lwp *, void *, register_t *);
171 int x86_set_mtrr(struct lwp *, void *, register_t *);
172 int x86_get_ldt(struct lwp *l, void *, register_t *);
173 int x86_set_ldt(struct lwp *l, void *, register_t *);
174 #else
175 #include <sys/cdefs.h>
176 __BEGIN_DECLS
177 int _X86_SYSARCH_L(get_ldt)(int, union descriptor *, int);
178 int _X86_SYSARCH_L(set_ldt)(int, union descriptor *, int);
179 int _X86_SYSARCH_L(iopl)(int);
180 int _X86_SYSARCH_L(pmc_info)(struct _X86_SYSARCH_L(pmc_info_args *));
181 int _X86_SYSARCH_L(pmc_startstop)(struct _X86_SYSARCH_L(pmc_startstop_args *));
182 int _X86_SYSARCH_L(pmc_read)(struct _X86_SYSARCH_L(pmc_read_args *));
183 int _X86_SYSARCH_L(set_mtrr)(struct mtrr *, int *);
184 int _X86_SYSARCH_L(get_mtrr)(struct mtrr *, int *);
185 int sysarch(int, void *);
186 __END_DECLS
187 #endif
188
189 #endif /* !_X86_SYSARCH_H_ */
190