; IBM/Microsoft Confidential
;
; Copyright (c) IBM Corporation 1987, 1989
; Copyright (c) Microsoft Corporation 1987, 1989
;
; All Rights Reserved


;****************************************************************************
;*                                                                          *
;* Source File: dhfixup.inc                                                 *
;*                                                                          *
;* Description:                                                             *
;*      This module has macro and structure support for dhfixup.asm         *
;*                                                                          *
;*                                                                          *
;****************************************************************************

KJMPTYPE        equ     0h
LDBXIMTYPE      equ     1h
RESETNMITYPE    equ     2h
CLEARNMITYPE    equ     3h
TESTWDNMITYPE   equ     4h
PUSHFLATDSTYPE  equ     5h
CMPFLATDSTYPE   equ     6h

FixUpStruc   struc
futype  db      ?               ; Type of operations
fuaddr  df      ?               ; Address to fixup
fusd    dd      ?               ; DWORD information for fixup
fusb    db      ?               ; Byte for padding
FixUpStruc   ends

IODelayFixUpStruc   struc
iofuaddr    dw  ?               ; Offset of Address to fixup
iofusd      db  ?               ; byte information for fixup
iofusb      db  ?               ; Byte for padding
IODelayFixUpStruc   ends



;** Kjmp
;
;   This macro sets up a near 32 jmp to 0, and setup up a fixup record in the
;   BIOFIXUP segment
;

Kjmp macro      fname
        local   a,b

        db      0E9H            ;; near rel32 jmp
a       dd      0
b       label   word

        BIOFIXUP        segment
                db      KJMPTYPE

                dd      offset DGROUP:a
                dw      DOSHLP_DATASEL
                dd      offset DGROUP:b
                db      0              ;; padding
        BIOFIXUP        ends

endm



;** ldirqi
;
;   This macro sets up a mov ebx, 0000000000, and sets up a fixup record in
;   the BIOFIXUP segment
;
;   Entry:
;       irqnum -- number of the irq ebx is being set up for
;

ldirqi macro    irqnum
        local   a

        db      0BBH            ;; mov ebx, immediate word
a       dd      0

        BIOFIXUP        segment
                db      LDBXIMTYPE

                dd      offset DGROUP:a
                dw      DOSHLP_DATASEL

                IF      irqnum gt MAX_IRQ
                    .err
                    %out  ldirqi : invalid irq number &irqnum
                ELSE
                    dd  irqnum * size irqi
                ENDIF

                db      0               ;; padding
        BIOFIXUP        ends

endm



;** resetnmi
;
;    This macro sets up the call for reseting the watchdog nmi counter,
;    for the RTC irq router
;
;    Entry
;       none
;

resetNMI macro
        local a

        db      0E8H            ;; call near 32 bit
a       dd      0
b       label   word
        BIOFIXUP        segment
                db      RESETNMITYPE
                dd      offset DGROUP:a
                dw      DOSHLP_DATASEL
                dd      offset DGROUP:b ;; address of end of call instr
                db      0               ;; pad
        BIOFIXUP        ends

endm



;** clearNMIcount
;
;   This macro clears the system count of NMIs that have occured.  The count
;   is used to determine when interrupts have been off too long
;
;   Entry
;       none

clearNMIcount   macro
        local a

        db      0C7h            ;; mov immediate to memory
        db      05h
a       dd      0
        dd      0

        BIOFIXUP        segment
                db      CLEARNMITYPE
                dd      offset DGROUP:a
                dw      DOSHLP_DATASEL
                dd      0               ;; pad
                db      0               ;; pad
        BIOFIXUP        ends

endm



;** testWDNMIEnabled
;
;    This macro tests to see if the watchdog nmi timer has been enabled.
;
;    Entry
;       none
;
;    Exit
;       zero flag set   -- watchdog nmi enabled
;       zero flag clear -- watchdog nmi not enabled
;

testWDNMIEnabled        macro
        local a

        db      0F6h            ;; test memory, imm
        db      05h
a       dd      0
        db      0FFh            ;; -1

        BIOFIXUP        segment
                db      TESTWDNMITYPE
                dd      offset DGROUP:a
                dw      DOSHLP_DATASEL
                dd      0               ;; pad
                db      0               ;; pad
        BIOFIXUP        ends
endm



;** pushflatds
;
;   This macro pushes the flat ds selector on the stack
;
;   Entry
;       none
;
;   Exit
;       flat ds selector pushed
;

pushflatds      macro
        local   a

        db      068h            ;; push immediate word
a       dd      0

        BIOFIXUP        segment
                db      PUSHFLATDSTYPE
                dd      offset DGROUP:a
                dw      DOSHLP_DATASEL
                dd      0
                db      0
        BIOFIXUP        ends
endm



;** cmpflatds
;
;   This macro compares eax with the flat ds selector
;
;   Entry
;       none
;
;   Exit
;       NZ if ax != flat ds
;       ZR if ax  = flat ds
;

cmpflatds       macro
        local   a

        db      66h             ;; operand override prefix
        db      3Dh             ;; cmp AX,immediate word
a       dw      0

        BIOFIXUP        segment
                db      CMPFLATDSTYPE
                dd      offset DGROUP:a
                dw      DOSHLP_DATASEL
                dd      0
                db      0
        BIOFIXUP        ends
endm

