/*static char *SCCSID = "@(#)doshlp.h   6.7 92/03/18";*/
/* SCCSID = @(#)doshlp.h        6.7 92/03/18   */

/*
 * IBM/Microsoft Confidential
 *
 * Copyright (c) IBM Corporation 1987, 1991
 * Copyright (c) Microsoft Corporation 1987, 1991
 *
 * All Rights Reserved
 */

/******************************************************************************
 *
 * Source File: Doshlp.h
 *
 * Description:
 * This file contains macros for doshlp's
 *
 * Entry Points:
 * none
 *
 * External References:
 * none
 *
 ******************************************************************************
 */

// constants for significant memory values
#define _1KB      (1L*1024L)     /* 1 k */
#define _64KB     (64L*_1KB)     /* 64 k */
#define _128KB    (2L*_64KB)     /* 128 k */
#define _640KB    (10L*_64KB)    /* 640 k */
#define _1MEGB    (_1KB*_1KB)    /* 1 m */
#define _4MEGB    (4L*_1MEGB)    /* 4 m */
#define _16MEGB   (16L*_1MEGB)   /* 16 m */
#define _64MEGB   (64L*_1MEGB)   /* 64 m */
#define _4GB      (0L)           /* 4 g (32 bit math wraps) */

// miscellaneous constants (shifting, masking, etc.)
#define PARASHIFT 4         /* paragraph shift count */
#define PARASIZE  (1 << PARASHIFT)    /* bytes in a paragraph */
#define PARAMASK  (PARASIZE - 1)
#define NUMPARAIN64K (1 << (16 - PARASHIFT)) /* paragraphs in 64k */

#define SECTSHIFT 9         /* ASSUMES 512 byte sectors */
#define SECTSIZE  (1 << SECTSHIFT)    /* bytes in a paragraph */
#define SECTMASK  (SECTSIZE - 1)

// size definition for HardwareInterruptFlag table entry
#define HardwareInterruptFlagSize   0x02

// flags for basic machine configurations
// !!IMPORTANT!! These flags should be mirrored to \h\dskinit.h
#define CFG_MCA              0x01
#define CFG_EISA             0x02
#define CFG_ABIOS_SUPPORTED  0x04
#define CFG_ABIOS_PRESENT    0x08
#define CFG_PCI              0x10  /* 83385 */
#define CFG_OEM_ABIOS        0x20  /* D90588 Mfr is OEM, valid if ABIOS supported */
                                   /* D91506 Flip polarity  */
#define CFG_IBM_ABIOS        0000  /* Bit mask, all bits off D91506 */
#define CFG_PENTIUM_CPU      0x40  /* Pentium CPU detected */

#define CFG_PROTECTONLY      0x08

// values for different detailed machine configurations
#define MACH_NONE    0x00      // no specifications made
#define MACH_COMPAQ  0x01      // used for NWD, 256K and Highspeed

// flags for machine features
#define FT_MCA          0x02
#define FT_MCA_AND_AT   0x01

// flags for DosHlp status
#define DHSTAT_DISCARDED    0x01
#define DHSTAT_RELOCATED    0x02
#define DHSTAT_MSG_LOADED   0x04

// equates for interrupt acknowleging
#define PIC1_EOI_MASK   0x60  // specific EOI mask for PIC1
#define PIC2_EOI  0x62  // specific EOI for master on PIC2 EOI
#define DH_IRQ_OUT_OF_RANGE 0x01 // irq eoi reques out of range

// Constants used to clear the NPX 287 exception
#define NPX287_BUSY_PORT    0x0F0   // NPX287 BUSY latch
#define NPX287_REAL_PORT    0x0F1   // NPX287 real/reset port
#define IRQ_NPX       13       // irq 13 for npx exception

// NPX Chip identifer
#define NPX_287 0    // coprocessor is a 287
#define NPX_387 1    // coprocessor is a 387

// equates for modesw vs loadall
#define OFF 0
#define ON  1

// equates for DHConfigAX bit definition
#define CFGAX_NPX_PRESENT   0x80
#define CFGAX_PS2_CENTURY_BYTE  0x10            //64012

// IVT table size
#define IVTLEN (4 * 0x7F)  // 78h entries of 4 bytes


// macro for defining entry in bios doshlp function table

/* ASM
DefDosHlp   MACRO dhfunction
   extrn DH&dhfunction:far
   DHtmp = offset $ - offset DosHlpFunctions
   .errnz   (DHtmp - DosHlp&dhfunction)
   dw DH&dhfunction
   dw DOSHLP_CODESEL
      ENDM
*/

