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