vm86.h 5.7 KB

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