🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.os.os2.programmer
Article #349

ODI Interface problems

#349
From: hamish
Date: Tue, 11 Aug 1992 01:40
593 lines
27159 bytes
OK. This piece of code is taken from the hrtimer devive driver, and I'm trying
to adapt it to provide a reasonalbe interface to the ODI drivers under OS/2
2.0, the problem is that when tryuing to access the RegisterPrescanStack
funtion of ODI thriought the LSL entry point obtained at init time, the whole
machine locks up daeder that a doornail, noit even a rap to show something
accessing invalid memory ptrs or anything. Can somebody help? I really need to
be able to get packets from the network, and the old ODI protocol interface for
OS/2 just isn't any help in the matter.

Oh yeah. The RegisterPrescan call is made at open time (ie when an app tries to
open the enet$ device).

Code begins here -----------
;**********************************************************************
;* MODULE NAME :  nit.asm                AUTHOR:  Hamish Marson       *
;* DATE WRITTEN:  2-7-92                                              *
;*                                                                    *
;* DESCRIPTION: Network Interface Tape for ODI devices under OS/2 2.0 *
;*              Adapted from hrtimer.sys                              *
;*                                                                    *
;**********************************************************************

        .286

;*********************************************************************
;*----------------------------- EQUATES -----------------------------*
;*********************************************************************

RP_StatusError          equ     80h     ; RP_Status error bit
RP_StatusDone           equ     01h     ; RP_Status done bit

                                        ; DEVICE HELPER FUNCTIONS
DevHlp_PhysToVirt       equ     15h     ; Convert a physical address to virtual
DevHlp_UnPhysToVirt     equ     32h     ; Release virtual memory

cr                      equ     0dh     ; ASCII code for carraige return
lf                      equ     0ah     ; ASCII code for line feed

stdin                   equ      0      ; File handle for standard input
stdout                  equ      1      ; File handle for standard output

BUFFER                  equ     10      ; Buffer up to 10 packet headers

;**********************************************************************
;*------------------------------ MACROS ------------------------------*
;**********************************************************************


;**********************************************************************
;*---------------------------- STRUCTURES ----------------------------*
;**********************************************************************

RequestPacket           struc           ; Request Packet header

    RP_Length           db      ?       ; Request Packet length
                        db      ?       ; Block devices only
    RP_CommandCode      db      ?       ; Command
    RP_ErrorCode        db      ?       ; Command Error Code
    RP_Status           db      ?       ; Command Status Code
                        dd      ?       ; Reserved
                        dd      ?       ; Queue Linkage - not used here

RequestPacket           ends


RequestPktInit          struc           ; Initialization Request Packet

                        db 13 dup(?)    ; Request Packet Header
    RPI_NumberUnits     db      ?       ; Block devices only - used to cancel
                                        ; DevHlp pointer in, on return from
init
    RPI_CodeSegLen      dw      ?       ;     Code segment length
    RPI_DataSegLen      dw      ?       ;     Data segment length
    RPI_CommandLine     dd      ?       ; Pointer to command line
                        db      ?       ; Block devices only

RequestPktInit          ends


RequestPktRead          struc           ; Read Request Packet (from DosRead)

                        db 13 dup(?)    ; Request Packet header
                        db      ?       ; Block devices only
    RPR_TransferAddr    dd      ?       ; Physical address of read buffer
    RPR_BytesRequested  dw      ?       ; Number of bytes to read

RequestPktRead          ends

;**********************************************************************
;*----------------------------- EXTERNS ------------------------------*
;**********************************************************************

        extrn  DosWrite:far
        extrn  DosDevIOCtl:far
        extrn  DosOpen:far

;**********************************************************************
;*-------------------------- DATA SEGMENT ----------------------------*
;**********************************************************************

DGROUP          group   _DATA

_DATA           SEGMENT word public  'DATA'

;**********************************************************************
;*---------------------- Device Driver Header ------------------------*
;**********************************************************************

