;	[]===========================================================[]
;
;	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.
;
; 	[]===========================================================[]
;
;----------------------------------------------------------------------------
;Rev	Date	 Name	Description
;----------------------------------------------------------------------------
;R10A	03/23/99 RIC	Fixed that the mistake of R01 code cause system hang
;			in 95/98 APM shutdown by using AT Power.
;R10	01/11/99 ADS	Added Suspend to HDD function.
;R07B	12/23/98 ADS	Fix s4 can't auto poweroff.
;R09	11/30/98 BAR	Update ESCD DMI use SMM mode.
;			define switch "Flash_IN_SMBASE"
;R06B	11/16/98 RIC	Remove R06A code and Recover old code.(see chiprun(R03))
;R06A	11/06/98 TNY	Fix that Trend Anti-Virus replace F0000-F4800 area
;			so, call this area's hook will cause system hang.
;R07A	11/04/98 RIC	Fix that the mistake of 'R07' code cause CTR-ALT-DEL
;			fail in W95/W98 shatdown by using AT power.
;R08	09/25/98 RIC	Fix that no ACPI_SUPPORT define BIOS can't auto-
;			poweroff in Win95/Win98 APM shutdown.
;R07	08/27/98 RIC	Issue Software SMI in APM16_PowerOff.
;			and move APM16_PowerOff code to SMI_Sof_Off(PMUPOST).
;R06	08/24/98 RIC	Fix that Trend Anti-Virus replace Hex_To_BCD routine
;			to cause System hang in RTC_Alarm_Resume routine.
;			(Suspend by EXTSMI Buttom + RTC alarm enabled)
;R05	08/12/98 RIC	Fix Win98 APM mode shun-down hang if AT power-supply
;			plugged.
;R04	08/04/98 RIC	Add delay before APM PowerOff function.
;R03	07/31/98 RIC	Support RTC Alarm Resume of VT596 F version or later.
;R01A	07/24/98 RIC	Remove "Cover_VT596_E_Version" define.
;R02	07/07/98 RIC	Support VT596 Modem Ring Resume function.
;R01	06/29/98 RIC	Fixed that system Power Buttom fail in new VT596 chip.
;			Add "Cover_VT596_E_Version" define.
;R00	05/13/98 RIC	Initialization.
.386p
		PAGE	56,132
		TITLE	CHIPSET  -- 386/486 EISA/ISA ROM/BIOS

		include BIOS.CFG
		include BSETUP.INC

		include COMMON.MAC
		include COMMON.EQU
		include POST.MAC
		include CMOS.EQU

SMI_ENTRY	EQU	0d0h
SMI_IDLE	EQU	0d1h
SMI_SUS 	EQU	0d3h

ifdef	PM_SUPPORT
		extrn	Get_Cmos:near
		extrn	Set_Cmos:Near
		extrn	Enable_CRT:near
		extrn	Disable_CRT:near
		extrn	PM_Option_Item:near
		extrn	PM_Auto_Table:near
		extrn	VGA_Type_Item:near

		extrn	Doze_Timer_Item:near
		extrn	Susp_Timer_Item:near
		extrn	Wait_APM_Item:near
		extrn	Video_Off_Item :near
		extrn	HDD_Timer_Item:Near
		extrn	IRQ3_Event_Item:Near
		extrn	Get_PMU:near		
		extrn	Set_PMU:near		
endif	;PM_SUPPORT
		extrn	Get_Ct:near
		extrn	Set_Ct:near
		extrn	Get_Set_Ct:near		
;R06A		extrn	Get_Set_Ct_OR:near	
;R06A		extrn	Get_Set_Ct_AND:near	
;R06A		extrn	Get_Set_PMU_OR:near	
;R06A		extrn	Get_Set_PMU_AND:near	
		extrn	Get_Set_Ct_OR:near		;R06B
		extrn	Get_Set_Ct_AND:near		;R06B
		extrn	Get_Set_PMU_OR:near		;R06B
		extrn	Get_Set_PMU_AND:near		;R06B
		extrn	GetItem_Value:Near
		extrn	Get_PMIO:near		
		extrn	Set_PMIO:near		

ifdef	Sleep_Mode_Select
		extrn	Suspend_Way_Item:Near
endif	;Sleep_Mode_Select
		extrn	SMI_Soft_Off:near 	;R10
		extrn	Post_call_proc:near	;R10

RSM		MACRO
		db     0FH,0AAH 	; Not defined in MASM.
		ENDM

FIXOFST 	MACRO	ADDRESS
		dw	offset ADDRESS - offset SMI_Handler_Start
		ENDM

;[]-----------------------------------------------------------------------[]
;     GGGGGGGG		   RRRRRRRR	    AA	     MMM       MMM
;   GGGGGGGGGGG 	   RRRRRRRRR	   AAAA      MMMMM   MMMMM
;  GGGG 		   RRR	  RRR	  AAAAAA     MMMMMM MMMMMM
;  GGG	  GGGGG 	   RRRRRRRRR	 AAA  AAA    MMM MMMMM MMM
;  GGGG     GGGG	   RRRRRRRR	AAAAAAAAAA   MMM MMMMM MMM
;   GGGGGGGGGGGG	   RRR	 RRR   AAAAAAAAAAAA  MMM  MMM  MMM
;    GGGGGGGGGG  ========  RRR	  RRR AAA	 AAA MMM  MMM  MMM
;[]-----------------------------------------------------------------------[]
G_RAM		SEGMENT USE16 AT 0

		ORG	04H*4
		include SEG_0.INC

		ORG	400H
		include G_RAM.INC

