home *** CD-ROM | disk | FTP | other *** search
/ The Developer Connection…ice Driver Kit for OS/2 3 / DEV3-D1.ISO / source / devnews / vol2 / sample3 / vdft.sav < prev    next >
Encoding:
Text File  |  1993-12-29  |  49.2 KB  |  935 lines

  1. /******************************************************************************/
  2. /*                                                                            */
  3. /*                     IBM Sample Virtual Device Driver                       */
  4. /*                                                                            */
  5. /*                 Copyright (c) IBM Corporation 1993                         */
  6. /*                         All Rights Reserved                                */
  7. /*                                                                            */
  8. /*   DISCLAIMER OF WARRANTIES.  The following [enclosed] code is              */
  9. /*   sample code created by IBM Corporation. This sample code is not          */
  10. /*   part of any standard or IBM product and is provided to you solely        */
  11. /*   for  the purpose of assisting you in the development of your             */
  12. /*   applications.  The code is provided "AS IS", without                     */
  13. /*   warranty of any kind.  IBM shall not be liable for any damages           */
  14. /*   arising out of your use of the sample code, even if they have been       */
  15. /*   advised of the possibility of such damages.                              */
  16. /*                                                                            */
  17. /******************************************************************************/
  18. /************************** START OF SPECIFICATIONS ***************************/
  19. /*                                                                            */
  20. /*   SOURCE FILE NAME:  VDFT.C                                                */
  21. /*                                                                            */
  22. /*   DESCRIPTIVE NAME:  Initialize virtual DFT device driver(VDFT)            */
  23. /*                                                                            */
  24. /*   FUNCTION: These routines comprise the Virtual DFT device driver which    */
  25. /*             supports the 3270 DFT addapter card.                           */
  26. /*                                                                            */
  27. /*   NOTES:    These routines work in conjunction with DFT_DDM.ASM ( the      */
  28. /*             DFT physical device driver.                                    */
  29. /*                                                                            */
  30. /*   RESTRICTIONS: None                                                       */
  31. /*                                                                            */
  32. /*   ENTRY POINTS:                                                            */
  33. /*             VDFTInit - Initialize virtual DFT device driver                */
  34. /*             VDFTPDDProc - VDFT entry point for PDFT                        */
  35. /*             VDFTDaIn - process first IN instruction to DFT                 */
  36. /*             VDFTDaOut- process first OUT instruction to DFT                */
  37. /*             VDFTStIN - process first IN instruction to DFT status register */
  38. /*             VDFTStOUT- process first OUT instruction to DFT status register*/
  39. /*             VDFTCreate - processing to be done at VDM create               */
  40. /*             VDFTTerminate - processing to be done at VDM terminate         */
  41. /*             VDFT_EOI  - handler for EOI instruction by DOS app             */
  42. /*             VDFTPDBChange - process PDB change event                       */
  43. /*             VDFTPDBDestroy - process PDB destroy event                     */
  44. /*                                                                            */
  45. /*   EXTERNAL REFERENCES:                                                     */
  46. /*             VDHInstallUserHook - Install VDM event hook                    */
  47. /*             VDHOpenPDD         - Get PDD entry point                       */
  48. /*             VDHOpenVIRQ        - register an IRQ for VDM                   */
  49. /*             VDHSetIOHookState  - Enable/Disable I/O port                   */
  50. /*                                  trapping                                  */
  51. /*             VDHInstallIOHook   - Install I/O port hooks                    */
  52. /*             VDHRemoveIOHook    - release IO hook                           */
  53. /*             VDHSetVIRR         - start simulating Interrupts               */
  54. /*                                  to the VDM                                */
  55. /*             VDHClearVIRR       - Stop simulating interrupts to             */
  56. /*                                  the VDM                                   */
  57. /*             VDHMapPages        - map physical to linear pages              */
  58. /**************************** END OF SPECIFICATIONS ***************************/
  59.  
  60. #define INCL_VDH
  61. #define NULL 0
  62.  
  63. #include <mvdm.h>                       /* VDH services, etc.        */
  64. #include <basemid.h>                    /* message numbers           */
  65. #include <builtin.h>                    /* builtin functions         */
  66. #include "VDFTP.H"                      /* Local Stuff               */
  67. // #include "common.h"
  68.  
  69. /*                                                                   */
  70. /*                 GLOBAL DATA AREA FOR VDFT                         */
  71. /*                                                                   */
  72.  
  73. HIRQ hirq_DFT = 0;                      /* holds handle for EOI hook */
  74.  
  75. HVDM HVDM_Owner = 0;                    /* hvdm of owner             */
  76. INT   Status_byte;                      /* Status Register value     */
  77.  
  78. BOOL  interruptsnotenabled = TRUE;      /* T = interrupts not enabled in DD    */
  79. BOOL  wait_for_EOI = FALSE;             /* T = EOI not done yet                */
  80. BOOL  wait_for_status_out = FALSE;      /* T = out to status port not done yet */
  81.  
  82. #pragma data_seg(CSWAP_DATA)
  83.  
  84. VDFTPDB PDB_Owner = 0;
  85.  
  86. FPFNPDD PDFTPDDProc = (FPFNPDD) 0;      /* addr of PDD service rtn  */
  87.  
  88. struct VDHMapSource_s MapSource = {     /* vdhms                    */
  89.                      0XCE000,           /* linear address to map    */
  90.                      0};                /* hvdms_hobj               */
  91.  
  92. struct VDHMapTarget_s MapTarget = {     /* vdhmt                    */
  93.                      0XCE000,           /* linear buffer address    */
  94.                      2,                 /* number of pages          */
  95.                      0                  /* handle                   */
  96.                      };
  97.  
  98. struct ioh_s htable = {
  99.                        VDFTDaIn,        /* byte input handler  */
  100.                        VDFTDaOut,       /* byte output handlr  */
  101.                        NULL,            /* word input handler  */
  102.                        NULL,            /* word output handlr  */
  103.                        NULL             /* dword & string I/O  */
  104.                        };               /* handler             */
  105.  
  106. struct ioh_s htable_st = {
  107.                        VDFTStIn,        /* byte input handler  */
  108.                        VDFTStOut,       /* byte output handlr  */
  109.                        NULL,            /* word input handler  */
  110.                        NULL,            /* word output handlr  */
  111.                        NULL             /* dword & string I/O  */
  112.                        };               /* handler             */
  113.  
  114. #pragma data_seg()
  115.  
  116. #pragma data_seg(SWAPINSTDATA)
  117.  
  118. HVDM  HVDM_Current;                     /* Current VDM handle  */
  119. VDFTPDB PDB_Current;                    /* Current PDB         */
  120.  
  121. #pragma data_seg()
  122.  
  123. #pragma data_seg(CINIT_DATA)
  124.  
  125. char szPDDName[]=DFT_NAME;
  126.  
  127. #pragma data_seg()
  128.  
  129. #pragma alloc_text(CSWAP_TEXT, VDFTDaIn, VDFTStIn, VDFTDaOut)
  130.  
  131. BOOL OS2Service(ULONG ulCommand,SGID sgid,ULONG ulCountBuffer);
  132. /********************** START OF SPECIFICATIONS ***********************/
  133. /*                                                                    */
  134. /* SUBROUTINE NAME:  VDFTDaIn                                         */
  135. /*                                                                    */
  136. /* DESCRIPTIVE NAME:  DFT Data Port In Instruction Handler            */
  137. /*                                                                    */
  138. /* FUNCTION:  The function of this routine is to service the VDM      */
  139. /*            IN instruction for DFT if the IN to the data port       */
  140. /*            is the first occurrence of I/O. If it is not the        */
  141. /*            first occurrence then the hook for this port will       */
  142. /*            have been disabled. This routine requests I/O direct    */
  143. /*            mode and if successful does the IN instruction.         */
  144. /*                                                                    */
  145. /* NOTES:  VDFTDaIn handles byte instructions only.                   */
  146. /*                                                                    */
  147. /* CONTEXT: VDM task time                                             */
  148. /*                                                                    */
  149. /* ENTRY POINT:  VDFTDaIn                                             */
  150. /*    LINKAGE:   CALL NEAR 32                                          */
  151. /*                                                                    */
  152. /* INPUT:  (PARAMETERS)  (passed on the stack)                        */
  153. /*         portaddr -    port address                                 */
  154. /*         pcrf     -    client register frame pointer                */
  155. /*                                                                    */
  156. /* EXIT-NORMAL:  returns byte of data from data port for DFT1         */
  157. /*                                                                    */
  158. /* EXIT-ERROR:  NONE                                                  */
  159. /*                                                                    */
  160. /* EFFECTS:  NONE                                                     */
  161. /*                                                                    */
  162. /* INTERNAL REFERENCES:  RequestDirect                                */
  163. /*                                                                    */
  164. /* EXTERNAL REFERENCES:  VDHSetIOHookState - Enable/Disable I/O port  */
  165. /*                                           trapping                 */
  166. /*                                                                    */
  167. /************************ END OF SPECIFICATIONS ***********************/
  168. BYTE HOOKENTRY VDFTDaIn(ULONG portaddr, PCRF pcrf)
  169. {
  170.  
  171.     BYTE dataread=0;                   /* set up byte to return      */
  172.  
  173. #ifdef DEBUG
  174.      _interrupt(3);
  175. #endif
  176.  
  177.     /*---------------------------------------------------------------*/
  178.     /*- Call to set up direct access mode for the port address      -*/
  179.     /*- passed in.                                                  -*/
  180.     /* If current requestor is not current owner, deny access        */
  181.     /*---------------------------------------------------------------*/
  182.  
  183.         if (RequestDirect())
  184.         {
  185.  
  186.       /*-------------------------------------------------------------*/
  187.       /* For performance, we want the DOS app to be able to directly */
  188.       /* access the port from here on.  Therefore, we will unhook    */
  189.       /* the ports.                                                  */
  190.       /*-------------------------------------------------------------*/
  191.  
  192.             VDHSetIOHookState(HVDM_Current,FirstReg,numPorts,&htable,(BOOL)FALSE);
  193.  
  194.     /*---------------------------------------------------------------*/
  195.     /*- Now do an IN to satisfy the application that caused         -*/
  196.     /*-  this routine to be executed.                               -*/
  197.     /*---------------------------------------------------------------*/
  198.  
  199.             dataread = __inpb(portaddr);
  200.         }
  201.  
  202.         return(dataread);              /* return data read           */
  203. }
  204.  
  205.  
  206. /********************** START OF SPECIFICATIONS ***********************/
  207. /*                                                                    */
  208. /* SUBROUTINE NAME:  VDFTStIn                                         */
  209. /*                                                                    */
  210. /* DESCRIPTIVE NAME:  DFT Status Port In Instruction Handler          */
  211. /*                                                                    */
  212. /* FUNCTION:  The function of this routine is to service the VDM      */
  213. /*            IN instruction for DFT if the IN to the status port     */
  214. /*            is the first occurrence of I/O. If it is not the        */
  215. /*            first occurrence then the hook for this port will       */
  216. /*            have been disabled. This routine requests I/O direct    */
  217. /*            mode and if successful does the IN instruction.         */
  218. /*                                                                    */
  219. /* NOTES:  VDFTStIn handles byte instructions only.                   */
  220. /*                                                                    */
  221. /* CONTEXT: VDM task time                                             */
  222. /*                                                                    */
  223. /* ENTRY POINT:  VDFTStIn                                             */
  224. /*    LINKAGE:  CALL NEAR 32                                          */
  225. /*                                                                    */
  226. /* INPUT:  (PARAMETERS)  (passed on the stack)                        */
  227. /*         portaddr -    port address                                 */
  228. /*         pcrf     -    client register frame pointer                */
  229. /*                                                                    */
  230. /* EXIT-NORMAL:  returns byte of data from status port for DFT        */
  231. /*                                                                    */
  232. /* EXIT-ERROR:  NONE                                                  */
  233. /*                                                                    */
  234. /* EFFECTS:  NONE                                                     */
  235. /*                                                                    */
  236. /* INTERNAL REFERENCES:  RequestDirect                                */
  237. /*                                                                    */
  238. /* EXTERNAL REFERENCES:  NONE                                         */
  239. /*                                                                    */
  240. /************************ END OF SPECIFICATIONS ***********************/
  241. BYTE HOOKENTRY VDFTStIn( ULONG portaddr, PCRF pcrf )
  242. {
  243.     BYTE dataread=0;                   /* set up byte to return      */
  244.  
  245. #ifdef DEBUG
  246.      _interrupt(3);
  247. #endif
  248.  
  249.     /*---------------------------------------------------------------*/
  250.     /*- Call to set up direct access mode for the port address      -*/
  251.     /*- passed in.                                                  -*/
  252.     /* If current requestor is not current owner, deny access        */
  253.     /*---------------------------------------------------------------*/
  254.  
  255.         if (RequestDirect())
  256.         {
  257.     /*---------------------------------------------------------------*/
  258.     /*- Now do an IN to satisfy the application that caused         -*/
  259.     /*-  this routine to be executed.                               -*/
  260.     /*---------------------------------------------------------------*/
  261.  
  262.             if (wait_for_status_out)
  263.                 dataread = Status_byte;
  264.             else
  265.                 dataread = __inpb(portaddr);
  266.  
  267.         }
  268.  
  269.         return(dataread);              /* return data read           */
  270. }
  271.  
  272. /********************** START OF SPECIFICATIONS ***********************/
  273. /*                                                                    */
  274. /* SUBROUTINE NAME:  VDFTDaOut                                        */
  275. /*                                                                    */
  276. /* DESCRIPTIVE NAME:  DFT Data Port OUT Instruction Handler           */
  277. /*                                                                    */
  278. /* FUNCTION:  The function of this routine is to service the VDM      */
  279. /*            OUT instruction for DFT if the OUT to the data port     */
  280. /*            is the first occurrence of I/O. If it is not the        */
  281. /*            first occurrence then the hook for this port will       */
  282. /*            have been disabled. This routine requests I/O direct    */
  283. /*            mode and if successful does the OUT instruction.        */
  284. /*                                                                    */
  285. /* NOTES:  VDFTDaOut currently handles byte instructions only.        */
  286. /*                                                                    */
  287. /* CONTEXT: VDM task time                                             */
  288. /*                                                                    */
  289. /* ENTRY POINT:  VDFTDaOut                                            */
  290. /*    LINKAGE:  CALL NEAR 32                                          */
  291. /*                                                                    */
  292. /* INPUT:  (PARAMETERS)  (passed on the stack)                        */
  293. /*         chartowrite - data to write                                */
  294. /*         portaddr    - port address                                 */
  295. /*         pcrf        - client register frame pointer                */
  296. /*                                                                    */
  297. /* EXIT-NORMAL:  NONE                                                 */
  298. /*                                                                    */
  299. /* EXIT-ERROR:  NONE                                                  */
  300. /*                                                                    */
  301. /* EFFECTS:  NONE                                                     */
  302. /*                                                                    */
  303. /* INTERNAL REFERENCES: RequestDirect                                 */
  304. /*                                                                    */
  305. /* EXTERNAL REFERENCES:  VDHSetIOHookState - Enable/Disable I/O port  */
  306. /*                                           trapping                 */
  307. /*                                                                    */
  308. /************************ END OF SPECIFICATIONS ***********************/
  309. VOID HOOKENTRY VDFTDaOut(BYTE chartowrite, ULONG portaddr, PCRF pcrf)
  310. {
  311.  
  312. #ifdef DEBUG
  313.   _interrupt(3);
  314. #endif
  315.  
  316.     /*---------------------------------------------------------------*/
  317.     /* Request direct access mode for this VDM.                      */
  318.     /*---------------------------------------------------------------*/
  319.  
  320.        if (RequestDirect())
  321.        {
  322.  
  323.       /*-------------------------------------------------------------*/
  324.       /* For performance, we want the DOS app to be able to directly */
  325.       /* access the port from here on.  Therefore, we will unhook    */
  326.       /* the port.                                                   */
  327.       /*-------------------------------------------------------------*/
  328.  
  329.            VDHSetIOHookState(HVDM_Current,FirstReg,numPorts,&htable,(BOOL)FALSE);
  330.  
  331.     /*---------------------------------------------------------------*/
  332.     /* Now do an OUT to satisfy the application that caused this int.*/
  333.     /*---------------------------------------------------------------*/
  334.  
  335.            __outpb(portaddr,chartowrite);
  336.  
  337.        }
  338.        return;
  339.  
  340. }
  341.  
  342. #pragma alloc_text(CSWAP_TEXT, VDFTStOut, VDFTFaultHandler, VDFTCreate)
  343.  
  344. /***************************START OF SPECIFICATIONS ***********************/
  345. /*                                                                        */
  346. /* SUBROUTINE NAME: VDFTStOut                                             */
  347. /*                                                                        */
  348. /*DESCRIPTIVE NAME: DFT Status Port OUT Instruction Handler               */
  349. /*                                                                        */
  350. /* FUNCTION:  The function of this routine is to service the VDM OUT      */
  351. /*            instruction for DFT if the OUT to the status port is the    */
  352. /*            first I/O.  If it is not the first occurrence, then         */
  353. /*            the hook for this port will have been disabled.  This       */
  354. /*            routine requests I/O direct mode and if successful, does    */
  355. /*            the OUT instruction.                                        */
  356. /*                                                                        */
  357. /* CONTEXT:  VDM task time                                                */
  358. /*                                                                        */
  359. /* ENTRY POINT: VDFTStOut                                                 */
  360. /*       LINKAGE:   CALL NEAR 32                                          */
  361. /*                                                                        */
  362. /*  INPUT: (PARAMETERS)   (passed on the stack)                           */
  363. /*               portaddr    -    port address                            */
  364. /*               pcrf            -    client register frame pointer       */
  365. /* EXIT-NORMAL:  return byte of data from status port for DFT             */
  366. /*                                                                        */
  367. /* EXIT-ERROR:    NONE                                                    */
  368. /*                                                                        */
  369. /* EFFECTS:          NONE                                                 */
  370. /*                                                                        */
  371. /* INTERNAL REFERENCES: RequestDirect                                     */
  372. /*                                                                        */
  373. /* EXTERNAL REFERENCES:  NONE                                             */
  374. /*                                                                        */
  375. /************************ END OF SPECIFICATIONS ***************************/
  376. VOID HOOKENTRY VDFTStOut(BYTE chartowrite, ULONG portaddr, PCRF pcrf)
  377. {
  378.  
  379. #ifdef DEBUG
  380.    _interrupt(3);
  381. #endif
  382.  
  383.     /*---------------------------------------------------------------*/
  384.     /* Request direct access mode for this VDM.                      */
  385.     /*---------------------------------------------------------------*/
  386.  
  387.        if (RequestDirect())
  388.            {
  389.     /*---------------------------------------------------------------*/
  390.     /* Do an OUT to satisfy the application.                         */
  391.     /*---------------------------------------------------------------*/
  392.            if (wait_for_status_out)
  393.                wait_for_status_out = FALSE;
  394.            else
  395.                __outpb(portaddr,chartowrite);
  396.  
  397.            DISABLE();
  398.            if ((interruptsnotenabled) && (wait_for_status_out==wait_for_EOI))
  399.                EnableInterrupts();
  400.            ENABLE();
  401.  
  402.            }
  403.  
  404.        return;
  405.  
  406. }
  407.  
  408. /***************************START OF SPECIFICATIONS ***********************/
  409. /*                                                                        */
  410. /* SUBROUTINE NAME: VDFTFaultHandler                                      */
  411. /*                                                                        */
  412. /*DESCRIPTIVE NAME: DFT routine called at page fault       handler entry  */
  413. /*                  point                                                 */
  414. /*                                                                        */
  415. /* FUNCTION:  The function of this routine is to service the page         */
  416. /*            fault handler entry point.  This routine tries to get       */
  417. /*            access to the adapter mapped into this VDM.                 */
  418. /*                                                                        */
  419. /* CONTEXT:  VDM task time                                                */
  420. /*                                                                        */
  421. /* ENTRY POINT: VDFTFaultHandler                                          */
  422. /*        LINKAGE:   CALL NEAR 32                                         */
  423. /*                                                                        */
  424. /*  INPUT: (PARAMETERS)   (passed on the stack)                           */
  425. /*              ULONG pvdm                                                */
  426. /*                                                                        */
  427. /* EXIT-NORMAL:                                                           */
  428. /*                                                                        */
  429. /* EXIT-ERROR:                                                            */
  430. /*                                                                        */
  431. /* EFFECTS:          NONE                                                 */
  432. /*                                                                        */
  433. /* INTERNAL REFERENCES:                                                   */
  434. /*                                                                        */
  435. /* EXTERNAL REFERENCES:   NONE                                            */
  436. /*                                                                        */
  437. /*************************************************************************/
  438.  
  439. VOID HOOKENTRY VDFTFaultHandler(PVDM pvdm)
  440. {
  441.  
  442. #ifdef  DEBUG
  443.            _interrupt(3);
  444. #endif
  445.  
  446.   RequestDirect();
  447.  
  448. }
  449.  
  450. /***************************START OF SPECIFICATIONS ***********************/
  451. /*                                                                        */
  452. /* SUBROUTINE NAME: VDFTCreate                                            */
  453. /*                                                                        */
  454. /* DESCRIPTIVE NAME: DFT routine called at VDM creation                   */
  455. /*                                                                        */
  456. /* FUNCTION:  The function of this routine is to service the creation of  */
  457. /*            a new VDM. I/O hooks will be installed for the DFT port.    */
  458. /*                                                                        */
  459. /* CONTEXT:  VDM task time                                                */
  460. /*                                                                        */
  461. /* ENTRY POINT: VDFTCreate                                                */
  462. /*        LINKAGE:   CALL NEAR 32                                         */
  463. /*                                                                        */
  464. /*  INPUT: (PARAMETERS)   (passed on the stack)                           */
  465. /*          hvdm   - handle of current VDM                                */
  466. /*                                                                        */
  467. /* EXIT-NORMAL:                                                           */
  468. /*                                                                        */
  469. /* EXIT-ERROR:    NONE                                                    */
  470. /*                                                                        */
  471. /* EFFECTS:          NONE                                                 */
  472. /*                                                                        */
  473. /* INTERNAL REFERENCES:                                                   */
  474. /*                                                                        */
  475. /* EXTERNAL REFERENCES:   VDHInstallIOHook - Install I/O port hooks       */
  476. /*                        VDHMapPages - map physical to linear pages      */
  477. /*                                                                        */
  478. /**************************************************************************/
  479.  
  480. BOOL HOOKENTRY VDFTCreate(HVDM hvdm)
  481. {
  482. #ifdef  DEBUG
  483.            _interrupt(3);
  484. #endif
  485.  
  486.     /*---------------------------------------------------------------*/
  487.     /* Set up per VDM instance data.                                 */
  488.     /*---------------------------------------------------------------*/
  489.         HVDM_Current = hvdm;
  490.  
  491.     /*---------------------------------------------------------------*/
  492.     /* Set a fault hook handler for adapter space                    */
  493.     /*---------------------------------------------------------------*/
  494.         if ( (VDHInstallFaultHook(hvdm,
  495.                      (PVOID)0XCE000,     /* linear buffer address    */
  496.                      2,                  /* number of pages          */
  497.                      VDFTFaultHandler,
  498.                      FALSE)) == FALSE)
  499.             return FALSE;
  500.  
  501.     /*---------------------------------------------------------------*/
  502.     /* Hook the 3270 DFT status port for IN/OUT instructions.        */
  503.     /* if the hook is unsuccessful, terminate the VDM.               */
  504.     /* NOTE: this hook is never disabled.                            */
  505.     /*---------------------------------------------------------------*/
  506.  
  507.         if ( VDHInstallIOHook(HVDM_Current,StatusReg,numstat,
  508.                               &htable_st,VDHIIH_ALWAYS_TRAP) == FALSE)
  509.             return FALSE;
  510.  
  511.     /*---------------------------------------------------------------*/
  512.     /* Hook all 3270 DFT ports for IN/OUT instructions.        */
  513.     /* if the hook is unsuccessful, terminate the VDM.               */
  514.     /* NOTE: these hooks are released on gaining direct access.      */
  515.     /*---------------------------------------------------------------*/
  516.  
  517.         if (VDHInstallIOHook(HVDM_Current,FirstReg,numPorts,
  518.                              &htable,0) == FALSE)
  519.             return FALSE;
  520.  
  521.         return  TRUE;
  522.  }
  523.  
  524. #pragma alloc_text(CSWAP_TEXT, VDFTTerminate, VDFTPDBChange, VDFTPDBDestroy)
  525.                                                                                            #pragma alloc_text(CSWAP_TEXT, VDFTStOut, VDFTFaultHandler, VDFTCreate)
  526. /***************************START OF SPECIFICATIONS ***********************/
  527. /*                                                                        */
  528. /* SUBROUTINE NAME: VDFTTerminate                                         */
  529. /*                                                                        */
  530. /* DESCRIPTIVE NAME: DFT routine called at VDM termination                */
  531. /*                                                                        */
  532. /* FUNCTION:  The function of this routine is to service the VDM          */
  533. /*            termination.  If the current VDM is the owner of the DFT    */
  534. /*            port, clear the exclusive flag and saved hvdm of current.   */
  535. /*                                                                        */
  536. /* CONTEXT:  VDM task time                                                */
  537. /*                                                                        */
  538. /* ENTRY POINT: VDFTTerminate                                             */
  539. /*        LINKAGE:   CALL NEAR 32                                         */
  540. /*                                                                        */
  541. /*  INPUT: (PARAMETERS)   (passed on the stack)                           */
  542. /*          hvdm   - handle of current VDM                                */
  543. /*                                                                        */
  544. /* EXIT-NORMAL:                                                           */
  545. /*                                                                        */
  546. /* EXIT-ERROR:    NONE                                                    */
  547. /*                                                                        */
  548. /* EFFECTS:          NONE                                                 */
  549. /*                                                                        */
  550. /* INTERNAL REFERENCES:                                                   */
  551. /*                                                                        */
  552. /* EXTERNAL REFERENCES:   VDHRemoveIOHook - release IO hook               */
  553. /*                                                                        */
  554. /**************************************************************************/
  555.  
  556. BOOL HOOKENTRY VDFTTerminate(HVDM hvdm)
  557. {
  558. #ifdef  DEBUG
  559.            _interrupt(3);
  560. #endif
  561.  
  562.     /*---------------------------------------------------------------*/
  563.     /* Indicate no owner of the ports.                               */
  564.     /*---------------------------------------------------------------*/
  565.  
  566.         if (HVDM_Owner == hvdm)
  567.         {
  568.            HVDM_Owner = (HVDM) FALSE;
  569.            if (! interruptsnotenabled)
  570.                DisableInterrupts();
  571.            wait_for_status_out = FALSE;
  572.            wait_for_EOI = FALSE;
  573.            Status_byte = 0;
  574.         }
  575.  
  576.     /*---------------------------------------------------------------*/
  577.     /* Undo all IO hooks.                                            */
  578.     /*---------------------------------------------------------------*/
  579.  
  580.         VDHRemoveIOHook(HVDM_Current,FirstReg,numPorts,&htable);
  581.         VDHRemoveIOHook(HVDM_Current,StatusReg,numstat,&htable_st);
  582.  
  583.     /*---------------------------------------------------------------*/
  584.     /* Unmap the adapter space in this VDM                           */
  585.     /*---------------------------------------------------------------*/
  586.  
  587.         VDHMapPages(&MapSource,&MapTarget,VDHMT_INVALID);
  588.  
  589.     /*---------------------------------------------------------------*/
  590.     /* Remove the fault hook handler for adapter space               */
  591.     /*---------------------------------------------------------------*/
  592.         VDHRemoveFaultHook(HVDM_Current, (PVOID)0XCE000, 2, VDFTFaultHandler);
  593.  
  594.         return TRUE;
  595.  
  596.  }
  597. /***************************START OF SPECIFICATIONS ***********************/
  598. /*                                                                        */
  599. /* SUBROUTINE NAME: VDFTPDBChange                                         */
  600. /*                                                                        */
  601. /* DESCRIPTIVE NAME: DFT routine called to register a PDB change handler  */
  602. /*                  entry point                                           */
  603. /*                                                                        */
  604. /* FUNCTION:  The function of this routine to register a PDB change       */
  605. /*            handler entry point                                         */
  606. /*                                                                        */
  607. /* CONTEXT:  VDM task time                                                */
  608. /*                                                                        */
  609. /* ENTRY POINT: VDFTPDBChange                                             */
  610. /*        LINKAGE:   CALL NEAR 32                                         */
  611. /*                                                                        */
  612. /*  INPUT: (PARAMETERS)   (passed on the stack)                           */
  613. /*             HVDM hvdm                                                  */
  614. /*             VLPTPDB segPDB                                             */
  615. /*                                                                        */
  616. /* EXIT-NORMAL:  return TRUE                                              */
  617. /*                                                                        */
  618. /* EXIT-ERROR:   return FALSE                                             */
  619. /*                                                                        */
  620. /* EFFECTS:          NONE                                                 */
  621. /*                                                                        */
  622. /* INTERNAL REFERENCES:                                                   */
  623. /*                                                                        */
  624. /* EXTERNAL REFERENCES:   NONE                                            */
  625. /*                                                                        */
  626. /**************************************************************************/
  627.  
  628. BOOL HOOKENTRY VDFTPDBChange(HVDM hvdm, VDFTPDB segPDB)
  629. {
  630. #ifdef  DEBUG
  631.            _interrupt(3);
  632. #endif
  633.  
  634.         PDB_Current = segPDB;
  635.  
  636.         return  TRUE;
  637.  }
  638. /***************************START OF SPECIFICATIONS ***********************/
  639. /*                                                                        */
  640. /* SUBROUTINE NAME: VDFTPDBDestroy                                        */
  641. /*                                                                        */
  642. /* DESCRIPTIVE NAME: DFT routine called at PDB destruction  handler entry */
  643. /*                  point                                                 */
  644. /*                                                                        */
  645. /* FUNCTION:  The function of this routine is to service the PDB          */
  646. /*            destruction handler entry point.  If the PDB has been       */
  647. /*            destroyed, and the current PDB was the owner of the DFT     */
  648. /*            port, clear the exclusive use flag and saved PDB address.   */
  649. /*                                                                        */
  650. /* CONTEXT:  VDM task time                                                */
  651. /*                                                                        */
  652. /* ENTRY POINT: VDFTPDBDestroy                                            */
  653. /*        LINKAGE:   CALL NEAR 32                                         */
  654. /*                                                                        */
  655. /*  INPUT: (PARAMETERS)   (passed on the stack)                           */
  656. /*                                                                        */
  657. /*             HVDM hvdm                                                  */
  658. /*             SEG segPDB                                                 */
  659. /* EXIT-NORMAL:   return TRUE                                             */
  660. /*                                                                        */
  661. /* EXIT-ERROR:    return FALSE                                            */
  662. /*                                                                        */
  663. /* EFFECTS:          NONE                                                 */
  664. /*                                                                        */
  665. /* INTERNAL REFERENCES:                                                   */
  666. /*                                                                        */
  667. /* EXTERNAL REFERENCES:   NONE                                            */
  668. /*                                                                        */
  669. /*************************************************************************/
  670.  
  671. BOOL HOOKENTRY VDFTPDBDestroy(HVDM hvdm, VDFTPDB segPDB)
  672. {
  673. #ifdef  DEBUG
  674.            _interrupt(3);
  675. #endif
  676.  
  677.     /*---------------------------------------------------------------*/
  678.     /* Indicate no owner of the ports.                               */
  679.     /*---------------------------------------------------------------*/
  680.  
  681.         if ((HVDM_Owner == hvdm) && (PDB_Owner == segPDB))
  682.         {
  683.            HVDM_Owner = (HVDM) FALSE;
  684.            PDB_Owner = FALSE;
  685.            if (! interruptsnotenabled)
  686.                DisableInterrupts();
  687.            wait_for_status_out = FALSE;
  688.            wait_for_EOI = FALSE;
  689.            Status_byte = 0;
  690.  
  691.     /*---------------------------------------------------------------*/
  692.     /* Unmap the adapter space in this VDM                           */
  693.     /*---------------------------------------------------------------*/
  694.            VDHMapPages(&MapSource,&MapTarget,VDHMT_INVALID);
  695.  
  696.         }
  697.  
  698.         return TRUE;
  699. }
  700.  
  701. #pragma alloc_text(CSWAP_TEXT, RequestDirect, VDFT_EOI, EnableInterrupts, DisableInterrupts)
  702.  
  703. /***************************START OF SPECIFICATIONS ***********************/
  704. /*                                                                        */
  705. /* SUBROUTINE NAME: RequestDirect                                         */
  706. /*                                                                        */
  707. /* DESCRIPTIVE NAME: Internal routine which will determine if the         */
  708. /*                  current requestor is the current owner of the port.   */
  709. /*                                                                        */
  710. /* FUNCTION:  The function of this routine is to service the IN/OUT trap. */
  711. /*            On the first I/O to the port, the current owner of the      */
  712. /*            port is determined.  If it is not the current requestor,    */
  713. /*            the current requestor will be denied.  In the case of a     */
  714. /*            VDM, the VDM will be terminated.                            */
  715. /*                                                                        */
  716. /* CONTEXT:  VDM task time                                                */
  717. /*                                                                        */
  718. /* ENTRY POINT: RequestDirect                                             */
  719. /*        LINKAGE:   CALL NEAR 32                                         */
  720. /*                                                                        */
  721. /*  INPUT: (PARAMETERS)   (passed on the stack)                           */
  722. /*                                                                        */
  723. /* EXIT-NORMAL: TRUE  if the current requestor is made the current owner. */
  724. /*                                                                        */
  725. /* EXIT-ERROR:  FALSE if the current requestor is denied access.          */
  726. /*                                                                        */
  727. /* EFFECTS:          NONE                                                 */
  728. /*                                                                        */
  729. /* INTERNAL REFERENCES:                                                   */
  730. /*                                                                        */
  731. /* EXTERNAL REFERENCES:   NONE                                            */
  732. /*                                                                        */
  733. /*************************************************************************/
  734.  
  735. BOOL PRIVENTRY RequestDirect()
  736. {
  737.  
  738. int resp_val;
  739.  
  740. #ifdef  DEBUG
  741.            _interrupt(3);
  742. #endif
  743.  
  744.         if (HVDM_Owner == HVDM_Current)
  745.            return TRUE;
  746.  
  747.         if (HVDM_Owner)
  748.         {
  749.         // Do the conflict popup
  750.  
  751.            VDHPopup(
  752.                   (PSZZ)NULL,
  753.                   (ULONG)NULL,
  754.                   (ULONG)MSG_VLPT_DEVICE_BUSY,
  755.                   (PULONG)SSToDS(&resp_val),
  756.                   (ULONG)(ABORT|IGNORE),
  757.                   (PSZ)NULL);
  758.  
  759.            if (resp_val == ABORT)
  760.               VDHKillVDM(HVDM_Current);
  761.  
  762.            return FALSE;
  763.         }
  764.  
  765.         // map adapter space into this VDM
  766.         VDHMapPages(&MapSource,&MapTarget,VDHMT_PHYSICAL);
  767.  
  768.         HVDM_Owner = HVDM_Current;
  769.         PDB_Owner = PDB_Current;
  770.         Status_byte = 0;
  771.         wait_for_status_out = FALSE;
  772.         wait_for_EOI = FALSE;
  773.         EnableInterrupts();
  774.         return TRUE;
  775.  
  776.  }
  777.  
  778.  
  779. /***************************START OF SPECIFICATIONS ***********************/
  780. /*                                                                        */
  781. /* SUBROUTINE NAME: VDFT_EOI                                              */
  782. /*                                                                        */
  783. /* DESCRIPTIVE NAME: Routine to service the EOI.                          */
  784. /*                                                                        */
  785. /*                                                                        */
  786. /* FUNCTION:  The function of this routine is to service the EOIs         */
  787. /*            issued by the DOS ISR to the 3270 DFT port.                 */
  788. /*            Since the PDD issued the EOI before notifying the VDD of    */
  789. /*            interrupt, we simply ignore the EOI and discontinue         */
  790. /*            sending the virtual interrupt.                              */
  791. /*                                                                        */
  792. /* CONTEXT:  VDM task time                                                */
  793. /*                                                                        */
  794. /* ENTRY POINT: VDFT_EOI                                                  */
  795. /*        LINKAGE:   CALL NEAR 32                                         */
  796. /*                                                                        */
  797. /*  INPUT: (PARAMETERS)   (passed on the stack)                           */
  798. /*          pcrf:  pointer to the client register frame                   */
  799. /*                                                                        */
  800. /* EXIT-NORMAL:   NONE                                                    */
  801. /*                                                                        */
  802. /* EXIT-ERROR:    NONE                                                    */
  803. /*                                                                        */
  804. /* EFFECTS:          NONE                                                 */
  805. /*                                                                        */
  806. /* INTERNAL REFERENCES:                                                   */
  807. /*                                                                        */
  808. /* EXTERNAL REFERENCES:   VDHClearVIRR - Stop simulating interrupts to    */
  809. /*                                       the VDM                          */
  810. /*                                                                        */
  811. /**************************************************************************/
  812.  
  813. VOID HOOKENTRY VDFT_EOI(PCRF pcrf)
  814. {
  815. #ifdef  DEBUG
  816.            _interrupt(3);
  817. #endif
  818.  
  819.     /*---------------------------------------------------------------*/
  820.     /* Quit sending the virtual interrupts to the VDM.               */
  821.     /*---------------------------------------------------------------*/
  822.         VDHClearVIRR(HVDM_Owner,hirq_DFT);
  823.  
  824.     /*---------------------------------------------------------------*/
  825.     /* If EOI = status out,  start interrupts again                  */
  826.     /*---------------------------------------------------------------*/
  827.         wait_for_EOI = FALSE;
  828.         DISABLE();
  829.         if ((interruptsnotenabled) && (wait_for_EOI==wait_for_status_out))
  830.            EnableInterrupts();
  831.         ENABLE();
  832.  
  833.         return;
  834.  }
  835.  
  836.  
  837. BOOL PRIVENTRY EnableInterrupts()
  838. {
  839.  
  840. #ifdef  DEBUG
  841.            _interrupt(3);
  842. #endif
  843.  
  844.         interruptsnotenabled = FALSE;
  845.         PDFTPDDProc (ENABLE_INTS,0,0);
  846.  
  847.         return TRUE;
  848.  
  849.  }
  850.  
  851.  
  852.  
  853. BOOL PRIVENTRY DisableInterrupts()
  854. {
  855.  
  856. #ifdef  DEBUG
  857.            _interrupt(3);
  858. #endif
  859.  
  860.         interruptsnotenabled = TRUE;
  861.         PDFTPDDProc (DISABLE_INTS,0,0);
  862.  
  863.         return TRUE;
  864.  
  865.  }
  866.  
  867. #pragma alloc_text(CINIT_TEXT, Start_Here)
  868. //#pragma alloc_text(CINIT_TEXT, VDDInit)
  869.  
  870. /********************** START OF SPECIFICATIONS ***********************/
  871. /*                                                                    */
  872. /* SUBROUTINE NAME:  VDFTInit (Start_here)                            */
  873. /*                                                                    */
  874. /* DESCRIPTIVE NAME:  Virtual DFT Initialization entry point          */
  875. /*                                                                    */
  876. /* FUNCTION:  The function of this routine is to register the VDM     */
  877. /*            Creation, Termination, PDB Change, and PDB Destroy      */
  878. /*            handlers. This routine also sets up the VDFT Port       */
  879. /*            Address table in the global data area.                  */
  880. /*                                                                    */
  881. /* NOTES:                                                             */
  882. /*                                                                    */
  883. /* CONTEXT: System Initialization                                     */
  884. /*                                                                    */
  885. /* ENTRY POINT:  VDFTInit                                             */
  886. /*    LINKAGE:  CALL NEAR 32                                          */
  887. /*                                                                    */
  888. /* INPUT: psz - pointer to configuration strings                      */
  889. /*                                                                    */
  890. /* EXIT-NORMAL: returns !0                                            */
  891. /*                                                                    */
  892. /* EXIT-ERROR: returns 0                                              */
  893. /*                                                                    */
  894. /* EFFECTS: VDFT Port Address table in the global data area.          */
  895. /*                                                                    */
  896. /* INTERNAL REFERENCES:  NONE                                         */
  897. /*                                                                    */
  898. /* EXTERNAL REFERENCES:  VDHInstallUserHook - Install VDM event hook  */
  899. /*                       VDHOpenPDD         - Get PDD entry point     */
  900. /*                       VDHOpenVIRQ        - register an IRQ for VDM */
  901. /*                       VDHReservePages    - set up some linear      */
  902. /*                                 space for use as the adapter space */
  903. /************************ END OF SPECIFICATIONS ***********************/
  904.  
  905. /* --------------------------------------------------------  */
  906. /* LFJ : Added #pragma entry() and changed main entry name   */
  907. /*       because Giverny requires main to be either _OPTLINK */
  908. /*       or _System linkage                                  */
  909. /* --------------------------------------------------------- */
  910. //#pragma entry(VDDInit)
  911. //BOOL EXPENTRY VDDInit(PSZ psz)
  912. #pragma entry(Start_Here)
  913. BOOL EXPENTRY Start_Here(PSZ psz)
  914. {
  915.  
  916. ULONG ErrorNumber;                 /* holds error number from getError*/
  917. #ifdef DEBUG
  918.    _interrupt(3);
  919. #endif
  920.     if(VDHRegisterVDD(VDDNAME,OS2Service,NULL))
  921.     {
  922.        return(FALSE);
  923.     }
  924.     return TRUE;
  925. }
  926. #if 0
  927. //Incomplete prototype
  928. BOOL OS2Service(ULONG ulCommand,SGID sgid,ULONG ulCountBuffer)
  929. {
  930.  
  931.  
  932. }
  933. #endif
  934.  
  935.