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