G_RAM		ENDS

ifdef	PM_SUPPORT

SMI_STRUCT	STRUC
		dd	?
_SpSave		dw	1 dup (?)
_EspSave	dd	1 dup (?)
_EaxSave	dd	1 dup (?)
_EbxSave	dd	1 dup (?)
_Cr2Save	dd	1 dup (?)
_Cr3Save	dd	1 dup (?)
_Gdt		dq	1 dup (0)
		dw	1 dup (?)
		dw	1 dup (?)
		db	1 dup (?)
		db	1 dup (?)
		db	1 dup (?)
		db	1 dup (?)
		dw	1 dup (?)
		dw	1 dup (?)
		db	1 dup (?)
		db	1 dup (?)
		db	1 dup (?)
		db	1 dup (?)
_DsSave		dt	1 dup (?)
_EsSave		dt	1 dup (?)
_SsSave		dt	1 dup (?)
_FsSave		dt	1 dup (?)
_GsSave		dt	1 dup (?)
_LdtSave	dt	1 dup (?)
_TskSave	dt	1 dup (?)
_Dstemp		db	10 dup (?)
_GdtSave	df	1 dup (?)
_GdtNew		dw	1 dup (?)
		dd	1 dup (?)
_IdtSave	df	1 dup (?)
_RealModeIdt	dw	1 dup (?)
		dd	1 dup (?)
SMI_STRUCT	ENDS

endif	;PM_SUPPORT

ifdef	PM_SUPPORT
;[]-----------------------------------------------------------------------[]
;  PPPPPPPPP  MMM	MMM	  RRRRRRRR	   AA	    MMM       MMM
;  PPP	  PPP MMMMM   MMMMM	  RRRRRRRRR	  AAAA	    MMMMM   MMMMM
;  PPPPPPPPP  MMMMMM MMMMMM	  RRR	 RRR	 AAAAAA     MMMMMM MMMMMM
;  PPPPPPPP   MMM MMMMM MMM	  RRRRRRRRR	AAA  AAA    MMM MMMMM MMM
;  PPP	      MMM MMMMM MMM	  RRRRRRRR     AAAAAAAAAA   MMM MMMMM MMM
;  PPP	      MMM  MMM	MMM	  RRR	RRR   AAAAAAAAAAAA  MMM  MMM  MMM
;  PPP	      MMM  MMM	MMM ===== RRR	 RRR AAA	AAA MMM  MMM  MMM
;[]-----------------------------------------------------------------------[]
PM_RAM		SEGMENT USE16 AT 0
		
		ORG	0

PM_RAM_START	LABEL	BYTE
		include 		PM_RAM.INC
		include 		CT_PMRAM.INC
PM_RAM_LEN	EQU	$-Offset PM_RAM:PM_RAM_START

PM_RAM		ENDS
endif	;PM_SUPPORT

DGROUP		GROUP	FCODE
FCODE		SEGMENT USE16 PARA Public 'CODE'
		ASSUME	CS:DGROUP

ifdef	PM_SUPPORT
;[]-------------------------------------------------------------------[]
;
; PPPPPPPP	 AA	  RRRRRRRR   TTTTTTTTTTT	       111
; PPPPPPPPP	AAAA	  RRRRRRRRR  TTTTTTTTTTT    ***       1111
; PPP	 PPP   AAAAAA	  RRR	 RRR	 TTT	    ***      11111
; PPPPPPPPP   AAA  AAA	  RRRRRRRRR	 TTT		       111
; PPPPPPPP   AAAAAAAAAA   RRRRRRRR	 TTT	    ***        111
; PPP	    AAAAAAAAAAAA  RRR	RRR	 TTT	    ***        111
; PPP	   AAA	      AAA RRR	 RRR	 TTT		       111
;
;
;   1. Standard routines that must be filled in to let the BIOS KERNAL
;      to program the PMU registers
;   2. Called during POST & after POST
;
;[]-------------------------------------------------------------------[]

;[]==============================================================[]
; Get_Set_PMIO:
;	Change a value in the chipset register(ACPI).
; Input  :	CX = Index register to change
;		bl = Value to change AND
;		bh = Value to change OR
; Output :	None
; Destory:	EAX, ECX, DX
;
;[]==============================================================[]
		Public	Get_Set_PMIO
Get_Set_PMIO	proc	near
		call	Get_PMIO
		and	al, bl			;AND data
		or	al, bh			;OR data
		call	Set_PMIO
		ret
Get_Set_PMIO	endp

;[]==============================================================[]
; Get_Set_PMIO_OR:
;	OR a value in the chipset register(ACPI).
; Input  :	CX = Index register to change
;		bl = Value to change (OR)
; Output :	None
; Destory:	EAX, ECX, DX
;
;[]==============================================================[]
		Public	Get_Set_PMIO_OR