// macro for defining entry in bios doshlp function table for discardable
// DosHlp

/* ASM
DefDiscDosHlp  MACRO dhfunction
   extrn DH&dhfunction:far
   DHtmp = offset $ - offset DosHlpFunctions
   .errnz   (DHtmp - DosHlp&dhfunction)
   dw DH&dhfunction
   dw DOSHLP_CODESEL + 10H
      ENDM
*/

// The following selectors describe the discardable DosHlp code and data

/* ASM
selSysInitCode EQU   110h
selSysInitData EQU   118h
*/

/* ****** Please note - any changes that modify the DosHlpFunction table
          will most likely create a dependency between a certain build of
          the os2ldr and os2krnl.  For this or any such dependancies
          between os2ldr and os2krnl, bump the DOSHLPVERSION. Os2ldr will
          refuse to load a kernel at the wrong level.
          OS/2 2.0 GA      = 4
          OS/2 2.0 Riker I = 4    <-- should have been bumped (ABIOS changes)
          OS/2 2.0 r205 SP = 5    <-- ABIOS 2 drop
          OS/2 2.0 r202 SP = 6    <-- ABIOS 2 not enabled in r202 (today!)
          OS/2 2.x Borg    = 7    <-- ABIOS 2 reenabled, also dump redesign
          OS/2 2.1 Borg    = 8    <-- Extended KernelAccess Table
          OS/2 2.x 4MEG    = 9    <-- Remove DosHlpGetIOPLList
	  OS/2 Warp trapdoor = 10 <-- Add SetDosEnv
	  OS/2 Warp Merlin   = 11 <-- Modified DosHlpSizeMem
   ******
 */
#define DOSHLPVERSION   11

#define TABLE_VERSION_SIZE  2


typedef struct DosHlpFunction {
   unsigned short TableVersion;     // Version of the DosHlp Table
   unsigned long DosHlpInit;     // Initialize Doshlps
   unsigned long DosHlpReboot;      // reboot machine
   unsigned long DosHlpNMI;      // enable/disable NMI
   unsigned long DosHlpSizeMem;     // determine memory size
   unsigned long DosHlpConfig;      // get Device Config Info
   unsigned long DosHlpBaseDDList;  // get table of base device drivers
   unsigned long DosHlpGetDriveParms;  // get disk drive parameters
   unsigned long DosHlpInitSystemDump; // Preprocissing of stand alone dump
   unsigned long DosHlpSystemDump;  // do system stand alone dump
   unsigned long DosHlpReadSectors; // Real mode Read sectors
   unsigned long DosHlpSerInit;     // initialize serial /IO
   unsigned long DosHlpSetBaudRate; // set transmission baud rate
   unsigned long DosHlpSerIn;    // read character from serial port
   unsigned long DosHlpSerOut;      // output character to serial port
   unsigned long DosHlpToneOn;      // turn speaker on
   unsigned long DosHlpToneOff;     // turn speaker off
   unsigned long DosHlpGetMask;     // Get 8259's masks
   unsigned long DosHlpSetMask;     // Set 8259's masks
   unsigned long DosHlpSetRealMask; // Set PIC masks for real mode
   unsigned long DosHlpSetProtMask; // Set PIC masks for prot mode
   unsigned long DosHlpSetDosEnv;   // Setup for transition to dos
   unsigned long DosHlpCallInt10;      // Call Int 10 for video service
   unsigned long DosHlpProtGetMessage; // Get message text
   unsigned long DosHlpRealGetMessage; // Get message text
   unsigned long DosHlpRegisterTmrDD;  // Register Tmr Device Driver
   unsigned long DosHlpTmr16QueryTime; // Get time from Tmr device
   unsigned long DosHlpEnableWatchdogNMI; // Enable Watchdog NMI
   unsigned long DosHlpDisableWatchdogNMI; // Disable watchdog
   unsigned long DosHlpInstallIRET; // install early HW int hdlr
   unsigned long DosHlpDiscard;     // Discard DosHlps

// 32-bit function calls start at this point in DosHlpFunction structure
// The initial value will be an segement:offset pair that will be converted
// to a FLAT 32-bit offset after paging is enabled

   unsigned long DosHlpInitInterrupts; // initialize interrupt system
   unsigned long DosHlpSetIRQMask;  // Mask or Unmask certain IRQ
   unsigned long DosHlpSendEOI;     // Acknowledge interrupt with EOI
   unsigned long DosHlpTmr32QueryTime; // Get time from Tmr device
   unsigned long DosHlpTmrSetRollover; // Set Tmr device Rollover count.
   unsigned long DosHlpInitNPX;     // determine presence of npx and initialize
   unsigned long DosHlpClrBusyNPX;  // clear pal npx busy line
   unsigned long DosHlpAckIntNPX;      // Acknowledge NPX IRQ
   unsigned long DosHlpWaitNPX;     // wait for end of npx instruction
   unsigned long DosHlpValidNPXSwitch; // validate npx context switch
   unsigned long DosHlpVNPXReset;      // virtual NPX reset
   unsigned long DosHlpVNPXClrBusy; // virtual NPX clear busy port
   unsigned long DosHlpWhyNMI;      // return pointer to NMI message
   unsigned long DosHlpAckNMI;      // acknowledge NMI
   unsigned long DosHlpResetWatchdogNMI;  // Reset Watchdog nmi counter
   unsigned long DosHlpDisableCache; // disable cache
   unsigned long DosHlpFindParity;  // find parity
   unsigned long DosHlpEnableCache; // enable cache
   unsigned long DosHlpGetErrorLogPtr; // get error log ptr
   unsigned long DosHlpWriteErrorLog; // write error log
   unsigned long DosHlpReadErrorLog; // read error log
   unsigned long DosHlpResetParity; // reset partiy
};

