;       SCCSID = @(#)abiosras.asm	6.1 90/11/17
;      SCCSID = @(#)abiosras.asm	1.11 90/03/09
; ****************************************************************************
; *                                                                          *
; *                       IBM/Microsoft Confidential                         *
; *                                                                          *
; *                 Copyright (c) IBM Corporation  1987, 1990                *
; *                 Copyright (c) Microsoft Corp.  1987, 1990                *
; *                           All Rights Reserved                            *
; *                                                                          *
; ****************************************************************************
PAGE    ,132
TITLE   ABIOSRAS - ABIOS Devhlp RAS support routines
NAME    ABIOSRAS

.xlist
.xcref
include dosseg.inc
include basemaca.inc
include osmaca.inc
include devsym.inc
include devhlp.inc
include rasmacro.inc
.cref
.list

        ModName abiosras
        CpuMode 386

IF RAS
        EXTRN   K_S_Systrace:near
        ReferGlobal  RASDevHelpDS,WORD
        ReferGlobal  RASDevHelpDX,WORD
;       This is a summary of the RAS tracing for Devhlp's, pre and post
;       invocation.
;
;          +----------------------------------------------------------+
;          | Major Code  06  - Devhelps                               |
;          |   Pre-Invocation Trace Events                            |
;          +----------------------------------------------------------+
;          |                      |Minor|                             |
;          | Interface Name       | Code|   Parameters Passed         |
;          +----------------------+-----+-----------------------------+
;          | DevHlp_GetLIDEntry   | 12  |  Desired Device ID        W |
;          |                      |     |  Relative Logical ID      W |
;          |                      |     |  Data Seg of DD           W |
;          |                      |     |  Device State             W |
;          +----------------------------------------------------------+
;          | DevHlp_FreeLIDEntry  | 0D  |  LID to release           W |
;          |                      |     |  Data Seg of DD           W |
;          +----------------------------------------------------------+
;          | DevHlp_ABIOSCall     | 01  |  Logical ID               W |
;          |                      |     |  ABIOS Entry Point        W |
;          |                      |     |  ABIOS Request Block     DW |
;          +----------------------------------------------------------+
;          | DevHlp_ABIOSCommonEntry 02 |  ABIOS Entry Point        W |
;          |                      |     |  ABIOS Request Block     DW |
;          +----------------------------------------------------------+
;          | DevHlp_GetDeviceBlock| 10  |  Logical ID               W |
;          |                      |     |  Data Seg of DD           W |
;          +----------------------------------------------------------+
;
;          3.10.2 Devhelps Post-Invocation Trace Events
;
;
;
;          +----------------------------------------------------------+
;          | Major Code  06  - Devhelps                               |
;          |   Post-Invocation Trace Events                           |
;          +----------------------------------------------------------+
;          |                      |Minor|                             |
;          | Interface Name       | Code|   Parameters Passed         |
;          +----------------------+-----+-----------------------------+
;          | DevHlp_GetLIDEntry   | 8012|  return code              W |
;          |                      |     |  LID                      W |
;          +----------------------------------------------------------+
;          | DevHlp_FreeLIDEntry  | 800D|  return code.             W |
;          +----------------------------------------------------------+
;          | DevHlp_ABIOSCall     | 8001|  return code.             W |
;          +----------------------------------------------------------+
;          | DevHlp_ABIOSCommonEntry8002|  return code.             W |
;          +----------------------------------------------------------+
;          | DevHlp_GetDeviceBlock| 8010|  Return code              W |
;          |                      |     |  Real mode pointer        @ |
;          |                      |     |  Protect mode pointer     W |
;          +----------------------------------------------------------+
;

        FARCODE HIGH4
RASLOCKCODE    SEGMENT


;** RAS_dh_GetLIDEntry - perform RAS tracing for GetLIDEntry devhlp
;
;       Sets up parameters on the stack and calls K_S_Systrace
;       to enter parameters into RAS circular buffer.
;
;       ENTRY:  (AL)    = Desired Device ID
;               (BL)    = Relative Logical ID
;               (DS)    = Data Segment of the Requesting Device Driver
;               -- DS is really RASStackDS
;               (DH)    = Device state
;               -- DX is really RASStackEDX
;               (BP)    = Base of entry in DevhlpFuncDisp table in dhrouter.asm
;       EXIT:   none
;
;       USES:   flags

Procedure RAS_dh_GetLIDEntry,near
        ASSUME DS:DOSGROUP,ES:NOTHING,SS:NOTHING

        push    word ptr ss:[esp].RASStackDS
        pop     RASDevHelpDS            ; Device Driver DS

        push    word ptr ss:[esp].RASStackEDX
        pop     RASDevHelpDX            ; Device Driver DX

        push    si
        push    dx
        push    ax
        push    bx
        push    ds

        shr     RASDevHelpDX,8          ;push parms on stack
        push    RASDevHelpDX
        push    RASDevHelpDS
        xor     bh,bh                   ; clear out upper byte
        push    bx
        xor     ah,ah                   ; clear out upper byte
        push    ax

        mov     dx,cs:[ebp].preminor     ; (dx) = Minor Code

        mov     si,sp                   ; point to parameter frame on stack
        push    ss
        pop     ds                      ; (DS:SI) = structure on stack

        mov     al,RAS_MC_DEVHLP        ; (al) = Major Code
        mov     bx,8                    ; 8 bytes of parms.
        call    K_S_Systrace

        pop     ax                      ; clear parms
        pop     bx
        add     sp,4                    ; skip RASDevHelpDS/DX parms

        pop     ds                      ; restore registers
        pop     bx
        pop     ax
        pop     dx
        pop     si
        ret
EndProc RAS_dh_GetLIDEntry


;** RAS_dh_FreeLIDEntry - perform RAS tracing for FreeLIDEntry devhlp
;
;       Sets up parameters on the stack and calls K_S_Systrace
;       to enter parameters into RAS circular buffer.
;
;       ENTRY:  (AX)    = Logical ID to Release
;               (DS)    = Data Segment of the Requesting Device Driver
;               -- DS is really RASStackDS
;               (BP)    = Base of entry in DevhlpFuncDisp table in dhrouter.asm
;       EXIT:   none
;
;       USES:   flags

Procedure RAS_dh_FreeLIDEntry,near
Entry   RAS_dh_GetDeviceBlock
        ASSUME DS:DOSGROUP,ES:NOTHING,SS:NOTHING

        push    word ptr ss:[esp].RASStackDS
        pop     RASDevHelpDS            ; Device Driver DS

        push    si
        push    bx
        push    dx
        push    ds

        push    RASDevHelpDS            ; push parms on stack
        push    ax

        mov     dx,cs:[ebp].preminor     ; (dx) = Minor Code

        mov     si,sp                   ; point to parameter frame on stack
        push    ss
        pop     ds                      ; (DS:SI) = structure on stack

        mov     al,RAS_MC_DEVHLP        ; (al) = Major Code
        mov     bx,4                    ; 4 bytes of parms.
        call    K_S_Systrace

        pop     ax
        add     sp,2                    ; skip RASDevHelpDS/DX parms

        pop     ds                      ; restore regs
        pop     dx
        pop     bx
        pop     si
        ret
EndProc RAS_dh_FreeLIDEntry


;** RAS_dh_ABIOSCall - perform RAS tracing for ABIOSCall devhlp
;
;       Sets up parameters on the stack and calls K_S_Systrace
;       to enter parameters into RAS circular buffer.
;
;       ENTRY:  (AX)    = Logical ID
;               (DH)    = ABIOS Entry Point
;               -- DX is really RASStackEDX
;               (DS:SI) = Pointer to the ABIOS Request Block
;               -- DS is really RASStackDS
;               (BP)    = Base of entry in DevhlpFuncDisp table in dhrouter.asm
;       EXIT:   none
;
;       USES:   flags

Procedure RAS_dh_ABIOSCall,near
        ASSUME DS:DOSGROUP,ES:NOTHING,SS:NOTHING

        push    word ptr ss:[esp].RASStackDS
        pop     RASDevHelpDS            ; Device Driver DS

        push    word ptr ss:[esp].RASStackEDX
        pop     RASDevHelpDX            ; Device Driver DX

        push    bx
        push    dx
        push    ds

        push    RASDevHelpDS            ; push parms on stack
        push    si
        shr     RASDevHelpDX,8          ; put dh in low byte, zero out high byte
        push    RASDevHelpDX
        push    ax

        mov     dx,cs:[ebp].preminor     ; (dx) = Minor Code

        mov     si,sp                   ; point to parameter frame on stack
        push    ss
        pop     ds                      ; (DS:SI) = structure on stack

        mov     al,RAS_MC_DEVHLP        ; (al) = Major Code
        mov     bx,8                    ; 8 bytes of parms.
        call    K_S_Systrace

        pop     ax                      ; clear parms
        add     sp,2                    ; skip RASDevHelpDS/DX parms
        pop     si
        add     sp,2                    ; skip RASDevHelpDS/DX parms

        pop     ds                      ; restore regs
        pop     dx
        pop     bx
        ret
EndProc RAS_dh_ABIOSCall


;** RAS_dh_ABIOSCommonEntry - perform RAS tracing for ABIOSCommonEntry devhlp
;
;       Sets up parameters on the stack and calls K_S_Systrace
;       to enter parameters into RAS circular buffer.
;
;       ENTRY:  (DH)    = ABIOS Entry Point
;               -- DX is really RASStackEDX
;               (DS:SI) = Pointer to the ABIOS Request Block
;               -- DS is really RASStackDS
;               (BP)    = Base of entry in DevhlpFuncDisp table in dhrouter.asm
;       EXIT:   none
;
;       USES:   flags

Procedure RAS_dh_ABIOSCommonEntry,near
        ASSUME DS:DOSGROUP,ES:NOTHING,SS:NOTHING


        push    word ptr ss:[esp].RASStackDS
        pop     RASDevHelpDS            ; Device Driver DS

        push    word ptr ss:[esp].RASStackEDX
        pop     RASDevHelpDX            ; Device Driver DX

        push    ax
        push    bx
        push    dx
        push    ds

        push    RASDevHelpDS            ; push parms on stack
        push    si
        shr     RASDevHelpDX,8          ; put dh into low byte,zero out high by
        push    RASDevHelpDX

        mov     dx,cs:[ebp].preminor     ; (dx) = Minor Code

        mov     si,sp                   ; point to parameter frame on stack
        push    ss
        pop     ds                      ; (DS:SI) = structure on stack

        mov     al,RAS_MC_DEVHLP        ; (al) = Major Code
        mov     bx,6                    ; 6 bytes of parms.
        call    K_S_Systrace

        add     sp,2                    ; skip RASDevHelpDS/DX parms
        pop     si
        add     sp,2                    ; skip RASDevHelpDS/DX parms

        pop     ds                      ; restore regs
        pop     dx
        pop     bx
        pop     ax
        ret
EndProc RAS_dh_ABIOSCommonEntry


;******************* POST INVOCATION CALLS *******************

;** RAS_CFparms_post - perform RAS post-invocation tracing for devhlps
;                      with the carry flag traced
;
;       Calls K_S_Systrace with appropriate major and minor codes
;
;       ENTRY:  (CF) = Return Code
;               (BP) = Base of entry in DevhlpFuncDisp table in devhlp.asm
;
;       EXIT:   none
;
;       USES:   flags
Procedure RAS_CFparameters_post,near
Entry   RAS_dh_FreeLIDEntry_post
Entry   RAS_dh_ABIOSCall_post
Entry   RAS_dh_ABIOSCommonEntry_post
        ASSUME DS:DOSGROUP,ES:NOTHING,SS:NOTHING

        push    ds
        push    si
        push    bx
        push    dx
        push    ax

        setc    al
        movzx   ax,al
        push    ax

        mov     dx,cs:[ebp].postminor     ; (dx) = Minor Code

        mov     si,sp                   ; point to parameter frame on stack
        push    ss
        pop     ds                      ; (DS:SI) = structure on stack

        mov     al,RAS_MC_DEVHLP        ; Major code for devhlps
        mov     bx,2                    ; 2 bytes of parms.
        call    K_S_Systrace

        pop     ax

        pop     ax
        pop     dx
        pop     bx
        pop     si
        pop     ds
        ret
EndProc RAS_CFparameters_post


;** RAS_CFAxparms_post - perform RAS post-invocation tracing for devhlps
;                      with AX and CF traced
;
;       Calls K_S_Systrace with appropriate major and minor codes
;
;       ENTRY:  (CF) = Return Code
;               (AX) = LID
;               (BP) = Base of entry in DevhlpFuncDisp table in devhlp.asm
;
;       EXIT:   none
;
;       USES:   flags
Procedure RAS_CFAxparameters_post,near
Entry   RAS_dh_GetLIDEntry_post
        ASSUME DS:DOSGROUP,ES:NOTHING,SS:NOTHING

        push    ds
        push    si
        push    bx
        push    dx

        push    ax
        jc      rf1
        xor     ax,ax
rf1:    push    ax

        mov     dx,cs:[ebp].postminor     ; (dx) = Minor Code

        mov     si,sp                   ; point to parameter frame on stack
        push    ss
        pop     ds                      ; (DS:SI) = structure on stack

        mov     al,RAS_MC_DEVHLP        ; Major code for devhlps
        mov     bx,4                    ; 4 bytes of parms.
        call    K_S_Systrace

        pop     ax
        pop     ax

        pop     dx
        pop     bx
        pop     si
        pop     ds
        ret
EndProc RAS_CFAxparameters_post


;** RAS_dh_GetDeviceBlock_post - perform RAS post-invocation tracing for devhlp
;                      GetDeviceBlock
;
;       Calls K_S_Systrace with appropriate major and minor codes
;
;       ENTRY:  (CF) = Return Code
;               (AX:BX) = Real mode device block pointer or error
;               (CX:DX) = Protect mode device block pointer
;               (BP) = Base of entry in DevhlpFuncDisp table in devhlp.asm
;
;       EXIT:   none
;
;       USES:   flags
Procedure RAS_dh_GetDeviceBlock_post,near
        ASSUME DS:DOSGROUP,ES:NOTHING,SS:NOTHING

        push    ds
        push    si

        push    cx
        push    dx
        push    ax
        push    bx
        setc    al
        movzx   ax,al
        push    ax

        mov     dx,cs:[ebp].postminor     ; (dx) = Minor Code

        mov     si,sp                   ; point to parameter frame on stack
        push    ss
        pop     ds                      ; (DS:SI) = structure on stack

        mov     al,RAS_MC_DEVHLP        ; Major code for devhlps
        mov     bx,10                   ; 10 bytes of parms.
        call    K_S_Systrace

        pop     ax
        pop     bx
        pop     ax
        pop     dx
        pop     cx

        pop     si
        pop     ds
        ret
EndProc RAS_dh_GetDeviceBlock_post

RASLOCKCODE    ENDS

ENDIF

        END