Get_Set_PMIO_OR	proc	near
		call    Get_PMIO
		or      al, bl			;OR data
		call    Set_PMIO
		ret
Get_Set_PMIO_OR	endp

;[]==============================================================[]
; Get_Set_PMIO_AND:
;	AND a value in the chipset register(ACPI).
; Input  :	CX = Index register to change
;		bl = Value to change (AND)
; Output :	None
; Destory:	EAX, ECX, DX
;
;[]==============================================================[]
		Public	Get_Set_PMIO_AND
Get_Set_PMIO_AND	proc	near
		call    Get_PMIO
		and     al, bl			;AND data
		call    Set_PMIO
		ret
Get_Set_PMIO_AND	endp

;[]==============================================================[]
; Set_PMIO_Clear:
;	Clear a value in the chipset register.
; Input  :	CX = Index register to change.
;		bl = Value to change (Clear)
; Output :	None
; Destory:	EAX, ECX, DX
;
;[]==============================================================[]
		Public	Set_PMIO_Clear
Set_PMIO_Clear	proc	near
		mov     al, 0ffh		; 0FFh (Write 1 to Clear)
		call    Set_PMIO		; Clear
		ret
Set_PMIO_Clear	endp

;[]========================================================================[]
;Procedure:	Get_PM_RAM_Seg
;
;Function :	To obtain the extended BIOS data area segment address.
;
;Input	  :	None
;
;Output   :	AX: should point to the extended BIOS data area
;
;Note	  :	1. Call from POST 79S (PM initialization)
;		2. Stack available
;[]========================================================================[]
		Public	Get_PM_RAM_Seg
Get_PM_RAM_Seg	Proc	Near
		mov	ax, PM_RAM_SEGMENT
		ret
Get_PM_RAM_Seg	Endp

;[]========================================================================[]
;Procedure:	Open_PM_RAM
;
;Function :	To enable the PM RAM read/write
;
;Input	  :	None
;
;Output   :	None
;
;Preserve :	All
;
;Note	  :	1. Stack available
;		2. called from PM_Init & APM
;[]========================================================================[]
		Public	F000_Shadow_W
		Public	Open_PM_RAM
Open_PM_RAM	Proc	Near
F000_Shadow_W:
		pushad
;R06A		mov	cx,VT692 + 63h
;R06A		mov	bl,00110000b		
;R06A		call	Get_Set_Ct_OR		

;R06B ;R06A - start
;R06B 		mov	cx,VT692 + 63h
;R06B 		call	Get_Ct
;R06B 		or	al,00110000b
;R06B 		call	Set_Ct
;R06B ;R06A - end
		mov	cx,VT692 + 63h		;R06B 
		mov	bl,00110000b		;R06B 
		call	Get_Set_Ct_OR		;R06B 

		popad
		ret

Open_PM_RAM	Endp

;[]========================================================================[]
;Procedure:	Close_PM_RAM
;
;Function :	To close PM RAM
;		(Normally, PM_RAM is located in shadow RAM)
;
;Input	  :	AL = 1 --> there is option ROM in the PM_RAM area
;		     0 --> there is no option ROM in the PM_RAM area
;
;Output   :	if input AL = 1
;
;		   switch the PM_RAM area back to ROM
;
;		if input AL = 0
;
;		   program this area into read-only mode
;
;Preserve :	All
;
;Note	  :	1. Stack available
;		2. called from PMI_Handler, PM_Init
;[]========================================================================[]
		Public	F000_Shadow_R
		Public	Close_PM_RAM
Close_PM_RAM	Proc	Near
F000_Shadow_R:
		pushad
		mov	cx,VT692 + 63h
		mov	bx,0010000011001111b
		call	Get_Set_Ct
		popad
		ret

Close_PM_RAM	Endp

;[]-------------------------------------------------------------------[]
;
; PPPPPPPP	 AA	  RRRRRRRR   TTTTTTTTTTT	       33333
; PPPPPPPPP	AAAA	  RRRRRRRRR  TTTTTTTTTTT    ***       333 333
; PPP	 PPP   AAAAAA	  RRR	 RRR	 TTT	    *** 	  333
; PPPPPPPPP   AAA  AAA	  RRRRRRRRR	 TTT			33333
; PPPPPPPP   AAAAAAAAAA   RRRRRRRR	 TTT	    *** 	  333
; PPP	    AAAAAAAAAAAA  RRR	RRR	 TTT	    ***       333 333
; PPP	   AAA	      AAA RRR	 RRR	 TTT		       33333
;
;	   Hooks to the real mode APM functions
;
;[]-------------------------------------------------------------------[]

;[]========================================================================[]
;Procedure:	Ct_Check_If_LowBat
;
;Function :	Tell BIOS whether the machine is in LOW BATTERY status
;
;Input	  :	DS = PM_RAM
;
;Output   :	if AC on line
;			BH =	01h
;			BL =	FFh
;
;		if AC off line
;			BH =	00h
;
;			BL =	00h ---> Battery Good
;			BL =	01h ---> Battery Low
;
;Note	  :	Stack available
;[]========================================================================[]
		ASSUME	DS:PM_RAM
		Public	Ct_Check_If_LowBat
