linux_machdep.h revision 1.34 1 1.34 christos /* $NetBSD: linux_machdep.h,v 1.34 2008/10/25 23:38:28 christos Exp $ */
2 1.1 fvdl
3 1.9 fvdl /*-
4 1.16 mycroft * Copyright (c) 1995, 2000 The NetBSD Foundation, Inc.
5 1.1 fvdl * All rights reserved.
6 1.1 fvdl *
7 1.9 fvdl * This code is derived from software contributed to The NetBSD Foundation
8 1.9 fvdl * by Frank van der Linden.
9 1.9 fvdl *
10 1.1 fvdl * Redistribution and use in source and binary forms, with or without
11 1.1 fvdl * modification, are permitted provided that the following conditions
12 1.1 fvdl * are met:
13 1.1 fvdl * 1. Redistributions of source code must retain the above copyright
14 1.1 fvdl * notice, this list of conditions and the following disclaimer.
15 1.1 fvdl * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 fvdl * notice, this list of conditions and the following disclaimer in the
17 1.1 fvdl * documentation and/or other materials provided with the distribution.
18 1.1 fvdl *
19 1.9 fvdl * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.9 fvdl * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.9 fvdl * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.9 fvdl * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.9 fvdl * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.9 fvdl * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.9 fvdl * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.9 fvdl * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.9 fvdl * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.9 fvdl * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.9 fvdl * POSSIBILITY OF SUCH DAMAGE.
30 1.1 fvdl */
31 1.1 fvdl
32 1.8 erh #ifndef _I386_LINUX_MACHDEP_H
33 1.8 erh #define _I386_LINUX_MACHDEP_H
34 1.1 fvdl
35 1.24 christos #include <compat/linux/common/linux_types.h>
36 1.21 christos #include <compat/linux/common/linux_signal.h>
37 1.24 christos #include <compat/linux/common/linux_siginfo.h>
38 1.21 christos
39 1.1 fvdl /*
40 1.1 fvdl * The Linux sigcontext, pretty much a standard 386 trapframe.
41 1.1 fvdl */
42 1.25 christos struct linux_fpreg {
43 1.25 christos uint16_t mant[4];
44 1.25 christos uint16_t expo;
45 1.25 christos };
46 1.25 christos
47 1.25 christos struct linux_fpxreg {
48 1.25 christos uint16_t mant[4];
49 1.25 christos uint16_t expo;
50 1.25 christos uint16_t pad[3];
51 1.25 christos };
52 1.25 christos
53 1.25 christos struct linux_xmmreg {
54 1.25 christos uint32_t reg[4];
55 1.25 christos };
56 1.25 christos
57 1.25 christos struct linux_fpstate {
58 1.25 christos uint32_t cw;
59 1.25 christos uint32_t sw;
60 1.25 christos uint32_t tag;
61 1.25 christos uint32_t ipoff;
62 1.25 christos uint32_t cssel;
63 1.25 christos uint32_t dataoff;
64 1.25 christos uint32_t datasel;
65 1.25 christos struct linux_fpreg st[8];
66 1.25 christos uint16_t status;
67 1.25 christos uint16_t magic;
68 1.25 christos uint32_t fxsr_env[6];
69 1.25 christos uint32_t mxcsr;
70 1.25 christos uint32_t reserved;
71 1.25 christos struct linux_fpxreg fxsr_st[8];
72 1.25 christos struct linux_xmmreg xmm[8];
73 1.25 christos uint32_t padding[56];
74 1.25 christos };
75 1.25 christos
76 1.1 fvdl
77 1.1 fvdl struct linux_sigcontext {
78 1.3 mycroft int sc_gs;
79 1.3 mycroft int sc_fs;
80 1.7 mycroft int sc_es;
81 1.7 mycroft int sc_ds;
82 1.7 mycroft int sc_edi;
83 1.7 mycroft int sc_esi;
84 1.7 mycroft int sc_ebp;
85 1.3 mycroft int sc_esp;
86 1.7 mycroft int sc_ebx;
87 1.7 mycroft int sc_edx;
88 1.7 mycroft int sc_ecx;
89 1.7 mycroft int sc_eax;
90 1.7 mycroft int sc_trapno;
91 1.7 mycroft int sc_err;
92 1.7 mycroft int sc_eip;
93 1.7 mycroft int sc_cs;
94 1.7 mycroft int sc_eflags;
95 1.7 mycroft int sc_esp_at_signal;
96 1.7 mycroft int sc_ss;
97 1.25 christos struct linux_fpstate *sc_387;
98 1.10 fvdl /* XXX check this */
99 1.10 fvdl linux_old_sigset_t sc_mask;
100 1.3 mycroft int sc_cr2;
101 1.1 fvdl };
102 1.1 fvdl
103 1.26 christos struct linux_libc_fpreg {
104 1.26 christos unsigned short significand[4];
105 1.26 christos unsigned short exponent;
106 1.26 christos };
107 1.26 christos
108 1.26 christos struct linux_libc_fpstate {
109 1.26 christos unsigned long cw;
110 1.26 christos unsigned long sw;
111 1.26 christos unsigned long tag;
112 1.26 christos unsigned long ipoff;
113 1.26 christos unsigned long cssel;
114 1.26 christos unsigned long dataoff;
115 1.26 christos unsigned long datasel;
116 1.26 christos struct linux_libc_fpreg _st[8];
117 1.26 christos unsigned long status;
118 1.26 christos };
119 1.26 christos
120 1.26 christos struct linux_ucontext {
121 1.26 christos unsigned long uc_flags;
122 1.26 christos struct ucontext *uc_link;
123 1.26 christos struct linux_sigaltstack uc_stack;
124 1.26 christos struct linux_sigcontext uc_mcontext;
125 1.26 christos linux_sigset_t uc_sigmask;
126 1.26 christos struct linux_libc_fpstate uc_fpregs_mem;
127 1.26 christos };
128 1.26 christos
129 1.1 fvdl /*
130 1.1 fvdl * We make the stack look like Linux expects it when calling a signal
131 1.1 fvdl * handler, but use the BSD way of calling the handler and sigreturn().
132 1.1 fvdl * This means that we need to pass the pointer to the handler too.
133 1.1 fvdl * It is appended to the frame to not interfere with the rest of it.
134 1.1 fvdl */
135 1.25 christos struct linux_rt_sigframe {
136 1.3 mycroft int sf_sig;
137 1.24 christos struct linux_siginfo *sf_sip;
138 1.26 christos struct linux_ucontext *sf_ucp;
139 1.25 christos struct linux_siginfo sf_si;
140 1.26 christos struct linux_ucontext sf_uc;
141 1.24 christos sig_t sf_handler;
142 1.25 christos };
143 1.25 christos
144 1.25 christos struct linux_sigframe {
145 1.25 christos int sf_sig;
146 1.3 mycroft struct linux_sigcontext sf_sc;
147 1.25 christos sig_t sf_handler;
148 1.1 fvdl };
149 1.4 fvdl
150 1.34 christos struct linux_user_desc {
151 1.34 christos unsigned int entry_number;
152 1.34 christos unsigned int base_addr;
153 1.34 christos unsigned int limit;
154 1.34 christos unsigned int seg_32bit:1;
155 1.34 christos unsigned int contents:2;
156 1.34 christos unsigned int read_exec_only:1;
157 1.34 christos unsigned int limit_in_pages:1;
158 1.34 christos unsigned int seg_not_present:1;
159 1.34 christos unsigned int useable:1;
160 1.34 christos };
161 1.34 christos
162 1.34 christos struct linux_desc_struct {
163 1.34 christos unsigned long a, b;
164 1.34 christos };
165 1.34 christos
166 1.34 christos
167 1.34 christos #define LINUX_LOWERWORD 0x0000ffff
168 1.34 christos
169 1.34 christos /*
170 1.34 christos * Macros which does the same thing as those in Linux include/asm-um/ldt-i386.h.
171 1.34 christos * These convert Linux user space descriptor to machine one.
172 1.34 christos */
173 1.34 christos #define LINUX_LDT_entry_a(info) \
174 1.34 christos ((((info)->base_addr & LINUX_LOWERWORD) << 16) | \
175 1.34 christos ((info)->limit & LINUX_LOWERWORD))
176 1.34 christos
177 1.34 christos #define LINUX_ENTRY_B_READ_EXEC_ONLY 9
178 1.34 christos #define LINUX_ENTRY_B_CONTENTS 10
179 1.34 christos #define LINUX_ENTRY_B_SEG_NOT_PRESENT 15
180 1.34 christos #define LINUX_ENTRY_B_BASE_ADDR 16
181 1.34 christos #define LINUX_ENTRY_B_USEABLE 20
182 1.34 christos #define LINUX_ENTRY_B_SEG32BIT 22
183 1.34 christos #define LINUX_ENTRY_B_LIMIT 23
184 1.34 christos
185 1.34 christos #define LINUX_LDT_entry_b(info) \
186 1.34 christos (((info)->base_addr & 0xff000000) | \
187 1.34 christos ((info)->limit & 0xf0000) | \
188 1.34 christos ((info)->contents << LINUX_ENTRY_B_CONTENTS) | \
189 1.34 christos (((info)->seg_not_present == 0) << LINUX_ENTRY_B_SEG_NOT_PRESENT) |\
190 1.34 christos (((info)->base_addr & 0x00ff0000) >> LINUX_ENTRY_B_BASE_ADDR) | \
191 1.34 christos (((info)->read_exec_only == 0) << LINUX_ENTRY_B_READ_EXEC_ONLY) |\
192 1.34 christos ((info)->seg_32bit << LINUX_ENTRY_B_SEG32BIT) | \
193 1.34 christos ((info)->useable << LINUX_ENTRY_B_USEABLE) | \
194 1.34 christos ((info)->limit_in_pages << LINUX_ENTRY_B_LIMIT) | 0x7000)
195 1.34 christos
196 1.34 christos #define LINUX_LDT_empty(info) \
197 1.34 christos ((info)->base_addr == 0 && \
198 1.34 christos (info)->limit == 0 && \
199 1.34 christos (info)->contents == 0 && \
200 1.34 christos (info)->seg_not_present == 1 && \
201 1.34 christos (info)->read_exec_only == 1 && \
202 1.34 christos (info)->seg_32bit == 0 && \
203 1.34 christos (info)->limit_in_pages == 0 && \
204 1.34 christos (info)->useable == 0)
205 1.34 christos
206 1.34 christos /*
207 1.34 christos * Macros for converting segments.
208 1.34 christos * They do the same as those in arch/i386/kernel/process.c in Linux.
209 1.34 christos */
210 1.34 christos #define LINUX_GET_BASE(desc) \
211 1.34 christos ((((desc)->a >> 16) & LINUX_LOWERWORD) | \
212 1.34 christos (((desc)->b << 16) & 0x00ff0000) | \
213 1.34 christos ((desc)->b & 0xff000000))
214 1.34 christos
215 1.34 christos #define LINUX_GET_LIMIT(desc) \
216 1.34 christos (((desc)->a & LINUX_LOWERWORD) | \
217 1.34 christos ((desc)->b & 0xf0000))
218 1.34 christos
219 1.34 christos #define LINUX_GET_32BIT(desc) \
220 1.34 christos (((desc)->b >> LINUX_ENTRY_B_SEG32BIT) & 1)
221 1.34 christos #define LINUX_GET_CONTENTS(desc) \
222 1.34 christos (((desc)->b >> LINUX_ENTRY_B_CONTENTS) & 3)
223 1.34 christos #define LINUX_GET_WRITABLE(desc) \
224 1.34 christos (((desc)->b >> LINUX_ENTRY_B_READ_EXEC_ONLY) & 1)
225 1.34 christos #define LINUX_GET_LIMIT_PAGES(desc) \
226 1.34 christos (((desc)->b >> LINUX_ENTRY_B_LIMIT) & 1)
227 1.34 christos #define LINUX_GET_PRESENT(desc) \
228 1.34 christos (((desc)->b >> LINUX_ENTRY_B_SEG_NOT_PRESENT) & 1)
229 1.34 christos #define LINUX_GET_USEABLE(desc) \
230 1.34 christos (((desc)->b >> LINUX_ENTRY_B_USEABLE) & 1)
231 1.34 christos
232 1.4 fvdl /*
233 1.28 christos * Used in ugly patch to fake device numbers.
234 1.4 fvdl */
235 1.28 christos /* Major device numbers for new style ptys. */
236 1.28 christos #define LINUX_PTC_MAJOR 2
237 1.28 christos #define LINUX_PTS_MAJOR 3
238 1.28 christos /* Major device numbers of VT device on both Linux and NetBSD. */
239 1.28 christos #define LINUX_CONS_MAJOR 4
240 1.4 fvdl
241 1.4 fvdl /*
242 1.4 fvdl * Linux ioctl calls for the keyboard.
243 1.4 fvdl */
244 1.4 fvdl #define LINUX_KDGKBMODE 0x4b44
245 1.4 fvdl #define LINUX_KDSKBMODE 0x4b45
246 1.4 fvdl #define LINUX_KDMKTONE 0x4b30
247 1.4 fvdl #define LINUX_KDSETMODE 0x4b3a
248 1.19 fvdl #define LINUX_KDGETMODE 0x4b3b
249 1.4 fvdl #define LINUX_KDENABIO 0x4b36
250 1.4 fvdl #define LINUX_KDDISABIO 0x4b37
251 1.4 fvdl #define LINUX_KDGETLED 0x4b31
252 1.4 fvdl #define LINUX_KDSETLED 0x4b32
253 1.20 fvdl #define LINUX_KDGKBTYPE 0x4b33
254 1.20 fvdl #define LINUX_KDGKBENT 0x4b46
255 1.20 fvdl #define LINUX_KIOCSOUND 0x4b2f
256 1.6 drochner
257 1.4 fvdl /*
258 1.4 fvdl * Mode for KDSKBMODE which we don't have (we just use plain mode for this)
259 1.4 fvdl */
260 1.4 fvdl #define LINUX_K_MEDIUMRAW 2
261 1.4 fvdl
262 1.4 fvdl /*
263 1.12 veego * VT ioctl calls in Linux (the ones that the pcvt emulation in wscons can handle)
264 1.4 fvdl */
265 1.4 fvdl #define LINUX_VT_OPENQRY 0x5600
266 1.4 fvdl #define LINUX_VT_GETMODE 0x5601
267 1.4 fvdl #define LINUX_VT_SETMODE 0x5602
268 1.6 drochner #define LINUX_VT_GETSTATE 0x5603
269 1.4 fvdl #define LINUX_VT_RELDISP 0x5605
270 1.4 fvdl #define LINUX_VT_ACTIVATE 0x5606
271 1.4 fvdl #define LINUX_VT_WAITACTIVE 0x5607
272 1.15 fvdl #define LINUX_VT_DISALLOCATE 0x5608
273 1.17 fvdl
274 1.17 fvdl /*
275 1.17 fvdl * This range used by VMWare (XXX)
276 1.17 fvdl */
277 1.17 fvdl #define LINUX_VMWARE_NONE 200
278 1.17 fvdl #define LINUX_VMWARE_LAST 237
279 1.17 fvdl
280 1.17 fvdl /*
281 1.17 fvdl * Range of ioctls to just pass on, so that LKMs (like VMWare) can
282 1.17 fvdl * handle them.
283 1.17 fvdl */
284 1.17 fvdl #define LINUX_IOCTL_MIN_PASS LINUX_VMWARE_NONE
285 1.17 fvdl #define LINUX_IOCTL_MAX_PASS (LINUX_VMWARE_LAST+8)
286 1.13 jdolecek
287 1.30 christos #define LINUX_UNAME_ARCH linux_get_uname_arch()
288 1.31 christos #define LINUX_NPTL
289 1.30 christos
290 1.18 mycroft #ifdef _KERNEL
291 1.18 mycroft __BEGIN_DECLS
292 1.30 christos void linux_syscall_intern(struct proc *);
293 1.30 christos const char *linux_get_uname_arch(void);
294 1.18 mycroft __END_DECLS
295 1.18 mycroft #endif /* !_KERNEL */
296 1.1 fvdl
297 1.8 erh #endif /* _I386_LINUX_MACHDEP_H */
298