;       SCCSID = @(#)errlog.asm 6.2 91/03/18
SCCSID  equ     "@(#)errlog.asm 6.2 91/03/18"
; ****************************************************************************
; *                                                                          *
; *                       IBM/Microsoft Confidential                         *
; *                                                                          *
; *                 Copyright (c) IBM Corporation  1987, 1990                *
; *                 Copyright (c) Microsoft Corp.  1987, 1990                *
; *                           All Rights Reserved                            *
; *                                                                          *
; ****************************************************************************

        PAGE    ,132                    ; (CTRL-OH)   IBM PC PRINTER CONDENSED MODE
;************************* START OF SPECIFICATIONS ***************************
;
;     SOURCE FILE NAME:  ERRLOG.ASM
;
;     DESCRIPTIVE NAME:  Workers for:
;                           DosLogMode
;                           DosGetLogBuffer
;                           DosLogEntry (dh_LogEntry)
;
;     FUNCTION:
;                w_LogMode :  Update Status of a Logging Facility
;
;           w_GetLogBuffer :  Copy a Log buffer
;
;               w_LogEntry :  Add subsystem packets to a log buffer
;
;           KernelLogEntry :  Add Kernel (device driver) packets to log buffer
;
;************************** END OF SPECIFICATIONS ****************************
;
;
.sall
.XLIST

INCL_ERROR_H    EQU     1               ; for error.inc  EQUates
INCL_ERROR2_H   EQU     1               ; for error2.inc EQUates

include dosseg.inc                      ; MUST be first include
include basemaca.inc
include fnotask.inc
include osmaca.inc
include mi.inc
include proc.inc
include bseerr.inc
include struc.inc
include pmode.inc
include infoseg.inc
include mhandle.inc
include filesys.inc
include sem.inc
include errlog.inc
.LIST
        CpuMode 386
        ModName errlog,FNO_ERRLOG_ASM


        EXTRN    SISData:WORD
        EXTRNFAR ProbeBuff                       ; ProbeBuff but don't copy
        EXTRNFAR SuBuff
        EXTRNFAR SemClear
        EXTRNFAR TCYield
        EXTRNFAR CloseSem
        EXTRNFAR OpenSem
        EXTRNFAR SegAlloc
        EXTRNFAR SegFree
        EXTRNFAR SemSet
        EXTRNFAR SemWait
        EXTRNFAR SemRequest
        EXTRNFAR SemHandle
        EXTRNFAR CreateSem

        ReferTask        Pid,WORD
        ReferTask        ptda_module,WORD        ; jrn

;        ReferTask        ptda_pszproc,DWORD

        ReferGlobal      TCResched,BYTE          ; Check for time critical
        ReferGlobal      InterruptLevel,BYTE
        ReferGlobal      _Sis2,BYTE              ; Infoseg copy

                                                 ;
                                                 ; Additions for CP20 DCR 1152
                                                 ; Allocated in dev/devhlp2.asm
                                                 ;
                                                 ;
        ReferGlobal      LogDDCS,WORD            ; CS for LOG$ device driver
        ReferGlobal      LogDDIdc,WORD           ; Offset of LOG$ IDC routine
        ReferGlobal      LogDDDS,WORD            ; DS for LOG$ device driver

        EXTRN32 _SELLdrDesc



        FARCODE HIGH4                ; DCR 996
LOGSWAPCODE  SEGMENT

        ASSUME ds:nothing, es:nothing


BREAK <w_LogEntry - Log packets in circular log buffer>
;*************** START OF SPECIFICATIONS ******************************
;
; SUBROUTINE NAME: w_LogEntry
;
; DESCRIPTIVE NAME: Worker Routine for DosLogEntry
;
; FUNCTION: This routine is called by DosLogEntry for 1.x API callers
;           This calls LOG$ device driver IDC entry point to log the records.
;           The IDC entry variables are setup by dh_LogEntry in dev\devhlp2.asm
;
; ENTRY POINT: w_LogEntry
;    LINKAGE:  CALL near from HIGH4CODE (HYBRID Entry)
;
; INPUT:
;        DI    -  Function code
;              0  -  Reserved
;              1  -  Log Data to error log buffer
;
;        BX:SI -> Data to be placed in log buffer
;
; EXIT-NORMAL:  AX = 0, CF = 0
;
; EXIT-ERROR:   AX = error code, CF = 1
;                    ERROR_LF_INVALID_FUNCTION
;                    ERROR_LF_SUSPENDED
;                    ERROR_LF_NOT_AVAIL
;
; EFFECTS:
;    Uses:  AX, BX, CX, DX, DI, SI, DS, ES, Flags
;
; INTERNAL REFERENCES:
;    ROUTINES: ErrorLogEntry - Log data packets
;              InvalidFunction - Invalid function given
;*************** END OF SPECIFICATIONS ********************************
;
Procedure w_LogEntry,HYBRID


LocalVar logdd,DWORD                             ; Addr of LOG$ IDC
        assume ds:nothing, es:nothing

EnterProc

    SaveReg <ds,es,fs,gs,bx,cx,dx,si,di>

    .386p
    NullContext <fs,gs>,ax              ; zero FS and GS in case we block
    CpuMode reset

        DosContext ds                               ; DOSGROUP

;
; Ensure caller has correct function code
;

      mov ax,ERROR_LF_INVALID_FUNCTION            ; Init Error code
      .if <di eq 1>                               ; Is request OK?
        mov  ax,ERROR_LF_NOT_AVAIL                  ; Assume not available
        test ds:SISData.SIS_SysLog,LF_LOGAVAILABLE  ; Test for available
        .if <nz>                                    ; Is Logging available?

; Make sure logging is enabled, if it is suspended, return an error

          mov ax,ERROR_LF_SUSPENDED                 ; Yes, Init Error code
          test ds:SISData.SIS_SysLog,LF_LOGENABLE
          .if <nz>                                  ; Is logging enabled?
            .if <LogDDCS ne 0>                  ; Is Device CS OK?
              ;
              ; Ensure user buffer ptr is valid
              ;
              push bx                              ; Save ptr to User buffer
              push si                              ;   which is in BX:SI
              mov  cx,26                           ; # Bytes to check
              mov  dh,ACCTYPE_RW                   ; Read Write Acces
              CALLFAR ProbeBuff                    ; BX:SI -> User Buffer
              assume ds:nothing, es:nothing
              pop   si                             ; Restore user's ptr
              pop   bx                             ;
              jnc   ctsd000                        ; Buffer OK
              jmp   tsd001                         ; Error leave quickly
ctsd000:                                           ; Continue Looking at buffer
              ;
              ; Get CS:offset and DS of LOG$ IDC
              ;
              DosContext ds                          ; DOSGROUP
              mov     ax,LogDDIdc                    ; IDC offset
              mov WORD PTR logdd,ax                  ; store IDC offset to call
              mov     ax,LogDDCS                     ; get CS
              mov WORD PTR logdd[2],ax               ; store cs of LOG$
              mov     ax,LogDDDS
              mov     ds,ax                          ; change DS - to LOG$ DS
              ;
              ; Call LOG$ IDC routine with CX=function(type of record)
              ;           ES:BX -> log packet
              ;           Return: AX = 0 or error code
              ;
              mov     es,bx                          ; Set parms for LOG$
              mov     bx,si
              mov     cx,83h                         ; function code for 1.x
                                                     ;   DosLogEntry caller
              call    DWORD PTR [logdd]              ; call using local var(SS)
            .endif
          .endif
        .endif
      .endif

      jmp    log106

tsd001:
       mov  ax,ERROR_LF_NOT_AVAIL              ; Indicate an error
       mov  cx,0                               ; Number of Records Added
log106:
       cmp ax,1                                   ; set carry if AX = zero
       cmc                                        ; reverse carry flag

    RestoreReg <di,si,dx,cx,bx,gs,fs,es,ds>

LeaveProc
      ret                                         ; Return


EndProc  w_LogEntry


LOGSWAPCODE ENDS

; Logging code Segment - Discarded if logging is not requested


        FARCODE HIGH4               ; DCR 996
LOGLOCKCODE  SEGMENT


LOGLOCKCODE  ENDS


        END
