| 1 | /*	$NetBSD: sysarch.h,v 1.15 2020/06/19 16:20:22 maxv 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_GET_MTRR		11 |
| 42 | #define X86_SET_MTRR		12 |
| 43 | #define X86_VM86		13 |
| 44 | #define X86_GET_GSBASE		14 |
| 45 | #define X86_GET_FSBASE		15 |
| 46 | #define X86_SET_GSBASE		16 |
| 47 | #define X86_SET_FSBASE		17 |
| 48 | |
| 49 | #ifdef _KERNEL |
| 50 | #define _X86_SYSARCH_L(x)	x86_##x |
| 51 | #define _X86_SYSARCH_U(x)	X86_##x |
| 52 | #elif defined(__i386__) |
| 53 | #define _X86_SYSARCH_L(x)	i386_##x |
| 54 | #define _X86_SYSARCH_U(x)	I386_##x |
| 55 | #define I386_GET_LDT		X86_GET_LDT |
| 56 | #define I386_SET_LDT		X86_SET_LDT |
| 57 | #define I386_IOPL		X86_IOPL |
| 58 | #define I386_GET_IOPERM		X86_GET_IOPERM |
| 59 | #define I386_SET_IOPERM		X86_SET_IOPERM |
| 60 | #define I386_OLD_VM86		X86_OLD_VM86 |
| 61 | #define I386_GET_MTRR		X86_GET_MTRR |
| 62 | #define I386_SET_MTRR		X86_SET_MTRR |
| 63 | #define I386_VM86		X86_VM86 |
| 64 | #define I386_GET_GSBASE		X86_GET_GSBASE |
| 65 | #define I386_GET_FSBASE		X86_GET_FSBASE |
| 66 | #define I386_SET_GSBASE		X86_SET_GSBASE |
| 67 | #define I386_SET_FSBASE		X86_SET_FSBASE |
| 68 | #else |
| 69 | #define _X86_SYSARCH_L(x)	x86_64_##x |
| 70 | #define _X86_SYSARCH_U(x)	X86_64_##x |
| 71 | #define X86_64_GET_LDT		X86_GET_LDT |
| 72 | #define X86_64_SET_LDT		X86_SET_LDT |
| 73 | #define X86_64_IOPL		X86_IOPL |
| 74 | #define X86_64_GET_IOPERM	X86_GET_IOPERM |
| 75 | #define X86_64_SET_IOPERM	X86_SET_IOPERM |
| 76 | #define X86_64_OLD_VM86		X86_OLD_VM86 |
| 77 | #define X86_64_GET_MTRR		X86_GET_MTRR |
| 78 | #define X86_64_SET_MTRR		X86_SET_MTRR |
| 79 | #define X86_64_VM86		X86_VM86 |
| 80 | #define X86_64_GET_GSBASE	X86_GET_GSBASE |
| 81 | #define X86_64_GET_FSBASE	X86_GET_FSBASE |
| 82 | #define X86_64_SET_GSBASE	X86_SET_GSBASE |
| 83 | #define X86_64_SET_FSBASE	X86_SET_FSBASE |
| 84 | #endif |
| 85 | |
| 86 | /* |
| 87 | * Architecture specific syscalls (x86) |
| 88 | */ |
| 89 | |
| 90 | struct _X86_SYSARCH_L(get_ldt_args) { |
| 91 | 	int start; |
| 92 | 	union descriptor *desc; |
| 93 | 	int num; |
| 94 | }; |
| 95 | |
| 96 | struct _X86_SYSARCH_L(set_ldt_args) { |
| 97 | 	int start; |
| 98 | 	union descriptor *desc; |
| 99 | 	int num; |
| 100 | }; |
| 101 | |
| 102 | struct _X86_SYSARCH_L(get_mtrr_args) { |
| 103 | 	struct mtrr *mtrrp; |
| 104 | 	int *n; |
| 105 | }; |
| 106 | |
| 107 | struct _X86_SYSARCH_L(set_mtrr_args) { |
| 108 | 	struct mtrr *mtrrp; |
| 109 | 	int *n; |
| 110 | }; |
| 111 | |
| 112 | struct _X86_SYSARCH_L(iopl_args) { |
| 113 | 	int iopl; |
| 114 | }; |
| 115 | |
| 116 | struct _X86_SYSARCH_L(get_ioperm_args) { |
| 117 | 	u_long *iomap; |
| 118 | }; |
| 119 | |
| 120 | struct _X86_SYSARCH_L(set_ioperm_args) { |
| 121 | 	u_long *iomap; |
| 122 | }; |
| 123 | |
| 124 | struct mtrr; |
| 125 | |
| 126 | #ifdef _KERNEL |
| 127 | int x86_iopl(struct lwp *, void *, register_t *); |
| 128 | int x86_get_ldt1(struct lwp *, struct x86_get_ldt_args *, union descriptor *); |
| 129 | int x86_set_ldt1(struct lwp *, struct x86_set_ldt_args *, union descriptor *); |
| 130 | int x86_set_sdbase(void *, char, lwp_t *, bool); |
| 131 | int x86_get_sdbase(void *, char); |
| 132 | #else |
| 133 | #include <sys/cdefs.h> |
| 134 | __BEGIN_DECLS |
| 135 | int _X86_SYSARCH_L(get_ldt)(int, union descriptor *, int); |
| 136 | int _X86_SYSARCH_L(set_ldt)(int, union descriptor *, int); |
| 137 | int _X86_SYSARCH_L(iopl)(int); |
| 138 | int _X86_SYSARCH_L(set_mtrr)(struct mtrr *, int *); |
| 139 | int _X86_SYSARCH_L(get_mtrr)(struct mtrr *, int *); |
| 140 | int sysarch(int, void *); |
| 141 | __END_DECLS |
| 142 | #endif |
| 143 | |
| 144 | #endif /* !_X86_SYSARCH_H_ */ |