home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ddkx86v5.zip / DDKX86 / SRC / DEV / PCMCIA / SOCKET / SSOS2DRV.ASM < prev    next >
Assembly Source File  |  1995-04-14  |  20KB  |  505 lines

  1. ;*DDK*************************************************************************/
  2. ;
  3. ; COPYRIGHT (C) Award Software International Inc., 1994
  4. ; COPYRIGHT    Copyright (C) 1995 IBM Corporation
  5. ;
  6. ;    The following IBM OS/2 WARP source code is provided to you solely for
  7. ;    the purpose of assisting you in your development of OS/2 WARP device
  8. ;    drivers. You may use this code in accordance with the IBM License
  9. ;    Agreement provided in the IBM Device Driver Source Kit for OS/2. This
  10. ;    Copyright statement may not be removed.;
  11. ;*****************************************************************************/
  12.                 name    SSOS2DRV
  13.                 page    60, 132
  14.                 title   'SSOS2DRV'
  15. ;******************************************************************************
  16. ;*
  17. ;*                            File SSOS2DRV.ASM
  18. ;*
  19. ;*                            OS2 Device Driver
  20. ;*
  21. ;*    The code in this file is relative to the OS2 Device Driver conception
  22. ;*    and OS2 memory structure. The file contains OS2 Device Driver header,
  23. ;*    strategy and interrupt routine, command line processing helpers and
  24. ;*    interrupt handlers for SS interrupt and keyboard interrupt.
  25. ;*
  26. ;*
  27. ;*
  28. ;******************************************************************************
  29.  
  30.                 .xlist
  31.                 include ssmac.inc           ; Macros
  32.                 include ssdefs.inc          ; Sockets Services definitions
  33.                 include ss_segm.inc         ; Segments definitions
  34.                 include ssos2.inc           ; OS2 specific definitions
  35.                 include ssPCIC.inc          ; PCIC datatypes and prototypes
  36.                 include ssmsg.inc           ; Message defs
  37.                 .list
  38.  
  39.  
  40. ;*****************************************************************************
  41. ;*                         --- Segment ResData ---
  42. ;*****************************************************************************
  43. sBegin          ResData
  44.  
  45.                 org     0
  46. DevHdr__       SysDev  {-1, DATTR_SS, offset Strategy, codRM_Entry, OS2DRVNAME, 0, 0, 0, 0}
  47. sDevCaps        dd      0                   ; Device capabilities
  48. staticFP        Request                     ; Device driver request header
  49. staticFP        DevHelp                     ; DevHelp Entry point
  50. staticFP        PriorHandler                ; Prior handler
  51.  
  52. pCardServices   dd      ?                   ; Card Services entry point
  53. wCS_DS          dw      ?                   ; Card Services data segment
  54.  
  55. sEnd            ResData
  56.  
  57. ;*****************************************************************************
  58. ;*                         --- Segment InitData ---
  59. ;*****************************************************************************
  60. sBegin          InitData
  61.  
  62. ;-------------------------------- Screen Output -------------------------------
  63.  
  64. osMsgFlag       db      MSG_OFF             ; Default: No messages
  65.  
  66. PrintCharBuff   db      0, 0                ; Print character buffer
  67. MessageTable    label   byte                ; Save_Message structure
  68. Msg_ID          dw      MSG_REPLACEMENT_STRING
  69. Msg_nMsgs       dw      1                   ; Only one message supported
  70. Msg_BufferOff   dw      InitDataOFFSET MsgBuffer
  71. Msg_BufferSeg   dw      InitDataBASE
  72.  
  73. MsgBuffer       db      MAX_MSG dup (0)     ; Message Buffer
  74.  
  75. ;-------------------------------- CS Interface --------------------------------
  76.  
  77. PCMCIA_Dev_Name db      "PCMCIA$  ", 00h    ; OS/2 CS Device
  78. PCMCIA_Data     AttachDD_Data {0, 0, 0, 0, 0, 0}
  79.  
  80. AddSSData       AddSS_Data {RSSE_PROT_1616, ResDataBASE}
  81.                                             ; Attribute One indicates, the
  82.                                             ; SSEntry and DataPointer arguments
  83.                                             ; are far 16-bit selector:offset
  84.                                             ; pointers
  85. sEnd            InitData
  86.  
  87. ;*****************************************************************************
  88. ;*                         --- Segment ResCode ---
  89. ;*****************************************************************************
  90. sBegin          ResCode
  91.  
  92. ;*****************************************************************************
  93. ;*                             --- Strategy ---
  94. ;*
  95. ;*     Purpose: Strategy procedure
  96. ;*       Input: es:bx - Request header
  97. ;*      Output: none
  98. ;* Scratch reg: none
  99. ;*     Written: by Alexis A.Piatetsky 22.07.94
  100. ;*****************************************************************************
  101. cProc           Strategy, <FAR>, <ax, bx, cx, dx, si, di, ds, es>
  102. cBegin          Strategy
  103.                 assumes ds, Nothing
  104.                 assumes es, Nothing
  105.                 assumes ss, Nothing
  106.  
  107.                 pushf                       ; Preserve All Regiseters
  108.  
  109.                 mov     ax, ResDataBASE     ; Use our data segment
  110.                 mov     ds, ax
  111.         assumes ds, ResData
  112.  
  113.                 mov     Off_Request, bx
  114.                 mov     Seg_Request, es
  115.  
  116.                 mov     Off_PriorHandler, 0 ; Initialise
  117.                 mov     Seg_PriorHandler, 0
  118.  
  119. ;---------------------- Device Driver supports ONLY Init ----------------------
  120.  
  121.                 mov     ax, STERR OR UNKNOWN_CMD    ; Default Error Code
  122.                 cmp     (InitPacket PTR es:[bx]).Pkt_Cmd, CMDInitBase
  123.                 jne     short opdone
  124.  
  125.                 mov     eax, (InitPacket PTR es:[bx]).PktInitpEnd
  126.                 mov     DevHelp, eax
  127.  
  128. ;----------- ## AAP ## 19.04.94 16:56 Scan command line. Skip filename --------
  129.  
  130.                 les     bx, (InitPacket PTR es:[bx]).PktInitParms
  131.                                                 ; ASCII string from CONFIG.SYS
  132. @@:             mov     al, es:[bx]
  133.                 or      al, al
  134.                 jz      @f
  135.                 cmp     al, ' '
  136.                 jbe     @f
  137.                 inc     bx
  138.                 jmp     short @b
  139. @@:
  140. ;----------------------------------- ## AAP End -------------------------------
  141.  
  142.                 call    coiInitSS
  143.         assume  es:Nothing
  144.                 jc      @f                  ; Initialisation failed
  145.  
  146.                 mov     ax, InitDataBASE
  147.                 mov     es, ax
  148.         assumes es, InitData
  149.                 call    osAddSS
  150.  
  151. @@:             les     bx, Request         ; Restore Request Header Ptr
  152.         assume  es:Nothing
  153.                 jc      @f
  154.  
  155.                 mov     ax, cs              ; Get Size of code
  156.                 call    GetSegmPars
  157.                 jc      @f
  158.                 mov     word ptr (InitPacket PTR es:[bx]).PktInitpEnd, dx
  159.  
  160.                 mov     ax, ds              ; Get size of data
  161.                 call    GetSegmPars
  162.                 jc      @f
  163.                 mov     word ptr (InitPacket PTR es:[bx+2]).PktInitpEnd, dx
  164.  
  165.                 mov     ax, 0               ; Init successful
  166.                 jmp     short opdone
  167.  
  168. @@:             mov     (InitPacket PTR es:[bx]).PktInitpEnd, 0
  169.                 mov     ax, STERR OR osGENERAL_FAILURE
  170.  
  171. opdone:         or      ax, STDON
  172.                 mov     (InitPacket PTR es:[bx]).Pkt_Status, ax     ; Set return status
  173.                 mov     (InitPacket PTR es:[bx]).PktInitcUnit, 0
  174.  
  175. ;----------------------------- Print all messages -----------------------------
  176.  
  177.                 push    ds
  178.                 pop     es
  179.         assumes es, ResData
  180.                 mov     ax, InitDataBASE
  181.                 mov     ds, ax
  182.         assumes ds, InitData
  183.  
  184.                 cmp     osMsgFlag, MSG_ON
  185.                 jne     @f
  186.  
  187.                 mov     si, InitDataOFFSET MessageTable
  188.                 xor     bx, bx
  189.                 mov     dl, DevHlp_Save_Message
  190.                 call    es:[DevHelp]
  191. @@:
  192.                 popf
  193.  
  194. cEnd            Strategy
  195.  
  196. ;*****************************************************************************
  197. ;*                            --- GetSegmPars ---
  198. ;*
  199. ;*     Purpose: Return Segment base address and size
  200. ;*       Input: ax - Selector of segment of interest
  201. ;*      Output: CY, if failed, else NC and
  202. ;*              dx - Segment size (Not LIMIT!!!)
  203. ;*              cx - Segment linear base address
  204. ;* Scratch reg: cx, dx
  205. ;*     Written: by Alexis A.Piatetsky 09.08.94
  206. ;*        Note: This routine works for both LDT and GDT, even if comment was
  207. ;*              initially writen for GDT only
  208. ;*****************************************************************************
  209. GetSegmPars     PROC    NEAR
  210.         assumes ds, ResData
  211.         assumes es, Nothing
  212.         assumes ss, Nothing
  213.                 push    ax
  214.                 mov     dl, DevHlp_GetDescInfo
  215.                 call    [DevHelp]
  216. gsm_Done:       pop     ax
  217.                 ret
  218. GetSegmPars     ENDP
  219.  
  220. COMMENT ~*********************************************************************
  221.  
  222.         Procedure:      GetSetSSAddr
  223.  
  224.         Purpose:        Get or Set SS addresses for call interface
  225.  
  226.         Entry:          [BP] = Pointer to entry args on stack
  227.                         [BX] = Pointer to adapter entry in Adapters array
  228.                         Args.BHReg = Desired processor mode
  229.                            00 = Real mode       02 = 16:32 Protect
  230.                            01 = 16:16 Protect   03 = 00:32 Protect
  231.                         Args.BLReg = Subfunction
  232.                            00 = Get Cod and Main Data segment descriptions
  233.                            01 = Get descriptions of additional data segments
  234.                            02 = Set mode-specific pointers for additional data segments
  235.                         If Args.BLReg = 0
  236.                            [ES]:[(E)DI] = Pointer to buffer for segment descriptions
  237.                         If Args.BLReg = 1
  238.                            Args.CXReg = Number of additional data segments
  239.                            [ES]:[(E)DI] = Pointer to buffer for add data seg descrips
  240.                         If Args.BLReg = 2
  241.                            Args.CXReg = Number of additional data segments
  242.                            [ES]:[(E)DI] = Pointer to buffer of mode-specific pointers
  243.  
  244.         Exit:           Args.AHReg = Return code
  245.                         If Args.AHReg = SUCCESS and Args.BLReg = 0
  246.                            Args.CXReg = Number of additional data segments
  247.                            Client-supplied buffer filled with main seg descriptions
  248.                         If Args.AHReg = SUCCESS and Args.BLReg = 1
  249.                            Client-supplied buffer with add data seg descrips
  250.  
  251.         WARNING:        This procedure assumes the code and data segments are
  252.                         the same during execution and uses just the code segment
  253.                         to compute return values.  If the code and data segments
  254.                         are not the same, this procedure MUST be modified.
  255.  
  256. *****************************************************************************~
  257.  
  258. GetSetSSAddr    PROC    NEAR
  259.                 assume  ds:@data, es:Nothing
  260.  
  261.                 cmp     (ARGS PTR [BP]).BLReg, 0 ; SubFunc zero (0) ?
  262.                 je      short @f                 ; Yes, continue
  263.  
  264.                 mov     AH, BAD_FUNCTION         ; No, indicate error
  265.                 jmp     short GSSSAddrExit       ;  and exit
  266. @@:
  267.                 cmp     (ARGS PTR [BP]).BHReg, RSSE_PROT_1616 ; 16:16 PM?
  268.                 je      short @f                 ; Yes, continue
  269.  
  270.                 mov     ah, BAD_MODE             ; No, indicate error
  271.                 jmp     short GSSSAddrExit       ;  and exit
  272. @@:
  273.  
  274. ;---------------------------- Resident code segment ---------------------------
  275.  
  276.                 mov     ax, cs
  277.                 call    GetSegmPars
  278.                 mov     ah, GENERAL_FAILURE      ; Assume, failure
  279.                 jc      GSSSAddrExit
  280.  
  281.                 dec     edx                      ; We must return Limit
  282.                 mov     dword ptr es:(SS_ADDR_MAIN PTR [di]).wCodeBaseLo, ecx
  283.                 mov     dword ptr es:(SS_ADDR_MAIN PTR [di]).wCodeSizeLo, edx
  284.  
  285. ;---------------------------- Resident data segment ---------------------------
  286.  
  287.                 mov     ax, ds
  288.                 call    GetSegmPars
  289.                 mov     ah, GENERAL_FAILURE      ; Assume, failure
  290.                 jc      GSSSAddrExit
  291.  
  292.                 dec     edx                      ; We must return Limit
  293.                 mov     dword ptr es:(SS_ADDR_MAIN PTR [di]).wDataBaseLo, ecx
  294.                 mov     dword ptr es:(SS_ADDR_MAIN PTR [di]).wDataSizeLo, edx
  295.  
  296. ;----------------------------- Entry point offset  ----------------------------
  297.  
  298.  
  299.                 mov     es:(SS_ADDR_MAIN PTR [di]).wCodeEntryLo,  OFFSET codRM_Entry
  300.                 mov     es:(SS_ADDR_MAIN PTR [di]).wCodeEntryHi,  0
  301.  
  302. ;-------------------------------- Data offset  --------------------------------
  303.  
  304.  
  305.                 mov     dword ptr es:(SS_ADDR_MAIN PTR [di]).wDataOffsetLo, 0
  306.  
  307.                 mov     (ARGS PTR [BP]).CXReg, 0 ; No Additional Data Segments
  308.  
  309.                 mov     ah, SUCCESS
  310. GSSSAddrExit:   ret
  311.  
  312. GetSetSSAddr    ENDP
  313.  
  314. sEnd            ResCode
  315.  
  316. ;*****************************************************************************
  317. ;*                         --- Segment InitCode ---
  318. ;*****************************************************************************
  319. sBegin          InitCode
  320.  
  321. ;*****************************************************************************
  322. ;*                             --- osAddSS ---
  323. ;*
  324. ;*     Purpose: Add SS to card services
  325. ;*       Input: none
  326. ;*      Output: none
  327. ;* Scratch reg: none
  328. ;*     Written: by Alexis A.Piatetsky 11.08.94
  329. ;*****************************************************************************
  330. osAddSS         PROC    FAR
  331.                 assumes ds, ResData
  332.                 assumes es, InitData
  333.                 assumes ss, Nothing
  334.  
  335.                 pushx   <ax, bx, cx, dx, di, si>
  336.  
  337. ;--------------------- Make call to CS in order to Add SS ---------------------
  338.  
  339.                 pushx   <ds, es>
  340.                 push    cs
  341.                 push    InitCodeOFFSET csRet ; Return point
  342.                 pushd   [pCardServices]      ; Card Services entry point
  343.  
  344.                 mov     bx, InitDataOFFSET AddSSData
  345.                 mov     cx, SIZEOF AddSS_Data
  346.                 mov     di, ResCodeBASE
  347.                 mov     si, ResCodeOFFSET codRM_Entry
  348.                 mov     dx, 0
  349.  
  350.                 mov     ax, wCS_DS
  351.                 mov     ds, ax
  352.         assumes ds, Nothing
  353.                 mov     ah, CARD_SERVICES
  354.                 mov     al, AddSS
  355.  
  356.                 retf                        ; call pCardServices
  357.  
  358. csRet:          popx    <es, ds>
  359.                 assumes ds, ResData
  360.                 assumes es, InitData
  361.  
  362.                 jnc     @f
  363.  
  364.                 mov     dx, InitDataOFFSET FailAddMsg
  365.                 cCall   osPrintString, <dx>
  366.                 stc
  367.  
  368. @@:             popx    <si, di, dx, cx, bx, ax>
  369.                 ret
  370. osAddSS         ENDP
  371.  
  372.  
  373. ;*****************************************************************************
  374. ;*                            --- osOKtoLoad ---
  375. ;*
  376. ;*     Purpose: Check, if SS could be loaded
  377. ;*       Input: none
  378. ;*      Output: NC, if yes
  379. ;*              CY and DX - offset of message, if not
  380. ;* Scratch reg: none
  381. ;*     Written: by Alexis A.Piatetsky 09.08.94
  382. ;*****************************************************************************
  383. osOKtoLoad      PROC    NEAR
  384.                 assumes ds, ResData
  385.                 assumes es, InitData
  386.                 assumes ss, Nothing
  387.  
  388.                 pushx   <ax, bx, di>
  389.  
  390.                 push    dx
  391.  
  392. ;----------------------- Try to attach to Card Services -----------------------
  393.  
  394.                 pushx   <ds, es>            ; xchg ds, es
  395.                 popx    <ds, es>
  396.         assumes es, ResData
  397.         assumes ds, InitData
  398.  
  399.                 mov     bx, InitDataOFFSET PCMCIA_Dev_Name
  400.                 mov     di, InitDataOFFSET PCMCIA_Data
  401.                 mov     dl,DevHlp_AttachDD
  402.                 call    es:[DevHelp]
  403.  
  404.                 pushx   <ds, es>            ; xchg ds, es
  405.                 popx    <ds, es>
  406.         assumes ds, ResData
  407.         assumes es, InitData
  408.                 jc      @f                  ; Attachement to CS failed
  409.  
  410.  
  411. ;------------------- Copy returned values to resident data  -------------------
  412.  
  413.                 mov     eax, dword ptr es:PCMCIA_Data.ADDD_IDCOff
  414.                 mov     pCardServices, eax
  415.                 mov     ax, es:PCMCIA_Data.ADDD_IDCDS
  416.                 mov     wCS_DS, ax
  417.  
  418.                 pop     dx
  419.                 clc                         ; We can load SS
  420.                 jmp     short otl_Done
  421.  
  422. @@:             mov     dx, offset CSPresentMsg
  423.                 add     sp, 2               ; Discard dx in the stack
  424.                 stc                         ; Do not load CS
  425.  
  426. otl_Done:       popx    <di, bx, ax>
  427.                 ret
  428. osOKtoLoad      ENDP
  429.  
  430. ;*****************************************************************************
  431. ;*                           --- PrintString ---
  432. ;*
  433. ;*     Purpose: Print NULL terminated string via OS/2 interface
  434. ;*   Prototype: void PrintString(PSTR pString);
  435. ;*       Input: Offset of string to print. String must be located in InitData
  436. ;*              segment
  437. ;*      Output: none
  438. ;* Scratch reg: none
  439. ;*     Written: by Alexis A.Piatetsky 02.05.94
  440. ;*****************************************************************************
  441. cProc           osPrintString, <NEAR, PUBLIC>, <di, cx, ax>
  442.                 parmW   pString             ; String Offset
  443. cBegin          PrintString
  444.                 assumes ds, ResData
  445.                 assumes es, InitData
  446.  
  447.                 pushx   <si, ds>
  448.                 mov     di, pString
  449.                 mov     si, di
  450.                 call    couStrLen           ; String length
  451.  
  452.                 mov     ax, cx
  453.  
  454.                 mov     di, InitDataOFFSET MsgBuffer
  455.                 call    couStrLen           ; Buffer length
  456.  
  457.                 push    ax                  ; Message length
  458.                 add     ax, cx
  459.                 cmp     ax, MAX_MSG         ; Do we have space?
  460.                 pop     ax                  ; Message length
  461.                 jae     @f                  ; Buffer full, abort print
  462.  
  463.                 xchg    ax, cx              ; ax - Buffer length, cx - Message
  464.                                             ; length
  465.                 add     di, ax              ; es:di - Point end of the buffer
  466.  
  467.                 push    es
  468.                 pop     ds
  469.         assumes ds, InitData
  470.  
  471.             rep movsb                       ; Copy message to the buffer
  472.  
  473. @@:             popx    <ds, si>
  474.         assumes ds, ResData
  475.  
  476. cEnd            osPrintString
  477.  
  478. ;*****************************************************************************
  479. ;*                           --- osPrintChar ---
  480. ;*
  481. ;*     Purpose: Print character via OS/2 interface
  482. ;*   Prototype: void PrintChar(WORD wChar);
  483. ;*       Input: Character to print
  484. ;*      Output: none
  485. ;* Scratch reg: none
  486. ;*     Written: by Alexis A.Piatetsky 02.05.94
  487. ;*****************************************************************************
  488. cProc           osPrintChar, <NEAR, PUBLIC>, <ax>
  489.                 parmW   wChar
  490. cBegin          PrintChar
  491.                 assumes ds, ResData
  492.                 assumes es, InitData
  493.  
  494.                 mov     ax, wChar
  495.                 mov     es:PrintCharBuff, al
  496.                 mov     ax, offset PrintCharBuff
  497.                 cCall   osPrintString, <ax>
  498.  
  499. cEnd            osPrintChar
  500.  
  501.  
  502. sEnd            InitCode
  503.                 END
  504.  
  505.