home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ddkx86v1.zip / DDKX86 / H / V8086.H < prev    next >
Text File  |  1995-04-14  |  15KB  |  404 lines

  1. /*DDK*************************************************************************/
  2. /*                                                                           */
  3. /* COPYRIGHT    Copyright (C) 1995 IBM Corporation                           */
  4. /*                                                                           */
  5. /*    The following IBM OS/2 WARP source code is provided to you solely for  */
  6. /*    the purpose of assisting you in your development of OS/2 WARP device   */
  7. /*    drivers. You may use this code in accordance with the IBM License      */
  8. /*    Agreement provided in the IBM Device Driver Source Kit for OS/2. This  */
  9. /*    Copyright statement may not be removed.                                */
  10. /*                                                                           */
  11. /*****************************************************************************/
  12. /***    V8086.H
  13.  *
  14.  *      SCCSID = @(#)v8086.h    6.12 92/02/28
  15.  *
  16.  *      Title:
  17.  *
  18.  *      8086 Emulation Export Include File
  19.  *
  20.  *      Description:
  21.  *
  22.  *      Contains the exported structures, defines and VDH
  23.  *      function prototypes for 8086 emulation.
  24.  *
  25.  *      MODIFICATION HISTORY
  26.  *      --------------------
  27.  *      05/07/91 RCW  Changed all occurences of the single line comment
  28.  *                    notation to the standard notation to allow users to
  29.  *                    maintain ANSI compatibility.  This is in response to
  30.  *                    PTR B718526.  All future updates to this and all other
  31.  *                    header files should use the standard commenting format.
  32.  * 73541 10/20/93 ChangeTeam  Added em86Is32Sel.
  33.  * 93273 12 AUG 1994 ChangeTeam Added VDHGetFlags(PULONG);
  34.  */
  35.  
  36.  
  37. /*INT32*/
  38.  
  39. /***ET+ Low memory defines - used by VBIOS */
  40.  
  41. #define IVT_START               0       /* Interrupt vector table start */
  42. #define IVT_LEN                 0x400   /*     "        "     "   length */
  43. /*end*/
  44.  
  45. /***ET+ flVdmStatus flags */
  46.  
  47. #define VDM_STATUS_VPM_32       0x00000001      /* 32 bit DPMI app */
  48. #define VDM_STATUS_VPM_32_BIT   0
  49. #define VDM_STATUS_VPM_APP      0x00000002      /* DPMI app started */
  50. #define VDM_STATUS_VPM_APP_BIT  1
  51. #define VDM_STATUS_VPM_EXEC     0x00000004      /* in VDM protected mode */
  52. #define VDM_STATUS_VPM_EXEC_BIT 2
  53. #define VDM_STATUS_VPM_TRAPMODE 0x00000008      /* V86 mode at kernel entry? */
  54. #define VDM_STATUS_VPM_TRAP_BIT 3
  55. #define VDM_STATUS_VPM_IF_FLAG  0x00000010      /* Virtual IF flag */
  56. #define VDM_STATUS_VPM_IF_BIT   4
  57. #define VDM_STATUS_VPM_08_HOOK  0x00000020      /* protect 08h hooked? */
  58. #define VDM_STATUS_VPM_08_BIT   5
  59. #define VDM_STATUS_VPM_1C_HOOK  0x00000040      /* protect 1Ch hooked? */
  60. #define VDM_STATUS_VPM_1C_BIT   6
  61. #define VDM_STATUS_VPM_PERM     0x00000080      /* protected mode allowed? */
  62. #define VDM_STATUS_VPM_PERM_BIT 7
  63. #define VDM_STATUS_VPM_XDOS     0x00000100      /* DOS API Extension active? */
  64. #define VDM_STATUS_VPM_XDOS_BIT 8
  65. #define VDM_STATUS_VPM_TERM     0x00000200      /* VDM terminating? */
  66. #define VDM_STATUS_VPM_TERM_BIT 9
  67. #define VDM_STATUS_VPM_EM_FLAG  0x00000400      /* Virtual EM flag */
  68. #define VDM_STATUS_VPM_EM_BIT   10
  69. #define VDM_STATUS_VPM_TASK_SW  0x00000800      /* Task switch for HW int */
  70. #define VDM_STATUS_VPM_TASK_BIT 11
  71. #define VDM_STATUS_VME          0x00001000      /* Virt Mode Ext present */
  72. #define VDM_STATUS_VME_BIT      12
  73. /*end*/
  74.  
  75. /***ET+ VDHInstallIntHook options */
  76.  
  77. #define VDH_ASM_HOOK            0x00000001L
  78. /*end*/
  79.  
  80. /***ET+ VDHInstallIOHook options */
  81.  
  82. #define VDHIIH_ASM_HOOK         VDH_ASM_HOOK
  83. #define VDHIIH_ALWAYS_TRAP      0x00000002L
  84. #define VDHIIH_NO_SIMULATE      0x00000004L
  85. #define VDHIIH_IGNORE           0x00000010L
  86. /*end*/
  87.  
  88. /***ET+ VDHSetIOHookState options */
  89.  
  90. #define SETIO_TRAP              TRUE
  91. #define SETIO_NOTRAP            FALSE
  92. /*end*/
  93.  
  94. /***ET+ I/O type flags - VDHInstallIOPort pfnOther handler */
  95.  
  96. #define IO_TYPE_SHIFT           8
  97. #define IO_TYPE_MASK            0x00000F00L
  98. #define IO_TYPE_INPUT           0x00000100L
  99. #define IO_TYPE_OUTPUT          0x00000000L
  100. #define IO_TYPE_STRING          0x00000200L
  101. #define IO_TYPE_BYTE            0x00000400L
  102. #define IO_TYPE_WORD            0x00000000L
  103. #define IO_TYPE_DWORD           0x00000800L
  104.  
  105. #define IO_TYPE_ADDR32          0x00001000L
  106. #define IO_TYPE_REP             0x00002000L
  107. #define IO_TYPE_REVERSE         0x00008000L
  108.  
  109. #define IO_SEG_SHIFT            16
  110. #define IO_SEG_MASK             0x000f0000L
  111. #define IO_SEG_ES               0x00000000L
  112. #define IO_SEG_CS               0x00010000L
  113. #define IO_SEG_SS               0x00020000L
  114. #define IO_SEG_DS               0x00030000L
  115. #define IO_SEG_FS               0x00040000L
  116. #define IO_SEG_GS               0x00050000L
  117. /*end*/
  118.  
  119. /***ET+ VDHCheckPagePerm and private DPMI options */
  120.  
  121. #define VPMPG_W            0x00000002      /* Writable */
  122. #define VPMPG_U            0x00000004      /* user mode accessible */
  123. #define VPMPG_X            0x00000008      /* eXecutable */
  124. #define VPMPG_R            0x00000010      /* Readable */
  125. #define VPMPG_RESERVED     0x00001000      /* Reserved for system use */
  126. /*end*/
  127.  
  128.  
  129. /***ET+ VDHAllocHook options */
  130.  
  131. #define VDH_CONTEXT_HOOK                0
  132. #define VDH_STI_HOOK                    1
  133. #define VDH_RETURN_HOOK                 2
  134. #define VDH_TIMER_HOOK                  3
  135. #define VDH_BP_HOOK                     4
  136. /*end*/
  137.  
  138. /***ET+ VDHArmContextHook options */
  139.  
  140. #define GLOBAL_CONTEXT_HOOK     ((HVDM) -1)
  141. /*end*/
  142.  
  143. /***ET+ VDHArmReturnHook options */
  144.  
  145. #define VDHARH_NORMAL_RET               0
  146. #define VDHARH_NORMAL_IRET              1
  147. #define VDHARH_RECURSIVE_RET            2
  148. #define VDHARH_RECURSIVE_IRET           3
  149. #define VDHARH_CSEIP_HOOK               4
  150. #define VDHARH_RECURSIVE_CSEIP_HOOK     5
  151. #define VDHARH_ALWAYS_ARM_HOOK          0x80000000
  152. /*end*/
  153.  
  154. /***ET+ VDHArmReturnHook recursive user stack usage
  155.  *
  156.  *      VDHARH_RECURSIVE_CSEIP_HOOK stack usage will vary depend
  157.  *      on the VDM protected mode "bitness".   If 32 bit, there
  158.  *      will be 8 bytes on the stack; otherwise, 4 bytes.
  159.  */
  160.  
  161. #define VDHARH_RECURSIVE_STACK_USAGE    4
  162. /*end*/
  163.  
  164. /***ET+ VDHPushFarCall user stack usage */
  165.  
  166. #define VDHPFC_STACK_USAGE              4
  167. /*end*/
  168.  
  169. /***ET+ VDHPushInt user stack usage */
  170.  
  171. #define VDHPI_STACK_USAGE               6
  172. /*end*/
  173.  
  174. /***ET+ VDHPushRegs/VDHPopRegs flags */
  175.  
  176. #define VDHREG_AX               0x00000001L
  177. #define VDHREG_BX               0x00000002L
  178. #define VDHREG_CX               0x00000004L
  179. #define VDHREG_DX               0x00000008L
  180. #define VDHREG_SI               0x00000010L
  181. #define VDHREG_DI               0x00000020L
  182. #define VDHREG_BP               0x00000040L
  183. #define VDHREG_SP               0x00000080L
  184. #define VDHREG_DS               0x00000100L
  185. #define VDHREG_ES               0x00000200L
  186. #define VDHREG_SS               0x00000400L
  187. #define VDHREG_FLAG             0x00000800L
  188. #define VDHREG_EREGS            0x10000000L        /* Push/Pop 32 bit values */
  189. #define VDHREG_ALL              (VDHREG_AX | VDHREG_BX | \
  190.                                  VDHREG_CX | VDHREG_DX | \
  191.                                  VDHREG_SI | VDHREG_DI | \
  192.                                  VDHREG_BP | VDHREG_SP | \
  193.                                  VDHREG_DS | VDHREG_ES | \
  194.                                  VDHREG_SS | VDHREG_FLAG)
  195. #define VDHREG_GENERAL          (VDHREG_AX | VDHREG_BX | \
  196.                                  VDHREG_CX | VDHREG_DX | \
  197.                                  VDHREG_SI | VDHREG_DI | \
  198.                                  VDHREG_BP | VDHREG_DS | \
  199.                                  VDHREG_ES | VDHREG_FLAG)
  200. /*end*/
  201.  
  202. /***ET+ CRF - Client Register Frame
  203.  *
  204.  *      The EBX register points to the CRF structure on entry
  205.  *      to I/O port handlers and VDD interrupt handlers.  VDDs
  206.  *      can retrieve or modify the client's registers with this
  207.  *      interface.
  208.  */
  209.  
  210. typedef struct crf_s {
  211.         ULONG crf_edi;
  212.         ULONG crf_esi;
  213.         ULONG crf_ebp;
  214.         ULONG crf_padesp;
  215.         ULONG crf_ebx;
  216.         ULONG crf_edx;
  217.         ULONG crf_ecx;
  218.         ULONG crf_eax;
  219.         ULONG crf_pad2[2];
  220.         ULONG crf_eip;
  221.         USHORT crf_cs;
  222.         USHORT crf_padcs;
  223.         ULONG crf_eflag;
  224.         ULONG crf_esp;
  225.         USHORT crf_ss;
  226.         USHORT crf_padss;
  227.         USHORT crf_es;
  228.         USHORT crf_pades;
  229.         USHORT crf_ds;
  230.         USHORT crf_padds;
  231.         USHORT crf_fs;
  232.         USHORT crf_padfs;
  233.         USHORT crf_gs;
  234.         USHORT crf_padgs;
  235.         ULONG crf_alteip;               /* other modes register set */
  236.         USHORT crf_altcs;
  237.         USHORT crf_altpadcs;
  238.         ULONG crf_alteflag;
  239.         ULONG crf_altesp;
  240.         USHORT crf_altss;
  241.         USHORT crf_altpadss;
  242.         USHORT crf_altes;
  243.         USHORT crf_altpades;
  244.         USHORT crf_altds;
  245.         USHORT crf_altpadds;
  246.         USHORT crf_altfs;
  247.         USHORT crf_altpadfs;
  248.         USHORT crf_altgs;
  249.         USHORT crf_altpadgs;
  250. } CRF;
  251.  
  252. typedef CRF *PCRF;
  253. /*end*/
  254.  
  255.  
  256. //c-begin
  257. /***ET+ Macros to improve VDM register manipulations from C */
  258.  
  259. #define AX(pcrf)    WORDOF(pcrf->crf_eax,0)
  260. #define AL(pcrf)    BYTEOF(pcrf->crf_eax,0)
  261. #define AH(pcrf)    BYTEOF(pcrf->crf_eax,1)
  262. #define BX(pcrf)    WORDOF(pcrf->crf_ebx,0)
  263. #define BL(pcrf)    BYTEOF(pcrf->crf_ebx,0)
  264. #define BH(pcrf)    BYTEOF(pcrf->crf_ebx,1)
  265. #define CX(pcrf)    WORDOF(pcrf->crf_ecx,0)
  266. #define CL(pcrf)    BYTEOF(pcrf->crf_ecx,0)
  267. #define CH(pcrf)    BYTEOF(pcrf->crf_ecx,1)
  268. #define DX(pcrf)    WORDOF(pcrf->crf_edx,0)
  269. #define DL(pcrf)    BYTEOF(pcrf->crf_edx,0)
  270. #define DH(pcrf)    BYTEOF(pcrf->crf_edx,1)
  271. #define SI(pcrf)    WORDOF(pcrf->crf_esi,0)
  272. #define DI(pcrf)    WORDOF(pcrf->crf_edi,0)
  273. #define BP(pcrf)    WORDOF(pcrf->crf_ebp,0)
  274. #define SP(pcrf)    WORDOF(pcrf->crf_esp,0)
  275. #define CS(pcrf)    WORDOF(pcrf->crf_cs,0)
  276. #define IP(pcrf)    WORDOF(pcrf->crf_eip,0)
  277. #define DS(pcrf)    WORDOF(pcrf->crf_ds,0)
  278. #define ES(pcrf)    WORDOF(pcrf->crf_es,0)
  279. #define SS(pcrf)    WORDOF(pcrf->crf_ss,0)
  280. #define FL(pcrf)    WORDOF(pcrf->crf_eflag,0)
  281.  
  282. /* General purpose macros */
  283.  
  284. #define INT_PIC1BASE    0x08
  285. #define INT_PIC2BASE    0x70
  286. #define INTFROMIRQ(irq) (((irq) < 8)? (irq) + INT_PIC1BASE: \
  287.                                       (irq) - 8 + INT_PIC2BASE)
  288. //c-end
  289.  
  290. /* VDHReadUBuf and VDHWriteUBuf flags */
  291.  
  292. #define VPM_FAULT_IF_RW_SET     0x01
  293. #define VPM_FAULT_IF_SU_SET     0x02
  294. #define VPM_SEL_PRESENT         0x04
  295. #define VPM_SEL_WRITEABLE       0x08
  296. #define VPM_FAULT_IF_RO         0x10
  297. #define VPM_SEL_IS_SS           0x20
  298. #define VPM_PROT_READ           0x40
  299. #define VPM_PROT_WRITE          0x80
  300. #define VPM_XCPTRET_ALT         0x100
  301. #define VPM_NO_SIM_EXCPT        0x200
  302.  
  303. /***ET+ Hook routine typedefs */
  304.  
  305. typedef BYTE HOOKENTRY BIH(ULONG, PCRF);        /* I/O hook routines */
  306. typedef VOID HOOKENTRY BOH(BYTE, ULONG, PCRF);
  307. typedef WORD HOOKENTRY WIH(ULONG, PCRF);
  308. typedef VOID HOOKENTRY WOH(WORD, ULONG, PCRF);
  309. typedef BOOL HOOKENTRY OTH(ULONG, PULONG, ULONG, ULONG, PCRF);
  310.  
  311. typedef BYTE (HOOKENTRY *PBIH)(ULONG, PCRF);    /* pointers to I/O hook routines */
  312. typedef VOID (HOOKENTRY *PBOH)(BYTE, ULONG, PCRF);
  313. typedef WORD (HOOKENTRY *PWIH)(ULONG, PCRF);
  314. typedef VOID (HOOKENTRY *PWOH)(WORD, ULONG, PCRF);
  315. typedef BOOL (HOOKENTRY *POTH)(ULONG, PULONG, ULONG, ULONG, PCRF);
  316.  
  317. typedef BOOL HOOKENTRY FNHOOK(PCRF);            /* hook routine */
  318. typedef BOOL (HOOKENTRY *PFNHOOK)(PCRF);        /* pointer to hook routine */
  319.  
  320. typedef VOID HOOKENTRY FNARM();                 /* arm hook routine */
  321. typedef VOID (HOOKENTRY *PFNARM)();             /* pointer to arm hook routine */
  322.  
  323.  
  324. /***ET+ IOH - I/O Port Hook Entry
  325.  *
  326.  *      This is the structure for the parameter to the VDHInstallIOHook
  327.  *      service.  Only the byte input and output handlers are required.
  328.  *      A null (0) entry indicates that the type of I/O should be
  329.  *      simulated.  The structure passed by VDHInstallIOHook is
  330.  *      copied and saved away after the NULLs are replaced with the
  331.  *      addresses of the simulation routines.
  332.  */
  333.  
  334. typedef struct ioh_s {
  335.         PBIH ioh_pbihByteInput;                 /* byte input handler */
  336.         PBOH ioh_pbohByteOutput;                /* byte output handler */
  337.         PWIH ioh_pwihWordInput;                 /* word input handler */
  338.         PWOH ioh_pwohWordOutput;                /* word output handler */
  339.         POTH ioh_pothOther;                     /* dword and string I/O handler */
  340. } IOH;
  341.  
  342. typedef IOH *PIOH;                              /* pointer to IOH entry */
  343. /*end*/
  344.  
  345.  
  346. /* 8086 emulation VDH services */
  347.  
  348. BOOL VDHENTRY VDHInstallIOHook(HVDM, PORT, ULONG, PIOH, FLAGS);
  349. VOID VDHENTRY VDHRemoveIOHook(HVDM, PORT, ULONG, PIOH);
  350. VOID VDHENTRY VDHSetIOHookState(HVDM, PORT, ULONG, PIOH, BOOL);
  351. BOOL VDHENTRY VDHInstallIntHook(HVDM, ULONG, PFNHOOK, FLAGS);
  352. HHOOK VDHENTRY VDHAllocHook(ULONG, PFNARM, ULONG);
  353. PVOID VDHENTRY VDHQueryHookData(HHOOK);
  354. VOID VDHENTRY VDHFreeHook(HHOOK);
  355. VOID VDHENTRY VDHArmContextHook(HHOOK, HVDM);
  356. VOID VDHENTRY VDHArmSTIHook(HHOOK, HVDM);
  357. BOOL VDHENTRY VDHArmReturnHook(HHOOK, ULONG);
  358. VPVOID VDHENTRY VDHArmBPHook(HHOOK);
  359. BOOL VDHENTRY VDHPushInt(ULONG);
  360. BOOL VDHENTRY VDHPopInt(VOID);
  361. BOOL VDHENTRY VDHPushRegs(FLAGS);
  362. BOOL VDHENTRY VDHPopRegs(FLAGS);
  363. BOOL VDHENTRY VDHPushStack(ULONG,PVOID);
  364. BOOL VDHENTRY VDHPopStack(ULONG,PVOID);
  365. VOID VDHENTRY VDHSetA20(BOOL);
  366. BOOL VDHENTRY VDHQueryA20(VOID);
  367. VOID VDHENTRY VDHSetFlags(ULONG);
  368. VOID VDHENTRY VDHGetFlags(PULONG);
  369. VOID VDHENTRY VDHSwitchToV86(VOID);
  370. VOID VDHENTRY VDHSwitchToVPM(VOID);
  371. BOOL VDHENTRY VDHCheckVPMIntVector(ULONG);
  372. BOOL VDHENTRY VDHCheckVPMExcept(ULONG);
  373. BOOL VDHENTRY VDHGetVPMIntVector(ULONG,PFPFN);
  374. BOOL VDHENTRY VDHGetSelBase(SEL,PULONG);
  375. BOOL VDHENTRY VDHChangeVPMIF(BOOL);
  376. BOOL VDHENTRY VDHReadUBuf(PVOID,ULONG,SEL,PULONG,ULONG);
  377. BOOL VDHENTRY VDHWriteUBuf(PVOID,ULONG,SEL,PULONG,ULONG);
  378. BOOL VDHENTRY VDHCheckPagePerm(ULONG,PVOID,ULONG,ULONG);
  379. BOOL VDHENTRY VDHRaiseException(ULONG,ULONG,ULONG);
  380. BOOL VDHENTRY VDHStartHWInt(BOOL);
  381. BOOL VDHENTRY VDHGetVPMExcept(ULONG,PFPFN,PBYTE);
  382. BOOL VDHENTRY VDHProbeUBuf(SEL,ULONG,ULONG,ULONG);
  383. BOOL VDHENTRY VDHPrepVPMIret(HHOOK);
  384. BOOL VDHENTRY VDHPopVPMFarRet(VOID);
  385. BOOL VDHENTRY VDHRegisterAPI(PSZ, PFNHOOK, PFNHOOK);
  386.  
  387. //c-begin
  388. BOOL VDHENTRY VDHSetVPMIntVector(ULONG, FPFN);
  389. BOOL VDHENTRY VDHSetVPMExcept(ULONG, FPFN, BYTE);
  390. BOOL VDHENTRY VDHPushFarCall(FPFN);
  391. //c-end
  392. //masm-begin
  393. //VDHENTRY VDHSetVPMIntVector   <ULONG, ULONG, ULONG>
  394. //VDHENTRY VDHSetVPMExcept  <ULONG, ULONG, ULONG, BYTE>
  395. //BOOL VDHENTRY VDHPushFarCall(ULONG, ULONG);
  396. //masm-end
  397. FPFN VDHENTRY VDHArmVPMBPHook(HHOOK);
  398. VOID VDHENTRY VDHEndUseVPMStack(VOID);
  399. VOID VDHENTRY VDHBeginUseVPMStack(VOID);
  400. //c-begin
  401. extern ULONG flVdmStatus;
  402. extern BOOL  em86Is32Sel(SEL);                                    //73541
  403. //c-end
  404.