// macro for defining kernel access table

/* ASM
EndKernelAccessTable MACRO
   KFtmp = offset $ - offset KernelAccessTable
   .errnz   (KFtmp - SIZE KernelAccess)
      ENDM
*/

typedef struct KernelAccess {
   unsigned long KernelAllocGDT;
   unsigned long KernelPhysToGDT;
   unsigned long KernelGotoReal;
   unsigned long KernelGotoProt;
   unsigned long KernelSetSSBase;
   unsigned long KernelIRQRouter;
   unsigned long KernelVirtToLin;
   unsigned short Kernel_IDT;
   unsigned long KernelNMICount;
   unsigned long Kernel_LoaderIOCTLWorker;                  //@V2.0SEN01
   unsigned long KernelSetSSBase1;                          //#94979
};


//
// The following structure is used by the int 15h call (function c7h) to
// determine memory configuration.
//

typedef struct Int15c7Table {
   unsigned short ByteLength;  // bytes of data returned
   unsigned long LocHiMem;     // local memory from 1M - 16M in 1K blocks
   unsigned long LocExMem;     // local memory from 16M - 4G in 1K blocks
   unsigned long SysHiMem;     // system memory from 1M - 16M in 1K blocks
   unsigned long SysExMem;     // system memory from 16M - 4G in 1K blocks
   unsigned long CacHiMem;     // cached memory from 1M - 16M in 1K blocks
   unsigned long CacExMem;     // cached memory from 16M - 4G in 1K blocks
   unsigned long PadHiMem;     // pad memory from 1M - 16M in 1K blocks
   unsigned long PadExMem;     // pad memory from 16M - 4G in 1K blocks
   unsigned short Reserved1[2];// reserved
   unsigned long Reserved2[7]; // reserved
};


//
// The following structure is used by the cgetdhphysmem (in CDOSHLP.C)
// subpart of the getdhphysmem doshlp function in DOSHLP.ASM to pass a
// description of physical memory to whatever calls getdhphysmem
//

#define PHYSMEMARRAYLIMIT 32
struct _PHYSMEMBLOCK {
   unsigned long BlockStartAddr; // flat start address of memory block
   unsigned long BlockByteLength;   // length of memory block in bytes
   unsigned long WhichCPULocal;  // flags -- block is local to which CPU
   unsigned long WhichCPUCached; // flags -- block cached by which CPU
};
typedef struct _PHYSMEMBLOCK PHYSMEMBLOCK;


// macros used in DevHlp Calls in OEMHLP$

#define DHVA_ACCESS_READ   0  // Verify Access Read
#define DHVA_ACCESS_WRITE  1  // Verify Access Write
#define DHPU_ACCESS_EXECUTE   0  // PhysToUVirt Execute access
#define DHPU_ACCESS_FREE   2  // PhysToUVirt free selector

// macros for calling kernel access functions

