Tvùrce webu je i pro tebe! Postav tøeba web. Bez grafika. Bez kodéra. Hned.
wz

INCLUDE

Includes

ALARM.INC - Alarm


; =============================================================================
;
;                              Litos - Alarm
;
; =============================================================================

; ------------- Alarm

struc		ALARM

		resb	LIST_size	; 0: link to list (empty = expired)
ALARM_Expire:	resd	2		; 8: system time of alarm expiration
ALARM_Repeat:	resb	7		; 10h: repeat interval (0=none)
ALARM_Level:	resb	1		; 17h: current level in alarm list
ALARM_Func:	resd	1		; 18h: callback function
					;	INPUT:	EBX = alarm structure
					;		ECX = user data
					;		EDI:ESI = system time
					;	DESTROYS: EAX..EBP
					;	NOTES:	Can enable interrupts.
					;     It can safely delete alarm entry.
ALARM_Data:	resd	1		; 1Ch: user data

endstruc				; size 20h = 32 bytes

BUFFER.INC - Buffer array


; =============================================================================
;
;                              Litos - Buffer array
;
; =============================================================================

; ------------- Buffer array head

struc		BUFHEAD

		resb	LIST_size	; 0: list of free buffer entries
BUFH_Lock:	resb	SPINLOCK_size	; 8: lock of buffer array
BUFH_EntrySize:	resd	1		; 0Ch: size of buffer entry (min. 8)
BUFH_BlockSize:	resd	1		; 10h: size of block (power of 2)
BUFH_BlockMask:	resd	1		; 14h: block mask (to get block head)
BUFH_Entries:	resd	1		; 18h: number of entries per block
BUFH_Reserve:	resd	1		; 1Ch: reserved block (NULL=none)

endstruc				; size 20h = 32 bytes

; ------------- Buffer block

struc		BUFBLOCK

BUFB_Used:	resd	1		; 0: counter of used buffers
		resd	1		; 4: ...padding
BUFB_Data:				; 8: first buffer entry

endstruc				; size of head: 8 bytes

CALENDAR.INC - Calendar, date and time


; =============================================================================
;
;                       Litos - Calendar, date and time
;
; =============================================================================

; Julian period is 2518277472000000000 nanoseconds (e.g. 7980 years).

; ------------- System time structure

struc		SYSTIME

