comment #**********************************************************************
/* $Id: dosx.ah 1.14 93/01/06 15:11:54 rwm Exp $ */

DOSX.AH - 386|DOS-Extender Interface Definitions

/************************************************************************/
/*	Copyright (C) 1986-1988 Phar Lap Software, Inc.			*/
/*	Unpublished - rights reserved under the Copyright Laws of the	*/
/*	United States.  Use, duplication, or disclosure by the 		*/
/*	Government is subject to restrictions as set forth in 		*/
/*	subparagraph (c)(1)(ii) of the Rights in Technical Data and 	*/
/*	Computer Software clause at 252.227-7013.			*/
/*	Phar Lap Software, Inc., 60 Aberdeen Ave., Cambridge, MA 02138	*/
/************************************************************************/

REVISION LOG

Rev. 1.00, JMB, 05-May-88	File creation date.

	FILE DESCRIPTION

This file contains the assembly language definitions for the interface
between 386|DOS-Extender and an application program.

#******************************************************************************
;
; 386|DOS-Extender system call numbers
;
DX_RESET_DATA	equ	2501h	;/* Reset DOS-Extender data structures */
DX_PMIV_GET	equ	2502h	;/* Get protected mode interrupt */
DX_RMIV_GET	equ	2503h	;/* Get real mode interrupt */
DX_PMIV_SET	equ	2504h	;/* Set protected mode interrupt */
DX_RMIV_SET	equ	2505h	;/* Set real mode interrupt */
DX_APMIV_SET	equ	2506h	;/* Set both vecs to get control in prot mode 
DX_RPMIV_SET	equ	2507h	;/* Get both interrupts separately */
DX_TOLINEAR	equ	2508h	;/* Get linear base address */
DX_TOPHYS	equ	2509h	;/* Convert a linear address to physical */
DX_MAP_PHYS	equ	250Ah	;/* Map physical memory to the end of seg
DX_HWIV_GET	equ	250Ch	;/* Get hardware interrupt vector base */
DX_RMLINK_GET	equ	250Dh	;/* Get real mode link information */
DX_REAL_CALL	equ	250Eh	;/* Call a real mode procedure */
DX_TOREAL	equ	250Fh	;/* Convert prot mode address to real addr
DX_REAL_REGCALL equ	2510h	;/* Call a real mode proc with register args
DX_REAL_INT	equ	2511h	;/* Issue a real mode int with register args
DX_DBG_LOAD	equ	2512h	;/* Load a program for debugging */
DX_SEG_ALIAS	equ	2513h	;/* Alias a segment */
DX_SEGATTR_SET	equ	2514h	;/* Set segment attributes */
DX_SEGATTR_GET	equ	2515h	;/* Get segment attributes */
DX_LDTMEM_FREE	equ	2516h	;/* Free all memory owned by LDT */
DX_DBUFF_GET	equ	2517h	;/* Get info on DOS data buffer */
DX_SEGMOV_HAND	equ	2518h	;/* Specify handler for moved segments */
DX_MEMERR_GET	equ	2519h	;/* Get additional memory error info */
DX_LOCK_PAGE	equ	251Ah	;/* Lock pages in memory */
DX_UNLOCK_PAGE	equ	251Bh	;/* Unlock pages in memory */
DX_PAGE_FREE	equ	251Ch	;/* Free physical memory pages */
DX_PTE_READ	equ	251Dh	;/* Read page table entry */
DX_PTE_WRITE	equ	251Eh	;/* Write page table entry */
DX_PTE_XCHG	equ	251Fh	;/* Exchange page table entries */
DX_VM_STATS	equ	2520h	;/* Get memory statistics */
DX_XMEM_LIMIT	equ	2521h	;/* Limit program's extended memory usage */
DX_PGFLT_HAND	equ	2522h	;/* Specify alternate page fault handler */
DX_OSWSP_HAND	equ	2523h	;/* Specify out-of-swap-space handler */
DX_PGREPL_HAND	equ	2524h	;/* Specify page replacement handlers */
DX_CMEM_LIMIT	equ	2525h	;/* Limit program's conventional memory usage 
DX_CONFIG_INF	equ	2526h	;/* Get Configuration Information */
DX_DBG_FLAGS	equ	2527h	;/* Set debug flags */
DX_CC_RDREGS	equ	2528h	;/* Read registers after Ctrl/C interrupt*/
DX_LOAD_EXP	equ	2529h	;/* Load Flat Model EXP file **/
DX_DBG_NEWLD	equ	252Ah	;/* New load pgm for debug 
DX_MEM_MGT	equ	252Bh	;/* Memory region page management */
DX_ADD_UNMAP	equ	252Ch	;/* Add unmapped pages at end of segment */
DX_CLOSE_VMH	equ	252Dh	;/* Close VMM file handle */
DX_VMM_PARAMS	equ	252Eh	;/* Get/Set VMM parameters */
DX_WR_PAGELOG	equ	252Fh	;/* Write record to VMM page log file */
DX_SET_DOSBUF	equ	2530h	;/* Set size of data buffer used for DOS calls
DX_RW_LDTDESC	equ	2531h	;/* Read/Write LDT descriptor */
DX_PMEXC_GET	equ	2532h	;/* Get prot mode processor exception vector */
DX_PMEXC_SET	equ	2533h	;/* Set prot mode processor exception vector */
DX_IF_GET	equ	2534h	;/* Get interrupt flag */
DX_SR_RW	equ	2535h	;/* Read/Write System Registers */
DX_MEM_USAGE	equ	2536h	;/* Min/Max Ext/Conv Memory Usage */
DX_REAL_ADDB	equ	2537h	;/* Allocate DOS memory above DOS Data Buffer
DX_SWI_RDREGS equ	2538h  ;/* Read PM regs after a SW interrupt */
DX_GET_HDROFF equ	2539h	;/* Get Offset of EXP file header */
DX_MSEG_FAILH equ	253Ah	;/* Install Mod. Segment Failure Handler */
DX_TOREAL_JMP equ	253Bh  ;/* Jump to real mode code, no context saved */
DX_SHRINK_SWAP	equ	253Ch	; shrink size of 386|VMM swap file
DX_RW_IDTDESC	equ	253Dh	; read/write IDT descriptor
DX_PROC_MFREE	equ	253Eh	;/* Free process LDT resources */
DX_REAL_ALLOC	equ	25C0h	;/* Allocate real mode memory */
DX_REAL_FREE	equ	25C1h	;/* Release real mode memory */
DX_REAL_RESIZE	equ	25C2h	;/* Change size of a real mode memory block
DX_EXEC_SPEC	equ	25C3h	;/* Special program execute call */

