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