;	[]===========================================================[]
;
;	NOTICE: THIS PROGRAM BELONGS TO AWARD SOFTWARE INTERNATIONAL(R)
;	        INC. IT IS CONSIDERED A TRADE SECRET AND IS NOT TO BE
;	        DIVULGED OR USED BY PARTIES WHO HAVE NOT RECEIVED
;	        WRITTEN AUTHORIZATION FROM THE OWNER.
;
; 	[]===========================================================[]
;

		PAGE	60,132
		TITLE	PNPBIOS  -- Plug and Play BIOS Interface
;----------------------------------------------------------------------------
;Rev	Date	 Name	Description
;----------------------------------------------------------------------------
;R105	04/22/99 TNY	Add ICH SMBus node if B1-stepping.
;R104	03/10/99 GAR	Add PC87363
;R103	03/23/99 RCH	Report ACPI I/O usage to prevent unreported I/O of
;			HCT testing for AMD-755/756 south bridge
;R102	03/11/99 TNY	Add FWH memory address node for ICH to patch 
;			unreported memory by HCT testing software
;R101	03/10/99 GAR	Add LPC47U33X
;R100	03/10/99 GAR	Add PC87364/366
;R99	03/09/99 GAR	Add LPC47B27X
;R68G	02/24/98 RIC	Add VIA686HM_Port Device Node for the sensor of VIA
;			686A chip.
;R63B   02/24/99 MIL	For SIS 5595 SouthBridge, We shuld always report
;			290-297h I/O Space decode for Hardware monitor.
;R98	02/12/99 GAR	Add ITE8702/12
;R97A	02/10/99 GAR	Change Ali5113D to Ali5113B
;R97	02/02/99 GAR	Add Ali5113D and cancel R94
;R96	01/28/99 BAR	Update ESCD DMI use SMM mode.
;R95	01/26/99 GAR	Support W83627F/HF
;R79B	01/21/99 RCH	Added a switch to patch booting NT failure from i558
;			boot ROM thru LAN. Note: this switch will cause DOS
;			ICU failure report.
;R94	01/19/99 GAR	Ali513x and Ali513xB use Ali513xF code
;R93	12/18/98 TNY	Add ICH GPIO and ACPIBase node.
;R91A	11/10/98 KEN	Fixed bug that the AMIDIAG report error while running
;			"Plug-n-Play Test", and mask the unnecessary codes to
;			process DX register in routine "get_next_node_no".
;R91	11/03/98 PHI	Changed the method to get device node number with
;			fixed number to avoid that the win95/98 report "new
;			device found" according to un-related device node
;			changing.
;R90	10/29/98 TNY	Add "Add_340h_Node" option.
;R89	10/22/98 GAR	Add code about ITE8673 and ITE8693
;R87	09/29/98 KVN	Release DMI and ESCD pool in flash ROM when not define
;			"ESCD_SUPPORT" and "FLASH_SUPPORT" in BIOS.CFG
;R86A	09/15/98 LAW	fixed code miss
;			We can't set NODES_INDEX in a ASM file, Because NODE_PROC
;			macro will set the temp_num wrong, and PNPE0.ASM compare
;			this NODE_NAME is not macth
;			So we use db to set this value
;			added "Special_Report_PS2_Node_for_Windows98" to use
;R86	09/10/98 LAW	fixed WINDOWS 98 cann't scan PNP0510 node again, so
;			PS2 NODE move to last NODE, for Reduce install IrDA
;			Driver again.
;R68F	09/02/98 RIC	Add SMBus_Port Device Node for VIA 596 chip.
;R58C   08/24/98 MIL    For Cyrix Cx5530 PCI Test fails on Video PCI Header,
;                       The New PCI header (VSA) will fills in the subsystem
;			vendor ID and report 40800000h-40FFFFFFh as the frame
;			buffer base address.
;			So, we must removed the region from the motherboard
;			resource list.
;R85	08/20/98 KEN	1. Add declaration of "NO_ISA_PNP" to unsupport ISA/PNP
;			   cards for the system doesn't contain ISA bus.
;			2. Supplement declaration of "ESCD_SUPPORT".
;R84	07/15/98 DNL	Added PnP bios function support for ACPI mode to prevent
;			"PnP BIOS testing error" for HCT 7.6
;R83	07/14/97 GAR	Added W83977EF SUPPORT
;R58B   07/08/98 MIL	Added extra memory space report for Cyrix MediaGXm +
;			Cx5530 to prevent SCT testing error.
;R82	05/27/98 LAW	add support NS351
;R81	05/11/98 RCH	Fixed system lose DMI function if ACPI is enabled
;R80	03/17/98 LAW	add Ali513xB
;R79A	02/06/98 RCH	Fixed DOS/ICU reporting "NVS resource conflict error"
;			if system memory bigger than 256Mb.
;R79	01/12/98 RCH	Rewrite dynamic node report method to have various
;			combinations of adding device nodes. The old method
;			will have wrong device node if the building order
;			is changed.
;R78	01/07/98 RCH	Report 64K ROM space at F0000H if "AVIDEO_AT_F000"
;			is defined
;R77	12/30/97 STV	Fixed Mylex DAC960 RAID controller card cannot work
;			successfully while the PS/2 mouse is not plugging,
;			the card will set to disable automatically while
;			without PS/2 mouse.PS/2 mouse plugging flag isn't
;			config_table+5 ,so change to SYSTEM1_BYTE(bit 2).
;			Config_Table+5 is EBDA flag. See atorgs.asm
;R68E	12/22/97 RIC	Remove IRQ9 node of VIA 576B chipset.
;R63A	11/17/97 TNY	Added "Add_290h_Node" for SiS chipset built-in
;			hardware monitoring IC I/O port decode.
;R76	11/06/97 LAW	added Ali513xF.SIO for New Ali513x support FastIR and KB
;			,Mouse Power on
;R75	10/28/97 LAW	added "NO_USE_KB"
;R74	10/28/97 LAW	added "ITE8681", "ITE8671", "W83877ATF"
;R73	10/22/97 KEN	Write the checksum word of ESCD to flash ROM to
;			validate the correction of ESCD more seriously.
;R68D	10/20/97 RIC	Modify ACPI_Port I/O Node.
;R58A   10/07/97 MIL	Added extra memory space report for GX86 + Cx5520
;			to prevent SCT testing error, I/O space as well.
;R72A	09/30/97 RAX	Fixed coding missed.
;R72	09/23/97 RAX	Add Cardbus support for WIN95 version before OSR2.
;R50B	08/18/97 DRS	Fixed updating ESCD fail
;R68C	08/07/97 RIC	Use ACPI_Port to establish ACPI I/O Node.
;R71	08/04/97 LAW	added "W83977ATF" Support
;R68B	07/30/97 RIC	Added a VIA_ACPI_IO_Node_Index in VIA ACPI Chip I/O
;			Base Address device node for POST Disable/Enable.
;R68A	07/18/97 RIC	Modify VIA ACPI Chip I/O Base Address device node
;			to 5F00-5FFF from 5F00-5F4F.
;			Because this chipset is not fully decode in ACPI I/O
;			Base Address & have very much garbage I/O !!!!
;R51C	07/11/97 TNY	Change ACPI I/O port to be 5e00h from 6100h, it can
;			fix some wave-table driver conflict in win95.
;R70	07/02/97 RAX	Add define create SMBaseMemNode report to patch SCT5.40
;			unreport memory test fail.
;R69	07/03/97 LAW	Added "NS309" for NS PC87309VLJ
;R60B	06/27/97 RCH	The patch for SiS5571 is done by chipset dependent
;			file(chippost.asm).
;R68	06/25/97 RIC	Add VIA ACPI Chipset I/O & IRQ device node.
;R67	06/25/97 RCH	Added memory usage report for switch "COMBINE_ISA_ROM"
;			to prevent "Unreport memory" for SCT.
;R66    06/19/97 TNY    Add "Add_Trident_3DImage975_Node".
;R65	06/15/97 LAW	Added support SMC37M60x, SMC37M61x
;R64	05/29/97 LAW	Added W83977TF SUPPORT
;R60A	05/08/97 RCH	The "unreport memory error" is caused by wrong memory
;			sizing, kill the un-necessary code
;R63	05/07/97 TNY	Add "Add_294h_Node" definition.
;R61	05/02/97 LAW	added W9775119.sio (Winbond W83977AF + ALi5119 com4)
;R60	05/02/97 RCH	Added patch code to pass SCT test for M/B's not
;			decode memory space properly. It's not a good idea
;			but customer don't want to fix the hardware.
;R59	04/23/97 LAW	Added "No_USE_KB" for some MB use extension KB
;R58	04/18/97 RCH	Added extra memory space report for GX86 to prevent
;			SCT testing error, I/O space as well.
;R57	04/17/97 DRS	Added SMC68X.SIO for SMC37C68X
;R56	03/22/97 KVN	Store DMI data to F000 shadow to fix Intel LDCM bug
;R55	03/20/97 LAW	Added SMC37C93XAPM, SMC37C93XFR
;R51B	03/07/97 TNY	Change SMBus I/O port to be 5f00h from 6200h, it can
;			fix some joystick driver conflict in win95.
;R54	03/06/97 LAW	Added W83877AF + W83877TF
;R53	03/06/97 LAW	Added SMC67x.SIO for SMC37C67x
;R50A	02/20/97 AVN	Fixed if enable reset configuration date in setup
;			and screen fail in bootup, because backup second CUP
;			code will destroy some useful code.
;R52	02/19/97 RCH	Fixed SCT 5.3 "unreport memory" error if USB legacy
;			support is enabled.
;R36A   02/14/97 KVN    Add function 53h-57h for LDCM utility
;R51A	02/12/96 TNY	Change reported length for fix IDE driver installed
;			error.
;R51	01/14/96 TNY	Add ACPI and SMBus controller report address.
;R50	12/24/96 AVN	Support MP Secondary Update Code For 1M/2M EEPROM
;R49	12/20/96 RCH	The SCT v5.xx reports "unreported memory" for PCI
;			devices that need ROM space but without ROM requesting
;			implemented in config. space 30H-33H. Chips like NCR
;			810/860, AHA7850/60/70 have the same problem.
;R45A	12/19/96 RCH	Kill R45, this cause onboard device's ROM can not
;			be assigned at address C8000H.
;R48	12/16/96 LAW	Added "SMC37C67X" "SMC37C68X" "ITE8679"
;			SMC37C67X  ---> SMC93X
;			SMC37C68X  ---> SMC93X
;			ITE8679    ---> ITE8680
;R47A	12/12/96 DNL	Because Yamaha 715 update new driver, so clear R47
;R47	12/11/96 DNL	Some pnp device driver (Yamaha 715 windows 3.1 driver)
;			pass wrong descriptor cause system halt, so added
;			"Special_Patch_For_PNP_Driver" definition to fixed this problem.
;R46	12/09/96 LAW	Modify superio define
;			ALi513x + ALi5123 -- > ALi513X
;			ALi514x + ALi5123 -- > ALi514X
;			W86967AF + W83977AF -- > W83977AF
;			NS307 + NS308 -- > NS308
;R45	11/29/96 RCH	Temporary patch for SCT testing for onboard SCSI ROM
;			usage.
;R44	11/26/96 RAY	Report mem addr FEE00000-FEE0FFFF & FEC00000-FEE0FFFF
;			for local APIC & IO APIC addressing space in
;			multi-processor system
;R39B	10/17/96 LAW	Added W83967AF mouse IRQ 12 run-time disable/enable
;R43A	10/02/96 TNY	Delete unnessary codes.
;R43	10/01/96 TNY	Fix KBC hang in PnP BIOS test in SCT5.10 for SuperIO
;			with KBC .
;R42	10/01/96 JSN	Added IRQ12_Ctl_By_Ct define,because Some M/B use
;			chipset's built-in PS2/AT KBC (exp. ALi M152x...).
;R41	09/30/96 RCH	It's not necessary to report 512Kb space at 0FFF80000H
;			if the extended BIOS is disabled ( bit 7 of PIIX3 reg.
;			4EH). Note: modify this table, the relative file -
;			CFEATURE.ASM for INTEL chipsets should be changed too.
;R40	09/26/96 RCH	SCT v5.10 still failed with 4Kb memory test even
;			the VGA driver was installed for onboard ATI/VGA,so
;			patch it with claimming 0C0000H-0C7FFFH occupied by
;			M/B
;R39A	09/26/96 LAW	Added NS307 mouse IRQ 12 run-time disable/enable
;R37B	09/18/96 RCH	The SiS/6205 VGA WIN/95 driver will open 4Mb space at
;			address 512Mb and cause SCT v5.10 memory decoding
;			test failure
;R39	09/13/96 RCH	Added mouse IRQ 12 disable/enable run-time control to
;			release IRQ for other devices dynamically, note: all
;			super I/Os with internal KBC should implement this
;			routine.
;R38	09/12/96 RCH	Fixed "Forced Configuration" for System Board of
;			SCT v5.10 testing while installing WIN95 first time
;R37A	08/29/96 RCH	More patches for SiS/551X,5596 & 571. Those chipsets
;			wrap around address FFEE0000-FFEFFFFF to address
;			E0000-FFFFF and cause WIN95 "4K-Page memory test"
;			failed.
;R32A	08/15/96 RAY	Fix error coding of R32. This error cause Win95
;			to have 2 PS2 mouse devnode after running the
;			Installation program or "Add New Hardware".
;R37	08/12/96 RCH	The SiS/5596 always decode memory space FFEF000-
;			FFEF6FFF & FFEFB000-FFEFFFFF and cause SCT v5.10
;			failed, so claim this range as M/B memory range if
;			define TOP_2ND_1MB_USED_64KB, note all CFG file for
;			SiS/5596 should have this switch
;R36	08/12/96 KVN	Add new DMI spec 2.0 support
;R35	08/12/96 RCH	SCT v5.10 will read I/O port 3F3H and get value 0FCH
;			, so report it as motherboard device to avoid testing
;			failure
;R34	08/12/96 KEN	Support read/write ESCD from/to F000 shadow RAM, for
;			Win95 SCT v5.10 to pass the ESCD Configuration test.
;R33	08/09/96 RCH	Report device type PNP0F13(PS2 mouse port) instead of
;			PNP0F0E(Microsoft compatible port)
;R32	07/25/96 RAY	Support dynamic enable/disable PS2 mouse:
;
;			  1. move the PS2 mouse devnode from PNPCHIP.ASM
;			  2. add related Get/Set routines
;			  3. before invoking the Get/Set routines, program
;			     the F000 shadow RAM as write enable
;
;R31	07/25/96 RAY	Change all the FIO_DSP to IO_DSP which will claim all
;			the I/O	ports in the devnode to be fully 16 bit
;			decode. This is added to let the BIOS to pass the
;			SCT v5.10 so as to apply for the Windows 95 logo
;
;R30B	07/23/96 KEN	Fix R30 using wrong descriptors.
;R30A	07/22/96 TNY	Fix always update ESCD after ICU driver installed.
;			It's a temporary solution, Ken will solve it with
;			a better method.
;R29B	07/05/96 RCH	More fix for "ESCD Configuration" testing for non
;			"ESCD_M2" BIOS. Note : This patch still failed with
;			reading ESCD data under SCT v5.10 , should not define
;			"ESCD_M2" if you to pass this testing.
;R30	07/02/96 RAY	1. Claim the EXT memory size, & top memory at 4G area
;			   as the motherboard resource as required by the
;			   SCT 5.10.
;			2. Also claim 4D0h-4D1h, CF8h-CFFh for PCI system
;R29A	06/27/96 RCH	R29 cause ICU v1.23 can not execute while EMM386
;			installed.
;R29	06/26/96 KEN	Fixed ESCD testing problem of Windows 95 SCT v5.10.
;			This problem occured when ESCD_M2 defined.
;			Since the testing item switch to DOS prompt and run
;			NVRAM.EXE, this will cause the BIOS to process ESCD
;			as real mode. The solution is to verify the entry
;			mode and actual mode whether matching or not. If the
;			modes mismatch, the BIOS will return error code as
;			FUNCTION_NOT_SUPPORT.
;R28	05/24/96 KEN	Fixed 3Com installation program passed incorrect
;			BiosSelector bug. This cause the utility hang and
;			only occured at v4.3 of this utility.
;R26B	04/25/96 DNL	Fixed R26A coding mistake
;R27	04/16/96 KVN	Pack DMI function become a module and put it in
;			0F000h-0F800h
;R26A	04/15/96 DNL	Fixed coding mistake
;R24B	04/05/96 KEN	Restore Check_16Bit_Stack routine, for other module
;			to call this function.
;R26	04/02/96 DNL	Add DOCK BIOS support
;R25	03/14/96 KEN	Report FUNC_NOT_SUPPORT for ESCD function, if once
;			write ESCD failed.
;R24A	01/15/96 KEN	Reserve original updating ESCD method.
;R24	01/12/96 KEN	Support updating ESCD with high memory (below 4GB).
;R23	12/29/95 RCH	Added DMI/BIOS functions support, BIOS reserve 4kb
;			(0FC000-0FCFFF) for DMI data storage.
;R18A	12/16/95 RCH	Support ESCD run-time function for EISA systems
;R22A	12/07/95 RAY	R22 cause Win95 to find H/W again if any one of the
;			devices in onboard_node is disabled.
;
;			So, a better way to resolve the bug that R22 wanted
;			to solve, we should do the followings:
;
;			1. restore the original order of onboard_node
;			2. in every *.SIO, make the 2 serial port nodes'
;			   node number not too close, i.e. COM1 node as
;			   the first node & COM2 node as the last node
;
;R22	12/01/95 RAY	Bug: When PS2 mouse node is removed in Windows 95,
;			     device manager report COM5 instead of COM1
;			Solution: Swap the order of devnodes between
;				  onboard_node & chip_node.
;R21	11/10/95 KEN	Store BiosSelector to stack for some customize routine
;			to get the selector.
;R20	10/27/95 KEN	Record RDDATA_NODE as 8 bytes address, since we manage
;			I/O resource with 8 bytes unit.
;R19	10/23/95 RAY	Support Audio devnode
;R18	10/02/95 RCH	Support EISA/PnP function
;R17	09/18/95 KEN	Fix 16 bit stack fault, when install CS4232 in windows.
;			Check_16Bit_Stack also be used in ESCDCHIP.
;R16	09/13/95 KEN	Add RD_DATA port device node.
;R15	08/17/95 KEN	Remove PS/2 mouse device node to PNPCHIP for customize
;			IRQ 12.
;R14	08/08/95 KEN	Fill reserved field with zero for function 40h to
;			match NSP testing.
;R13	07/05/95 KEN	Re-structure device node index method.
;R12	07/01/95 RAY	Support dynamic Get/Set devnode
;R11	06/23/95 RCH	Disable interrupt before execute service routine to
;			prevent system hang with mouse moving
;R10	06/07/95 KEN	Get largest device nodes size with actual enabled
;			device nodes, since Win95 PnP_BIOS test fail if not
;			found the size of device node matching the largest
;			node size.
;R09	05/19/95 RCH	Kill codes for function "Get_APM_Table" due to PnPBIOS
;			test failed(Trap 0D occured), Note, this is the
;			temporary solution.
;R08	05/12/95 KEN	Get EscdSelector from BiosSelector, since some
;			applications pass invalid EscdSelector. Example
;			Phoenix NVRAM, Intel NSPTEST.
;R07	04/17/95 KEN	Remove DEFAULT_ESCD table from PNPCHIP to PNPBIOS
;R06	04/12/95 KEN	Add recognizing for 32-bit stack of protected mode.
;R05	04/11/92 KEN	Fix ESCD checksum error bug.
;R04	04/11/92 KEN	Fix some bugs for running Win95.
;R03	03/15/95 KEN	Fix bug for reserved function call (Function 6,7,8)
;R02	03/08/95 DNL	Added PS/2 mouse device node support
;R01	03/08/95 DNL	Follow Microsoft WINDOWS 95 system BIOS design spec.
;R00	10/01/94 KEN	Initial Revision