;
; 386|DOS-Extender error codes
;
_DXE_LDT_SIZE	equ	128	; LDT buf too small in load for debug call */
_DXE_BAD_PARAM	equ	129	; Bad parameter passed in to system call */
_DXE_NOT_DPMI	equ	130	; Operation not supported under this */
				; DPMI implementation */
_DXE_DBG_NOSAV	equ	131	; Register saving for debuggers not enabled */
_DXE_DBG_NOREG	equ	132	; Register buffer for debuggers is empty */
_DXE_NO_PAGELOG	equ	133	; Attempt to write to VMM page log file */
				; when no file exists */
_DXE_MAX_VMH	equ	134	; Maximum number of 386|VMM file handles */
				; are already allocated */

;
; Parameter block used for Call through from real to protected mode
; system service.  (Documented in Get Real Mode Link Information system
; call 250Dh)
;
PMC_BLK	struc
	PMC_DS	dw	?	; value to load into DS
	PMC_ES	dw	?	; value to load into ES
	PMC_FS	dw	?	; value to load into FS
	PMC_GS	dw	?	; value to load into GS
PMC_BLK	ends

;
; Parameter block passed to Call Real Mode Procedure system call (2510h)
;
RMC_BLK	struc
	RMC_DS	dw	?	; real mode DS value
	RMC_ES	dw	?	; real mode ES value
	RMC_FS	dw	?	; real mode FS value
	RMC_GS	dw	?	; real mode GS value
	RMC_EAX	dd	?	; real mode EAX value
	RMC_EBX	dd	?	; real mode EBX value
	RMC_ECX	dd	?	; real mode ECX value
	RMC_EDX	dd	?	; real mode EDX value
RMC_BLK	ends

;
; Parameter block passed to Issue Real Mode Interrupt system call (2511h)
;
RMI_BLK	struc
	RMI_INUM dw	?	; interrupt to issue
	RMI_DS	dw	?	; real mode DS value
	RMI_ES	dw	?	; real mode ES value
	RMI_FS	dw	?	; real mode FS value
	RMI_GS	dw	?	; real mode GS value
	RMI_EAX	dd	?	; real mode EAX value
	RMI_EDX	dd	?	; real mode EDX value
RMI_BLK	ends