TimerHeader             label   byte            ; Device Driver header

    NextDeviceDriver    dd      -1              ; Last driver in chain
    DeviceAttribute     dw      1000100010000000B  ; Char,Open/Close,OS/2 1.1
    StrategyOffset      dw      Strategy        ; Offset of Strategy Routine
                        dw      -1              ; IDC - not used here
    DeviceName          db      'ENET$   '      ; Driver Device-Name
    SDevProtCS          DW      ?
    SDevProtDS          DW      ?
    SDevRealCS          DW      ?
    SDevRealDS          DW      ?
;**********************************************************************
;*------------ Data areas used by Strategy and Interrupt -------------*
;**********************************************************************

DevHlpPtr               dd      ?               ; Pointer to Device Helper
                                                ;   routine - Set at init rqst
UserCount               dw      0               ; Number of active users

BytesWritten            dw      ?               ; Used for DosWrite calls


ReadDataBuf             dd ?                    ; First word is # calls
PacketsWait             dw ?                    ; Second word is # headers
                        db 128*BUFFER dup (?)   ; Buffer to return to caller

ReadDataLen             equ     $ - ReadDataBuf ; Length of ReadDataBuf

;**********************************************************************
;*--------------------- Command (Request) List -----------------------*
;**********************************************************************

CmdList         label   word

                dw      Initialize      ;  0 = Initialize driver
                dw      Error           ;  1 = Media Check
                dw      Error           ;  2 = Build BPB
                dw      Error           ;  3 = Not used
                dw      Read            ;  4 = Read from device
                dw      DummyRet        ;  5 = Non-destructive read
                dw      DummyRet        ;  6 = Return input status
                dw      FlushInput      ;  7 = Flush input buffers
                dw      Error           ;  8 = Write to device
                dw      Error           ;  9 = Write with verify
                dw      DummyRet        ; 10 = Return output status
                dw      FlushOutput     ; 11 = Flush output buffers
                dw      Error           ; 12 = Not used
                dw      Open            ; 13 = Device open
                dw      Close           ; 14 = Device close

MaxCmd          equ     ( $ - CmdList ) / TYPE CmdList

CopyRightMsg    db      cr, lf
                db      'Network Interface Tap - Version 1.0', cr, lf
                db      'Hamish Marson, University of Waikato. 1992', cr, lf
                db      'Source from IBM Personal Systems Developer
(1991)',cr,lf
CopyRightMsgLen equ     $ - CopyRightMsg

InitNotOkMsg    db      'NIT.SYS Initialization Failed', cr, lf
InitNotOkMsgLen equ     $ - InitNotOkMsg

LinkHandle      dw      ?               ; handle for LINKSUP$

; LSL Jump Addresses
lsltable        label word
lt_protsup      dd      ?               ; Protocol Support Calls
lt_genserv      dd      ?               ; General Services Call
lt_tt           db 16 dup(?)            ; reserved

; PrescanInfoStruct
PrescanInfo     label word
RecvHandlerPtr  dd      PrescanReceive
CntlHandlerPtr  dd      PrescanControl


LastData        equ     $ - CopyRightMsg

MarkMsg         db      cr,lf
                db      'Program Mark',cr,lf
MarkMsgLen      equ     $ - MarkMsg

LinkName        db      'LINKSUP$',0            ; Name of LSL to open

OpenErrorMsg    db      'Couldn''t open LINKSUP$ device',cr,lf
OpenErrorMsgLen equ     $ - OpenErrorMsg

_DATA           ENDS

;**********************************************************************
;*-------------------------- CODE SEGMENT ----------------------------*
;**********************************************************************

_TEXT           SEGMENT word public  'CODE'

                assume cs:_TEXT, ds:DGROUP

;**********************************************************************
;*---------------------------- Strategy ------------------------------*
;*                                                                    *
;*  STRATEGY ENTRY POINT.                                             *
;*                                                                    *
;*  INPUT: ES:BX = address of request packet                          *
;*                                                                    *
;*  1 -                                                               *
;*                                                                    *
;*  OUTPUT: nothing                                                   *
;*                                                                    *
;*--------------------------------------------------------------------*
;**********************************************************************

Strategy        PROC    far

        cmp     es:[bx].RP_CommandCode, MaxCmd  ; Command within jumb table?
        jbe     JumpCmd                         ;   YES: execute command