Ct_Check_If_LowBat	Proc	Near
		mov	bx,1FFh 		;assume AC power
		ret
Ct_Check_If_LowBat	Endp

;[]========================================================================[]
;Procedure:	Ct_APM_Func01
;
;Function :	To do OEM specific functions when APM is connected
;
;Input	  :	DS = PM_RAM
;
;Saves	  :	all
;
;[Note] :	1. This routine will be called "ONLY" when APM fucntion 01
;		   is successful, i.e. APM successfully connected
;
;		2. Function spec. of the APM function 01
;		   (Interface connect)
;
;		   Input  : DS = PM_RAM
;			    AH = 53h
;			    AL = 01h
;			    BX = 0000h - system BIOS
;
;		   Output : if function successful:
;				carry = 0 (NC)
;			    if function unsuccessful:
;				carry = 1 (CY)
;				ah = eoror code
;					02h interface connect
;					    already in effect
;					09h unrecognized device ID
;[]========================================================================[]
		ASSUME	DS:PM_RAM
		Public	Ct_APM_Func01
Ct_APM_Func01	Proc	Near

		ret

Ct_APM_Func01	Endp

;[]========================================================================[]
;Procedure:	Ct_APM_Func04
;
;Function :	To do OEM specific functions when APM is disconnected
;
;Input	  :	DS = PM_RAM
;
;Saves	  :	all
;
;[Note]   :	1. This routine will be called "ONLY" when APM fucntion 04
;		   is successful, i.e. APM successfully disconnected
;
;		2. Function spec. of the APM function 04
;		   (Interface disconnect)
;
;		   Input:
;			ah = 53h
;			al = 04h
;			bx = 0000h - system BIOS
;			DS = PM_RAM
;
;		   Output:
;			if function successful:
;				carry = 0 (NC)
;
;			if function unsuccessful:
;				carry = 1 (CY)
;				ah = error code
;				03h = interface not connected
;				09h = unrecognized device ID
;
;[]========================================================================[]
		ASSUME	DS:PM_RAM
		Public	Ct_APM_Func04
Ct_APM_Func04	Proc	Near

		ret

Ct_APM_Func04	Endp

;[]========================================================================[]
;Procedure:	Ct_APM_Func05
;
;Function :	Set power state into DOZE mode
;
;Input	  :	DS = PM_RAM
;
;Output   :	None
;
;[Note]   :	1. This routine will be called "ONLY" when APM fucntion 05
;		   is successful, i.e. APM is going to put system into
;		   idle state
;
;		2. Function spec. of the APM function 05
;		   (CPU Idle call)
;
;		   Input    :	DS = PM_RAM
;				AH = 53h
;				AL = 05h
;
;		   Output   :	CF - Error
;				     AH = 03h Interface not connected
;				NC - Success
;
;[]========================================================================[]
		ASSUME	DS:PM_RAM
		public	Ct_APM_Func05
Ct_APM_Func05	Proc	Near
		cmp	[PM_TimeOut_Type],0
		je	short @F
		cmp	[PM_TimeOut_Type],3
		jae	short @F
		call	Issue_SW_SMI
	@@:
		ret

Ct_APM_Func05	Endp
;[]========================================================================[]
;Procedure:	Ct_APM_Func06
;
;Function :	Set power state into Full On mode
;
;Input	  :	DS = PM_RAM
;
;Output   :	None
;
;[Note]   :	1. This routine will be called "ONLY" when APM fucntion 06
;		   is successful, i.e. APM is going to put system into
;		   full-on state
;
;		2. Function spec. of the APM function 06
;		   (CPU Busy Call)
;
;		   Input    :	AH = 53h
;				AL = 06h
;
;		   Output   :	CF - Error
;				     AH = 03h Interface not connected
;				NC - Success
;
;[]========================================================================[]
		ASSUME	DS:PM_RAM
		public	Ct_APM_Func06
Ct_APM_Func06	Proc	Near
		ret
Ct_APM_Func06	Endp

;[]========================================================================[]
;[]========================================================================[]
		Public	CT_APM_FUNC10
CT_APM_FUNC10	Proc	Near
		ret
CT_APM_FUNC10	Endp

;[]========================================================================[]
;[]========================================================================[]
		ASSUME	DS:PM_RAM
		PUBLIC	APM_16_SUSPEND
APM_16_SUSPEND	Proc	NEAR
		mov	[PM_TimeOut_Type],03h
		call	Issue_SW_SMI
		ret
APM_16_SUSPEND	Endp

;[]========================================================================[]
;[]========================================================================[]
		Public	APM_16_Standby
APM_16_Standby	Proc	Near
		jmp	APM_16_Suspend
		ret
APM_16_Standby	Endp

		Public	Software_SMI		
		public	Issue_sw_smi
Issue_SW_Smi:
Software_SMI:					

		mov	cl, 2Ah			
		mov	bl, 40h
		call	Get_Set_PMIO_OR

		mov	cl, 2fh			
		mov	al, 1			
		call	Set_PMIO		
		ret