.386P

.XLIST
;[]========================================================================[]
;
;	Include file definition
;
;[]========================================================================[]

		INCLUDE BIOS.CFG
		INCLUDE COMMON.EQU		;R18
		INCLUDE PNP.EQU
		INCLUDE	COMMON.MAC		;R50
ifdef 	ACPI_Support				;R62
		include	acpi_ct.inc		;R62
		include	acpi.inc		;R62
endif;	ACPI_Support				;R62

ifdef	CARDBUS_SUPPORT				;R72A
		include	bsetup.inc		;R72A
endif	;CARDBUS_SUPPORT			;R72A

ifdef DMI_ENABLED				;R23
ifdef	FLASH_SUPPORT	;R87
;R27		include dmi.equ		;R23
;R27 start
		extrn	Get_DMI_Information:near
		extrn	Get_DMI_Struct:near
		extrn	Set_DMI_Struct:near
		extrn	DMI_Get_Struct_Chng_Info:near	;R36A
		extrn	DMI_Control:near		;R36A
		extrn	Get_GPNV_Info:near		;R36A
		extrn	Read_GPNV:near			;R36A
		extrn	Write_GPNV:near			;R36A
;R27 end
endif	;FLASH_SUPPORT	;R87
endif; DMI_ENABLED				;R23

IRQ12_CTRL	=	0			;R75
ifndef	NO_USE_KB				;R75
;R46 - start
;------------------
; ALi5123/513x/514x
;------------------
;R94ifdef	ALi513XB
;R94ALi5123			EQU	1
;R94endif;	ALi513XB
;R94ifdef	ALi513X
;R94ALi5123			EQU	1
;R94endif;	ALi513X
;R97 - start
;R97Aifdef	ALi5113D
ifdef	ALi5113B				;R97A
ALi5123			EQU	1
endif;	ALi5113B				;R97A
;R97Aendif;	ALi5113D
ifdef	ALi513XB
ALi5123			EQU	1
endif;	ALi513XB
ifdef	ALi513X
ALi5123			EQU	1
endif;	ALi513X
;R97 - end
ifdef	ALi514X
ALi5123			EQU	1
endif;	ALi514X

;R104 - start
ifdef	PC87363
	PC87364		=	1
endif	;PC87363
;R104 - end
;R100 - start
ifdef	PC87366
	PC87364		=	1
endif	;PC87366

ifdef	PC87364
	IRQ12_CTRL	=	1
endif	;PC87364
;R100 - end

;------------------
; W83967/977
;------------------
;R95 - start
ifdef	W83627F
W83977AF		EQU	1
endif;	W83627F

ifdef	W83627HF
W83977AF		EQU	1
endif;	W83627HF
;R95 - end

ifdef	W83967AF
W83977AF		EQU	1
endif;	W83967AF

ifdef	W83977ATF				;R71
W83977AF		EQU	1		;R71
endif;	W83977ATF				;R71

ifdef	W83977EF				;R24
W83977AF		EQU	1		;R24
endif;	W83977EF				;R24

ifdef	W83977TF				;R24
W83977AF		EQU	1		;R24
endif;	W83977TF				;R24

;------------------
; NS307/308
;------------------
ifdef	NS308
NS307			EQU	1
endif;	NS308
;R46 - end

;R48 - start
;R53ifndef	SMC37C93X
;R53ifdef	SMC37C67X
;R53SMC37C93X			EQU	1
;R53endif;	SMC37C67X
;R53endif;	SMC37C93X

;R57 ifndef	SMC37C93X
;R57 ifdef	SMC37C68X
;R57 SMC37C93X			EQU	1
;R57 endif;	SMC37C68X
;R57 endif;	SMC37C93X

;R89 - start
ifdef   ITE8693
ITE8680                         EQU     1
endif;  ITE8693
ifdef   ITE8673
ITE8680                         EQU     1
endif;  ITE8673
;R89 - end

ifdef	ITE8679
ITE8680				EQU	1
endif;	ITE8679
;R48 - end
ifdef	ITE8681					;R74
ITE8680				EQU	1	;R74
endif;	ITE8681					;R74
ifdef	ITE8671					;R74
ITE8680				EQU	1	;R74
endif;	ITE8671					;R74

;R54 - start
ifdef	W83877AF
W83877F				EQU	1
endif;	W83877AF
ifdef	W83877TF
W83877F				EQU	1
endif;	W83877TF
;R54 - end
ifdef	W83877ATF				;R74
W83877F				EQU	1	;R74
endif;	W83877ATF				;R74

;R55 - start
ifdef	SMC37C93XAPM
SMC37C93X			EQU	1
endif;	SMC37C93XAPM
ifdef	SMC37C93XFR
SMC37C93X			EQU	1
endif;	SMC37C93XFR
;R55 - end

ifdef	SMC37M60x				;R65
SMC37C67X			EQU	1	;R65
endif;	SMC37M60x				;R65
ifdef	SMC37M61x				;R65
SMC37C67X			EQU	1	;R65
endif;	SMC37M61x				;R65
ifdef	SMC37B77x
SMC37C67X			EQU	1
endif;	SMC37B77x

;R39 - start
;R75IRQ12_CTRL	=	0

ifdef	SMC37C93X
IRQ12_CTRL	=	1
endif;	SMC37C93X

;R101 - start
ifdef	LPC47U33X
	LPC47B27X	EQU	1
endif;	LPC47U33X
;R101 - end
;R99 - start
ifdef	LPC47B27X
IRQ12_CTRL	=	1
endif;	LPC47B27X
;R99 - end

ifdef	PC87306
IRQ12_CTRL	=	1
endif;	PC87306

ifdef	ALI5123
IRQ12_CTRL	=	1
endif;	ALI5123

;R75ifndef	NO_USE_KB			;R59
ifdef	ITE8680
IRQ12_CTRL	=	1
endif;	ITE8680
;R75endif;	NO_USE_KB			;R59

;R98 - start
ifdef	ITE8712
ITE8702			EQU	1
endif	;ITE8712

ifdef	ITE8702
IRQ12_CTRL	=	1
endif	;ITE8702
;R98 - end

ifdef	NS307				;R39A
IRQ12_CTRL	=	1		;R39A
endif;	NS307				;R39A

ifdef	W83977AF			;R39B
IRQ12_CTRL	=	1		;R39B
endif;	W83977AF			;R39B

ifdef	SMC37C67X			;R53
IRQ12_CTRL	=	1		;R53
endif;	SMC37C67X			;R53

ifdef	SMC37C68X			;R57
IRQ12_CTRL	=	1		;R57
endif;	SMC37C68X			;R57

ifdef	W83977_N_ALi5119		;R61
IRQ12_CTRL	=	1		;R61
endif;	W83977_N_ALi5119		;R61

ifdef	NS351					;R82
NS309			EQU	1		;R82
endif;	NS351					;R82
ifdef	NS309				;R69
IRQ12_CTRL	=	1		;R69
endif;	NS309				;R69

;R94- start
;R97ifdef	ALi513x
;R97ALi513xF		EQU	1
;R97endif	;ALi513x
;R97ifdef	ALi513xB
;R97ALi513xF		EQU	1
;R97endif	;ALi513xB
;R94 - end
ifdef	ALi513xF			;R76
IRQ12_CTRL	=	1		;R76
endif;	ALi513xF			;R76
endif;	NO_USE_KB			;R75

ifdef	IRQ12_BY_W877_IRQIN
IRQ12_CTRL	=	1
endif;	IRQ12_BY_W877_IRQIN

if	IRQ12_CTRL
		extrn	Irq12_Control:near
endif;	IRQ12_CTRL
;R39 - end

.LIST

;[]========================================================================[]
;
;	External label definition
;
;[]========================================================================[]

ifdef	PNP_BIOS
;R15		EXTRN	SYSTEM4_BYTE:byte		;R13
;R13		extrn	CHIP_NODE_TOTAL:abs		;R12
;R13		extrn	ONBOARD_NODE_TOTAL:abs		;R12
		EXTRN	CHIP_NODE_INDEX:byte		;PNPCHIP.ASM
		EXTRN	CHIP_NODE_PROC:byte		;PNPCHIP.ASM
;R13		EXTRN	CHIP_NODE_LARGEST:abs		;PNPCHIP.ASM
		EXTRN	ONBOARD_NODE_INDEX:byte 	;PNPIO.ASM
		EXTRN	ONBOARD_NODE_PROC:byte		;PNPIO.ASM
;R13		EXTRN	ONBOARD_NODE_LARGEST:abs	;PNPIO.ASM

		EXTRN	AUDIO_NODE_INDEX:Byte		;R19
		EXTRN	AUDIO_NODE_PROC:Byte		;R19

		EXTRN	TOTAL_NODES:byte		;PNPKERNL.ASM
		EXTRN	LARGEST_SIZE:word		;PNPKERNL.ASM	;R10
		EXTRN	Ct_Get_Resource_Map:near	;PNPCHIP.ASM
		EXTRN	Ct_Set_Resource_Map:near	;PNPCHIP.ASM
ifdef	CMOS_RAM_SUPPORT
		EXTRN	Get_Tag_Name:near		;PNPPOST.ASM
		EXTRN	Record_IO_Map:near		;PNPPOST.ASM
endif	;CMOS_RAM_SUPPORT
ifdef	ESCD_SUPPORT
;R18A IF 	BUS_TYPE EQ ISA_BUS				;R18
		EXTRN	Ct_ESCD_Info:near		;PNPCHIP.ASM
		EXTRN	Ct_Get_ESCD:near		;PNPCHIP.ASM
		EXTRN	Ct_Set_ESCD:near		;PNPCHIP.ASM
;R18A endif;	BUS_TYPE EQ ISA_BUS				;R18
endif	;ESCD_SUPPORT					;R85
		EXTRN	Ct_Buffer_Request:near		;PNPCHIP.ASM	;R25
		EXTRN	Ct_Save_Shadow:near		;PNPCHIP.ASM	;R25
		EXTRN	Ct_Restore_Shadow:near		;PNPCHIP.ASM	;R25
		EXTRN	Ct_Shadow_Write:near		;PNPCHIP.ASM	;R25
		EXTRN	Ct_Set_Shadow:near		;PNPCHIP.ASM	;R25
		EXTRN	ESCD_FLAG:byte			;PNPKERNL.ASM	;R25
;R85endif	;ESCD_SUPPORT
;R07		EXTRN	DEFAULT_ESCD:byte		;PNPCHIP.ASM
;R07		EXTRN	DEFAULT_ESCD_L:abs		;PNPCHIP.ASM
		EXTRN	PNP_RD:word			;PNPKERNL.ASM
		EXTRN	LAST_CSN:byte			;PNPKERNL.ASM

		extrn	CONFIG_TABLE:near		;R32
		extrn	KB_CNTRLR_OUT:near		;R32
		EXTRN	SYSTEM4_BYTE:byte		;R32
		EXTRN	SYSTEM1_BYTE:byte		;R77
		extrn	Ct_Shadow_Read:Near		;R32
;R56		extrn	Shadow_ESCD_Address:near	;R34

 ifdef 	IRQ12_Ctl_By_Ct							;R42
		extrn	Ct_IRQ12_Control:near		;PNPCHIP.ASM	;R42
 endif	;IRQ12_Ctl_By_Ct						;R42

;R50 - start
ifdef	MP_SUPPORT
		extrn	Check_A20_AndRecord:near
		extrn	GDTR1:near
		extrn	ESCD_INDEX:abs
		extrn	F0DATA_INDEX:abs
		extrn	A20_On:near
		extrn	A20_Off:near
endif;	MP_SUPPORT
;R50 - end

endif	;PNP_BIOS

;R02 - start
G_RAM		SEGMENT USE16 AT 0

		ORG	04H*4
		INCLUDE SEG_0.INC

		ORG	400H
		INCLUDE G_RAM.INC

		ORG	2000h		;R16
		INCLUDE	PNPDATA.INC	;R16

G_RAM		ENDS
;R02 - end

DGROUP		GROUP	FCODE
FCODE		SEGMENT USE16 DWORD PUBLIC 'CODE'
		ASSUME	CS:DGROUP,DS:NOTHING

IFDEF	PNP_BIOS

;[]========================================================================[]
;Procedure:	PNP_BIOS_Entry
;Function :	Plug and Play BIOS run-time interface entry
;Input	  :	None
;Output   :	None
;Registers:
;Note	  :
;[]========================================================================[]
		public	PNP_BIOS_Entry
		public	PNP_BIOS_Real		;R06
		public	PNP_BIOS_Prot		;R06
PNP_BIOS_Entry	proc	far
PNP_BIOS_Prot:					;R06

		pushf
		push	ebp
		push	edx			;R24
		mov	dl, PNP_PROT		;R24;protected mode
;R24		push	ax			;R21;for selector to save

;R06 - start
;R17		xor	ebp, ebp
;R17		mov	bp, ss
;R17		lar	ebp, ebp
;R17		test	ebp, 00400000h
;R24		call	Check_16Bit_Stack	;R17
		xor	ebp, ebp		;R24
		mov	bp, ss			;R24
		lar	ebp, ebp		;R24
		test	ebp, 00400000h		;R24
		jz	short Stack_16Bit
		mov	ebp, esp
		sub	esp, PARA_SIZE		;R24
		or	dl, PNP_STACK32		;R24;32 bits mode
		jmp	short Check_Stack_Done
		align	4
PNP_BIOS_Real:
		pushf
		push	ebp
		push	edx			;R24
		xor	dl, dl			;R24;real mode
;R24		push	ax			;R21;for selector to save
Stack_16Bit:
		movzx	ebp, sp
		sub	sp, PARA_SIZE		;R24
Check_Stack_Done:
;R06 - end
;R06		mov	ebp, esp
;R21		add	ebp, 10 		;16-bit stack base
;R24		add	ebp, 12			;R21
		add	ebp, DEFAULT_STACK	;R24
		mov	bPnpModeFlag, dl	;R24

; Main procedure to process BIOS function call

		push	eax
		push	ebx
		push	ecx
;R24		push	edx
		push	esi
		push	edi
		push	ds
		push	es
		push	gs	;R96 support flash_in_smbase
;R84 ;R62 - start
;R84 ifdef 	ACPI_Support
;R84 ;Return error for all PnP function calls if ACPI is enabled
;R84 		push	dx
;R84 		push	ax
;R84 		mov	dx, PM1a_CNT_BLK      	;
;R84 		in	al, dx			;Read control register
;R84 		test	al, SCI_EN		;Set SCI_EN bit
;R84 		pop	ax
;R84 		pop	dx
;R84 		jz	short @f 		;No, then continue on
;R84
;R84 ;R81 - start
;R84 		mov	ax, [ebp] 		;function code in stack
;R84 		cmp	al, 50H			;valid PnP function ?
;R84 		jae	short @F		;not PnP function.
;R84 ;R81 - end
;R84
;R84 		mov	ax, UNKNOWN_FUNC	;Yes, return with unknown function code
;R84 		jmp	short PNP_BIOS_Exit
;R84 @@:
;R84 endif;	ACPI_Support
;R84 ;R62 - end

		xor	esi, esi			;clear high word
		xor	edi, edi			;clear high word

		mov	ax, [ebp]			;function code in stack
		mov	si, offset DGROUP:FuncCode	;function code scan table
		mov	bx, offset DGROUP:FuncTable	;routine table
		mov	cx, FuncCode_L			;total functions
@@:
		cmp	al, cs:[si]
		je	short @f
		add	bx, 2
		inc	si
		loop	short @b
		mov	ax, UNKNOWN_FUNC	;unknown function code
		jmp	short PNP_BIOS_Exit
@@:
		cli					;R11
		call	word ptr cs:[bx]
PNP_BIOS_Exit:

; Process return code from individual sub-routine

		mov	dx, ax			;R24
;R24		mov	bp, ax			;save return code

		pop	gs	;R96 support flash_in_smbase
		pop	es
		pop	ds
		pop	edi
		pop	esi
;R24		pop	edx
		pop	ecx
		pop	ebx
		pop	eax
;R24		pop	ax			;R21;dummy

		add	esp, PARA_SIZE		;R24

		mov	ax, dx			;R24
;R24		mov	ax, bp			;restore return code

		pop	edx			;R24
		pop	ebp
		popf
		ret
;R03Invalid_Func:
;R03		jmp	short PNP_BIOS_Exit
;R03Reserve_Func:
;R03		mov	ax, FUNC_NOT_SUPPORT
;R03		ret

PNP_BIOS_Entry	endp

Reserve_Func:						;R03
		mov	ax, FUNC_NOT_SUPPORT		;R03
		ret					;R03

;R17 - start
;R24		public	Check_16Bit_Stack
;R24Check_16Bit_Stack:
;R24		push	eax
;R24		mov	eax, cr0
;R24		test	al, 1
;R24		jz	short @f	;jmp if real mode
;R24		xor	eax, eax
;R24		mov	ax, ss
;R24		lar	eax, eax
;R24		test	eax, 00400000h	;ZF=1 if 16 bit stack
;R24@@:
;R24		pop	eax
;R24		ret
;R17 - end
;R24B - start
		public	Check_16Bit_Stack
Check_16Bit_Stack:
;R34		push	eax

;Don't execute LAR instruction under SCT v5.10 , it cause run-time error;R29B
		test	bPnpModeFlag, PNP_PROT	;protected mode ? 	;R29B
		jz	short @F				  	;R29B

Check_16Bit_Stack1:				;R34
		push	eax			;R34
		xor	eax, eax
		mov	ax, ss
		lar	eax, eax
		test	eax, 00400000h	;ZF=1 if 16 bit stack
		pop	eax			;R34
@@:
;R34		pop	eax
		ret
;R24B - end
;R29A ;R29 - start
;R29A ;[]========================================================================[]
;R29A ; Input:	none
;R29A ; Output:	CF = 0 mode match
;R29A ;		CF = 1 mode mismatch
;R29A ;[]========================================================================[]
;R29A Verify_PnpMode:
;R29A 		push	ax
;R29A 		smsw	ax
;R29A 		xor	ah, ah
;R29A 		test	al, 1
;R29A 		jz	short @f
;R29A 		mov	ah, PNP_PROT
;R29A @@:
;R29A 		mov	al, bPnpModeFlag
;R29A 		and	al, not PNP_PROT
;R29A 		xor	al, ah
;R29A 		clc
;R29A 		jz	short @f
;R29A 		stc
;R29A @@:
;R29A 		pop	ax
;R29A 		ret
;R29A ;R29 - end

;[]========================================================================[]
;
;	Plug and Play BIOS Function Code Table
;
;[]========================================================================[]

FuncCode	label	byte
	db	00h	;00 Get Number of System Device Nodes
	db	01h	;01 Get System Device Node
	db	02h	;02 Set System Device Node
	db	03h	;03 Get Event
	db	04h	;04 Send Message
	db	05h	;05 Get Docking Station Information
	db	06h	;06 Reserved
	db	07h	;07 Reserved
	db	08h	;08 Reserved
	db	09h	;09 Set Statically Allocated Resource Information
	db	0Ah	;0A Get Statically Allocated Resource Information
	db	0Bh	;0B Get APM ID Table
	db	40h	;40 Get Plug & Play ISA Configuration Structure
	db	41h	;41 Get Extended System Configuration Data (ESCD) Info
	db	42h	;42 Read Extended System Configuration Data (ESCD)
	db	43h	;43 Write Extended System Configuration Data (ESCD)

;R23 - start
ifdef 	DMI_ENABLED
ifdef	FLASH_SUPPORT	;R87
    ;========================================================
	db	50h  	;50h Returns DMI information
	db	51h  	;51h Copies into buffer
	db	52h  	;52h Copies from buffer
	db	53h  	;53h Returns DMI Structure Change Info	;R36A
	db	54h  	;54h Controls a system action		;R36A
	db	55h  	;55h Returns info about the GPNV	;R36A
	db	56h  	;56h Reads the entire specified GPNV	;R36A
	db	57h  	;57h Writes into the GPNV		;R36A
	db	58h  	;58h Reserved Function
    ;========================================================
endif	;FLASH_SUPPORT	;R87
endif; 	DMI_ENABLED
;R23 - end

FuncCode_L	equ	$ - FuncCode

;[]========================================================================[]
;
;	Plug and Play BIOS Function Routine Table
;
;[]========================================================================[]

FuncTable	label	word
	dw	offset DGROUP:Get_Num_Nodes
	dw	offset DGROUP:Get_Device_Node
	dw	offset DGROUP:Set_Device_Node
	dw	offset DGROUP:Get_Event
	dw	offset DGROUP:Send_Msg
	dw	offset DGROUP:Get_Dock_Info
	dw	offset DGROUP:Reserve_Func
	dw	offset DGROUP:Reserve_Func
	dw	offset DGROUP:Reserve_Func
	dw	offset DGROUP:Set_Resource_Info
	dw	offset DGROUP:Get_Resource_Info
	dw	offset DGROUP:Get_APM_Table
	dw	offset DGROUP:Get_Config_Struct
	dw	offset DGROUP:Get_ESCD_Info
	dw	offset DGROUP:Read_ESCD
	dw	offset DGROUP:Write_ESCD

;R23 - start
ifdef	 DMI_ENABLED
ifdef	FLASH_SUPPORT	;R87
    ;========================================================
	dw	offset DGROUP:Get_DMI_Information  	;50h Returns DMI information
	dw	offset DGROUP:Get_DMI_Struct  		;51h Copies into buffer
	dw	offset DGROUP:Set_DMI_Struct  		;52h Copies from buffer
	dw	offset DGROUP:DMI_Get_Struct_Chng_Info  ;53h Returns DMI Structure Change Info	;R36A
	dw	offset DGROUP:DMI_Control	  	;54h Controls a system action		;R36A
	dw	offset DGROUP:Get_GPNV_Info	  	;55h Returns info about the GPNV	;R36A
	dw	offset DGROUP:Read_GPNV		  	;56h Reads the entire specified GPNV	;R36A
	dw	offset DGROUP:Write_GPNV	  	;57h Writes into the GPNV		;R36A
	dw	offset DGROUP:Reserve_Func		;58h Reserved Function
    ;========================================================
endif	;FLASH_SUPPORT	;R87
endif;	 DMI_ENABLED
;R23 - end

;[]========================================================================[]
;Procedure:	Function 0	Get Number of System Device Nodes
;Function :
;Input	  :	EBP = stack pointer for parameters
;Output   :	AX = return code
;Registers:
;Note	  :
;[]========================================================================[]

; Parameters in stack

F0BiosSelector	equ	word  ptr [ebp+10]
F0NodeSizeSeg	equ	word  ptr [ebp+8]
F0NodeSizeOff	equ	word  ptr [ebp+6]
F0NodeSize	equ	dword ptr [ebp+6]
F0NumNodesSeg	equ	word  ptr [ebp+4]
F0NumNodesOff	equ	word  ptr [ebp+2]
F0NumNodes	equ	dword ptr [ebp+2]

		public	Get_Num_Nodes
Get_Num_Nodes	proc	near

;R12		mov	ds, F0BiosSelector
;R12		mov	al, ds:TOTAL_NODES
;R12		or	al, al
;R12		jnz	short @f
;R12		mov	ax, FUNC_NOT_SUPPORT
;R12		ret
;R12@@:
;R12		mov	es, F0NumNodesSeg		;R10
;R12		mov	di, F0NumNodesOff		;R10
;R12		mov	es:[di], ax			;R10
;R12		mov	es, F0NodeSizeSeg		;R10
;R12		mov	di, F0NodeSizeOff		;R10
;R12		mov	ax, ds:LARGEST_SIZE		;R10
;R12		mov	es:[di], ax			;R10
;R10		mov	ds, F0NumNodesSeg
;R10		mov	si, F0NumNodesOff
;R10		mov	ds:[si], ax
;R10		mov	ds, F0NodeSizeSeg
;R10		mov	si, F0NodeSizeOff
;R10		mov	ax, SYSTEM_NODE_LARGEST
;R10		mov	dx, CHIP_NODE_LARGEST
;R10		cmp	ax, dx
;R10		ja	short @f
;R10		mov	ax, dx
;R10@@:
;R10		mov	dx, ONBOARD_NODE_LARGEST
;R10		cmp	ax, dx
;R10		ja	short @f
;R10		mov	ax, dx
;R10@@:
;R10		mov	ds:[si], ax
;R12		mov	ax, SUCCESS
;R12		ret

;R12 - starts
;R13		xor	ax, ax
;R13		call	Get_Maximum_Node
;R13		xchg	ah,al
;R13		mov	es, F0NumNodesSeg
;R13		mov	di, F0NumNodesOff
;R13		mov	es:[di], ax
;R13
;R13		mov	ax, SYSTEM_NODE_LARGEST
;R13		cmp	ax, CHIP_NODE_LARGEST
;R13		jae	short @f
;R13		mov	ax, CHIP_NODE_LARGEST
;R13	@@:
;R13		cmp	ax, ONBOARD_NODE_LARGEST
;R13		jae	short @f
;R13		mov	ax, ONBOARD_NODE_LARGEST
;R13	@@:
;R13		mov	es, F0NodeSizeSeg
;R13		mov	di, F0NodeSizeOff
;R13		mov	es:[di], ax
;R13 - start
		mov	ds, F0BiosSelector
		mov	al, ds:TOTAL_NODES
		mov	es, F0NumNodesSeg
		mov	di, F0NumNodesOff
		mov	es:[di], ax
		mov	es, F0NodeSizeSeg
		mov	di, F0NodeSizeOff
		mov	ax, ds:LARGEST_SIZE
		mov	es:[di], ax
;R13 - end

		mov	ax, SUCCESS

		ret
;R12 - ends

Get_Num_Nodes	endp

;[]========================================================================[]
;Procedure:	Function 1	Get System Device Node
;Function :
;Input	  :	EBP = stack pointer for parameters
;Output   :	AX = return code
;Registers:
;Note	  :
;[]========================================================================[]

; Parameters in stack

F1BiosSelector	equ	word  ptr [ebp+12]
F1Control	equ	word  ptr [ebp+10]
F1DevNodeBufSeg equ	word  ptr [ebp+8]
F1DevNodeBufOff equ	word  ptr [ebp+6]
F1DevNodeBuf	equ	dword ptr [ebp+6]
F1NodeSeg	equ	word  ptr [ebp+4]
F1NodeOff	equ	word  ptr [ebp+2]
F1Node		equ	dword ptr [ebp+2]

		public	NODES_INDEX
NODES_INDEX	LABEL	WORD
;R22A		DW	offset DGROUP:ONBOARD_NODE_INDEX	;R22
		DW	offset DGROUP:SYSTEM_NODE_INDEX
		DW	offset DGROUP:CHIP_NODE_INDEX
;R22		DW	offset DGROUP:ONBOARD_NODE_INDEX
		DW	offset DGROUP:ONBOARD_NODE_INDEX	;R22A
		DW	offset DGROUP:AUDIO_NODE_INDEX		;R19
ifdef	Special_Report_PS2_Node_for_Windows98			;R86A
		DW	offset DGROUP:PS2_NODE_INDEX		;R86
endif;	Special_Report_PS2_Node_for_Windows98			;R86A
		Public	NO_OF_NODE_TBL				;R19
NO_OF_NODE_TBL	EQU	($ - offset NODES_INDEX)/2		;R19

		public	NODES_PROC
NODES_PROC	LABEL	WORD
;R22A		DW	offset DGROUP:ONBOARD_NODE_PROC		;R22
		DW	offset DGROUP:SYSTEM_NODE_PROC
		DW	offset DGROUP:CHIP_NODE_PROC
;R22		DW	offset DGROUP:ONBOARD_NODE_PROC
		DW	offset DGROUP:ONBOARD_NODE_PROC		;R22A
		DW	offset DGROUP:AUDIO_NODE_PROC		;R19
ifdef	Special_Report_PS2_Node_for_Windows98			;R86A
		DW	offset DGROUP:PS2_NODE_PROC		;R86
endif;	Special_Report_PS2_Node_for_Windows98			;R86A

		public	Get_Device_Node
Get_Device_Node proc	near

;R12		mov	ds, F1BiosSelector
;R12		mov	al, ds:TOTAL_NODES
;R12		or	al, al
;R12		jnz	short @f
;R12		mov	ax, FUNC_NOT_SUPPORT
;R12		ret
;R12@@:
;R12		mov	es, F1NodeSeg
;R12		mov	di, F1NodeOff
;R12		xor	ah, ah
;R12		mov	al, es:[di]
;R12		cmp	al, ds:TOTAL_NODES
;R12		jb	short @f
;R12Invalid_Node:
;R12		mov	ax, INVALID_HANDLE
;R12		ret
;R12@@:
;R12;R04 - start
;R12		mov	si, F1Control
;R12		test	si, 0FFFCh
;R12		jnz	short F1_Bad_Param
;R12		or	si, si
;R12		jz	short F1_Bad_Param
;R12		cmp	si, 00000011b
;R12		je	short F1_Bad_Param
;R12;R04 - end
;R12
;R12		push	ax
;R12		inc	al
;R12		cmp	al, ds:TOTAL_NODES
;R12		jb	short @f
;R12		mov	al, -1
;R12@@:
;R12		mov	es:[di], al
;R12		pop	ax
;R12
;R12		mov	si, cs
;R12		mov	ds, si
;R12		xor	di, di				;node number counter
;R12		mov	bx, offset DGROUP:NODES_INDEX
;R12		mov	cx, 3
;R12Check_Node_Loop:
;R12		mov	si, ds:[bx]
;R12Check_Valid_Node:
;R12		cmp	byte ptr ds:[si], 0FFh		;index table end
;R12		je	short Check_Next_Table
;R12		test	byte ptr ds:[si], 80h		;disable bit
;R12		jz	short @f
;R12Check_Next_Node:
;R12		add	si, 3
;R12		jmp	short Check_Valid_Node
;R12@@:
;R12		cmp	di, ax
;R12		je	short Node_Correct
;R12		inc	di
;R12		jmp	short Check_Next_Node
;R12Check_Next_Table:
;R12		add	bx, 2
;R12		loop	short Check_Node_Loop
;R12		jmp	short Invalid_Node
;R12
;R12Node_Correct:
;R12		inc	si
;R12		mov	si, ds:[si]
;R12		mov	es, F1DevNodeBufSeg
;R12		mov	di, F1DevNodeBufOff
;R12		mov	cx, ds:[si]
;R12		push	di
;R12		cld
;R12		rep	movsb
;R12		pop	di
;R12		mov	es:[di+2], al
;R12		mov	F1Control, 02
;R12		call	Sum_Node
;R12		mov	ax, SUCCESS
;R12		ret
;R12;R04 - start
;R12F1_Bad_Param:
;R12		mov	ax, BAD_PARAM
;R12		ret
;R12;R04 - end

;R12 - starts
;R47A ifdef	Special_Patch_For_PNP_Driver		;R47
;R47A 		mov	ax,cs			;R47
;R47A 		mov	ds,ax			;R47
;R47A else	;Special_Patch_For_PNP_Driver		;R47
		mov	ds, F1BiosSelector
;R47A endif	;Special_Patch_For_PNP_Driver		;R47
;R24		mov	word ptr [ebp-12], ds	;R21
		mov	wBiosSelector, ds	;R24

	;calculate maximum devnode no.

;R13		call	Get_Maximum_Node	;AH = maximum node
		mov	ah, ds:TOTAL_NODES	;R13

	;get input devnode number in AL

		mov	es, F1NodeSeg
		mov	di, F1NodeOff
		mov	al, es:[di]

;R91A	;check for invalid node number
;R91A
;R91A		cmp	al, ah			;input node number valid ?
;R91A		jae	short Invalid_Node	;invalid !

	;check for bad parameters, bit 0,1 must be XOR

		mov	si, F1Control
		test	si, 0FFFCh
		jnz	short Err_Bad_Param
		or	si, si
		jz	short Err_Bad_Param
		cmp	si, 00000011b
		je	short Err_Bad_Param

	;return to caller with next device node number

		push	ax
;R91A		inc	al
;R91A		cmp	al, ah
;R91A		jb	short @F
;R91A		mov	al, -1
;R91A		jmp	Not_Need_get_next_node_no	;R91
;R91A	@@:
		call	get_next_node_no		;R91

;R91A	Not_Need_get_next_node_no:			;R91

		mov	es:[di], al
		pop	ax
		jc	short Invalid_Node		;R91A

	;calculate SI to point to the correct devnode pointer

		call	Get_DevNode_Pointer
		jc	short Invalid_Node

	;copy the whole devnode into destination buffer

		push	word ptr ds:[si]	;save flag

		inc	si			;skip flag
		mov	si, ds:[si]		;devnode address
		mov	es, F1DevNodeBufSeg	;dest segment
		mov	di, F1DevNodeBufOff	;dest offset
		mov	cx, ds:[si]		;first byte in devnode=length
		push	di			;save DI
		cld				;copy the whole devnode
		rep	movsb			;  into buffer
		pop	di			;restore DI

		pop	cx			;restore flag in CL
		test	cl, 00000100b		;R13;special get device node ?
		jz	short No_Special_Get	;R13
		mov	cx, F1Control		;R13

	;invoke the coresponding Get procedure if needed

		xor	si,si
		call	Invoke_Special_Get_Set

No_Special_Get: 				;R13

	;finally 1. report with correct devnode number
	;	 2. calculate checksum

		mov	es:[di+2], al
		call	Sum_Node
		mov	ax, SUCCESS
		ret

	Err_Bad_Param:

		mov	ax, BAD_PARAM
		ret

	Invalid_Node:

		mov	ax, INVALID_HANDLE
		ret
