sysarch.h revision 1.1 1 /* $NetBSD: sysarch.h,v 1.1 2007/04/16 19:12:19 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 #ifdef _KERNEL
43 #define _X86_SYSARCH_L(x) x86_##x
44 #define _X86_SYSARCH_U(x) X86_##x
45 #define X86_GET_LDT 0
46 #define X86_SET_LDT 1
47 #define X86_IOPL 2
48 #define X86_GET_IOPERM 3
49 #define X86_SET_IOPERM 4
50 #define X86_OLD_VM86 5
51 #define X86_PMC_INFO 8
52 #define X86_PMC_STARTSTOP 9
53 #define X86_PMC_READ 10
54 #define X86_GET_MTRR 11
55 #define X86_SET_MTRR 12
56 #define X86_VM86 13
57 #elif defined(i386)
58 #define _X86_SYSARCH_L(x) i386_##x
59 #define _X86_SYSARCH_U(x) I386_##x
60 #define I386_GET_LDT X86_GET_LDT
61 #define I386_SET_LDT X86_SET_LDT
62 #define I386_IOPL X86_IOPL
63 #define I386_GET_IOPERM X86_GET_IOPERM
64 #define I386_SET_IOPERM X86_SET_IOPERM
65 #define I386_OLD_VM86 X86_OLD_VM86
66 #define I386_PMC_INFO X86_PMC_INFO
67 #define I386_PMC_STARTSTOP X86_PMC_STARTSTOP
68 #define I386_PMC_READ X86_PMC_READ
69 #define I386_GET_MTRR X86_GET_MTRR
70 #define I386_SET_MTRR X86_SET_MTRR
71 #define I386_VM86 X86_VM86
72 #else
73 #define _X86_SYSARCH_L(x) x86_64_##x
74 #define _X86_SYSARCH_U(x) X86_64_##x
75 #define X86_64_GET_LDT X86_GET_LDT
76 #define X86_64_SET_LDT X86_SET_LDT
77 #define X86_64_IOPL X86_IOPL
78 #define X86_64_GET_IOPERM X86_GET_IOPERM
79 #define X86_64_SET_IOPERM X86_SET_IOPERM
80 #define X86_64_OLD_VM86 X86_OLD_VM86
81 #define X86_64_PMC_INFO X86_PMC_INFO
82 #define X86_64_PMC_STARTSTOP X86_PMC_STARTSTOP
83 #define X86_64_PMC_READ X86_PMC_READ
84 #define X86_64_GET_MTRR X86_GET_MTRR
85 #define X86_64_SET_MTRR X86_SET_MTRR
86 #define X86_64_VM86 X86_VM86
87 #endif
88
89 /*
90 * Architecture specific syscalls (x86)
91 */
92
93 struct _X86_SYSARCH_L(get_ldt_args) {
94 int start;
95 union descriptor *desc;
96 int num;
97 };
98
99 struct _X86_SYSARCH_L(set_ldt_args) {
100 int start;
101 union descriptor *desc;
102 int num;
103 };
104
105 struct _X86_SYSARCH_L(get_mtrr_args) {
106 struct mtrr *mtrrp;
107 int *n;
108 };
109
110 struct _X86_SYSARCH_L(set_mtrr_args) {
111 struct mtrr *mtrrp;
112 int *n;
113 };
114
115 struct _X86_SYSARCH_L(iopl_args) {
116 int iopl;
117 };
118
119 struct _X86_SYSARCH_L(get_ioperm_args) {
120 u_long *iomap;
121 };
122
123 struct _X86_SYSARCH_L(set_ioperm_args) {
124 u_long *iomap;
125 };
126
127 struct _X86_SYSARCH_L(pmc_info_args) {
128 int type;
129 int flags;
130 };
131
132 #define PMC_TYPE_NONE 0
133 #define PMC_TYPE_I586 1
134 #define PMC_TYPE_I686 2
135 #define PMC_TYPE_K7 3
136
137 #define PMC_INFO_HASTSC 0x01
138
139 #ifdef i386
140 #define PMC_NCOUNTERS 4
141 #else
142 #define PMC_NCOUNTERS 2
143 #endif
144
145 struct _X86_SYSARCH_L(pmc_startstop_args) {
146 int counter;
147 uint64_t val;
148 uint8_t event;
149 uint8_t unit;
150 uint8_t compare;
151 uint8_t flags;
152 };
153
154 #define PMC_SETUP_KERNEL 0x01
155 #define PMC_SETUP_USER 0x02
156 #define PMC_SETUP_EDGE 0x04
157 #define PMC_SETUP_INV 0x08
158
159 struct _X86_SYSARCH_L(pmc_read_args) {
160 int counter;
161 uint64_t val;
162 uint64_t time;
163 };
164
165 struct mtrr;
166
167 #ifdef _KERNEL
168 int x86_iopl(struct lwp *, void *, register_t *);
169 int x86_get_mtrr(struct lwp *, void *, register_t *);
170 int x86_set_mtrr(struct lwp *, void *, register_t *);
171 int x86_get_ldt(struct lwp *l, void *, register_t *);
172 int x86_set_ldt(struct lwp *l, void *, register_t *);
173 #else
174 #include <sys/cdefs.h>
175 __BEGIN_DECLS
176 int _X86_SYSARCH_L(get_ldt)(int, union descriptor *, int);
177 int _X86_SYSARCH_L(set_ldt)(int, union descriptor *, int);
178 int _X86_SYSARCH_L(iopl)(int);
179 int _X86_SYSARCH_L(pmc_info)(struct _X86_SYSARCH_L(pmc_info_args *));
180 int _X86_SYSARCH_L(pmc_startstop)(struct _X86_SYSARCH_L(pmc_startstop_args *));
181 int _X86_SYSARCH_L(pmc_read)(struct _X86_SYSARCH_L(pmc_read_args *));
182 int _X86_SYSARCH_L(set_mtrr)(struct mtrr *, int *);
183 int _X86_SYSARCH_L(get_mtrr)(struct mtrr *, int *);
184 int sysarch(int, void *);
185 __END_DECLS
186 #endif
187
188 #endif /* !_X86_SYSARCH_H_ */
189