routine

        call    Error                           ;   NO: send back error
        jmp     short exit                      ;       and exit

JumpCmd:

        mov     al, es:[bx].RP_CommandCode      ; Isolate command,
        cbw                                     ;   convert to word,
        mov     si, ax                          ;   put into index register,
        shl     si, 1                           ;   multiply by 2 so it is a
                                                ;   word rather than byte
offset
        call    CmdList [si]                    ; Call command routine

exit:
        ret                                     ; Return to operating system

Strategy        ENDP

;**********************************************************************
;*------------------------------ Read --------------------------------*
;*                                                                    *
;*  HANDLE A READ REQUEST.                                            *
;*                                                                    *
;*  INPUT: ES:BX = address of request packet                          *
;*                                                                    *
;*  1.                                                                *
;*                                                                    *
;*  OUTPUT: status byte set                                           *
;*                                                                    *
;*--------------------------------------------------------------------*
;**********************************************************************

Read            PROC    near

        cmp     es:[bx].RPR_BytesRequested, ReadDataLen
        jl      SetError                ; Caller's buffer is too small

        push    es                      ; Save packet pointer
        push    bx

        mov     ax, word ptr es:[bx].RPR_TransferAddr + 2   ; Store ReadPacket
        mov     cx, es:[bx].RPR_BytesRequested              ;   variables in
        mov     bx, word ptr es:[bx].RPR_TransferAddr       ;   registers

        mov     dh, 1                   ; 1 = Store result in ES:DI
        mov     dl, DevHlp_PhysToVirt   ; Use the PhysToVirt function
        call    DevHlpPtr               ; Call the Device Helper routine
        jc      DevHlpError

        mov     si, offset ReadDataBuf  ; Address of timestamp data
        mov     cx, (ReadDataLen / 2)   ; Number of words in timestamp data
        cld                             ; Move forward
        rep     movsw                   ; Move that data

        sti                             ; Enable interrupts

        mov     dl, DevHlp_UnPhysToVirt ; Free Virtual Memory function
        call    DevHlpPtr               ; Call the Device Helper routine

        pop     bx                      ; Restore packet pointer
        pop     es

        mov     es:[bx].RPR_BytesRequested, ReadDataLen

        jmp     short GetOut

DevHlpError:

        pop     bx                      ; Restore packet pointer
        pop     es

SetError:

        mov     es:[bx].RPR_BytesRequested, 0


GetOut:
        or      byte ptr es:[bx].RP_Status, RP_StatusDone
        ret

Read            ENDP

;**********************************************************************
;*-------------------------- Flush Input -----------------------------*
;*                                                                    *
;*  HANDLE A FLUSH INPUT REQUEST.                                     *
;*                                                                    *
;*  INPUT: ES:BX = address of request packet                          *
;*                                                                    *
;*  1.                                                                *
;*                                                                    *
;*  OUTPUT: status byte set                                           *
;*                                                                    *
;*--------------------------------------------------------------------*
;**********************************************************************

FlushInput      PROC    near


        or      byte ptr es:[bx].RP_Status, RP_StatusDone
        ret

FlushInput      ENDP

;**********************************************************************
;*---------------------------Flush Output ----------------------------*
;*                                                                    *
;*  HANDLE A FLUSH OUTPUT REQUEST.                                    *
;*                                                                    *
;*  INPUT: ES:BX = address of request packet                          *
;*                                                                    *
;*  1.                                                                *
;*                                                                    *
;*  OUTPUT: status byte set                                           *
;*                                                                    *
;*--------------------------------------------------------------------*
;**********************************************************************

FlushOutput    PROC    near


        or      byte ptr es:[bx].RP_Status, RP_StatusDone
        ret

FlushOutput     ENDP

;**********************************************************************
;*------------------------------ Open --------------------------------*
;*                                                                    *
;*  HANDLE AN OPEN REQUEST.                                           *
;*                                                                    *
;*  INPUT: ES:BX = address of request packet                          *
;*                                                                    *
;*  1 -                                                               *
;*                                                                    *
;*  OUTPUT: status byte set                                           *
;*                                                                    *
;*--------------------------------------------------------------------*
;**********************************************************************