;R09 - start
;[]========================================================================[]
;		Flash_SW_Smi
;	Do'nt destroy  any register flash 
;	must use register tanrfser data to SMM mode
;[]========================================================================[]
ifdef	Flash_IN_SMBASE
		public	Flash_sw_smi
Flash_SW_Smi:
		pushad
		mov	cx, 2Ah
		mov	bl, 40h
		call	Get_Set_PMIO_OR
		popad
		mov	dx,ACPI_Port + 2FH
		mov	al,1
		out	dx,al		
		ret
endif;	Flash_IN_SMBASE
;R09 - end

		Public	PM_Before_HDD
		ALIGN	4
PM_Before_HDD	Proc	Near
		ret
PM_Before_HDD	Endp

		Public	PM_After_HDD
		ALIGN	4
PM_After_HDD	Proc	Near
		ret
PM_After_HDD	Endp

		Public	PM_Before_FDD
		ALIGN	4
PM_Before_FDD	Proc	Near
		ret
PM_Before_FDD	Endp

		Public	PM_After_FDD
		ALIGN	4
PM_After_FDD	Proc	Near
		ret
PM_After_FDD	Endp

		Public	PM_Before_PS2_Mouse
		ALIGN	4
PM_Before_PS2_Mouse	Proc	Near
		ret
PM_Before_PS2_Mouse	Endp

		Public	PM_After_PS2_Mouse
		ALIGN	4
PM_After_PS2_Mouse	Proc	Near
		ret
PM_After_PS2_Mouse	Endp


;[]========================================================================[]
;Input:		CF = 1 default no power off supported
;Output:	if no power off supported, just return.
;		else
;			CF = 1 power off fail
;			CF = 0 power off successful
;[]========================================================================[]
		ASSUME	DS:PM_RAM
		Public	APM_16_PowerOff
APM_16_PowerOff	Proc	Near

ifndef	ACPI_Support				;R08
		mov	cl, 2ah			;R08
		mov	bl, 40h			;R08
		call	Get_Set_PMIO_OR		;R08
endif;	ACPI_Support				;R08
		mov	cl, 2fh			;R07 SMI SoftwareOff
		mov	al, 57h			;R07
		call	Set_PMIO		;R07
;R07A		ret				;R07