;R12 - ends

Get_Device_Node endp

;-----------------------------------------------------------
;-----------------------------------------------------------
Sum_Node	proc	near
		mov	si, di
		add	si, 12
		mov	cx, 3
block_loop:
		push	cx
		xor	ah, ah
tags_loop:
		lods	byte ptr es:[si]
		add	ah, al
		cmp	al, 79h
		je	short tags_end
		test	al, 80h
		jnz	short large_tag
		xor	cx, cx
		and	al, 07
		mov	cl, al
		jmp	short @f
large_tag:
		lods	byte ptr es:[si]
		add	ah, al
		mov	cl, al
		lods	byte ptr es:[si]
		add	ah, al
		mov	ch, al
@@:
		or	cx, cx
		jz	short tags_loop
tag_loop:
		lods	byte ptr es:[si]
		add	ah, al
		loop	short tag_loop
		jmp	short tags_loop
tags_end:
		mov	al, byte ptr es:[si]
		add	ah, al
		neg	ah
		add	es:[si], ah
		inc	si
		pop	cx
		loop	short block_loop
		ret
Sum_Node	endp

;[]========================================================================[]
;Procedure:	Function 2	Set System Device Node
;Function :
;Input	  :	EBP = stack pointer for parameters
;Output   :	AX = return code
;Registers:
;Note	  :
;[]========================================================================[]

; Parameters in stack

;R12F2BiosSelector	equ	word  ptr [ebp+12]
;R12F2Control	equ	word  ptr [ebp+10]
;R12F2DevNodeBufSeg	equ	word  ptr [ebp+8]
;R12F2DevNodeBufOff	equ	word  ptr [ebp+6]
;R12F2DevNodeBuf	equ	dword ptr [ebp+6]
;R12F2NodeSeg	equ	word  ptr [ebp+4]
;R12F2NodeOff	equ	word  ptr [ebp+2]
;R12F2Node		equ	dword ptr [ebp+2]

;R12 - starts
F2BiosSelector	equ	word  ptr [ebp+10]
F2Control	equ	word  ptr [ebp+8]
F2DevNodeBufSeg equ	word  ptr [ebp+6]
F2DevNodeBufOff equ	word  ptr [ebp+4]
F2Node		equ	word  ptr [ebp+2]
;R12 - ends
		public	Set_Device_Node
Set_Device_Node proc	near

;R12		mov	ax, FUNC_NOT_SUPPORT
;R12		ret

;R12 - starts
		mov	ds, F2BiosSelector
;R24		mov	word ptr [ebp-12], ds	;R21
		mov	wBiosSelector, ds	;R24

	;get input devnode number in AL

		mov	ax, F2Node

	;calculate DH/DL to point to the correct set devnode procedure

		call	Get_DevNode_Pointer
		jc	short Invalid_Node

	;check for bad parameters, bit 0,1 must not both be 0

		mov	cl, ds:[si]
		test	cl, 03h 		;can be set?
		jz	short Err_Bad_Param	;no, report error !

		mov	bx, F2Control
		test	bx, 0FFFCh
		jnz	short Err_Bad_Param
		or	bl, bl
		jz	short Err_Bad_Param

		mov	ch, cl
		and	ch, 03h
		cmp	ch, 01h 		;
		jne	short @F
		cmp	bl, 03h 		;set both ?
		je	short F2_Not_Static
	@@:
		test	bl, 02h 		;static set ?
		jz	short @F		;no
		test	cl, 02h 		;can be set statically ?
		jz	Err_Bad_Param		;no
	@@:
		test	bl, 01h 		;dynamic set ?
		jz	short @F		;no
		test	cl, 01h 		;can be set dynamically ?
		jz	Err_Bad_Param		;no
	@@:
		mov	cl, bl			;R13

	;invoke the coresponding Get procedure if needed

		mov	si, 2
		mov	es, F2DevNodeBufSeg	;dest segment
		mov	di, F2DevNodeBufOff	;dest offset
		mov	ds, F2BiosSelector	;R32
		call	Invoke_Special_Get_Set

	F2_Success:

		mov	ax, SUCCESS
		ret

	F2_Not_Static:

		mov	ax, NOT_SET_STATICALLY
		ret
;R12 - ends

Set_Device_Node endp

;R12 - starts
;--------------------------------------
;input	:	None
;Output :	AH = maximum node
;--------------------------------------
;R13Get_Maximum_Node	Proc	Near
;R13
;R13		mov	ah, SYSTEM_NODE_TOTAL
;R13		add	ah, CHIP_NODE_TOTAL
;R13		add	ah, ONBOARD_NODE_TOTAL
;R13		ret
;R13
;R13Get_Maximum_Node	Endp

;-----------------------------------------------------------
;input	:	AL = devnode number
;output :	NC:
;			SI - Point to "DevNode Pointer"
;			DL - index table #
;			DH - the "DH"th devnode in index table #"DL"
;		CF:
;			invalid node number
;-----------------------------------------------------------
Get_DevNode_Pointer	Proc	Near

		xor	ah, ah

		mov	si, cs
		mov	ds, si
		xor	di, di			;node number counter

		mov	bx, offset DGROUP:NODES_INDEX

;R19		mov	cx, 3			;3 index tables to check
		mov	cx, NO_OF_NODE_TBL ;no. of index tables to check ;R19
		xor	dx, dx			;DH - counter for devnode that
						;     needs special Get/Set Devnode
						;DL - index table counter
	Check_Node_Loop:

		push	cx			;R13

		mov	si, ds:[bx]
;R13		mov	dh,-1
		xor	cx, cx			;R13
		mov	cl, ds:[si]		;R13
		jcxz	short Check_Next_Table	;R13
		xor	dh, dh			;R13
		inc	si			;R13

	Check_Valid_Node:

;R13		cmp	byte ptr ds:[si], 0FFh	;index table end ?
;R13		je	short Check_Next_Table	;yes !
;R13		test	byte ptr ds:[si], 80h	;need special Get/Set ?
;R13		jz	short @F		;no need !
;R13		inc	dh			;increase counter
;R13	@@:
		test	byte ptr ds:[si], 80h	;R13;disable ?
		jnz	short @f		;R13
		cmp	di, ax			;finally found devnode ?
		je	short Node_Correct	;yes
;R91		inc	di			;
	@@:					;R13
		inc	di			;R91
		inc	dh			;R13
		add	si, 3			;next entry in index table
;R13		jmp	short Check_Valid_Node	;check again
		loop	short Check_Valid_Node	;R13

	Check_Next_Table:
		pop	cx			;R13

		inc	dl			;point to next index tbl
		add	bx, 2			;point to next index tbl
		loop	short Check_Node_Loop

		stc
		ret

Node_Correct:
		pop	cx			;R13
		clc
		ret

Get_DevNode_Pointer	Endp
;R91 - stsrt
get_next_node_no	proc	near

;R91A		push	es
		push	ds			;R91A
		push	di

		xor	ah, ah
		mov	si, cs
		mov	ds, si
		xor	di, di			;node number counter

		mov	bx, offset DGROUP:NODES_INDEX

		mov	cx, NO_OF_NODE_TBL ;no. of index tables to check ;R19
;R91A		xor	dx, dx			;DH - counter for devnode that
						;     needs special Get/Set Devnode
						;DL - index table counter
	Check_Next_Node_Loop:

		push	cx
		mov	si, ds:[bx]
		xor	cx, cx
		mov	cl, ds:[si]
		jcxz	short Check_Next_Table_Correct
;R91A		xor	dh, dh
		inc	si

	Check_Valid_Next_Node:
		cmp	di,ax
		jb	short just_next_node
;R91A - start
		ja	short Found_Next_Node	;check next available node
		test	byte ptr ds:[si], 80h	;current node disabled?
		jz	short just_next_node
		pop	cx
		jmp	short Invalid_Node_Number
	Found_Next_Node:
		test	byte ptr ds:[si], 80h	;disable node?
		jz	short Next_Node_Correct
;R91A - end
;R91A		test	byte ptr ds:[si], 80h	;disable ?
;R91A		jnz	short @f
;R91A
;R91A		cmp	di, ax			;finally found devnode ?
;R91A		je	short Next_Node_Correct	;yes
;R91A	@@:
;R91A	 	inc	al
	just_next_node:
		inc	di
;R91A     		inc	dh
		add	si, 3			;next entry in index table
		loop	short Check_Valid_Next_Node

	Check_Next_Table_Correct:
		pop	cx

;R91A		inc	dl			;point to next index tbl
		add	bx, 2			;point to next index tbl
		loop	short Check_Next_Node_Loop
		cmp	ax, di				;R91A;exceed largest node
		jae	short Invalid_Node_Number	;R91A

		mov	al, -1
		pop	di
		pop	ds				;R91A
		clc					;R91A;correct node number
;R91A		pop	es
		ret

Next_Node_Correct:
		mov	ax, di				;R91A
		pop	cx
		pop	di
		pop	ds				;R91A
		clc					;R91A;correct node number
;R91A		pop	es
		ret
;R91A - start
Invalid_Node_Number:
		pop	di
		pop	ds
		stc				;invalid node number
		ret
;R91A - end

get_next_node_no	endp

;R91 - end
;-----------------------------------------------------
;input	:	CL: bit 7 = 1 --> need special Get/Set
;		SI: = 0 --> invoke special Get
;		    = 2 --> invoke special Set
;-----------------------------------------------------
Invoke_Special_Get_Set	Proc	Near

;R13		test	cl, 80h 		;need special Get/Set
;R13		jz	short No_Need_Get_Set	;no need, skip the followings

	;calculate the correct entry point of the Get/Set Routine

		push	di
		push	ax
		movzx	bx, dl
		shl	bx, 1
		add	bx, offset DGROUP:NODES_PROC
;R13		mov	ax, 4
;R13		mul	dh
;R13		add	ax, ds:[bx]
;R13		mov	bx, ax
;R13 - start
		mov	bx, ds:[bx]
	@@:
		mov	al, ds:[bx]		;node number
		cmp	al, dh
		je	short @f
		cmp	al, 0FFh		;NODE_PROC end
		je	short No_Special_Found
		add	bx, 7			;NODE_PROC structure length
		jmp	short @b
	@@:
		inc	bx			;skip node number byte
;R13 - end
		call	word ptr ds:[bx+si]

No_Special_Found:				;R13

		pop	ax
		pop	di

No_Need_Get_Set:

		ret

Invoke_Special_Get_Set	Endp
;R12 - ends

;[]========================================================================[]
;Procedure:	Function 3	Get Event
;Function :
;Input	  :	EBP = stack pointer for parameters
;Output   :	AX = return code
;Registers:
;Note	  :
;[]========================================================================[]

;R26 - start
ifdef	DOCK_BIOS_Support

bflg_OS_ACTIVE		EQU	10000000b
bflg_OPEN_REQUEST	EQU	01000000b
bflg_UNDOCK_PERMIT	EQU	00100000b
bflg_DOCKED		EQU	00010000b

; Return / Error Codes
EVENTS_NOT_PENDING		EQU	86h
SYSTEM_NOT_DOCKED 		EQU	87h
MSG_NOT_SUPPORTED 		EQU	8Eh

; Event Messages
emsg_ABOUT_TO_CHANGE_CONFIG	EQU	0001h
emsg_DOCK_CHANGED		EQU	0002h
emsg_SYSTEM_DEVICE_CHANGED	EQU	0003h
emsg_CONFIG_CHANGE_FAILED	EQU	0004h
emsg_UNKNOWN_SYSTEM_EVENT	EQU	0FFFFh

; Response Messages
rmsg_OK 			EQU	00h
rmsg_ABORT			EQU	01h

; Control Messages
cmsg_UNDOCK_DEFAULT_ACTION	EQU	40h
cmsg_POWER_OFF			EQU	41h
cmsg_PNP_OS_ACTIVE		EQU	42h
cmsg_PNP_OS_INACTIVE		EQU	43h

		extrn	pnp_EvntFlgAddr:Byte
		extrn	pnp_BIOSFlgAddr:Byte
;R26A		extrn	Ct_Shadow_Write:near
;R26A		extrn	Ct_Shadow_Read:near
		extrn	Ct_Shadow_Read:near		;R26B
		extrn	Ct_UNDOCK_OK:near
		extrn	Ct_ABORT_DOCK:near
		extrn	Ct_UNDOCK_REQ:near
		extrn	Ct_DOCK_INFO:near
		extrn	Ct_COLD_DOCK:near
endif	;DOCK_BIOS_Support
;R26 - end

; Parameters in stack

F3BiosSelector	equ	word  ptr [ebp+6]
F3MessageSeg	equ	word  ptr [ebp+4]
F3MessageOff	equ	word  ptr [ebp+2]
F3Message	equ	dword ptr [ebp+2]

		public	Get_Event
Get_Event	proc	near

;R26 - start
ifdef	DOCK_BIOS_Support
		push	ds				; ds:si ptr to BDA
		push	es				;
		push	bx				; es:bx ptr to OS message
		push	si				;

; Setup pointer to BIOS DATA AREA (event flag / BIOSflags)

		mov	si,F3BiosSelector		; Get Seg/Selector of BDA
		mov	ds,si
		mov	si, offset pnp_EvntFlgAddr		; Get EventFlag address

		cmp	BYTE PTR ds:[si], 1		; Test if event just occured
		je	short fGetEvent_EventOccurred

		mov	ax, EVENTS_NOT_PENDING
		jmp	short fGetEventDone

fGetEvent_EventOccurred:

;R26B		call	Ct_Save_Shadow			;R26A
		Call	Ct_Shadow_Write
		mov	BYTE PTR ds:[si], 0		; Clear Event Flag
;R26A		Call	Ct_Shadow_Read
;R26B		call	Ct_Restore_Shadow		;R26A
		Call	Ct_Shadow_Read			;R26B
		mov	si, offset pnp_BIOSFlgAddr	; Point to BIOS Docking Flgs

; Setup pointer to callers msg data structure
		mov	bx, F3MessageSeg		; Get msg seg ptr
		mov	es, bx				;
		mov	bx, F3MessageOff		; Get msg offset ptr

; Check for Event Type
		test	BYTE PTR ds:[si], bflg_OPEN_REQUEST
		jnz	short fGetEvent_OpenReq		; Check if open request

		test	BYTE PTR ds:[si], bflg_UNDOCK_PERMIT
		jnz	short fGetEvent_OK_Change	; Check if undock permit

		test	BYTE PTR ds:[si], bflg_DOCKED	; Test if docked
		jnz	short fGetEvent_OK_Change	; If not, then change config

		mov	ax, emsg_UNKNOWN_SYSTEM_EVENT	; If nothing else, then
		jmp	short fGetEventDone		; return error

; If undock event, issue ABOUT_TO_CHANGE_CFG message
fGetEvent_OpenReq:
		mov	WORD PTR es:[bx], emsg_ABOUT_TO_CHANGE_CONFIG
		mov	ax, SUCCESS			; Indicate success
		jmp	short fGetEventDone			;

fGetEvent_OK_Change:
		mov	WORD PTR es:[bx], emsg_DOCK_CHANGED
		mov	ax, SUCCESS			; Indicate success

fGetEventDone:
; Clean up and return back
		pop	si
		pop	bx
		pop	es
		pop	ds
else	;DOCK_BIOS_Support
;R26 - end
		mov	ax, FUNC_NOT_SUPPORT
endif	;DOCK_BIOS_Support				;R26
		ret
Get_Event	endp

;[]========================================================================[]
;Procedure:	Function 4	Send Message
;Function :
;Input	  :	EBP = stack pointer for parameters
;Output   :	AX = return code
;Registers:
;Note	  :
;[]========================================================================[]

; Parameters in stack

;R26 F4BiosSelector	equ	word  ptr [ebp+6]
;R26 F4MessageSeg	equ	word  ptr [ebp+4]
;R26 F4MessageOff	equ	word  ptr [ebp+2]
F4BiosSelector	equ	word  ptr [ebp+4]		;R26
;R26AF4Message	equ	dword ptr [ebp+2]
F4Message	equ	word ptr [ebp+2]		;R26A

		public	Send_Msg
Send_Msg	proc	near

;R26 - start
ifdef	DOCK_BIOS_Support
		push	ds				;
		push	bx				; bx is the OS message
		push	si				; ds:si ptr to BDA

;R26B		call	Ct_Save_Shadow			;R26A
		Call	Ct_Shadow_Write
; Setup pointer to BIOS DATA AREA (event flag / BIOSflags)
		mov	si, F4BiosSelector		; Get Seg/Selector of BDA
		mov	ds, si				;
		mov	si, offset pnp_BIOSFlgAddr	; Point to BIOS Docking Flgs

		mov	bx, F4Message			; Get caller message

		cmp	bx, cmsg_PNP_OS_ACTIVE		; Check if PNP OS Active msg
		jne	short fSendMsg_Chk1
		or	BYTE PTR ds:[si], bflg_OS_ACTIVE; if yes, set our flag
		mov	ax, SUCCESS			; Indicate success
		jmp	short fSendMsgDone			;

fSendMsg_Chk1:
		cmp	bx, cmsg_PNP_OS_INACTIVE	; Chk if PnP OS InActive msg
		jne	short fSendMsg_Chk2			;
		and	BYTE PTR ds:[si], NOT bflg_OS_ACTIVE
		mov	ax, SUCCESS			; Indicate success
		jmp	short fSendMsgDone

fSendMsg_Chk2:
		cmp	bx, rmsg_OK			; Check if OK To Dock
		jne	short fSendMsg_Chk3

		Call	Ct_UNDOCK_OK

		mov	ax, SUCCESS			; Indicate success
		jmp	short fSendMsgDone