Open            PROC    near
; First save the ptr to the request packet
        push    es
        push    bx
; Now call the RegisterPrescanStack function to register our recieve packet
; handler.
        mov     ax,ds           ; Setup ptr to Prescan Info Struct
        mov     es,ax
        mov     si,offset PrescanInfo
        mov     bx,0ah          ; Function code
        mov     ax,0            ; Board # 0
        call    lt_protsup      ; Call the protocol support service

        pop     bx
        pop     es
        mov     byte ptr es:[bx].RP_ErrorCode, al          ; return error code
        or      byte ptr es:[bx].RP_Status, RP_StatusDone  ; Indicate DONE
        ret

Open            ENDP

PrescanReceive  PROC    far
        .386
        mov     eax,ReadDataBuf
        add     eax,1
        mov     ReadDataBuf,eax
        .286

        mov     ax,8001h        ; Indicate packet not wanted
PrescanReceive  ENDP

PrescanControl  PROC    far

PrescanCOntrol  ENDP

;**********************************************************************
;*------------------------------ Close -------------------------------*
;*                                                                    *
;*  HANDLE A CLOSE REQUEST.                                           *
;*                                                                    *
;*  INPUT: ES:BX = address of request packet                          *
;*                                                                    *
;*  1 -                                                               *
;*                                                                    *
;*  OUTPUT: status byte set                                           *
;*                                                                    *
;*--------------------------------------------------------------------*
;**********************************************************************

Close           PROC    near
; First save the ptr to the request packet
        push    es
        push    bx
; Now call the DeRegisterPrescanStack function to unregister our recieve packet
; handler.
        mov     bx,0bh          ; Function code
        mov     ax,0            ; Board # 0
        call    [lt_protsup]    ; Call the protocol support service

        pop     bx
        pop     es
        mov     byte ptr es:[bx].RP_ErrorCode, al          ; return error code
        or      byte ptr es:[bx].RP_Status, RP_StatusDone  ; Indicate DONE
        ret

Close           ENDP

;**********************************************************************
;*------------------------------ Error -------------------------------*
;*                                                                    *
;*  HANDLE AN UNSUPPORTED REQUEST.                                    *
;*                                                                    *
;*  INPUT: ES:BX = address of request packet                          *
;*                                                                    *
;*  1 -                                                               *
;*                                                                    *
;*  OUTPUT: status byte set                                           *
;*                                                                    *
;*--------------------------------------------------------------------*
;**********************************************************************

Error           PROC    near

        mov     byte ptr es:[bx].RP_ErrorCode, 3  ; OS/2 Unknown Command RC
                                                  ; Indicate DONE and ERROR
        or      byte ptr es:[bx].RP_Status, RP_StatusError + RP_StatusDone
        ret

Error           ENDP

;**********************************************************************
;*---------------------------- DummyRet ------------------------------*
;*                                                                    *
;*  HANDLE A REQUIRED BUT UNUSED REQUEST                              *
;*                                                                    *
;*  INPUT: ES:BX = address of request packet                          *
;*                                                                    *
;*  1 -                                                               *
;*                                                                    *
;*  OUTPUT: status byte set                                           *
;*                                                                    *
;*--------------------------------------------------------------------*
;**********************************************************************

DummyRet        PROC    near

        or      byte ptr es:[bx].RP_Status, RP_StatusDone  ; Indicate DONE
        ret

DummyRet        ENDP

;**********************************************************************
;*---------------------------- Initialize ----------------------------*
;*                                                                    *
;*  DEVICE DRIVER INTIALIZATION ROUTINE (DISCARDED BY OS2 AFTER USE)  *
;*                                                                    *
;*  INPUT: ES:BX = address of init packet                             *
;*                                                                    *
;*  1 -                                                               *
;*                                                                    *
;*  OUTPUT: nothing                                                   *
;*                                                                    *
;*--------------------------------------------------------------------*
;**********************************************************************