#define KPG_RING0_CODE     5  // KernelPhysToGDT Ring0 code

// Macro to call a DosHlp 16-bit function for DosHlp 32-bit code

/* ASM
CALLDH16  macro   name        ;; call far32 ptr F16PRE_&name
;;  can't use a plain far call because masm turns it into a 16 bit far call
;;  call  far ptr %F16PRE_&name
    db       MI_LONG_CALL
    CatPrefix <dd offset>, %F16PRE_, <name>
    dw       DOSHLP_CODESEL
endm
*/

// Macro to call a Discardable DosHlp 16-bit function for DosHlp 32-bit code

/* ASM
CALLDDH16  macro    name      ;; call far32 ptr F16PRE_&name
;;  can't use a plain far call because masm turns it into a 16 bit far call
;;  call  far ptr %F16PRE_&name
    db       MI_LONG_CALL
    CatPrefix <dd offset>, %F16PRE_, <name>
    dw       selSysInitCode
endm
*/

// Macro to call devhlp function

/* ASM
Dev_Hlp macro  function
   mov   dl, DevHlp_&function
   call  [DEVHLP]
   endm
*/

// macros for base device driver references

#define IPL_DEPENDENT      1  // For DCR851 - Base Device Drivers can be
#define IPL_INDEPEND    2  // IPL Independent
#define BASEDD_AT    0  // use AT device drivers
#define BASEDD_PS2      1  // PS/2's with ABIOS

// drive parameter save area structure

/* ASM
DHDriveParms   STRUC
   DPCylcount     DW 0  ; Number of cylinders
   DPSPT       DW 0  ; Number of sectors per track
   DPHeads     DW 0  ; Number of heads
   DPPrecomp      DW 0  ; Hard disk precomp cylinder
   DPFlags     DW 0  ; Device flags as defined below
;     xxxxxxx1 = Non-removable media
;     xxxxxx1x = Change line supported
DHDriveParms   ENDS
*/

//*****************************************************************************
//  If the module RASCRV.ASM ever changes the physical location of the  rasdmp
//  variable them this offset must also be changed !!
//*****************************************************************************

#define BOOTOFFSET     0x8b      // offset to bootstrap string

// The following constants describe the use of port 92h which gives
// alternate support of REBOOTING and A20 line toggling

#define ALT_SUPP_PORT      0x92
#define ALT_SUPP_REBOOT    0x01
#define ALT_SUPP_A20    0x02

// the following in the constant for setting an AT class machine to
// HIGH speed through the keyboard (int 16h) interface

#define SETSPEED_HIGH      0x0f002 // F0h - set speed
               // 02h - highest possible speed

// the following are constants for video support

#define _8514_HORZTOTAL    0x02E8       // (W/O)
#define _8514_DSPCTRL      0x22E8       // (W/O)
#define _8514_ADVCTRL      0x4AE8       // (W/O)
#define _8514_ERRORTERM    0x92E8       // suitable for presence test (R/W)
#define _8514_STATUS    0x9AE8       // (R/O)

#define _8514_TEST_VALUE   0x5555
#define _8514_STATUS_ERROR 0x80

#define _8514_APPLY_CRTC_RESET   0x53
#define _8514_REMOVE_CRTC_RESET 0x33
#define _8514_VGA_MODE     0x02
#define _8514_AF_DRAM_REFRESH 0x0a

#define INT10_SETMODE      0x00
#define INT10_WRITETTY     0x0e
#define INT10_QUERYMODE    0x0f

#define VIDEOMODE_CO80     0x003
#define VIDEOMODE_MONO80   0x007
#define VIDEOMODE_MONO640X350X4 0x00F

// The following are definitions for communications via
// the serial communications port(s)

#define COM1_PORT 0x03f8
#define COM2_PORT 0x02f8

#define COM_DAT   0x00
#define COM_IEN   0x01     // interrupt enable
#define COM_IER   0x02     // interrupt ID
#define COM_LCR   0x03     // line control registers
#define COM_MCR   0x04     // modem control register
#define COM_LSR   0x05     // line status register
#define COM_MSR   0x06     // modem status regiser
#define COM_DLL   0x00     // divisor latch least sig
#define COM_DLM   0x01     // divisor latch most sig

//**  equates for 8042
#define KBD_STATUS_PORT 0x64     // 8042 com port
#define PORT_A    0x60     // 8042 data port
#define BUF_FULL  0x2      // 8042 busy bit
#define PORTRESET 0x0F0    // Magic reset value (i.e. bit 0 == 0)