fSendMsg_Chk3:
		cmp	bx, rmsg_ABORT			; Check if ABORT To Dock
		jne	short fSendMsg_Chk4

		and	BYTE PTR ds:[si], NOT bflg_OPEN_REQUEST
		and	BYTE PTR ds:[si], NOT bflg_UNDOCK_PERMIT
		or	BYTE PTR ds:[si], bflg_DOCKED	; Set Dock flag in BDA

		Call	Ct_ABORT_DOCK

		mov	ax, SUCCESS			; Indicate success
		jmp	short fSendMsgDone
fSendMsg_Chk4:
		cmp	bx, cmsg_UNDOCK_DEFAULT_ACTION	; Check if Default undock
		jne	short fSendMsg_Chk5			;

; Set undock request in Moon

		Call	Ct_UNDOCK_REQ
		mov	ax, SUCCESS			; Indicate success
		jmp	short fSendMsgDone
fSendMsg_Chk5:
		cmp	bx,cmsg_POWER_OFF
		jnz	short fSendMsg_Chk6

; Set System Power off
fSendMsg_Chk6:
		mov	ax, MSG_NOT_SUPPORTED

fSendMsgDone:
;R26A		Call	Ct_Shadow_Read
;R26B		call	Ct_Restore_Shadow		;R26A
		Call	Ct_Shadow_Read			;R26B

		pop	si
		pop	bx
		pop	ds
else	;DOCK_BIOS_Support
;R26 - end
		mov	ax, FUNC_NOT_SUPPORT
endif	;DOCK_BIOS_Support				;R26
		ret
Send_Msg	endp

;[]========================================================================[]
;Procedure:	Function 5	Get Docking Station Information
;Function :
;Input	  :	EBP = stack pointer for parameters
;Output   :	AX = return code
;Registers:
;Note	  :
;[]========================================================================[]

; Parameters in stack

F5BiosSelector	equ	word  ptr [ebp+6]
F5DockInfoSeg	equ	word  ptr [ebp+4]
F5DockInfoOff	equ	word  ptr [ebp+2]
F5DockInfo	equ	dword ptr [ebp+2]

		public	Get_Dock_Info
Get_Dock_Info	proc	near

;R26 - start
ifdef	DOCK_BIOS_Support
		push	ds		   	; ds:si ptr to BDA
		push	es
		push	bx		   	; es:bx ptr to OS message
		push	si

;R26B		call	Ct_Save_Shadow		;R26A
		Call	Ct_Shadow_Write
; Setup pointer to BIOS DATA AREA (BIOSflags)
		mov	si, F5BiosSelector	; Get Seg/Selector of BDA
		mov	ds, si
		mov	si, offset pnp_BIOSFlgAddr	; Point to BIOS Docking Flgs

; Setup pointer to callers data structure
		mov	bx, F5DockInfoSeg	; Get struc seg ptr
		mov	es, bx				;
		mov	bx, F5DockInfoOff	; Get struc offset ptr

		test	BYTE PTR ds:[si], bflg_DOCKED	; Check if system is docked
		jnz	fGetDockStInfo_Docked

; Check if this is cold dock

		Call	Ct_COLD_DOCK
		jnc	short fGetDockStInfo_ColdDock

		mov	ax, SYSTEM_NOT_DOCKED
		jmp	short fGetDockStInfo_Done

fGetDockStInfo_ColdDock:
		or	BYTE PTR ds:[si], bflg_DOCKED	; Set Dock flag in BDA
;;;		or	BYTE PTR ds:[si], bflg_EVENT_COMPLETE

fGetDockStInfo_Docked:

; Fill in the callers data structure with Docking Station Info

		Call	Ct_DOCK_Info

		mov	ax, SUCCESS		; Indicate success

fGetDockStInfo_Done:
;R26A		Call	Ct_Shadow_Read
;R26B		call	Ct_Restore_Shadow	;R26A
		Call	Ct_Shadow_Read		;R26B
; Clean up and return back
		pop	si
		pop	bx
		pop	es
		pop	ds
else	;DOCK_BIOS_Support
;R26 - end
		mov	ax, FUNC_NOT_SUPPORT
endif	;DOCK_BIOS_Support				;R26
		ret
Get_Dock_Info	endp

;[]========================================================================[]
;Procedure:	Function 9	Set Statically Allocated Resource Information
;Function :
;Input	  :	EBP = stack pointer for parameters
;Output   :	AX = return code
;Registers:
;Note	  :
;[]========================================================================[]

; Parameters in stack

F9BiosSelector	equ	word  ptr [ebp+6]
F9ResBlockSeg	equ	word  ptr [ebp+4]
F9ResBlockOff	equ	word  ptr [ebp+2]
F9ResBlock	equ	dword ptr [ebp+2]

		public	Set_Resource_Info
Set_Resource_Info	proc	near

ifdef	ESCD_SUPPORT

		mov	ax, USE_ESCD_SUPPORT

else	;ESCD_SUPPORT

ifdef	CMOS_RAM_SUPPORT

		sub	sp, RESOURCE_LENGTH
		mov	di, sp
		mov	ax, ss
		mov	es, ax
		mov	ds, F9ResBlockSeg
		mov	si, F9ResBlockOff
		call	Decode_Resource
		call	Ct_Set_Resource_Map
		mov	ax, SUCCESS
		add	sp, RESOURCE_LENGTH

else	;CMOS_RAM_SUPPORT

		mov	ax, FUNC_NOT_SUPPORT

endif	;CMOS_RAM_SUPPORT

endif	;ESCD_SUPPORT

		ret

Set_Resource_Info	endp

;[]========================================================================[]
;Procedure:	Function 0Ah	Get Statically Allocated Resource Information
;Function :
;Input	  :	EBP = stack pointer for parameters
;Output   :	AX = return code
;Registers:
;Note	  :
;[]========================================================================[]

; Parameters in stack

FaBiosSelector	equ	word  ptr [ebp+6]
FaResBlockSeg	equ	word  ptr [ebp+4]
FaResBlockOff	equ	word  ptr [ebp+2]
FaResBlock	equ	dword ptr [ebp+2]

		public	Get_Resource_Info
Get_Resource_Info	proc	near

ifdef	ESCD_SUPPORT

		mov	ax, USE_ESCD_SUPPORT

else	;ESCD_SUPPORT

ifdef	CMOS_RAM_SUPPORT

		sub	sp, RESOURCE_LENGTH
		mov	si, sp
		mov	ax, ss
		mov	ds, ax
		call	Ct_Get_Resource_Map
		jnc	short @f
		mov	cx, RESOURCE_LENGTH
		push	ds
		pop	es
		mov	di, si
		mov	al, 0FFh
		rep	stosb
@@:
		mov	es, FaResBlockSeg
		mov	di, FaResBlockOff
		call	Encode_Resource
		add	sp, RESOURCE_LENGTH
		mov	ax, SUCCESS

else	;CMOS_RAM_SUPPORT

		mov	ax, FUNC_NOT_SUPPORT

endif	;CMOS_RAM_SUPPORT

endif	;ESCD_SUPPORT

		ret

Get_Resource_Info	endp

;[]========================================================================[]
;Procedure:	Function 0Bh	Get APM ID Table
;Function :
;Input	  :	EBP = stack pointer for parameters
;Output   :	AX = return code
;Registers:
;Note	  :
;[]========================================================================[]

; Parameters in stack

FbBiosSelector	equ	word  ptr [ebp+10]
FbIdTableSeg	equ	word  ptr [ebp+8]
FbIdTableOff	equ	word  ptr [ebp+6]
FbIdTable	equ	dword ptr [ebp+6]
FbBufSizeSeg	equ	word  ptr [ebp+4]
FbBufSizeOff	equ	word  ptr [ebp+2]
FbBufSize	equ	dword ptr [ebp+2]

		public	Get_APM_Table
Get_APM_Table	proc	near
;R04 - start
;R04		mov	ax, FUNC_NOT_SUPPORT
;R04		ret
		mov	si, FbBufSizeSeg
		mov	ds, si
		mov	si, FbBufSizeOff
		cmp	word ptr ds:[si], APM_Tbl_Size
		jae	short APM_Buff_Large_Enough

	APM_Buff_Too_Small:

		mov	word ptr ds:[si], APM_Tbl_Size
		mov	ax, BUF_TOO_SMALL
		ret

	APM_Buff_Large_Enough:

;R09		mov	si, FbBiosSelector
;R09		mov	ds, si
;R09		mov	si, offset DGROUP:APM_Tbl
;R09
;R09		mov	di, FbIdTableSeg
;R09		mov	es, di
;R09		mov	di, FbIdTableOff
;R09
;R09		mov	cx, APM_Tbl_Size
;R09		cld
;R09		rep	movsb
		mov	ax, SUCCESS
		ret
APM_Tbl:
		dd	0
		dw	0
APM_Tbl_Size	EQU	($ - (offset APM_Tbl))
;R04 - end
Get_APM_Table	endp

;[]========================================================================[]
;Procedure:	Function 40h	Get Plug & Play ISA Configuration Structure
;Function :
;Input	  :	EBP = stack pointer for parameters
;Output   :	AX = return code
;Registers:
;Note	  :
;[]========================================================================[]

; Parameters in stack

F40BiosSelector equ	word  ptr [ebp+6]
F40ConfigSeg	equ	word  ptr [ebp+4]
F40ConfigOff	equ	word  ptr [ebp+2]
F40Config	equ	dword ptr [ebp+2]

		public	Get_Config_Struct
Get_Config_Struct	proc	near
ifdef	NO_ISA_PNP 						;R85
		mov	ax, NO_ISA_PNP_CARDS			;R85
else	;NO_ISA_PNP						;R85
;R28		mov	ds, F40BiosSelector
		mov	ax, F40BiosSelector			;R28
		test	bPnpModeFlag, PNP_PROT			;R28
		jnz	short @f				;R28
		mov	ax, 0F000h				;R28
@@:								;R28
		mov	ds, ax					;R28
		mov	es, F40ConfigSeg
		mov	di, F40ConfigOff
		xor	ax, ax
		mov	word ptr es:[di+4], ax	;fill zero	;R14
		mov	ax, ds:PNP_RD
		mov	es:[di+2], ax
		mov	al, ds:LAST_CSN
		mov	es:[di+1], al
;R04		mov	di, SUCCESS
;R04		or	al, al
;R04		jnz	short @f
;R04		mov	di, NO_ISA_PNP_CARDS
;R04@@:
;R04		mov	ax, di
		mov	byte ptr es:[di], 01h	;R04
		mov	ax, SUCCESS		;R04
endif	;NO_ISA_PNP						;R85
		ret
Get_Config_Struct	endp

;[]========================================================================[]
;Procedure:	Function 41h	Get Extended System Configuration Data (ESCD)
;				Information
;Function :
;Input	  :	EBP = stack pointer for parameters
;Output   :	AX = return code
;Registers:
;Note	  :
;[]========================================================================[]

; Parameters in stack

F41BiosSelector equ	word  ptr [ebp+14]
F41NvsBaseSeg	equ	word  ptr [ebp+12]
F41NvsBaseOff	equ	word  ptr [ebp+10]
F41NvsBase	equ	dword ptr [ebp+10]
F41EscdSizeSeg	equ	word  ptr [ebp+8]
F41EscdSizeOff	equ	word  ptr [ebp+6]
F41EscdSize	equ	dword ptr [ebp+6]
F41MinSizeSeg	equ	word  ptr [ebp+4]
F41MinSizeOff	equ	word  ptr [ebp+2]
F41MinSize	equ	dword ptr [ebp+2]

		public	Get_ESCD_Info
Get_ESCD_Info	proc	near

ifdef	ESCD_SUPPORT
		mov	ds, F41BiosSelector		;R25
		mov	ax, FUNC_NOT_SUPPORT		;R25
		test	byte ptr ds:ESCD_FLAG, 01h	;R25
		jz	short @f			;R25
		ret					;R25
@@:							;R25
;R29A 		call	Verify_PnpMode		;R29
;R29A 		jnc	short @f		;R29
;R29A 		ret				;R29
;R29A @@: 					;R29

;R18A IF 	BUS_TYPE EQ ISA_BUS				;R18
		call	Ct_ESCD_Info
;R18A endif; 	BUS_TYPE EQ ISA_BUS				;R18
		mov	ax, SUCCESS

else	;ESCD_SUPPORT

		mov	ax, FUNC_NOT_SUPPORT

endif	;ESCD_SUPPORT

		ret

Get_ESCD_Info	endp

;[]========================================================================[]
;Procedure:	Function 42h	Read Extended System Configuration Data (ESCD)
;Function :
;Input	  :	EBP = stack pointer for parameters
;Output   :	AX = return code
;Registers:
;Note	  :
;[]========================================================================[]

; Parameters in stack

F42BiosSelector equ	word  ptr [ebp+8]
F42EscdSelector equ	word  ptr [ebp+6]
F42EscdBufSeg	equ	word  ptr [ebp+4]
F42EscdBufOff	equ	word  ptr [ebp+2]
F42EscdBuf	equ	dword ptr [ebp+2]

		public	Read_ESCD
Read_ESCD	proc	near

ifdef	ESCD_SUPPORT
		mov	ds, F42BiosSelector		;R25
		mov	ax, FUNC_NOT_SUPPORT		;R25
		test	byte ptr ESCD_FLAG, 01h		;R25
		jz	short @f			;R25
		ret					;R25
@@:							;R25
;R34 - start
ifdef	ESCD_M2
		test	byte ptr ds:ESCD_FLAG, 02h	;ESCD shadow flag
		jz	short @f
		mov	es, F42EscdBufSeg
		mov	di, F42EscdBufOff
		call	Read_ESCD_Shadow
		jc	short @f
		mov	ds, F42EscdBufSeg
		mov	si, F42EscdBufOff
		jmp	short Read_ESCD_Success
@@:
endif	;ESCD_M2
;R34 - end
;R29A 		call	Verify_PnpMode		;R29
;R29A 		jnc	short @f		;R29
;R29A 		ret				;R29
;R29A @@: 					;R29
;R18A IF 	BUS_TYPE EQ ISA_BUS				;R18

;R08		mov	ds, F42EscdSelector
;R24		mov	ds, F42BiosSelector	;R08

ifdef	ESCD_M2					;R29B
		mov	ds, F42EscdSelector	;R24
else;	ESCD_M2					;R29B
		mov	ds, F42BiosSelector	;R29B
endif;	ESCD_M2					;R29B

		mov	wEscdSelector, ds	;R24A
		mov	ax, F42BiosSelector	;R24A
		mov	wBiosSelector, ax	;R24A

		mov	es, F42EscdBufSeg
		mov	di, F42EscdBufOff

		push	es			;R05
		push	di			;R05

		call	Ct_Get_ESCD

		jnc	short @f

		mov	es, F42EscdBufSeg
		mov	di, F42EscdBufOff

		mov	ax, cs
		mov	ds, ax
		mov	si, offset DGROUP:DEFAULT_ESCD
		mov	cx, DEFAULT_ESCD_L

		rep	movsb

	@@:
		pop	si			;R05
		pop	ds			;R05
Read_ESCD_Success:				;R34
;R73		call	Sum_Escd		;R05
;R73 - start
		call	Checksum_ESCD
		jnc	short @f
		mov	ax, FUNC_NOT_SUPPORT
		ret
@@:
;R73 - end
;R18A endif; 	BUS_TYPE EQ ISA_BUS				;R18
		mov	ax, SUCCESS

else	;ESCD_SUPPORT

		mov	ax, FUNC_NOT_SUPPORT

endif	;ESCD_SUPPORT

		ret

Read_ESCD	endp

ifdef	ESCD_SUPPORT					;R85
;R73 - start
;[]========================================================================[]
; Input:	DS:SI = point to ESCD buffer
; Output:	CF = 0 ESCD checksum successful
;		CF = 1 ESCD checksum fail
;[]========================================================================[]

Checksum_ESCD	proc	near
		mov	cx, ds:[si]
		jcxz	short Checksum_ESCD_Fail
		cmp	cx, ESCD_SIZE
		ja	short Checksum_ESCD_Fail
		sub	cx, 2			;length of checksum word
		jb	short Checksum_ESCD_Fail
		xor	dx, dx
		xor	ax, ax
Checksum_ESCD_Loop:
		lodsb
		add	dx, ax
		loop	short Checksum_ESCD_Loop
		add	dx, ds:[si]
		jnz	short Checksum_ESCD_Fail
		clc
		ret
Checksum_ESCD_Fail:
		stc
		ret
Checksum_ESCD	endp
;R73 - end
;R18A IF 	BUS_TYPE EQ ISA_BUS				;R18
;R05 - start
Sum_Escd	proc	near
		mov	cx, ds:[si]
		jcxz	short Sum_Escd_Exit
		cmp	cx, ESCD_SIZE
		ja	short Sum_Escd_Exit
		sub	cx, 2			;length of checksum word
		jb	short Sum_Escd_Exit
		xor	dx, dx
		xor	ax, ax
Sum_Escd_Loop:
		lodsb
		add	dx, ax
		loop	short Sum_Escd_Loop
		neg	dx
		mov	ds:[si], dx
Sum_Escd_Exit:
		ret
Sum_Escd	endp
;R05 - end
;R18A endif; 	BUS_TYPE EQ ISA_BUS				;R18
endif	;ESCD_SUPPORT					;R85

;[]========================================================================[]
;Procedure:	Function 43h	Write Extended System Configuration Data (ESCD)
;Function :
;Input	  :	EBP = stack pointer for parameters
;Output   :	AX = return code
;Registers:
;Note	  :
;[]========================================================================[]

;R50 - start
ifdef	MP_SUPPORT
ifndef	Flash_2M_support
ifdef	Flash_4K_Unit
Support_1M_With_MP_Upd_Code	EQU	1
endif;	Flash_4K_Unit
endif;	Flash_2M_support
endif;	MP_SUPPORT
;R50 - end

; Parameters in stack