;
; Parameter block passed to Exec system calls (AH=4B or AX=25C3)
;
EXEC_BLK struc
	EX_EOFF dd ?		; Pointer to environment string
	EX_ESEG dw ?			;
	EX_COFF dd ?		; Pointer to command tail string
	EX_CSEG dw ?			;
EXEC_BLK ends

;
; Parameter block passed to Load Pgm for Debug system call (2512)
;
LDDBG_BLK struc
	db (size EXEC_BLK) dup (?) ; same as EXEC parameter block
	EX_LOFF	dd	?	; Pointer to LDT buffer to fill in
	EX_LSEG	dw	?		;
;
; Outputs: Child program's important values.
;
	LD_REAL_PSP dw	?	; program's real mode PSP segment address
	LD_PROTF dw	?	; 1 ==> prot mode pgm, 0 => real mode pgm
	LD_EIP	dd	?	; initial register values
	LD_CS	dw	?		;
	LD_ESP	dd	?		;
	LD_SS	dw	?		;
	LD_DS	dw	?		;
	LD_ES	dw	?		;
	LD_FS	dw	?		;
	LD_GS	dw	?		;
LDDBG_BLK ends

;
; Data structure for load EXP file system call (2529h)
;
LDEXP_BLK struc
	LX_EIP	dd	?	; initial EIP
	LX_CS	dw	?	; initial CS
	LX_ESP	dd	?	; initial ESP
	LX_SS	dw	?	; initial SS
	LX_DS	dw	?	; initial DS
	LX_ES	dw	?	; initial ES
	LX_FS	dw	?	; initial FS
	LX_GS	dw	?	; initial GS
	LX_MINSIZE dd	?	; min size of pgm segment
	LX_EXTRAMEM dd	?	; amt of extra mem allocated 
	; from here to LDEXP_SIZE zeroed
LDEXP_BLK ends
LDEXP_SIZE equ	64	; size of load EXP param block, in bytes

;
; Data struct for info returned by Read Regs From Int (2528h, 2538h).
;
SWI_REGS struc
		dw	?	; unused, not modified
		dd	?	; unused, not modified
		dw	?	; unused, not modified
	SWI_EAX	dd	?
	SWI_EBX	dd	?
	SWI_ECX	dd	?
	SWI_EDX	dd	?
	SWI_ESI	dd	?
	SWI_EDI	dd	?
	SWI_EBP	dd	?
	SWI_ESP	dd	?
	SWI_CS	dw	?
	SWI_DS	dw	?
	SWI_SS	dw	?
	SWI_ES	dw	?
	SWI_FS	dw	?
	SWI_GS	dw	?
	SWI_EIP	dd	?
	SWI_EFLAGS dd	?
SWI_REGS ends

;
; Data structure pointed to by DS:ESI on Map Data File at Offset call
; (system call 252Bh, subfunction 11)
;
MAP_FILE struc
	MF_STARTOFFS dd	?	; starting BYTE offset to map in file */
	MF_ACCESS dd	?	; file access and sharing mode for file open*/
MAP_FILE ends

;
; Data struct for read/write system regs (2535h).
;
SYS_REGS struc
	SR_CR0	dd	?
	SR_DR0	dd	?
	SR_DR1	dd	?
	SR_DR2	dd	?
	SR_DR3	dd	?
		dd	?
		dd	?
	SR_DR6	dd	?
	SR_DR7	dd	?
		dd	?
		dd	?
		dd	?
SYS_REGS ends

;**************************************************************
; Interrupt stack frame
;**************************************************************
INT_CR2 equ	(dword ptr 56[esp])	; CR2 at time of interrupt
INT_INUM equ	(dword ptr 52[esp])	; interrupt number
INT_FL equ	(dword ptr 48[esp])	; flag bits
	IFL_RMODE equ	00000001h		; int occurred in real mode
	IFL_LDSREGS equ	00000002h		; load seg regs on return
INT_GS equ	(dword ptr 44[esp])	; GS at time of interrupt
INT_FS equ	(dword ptr 40[esp])	; FS at time of interrupt
INT_DS equ	(dword ptr 36[esp])	; DS at time of interrupt
INT_ES equ	(dword ptr 32[esp])	; ES at time of interrupt
INT_SS equ	(dword ptr 28[esp])	; SS:ESP at time of interrupt
INT_ESP equ	(dword ptr 24[esp])		;
INT_EFLAGS equ	(dword ptr 20[esp])	; EFLAGS at time of interrupt
INT_CS equ	(dword ptr 16[esp])	; CS:EIP at time of interrupt
INT_EIP equ	(dword ptr 12[esp])		;
INT_DOSX_EFL equ (dword ptr 8[esp])	; return stack frame in
INT_DOSX_CS equ	(dword ptr 4[esp])		; 386|DOS-Extender handler
INT_DOSX_EIP equ (dword ptr [esp])		; DO NOT MODIFY
; for exceptions 8 and 10-14, there is also an error code 

