home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tolkit45.zip / os2tk45 / samples / tcpiptk / r0lib32 / init16.c < prev    next >
C/C++ Source or Header  |  1999-05-11  |  5KB  |  151 lines

  1. /********************************************************copyrite.xic********/
  2. /*                                                                          */
  3. /*   Licensed Materials - Property of IBM                                   */
  4. /*   IBM TCP/IP for OS/2                                                    */
  5. /*   (C) Copyright IBM Corporation. 1990,1996.                              */
  6. /*                                                                          */
  7. /*   All rights reserved.                                                   */
  8. /*                                                                          */
  9. /*   US Government Users Restricted Rights -                                */
  10. /*   Use, duplication or disclosure restricted by GSA ADP Schedule          */
  11. /*   Contract with IBM Corp.                                                */
  12. /*                                                                          */
  13. /*--------------------------------------------------------------------------*/
  14. /*  DISCLAIMER OF WARRANTIES.  The following [enclosed] code is             */
  15. /*  sample code created by IBM Corporation. This sample code is not         */
  16. /*  part of any standard or IBM product and is provided to you solely       */
  17. /*  for  the purpose of assisting you in the development of your            */
  18. /*  applications.  The code is provided "AS IS", without                    */
  19. /*  warranty of any kind.  IBM shall not be liable for any damages          */
  20. /*  arising out of your use of the sample code, even if they have been      */
  21. /*  advised of the possibility of such damages.                             */
  22. /*--------------------------------------------------------------------------*/
  23. /************************** INIT16.C ****************************************/
  24. #define  _16BITCODE
  25. #define  INCL_DOS
  26. #define  INCL_DOSINFOSEG
  27. #include <os2.h>
  28.  
  29. #include <sys\itypes.h>
  30. #include <driver.h>
  31. #include <genio.h>
  32. #include <pddentry.h>
  33. #include <sys\dprintf.h>
  34. #include <sys\socket.h>
  35. #include <entry.h>
  36.  
  37. extern void setjmp32(void);
  38. extern struct DOSTABLE *GetDosVarLinearPtr(void);          /* index=09 default*/
  39.  
  40. void initdevice();
  41.  
  42. short initflag;
  43. unsigned long * ptkssbase=0;        /* Ptr to kernel ssbase. amol 10/10/96 */
  44.  
  45. struct DOSTABLE {
  46.   unsigned char   NumEntries;    /* Number of entries is DOSTABLE */
  47.   unsigned long   HardErr;       /* Hard error routine            */
  48.   unsigned long   uCase;         /* h_UCase                       */
  49.   unsigned long   Dummy[3];
  50.   unsigned long   MemMapAlias;   /* h_MemMapAlias                 */
  51.   unsigned long   MemUnMapAlias; /* h_UCase                       */
  52.   unsigned long   GoProtAll;     /* h_GoProtAll                   */
  53.   unsigned long   GoRealAll;     /* h_GoRealAll                   */
  54.   unsigned long   RedirDevice;   /* h_doshelp_RedirDev            */
  55.   unsigned long   Dummy2[2];
  56.   unsigned long   SFFromSFN;     /* h_SFFromSFN                   */
  57.   unsigned long   SegGetInfo;    /* h_SegGetInfo                  */
  58.   unsigned long   Dummy3[3];
  59.   unsigned char   NumEntries2;
  60.   unsigned long   DosTab2[18];
  61. };
  62. struct DOSTABLE *PDosTbl;
  63.  
  64. typedef unsigned long physaddr;  /* A physical address is 4 bytes */
  65. typedef void far * farptr;
  66.  
  67. typedef struct _2words_def {
  68.   unsigned short low;
  69.   unsigned short high;
  70.   } _2words_type;
  71.  
  72. typedef struct _segaddr_def {
  73.   unsigned short offset;
  74.   unsigned short segment;
  75.   } _segadr_type;
  76.  
  77. typedef union _32bits_def {
  78.    physaddr phys;
  79.    void far * fptr;
  80.    _2words_type _2words;
  81.    _segadr_type _segadr;
  82.    } _32bits;
  83.  
  84. void devopen(lpreq)
  85. lpRequest lpreq;
  86. {
  87.    lpreq->reqstatus |= DONE_BIT;
  88. }
  89.  
  90. void devclose(lpreq)
  91. lpRequest lpreq;
  92. {
  93.    lpreq->reqstatus |= DONE_BIT;
  94. }
  95.  
  96. void init16_c(lpreq)
  97. lpRequest lpreq;
  98. {
  99.    switch(lpreq->reqcommand) {
  100.       case INIT:
  101.            /* int3break(); */
  102.            initdevice(lpreq);
  103.            initflag=1;
  104.            setjmp32();
  105.            break;
  106.       case OPEN:
  107.            devopen(lpreq);
  108.            break;
  109.       case CLOSE:
  110.            devclose(lpreq);
  111.            break;
  112.       case GENIO:
  113.            /* this case should be handled in driver.c (32bit mode) */
  114.            lpreq->reqstatus = GEN_ERR + ERR_UNKNOWNCOMMAND + DONE_BIT;
  115.            break;
  116.       case INIT_COMPLETE:
  117.            lpreq->reqstatus |= DONE_BIT;
  118.            break;
  119.       default:
  120.            lpreq->reqstatus = GEN_ERR + ERR_UNKNOWNCOMMAND + DONE_BIT;
  121.            break;
  122.    } /* end switch */
  123. }
  124.  
  125.  
  126. void initdevice(lpRequest lpreq)
  127. {
  128.    extern ULONG near devhelp;
  129.    extern void near last_c();
  130.    extern void near last_d();
  131.    lpInit_Packet lpi;
  132.    int  lc ,ld;
  133.  
  134.    lpi  = (lpInit_Packet)lpreq;
  135.  
  136.    devhelp = lpi->lpDevHlp;     /* save the devhelp entry point */
  137.  
  138.    PDosTbl=(struct DOSTABLE *)GetDosVarLinearPtr();       /* index=09 default*/
  139.    /*This Magic#11 (DOSTAB2_TKSSBASE) points to the
  140.     *  required base address of ss.
  141.     */
  142.    ptkssbase=(unsigned long *) PDosTbl->DosTab2[11];
  143.  
  144.    lc            = ((int) last_c)-1;
  145.    ld            = ((int) last_d)-1;
  146.    lpi->lpDevHlp = MAKEULONG(lc, ld);   /* return last_c and last_d to kernel */
  147.    lpi->InitArgs = 0L;
  148.  
  149.    lpreq->reqstatus = DONE_BIT;
  150. }
  151.