;R07		xor	cx,cx				;R04
;R07	Delay_For_PowerOff:				;R04
;R07		NEWIODELAY				;R04
;R07	ifdef	More_Delay_Before_PowerOff		;R04
;R07		NEWIODELAY				;R04
;R07		NEWIODELAY				;R04
;R07		NEWIODELAY				;R04
;R07		NEWIODELAY				;R04
;R07		NEWIODELAY				;R04
;R07	endif;	More_Delay_Before_PowerOff		;R04
;R07		loop	short Delay_For_PowerOff	;R04
;R07
;R07		mov	al,1			
;R07		call	far ptr RTC_Alarm_Resume
;R07;R01 - start
;R07;R01A ifdef	Cover_VT596_E_Version
;R07  IFNDEF	NO_ATX_Judgement
;R07    ifndef	Always_ATX_Power
;R07		;***************************************;
;R07		;  ATX/AT power judge by GPI for 596	;
;R07		;***************************************;
;R07Power_Type_Judge_In_GPI_7_0	=	00h
;R07Power_Type_Judge_In_GPI_15_8	=	00h
;R07Power_Type_Judge_In_GPI_21_16	=	00h
;R07		;***************************************;
;R07		;  Use "ATX_High_AT_Low_In_GPI" Define	;
;R07		;***************************************;
;R07	  ifdef	ATX_High_AT_Low_In_GPI
;R07		if	ATX_High_AT_Low_In_GPI	LE	7
;R07		 if	ATX_High_AT_Low_In_GPI	GE	0
;R07Power_Type_Judge_In_GPI_7_0 = Power_Type_Judge_In_GPI_7_0 or (01h shl ATX_High_AT_Low_In_GPI)
;R07		 endif;	ATX_High_AT_Low_In_GPI	GE	0
;R07		endif;	ATX_High_AT_Low_In_GPI	LE	7
;R07		if	ATX_High_AT_Low_In_GPI	LE	15
;R07		 if	ATX_High_AT_Low_In_GPI	GE	8
;R07Power_Type_Judge_In_GPI_15_8 = Power_Type_Judge_In_GPI_15_8 or (01h shl (ATX_High_AT_Low_In_GPI-8))
;R07		 endif;	ATX_High_AT_Low_In_GPI	GE	8
;R07		endif;	ATX_High_AT_Low_In_GPI	LE	15
;R07		if	ATX_High_AT_Low_In_GPI	LE	21
;R07		 if	ATX_High_AT_Low_In_GPI	GE	16
;R07Power_Type_Judge_In_GPI_21_16 = Power_Type_Judge_In_GPI_21_16 or (01h shl (ATX_High_AT_Low_In_GPI-16))
;R07		 endif;	ATX_High_AT_Low_In_GPI	GE	16
;R07		endif;	ATX_High_AT_Low_In_GPI	LE	21
;R07	  endif;ATX_High_AT_Low_In_GPI
;R07		;***************************************;
;R07		;  Use "ATX_Low_AT_High_In_GPI" Define	;
;R07		;***************************************;
;R07	  ifdef	ATX_Low_AT_High_In_GPI
;R07		if	ATX_Low_AT_High_In_GPI	LE	7
;R07		 if	ATX_Low_AT_High_In_GPI	GE	0
;R07Power_Type_Judge_In_GPI_7_0 = Power_Type_Judge_In_GPI_7_0 or (01h shl ATX_Low_AT_High_In_GPI)
;R07		 endif;	ATX_Low_AT_High_In_GPI	GE	0
;R07		endif;	ATX_Low_AT_High_In_GPI	LE	7
;R07		if	ATX_Low_AT_High_In_GPI	LE	15
;R07		 if	ATX_Low_AT_High_In_GPI	GE	8
;R07Power_Type_Judge_In_GPI_15_8 = Power_Type_Judge_In_GPI_15_8 or (01h shl (ATX_Low_AT_High_In_GPI-8))
;R07		 endif;	ATX_Low_AT_High_In_GPI	GE	8
;R07		endif;	ATX_Low_AT_High_In_GPI	LE	15
;R07		if	ATX_Low_AT_High_In_GPI	LE	21
;R07		 if	ATX_Low_AT_High_In_GPI	GE	16
;R07Power_Type_Judge_In_GPI_21_16 = Power_Type_Judge_In_GPI_21_16 or (01h shl (ATX_Low_AT_High_In_GPI-16))
;R07		 endif;	ATX_Low_AT_High_In_GPI	GE	16
;R07		endif;	ATX_Low_AT_High_In_GPI	LE	21
;R07	  endif;ATX_Low_AT_High_In_GPI
;R07
;R07		;***************************************;
;R07		;  ATX => CMOS Protect, AT => Skip	;
;R07		;***************************************;
;R07	  if	Power_Type_Judge_In_GPI_7_0	NE	00h
;R07		mov	dx, ACPI_Port + 48h
;R07		in	al, dx
;R07		test	al, Power_Type_Judge_In_GPI_7_0
;R07	  endif;Power_Type_Judge_In_GPI_7_0	NE	00h
;R07	  if	Power_Type_Judge_In_GPI_15_8	NE	00h
;R07		mov	dx, ACPI_Port + 49h
;R07		in	al, dx
;R07		test	al, Power_Type_Judge_In_GPI_15_8
;R07	  endif;Power_Type_Judge_In_GPI_15_8	NE	00h
;R07	  if	Power_Type_Judge_In_GPI_21_16	NE	00h
;R07		mov	dx, ACPI_Port + 4Ah
;R07		in	al, dx
;R07		test	al, Power_Type_Judge_In_GPI_21_16
;R07	  endif;Power_Type_Judge_In_GPI_21_16	NE	00h
;R07
;R07	  ifdef	ATX_High_AT_Low_In_GPI		; If ATX power ?
;R07		jz	short @F		; No,jmp!
;R07	  endif;	ATX_High_AT_Low_In_GPI		; (1:ATX, 0:AT)
;R07	  ifdef	ATX_Low_AT_High_In_GPI		; If ATX power ?
;R07		jnz	short @F		; No,jmp!
;R07	  endif;	ATX_Low_AT_High_In_GPI		; (0:ATX, 1:AT)
;R07	  ifndef	ATX_High_AT_Low_In_GPI
;R07	  ifndef	ATX_Low_AT_High_In_GPI
;R07		mov	dx, ACPI_Port + 05h	; Doing a Sequence let
;R07		mov	al, 01h			; AT Power to work properly
;R07		out	dx, al			; in CMOS Protection Mode.
;R07		mov	al, 11h			;
;R07		out	dx, al			;
;R07		mov	al, 10h			;
;R07		out	dx, al			;
;R07	  endif;	ATX_Low_AT_High_In_GPI
;R07	  endif;	ATX_High_AT_Low_In_GPI
;R07    endif;	Always_ATX_Power
;R07
;R07    ifdef	Detect_ATX_Power_By_CMOS_Bank2
;R07		mov	al, 90h			;
;R07		out	72h, al			;
;R07		mov	al, 55h			;
;R07		out	73h, al			;
;R07		mov	al, 90h			;
;R07		out	72h, al			;
;R07		in	al, 73h			;
;R07		cmp	al, 55h			; Is ATX power ?
;R07		jnz	short @F		; No,jump
;R07    endif;	Detect_ATX_Power_By_CMOS_Bank2
;R07  ENDIF;	NO_ATX_Judgement
;R07;R01A endif;	Cover_VT596_E_Version
;R07;R01 - end
;R07		mov	cl, 05h			
;R07ifdef	VT596					
;R07		mov	bx, 28E3h		
;R07else;	VT596					
;R07		mov	bx, 20E3h		
;R07endif;	VT596					
;R07		call	Get_Set_PMIO		
;R10 - start
  IFDEF	DONT_RELEASE_E000_FOR_PCI		;R10A
    ifdef		VT586_ACPI

		Post_Func_Call	SMI_Soft_Off
		
    endif;		VT586_ACPI			
  ENDIF;DONT_RELEASE_E000_FOR_PCI		;R10A