F43BiosSelector equ	word  ptr [ebp+8]
F43EscdSelector equ	word  ptr [ebp+6]
F43EscdBufSeg	equ	word  ptr [ebp+4]
F43EscdBufOff	equ	word  ptr [ebp+2]
F43EscdBuf	equ	dword ptr [ebp+2]

		public	Write_ESCD
Write_ESCD	proc	near

ifdef	ESCD_SUPPORT
		mov	ds, F43BiosSelector		;R25
		mov	ax, FUNC_NOT_SUPPORT		;R25
		test	byte ptr ESCD_FLAG, 01h		;R25
		jz	short @f			;R25
		ret					;R25
@@:							;R25
;R34 - start
ifdef	ESCD_M2
;R50A ifndef	Support_1M_With_MP_Upd_Code			;R50
		test	byte ptr ds:ESCD_FLAG, 02h	;ESCD shadow flag
		jz	short @f
;R50A endif;	Support_1M_With_MP_Upd_Code			;R50

		push	ds
		push	es

;R50A ;R50 - start
;R50A ifdef	Support_1M_With_MP_Upd_Code
;R50A 		call	Get_Shadow_Address
;R50A 		mov	di, ax
;R50A 		mov	es, F43BiosSelector
;R50A 		mov	ds, F43EscdSelector
;R50A 		mov	si, ESCD_REAL_BASE
;R50A 		call	Backup_P6_Sec_Block_To_Shadow
;R50A endif;	Support_1M_With_MP_Upd_Code
;R50A ;R50 - end

		mov	ds, F43EscdBufSeg
		mov	si, F43EscdBufOff
		mov	es, F43BiosSelector
		call	Write_ESCD_Shadow
		pop	es
		pop	ds

;R50A ;R50 - start
;R50A ifdef	Support_1M_With_MP_Upd_Code
;R50A 		mov	ds, F43BiosSelector
;R50A 		call	Get_Shadow_Address
;R50A 		mov	si, ax
;R50A 		mov	cx, ESCD_SIZE
;R50A endif;	Support_1M_With_MP_Upd_Code
;R50A ;R50 - end

@@:
;R50A - start
;R73ifdef	Support_1M_With_MP_Upd_Code
		mov	si, ESCD_REAL_BASE+ESCD_SIZE/2
		mov	es, F43BiosSelector
		call	Get_Shadow_Address
		mov	di, ax
		add	di, ESCD_SIZE/2

;R73		push	ds
;R73		mov	ds, F43BiosSelector
		test	byte ptr ds:ESCD_FLAG, 02h	;ESCD shadow flag
;R73		pop	ds
		jnz	short Backup_CPU_Code_To_Shadow

	; Copy ESCD and backup second CPU update code to RAM
		push	ds			;R50B
		push	si
		mov	ds, F43EscdBufSeg
		mov	si, F43EscdBufOff
		mov	ax, 5000h
		mov	es, ax
		xor	di, di
		push	es				;R73
		push	di				;R73
		mov	cx, ESCD_SIZE/2
		rep	movsb
		pop	si				;R73
		pop	ds				;R73
		call	Sum_ESCD			;R73
		pop	si
		pop	ds			;R50B

Backup_CPU_Code_To_Shadow:
ifdef	Support_1M_With_MP_Upd_Code			;R73
		call	Backup_P6_Sec_Block_To_Shadow
endif;	Support_1M_With_MP_Upd_Code			;R73

		call	Get_Shadow_Address
		mov	si,ax

		test	byte ptr ds:ESCD_FLAG, 02h	;ESCD shadow flag
		jnz	short Write_CPU_Code_From_Shadow

		push	es
		pop	ds
		xor	si,si

Write_CPU_Code_From_Shadow:
		mov	cx, ESCD_SIZE

;R73endif;	Support_1M_With_MP_Upd_Code
;R50A - end
endif	;ESCD_M2
;R34 - end
;R29A 		call	Verify_PnpMode		;R29
;R29A 		jnc	short @f		;R29
;R29A 		ret				;R29
;R29A @@:  					;R29

;R18A IF 	BUS_TYPE EQ ISA_BUS				;R18
;R08		mov	es, F43EscdSelector
;R24		mov	es, F43BiosSelector	;R08

ifdef	ESCD_M2					;R29B
		mov	es, F43EscdSelector	;R24
else;	ESCD_M2					;R29B
		mov	es, F43BiosSelector	;R29B
endif;	ESCD_M2					;R29B

		mov	wEscdSelector, es	;R24A
		mov	ax, F43BiosSelector	;R24A
		mov	wBiosSelector, ax	;R24A

;R73ifndef	Support_1M_With_MP_Upd_Code		;R50
;R73		mov	ds, F43EscdBufSeg
;R73		mov	si, F43EscdBufOff
;R73
;R73		mov	cx, ds:[si]
;R73endif;	Support_1M_With_MP_Upd_Code		;R50

		call	Ct_Set_ESCD
		jc	short Func43_Fail
;R18A endif; 	BUS_TYPE EQ ISA_BUS				;R18

		mov	ax, SUCCESS
		ret

Func43_Fail:
;R25 - start
		pushf
		push	ebp
		cli
		mov	es, F43BiosSelector
		mov	di, offset ESCD_FLAG
		xor	eax,eax
		call	Ct_Buffer_Request	;buffer request for saving status
		shl	eax,1
		sub	esp, eax		;reduce stack for saving status
		mov	ebp, esp		;status buffer index
		call	Ct_Save_Shadow		;save shadow status
		call	Ct_Shadow_Write
;R34		mov	al, 01
		mov	al, es:[di]		;R34
		or	al, 01			;R34
		call	Ct_Set_Shadow
		call	Ct_Restore_Shadow	;restore shadow status
		xor	eax, eax
		call	Ct_Buffer_Request	;buffer request for saving status
		shl	eax,1
		add	esp,eax
		pop	ebp
		popf
;R25 - end

endif	;ESCD_SUPPORT

		mov	ax, FUNC_NOT_SUPPORT
		ret

Write_ESCD	endp

;R50 - start
ifdef	ESCD_SUPPORT
ifdef	ESCD_M2
ifdef	Support_1M_With_MP_Upd_Code
Backup_P6_Sec_Block_To_Shadow	proc	near
		push	ds
		push	es
		pushad
		cli

		smsw	ax			;get machine word
		push	ax			;save machine word
		test	al,1			;in protected mode ?
		jnz	short @f		;yes, use original selector

		call	Check_A20_AndRecord	;read A20 status

		push	ds
		call	A20_On
		pop	ds

                lgdt    fword ptr cs:GDTR1

		mov	eax, cr0
		or	al, 1			;protect mode enable
		mov	cr0, eax

		FAR_JMP DGROUP:$+4, 08H		;clear prefetch, bios cs

		mov	ax, ESCD_INDEX
		mov	ds, ax			;ds = 00000000h

;R50A		mov	ax,F0DATA_INDEX
;R50A		mov	gs, ax			;gs = F000h

@@:
		push	ebp			;save parameter pointer

		xor	eax,eax
		call	Ct_Buffer_Request	;buffer request for saving status

		shl	eax,1

		call	Check_16Bit_Stack	;16-bit stack ?
		jz	short @f		;jump if 16-bit stack

		sub	esp, eax		;reduce stack for saving status
		mov	ebp, esp		;status buffer index
		jmp	short Backup_P6_Sec_Block_To_Shadow1

@@:
		sub	sp, ax
		movzx	ebp, sp

Backup_P6_Sec_Block_To_Shadow1:

		call	Ct_Save_Shadow		;save shadow status
		Call	Ct_Shadow_Write

;R50A		mov	cx,ESCD_SIZE
		mov	cx,ESCD_SIZE/2		;R50A
		rep	movsb

		call	Ct_Restore_Shadow	;restore shadow status

		xor	eax, eax
		call	Ct_Buffer_Request

		shl	eax,1
		add	esp,eax

		pop	ebp			;restore parameter pointer

		pop	ax			;original machine word
		test	al,1			;in protected mode ?
		jnz	short @f		;yes, no change mode

		mov	eax, cr0
		and 	al, NOT 01H		;go back to real mode
		mov	cr0, eax

		FAR_JMP	DGROUP:$+4, 0F000h	;flush CPU instruction queue

		test	bPnpModeFlag, A20_HIGH	;the original state of A20 is on ?
		jnz	short @F

		push	ds
		call	A20_Off
		pop	ds

@@:
		clc
		popad
		pop	es
		pop	ds
		ret
Backup_P6_Sec_Block_To_Shadow	endp
endif;	Support_1M_With_MP_Upd_Code
endif;	ESCD_M2
endif;	ESCD_SUPPORT
;R50 - end

;R34 - start
ifdef	ESCD_SUPPORT
ifdef	ESCD_M2
;[]========================================================================[]
;Procedure:	Write_ESCD_Shadow
;Function :	Write ESCD to F000 Shadow RAM
;Input    :	DS:SI = pointer for caller's ESCD buffer
;		ES = BIOS selector/segment
;Output   :	CF = 0 successful
;		CF = 1 fail
;[]========================================================================[]
		public	Write_ESCD_Shadow
Write_ESCD_Shadow	proc	near
		push	ds
		push	es
		pushad

		call	Get_Shadow_Address
		jc	short Write_ESCD_Shadow_Fail

		mov	di, ax

		xor	eax,eax
		call	Ct_Buffer_Request	;buffer request for saving status

		shl	eax,1			;size in word

		push	ax
		smsw	ax
		test	al, 1
		pop	ax
		jz	short @f		;jump if real mode

		call	Check_16Bit_Stack1	;16-bit stack ?
		jz	short @f		;jump if 16-bit stack

		sub	esp, eax		;reduce stack for saving status
		mov	ebp, esp		;status buffer index
		jmp	short Write_ESCD_Shadow1

@@:
		sub	sp, ax
		movzx	ebp, sp

Write_ESCD_Shadow1:
		call	Ct_Save_Shadow		;save shadow status
		call	Ct_Shadow_Write

		push	es			;R73
		push	di			;R73
		mov	cx, ds:[si]
		cld
	@@:
		mov	al, ds:[si]
		mov	es:[di], al
		inc	si
		inc	di
		loop	short @b
		pop	si			;R73
		pop	ds			;R73
		call	Sum_ESCD		;R73

		or	byte ptr es:ESCD_FLAG, 02h

		call	Ct_Restore_Shadow	;restore shadow status
		xor	eax, eax
		call	Ct_Buffer_Request	;buffer request for saving status
		shl	eax,1			;size in word
		add	esp,eax
		clc				;success

Write_ESCD_Shadow_Fail:
		popad
		pop	es
		pop	ds
		ret
Write_ESCD_Shadow	endp

;[]========================================================================[]
;Procedure:	Read_ESCD_Shadow
;Function :	Read ESCD from F000 Shadow RAM
;Input    :	ES:DI = pointer for caller's ESCD buffer
;		DS = BIOS selector/segment
;Output   :	CF = 0 successful
;		CF = 1 fail
;[]========================================================================[]

Read_ESCD_Shadow	proc	near
		push	ds
		push	es
		pushad

		call	Get_Shadow_Address
		jc	short Read_ESCD_Shadow_Fail

		mov	si, ax

		cmp	dword ptr ds:[si+2], 'GFCA'	;ESCD signature
		jne	short Read_ESCD_Shadow_Fail

		mov	cx, ds:[si]
		cld
	@@:
		mov	al, ds:[si]
		mov	es:[di], al
		inc	si
		inc	di
		loop	short @b
		clc
		jmp	short Read_ESCD_Shadow_Exit

Read_ESCD_Shadow_Fail:
		stc
Read_ESCD_Shadow_Exit:
		popad
		pop	es
		pop	ds
		ret
Read_ESCD_Shadow	endp

;[]========================================================================[]
;Procedure:	Get_Shadow_Address
;Function :	calculate offset address for ESCD shadow in F000 segment
;Input    :	none
;Output   :	CF = 0 successful
;			AX = offset address for ESCD shadow
;		CF = 1 fail
;[]========================================================================[]

Get_Shadow_Address	proc	near
;R56		mov	ax, offset Shadow_Escd_Address
;R56		add	ax, 0FFFh			;next 4KB boundary
;R56		jc	short Get_Shadow_Address_Fail
;R56		and	ax, 0F000h			;in 4KB boundary
;R56		cmp	ax, 7000h			;maximum 4KB size
;R56		ja	short Get_Shadow_Address_Fail
		mov	ax,Shadow_Escd_Address	;R56
		clc
		ret
;R56Get_Shadow_Address_Fail:
;R56		stc
;R56		ret
Get_Shadow_Address	endp
endif	;ESCD_M2
endif	;ESCD_SUPPORT
;R34 - end

ifdef	CMOS_RAM_SUPPORT

;[]========================================================================[]
;Procedure:	Decode_Resource
;Function :	Translate resource information to resource map
;Input	  :	DS:SI = point to resource information
;		ES:DI = point to resource map
;Output   :	none
;Registers:
;Note	  :
;[]========================================================================[]
		public	Decode_Resource
Decode_Resource proc	near

		push	si
		push	di

		push	di
		mov	cx, RESOURCE_LENGTH
		mov	al, 0FFh
		mov	es:[di], al
		inc	di
		pop	di

		xor	cx, cx

Decode_Resource_Loop:

		add	si, cx
		call	Get_Tag_Name
		cmp	ah, sEndTag
		je	short Decode_Resource_Exit
		cmp	ah, sIrqFormat
		jne	short @f
		mov	ax, ds:[si]			;IRQ mask
		not	ax
		and	es:IRQ_MAP[di],ax		;IRQ map offset
		jmp	short Decode_Resource_Loop
@@:
		cmp	ah, sDmaFormat
		jne	short @f
		mov	ax, ds:[si]			;DMA mask
		not	al
		and	es:DMA_MAP[di],al		;DMA map offset
		jmp	short Decode_Resource_Loop
@@:
		cmp	ah, sIoPortFixed
		jne	short Decode_Resource_Loop
		mov	ax, ds:[si]			;range base address
		xor	dx, dx
		mov	dl, ds:[si+2]			;range length
		push	ds
		push	si
		push	es
		pop	ds
		mov	si, di			;ds:si point to resource map
		call	Record_IO_Map
		pop	si
		pop	ds
		jmp	short Decode_Resource_Loop

Decode_Resource_Exit:

		pop	di
		pop	si

		ret

Decode_Resource endp

;[]========================================================================[]
;Procedure:	Encode_Resource
;Function :	Translate resource map to resource information
;Input	  :	DS:SI = point to resource map
;		ES:DI = point to resource information
;Output   :	none
;Registers:
;Note	  :
;[]========================================================================[]
		public	Encode_Resource
Encode_Resource proc	near

		push	si
		push	di

		xor	ah, ah			;checksum

		mov	al, 22h 		;IRQ tag
		mov	es:[di], al
		inc	di
		add	ah, al
		mov	al,ds:[si]		;IRQ mask
		inc	si
		not	al
		mov	es:[di], al
		inc	di
		add	ah, al
		mov	al,ds:[si]
		inc	si
		not	al
		mov	es:[di], al
		inc	di
		add	ah, al

		mov	al, 2Ah 		;DMA tag
		mov	es:[di], al
		inc	di
		add	ah, al
		mov	al,ds:[si]		;DMA mask
		inc	si
		not	al
		mov	es:[di], al
		inc	di
		add	ah, al
		mov	al, 00011001b		;DMA information
		mov	es:[di], al
		inc	di
		add	ah, al

		mov	cx, 12
		mov	dx, 100h
Encode_IO_Loop1:
		mov	al,ds:[si]
		inc	si
		push	cx
		mov	cx, 8
		mov	bl, al
Encode_IO_Loop2:
		test	bl, 1
		jnz	@f

		mov	al, 4Bh 		;Fixed I/O tag
		mov	es:[di], al
		inc	di
		add	ah, al

		mov	al, dl			;range base address
		mov	es:[di], al
		inc	di
		add	ah, al
		mov	al, dh
		mov	es:[di], al
		inc	di
		add	ah, al

		mov	al, 8			;length
		mov	es:[di], al
		inc	di
		add	ah, al
@@:
		add	dx, 8
		shr	bl, 1
		loop	short Encode_IO_Loop2
		pop	cx
		loop	short Encode_IO_Loop1

		mov	al, 79h 		;end tag
		mov	es:[di], al
		inc	di
		add	al, ah
		neg	al			;checksum
		mov	es:[di], al
		inc	di

		pop	di
		pop	si

		ret

Encode_Resource endp

endif	;CMOS_RAM_SUPPORT

;R02 - start
comment %	;R15
Ct_PS2_Node	Proc	Near

;R12		push	ds
;R12		mov	ax,G_RAM
;R12		mov	ds,ax
;R12		assume	ds:G_RAM
;R12
;R12		test	byte ptr Hardware,00000100b	; PS/2 installed ?
;R12		pop	ds
;R12		jnz	short @F			;Yes
;R12		stc
;R12		ret
;R12@@:
;R12		clc
;R13 - start
		push	ds
		mov	ax, 0F000h
		mov	ds, ax
		test	byte ptr ds:SYSTEM4_BYTE, 80h	;ps2 mouse support?
		jz	short Ct_PS2_Fail

		mov	ax, G_RAM
		mov	ds, ax
		test	byte ptr ds:Hardware, 00000100b	;PS/2 installed ?
		jz	short @F			;Yes

		mov	ax, cs
		mov	ds, ax
		add	di, 12				;point to desp start
		mov	si, offset DGROUP:PS2_Resource
		mov	cx, PS2_Resource_L
		rep	movsb
@@:
		pop	ds
		clc
		ret
Ct_PS2_Fail:
		pop	ds
		stc
;R13 - end
		ret

Ct_PS2_Node	Endp
%		;R15

;R32 - starts
Ct_Get_PS2_Node	Proc	Near