Initialize      PROC    near

        push    stdout                          ; Write copyright info
        push    ds
        push    offset CopyRightMsg
        push    CopyRightMsgLen
        push    ds
        push    offset BytesWritten
        call    DosWrite

        mov     ax, word ptr es:[bx].RPI_CodeSegLen   ; Save pointer to
        mov     word ptr DevHlpPtr , ax               ;   Device Helper routine
        mov     ax, word ptr es:[bx].RPI_DataSegLen
        mov     word ptr DevHlpPtr  + 2, ax
; DO init here.
        .386
        push    ds
        push    offset LinkName                         ; pszFileName
        push    ds
        push    offset LinkHandle                       ; ppshfFileHandle
        push    ds
        push    offset BytesWritten                     ; pActionTaken
        push    DWORD PTR 0                             ; ulFileSize
        push    WORD PTR 0                             ; usFileAttribute
        push    WORD PTR  1                             ; Open Flag (RW)
        push    WORD PTR  42h                           ; OpenMode
        push    DWORD PTR 0                             ; reserved = 0
        call    DosOpen
        .286

        mov     ax,LinkHandle                           ; link handle to ax
        jl      OpenError                               ; error if<0

; Now Get the LSL table data for General call entry pt etc
;        @DosDevIOCtl lsltable,lsltable,2,0a1h,[LinkHandle]
        push    ds
        push    offset  lsltable
        push    ds
        push    offset  lsltable
        push    2
        push    0a1h
        push    LinkHandle
        call    DosDevIOCtl

NoError:
        mov     es:[bx].RPI_CodeSegLen, offset Initialize   ; End of code seg
        mov     es:[bx].RPI_DataSegLen, offset LastData     ; End of data seg

InitExit:
        or      byte ptr es:[bx].RP_Status, RP_StatusDone   ; Indicate DONE
        ret

OpenError:
        push    stdout                          ; Write copyright info
        push    ds
        push    offset OpenErrorMsg
        push    OpenErrorMsgLen
        push    ds
        push    offset BytesWritten
        call    DosWrite
        jmp     InitError

InitError:
        mov     es:[bx].RPI_NumberUnits, 0      ; Zero these fields so OS/2
        mov     es:[bx].RPI_CodeSegLen, 0       ;    knows to cancel this
        mov     es:[bx].RPI_DataSegLen, 0       ;    device driver

        mov     byte ptr es:[bx].RP_ErrorCode, 0ch      ; General Failure error
        or      byte ptr es:[bx].RP_Status, RP_StatusError ; Error condition
        jmp     InitExit                        ; **** END ERROR ****

Initialize      ENDP

_TEXT           ENDS

END

;**********************************************************************
;*                       END OF SOURCE CODE                           *
;**********************************************************************

END-------------------

Now all thos who stayed to here, thanks.

But!! What is going wrong? As far as I can tell it should work. But it just
locks my system up instead. Can anyone tell me (Or show me) a way that will
work?

TIA.

-- 
==============================================================================
|  Hamish Marson   <h.marson@waikato.ac.nz>                             OS/2 |
|  Programmer (n/5), School of Computing and Mathematical Sciences           | 
|  University of Waikato,                                                    |
|  Hamilton, New Zealand.                                                    |
|Disclaimer:  Anything said in this message is the personal opinion of the   |
|             finger hitting the keyboard & doesn't represent my employers   |
|             opinion in any way. (ie we probably don't agree)               |
==============================================================================
  Q. If Nuclear Tests are so safe, why don't the French do them under Paris?
Technical Details
Message-ID: <1992Aug11.134013.10001@waikato.ac.nz>
Path: arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!sdd.hp.com!wupost!waikato.ac.nz!hamish

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!sdd.hp.com!wupost!waikato.ac.nz!hamish
From: hamish@waikato.ac.nz
Newsgroups: comp.os.os2.programmer,comp.sys.novell
Subject: ODI Interface problems
Message-ID: <1992Aug11.134013.10001@waikato.ac.nz>
Date: 11 Aug 92 13:40:12 +1200
Organization: University of Waikato, Hamilton, New Zealand
Lines: 593