;R10 - end
ifdef	APC_POWER_SWITCH_SUPPORT		
						
		extrn	APC_POWER_OFF:Near	
		call	APC_POWER_OFF		
						
endif;	APC_POWER_SWITCH_SUPPORT		
;R10 ;R07@@:
;R10 ;R07B - start
;R10 ifdef	ACPI_Support
;R10 ifdef	S4_SUPPORT
;R10 		mov	cl, 05h			
;R10 ifdef	VT596					
;R10 		mov	bx, 28E3h		
;R10 else;	VT596					
;R10 		mov	bx, 20E3h		
;R10 endif;	VT596					
;R10 		call	Get_Set_PMIO		
;R10 endif;	S4_SUPPORT
;R10 endif;	ACPI_Support
;R10 ;R07B - end
		sti				;R05
		jmp	short $			;R05

		ret
APM_16_PowerOff	Endp

;R07;[]========================================================================[]
;R07; RTC_Alarm_Resume:
;R07;		Power On ATX or Resume by RTC Alarm.
;R07;
;R07;Input:		AL = 0	Turn Off RTC function.
;R07;		   = 1	Turn On RTC function.
;R07;Output:
;R07;[]========================================================================[]
;R07		ASSUME	DS:PM_RAM
;R07;		Public	RTC_Alarm_Resume
;R07RTC_Alarm_Resume	Proc	Far
;R07		pusha
;R07		mov	bh,al			; bit 1 = 0 : OFF
;R07						;	  1 : ON
;R07		pusha
;R07ifdef	Record_PWRON_Status
;R07		mov	al,RdRsmSts_CMOS
;R07		OUT	70h,al
;R07		jcxz	short $+2
;R07		IN	AL,71h
;R07		jcxz	short $+2
;R07		test	al,RdRsmSts_CMOS_Bits
;R07		jnz	Dont_Record_PWRON_Status	; 00 : Set Auto
;R07							; xx : not Set Auto
;R07		mov	al,RdRsmSts_CMOS
;R07		OUT	70h,al
;R07		jcxz	short $+2
;R07		IN	AL,71h
;R07		jcxz	short $+2
;R07		or	al,(RdRsmSts_CMOS_Bits AND (RdRsmSts_CMOS_Bits SHR 1))
;R07		OUT	71h,al
;R07		jcxz	short $+2
;R07Dont_Record_PWRON_Status:
;R07endif;	Record_PWRON_Status
;R07;R02		mov	cl, 27h
;R07		mov	bl,02h
;R07		test	PM_RAM:[ALARM_RESUME], 08h
;R07		jz	short	@f
;R07	ifdef	VT596				;R02 - starts
;R07		mov	cl, 25h			; Enable RI Resume for VT596
;R07		call	Get_PMIO		;
;R07		or	al,01h			;
;R07		call	Set_PMIO		;
;R07	endif;	VT596				;R02 - ends
;R07		or	bl,04h
;R07@@:
;R07		mov	cl, 27h			;R02
;R07		call	Get_Set_PMIO_OR
;R07		popa
;R07
;R07		test	byte ptr PM_RAM:[ALARM_RESUME],01h ; If Setup set Enable ?
;R07		jz	No_RTC_On_Support ; No, Jmp!
;R07
;R07		;-------------------------------;
;R07		; Set RTC Alarm Status & Timer	;
;R07		;-------------------------------;
;R07		cmp	bh,1
;R07		jz	short Set_RTC_Alarm_On
;R07Set_RTC_Alarm_Off:
;R07ifdef	VT596					;R03 - starts
;R07		mov	bl,not 04h		; Set RTC Alarm Resume Off
;R07		mov	cl, 03h
;R07		call	Get_Set_PMIO_AND
;R07else;	VT596					;R03 - ends
;R07		mov	bl,not 01h		; Set RTC Alarm Resume Off
;R07		mov	cl, 27h
;R07		call	Get_Set_PMIO_AND
;R07endif;	VT596					;R03
;R07
;R07		mov	al,0Bh			; Restore RTC Alarm Ststus
;R07		call	Get_CMOS		; CMOS index 0Bh bit 5.
;R07		mov	ah,al			;
;R07		mov	al,byte ptr PM_RAM:[ALARM_RESUME]
;R07		and	al, 20h			; mask bit5
;R07		or	ah,al			;
;R07		mov	al,0Bh			;
;R07		call	Set_CMOS		;
;R07
;R07						; Restore STD Alarm Timer.
;R07		mov	ah,byte ptr PM_RAM:[Alarm_Timer_Second]
;R07		mov	al,01h			;
;R07		call	Set_Cmos		;
;R07		mov	ah,byte ptr PM_RAM:[Alarm_Timer_Minute]
;R07		mov	al,03h			;
;R07		call	Set_Cmos		;
;R07		mov	ah,byte ptr PM_RAM:[Alarm_Timer_Hour]
;R07		mov	al,05h			;
;R07		call	Set_Cmos		;
;R07
;R07		mov	ah,0			; Clear Extend Alarm Timer.
;R07		mov	al,7Fh			;
;R07		call	_Set_Cmos		;
;R07		mov	al,7Eh			;
;R07		call	_Set_Cmos		;
;R07		mov	al,7Dh			;
;R07		call	_Set_Cmos		;
;R07
;R07		jmp	No_RTC_On_Support	;
;R07
;R07Set_RTC_Alarm_On:
;R07ifdef	VT596					;R03 - starts
;R07		mov	bl, 04h			; Set RTC Alarm Resume Off
;R07		mov	cl, 03h
;R07		call	Get_Set_PMIO_OR
;R07else;	VT596					;R03 - ends
;R07		mov	bl, 01h			; Set RTC Alarm Resume On
;R07		mov	cl, 27h
;R07		call	Get_Set_PMIO_OR
;R07endif;	VT596					;R03
;R07
;R07		mov	al,0Bh			; Set RTC Alarm ON
;R07		call	Get_CMOS		; CMOS index 0Bh bit 5.
;R07		mov	ah,al			; (Alarm Status).
;R07		and	al, 20h			; mask bit5
;R07		or	byte ptr PM_RAM:[ALARM_RESUME],al
;R07		or	ah,20h			;
;R07		mov	al,0Bh			;
;R07		call	Set_CMOS		;
;R07
;R07		mov	al,05h			; Save STD RTC Alarm Timer
;R07		call	Get_Cmos		; Setting.
;R07		mov	byte ptr PM_RAM:[Alarm_Timer_Hour],al
;R07		mov	al,03h			;
;R07		call	Get_Cmos		;
;R07		mov	byte ptr PM_RAM:[Alarm_Timer_Minute],al
;R07		mov	al,01h			;
;R07		call	Get_Cmos		;
;R07		mov	byte ptr PM_RAM:[Alarm_Timer_Second],al
;R07
;R07		mov	ah,0			; Clear Extend Alarm Timer.
;R07		mov	al,7Fh			;
;R07		call	_Set_Cmos		;
;R07		mov	al,7Eh			;
;R07		call	_Set_Cmos		;
;R07
;R07		mov	bl,0			; Clear Flag
;R07
;R07		mov	al,4Fh			; Set Hour Alarm Timer.
;R07		call	Get_Cmos		;
;R07		add	bl,al			; Tset if set zero.
;R07		call	Hex_2_BCD		;
;R07		mov	al,05h			;
;R07		call	Set_Cmos		;
;R07
;R07		mov	al,4Eh			; Set Minute Alarm Timer.
;R07		call	Get_Cmos		;
;R07		add	bl,al			; Tset if set zero.
;R07		call	Hex_2_BCD		;
;R07		mov	al,03h			;
;R07		call	Set_Cmos		;
;R07
;R07		mov	al,4Dh			; Set Second Alarm Timer.
;R07		call	Get_Cmos		;
;R07		add	bl,al			; Tset if set zero.
;R07		call	Hex_2_BCD		;
;R07		mov	al,01h			;
;R07		call	Set_Cmos		;
;R07
;R07		mov	al,5Dh			; Set Date Alarm Timer.
;R07		call	Get_Cmos		;
;R07		cmp	bl,0			; If set 00:00:00 ?
;R07		jnz	short @f		; No,jmp
;R07		dec	al			; Yes => Date = Date - 1.
;R07@@:						;
;R07		call	Hex_2_BCD		;
;R07		mov	al,7Dh			;
;R07		call	Set_Cmos		;
;R07
;R07No_RTC_On_Support:
;R07ifdef	SANLI_Keyboard_Special
;R07		push	ds
;R07		mov	ax,40h
;R07		mov	ds,ax
;R07		and	byte ptr ds:[17h],not 70h
;R07		extrn	UPDATE_LED:NEAR		
;R07		call	UPDATE_LED		
;R07		xor	cx,cx
;R07		loop	short $
;R07		pop	ds
;R07endif;	SANLI_Keyboard_Special
;R07		popa
;R07		ret
;R07RTC_Alarm_Resume	Endp
;R07
;R07;R06Hex_2_BCD:
;R07;R06		mov	ah,al
;R07;R06		extrn	Hex_To_BCD:Near
;R07;R06		call	Hex_To_BCD
;R07;R06		ret
;R07;R06 - starts
;R07;[]========================================================================[]
;R07;Function :	Convert one byte Hex number to BCD
;R07;
;R07;Input	:	AL in HEX
;R07;
;R07;Output	:	AH in BCD
;R07;
;R07;Destory :	AL
;R07;[]========================================================================[]
;R07Hex_2_BCD:
;R07		push	cx
;R07		xor	ah,ah
;R07		mov	cl,10
;R07		idiv	cl
;R07		mov	cl,4
;R07		shl	al,cl
;R07		or	ah,al
;R07		pop	cx
;R07		ret
;R07;R06 - ends
;R07_Set_Cmos:
;R07		call	Set_Cmos
;R07		xchg	al,ah
;R07		ret

endif	;PM_SUPPORT

;---------------------------------------------------------------------------

FCODE		ENDS
		END