;R32A		test	byte ptr cs:[CONFIG_TABLE+5], 80h
;R77		test	byte ptr cs:[CONFIG_TABLE+5], 04h	;R32A
		test	byte ptr cs:System1_byte, 04h		;R77
		mov	ax, 1000h
		jnz	short @F
		xor	ax, ax
	@@:
		mov	word ptr es:[di+PS2_IRQ_LOCATION+1], ax
		clc
		ret

Ct_Get_PS2_Node	Endp

Ct_Set_PS2_Node	Proc	Near

		pushf
		pushad
		call	Ct_Shadow_Write

		cmp	word ptr es:[di+PS2_IRQ_LOCATION+1], 1000h
;R32A		mov	ax, 80A8h 		;enable mouse interface
		mov	ax, 04A8h 		;enable mouse	;R32A
		je	short @F
		mov	ax, 00A7H 		;disable mouse interface
	@@:
;R32A		and	byte ptr ds:[CONFIG_TABLE+5], not 80h
		and	byte ptr ds:[CONFIG_TABLE+5], not 04h	;R32A
		or	byte ptr ds:[CONFIG_TABLE+5], ah
		and	byte ptr ds:system1_byte, not 04h	;R77
		or	byte ptr ds:system1_byte, ah		;R77

if	IRQ12_CTRL				;R39
		;input : AH = 04H enable IRQ 12	;R39
		;	    = 00H disable IRQ 12;R39
		call	Irq12_Control		;R39
endif;	IRQ12_CTRL				;R39

ifdef 	IRQ12_Ctl_By_Ct					;R42
		;input : AH = 04H enable IRQ 12		;R42
		;	    = 00H disable IRQ 12	;R42
		call	Ct_IRQ12_Control		;R42
endif	;IRQ12_Ctl_By_Ct 				;R42

		call	KB_CNTRLR_OUT

;R43 - start
;R43A		mov 	cx,10
;R43A	@@:
		in 	al,60h			;read garbadge
		jmp	short $+2
		jmp	short $+2
;R43A		loop 	@B
;R43 - end

		call	Ct_Shadow_Read
		popad
		popf
		ret

Ct_Set_PS2_Node	Endp

Ct_PS2_Node	Proc	Near

		push	ds
		mov	ax, 0F000h
		mov	ds, ax
		test	byte ptr ds:SYSTEM4_BYTE, 80h	;ps2 mouse support?
		jz	short Ct_PS2_Fail

		mov	ax, G_RAM
		mov	ds, ax
		test	byte ptr ds:Hardware, 00000100b	;PS/2 installed ?

	ifndef	REPORT_DIS_NODE
		jz	short Ct_PS2_Fail
	else	;REPORT_DIS_NODE
		jz	short @F			;Yes
	endif	;REPORT_DIS_NODE

		pop	ds
		clc
		ret
Ct_PS2_Fail:
		pop	ds
		stc
		ret

Ct_PS2_Node	Endp
;R32 - ends

;R12 - starts
		Public	Dummy_Set_Node
Dummy_Set_Node	Proc	Near
		clc	;R13
		ret
Dummy_Set_Node	Endp
;R12 - ends

		ASSUME	DS:NOTHING
;R02 - end

;[]========================================================================[]
;
;	SYSTEM DEVICE NODES DEFINITION
;
;[]========================================================================[]

		PUBLIC	SYSTEM_NODE
;R13		PUBLIC	SYSTEM_NODE_TOTAL
;R13		PUBLIC	SYSTEM_NODE_LARGEST
SYSTEM_NODE	LABEL	BYTE

;DEV_NODE	wMF_CODE, wPRODUCT_ID, dDEV_TYPE, bDEV_ATTR
;	MEM_DSP 	bMEM_INFO, dMEM_MIN, dMEM_MAX, wMEM_ALIGN, dMEM_LEN
;	MEM32_DSP	bMEM_INFO, dMEM_MIN, dMEM_MAX, dMEM_ALIGN, dMEM_LEN
;	FMEM32_DSP	bMEM_INFO, dMEM_BASE, dMEM_LEN
;	IO_DSP		bIO_INFO, wIO_MIN, wIO_MAX, bIO_ALIGN, bIO_LEN
;	FIO_DSP 	wIO_BASE, bIO_LEN
;	IRQ_DSP 	wIRQ_MASK, [bIRQ_TYPE]
;	DMA_DSP 	bDMA_CH, bDMA_INFO
;	END_DSP
;	END_DSP
;	END_DSP

; PIC (8259 Compatible)

;R13DEV_NODE	41D0H, 0000H, 080000H, 00000011B
DEV_NODE	41D0H, 0000H, 080000H, 00000011B, PIC_NODE	;R13
	IRQ_DSP 	0000000000000100B
;R01	FIO_DSP 	20H, 16
;R01	FIO_DSP 	0A0H, 16
;R31	FIO_DSP 	20H, 2				;R01
;R31	FIO_DSP 	0A0H, 2 			;R01
	IO_DSP 		1, 20H, 20H, 0, 2		;R31
	IO_DSP 		1, 0A0H, 0A0H, 0, 2 		;R31
	END_DSP
	END_DSP
	END_DSP
DEV_NODE_END

; DMA Controller (8237 Compatible)

;R13DEV_NODE	41D0H, 0200H, 080100H, 00000011B
DEV_NODE	41D0H, 0200H, 080100H, 00000011B, DMA_NODE	;R13
	DMA_DSP 	00010000B, 0
;R31	FIO_DSP 	00H, 16
;R01 - start
;R31	FIO_DSP 	81H, 3
;R31	FIO_DSP 	87H, 1
;R31	FIO_DSP 	89H, 3
;R31	FIO_DSP 	8FH, 3
;R01 - end
;R01	FIO_DSP 	0C0H, 16
;R31	FIO_DSP 	0C0H, 32			;R01
	IO_DSP 		1, 00H, 00H, 0, 16		;R31
	IO_DSP 		1, 81H, 81H, 0, 3		;R31
	IO_DSP 		1, 87H, 87H, 0, 1		;R31
	IO_DSP 		1, 89H, 89H, 0, 3		;R31
	IO_DSP 		1, 8FH, 8FH, 0, 3		;R31
	IO_DSP 		1, 0C0H, 0C0H, 0, 32		;R31
	END_DSP
	END_DSP
	END_DSP
DEV_NODE_END

; System Timer

;R13DEV_NODE	41D0H, 0100H, 080201H, 00000011B
DEV_NODE	41D0H, 0100H, 080201H, 00000011B, TIMER_NODE	;R13
	IRQ_DSP 	0000000000000001B
;R01	FIO_DSP 	40H, 16
;R31	FIO_DSP 	40H, 4				;R01
	IO_DSP 		1, 40H, 40H, 0, 4		;R31
	END_DSP
	END_DSP
	END_DSP
DEV_NODE_END

; Real Time Clock

;R13DEV_NODE	41D0H, 0B00H, 080300H, 00000011B
DEV_NODE	41D0H, 0B00H, 080300H, 00000011B, RTC_NODE	;R13
	IRQ_DSP 	0000000100000000B
;R01	FIO_DSP 	70H, 16
;R31	FIO_DSP 	70H, 2				;R01
	IO_DSP 		1, 70H, 70H, 0, 2		;R31
	END_DSP
	END_DSP
	END_DSP
DEV_NODE_END

; Keyboard

;R13DEV_NODE	41D0H, 0303H, 090000H, 00001011B
DEV_NODE	41D0H, 0303H, 090000H, 00001011B, KB_NODE	;R13
	IRQ_DSP 	0000000000000010B
;R31	FIO_DSP 	60H, 1
;R31	FIO_DSP 	64H, 1
	IO_DSP 		1, 60H, 60H, 0, 1		;R31
	IO_DSP 		1, 64H, 64H, 0, 1		;R31
	END_DSP
	END_DSP
	END_DSP
DEV_NODE_END

;PC speaker

;R13DEV_NODE	41D0H, 0800H, 088000H, 00000011B
DEV_NODE	41D0H, 0800H, 088000H, 00000011B, SPK_NODE	;R13
;R31	FIO_DSP 	61H, 1
	IO_DSP 		1, 61H, 61H, 0, 1		;R31
	END_DSP
	END_DSP
	END_DSP
DEV_NODE_END

; Math Coprocessor

;R13DEV_NODE	41D0H, 0C04H, 0B0100H, 00000011B
DEV_NODE	41D0H, 0C04H, 0B0100H, 00000011B, MPU_NODE	;R13
	IRQ_DSP 	0010000000000000B
;R31	FIO_DSP 	0F0H, 16
	IO_DSP 		1, 0F0H, 0F0H, 0, 16		;R31
	END_DSP
	END_DSP
	END_DSP
DEV_NODE_END

; ROM BIOS Memory

		PUBLIC	MbRom_Node			;R49
MbRom_Node	label	near				;R49

;R13DEV_NODE	41D0H, 0C01H, 050000H, 00000011B
DEV_NODE	41D0H, 0C01H, 050000H, 00000011B, ROM_NODE	;R13

ifdef	PATCH_ONBOARD_ATI_SCT					;R40
	FMEM32_DSP	00010010B, 0000C0000H, 0008000H	;32Kb	;R40
endif;	PATCH_ONBOARD_ATI_SCT					;R40

;R45A ifdef	ONBOARD_SCSI_SLOT				 ;R45
;R45A 	FMEM32_DSP	00010010B, 0000C8000H, 0004000H	;16Kb ROM;R45
;R45A endif;	ONBOARD_SCSI_SLOT				 ;R45

ifdef	PATCH_I558_BOOT_ROM_NT_40				;R79B
 ifndef	AVIDEO_AT_F000
	;Report E0000-EFFFF used by system BIOS
	FMEM32_DSP	00110010B, 0E0000H, 10000H	;64Kb ROM
 endif;	AVIDEO_AT_F000
	;Report F0000-FFFFF used by system BIOS
	;Note that the following four memory nodes are also used for
	;USB frame buffer , onboard SCSI and Shrank ROM.
	FMEM32_DSP	00110010B, 0F0000H, 04000H	;16K ROM
	FMEM32_DSP	00110010B, 0F4000H, 04000H	;16K ROM
	FMEM32_DSP	00110010B, 0F8000H, 04000H	;16K ROM
	public	LastMbNodeShared
LastMbNodeShared:
	FMEM32_DSP	00110010B, 0FC000H, 04000H	;16K ROM
endif;	PATCH_I558_BOOT_ROM_NT_40				;R79B

;R79 ifdef	AVIDEO_AT_F000 		     		;R78
;R79	FMEM32_DSP	00110010B, 0F0000H, 10000H	;R78
;R79 else;	AVIDEO_AT_F000 				;R78
;R79	FMEM32_DSP	00110010B, 0E0000H, 20000H
;R79 endif;	AVIDEO_AT_F000 				;R78
;R79 - start
;R79A ifndef	AVIDEO_AT_F000
;R79A	;Report E0000-EFFFF used by system BIOS
;R79A	FMEM32_DSP	00110010B, 0E0000H, 10000H	;64Kb ROM
;R79A endif;	AVIDEO_AT_F000
;R79A	;Report F0000-FFFFF used by system BIOS
;R79A	;Note that the following four memory nodes are also used for
;R79A	;USB frame buffer , onboard SCSI and Shrank ROM.
;R79A	FMEM32_DSP	00110010B, 0F0000H, 04000H	;16K ROM
;R79A	FMEM32_DSP	00110010B, 0F4000H, 04000H	;16K ROM
;R79A	FMEM32_DSP	00110010B, 0F8000H, 04000H	;16K ROM
;R79A	public	LastMbNodeShared
;R79ALastMbNodeShared:
;R79A	FMEM32_DSP	00110010B, 0FC000H, 04000H	;16K ROM
;R79 - end

	FMEM32_DSP	00000111B, 000000H, 0A0000H	;R01

;R70 start
ifdef	SiS510X_SMBase_PATCH
	public	SMbaseMemNode
SMbaseMemNode:
	FMEM32_DSP	00000111B, 08000000H, 1FE00000H
endif;	SiS510X_SMBase_PATCH
;R70 end

;R37 - start
ifdef	TOP_2ND_1MB_USED_64KB
	;Claim memory range for SiS/5596
	FMEM32_DSP	00000111B, 020000000H, 0400000H	;4Mb space from;R37B
							;addr. 512Mb   ;R37B
;R37A	FMEM32_DSP	00010000B, 0FFEF0000H, 0010000H	;64kb occupied
;R60B;R60 - start
;R60Bifdef	DAEWOO_5571_PATCH
;R60B	FMEM32_DSP	00010000B, 0FFEE0000H, 0010000H	;64kb
;R60B	public	T9685_Dirty
;R60BT9685_Dirty:
;R60B	FMEM32_DSP	00010000B, 0FFEF0000H, 0010000H	;64kb
;R60B;R60A	public	DirtyAddr
;R60B;R60ADirtyAddr:
;R60B;R60A	FMEM32_DSP	00010000B, 001000000H, 3F00000H	;64Mboccupied
;R60Belse;	DAEWOO_5571_PATCH
 		FMEM32_DSP	00010000B, 0FFEE0000H, 0020000H	;128kb occupied;R37A
;R60Bendif;	DAEWOO_5571_PATCH
;R60B
;R60B;R60 - end
endif;	TOP_2ND_1MB_USED_64KB
;R37 - end

;Report 40008000H-40ffffffH as system memory space for GX86	;R58
ifdef	USE_MEM_256M						;R58
	FMEM32_DSP	00010010B, 040008000H, 0FF8000H	;     	;R58
endif;	USE_MEM_256M						;R58

ifdef	USE_MEM_Cx5520_Special					;R58A
         FMEM32_DSP	00010010B, 040008000H, 0008000H	;     	;R58A
         FMEM32_DSP	00010010B, 040011000H, 0FEF000H	;     	;R58A
endif	;USE_MEM_Cx5520_Special					;R58A

ifdef	USE_MEM_Cx5530_Special					;R58B
         FMEM32_DSP	00010010B, 040010000H, 0001000H	;Video	;R58B
         FMEM32_DSP	00010010B, 040008000H, 0008000H	;     	;R58B
;R58C    FMEM32_DSP	00010010B, 040018000H, 1000000H	;     	;R58B
         FMEM32_DSP	00010010B, 040018000H, 07E8000H	;     	;R58C
         FMEM32_DSP	00010010B, 041000000H, 0018000H	;     	;R58C
;	 FMEM32_DSP	00010010B, 0000C0000H, 0008000H	;C0000-C7fff;R58B
endif	;USE_MEM_Cx5530_Special					;R58B

;R30 - starts
;R41	FMEM32_DSP	00010010B, 0FFF80000H, 0080000H
;R102 - start
ifdef	ICH
	FMEM32_DSP	00010010B, 0FFB00000H, 0100000H ;FWH , 1MB
	FMEM32_DSP	00010010B, 0FFF00000H, 0100000H	;ICH , 1MB
else;	ICH
;R102 - end
;Report top 512kb on 4GB boundary as system memory space for GX86;R58
 ifdef	USE_512K_ON_TOP_4GB					;R58
	FMEM32_DSP	00010010B, 0FFFC0000H, 0040000H	;256kb	;R58
 else;	USE_512K_ON_TOP_4GB					;R58
	FMEM32_DSP	00010010B, 0FFFE0000H, 0020000H	;R41
 endif;	USE_512K_ON_TOP_4GB					;R58
endif;	ICH							;R102
;R44 - starts
ifdef	MP_SUPPORT
	FMEM32_DSP	00010010B, 0FEC00000H, 0010000H
	FMEM32_DSP	00010010B, 0FEE00000H, 0010000H
endif	;MP_SUPPORT
;R44 - ends
	Public	EXT_MEM_RESOURCE_LOC
EXT_MEM_RESOURCE_LOC:
	FMEM32_DSP	00000111B, 000100000H, 0F00000H
;R38	IO_DSP		1,03F3h,03F3h,0,1		;R35
;R38 ifdef	PCI_BUS
;R38 ;R30A	FIO_DSP		04D0h, 2
;R38 ;R30A	FIO_DSP		0CF8h, 8
;R38 	IO_DSP		1,04D0h,04D0h,0,2		;R30B
;R38 	IO_DSP		1,0CF8h,0CF8h,0,8		;R30B
;R38 endif	;PCI_BUS
;R30 - ends
		public	EndOf_MbRom_Node		;R49
EndOf_MbRom_Node	label	near			;R49

	END_DSP
	END_DSP
	END_DSP
DEV_NODE_END

;R79A - start
; Mother board resource device node
ifndef	PATCH_I558_BOOT_ROM_NT_40				;R79B
DEV_NODE	41D0H, 0C02H, 088000H, 00000011B, ROM1_NODE
 ifndef	AVIDEO_AT_F000
	;Report E0000-EFFFF used by system BIOS
	FMEM32_DSP	00110010B, 0E0000H, 10000H	;64Kb ROM
 endif;	AVIDEO_AT_F000
	;Report F0000-FFFFF used by system BIOS
	;Note that the following four memory nodes are also used for
	;USB frame buffer , onboard SCSI and Shrank ROM.
	FMEM32_DSP	00110010B, 0F0000H, 04000H	;16K ROM
	FMEM32_DSP	00110010B, 0F4000H, 04000H	;16K ROM
	FMEM32_DSP	00110010B, 0F8000H, 04000H	;16K ROM
	public	LastMbNodeShared
LastMbNodeShared:
	FMEM32_DSP	00110010B, 0FC000H, 04000H	;16K ROM
	END_DSP
	END_DSP
	END_DSP
DEV_NODE_END
endif;	PATCH_I558_BOOT_ROM_NT_40				;R79B
;R79A - end