;**************************************************************
; segment selectors in DOS-Extender descriptor tables
;**************************************************************
;
; Bit which indicates LDT vs. GDT selector
;
SEL_LDT	equ 0004h		; table indicator; 0 ==> GDT, 1 ==> LDT

;
; GDT selectors
;
SS_NULL		equ	0000h	; system null segment selector
SS_LDT		equ 	0028h	; LDT system segment
SS_DLDT		equ	0030h	; data segment mapping the LDT
SS_DGDT		equ	0038h	; data segment mapping the GDT
SS_DIDT		equ	0050h	; data segment mapping the IDT
SS_TSS		equ	0080h	; DOS-X TSS system segment
SS_DTSS		equ	0088h	; data segment mapping the DOS-X TSS
SS_PGTAB	equ	00D0h	; page table segment
SS_PTINF	equ	00D8h	; page table info

;
; LDT segment selectors
;
SS_CODE		equ	0008h or SEL_LDT ; User code segment
SS_DATA		equ	0010h or SEL_LDT ; User data segment
SS_SCREEN	equ	0018h or SEL_LDT ; User text screen segment
SS_PSP		equ	0020h or SEL_LDT ; User PSP
SS_ENV		equ	0028h or SEL_LDT ; User DOS environment strings
SS_DOSMEM	equ	0030h or SEL_LDT ; Writeable data segment for lower
						; 1 megabyte of memory
SS_1167		equ	0038h or SEL_LDT ; Weitek 1167, 3167, 4167 coprocessor
SS_WEITEK	equ	0038h or SEL_LDT ; Weitek 1167, 3167, 4167 coprocessor
SS_GRAPHICS	equ	0040h or SEL_LDT ; User graphics screen segment
SS_CYRIX	equ	004Ch or SEL_LDT ; Cyrix EMC87 coprocessor

;****************************************************************
; Page Tables
;****************************************************************
;
; Software-defined page table entry bit definitions for pages marked present.
;
PE_ALLOC equ	00000200h	; page was actually allocated, as opposed to
				; just mapped in with system call 250Ah
PE_LOCKED equ	00000800h	; page is locked in memory

;
; Bit definitions for a page table entry for a swapped page
;
SPE_SWAPPED equ	00000002h	; page is swapped to disk
SPE_ZERO equ	00000004h	; zero page and mark it dirty when it is
				; ref'd, instead of reading it in from disk
SPE_REPLCD equ	00000008h	; page was replaced (kicked out of memory) -
				; used only for statistics keeping

;
; Bit definitions for DWORD entry kept in page table info segment for each
; page table entry, if VM is present
;
PTI_LFUCNT equ	0F0000000h	; LFU count field
PTI_ONDISK equ	00800000h	; page is on disk
PTI_INEXP equ	00400000h	; page is in EXP file, not swap file

;
; Boolean Values
;
TRUE	equ	1			; Boolean 'true' value
FALSE	equ	0			; Boolean 'false' value

;
; FASTMOVS -- macro to copy memory efficiently
;
;	Input:	DS:ESI = source buffer
;		ES:EDI = destination buffer
;		ECX = byte count
;		DF = 0
;
;	Output: ESI,EDI	advanced to one byte past copied data
;		ECX	0
;		EAX	destroyed
;
FASTMOVS macro
	mov	eax,ecx			;; save low 2 bits of ECX
	shr	ecx,2			;; move all doublewords
	rep movsd
	mov	ecx,eax			;; get back low 2 bits
	and	ecx,3
	rep movsb			;; move remaining bytes
	endm

;
; FASTSTOS -- macro to store memory efficiently
;
;	Input:	ES:EDI = destination buffer
;		ECX = byte count
;		AL = byte to store
;		DF = 0
;
;	Output: EDI	advanced to one byte past stored data
;		ECX	0
;		EAX,EDX	destroyed
;
FASTSTOS macro
	mov	ah,al			;; replicate AL throughout EAX
	push	ax
	shl	eax,16
	pop	ax
	mov	edx,ecx			;; save low 2 bits of ECX
	shr	ecx,2			;; store all doublewords
	rep stosd
	mov	ecx,edx			;; get back low 2 bits
	and	ecx,3
	rep stosd			;; store remaining bytes
	endm
