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