#define BUF_FULL_IN  2     // 8042 input buffer busy bit
#define BUF_FULL_OUT 1     // 8042 output buffer busy bit

#define CLOCK_RATEL  1     // LSW of clock rate
#define CLOCK_RATEH  0x0C200  // MSW of clock rate
#define LC_DLAB   0x80     // divisor latch access bit

//**  Valid baud rates

#define BD_150    150
#define BD_300    300
#define BD_600    600
#define BD_1200   1200
#define BD_2400   2400
#define BD_4800   4800
#define BD_9600   9600
#define BD_19200  19200
#define BD_38400  38400
#define BD_57600  57600
#define BD_115200 115200

//**  OEMBeep equates

#define TIMER_PORT   0x40     // 8254 timer/counter port address
#define SPEAKER_PORT 0x61     // speaker port
#define SPEAKER_MASK 0x03     // speaker enable bits
               //  bit 0 = 8253 Timer 2 Gate Speaker
               //  bit 1 = Speaker Data

#define TIMER_FREQ_HI   0x12     // frequency of timer's oscillator
#define TIMER_FREQ_LO   0x34CF

//**  RTC/CMOS equates

#define CMOS_CTRL    0x70  // RTC/CMOS control port
#define CMOS_DATA    0x71  // RTC/CMOS data port
#define CMOS_REG_B      0x8b  // CMOS register B
#define ENABLE_PERIODIC_TIMER 0x52  // Enable periodic timer interrupt
#define RomDataSeg      0x40  // ROM data (tiled)

//**  equates for NMI hardware
#define NMI_STATUS_PORT    0x61  // IBM AT STATUS PORT
#define NMI_PORT     0x70  // IBM AT NMI disable/enable port
#define ENABLENMI    0x0d  // Enable NMI
#define DISABLENMI      0x8d  // Disable NMI
#define DISABLENMI_REQ     0x80  // Disable NMI request value
#define NMI_IOCHK_CONTROL  0x04  // Assertion of IOCHK
#define NMI_FAILSAFE_CONTROL  0x08  // Parity error from memory

// the following constants are used by the WatchdoNMI handling

#define NWD_MAX_INTERVAL   1000     // interval in milliseconds

// counter programming

#define IT_COUNTER0     0     // select counter 0
#define IT_LSBMSB    0x30     // write LSB, then MSB of count
#define IT_LSB       0x10     // write LSB of count
#define IT_MODE0     0     // select counter mode 0
#define IT_BINARY    0     // select binary counting

// DeskPro constants

#define DP_IT_ICOUNTL      0xFFFF      // lsb of count
#define DP_IT_ICOUNTH      0xFFFF      // msb of count
#define DP_NMI_PERIOD      55    // period in milliseconds
#define DP_FAILSAFE_NMI_OCCURRED 0x80  // mask for detecting watchdog nmi
#define DP_FAILSAFE_NMI_MASK     0x04  // mask watchdog nmi off

#define DP_IT2_C0_COUNT    0x48     // count port for NMI timer
#define DP_IT2_COMMAND     0x4B     // command port for NMI timer

// EISA class constants

#define EISA_IT_ICOUNTL    0xFFFF      // lsb of count
#define EISA_IT_ICOUNTH    0xFFFF      // msb of count
#define EISA_IT_PERIOD     220      // period of nmi timer in milliseconds

#define EISA_IT2_C0_COUNT  0x48     // nmi timer count register
#define EISA_IT2_COMMAND   0x4b     // nmi timer command register

// MCA class constants

#define MCA_IT_ICOUNT      9     // initial count
#define MCA_NMI_PERIOD     500      // period of nmi timer in milliseconds
#define MCA_ARBITRATION_MASK  0x40     // arbitration mask
#define MCA_WATCHDOG_NMI_MASK 0x10     // watchdog nmi bit

#define MCA_TC3_COUNT      0x44     // count port for nmi timer
#define MCA_TC3_COMMAND    0x47     // command port for nmi timer
#define MCA_SYSTEM_CONTROL_PORT_A   0x92  // system control port A
#define MCA_SYSTEM_CONTROL_PORT_B   0x61  // system control port B
#define MCA_ARBITRATION_REG      0x90  // arbitration register

// SetDosEnv defines
#define DosIVTSize	((256 * 4) + 256)   // 256 ivt entries + 40:0  for 100h