;R79 ;R49 - start
;R79 ;Reserve a dummy ROM node for onboard devices ROM report
;R79 		public	Onboard_Scsi_RomNode
;R79 Onboard_Scsi_RomNode	label	near
;R79 	FMEM32_DSP	00010010B, 000000000H, 0000000H	;dummy DSP
;R79 ;R49 - end
;R79
;R79 ;R67 - start
;R79 ifdef	COMBINE_ISA_ROM
;R79 ;Reserve a dummy ROM node for onboard devices ROM report
;R79 		public	Onboard_Other_RomNode
;R79 Onboard_Other_RomNode	label	near
;R79 	FMEM32_DSP	00010010B, 000000000H, 0000000H	;dummy DSP
;R79 endif;	COMBINE_ISA_ROM
;R79 ;R67 - end
;R79
;R79 ;R52 - start
;R79 ifdef	USB_SUPPORT
;R79 ;Reserve a dummy ROM node for USB frame buffer located in c8000-effff area
;R79 		public	Usb_MemNode
;R79 Usb_MemNode	label	near
;R79 	FMEM32_DSP	00000111B, 0000C8000H, 0002000H	;dummy DSP
;R79 endif;	USB_SUPPORT
;R79 ;R52 - end

ifndef	PCI_BUS 					;R04
; ISA Bridge

;R13DEV_NODE	41D0H, 0A00H, 060100H, 00000011B
DEV_NODE	41D0H, 0A00H, 060100H, 00000011B, ISAB_NODE	;R13
	END_DSP
	END_DSP
	END_DSP
DEV_NODE_END
endif	;PCI_BUS					;R04

ifdef	PCI_BUS 					;R12
; PCI Bridge						;R12
							;R12
;R13DEV_NODE	41D0H, 0A03H, 060400H, 00000011B	;R12
DEV_NODE	41D0H, 0A03H, 060400H, 00000011B, PCIB_NODE	;R13
;R66 - start
ifdef	Add_Trident_3DImage975_Node
                IO_DSP          1,2100h,2100h,0,70h
                IO_DSP          1,2180h,2180h,0,70h
                IO_DSP          1,2178h,2178h,0,08h
                IO_DSP          1,21f8h,21f8h,0,08h
endif;	Add_Trident_3DImage975_Node
;R66 - end
ifdef	Add_290h_Node					;R63A
 	IO_DSP		1,0290h,0290h,0,16		;R63A
else;	Add_290h_Node					;R63B
ifdef	SIS5595_ID					;R63B
 	IO_DSP		1,0290h,0290h,0,8		;R63B
endif	;SIS5595_ID                                     ;R63B
endif;	Add_290h_Node					;R63A

ifdef	Add_294h_Node					;R63
 	IO_DSP		1,0294h,0294h,0,4		;R63
endif;	Add_294h_Node					;R63

ifdef	Add_340h_Node					;R90
 	IO_DSP		1,0340h,0340h,0,8		;R90
endif;	Add_340h_Node					;R90

 	IO_DSP		1,04D0h,04D0h,0,2		;R38
 	IO_DSP		1,0CF8h,0CF8h,0,8		;R38
 	IO_DSP		1,0480h,0480h,0,16      	;R58
ifdef	USE_IO_4000H_5FFFH				;R58
 	IO_DSP		1,4000H,4000H,0,010H		;R58
 	IO_DSP		1,5000H,5000H,0,020H		;R58
endif;	USE_IO_4000H_5FFFH				;R58

ifdef	Add_PIIX4_SMBus_Node				;R51
		public	PIIX4_SMBus_IONode		;R51
PIIX4_SMBus_IONode	label	near			;R51
;R51A 	IO_DSP		1,6100h,6100h,0,80h		;R51
;R51A 	IO_DSP		1,6200h,6200h,0,80h		;R51
;R51C 	IO_DSP		1,6100h,6100h,0,40h		;R51A
 	IO_DSP		1,ACPI_Port,ACPI_Port,0,40h	;R51C
;R51B 	IO_DSP		1,6200h,6200h,0,20h		;R51A
 	IO_DSP		1,SMBus_Port,SMBus_Port,0,20h	;R51B
endif;	Add_PIIX4_SMBus_Node				;R51

;R93 - start
ifdef	ICH
 	IO_DSP		1,ACPI_Port,ACPI_Port,0,0c0h
;R105 - start
		public	ICH_SMBus_IONode
ICH_SMBus_IONode	label	near
 	IO_DSP		1,SMBus_Port,SMBus_Port,0,20h
;R105 - end
endif;	ICH
;R93 - end

;R103 - start
ifdef	COBRA_ACPI
	;Report I/O usage for ACPI
	IO_DSP	1, ACPI_Port+000h, ACPI_Port+000h, 0, 080h	
	IO_DSP	1, ACPI_Port+080h, ACPI_Port+080h, 0, 080h	
endif;	COBRA_ACPI
;R103 - end

ifdef	VT586_ACPI					;R68	VIA  ACPI
;R68E	IRQ_DSP      0000001000000000B			;R68	Chipset.
		Public	VIA_ACPI_IO_Node_Index		;R68B
VIA_ACPI_IO_Node_Index:					;R68B
;R68A	IO_DSP	     1, 5F00h, 5F00h, 0, 050h		;R68
;R68C	IO_DSP	     1, 5F00h, 5F00h, 0, 076h		;R68A 5F00h - 5F75h
;R68C	IO_DSP	     1, 5F77h, 5F77h, 0, 009h		;R68A 5F77h - 5F7Fh
;R68C	IO_DSP	     1, 5F80h, 5F80h, 0, 030h		;R68A 5F80h - 5FAFh
;R68C	IO_DSP	     1, 5FBCh, 5FBCh, 0, 004h		;R68A 5FBCh - 5FBFh
;R68C	IO_DSP	     1, 5FE0h, 5FE0h, 0, 016h		;R68A 5FE0h - 5FF5h
;R68C	IO_DSP	     1, 5FF7h, 5FF7h, 0, 009h		;R68A 5FE0h - 5FF5h
if	ACPI_Port	EQ	5f00h			;R68D
	IO_DSP	1, ACPI_Port+000h, ACPI_Port+000h, 0, 076h ;R68C 5F00h - 5F75h
	IO_DSP	1, ACPI_Port+077h, ACPI_Port+077h, 0, 009h ;R68C 5F77h - 5F7Fh
	IO_DSP	1, ACPI_Port+080h, ACPI_Port+080h, 0, 030h ;R68C 5F80h - 5FAFh
	IO_DSP	1, ACPI_Port+0BCh, ACPI_Port+0BCh, 0, 004h ;R68C 5FBCh - 5FBFh
	IO_DSP	1, ACPI_Port+0E0h, ACPI_Port+0E0h, 0, 016h ;R68C 5FE0h - 5FF5h
	IO_DSP	1, ACPI_Port+0F7h, ACPI_Port+0F7h, 0, 009h ;R68C 5FE0h - 5FF5h
else	;ACPI_Port						;R68D
	IO_DSP	1, ACPI_Port+000h, ACPI_Port+000h, 0, 080h	;R68D
	IO_DSP	1, ACPI_Port+080h, ACPI_Port+080h, 0, 080h	;R68D
endif	;ACPI_Port						;R68D
ifdef	SMBus_Port					;R68F
 	IO_DSP		1,SMBus_Port,SMBus_Port,0,20h	;R68F
endif;	SMBus_Port					;R68F
ifdef	VT686							;R68G
  IFDEF	VIA686HM_Port						;R68G
 	IO_DSP		1,VIA686HM_Port,VIA686HM_Port,0,80h	;R68G
  ENDIF;VIA686HM_Port						;R68G
endif;	VT686							;R68G
endif;	VT586_ACPI					;R68

	END_DSP 					;R12
	END_DSP 					;R12
	END_DSP 					;R12
DEV_NODE_END						;R12
endif	;PCI_BUS					;R12

;R02 - start
; PS/2 mouse

comment %	;R15
DEV_NODE	41D0H, 0F0EH, 090200H, 00000011B, PS2_NODE
;R13	IRQ_DSP 	0001000000000000B
	IRQ_DSP 	0000000000000000B		;R13
	END_DSP
PS2_Resource	label	byte				;R13
	IRQ_DSP 	0001000000000000B		;R13
PS2_Resource_L	equ	$ - PS2_Resource		;R13
	END_DSP
	END_DSP
DEV_NODE_END
%		;R15
;R02 - end

;R32 - starts
PS2_Mouse_Node:
;R33 DEV_NODE	41D0H, 0F0EH, 090200H, 0000000110000000B, PS2_NODE
DEV_NODE	41D0H, 0F13H, 090200H, 0000000110000000B, PS2_NODE	;R33
PS2_IRQ_LOCATION	EQU	$ - offset dgroup:PS2_Mouse_Node
	IRQ_DSP 	0000000000000000B
	END_DSP
 START_DF
PS2_Resource	label	byte
	IRQ_DSP 	0001000000000000B
PS2_Resource_L	equ	$ - PS2_Resource
 END_DF
	END_DSP
	END_DSP
DEV_NODE_END
;R32 - ends

ifndef	NO_ISA_PNP					;R85
;R16 - start
; PnP RD_DATA port device node
DEV_NODE	41D0H, 0C02H, 088000H, 00000011B, RDDATA_NODE
;R20	FIO_DSP 	203h, 1
;R31	FIO_DSP 	203h, 8				;R20
	IO_DSP 		1, 203h, 203h, 0, 8		;R31
	END_DSP
	END_DSP
	END_DSP
DEV_NODE_END
;R16 - end
endif	;NO_ISA_PNP					;R85

;R72 start
ifdef	Cardbus_support
COMPILE_FOR_PNP_COMPATIBLE_NODE	=	1
	include	cardbus.inc
endif	;Cardbus_support
;R72 end

;R13	END_NODE
;R13SYSTEM_NODE_TOTAL	=	NODE_NUM
;R13SYSTEM_NODE_LARGEST =	LARGEST_NODE

; Device node index table structure
; byte 0	total number of the device nodes in this table
; byte 1-3	device 0 index structure
;	Byte	attribute flag of device node
;		bit7 = 1	disable (don't report)
;		bit6		reserved
;		bit5		reserved
;		bit4		reserved
;		bit3 = 1	special post procedure support
;		bit2 = 1	special get device node support
;		bit1 = 1	static set device node support
;		bit0 = 1	dynamically set device node support
;	word	offset address point to description block
; byte 4-6	device 1 index structure
; ......

		PUBLIC	SYSTEM_NODE_INDEX
SYSTEM_NODE_INDEX	LABEL	WORD
;R13		SET_NODES_INDEX NODE_NUM
;R13		DB	0FFh
;R13 - start
		DB	SYSTEM_NODES_NUM
		SET_NODE_INDEX	PIC_NODE, 00000000B
		SET_NODE_INDEX	DMA_NODE, 00000000B
		SET_NODE_INDEX	TIMER_NODE, 00000000B
		SET_NODE_INDEX	RTC_NODE, 00000000B
		SET_NODE_INDEX	KB_NODE, 00000000B
		SET_NODE_INDEX	SPK_NODE, 00000000B
		SET_NODE_INDEX	MPU_NODE, 00000000B
		SET_NODE_INDEX	ROM_NODE, 00000000B
ifndef	PATCH_I558_BOOT_ROM_NT_40				;R79B
 		SET_NODE_INDEX	ROM1_NODE, 00000000B		;R79A
endif;	PATCH_I558_BOOT_ROM_NT_40				;R79B
ifdef	PCI_BUS
		SET_NODE_INDEX	PCIB_NODE, 00000000B
else	;PCI_BUS
		SET_NODE_INDEX	ISAB_NODE, 00000000B
endif	;PCI_BUS
;R15		SET_NODE_INDEX	PS2_NODE, 00001000B
ifndef	Special_Report_PS2_Node_for_Windows98			;R86A
		SET_NODE_INDEX	PS2_NODE, 00001101b		;R86A
ifndef	NO_ISA_PNP						;R86A
		SET_NODE_INDEX	RDDATA_NODE, 00001000B		;R86A
endif	;NO_ISA_PNP						;R86A
endif;	Special_Report_PS2_Node_for_Windows98			;R86A
;R86		SET_NODE_INDEX	PS2_NODE, 00001101b 	;R32
;R86ifndef	NO_ISA_PNP				;R85
;R86		SET_NODE_INDEX	RDDATA_NODE, 00001000B	;R16
;R86endif	;NO_ISA_PNP				;R85
;R72 start
ifdef	Cardbus_support
COMPILE_FOR_PNP_COMPATIBLE_NODE	=	2
	include	cardbus.inc
endif	;Cardbus_support
;R72 end
SYSTEM_NODES_NUM	EQU	($ - SYSTEM_NODE_INDEX - 1)/3
;R13 - end

; Special process table structure (one device)
; byte		node number in the above index table
; word		offset address of special get device node procedure
; word		offset address of special set device node procedure
; word		offset address of special post process procedure

		PUBLIC	SYSTEM_NODE_PROC
SYSTEM_NODE_PROC	LABEL	BYTE
ifndef	Special_Report_PS2_Node_for_Windows98			;R86A
	NODE_PROC	PS2_NODE ,Ct_Get_PS2_Node ,Ct_Set_PS2_Node ,Ct_PS2_Node 	;R86A
ifndef	NO_ISA_PNP						;R86A
	NODE_PROC	RDDATA_NODE, Dummy_Set_Node, Dummy_Set_Node, Ct_RdData_Node	;R86A
endif	;NO_ISA_PNP						;R86A
endif;	Special_Report_PS2_Node_for_Windows98			;R86A
;R12		NODE_PROC	PS2_NODE, Ct_PS2_Node			;R02
;R13		NODE_PROC	PS2_NODE, Ct_PS2_Node, Dummy_Set_Node	;R12
;R15	NODE_PROC	PS2_NODE, Dummy_Set_Node, Dummy_Set_Node, Ct_PS2_Node	;R13
;R86	NODE_PROC	PS2_NODE ,Ct_Get_PS2_Node ,Ct_Set_PS2_Node ,Ct_PS2_Node 	;R32
;R86ifndef	NO_ISA_PNP					;R85
;R86	NODE_PROC	RDDATA_NODE, Dummy_Set_Node, Dummy_Set_Node, Ct_RdData_Node	;R16
;R86endif	;NO_ISA_PNP					;R85
;R72 start
ifdef	Cardbus_support
COMPILE_FOR_PNP_COMPATIBLE_NODE	=	3
	include	cardbus.inc
endif	;Cardbus_support
;R72 end
		DB	0FFh

; CHK_ATTR is for assembler to check corresponding procedure present in
;	NODE_PROC table, if its attribute flag of index table indicate
;	special procedure needed. Avoid coding mistake.

		CHK_ATTR	%NODE_NUM	;R13

;R86 - start
ifdef	Special_Report_PS2_Node_for_Windows98			;R86A
		PUBLIC	PS2_NODE_INDEX
PS2_NODE_INDEX	LABEL	WORD
	DB	PS2_NODES_NUM
	SET_NODE_INDEX	PS2_NODE, 00001101b
ifndef	NO_ISA_PNP
	SET_NODE_INDEX	RDDATA_NODE, 00001000B
endif;	NO_ISA_PNP
PS2_NODES_NUM	EQU	($ - PS2_NODE_INDEX - 1)/3

		PUBLIC	PS2_NODE_PROC
PS2_NODE_PROC	LABEL	BYTE
;NODE_PROC	PS2_NODE ,Ct_Get_PS2_Node ,Ct_Set_PS2_Node ,Ct_PS2_Node
		db	0	;because macro set this is 0Ah, than pnpe0.asm
				;compare this is not match
		DW	offset DGROUP:Ct_Get_PS2_Node
		DW	offset DGROUP:Ct_Set_PS2_Node
		DW	offset DGROUP:Ct_PS2_Node
ifndef	NO_ISA_PNP
;NODE_PROC	RDDATA_NODE, Dummy_Set_Node, Dummy_Set_Node, Ct_RdData_Node
		db	1	;because macro set this is 0bh
		DW	offset DGROUP:Dummy_Set_Node
		DW	offset DGROUP:Dummy_Set_Node
		DW	offset DGROUP:Ct_RdData_Node
endif;	NO_ISA_PNP

		DB	0FFh
endif;	Special_Report_PS2_Node_for_Windows98			;R86A
;R86 - end
;R72 start
ifdef	Cardbus_support
COMPILE_FOR_PNP_COMPATIBLE_NODE	=	4
	include	cardbus.inc
endif	;Cardbus_support
;R72 end

ifndef	NO_ISA_PNP					;R85
;R16 - start
Ct_RdData_Node	proc	near
		push	ds
		xor	ax, ax
		mov	ds, ax
		cmp	byte ptr ds:TEMP_LAST_CSN, 0
		stc
		je	short Ct_RdData_Exit
		mov	ax, ds:TEMP_PNP_RD
		and	al, 11111000b			;R20
;R31		mov	es:[di+13], ax			;IO port value position

	;IO port value position	in ES:[DI+14] &	ES:[DI+16]	;R31

		mov	es:[di+14], ax				;R31
		mov	es:[di+16], ax				;R31

		clc
Ct_RdData_Exit:
		pop	ds
		ret
Ct_RdData_Node	endp
;R16 - end
endif	;NO_ISA_PNP					;R85

ifdef	ESCD_SUPPORT					;R85
;R07 - start
;[]========================================================================[]
;
;	System Default ESCD definition
;
;[]========================================================================[]

		PUBLIC	DEFAULT_ESCD
		PUBLIC	DEFAULT_ESCD_L
DEFAULT_ESCD	LABEL	BYTE

	ESCDDEF

	BRDDEF	0000h, 0000h, 0100000001000000b

	BRDEND

	ESCDEND

DEFAULT_ESCD_L	EQU	$ - DEFAULT_ESCD
;R07 - end
endif	;ESCD_SUPPORT					;R85

;R27ifdef 	DMI_ENABLED				;R23
;R27	  include dmi_func.inc			;R23
;R27endif	;DMI_ENABLED				;R23

ENDIF	;PNP_BIOS

FCODE		ENDS
		END
