;       SCCSID = @(#)nmi.asm    6.5 92/03/17
;      SCCSID = @(#)nmi.asm     6.5 92/03/17
PAGE    ,132
NAME    NMI
TITLE   NMI Manager
.286c
        ModName  NMI

;**     NMI
;
;
;       DESCRIPTION
;
;       The NMI Manager is designed to initialize NMI handling
;       on the IBM PC AT, and provides a central location
;       for disable and enable NMI functions.
;
;       NMI occurences are only handled by the NMI Manager in PROTECT MODE
;
;
;       MODIFICATION HISTORY:
;
; @@   05/29/87         CWL                 PTM 4810
;               Changed code to check for IBM 7552 Industrial AT and if found
;               perform enableNMI and disableNMI for that hardware.
;      09/20/88         DEH                 DCR123
;               Changed EnableNMI and DisableNMI to call DosHlpNMI to
;               enable/disable the nmi on a non-abios machine


.xlist
        include dosseg.inc
        include basemaca.inc
        include osmaca.inc
        include struc.inc
        include config.inc                  ;@@ ;need to check for 7552
        include doshlp.inc                      ; needed to call doshlps
        include modesw.inc

.list


        ReferGlobal     Initialize_Flags,BYTE   ;defined by syservin.asm and
        ReferGlobal     ABIOS_present,BYTE      ;will be defined by sysinit
        ReferGlobal     DevConfigTbl        ;@@ ;need to check for 7552


CONSTANTS segment
        extrn   DHF:dword

;       state_nmi moved to sdata.asm for System Anchor Block - f122427

        extrn   state_nmi:byte
CONSTANTS ends

        Extrn   IBMInitNMI:NEAR
        Extrn   IBMEnableNMI:NEAR
        Extrn   IBMDisableNMI:NEAR




NMI_PORT        equ    70H
Enable          equ    0H               ; flag to DosHlpNMI to enable NMI
Disable         equ    80H              ; flag to DosHlpNMI to disable NMI





          FARCODE INIT
INITCODE segment

ASSUME  DS:CONSTANTS



;/********************** START OF SPECIFICATIONS *********************/
;/*                                                                  */
;/* SUBROUTINE NAME:  InitNMI                                        */
;/*                                                                  */
;/* DESCRIPTIVE NAME:  Initialize NMI Manager                        */
;/*                                                                  */
;/* FUNCTION: This routine is called by SYSINIT to initialize        */
;/*           the NMI Manager.                                       */
;/*                                                                  */
;/* NOTES:                                                           */
;/*         Protect Mode only  (System Initialization time)          */
;/*                                                                  */
;/* ENTRY POINT: InitNMI                                             */
;/*    LINKAGE: Call Near                                            */
;/*                                                                  */
;/* INPUT:                                                           */
;/*      none                                                        */
;/*                                                                  */
;/* EXIT-NORMAL:   cf = 0                                            */
;/*                ax = 0                                            */
;/*                                                                  */
;/* EXIT-ERROR:    cf = 1  Unable to initialize NMI Handler          */
;/*                        (ABIOS initialization error for NMI)      */
;/*                ax =    Error_Cannot_Init_NMI                     */
;/* EFFECTS:                                                         */
;/*      All registers saved except AX                               */
;/*                                                                  */
;/* INTERNAL REFERENCES:                                             */
;/*                                                                  */
;/*      none                                                        */
;/*                                                                  */
;/* EXTERNAL REFERENCES:                                             */
;/*                                                                  */
;/*                ABIOS_present                                     */
;/*                                                                  */
;/*                                                                  */
;/*    ROUTINES:                                                     */
;/*                IBMInitNMI                                        */
;/*                                                                  */
;/*********************** END OF SPECIFICATIONS **********************/

Procedure  InitNMI

        push    ds
        DosContext      <ds>

        .if    <ABIOS_present eq 0>     ; If ABIOS is not present, no need
                                        ; for further processing.
          clc                             ; Tell SysInit we're ok
          mov     ax,0

        .else

          Call  IBMInitNMI
          jc    in20

        .endif

        DosContext      <ds>
        or      Initialize_Flags,MASK NMI_Initialized

in20:
        pop     ds
        ret                              ; return to SysInit


EndProc    InitNMI


INITCODE ends

        FARCODE LOW
CODE SEGMENT

ASSUME  DS:CONSTANTS

;/********************** START OF SPECIFICATIONS *********************/
;/*                                                                  */
;/* SUBROUTINE NAME:  EnableNMI                                      */
;/*                                                                  */
;/* DESCRIPTIVE NAME:  Enable NMI                                    */
;/*                                                                  */
;/* FUNCTION:  This routine enables the maskable events of NMI at    */
;/*            the hardware when ABIOS is not in the system.         */
;/*                                                                  */
;/* NOTES:  NONE                                                     */
;/*                                                                  */
;/* ENTRY POINT: EnableNMI                                           */
;/*    LINKAGE: Hybrid                                               */
;/*             Call Near (When called from within DOSGROUP)         */
;/*             Call Far  (When called from another segment)         */
;/*                                                                  */
;/* INPUT:                                                           */
;/*      none                                                        */
;/*                                                                  */
;/* EXIT-NORMAL:  CF = 0                                             */
;/*                                                                  */
;/* EXIT-ERROR:   CF = 1  Unable to complete enable operation        */
;/*                                                                  */
;/* EFFECTS:                                                         */
;/*     none                                                         */
;/*                                                                  */
;/* INTERNAL REFERENCES:                                             */
;/*                                                                  */
;/*     none                                                         */
;/*                                                                  */
;/*    ROUTINES:                                                     */
;/*     none                                                         */
;/*                                                                  */
;/* EXTERNAL REFERENCES:                                             */
;/*                                                                  */
;/*               ABIOS_present                                      */
;/*                                                                  */
;/*    ROUTINES:                                                     */
;/*                                                                  */
;/*               IBMEnableNMI                                       */
;/*               DosHlpNMI                                          */
;/*                                                                  */
;/*********************** END OF SPECIFICATIONS **********************/


Procedure  EnableNMI,<hybrid,far16>

        SaveReg <ax,dx,si,ds>
        DosContext <ds>

        .if    <ABIOS_present eq 1> and       ; Is Abios present?
        .if <BIT Initialize_Flags and <MASK NMI_Initialized>> ;NMI Initialized

          call    IBMEnableNMI            ; Yes, use ABIOS routines.

        .else
; This section of code can now be found in bios/dhmodesw.asm dhnmi

          mov     ax, Enable              ; enable NMI,
                                          ; do not set parity and IO Chk
          call    DHF.DosHlpNMI

        .endif

        DosContext <ds>
        mov     ds:[state_nmi],1        ; set state flag
        RestoreReg <ds,si,dx,ax>
        ret


EndProc    EnableNMI

;/********************** START OF SPECIFICATIONS *********************/
;/*                                                                  */
;/* SUBROUTINE NAME:  DisableNMI                                     */
;/*                                                                  */
;/* DESCRIPTIVE NAME:  Disable NMI                                   */
;/*                                                                  */
;/* FUNCTION:  This routine disables the maskable events of NMI at   */
;/*            the hardware when ABIOS is not in the system.         */
;/*                                                                  */
;/* ENTRY POINT: DisableNMI                                          */
;/*    LINKAGE:  Hybrid                                              */
;/*              Call Near (When called from within DOSGROUP)        */
;/*              Call Far  (When called from another segment)        */
;/*                                                                  */
;/* INPUT:                                                           */
;/*      none                                                        */
;/*                                                                  */
;/* EXIT-NORMAL:  CF = 0                                             */
;/*                                                                  */
;/* EXIT-ERROR:   CF = 1  Unable to complete disable operation       */
;/*                                                                  */
;/* EFFECTS:                                                         */
;/*      none                                                        */
;/*                                                                  */
;/* INTERNAL REFERENCES:                                             */
;/*                                                                  */
;/*               Disable                                            */
;/*                                                                  */
;/*    ROUTINES:                                                     */
;/*      none                                                        */
;/*                                                                  */
;/* EXTERNAL REFERENCES:                                             */
;/*                                                                  */
;/*               ABIOS_present                                      */
;/*                                                                  */
;/*    ROUTINES:                                                     */
;/*               IBMDisableNMI                                      */
;/*               DosHlpNMI                                          */
;/*                                                                  */
;/*********************** END OF SPECIFICATIONS **********************/


Procedure  DisableNMI,<hybrid,far16>

        SaveReg <ax,dx,si,ds>
        DosContext <ds>

        .if    <ABIOS_present eq 1> and       ; Is Abios present?
        .if <BIT Initialize_Flags and <MASK NMI_Initialized>> ;NMI Initialized

          call    IBMDisableNMI

        .else                             ; Yes, use ABIOS routines.

; This section of code can now be found in bios/dhmodesw.asm dhnmi

          mov     al, Disable
          call    DHF.DosHlpNMI

        .endif

        DosContext <ds>
        mov     ds:[state_nmi],0             ; clear state flag
        RestoreReg <ds,si,dx,ax>
        ret

EndProc    DisableNMI

CODE    ENDS











        END