SYSTIME_100NSec:resd	1		; 0: 100-nanoseconds (0 to 9'999'999)
SYSTIME_Sec:	resb	1		; 4: second (0 to 59)
SYSTIME_Min:	resb	1		; 5: minute (0 to 59)
SYSTIME_Hour:	resb	1		; 6: hour (0 to 23)
SYSTIME_DayWeek:resb	1		; 7: day of week (0=Sunday..6=Saturday)
SYSTIME_Day:	resb	1		; 8: day in month (1 to 31)
SYSTIME_Month:	resb	1		; 9: month (1 to 12)
SYSTIME_Year:	resw	1		; 0Ah: year (-4712 to +3268)
					; year > 0 is CE, year <= 0 is "1-BCE"
					; (e.g. 0 is 1 BCE, -1 is 2 BCE, ...)
					; (CE="Common Era" or AD="Anno Domini",
					;     BCE="Before the Common Era" or
					;     BC="Before Christ"
SYSTIME_DayYear:resw	1		; 0Ch: day in year (0 to 365)
SYSTIME_Week:	resb	1		; 0Eh: week (1 to 53)
SYSTIME_Flags:	resb	1		; 0Fh: flags
					;	B0: leap year,366 days else 365
					;	    (year 1582 has 355 days)
					;	B1: Gregorian calendar
					;	B2: 53 weeks (else 52)
					;	    (year 1582 has 51 weeks)
					;	B3: last week of previous year
					;	    (week=51 to 53, use year-1)
					;	B4: first week of next year
					;	    (week=1, use year+1)

endstruc				; size 16 bytes

CHARSET.INC - Character sets


; =============================================================================
;
;                           Litos - Character sets
;
; =============================================================================

FONTMAX		EQU	267fh		; maximal font value
FONTMAP		EQU	(FONTMAX/256+1)	; number of mapping pages

; ------------- Character set

struc		CHARSET

CHSET_CodePage:	resd	1		; 0: code page
CHSET_Flags:	resd	1		; 4: flags (see below)
CHSET_ToUni:	resd	1		; 8: table to Unicode
CHSET_FromUni:	resd	1		; 0Ch: table from Unicode
CHSET_Capital:	resd	1		; 10h: table to capital characters
CHSET_Small:	resd	1		; 14h: table to small characters
CHSET_ReadChar:	resd	1		; 18h: read character from buffer
					;	INPUT:	EBX = character set
					;		ECX = remaining bytes
					;		EDX = invalid char.
					;		ESI = source buffer
					;	OUTPUT:	EAX = Unicode char
					;		ECX = next remaining
					;		ESI = next source
CHSET_WriteChar:resd	1		; 1Ch: write character into buffer
					;	INPUT:	EAX = Unicode char
					;		EBX = character set
					;		EDX = invalid char.
					;		EDI = dest. buffer
					;		EBP = remaining bytes
					;	OUTPUT:	EDI = next destination
					;		EBP = next remaining
					;	DESTROYS: EAX

endstruc				; size 20h = 32 bytes

; ------------- Flags

CHSET_MBYTE	EQU	B0		; multibyte character set

; ------------- Supported code pages

				; special single byte codes
CP_ASCII	EQU	0		; ASCII
CP_DEC		EQU	1		; DEC VT100 graphics
				; OEM Codepages (DOS)
CP_IBM437	EQU	437		; IBM-437 (United States)
CP_IBM720	EQU	720		; Asmo-720 (Arabic)
CP_IBM737	EQU	737		; IBM-737 (Greek)
CP_IBM775	EQU	775		; IBM-775 (Baltic)
CP_IBM850	EQU	850		; IBM-850 (Latin 1, West Europe)
CP_IBM852	EQU	852		; IBM-852 (Latin 2, Central European)
CP_IBM855	EQU	855		; IBM-855 (Cyrillic, primarily Russian)
CP_IBM857	EQU	857		; IBM-857 (Turkish)
CP_IBM858	EQU	858		; IBM-858 (Latin 1 + Euro)
CP_IBM860	EQU	860		; IBM-860 (Portuguese)
CP_IBM861	EQU	861		; IBM-861 (Icelandic)
CP_IBM862	EQU	862		; IBM-862 (Hebrew)
CP_IBM863	EQU	863		; IBM-863 (French Canadian)
CP_IBM865	EQU	865		; IBM-865 (Nordic)
CP_IBM866	EQU	866		; IBM-866 (Russian)
CP_IBM869	EQU	869		; IBM-869 (Modern Greek)
CP_IBM895	EQU	895		; IBM-895 (Kamenickych, Czech)
				; Windows Single Byte Character Set Codepages
CP_WIN874	EQU	874		; Windows-874 (Thai)
CP_WIN1250	EQU	1250		; Windows-1250 (Central Europe)
CP_WIN1251	EQU	1251		; Windows-1251 (Cyrillic)
CP_WIN1252	EQU	1252		; Windows-1252 (Latin 1 Windows)
CP_WIN1253	EQU	1253		; Windows-1253 (Greek)
CP_WIN1254	EQU	1254		; Windows-1254 (Turkish)
CP_WIN1255	EQU	1255		; Windows-1255 (Hebrew)
CP_WIN1256	EQU	1256		; Windows-1256 (Arabic)
CP_WIN1257	EQU	1257		; Windows-1257 (Baltic)
CP_WIN1258	EQU	1258		; Windows-1258 (Vietnam)
				; ISO Codepages
CP_ISO88591	EQU	28591		; ISO 8859-1 (Latin 1 Western European)
CP_ISO88592	EQU	28592		; ISO 8859-2 (Latin 2 Central European)
CP_ISO88593	EQU	28593		; ISO 8859-3 (Latin 3)
CP_ISO88594	EQU	28594		; ISO 8859-4 (Baltic)
CP_ISO88595	EQU	28595		; ISO 8859-5 (Cyrillic)
CP_ISO88596	EQU	28596		; ISO 8859-6 (Arabic)
CP_ISO88597	EQU	28597		; ISO 8859-7 (Greek)
CP_ISO88598	EQU	28598		; ISO 8859-8 (Hebrew)
CP_ISO88599	EQU	28599		; ISO 8859-9 (Turkish)
CP_ISO885915	EQU	28605		; ISO 8859-15 (Latin 9)
				; multibyte codepages
CP_UTF16LE	EQU	1200		; Unicode UTF-16LE (little endian, PC)
CP_UTF16BE	EQU	1201		; Unicode UTF-16BE (big endian, MAC)
CP_UTF32LE	EQU	12000		; Unicode UTF-32LE (little endian, PC)
CP_UTF32BE	EQU	12001		; Unicode UTF-32BE (big endian, MAC)
CP_UTF8		EQU	65001		; Unicode UTF-8

CP_UNICODE	EQU	CP_UTF32LE	; native Unicode code page

CONSOLE.INC - Console


; =============================================================================
;
;                               Litos - Console
;
; =============================================================================

CONSOLE_NUM	EQU	32		; maximal number of consoles (hardcode)

; ------------- Console interface (primary or secondary)

struc		CONSOLE1

CON_DataWrite:	resd	1		; 0: private data for output interface
CON_Write:	resd	1		; 4: output function
					;	INPUT:	AL = character to write
					;		EBX = private data
CON_DataMWrite:	resd	1		; 8: private data for multi-output
CON_MWrite:	resd	1		; 0Ch: multi-output function
					;	INPUT:	EAX = output buffer
					;		EBX = private data
					;		ECX = number of bytes
CON_DataRead:	resd	1		; 10h: private data for input interface
CON_Read:	resd	1		; 14h: input function (without wait)
					;	INPUT:	EBX = private data
					;	OUTPUT:	AL = character (if NC)
					;		CY = no character ready
					;		  (AL = 0 if CY)
CON_DataKRead:	resd	1		; 18h: private data for input interface
CON_KRead:	resd	1		; 1Ch: key input function (without wait)
					;	INPUT:	EBX = private data
					;	OUTPUT:	EAX = key code (if NC)
					;		CY = no character ready
					;		  (EAX = 0 if CY)
CON_DataMRead:	resd	1		; 20h: private data for multi-input
CON_MRead:	resd	1		; 24h: multi-input function (no wait)
					;	INPUT:  EAX = input buffer
					;		EBX = private data
					;		ECX = buffer size
					;	OUTPUT:	ECX = read bytes
					;		CY = no character ready
					;		  (ECX = 0 if CY)

endstruc				; size 28h = 40 bytes

; ------------- Console interface

struc		CONSOLE

		resb	CONSOLE1_size	; 0: primary interface
CON_2:		resb	CONSOLE1_size	; 28h: secondary interface (echo)

endstruc				; size 50h = 80 bytes

CONSTANT.INC - Constants


; =============================================================================
;
;                             Litos - Constants
;
; =============================================================================

NULL		EQU	0		; invalid pointer

TRUE		EQU	1		; TRUE constant
FALSE		EQU	0		; FALSE constant

; ------------- ASCII control characters

NUL		EQU	0		; Nul (filling) character
SOH		EQU	1		; Start of Header
STX		EQU	2		; Start of Text
ETX		EQU	3		; End of Text
EOT		EQU	4		; End of Transmission
ENQ		EQU	5		; Enquiry
ACK		EQU	6		; Acknowledge
BEL		EQU	7		; Bell
BS		EQU	8		; Backspace
HT		EQU	9		; Horizontal Tabulator
TAB		EQU	HT
LF		EQU	10		; Line Feed
VT		EQU	11		; Vertical Tabulator
FF		EQU	12		; Form Feed
CR		EQU	13		; Carriage Return
SHO		EQU	14		; Shift Out (SO)
SHI		EQU	15		; Shift In (SI)
DLE		EQU	16		; Data Link Escape
DC1		EQU	17		; Device Control 1, XOn
DC2		EQU	18		; Device Control 2, XOff
DC3		EQU	19		; Device Control 3
DC4		EQU	20		; Device Control 4
NAK		EQU	21		; Negative Acknowledge
SYN		EQU	22		; Synchronous Idle
ETB		EQU	23		; End of Transmission Block
CAN		EQU	24		; Cancel
EM		EQU	25		; End of Medium
SUBS		EQU	26		; Substitute (SUB)
ESC		EQU	27		; Escape
FSEP		EQU	28		; File Separator (FS)
GSEP		EQU	29		; Group Separator (GS)
RSEP		EQU	30		; Record Separator (RS)
USEP		EQU	31		; Unit Separator (US)
SPACE		EQU	32		; Space

CSI		EQU	80h+ESC		; extended Escape

; ------------- Bits

B0		EQU	00000001b				; 1
B1		EQU	00000010b				; 2
B2		EQU	00000100b				; 4
B3		EQU	00001000b				; 8
B4		EQU	00010000b				; 10h
B5		EQU	00100000b				; 20h
B6		EQU	01000000b				; 40h
B7		EQU	10000000b				; 80h

B8		EQU	0000000100000000b			; 100h
B9		EQU	0000001000000000b			; 200h
B10		EQU	0000010000000000b			; 400h
B11		EQU	0000100000000000b			; 800h
B12		EQU	0001000000000000b			; 1000h
B13		EQU	0010000000000000b			; 2000h
B14		EQU	0100000000000000b			; 4000h
B15		EQU	1000000000000000b			; 8000h

B16		EQU	000000010000000000000000b		; 10000h
B17		EQU	000000100000000000000000b		; 20000h
B18		EQU	000001000000000000000000b		; 40000h
B19		EQU	000010000000000000000000b		; 80000h
B20		EQU	000100000000000000000000b		; 100000h
B21		EQU	001000000000000000000000b		; 200000h
B22		EQU	010000000000000000000000b		; 400000h
B23		EQU	100000000000000000000000b		; 800000h

B24		EQU	00000001000000000000000000000000b	; 1000000h
B25		EQU	00000010000000000000000000000000b	; 2000000h
B26		EQU	00000100000000000000000000000000b	; 4000000h
B27		EQU	00001000000000000000000000000000b	; 8000000h
B28		EQU	00010000000000000000000000000000b	; 10000000h
B29		EQU	00100000000000000000000000000000b	; 20000000h
B30		EQU	01000000000000000000000000000000b	; 40000000h
B31		EQU	10000000000000000000000000000000b	; 80000000h

CPU.INC - Processor


; =============================================================================
;
;                               Litos - Processor
;
; =============================================================================

; ------------- Registers in stack (pushed with PUSHA instruction)

struc		REGSTACK

REGS_EDI:	resd	1		; 0: EDI register
REGS_ESI:	resd	1		; 4: ESI register
REGS_EBP:	resd	1		; 8: EBP register
REGS_ESP:	resd	1		; 0Ch: ESP register
					; (points behind end of structure)
REGS_EBX:	resd	1		; 10h: EBX register
REGS_EDX:	resd	1		; 14h: EDX register
REGS_ECX:	resd	1		; 18h: ECX register
REGS_EAX:	resd	1		; 1Ch: EAX register

endstruc				; size 20h = 32 bytes

; ------------- Segments in stack (pushed with PUSH DS, ES, FS, GS)

struc		SEGSTACK

SEGS_GS:	resw	2		; 0: GS register (WORD)
SEGS_FS:	resw	2		; 4: FS register (WORD)
SEGS_ES:	resw	2		; 8: ES register (WORD)
SEGS_DS:	resw	2		; 0Ch: DS register (WORD)

endstruc				; size 16 bytes

; ------------- Stack content on interrupt

struc		REGINT

REGI_EIP:	resd	1		; 0: instruction pointer (EIP)
REGI_CS:	resw	2		; 4: code segment (WORD, CS)
REGI_Flags:	resd	1		; 8: flags (EFLAGS), see below

endstruc				; size 12 bytes

; ------------- FPU register

struc		FPUREG

FPUREG_Sign:	resb	8		; 0: significand (64 bits)
FPUREG_Exp:	resb	2		; 8: exponent (15 bits)+sign (1 bit)

endstruc				; size 10 bytes

; ------------- FPU state (saved with FSTENV/FNSTENV/FSAVE/FNSAVE instructions)

struc		FPUSTATE
				; --- state stored with FSTENV/FNSTENV
FPU_CW:		resw	2		; 0: control word
FPU_SW:		resw	2		; 4: status word
FPU_TW:		resw	2		; 8: tag word
FPU_IP:		resd	1		; 0Ch: instruction pointer
FPU_CS:		resw	1		; 10h: code selector
FPU_OP:		resw	1		; 12h: opcode
FPU_DP:		resd	1		; 14h: data pointer
FPU_DS:		resw	2		; 18h: data selector
				; --- extension stored with FSAVE/FNSAVE
FPU_ST:		resb	FPUREG_size*8	; 1Ch: data registers
		resd	1		; 6Ch: padding

endstruc				; size 70h = 112 bytes

; ------------- FPU register with padding

struc		FPUXREG

		resb	FPUREG_size	; 0: FPU register
		resb	3		; 0Ah: padding (reserved)

endstruc				; size 16 bytes

; ------------- FPU MMX register

struc		FPUMMX

FPUMMX_Data:	resd	4		; 0: MMX register

endstruc				; size 16 bytes

; ------------- FPU extended state (saved with FXSAVE instruction)

struc		FPUXSTATE

FPUX_CW:	resw	1		; 0: control word
FPUX_SW:	resw	1		; 2: status word
FPUX_TW:	resw	1		; 4: tag word
FPUX_OP:	resw	1		; 6: opcode
FPUX_IP:	resd	1		; 8: instruction pointer
FPUX_CS:	resw	2		; 0Ch: code selector
FPUX_DP:	resd	1		; 10h: data pointer
FPUX_DS:	resw	2		; 14h: data selector
FPUX_MXCSR:	resd	1		; 18h:
		resd	1		; 1Ch: ...reserved
FPUX_ST:	resb	FPUXREG_size*8	; 20: data registers
FPUX_MMX:	resb	FPUMMX_size*8	; 0A0h: MMX registers
		resb	14*16		; 120h: padding

endstruc				; size 200h = 512 bytes

; ------------- EFLAG bits

EFLAGS_CF_BIT	EQU	0		; carry flag
EFLAGS_CF	EQU	B0

EFLAGS_PF_BIT	EQU	2		; parity flag
EFLAGS_PF	EQU	B2

EFLAGS_AF_BIT	EQU	4		; auxiliary carry flag
EFLAGS_AF	EQU	B4

EFLAGS_ZF_BIT	EQU	6		; zero flag
EFLAGS_ZF	EQU	B6

EFLAGS_SF_BIT	EQU	7		; sign flag
EFLAGS_SF	EQU	B7

EFLAGS_TF_BIT	EQU	8		; trap flag
EFLAGS_TF	EQU	B8

EFLAGS_IF_BIT	EQU	9		; interrupt enable flag
EFLAGS_IF	EQU	B9

EFLAGS_DF_BIT	EQU	10		; direction flag
EFLAGS_DF	EQU	B10

EFLAGS_OF_BIT	EQU	11		; overflow flag
EFLAGS_OF	EQU	B11

EFLAGS_IOPL_MASK EQU	B12+B13		; I/O privilege level mask
EFLAGS_IOPL_SHIFT EQU	B12		; I/O privilege level bit shifts

EFLAGS_NT_BIT	EQU	14		; nested task
EFLAGS_NT	EQU	B14

EFLAGS_RF_BIT	EQU	16		; resume flag
EFLAGS_RF	EQU	B16

EFLAGS_VM_BIT	EQU	17		; virtual-8086 mode
EFLAGS_VM	EQU	B17

EFLAGS_AC_BIT	EQU	18		; alignment check
EFLAGS_AC	EQU	B18

EFLAGS_VIF_BIT	EQU	19		; virtual interrupt flag
EFLAGS_VIF	EQU	B19

EFLAGS_VIP_BIT	EQU	20		; virtual interrupt pending
EFLAGS_VIP	EQU	B20

EFLAGS_ID_BIT	EQU	21		; CPUID detection flag
EFLAGS_ID	EQU	B21

CRITICAL.INC - Critical section


; =============================================================================
;
;                         Litos - Critical section
;
; =============================================================================

; ------------- Critical section

struc		CRITIC

CRITIC_Lock:	resd	1		; 0: spin lock counter (-1=unlocked)
CRITIC_Recurs:	resd	1		; 4: recursion counter
CRITIC_Owner:	resd	1		; 8: owning task (0=none)

endstruc				; size 0ch = 12 bytes

CROSS.INC - Cross list


; =============================================================================
;
;                            Litos - Cross list
;
; =============================================================================

; ------------- Cross list entry or list head

struc		CROSS

		resb	LIST_size	; 0: next/previous cross list entry
CROSS_Link:	resd	1		; 8: link to cross-linked list entry
CROSS_Owner:	resd	1		; 0Ch: owner of this cross list entry

endstruc				; size 16 bytes

DATADEV.INC - Data device


; =============================================================================
;
;                           Litos - Data device
;
; =============================================================================

; ------------- Data device function block

struc		DATADEVF

		resb	DFB_size	; 0: drive function block

DDEV_Open:	resd	1		; 14h: open data device
					;	OUTPUT:	CY=error

DDEV_Close:	resd	1		; 18h: close data device
					;	OUTPUT: CY=error

DDEV_Read:	resd	1		; 1Ch: read data from device
					;	INPUT:	EDX:EAX=data offset
					;		EBX=data device
					;		ECX=data length
					;		ESI=data buffer
					;	OUTPUT:	EAX=bytes OK read
					;		CY=error

DDEV_Write:	resd	1		; 20h: write data to device
					;	INPUT:	EDX:EAX=data offset
					;		EBX=data device
					;		ECX=data length
					;		ESI=data buffer
					;	OUTPUT:	EAX=bytes OK written
					;		CY=error

DDEV_Verify:	resd	1		; 24h: verify data from device
					;	INPUT:	EDX:EAX=data offset
					;		EBX=data device
					;		ECX=data length
					;	OUTPUT:	EAX=bytes OK verified
					;		CY=error

DDEV_Compare:	resd	1		; 28h: compare data from device
					;	INPUT:	EDX:EAX=data offset
					;		EBX=data device
					;		ECX=data length
					;		ESI=data buffer
					;	OUTPUT:	EAX=bytes OK compared
					;		CY=error

DDEV_LockDoor:	resd	1		; 2Ch: lock door
					;	INPUT:	AL=0 unlock, <>0 lock
					;	OUTPUT:	CY=error

DDEV_GetOpen:	resd	1		; 30h: get door open status
					;	OUTPUT:	CY=error
					;		EAX=0 open, 1 close
					;		+empty, 2 close+media

DDEV_SetOpen:	resd	1		; 34h: set door open status
					;	INPUT:	AL=0 open, <>0 close
					;	OUTPUT:	CY=error

DDEV_Changed:	resd	1		; 38h: test media change
					;	OUTPUT:	EAX=0 not, <>0 changed
					;		CY=error

endstruc				; size 3Ch = 60 bytes

; ------------- Data device parameter block
; Granularity = sector size (on block device) or byte (on character device)

struc		DATADEV

		resb	DPB_size	; 0: driver parameter block
DDEV_Flags:	resd	1		; 40h: flags (see below)
DDEV_Caps:	resd	1		; 44h: capabilities (see below)
		resb	3		; 48h
DDEV_GranBits:	resb	1		; 4Bh: granularity bits (0=1 byte,...)
DDEV_GranSize:	resd	1		; 4Ch: granularity size (1, 2, 4, ...)
DDEV_GranMask:	resd	1		; 50h: granularity inverse mask
DDEV_FileName:	resd	1		; 54h: device file name STEXT
DDEV_Size:	resd	2		; 58h: media size (bytes)
DDEV_CurPos:	resd	2		; 60h: current position

endstruc				; size 68h = 104 bytes

; ------------- Data device flags

DDEV_CHARDEV	EQU	B0		; character device
DDEV_OPENED	EQU	B1		; data device is opened
DDEV_LOCKED	EQU	B2		; door is locked
DDEV_WRITEVER	EQU	B3		; write with verify or compare
DDEV_USECOMP	EQU	B4		; use compare instead verify
DDEV_HWWPROT	EQU	B5		; hardware write-protected
DDEV_SWWPROT	EQU	B6		; software write-protected

; ------------- Data device capabilities

DDEV_CANSEEK	EQU	B0		; can seek (and has size)
DDEV_CANLOCK	EQU	B1		; can lock door
DDEV_CANGETOPEN EQU	B2		; can get door open
DDEV_CANSETOPEN EQU	B3		; can set door open
DDEV_CANCHANGE	EQU	B4		; can detect media change
DDEV_CHANGESAFE EQU	B5		; can detect media change safely
DDEV_VOLATILE	EQU	B6		; data volatile (cannot verify, cache)
DDEV_CANREAD	EQU	B7		; can read
DDEV_CANWRITE	EQU	B8		; can write
DDEV_CANVERIFY	EQU	B9		; can verify
DDEV_CANCOMPARE	EQU	B10		; can compare
DDEV_CANWRIVER	EQU	B11		; can write with verify
DDEV_CANWRICOMP EQU	B12		; can write with compare
DDEV_CANHWWPROT EQU	B13		; can hardware write-protect

DDEV_CANALLR	EQU	DDEV_CANREAD+DDEV_CANVERIFY+DDEV_CANCOMPARE
DDEV_CANALLW	EQU	DDEV_CANWRITE+DDEV_CANWRIVER+DDEV_CANWRICOMP
DDEV_CANALL	EQU	DDEV_CANALLR+DDEV_CANALLW

DISK.INC - Block device


; =============================================================================
;
;                             Litos - Block device
;
; =============================================================================

; ------------- Block device function block

struc		DISKF

		resb	DATADEVF_size	; 0: data device function block

DISKF_ReadTrk:	resd	1		; 3Ch: read sectors from track
					;	INPUT:	EAX=start sector (1...)
					;		EBX=block device
					;		ECX=number of sectors
					;		EDX=data buffer
					;		ESI=head (0...)
					;		EDI=cylinder (0...)
					;	OUTPUT:	EAX=sectors OK read
					;		CY=error

DISKF_WriteTrk:	resd	1		; 40h: write sectors to track
					;	INPUT:	EAX=start sector (1...)
					;		EBX=block device
					;		ECX=number of sectors
					;		EDX=data buffer
					;		ESI=head (0...)
					;		EDI=cylinder (0...)
					;	OUTPUT:	EAX=sectors OK written
					;		CY=error

DISKF_VerifyTrk:resd	1		; 44h: verify sectors from track
					;	INPUT:	EAX=start sector (1...)
					;		EBX=block device
					;		ECX=number of sectors
					;		ESI=head (0...)
					;		EDI=cylinder (0...)
					;	OUTPUT:	EAX=sectors OK verified
					;		CY=error

DISKF_CompTrk:	resd	1		; 48h: compare sectors from track
					;	INPUT:	EAX=start sector (1...)
					;		EBX=block device
					;		ECX=number of sectors
					;		EDX=data buffer
					;		ESI=head (0...)
					;		EDI=cylinder (0...)
					;	OUTPUT:	EAX=sectors OK compared
					;		CY=error

DISKF_FormatTrk:resd	1		; 4Ch: format track
					;	INPUT:	AL=filler byte
					;		EBX=block device
					;		ESI=head (0...)
					;		EDI=cylinder (0...)
					;	OUTPUT:	CY=error

endstruc				; size 50h = 80 bytes

; ------------- Block device parameter block

struc		DISK

		resb	DATADEV_size	; 0: driver parameter block
DISK_SectNum:	resd	2		; 60h: total number of sectors
DISK_TrackSect:	resd	1		; 68h: number of sectors per track
DISK_Heads:	resd	1		; 6Ch: number of heads
DISK_Tracks:	resd	1		; 70h: number of cylinders

endstruc				; size 74h = 116 bytes

DISK_SectSize	EQU	DDEV_GranSize	; sector size (bytes)

; ------------- Block device logical media (partition) descriptor

;struc		PARTITION
;
;PART_Size:	resd	2		; 0: media size (bytes)
;PART_SectNum:	resd	2		; 8: total number of sectors
;PART_StrtSect:	resd	2		; 10h: first sector
;PART_StrtHead:	resd	1		; 18h: head of first sector
;PART_StrtTrck:	resd	1		; 1Ch: track of first sector
;PART_EndSect:	resd	2		; 20h: last sector (size=last-first+1)
;PART_EndHead:	resd	1		; 28h: head of last sector
;PART_EndTrck:	resd	1		; 2Ch: track of last sector
;
;endstruc				; size 30h = 48 bytes

;DISK_LMedia:	resb	LMEDIA_size	; 70h: primary partition descriptor

;DISK_PartSize	EQU	DISK_LMedia+LMEDIA_Size ; partition size (bytes)
;DISK_PartSectN	EQU	DISK_LMedia+LMEDIA_SectNum ; partition sectors
;DISK_StrtSect	EQU	DISK_LMedia+LMEDIA_StrtSect ; first sector
;DISK_StrtHead	EQU	DISK_LMedia+LMEDIA_StrtHead ; head of first sector
;DISK_StrtTrck	EQU	DISK_LMedia+LMEDIA_StrtTrck ; track of first sector
;DISK_EndSect	EQU	DISK_LMedia+LMEDIA_EndSect ; last sector
;DISK_EndHead	EQU	DISK_LMedia+LMEDIA_EndHead ; head of last sector
;DISK_EndTrck	EQU	DISK_LMedia+LMEDIA_EndTrck ; track of last sector

DISPLAY.INC - Display driver


; =============================================================================
;
;                         Litos - General display
;
; =============================================================================

; ------------- Standard PC colors

COL_BLACK	EQU	0		; black
COL_BLUE	EQU	1		; blue
COL_GREEN	EQU	2		; green
COL_CYAN	EQU	3		; cyan
COL_RED		EQU	4		; red
COL_MAGENTA	EQU	5		; magenta
COL_YELLOW	EQU	6		; yellow (brown)
COL_WHITE	EQU	7		; white
COL_LBLACK	EQU	8		; light black (gray)
COL_LBLUE	EQU	9		; light blue
COL_LGREEN	EQU	10		; light green
COL_LCYAN	EQU	11		; light cyan
COL_LRED	EQU	12		; light red
COL_LMAGENTA	EQU	13		; light magenta
COL_LYELLOW	EQU	14		; light yellow
COL_LWHITE	EQU	15		; light white

COL_BROWN	EQU	COL_YELLOW	; brown (dark yellow)
COL_GRAY	EQU	COL_LBLACK	; gray (light black)

; ------------- Monochrome attributes

COL_INVIS	EQU	00h		; invisible
COL_UNDER	EQU	01h		; underline
COL_NORMAL	EQU	07h		; normal
COL_INTENS	EQU	0fh		; intensity
COL_INVERSE	EQU	70h		; inverse
COL_DARK	EQU	08h		; dark

; ------------- Color attributes

COL_FGINT	EQU	B3		; foreground intensity bit
COL_CHAR2	EQU	COL_FGINT	; alternate charset
COL_BLINK	EQU	B7		; blinking bit
COL_BGINT	EQU	COL_BLINK	; background intensity bit

; ------------- Position

struc		POSITION

POS_X:		resd	1		; 0: horizontal position
POS_Y:		resd	1		; 4: vertical position

endstruc				; size 8 bytes

; ------------- Dimension

struc		DIMENSION

DIM_W:		resd	1		; 0: width
DIM_H:		resd	1		; 4: height

endstruc				; size 8 bytes

; ------------- Area

struc		AREA

AREA_Pos:	resb	POSITION_size	; 0: area position
AREA_Dim:	resb	DIMENSION_size	; 8: area dimension

endstruc				; size 16 bytes

AREA_X		EQU	AREA_Pos+POS_X	; area left
AREA_Y		EQU	AREA_Pos+POS_Y	; area top
AREA_W		EQU	AREA_Dim+DIM_W	; area width
AREA_H		EQU	AREA_Dim+DIM_H	; area height

; ------------- Extended area

struc		AREAX

		resb	AREA_size	; 0: area position and dimension
AREA_End:	resb	POSITION_size	; 10h: area end position + 1
					; (end = position + dimension)

endstruc				; size 18h = 24 bytes

AREA_X2		EQU	AREA_End+POS_X	; area right+1
AREA_Y2		EQU	AREA_End+POS_Y	; area bottom+1

; ------------- Videomode

struc		VMODE

VMODE_VirtDim:	resb	DIMENSION_size	; 0: virtual dimension (0=auto)
VMODE_DispDim:	resb	DIMENSION_size	; 8: display dimension (0=auto)
VMODE_FontDim:	resb	DIMENSION_size	; 10h: text font dimension (0=auto)
VMODE_Freq:	resd	1		; 18h: vertical frequency [Hz] (0=auto)
VMODE_MemMode:	resb	1		; 1Ch: memory mode (see below, 0=auto)
VMODE_BitsPoint:resb	1		; 1Dh: total bits per point
VMODE_BitsPlane:resb	1		; 1Eh: bits per point in one plane
VMODE_Planes:	resb	1		; 1Fh: color planes
VMODE_BaseAddr:	resd	1		; 20h: videomemory base address
VMODE_DispSize:	resd	1		; 24h: size of display page
VMODE_MaxOff:	resd	1		; 28h: maximal offset of display page
VMODE_ScanLine:	resd	1		; 2Ch: bytes per scan line
VMODE_PlaneSize:resd	1		; 30h: size of one plane (bytes)
VMODE_Port:	resd	1		; 34h: control port (+1=data port)

endstruc				; size 38h = 56 bytes

VMODE_VirtW	EQU	VMODE_VirtDim+DIM_W ; virtual width
VMODE_VirtH	EQU	VMODE_VirtDim+DIM_H ; virtual height
VMODE_W		EQU	VMODE_DispDim+DIM_W ; display width
VMODE_H		EQU	VMODE_DispDim+DIM_H ; display heigh
VMODE_FontW	EQU	VMODE_FontDim+DIM_W ; text font width
VMODE_FontH	EQU	VMODE_FontDim+DIM_H ; text font height

; ------------- Memory mode

VMODE_TEXT	EQU	1		; simple text (1 byte, without color)
VMODE_TEXTMONO	EQU	2		; monochrome text mode (2 bytes)
VMODE_TEXTCOLOR	EQU	3		; color text mode (2 bytes)
VMODE_1BIT	EQU	4		; 2 colors, 1 bit
VMODE_2BIT	EQU	5		; 4 colors, 2 bits
VMODE_2BITN	EQU	6		; 4 colors, 1 bit, 2 planes (no-stand.)
VMODE_3BITN	EQU	7		; 8 colors, 1 bit, 3 planes (no-stand.)
VMODE_4BIT	EQU	8		; 16 colors, 1 bit, 4 planes
VMODE_4BITN	EQU	9		; 16 colors, 4 bit (no-stand.)
VMODE_8BIT	EQU	10		; 256 colors, 8 bits
VMODE_8BITN	EQU	11		; 256 colors, 1 byt, 8 planes (no-std.)
VMODE_15BIT	EQU	12		; 32K colors, 2 bytes (B5, G5, R5)
VMODE_15BITA	EQU	13		; 32K colors, 2 bytes (B5, G5, R5, A1)
VMODE_16BIT	EQU	14		; 64K colors, 2 bytes (B5, G6, R5)
VMODE_24BIT	EQU	15		; True-Color, 3 bytes (B8, G8, R8)
VMODE_32BIT	EQU	16		; True-Color, 4 bytes (B8, G8, R8)
VMODE_32BITA	EQU	17		; True-Color, 4 bytes (B8, G8, R8, A8)

; ------------- Display driver function block
; Driver may modify entries after setting videomode.

struc		DDFB

		resb	DFB_size	; 0: driver function block

DDFB_EnumMode:	resd	1		; 14h: function - enumerate videomodes
					;	INPUT:	EAX = index (0...)
					;		EBX = display driver
					;		EDX = videomode struc.,
					;		      NULL=not used
					;	OUTPUT:	CY = invalid index,
					;		     EAX = max. index
					;		NC = videomode struc.
					;		     is filled up
					;		EAX = index/max.index

DDFB_TestMode:	resd	1		; 18h: function - test videomode
					;	INPUT:	EBX = display driver
					;		EDX = videomode struc.
					;		 (full dim., disp.dim.,
					;		 font dimension, freq.
					;		 and mem. mode can be
					;		 set or 0=auto)
					;	OUTPUT:	CY = invalid mode
					;		NC = videomode struc.
					;		     is filled up

DDFB_SetMode:	resd	1		; 1Ch: function - set videomode
					;	INPUT:	EBX = display driver
					;		EDX = videomode struc.
					;		 (full dim., disp.dim.,
					;		 font dimension, freq.
					;		 and mem. mode can be
					;		 set or 0=auto)
					;	OUTPUT:	CY = invalid mode
					;		NC = videomode struc.
					;		     is filled up

DDFB_Clear:	resd	1		; 20h: function - clear screen+reset
					;	INPUT:	EBX = display driver

DDFB_SetOffset:	resd	1		; 24h: function - set display offset
					;	INPUT:	EBX = display driver
					;		ECX = display X coord.
					;		EDX = display Y coord.

DDFB_SetCursor:	resd	1		; 28h: function - set cursor position
					;	INPUT:	EBX = display driver
					;		ECX = cursor column
					;		EDX = cursor row

DDFB_SetCurSize:resd	1		; 2Ch: function - set cursor size
					;	INPUT:	EBX = display driver
					;		ECX = top scan line
					;		EDX = bottom scan line

DDFB_SetVisible:resd	1		; 30h: function - set cursor visible
					;	INPUT:	AL = 0 off,1 on,2 flip
					;		EBX = display driver

DDFB_LoadFont:	resd	1		; 34h: function - load text font
					;	INPUT:	AL = bank (0...)
					;		AH = font height(0=def)
					;		EBX = display driver
					;		CL = first index
					;		DL = last index
					;		ESI = font

DDFB_SetFont:	resd	1		; 38h: function - set font bank
					;	INPUT:	EBX = display driver
					;		CL = bank for attr3=0
					;		DL = bank for attr3=1

DDFB_SetBorder:	resd	1		; 3Ch: function - set border color
					;	INPUT:	AL = border color
					;		EBX = display driver

DDFB_SetPalCGA:	resd	1		; 40h: function - set CGA palette
					;	INPUT:	AL = CGA palette
					;			0 = blue off
					;			1 = blue on
					;		EBX = display driver

DDFB_SetPalEGA:	resd	1		; 44h: function - set EGA palette
					;	INPUT:	AL = start index 0..16
					;		EBX = display driver
					;		CL = stop index 0..16
					;		EDX = EGA palettes

DDFB_SetPalVGA:	resd	1		; 48h: function - set VGA palette
					;	INPUT:	AL = start index
					;		EBX = display driver
					;		CL = stop index
					;		EDX = VGA palette

DDFB_SetPalInx:	resd	1		; 4Ch: function - set indexed palette
					;	INPUT:	EAX = index table
					;		EBX = display driver
					;		ECX = number of entries
					;		EDX = VGA palette

DDFB_FillUp:	resd	1		; 50h: function - fill-up region
					;	INPUT:	AL = color or character
					;		AH = color (text mode)
					;		EBX = display driver
					;		ECX = region width
					;		EDX = region height
					;		ESI = region left
					;		EDI = region top

DDFB_Move:	resd	1		; 54h: function - move region
					;	INPUT:	EAX = dest. offset
					;		EBX = display driver
					;		ECX = region width
					;		EDX = region height
					;		ESI = region left
					;		EDI = region top

DDFB_BufferSize:resd	1		; 58h: function - get buffer size
					;	INPUT:	EBX = display driver
					;		ECX = region width
					;		EDX = region height
					;	OUTPUT:	EAX = buffer size

DDFB_GetRegion:	resd	1		; 5Ch: function - get region
					;	INPUT:	EAX = dest. buffer
					;		EBX = display driver
					;		ECX = region width
					;		EDX = region height
					;		ESI = region left
					;		EDI = region top

DDFB_SetRegion:	resd	1		; 60h: function - set region
					;	INPUT:	EAX = source buffer
					;		EBX = display driver
					;		ECX = region width
					;		EDX = region height
					;		ESI = region left
					;		EDI = region top

DDFB_SetRegCol:	resd	1		; 64h: function - set region with color
					;	INPUT:	EAX = source buffer
					;		EBX = display driver
					;		ECX = region width
					;		EDX = region height
					;		ESI = region left
					;		EDI = region top
					;		EBP = color

DDFB_SetColMask:resd	1		; 68h: function - set reg.with col.mask
					;	INPUT:	EAX = buffer
					;		EBX = display driver
					;		ECX = region width
					;		EDX = region height
					;		ESI = region left
					;		EDI = region top
					;		EBP = transparent color

DDFB_SetMasked:	resd	1		; 6Ch: function - set region with mask
					;	INPUT:	EAX = buffer + bit mask
					;		EBX = display driver
					;		ECX = region width
					;		EDX = region height
					;		ESI = region left
					;		EDI = region top

DDFB_SetAlpha:	resd	1		; 70h: function - set region with alpha
					;	INPUT:	EAX = buffer + alpha
					;		EBX = display driver
					;		ECX = region width
					;		EDX = region height
					;		ESI = region left
					;		EDI = region top

		resd	1

endstruc				; size 78h = 120 bytes

; ------------- Display driver parameter block

DISPMAXREG	EQU	30h		; maximal number of display registers

struc		DDPB

		resb	DPB_size	; 0: driver parameter block
DDPB_Flags:	resd	1		; 40h: flags (see below)
DDPB_MemSize:	resd	1		; 44h: total videomemory size
DDPB_CurPos:	resb	POSITION_size	; 48h: text cursor position X
DDPB_CurSizeT:	resd	1		; 50h: cursor size - top scan line
DDPB_CurSizeB:	resd	1		; 54h: cursor size - bottom scan line
DDPB_Offset:	resb	POSITION_size	; 58h: current display offset
DDPB_Addr:	resd	1		; 60h: current display address
DDPB_FromUni:	resd	1		; 64h: mapping table from Unicode
DDPB_FontBuff:	resd	1		; 68h: font buffer (128*32 = 4 KB)
		resd	1		; 6Ch: ...padding
DDPB_VMode:	resb	VMODE_size	; 70h: current videomode
DDPB_Regs:	resb	DISPMAXREG	; 0A8h: cache of display registers

endstruc				; size 0D8h = 216 bytes

DDPB_CurPosX	EQU	DDPB_CurPos+POS_X ; cursor position X
DDPB_CurPosY	EQU	DDPB_CurPos+POS_Y ; cursor position Y
DDPB_OffX	EQU	DDPB_Offset+POS_X ; display offset X
DDPB_OffY	EQU	DDPB_Offset+POS_Y ; display offset Y
DDPB_VirtW	EQU	DDPB_VMode+VMODE_VirtW ; virtual width (0=auto)
DDPB_VirtH	EQU	DDPB_VMode+VMODE_VirtH ; virtual height (0=auto)
DDPB_W		EQU	DDPB_VMode+VMODE_W ; display width (0=auto)
DDPB_H		EQU	DDPB_VMode+VMODE_H ; display height (0=auto)
DDPB_FontW	EQU	DDPB_VMode+VMODE_FontW ; text font width (0=auto)
DDPB_FontH	EQU	DDPB_VMode+VMODE_FontH ; text font height (0=auto)
DDPB_Freq	EQU	DDPB_VMode+VMODE_Freq ; vert. frequency [Hz] (0=auto)
DDPB_MemMode	EQU	DDPB_VMode+VMODE_MemMode ; memory mode
DDPB_BitsPoint	EQU	DDPB_VMode+VMODE_BitsPoint ; total bits per point
DDPB_BitsPlane	EQU	DDPB_VMode+VMODE_BitsPlane ; bits per point in 1 plane
DDPB_Planes	EQU	DDPB_VMode+VMODE_Planes ; color planes
DDPB_BaseAddr	EQU	DDPB_VMode+VMODE_BaseAddr ; videomemory base address
DDPB_DispSize	EQU	DDPB_VMode+VMODE_DispSize ; size of display page
DDPB_MaxOff	EQU	DDPB_VMode+VMODE_MaxOff ; maximal offset of disp. page
DDPB_ScanLine	EQU	DDPB_VMode+VMODE_ScanLine ; bytes per scan line
DDPB_PlaneSize	EQU	DDPB_VMode+VMODE_PlaneSize ; size of one plane
DDPB_Port	EQU	DDPB_VMode+VMODE_Port ; control port

; ------------- Display driver flags

DDPB_CURON	EQU	B0		; cursor is on
DDPB_CANTEXT	EQU	B1		; can use text videomodes
DDPB_CANGRAPH	EQU	B2		; can use graphic videomodes
DDPB_CANFONT	EQU	B3		; can set fonts
DDFB_VGA	EQU	B4		; card is VGA compatible

; ------------- Fixed font

struc		FIXFONT

FIXFONT_Width:	resd	1		; 0: character width
FIXFONT_Height:	resd	1		; 4: character height
FIXFONT_Map:	resd	1		; 8: mapping from Unicode to address
FIXFONT_Invalid:resd	1		; 0Ch: pointer to invalid character
FIXFONT_End:	resd	1		; 10h: end of font data
FIXFONT_Data:				; 14h: start of font data
					;	- (1) number of Unicode codes
					;	- N*(2) Unicode code
					;	- font data  

endstruc				; size 20 bytes

FIXFONT_MASK	EQU	B0+B1+B2+B3+B4	; mask of number of Unicode codes
FIXFONT_VGRAPHT	EQU	B5		; expand vertical graphics top
FIXFONT_VGRAPHB	EQU	B6		; expand vertical graphics bottom

DRIVER.INC - General driver


; =============================================================================
;
;                           Litos - General driver
;
; =============================================================================

; ------------- Resource descriptor

struc		RESOURCE

		resb	LIST_size	; 0: resource list of one driver
RES_Start:	resd	1		; 8: start of resource
RES_SizeFlagsDW:			;   size, type and flags as DWORD
RES_Size:	resw	1		; 0Ch: size of resource-1 (max. 64 K)
RES_Type:	resb	1		; 0Eh: resource type
RES_Flags:	resb	1		; 0Fh: resource flags

endstruc				; size 16 bytes

; ------------- Resource type

RES_IRQ		EQU	0		; resource type - IRQ (interrupt)
RES_DMA		EQU	1		; resource type - DMA
RES_PORT	EQU	2		; resource type - port
RES_MEM		EQU	3		; resource type - memory

; ------------- Resource flags

RES_STATIC	EQU	B0		; resource descriptor is static
RES_AUTO	EQU	B1		; resource is auto selected
RES_CANMANUAL	EQU	B2		; resource can be selected manually
RES_PAGES	EQU	B3		; resource size is in 4 KB pages

; ------------- Driver function block

struc		DFB

DFB_Detect:	resd	1		; 0: device detection
					;	OUTPUT: CY=device not detected
DFB_Init:	resd	1		; 4: device initialization
					;	OUTPUT: CY=init error
DFB_DeInit:	resd	1		; 8: device deinitialization
					;	OUTPUT: CY=deinit error
DFB_Enable:	resd	1		; 0Ch: enable device
					;	OUTPUT: CY=cannot enable
DFB_Disable:	resd	1		; 10h: disable device
					;	OUTPUT: CY=cannot disable

endstruc				; size 14h = 20 bytes

; ------------- Driver parameter block

struc		DPB

		resb	RBNODE_size	; 0: red-black tree node
DPB_Lock:	resb	SPINLOCK_size	; 18h: driver lock
DPB_FlagsDW:				;   driver index, class and flags
DPB_Index:	resb	1		; 1Ch: driver index of identical class
DPB_Class:	resb	1		; 1Dh: driver class and subclass
DPB_Flags:	resb	1		; 1Eh: driver flags (see below)
DPB_ClassFlags:	resb	1		; 1Fh: class specific driver flags
DPB_VersionDW:				;   driver version (as DWORD)
DPB_Build:	resw	1		; 20h: build number of driver version
DPB_VerMin:	resb	1		; 22h: minor driver version
DPB_VerMaj:	resb	1		; 23h: major driver version
DPB_Vendor:	resd	1		; 24h: pointer to vendor name STEXT
DPB_Name:	resd	1		; 28h: pointer to driver name STEXT
DPB_Model:	resd	1		; 2Ch: pointer to model name STEXT
DPB_Modul:	resd	1		; 30h: modul path (empty = internal)
DPB_Func:	resd	1		; 34h: pointer to driver function block
DPB_Resource:	resb	LIST_size	; 38h: resource list

endstruc				; size 40h = 64 bytes

; ------------- Driver flags

DPB_STATIC	EQU	B0		; structure is static (don't delete it)
DPB_DISABLED	EQU	B1		; driver is disabled
DPB_CANDISABLE	EQU	B2		; driver can be disabled
DPB_USED	EQU	B3		; driver is used (linked to someone)

; ------------- Driver class and subclass (it can change, use mapping function)

DRVCLASS_NUM	EQU	8		; number of driver classes
DRVCLASS_SHIFT	EQU	5		; driver class bit shift
DRVCLASS_MASK	EQU	(DRVCLASS_NUM-1) << DRVCLASS_SHIFT ; driver class mask

DRVSUB_NUM	EQU	32		; number of driver subclasses
DRVSUB_MASK	EQU	DRVSUB_NUM-1	; driver subclass mask

DRV_NO		EQU	0		; unspecified device class

DRV_SYS		EQU	1<<DRVCLASS_SHIFT; system device
DRV_SYS_NO	EQU	DRV_SYS + 0	; unspecified system device
DRV_SYS_MB	EQU	DRV_SYS + 1	; motherboard
DRV_SYS_SYS	EQU	DRV_SYS + 2	; system kernel
DRV_SYS_FPU	EQU	DRV_SYS + 3	; mathematic coprocessor
DRV_SYS_DMA	EQU	DRV_SYS + 4	; DMA controller (8237A, 74612)
DRV_SYS_IRQ	EQU	DRV_SYS + 5	; interrupt controller (8259A)
DRV_SYS_CMOS	EQU	DRV_SYS + 6	; CMOS real-time clock (MC146818)
DRV_SYS_TIMER	EQU	DRV_SYS + 7	; timer (8254)
DRV_SYS_KEYB	EQU	DRV_SYS + 8	; keyboard controller (8042)
;DRV_SYS_PC	EQU	DRV_SYS + 9	; computer
;DRV_SYS_CPU	EQU	DRV_SYS + 10	; processor
;DRV_SYS_MEM	EQU	DRV_SYS + 11	; memory
;DRV_SYS_BIOS	EQU	DRV_SYS + 12	; BIOS memory
;DRV_SYS_BUS	EQU	DRV_SYS + 13	; bus controller
;DRV_SYS_PNP	EQU	DRV_SYS + 14	; Plug-and-Play controller
;DRV_SYS_PCI	EQU	DRV_SYS + 15	; PCI bus controller
;DRV_SYS_AGP	EQU	DRV_SYS + 16	; AGP bus controller
;DRV_SYS_APM	EQU	DRV_SYS + 17	; advanced power management
;DRV_SYS_SPEAK	EQU	DRV_SYS + 18	; speaker
;DRV_SYS_BRID	EQU	DRV_SYS + 19	; bridge
;DRV_SYS_CODE	EQU	DRV_SYS + 20	; microcode updater

DRV_INP		EQU	2<<DRVCLASS_SHIFT; input device
DRV_INP_NO	EQU	DRV_INP + 0	; unspecified input device
DRV_INP_KEYB	EQU	DRV_INP + 1	; keyboard
DRV_INP_PUN	EQU	DRV_INP + 2	; punch card/tape reader
DRV_INP_BAR	EQU	DRV_INP + 3	; bar code reader
DRV_INP_SCAN	EQU	DRV_INP + 4	; scanner
DRV_INP_PEN	EQU	DRV_INP + 5	; light pen
DRV_INP_MOUSE	EQU	DRV_INP + 6	; mouse
DRV_INP_TAB	EQU	DRV_INP + 7	; tablet
DRV_INP_JOY	EQU	DRV_INP + 8	; joystick

DRV_OUT		EQU	3<<DRVCLASS_SHIFT; output device
DRV_OUT_NO	EQU	DRV_OUT + 0	; unspecified output device
DRV_OUT_MON	EQU	DRV_OUT + 1	; monitor
DRV_OUT_TTY	EQU	DRV_OUT + 2	; data terminal
DRV_OUT_TXT	EQU	DRV_OUT + 3	; text display (MDA)
DRV_OUT_GRAPH	EQU	DRV_OUT + 4	; graphic display(HGC,CGA,EGA,VGA,SVGA)
DRV_OUT_3D	EQU	DRV_OUT + 5	; 3D graphic display
DRV_OUT_PRINT	EQU	DRV_OUT + 6	; printer
DRV_OUT_PUN	EQU	DRV_OUT + 7	; punch card/tape writer
DRV_OUT_BDISP	EQU	DRV_OUT + 8	; braille display
DRV_OUT_BPRN	EQU	DRV_OUT + 9	; braille printer
DRV_OUT_PLOT	EQU	DRV_OUT + 10	; plotter

DRV_DISK	EQU	4<<DRVCLASS_SHIFT; storage device
DRV_DISK_NO	EQU	DRV_DISK + 0	; unspecified storage device
DRV_DISK_FD	EQU	DRV_DISK + 1	; floppy disk
DRV_DISK_HD	EQU	DRV_DISK + 2	; hard disk
DRV_DISK_RAM	EQU	DRV_DISK + 3	; RAM disk
DRV_DISK_CD	EQU	DRV_DISK + 4	; CD or DVD disk
DRV_DISK_VIRT	EQU	DRV_DISK + 5	; virtual (file) disk
DRV_DISK_FLASH	EQU	DRV_DISK + 6	; flash disk
DRV_DISK_MAG	EQU	DRV_DISK + 7	; magnetic tape

DRV_NET		EQU	5<<DRVCLASS_SHIFT; communication driver
DRV_NET_NO	EQU	DRV_NET + 0	; unspecified communication driver
DRV_NET_CARD	EQU	DRV_NET + 1	; net card
DRV_NET_PROT	EQU	DRV_NET + 2	; net protocol
DRV_NET_SHARE	EQU	DRV_NET + 3	; net share
DRV_NET_COM	EQU	DRV_NET + 4	; COM transfer

DRV_CTRL	EQU	6<<DRVCLASS_SHIFT; periphery controller
DRV_CTRL_NO	EQU	DRV_CTRL + 0	; unspecified periphery controller
DRV_CTRL_FD	EQU	DRV_CTRL + 1	; floppy disk controller
DRV_CTRL_IDE	EQU	DRV_CTRL + 2	; IDE controller
DRV_CTRL_SCSI	EQU	DRV_CTRL + 3	; SCSI controller
DRV_CTRL_USB	EQU	DRV_CTRL + 4	; USB controller
DRV_CTRL_COM	EQU	DRV_CTRL + 5	; COM port
DRV_CTRL_LPT	EQU	DRV_CTRL + 6	; LPT port
DRV_CTRL_PS2	EQU	DRV_CTRL + 7	; PS/2 controller

DRV_MED		EQU	7<<DRVCLASS_SHIFT; multimedia driver
DRV_MED_NO	EQU	DRV_MED + 0	; unspecified multimedia driver
DRV_MED_CTRL	EQU	DRV_MED + 1	; media control, mixer
DRV_MED_SND	EQU	DRV_MED + 2	; sound device
DRV_MED_MUS	EQU	DRV_MED + 3	; music device
DRV_MED_CODEC	EQU	DRV_MED + 4	; codec
DRV_MED_TV	EQU	DRV_MED + 5	; TV tuner
DRV_MED_CAP	EQU	DRV_MED + 6	; capture

ERRORS.INC - Errors


; =============================================================================
;
;                             Litos - Error codes
;
; =============================================================================

; ------------- Error categories

ERR_CATBIT	EQU	5		; error category bit position
ERR_CATBITS	EQU	3		; error category bits
ERR_CATMASK	EQU	0e0h		; error category mask

ERR_GENERAL	EQU	0 << ERR_CATBIT	; general error (OK or unspecified)
ERR_SYNTAX	EQU	1 << ERR_CATBIT	; syntax error
ERR_MATH	EQU	2 << ERR_CATBIT	; mathematic
ERR_KERNEL	EQU	3 << ERR_CATBIT	; kernel
ERR_MEMORY	EQU	4 << ERR_CATBIT	; memory
ERR_TASK	EQU	5 << ERR_CATBIT	; task or process
ERR_FILE	EQU	6 << ERR_CATBIT	; file system
ERR_DEVICE	EQU	7 << ERR_CATBIT	; device

; ------------- General error

ERR_OK		EQU	ERR_GENERAL+0	; operation OK (hardcoded 0)
;ERR_NOMORE	EQU	ERR_GENERAL+1	; no more item

; ------------- Syntax error

;ERR_NOTIMPL	EQU	ERR_SYNTAX+1	; function not implemented
;ERR_INVCODE	EQU	ERR_SYNTAX+2	; invalid function code
;ERR_INVARG	EQU	ERR_SYNTAX+3	; invalid argument
;ERR_PERMIT	EQU	ERR_SYNTAX+4	; operation not permitted
;ERR_TOOLONG	EQU	ERR_SYNTAX+5	; argument list too long
;ERR_EXECFORM	EQU	ERR_SYNTAX+6	; exec format error
;ERR_ADDRESS	EQU	ERR_SYNTAX+7	; bad address

; ------------- Mathematic

;ERR_MATHARG	EQU	ERR_MATH+1	; math argument out of domain of func
;ERR_RANGE	EQU	ERR_MATH+2	; math result not representable
;ERR_DIVIDE	EQU	ERR_MATH+3	; divide zero

; ------------- Kernel

;ERR_INTCALL	EQU	ERR_KERNEL+1	; interrupted system call

; ------------- Memory

;ERR_NOMEM	EQU	ERR_MEMORY+1	; out of memory
;ERR_QUEUEFULL	EQU	ERR_MEMORY+2	; queue full
;ERR_INVMEM	EQU	ERR_MEMORY+3	; invalid memory (VMA error)

; ------------- Task and process

;ERR_NOPROC	EQU	ERR_TASK+1	; no such process
;ERR_NOCHILD	EQU	ERR_TASK+2	; no child processes

; ------------- File system

;ERR_NOFILE	EQU	ERR_FILE+1	; no such file or directory
;ERR_BADFILE	EQU	ERR_FILE+2	; bad file number
;ERR_ACCESS	EQU	ERR_FILE+3	; permission denied
;ERR_EXIST	EQU	ERR_FILE+4	; file already exists
;ERR_NOTDIR	EQU	ERR_FILE+5	; not a directory
;ERR_ISDIR	EQU	ERR_FILE+6	; is a directory
;ERR_FTABOVER	EQU	ERR_FILE+7	; file table overflow
;ERR_TOOFILES	EQU	ERR_FILE+8	; too many open files
;ERR_NOTTY	EQU	ERR_FILE+9	; not a typewriter
;ERR_TXTBUSY	EQU	ERR_FILE+10	; text file busy
;ERR_FILEBIG	EQU	ERR_FILE+11	; file too large
;ERR_READONLY	EQU	ERR_FILE+12	; read-only file system
;ERR_TOOLINKS	EQU	ERR_FILE+13	; too many links
;ERR_PIPE	EQU	ERR_FILE+14	; broken pipe
;ERR_NAMELONG	EQU	ERR_FILE+15	; file name too long
;ERR_NOLOCK	EQU	ERR_FILE+16	; no record locks available
;ERR_NOTEMPTY	EQU	ERR_FILE+17	; directory not empty
;ERR_TOOSYMB	EQU	ERR_FILE+18	; too many symbolic links encountered
;ERR_WDBLOCK	EQU	ERR_FILE+19	; operation would block
;ERR_IDREM	EQU	ERR_FILE+20	; identifier removed
;ERR_LNKRANGE	EQU	ERR_FILE+21	; link number out of range
;ERR_NOANODE	EQU	ERR_FILE+22	; no anode

; ------------- Device

;ERR_IOERR	EQU	ERR_DEVICE+1	; I/O error
;ERR_NOXIO	EQU	ERR_DEVICE+2	; no such device or address
;ERR_AGAIN	EQU	ERR_DEVICE+3	; try again
;ERR_NOTBLK	EQU	ERR_DEVICE+4	; block device required
;ERR_BUSY	EQU	ERR_DEVICE+5	; device or resource busy
;ERR_XDEV	EQU	ERR_DEVICE+6	; cross-device link
;ERR_NODEV	EQU	ERR_DEVICE+7	; no such device
;ERR_NOSPACE	EQU	ERR_DEVICE+8	; no space left on device
;ERR_SEEK	EQU	ERR_DEVICE+9	; illegal seek
;ERR_NOTATT	EQU	ERR_DEVICE+10	; protocol driver not attached
;ERR_NOCSI	EQU	ERR_DEVICE+11	; no CSI structure available
;ERR_XCHANGE	EQU	ERR_DEVICE+12	; invalid exchange
;ERR_XFULL	EQU	ERR_DEVICE+13	; exchange full

EXCEPTION.INC - Exceptions


; =============================================================================
;
;                               Litos - Exceptions
;
; =============================================================================

; ------------- Get data from user space with default value
; %1=register, %2=address, %3=default value

%macro		GET	3
%%L1:		mov	%1,[%2]
%%L2:
		FIX_SECTION
%%L3:		mov	%1,%3
		jmp	%%L2

		EXC_SECTION
		dd	%%L1

		EXC2_SECTION
		dd	%%L3

		CODE_SECTION 32
%endmacro

; ------------- Get data from user space with error
; %1=register, %2=address, %3=error handler

%macro		GET_ERR	3
%%L1:		mov	%1,[%2]

		EXC_SECTION
		dd	%%L1

		EXC2_SECTION
		dd	%3

		CODE_SECTION 32
%endmacro

; ------------- Put data to user space with ignore
; %1=address, %2=register

%macro		PUT	2
%%L1:		mov	[%1],%2
%%L2:
		EXC_SECTION
		dd	%%L1

		EXC2_SECTION
		dd	%%L2

		CODE_SECTION 32
%endmacro

; ------------- Put data to user space with error
; %1=address, %2=register, %3=error handler

%macro		PUT_ERR	3
%%L1:		mov	[%1],%2

		EXC_SECTION
		dd	%%L1

		EXC2_SECTION
		dd	%3

		CODE_SECTION 32
%endmacro

; ------------- Copy data to/from user space (on error: ECX != 0)
; EDI=destination address, ESI=source address, ECX=data size

%macro		COPY	0
%%L1:		rep	movsd
%%L2:
		EXC_SECTION
		dd	%%L1

		EXC2_SECTION
		dd	%%L2

		CODE_SECTION 32
%endmacro

FLOPPY.INC - Floppy disk


; =============================================================================
;
;                           Litos - Floppy disk
;
; =============================================================================
; This is very simplified version of the drive. It supports only 1 drive with
; one media format (1.44 MB).

; ------------- Floppy disk controller function block

struc		FDCF

		resb	DFB_size	; 0: driver function block

endstruc				; size 14h = 20 bytes

; ------------- Floppy disk controller parameter block

FDBUFFSIZE	EQU	4000h		; DMA buffer size (18 sectors = 9K)

struc		FDC

		resb	DPB_size	; 0: driver parameter block
FDC_Flags:	resb	1		; 40h: flags (see below, DWORD aligned)
		resb	3
FDC_Buffer:	resd	1		; 44h: pointer to DMA buffer
FDC_IntLock:	resb	TASKLOCK_size	; 48h: task lock for interrupt
FDC_MotorLock:	resb	SPINLOCK_size	; 54h: motor lock
FDC_Mutex:	resb	MUT_size	; 58h: mutex to lock access to floppy

endstruc				; size 74h = 116 bytes

; ------------- Floppy disk controller flags

FDC_INTOK_BIT 	EQU	0		; interrupt occurs
FDC_INTOK	EQU	1 << FDC_INTOK_BIT

FDC_DEFFLAG	EQU	0		; default flags

; ------------- Floppy disk device function block

struc		FLOPPYF

		resb	DISKF_size	; 0: block device function block

endstruc				; size 54h = 84 bytes

; ------------- Floppy disk data device capabilities

FLOPPY_CAP	EQU	DDEV_CANSEEK+DDEV_CANCHANGE+DDEV_CANALL+DDEV_CANHWWPROT

; ------------- Floppy disk device parameter block

FLOP_REPMAX	EQU	7		; maximal number of replies

struc		FLOPPY

		resb	DISK_size	; 0: block device parameter block

FLOPPY_FDC:	resd	1		; 74h: pointer to controller FDC
FLOPPY_Flags:	resb	1		; 78h: flags (see below, DWORD aligned)
FLOPPY_Track:	resb	1		; 79h: current track number
FLOPPY_Head:	resb	1		; 7Ah: current head number
FLOPPY_LastErr:	resb	1		; 7Bh: last error code (see below)
FLOPPY_Buffer:	resd	1		; 7Ch: pointer to DMA buffer
FLOPPY_Alarm:	resb	ALARM_size	; 80h: motor OFF timer
FLOPPY_Reply:	resb	FLOP_REPMAX	; 0A0h: reply buffer
		resb	1		; 0AFh

endstruc				; size 0B0h = 176 bytes

FLOPPY_ST0	EQU	FLOPPY_Reply + 0 ; reply register 0
FLOPPY_ST1	EQU	FLOPPY_Reply + 1 ; reply register 1
FLOPPY_ST2	EQU	FLOPPY_Reply + 2 ; reply register 2
FLOPPY_ST3	EQU	FLOPPY_Reply + 0 ; reply register 3 (=result)

; ------------- Floppy disk device flags

FLOPPY_RESREQ	EQU	B0		; reset request
FLOPPY_SEEKREQ	EQU	B1		; seek request
FLOPPY_MOTORON	EQU	B2		; motor is ON

FLOPPY_DEFFLAG	EQU	FLOPPY_SEEKREQ+FLOPPY_RESREQ ; default flags

; ------------- Floppy disk error code

				; *** No error
FDERR_OK	EQU	00h		; no error
				; *** General errors
FDERR_UNKOWN	EQU	11h		; unknown error
				; *** FDC controller errors
FDERR_FDCERR	EQU	21h		; controller general error
FDERR_FDCRESET	EQU	22h		; controller reset error
FDERR_FDCREADY	EQU	23h		; controller not ready (FDC time-out)
FDERR_FDCWRITE	EQU	24h		; error writing command to controller
FDERR_FDCREAD	EQU	25h		; error receiving state from controller
FDERR_FDCOVER	EQU	26h		; result buffer overrun
FDERR_OVERRUN	EQU	27h		; data overrun (data lost, DMA error)
				; *** Drive error
FDERR_SEEKERR	EQU	31h		; seek error
FDERR_TIMEOUT	EQU	32h		; operation (interrupt) time-out
FDERR_DRVREADY	EQU	33h		; drive not ready
FDERR_ZEROTRACK	EQU	34h		; recalibrate error, track 0 not found
				; *** Media error
FDERR_ADDRFND	EQU	41h		; missing sector address mark
FDERR_WPROT	EQU	42h		; disk write-protected
FDERR_DATAFND	EQU	43h		; missing sector data
FDERR_CRC	EQU	44h		; bad CRC of sector
FDERR_SECTFND	EQU	45h		; sector not found
FDERR_BADHEAD	EQU	46h		; sector head does not correspomd

; ------------- Floppy disk track layout (one entry, used with format track)

struc		FTRACK

FTRACK_Cyl:	resb	1		; 0: cylinder number (0..79)
FTRACK_Head:	resb	1		; 1: head number (0..1)
FTRACK_Sect:	resb	1		; 2: sector number (1..)
FTRACK_Size:	resb	1		; 3: sector size (0=128,...)

endstruc				; size 4 bytes

; ------------- Main status register

FDS_BUSYMASK	EQU	B0+B1+B2+B3	; busy mask (drive 0..3 seeks)
FDS_BUSY	EQU	B4		; controller busy (command in progress)
FDS_NONDMA	EQU	B5		; non-DMA mode (SPECIFY is executed)
FDS_DIRREAD	EQU	B6		; data direction 1=FDC->CPU, 0=CPU->FDC
FDS_READY	EQU	B7		; data register ready (to transfer)

; ------------- Digital output register (DOR)

FDDOR_SELMASK	EQU	B0+B1		; drive select mask (0..3)
FDDOR_FDCENABLE	EQU	B2		; FDC enable (0=controller reset)
FDDOR_DMAENABLE	EQU	B3		; DMA enable
FDDOR_MOTOR0	EQU	B4		; drive 0 motor enable
FDDOR_MOTOR1	EQU	B5		; drive 1 motor enable
FDDOR_MOTOR2	EQU	B6		; drive 2 motor enable
FDDOR_MOTOR3	EQU	B7		; drive 3 motor enable

FDDOR_MOTMASK	EQU	B4+B5+B6+B7	; drive motors mask

; ------------- Status register ST0

FDST0_DRVMASK	EQU	B0+B1		; drive unit at interrupt
FDST0_HEAD	EQU	B2		; head state at interrupt
FDST0_NREADY	EQU	B3		; not ready (drive is not ready with
					; R/W command or access to side 1
					; required on single side drive)
FDST0_EQERR	EQU	B4		; equipment check error, fault signal
					; received or track 0 not found
FDST0_SEEKEND	EQU	B5		; seek completed
FDST0_INTMASK0	EQU	B6		; interrupt code mask (low bit)
FDST0_INTMASK1	EQU	B7		; interrupt code mask (high bit)
FDST0_INTMASK	EQU	B6+B7		; interrupt code mask
					;  00 = normal termination
					;  01 = abnormal termination, command
					;	was started but was not
					;	successfully completed
					;  10 = invalid command, command
					;	was never started
					;  11 = abnormal termination, ready
					;	signal changed state

; ------------- Status register ST1

FDST1_MISADDR	EQU	B0		; missing address mark
FDST1_WP	EQU	B1		; write protect (during write)
FDST1_NDATA	EQU	B2		; no data (sector not found)
FDST1_OVERRUN	EQU	B4		; overrun (FDC is not serviced by the
					; host system during data transfer)
FDST1_CRC	EQU	B5		; CRC error in data or head
FDST1_EOC	EQU	B7		; end of cylinder (FDC tries to access
					; sector after last sector of cylinder)

; ------------- Status register ST2

FDST2_MISADDR	EQU	B0		; missing address mark in data field
FDST2_BADCYL	EQU	B1		; bad cylinder (different cylinder)
FDST2_SCANERR	EQU	B2		; scan not satisfied (cannot find
					; sector during scan command)
FDST2_SCANEQU	EQU	B3		; scan equal hit
FDST2_WRONGCYL	EQU	B4		; wrong cylinder
FDST2_CRC	EQU	B5		; CRC error in data
FDST2_CTRLMARK	EQU	B6		; control mark

; ------------- Status register ST3

FDST3_HEAD	EQU	B2		; head
FDST3_DS	EQU	B3		; drive us double-sided
FDST3_TRACK0	EQU	B4		; track zero signal
FDST3_READY	EQU	B5		; drive is ready
FDST3_WP	EQU	B6		; write protect
FDST3_FAULT	EQU	B7		; drive fault

; ------------- Floppy disk commands
; Recalibrate:
;     W - DS drive select (B0+B1)

; Read/write data:
;     W - HDS+DS head select (B2) + drive select (B0+B1)
; 	- C cylinder (for sector ID information, starting 0)
; 	- H head (for sector ID information, 0 or 1)
;	- R sector number (for sector ID information. starting 1)
;	- N sector size (for sector ID information, 0=128 B...)
;	- EOT end of track (final sector number of a cylinder)
;	- GPL gap 3 length (spacing between sector excl. VCO sync field)
;	- DTL data length when N is 0
;     R	- ST0
;	- ST1
;	- ST2
; 	- C cylinder
; 	- H head
;	- R sector number
;	- N sector size
;
; Format a track:
;     W - HDS+DS head select (B2) + drive select (B0+B1)
;	- N sector size (for sector ID information, 0=128 B...)
;	- SC sectors/track
;	- GPL gap 3 length (spacing between sector excl. VCO sync field)
;	- D filler byte
;     R	- ST0
;	- ST1
;	- ST2
; 	- C cylinder
; 	- H head
;	- R sector number
;	- N sector size
;
; Sense interrupt status:
;     R	- ST0
;	- PCN present cylinder number
;
; Specify:
;     W - SRT+HUT step rate time (B4..B7) + head uload time (B0..B3)
;	- HLT+ND head load time (B1..B7) + non-DMA mode (B0)
;
; Semse drive status:
;     W - HDS+DS head select (B2) + drive select (B0+B1)
;     R	- ST3
;
; Seek:
;     W - HDS+DS head select (B2) + drive select (B0+B1)
;     W	- NCN new cylinder number
;
; Invalid command:
;     R - ST0 with 80h

FD_SPECIFY	EQU	3		; specify

FD_STATUS	EQU	4		; sense drive status (read ST3)

FD_WRITE	EQU	5+B6		; write (without multi-track, with MFM)

FD_READ		EQU	6+B5+B6		; read (without multi-track, with MFM,
					;	with skip deleted data)

FD_RECALIB	EQU	7		; recalibrate (move to track 0)

FD_SENSE	EQU	8		; sense interrupt status

FD_FORMAT	EQU	0dh+B6		; format track (with MFM)

FD_SEEK		EQU	0fh		; seek

GLDT.INC - Global/local descriptor


; =============================================================================
;
;                       Litos - Global/local descriptor
;
; =============================================================================

; ------------- Global/Local Descriptor Table, GLDT

struc		GLDT

GLDT_Limit:	resw	1		; 0: segment limit (bits 0 to 15)
GLDT_Base:	resw	1		; 2: base address (bits 0 to 15)
GLDT_Base2:	resb	1		; 4: base address (bits 16 to 23)
GLDT_Access:	resb	1		; 5: access rights
					;    if code/data type decriptor (B4):
					;	B0: 1=segment accessed 
					;	if code segment (B3=1):
					;	  B1: 1=read, 0=no read
					;	  B2: 1=code segment may only
					;		be executed when CPL
					;	       (current privileg level)
					;		>= DPL (descriptor
					;		privileg level) and CPL
					;		remains unchanged
					;	if data segment (B3=0):
					;	   B1: 1=read/write,0=read only
					;	   B2: 1=expand down, 0=exp. up
					;	B3: 1=code, 0=data segment
					;    if system/gate type descriptor:
					;	B0-B3: segment type
					;		0 = ...reserved
					;		1 = available 286 TSS
					;		2 = LDT
					;		3 = busy 286 TSS
					;		4 = 286 call gate
					;		5 = task gate
					;		6 = 286 interrupt gate
					;		7 = 286 trap gate
					;		8 = ...reserved
					;		9 = available 386 TSS
					;		10 = ...reserved
					;		11 = busy 386 TSS
					;		12 = 386 call gate
					;		13 = ...reserved
					;		14 = 386 interrupt gate
					;		15 = 386 trap gate
					;    B4: descriptor type
					;		1=code or data
					;		0=system or gate
					;    B5-B6: descriptor privilege level
					;		0 = kernel
					;		1 = services
					;		2 = drivers
					;		3 = applications
					;    B7: 1=segment is present in memory
GLDT_Flags:	resb	1		; 6: flags
					;    B0-B3: segment limit (bits 16-19)
					;    B4: available for use of system
					;    B5: 0 (must always be zero)
					;    B6: operand size 
					;	   1=32 bits (use ESP)
					;	   0=16 bits (use SP)
					;    B7: size granularity 1=4KB, 0=1B
GLDT_Base3:	resb	1		; 7: base address (bits 24 to 31)

endstruc				; size 8 bytes

; ------------- Global descriptor table - indexes

SYSTEM_GDT_CS	EQU	1		; index of system 4GB code descriptor
SYSTEM_GDT_DS	EQU	2		; index of system 4GB data descriptor
USER_GDT_CS	EQU	3		; index of user 4GB code desriptor
USER_GDT_DS	EQU	4		; index of user 4GB data desriptor
PNP_GDT_CS	EQU	5		; index of PNP 64K 32b code desriptor
PNP_GDT_CS16	EQU	6		; index of PNP 64K 16b code desriptor
PNP_GDT_DS16	EQU	7		; index of PNP 64K 16b data desriptor
APM_GDT_CS	EQU	8		; index of APM 64K 32b code desriptor
APM_GDT_CS16	EQU	9		; index of APM 64K 16b code desriptor
APM_GDT_DS	EQU	10		; index of APM 64K 32b data desriptor
TASK_GDT_LDT	EQU	11		; base index of task LTD (4090 or 250)
TASK_GDT_TSS	EQU	TASK_GDT_LDT+TASK_MAX ; base index of task TSS

BOOT_GDT_NUM	EQU	11		; number of GDTs in boot GDT table
SYSTEM_GDT_NUM	EQU	TASK_GDT_TSS+TASK_MAX ; number of GDTs (8191 or 511)

; ------------- Global descriptor table - selectors

SYSTEM_CS	EQU	SYSTEM_GDT_CS*8	; system 4GB code selector
SYSTEM_DS	EQU	SYSTEM_GDT_DS*8	; system 4GB data selector
USER_CS		EQU	USER_GDT_CS*8	; user 4GB code selector
USER_DS		EQU	USER_GDT_DS*8	; user 4GB data selector
PNP_CS		EQU	PNP_GDT_CS*8	; PNP 64K 32b code selector
PNP_CS16	EQU	PNP_GDT_CS16*8	; PNP 64K 16b code selector
PNP_DS16	EQU	PNP_GDT_DS16*8	; PNP 64K 16b data selector
APM_CS		EQU	APM_GDT_CS*8	; APM 64K 32b code selector
APM_CS16	EQU	APM_GDT_CS16*8	; APM 64K 16b code selector
APM_DS		EQU	APM_GDT_DS*8	; APM 64K 32b data selector
TASK_FIRST_LDT	EQU	TASK_GDT_LDT*8	; task LTD (Local Descriptor Table)
TASK_FIRST_TSS	EQU	TASK_GDT_TSS*8	; task TSS (Task State Segment)

HASH.INC - Hash list


; =============================================================================
;
;                             Litos - Hash list
;
; =============================================================================

; ------------- Hash list head

struc		HASHH

HASHH_First:	resd	1		; 0: pointer to first entry (0=empty)

endstruc				; size 4 bytes

; ------------- Hash list entry

struc		HASHE

HASHE_Next:	resd	1		; 0: pointer to next entry (0=none)
					;   (pointer must be first entry!)
HASHE_Prev:	resd	1		; 4: pointer to previous entry

endstruc				; size 8 bytes

IDT.INC - Interrupt descriptor


; =============================================================================
;
;                         Litos - Interrupt descriptor
;
; =============================================================================

; ------------- Interrupt Descriptor Table, IDT

struc		IDT

IDT_Offset:	resw	1		; 0: offset in segment (bits 0 to 15)
IDT_Selector:	resw	1		; 2: target segment selector
IDT_Count:	resb	1		; 4: DWORD count, must be 0
					;     for call gate:
					;	B0-B4 = number of parameters
					;		to copy from calling
					;		procedure stack to the
;					;		new stack
IDT_Flags:	resb	1		; 5: flags
					;	B0-B3: entry type
					;		5 = task gate
					;			(uses TSS)
					;		12 = call gate
					;		14 = 386 interrupt gate
					;			(uses GDT)
					;		15 = 386 trap gate
					;			(uses LDT)
					;	B4: 0 (must always be zero)
					;	B5-B6: descr. privilege level
					;		0 = exceptions and
					;		    hardware interrupts
					;		3 = software interrupts
					;	B7: 1=present in memory
					;	(if it is not set a Not Preset
					;	#NP exception is generated)
IDT_Offset2:	resw	1		; 6: offset in segment (bits 16 to 31)

endstruc				; size 8 bytes

; -----------------------------------------------------------------------------
; Task gate
;	Includes the TSS selector of the process that must replace the current
;	one when an interrupt signal occurs.
; Call gate
;	Call gates facilitate controlled transfers of program control between
;	different privilege levels. A call-gate descriptor may reside in the
;	GDT or LDT, but not in IDT. Call gate can be accessed using CALL or
;	JMP instruction with segment selector identifying the call gate (offset
;	will be ignored). CPU uses destination code segment and offset from
;	the call gate to determine procedure entry point.
; Interrupt gate
;	Includes the Segment Selector and the offset inside the segment of an
;	interrupt or exception handler. While transferring control to the
;	proper segment, the processor clears the IF flag, thus disabling
;	further maskable interrupts.
; Trap gate
;	Similar to an interrupt gate, except that while transferring control to
;	the proper segment, the processor does not modify the IF flag.
; -----------------------------------------------------------------------------

; Error code (for exception handler):
;	B0: EXT (External event), 1=external (hw) event caused the exception
;	B1: IDT (Descriptor location), 1=index refers to IDT, 0=GDT or LDT
;	B2: TI (GDT/LDT, only if IDT=0), 1=index refers to LDT, 0=..to GDT
;	B3-B15: segment selector index
;	B16-B31: reserved

IRQ.INC - Interrupt request


; =============================================================================
;
;                           Litos - Interrupt request
;
; =============================================================================

IRQ_FIRST	EQU	20h		; first interrupt for IRQ
					; (must be multiple of 8)
IRQ_NUM		EQU	16		; number of IRQ lines
TIMER_IRQ	EQU	0		; IRQ for system timer
KEYB_IRQ	EQU	1		; IRQ for keyboard

; ------------- IRQ descriptor (size must be power of 2)

struc		IRQDESC

		resb	LIST_size	; 0: list of IRQ handlers
IRQDESC_Flags:	resw	1		; 8: IRQ descriptor flags (not used)
IRQDESC_IRQ:	resb	1		; 0Ah: current IRQ number
		resb	1		; ...padding
IRQDESC_Total:	resd	1		; 0Ch: total number of handlers
IRQDESC_Active:	resd	1		; 10h: number of active fast handlers
IRQDESC_Count:	resd	1		; 14h: counter for slow interrupts
		resd	2		; ...padding

endstruc				; size 20h = 32 bytes

; ------------- IRQ handler (hardcoded in TimeIRQHandler)

struc		IRQHAND

		resb	LIST_size	; 0: link to next IRQ handler
IRQHAND_Desc:	resd	1		; 8: pointer to IRQ descriptor
IRQHAND_Flags:	resw	1		; 0Ch: IRQ flags (see below)
IRQHAND_IRQ:	resb	1		; 0Eh: current IRQ number
IRQHAND_Best:	resb	1		; 0Fh: recommended best IRQ number
IRQHAND_Mask:	resd	1		; 10h: mask of usable IRQs (1=enabled)
IRQHAND_Data:	resd	1		; 14h: user data (NULL=disabled)
IRQHAND_Count:	resd	1		; 18h: counter for slow interrupts
IRQHAND_Fast:	resd	1		; 1Ch: fast handler (NULL=none)
					;	INPUT:	EAX = IRQ number
					;		EBX = user data
					;	OUTPUT: CY = not own interrupt
IRQHAND_Slow:	resd	1		; 20h: slow handler (NULL=none)
					;    (called with interrupts enabled)
					;	INPUT:	EAX = IRQ number
					;		EBX = user data
					;		ECX = num.of interrupts
IRQHAND_Setup:	resd	1		; 24h: callback (NULL=none, see below)

endstruc				; size 28h = 40 bytes

; ------------- IRQ device callback setup functions (called with IRQ locked)
; These functions are currently not used.

IRQSET_INFO	EQU	1		; get handler info
					;	EAX = flags, set to 0 now
IRQSET_PAUSE	EQU	2		; pause handler activity
IRQSET_RESUME	EQU	3		; resume handler activity
IRQSET_SET	EQU	4		; set new IRQ number
					;	INPUT: ECX = new IRQ number
					;	OUTPUT: CY=error

; ------------- IRQ flags
				; --- one of following 4 flags must be set
IRQ_PRIVATE	EQU	B0		; IRQ must be private
					;  (no other handlers can use this IRQ)
IRQ_LAST	EQU	B1		; IRQ must be last in handler chain
					;  (other handlers can be "shared")
IRQ_DYNAM	EQU	B2		; IRQ can be dynamic allocated
					;  (only one handler can be enabled)
IRQ_SHARE	EQU	B3		; IRQ can be shared
					;  (handlers detect their interrupts
					;   using fast handler)

IRQ_TRAFFIC	EQU	B5		; high traffic IRQ, should be the first

IRQ_ACTIVE	EQU	B6		; fast handler is active (IRQ enabled)
IRQ_ACTIVE_BIT	EQU	6		; (bit number of IRQ_ACTIVE flag)

KEYBOARD.INC - Keyboard driver


; =============================================================================
;
;                            Litos - Keyboard driver
;
; =============================================================================

KEYBBUF_SIZE	EQU	64		; keyb. buffer size (DWORDs, hardcoded)

; ------------- Keyboard buffer

struc		KEYBBUF

		resb	SPINLOCK_size	; 0: keyboard buffer lock
KBUF_Write:	resb	1		; 4: write offset into input buffer
KBUF_ReadKey:	resb	1		; 5: key code read offset
KBUF_ReadChar:	resb	1		; 6: character read offset
KBUF_Cache:	resb	1		; 7: cache unread character
KBUF_Flags:	resb	1		; 8: flags (see below)
KBUF_Index:	resb	1		; 9: console index
		resb	2		; 0Ah: ...padding
KBUF_WKeyData:	resd	1		; 0Ch: private data for write function
KBUF_WKeyFnc:	resd	1		; 10h: virtual function to write
					;	key code into buffer
					;	INPUT:	EAX = key code
					;		EBX = private data
					;  It can be overwritten by other func.
KBUF_Buff:	resd	KEYBBUF_SIZE	; 14h: key buffer

endstruc				; size 114h = 276 bytes

; ------------- Keyboard buffer flags

KBUF_CACHE_BIT:	EQU	0		; cache contains unread character
KBUF_CACHE:	EQU	1 << KBUF_CACHE_BIT

; ------------- Keyboard driver flags

KEYB_SCROLL	EQU	B0		; Scroll Lock is on (LED hardcoded)
KEYB_NUM	EQU	B1		; Num Lock is on (LED hardcoded)
KEYB_CAPS	EQU	B2		; Caps Lock is on (LED hardcoded)
KEYB_INSERT	EQU	B3		; Insert is on
KEYB_SHIFT	EQU	B4		; Left or Right Shift is on
KEYB_CTRL	EQU	B5		; Left or Right Ctrl is on
KEYB_ALT	EQU	B6		; Left or Right Alt is on
KEYB_PAUSE	EQU	B7		; Pause is on
KEYB_EXT_BIT	EQU	8		; extended prefix E0
KEYB_EXT	EQU	1<<KEYB_EXT_BIT
KEYB_EXT2_BIT	EQU	9		; extended prefix E1
KEYB_EXT2	EQU	1<<KEYB_EXT2_BIT
KEYB_SEND_BIT	EQU	10		; sending to keyboard is running
KEYB_SENDING	EQU	1<<KEYB_SEND_BIT
KEYB_SENDSET	EQU	B11		; send keyboard setup request
KEYB_SENDLED	EQU	B12		; send LED state request
KEYB_SENDRATE	EQU	B13		; send typematic rate requset
KEYB_PRESENT	EQU	B15		; keyboard is present

KEYB_REQMASK	EQU	KEYB_SENDSET+KEYB_SENDLED+KEYB_SENDRATE ; request mask
KEYB_DEFAULT	EQU	KEYB_NUM+KEYB_PRESENT+KEYB_REQMASK ; default flags

; ------------- Key code

struc		KEYCODE

KEYCODE_Char:	resw	1		; 0: character or virtual code
KEYCODE_Scan:	resb	1		; 2: scan code (see below)
KEYCODE_Flags:	resb	1		; 3: flags (see below)

endstruc				; size 4 bytes (hardcoded)

; ------------- Key code flags

KEYCODE_SHIFT_BIT EQU	0		; Left or Right Shift is on
KEYCODE_CTRL_BIT EQU	1		; Left or Right Ctrl is on
KEYCODE_ALT_BIT	 EQU	2		; Left or Right Alt is on
KEYCODE_CH16_BIT EQU	5		; character is 16-bit (else 8-bit)
KEYCODE_CHAR_BIT EQU	6		; character code (else virtual)
KEYCODE_UP_BIT	 EQU	7		; key is released (flag is hardcoded)

KEYCODE_SHIFT	EQU	1<<KEYCODE_SHIFT_BIT; Left or Right Shift is on
KEYCODE_CTRL	EQU	1<<KEYCODE_CTRL_BIT ; Left or Right Ctrl is on
KEYCODE_ALT	EQU	1<<KEYCODE_ALT_BIT  ; Left or Right Alt is on
KEYCODE_CHAR16	EQU	1<<KEYCODE_CH16_BIT ; character is 16-bit (else 8-bit)
KEYCODE_CHAR	EQU	1<<KEYCODE_CHAR_BIT ; character code (else virtual)
KEYCODE_UP	EQU	1<<KEYCODE_UP_BIT   ; key is released

; ------------- Virtual key (key code as DWORD)

VIRTKEY_SHIFT_BIT EQU	KEYCODE_SHIFT_BIT+24 ; Left or Right Shift is on
VIRTKEY_CTRL_BIT EQU	KEYCODE_CTRL_BIT+24  ; Left or Right Ctrl is on
VIRTKEY_ALT_BIT	 EQU	KEYCODE_ALT_BIT+24   ; Left or Right Alt is on
VIRTKEY_CH16_BIT EQU	KEYCODE_CH16_BIT+24  ; character is 16-bit (else 8-bit)
VIRTKEY_CHAR_BIT EQU	KEYCODE_CHAR_BIT+24  ; character code (else virtual)
VIRTKEY_UP_BIT	 EQU	KEYCODE_UP_BIT+24    ; key is released

VIRTKEY_SHIFT	EQU	1<<VIRTKEY_SHIFT_BIT; Left or Right Shift is on
VIRTKEY_CTRL	EQU	1<<VIRTKEY_CTRL_BIT ; Left or Right Ctrl is on
VIRTKEY_ALT	EQU	1<<VIRTKEY_ALT_BIT  ; Left or Right Alt is on
VIRTKEY_CHAR16	EQU	1<<VIRTKEY_CH16_BIT ; character is 16-bit (else 8-bit)
VIRTKEY_CHAR	EQU	1<<VIRTKEY_CHAR_BIT ; character code (else virtual)
VIRTKEY_UP	EQU	1<<VIRTKEY_UP_BIT   ; key is released

VIRTKEY_MASK	EQU	0ff00ffffh	; virtual key mask (without scan code)

; ------------- Keyboard scan and virtual codes

KEY_NONE	EQU	0		; no key (or virtual character)
KEY_ESC		EQU	1		; Esc		(01 / 81)
KEY_1		EQU	2		; 1 !		(02 / 82)
KEY_2		EQU	3		; 2 @		(03 / 83)
KEY_3		EQU	4		; 3 #		(04 / 84)
KEY_4		EQU	5		; 4 $		(05 / 85)
KEY_5		EQU	6		; 5 %		(06 / 86)
KEY_6		EQU	7		; 6 ^		(07 / 87)
KEY_7		EQU	8		; 7 &		(08 / 88)
KEY_8		EQU	9		; 8 *		(09 / 89)
KEY_9		EQU	0ah		; 9 (		(0A / 8A)
KEY_0		EQU	0bh		; 0 )		(0B / 8B)
KEY_HYPHEN	EQU	0ch		; - _		(0C / 8C)
KEY_EQU		EQU	0dh		; = +		(0D / 8D)
KEY_BS		EQU	0eh		; Backspace	(0E / 8E)
KEY_TAB		EQU	0fh		; Tab		(0F / 8F)
KEY_Q		EQU	10h		; Q		(10 / 90)
KEY_W		EQU	11h		; W		(11 / 91)
KEY_E		EQU	12h		; E		(12 / 92)
KEY_R		EQU	13h		; R		(13 / 93)
KEY_T		EQU	14h		; T		(14 / 94)
KEY_Y		EQU	15h		; Y		(15 / 95)
					;	or virtual KEY_Z
KEY_U		EQU	16h		; U		(16 / 96)
KEY_I		EQU	17h		; I		(17 / 97)
KEY_O		EQU	18h		; O		(18 / 98)
KEY_P		EQU	19h		; P		(19 / 99)
KEY_LBRACKET	EQU	1ah		; [ {		(1A / 9A)
KEY_RBRACKET	EQU	1bh		; ] }		(1B / 9B)
KEY_ENTER	EQU	1ch		; Enter		(1C / 9C)
KEY_CTRL	EQU	1dh		; Left Ctrl	(1D / 9D)
KEY_A		EQU	1eh		; A		(1E / 9E)
KEY_S		EQU	1fh		; S		(1F / 9F)
KEY_D		EQU	20h		; D		(20 / A0)
KEY_F		EQU	21h		; F		(21 / A1)
KEY_G		EQU	22h		; G		(22 / A2)
KEY_H		EQU	23h		; H		(23 / A3)
KEY_J		EQU	24h		; J		(24 / A4)
KEY_K		EQU	25h		; K		(25 / A5)
KEY_L		EQU	26h		; L		(26 / A6)
KEY_SEMICOLON	EQU	27h		; ; :		(27 / A7)
KEY_SQUOTE	EQU	28h		; ' "		(28 / A8)
KEY_BACKQUOTE	EQU	29h		; ` ~		(29 / A9)
KEY_SHIFT	EQU	2ah		; Left Shift	(2A / AA)
KEY_BACKSLASH	EQU	2bh		; \ |		(2B / AB)
KEY_Z		EQU	2ch		; Z		(2C / AC)
					; 	or virtual KEY_Y
KEY_X		EQU	2dh		; X		(2D / AD)
KEY_C		EQU	2eh		; C		(2E / AE)
KEY_V		EQU	2fh		; V		(2F / AF)
KEY_B		EQU	30h		; B		(30 / B0)
KEY_N		EQU	31h		; N		(31 / B1)
KEY_M		EQU	32h		; M		(32 / B2)
KEY_COMMA	EQU	33h		; , <		(33 / B3)
KEY_PERIOD	EQU	34h		; . >		(34 / B4)
KEY_SLASH	EQU	35h		; / ?		(35 / B5)
KEY_RSHIFT	EQU	36h		; Right Shift	(36 / B6)
					;	virtual KEY_SHIFT
KEY_GREYSTAR	EQU	37h		; Gray [*]	(37 / B7)
KEY_ALT		EQU	38h		; Left Alt	(38 / B8)
KEY_SPACE	EQU	39h		; SpaceBar	(39 / B9)
KEY_CAPSLOCK	EQU	3ah		; CapsLock	(3A / BA)
KEY_F1		EQU	3bh		; F1		(3B / BB)
KEY_F2		EQU	3ch		; F2		(3C / BC)
KEY_F3		EQU	3dh		; F3		(3D / BD)
KEY_F4		EQU	3eh		; F4		(3E / BE)
KEY_F5		EQU	3fh		; F5		(3F / BF)
KEY_F6		EQU	40h		; F6		(40 / C0)
KEY_F7		EQU	41h		; F7		(41 / C1)
KEY_F8		EQU	42h		; F8		(42 / C2)
KEY_F9		EQU	43h		; F9		(43 / C3)
KEY_F10		EQU	44h		; F10		(44 / C4)
KEY_NUMLOCK	EQU	45h		; NumLock	(45 / C5)
KEY_SCROLL	EQU	46h		; ScrollLock	(46 / C6)
KEY_NUM7	EQU	47h		; [7 Home]	(47 / C7)
					;	virtual KEY_HOME
KEY_NUM8	EQU	48h		; [8 Up]	(48 / C8)
					;	virtual KEY_UP
KEY_NUM9	EQU	49h		; [9 PgUp]	(49 / C9)
					;	virtual KEY_PAGEUP
KEY_GREYMINUS	EQU	4ah		; Gray [-]	(4A / CA)
KEY_NUM4	EQU	4bh		; [4 Left]	(4B / CB)
					;	virtual KEY_LEFT
KEY_NUM5	EQU	4ch		; [5]		(4C / CC)
KEY_NUM6	EQU	4dh		; [6 Right]	(4D / CD)
					;	virtual KEY_RIGHT
KEY_GREYPLUS	EQU	4eh		; Gray [+]	(4E / CE)
KEY_NUM1	EQU	4fh		; [1 End]	(4F / CF)
					;	virtual KEY_END
KEY_NUM2	EQU	50h		; [2 Down]	(50 / D0)
					;	virtual KEY_DOWN
KEY_NUM3	EQU	51h		; [3 PgDn]	(51 / D1)
					;	virtual KEY_PAGEDOWN
KEY_NUM0	EQU	52h		; [0 Ins]	(52 / D2)
					;	virtual KEY_INSERT
KEY_DECIMAL	EQU	53h		; [. Del]	(53 / D3)
					;	virtual KEY_DELETE
KEY_SYSRQ	EQU	54h		; SysRq	    (PrtScr with Alt) (54 / D4)
KEY_BACKSLASH2	EQU	56h		; \ | alternative (56 / D6)
					;	virtual KEY_BACKSLASH
KEY_F11		EQU	57h		; F11		(57 / D7)
KEY_F12		EQU	58h		; F12		(58 / D8)
KEY_MESSENGER	EQU	5+B7		; Messenger	(E0 05 / E0 85)
KEY_EDITREDO	EQU	7+B7		; Edit Redo	(E0 07 / E0 87)
KEY_EDITUNDO	EQU	8+B7		; Edit Undo	(E0 08 / E0 88)
KEY_APPLEFT	EQU	9+B7		; Application Left (E0 09 / E0 89)
KEY_EDITPASTE	EQU	0ah+B7		; Edit Paste	(E0 0A / E0 8A)
KEY_SCRLNORM	EQU	0bh+B7		; Scroll Normal	(E0 0B / E0 8B)
					;  press=scroll up, release=scrool down
KEY_MEDPREV	EQU	10h+B7		; Media Prev	(E0 10 / E0 90)
KEY_SCRLFAST	EQU	11h+B7		; Scroll Fast	(E0 11 / E0 91)
					;  press=scroll up, release=scrool down
KEY_SCRLFASTER	EQU	12h+B7		; Scroll Faster	(E0 12 / E0 92)
					;  press=scroll up, release=scrool down
KEY_WORD	EQU	13h+B7		; Word		(E0 13 / E0 93)
KEY_EXCEL	EQU	14h+B7		; Excel		(E0 14 / E0 94)
KEY_CALENDAR	EQU	15h+B7		; Calendar	(E0 15 / E0 95)
KEY_LOGOFF	EQU	16h+B7		; Log Off	(E0 16 / E0 96)
KEY_EDITCUT	EQU	17h+B7		; Edit Cut	(E0 17 / E0 97)
KEY_EDITCOPY	EQU	18h+B7		; Edit Copy	(E0 18 / E0 98)
KEY_MEDNEXT	EQU	19h+B7		; Media Next	(E0 19 / E0 99)
KEY_NUMENTER	EQU	1ch+B7		; Gray [Enter]	(E0 1C / E0 9C)
KEY_RCTRL	EQU	1dh+B7		; Right Ctrl	(E0 1D / E0 9D)
					;	virtual KEY_CTRL
KEY_APPRIGHT	EQU	1eh+B7		; Application Right (E0 1E / E0 9E)
KEY_SCRLFASTEST	EQU	1fh+B7		; Scroll Fastest (E0 1F / E0 9F)
					;  press=scroll up, release=scrool down
KEY_VOLMUTE	EQU	20h+B7		; Volume Mute	(E0 20 / E0 A0)
KEY_CALCUL	EQU	21h+B7		; Calculator	(E0 21 / E0 A1)
KEY_MEDPLAY	EQU	22h+B7		; Media Play	(E0 22 / E0 A2)
KEY_SPELL	EQU	23h+B7		; Spell		(E0 23 / E0 A3)
KEY_MEDSTOP	EQU	24h+B7		; Media Stop	(E0 24 / E0 A4)
KEY_SHIFT2	EQU	2ah+B7		; fake Left Shift (E0 2A / E0 AA)
					;	virtual KEY_SHIFT
KEY_VOLDOWN	EQU	2eh+B7		; Volume-	(E0 2E / E0 AE)
KEY_VOLUP	EQU	30h+B7		; Volume+	(E0 30 / E0 B0)
KEY_WWWHOME	EQU	32h+B7		; WWW Home	(E0 32 / E0 B2)
KEY_DIVIDE	EQU	35h+B7		; Gray [/]	(E0 35 / E0 B5)
KEY_RSHIFT2	EQU	36h+B7		; fake Right Shift (E0 36 / E0 B6)
					;	virtual KEY_SHIFT
KEY_PRINT	EQU	37h+B7		; PrintScr  (E0 2A E0 37 / E0 B7 E0 AA)
					; or Ctrl+PrintScr (E0 37 / E0 B7)
KEY_RALT	EQU	38h+B7		; Right Alt	(E0 38 / E0 B8)
					;	virtual KEY_ALT
KEY_HELP	EQU	3bh+B7		; Help		(E0 3B / E0 BB)
KEY_MYMUSIC	EQU	3ch+B7		; My Music	(E0 3C / E0 BC)
KEY_TASK	EQU	3dh+B7		; Task Pane	(E0 3D / E0 BD)
KEY_FILENEW	EQU	3eh+B7		; File New	(E0 3E / E0 BE)
KEY_FILEOPEN	EQU	3fh+B7		; File Open	(E0 3F / E0 BF)
KEY_FILECLOSE	EQU	40h+B7		; File Close	(E0 40 / E0 C0)
KEY_EMAILREPLY	EQU	41h+B7		; Email Reply	(E0 41 / E0 C1)
KEY_EMAILFRWRD	EQU	42h+B7		; Email Forward	(E0 42 / E0 C2)
KEY_EMAILSEND	EQU	43h+B7		; Email Send	(E0 43 / E0 C3)
KEY_PAUSE	EQU	45h+B7		; Pause		(E1 1D 45 / E1 9D C5)
KEY_BREAK	EQU	46h+B7		; Break (Pause with Ctrl) (E0 46/E0 C6)
KEY_HOME	EQU	47h+B7		; Home		(E0 47 / E0 C7)
KEY_UP		EQU	48h+B7		; Up		(E0 48 / E0 C8)
KEY_PAGEUP	EQU	49h+B7		; Page Up	(E0 49 / E0 C9)
KEY_LEFT	EQU	4bh+B7		; Left		(E0 4B / E0 CB)
KEY_RIGHT	EQU	4dh+B7		; Right		(E0 4D / E0 CD)
KEY_END		EQU	4fh+B7		; End		(E0 4F / E0 CF)
KEY_DOWN	EQU	50h+B7		; Down		(E0 50 / E0 D0)
KEY_PAGEDOWN	EQU	51h+B7		; Page Down	(E0 51 / E0 D1)
KEY_INSERT	EQU	52h+B7		; Insert	(E0 52 / E0 D2)
KEY_DELETE	EQU	53h+B7		; Delete	(E0 53 / E0 D3)
KEY_FILESAVE	EQU	57h+B7		; File Save	(E0 57 / E0 D7)
KEY_FILEPRINT	EQU	58h+B7		; File Print	(E0 58 / E0 D8)
KEY_WIN		EQU	5bh+B7		; Left Win	(E0 5B / E0 DB)
KEY_RWIN	EQU	5ch+B7		; Right Win	(E0 5C / E0 DC)
					;	virtual KEY_WIN
KEY_WINMENU	EQU	5dh+B7		; Win Menu	(E0 5D / E0 DD)
KEY_POWER	EQU	5eh+B7		; Power		(E0 5E / E0 DE)
KEY_SLEEP	EQU	5fh+B7		; Sleep		(E0 5F / E0 DF)
KEY_WAKEUP	EQU	63h+B7		; Wake Up	(E0 63 / E0 E3)
KEY_MYPIC	EQU	64h+B7		; My Picture	(E0 64 / E0 E4)
KEY_FILESEARCH	EQU	65h+B7		; File Search	(E0 65 / E0 E5)
KEY_WWWFAVOR	EQU	66h+B7		; WWW Favorites	(E0 66 / E0 E6)
KEY_WWWREF	EQU	67h+B7		; WWW Refresh	(E0 67 / E0 E7)
KEY_WWWSTOP	EQU	68h+B7		; WWW Stop	(E0 68 / E0 E8)
KEY_WWWFWRD	EQU	69h+B7		; WWW Forward	(E0 69 / E0 E9)
KEY_WWWBACK	EQU	6ah+B7		; WWW Back	(E0 6A / E0 EA)
KEY_MYCOMP	EQU	6bh+B7		; My Computer	(E0 6B / E0 EB)
KEY_EMAIL	EQU	6ch+B7		; E-mail	(E0 6C / E0 EC)
KEY_MEDSEL	EQU	6dh+B7		; Media	Select	(E0 6D / E0 ED)

; ------------- Keyboard state scan codes (read from port 60h)

KEYSTATE_NONE	EQU	0		; no key code or keyboard error
KEYSTATE_TEST	EQU	0aah		; self-test complete OK
KEYSTATE_PREF	EQU	0e0h		; prefix
KEYSTATE_PREF2	EQU	0e1h		; prefix 2 (Pause/Break, no release)
KEYSTATE_ECHO	EQU	0eeh		; result of echo command
KEYSTATE_ACK	EQU	0fah		; acknowledge
KEYSTATE_FAILMF	EQU	0fch		; diagnostic failure (MF keyboard)
KEYSTATE_FAILAT	EQU	0fdh		; diagnostic failure (AT keyboard)
KEYSTATE_NACK	EQU	0feh		; send error, resend last code
KEYSTATE_ERROR	EQU	0ffh		; keyboard error/buffer full

; ------------- Keyboard commands (write it to port 60h)

KEYCMD_SETLED	EQU	0edh		; set LED, 1 byte follows:
					;	B0 = Scroll Lock is on
					;	B1 = Num Lock is on
					;	B2 = Caps Lock is on
KEYCMD_ECHO	EQU	0eeh		; diagnostic echo, returns 0eeh
KEYCMD_SETRATE	EQU	0f3h		; set typematic rate, 1 byte follows:
					;	B0..B4: typematic rate
					;	   0=30.0, 1=26.7,..31=2.0
					;	B5..B6: delay
					;	   0=250 ms,...3=1000 ms
KEYCMD_SCANMODE	EQU	0f0h		; set scan mode, 1 byte follows:
					;	0 = get keyboard scan mode
					;	1..3 = set scan mode 1..3
KEYCMD_ENABLE	EQU	0f4h		; keyboard enable
KEYCMD_DISABLE	EQU	0f5h		; keyboard disable
KEYCMD_RESET	EQU	0ffh		; keyboard reset

LIST.INC - List


; =============================================================================
;
;                              Litos - List
;
; =============================================================================

; ------------- List entry or list head
; List head is empty (contains no entries), if NEXT points to itself.
; List entry normally has undefined pointers if it is not in a list
; (it need not to be initialized) but it can be used as safe entry, where
; NEXT points to itself as flag that the entry is not linked in any list.

struc		LIST

LIST_Next:	resd	1		; 0: pointer to next (first) entry
					; should be first entry, more optimized
LIST_Prev:	resd	1		; 4: pointer to previous (last) entry

endstruc				; size 8 bytes

OBJECT.INC - Objects


; =============================================================================
;
;                               Litos - Objects
;
; =============================================================================

; ------------- System object

struc		OBJECT

		resb	TREE_size	; 0: list link
OBJECT_Owner:	resb	CROSS_size	; 10h: list of processes owning object
OBJECT_Type:	resd	1		; 20h: pointer to object type (0=free)
OBJECT_Ref:	resd	1		; 24h: reference counter
OBJECT_Name:	resd	1		; 28h: pointer to name of object
OBJECT_Access:	resd	1		; 2Ch: access rights
OBJECT_Data:	resd	1		; 30h: data/pointer to object data

endstruc				; size 40h = 64 bytes

; ------------- Object types

OBJECT_FREE	EQU	0		; free (unused) object
OBJECT_PROCESS	EQU	1		; process
OBJECT_TASK	EQU	2		; task (thread)
OBJECT_CRITICAL	EQU	3		; critical section

; ------------- Object type

struc		OBJTYPE

		resb	LIST_size	; 0: list of object types
OBJTYPE_Name:	resd	1		; 8: name of object type
OBJTYPE_Parent:	resd	1		; 0Ch: pointer to parent object type
OBJTYPE_Flags:	resd	1		; 10h: flags (see below)
OBJTYPE_Destroy:resd	1		; 14h: object destructor (function)
OBJTYPE_Open:	resd	1		; 18h: open object (function)
OBJTYPE_Close:	resd	1		; 1Ch: close object (function)
OBJTYPE_Duplik:	resd	1		; 20h: duplikate object (function)
OBJTYPE_Delete:	resd	1		; 24h: delete object (function)
OBJTYPE_Read:	resd	1		; 28h: read object (function)
OBJTYPE_Write:	resd	1		; 2Ch: write to object (function)
OBJTYPE_Flush:	resd	1		; 30h: flush write (function)
OBJTYPE_Seek:	resd	1		; 34h: seek in object (function)

endstruc				; size 38h = 56 bytes

PAGE.INC - Memory pages


; =============================================================================
;
;                           Litos - Memory pages
;
; =============================================================================

; ------------- Memory page frame

PAGE_SIZE	EQU	4096		; memory page size
PAGE_SHIFT	EQU	12		; bits of memory page size
PAGE_MASK	EQU	~(PAGE_SIZE-1)	; mask page bits, round to page frame
PAGE_MAX	EQU	SYSTEM_SIZE >> PAGE_SHIFT ; maximal page number

PAGEDIR_SHIFT	EQU	22		; bits to get page directory index
PAGEDIR_NUM	EQU	1024		; number of entries per page directory

; ------------- Page Directory Entry, PDE

struc		PDE

		resd	1		; B0: P: 1=present in memory
					; B1: R/W: Read/Write protection
					;	0=page can only be read
					;	1=page can be read and write
					; B2: U/S: User/Supervisor protection
					;	0=only CPL < 3 can access page
					;	(e.g. CPU is in kernel mode)
					;	1=page can always be accessed
					; B3: PWT: page write-through control
					;	(only 486 and later)
					;	0=hw cache uses write-through
					;	1=hw cache uses write-back
					; B4: PCD: page cache disable
					;	(only 486 and later)
					;	0=IVP can be enabled (see CR0)
					;	1=IVP is disabled
					; B5: A: 1=page frame was accessed
					; B7: Page size, 1=2(4) MB pages, 0=4KB
					; B8: Global page (not flushed)
					; B9-B11: available for system
					; B12-B31: page table address (B12-B31)

endstruc				; size 4 bytes

; ------------- Page Table Entry, PTE

struc		PTE

		resd	1		; B0: P: 1=present in memory
					; B1: R/W: Read/Write protection
					;	0=page can only be read
					;	1=page can be read and write
					; B2: U/S: User/Supervisor protection
					;	0=only CPL < 3 can access page
					;	(e.g. CPU is in kernel mode)
					;	1=page can always be accessed
					; B3: PWT: Page write-through control
					;	(only 486 and later)
					;	0=hw cache uses write-back
					;	1=hw cache uses write-through
					; B4: PCD: page cache disable
					;	(only 486 and later)
					;	0=IVP can be enabled (see CR0)
					;	1=IVP is disabled
					; B5: A: 1=page frame was accessed
					; B6: D: 1=dirty (modified)
					; B7: Page size, 1=2(4) MB pages, 0=4KB
					; B8: Global page (not flushed)
					; B9-B11: available for system
					; B12-B31: page frame address (B12-B31)

endstruc				; size 4 bytes

; ------------- Page entry flags

PE_PRESENT_BIT	EQU	0		; page present in memory
PE_PRESENT	EQU	1<<PE_PRESENT_BIT

PE_RW_BIT	EQU	1		; page can be written
PE_RW		EQU	1<<PE_RW_BIT

PE_USER_BIT	EQU	2		; page can be accessed by user
PE_USER		EQU	1<<PE_USER_BIT

PE_PWT_BIT	EQU	3		; hw cache uses write-back
PE_PWT		EQU	1<<PE_PWT_BIT

PE_PCD_BIT	EQU	4		; page cache disabled
PE_PCD		EQU	1<<PE_PCD_BIT

PE_ACCESSED_BIT	EQU	5		; page frame was accessed
PE_ACCESSED	EQU	1<<PE_ACCESSED_BIT

PE_DIRTY_BIT	EQU	6		; page is modified (dirty)
PE_DIRTY	EQU	1<<PE_DIRTY_BIT

PE_PSE_BIT	EQU	7		; large pages 4 MB (or 2 MB)
PE_PSE		EQU	1<<PE_PSE_BIT

PE_GLOBAL_BIT	EQU	8		; global page (not flushed)
PE_GLOBAL	EQU	1<<PE_GLOBAL_BIT

; ------------- Page types
					; system memory
PE_INIT		EQU	PE_PRESENT+PE_RW
					; reserved page (invalid)
PE_NONE		EQU	PE_ACCESSED
					; shared page
PE_SHARED	EQU	PE_PRESENT+PE_RW+PE_USER+PE_ACCESSED
					; copy on write
PE_COPY		EQU	PE_PRESENT+PE_USER+PE_ACCESSED
					; read only page
PE_READONLY	EQU	PE_PRESENT+PE_USER+PE_ACCESSED

; ------------- Page descriptor

struc		PAGEDESC

		resb	LIST_size	; 0: list of pages in virtual memory
PG_Hash:	resb	HASHE_size	; 8: hash cache list of pages
PG_Flags:	resd	1		; 10h: page flags (see below)
PG_Ref:		resd	1		; 14h: page share reference counter
PG_Address:	resd	1		; 18h: address in system memory
PG_Virtual:	resd	1		; 1Ch: address in process memory
PG_Space:	resd	1		; 20h: pointer to page space (0=none)

;PAGE_Map:	resd	1		; pointer to addess space
;PAGE_Index:	resd	1		; index within mapping
;PAGE_Last:	resb	LIST_size	; pageout list
;PAGE_Buffers:	resd	1		; buffer map

		resd	1		; ... padding to 8-byte boundary

endstruc				; size 28h = 40 bytes

; ------------- Page flags

;PG_USED_BIT	EQU	0		; page is used
;PG_USED		EQU	1<<PG_USED_BIT

PG_RESERVE_BIT	EQU	0		; page is reserved (not commited)
PG_RESERVE	EQU	1<<PG_RESERVE_BIT

PG_ZERO_BIT	EQU	1		; zero page
PG_ZERO		EQU	1<<PG_ZERO_BIT

PG_LOCKED_BIT	EQU	2		; page is locked in I/O operation
PG_LOCKED	EQU	1<<PG_LOCKED_BIT

PG_ERROR_BIT	EQU	3		; I/O error occured while transfering
PG_ERROR	EQU	1<<PG_ERROR_BIT

PG_DIRTY_BIT	EQU	4		; page has been modified
PG_DIRTY	EQU	1<<PG_DIRTY_BIT

PG_ACTIVE_BIT	EQU	5		; page is in active page list
PG_ACTIVE	EQU	1<<PG_ACTIVE_BIT

PG_COPYW_BIT	EQU	6		; copy on write
PG_COPYW	EQU	1<<PG_COPYW_BIT

; ------------- Page space

struc		PAGESPACE

		resb	SPINLOCK_size	; 0: lock of page space
PS_Total:	resd	1		; 4: number of total pages
PS_Clean:	resb	LIST_size	; 8: list of clean pages
PS_Dirty:	resb	LIST_size	; 10h: list of dirty pages
PS_Locked:	resb	LIST_size	; 18h: list of locked pages

;PS_Operations:				; operations on this page space
;PS_Flags:
;PS_Owner:

endstruc				; size 20h = 32 bytes

PROCESS.INC - Process


; =============================================================================
;
;                                Litos - Process
;
; =============================================================================

; ------------- Process

struc		PROCESS

PROC_Link:	resb	TREE_size	; tree link to other processes
PROC_TaskList:	resb	LIST_size	; list of threads in a process

endstruc

RBTREE.INC - Red-black balanced tree


; =============================================================================
;
;                       Litos - Red-black balanced tree
;
; =============================================================================

; ------------- Red-black common head

struc		RBCOMMON

		resb	LIST_size	; 0: list of entries
RB_ColorFlags:
RB_Color:	resb	1		; 8: color of node (see below)
RB_Flags:	resb	1		; 9: flags (see below)
RB_DataW:	resw	1		; 0Ah: possible data of tree node, WORD

endstruc				; size 12 bytes

; ------------- Red-black balanced tree node

struc		RBNODE

		resb	RBCOMMON_size	; common head (list and flags)
RBN_Parent:	resd	1		; 0Ch: parent node (NULL=root)
RBN_Left:	resd	1		; 10h: left node (lower, 0=none)
RBN_Right:	resd	1		; 14h: right node (higher, 0=none)
					;      (hardcoded: right = left + 4)
RBN_Data:				; 18h: possible data of tree node

endstruc				; size 18h = 24 bytes

; ------------- Red-black balanced tree root

struc		RBROOT

		resb	RBCOMMON_size	; common head (list and flags)
RBR_Node:	resd	1		; 0Ch: pointer to first node (0=empty)
RBR_Count:	resd	1		; 10h: number of nodes in the tree

endstruc				; size 14h = 20 bytes

; ------------- Red-black color of node

RB_RED		EQU	0		; red color of node (hardcoded)
RB_BLACK	EQU	1		; black color of node

; ------------- Red-black flags

RB_ROOT		EQU	B0		; this is the root (else this is node)

SEMAPHOR.INC - Semaphore and mutex


; =============================================================================
;
;                        Litos - Semaphore and mutex
;
; =============================================================================

; ------------- Semaphore

struc		SEM

		resb	TASKLOCK_size	; 0: task lock
SEM_Count:	resd	1		; 0Ch: lock counter, > 0 unlocked
SEM_Sleepers:	resd	1		; 10h: 1=some task is waiting (else 0)

endstruc				; size 14h = 20 bytes

; ------------- Mutex

struc		MUT

		resb	SEM_size	; 0: semaphore
SEM_Owner:	resd	1		; 14h: owner
SEM_Recursion:	resd	1		; 18h: recursion counter

endstruc				; size 1Ch = 28 bytes

; ------------- Semaphore counter value

SEM_UNLOCKED	EQU	1		; semaphore is unlocked (hardcoded)
SEM_LOCKED	EQU	0		; semaphore is locked (hardcoded)

SIGNAL.INC - Signals


; =============================================================================
;
;                                Litos - Signals
;
; =============================================================================

SIG_TOTAL	EQU	64		; total number of signals

; ------------- Signal info (partialy hardcoded, must be DWORD aligned)

struc		SIGINFO

SI_SignalDW:				; signal byte parameters as DWORD
SI_Signal:	resb	1		; 0: signal number (see below)
SI_Reason:	resb	1		; 1: signal reason (see below)
SI_Error:	resb	1		; 2: error code (see below, 0=no error)
SI_Type:	resb	1		; 3: signal format type (see below)

SI_Sender:	resd	1		; 4: sender (task address)

SI_TrapAddr:				; trap: instruction address
SI_TimerID:				; timer: timer identifier
SI_PollFile:				; poll: file descriptor
SI_RTValue:				; real-time signal: signal value
SI_Param1:	resd	1		; 8: first parameter

SI_TrapNum:				; trap: trap number
SI_TimerOver:				; timer: overrun count
SI_Param2:	resd	1		; 0Ch: second parameter

SI_TrapErr:				; trap: trap error code
SI_Param3:	resd	1		; 10h: third parameter

SI_Param4:	resd	1		; 14: fourth parameter

endstruc				; size 18h = 24 bytes

; ------------- Signal reason

;SIR_USER	EQU	0		; sent by kill(), sigsend(), raise()
;SIR_KERNEL	EQU	1		; sent by kernel, software (1 to 127)
SIR_TRAP	EQU	256-1		; sent by trap
;SIR_QUEUE	EQU	256-2		; sent by sigqueue()
;SIR_TIMER	EQU	256-3		; sent by timer
;SIR_MESG	EQU	256-4		; sent by message queue
;SIR_ASYNC	EQU	256-5		; sent by AIO completed
;SIR_SIGIO	EQU	256-6		; sent by queued SIGIO
;SIR_TKILL	EQU	256-7		; sent by tkill() or tgkill()
;SIR_DETHREAD	EQU	256-8		; sent by execve()

; ------------- Signal format type

;SIT_GENERAL	EQU	0		; undefined
SIT_TRAP	EQU	1		; trap
;SIT_KILL	EQU	2		; kill
;SIT_TIMER	EQU	3		; timer
;SIT_POLL	EQU	4		; poll
;SIT_CHLD	EQU	5		; child
;SIT_RT		EQU	6		; real-time signal
;SIT_MESQ	EQU	7		; message queue

; ------------- SIGILL error codes

ILL_CODE	EQU	1		; illegal opcode
;ILL_OPER	EQU	2		; illegal operand
;ILL_ADDR	EQU	3		; illegal addressing mode
;ILL_TRAP	EQU	4		; illegal trap
;ILL_PCODE	EQU	5		; privileged opcode
;ILL_PREG	EQU	6		; privileged register
;ILL_FPU	EQU	7		; coprcessor error
;ILL_STACK	EQU	8		; internal stack error

;ILL_MAX		EQU	8		; last SIGILL error code

; ------------- SIGTRAP error codes

TRAP_BREAK	EQU	1		; process breakpoint
TRAP_TRACE	EQU	2		; process trace trap

;TRAP_MAX	EQU	2		; last SIGTRAP error code

; ------------- SIGFPE error codes

FPE_NO		EQU	1		; no math coprocessor or emulator
FPE_IDIV	EQU	2		; integer divide by zero
FPE_SEGM	EQU	3		; coprocessor segment overrun
;FPE_IOVF	EQU	4		; integer overflow
;FPE_FDIV	EQU	5		; floating point divide by zero
;FPE_FOVF	EQU	6		; floating point overflow
;FPE_FUND	EQU	7		; floating point underflow
;FPE_FRES	EQU	8		; floating point inexact result
;FPE_FOPER	EQU	9		; floating point invalid operand
;FPE_FSUB	EQU	10		; subscript out of range

;FPE_MAX		EQU	10		; last SIGFPE error code

; ------------- SIGSEGV error codes

SEGV_OVER	EQU	1		; overflow (INTO instruction)
SEGV_BOUND	EQU	2		; bound range exceeded (BOUND instr.)
SEGV_TSS	EQU	3		; invalid TSS
SEGV_IRET	EQU	4		; IRET exception error
;SEGV_MAPERR	EQU	5		; address not mapped
;SEGV_ACCESS	EQU	6		; invalid access rights

;SEGV_MAX	EQU	6		; last SIGSEGV error code

; ------------- SIGBUS error codes

BUS_SEGM	EQU	1		; segment not present
BUS_STACK	EQU	2		; stack segment fault
BUS_ALIGN	EQU	3		; invalid address alignment
;BUS_EXIST	EQU	4		; non-exist physical address
;BUS_HARDW	EQU	5		; hardware error

;BUS_MAX		EQU	5		; last SIGBUS error code

; ------------- SIGCHLD error codes

;CHLD_EXIT	EQU	1		; child has exited
;CHLD_KILL	EQU	2		; child was killed
;CHLD_DUMP	EQU	3		; child terminated abnormally
;CHLD_TRAP	EQU	4		; traced child has trapped
;CHLD_STOP	EQU	5		; child has stopped
;CHLD_CONT	EQU	6		; child has continued

;CHLD_MAX	EQU	6		; last SIGCHLD error code

; ------------- SIGPOLL error codes

;POLL_IN	EQU	1		; data input available
;POLL_OUT	EQU	2		; output buffer available
;POLL_MSG	EQU	3		; input message available
;POLL_ERR	EQU	4		; I/O error
;POLL_HIGH	EQU	5		; high priority input available
;POLL_HUP	EQU	6		; device disconnected (hang up)

;POLL_MAX	EQU	6		; last SIGPOLL error code

; ------------- Signal queue item

struc		SIGNAL

		resb	LIST_size	; 0: list of signals
SIGNAL_Info:	resb	SIGINFO_size	; 8: signal info
 
endstruc                                ; size 20h = 32 bytes

; ------------- Signal action (size hardcoded in SignalSetAction,SignalTestIgn)

struc		SIGACT

SA_Handler:	resd	1		; 0: signal handler (see below)
					;  input parameter without SIGINFO:
					;	- signal number
					;  input parameters with SIGINFO:
					;	- signal number
					;	- pointer to SIGINFO
					;	- user data
SA_Flags:	resd	1		; 4: flags (see below)
SA_Mask:	resd	2		; 8: signal action mask

endstruc				; size 10h = 16 bytes

; ------------- Special signal handler (hardcoded in DoSignal)

SA_ERR		EQU	-1		; error return from signal
SA_DEF		EQU	0		; default signal handling (hardcoded)
SA_IGN		EQU	1		; ignore signal (hardcoded)
SA_TERM		EQU	2		; terminate the process
SA_DUMP		EQU	3		; terminate the process and dump core
SA_STOP		EQU	4		; stop the task
SA_PAR		EQU	5		; use parent's signal action handler

; ------------- Signal action flags

SA_NOCHILD	EQU	B0		; don't generate SIGCHLD when stop
SA_NOWAIT	EQU	B1		; don't create zombies when stop
SA_SIGINFO	EQU	B2		; use handler with SIGINFO
SA_RESTART	EQU	B28		; get restarting signals
SA_NOBLOCK	EQU	B30		; don't block signal in the handler
SA_RESET	EQU	B31		; reset handler to default after event

; ------------- Shared table of signal actions
; Table contains signals 1 to 63, signal 0 is not used.
; Offset of signal action in the table can be computed as "signal_number * 16".

struc		SIGTAB

		resb	SPINLOCK_size	; 0: table lock
ST_Ref:		resd	1		; 4: reference counter of table
		resd	2		; 8: ...padding
ST_Action:	resb	SIGACT_size * (SIG_TOTAL-1) ; 10h: table of signals

endstruc				; size 400h = 1024 bytes

; ------------- Signal numbers

SIGNULL		EQU	0		; unused signal (invalid, reserved)
; TODO: should we use this signal as SIGCONT? (it need not to store into queue)

SIGHUP		EQU	1		; hang up controlling terminal
					; (serial line was dropped, lost DCD)
					; new usage: re-read configuration
					; default action: terminate
SIGINT		EQU	2		; interrupt from keyboard (Ctrl+C)
					; default action: terminate
SIGQUIT		EQU	3		; quit from keyboard (Ctrl+\, SysRq)
                                        ; default action: terminate + dump
SIGILL		EQU	4		; illegal instruction
                                        ; default action: terminate + dump
SIGTRAP		EQU	5		; trace/breakpoint trap (debugging)
                                        ; default action: terminate + dump
SIGABRT		EQU	6		; abort, abnormal termination
                                        ; default action: terminate + dump
SIGIOT		EQU	SIGABRT
SIGBUS		EQU	7		; bus error
                                        ; default action: terminate + dump
SIGFPE		EQU	8		; floating-point exception
                                        ; default action: terminate + dump
SIGKILL         EQU     9               ; kill, forced-process termination
					; (cannot be caught or ignored)
					; default action: terminate
SIGUSR1		EQU	10		; user defined signal 1
					; default action: terminate
SIGSEGV		EQU	11		; invalid memory reference
                                        ; default action: terminate + dump
SIGUSR2		EQU	12		; user defined signal 2
					; default action: terminate
SIGPIPE		EQU	13		; write to pipe with no readers
					; default action: terminate
SIGALRM		EQU	14		; real timer expired (uses real time)
					; default action: terminate
SIGTERM		EQU	15		; request process termination
					; (unlike SIGKILL it can be ignored)
					; default action: terminate
SIGSTKFLT	EQU	16		; coprocessor stack error
					; default action: terminate
SIGCHLD		EQU     17		; child process stopped or terminated
					; (if ignored it creates zombie
					; waiting for "wait" system call)
					; default action: ignore
SIGCLD		EQU     SIGCHLD
SIGCONT		EQU	18		; resume execution, if stopped
					; (cannot be caught or ignored),
                                        ; default action: continue
SIGSTOP		EQU	19		; pause process execution
					; (cannot be caught or ignored),
					; default action: stop
SIGTSTP		EQU	20		; suspend request from tty (Ctrl+Z)
					; default action: stop
SIGTTIN		EQU	21		; tty input for background process
					; default action: stop
SIGTTOU		EQU	22		; tty output for background process
					; default action: stop
SIGURG		EQU	23		; urgent condition on socket
					; default action: ignore
SIGXCPU		EQU	24		; CPU time limit exceeded
                                        ; default action: terminate + dump
SIGXFSZ		EQU	25		; file size limit exceeded
                                        ; default action: terminate + dump
SIGVTALRM	EQU	26		; virtual timer expired (computes
					; only time spent in process)
					; default action: terminate
SIGPROF		EQU	27		; profiling timer expired (computes
					; time spent in process and system)
					; default action: terminate
SIGWINCH	EQU	28		; window (or terminal) resizing
					; default action: ignore
SIGIO		EQU	29		; input or output becomes possible
SIGPOLL		EQU	SIGIO		; Pollable event
					; default action: terminate
SIGPWR		EQU	30		; power supply failure
					; default action: terminate
SIGSYS		EQU	31		; bad system call (bad argument)
                                        ; default action: terminate + dump
SIGUNUSED	EQU	31		; unused signal

; ------------- Signal context

struc		SIGCONTEXT

SC_EIP:		resd	1		; 0: EIP register
SC_CS:		resw	2		; 4: CS register
SC_Flags:	resd	1		; 8: Flags
SC_Trap:	resd	1		; 0Ch: trap number
SC_ESP:		resd	1		; 10h: ESP register
SC_SS:		resw	2		; 14h: SS register
SC_CR2:		resd	1		; 18h: CR2 register
SC_Error:	resd	1		; 1Ch: error code
SC_SEG:		resb	SEGSTACK_size	; 20h: segments in stack
SC_REG:		resb	REGSTACK_size	; 30h: registers in stack
SC_Mask:	resd	2		; 50h: old signal mask
		resd	2		; 58h: ...reserved
SIGC_FPU:	resb	FPUSTATE_size	; 60h: FPU state

endstruc				; size 0D0h = 208 bytes

; ------------- Signal frame

struc		SIGFRAME

SF_Return:	resd	1		; 0: pointer to return code SF_RetCode
SF_Signal:	resd	1		; 4: signal number
SF_Context:	resb	SIGCONTEXT_size	; 8: signal context
SF_RetCode:	resb	8		; 0D8h: return code

endstruc				; size 0E0h = 224 bytes

SPINLOCK.INC - Spin-lock


; =============================================================================
;
;                             Litos - Spin-lock
;
; =============================================================================

SPINLOCK_size	EQU	4		; size of spin-lock



; Currently not used - locked places are very short, it would not be efficient.

%ifdef _UNUSED_

RWSPIN_size	EQU	4		; size of read/write spin-lock

%endif ; _UNUSED_

TASK.INC - Task


; =============================================================================
;
;                               Litos - Task (thread)
;
; =============================================================================

%ifdef MINI
IOBITMAP_MAX	EQU	400h		; max I/O address space (1 KB)
%else
IOBITMAP_MAX	EQU	10000h		; max I/O address space (64 KB)
%endif
IOBITMAP_SIZE	EQU	IOBITMAP_MAX/8	; size of I/O bit map (8 KB or 128 B)

%ifdef MINI
TASK_SIZE	EQU	1000h		; task-state segment size (4 KB)
TASK_SHIFT	EQU	14		; number of bits of task-state segment
%else
TASK_SIZE	EQU	4000h		; task-state segment size (16 KB)
TASK_SHIFT	EQU	14		; number of bits of task-state segment
%endif

TASK_MASK	EQU	~(TASK_SIZE-1)	; mask of task address

%ifdef MINI
TASK_MAX	EQU	250		; maximal number of tasks
TASK_ADMIN	EQU	20		; number of tasks reserved for admin
%else
TASK_MAX	EQU	4090		; maximal number of tasks
					; (don't increase it above 4090,
					; it is limit due to GDT table size)
TASK_ADMIN	EQU	50		; number of tasks reserved for admin
%endif

; ------------- Macro - reschedule run-queue (%1 = run-queue)

%macro		RESCHEDULE 1
		and	dword [%1+RUNQ_NextSched],byte 0 ; schedule request
%endmacro

; ------------- Resource limits

struc		RESLIM

RL_StackSize:	resd	1		; maximal size of the stack
RL_VirtMemReg:	resd	1		; maximal regions of virtual memory
RL_PagesUsed:	resd	1		; maximal number of physical pages

endstruc

; ------------- Task

struc		TASK
		resb	OBJECT_size	; 0: task object head

				; === hardware hardcoded part (TSS, size 208Ch)
		alignb	4,resb 1
TASK_TSS:
TASK_Back:	resw	1		; +0: back link (selector of prev.task)
		resw	1
TASK_ESP0:	resd	1		; +4: ESP of privilege level 0
TASK_SS0:	resw	1		; +8: SS of privilege level 0
		resw	1
TASK_ESP1:	resd	1		; +0Ch: ESP of privilege level 1
TASK_SS1:	resw	1		; +10h: SS of privilege level 1
		resw	1
TASK_ESP2:	resd	1		; +14h: ESP of privilege level 2
TASK_SS2:	resw	1		; +18h: SS of privilege level 2
		resw	1
TASK_CR3:	resd	1		; +1Ch: CR3 (PDE base physical address)
TASK_EIP:	resd	1		; +20h: EIP
TASK_Flags:	resd	1		; +24h: EFLAGS
TASK_EAX:	resd	1		; +28h: EAX
TASK_ECX:	resd	1		; +2Ch: ECX
TASK_EDX:	resd	1		; +30h: EDX
TASK_EBX:	resd	1		; +34h: EBX
TASK_ESP:	resd	1		; +38h: ESP
TASK_EBP:	resd	1		; +3Ch: EBP
TASK_ESI:	resd	1		; +40h: ESI
TASK_EDI:	resd	1		; +44h: EDI
TASK_ES:	resw	1		; +48h: ES
		resw	1
TASK_CS:	resw	1		; +4Ch: CS
		resw	1
TASK_SS:	resw	1		; +50h: SS
		resw	1
TASK_DS:	resw	1		; +54h: DS
		resw	1
TASK_FS:	resw	1		; +58h: FS
		resw	1
TASK_GS:	resw	1		; +5Ch: GS
		resw	1
TASK_LDT:	resw	1		; +60: LDT segment selector
		resw	1
TASK_Trace:	resb	1		; +64h: Debug trace flag (see below)
		resb	1
TASK_IOBase:	resw	1		; +66h: offset of I/O permiss. bit map
TASK_Redirect:	resb	32		; +68h: sw interrupt redirect. bit map
					;	0=interrupt redirected back
					;	1=interrupt handled protected
TASK_IOBitmap:	resb	IOBITMAP_SIZE	; +88h: I/O permission bit map
					;	0=access to port is allowed
					;	1=access denied, #GP signaled
TASK_IOTerm:	resd	1		; +2088h: I/O bit map terminator (= -1)
				; === hardware hardcoded part (FPU, size 70h)
		alignb	4,resb 1
TASK_FPU:
TASK_CWD:	resd	1		; +0: FPU register CWD
TASK_SWD:	resd	1		; +4: FPU register SWD
TASK_TWD:	resd	1		; +8: FPU register TWD
TASK_FIP:	resd	1		; +0Ch: FPU register FIP
TASK_FCS:	resd	1		; +10h: FPU register FCS
TASK_FOO:	resd	1		; +14h: FPU register FOO
TASK_FOS:	resd	1		; +18h: FPU register FOS
TASK_FPUData:	resb	8*10		; +1Ch: FPU data registers
TASK_FPUStatus:	resd	1		; +6Ch: FPU software status
				; === variable part
		alignb	4,resb 1
TASK_TR:	resd	1		; task register (to switch task)
TASK_TSSIndex:	resd	1		; TSS index
TASK_Link:	resb	TREE_size	; tree link to other tasks
TASK_State:	resb	1		; current task state (see below)
TASK_Type:	resb	1		; task type (see below)
TASK_CPU:	resb	1		; index of current/last CPU
TASK_Process:	resd	1		; pointer to parent process
TASK_ProcList:	resb	LIST_size	; list of threads in a process
TASK_VirtMem:	resd	1		; pointer to virtual memory descriptor

		alignb	4,resb 1
TASK_CPUMask:	resd	1		; mask of allowed CPUs
TASK_ExitCode:	resd	1		; exit code
		alignb	8,resb 1
TASK_Alarm:	resb	ALARM_size	; alarm to wake-up sleeping task
TASK_ConOutMask:resd	1		; mask of output consoles
TASK_ConInMask:	resd	1		; mask of input consoles
				; --- priority
TASK_AbsPrio:	resb	1		; absolute priority (0 to 31,see below)
TASK_RelPrio:	resb	1		; relative priority (-31 to +31)
TASK_AddPrio:	resb	1		; temporary increment priority (max.20)
TASK_MaxPrio:	resb	1		; maximal priority (0, 31 or 24)
TASK_Priority:	resb	1		; current priority
TASK_Focus:	resb	1		; bool flag, <> 0 task with user focus
				; --- statistik
		alignb	4,resb 1
TASK_StartTime:	resd	2		; time of task start
TASK_RunTime:	resd	2		; running time of task
				; --- run-queue
		alignb	4,resb 1
TASK_Queue:	resb	LIST_size	; link to task queue list
TASK_QueueLev:	resd	1		; current level in task/wait queue
TASK_RunQueue:	resd	1		; pointer to current/last run-queue
TASK_TaskQueue:	resd	1		; pointer to current task queue
TASK_Remaining:	resd	1		; remaining time quantum (in 100-ns)
;TASK_LockSem:	resd	1		; pointer to locked semaphore
;TASK_ValSem:	resd	1		; value for locked semaphore
TASK_TaskList:	resb	LIST_size	; task lock list entry
TASK_TaskLock:	resd	1		; pointer to TASKLOCK (NULL=none)
				; --- Signals (0..31:regular, 32..63:real-time)
		alignb	4,resb 1
TASK_SigMask:	resd	2		; signal mask (1=enabled)
TASK_Signal:	resd	2		; signals (1=ON)
TASK_SigLock:	resb	SPINLOCK_size	; signal queue list lock
TASK_SigQueue:	resb	LIST_size	; link to signal queue list
TASK_SigMax:	resd	1		; max. number of signals in queue
TASK_SigNum:	resd	1		; number of signals in signal queue
TASK_SigRTNum:	resb	32		; number of real-time signals
TASK_SigAction:	resd	1		; pointer to table of signal actions
TASK_SigRes:	resd	1		; reserve signal entry for SIGKILL
				; --- Traps
		alignb	4,resb 1
TASK_TrapNum:	resd	1		; last trap number
TASK_TrapErr:	resd	1		; last error code

;TASK_Process:	resd	1		; pointer to owner process
;TASK_User:	resd	1		; pointer to current user
				; --- Resource limits
		alignb	4, resb 1
TASK_ResLim:	resb	RESLIM_size	; current resource limits
TASK_PagesUsed:	resd	1		; number of used physical pages

				; === stack
TASK_Stack0:	resb	TASK_SIZE-4-TASK_Stack0 ; stack (nearly 8 KB or 4 KB)
TASK_Stack:				; 4000h-4 or 1000h-4: end of stack
		resd	1		; reserve for disable reaching boundary
endstruc				; size 4000h = 16 KB (or 1000h = 4 KB)

; ------------- Debug trace flag

PTRACED		EQU	B0		; trace flag - task is traced

; ------------- Task state

TASK_RUNNING	EQU	0		; task is running
TASK_FALLASLEEP	EQU	1		; task is falling asleep
TASK_SLEEP	EQU	2		; task sleeps
TASK_WAKEUP	EQU	3		; task is waking-up
TASK_PAUSE	EQU	4		; task is paused
;TASK_LOCKED	EQU	6		; task is locked (semaphore)

;TASK_SWAPPING	EQU	5		; task is swapping
;TASK_DEAD	EQU	6		; task is dead

; ------------- Task type

TASK_IDLE	EQU	0		; idle task
TASK_INIT	EQU	1		; init system task
TASK_DAEMON	EQU	2		; system daemon
TASK_DEVICE	EQU	3		; device task
TASK_USER	EQU	4		; user task

; ------------- Task absolute priority (0 to 31)

PRIORITY_MAXDRV	EQU	31		; maximal priority - drivers
PRIORITY_MAXUSR	EQU	24		; maximal priority - user

PRIORITY_REAL	EQU	26		; real-time priority (only drivers)
PRIORITY_HIGH	EQU	20		; high priority
PRIORITY_NORMAL	EQU	14		; normal priority (middle priority)
PRIORITY_LOW	EQU	8		; low priority
PRIORITY_IDLE	EQU	2		; idle priority

PRIORITY_MIN	EQU	0		; minimal priority

; ------------- Task queue

QUEUE_LISTS	EQU	32		; number of lists in task queue

struc		QUEUE

QUEUE_Total:	resd	1		; 0: total number of tasks in queue
QUEUE_Mask:	resd	1		; 4: mask of non-empty lists
QUEUE_List:	resb	LIST_size*QUEUE_LISTS ; 8: lists of TASKs

endstruc				; size 108h = 264 bytes

; ------------- Task run-queue (it is accessed only by 1 CPU, no lock required)
; Hash index = priority 0 to 31, time is in 100-nanosecs

struc		RUNQ

RUNQ_Current:	resd	1		; 0: pointer to current task queue
RUNQ_Expired:	resd	1		; 4: pointer to expired task queue
RUNQ_NextSched:	resd	1		; 8: 100-ns time to next scheduling
RUNQ_Elapsed:	resd	1		; 0Ch: elapsed 100-ns time
RUNQ_Total:	resd	1		; 10h: total number of running tasks
RUNQ_Idle:	resd	1		; 14h: idle task
RUNQ_Flags:	resd	1		; 18h: flags
					;	B0: 1=memory error signaled
					;	B1: 1=I/O error signaled
					;	B2: 1=watchdog signaled
					;	B3: 1=memory,I/O check disabled
					;	B4: 1=watchdog check disabled
RUNQ_CountMem:	resd	1		; 1Ch: 100-ns timer for mem.,I/O check
RUNQ_CountDog:	resd	1		; 20h: 100-ns timer for watchdog check
		resd	1		; 24h: padding

;RUNQ_RunTime:	resd	2		; 10h: running time accumulator
;RUNQ_IdleTime:	resd	2		; 18h: idle time accumulator
;RUNQ_Running:	resd	1		; 1Ch: pointer to running task

endstruc				; size 28h = 40 bytes

; ------------- Delays for new NMI checks (in seconds, max. 215)

NMI_DELAYMEM	EQU	15		; delay for new memory or I/O check
NMI_DELAYDOG	EQU	5		; delay for new watchdog check

; ------------- Macro - get current task (%1 = destination register)

%macro		CURRENT 1
		mov	%1,TASK_MASK	; prepare mask
		and	%1,esp		; get thread info
%endmacro

TASKLOCK.INC - Task lock


; =============================================================================
;
;                             Litos - Task lock
;
; =============================================================================

; ------------- Task lock

struc		TASKLOCK

		resb	LIST_size	; 0: task list
TLOCK_Lock:	resb	SPINLOCK_size	; 8: lock of task list

endstruc				; size 0Ch = 12 bytes

; ------------- Task lock with lockable data

struc		TASKLOCKD

		resb	TASKLOCK_size	; task lock
TLOCK_Data:	resd	1		; 0Ch: pointer to lockable data

endstruc				; size 10h = 16 bytes

; ------------- Task lock with integer variable
; Notes: Only lower part of TLOCK_Ref and TLOCK_Set need to be initialized
; with variables of lower operand size.

struc		TASKLOCKV

		resb	TASKLOCKD_size	; task lock with lockable data
TLOCK_Ref:	resd	2		; 10h: reference value to compare
TLOCK_Set:	resd	2		; 18h: value to set

endstruc				; size 20h = 32 bytes

; ------------- Callback function flags for integer variable
; Notes: Floating point variable is not supported - it could raise exception.

TLOCK_BYTE	EQU	0		; operand size - byte
TLOCK_WORD	EQU	1		; operand size - word
TLOCK_DWORD	EQU	2		; operand size - double word
TLOCK_QWORD	EQU	3		; operand size - quadruple word

TLOCK_SIGNED	EQU	0 << 2		; operand signification - signed
TLOCK_UNSIGNED	EQU	1 << 2		; operand signification - unsigned

TLOCK_NOP	EQU	0 << 3		; operation - do nothing
TLOCK_SET	EQU	1 << 3		; operation - set value
TLOCK_INC	EQU	2 << 3		; operation - increment
TLOCK_DEC	EQU	3 << 3		; operation - decrement

TLOCK_FALSE	EQU	0 << 5		; test - not suitable
TLOCK_TRUE	EQU	1 << 5		; test - suitable
TLOCK_EQ	EQU	2 << 5		; test - equal "="
TLOCK_NEQ	EQU	3 << 5		; test - not-equal "!="
TLOCK_LT	EQU	4 << 5		; test - less than "<"
TLOCK_LE	EQU	5 << 5		; test - less or equal "<="
TLOCK_GT	EQU	6 << 5		; test - greater than ">"
TLOCK_GE	EQU	7 << 5		; test - greater or equal ">="

; ------------- Callback function flags for bit variable

TLOCK_BIT0	EQU	0		; bit number 0
TLOCK_BIT1	EQU	1		; bit number 1
TLOCK_BIT2	EQU	2		; bit number 2
TLOCK_BIT3	EQU	3		; bit number 3
TLOCK_BIT4	EQU	4		; bit number 4
TLOCK_BIT5	EQU	5		; bit number 5
TLOCK_BIT6	EQU	6		; bit number 6
TLOCK_BIT7	EQU	7		; bit number 7

TLOCK_BITNOP	EQU	0 << 3		; bit operation - do nothing
TLOCK_BITSET	EQU	1 << 3		; bit operation - set bit
TLOCK_BITRES	EQU	2 << 3		; bit operation - reset bit
TLOCK_BITCOM	EQU	3 << 3		; bit operation - complement bit

TLOCK_BITFALSE	EQU	0 << 5		; bit test - not suitable
TLOCK_BITTRUE	EQU	1 << 5		; bit test - suitable
TLOCK_BITWASSET	EQU	2 << 5		; bit test - bit was set
TLOCK_BITWASRES	EQU	3 << 5		; bit test - bit was reset

TLOCK_BITEXT	EQU	B7		; ...reserved

TEXT.INC - Text string


; =============================================================================
;
;                            Litos - Text string
;
; =============================================================================

; ------------- Macro - small text string constant, BYTE length (%1 = text)

%macro		STEXT	1
		db	%%L2-%%L1	; length of text
%%L1:		db	%1		; text
%%L2:
%endmacro

; ------------- Macro - medium text string constant, WORD length (%1 = text)

%macro		MTEXT	1
		dw	%%L2-%%L1	; length of text
%%L1:		db	%1              ; text
%%L2:
%endmacro

; ------------- Macro - large text string constant, DWORD length (%1 = text)

%macro		LTEXT	1
		dd	%%L2-%%L1	; length of text
%%L1:		db	%1		; text
%%L2:
%endmacro

; ------------- Variable text string

struc		TEXT

TEXT_Ref:	resd	1		; 0: reference counter
TEXT_Length:	resd	1		; 4: text length
TEXT_Text:				; 8: text

endstruc				; length 8 + text length

; ------------- Macro - variable text string constant (%1 = text in quotes)

%macro		TXT	1
		dd	40000000h	; reference counter
		dd	%%L2-%%L1	; length of text
%%L1:		db	%1		; text
%%L2:
%endmacro

TRAPS.INC - Traps and interrupts


; =============================================================================
;
;                                  Litos - Traps
;
; =============================================================================

; ------------- Trap stack frame

struc		TRAPSTACK

TRAP_ES:	resw	2		; 0: ES register
TRAP_DS:	resw	2		; 4: DS register
TRAP_Reg:	resb	REGSTACK_size	; 8: registers
TRAP_Code:	resd	1		; 28h: error code (-1=trap, 0=system)
TRAP_Int:	resb	REGINT_size	; 2Ch: EIP, CS and Flags
				; these 2 entries are not used in kernel mode
TRAP_ESP:	resd	1		; 38h: stack ESP
TRAP_SS:	resw	2		; 3Ch: stack SS

endstruc				; size 40h = 64 bytes

TREE.INC - Tree list


; =============================================================================
;
;                              Litos - Tree list
;
; =============================================================================

; ------------- Tree list entry

struc		TREE

		resb	LIST_size	; 0: sibling list
TREE_Child:	resd	1		; 8: pointer to a child (NULL=none)
TREE_Parent:	resd	1		; 0Ch: pointer to parent (NULL=none)

endstruc				; size 16 bytes

VIRTMEM.INC - Virtual memory


; =============================================================================
;
;                            Litos - Virtual memory
;
; =============================================================================

VIRTMEM_MID	EQU	SYSTEM_ADDR/2	; middle of task virtual space

;VIRTMEM_MAXREG	EQU	2048		; maximal number of regions

; ------------- Virtual memory descriptor

struc		VMDESC

		resb	RBROOT_size	; 0: red-black tree root of region list
VMD_Cache:	resd	1		; 14h: cache, last used region (0=none)
VMD_PGD:	resd	1		; 18h: pointer to page global directory
VMD_Lock:	resb	SPINLOCK_size	; 1Ch: lock
VMD_HeapStart:	resd	1		; 20h: start address of the heap
VMD_HeapEnd:	resd	1		; 24h: address behind end of the heap
VMD_Ref:	resd	1		; 28h: reference counter
		resd	1		; 2Ch: ...padding

endstruc				; size 30h = 48 bytes

; ------------- Table of virtual memory functions

struc		VMFUNC

VMF_Open:	resd	1		; 0: open the region
					;   INPUT: EBX = pointer to VMREG
VMF_Close:	resd	1		; 4: close the region
					;   INPUT: EBX = pointer to VMREG
endstruc

; ------------- Virtual memory region

struc		VMREG

		resb	RBNODE_size	; 0: red-black tree node
VMR_Start:	resd	1		; 18h: start address (=first byte)
VMR_End:	resd	1		; 1Ch: end address (=last byte)
					;   (size = end-start+1)
VMR_Flags:	resd	1		; 20h: flags (see below)
VMR_File:	resd	1		; 24h: mapped file (NULL=none)
VMR_Offset:	resd	2		; 28h: offset in mapped file
VMR_Share:	resb	LIST_size	; 30h: list of share regions
					;      or list of file mapping
VMR_Parent:	resd	1		; 38h: pointer to parent VMDESC
VMR_FuncTab:	resd	1		; 3Ch: pointer to functions VMFUNC

endstruc				; size 40h = 64 bytes

; ------------- Virtual memory region flags

VMR_READ	EQU	B0		; pages can be read
VMR_WRITE	EQU	B1		; pages can be written
VMR_EXEC	EQU	B2		; pages can be executed
VMR_SHARE	EQU	B3		; pages are shared by several processes
VMR_ALLACCESS	EQU	VMR_READ+VMR_WRITE+VMR_EXEC ; all access

VMR_MAYREAD	EQU	B4		; VM_READ flag may be set
VMR_MAYWRITE	EQU	B5		; VM_WRITE flag may be set
VMR_MAYEXEC	EQU	B6		; VM_EXEC flag may be set
VMR_MAYSHARE	EQU	B7		; VM_SHARE flag may be set
VMR_MAYALLACCESS EQU	VMR_MAYREAD+VMR_MAYWRITE+VMR_MAYEXEC ; may all access

VMR_GROWSDOWN	EQU	B8		; can expand toward lower addresses
VMR_GROWSUP	EQU	B9		; can expand toward higher addresses
;VMR_SHM	EQU	B10		; region is used for IPC shared memory
;VMR_DENYWRITE	EQU	B11		; maps a file tha cannot be written
;VMR_EXECUTABLE	EQU	B12		; the region maps an executable file
;VMR_LOCKED	EQU	B13		; pages are locked,cannot swap them out
;VMR_IO		EQU	B14		; memory mapped I/O
;VMR_SEQ_READ	EQU	B15		; applic. accesses pages sequentially
;VMR_RAND_READ	EQU	B16		; applic. accesses pages randomly
;VMR_DONTCOPY	EQU	B17		; don't copy region on fork
;VMR_DONTEXPAND	EQU	B18		; cannot expand through mremap()
;VMR_RESERVED	EQU	B19		; does not swap out the region

VMR_COMMIT	EQU	B25		; pages are commited (else reserved)
VMR_FINDUP	EQU	B26		; search free region up
VMR_FINDDOWN	EQU	B27		; search free region down
VMR_OVERWRITE	EQU	B28		; overwrite existing region

VMR_STACK	EQU	VMR_ALLACCESS+VMR_MAYALLACCESS+VMR_GROWSDOWN ; stack

VT102.INC - VT102 terminal emulator


; =============================================================================
;
;                        Litos - VT102 terminal emulator
;
; =============================================================================

VT_TABS		EQU	256		; number of tab stops
VT_PARAMS	EQU	16		; maximal number of parameters

; ------------- VT100 terminal interface

struc		VTERM

VT_Disp:	resd	1		; 0: display driver DDPB
VT_WKeyData:	resd	1		; 4: private data for write function
VT_WKeyFnc:	resd	1		; 8: function to write key into keyb.
					;	INPUT:	EAX = key code
					;		EBX = private data
VT_Addr:	resd	1		; 0Ch: videomemory address
VT_Dim:		resb	DIMENSION_size	; 10h: display dimension
VT_Pos:		resb	POSITION_size	; 18h: cursor position
VT_ScanLine:	resd	1		; 20h: bytes per scan line
VT_Current:	resd	1		; 24h: current cursor address
VT_CharsetG0:	resd	1		; 28h: pointer to G0 charset CHARSET
VT_CharsetG1:	resd	1		; 2Ch: pointer to G1 charset CHARSET
VT_PushG0:	resd	1		; 30h: pointer to saved G0 charset
VT_PushG1:	resd	1		; 34h: pointer to saved G1 charset
VT_CharSet:	resd	1		; 38h: pointer to current charset
VT_Esc:		resd	1		; 3Ch: Escape service address
VT_Flags:	resb	1		; 40h: flags (see below)
VT_Flags2:	resb	1		; 41h: flags 2 (see below)
VT_Attrib:	resb	1		; 42h: attribute flags (see below)
VT_PushAttrib:	resb	1		; 43h: saved attribute flags
VT_Color:	resb	1		; 44h: current color (77h max)
VT_ColorAttr:	resb	1		; 45h: current color with attributes
VT_PushColor:	resb	1		; 46h: saved color
VT_DefColor:	resb	1		; 47h: default color
VT_UnderColor:	resb	1		; 48h: underline color (0 to 15)
VT_DarkColor:	resb	1		; 49h: dark color (0 to 15)
VT_ParNum:	resb	1		; 4Ah: number of parameters
VT_UtfNum:	resb	1		; 4Bh: UTF code character counter
VT_UtfChar:	resd	1		; 4Ch: UTF character accumulator
VT_ClearChar:	resd	1		; 50h: 2 clearing characters with color
VT_PushAddr:	resd	1		; 54h: saved cursor address
VT_EndAddr:	resd	1		; 58h: end address of display
		resd	1		; 5Ch: ...padding
VT_PushPos:	resb	POSITION_size	; 60h: saved cursor position
VT_ScrollT:	resd	1		; 68h: top line of scrolling region
VT_ScrollB:	resd	1		; 6Ch: bottom line of scroll. region+1
VT_Tabs:	resb	VT_TABS/8	; 70h: tab stops
VT_Palettes:	resb	16*3		; 90h: palettes (16 RGB colors 0..63)
VT_Param:	resd	VT_PARAMS	; C0h: parameters

endstruc				; size 100h = 256 bytes

VT_DimW		EQU	VT_Dim+DIM_W	; display width
VT_DimH		EQU	VT_Dim+DIM_H	; display height
VT_PosX		EQU	VT_Pos+POS_X	; cursor X
VT_PosY		EQU	VT_Pos+POS_Y	; cursor Y
VT_PushPosX	EQU	VT_PushPos+POS_X ; saved cursor X
VT_PushPosY	EQU	VT_PushPos+POS_Y ; saved cursor Y

; ------------- VT100 flags

VT_CURSON	EQU	B0		; cursor is ON
VT_UPDATE_BIT	EQU	1		; update cursor
VT_UPDATE	EQU	1<<VT_UPDATE_BIT
VT_NEEDWRAP	EQU	B2		; wrap request
VT_AUTOCR	EQU	B3		; auto CR after LF
VT_CTRL		EQU	B4		; display control characters
VT_ALTCHAR	EQU	B5		; use alternate character set
VT_USESCROLL	EQU	B6		; use scroll window
VT_ESCQUES	EQU	B7		; escape sequence "ESC [ ?"

VT_DEFFLAGS	EQU	VT_CURSON+VT_AUTOCR ; default flags

; ------------- VT100 flags 2

VT_MONO		EQU	B0		; use monochromatic mode
VT_512CHAR	EQU	B1		; use 512-character display
VT_HIGHBG	EQU	B2		; use high intensity background
VT_USEUTF	EQU	B3		; use UTF character code
VT_ANSI		EQU	B4		; ANSI.SYS compatible

VT_DEFFLAGS2	EQU	VT_ANSI ;VT_USEUTF+VT_512CHAR ; default flags 2

; ------------- Attribute flags

VT_INVIS	EQU	B0		; invisible
VT_UNDER	EQU	B1		; underline
VT_INVERSE	EQU	B2		; inverse
VT_DARK		EQU	B3		; dark
VT_INTENS	EQU	B4		; intensity
VT_BGINTENS	EQU	B5		; background intensity
VT_BLINK	EQU	B6		; blinking

VT_CHARG1_BIT	EQU	7		; use G1 charset (else G0)
VT_CHARG1	EQU	1<<VT_CHARG1_BIT

VT_DEFATTR	EQU	0		; default attribute flags
VT_ATTRMASK	EQU	B0+B1+B2+B3+B4+B5+B6 ; attribute mask

Back to source browser