blob: a2be241ed036999c07b7196a9f0d5d300f1efc22 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef _LINUX_VM86_H
2#define _LINUX_VM86_H
3
4/*
5 * I'm guessing at the VIF/VIP flag usage, but hope that this is how
6 * the Pentium uses them. Linux will return from vm86 mode when both
7 * VIF and VIP is set.
8 *
9 * On a Pentium, we could probably optimize the virtual flags directly
10 * in the eflags register instead of doing it "by hand" in vflags...
11 *
12 * Linus
13 */
14
15#define TF_MASK 0x00000100
16#define IF_MASK 0x00000200
17#define IOPL_MASK 0x00003000
18#define NT_MASK 0x00004000
Matt Mackall64ca9002006-01-08 01:05:26 -080019#ifdef CONFIG_VM86
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#define VM_MASK 0x00020000
Matt Mackall64ca9002006-01-08 01:05:26 -080021#else
22#define VM_MASK 0 /* ignored */
23#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#define AC_MASK 0x00040000
25#define VIF_MASK 0x00080000 /* virtual interrupt flag */
26#define VIP_MASK 0x00100000 /* virtual interrupt pending */
27#define ID_MASK 0x00200000
28
29#define BIOSSEG 0x0f000
30
31#define CPU_086 0
32#define CPU_186 1
33#define CPU_286 2
34#define CPU_386 3
35#define CPU_486 4
36#define CPU_586 5
37
38/*
39 * Return values for the 'vm86()' system call
40 */
41#define VM86_TYPE(retval) ((retval) & 0xff)
42#define VM86_ARG(retval) ((retval) >> 8)
43
44#define VM86_SIGNAL 0 /* return due to signal */
Joe Perches9e8a9352008-03-23 01:03:58 -070045#define VM86_UNKNOWN 1 /* unhandled GP fault
46 - IO-instruction or similar */
Linus Torvalds1da177e2005-04-16 15:20:36 -070047#define VM86_INTx 2 /* int3/int x instruction (ARG = x) */
Joe Perches9e8a9352008-03-23 01:03:58 -070048#define VM86_STI 3 /* sti/popf/iret instruction enabled
49 virtual interrupts */
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
51/*
52 * Additional return values when invoking new vm86()
53 */
54#define VM86_PICRETURN 4 /* return due to pending PIC request */
55#define VM86_TRAP 6 /* return due to DOS-debugger request */
56
57/*
58 * function codes when invoking new vm86()
59 */
60#define VM86_PLUS_INSTALL_CHECK 0
61#define VM86_ENTER 1
62#define VM86_ENTER_NO_BYPASS 2
63#define VM86_REQUEST_IRQ 3
64#define VM86_FREE_IRQ 4
65#define VM86_GET_IRQ_BITS 5
66#define VM86_GET_AND_RESET_IRQ 6
67
68/*
69 * This is the stack-layout seen by the user space program when we have
70 * done a translation of "SAVE_ALL" from vm86 mode. The real kernel layout
71 * is 'kernel_vm86_regs' (see below).
72 */
73
74struct vm86_regs {
75/*
76 * normal regs, with special meaning for the segment descriptors..
77 */
78 long ebx;
79 long ecx;
80 long edx;
81 long esi;
82 long edi;
83 long ebp;
84 long eax;
85 long __null_ds;
86 long __null_es;
87 long __null_fs;
88 long __null_gs;
89 long orig_eax;
90 long eip;
91 unsigned short cs, __csh;
92 long eflags;
93 long esp;
94 unsigned short ss, __ssh;
95/*
96 * these are specific to v86 mode:
97 */
98 unsigned short es, __esh;
99 unsigned short ds, __dsh;
100 unsigned short fs, __fsh;
101 unsigned short gs, __gsh;
102};
103
104struct revectored_struct {
105 unsigned long __map[8]; /* 256 bits */
106};
107
108struct vm86_struct {
109 struct vm86_regs regs;
110 unsigned long flags;
111 unsigned long screen_bitmap;
112 unsigned long cpu_type;
113 struct revectored_struct int_revectored;
114 struct revectored_struct int21_revectored;
115};
116
117/*
118 * flags masks
119 */
120#define VM86_SCREEN_BITMAP 0x0001
121
122struct vm86plus_info_struct {
123 unsigned long force_return_for_pic:1;
124 unsigned long vm86dbg_active:1; /* for debugger */
125 unsigned long vm86dbg_TFpendig:1; /* for debugger */
126 unsigned long unused:28;
127 unsigned long is_vm86pus:1; /* for vm86 internal use */
128 unsigned char vm86dbg_intxxtab[32]; /* for debugger */
129};
130
131struct vm86plus_struct {
132 struct vm86_regs regs;
133 unsigned long flags;
134 unsigned long screen_bitmap;
135 unsigned long cpu_type;
136 struct revectored_struct int_revectored;
137 struct revectored_struct int21_revectored;
138 struct vm86plus_info_struct vm86plus;
139};
140
141#ifdef __KERNEL__
142/*
143 * This is the (kernel) stack-layout when we have done a "SAVE_ALL" from vm86
144 * mode - the main change is that the old segment descriptors aren't
145 * useful any more and are forced to be zero by the kernel (and the
146 * hardware when a trap occurs), and the real segment descriptors are
147 * at the end of the structure. Look at ptrace.h to see the "normal"
148 * setup. For user space layout see 'struct vm86_regs' above.
149 */
Jeremy Fitzhardinge49d26b62006-12-07 02:14:03 +0100150#include <asm/ptrace.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151
152struct kernel_vm86_regs {
153/*
154 * normal regs, with special meaning for the segment descriptors..
155 */
Jeremy Fitzhardinge49d26b62006-12-07 02:14:03 +0100156 struct pt_regs pt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157/*
158 * these are specific to v86 mode:
159 */
160 unsigned short es, __esh;
161 unsigned short ds, __dsh;
162 unsigned short fs, __fsh;
163 unsigned short gs, __gsh;
164};
165
166struct kernel_vm86_struct {
167 struct kernel_vm86_regs regs;
168/*
169 * the below part remains on the kernel stack while we are in VM86 mode.
170 * 'tss.esp0' then contains the address of VM86_TSS_ESP0 below, and when we
171 * get forced back from VM86, the CPU and "SAVE_ALL" will restore the above
172 * 'struct kernel_vm86_regs' with the then actual values.
173 * Therefore, pt_regs in fact points to a complete 'kernel_vm86_struct'
174 * in kernelspace, hence we need not reget the data from userspace.
175 */
176#define VM86_TSS_ESP0 flags
177 unsigned long flags;
178 unsigned long screen_bitmap;
179 unsigned long cpu_type;
180 struct revectored_struct int_revectored;
181 struct revectored_struct int21_revectored;
182 struct vm86plus_info_struct vm86plus;
183 struct pt_regs *regs32; /* here we save the pointer to the old regs */
184/*
185 * The below is not part of the structure, but the stack layout continues
186 * this way. In front of 'return-eip' may be some data, depending on
187 * compilation, so we don't rely on this and save the pointer to 'oldregs'
188 * in 'regs32' above.
189 * However, with GCC-2.7.2 and the current CFLAGS you see exactly this:
190
191 long return-eip; from call to vm86()
192 struct pt_regs oldregs; user space registers as saved by syscall
193 */
194};
195
Matt Mackall64ca9002006-01-08 01:05:26 -0800196#ifdef CONFIG_VM86
197
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198void handle_vm86_fault(struct kernel_vm86_regs *, long);
199int handle_vm86_trap(struct kernel_vm86_regs *, long, int);
Harvey Harrisone04f99c2008-02-04 16:48:04 +0100200struct pt_regs *save_v86_state(struct kernel_vm86_regs *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201
Matt Mackall64ca9002006-01-08 01:05:26 -0800202struct task_struct;
203void release_vm86_irqs(struct task_struct *);
204
205#else
206
207#define handle_vm86_fault(a, b)
208#define release_vm86_irqs(a)
209
Joe Perches9e8a9352008-03-23 01:03:58 -0700210static inline int handle_vm86_trap(struct kernel_vm86_regs *a, long b, int c)
211{
Matt Mackall64ca9002006-01-08 01:05:26 -0800212 return 0;
213}
214
215#endif /* CONFIG_VM86 */
216
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217#endif /* __KERNEL__ */
218
219#endif