;	[]===========================================================[]
;
;	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
;----------------------------------------------------------------------------
;R69	04/28/99 RAX	Addded switch 'RI_AlWAYS_Wakeup_SUSPEND'.
;R65A	04/27/99 RAX	Added switch to enable PME wake-up suspend always, and
;			fixed PME didn't control.
;R68	04/26/99 RAX	Fixed 'HDD_PWRDOWN_IN_SUSPEND' funtion not working and
;			add switch to remove HDD power down in suspend fuction
;			control item.
;R30A	04/23/99 RIC	Fix that "WAKE_LAN_BY_LID"&"LID_Triger_By_Rising_Edge"
;			definition fail in using 3Com LAN on 596A chip.
;			And add "LID_ACTIVE_HIGH" definition.
;R67	04/22/99 RIC	Fix that NT2000(Build-in 1982-2015) can't be installed.
;			Because CMOS 7fh is ACPI Century Field not Year Alarm!
;R66A	04/16/99 RIC	Fixed that "IOTRAP_SUPPORT" definition cause system
;			unstable.
;R66	04/12/99 RIC	Add "USB_MOUSE_SUPPORT" definition.
;R65	03/26/99 RAX	Added "PME_SUPPORT" define to support PME wakeup and
;			power on even ACPI mode and fixed coding mistake.
;R64	03/26/99 RIC	Save CMOS Index Port in SMI Hander.
;R49C	03/24/99 ADS	Fixed s4 resume hang in post 61h with SDRAM 64M bytes. 
;R63	03/22/99 RAX	Added define for that if customer request PM function
;			working just only APM hooked.
;R62	03/19/99 RAX	Fixed PM didn't work on BIOS 6.00.
;R49B	03/17/99 ADS	Fixed s4 resume hanged in VGA BIOS.
;R61	03/11/99 ADS	Add "WAKE_LAN_BY_GPI" function to support PCI2.2 
;			specification.
;			NOTE: you must defined "WAKE_LAN_BY_LID" before
;			     "WAKE_LAN_BY_GPI".  	
;R52B	03/08/99 RIC	Fix the R52A code was still in-completely.
;R32A	02/08/99 RIC	Fix that Modem Ring Resume Setting to Disable fail
;			in "Move_F000_PMU_INIT_To_E000" define.
;R60	02/01/99 RAX	Modify code for not use hard coding.
;R59	02/01/99 ADS	Added "Chkwakeup_source" hook to resume from SMI 
;			function(ext: power buttom,extsmi etc...)for WIN98 
;			OSR1.
;R58	02/01/99 ADS	Patch WIN98 OSR1 enable "scheduled task" will clear all
;			resume event (ex:like keyboard mouse etc..)
;R57	01/30/99 PAL	Added "ADM9240_CPUFAN_CNTL_IN_SUSPEND" option 
;R56	01/27/99 RAY	Support LCD_CRT_OPTION & NEW_SUPERVGA_KERNEL
;R52A	01/21/99 RIC	Fix the R52 code was still in-completely.
;R55	01/20/99 GAR	Add special for TYAN
;R54	01/20/99 RIC	Fix that VGA Active of PM Setup set ON cause system
;			to hang in Win98(ACPI mode)
;R53	01/20/99 RIC	Fix that Power Fail function abnormally when reset in
;			Suspend or S1.
;R52	01/19/99 ADS	Add VT686 PM event VGA reg. 
;R51	01/14/99 ADS	Add "PM_Beep_Speaker" function to support into suspend
;			& resume speaker beep. 
;R49A	01/13/99 ADS	Fixed sometime cause s4 resume hanged.
;R50	01/12/99 RIC	Add "Blink_Suspend_LED_In_GPO0" definition.
;R49	01/11/99 ADS	Added Suspend to HDD function.
;R48	01/05/99 GAR	If define POWER_LED_SELECTION, POWER_LED_USE will
;			be defined
;R47	01/05/99 RIC	Add 50h func SMI call in SMI_Soft_Off routine for
;			specail programing of ACPI wake up .
;R46	01/04/99 GAR	Fix bug. If PS2 mouse doesn't exist and restart to DOS
;			in APCI mode, the keyboard will be lock
;R45	12/31/98 ADS	Add "APC_Power_LED_ITEM" define for customer request. 
;R31A	12/31/98 GAR	Fix bug.The mouse power on will not effect if R31
;R44	12/29/98 ADS	Fixed s4 can't show progress view.
;R42B	12/28/98 GAR	Fix power led compile bug.
;R43	12/28/98 PAL	Added "FAN3_CNTL_USE_PWM" to control fan in suspend
;R42A	12/24/98 GAR	Move fan code of ITE8693 to ITE8693.SSR
;R42	12/21/98 GAR	Add led and fan functions for ITE8693/8673 
;R21A	12/16/98 RIC	Add E000_Read_GPI_Pin sub-routine.
;R41	12/08/98 PAL	Added W83782D & W83783S CPUFAN control in suspend use
;			"W83782D_CPUFAN_CNTL_IN_SUSPEND" & "CPU1_FAN_USE_PWM"
;R05A	12/02/98 RIC	Fix that IRQ Wake Event of ACPI don't according to
;			BIOS Setup.
;R40	11/30/98 BAR	Update ESCD DMI use SMM mode.
;R39	11/26/98 RIC	Modify the Throttling Reg to 24bit from 32bit
;			for HCT test fail in Throttling Duty Cycle
;R38A	11/16/98 RIC	Fix that Trend Anti-Virus replace F0000-F4800 area.
;			So move Get_Set_Ct_OR, Get_Set_Ct_AND to chiprun.
;R38	11/13/98 PAL	Move E000 shadow control code from CHIPPOST.ASM
;			to avoid Trend code destroy and added Wakeup_VGA option
;R37	11/11/98 ADS	Added suspend to HDD function.
;R36	11/10/98 RIC	Fix that APM1.2 of HCT8.0 test fail in Disabled Timer.
;R35	11/04/98 RIC	Add "Power_Type_Selectable" definition.
;R34	11/01/98 RIC	If Onchip USB Disable, don't enable Legacy USB SMI.
;			Otherwise some mainboards will sometimes have garbage
;			SMI.
;R33	11/01/98 RIC	Add "Disable_EXTSMI_When_PowerOff" define.
;R32	10/30/98 RIC	Fix that Modem Ring Resume Setting to Disable fail.
;R31	10/29/98 GAR	Add to disable and enable keybroad interface command
;			to solve that when windows restart to DOS, keyborad
;			doesn't work.
;R30	10/26/98 RIC	Fix that "WAKE_LAN_BY_LID" fail in using 3Com LAN
;			Card.
;R29	10/20/98 RIC	Turn on/off HDD standby timer while ACPI function on/off
;R28	10/19/98 RIC	Save PCI configuration space I/O port.
;R25B	10/08/98 RIC	Fix that "Clear_PME_Before_Off" define still hang
;			in some mainboards.
;R27	10/07/98 RIC	Fix that RTC alarm resume cause system to hang in
;			Windows NT.
;R25A	10/06/98 RIC	Fix that "Clear_PME_Before_Off" define sometimes hang.
;R22A	10/06/98 GAR	Add "Use_4_Frame_PS2_Mouse" for 4 frame PS2 mouse
;R23A	10/06/98 RIC	Remove R23 code.
;R26	09/23/98 RIC	Change ACPI IRQ assign algorithm to Auto-assigned.
;			If you want to use old algorithm, please define:
;			1."No_ACPI_IRQ_Auto_Assign" for disabled new algorithm.
;			2."ACPI_IRQ_Selectable" for enabled old algorithm.
;R25	09/22/98 RIC	Add "Clear_PME_Before_Off" define to support WOL
;			in suspend.
;R24	09/22/98 RIC	Fix that WOL hang in POST 0Dh in some mainboard
;			(with 596 SouthBridge)
;R23	09/21/98 RIC	Add "Cover_Garbage_IRQ12" define.
;R09A	09/16/98 ADS	Fixed error.
;R22	09/16/98 GAR	Add PS2 mouse reset command to IO_SOFT_OFF.
;			This can enable PS2 mouse, if you select mouse power
;			on.
;R07A	09/11/98 RIC	Add "Disable_EXTSMI_Button" define to fix that some 
;			mainboard design error in EXTSMI.
;			(System will Auto-PowerOn when PowerOff by PWRBTN)
;R16B	09/10/98 RIC	Fix that R16A code cause system sometimes auto PowerOn
;			when Power Button press in Instant-Off condition.
;R20B	09/09/98 RIC	Fix that R20 code cause EXTSMI Button abnormal.
;R21	09/01/98 RIC	Add E000_Control_GPO_Pin routine.
;R20A	08/31/98 ADS	Fixed R20 error.
;R20	08/27/98 RIC	Add SMI_Sof_Off routine.
;			and move APM16_PowerOff(PMU) code to SMI_Sof_Off.
;R18A	08/20/98 RIC	Fixed that R18 code mistake in "Always_Enable_LID".
;R19	08/18/98 RIC	Fixed that Power Buttom still can entry suspend.
;R18	08/12/98 RIC	Add "Always_Enable_LID" 
;			    "WAKE_LAN_BY_LID"	definition.
;R17    08/10/98 RIC    Fixed that system USB garbage status cause SMI routine
;			fail when USB set to Disabled.
;R16A	08/05/98 RIC	Fixed that abnormal Power Button function atill cause
;			RTC Alarm resume fail.
;R16	07/29/98 RIC	Fixed that Power Button function is abnormally in 596
;			 chip.
;			Reason:
;				596 chip ACPI I/O Reg 2C[2] and 586B are
;				in reverse design.
;R15	07/28/98 RIC	Let USB Keyboard can wakeup from suspend when USB
;			IRQ don't set to wakeup event.
;R14	07/24/98 RIC	Add "Wake_On_GPI_Support" define.
;R13	07/20/98 RIC	Add "LID_SUPPORT" define
;R12	07/20/98 RIC	Fixed that SMBus Host Status cause system not to entry
;			Suspend Mode.
;R11	07/15/98 RIC	Remove no use code.
;R10	07/09/98 RIC	Add "Wake_On_EXTSMI0_Support" define.
;R09	07/07/98 RIC	Fixed that Green function is abnormal when Doze Time
;			set enabled and Suspend Timer set to Disabled
;R08	07/01/98 RIC	Fixed that Thermal function work abnormally.
;			and Add "No_Thermal_Warning_Beep" for Thermal_With_SMI
;R07	06/29/98 RIC	Fixed that system Power Buttom fail in new VT596 chip.
;			Add "Cover_VT596_E_Version" define.
;R06	06/29/98 RIC	Fixed that system hang at POST 0Ah in new VT596 chip.
;R05	06/15/98 RIC	Fixed that system(with VT596,ACPI) can't wake-up from
;			'S1' mode in Win98.
;R04	06/15/98 RIC	Fixed that PM Timeout and COM Mouse WakeUp abnormally
;			in VT596.
;R03	06/12/98 RIC	Add "No_PowerBottom_Debounce_In_Memphis" define.
;R02	06/15/98 RIC	Fix code mistake.
;R01A	05/19/98 RIC	Fixed that R01 code is not successful and modify 
;			"OverHot_Use_Thermal_Pin" define to "Thermal_Enable"
;R01	05/18/98 ADS	Added "Suspend_When_High_In_GPI" &"OverHot_Use_Thermal_Pin"
;			define.			
;R00	05/13/98 RIC	Initialization.

.386p
		PAGE	56,132
		TITLE	CHIPSET  -- 686 EISA/ISA ROM/BIOS

		include BIOS.CFG
		include BSETUP.INC

		include COMMON.MAC
		include COMMON.EQU
		include POST.MAC
		include CMOS.EQU
		INCLUDE CHIPSET.EQU
_SMI_ENTRY	EQU	0d0h
SMI_IDLE	EQU	0d1h
SMI_SUS 	EQU	0d3h

ifdef	APM_IN_SMBASE
	COMPILE_FOR_APMBIOS	=	1
		include	APM.INC
endif	;APM_IN_SMBASE
;R40 - start
ifdef	Flash_IN_SMBASE
	COMPILE_FOR_APMBIOS	=	1
		include	SMIFlash.INC
endif	;Flash_IN_SMBASE
;R40 - end

		extrn	Get_Cmos:near
		extrn	Set_Cmos:Near
ifndef	CRT_Control_Not_In_F000			
ifndef	CRT_Control_Not_In_APM			
		extrn	Enable_CRT:near
		extrn	Disable_CRT:near
endif	;CRT_Control_Not_In_APM			
endif	;CRT_Control_Not_In_F000		
		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
;R62 start
		extrn	IRQ4_Event_Item:near
		extrn	IRQ5_Event_Item:near
		extrn	IRQ6_Event_Item:near
		extrn	IRQ7_Event_Item:near
		extrn	IRQ8_Event_Item:near
		extrn	IRQ9_Event_Item:near
		extrn	IRQ10_Event_Item:near
		extrn	IRQ11_Event_Item:near
		extrn	IRQ12_Event_Item:near
		extrn	IRQ13_Event_Item:near
		extrn	IRQ14_Event_Item:near
		extrn	IRQ15_Event_Item:near
;R62 end
		extrn	Get_PMU:near
		extrn	Get_Set_PMU:near
		extrn	Set_PMU:near
		extrn	Get_Set_PMU_OR:near		
;R38		extrn	Get_Set_PMU_AND:near		
		extrn	Get_Set_Ct_AND:near		;R38A
		extrn	Get_Set_PMU_AND:near		;R38A

		extrn	GetItem_Value:Near
		extrn	Get_PM_RAM_Seg:near
		extrn	Open_PM_RAM:near
		extrn	Close_PM_RAM:near

		extrn	Evt_HDD_Item:near
		extrn	Evt_DMA_Item:near
		extrn	Evt_INTR_Item:near
		extrn	Evt_LPT_COM_Item:near
		extrn	M_Evt_VGA_Item:near
ifdef	Have_Conserve_Item				
		extrn	Conserve_Mode_Item:near
endif;	Have_Conserve_Item				
		extrn	Alarm_Item:near			
;R20		extrn	RTC_Alarm_Resume:Far		
		extrn	PWRBTN_OVRD_Item:Near		
		extrn	Ring_Item:Near			
ifdef	ABIT_Have_Suspend_Fan_Item			
		extrn	Fan_Item:Near			
endif;	ABIT_Have_Suspend_Fan_Item			
ifndef	New_Superio_Led_Function		;R42
ifdef	PM_LED_USE_GPIO					
		extrn	Set_PM_LED:near			
endif;	PM_LED_USE_GPIO					
ifdef	LED_Blinking_at_PM				
		extrn	Set_PM_LED_Blinking:near	
endif;	LED_Blinking_at_PM				
;R48 - start
ifdef Power_Led_Selection
POWER_LED_USE		EQU	1
endif ;Power_Led_Selection
;R48 - end
;R42 - start
ifdef	POWER_LED_USE			  
		extrn	Set_power_led:near	
endif;	POWER_LED_USE			  	
else	;New_Superio_Led_Function
ifdef	LED_Blinking_at_PM				
		extrn	Set_power_led:near	
endif;	LED_Blinking_at_PM				
endif	;New_Superio_Led_Function

;R42Aifdef	Superio_support_Fan
;R42A	extrn	Fan_Power_On:Near
;R42A	extrn	Fan_Power_Off:Near
;R42Aendif	;Superio_support_Fan
;R42 - end
ifdef	HDD_PWRDOWN_IN_SUSPEND
ifndef	HDD_always_PWRDOWN_IN_SUSPEND		;R68
		extrn	HDD_Power_Item:near	   	
endif	;HDD_always_PWRDOWN_IN_SUSPEND		;R68
endif;	HDD_PWRDOWN_IN_SUSPEND			   	
ifdef	Break_Suspend_In_Mouse_CMOS	       		
                extrn   Mouse_Irq_Item:near	   	
		extrn	CONFIG_TABLE:near	   	
		extrn	system1_byte:near	   	
endif;	Break_Suspend_In_Mouse_CMOS			

		extrn	Post_call_proc:near
		extrn	F000_call_proc:near
		extrn	F000_GetItem_Value:near
		extrn	Get_PMIO:near			
		extrn	Set_PMIO:near			
		extrn	Get_Set_PMIO:near		
		extrn	Get_Set_PMIO_OR:near		
		extrn	Get_Set_PMIO_AND:near		
		extrn	Set_PMIO_Clear:near		

		extrn	Issue_SW_SMI:near		

		extrn	F000_Func_End:near
		extrn	F000_Vect:near
;R42ifdef	POWER_LED_USE					
;R42		extrn	Set_power_led:near		
;R42endif;	POWER_LED_USE					
ifdef	ACPI_Support
		extrn	ACPI_option_Item:near
		extrn	fPROC_Set_HDD_Standby_Timer:far	;R29
;R26  IFNDEF	No_ACPI_IRQ_Selectable
  IFDEF	ACPI_IRQ_Selectable			;R26
		extrn	Assign_ACPI_IRQ_Item:near	
;R26  ENDIF;	No_ACPI_IRQ_Selectable
  ENDIF;ACPI_IRQ_Selectable			;R26
ifdef	S4_SUPPORT
		extrn	Do_S4_Suspend:far
		extrn	E_S4_Resume:far
		extrn	WakeUP_VGA:far			;R38
		extrn	REAL_IDT_LOC:near		
endif;	S4_SUPPORT

endif	;ACPI_Support
;R65A start
ifdef	PME_SUPPORT
		extrn	WO_Item:near
endif	;PME_SUPPORT
;R65A end
;R37 - starts
ifdef	Notebook_Power_Management      
		extrn	Suspend_0V:near
		extrn	Resume_0V:near 
		extrn	Suspend_Option_Item:near	;R49
		extrn	OS_TYPE_ITEM:near		;R49
endif	;Notebook_Power_Management     
;R37 - ends
IFDEF		USB_SUPPORT
ifdef	USB_MOUSE_SUPPORT			;R66
		extrn	USB_Mouse_Item:near	;R66
endif	;USB_MOUSE_SUPPORT			;R66
		extrn	ONBD_USB_Item:near	;R17
		extrn	Usb_Legacy_Item:near
COMPILE_FOR_USBBIOS	=	1
		include	USBBIOS.ASM
ENDIF		;USB_SUPPORT

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
;R37 - starts
ifdef	Notebook_Power_Management
SM_RAM		SEGMENT USE16 AT 0
		INCLUDE SM_RAM.INC
SM_RAM		ENDS
;R49 - starts
ZV_Temp_Stack	SEGMENT USE16 AT 0
		org	1000h
VIDEO_BUFFER	LABEL	WORD
		org	2000h
VMode_BUFFER	LABEL	WORD
		org	0FFF0h
ZV_STACK_TOP	LABEL	DWORD
ZV_Temp_Stack	ENDS
;R49 - ends
endif;	Notebook_Power_Management
;R37 - ends

;R11 SMI_STRUCT	STRUC
;R11 		dd	?
;R11 _SpSave		dw	1 dup (?)
;R11 _EspSave	dd	1 dup (?)
;R11 _EaxSave	dd	1 dup (?)
;R11 _EbxSave	dd	1 dup (?)
;R11 _Cr2Save	dd	1 dup (?)
;R11 _Cr3Save	dd	1 dup (?)
;R11 _Gdt		dq	1 dup (0)
;R11 		dw	1 dup (?)
;R11 		dw	1 dup (?)
;R11 		db	1 dup (?)
;R11 		db	1 dup (?)
;R11 		db	1 dup (?)
;R11 		db	1 dup (?)
;R11 		dw	1 dup (?)
;R11 		dw	1 dup (?)
;R11 		db	1 dup (?)
;R11 		db	1 dup (?)
;R11 		db	1 dup (?)
;R11 		db	1 dup (?)
;R11 _DsSave		dt	1 dup (?)
;R11 _EsSave		dt	1 dup (?)
;R11 _SsSave		dt	1 dup (?)
;R11 _FsSave		dt	1 dup (?)
;R11 _GsSave		dt	1 dup (?)
;R11 _LdtSave	dt	1 dup (?)
;R11 _TskSave	dt	1 dup (?)
;R11 _Dstemp		db	10 dup (?)
;R11 _GdtSave	df	1 dup (?)
;R11 _GdtNew		dw	1 dup (?)
;R11 		dd	1 dup (?)
;R11 _IdtSave	df	1 dup (?)
;R11 _RealModeIdt	dw	1 dup (?)
;R11 		dd	1 dup (?)
;R11 SMI_STRUCT	ENDS


;[]-----------------------------------------------------------------------[]
;  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

DGROUP		GROUP	FCODE
FCODE		SEGMENT USE16 PARA Public 'CODE'
		ASSUME	CS:DGROUP


;[]-------------------------------------------------------------------[]
;
; 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
;
;[]-------------------------------------------------------------------[]
;R38 - start
;[]==============================================================[]
; Disable_E000_ROM_Shadow : (POST 63h)
;	Disable E000 ROM Shadow (Direct Access to ISA)
; Input : None
; Output: None
; Save: all
;[]==============================================================[]
		public	Disable_E000_ROM_Shadow
Disable_E000_ROM_Shadow	proc	near

	;disable E0000 shadow RAM
		
		mov	cx,VT692 + 63h
		mov	bl,NOT 0c0H
		call	Get_Set_Ct_AND

	;disable onboard E0000 ROM
		mov	cx,VT586 + 43h
		mov	bl,NOT 30H
		call	Get_Set_Ct_AND

		ret
Disable_E000_ROM_Shadow	endp
;R38A ;[]==============================================================[]
;R38A ; Get_Set_Ct_AND(Get_Set_PCI_AND):
;R38A ;	AND a value in the chipset register.
;R38A ; Input  :	CX = Index register to change.
;R38A ;		bl = Value to change (AND)
;R38A ; Output :	None
;R38A ; Destory:	EAX, ECX, DX
;R38A ;
;R38A ;[]==============================================================[]
;R38A 		Public	Get_Set_Ct_AND, Get_Set_PMU_AND
;R38A Get_Set_Ct_AND	proc	near
;R38A Get_Set_PMU_AND:
;R38A 		extrn	Get_Ct:near
;R38A 		extrn	Set_Ct:near
;R38A 		call    Get_Ct
;R38A 		and     al, bl			;AND data
;R38A 		call    Set_Ct
;R38A 		ret
;R38A Get_Set_Ct_AND	endp

;[]==============================================================[]
;E000_Shadow_R:
;	Set video BIOS(E000-E800) shadow readonly
;Input : none
;Output: none
;[]==============================================================[]
		Public	E000_Shadow_R
E000_Shadow_R   proc    near
		extrn	GET_SET_CT:near
		mov     cx,VT692 + 63h
		mov	bx,803fh
		call    GET_SET_CT
		ret
E000_Shadow_R   endp

		Public	E000_64k_Shadow_R
E000_64k_Shadow_R   proc    near
		jmp	E000_Shadow_R
E000_64k_Shadow_R   endp
;R38 - end

;[]========================================================================[]
;Procedure:	Get_PM_IRQ
;
;Function :	Tell BIOS which IRQ is PMI using
;
;Input	  :	None
;
;Output   :	NC:
;			AL = 1	- PMI using IRQ 15
;			AL = 2	- PMI using NMI
;			AL = 3	- PMI using SMI
;		CF:
;			No IRQ or NMI or SMI is available
;
;Preserve :	All except AX & FLAG
;
;Note	  :	1. Stack available
;		2. called from PM_Init
;[]========================================================================[]
		Public	Get_PM_IRQ
Get_PM_IRQ	Proc	Near
		mov	al,03h		;always SMI for PENTIUM CPU
		clc
		ret
Get_PM_IRQ	Endp

;[]========================================================================[]
;Procedure:	Check_PM_Using_NMI
;
;Function :	To handle the NMI which is caused by a PMU
;
;Input	  :	None
;
;Output   :	None
;
;Saves	  :	Please save all registers
;
;[Note]   :	1. Called every time a NMI is occured
;		2. check to see if this SMI is issue by PMU
;
;		     if PMI ;  Serve the PMI then
;
;			       sti
;			       iret
;
;		     if not PMI : jump back to a external label(near)
;				  named "NMI_Original" & do nothing!
;
;		   So if your chip never use NMI, just "jmp NMI_Original"!
;
;[]========================================================================[]
		Public	Check_PM_Using_NMI
Check_PM_Using_NMI:
PM_Not_NMI:
		extrn	NMI_Original:near
		jmp	NMI_Original

;[]-------------------------------------------------------------------[]
;
; PPPPPPPP	 AA	  RRRRRRRR   TTTTTTTTTTT	       2222222
; PPPPPPPPP	AAAA	  RRRRRRRRR  TTTTTTTTTTT    ***       22222222
; PPP	 PPP   AAAAAA	  RRR	 RRR	 TTT	    ***      222  222
; PPPPPPPPP   AAA  AAA	  RRRRRRRRR	 TTT			 222
; PPPPPPPP   AAAAAAAAAA   RRRRRRRR	 TTT	    *** 	222
; PPP	    AAAAAAAAAAAA  RRR	RRR	 TTT	    ***        2222222
; PPP	   AAA	      AAA RRR	 RRR	 TTT		      22222222
;
;
;		Called during POST Only
;
;[]-------------------------------------------------------------------[]

;[]========================================================================[]
;Procedure:	Ct_Check_Green_VGA
;
;Function :	To tell BIOS kernel that if the VGA adaptor's V/H SYNC
;		signal should be turned off or not when video off.
;		This should refer to the setup setting.
;
;Input    :	None
;
;Output   :	ZF : don't turned off V/H SYNC
;		NZ : V/H SYNC can be turned off
;
;Note	  :	1. Some VGA adaptors use V/H SYNC signals for special
;		   purpose, e.g. TSENG LAB use them for DRAM refresh.
;		   Therefore, these signals must never be turn off
;		   at any time.
;		2. called from POST at POST 82
;[]========================================================================[]
			Public	Ct_Check_Green_VGA
Ct_Check_Green_VGA	Proc	Near
		pushad
		mov	si,offset VGA_Type_Item
		call	GetItem_Value
		or	al,al
		popad
		ret
Ct_Check_Green_VGA	Endp

;[]==============================================================[]
;Input: None
;Function :	To see if it is a SMI
;[]==============================================================[]
			Public	Ct_Check_SMI_Start
Ct_Check_SMI_Start	Proc	Near

		extrn	Not_SMI_Start:near
		jmp	Not_SMI_Start

Ct_Check_SMI_Start	Endp

;[]==============================================================[]
;Procedure:	PM_Option_Check
;
;Function :	Get PM option
;
;Input	  :	None
;
;Output   :	1. ZF  - User Defined!
;			 i.e. use CMOS value to prg PM chip
;
;		   NZ  - Use Pre-defined value to prg PM chip
;			 AL = PM option
;			    i.e. DISBLED
;				 MAX-POWER_SAVING
;				 MIN-POWERING-SAVING....
;			 SI = offset of auto-table
;			    i.e. MIN_PM_SAVING_TABLE
;				 MAX_PM_SAVING_TABLE
;				 PM_DISABLE_TABLE	   in file PFEATURE.ASM
;
;		2. CF  - Global Power Management should be disabled
;
;		   NC  - Global Power Management should be enabled
;
;Registers :	FLAGS, AX, SI - destroyed
;		Others	      - should be preserved
;[]==============================================================[]
		Public	PM_Option_Check
PM_Option_Check Proc	Near
		mov	si,offset cs:PM_Option_Item
		call	GetItem_Value
		mov	cl,al
		xor	ch,ch

		mov	si,offset cs:PM_Auto_Table
		shl	cx,1
		dec	cx
		add	si,cx
		mov	si,cs:[si]

PM_Option_Check_Exit:

		cmp	al,1			;PM disabled?
		je	short @F		;yes

	;if PM option is "user defined" then OEM routine should
	;check here for both items disabled

		or	al,al			;set/clear Zero Flag
		clc
		ret

	@@:
		or	al,al			;set/clear Zero Flag
ifdef Set_APM_According_PM_Setup
		stc				;indicate PM disable
else; Set_APM_According_PM_Setup
		clc				;indicate PM disable
endif; Set_APM_According_PM_Setup

		ret
PM_Option_Check Endp

;[]==================================================================[]
;Procedure:	Ct_Global_PM_Disable
;
;Function :	To disable all power management features
;
;Input	  :	None

;Output   :	None
;
;Registers:	all registers preserved
;
;[Note]   :	called from PM_INIT before PM_RAM is available
;[]==================================================================[]
			Public	Ct_Global_PM_Disable
Ct_Global_PM_Disable	Proc	Near
		pusha
ifdef	USB_SUPPORT				     
		POST_FUNC_CALL	Ct_Check_Usb_Disabled
		jnc	short @f		     
endif	;USB_SUPPORT				     
	@@:
		popa
		ret
Ct_Global_PM_Disable	Endp

;[]==================================================================[]
;Procedure:	Clear_PM_RAM
;
;Function :	Clear power management data area (PM_RAM segment)
;		This routine is used to clear extended BIOS data area
;		in order to provide a clean environment for power
;		management code
;
;Input	  :	ES : PM_RAM

;Output   :	None
;
;Registers:	all registers preserved except FLAGS
;
;[Note]   :	called from PM_INIT
;[]==================================================================[]
		Public	Clear_PM_RAM
Clear_PM_RAM	Proc	Near
		ASSUME	ES:PM_RAM

		pusha
		mov	di,offset PM_RAM:PM_RAM_START
		mov	cx,PM_RAM_LEN
		xor	ax,ax
		cld
		rep	stosb
		popa
		ret

Clear_PM_RAM	Endp

;[]========================================================================[]
;Procedure:	Ct_PMRAM_Use_SYSRAM
;
;Function :	To tell the BIOS kernel that if you are using the SYSRAM
;		for PM_RAM
;
;Input	  :	None
;
;Output   :	AL = Size of PM_RAM that you want to reserved from SYSRAM.
;		0=None, 1=1K, 2=2k  etc.
;
;Save	  :	All registers except AL & FLAGS
;
;Note	  :	1. called before PM_INIT (POST 79)
;		2. simply return AL=0 if PM_RAM is located at shadow RAM
;		   or SMRAM
;		4. stack available
;[]========================================================================[]
		Public	Ct_PMRAM_Use_SYSRAM
Ct_PMRAM_Use_SYSRAM	Proc	Near
		xor	al,al
		ret
Ct_PMRAM_Use_SYSRAM	Endp

;[]========================================================================[]
;Procedure:	Ct_Early_PM_Init
;
;Function :	Early PM chip initializations
;
;Input	  :	None
;
;Output   :	None
;
;Preserve :	All
;
;Note	  :	1. Call from POST 9
;		2. Stack available
;		3. You can initialize any PM function which is needed
;		   to be done earlier!
;[]========================================================================[]
		Public	Ct_Early_PM_Init
Ct_Early_PM_Init	Proc	Near
		Post_Func_Call E000_Ct_Early_PM_Init
		ret
Ct_Early_PM_Init	Endp

ifndef	New_Superio_Led_Function		;R42
ifdef	PM_LED_USE_GPIO				
F000_Set_PM_LED Proc	Far			
		call	Set_PM_LED		
		retf				
F000_Set_PM_LED Endp				
endif;	PM_LED_USE_GPIO				
ifdef	LED_Blinking_at_PM			
F000_Set_PM_LED_Blinking Proc	Far		
		call	Set_PM_LED_Blinking	
		retf				
F000_Set_PM_LED_Blinking Endp			
endif;	LED_Blinking_at_PM			
ifdef	POWER_LED_USE				
F000_Set_POWER_LED Proc	Far			
		call	Set_POWER_LED		
		retf				
F000_Set_POWER_LED Endp				
endif;	POWER_LED_USE				
;R42 - start
else	;New_Superio_Led_Function
ifdef	LED_Blinking_at_PM				
F000_LED_Flash	Proc	Far			
		call	Set_POWER_LED		
		retf				
F000_LED_Flash	Endp				
endif;	LED_Blinking_at_PM				
endif	;New_Superio_Led_Function

;R42Aifdef	Superio_Support_Fan
;R42AF000_Fan_Power_On Proc	Far
;R42A		call	Fan_Power_On
;R42A		retf
;R42AF000_Fan_Power_On Endp
;R42A
;R42AF000_Fan_Power_Off Proc	Far
;R42A		call	Fan_Power_Off
;R42A		retf
;R42AF000_Fan_Power_Off Endp
;R42Aendif;	Superio_Support_Fan
;R42 - end
;[]========================================================================[]
;Input	:	None
;Output	:	AL = 0 			 --> Currently MODEM Ring cannot 
;					     wake up system
;		AL = RING_WAKEUP_ENABLED --> Currently MODEM Ring can
;					     wake up system
;[]========================================================================[]
		Public	CT_RING_WAKEUP_STATUS
CT_RING_WAKEUP_STATUS	Proc	Near

		mov	cx, VT586_ACPI + 44h
		call	Get_PMU
		mov	bl,al
		mov	[WAKE_MODEM0],al

		mov	cx,VT586_ACPI + 45h
		call	Get_PMU
		mov	bh,al
		mov	[WAKE_MODEM1],al

		mov	cx, VT586_ACPI + 46h
		call	Get_PMU	
		or	bl,al

		mov	cx, VT586_ACPI + 47h
		call	Get_PMU	
		mov	bh,al

		mov	word ptr PM_RAM:[DEASSERT_STPCLK_IRQS],bx

		extrn	Modem_IRQ_Item:near
		mov	si, offset Modem_IRQ_Item
		call	GetItem_Value
		mov	word ptr [APM_Modem_IRQ], 0
		or	al, al
		jz	short @F

		mov	bx, 1
		mov	cl, al
		shl	bx, cl
		mov	word ptr [APM_Modem_IRQ], bx
		or	word ptr PM_RAM:[DEASSERT_STPCLK_IRQS],bx
		or	byte ptr [WAKE_MODEM0],bl		 
		or	byte ptr [WAKE_MODEM1],bh		 

		test	ax,bx
		mov	al, RING_WAKEUP_ENABLED		;current ON
		jnz	short @F
		xor	al, al				;current OFF
	@@:
		ret

CT_RING_WAKEUP_STATUS	Endp

;[]========================================================================[]
;Input	:	None
;Output	:	AL = 0 			--> PM Timer is currently disabled
;		AL = PMU_TIMER_ENABLED	--> PM Timer is currently Enabled
;[]========================================================================[]
		Public	CT_PMU_TIMER_STATUS
CT_PMU_TIMER_STATUS	Proc	Near

		mov	al, PMU_TIMER_ENABLED		;assume enabled 

		mov	cx,VT586_ACPI+50h
		call	Get_PMU
		test	al,80h
		jnz	short @F			;No
		xor	al, al				;all mode disable
	@@:
		ret

CT_PMU_TIMER_STATUS	Endp

;[]========================================================================[]
;Procedure:	Ct_PM_Final_Init
;
;Function :	PM initialization before boot
;
;Input    :	None
;
;Output   :	None
;
;Registers:	Please preserve all registers
;
;Note	  :	1. Call from POST 82
;		2. Stack available
;[]========================================================================[]
		Public	Ct_PM_Final_Init
Ct_PM_Final_Init	Proc	Near

ifdef	Move_F000_PMU_INIT_To_E000				
		Post_Func_Call E000_Ct_PM_Final_Init
else;	Move_F000_PMU_INIT_To_E000				

ifdef	Have_Conserve_Item
		mov	si,offset Conserve_Mode_Item
		call	GetItem_Value
		mov	bl,al
		shl	bl,4
else;	Have_Conserve_Item				
		xor	bl,bl
endif;	Have_Conserve_Item				
		mov	cx,VT586_ACPI + 53h
		call	Get_Set_PMU_OR

		mov	cl, 30h
		call	Set_PMIO_Clear

;R67		mov	ah,0			; Clear Y-M-D Alarm Setting.

		mov	al,32h			;R67 Set ACPI Century Field
		call	Get_Cmos		;R67  to the year of Now !
		mov	ah,al			;R67
		mov	al,7fh			;
		call	Set_Cmos		;

		xchg	al,ah			; Clear M-D Alarm Setting.
		mov	al,7eh			;
		call	Set_Cmos		;
		xchg	al,ah			;
		mov	al,7dh			;
		call	Set_Cmos		;
ifdef	Disable_ExtSMI_SW_In_POST
 		mov	cl, 01h			; Clear Power Buttom Status
 		call	Get_PMIO		;
 		call	Set_PMIO		;
 		Post_Func_call	Delay_About_1_Second
 		mov	cl, 01h			;
 		call	Get_PMIO		;
 		call	Set_PMIO		;
 
 		mov	cl, 03h			; Enable Power Buttom
 		mov	bl, 01h			;
 		call	Get_Set_PMIO_OR		;
endif;	Disable_ExtSMI_SW_In_POST

;R01A - starts
ifdef	VT596
  IFDEF	Thermal_Enable
                mov     cx,VT586_ACPI + 4ch
;R08		mov     bl,70h
;R08		call    E000_Get_Set_PMU_OR
		mov     bl,0D0h			;R08
		call    Get_Set_PMU_OR		;R08
    ifndef	Thermal_Active_By_High		;R08
                mov     cl,2ch			;R08
                mov     bl,40h			;R08
                call    Get_Set_PMIO_OR		;R08
    endif;	Thermal_Active_By_High		;R08
  ENDIF;Thermal_Enable			
endif;	VT596
;R01A - ends

endif;	Move_F000_PMU_INIT_To_E000				

		ret
Ct_PM_Final_Init	Endp

;[]========================================================================[]
;Procedure:	Ct_PM_Init
;
;Function :	Special PM init which the standard code can't do
;
;Input	  :	DS = DGROUP
;		ES = PM_RAM
;
;Output   :	None
;
;Note	  :	1. Call from POST 79S (PM initialization)
;		2. Stack available
;		3. Don't destroy any SEGMENT registers!
;[]========================================================================[]
		ASSUME	ES:PM_RAM
		ASSUME	DS:DGROUP
		Public	Ct_PM_Init
Ct_PM_Init	Proc	Near

ifdef	Move_F000_PMU_INIT_To_E000				
		Post_Func_Call E000_Ct_Pm_Init
else;	Move_F000_PMU_INIT_To_E000				
		pusha
		push	ds
		push	es
		pop	ds

;--------------- Set 32bit Timer for ACPI ------------------------
;R39		mov	cx, VT586_ACPI + 41h
;R39		mov	bl, 08h			
;R39		call	Get_Set_PMU_OR		

		mov	si, offset DGROUP:Alarm_Item
		call	GetItem_Value		;get setup setting
		mov	bl,al
		mov	si, offset DGROUP:PWRBTN_OVRD_Item
		call	GetItem_Value		;get setup setting
		shl	al,1
		or	bl,al
		mov	PM_RAM:[ALARM_RESUME], bl

		mov	si, offset DGROUP:Ring_Item	; Set Ring Resume
		call	GetItem_Value		; By Setup Item
		mov	bh,al				;R32
		shl	al,3
		or	PM_RAM:[ALARM_RESUME], al
ifndef	VT596						;R32
		mov	cl, 27h
		mov	bl,not 04h
		call	Get_Set_PMIO_AND
else;	VT596						;R32
		mov	cl, 25h				;R32
		mov	bl,not 01h			;R32
		call	Get_Set_PMIO			;R32
endif;	VT596						;R32
ifdef Set_APM_According_PM_Setup
		call	PM_Option_Check			   ; If PM set Disable
		jc	short @f			   ; No, Jmp !
		or	byte ptr PM_RAM:[ALARM_RESUME],80h ; Set Flag to be PM Disable ?
@@:
endif; Set_APM_According_PM_Setup

ifdef	ABIT_Have_Suspend_Fan_Item
		mov	si, offset DGROUP:Fan_Item
		call	GetItem_Value
		shl	al,2
		or	PM_RAM:[ALARM_RESUME], al
endif;	ABIT_Have_Suspend_Fan_Item


;--------------- Save miscellaneous setup settings ---------------

		mov	si,offset DGROUP:Doze_Timer_Item
		mov	di,offset PM_RAM:DOZE_TIME
;R62 start
		call	Timer_Transfer

		mov	si,offset DGROUP:Susp_Timer_Item
		mov	di,offset PM_RAM:SUSPEND_TIME
		call	Timer_Transfer
;R62 end
;R62 		mov	cx,2
;R62 
;R62 	Prg_Next_Item:
;R62 
;R62 		call	GetItem_Value		;get setup setting
;R62 		xor	ah,ah
;R62 		shl	ax,1	
;R62 		mov	bx,offset Timer_Value	;value table
;R62 		add	bx,ax			;translate
;R62 		mov	ax,cs:[bx]		;into reg. value	
;R62 		mov	es:[di],ax		;save value in PM_RAM	
;R62 
;R62 		add	si,ITEM_SIZE
;R62 		inc	di
;R62 		inc	di						
;R62 		loop	short Prg_Next_Item

		mov	ax,PM_RAM:[DOZE_Time]			
		mov	PM_RAM:[Doze_Setting],ax		
								
		mov	ax,PM_RAM:[SUSPEND_TIME]		
		mov	PM_RAM:[Suspend_Setting],ax		

        ;Primary/Secondary Setting
;R62 		mov	si,offset DGROUP:IRQ3_Event_Item
;R62 		mov	cx,13
;R62                 xor     bx, bx
;R62 		xor	dx,dx
;R62         set_pri:
;R62                 call    GetItem_Value
;R62                 or      bl, al
;R62                 and     bl, 11111101b
;R62                 shr     al, 1
;R62                 or      dl, al
;R62 pri:
;R62                 add     si, ITEM_SIZE
;R62                 ror     bx, 1
;R62                 ror     dx, 1
;R62                 loop    set_pri
;R62 start
		mov	di,offset DGROUP:IRQ_Evnt_TBL
		mov	cx,IRQ_Evnt_TBL_Len
                xor     bx, bx
		xor	dx,dx
        set_pri:
		mov	si,word ptr CS:[DI]
		push	di
                call    GetItem_Value
		pop	di
                or      bl, al
                and     bl, 11111101b
                shr     al, 1
                or      dl, al
pri:
                add     di, 2
                ror     bx, 1
                ror     dx, 1
                loop    short set_pri
;R62 end
		test	byte ptr FLOPPY_TYPE[bp],0ffH	; no floppy installed ?
		jnz	short Fdd_Attach
		and	bl,NOT 01000000b 	;disable IRQ6 primary event
Fdd_Attach:
;R23A ifdef	Cover_Garbage_IRQ12			;R23 - starts
;R23A 		test	bh,10h
;R23A 		jz	short W_IRQ12_Dis
;R23A 		or	PM_RAM:[ALARM_RESUME], 80h	;Wake Event IRQ12 Enabled.
;R23A 		and	bh,not 10h
;R23A 	W_IRQ12_Dis:
;R23A endif;	Cover_Garbage_IRQ12			;R23 - ends
ifdef	VT686					;R52A
		or	bl,00000010b		;R52A Always Enable IRQ1(Keyboard Event).
endif;	VT686					;R52A
                push    dx
                mov     cx, VT586_ACPI + 44h
                mov     al, bl
                call    Set_PMU

                mov     cx, VT586_ACPI + 45h
                mov     al, bh
                call    Set_PMU
                pop     dx
                mov     bx, dx
                mov     cx, VT586_ACPI + 46h

                mov     al, bl
                call    Set_PMU
		mov     cx, VT586_ACPI + 47h

                mov     al, bh
                call    Set_PMU

	;APM option

		mov	si,offset DGROUP:Wait_APM_Item
		call	GetItem_Value
		mov	PM_RAM:[Wait_APM_Flag],al

	;video off option

		mov	si,offset Video_Off_Item
		call	GetItem_value
		mov	PM_RAM:[Video_Off_Mode],al

;Read DOZE timer setup value and store in SM RAM

;Read Suspend timer setup value and store in SM RAM

;Set Conserve Mode
		mov	cx, VT586_ACPI + 53h
                mov     al, 88h                 ; But the first conserve mode will on afer
                call    Set_PMU                 ; first doze state

		mov	PM_RAM:[PM_MODE1],FULL_ON
		post_func_call	Update_PM_Timer		

;enable primary activity monitor

		post_func_call	End_Pmi_Handler 	;clear status

ifdef	Break_Suspend_In_Mouse_CMOS	       		
                mov     si,offset Mouse_Irq_Item	
		call    GetItem_Value
		shl	al,2
                mov     PM_RAM:[MISC_CNTL1],al		
endif;	Break_Suspend_In_Mouse_CMOS	       		   	

ifdef	HDD_PWRDOWN_IN_SUSPEND					
ifdef   HDD_PWRDOWN_IN_SUSPEND_After_1Min 			
		mov	si,offset HDD_Power_Item		
		Call	GetItem_Value		
 								
		mov	byte ptr PM_RAM:[HDD_OFF_Timer],al	

		cmp 	al,0				   
		jz	short @f			   

		post_func_call	HDD_Timer_Restore	
@@:					 
endif;	HDD_PWRDOWN_IN_SUSPEND_After_1Min
endif;	HDD_PWRDOWN_IN_SUSPEND
		mov	cl, 2ch
;R08		mov	al, 1
;R08		call	Set_PMIO
;R16		mov	bx, 01e0h		;R08
		mov	bx, 01e4h		;R16
		call	Get_Set_PMIO		;R08
;Set CPU type


ifdef	VT686				;R52A - starts
		mov	si,offset Evt_INTR_Item
		call	F000_Getitem_Value
		mov	bl,00000000b			; set primary activity
		test	al,1	    
		jz	short @F    
		mov	bl,00000010b
@@:				    
		mov	PM_RAM:[VT586PM_I34h_Value],bl	;default
		mov	cl, 34h
		call	E000_Set_PMIO
	
		mov	si,offset Evt_HDD_Item
		call	F000_GetItem_Value
		or	al,al
		jz	short No_Evt_HDD
		or	PM_RAM:[VT586PM_I34h_Value],00011100b
	No_Evt_HDD:

		mov	si,offset Evt_DMA_Item
		call	F000_GetItem_Value
		or	PM_RAM:[VT586PM_I34h_Value],al

		mov	si,offset Evt_LPT_COM_Item
		call	F000_GetItem_Value
		or	al,al
		jz	short No_Evt_LPT_COM
		or	PM_RAM:[VT586PM_I34h_Value],11100000b
	No_Evt_LPT_COM:

		mov	si,offset M_Evt_VGA_Item
		call	F000_GetItem_Value
		mov	cl, 35h
		call	E000_Set_PMIO
else;	VT686				;R52A - ends
		mov	si,offset Evt_INTR_Item
		call	Getitem_Value
		mov	bl,10000000b			; set primary activity
		test	al,1	    
		jz	short @F    
		mov	bl,10000010b			
@@:				    
		mov	al,bl	    
		mov	PM_RAM:[VT586PM_I34h_Value],al	;default
		mov	cl, 34h
		call	Set_PMIO
	
		mov	si,offset Evt_HDD_Item
		call	GetItem_Value
		shl	al,3
		or	PM_RAM:[VT586PM_I34h_Value],al

		mov	si,offset Evt_DMA_Item
		call	GetItem_Value
		or	PM_RAM:[VT586PM_I34h_Value],al

;R52A		mov	si,offset Evt_INTR_Item
;R52A		call	GetItem_Value
;R52A		shl	al,1
;R52A		or	PM_RAM:[VT586PM_I34h_Value],al


		mov	si,offset Evt_LPT_COM_Item
		call	GetItem_Value
		shl	al,5
		or	PM_RAM:[VT586PM_I34h_Value],al

		mov	si,offset M_Evt_VGA_Item
		call	GetItem_Value
;R52Aifndef	VT686			;R52
		shl	al,4
		or	PM_RAM:[VT586PM_I34h_Value],al
;R52A;R52 - starts	
;R52Aelse;	VT686
;R52A		mov	cl, 35h
;R52A		call	E000_Set_PMIO
;R52Aendif;	VT686
;R52A;R52 - ends
endif;	VT686				;R52A

		mov	cl, 38h
		mov	al, 01h
		call	Set_PMIO

ifdef	Have_Fan_Control_Item_In_GPO_Low
	Have_Fan_Control_Item_In_GPO 	EQU	1
endif;	Have_Fan_Control_Item_In_GPO_Low
ifdef	Have_Fan_Control_Item_In_GPO_High
	Have_Fan_Control_Item_In_GPO 	EQU	1
endif;	Have_Fan_Control_Item_In_GPO_High

ifdef   Have_Fan_Control_Item_In_GPO
		extrn	Fan_Control_Item:near
		mov	si, offset DGROUP:Fan_Control_Item 
		call	GetItem_Value	       ;save suspend--> fan
		shl	al,7			       ;stop ?
 		or	PM_RAM:[Video_Off_Mode],al
endif;  Have_Fan_Control_Item_In_GPO

ifdef ACPI_SUPPORT			;
		mov	cl, 2ah		; Enable Software SMI
		mov	bl, 40h		;
		call	Get_Set_PMIO_OR	;
endif ;ACPI_SUPPORT			;

		push	ds			     
		mov	ax,G_RAM		     
		mov	ds,ax			     
		assume	ds:G_RAM		     
		mov	bl,byte ptr ds:[hardware]    
		pop	ds			     
		mov	byte ptr PM_RAM:[PS2_INST],bl
		pop	ds
		popa
endif;	Move_F000_PMU_INIT_To_E000				

		ret
Ct_PM_Init	Endp

ifndef	Move_F000_PMU_INIT_To_E000				
;R62 start
;==================================================[]
;Input: SI = item offset
;	DI = timer setting offset in PM_RAM
;==================================================[]
Timer_Transfer	proc	near
		call	GetItem_Value		;get setup setting
		xor	ah,ah
		shl	ax,1	
		mov	bx,offset Timer_Value	;value table
		add	bx,ax			;translate
		mov	ax,cs:[bx]		;into reg. value	
		mov	es:[di],ax		;save value in PM_RAM	
		ret
Timer_Transfer	ENDP

IRQ_Evnt_TBL:
		dw	offset IRQ3_Event_Item
		dw	offset IRQ4_Event_Item
		dw	offset IRQ5_Event_Item
		dw	offset IRQ6_Event_Item
		dw	offset IRQ7_Event_Item
		dw	offset IRQ8_Event_Item
		dw	offset IRQ9_Event_Item
		dw	offset IRQ10_Event_Item
		dw	offset IRQ11_Event_Item
		dw	offset IRQ12_Event_Item
		dw	offset IRQ13_Event_Item
		dw	offset IRQ14_Event_Item
		dw	offset IRQ15_Event_Item
IRQ_Evnt_TBL_Len	EQU	($ - offset IRQ_Evnt_TBL) /2
;R62 end

;			value	,unit	
;		----------------------
Timer_Value:
		db	00000000b,0ah		;Disable
		db	00000101b,0ah		;5 Sec  
		db	00001010b,0ah		;10 Sec 
		db	00010100b,0ah		;20 Sec 
		db	00011110b,0ah		;30 Sec 
		db	00101000b,0ah		;40 Sec 
		db	00111100b,0ah		;1 Min  
		db	01111000b,0ah		;2 Min  
		db	00000100b,0bh		;4 Min  
		db	00000110b,0bh		;6 Min  
		db	00001000b,0bh		;8 Min  
		db	00001010b,0bh		;10 Min 
		db	00010100b,0bh		;20 Min 
		db	00011110b,0bh		;30 Min 
		db	00101000b,0bh		;40 Min 
		db	00111100b,0bh		;1 Hour 
endif;	Move_F000_PMU_INIT_To_E000				

;[]========================================================================[]
;Procedure:	Ct_LCD_Init
;
;Function :	Set the LCD power down timer which initial method
;		varies from chip to chip
;
;Input	  :	DS = DGROUP
;		ES = PM_RAM
;
;Output   :	None
;
;Note	  :	1. Call from POST 79S (PM initialization)
;		2. Stack available
;		3. Don't destroy any SEGMENT registers!
;[]========================================================================[]
		ASSUME	ES:PM_RAM
		ASSUME	DS:DGROUP
		Public	Ct_LCD_Init
Ct_LCD_Init	Proc	Near
		ret
Ct_LCD_Init	Endp

;[]========================================================================[]
;Procedure:	HDD_Standby_Offset
;
;Function :	Tell BIOS kernal the offset of the setup item
;		"HDD Power Down Timer"
;
;Input	  :	DS = DGROUP
;		ES = PM_RAM
;
;Output   :	NC: HDD Power Down Item exist
;		    SI = Item offset
;		CF: HDD Power Down Item absent
;		    SI Don't care
;
;Note	  :	1. Call from POST 79S (PM initialization)
;		2. Stack available
;		3. Don't destroy any SEGMENT registers!
;		4. If you don't have such a item in SETUP,
;		   just set carry flag & return!
;[]========================================================================[]
		ASSUME	ES:PM_RAM
		ASSUME	DS:DGROUP
		Public	HDD_Standby_Offset
HDD_Standby_Offset	Proc	Near

		extrn	HDD_Timer_Item:Near
		mov	si,offset HDD_Timer_Item

		clc
		ret

HDD_Standby_Offset	Endp
;[]========================================================================[]
;Procedure:	Get_IRQ15_Offset
;
;Input	  :	DS = G_RAM
;
;Output   :	NC:
;			AX = Segment location of the IRQ15
;			     PMI service routine
;			SI = offset of the IRQ15 PMI service routine
;
;			i.e. AX:SI
;
;		CF:
;			IRQ 15 is not supported!
;
;Registers:	Please preserve all registers except AX & SI
;
;[Note]   :	1. called from PM_INIT
;		   NC: AX:SI will be placed interrupt table located
;		       in segment 0
;		   CF: IRQ15 vector will be masked off
;[]========================================================================[]
			ASSUME	DS:G_RAM
			Public	Get_IRQ15_Offset
Get_IRQ15_Offset	Proc	Near
			stc
			ret
Get_IRQ15_Offset	Endp

;[]========================================================================[]
;Procedure:	Ct_Resume_Handle
;
;Function :	Ct_Resume_Handle
;
;Input	  :	None
;
;Output   :	None
;[]========================================================================[]
		Public	Ct_Resume_Handle
Ct_Resume_Handle	Proc	Near
		mov	ax,G_RAM
		mov	ds,ax
		ASSUME	DS:G_RAM
		mov	ss,G_RAM:[ROM_MODULE_SEG]
		mov	sp,G_RAM:[ROM_MODULE_OFFSET]
		iret
Ct_Resume_Handle	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
;
;[]-------------------------------------------------------------------[]

;[]-------------------------------------------------------------------[]
;
; PPPPPPPP	 AA	  RRRRRRRR   TTTTTTTTTTT		44444
; PPPPPPPPP	AAAA	  RRRRRRRRR  TTTTTTTTTTT    ***        444444
; PPP	 PPP   AAAAAA	  RRR	 RRR	 TTT	    ***       444 444
; PPPPPPPPP   AAA  AAA	  RRRRRRRRR	 TTT		     4444444444
; PPPPPPPP   AAAAAAAAAA   RRRRRRRR	 TTT	    ***     44444444444
; PPP	    AAAAAAAAAAAA  RRR	RRR	 TTT	    *** 	  444
; PPP	   AAA	      AAA RRR	 RRR	 TTT			  444
;
;
;
;	   OEM specific subroutines
;
;	   Normally, this part will be placed with the PMI handler
;	   (IRQ15 or SMI or NMI)
;
;[]-------------------------------------------------------------------[]

;[]========================================================================[]
;Function :	Routine to handle the power management interrupt (PMI).
;
;Input    :	None
;
;Output   :	if PM using IRQ --- no output!
;		if PM using NMI --- NC: BIOS has handle this NMI for
;					PM chip!
;				    CF: NMI is not issue by PM chip
;
;Destroy:	if PM using IRQ --- destroy None
;		if PM using NMI --- destroy FLAG
;[]========================================================================[]

		Public	APM_R31_Added
APM_R31_Added:

;[]========================================================================[]
;Procedure:	Get_PMI_Source
;
;Function :	To get the corresponding PMI routine according
;		to what kind of PMI it is
;
;Input    :	DS = PM_RAM
;
;Output   :	SI = point to appropriate PMI handler
;		e.g. if it is a suspend request
;		     SI = offset Suspend_Handler
;
;Note	  :	1. Called from PM_Handler
;		2. stack available
;		3. The BIOS PM kernal will issue:
;		   "call si" after calling this routine!
;[]========================================================================[]

;[]========================================================================[]
;
;Function :	Service routine to handle PMI source 0Fh (reg. 35h bit 4-0)
;
;[]========================================================================[]

;[]========================================================================[]
;
;Function :	Service routine to handle PMI source
;
;[]========================================================================[]

;[]========================================================================[]
;
;Function :	Service routine to handle PMI source 
;
;[]========================================================================[]

;[]========================================================================[]
;
;Function :	Service routine to handle EXT SMI1 source 
;
;[]========================================================================[]

;[]========================================================================[]
;
;Function :	Service routine to handle PMI source 
;
;[]========================================================================[]

;[]========================================================================[]
;
;Function :	Service routine to handle PMI source
;
;[]========================================================================[]

;[]========================================================================[]
;
;Function :	Service routine to handle PMI source
;
;[]========================================================================[]


		ASSUME	DS:PM_RAM
ifndef	CRT_Control_Not_In_F000			
F000_Enable_CRT	Proc	Far
		call	Enable_CRT
		retf
F000_Enable_CRT	Endp

F000_Disable_CRT Proc	Far
		call	Disable_CRT
		retf
F000_Disable_CRT Endp
endif	;CRT_Control_Not_In_F000		

ifndef	V_ALARM_IN_E000			
F000_Virtual_Resume_Timer Proc	Far
		call	Virtual_Resume_Timer
		retf
F000_Virtual_Resume_Timer Endp

;-----------------------------------------------------------
;Function :	1. reg.30h bit 1,0 --> 00b (Full-On Mode)
;		2. set PM_RAM:[PM_MODE]=FULL_ON
;		3. Enable CRT display
;		4. set CPU to its full speed
;
;Input	  :	DS = PM_RAM
;
;Output	  :	None
;-----------------------------------------------------------

;[]========================================================================[]
;input	:	DS = PM_RAM
;[]========================================================================[]


		include	v_alarm.inc

Low_Power_Throttling	Proc	Near
		ret
Low_Power_Throttling	Endp
endif	;V_ALARM_IN_E000		

		ALIGN	4
		Public	PM_Int8_Hook
PM_Int8_Hook	Proc	Near
		ret
PM_Int8_Hook	Endp

;[]===============================================================[]
;
; Cfg_Video_Mode:
;	Routine to initial video after vga initial within POST.
;
; Entry:	none
;
; Exit:		none
;
; Name	| Date		| Description
; -----------------------------------------------------------------
;[]==================================================================[]
		public	Cfg_Video_Mode
Cfg_Video_Mode	proc	near
		ret
Cfg_Video_Mode	endp


;----------------------------------------------------------------------------
;Output   :	AL = 0  DPMS not support
;		(CRT sleep disable or Controll by H/V sync & Blanking)
;		   = 1  CRT sleep use DPMS STANDBY
;		   = 2	CRT sleep use DPMS SUSPEND
;*(Default Value)  = 3	CRT sleep use DPMS OFF       
;		   = 4	CRT sleep use DPMS REDUCE ON (not support in v1.0)
;----------------------------------------------------------------------------
		Public	Get_DPMS_Option
Get_DPMS_Option	proc	near

ifndef	NO_DPMS_SUPPORT
		extrn	VGA_Type_Item:near
		mov     si,offset VGA_Type_Item
		call    GetItem_Value
		cmp	al,3	

		jnz	short _No_DPMS_Support
		mov     dx,12D2H                ; ST AGP vendor ID
		mov     cx,0018H                ; RIVA 128 device ID
		xor     si,si                   ; first device
		mov     ax,0b102H               ; find PCI device func. call
		int     1AH
		jnc	short Have_ST_AGP	; Found => Set No Support DPMS
		mov	al,3
		jmp	short @f		; No => Set Support DPMS
Have_ST_AGP:
_No_DPMS_Support:
		xor	al,al			; Set No Support DPMS
@@:
else	;DPMS_STANDARD
		xor	al,al
endif	;DPMS_STANDARD
		ret

Get_DPMS_Option	endp

ifndef	CRT_Control_Not_In_F000				
	ifdef	CRT_Control_Not_In_APM			
		include	CRT_Ctrl.inc			
	endif	;CRT_Control_Not_In_APM			
endif	;CRT_Control_Not_In_F000			

;R56 - starts
ifdef	LCD_CRT_OPTION
;[]==================================================================[]
;
; Procedure Name: LCD_BACKLIGHT_ON
;
;	This routine is used to turn on the LCD backlight.
;
; Saves: all
; Input: 
;	none
;
; Output: 
;	none
;
; [Note]:
;	1. This routine is hardware dependent.
;
; Author: Daniel Huang
; Date: August, 08, 1995
;
; Name	| Date		| Description
; -----------------------------------------------------------------
; DNL	| 08/08/95	| Initial version for C&T65545
;[]==================================================================[]

		PUBLIC	LCD_BACKLIGHT_ON
LCD_BACKLIGHT_ON	PROC	NEAR

		clc
		ret
LCD_BACKLIGHT_ON	ENDP

;[]==================================================================[]
;
; Procedure Name: LCD_BACKLIGHT_OFF
;
;	This routine is used to turn off the LCD backlight.
;
; Saves: all
; Input: 
;	none
;
; Output: 
;	none
;
; [Note]:
;	1. This routine is hardware dependent.
;
; Author: Daniel Huang
; Date: August, 08, 1995
;
; Name	| Date		| Description
; -----------------------------------------------------------------
; DNL	| 08/08/95	| Initial version for C&T65545
;[]==================================================================[]

		PUBLIC	LCD_BACKLIGHT_OFF
LCD_BACKLIGHT_OFF	PROC	NEAR

		clc
		ret
LCD_BACKLIGHT_OFF	ENDP
endif	;LCD_CRT_OPTION

ifdef	NEW_SUPERVGA_KERNEL

		public	VGA_SIGN_ON_BEFORE
VGA_SIGN_ON_BEFORE	proc	near
		ret
VGA_SIGN_ON_BEFORE	ENDP

;;============================================================
		public	CT_MODESET_ADJUST
CT_MODESET_ADJUST	proc	near
		ret
CT_MODESET_ADJUST	ENDP
;;============================================================
		public	CT_GET_PANEL_TYPE
CT_GET_PANEL_TYPE	proc	near
		ret
CT_GET_PANEL_TYPE	ENDP

F_Video_Func	Proc	Far
	    	Call	Video_Func
	    	retf
F_Video_Func	Endp

;===============================================================
		public	CT_PWR_OFF_PANEL
CT_PWR_OFF_PANEL	proc	near
		ret
CT_PWR_OFF_PANEL	ENDP
;===============================================================
		public	CT_PWR_ON_PANEL
CT_PWR_ON_PANEL	proc	near
		ret
CT_PWR_ON_PANEL	ENDP
;===============================================================
		public	Ct_Set_TV_Mode
Ct_Set_TV_Mode	Proc	Near
		ret
Ct_Set_TV_Mode	ENDP

;===============================================================
endif	;NEW_SUPERVGA_KERNEL
;R56 - ends

;---------------------------------------------------------------------------
;R49 - starts
ifdef	Notebook_Power_Management
		Public	F_Suspend_0V
F_Suspend_0V	proc	Far
		call  Suspend_0V
		ret
F_Suspend_0V	ENDP
F_Resume_0V	Proc	Far
 		Call Resume_0V
 		ret
F_Resume_0V	Endp
endif	;Notebook_Power_Management
;R49 - ends

FCODE		ENDS

;--------------------------------------------------------------
;--------------------------------------------------------------
;----- The following codes will be located at E000 ! ----------
;----- The following codes will be located at E000 ! ----------
;----- The following codes will be located at E000 ! ----------
;----- The following codes will be located at E000 ! ----------
;--------------------------------------------------------------
;--------------------------------------------------------------
EGROUP		GROUP	ECODE
ECODE		SEGMENT USE16 PARA PUBLIC 'ECODE'
		ASSUME	CS:EGROUP,DS:G_RAM,ES:EGROUP
		align	4


if	STD_Function	EQ	1

;[]========================================================================[]
;
;Procedure:	CT_0V_Shutdown
;
;Function :	Routine to put system into off state.
;
;Input	  :	None
;
;Output   :	None
;
;[]========================================================================[]
		Public	CT_0V_Shutdown	
CT_0V_Shutdown	Proc	Near
		mov	ax,PM_RAM_SEGMENT
		mov	ds,ax
		extrn	APM_16_PowerOff:near
		F000_call	DGROUP:APM_16_PowerOff
		ret
CT_0V_Shutdown	Endp

;[]========================================================================[]
;
;Procedure:	CT_System_Wakeup
;
;Function :	Routine for system wake up from Zero-Volt-Suspend.
;
;Input	  :	None
;
;Output   :	None
;
;[]========================================================================[]
		Public	CT_System_Wakeup
CT_System_Wakeup	Proc	Near
		ret
CT_System_Wakeup	Endp

;[]========================================================================[]
;
; Suspend_Chipset_Table
;
;	This table describe chipset registers which save & restore during
;	Zero-Volt-Suspend & Resume.
;	It is refrenced by routine Save_Chipset & Restore_Chipset.
;
;	Formate:
;
;		DW	<Register Index start>, <Regisetr counts>
;		DW		:			:
;		DW		:			:
;		DW		:			:
;		DW	<Register Index start>, <Regisetr counts>
;		DW	FFFFh					; End of table
;
;
;[]========================================================================[]
		PUBLIC	Suspend_Chipset_Table
Suspend_Chipset_Table:
;R49C;R49B		dw	VT586 + 00h,     	100h
;R49C 		dw	VT586 + 00h,     	37h	;R49B
;R49C 		dw	VT586 + 47h,     	60h	;R49B
;R49C 		dw	VT586_IDE + 00h,	100h
;R49C 		dw	VT586_USB + 00h,	100h
;R49C 
;R49C		dw	VT586_ACPI + 00h,	14h	   ;R49B
;R49C 		dw	VT586_ACPI + 16h,	40h - 16h  ;R49B
;R49C ifdef	VT686
;R49C  		dw	VT586_USB_2 + 10h,	31h
;R49C  		dw	VT686_AC97 + 10h,	30h
;R49C  		dw	VT686_AC97 +100h+10h,	30h	;MC97 function 6 
;R49C endif;	VT686

;R49		dw	VT586_ACPI + 00h,	14h
;R49		dw	VT586_ACPI + 16h,	40h - 16h
;R49A		dw	VT586_ACPI + 40h,	1;R49

;R49C - starts
		dw	VT692 + 10h,     	90h
		dw	VT692_PP + 10h,     	30h

 		dw	VT586 + 00h,     	37h
 		dw	VT586 + 47h,     	60h
 		dw	VT586_IDE + 00h,	100h
 		dw	VT586_USB + 00h,	100h
 
 		dw	VT586_ACPI + 16h,	40h - 16h
;R49C - ends
		dw	0FFFFh

;[]========================================================================[]
;Procedure:	Get_SMBASE_Seg
;
;Function :	Return SMBASE segment.
;
;Input	  :	None
;
;Output   :	EAX: should point to the SMBASE address (32bit address).
;
;[]========================================================================[]
		Public	Get_SMBASE_SEG
Get_SMBASE_SEG	Proc	Near
		mov	eax, 0A0000h
		ret
Get_SMBASE_SEG	Endp

;[]========================================================================[]
;Procedure:	CT_AllShadow_RW
;
;Function :	To Enable/Disable all shadow Read/Write.
;
;Input	  :	AL = 0 For all shadow readable.
;		AL = 1 For all shadow writeable.
;
;Output   :	None
;
;Preserve :
;
;Note	  :	1. Stack available.
;		2. called from Suspend_0V or Resume_0V.
;		3. If the chipset support shadow RAM both Readable & Writeable
;		   then don't care input AL, Just program chipset for shadow
;		   RAM both R/W-able.
;
;[]========================================================================[]
		Public	CT_AllShadow_RW
CT_AllShadow_RW	Proc	Near
		pusha
		push	ebx
		mov	cx,VT692 + 61h
		mov	bl,0FFh
		call	E000_GET_SET_PMU_OR
		inc	cl
		call	E000_GET_SET_PMU_OR
		inc	cl
		mov	bl,0F0h
		call	E000_GET_SET_PMU_OR
		pop	ebx
		popa
		ret
CT_AllShadow_RW	Endp

;[]========================================================================[]
;Procedure:	CT_SMBASE_Off
;
;Function :	To disable SMBASE map function.
;
;Input	  :	None
;
;Output   :	None
;
;[]========================================================================[]
		Public	CT_SMBASE_Off
CT_SMBASE_Off	Proc	Near
		pusha	   
		push	ebx
		mov	cx,VT692+63h
;R44		mov	bx,00Fch
		mov	bx,02Fch	;R44
		call	E000_GET_SET_PMU
		pop	ebx
		popa
		ret
CT_SMBASE_Off	endp

;[]========================================================================[]
;Procedure:	CT_SMBASE_On
;
;Function :	To Enable SMBASE map function.
;
;Input	  :	None
;
;Output   :	None
;
;[]========================================================================[]
		Public	CT_SMBASE_On
CT_SMBASE_On	Proc	Near
		pusha
		push	ebx
		mov	cx,VT692+63h
		mov	bx,00FCh	;R49A
;R49A		mov	bx,03FCh
		call	E000_GET_SET_PMU
		pop	ebx
		popa
		ret
CT_SMBASE_On	Endp

;[]========================================================================[]
;Procedure:	CT_Disable_SMI
;
;Function :	To disable SMI trigger.
;
;Input	  :	None
;
;Output   :	None
;
;[]========================================================================[]
		Public	CT_Disable_SMI
CT_Disable_SMI	Proc	Near
		ret
CT_Disable_SMI	Endp
;[]========================================================================[]
;Procedure:	CT_Skip_ZV_Shadow
;
;Function :	To tell ZV suspend kernal that do not save/restore shadow RAM
;		if it is need.
;
;Input	  :	AX = shadow RAM segment C000H,D000H,E000H,F000H.
;
;Output   :	ZF = Skip this segment save/restore during ZV susupend/resume.
;		NZF = This segment save/restore during ZV susupend/resume.
;
;Save	  :	AX
;
;Note	  :	Sometime chipset use shadow RAM for SMBASE, So it is need to
;		skip shadow RAM save/restore during ZV susupend/resume.
;		Refrence the chipset Sis-550X for this case.
;
;[]========================================================================[]
		Public	CT_Skip_ZV_Shadow
CT_Skip_ZV_Shadow	Proc	Near
		or	ax,ax
		ret
CT_Skip_ZV_Shadow	Endp

		Public	Save_Ct_device
Save_Ct_device	Proc	near
		ret
Save_Ct_device	Endp

		Public	Restore_Ct_device
Restore_Ct_device	Proc	Near
		ret
Restore_Ct_device	Endp

ifdef	S4_Support
		Public	Wakeup_Device
Wakeup_Device	Proc	NEAR

	; Enable IDE Channel
		push	ebx
		mov	cx, VT586_IDE+04H
		mov	bl, 05h
		Call	E000_Get_Set_PMU_OR
		pop	ebx
		ret

Wakeup_Device	Endp
endif;	S4_Support
endif	;STD_Function

ifdef	ACPI_Support
;[]========================================================================[]
;Procedure:	Ct_ACPI_Option
;
;Function :	Return ACPI on/off status
;
;Input	  :	None
;
;Output   :	CF = 1   ACPI off
;		CF = 0   ACPI on
;[]========================================================================[]
		Public	Ct_ACPI_Option
Ct_ACPI_Option	Proc	Near


;R26  IFNDEF	No_ACPI_IRQ_Selectable
  IFDEF	ACPI_IRQ_Selectable			;R26
		mov	si,offset Assign_ACPI_IRQ_Item
		call    F000_GetItem_Value
		or	al,al			; if ACPI IRQ set NA ?
		jnz	short @F		; No, jmp !
		stc				; Set Not ACPI
		ret
@@:
;R26  ENDIF;	No_ACPI_IRQ_Selectable
  ENDIF;ACPI_IRQ_Selectable			;R26

		mov	si,offset ACPI_option_Item
                call    F000_GetItem_Value
		or	al,al			;Enable ACPI ?
		clc				; Set Is ACPI
		jz	short @F		;Yes
		stc				; Set Not ACPI
@@:
		ret

Ct_ACPI_Option	Endp
endif;	ACPI_Support

;[]========================================================================[]
;Procedure:	E000_Ct_Early_PM_Init
;
;Function :	Early PM chip initializations
;
;Input	  :	None
;
;Output   :	None
;
;Preserve :	All
;
;Note	  :	1. Call from POST 9
;		2. Stack available
;		3. You can initialize any PM function which is needed
;		   to be done earlier!
;[]========================================================================[]
		Public	E000_Ct_Early_PM_Init
E000_Ct_Early_PM_Init	Proc	Near

		push	ds
		push	es
		pushad
		cld
ifdef	Wake_On_GPI_Support			;R14 - starts
		mov	al,55h NMI_OFF			; CMOS [55h] :
		out	70h,al			; bit 4 :  Wake_On_GPI_Support
		in	al,71h			;
		and	al,10h
		shr	al,4
		shl	al,Wake_On_GPI_Support
		mov	bh, al
		mov	cl, 24h			;
		mov	bl, not (01h shl Wake_On_GPI_Support)
		call	E000_Get_Set_PMIO	;
endif;	Wake_On_GPI_Support			;R14 - ends

ifdef	VT596
		mov	bl,not 04h		;R27 Set RTC Alarm Resume Off
		mov	cl, 03h			;R27
		call	E000_Get_Set_PMIO_AND	;R27

		mov	dx,ACPI_Port + 00h	
		in	ax,dx	       		
		out	dx,ax			
		mov	dx,ACPI_Port + 20h	;R06
		in	ax,dx	       		;R06
		out	dx,ax			;R06
		mov	dx,ACPI_Port + 30h	;R06
		in	ax,dx	       		;R06
		out	dx,ax			;R06
		mov	dx,ACPI_Port + 32h	;R06
		in	ax,dx	       		;R06
		out	dx,ax			;R06
		mov	dx,ACPI_Port + 28h	;R04
		in	ax,dx	       		;R04
		out	dx,ax			;R04
  IFNDEF	Power_Button_Dont_Set_Level_Trigger	;R16 - starts
		mov	cl, 2Ch			; Set Power Button to
		mov	bl, 04h			;	Level Trigger
		call	E000_Get_Set_PMIO_OR	;
  ENDIF;	Power_Button_Dont_Set_Level_Trigger	;R16 - ends
  IFDEF	Always_Enable_LID			;R18 - starts
		mov	cl, 25h			; Always Enable LID#
;R18A		mov	bl,80h			;
		mov	bl,08h			;R18A
		call	E000_Get_Set_PMIO_OR	;
  ENDIF;Always_Enable_LID			;
  IFDEF	WAKE_LAN_BY_LID
		mov	al,55h NMI_OFF			; CMOS [55h] :
		out	70h,al			; bit 4 :  WAKE_LAN_BY_LID
		in	al,71h			;
		and	al,10h
		shr	al,1
		mov	bh, al
		mov	bl, not 08h
		mov	cl, 25h			; 25h bit 3 : LID#
		call	E000_Get_Set_PMIO	;

    ifdef	WAKE_LAN_BY_GPI			;R61
		shr	bh, 3			;R61
		mov	cl, WAKE_LAN_BY_GPI 	;R61
		shl	bh, cl			;R61
		mov	bl, bh			;R61
		not	bl			;R61
		mov	dx, ACPI_Port + 24h	;R61
		in	al, dx			;R61
		and	al, bl			;R61
		or	al, bh			;R61	
		mov	dx, ACPI_Port + 24h	;R61
		out	dx, al			;R61
    endif;	WAKE_LAN_BY_GPI			;R61

   IFDEF	LID_ACTIVE_HIGH			;R30A - starts
		mov	cl, 2Ch			; 2Ch bit 7 : LID# Rising Trigger
		mov	bl,not 80h		;
		call	E000_Get_Set_PMIO_AND	;
   ELSE;	LID_ACTIVE_HIGH			;R30A - ends
    ifndef	LID_Triger_By_Rising_Edge	;R30
		mov	cl, 2Ch			;R30 2Ch bit 7 : LID# Falling Trigger
		mov	bl, 80h			;R30
		call	E000_Get_Set_PMIO_OR	;R30
    else;	LID_Triger_By_Rising_Edge	;R30A
		mov	cl, 2Ch			;R30A 2Ch bit 7 : LID# Rising Trigger
		mov	bl,not 80h		;R30A
		call	E000_Get_Set_PMIO_AND	;R30A
    endif;	LID_Triger_By_Rising_Edge	;R30
   ENDIF;	LID_ACTIVE_HIGH			;R30A

  ENDIF;WAKE_LAN_BY_LID				;R18 - ends
endif;	VT596

                mov     ax,cs
                mov     ds,ax
                mov     ax,03800h               ; orginal CPU SMBase
                mov     es,ax
                mov     cx,Change_SMBase_L      ;dword length
                mov     si,offset Change_SMBase
                xor     di,di
                rep     movsb

; Enable SMI
		Call	E000_Ct_Enable_SMI

                F000_call       Issue_SW_SMI    ;Change SMBASE
		xor	cx, cx			
@@:						
		loop	@B			
;R11 M1_Cpu:


; Disable all SMI

; Enable SMI
; **** Change_SMBase subroutine is executing at this point in SMM Mode ****
; **** After this point, all SMM execute at memory 0A8000h ****************

; Disable SMI

; Enable SMRAM can be access
		mov	cx, VT692 + 63h   ;Enable a000:0 - b000:ffff read/write to DRAM
		mov	bx, 01fch		
		call	E000_Get_Set_PMU	
		mov	ax,cs
		mov	ds,ax
		mov	ax,0A800h	
		mov	es,ax

; Copy SMI_Handler to SMRAM 0A8000h
; DS = CS, ES = 0A8000h

		mov	cx, (SMI_Handler_Len/4)
		mov	si,offset SMI_Handler_Start

		xor	di,di
		rep	movsd

; Modified the offset of JMP instruction for different CPU

;R11 		mov	si, (offset Intel_SMI_Start-offset SMI_Handler_Start-3)
;R11 
;R11 Intel_Cpu:
;R11 		mov	word ptr es:[1], si

ifdef	APM_IN_SMBASE
		call	Move_APMCode
endif	;APM_IN_SMBASE
;R40 -  start
ifdef	Flash_IN_SMBASE
		call	Move_FlashCode
endif	;Flash_IN_SMBASE
;R40 - end
; Close SMRAM, for operate correctly at SMRAM

		mov	cx,VT692 + 63h
		mov	bx, 0fch
		call	E000_Get_Set_PMU
ifdef	Suspend_TurnOff_Fan_By_GPIO_0_High	
		mov	cl, 42h			;
		mov	bl, not 01h		;
		call	E000_Get_Set_PMIO_AND	;
 
		mov	cl, 40h			;Active GPIO 0 is Output
		mov	bl, 01h			;
		call	E000_Get_Set_PMIO_OR	;
endif;	Suspend_TurnOff_Fan_By_GPIO_0_High	
ifdef	Suspend_TurnOff_Fan_By_GPO_LowByte_Low
		mov	cx,VT586_ACPI + 40h	; Set Pin136 GPO_WE
		mov	bl,not 80h
		call	E000_Get_Set_PMU_AND
		mov	cl, 46h			;GPO Hi Byte = High
		mov	bl, Suspend_TurnOff_Fan_By_GPO_LowByte_Low
		call	E000_Get_Set_PMIO_OR	;
endif;	Suspend_TurnOff_Fan_By_GPO_LowByte_Low
ifdef	Suspend_TurnOff_Fan_By_GPO_HiByte_Low
		mov	cx,VT586_ACPI + 40h	; Set Pin136 GPO_WE
		mov	bl,not 80h
		call	E000_Get_Set_PMU_AND
		mov	cl, 47h			;GPO Hi Byte = High
		mov	bl, Suspend_TurnOff_Fan_By_GPO_HiByte_Low
		call	E000_Get_Set_PMIO_OR	;
endif;	Suspend_TurnOff_Fan_By_GPO_HiByte_Low
ifdef	Suspend_TurnOff_Fan_By_GPO_LowByte_High
		mov	cx,VT586_ACPI + 40h	; Set Pin136 GPO_WE
		mov	bl,not 80h
		call	E000_Get_Set_PMU_AND
		mov	cl, 46h			;GPO Hi Byte = Low
		mov	bl,not Suspend_TurnOff_Fan_By_GPO_LowByte_High
		call	E000_Get_Set_PMIO_AND	;
endif;	Suspend_TurnOff_Fan_By_GPO_LowByte_High
ifdef	Suspend_TurnOff_Fan_By_GPO_HiByte_High
		mov	cx,VT586_ACPI + 40h	; Set Pin136 GPO_WE
		mov	bl,not 80h
		call	E000_Get_Set_PMU_AND
		mov	cl, 47h			;GPO Hi Byte = Low
		mov	bl,not Suspend_TurnOff_Fan_By_GPO_HiByte_High
		call	E000_Get_Set_PMIO_AND	;
endif;	Suspend_TurnOff_Fan_By_GPO_HiByte_High
ifdef	Suspend_TurnOff_Fan_By_GPO_Low
		mov	cx,VT586_ACPI + 40h	; Set Pin136 GPO_WE
		mov	bl,not 80h
		call	E000_Get_Set_PMU_AND
		mov	dx, ACPI_Port + 46h
		in	ax,dx
		or	ax, Suspend_TurnOff_Fan_By_GPO_Low
		out	dx,ax
		out	dx,ax
endif;	Suspend_TurnOff_Fan_By_GPO_Low
IFDEF	VT596
	;-------------------------------------;
	;   >> 596(3050) : <<		      ;
	;  Control GPO to High After PowerOn  ;Because default of GPIO is LOW
	;-------------------------------------;
			;---------;
			; GPO0-7  ;
			;---------;
		GPO_Port_4C_VAL	= 00h
	ifdef	Suspend_Send_Low_To_GPO0
		GPO_Port_4C_VAL	= GPO_Port_4C_VAL OR 01h
	endif;	Suspend_Send_Low_To_GPO0
	ifdef	Suspend_Send_Low_To_GPO1
		GPO_Port_4C_VAL	= GPO_Port_4C_VAL OR 02h
	endif;	Suspend_Send_Low_To_GPO1
	ifdef	Suspend_Send_Low_To_GPO2
		GPO_Port_4C_VAL	= GPO_Port_4C_VAL OR 04h
	endif;	Suspend_Send_Low_To_GPO2
	ifdef	Suspend_Send_Low_To_GPO3
		GPO_Port_4C_VAL	= GPO_Port_4C_VAL OR 08h
	endif;	Suspend_Send_Low_To_GPO3
	ifdef	Suspend_Send_Low_To_GPO4
		GPO_Port_4C_VAL	= GPO_Port_4C_VAL OR 10h
	endif;	Suspend_Send_Low_To_GPO4
	ifdef	Suspend_Send_Low_To_GPO5
		GPO_Port_4C_VAL	= GPO_Port_4C_VAL OR 20h
	endif;	Suspend_Send_Low_To_GPO5
	ifdef	Suspend_Send_Low_To_GPO6
		GPO_Port_4C_VAL	= GPO_Port_4C_VAL OR 40h
	endif;	Suspend_Send_Low_To_GPO6
	ifdef	Suspend_Send_Low_To_GPO7
		GPO_Port_4C_VAL	= GPO_Port_4C_VAL OR 80h
	endif;	Suspend_Send_Low_To_GPO7
 ifdef	Suspend_Send_Low_To_GPO
  if	Suspend_Send_Low_To_GPO LE	7
GPO_Port_4C_VAL = GPO_Port_4C_VAL OR (01h SHL Suspend_Send_Low_To_GPO)
  endif;Suspend_Send_Low_To_GPO LE	7
 endif;	Suspend_Send_Low_To_GPO
if	GPO_Port_4C_VAL		NE	00h
		mov	cl, 4Ch
		mov	bl, GPO_Port_4C_VAL
		call	E000_Get_Set_PMIO_OR
endif;	GPO_Port_4C_VAL		NE	00h
			;---------;
			; GPO8-15 ;
			;---------;
		GPO_Port_4D_VAL	= 00h
	ifdef	Suspend_Send_Low_To_GPO8
		GPO_Port_4D_VAL	= GPO_Port_4D_VAL OR 01h
	endif;	Suspend_Send_Low_To_GPO8
	ifdef	Suspend_Send_Low_To_GPO9
		GPO_Port_4D_VAL	= GPO_Port_4D_VAL OR 02h
	endif;	Suspend_Send_Low_To_GPO9
	ifdef	Suspend_Send_Low_To_GPO10
		GPO_Port_4D_VAL	= GPO_Port_4D_VAL OR 04h
	endif;	Suspend_Send_Low_To_GPO10
	ifdef	Suspend_Send_Low_To_GPO11
		GPO_Port_4D_VAL	= GPO_Port_4D_VAL OR 08h
	endif;	Suspend_Send_Low_To_GPO11
	ifdef	Suspend_Send_Low_To_GPO12
		GPO_Port_4D_VAL	= GPO_Port_4D_VAL OR 10h
	endif;	Suspend_Send_Low_To_GPO12
	ifdef	Suspend_Send_Low_To_GPO13
		GPO_Port_4D_VAL	= GPO_Port_4D_VAL OR 20h
	endif;	Suspend_Send_Low_To_GPO13
	ifdef	Suspend_Send_Low_To_GPO14
		GPO_Port_4D_VAL	= GPO_Port_4D_VAL OR 40h
	endif;	Suspend_Send_Low_To_GPO14
	ifdef	Suspend_Send_Low_To_GPO15
		GPO_Port_4D_VAL	= GPO_Port_4D_VAL OR 80h
	endif;	Suspend_Send_Low_To_GPO15
 ifdef	Suspend_Send_Low_To_GPO
  if	Suspend_Send_Low_To_GPO LE	15
  if	Suspend_Send_Low_To_GPO GE	8
GPO_Port_4D_VAL = GPO_Port_4D_VAL OR (01h SHL (Suspend_Send_Low_To_GPO-8))
  endif;Suspend_Send_Low_To_GPO LE	8
  endif;Suspend_Send_Low_To_GPO LE	15
 endif;	Suspend_Send_Low_To_GPO
if	GPO_Port_4D_VAL		NE	00h
		mov	cl, 4Dh
		mov	bl, GPO_Port_4D_VAL
		call	E000_Get_Set_PMIO_OR
endif;	GPO_Port_4D_VAL		NE	00h
			;----------;
			; GPO16-23 ;
			;----------;
		GPO_Port_4E_VAL	= 00h
	ifdef	Suspend_Send_Low_To_GPO16
		GPO_Port_4E_VAL	= GPO_Port_4E_VAL OR 01h
	endif;	Suspend_Send_Low_To_GPO16
	ifdef	Suspend_Send_Low_To_GPO17
		GPO_Port_4E_VAL	= GPO_Port_4E_VAL OR 02h
	endif;	Suspend_Send_Low_To_GPO17
	ifdef	Suspend_Send_Low_To_GPO18
		GPO_Port_4E_VAL	= GPO_Port_4E_VAL OR 04h
	endif;	Suspend_Send_Low_To_GPO18
	ifdef	Suspend_Send_Low_To_GPO19
		GPO_Port_4E_VAL	= GPO_Port_4E_VAL OR 08h
	endif;	Suspend_Send_Low_To_GPO19
	ifdef	Suspend_Send_Low_To_GPO20
		GPO_Port_4E_VAL	= GPO_Port_4E_VAL OR 10h
	endif;	Suspend_Send_Low_To_GPO20
	ifdef	Suspend_Send_Low_To_GPO21
		GPO_Port_4E_VAL	= GPO_Port_4E_VAL OR 20h
	endif;	Suspend_Send_Low_To_GPO21
	ifdef	Suspend_Send_Low_To_GPO22
		GPO_Port_4E_VAL	= GPO_Port_4E_VAL OR 40h
	endif;	Suspend_Send_Low_To_GPO22
	ifdef	Suspend_Send_Low_To_GPO23
		GPO_Port_4E_VAL	= GPO_Port_4E_VAL OR 80h
	endif;	Suspend_Send_Low_To_GPO23
 ifdef	Suspend_Send_Low_To_GPO
  if	Suspend_Send_Low_To_GPO LE	23
  if	Suspend_Send_Low_To_GPO GE	16
GPO_Port_4E_VAL = GPO_Port_4E_VAL OR (01h SHL (Suspend_Send_Low_To_GPO-16))
  endif;Suspend_Send_Low_To_GPO LE	16
  endif;Suspend_Send_Low_To_GPO LE	23
 endif;	Suspend_Send_Low_To_GPO
if	GPO_Port_4E_VAL		NE	00h
		mov	cl, 4Eh
		mov	bl, GPO_Port_4E_VAL
		call	E000_Get_Set_PMIO_OR
endif;	GPO_Port_4E_VAL		NE	00h
			;----------;
			; GPO24-30 ;
			;----------;
		GPO_Port_4F_VAL	= 00h
	ifdef	Suspend_Send_Low_To_GPO24
		GPO_Port_4F_VAL	= GPO_Port_4F_VAL OR 01h
	endif;	Suspend_Send_Low_To_GPO24
	ifdef	Suspend_Send_Low_To_GPO25
		GPO_Port_4F_VAL	= GPO_Port_4F_VAL OR 02h
	endif;	Suspend_Send_Low_To_GPO25
	ifdef	Suspend_Send_Low_To_GPO26
		GPO_Port_4F_VAL	= GPO_Port_4F_VAL OR 04h
	endif;	Suspend_Send_Low_To_GPO26
	ifdef	Suspend_Send_Low_To_GPO27
		GPO_Port_4F_VAL	= GPO_Port_4F_VAL OR 08h
	endif;	Suspend_Send_Low_To_GPO27
	ifdef	Suspend_Send_Low_To_GPO28
		GPO_Port_4F_VAL	= GPO_Port_4F_VAL OR 10h
	endif;	Suspend_Send_Low_To_GPO28
	ifdef	Suspend_Send_Low_To_GPO29
		GPO_Port_4F_VAL	= GPO_Port_4F_VAL OR 20h
	endif;	Suspend_Send_Low_To_GPO29
	ifdef	Suspend_Send_Low_To_GPO30
		GPO_Port_4F_VAL	= GPO_Port_4F_VAL OR 40h
	endif;	Suspend_Send_Low_To_GPO30
 ifdef	Suspend_Send_Low_To_GPO
  if	Suspend_Send_Low_To_GPO LE	30
  if	Suspend_Send_Low_To_GPO GE	24
GPO_Port_4F_VAL = GPO_Port_4F_VAL OR (01h SHL (Suspend_Send_Low_To_GPO-24))
  endif;Suspend_Send_Low_To_GPO LE	24
  endif;Suspend_Send_Low_To_GPO LE	30
 endif;	Suspend_Send_Low_To_GPO
if	GPO_Port_4F_VAL		NE	00h
		mov	cl, 4Fh
		mov	bl, GPO_Port_4F_VAL
		call	E000_Get_Set_PMIO_OR
endif;	GPO_Port_4F_VAL		NE	00h
ENDIF;	VT596

ifdef	Power_On_ATX_By_GPIO0
ifdef	Have_Keyboard_PowerOn_Item		
		mov	al,55h NMI_OFF			; CMOS [55h] :
		out	70h,al			; bit 4 : Keyboard_Item of setup
		in	al,71h			;
		and	al,10h
		shr	al,4
		mov	bh, al
else;	Have_Keyboard_PowerOn_Item
		mov	bh,01h
endif;	Have_Keyboard_PowerOn_Item
		mov	cl, 26h			;
		mov	bl, not 01h		;
		call	E000_Get_Set_PMIO	;
		;---------------------------------------;
		;    Clear Keyboard's Output Buffer	;
		;---------------------------------------;
		push	ds			; copy these code from
		mov	ax,G_RAM		; Post_13S of E0POST.asm !
		mov	ds,ax
		ASSUME	DS:G_RAM
		pushf
		sti
		xor	cx,cx

	Cln_KB_Buf_:

		in	al,60h
		NEWIODELAY
		loop	short Cln_KB_Buf_

		and	INIT_ERR_FLG,NOT (IEF_SETUP_OK+IEF_TO_ENTER_SETUP)
		mov	dword ptr PTR_KBD_BUF_HD,01e001eh
		popf
		pop	ds
		ASSUME	DS:PM_RAM
endif;	Power_On_ATX_By_GPIO0			
;R10 - starts
ifdef	Wake_On_EXTSMI0_Support
		mov	al,55h NMI_OFF			; CMOS [55h] :
		out	70h,al			; bit 4 : Keyboard_Item of setup
		in	al,71h			;
		and	al,10h
		shr	al,4
		mov	bh, al
		mov	cl, 26h			;
		mov	bl, not 01h		;
		call	E000_Get_Set_PMIO	;
endif;	Wake_On_EXTSMI0_Support
;R10 - ends


		mov	cx,VT586_ACPI + 40h	; Enable =>
						; Power Buttom Debounce !
		mov	bl, 20h
		call	E000_Get_Set_PMU_OR

		mov	cl, 01h			; Clear Power Buttom Status
		call	E000_Get_PMIO
		call	E000_Set_PMIO
		call	Delay_About_1_Second
		mov	cl, 01h
		call	E000_Get_PMIO
		call	E000_Set_PMIO

ifdef	Disable_ExtSMI_SW_In_POST
 		mov	al,55h NMI_OFF			
 		F000_call	Get_Cmos	
 		test	al,80h			
 		jz	short @f		
endif;	Disable_ExtSMI_SW_In_POST
  IFNDEF	WAKE_LAN_BY_LID			;R24
    IFNDEF	PATCH_WOL_STATUS		;R24
		mov	cl, 03h			; Enable Power Buttom
		mov	bl, 01h
		call	E000_Get_Set_PMIO_OR
    ENDIF;	PATCH_WOL_STATUS		;R24
  ENDIF;	WAKE_LAN_BY_LID			;R24
  IFDEF		WAKE_LAN_BY_LID			;R24 - starts
		mov	cl, 03h			; Disable Power Buttom
		mov	bl,not 01h
		call	E000_Get_Set_PMIO_AND
  ENDIF;	WAKE_LAN_BY_LID
  IFDEF		PATCH_WOL_STATUS
		mov	cl, 03h			; Disable Power Buttom
		mov	bl,not 01h
		call	E000_Get_Set_PMIO_AND
  ENDIF;	PATCH_WOL_STATUS		;R24 - ends
@@:						
		mov	cl, 27h
		mov	bl,02h
		call	E000_Get_Set_PMIO_OR
ifdef	Cache_ZZ_Pin_To_GPIO4
		mov	cl, 40h
		mov	bl,10h
		call	E000_Get_Set_PMIO_OR
		mov	cl, 42h
		mov	bl,not 10h
		call	E000_Get_Set_PMIO_AND
endif;	Cache_ZZ_Pin_To_GPIO4

ifdef	Clear_PME_Before_Off				;R25B
		call	Record_WOL_Info			;R25B
endif;	Clear_PME_Before_Off				;R25B

		popad
		pop	es
		pop	ds

		ret
E000_Ct_Early_PM_Init	Endp

ifdef	APM_IN_SMBASE
	COMPILE_FOR_APMBIOS	=	2
		include	APM.INC
endif	;APM_IN_SMBASE
;R40 -  start
ifdef	Flash_IN_SMBASE
	COMPILE_FOR_APMBIOS	=	2
		include	SMIFlash.INC
endif	;Flash_IN_SMBASE
;R40 - end

ifdef	Move_F000_PMU_INIT_To_E000
;[]========================================================================[]
;Procedure:	E000_Ct_PM_Final_Init
;
;Function :	PM initialization before boot
;
;Input    :	None
;
;Output   :	None
;
;Registers:	Please preserve all registers
;
;Note	  :	1. Call from POST 82
;		2. Stack available
;[]========================================================================[]
		ASSUME	ES:PM_RAM
		ASSUME	DS:DGROUP
		Public	E000_Ct_PM_Final_Init
E000_Ct_PM_Final_Init	Proc	Near

ifdef	Have_Conserve_Item				
		mov	si,offset Conserve_Mode_Item
		call	F000_GetItem_Value
		mov	bl,al
		shl	bl,4
else;	Have_Conserve_Item				
   		xor	bl,bl				
endif;	Have_Conserve_Item				
		mov	cx,VT586_ACPI + 53h
		call	E000_Get_Set_PMU_OR

		mov	cl, 30h
		call	E000_Set_PMIO_Clear

;R67		mov	ah,0			; Clear Y-M-D Alarm Setting.

		mov	al,32h			;R67 Set ACPI Century Field
		F000_call	Get_Cmos	;R67  to the year of Now !
		mov	ah,al			;R67
		mov	al,7fh			;
		F000_call	Set_Cmos	;

		xchg	al,ah			; Clear M-D Alarm Setting.
		mov	al,7eh			;
		F000_call	Set_Cmos	;
		xchg	al,ah			;
		mov	al,7dh			;
		F000_call	Set_Cmos	;
ifdef	Disable_ExtSMI_SW_In_POST
 		mov	cl, 01h			; Clear Power Buttom Status
 		call	E000_Get_PMIO		;
 		call	E000_Set_PMIO		;
 		call	Delay_About_1_Second	;
 		mov	cl, 01h			;
 		call	E000_Get_PMIO		;
 		call	E000_Set_PMIO		;
 
 		mov	cl, 03h			; Enable Power Buttom
 		mov	bl, 01h			;
 		call	E000_Get_Set_PMIO_OR	;
endif;	Disable_ExtSMI_SW_In_POST

;R08A - starts
ifdef	VT596
  IFDEF	Thermal_Enable			
                mov     cx,VT586_ACPI + 4ch
		mov     bl,0D0h
                call    E000_Get_Set_PMU_OR
    ifndef	Thermal_Active_By_High
                mov     cl,2ch
                mov     bl,40h
                call    E000_Get_Set_PMIO_OR
    endif;	Thermal_Active_By_High
  ENDIF;Thermal_Enable				
;R45 - starts
ifdef	APC_Power_LED_ITEM
		mov	al, APC_LED_CMOS
 		F000_call	Get_Cmos	
		test	al, APC_LED_CMOS_BIT
		jnz	short Enable_GPO_Device
		mov	bl, 0Bfh		;disable GPO23,22
		mov	cx, VT596+75h
		call	E000_Get_Set_PMU_AND
		jmp	short Disable_GPO_Device
Enable_GPO_Device:
		mov	bl, 40h			;enable GPO23,22
		mov	cx, VT596+75h
		call	E000_Get_Set_PMU_OR
Disable_GPO_Device:
endif;	APC_Power_LED_ITEM
;R45 - ends
endif;	VT596					
;R08 - ends
		ret
E000_Ct_PM_Final_Init	Endp

;[]========================================================================[]
;Procedure:	E000_Ct_PM_Init
;
;Function :	Special PM init which the standard code can't do
;
;Input	  :	DS = DGROUP
;		ES = PM_RAM
;
;Output   :	None
;
;Note	  :	1. Call from POST 79S (PM initialization)
;		2. Stack available
;		3. Don't destroy any SEGMENT registers!
;[]========================================================================[]
		ASSUME	ES:PM_RAM
		ASSUME	DS:DGROUP
		Public	E000_Ct_PM_Init
E000_Ct_PM_Init	Proc	Near
		pusha
;R49 - starts
ifdef	Notebook_Power_Management
		mov	si,offset OS_Type_Item
		call	F000_GetItem_Value
		mov	byte ptr PM_RAM:OS_TYPE_BYTE,al
endif	;Notebook_Power_Management
;R49 - ends
		push	ds
		push	es
		pop	ds

;--------------- Set 32bit Timer for ACPI ------------------------
;R39		mov	cx, VT586_ACPI + 41h
;R39		mov	bl, 08h			
;R39		call	E000_Get_Set_PMU_OR	
;R65A start
ifdef	PME_SUPPORT
		mov	si, offset DGROUP:WO_Item
		call	F000_GetItem_Value		;get setup setting
		shl	al,5
		mov	bl,al

		mov	cl,24h
		call	E000_Get_PMIO
		and	al,not 20h
		or	al,bl
		call	E000_Set_PMIO
endif	;PME_SUPPORT
;R65A end

		mov	si, offset DGROUP:Alarm_Item
		call	F000_GetItem_Value		;get setup setting
		mov	bl,al
		mov	si, offset DGROUP:PWRBTN_OVRD_Item
		call	F000_GetItem_Value		;get setup setting
		shl	al,1
		or	bl,al
		mov	PM_RAM:[ALARM_RESUME], bl

		mov	si, offset DGROUP:Ring_Item	; Set Ring Resume
		call	F000_GetItem_Value		; By Setup Item
		mov	bh,al				;R32A
		shl	al,3
		or	PM_RAM:[ALARM_RESUME], al
ifndef	VT596						;R32A
		mov	cl, 27h
		mov	bl,not 04h
		call	E000_Get_Set_PMIO_AND
else;	VT596						;R32A
		mov	cl, 25h				;R32A
		mov	bl,not 01h			;R32A
		call	E000_Get_Set_PMIO		;R32A
endif;	VT596						;R32A
ifdef Set_APM_According_PM_Setup		
		F000_call	PM_Option_Check			   ; If PM set Disable
		jc	short @f			   ; No, Jmp !
		or	byte ptr PM_RAM:[ALARM_RESUME],80h ; Set Flag to be PM Disable ?
@@:
endif; Set_APM_According_PM_Setup		

ifdef	ABIT_Have_Suspend_Fan_Item
		mov	si, offset DGROUP:Fan_Item
		call	F000_GetItem_Value
		shl	al,2
		or	PM_RAM:[ALARM_RESUME], al
endif;	ABIT_Have_Suspend_Fan_Item
;--------------- Save miscellaneous setup settings ---------------

		mov	si,offset DGROUP:Doze_Timer_Item
		mov	di,offset PM_RAM:DOZE_TIME
;R62 start
		call	Timer_Transfer

		mov	si,offset DGROUP:Susp_Timer_Item
		mov	di,offset PM_RAM:SUSPEND_TIME
		call	Timer_Transfer
;R62 end
;R62 		mov	cx,2
;R62 
;R62 	Prg_Next_Item:
;R62 
;R62 		call	F000_GetItem_Value		;get setup setting
;R62 		xor	ah,ah
;R62 		shl	ax,1	
;R62 		mov	bx,offset Timer_Value	;value table
;R62 		add	bx,ax			;translate
;R62 		mov	ax,cs:[bx]		;into reg. value	
;R62 		mov	es:[di],ax		;save value in PM_RAM	
;R62 
;R62 		add	si,ITEM_SIZE
;R62 		inc	di
;R62 		inc	di						
;R62 		loop	short Prg_Next_Item

		mov	ax,PM_RAM:[DOZE_Time]			
		mov	PM_RAM:[Doze_Setting],ax		
								
		mov	ax,PM_RAM:[SUSPEND_TIME]		
		mov	PM_RAM:[Suspend_Setting],ax		

        ;Primary/Secondary Setting
;R62 		mov	si,offset DGROUP:IRQ3_Event_Item
;R62 		mov	cx,13
;R62                 xor     bx, bx
;R62 		xor	dx,dx
;R62         set_pri:
;R62                 call    F000_GetItem_Value
;R62                 or      bl, al
;R62                 and     bl, 11111101b
;R62                 shr     al, 1
;R62                 or      dl, al
;R62 pri:
;R62                 add     si, ITEM_SIZE
;R62                 ror     bx, 1
;R62                 ror     dx, 1
;R62                 loop    set_pri
;R62 start
		mov	di,offset IRQ_Evnt_TBL
		mov	cx,IRQ_Evnt_TBL_Len
                xor     bx,bx
		xor	dx,dx
        set_pri:
		mov	si,word ptr CS:[DI]
		push	di
                call    F000_GetItem_Value
		pop	di
                or      bl, al
                and     bl, 11111101b
                shr     al, 1
                or      dl, al
pri:
		add	di,2
                ror     bx, 1
                ror     dx, 1
                loop    short set_pri
;R62 end
		
		test	byte ptr FLOPPY_TYPE[bp],0ffH	; no floppy installed ?
		jnz	short Fdd_Attach
		and	bl,NOT 01000000b 	;disable IRQ6 primary event
Fdd_Attach:
;R23A ifdef	Cover_Garbage_IRQ12			;R23 - starts
;R23A 		test	bh,10h
;R23A 		jz	short W_IRQ12_Dis
;R23A 		or	PM_RAM:[ALARM_RESUME], 80h	;Wake Event IRQ12 Enabled.
;R23A 		and	bh,not 10h
;R23A 	W_IRQ12_Dis:
;R23A endif;	Cover_Garbage_IRQ12			;R23 - ends
ifdef	VT686					;R52B
		or	bl,00000010b		;R52B Always Enable IRQ1(Keyboard Event).
endif;	VT686					;R52B
                push    dx
                mov     cx, VT586_ACPI + 44h
                mov     al, bl
                call    E000_Set_PMU

                mov     cx, VT586_ACPI + 45h
                mov     al, bh
                call    E000_Set_PMU
                pop     dx
                mov     bx, dx
                mov     cx, VT586_ACPI + 46h

                mov     al, bl
                call    E000_Set_PMU
		mov     cx, VT586_ACPI + 47h	

                mov     al, bh
                call    E000_Set_PMU

	;APM option

		mov	si,offset DGROUP:Wait_APM_Item
		call	F000_GetItem_Value
		mov	PM_RAM:[Wait_APM_Flag],al

	;video off option

		mov	si,offset Video_Off_Item
		call	F000_GetItem_value
		mov	PM_RAM:[Video_Off_Mode],al

;Read DOZE timer setup value and store in SM RAM

;Read Suspend timer setup value and store in SM RAM

;Set Conserve Mode
		mov	cx, VT586_ACPI + 53h
                mov     al, 88h                 ; But the first conserve mode will on afer
                call    E000_Set_PMU                 ; first doze state

		mov	PM_RAM:[PM_MODE1],FULL_ON
		call	Update_PM_Timer		

;enable primary activity monitor

		call	End_Pmi_Handler 	;clear status
ifdef	Break_Suspend_In_Mouse_CMOS	       		   	
                mov     si,offset Mouse_Irq_Item	
                call    F000_GetItem_Value
		shl	al,2
                mov     PM_RAM:[MISC_CNTL1],al		
endif;	Break_Suspend_In_Mouse_CMOS	       		   	

ifdef	HDD_PWRDOWN_IN_SUSPEND					
ifdef   HDD_PWRDOWN_IN_SUSPEND_After_1Min 			
		mov	si,offset HDD_Power_Item		
		Call	F000_GetItem_Value			
 								
		mov	byte ptr PM_RAM:[HDD_OFF_Timer],al	

		cmp 	al,0				   
		jz	short @f			   

		Call	HDD_Timer_Restore
@@:					 
endif;	HDD_PWRDOWN_IN_SUSPEND_After_1Min
endif;	HDD_PWRDOWN_IN_SUSPEND
		mov	cl, 2ch
;R08		mov	al, 1
;R08		call	E000_Set_PMIO
;R16		mov	bx, 01e0h		;R08
		mov	bx, 01e4h		;R16
		call	E000_Get_Set_PMIO	;R08
;Set CPU type

ifdef	VT686				;R52B - starts
		mov	si,offset Evt_INTR_Item
		call	F000_Getitem_Value
		mov	bl,00000000b			; set primary activity
		test	al,1	    
		jz	short @F    
		mov	bl,00000010b
@@:				    
		mov	PM_RAM:[VT586PM_I34h_Value],bl	;default
		mov	cl, 34h
		call	E000_Set_PMIO
	
		mov	si,offset Evt_HDD_Item
		call	F000_GetItem_Value
		or	al,al
		jz	short No_Evt_HDD
		or	PM_RAM:[VT586PM_I34h_Value],00011100b
	No_Evt_HDD:

		mov	si,offset Evt_DMA_Item
		call	F000_GetItem_Value
		or	PM_RAM:[VT586PM_I34h_Value],al

		mov	si,offset Evt_LPT_COM_Item
		call	F000_GetItem_Value
		or	al,al
		jz	short No_Evt_LPT_COM
		or	PM_RAM:[VT586PM_I34h_Value],11100000b
	No_Evt_LPT_COM:

		mov	si,offset M_Evt_VGA_Item
		call	F000_GetItem_Value
		mov	cl, 35h
		call	E000_Set_PMIO
else;	VT686				;R52B - ends
		mov	si,offset Evt_INTR_Item
		call	F000_Getitem_Value
		mov	bl,10000000b			; set primary activity
		test	al,1	    
		jz	short @F    
		mov	bl,10000010b
@@:				    
		mov	al,bl	    
		mov	PM_RAM:[VT586PM_I34h_Value],al	;default
		mov	cl, 34h
		call	E000_Set_PMIO
	
		mov	si,offset Evt_HDD_Item
		call	F000_GetItem_Value
		shl	al,3
		or	PM_RAM:[VT586PM_I34h_Value],al

		mov	si,offset Evt_DMA_Item
		call	F000_GetItem_Value
		or	PM_RAM:[VT586PM_I34h_Value],al

		mov	si,offset Evt_INTR_Item
		call	F000_GetItem_Value
		shl	al,1
		or	PM_RAM:[VT586PM_I34h_Value],al


		mov	si,offset Evt_LPT_COM_Item
		call	F000_GetItem_Value
		shl	al,5
		or	PM_RAM:[VT586PM_I34h_Value],al

		mov	si,offset M_Evt_VGA_Item
		call	F000_GetItem_Value
;R52B ifndef	VT686			;R52
		shl	al,4
		or	PM_RAM:[VT586PM_I34h_Value],al
;R52B ;R52 - starts	
;R52B else;	VT686
;R52B 		mov	cl, 35h
;R52B 		call	E000_Set_PMIO
;R52B endif;	VT686
;R52B ;R52 - ends
endif;	VT686				;R52B

		mov	cl, 38h
		mov	al, 01h
		call	E000_Set_PMIO


ifdef	Have_Fan_Control_Item_In_GPO_Low
	Have_Fan_Control_Item_In_GPO 	EQU	1
endif;	Have_Fan_Control_Item_In_GPO_Low
ifdef	Have_Fan_Control_Item_In_GPO_High
	Have_Fan_Control_Item_In_GPO 	EQU	1
endif;	Have_Fan_Control_Item_In_GPO_High

ifdef   Have_Fan_Control_Item_In_GPO
		extrn	Fan_Control_Item:near
		mov	si, offset DGROUP:Fan_Control_Item 
		call	F000_GetItem_Value	       ;save suspend--> fan
		shl	al,7			       ;stop ?
 		or	PM_RAM:[Video_Off_Mode],al
endif;  Have_Fan_Control_Item_In_GPO

ifdef ACPI_SUPPORT			
		mov	cl, 2ah		; Enable Software SMI
		mov	bl, 40h
		call	E000_Get_Set_PMIO_OR
endif ;ACPI_SUPPORT

;R25B ifdef	Clear_PME_Before_Off				;R25A
;R25B 		call	Record_WOL_Info			;R25A
;R25B endif;	Clear_PME_Before_Off				;R25A


		push	ds			     
		mov	ax,G_RAM		     
		mov	ds,ax			     
		assume	ds:G_RAM		     
		mov	bl,byte ptr ds:[hardware]    
		pop	ds			     
		mov	byte ptr PM_RAM:[PS2_INST],bl
		pop	ds
		popa

		ret
E000_Ct_PM_Init	Endp

;R25A - starts
ifdef	Clear_PME_Before_Off
Record_WOL_Info	proc	near

;R25B                push    ds
;R25B                mov     ax, PM_RAM_SEGMENT
;R25B                mov     ds, ax
;R25B                ASSUME  DS:PM_RAM

		xor     si,si                   ;first device
		mov     ecx,00020000h           ;find class code (Network)
		mov     ax,0b103H               ;find PCI device func. call
		int     1AH
		jc      short No_WOL_Card

;R25B		mov	byte ptr PM_RAM:[WOL1_Bus],bh
;R25B		mov	byte ptr PM_RAM:[WOL1_Device],bl
		mov	al,0F0h			;R25B
		out	72h,al			;R25B
		mov	al,bh			;R25B
		out	73h,al			;R25B
		mov	al,0F1h			;R25B
		out	72h,al			;R25B
		mov	al,bl			;R25B
		out	73h,al			;R25B

		inc     si			;the 2'nd device
		mov     ecx,00020000h           ;find class code (Network)
		mov     ax,0b103H               ;find PCI device func. call
		int     1AH
		jc      short No_WOL_Card

;R25B		mov	byte ptr PM_RAM:[WOL2_Bus],bh
;R25B		mov	byte ptr PM_RAM:[WOL2_Device],bl
		mov	al,0F2h			;R25B
		out	72h,al			;R25B
		mov	al,bh			;R25B
		out	73h,al			;R25B
		mov	al,0F3h			;R25B
		out	72h,al			;R25B
		mov	al,bl			;R25B
		out	73h,al			;R25B

	No_WOL_Card:

;R25B		pop	ds
;R25B                ASSUME  DS:NOTHING


		ret	
Record_WOL_Info	endp
endif;	Clear_PME_Before_Off
;R25A - ends
;R62 start
;==================================================[]
;Input: SI = item offset
;	DI = timer setting offset in PM_RAM
;==================================================[]
Timer_Transfer	proc	near
		call	F000_GetItem_Value		;get setup setting
		xor	ah,ah
		shl	ax,1	
		mov	bx,offset Timer_Value	;value table
		add	bx,ax			;translate
		mov	ax,cs:[bx]		;into reg. value	
		mov	es:[di],ax		;save value in PM_RAM	
		ret
Timer_Transfer	ENDP

IRQ_Evnt_TBL:
		dw	offset DGROUP:IRQ3_Event_Item
		dw	offset DGROUP:IRQ4_Event_Item
		dw	offset DGROUP:IRQ5_Event_Item
		dw	offset DGROUP:IRQ6_Event_Item
		dw	offset DGROUP:IRQ7_Event_Item
		dw	offset DGROUP:IRQ8_Event_Item
		dw	offset DGROUP:IRQ9_Event_Item
		dw	offset DGROUP:IRQ10_Event_Item
		dw	offset DGROUP:IRQ11_Event_Item
		dw	offset DGROUP:IRQ12_Event_Item
		dw	offset DGROUP:IRQ13_Event_Item
		dw	offset DGROUP:IRQ14_Event_Item
		dw	offset DGROUP:IRQ15_Event_Item
IRQ_Evnt_TBL_Len	EQU	($ - offset IRQ_Evnt_TBL)/2
;R62 end

;			value	,unit	
;		----------------------
Timer_Value:
		db	00000000b,0ah		;Disable
		db	00000101b,0ah		;5 Sec  
		db	00001010b,0ah		;10 Sec 
		db	00010100b,0ah		;20 Sec 
		db	00011110b,0ah		;30 Sec 
		db	00101000b,0ah		;40 Sec 
		db	00111100b,0ah		;1 Min  
		db	01111000b,0ah		;2 Min  
		db	00000100b,0bh		;4 Min  
		db	00000110b,0bh		;6 Min  
		db	00001000b,0bh		;8 Min  
		db	00001010b,0bh		;10 Min 
		db	00010100b,0bh		;20 Min 
		db	00011110b,0bh		;30 Min 
		db	00101000b,0bh		;40 Min 
		db	00111100b,0bh		;1 Hour 
endif;	Move_F000_PMU_INIT_To_E000					

IFDEF		USB_SUPPORT
COMPILE_FOR_USBBIOS	=	2
		include	USBBIOS.ASM

E000_Ct_Enable_SMI	proc	near
		mov	cx, VT586 + 48h		;R34 If Onchip USB Enable ?
		call	E000_Get_PMU		;R34
		test	al,04h			;R34
		jnz	short USB_Dis_1		;R34
		mov	cl, 2Ah			
		mov	bl, 10h			
		call	E000_Get_Set_PMIO_OR	
	USB_Dis_1:				;R34
		mov	cl, 2Ch			
		mov	bl, 01h			
		call	E000_Get_Set_PMIO_OR	
ifdef   OverHot_Use_ExtSmi
                mov     cl,24h
                mov     bl,OVERHOT_USE_EXTSMI	;EXTSMI ?
                call    E000_Get_Set_PMIO_OR
endif;	OverHot_Use_ExtSmi

ifdef   LM75_USE_EXTSMI4			
                mov     cl,24h
                mov     bl,10h                  ;;EXTSMI4
                call    E000_Get_Set_PMIO_OR
endif;	LM75_USE_EXTSMI4			
ifdef   LM75_USE_EXTSMI3			
                mov     cl,24h
                mov     bl,08h                  ;;EXTSMI3
                call    E000_Get_Set_PMIO_OR
endif;	LM75_USE_EXTSMI3			

ifdef   VT596					
;R07A  IFDEF	Cover_VT596_E_Version			;R07 - starts
  IFDEF	Disable_EXTSMI_Button			;R07A
                mov     cl,24h
                mov     bl,not 01H		;Disable EXTSMI
                call    E000_Get_Set_PMIO_AND
;R07A  ELSE;	Cover_VT596_E_Version			;R07 - ends
  ELSE;	Disable_EXTSMI_Button			;R07A
                mov     cl,24h
                mov     bl,01H			;EXTSMI
                call    E000_Get_Set_PMIO_OR
;R07A  ENDIF;Cover_VT596_E_Version			;R07
  ENDIF;Disable_EXTSMI_Button			;R07A
;R01 - starts
  IFDEF	Suspend_When_High_In_GPI
                mov     cl,24h				; Enable SMI of GPI.
;R01A		mov     bl,Suspend_When_High_In_GPI
		mov     bl,(01h shl Suspend_When_High_In_GPI)	;R01A
                call    E000_Get_Set_PMIO_OR
  ENDIF;Suspend_When_High_In_GPI

;R01A ifdef	OverHot_Use_Thermal_Pin
  IFDEF	Thermal_Enable			;R01A
    ifdef Thermal_With_SMI		;R01A

                mov     cl,25h
                mov     bl,04h
                call    E000_Get_Set_PMIO_OR
    endif;Thermal_With_SMI		;R01A
;R01A endif;	OverHot_Use_Thermal_Pin
  ENDIF;Thermal_Enable			;R01A
;R01 - ends
endif;	VT596					

ifdef   Suspend_SW_USE_EXTSMI		       	
                mov     cl,24h
                mov     bl,Suspend_SW_USE_EXTSMI   ;EXTSMI
                call    E000_Get_Set_PMIO_OR
endif;	Suspend_SW_USE_EXTSMI		       	

ifdef   Suspend_SW_USE_EXTSMI4			
                mov     cl,24h
                mov     bl,10h                  ;;EXTSMI4
                call    E000_Get_Set_PMIO_OR
endif;	Suspend_SW_USE_EXTSMI4			

		ret
E000_Ct_Enable_SMI	Endp

E000_Ct_Disable_SMI	proc	near
		mov	cl, 2Ah
		mov	bl, not 10h		
		call	E000_Get_Set_PMIO_AND	
		mov	cl, 2Ch			
		mov	bl, NOT 01h		
		call	E000_Get_Set_PMIO_AND	

ifdef   OverHot_Use_ExtSmi
                mov     cl,24h
                mov     bl,not OVERHOT_USE_EXTSMI	;EXTSMI ?
                call    E000_Get_Set_PMIO_AND
endif;	OverHot_Use_ExtSmi
ifdef   LM75_USE_EXTSMI4			
                mov     cl,24h
                mov     bl,not 10h              ;;EXTSMI4
                call    E000_Get_Set_PMIO_AND
endif;	LM75_USE_EXTSMI4			
ifdef   LM75_USE_EXTSMI3			
                mov     cl,24h
                mov     bl,not 08h              ;;EXTSMI3
                call    E000_Get_Set_PMIO_AND
endif;	LM75_USE_EXTSMI3			

ifdef   VT596					
                mov     cl,24h
                mov     bl,not 01H			;EXTSMI
                call    E000_Get_Set_PMIO_AND
;R01 - starts
  IFDEF	Suspend_When_High_In_GPI
                mov     cl,24h				; Disable SMI of GPI.
;R01A		mov     bl, not Suspend_When_High_In_GPI	
		mov	bl, not (01h shl Suspend_When_High_In_GPI)	;R01A
                call    E000_Get_Set_PMIO_AND
  ENDIF;Suspend_When_High_In_GPI
;R01A ifdef	OverHot_Use_Thermal_Pin
  IFDEF	Thermal_Enable			;R01A
    ifdef Thermal_With_SMI		;R01A
                mov     cl,25h
                mov     bl,not 04h
                call    E000_Get_Set_PMIO_AND
    endif;Thermal_With_SMI		;R01A
;R01A endif;	OverHot_Use_Thermal_Pin
  ENDIF;Thermal_Enable			;R01A
;R01 - ends
endif;	VT596					


ifdef   Suspend_SW_USE_EXTSMI		       	
                mov     cl,24h
                mov     bl,not Suspend_SW_USE_EXTSMI 
                call    E000_Get_Set_PMIO_AND
endif;	Suspend_SW_USE_EXTSMI		       	

ifdef   Suspend_SW_USE_EXTSMI4			
                mov     cl,24h
                mov     bl,not 10h              ;;EXTSMI4
                call    E000_Get_Set_PMIO_AND
endif;	Suspend_SW_USE_EXTSMI4			

		ret
E000_Ct_Disable_SMI	Endp

;[]========================================================================[]
;Procedure:	Ct_Usb_Init
;Function:	USB initialization for Chipset dependent module
;		1. Initialize SMI handler
;		2. Check USB legacy support enabled
;		3. Initialize chipset dependent feature for legacy support
;Input:		none
;Output:	CF = 0 USB legacy support enabled and initialization successful
;		CF = 1 USB legacy support disabled or initialization fail
;[]========================================================================[]

Ct_Usb_Init:
		mov	cx, VT586_USB+LEGACY_HI
		mov	bl, USBPIRQDEN		;must be enabled for VIA chip
		call	E000_Get_Set_PMU_OR	

		mov	cx, VT586+48h
		call	E000_Get_PMU
		test	al, 04
		jnz	short Ct_Usb_Init_Fail

;R66 - starts
ifdef	IOTRAP_SUPPORT
                call    Ct_EnableUsbLegacySmi	;Enable Legacy USB SMI
endif	;IOTRAP_SUPPORT
;R66 - ends

		call	E000_Ct_Enable_SMI

		clc
		ret

Ct_Usb_Init_Fail:
		stc
		ret

;[]========================================================================[]
;Procedure:	Ct_Check_Usb_Disabled
;Function:	Check USB host controller enabled and legacy support enabled
;		1. Check host controller enabled
;		2. Check legacy support enabled
;Input:		none
;Output:	CF = 0 Host present and legacy support enabled
;		CF = 1 Host disabled or legacy support disabled
;[]========================================================================[]

Ct_Check_Usb_Disabled:
;R17		mov	cx, VT586+48h
;R17		call	E000_Get_PMU
;R17		test	al, 04
;R17		jnz	short Ct_Check_Usb_Fail
		mov	si, offset ONBD_USB_Item	;R17
		call	F000_GetItem_Value		;R17
		or	al, al				;R17
		jnz	short Ct_Check_Usb_Fail		;R17

		mov	si, offset USB_Legacy_Item
		call	F000_GetItem_Value
;R66 - starts
ifdef	USB_MOUSE_SUPPORT
		xor	dl, dl
		or	al, al
		jz	short Check_Mouse_Item
		or	dl, USBKBSUPPORT
Check_Mouse_Item:
		push	dx
		mov	si, offset USB_Mouse_Item
		call	F000_GetItem_Value
		pop	dx
		or	al, al
		jz	short Check_Mouse_End
		or	dl, USBMSSUPPORT
Check_Mouse_End:
		mov	al, dl
endif	;USB_MOUSE_SUPPORT
;R66 - ends
		or	al, al
		jz	short Ct_Check_Usb_Fail

		clc
		ret

Ct_Check_Usb_Fail:
		stc
		ret

;[]========================================================================[]
;Procedure:	Ct_Usb_ID
;Function:	Report PCI ID of USB host controller
;Input:		none
;Output:	AX = Host controller ID
;[]========================================================================[]

Ct_Usb_ID:
		mov	ax, VT586_USB
		ret

ENDIF		;USB_SUPPORT

;*********************************************************************
;*********************************************************************
;*****                                                           *****
;*****      The following codes                                  *****
;*****      (between label SMI_Handler_Start & SMI_Handler_End)  *****
;*****      should be placed in SMRAM !!!                        *****
;*****                                                           *****
;*********************************************************************
;*********************************************************************
;[]==========================================================================[]
; Change_SMBase:
;       Change SMRAM address to 0A0000h - 0AFFFFh.
;       This is a temporary SMI handler routine.
;[]==========================================================================[]

                ALIGN   4
Change_SMBase   Proc    Near
; Change SMBase
;		mov	cx, VT586 + 84h
;		call	Get_Pci
;		and	al, 0feh
;		call	Set_Pci
		mov	dx,ACPI_Port+28h
		mov	al,0ffh
		out 	dx,al

        ; Change SMBase

                mov     eax,0A0000h
                mov     di,0FEF8h               ;SMBASE location
                mov     dword ptr cs:[di], eax
		mov	dx,ACPI_Port+2dh
		mov	al,01h
		out 	dx,al
; Clear SMI request
;		mov	cx, VT586 + 86h		;SMI Enable register
;		mov	al, 0ffh
;		call	Set_PCI
;		mov	cx, VT586 + 87h		;SMI Enable register
;		mov	al, 0ffh
;		call	Set_PCI

                RSM

Change_SMBase   Endp
Change_SMBase_L EQU     $ - offset Change_SMBase
		ALIGN	4
		Public	SMI_Handler_Start
SMI_Handler_Start	label	near
SMI_Start:
		db	0E9h			;JMP
;R11		dw	?			;Intel_SMI_Start or
;R11						;Cyrix_SMI_Start
		dw	(offset Intel_SMI_Start-offset SMI_Handler_Start-3)
;------------------------------------------------------------------------

;*********************************************************************
;*********************************************************************
;R11 			ALIGN	4
;R11 Stack_top2	EQU	03BFF0h		
_SMBASE_LOC	EQU	0A800h
;R11 		ALIGN	4
;R11 ;Data saving table for CYRIX CPU
;R11 
;R11 SpSave		dw	?
;R11 EspSave		dd	?
;R11 EaxSave		dd	?
;R11 EbxSave		dd	?
;R11 Cr2Save		dd	?
;R11 Cr3Save		dd	?
;R11 
;R11 Gdt		dq	0
;R11 RD_WR		EQU	12h		;read/write
;R11 EX_RD		EQU	1Ah		;execute/readable
;R11 ADDR		=	0
;R11 LIMT		= 	100000h
;R11 G_BIG		=	$ - Gdt
;R11 		dw	(LIMT-1 AND 0ffffh)
;R11 		dw	(ADDR AND 0ffffh)
;R11 		db	((ADDR SHR 16) AND 0ffh)
;R11 		db	RD_WR OR (0 SHL 5) OR (1 SHL 7)
;R11 		db	((LIMT-1 SHR 16) AND 0fh) OR (0 SHL 6) OR (1 SHL 7)
;R11 		db	((ADDR SHR 24) AND 0ffh)
;R11 G_CODE		=	$ - Gdt
;R11 		dw	(LIMT-1 AND 0ffffh)
;R11 		dw	(ADDR AND 0ffffh)
;R11 		db	((ADDR SHR 16) AND 0ffh)
;R11 		db	EX_RD OR (0 SHL 5) OR (1 SHL 7)
;R11 		db	((LIMT-1 SHR 16) AND 0fh) OR (0 SHL 6) OR (1 SHL 7)
;R11 		db	((ADDR SHR 24) AND 0ffh)
;R11 GDTSIZE		=	($ - Gdt)
;R11 
;R11 DsSave		dt	?
;R11 EsSave		dt	?
;R11 SsSave		dt	?
;R11 FsSave		dt	?
;R11 GsSave		dt	?
;R11 LdtSave		dt	?
;R11 TskSave		dt	?
;R11 Dstemp		db	0ffh,0ffh,0,0,0,92h,8fh,0,0,0	;4 Gb segment
;R11 GdtSave		df	0
;R11 GdtNew		dw	GDTSIZE-1
;R11 		dd	?				;address
;R11 IdtSave		df	0
;R11 RealModeIdt	dw	3ffh
;R11 		dd	0
;R11 
;R11 Cyrix_SMI_Start:
;R11 		mov	cs:[_EaxSave],eax
;R11 		mov	cs:[_EspSave],esp
;R11 		mov	cs:[_EbxSave],ebx
;R11 		SVLDT	CS,_LdtSave		;save LDT
;R11 		SVDC	CS,_DsSave,DS		;save DS
;R11 		SVDC	CS,_EsSave,ES		;save ES
;R11 		SVDC	CS,_SsSave,SS		;save SS
;R11 		SVDC	CS,_FsSave,FS		;save FS
;R11 		SVDC	CS,_GsSave,GS		;save GS
;R11 		RSDC	CS,_Dstemp,DS		;set DS
;R11 		RSDC	CS,_Dstemp,SS		;set SS
;R11 		RSDC	CS,_Dstemp,ES		;set ES
;R11 
;R11 		db	066h
;R11 		SGDT	fword ptr cs:[_GdtSave]	;save GDT
;R11 
;R11 		db	066h
;R11 		SIDT	fword ptr cs:[_IdtSave]	;save IDT
;R11 
;R11 		mov	eax,cr2
;R11 		mov	cs:[_Cr2Save],eax		;save CR2
;R11 
;R11 		mov	eax,cr3
;R11 		mov	cs:[_Cr3Save],eax		;save CR3
;R11 
;R11 		mov	ax,_SMBASE_LOC
;R11 		mov	ss,ax		;setup stack
;R11 		mov	esp,STACK_TOP2
;R11 
;R11 	;----------------------------
;R11 	;Clear VM flag in Eflags
;R11 
;R11 		mov	eax,0
;R11 		push	eax
;R11 		mov	eax,_SMBASE_LOC
;R11 		push	eax
;R11 		mov	eax,offset @F
;R11 		sub	eax,offset SMI_Handler_Start
;R11 		push	eax
;R11 		iretd
;R11 	@@:
;R11 	;----------------------------
;R11 
;R11 		db	66h
;R11 		LIDT	fword ptr cs:[_RealModeIdt]		;set real mode IDT
;R11 
;R11 		mov	ax,cs
;R11 		mov	ss,ax
;R11 		mov	esp,Stack_top2
;R11 
;R11 		pushad				
;R11 		mov	dx, 0cf8h		
;R11 		in	eax, dx			
;R11 		push	eax			
;R11 
;R11 ifdef	USB_SUPPORT
;R11 		pushad
;R11 		push	ds
;R11 		push	es
;R11 		call	Usb_Smi
;R11 		pop	es
;R11 		pop	ds
;R11 		popad
;R11 		jnc	short Cyrix_SMI_Exit
;R11 endif	;USB_SUPPORT
;R11 
;R11 		CALL	PMI_Handler
;R11 
;R11 Cyrix_SMI_Exit:
;R11 		pop	eax			
;R11 		mov	dx, 0cf8h		
;R11 		out	dx, eax			
;R11 		popad				
;R11 
;R11 		RSLDT	CS,_LdtSave		;retore LDT
;R11 		RSDC	CS,_DsSave,DS		;restore DS
;R11 		RSDC	CS,_EsSave,ES		;restore ES
;R11 		RSDC	CS,_SsSave,SS		;restore SS
;R11 		RSDC	CS,_FsSave,FS		;restore FS
;R11 		RSDC	CS,_GsSave,GS		;restore GS
;R11 
;R11 		db	66h
;R11 		LGDT	fword ptr cs:[_GdtSave]	;restore GDT
;R11 		db	66h
;R11 		LIDT	fword ptr cs:[_IdtSave]	;restore IDT
;R11 
;R11 		mov	eax,cs:[_Cr2Save]	;restore CR2
;R11 		mov	cr2,eax
;R11 		mov	eax,cs:[_Cr3Save]	;restore CR3
;R11 		mov	cr3,eax
;R11 
;R11 		mov	esp,cs:[_EspSave]
;R11 		mov	eax,cs:[_EaxSave]
;R11 		mov	ebx,cs:[_EbxSave]
;R11 
;R11 		RSM

STACK_TOP1	EQU	03FF0H
		ALIGN	4
Intel_SMI_Start:

; Force Intel SMI offset from 8000h to 0.

		db	0EAh
		dw	(offset @F-offset SMI_Handler_Start)
		dw	_SMBASE_LOC
@@:


		cli
		mov	ax,cs
		mov	ss,ax		;setup stack
		mov	esp,STACK_TOP1

ifdef	USB_SUPPORT
		pushad
		push	ds
		push	es

		mov	dx,0cf8h			;R28
		in	eax,dx				;R28
		push	eax				;R28
		push	dx				;R28

		call	Usb_Smi

		pop	dx				;R28
		pop	eax				;R28
		out	dx,eax				;R28

		pop	es
		pop	ds
		popad
		jc	short @f
		rsm
@@:
endif	;USB_SUPPORT

;far call PMI_handler in F0000h
;PMI_Handler in F0000h use IRET to return to user,
;so pushf before calling

		mov	dx,0cf8h			;R28
		in	eax,dx				;R28
		push	eax				;R28
		push	dx				;R28

		in      al, 70h				;R64
		push	ax				;R64

		CALL	PMI_Handler

		pop	ax				;R64
		out	70h,al				;R64

		pop	dx				;R28
		pop	eax				;R28
		out	dx,eax				;R28

		RSM	;Execute RSM instruction to get back to application

;----------------------------------------------------------------------
;Function :	Set Mode timer with appropriate value
;Input	  :	DS = PM_RAM
;----------------------------------------------------------------------
		ASSUME	DS:PM_RAM
Update_PM_Timer	Proc	Near

		pusha

		mov	si,offset PM_RAM:DOZE_TIME
		mov	al,[PM_MODE1]
		xor	ah,ah

;R09		mov	cx,3
;R09A		mov	cx,3			;R09
		mov	cx,2			;R09A
		sub	cx,ax

		shl	ax,1
		add	si,ax
		xor	bh,bh
		jcxz	short Prg_Timer_Value
	@@:
		mov	bx,[si]
		or	bl,bl
		jnz	short Prg_Timer_Value
		inc	si
		inc	si
		loop	short @B
		xor	bh,bh
Prg_Timer_Value:

		mov	cx,VT586_ACPI + 51h
		mov	al,bl				;set timer value
		call	E000_Set_PMU
		
		mov	cx,VT586_ACPI + 50h
		mov	al,bh				;set timer unit
		call	E000_Set_PMU


		mov	cl, 2ah
		mov	bl, 04h
		call	E000_Get_Set_PMIO_OR
;R14 ifdef	SUSPEND_SWITCH
;R14 		mov	cl, 24h
;R14 		mov	bl,00000010b
;R14 		call	E000_Get_Set_PMIO_OR
;R14 endif	;SUSPEND_SWITCH

		popa
		ret

Update_PM_Timer	Endp

;[]========================================================================[]
;Procedure:	End_PMI_Handler
;
;Function :	Handle the end of PMI
;
;Input    :	DS = PM_RAM
;
;Output   :	None
;
;Note	  :	1. called from every PMI & after PMI requests has been served
;		2. stack available
;[]========================================================================[]
		ASSUME	DS:PM_RAM
		Public	End_PMI_Handler
End_PMI_Handler	Proc	Near

; Clear activity source
		mov	cl, 00h
		call	E000_Set_PMIO_Clear	
		mov	cl, 30h
		call	E000_Set_PMIO_Clear	
		mov	cl, 28h
		call	E000_Set_PMIO_Clear	
		mov	cl, 20h
		call	E000_Set_PMIO_Clear	

		mov	cl, 2ch
		mov	bl, 11h			
		call	E000_Get_Set_PMIO_OR	
		mov	cl, 2dh
		mov	al, 1
		call	E000_Set_PMIO

;R64                in      al, 70h
;R64		out	70h,al
		ret

End_PMI_Handler	Endp

;[]========================================================================[]
;Function :	Routine to handle the power management interrupt (PMI).
;
;Input    :	None
;
;Output   :	if PM using IRQ --- no output!
;		if PM using NMI --- NC: BIOS has handle this NMI for
;					PM chip!
;				    CF: NMI is not issue by PM chip
;
;Destroy:	if PM using IRQ --- destroy None
;		if PM using NMI --- destroy FLAG
;[]========================================================================[]
		Public	PMI_Handler
PMI_Handler	Proc	near

		cli
		pushad
ifdef	S4_Support				
		mov	ax,SEG REAL_IDT_LOC	
		mov	es,ax			
		mov	si,OFFSET REAL_IDT_LOC	
		lidt	fword ptr es:[si]	
endif;	S4_Support				

		push	ds
		push	es
		push	fs
		push	gs

ifndef	Set_APM_According_PM_Setup		
ifdef	Debug_SMI			
		mov	al, _SMI_ENTRY	
		out	80h, al
endif;	Debug_SMI			
endif;	Set_APM_According_PM_Setup		

;-------------- Branch to appropriate PMI Handlers -------------------------

It_Is_PMI:
		mov	ax,PM_RAM_SEGMENT
		mov	ds,ax
		ASSUME	DS:PM_RAM

		mov	cx,VT692 + 63h
		call	E000_Get_PMU
		push	ax

		call	E000_Open_PM_RAM

;-------------- Branch to appropriate PMI Handlers -------------------------
		call	Get_PMI_Source		;Get PMI Handler routine offset in SI
ifdef	Clear_PME_Before_Off				;R25
		call	SMI_Patch_LanBoot		;R25
endif;	Clear_PME_Before_Off				;R25
		call	End_PMI_Handler

		call	E000_Close_PM_RAM

                pop     ax
		mov	cx,VT692 + 63h
		call	E000_Set_PMU

;----------------- PMI request is done! About to leave ISR ------------------
		pop	gs
		pop	fs
		pop	es
		pop	ds
		popad
		RET

PMI_Handler	Endp

ifdef	CRT_Control_Not_In_F000				
		include	CRT_Ctrl.inc			
endif	;CRT_Control_Not_In_F000			

;[]========================================================================[]
;Procedure:	E000_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	E000_Open_PM_RAM
E000_Open_PM_RAM	Proc	Near

		push	ebx
		mov	cx,VT692 + 63h
		mov	bl,00110000b		;enable PM_RAM read/write
		call	E000_Get_Set_PMU_OR	
		pop	ebx			
		ret

E000_Open_PM_RAM	Endp



;[]========================================================================[]
;Procedure:	E000_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	E000_Close_PM_RAM
E000_Close_PM_RAM	Proc	Near

		mov	cx,VT692 + 63h
		mov	bx,0010000011001111b	;shadow read-only
		call	E000_Get_Set_PMU	
		ret

E000_Close_PM_RAM	Endp
;R51 - starts
ifdef	PM_Beep_Speaker
;[]========================================================================[]
;Procedure :    PM_Warning_Beep
;
;Input     :    cx = no of beeps
;
;Output    :    AH bit 1,0    = original speaker status
;               AL bit 765432 = original port 61h status
;                      1,0    = 00
;
;Note      :    speaker will be turned off
;
;[]========================================================================[]
DATA8254        EQU     40H
CTRL8254        EQU     43H

                Public  PM_Warning_Beep
PM_Warning_Beep Proc    Near

                in      al,61h
		push	ax

;------------------ program speaker frequency -------------------------

                mov     al,0B6H
                out     CTRL8254,al
                NEWIODELAY
                mov     al,50h
                out     DATA8254+2,al
                NEWIODELAY
                mov     al,03h
                out     DATA8254+2,al
                NEWIODELAY

;-------------------- save speaker status -----------------------------

                in      al,61h
                mov     ah,al
                and     ah,03h

;------------------------ Beep loop -----------------------------------

Beep_Loop:
                push    cx

                in      al,61h
                NEWIODELAY
                or      al,3
                out     61h,al
                NEWIODELAY

                mov     cx,1000h
                call    Wait_Refr

                and     al,not 03h
                out     61h,al
                NEWIODELAY

                call    Wait_Refr

                pop     cx

                loop    Beep_Loop

		pop	ax
		out	61h, al

                ret

PM_Warning_Beep Endp

;--------------------------------------------
;Input  :       CX = number of Refresh Cycle
;--------------------------------------------
                ALIGN   4
Wait_Refr       Proc    Near
                pusha

Next_Refresh_Cycle:

        @@:
                in      al,61h
                test    al,010h
                jz      short @B
        @@:
                in      al,61h
                test    al,010h
                jnz     short @B

                loop    Next_Refresh_Cycle

                popa
                ret
Wait_Refr       Endp
endif	;PM_Beep_Speaker
;R51 - ends
;---------------------------------------------------------------
; E000_Get_PMU:
;       Reads a value directly from the chipset register.
;
; Input  :      CX = Index register to read
; Output :      AL = Value read
; Destory:      EAX, DX
;---------------------------------------------------------------
                public  E000_Get_PMU
E000_Get_PMU    proc    near

CONFIG_ADDR	EQU	0cf8h

                mov     ax, 8000h               ;enable PCI config.
                shl     eax, 16
                mov     ax, cx
                and     al, not 03h             ;32 bit access for PCI
                mov     dx, CONFIG_ADDR         ;index is 0CF8h
                out     dx, eax
                mov     dl, 0FCh                ;start from 0CFCh
                mov     al, cl
                and     al, 03h
                add     dl, al                  ;byte index to read
                in      al, dx
                ret
E000_Get_PMU    endp

;---------------------------------------------------------------
; E000_Set_PMU:
;       Changes a value in the chipset register.
; Input  :      CX = Index register to change
;               AL = Value to change
; Output :      None
; Destory:      EAX, ECX, DX
;
;---------------------------------------------------------------
                public  E000_Set_PMU
E000_Set_PMU    proc    near
                xchg    ax, cx
                shl     ecx, 16          ;save write value
                xchg    ax, cx           ;restore cx
                mov     ax, 8000h        ;enable PCI config.
                shl     eax, 16
                mov     ax, cx
                and     al, not 03h      ;32 bit access for PCI
                mov     dx, CONFIG_ADDR  ;index is 0CF8h
                out     dx, eax
                mov     dl, 0fch         ;start from 0cfch
                mov     al, cl
                and     al, 03h
                add     dl, al           ;byte index to read
                shr     ecx, 16          ;restore value
                mov     ax, cx
                out     dx, al
                ret

E000_Set_PMU    endp

;---------------------------------------------------------------
; E000_Get_Set_PMU:
;       Read one chipset register value and set it back.
; Input  :      CX = register index
;               BL = value to AND
;               BH = value to OR
; Output :      None
; Destroy:      EAX, ECX, DX
;---------------------------------------------------------------
                public  E000_Get_Set_PMU
E000_Get_Set_PMU      proc    near

                call    E000_Get_PMU
                and     al, bl                  ;AND data
                or      al, bh                  ;OR data
                call    E000_Set_PMU
                ret

E000_Get_Set_PMU      endp
;---------------------------------------------------------------
; E000_Get_Set_PMU_AND:
;       Read one chipset register value and set it back (AND).
; Input  :      CX = register index
;               BL = value to AND
; Output :      None
; Destroy:      EAX, ECX, DX
;---------------------------------------------------------------
                public  E000_Get_Set_PMU_AND
E000_Get_Set_PMU_AND	proc    near

                call    E000_Get_PMU
                and     al, bl                  ;AND data
                call    E000_Set_PMU
                ret

E000_Get_Set_PMU_AND	endp

;---------------------------------------------------------------
; E000_Get_Set_PMU_OR:
;       Read one chipset register value and set it back (OR).
; Input  :      CX = register index
;               BL = value to OR
; Output :      None
; Destroy:      EAX, ECX, DX
;---------------------------------------------------------------
                public  E000_Get_Set_PMU_OR
E000_Get_Set_PMU_OR	proc    near

                call    E000_Get_PMU
                or	al, bl			;AND data
                call    E000_Set_PMU
                ret

E000_Get_Set_PMU_OR	endp

                public  E000_Get_PMIO
E000_Get_PMIO   proc    near
		push	dx
		mov	eax, 80000000h + VT586_ACPI + 48h
		mov	dx, 0cf8h
		out	dx, eax
		mov	dl, 0fch
		in	ax, dx
		mov	dx, ax
		and	dx, NOT 03h
		add	dl, cl
		in	al, dx
		pop	dx
                ret
E000_Get_PMIO	endp

                public  E000_Set_PMIO
E000_Set_PMIO   proc    near
		push	dx
		push	bx
		mov	bl, al
		mov	eax, 80000000h + VT586_ACPI + 48h
		mov	dx, 0cf8h
		out	dx, eax
		mov	dl, 0fch
		in	ax, dx
		mov	dx, ax
		and	dx, NOT 03h
		add	dl, cl
		mov	al, bl
		out	dx, al
		pop	bx
		pop	dx
                ret
E000_Set_PMIO	endp
;[]==============================================================[]
; E000_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	E000_Get_Set_PMIO
E000_Get_Set_PMIO	proc	near
		call	E000_Get_PMIO
		and	al, bl			;AND data
		or	al, bh			;OR data
		call	E000_Set_PMIO
		ret
E000_Get_Set_PMIO	endp

;[]==============================================================[]
; E000_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	E000_Get_Set_PMIO_OR
E000_Get_Set_PMIO_OR	proc	near
		call    E000_Get_PMIO
		or      al, bl			;OR data
		call    E000_Set_PMIO
		ret
E000_Get_Set_PMIO_OR	endp

;[]==============================================================[]
; E000_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	E000_Get_Set_PMIO_AND
E000_Get_Set_PMIO_AND	proc	near
		call    E000_Get_PMIO
		and     al, bl			;AND data
		call    E000_Set_PMIO
		ret
E000_Get_Set_PMIO_AND	endp

;[]==============================================================[]
; E000_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	E000_Set_PMIO_Clear
E000_Set_PMIO_Clear	proc	near
		mov     al, 0ffh		; 0FFh (Write 1 to Clear)
		call    E000_Set_PMIO		; Clear
		ret
E000_Set_PMIO_Clear	endp

;R21 - starts
		Public	E000_GPO_PIN_LOW
E000_GPO_PIN_LOW	Proc	Near
		Call	E000_Control_GPO_Pin
		ret
E000_GPO_PIN_LOW	Endp

		Public	E000_GPO_PIN_High
E000_GPO_PIN_High	Proc	Near
		or	bl,GPO_PIN_HIGH
		Call	E000_Control_GPO_Pin
		ret
E000_GPO_PIN_High	Endp

		Public	E000_Control_GPO_Pin
E000_Control_GPO_Pin	Proc	Near
		pushad

		mov	cl,bl
		and	cl,07h
		mov	bh,01h
		shl	bh,cl

		mov	cl,bl
		and	cl,07fh
		shr	cl,3
		add	cl,4ch

		test	bl,GPO_PIN_HIGH
		mov	bl,bh
		jz	short	_Set_and_

		Call	E000_Get_Set_PMIO_OR
		popad
		ret
	_Set_and_:
		not	bl
		Call	E000_Get_Set_PMIO_AND

		popad
		ret
E000_Control_GPO_Pin	Endp
;R21A - start
		Public	E000_Read_GPI_Pin
E000_Read_GPI_Pin	Proc	Near
		pushad

		mov	cl,bl
		and	cl,07h
		mov	bh,01h
		shl	bh,cl			; BH = bit map
		push	cx			; CL = shift offset

		mov	cl,bl
		and	cl,07fh
		shr	cl,3
		add	cl,48h

		Call	E000_Get_PMIO

		pop	cx
		and	al,bh			; AND BH
		shr	al,cl			; SHR CL

		or	al,al

		popad
		ret
E000_Read_GPI_Pin	Endp
;R21A - end
;R21 - ends

;[]========================================================================[]
;Procedure:	Get_PMI_Source
;
;Function :	To get the corresponding PMI routine according
;		to what kind of PMI it is
;
;Input    :	DS = PM_RAM
;
;Output   :	SI = point to appropriate PMI handler
;		e.g. if it is a suspend request
;		     SI = offset Suspend_Handler
;
;Note	  :	1. Called from PM_Handler
;		2. stack available
;		3. The BIOS PM kernal will issue:
;		   "call si" after calling this routine!
;[]========================================================================[]
		ASSUME	DS:PM_RAM
		Public	Get_PMI_Source
Get_PMI_Source	Proc	Near
		mov	cl, 21h				
		call	E000_Get_PMIO			
		test	al,01h
		jz	short @f
		call	Clear_Modem_Ring_Status
@@:		
		mov	cl, 28h
		call	E000_Get_PMIO
		mov	bl, al
		and	bl,not 80h		;R04
		mov	cl, 01h			; ACPI Chip :
		call	E000_Get_PMIO		; Move Suspend Buttom to
		and	al,01h			; Power Buttom offset 01 bit 0 (status)
		shl	al, 7			; 
		or	bl, al			; bit 7 of BL: ExtSMI status

		mov	cl, 2ah
		call	E000_Get_PMIO
		mov	bh, al
		mov	cl, 03h			; ACPI Chip :
		call	E000_Get_PMIO		; Move Suspend Buttom to
		and	al,01h			; Power Buttom 
		shl	al, 7			; offset 03 bit 0 (On/Off)
		or	al, bh
		and	bl, al
;R54 ifndef	VT686		;R52
;R54 		test	PM_RAM:[VT586PM_I34h_Value], 10h ; if VGA Event is Diabled
;R54 		jz	short @f       			 ; Yes, jump!
;R54 		
;R54 		mov	cl, 30h
;R54                 call    e000_get_PMIO
;R54 		test 	al, 10h	       		; Judgement is video active
;R54 		jz	short @f       		; No, jump!
;R54 		mov	cl, 30h
;R54                 call    E000_Get_PMIO
;R54 		and	al, 10h
;R54                 call    E000_Set_PMIO
;R54 		call	Null_Handler		; Reset timer 
;R54                 jmp	Get_PMI_Source_End
;R54         @@:
;R54 else;	VT686		;R52  - starts
;R54 		mov	cl, 35h	      ; if VGA Event is Diabled
;R54 		call    e000_get_PMIO ; Yes, jump!
;R54 		jz	short VGA_Evt_Disable       			 
;R54 		
;R54 		mov	cl, 31h
;R54                 call    e000_get_PMIO
;R54 		test 	al, 01h	       		; Judgement is video active
;R54 		jz	short VGA_Evt_Disable 	; No, jump!
;R54 		mov	cl, 31h
;R54                 call    E000_Get_PMIO
;R54 		and	al, 01h
;R54                 call    E000_Set_PMIO
;R54 		call	Null_Handler		; Reset timer 
;R54                 jmp	Get_PMI_Source_End
;R54 	VGA_Evt_Disable:
;R54 endif;	VT686		;R52 - ends

ifdef   OverHot_Use_ExtSmi
                mov     cl,20h
                call    e000_get_pmio
                and     al,OverHot_Use_ExtSmi
                xor     bh,bh
                or      bh,al

                test    bh,OverHot_Use_ExtSmi
                jz      short @F
                call    OverHot_Use_Handler
                cmp     bl,0
                je      Get_PMI_Source_End
        @@:
endif;	OverHot_Use_ExtSmi
ifdef   LM75_USE_EXTSMI4			
                mov     cl,20h
                call    e000_get_pmio
                and     al,10h
                shr     al,4
                xor     bh,bh
                or      bh,al

                test    bh,00000001b
                jz      short @F
                call    LM75_OverHot_Handler
                cmp     bl,0
                je      Get_PMI_Source_End
        @@:
endif;	LM75_USE_EXTSMI4			
ifdef   LM75_USE_EXTSMI3			
                mov     cl,20h
                call    e000_get_pmio
                and     al,08h
                shr     al,3
                xor     bh,bh
                or      bh,al

                test    bh,00000001b
                jz      short @F
                call    LM75_OverHot_Handler
                cmp     bl,0
                je      Get_PMI_Source_End
        @@:
endif;	LM75_USE_EXTSMI3			

ifdef   VT596					
                mov     cl,20h
                call    e000_get_pmio
                and     al,01H			
                xor     bh,bh
                or      bh,al

                test    bh,01H		        ;is EXTSMI ? 
                jz      short @F		;no jmp!
	ifdef	Debug_SMI		
		push	ax		
		mov	al,95h		
		out	80h,al		
		pop	ax		
	endif;	Debug_SMI		
  IFDEF	Set_APM_According_PM_Setup
		test	byte ptr PM_RAM:[ALARM_RESUME],80h ; If Setup set PM Disable ?
		jnz	short Skip_ExtSMI_1		   ; No, Jmp !
		call	Set_Full_On_State
		ret
Skip_ExtSMI_1:
  ENDIF;Set_APM_According_PM_Setup
		mov 	al,0aah		
		call	Turbo_SW_Handler  
		jmp	Get_PMI_Source_End
        @@:
;R01 - starts
  IFDEF	Suspend_When_High_In_GPI
                mov     cl,20h
                call    e000_get_pmio
;R01A		and     al,Suspend_When_High_In_GPI
		and     al,(01h shl Suspend_When_High_In_GPI)	;R01A
                xor     bh,bh
                or      bh,al

;R01A		test    bh,Suspend_When_High_In_GPI
                test    bh,(01h shl Suspend_When_High_In_GPI)	;R01A
                jz      short @F
	ifdef	Debug_SMI		
		push	ax		
		mov	al,97h		
		out	80h,al		
		pop	ax		
	endif;	Debug_SMI		
    ifdef Set_APM_According_PM_Setup
		test	byte ptr PM_RAM:[ALARM_RESUME],80h ; If Setup set PM Disable ?
		jnz	short Skip_GPI		   	   ; No, Jmp !
		call	Set_Full_On_State
		ret
Skip_GPI:
    endif;Set_APM_According_PM_Setup
;R01A		call	SW_SMI_Handler
		mov 	al,0aah			;R01A
		call	Turbo_SW_Handler  	;R01A
		jmp	Get_PMI_Source_End
        @@:
  ENDIF;Suspend_When_High_In_GPI

;R01A ifdef   OverHot_Use_Thermal_Pin
  IFDEF	Thermal_Enable			;R01A
    ifdef Thermal_With_SMI		;R01A
                mov     cl,21h
                call    e000_get_pmio
                test    al,04H
                jz	short @F

                call    OverHot_Use_Handler
                cmp     bl,0
                jmp     Get_PMI_Source_End
        @@:
    endif; Thermal_With_SMI		;R01A
;R01A endif;	OverHot_Use_Thermal_Pin
  ENDIF;	Thermal_Enable		;R01A
;R01 - ends
endif; VT596					

ifdef   Suspend_SW_USE_EXTSMI			
                mov     cl,20h
                call    e000_get_pmio
                and     al,Suspend_SW_USE_EXTSMI
                xor     bh,bh
                or      bh,al

                test    bh,Suspend_SW_USE_EXTSMI
                jz      short @F
	ifdef	Debug_SMI		
		push	ax		
		mov	al,96h		
		out	80h,al		
		pop	ax		
	endif;	Debug_SMI		
ifdef	Set_APM_According_PM_Setup
		test	byte ptr PM_RAM:[ALARM_RESUME],80h ; If Setup set PM Disable ?
		jnz	short Skip_ExtSMI_1		   ; No, Jmp !
		call	Set_Full_On_State
		ret
Skip_ExtSMI_1:
endif;	Set_APM_According_PM_Setup
		mov 	al,0aah		
		call	Turbo_SW_Handler  
		jmp	Get_PMI_Source_End
        @@:
endif;	Suspend_SW_USE_EXTSMI		        

ifdef   Suspend_SW_USE_EXTSMI4			
                mov     cl,20h
                call    e000_get_pmio
                and     al,10h
                shr     al,4
                xor     bh,bh
                or      bh,al

                test    bh,00000001b
                jz      short @F
	ifdef	Debug_SMI		
		push	ax		
		mov	al,70h		
		out	80h,al		
		pop	ax		
	endif;	Debug_SMI		
ifdef	Set_APM_According_PM_Setup
		test	byte ptr PM_RAM:[ALARM_RESUME],80h ; If Setup set PM Disable ?
		jnz	short Skip_ExtSMI		   ; No, Jmp !
		call	Set_Full_On_State
		ret
Skip_ExtSMI:
endif;	Set_APM_According_PM_Setup		
		mov 	al,0aah		
		call	Turbo_SW_Handler  
		jmp	Get_PMI_Source_End
        @@:
endif;	Suspend_SW_USE_EXTSMI4			
		cmp	bl,0
		jne	short @F
	ifdef	Debug_SMI
		push	ax
		mov	al,71h
		out	80h,al
		pop	ax
	endif;	Debug_SMI
		call	Null_Handler
		jmp	Get_PMI_Source_End
	@@:

		test	bl,01000000b
		jz	short @F
	ifdef	Debug_SMI
		push	ax
		mov	al,72h
		out	80h,al
		pop	ax
	endif;	Debug_SMI
		call	SW_SMI_Handler
		jmp	Get_PMI_Source_End
	@@:

		test	bl,10000000b
		jz	short @F
	ifdef	Debug_SMI
		push	ax
		mov	al,73h
		out	80h,al
		pop	ax
	endif;	Debug_SMI
		or	byte ptr PM_RAM:[ALARM_RESUME],40h ;R20 Set Press PowerButtom Flag

		call	Turbo_SW_Handler
		jmp	Get_PMI_Source_End
	@@:

		test	bl,00000001b
		jz	short @F
	ifdef	Debug_SMI
		push	ax
		mov	al,74h
		out	80h,al
		pop	ax
	endif;	Debug_SMI
		call	Primary_Active_Handler
		jmp	Get_PMI_Source_End
	@@:

;R54 - starts
ifndef	VT686
		test	PM_RAM:[VT586PM_I34h_Value], 10h ; if VGA Event is Diabled
		jz	short @f       			 ; Yes, jump!
		
		mov	cx, 30h
                call    e000_get_PMIO
		test 	al, 10h	       		; Judgement is video active
		jz	short @f       		; No, jump!
		mov	cx, 30h
                call    E000_Get_PMIO
		and	al, 10h
                call    E000_Set_PMIO
		call	Null_Handler		; Reset timer 
                jmp	Get_PMI_Source_End
        @@:
else;	VT686
		mov	cx, 35h
                call    e000_get_PMIO
		test	al,01h
		jz	short @f
		
		mov	cx, 31h
                call    e000_get_PMIO
		test 	al, 01h	       		; Judgement is video active
		jz	short @f       		; No, jump!
		mov	cx, 31h
                call    E000_Get_PMIO
		and	al, 01h
                call    E000_Set_PMIO
		call	Null_Handler		; Reset timer 
                jmp	Get_PMI_Source_End
        @@:
endif;	VT686
;R54 - ends

		test	bl,00000100b
		jz	short @F
	ifdef	Debug_SMI
		push	ax
		mov	al,75h
		out	80h,al
		pop	ax
	endif;	Debug_SMI
		call	GP0_Timeout_Handler
		jmp	Get_PMI_Source_End
	@@:

		test	bl,00001000b
		jz	short @F
	ifdef	Debug_SMI
		push	ax
		mov	al,76h
		out	80h,al
		pop	ax
	endif;	Debug_SMI
		call	IRQ_Active_Handler
		jmp	Get_PMI_Source_End
	@@:
		test	bl,00000010b
		jz	short @F
	ifdef	Debug_SMI
		push	ax
		mov	al,77h
		out	80h,al
		pop	ax
	endif;	Debug_SMI
		call	Secondary_Timeout_Handler
		jmp	Get_PMI_Source_End
	@@:


		test	bl,00110000b
		jz	short @F
	ifdef	Debug_SMI
		push	ax
		mov	al,78h
		out	80h,al
		pop	ax
	endif;	Debug_SMI
		call	Null_Handler
		jmp	Get_PMI_Source_End
	@@:


Get_PMI_Source_End:
ifdef	Always_LM75_OverHot			
                call    LM75_OverHot_Handler	
endif;	Always_LM75_OverHot			

		ret

Get_PMI_Source	Endp


		ALIGN	4
;[]========================================================================[]
;[]========================================================================[]
Null_Handler	Proc	Near
		call	Set_Full_On_State
		ret
Null_Handler	Endp
;R01 - starts
;R01Aifdef	OverHot_Use_Thermal_Pin
ifdef	Thermal_Enable			;R01A
  IFDEF	Thermal_With_SMI		;R01A
OverHot_Use_Handler    proc    near
;R01A                 xor     al,al
;R01A                 mov     cl,21h
;R01A                 call    e000_get_pmio
;R01A 		test	al,04h
;R01A                 jnz     Warning_Beep_Off
;R01A Warning_Beep_On:
;R01A 		mov     al,0bbh		
;R01A 		out     80h,al		
;R01A 
;R01A                 mov     cl,10h                  ;speed low
;R01A ifdef	Thermal_Percent
;R01A 		mov     al,Thermal_Percent
;R01A else;	Thermal_Percent
;R01A 		mov     al,14h
;R01A endif;	Thermal_Percent
;R01A 
;R01A                 call    e000_set_pmio
;R01A 
;R01A ifndef	No_LM75_Warning_Beep			
;R01A                 mov     al,0b6h                 ;beep on
;R01A                 out     43h,al
;R01A                 newiodelay
;R01A                 mov     al,50h
;R01A                 out     42h,al
;R01A                 newiodelay
;R01A                 mov     al,03h
;R01A                 out     42h,al
;R01A                 newiodelay
;R01A                 in      al,61h
;R01A                 or      al,03h
;R01A                 out     61h,al
;R01A endif;	No_LM75_Warning_Beep			
;R01A                 jmp     short @F
;R01A Warning_Beep_Off:
;R01A 		mov     al,0ffh		
;R01A 		out     80h,al		
;R01A 
;R01A ifndef	No_LM75_Warning_Beep		
;R01A                 in      al,61h                  ;beep off
;R01A                 and     al,not 03h
;R01A                 out     61h,al
;R01A endif;	No_LM75_Warning_Beep
;R01A 
;R01A                 mov     cl, 10h                 ;speed high
;R01A                 mov     al, 10h
;R01A                 call    E000_Set_PMIO
;R01A         @@:
;R08 - starts
		push	bx
                mov     cl,21h
                call    e000_get_pmio
		test	al,04h
                jnz     Warning_Beep_Off
Warning_Beep_On:
		mov     al,0bbh		
		out     80h,al		

ifndef	No_Thermal_Warning_Beep
                mov     al,0b6h                 ;beep on
                out     43h,al
                newiodelay
                mov     al,50h
                out     42h,al
                newiodelay
                mov     al,03h
                out     42h,al
                newiodelay
                in      al,61h
                or      al,03h
                out     61h,al
endif;	No_Thermal_Warning_Beep
                jmp     short @F
Warning_Beep_Off:
		mov     al,0ffh		
		out     80h,al		

ifndef	No_Thermal_Warning_Beep
                in      al,61h                  ;beep off
                and     al,not 03h		;
                out     61h,al			;
endif;	No_Thermal_Warning_Beep

        @@:
                mov     cl,21h			; Clear Thermal Status
                call    e000_get_pmio		;
		and	al,04h			;
                call    e000_set_pmio		;

		pop	bx
;R08 - ends
                ret
OverHot_Use_Handler    endp
  ENDIF;	Thermal_With_SMI		;R01A
;R01A endif;	OverHot_Use_Thermal_Pin
endif;	Thermal_Enable			;R01A
;R01 - ends

ifdef   OverHot_Use_ExtSmi			
OverHot_Use_Handler    proc    near
                xor     al,al
                mov     cl,44h
                call    e000_get_pmio
		test	al,OverHot_Use_ExtSmi
                jnz     Warning_Beep_Off
Warning_Beep_On:
		mov     al,0bbh		
		out     80h,al		

                mov     cl,10h                  ;speed low
ifdef	LM75_Throttling_Percent				
		mov     al,LM75_Throttling_Percent	
else;	LM75_Throttling_Percent				
		mov     al,14h				
endif;	LM75_Throttling_Percent				

                call    e000_set_pmio

ifndef	No_LM75_Warning_Beep			
                mov     al,0b6h                 ;beep on
                out     43h,al
                newiodelay
                mov     al,50h
                out     42h,al
                newiodelay
                mov     al,03h
                out     42h,al
                newiodelay
                in      al,61h
                or      al,03h
                out     61h,al
endif;	No_LM75_Warning_Beep			
                jmp     short @F
Warning_Beep_Off:
		mov     al,0ffh		
		out     80h,al		

ifndef	No_LM75_Warning_Beep		
                in      al,61h                  ;beep off
                and     al,not 03h
                out     61h,al
endif;	No_LM75_Warning_Beep

                mov     cl, 10h                 ;speed high
                mov     al, 10h
                call    E000_Set_PMIO
        @@:
                ret
OverHot_Use_Handler    endp
endif;  OverHot_Use_ExtSmi			
ifdef   LM75_USE_EXTSMI4			
LM75_OverHot_Handler    proc    near

                xor     al,al
                mov     cl,44h
                call    e000_get_pmio
		test	al,10h
                jnz     Warning_Beep_Off
Warning_Beep_On:
		mov     al,0bbh
		out     80h,al

                mov     cl,10h                  ;speed low
ifdef	LM75_Throttling_Percent				
		mov     al,LM75_Throttling_Percent	
else;	LM75_Throttling_Percent				
		mov     al,14h				
endif;	LM75_Throttling_Percent				

                call    e000_set_pmio

ifndef	No_LM75_Warning_Beep			
                mov     al,0b6h                 ;beep on
                out     43h,al
                newiodelay
                mov     al,50h
                out     42h,al
                newiodelay
                mov     al,03h
                out     42h,al
                newiodelay
                in      al,61h
                or      al,03h
                out     61h,al
endif;	No_LM75_Warning_Beep			
                jmp     short @F
Warning_Beep_Off:
		mov     al,0ffh		
		out     80h,al		

ifndef	No_LM75_Warning_Beep			
                in      al,61h                  ;beep off
                and     al,not 03h
                out     61h,al
endif;	No_LM75_Warning_Beep			

                mov     cl, 10h                 ;speed high
                mov     al, 10h
                call    E000_Set_PMIO
        @@:
                ret
LM75_OverHot_Handler    endp
endif;	LM75_USE_EXTSMI4

ifdef   LM75_USE_EXTSMI3			
LM75_OverHot_Handler    proc    near
                mov     al,0bbh
                out     80h,al

                xor     al,al
                mov     cl,44h
                call    e000_get_pmio
                and     al,08h
                or      al,al
                jnz     Warning_Beep_Off
Warning_Beep_On:
                mov     cl,10h                  ;speed low
ifdef	LM75_Throttling_Percent				
		mov     al,LM75_Throttling_Percent	
else;	LM75_Throttling_Percent				
		mov     al,14h				
endif;	LM75_Throttling_Percent				
                call    e000_set_pmio

                mov     al,0b6h                 ;beep on
                out     43h,al
                newiodelay
                mov     al,50h
                out     42h,al
                newiodelay
                mov     al,03h
                out     42h,al
                newiodelay
                in      al,61h
                or      al,03h
                out     61h,al
                jmp     short @F
Warning_Beep_Off:
                in      al,61h                  ;beep off
                and     al,not 03h
                out     61h,al

                mov     cl, 10h                 ;speed high
                mov     al, 10h
                call    E000_Set_PMIO
        @@:
                ret
LM75_OverHot_Handler    endp
endif;	LM75_USE_EXTSMI3

ifdef	APM_IN_SMBASE
	COMPILE_FOR_APMBIOS	=	3
		include	APM.INC
endif	;APM_IN_SMBASE
;R40 -  start
ifdef	Flash_IN_SMBASE
	COMPILE_FOR_APMBIOS	=	3
		include	SMIFlash.INC
endif	;Flash_IN_SMBASE
;R40 - end

;[]========================================================================[]
;
;Function :	Service routine to handle PMI source 0Fh (reg. 35h bit 4-0)
;
;[]========================================================================[]
		ALIGN	4
SW_SMI_Handler	Proc	Near

ifdef	ACPI_Support				
		call	ACPIOnOff		
		jc	short @f		
		ret				
@@:						
endif;	ACPI_Support				
;R20 - starts
;R20B ifdef	ACPI_Support				;R20A	

;R20B		mov	dx, SMI_CMD_RD		;
		mov	dx, ACPI_Port + 2Fh	;R20B
		in	al, dx			;Read SMI_CMD (APMC) port
		mov	bl,al
		and	bl, 0F0h		;
		cmp	bl, 050h		;If SMI Soft Off ?
		jnz	short	Not_SMI_Soft_Off
		call	SMI_Soft_Off
Not_SMI_Soft_Off:
;R20B endif;	ACPI_Support				;R20A
;R20 - ends
		;reset software SMI register
ifndef ACPI_SUPPORT					
		mov	cl, 2ah				;VT3040 status port 
		mov	bl, NOT 40h
		call	E000_Get_Set_PMIO_AND
endif ;ACPI_SUPPORT					

		mov	cl, 28h
		call	E000_Get_PMIO
		call	E000_Set_PMIO
;R37 - starts
ifdef	NoteBook_Power_Management
		mov	al,[Software_SMI_Type]
		cmp	al,SMI_0V_Resume
		jne	short @F
		call	far ptr	Software_SMI_0V_Resume
		cmp	al,SMI_BIOS_RSM
		jne	short @F
		call	far ptr Software_SMI_BIOS_RSM
@@:
endif	;NoteBook_Power_Management
;R37 - ends

ifdef	APM_IN_SMBASE
		call	Chk_Kernel_SMI
		jc	short Not_KRNLSMI
		ret
	Not_KRNLSMI:
endif	;APM_IN_SMBASE
;R40 - start
ifndef	APM_IN_SMBASE
ifdef	Flash_IN_SMBASE
		call	Chk_Kernel_SMI
		jc	short Not_KRNLSMI
		ret
	Not_KRNLSMI:
endif	;Flash_IN_SMBASE
endif	;APM_IN_SMBASE
;R40 - end
		mov	al, [Software_SMI_Type]
		cmp	al, CRT_OFF_REQ
		jne	short @F
ifdef	CRT_Control_Not_In_F000			
		call	Disable_CRT		
else	;CRT_Control_Not_In_F000		
		FAR_Call F000_Disable_CRT, 0F000h
endif	;CRT_Control_Not_In_F000		
		ret
	@@:
		cmp	al, CRT_ON_REQ
		jne	short @F
ifdef	CRT_Control_Not_In_F000			
		call	Enable_CRT		
else	;CRT_Control_Not_In_F000		
		FAR_Call F000_Enable_CRT, 0F000h
endif	;CRT_Control_Not_In_F000		
		ret
	@@:

ifdef	ACPI_SUPPORT
ifdef	S4_SUPPORT
		cmp	al,SMI_S4_Resume
		jne	short @f
		FAR_Call	E_S4_Resume,0E000h
		ret
@@:
endif	;S4_SUPPORT
endif	;ACPI_SUPPORT

	;------------------------------------------------------

		cmp	al, ENABLE_RESUME_TIMER_REQ
		jne	short @F
		ret
	@@:

	;------------------------------------------------------

		cmp	al, DISABLE_RESUME_TIMER_REQ
		jne	short @F
		ret
	@@:

	;------------------------------------------------------

		cmp	al, ENABLE_RESUME_RING
		jne	short @F
 
		mov	ax, word ptr [APM_Modem_IRQ]
		or	byte ptr [WAKE_MODEM0], al
		or	byte ptr [WAKE_MODEM1], ah
		or	word ptr [DEASSERT_STPCLK_IRQS], ax

		ret
	@@:

	;------------------------------------------------------

		cmp	al, DISABLE_RESUME_RING
		jne	short @F
		mov	ax, word ptr [APM_Modem_IRQ]
		not	ax
		and	byte ptr [WAKE_MODEM0], al
		and	byte ptr [WAKE_MODEM1], ah
		and	word ptr [DEASSERT_STPCLK_IRQS], ax

		ret
	@@:
	;---- timer base --------------------------------------------------
		mov	bx,(00000000b shl 8)+11110111b
		cmp	al, DISABLE_PM_REQ
		je	short To_Disable_PM_Timer

		mov	bx,(00001000b shl 8)+11110111b
		cmp	al, ENABLE_PM_REQ
		je	short To_Enable_PM_Timer
		cmp	al, RESTORE_POWERON_D4_REQ
		je	short To_Enable_PM_Timer

		cmp	al, ENABLE_TIMER_REQ
		je	short To_Enable_PM_Timer

		xor	bh, bh
		cmp	al, DISABLE_TIMER_REQ
		jne	short Not_APM_Driver_Req

		mov	Dword ptr [DOZE_TIME], 0		;R36

	To_Disable_PM_Timer:
	To_Enable_PM_Timer:
		mov	cx, VT586_ACPI + 50h
		call	Set_Full_ON_State
		call	E000_Get_Set_PMU
		ret

	Not_APM_Driver_Req:

		cmp	[PM_TimeOut_Type],04h		;Full-On Request?
		je	Set_Full_On_State

		test	[PM_TimeOut_Type],03h		;Any Request?
		jz	short SW_SMI_Exit		;no!
		mov	al,[PM_TimeOut_Type]
		add	al,0D6h
		out	80h,al
		call	Go_PM_State

	SW_SMI_Exit:

		mov	[PM_TimeOut_Type],00h		;clear request

		ret

SW_SMI_Handler	Endp

;R20 - starts
;[]========================================================================[]
; SMI_Soft_Off:
;		Soft Off
;
;Input:		AL Bit3 = 1	not call from Software SMI.(use "call")
;		        = 0	call from Software SMI.
;		AL bit1 = 1  :  Do PowerOff 
;		        = 0  :  Don't PowerOff
;
;		AL = 50h  call from ACPI Wake-Up		;R47
;		AL = 51h  call from S1
;		AL = 55h  call from S5
;		AL = 57h  call from APM16 PowerOff
;		AL = 5Ah  call from PowerButtom to Power Off
;		AL = 58h  call from PowerButtom/EXTSMI Buttom to Suspend
;
;Output:	None.
;[]========================================================================[]
	Public	SMI_Soft_Off	;R49
SMI_Soft_Off	Proc	Near

		call	Enable_Resume_Event

ifdef	SUPERIO_SOFT_OFF_SUPPORT
		call	IO_Soft_Off
endif;	SUPERIO_SOFT_OFF_SUPPORT

		call	Chipset_Soft_Off

		ret
SMI_Soft_Off	Endp


Chipset_Soft_Off	Proc	Near

		test	al,00000010b		;bit 1 = 1 : Do PowerOff 
						;bit 1 = 0 : Don't PowerOff
		jz	short Dont_Turn_Off_ATX_Power

	call	Clear_Power_Buttom_Status	

		xor	cx,cx				
	Delay_For_PowerOff:				
		NEWIODELAY				
	ifdef	More_Delay_Before_PowerOff		
		NEWIODELAY				
		NEWIODELAY				
		NEWIODELAY				
		NEWIODELAY				
		NEWIODELAY				
	endif;	More_Delay_Before_PowerOff		
		loop	short Delay_For_PowerOff	


  IFNDEF	NO_ATX_Judgement
    ifndef	Always_ATX_Power
		;***************************************;
		;  ATX/AT power judge by GPI for 596	;
		;***************************************;
Power_Type_Judge_In_GPI_7_0	=	00h
Power_Type_Judge_In_GPI_15_8	=	00h
Power_Type_Judge_In_GPI_21_16	=	00h
		;***************************************;
		;  Use "ATX_High_AT_Low_In_GPI" Define	;
		;***************************************;
	  ifdef	ATX_High_AT_Low_In_GPI
		if	ATX_High_AT_Low_In_GPI	LE	7
		 if	ATX_High_AT_Low_In_GPI	GE	0
Power_Type_Judge_In_GPI_7_0 = Power_Type_Judge_In_GPI_7_0 or (01h shl ATX_High_AT_Low_In_GPI)
		 endif;	ATX_High_AT_Low_In_GPI	GE	0
		endif;	ATX_High_AT_Low_In_GPI	LE	7
		if	ATX_High_AT_Low_In_GPI	LE	15
		 if	ATX_High_AT_Low_In_GPI	GE	8
Power_Type_Judge_In_GPI_15_8 = Power_Type_Judge_In_GPI_15_8 or (01h shl (ATX_High_AT_Low_In_GPI-8))
		 endif;	ATX_High_AT_Low_In_GPI	GE	8
		endif;	ATX_High_AT_Low_In_GPI	LE	15
		if	ATX_High_AT_Low_In_GPI	LE	21
		 if	ATX_High_AT_Low_In_GPI	GE	16
Power_Type_Judge_In_GPI_21_16 = Power_Type_Judge_In_GPI_21_16 or (01h shl (ATX_High_AT_Low_In_GPI-16))
		 endif;	ATX_High_AT_Low_In_GPI	GE	16
		endif;	ATX_High_AT_Low_In_GPI	LE	21
	  endif;ATX_High_AT_Low_In_GPI
		;***************************************;
		;  Use "ATX_Low_AT_High_In_GPI" Define	;
		;***************************************;
	  ifdef	ATX_Low_AT_High_In_GPI
		if	ATX_Low_AT_High_In_GPI	LE	7
		 if	ATX_Low_AT_High_In_GPI	GE	0
Power_Type_Judge_In_GPI_7_0 = Power_Type_Judge_In_GPI_7_0 or (01h shl ATX_Low_AT_High_In_GPI)
		 endif;	ATX_Low_AT_High_In_GPI	GE	0
		endif;	ATX_Low_AT_High_In_GPI	LE	7
		if	ATX_Low_AT_High_In_GPI	LE	15
		 if	ATX_Low_AT_High_In_GPI	GE	8
Power_Type_Judge_In_GPI_15_8 = Power_Type_Judge_In_GPI_15_8 or (01h shl (ATX_Low_AT_High_In_GPI-8))
		 endif;	ATX_Low_AT_High_In_GPI	GE	8
		endif;	ATX_Low_AT_High_In_GPI	LE	15
		if	ATX_Low_AT_High_In_GPI	LE	21
		 if	ATX_Low_AT_High_In_GPI	GE	16
Power_Type_Judge_In_GPI_21_16 = Power_Type_Judge_In_GPI_21_16 or (01h shl (ATX_Low_AT_High_In_GPI-16))
		 endif;	ATX_Low_AT_High_In_GPI	GE	16
		endif;	ATX_Low_AT_High_In_GPI	LE	21
	  endif;ATX_Low_AT_High_In_GPI

		;***************************************;
		;  ATX => CMOS Protect, AT => Skip	;
		;***************************************;
	  if	Power_Type_Judge_In_GPI_7_0	NE	00h
		mov	dx, ACPI_Port + 48h
		in	al, dx
		test	al, Power_Type_Judge_In_GPI_7_0
	  endif;Power_Type_Judge_In_GPI_7_0	NE	00h
	  if	Power_Type_Judge_In_GPI_15_8	NE	00h
		mov	dx, ACPI_Port + 49h
		in	al, dx
		test	al, Power_Type_Judge_In_GPI_15_8
	  endif;Power_Type_Judge_In_GPI_15_8	NE	00h
	  if	Power_Type_Judge_In_GPI_21_16	NE	00h
		mov	dx, ACPI_Port + 4Ah
		in	al, dx
		test	al, Power_Type_Judge_In_GPI_21_16
	  endif;Power_Type_Judge_In_GPI_21_16	NE	00h

	  ifdef	ATX_High_AT_Low_In_GPI		; If ATX power ?
		jz	short Dont_Turn_Off_ATX_Power		; No,jmp!
	  endif;	ATX_High_AT_Low_In_GPI		; (1:ATX, 0:AT)
	  ifdef	ATX_Low_AT_High_In_GPI		; If ATX power ?
		jnz	short Dont_Turn_Off_ATX_Power		; No,jmp!
	  endif;	ATX_Low_AT_High_In_GPI		; (0:ATX, 1:AT)
	  ifndef	ATX_High_AT_Low_In_GPI
	  ifndef	ATX_Low_AT_High_In_GPI
		mov	dx, ACPI_Port + 05h	; Doing a Sequence let
		mov	al, 01h			; AT Power to work properly
		out	dx, al			; in CMOS Protection Mode.
		mov	al, 11h			;
		out	dx, al			;
		mov	al, 10h			;
		out	dx, al			;
	  endif;	ATX_Low_AT_High_In_GPI
	  endif;	ATX_High_AT_Low_In_GPI
    endif;	Always_ATX_Power

    ifdef	Detect_ATX_Power_By_CMOS_Bank2
		mov	al, 90h			;
		out	72h, al			;
		mov	al, 55h			;
		out	73h, al			;
		mov	al, 90h			;
		out	72h, al			;
		in	al, 73h			;
		cmp	al, 55h			; Is ATX power ?
		jnz	short Dont_Turn_Off_ATX_Power		; No,jump
    endif;	Detect_ATX_Power_By_CMOS_Bank2
  ENDIF;	NO_ATX_Judgement

;R35 - start
ifdef   Power_Type_Selectable
		mov	al,Power_Type_CMOS
		out	70h,al
		in	al,71h
		test	al,Power_Type_CMOS_Bit	; If AT Power ?
		jz	short Dont_Turn_Off_ATX_Power
endif;  Power_Type_Selectable
;R35 - end

ifdef	Disable_EXTSMI_When_PowerOff		;R33
		mov	cl, 24h			;R33
		mov	bl, not 01h		;R33
		call	E000_Get_Set_PMIO_AND	;R33
endif;	Disable_EXTSMI_When_PowerOff		;R33

		mov	cl, 05h			
ifdef	VT596					
		mov	bx, 28E3h		
else;	VT596					
		mov	bx, 20E3h		
endif;	VT596					
		call	E000_Get_Set_PMIO		
Dont_Turn_Off_ATX_Power:
		ret
Chipset_Soft_Off	Endp

Enable_Resume_Event	Proc	Near
;R65A start
ifdef	PME_SUPPORT
ifdef	PME_AlWAYS_Wakeup_SUSPEND
		call	Enable_PME
		cmp	al,57h
		je	short offCall
		cmp	al,5Ah
		jne	short NotoffCall
	offCall:
		call	Restore_PME_Setting
	NotoffCall:
endif	;PME_AlWAYS_Wakeup_SUSPEND
endif	;PME_SUPPORT
;R65A end
		pusha

		cmp	al,50h			;R47
		jz	short ACPI_Wake_Up	;R47
		
		mov	bh,1			; Set RTC Alarm Resume
		call	RTC_Alarm_Resume	;

ifdef	Clear_PME_Before_Off				;R25
		call	SMI_Patch_LanBoot		;R25
endif;	Clear_PME_Before_Off				;R25

ifdef	Record_PWRON_Status
		cmp	al,51h				;R53
		jz	short Dont_Record_PWRON_Status	;R53
		cmp	al,58h				;R53
		jz	short Dont_Record_PWRON_Status	;R53

		mov	al,RdRsmSts_CMOS
		OUT	70h,al
		jcxz	short $+2
		IN	AL,71h
		jcxz	short $+2
		test	al,RdRsmSts_CMOS_Bits
		jnz	Dont_Record_PWRON_Status	; 00 : Set Auto
							; xx : not Set Auto
		mov	al,RdRsmSts_CMOS
		OUT	70h,al
		jcxz	short $+2
		IN	AL,71h
		jcxz	short $+2
		or	al,(RdRsmSts_CMOS_Bits AND (RdRsmSts_CMOS_Bits SHR 1))
		OUT	71h,al
		jcxz	short $+2
Dont_Record_PWRON_Status:
endif;	Record_PWRON_Status

		popa
		ret
;R47 - starts
ACPI_Wake_Up:
		mov	bh,0			; Set RTC Alarm Disabled
		call	RTC_Alarm_Resume	;

		popa
		ret
;R47 - ends
Enable_Resume_Event	Endp

;R65A start
ifdef	PME_SUPPORT
ifdef	PME_AlWAYS_Wakeup_SUSPEND
Enable_PME	proc	near
		pusha
		mov	cl,24h
		mov	bl,20h
		call	E000_Get_Set_PMIO_OR
		popa
		ret
Enable_PME	ENDP

Restore_PME_Setting	proc	near
		pusha

		mov	al,WOL_CMOS
		out	CMOS,al
		NEWIODELAY
		in	al,CMOS+1
		and	al,WOL_CMOS_BIT
		mov	bl,al
		jz	short Dis_PME
		mov	bl,20h
	Dis_PME:
		mov	cl,24h
		call	E000_Get_PMIO
		and	al,not 20h
		or	al,bl
		call	E000_Set_PMIO
		popa
		ret
Restore_PME_Setting	ENDP
endif	;PME_AlWAYS_Wakeup_SUSPEND
endif	;PME_SUPPORT
;R65A end
;[]========================================================================[]
; RTC_Alarm_Resume:
;		Power On ATX or Resume by RTC Alarm.
;
;Input:		BH = 0	Turn Off RTC function.
;		   = 1	Turn On RTC function.
;Output:
;[]========================================================================[]
		ASSUME	DS:PM_RAM
		Public	RTC_Alarm_Resume
RTC_Alarm_Resume	Proc	Near
		pusha
						;BH = 0 : OFF
						;     1 : ON
		pusha

		mov	bl,02h
		test	PM_RAM:[ALARM_RESUME], 08h
		jz	short	@f

		mov	cl, 25h			; Enable RI Resume for VT596
		call	E000_Get_PMIO		;
		or	al,01h			;
		call	E000_Set_PMIO		;

		or	bl,04h
@@:
		mov	cl, 27h			
		call	E000_Get_Set_PMIO_OR
		popa

		test	byte ptr PM_RAM:[ALARM_RESUME],01h ; If Setup set Enable ?
		jz	No_RTC_On_Support ; No, Jmp!

		;-------------------------------;
		; Set RTC Alarm Status & Timer	;
		;-------------------------------;
		cmp	bh,1
		jz	Set_RTC_Alarm_On
Set_RTC_Alarm_Off:
		mov	bl,not 04h		; Set RTC Alarm Resume Off
		mov	cl, 03h
		call	E000_Get_Set_PMIO_AND

		mov	al,0Bh			; Restore RTC Alarm Status
		call	SM_Get_CMOS		; CMOS index 0Bh bit 5.
		mov	ah,al			;
		mov	al,byte ptr PM_RAM:[ALARM_RESUME]
		and	al, 20h			; mask bit5
		or	ah,al			;
		mov	al,0Bh			;
		call	SM_Set_CMOS		;

						; Restore STD Alarm Timer.
		mov	ah,byte ptr PM_RAM:[Alarm_Timer_Second]
		mov	al,01h			;
		call	SM_Set_Cmos		;
		mov	ah,byte ptr PM_RAM:[Alarm_Timer_Minute]
		mov	al,03h			;
		call	SM_Set_Cmos		;
		mov	ah,byte ptr PM_RAM:[Alarm_Timer_Hour]
		mov	al,05h			;
		call	SM_Set_Cmos		;

;R67		mov	ah,0			; Clear Extend Alarm Timer.
;R67		mov	al,7Fh			;
;R67		call	_Set_Cmos		;
		mov	al,7Eh			;
		call	_Set_Cmos		;
		mov	al,7Dh			;
		call	_Set_Cmos		;

		jmp	No_RTC_On_Support	;

Set_RTC_Alarm_On:
		mov	bl, 04h			; Set RTC Alarm Resume On
		mov	cl, 03h
		call	E000_Get_Set_PMIO_OR

		mov	al,0Bh			; Set RTC Alarm ON
		call	SM_Get_CMOS		; CMOS index 0Bh bit 5.
		mov	ah,al			; (Alarm Status).
		and	al, 20h			; mask bit5
		or	byte ptr PM_RAM:[ALARM_RESUME],al
		or	ah,20h			;
		mov	al,0Bh			;
		call	SM_Set_CMOS		;

		mov	al,05h			; Save STD RTC Alarm Timer
		call	SM_Get_Cmos		; Setting.
		mov	byte ptr PM_RAM:[Alarm_Timer_Hour],al
		mov	al,03h			;
		call	SM_Get_Cmos		;
		mov	byte ptr PM_RAM:[Alarm_Timer_Minute],al
		mov	al,01h			;
		call	SM_Get_Cmos		;
		mov	byte ptr PM_RAM:[Alarm_Timer_Second],al

;R67		mov	ah,0			; Clear Extend Alarm Timer.
;R67		mov	al,7Fh			;
;R67		call	_Set_Cmos		;
		mov	al,7Eh			;
		call	_Set_Cmos		;

		mov	bl,0			; Clear Flag

ifndef	Alarm_Hour_CMOS				;R60
		mov	al,4Fh			; Set Hour Alarm Timer.
else	;Alarm_Hour_CMOS			;R60
		mov	al,Alarm_Hour_CMOS	;R60
endif	;Alarm_Hour_CMOS			;R60
		call	SM_Get_Cmos		;
		add	bl,al			; Tset if set zero.
		call	Hex_2_BCD		;
		mov	al,05h			;
		call	SM_Set_Cmos		;

ifndef	Alarm_Min_CMOS				;R60
		mov	al,4Eh			; Set Minute Alarm Timer.
else	;Alarm_Min_CMOS				;R60
		mov	al,Alarm_Min_CMOS	;R60
endif	;Alarm_Min_CMOS				;R60
		call	SM_Get_Cmos		;
		add	bl,al			; Tset if set zero.
		call	Hex_2_BCD		;
		mov	al,03h			;
		call	SM_Set_Cmos		;

ifndef	Alarm_Sec_CMOS				;R60
		mov	al,4Dh			; Set Second Alarm Timer.
else	;Alarm_Sec_CMOS				;R60
		mov	al,Alarm_Sec_CMOS	;R60
endif	;Alarm_Sec_CMOS				;R60
		call	SM_Get_Cmos		;
		add	bl,al			; Tset if set zero.
		call	Hex_2_BCD		;
		mov	al,01h			;
		call	SM_Set_Cmos		;

ifndef	Alarm_Date_CMOS
		mov	al,5Dh			; Set Date Alarm Timer.
else;	Alarm_Date_CMOS
		mov	al,Alarm_Date_CMOS	; Set Date Alarm Timer.
endif;	Alarm_Date_CMOS
		call	SM_Get_Cmos		;
		cmp	bl,0			; If set 00:00:00 ?
		jnz	short _Not_Z		; No,jmp
		dec	al			; Yes => Date = Date - 1.
_Not_Z:						;
		call	Hex_2_BCD		;
		mov	al,7Dh			;
		call	SM_Set_Cmos		;

No_RTC_On_Support:
ifdef	SANLI_Keyboard_Special
		push	ds
		mov	ax,40h
		mov	ds,ax
		and	byte ptr ds:[17h],not 70h
		extrn	UPDATE_LED:NEAR		
		call	UPDATE_LED		
		xor	cx,cx
		loop	short $
		pop	ds
endif;	SANLI_Keyboard_Special
		popa
		ret
RTC_Alarm_Resume	Endp

;[]========================================================================[]
;Function :	Convert one byte Hex number to BCD
;
;Input	:	AL in HEX
;
;Output	:	AH in BCD
;
;Destory :	AL
;[]========================================================================[]
Hex_2_BCD:
		push	cx
		xor	ah,ah
		mov	cl,10
		idiv	cl
		mov	cl,4
		shl	al,cl
		or	ah,al
		pop	cx
		ret
SM_Get_Cmos:
		OUT	70h,AL			; address to interface
		jcxz	short $+2
		IN	AL,71h
		jcxz	short $+2
		ret

SM_Set_Cmos:
		OUT	70h,AL			; address to interface
		jcxz	short $+2
		xchg	al,ah			;ah=index,al=value	   
		OUT	71h,AL			; and output it
		jcxz	short $+2
		ret

_Set_Cmos:
		call	SM_Set_Cmos
		xchg	al,ah
		ret
;R20 - ends

;R25 - starts
ifdef	Clear_PME_Before_Off
;[]========================================================================[]
;Function : Clear PME# status of Intel 558 LAN chip.
;	    The PME# keep at low state while the system is power-on by
;	    LAN. BIOS need to clear PME# status to make PME# to high
;	    state for next wake-on-lan.
;Input    : none
;Output   : none	
;[]========================================================================[]
SMI_Patch_LanBoot	Proc	near
		pushad
;R25A  IFDEF	WAKE_LAN_BY_LID
;R25A		mov	cl, 21h			
;R25A		call	E000_Get_PMIO		
;R25A		test	al,08h			
;R25A		jz	short Not_WOL_Card
;R25A  ENDIF;WAKE_LAN_BY_LID
;R25A  IFDEF	Wake_On_GPI_Support			;
;R25A		mov	cl, 20h			;
;R25A		call	E000_Get_PMIO		;
;R25A		test	al, (01h shl Wake_On_GPI_Support)
;R25A		jz	short Not_WOL_Card
;R25A
;R25A  ENDIF;Wake_On_GPI_Support			;
;R25A
;R25A		xor     si,si                   ;first device
;R25A
;R25A	Clear_PME:				;R56A
;R25A
;R25A		mov     ecx,00020000h           ;find class code (Network)
;R25A		mov     ax,0b103H               ;find PCI device func. call
;R25A
;R25A		int	1AH
;R25A		jc      short Not_WOL_Card
;R25A
;R25A		push	bx			;save Bus No + Device No + Func No
;R25A		mov	ch,bl			;device + function No.
;R25A		mov	cl,34h			;PME# point register
;R25A		call	E000_Get_CfgSpace_Byte
;R25A		pop	bx			;get Bus No + Device No + Func No
;R25A		mov	ch,bl
;R25A		mov	cl,al
;R25A		add	cl,3			
;R25A
;R25A		push	bx			;save Bus No + Device No + Func No
;R25A		push	cx			;save Register index
;R25A		call	E000_Get_CfgSpace_Byte	
;R25A		pop	cx			;get Register index
;R25A		pop	bx			;get Bus No + Device No + Func No
;R25A
;R25A		test	al,11111000b		;PMC bit 31-27 if any bit is
;R25A		jz	short No_PME_Support	;not 0 then PME# not supported
;R25A
;R25A		add	cl,2
;R25A
;R25A		call	E000_Get_CfgSpace_Byte
;R25A		call	E000_Set_CfgSpace_Byte	;write to clear PME# status
;R25A
;R25A	No_PME_Support:
;R25A
;R25A		inc	si			;R56A next device
;R25A		jmp	short Clear_PME		;R56A

;R25A - starts
;R25B		mov	bh,byte ptr PM_RAM:[WOL1_Bus]
;R25B		mov	ch,byte ptr PM_RAM:[WOL1_Device]
;R25B
;R25B		cmp	word ptr [WOL1_Bus],0
;R25B		je	No_WOL2
;R25B
;R25B		mov	bh,byte ptr PM_RAM:[WOL1_Bus]
;R25B		mov	ch,byte ptr PM_RAM:[WOL1_Device]

		mov	al,0F0h			;R25B
		out	72h,al			;R25B
		jmp	$+2			;R25B
		in	al,73h			;R25B
		mov	bh,al			;R25B
		mov	al,0F1h			;R25B
		out	72h,al			;R25B
		jmp	$+2			;R25B
		in	al,73h			;R25B
		mov	ch,al			;R25B

		mov	bl,ch			;R25B
		or	bx,bx			;R25B
		jz	No_WOL2			;R25B

		mov	cl,34h			;PME# point register
		call 	E000_Get_CfgSpace_Byte
		mov	cl,al
		add	cl,3			
		call 	E000_Get_CfgSpace_Byte
		
		test	al,11111000b		;PMC bit 31-27 if any bit is
		jz	short No_WOL1		;not 0 then PME# not supported

		add	cl,2
		call 	E000_Get_CfgSpace_Byte
		call 	E000_Set_CfgSpace_Byte
		
	No_WOL1:

;R25B		cmp	word ptr [WOL2_Bus],0
;R25B		je	short No_WOL2
;R25B
;R25B		mov	bh,byte ptr PM_RAM:[WOL2_Bus]
;R25B		mov	ch,byte ptr PM_RAM:[WOL2_Device]

		mov	al,0F2h			;R25B
		out	72h,al			;R25B
		jmp	$+2			;R25B
		in	al,73h			;R25B
		mov	bh,al			;R25B
		mov	al,0F3h			;R25B
		out	72h,al			;R25B
		jmp	$+2			;R25B
		in	al,73h			;R25B
		mov	ch,al			;R25B

		mov	bl,ch			;R25B
		or	bx,bx			;R25B
		jz	No_WOL2			;R25B

		mov	cl,34h			;PME# point register
		call 	E000_Get_CfgSpace_Byte
		mov	cl,al
		add	cl,3			
		call 	E000_Get_CfgSpace_Byte
		
		test	al,11111000b		;PMC bit 31-27 if any bit is
		jz	short No_WOL1		;not 0 then PME# not supported

		add	cl,2
		call 	E000_Get_CfgSpace_Byte
		call 	E000_Set_CfgSpace_Byte

	No_WOL2:
;R25A - ends
;R25A	Not_WOL_Card:				
;R25A
;R25A  IFDEF	WAKE_LAN_BY_LID
;R25A	fuc_:					
;R25A		mov	cl, 21h			
;R25A		mov	bl, 08h			
;R25A		call	E000_Get_Set_PMIO_AND	
;R25A		call	E000_Get_PMIO		
;R25A		test	al,08h			
;R25A		jnz	short fuc_		
;R25A
;R25A  ENDIF;WAKE_LAN_BY_LID
;R25A  IFDEF	Wake_On_GPI_Support			;
;R25A	fuc_:					
;R25A		mov	cl, 20h			;
;R25A		mov	bl, (01h shl Wake_On_GPI_Support)
;R25A		call	E000_Get_Set_PMIO_AND	;
;R25A		call	E000_Get_PMIO		;
;R25A		test	al, (01h shl Wake_On_GPI_Support)
;R25A		jnz	short fuc_		
;R25A
;R25A
;R25A  ENDIF;Wake_On_GPI_Support			;

;R25B - starts
  IFDEF	WAKE_LAN_BY_LID
	fuc_:					
		mov	cl, 21h			
		mov	bl, 08h			
		call	E000_Get_Set_PMIO_AND	
		call	E000_Get_PMIO		
		test	al,08h			
		jnz	short fuc_		
  ENDIF;WAKE_LAN_BY_LID
  IFDEF	Wake_On_GPI_Support
	fuc_:					
		mov	cl, 20h			
		mov	bl, (01h shl Wake_On_GPI_Support)
		call	E000_Get_Set_PMIO_AND	
		call	E000_Get_PMIO		
		test	al, (01h shl Wake_On_GPI_Support)
		jnz	short fuc_		
  ENDIF;Wake_On_GPI_Support			
  IFDEF	WAKE_LAN_BY_GPI1
	fuc_:					
		mov	cl, 20h
		mov	bl, 02h
		call	E000_Get_Set_PMIO_AND	
		call	E000_Get_PMIO		
		test	al,02h			
		jnz	short fuc_		
  ENDIF;WAKE_LAN_BY_GPI1
  IFDEF	WAKE_LAN_BY_RI
	fuc_:					
		mov	cl, 21h			
		mov	bl, 01h
		call	E000_Get_Set_PMIO_AND	
		call	E000_Get_PMIO		
		test	al,01h			
		jnz	short fuc_		
  ENDIF;WAKE_LAN_BY_RI
;R25B - ends

		popad
		ret
SMI_Patch_LanBoot	endp

E000_Get_CfgSpace_Byte:
                mov     ax,8000H        ;enable PCI config.
		or	al,bh		;set bus no.
                shl     eax,16
                mov     ax,cx
                and     al,NOT 03h      ;32 bit access for PCI
                mov     dx,CONFIG_ADDR  ;index is 0cf8h
                out     dx,eax
                add     dl,4            ;start from 0cfch
                mov     al,cl
                and     al,03h
                add     dl,al           ;byte index to read
                in      al,dx
                ret

;[]========================================================================[]
;[]========================================================================[]
                ALIGN   4
E000_Set_CfgSpace_Byte:
                xchg    ax,cx
                shl     ecx,16          ;save value
                xchg    ax,cx           ;restore cx
                mov     ax,8000H        ;enable PCI config.
		or	al,bh		;set bus no.
                shl     eax,16
                mov     ax,cx
                and     al,NOT 03h      ;32 bit access for PCI
                mov     dx,CONFIG_ADDR  ;index is 0cf8h
                out     dx,eax
                add     dl,4            ;start from 0cfch
                mov     al,cl
                and     al,03h
                add     dl,al           ;byte index to read
                mov     eax,ecx
                shr     eax,16
                out     dx,al
                ret
endif;	Clear_PME_Before_Off
;R25 - ends

;[]========================================================================[]
;
;Function :	Service routine to handle PMI source
;
;[]========================================================================[]
			ALIGN	4
Secondary_Timeout_Handler	Proc	Near

		mov	al,[POST_MODE]
		out	80h,al	      

		mov	cl, 28h
		mov	al, 02h
		call	E000_Set_PMIO
		mov	[PM_TimeOut_Type],03h	;Suspend request
		jmp	Go_suspend
		ret
Secondary_Timeout_Handler	Endp

;[]========================================================================[]
;
;Function :	Service routine to handle PMI source 
;
;[]========================================================================[]
			ALIGN	4
DRQ_Active_Handler	Proc	Near
		call	Set_Full_On_State
		ret
DRQ_Active_Handler	Endp

;[]========================================================================[]
;
;Function :	Service routine to handle EXT SMI1 source 
;
;[]========================================================================[]
Turbo_SW_Handler	Proc	Near

ifdef   VT596				
		push	ax		
endif;  VT596				
ifdef   Suspend_SW_USE_EXTSMI		
		push	ax		
endif;   Suspend_SW_USE_EXTSMI		

ifdef   Suspend_SW_USE_EXTSMI4		
		push	ax		
endif;   Suspend_SW_USE_EXTSMI4		

		mov	al,55h NMI_OFF			; CMOS [55h] :
		out	70h,al			; bit 5 : Alarm_Item of setup
						; bit 6 : Modem Ring
		in	al,71h			; bit 7 : PWRBTN_OVRD_Item of setup
		mov	bl,al			; Get setup setting ?
		and	al,20h
		shr	al,5
		mov	cl,bl		; Get bit 7 set to [ALARM_RESUME] bit 1
		and	cl,80h
		shr	cl,6		
		or	al,cl
		and	bl,40h		; Get bit 6 set to [ALARM_RESUME] bit 3
		shr	bl,3
		or	al,bl
		or	PM_RAM:[ALARM_RESUME], al
						; PM_RAM:[ALARM_RESUME] :
						; bit 0 : Alarm_Item of setup
						; bit 1 : PWRBTN_OVRD_Item of 
;R20		mov	al,1				; Turn On
;R20		call	far ptr RTC_Alarm_Resume

ifdef  VT596 					
		pop	ax
                cmp	al,0aah			
;R20B		je	short @f		
		je	short Not_Power_Button_		;R20B
endif;  VT596					

ifdef   Suspend_SW_USE_EXTSMI			
		pop	ax			
                cmp	al,0aah			
;R20B		je	short @f		
		je	short Not_Power_Button_		;R20B
endif;   Suspend_SW_USE_EXTSMI			

ifdef   Suspend_SW_USE_EXTSMI4		
		pop	ax		
                cmp	al,0aah		
;R20B		je	short @f	
		je	short Not_Power_Button_		;R20B
endif;   Suspend_SW_USE_EXTSMI4		
;R20		test	byte ptr PM_RAM:[ALARM_RESUME],02h ; If Setup set Instant-off ?
;R20		jz	short @f
;R20 ;R16		mov	cl, 05h
;R20 ifdef	VT596					
;R20 		call	Clear_Power_Buttom_Status	;R16
;R20 		mov	bx, 28E3h		
;R20 else;	VT596					
;R20 		mov	bx, 20E3h
;R20 endif;	VT596					
;R20 		mov	cl, 05h				;R16
;R20 		call	E000_Get_Set_PMIO
;R20B @@:
ifndef	Disable_ExtSMI_SW_In_POST
  		push	es
  		mov	ax,G_RAM
  		mov	es,ax
  		assume	es:G_RAM
;R19  		pop	es				
  		test	word ptr es:[INIT_ERR_FLG],IEF_IN_POST
  		pop	es				;R19
;R20  		jnz	short Skip_EXTSMI_In_POST
;R20 - starts
  		jz	short EXTSMI_Not_In_POST
		mov	al,58h
		test	byte ptr PM_RAM:[ALARM_RESUME],02h ; If Setup set Instant-off ?
		jz	short @f
		mov	al,5Ah
	@@:
		call	SMI_Soft_Off
  		jmp	short Skip_EXTSMI_In_POST
EXTSMI_Not_In_POST:
;R20 - ends
endif;	Disable_ExtSMI_SW_In_POST
Not_Power_Button_:					;R20B
ifndef	USB_Legacy_PM_Support				
ifndef	USB_PM_SUPPORT
	call	Clear_Power_Buttom_Status	
endif;	USB_PM_SUPPORT					
endif;	USB_Legacy_PM_Support				
ifdef Set_APM_According_PM_Setup		
		test	byte ptr PM_RAM:[ALARM_RESUME],80h ; If Setup set PM Disable ?
		jnz	short @f			   ; No, Jmp !
		call	Set_Full_On_State
		ret
@@:
endif; Set_APM_According_PM_Setup		
ifdef SUSPEND_SWITCH
		mov	cl, 2Dh			; Clear SMI Lock
		mov	bl, not 0FEh		; Then do PM function
		call	E000_Get_Set_PMIO_AND
		mov	cx,VT586_ACPI + 50h
		mov	bl,0f0h			;disable GP0 timer
		call	E000_Get_Set_PMU_AND	

		mov	si,offset Suspend_Setting
		mov	[PM_TimeOut_Type],03h
ifndef Extrn_SMI_Control_By_Suspend_TimeOut_Mode	
		or	byte ptr[ALARM_RESUME],10h ; Assign User extrn SMI
endif ;Extrn_SMI_Control_By_Suspend_TimeOut_Mode	

		call	Set_PM_State
ifndef Extrn_SMI_Control_By_Suspend_TimeOut_Mode	
		and	byte ptr[ALARM_RESUME],not 10h	; Clear Status
endif ;Extrn_SMI_Control_By_Suspend_TimeOut_Mode	
		call	Clear_Power_Buttom_Status	;R16A
;R20		mov	al,0				;R16A Turn Off
;R20		call	far ptr RTC_Alarm_Resume	;R16A
Skip_EXTSMI_In_POST:					
		call	Clear_Power_Buttom_Status	;R19
		call	Set_Full_On_State	
else	;SUSPEND_SWITCH
		call	Clear_Power_Buttom_Status	;R16A
;R20		mov	al,0				;R16A Turn Off
;R20		call	far ptr RTC_Alarm_Resume	;R16A
		mov	bh,0				;R20 Turn Off
		call	RTC_Alarm_Resume		;R20
Skip_EXTSMI_In_POST:					
		call	Clear_Power_Buttom_Status	;R19
		call	Set_Full_On_State
endif	;SUSPEND_SWITCH
;R16A		call	Clear_Power_Buttom_Status	
;R16A		mov	al,0				; Turn Off
;R16A		call	far ptr RTC_Alarm_Resume
		ret
Turbo_SW_Handler	Endp
Delay_About_1_Second	Proc	Near
		push	cx

		xor cx,cx
_delay:
		newiodelay
		newiodelay
		loop short _delay

		pop cx
		ret
Delay_About_1_Second	Endp

Clear_Power_Buttom_Status	Proc	Near
@@:
		mov	cl, 01h			; Clear Power Buttom Status
		call	E000_Get_PMIO		; till Power Buttom opened.
		call	E000_Set_PMIO
		call	Delay_About_1_Second
		mov	cl, 01h
		call	E000_Get_PMIO
		test	al,01h
		jnz	short	@b

ifdef	VT596
                mov     cl,20h
		call	E000_Get_PMIO		; till Power Buttom opened.
		call	E000_Set_PMIO
		call	Delay_About_1_Second
                mov     cl,20h
		call	E000_Get_PMIO
		test	al,01H
		jnz	short	@b
endif;	VT596

ifdef	Suspend_SW_USE_EXTSMI
                mov     cl,20h
		call	E000_Get_PMIO		; till Power Buttom opened.
		call	E000_Set_PMIO
		call	Delay_About_1_Second
                mov     cl,20h
		call	E000_Get_PMIO
		test	al,Suspend_SW_USE_EXTSMI
		jnz	short	@b
endif;	Suspend_SW_USE_EXTSMI

ifdef	Suspend_SW_USE_EXTSMI4		
                mov     cl,20h
		call	E000_Get_PMIO		; till Power Buttom opened.
		call	E000_Set_PMIO
		call	Delay_About_1_Second
                mov     cl,20h
		call	E000_Get_PMIO
		test	al,10h
		jnz	short	@b
endif;	Suspend_SW_USE_EXTSMI4		

		ret
Clear_Power_Buttom_Status	Endp

;[]========================================================================[]
;
;Function :	Service routine to handle PMI source 
;
;[]========================================================================[]
			ALIGN	4
IRQ_Active_Handler	Proc	Near
		call	Set_Full_On_State
		ret
IRQ_Active_Handler	Endp

;[]========================================================================[]
;
;Function :	Service routine to handle PMI source
;
;[]========================================================================[]
			ALIGN	4
Primary_Active_Handler	Proc	Near

		call	Set_Full_On_State
		ret
Primary_Active_Handler	Endp

;[]========================================================================[]
;
;Function :	Service routine to handle PMI source
;
;[]========================================================================[]
			ALIGN	4
GP0_Timeout_Handler	Proc	Near
	ifdef	Blink_Suspend_LED_In_GPO0			;R50
	  ifdef	No_StandBy_Blink_LED				;R50
		ifdef	VT686					;R50
		mov	cx,VT586_ACPI + 54h			;R50
		mov	bx,01FCh				;R50
		call	E000_Get_Set_PMU			;R50
		endif;	VT686					;R50
	  endif;No_StandBy_Blink_LED				;R50
	endif;	Blink_Suspend_LED_In_GPO0			;R50

		mov	cl, 28h
		mov	al, 04h
		call	E000_Set_PMIO

		mov	al, [VT586PM_50h_Value]       ;Disable GP0
		and	al, 11110000b
		mov	cx,VT586_ACPI + 50h
		call	E000_Set_PMU                 

		mov	al,[PM_MODE1]
		cmp	al,FULL_ON			;Now Full-On mode?
		mov	si,offset Doze_Setting
		mov	[PM_TimeOut_Type],01h		;Doze request
		je	short @F			;yes

		mov	si,offset Suspend_Setting
		mov	[PM_TimeOut_Type],03h		;Suspend request
	@@:
		call	Set_PM_State
		mov	cl, 2Dh			; Clear SMI Lock
		mov	bl, not 0FEh		; Then do PM function
		call	E000_Get_Set_PMIO_AND
		ret

GP0_Timeout_Handler	Endp

;-----------------------------------------------------------
;Function :	1. reg.30h bit 1,0 --> 00b (Full-On Mode)
;		2. set PM_RAM:[PM_MODE]=FULL_ON
;		3. Enable CRT display
;		4. set CPU to its full speed
;
;Input	  :	DS = PM_RAM
;
;Output	  :	None
;-----------------------------------------------------------
		ASSUME	DS:PM_RAM
Set_Full_On_State	Proc	Near

		pusha

		cmp	[PM_MODE1],SUSPEND_MODE
		jne	short @F
		mov	[APMEventSave],RESUME_NORMAL_NOTIFY
@@:

;******************************
;1. Chipset's MUSTs for wake up
;******************************

	;clear STPCLK#

		mov	cl, 10h
		mov	al, 10h
		call	E000_Set_PMIO

;*******************************************
;2. Restore all items which has been changed 
;*******************************************

		mov	[PM_MODE1],FULL_ON
ifdef	CRT_Control_Not_In_F000			
		call	Enable_CRT		
else	;CRT_Control_Not_In_F000		
		FAR_Call F000_Enable_CRT, 0F000h
endif	;CRT_Control_Not_In_F000		

;********************************************************
;3. clear any possible flags of APM & of this BIOS itself
;********************************************************

		and	[PM_CTRL_FLAG],not CPU_IDLE_FLAG	;Clear Idle flag
		mov	[PM_TimeOut_Type],00h			

;***********************************
;4. set indications for FULL-ON mode
;***********************************

		mov	[PM_TimeOut_Type],0	;Full_On_Mode
		mov	[PM_MODE],FULL_ON
		mov	al,PMI_FULLON		; debug port
		out	80h,al			; debug port

;******************
;5. update PM timer
;******************

		mov	cl, 2ah
		mov	bl, 11111100b		;disable primary
		call	E000_Get_Set_PMIO_AND	

		mov	al,PMI_FULLON
		out	80h,al
		mov	[PM_MODE],FULL_ON

		mov	[PM_TimeOut_Type],00h		;clear request	

		call	Update_PM_Timer

		mov	cl, 34h
;R02		mov	al,10000000b		; set activity dector default
		mov	al,PM_RAM:[VT586PM_I34h_Value]	;R02
		call	E000_Set_PMIO

ifdef	Suspend_LED_Control			
;Set bit 6 to "1" to turn on suspend LED		
		mov	ah,1				
		call	Send_Smout			
endif;	Suspend_LED_Control			

ifdef	LID_SUPPORT					;R13
		mov	cl, 23h				;R13
		mov	bl, 10h				;R13
		call	E000_Get_Set_PMIO_AND		;R13
endif;	LID_SUPPORT					;R13

;R41 - start
ifdef	W83782D_CPUFAN_CNTL_IN_SUSPEND
		Call	Turn_On_CPU_Fan
endif;	W83782D_CPUFAN_CNTL_IN_SUSPEND
;R41 - end
;R57 - start
ifdef	ADM9240_CPUFAN_CNTL_IN_SUSPEND
		Call	Turn_On_Fan
endif;	ADM9240_CPUFAN_CNTL_IN_SUSPEND
;R57 - end

;R42A - start
ifdef	Superio_Support_Sensor
		Call	Turn_On_CPU_Fan
endif	;Superio_Support_Sensor
;R42A - end
	ifdef	Blink_Suspend_LED_In_GPO0			;R50
		ifdef	VT686					;R50
		mov	cx,VT586_ACPI + 54h			;R50
		mov	bl,not 03h				;R50
		call	E000_Get_Set_PMU_AND			;R50
		endif;	VT686					;R50
	endif;	Blink_Suspend_LED_In_GPO0			;R50

		popa
		ret

Set_Full_On_State	Endp

;[]========================================================================[]
;input	:	DS = PM_RAM
;[]========================================================================[]
		ASSUME	DS:PM_RAM
Set_PM_State	Proc	Near

		cmp	byte ptr [si],00h
		jne	short PM_State_Yes
ifndef Extrn_SMI_Control_By_Suspend_TimeOut_Mode	
		test	byte ptr[ALARM_RESUME],10h ; if user extrn SMI
		jnz	short PM_State_Yes	   ; Yes,jmp
endif ;Extrn_SMI_Control_By_Suspend_TimeOut_Mode	
		cmp	si,offset Suspend_Setting
		jne	short @F
		ret
	@@:
		inc	[PM_TimeOut_Type]
		inc	[PM_TimeOut_Type]
		inc	si
		jmp	short Set_PM_State

PM_State_Yes:

		call	Enable_WakeUp_Source

ifdef	ADVANCE_POWER_MANAGEMENT

		xor	bl,bl					
		test	byte ptr [Wait_APM_Flag],0FFh		;user care APM?
		jz	short Dont_Care_APM			;no!
		test	[APM_STATUS],IS_CONNECT_CALL_MADE	;APM connected?
		jz	short Dont_Care_APM			;APM not connected!
		test	[EXTEND_APM_STATUS],IS_PM_ENGAGED	
		jz	short @F				


		cmp	[PM_TimeOut_Type],03h			;Suspend request?
		jne	short Idle_Req				;no!
		mov	[APMEventSave],SUSPENDREQUEST      	;make APM request
		jmp	short Wait_For_APM
Idle_Req:
		test	[EXTEND_APM_STATUS],APM_16BIT_FUNC_MODE
		mov	bl,6				       
		jnz	short Dont_Care_APM		       

		or	[PM_CTRL_FLAG],CPU_IDLE_FLAG
		mov	[PM_MODE],FULL_ON
Wait_For_APM:
		ret
Dont_Care_APM:
		mov	al,[PM_TimeOut_Type]
		or	al,0D0h
		out	80h,al
;R63 start
ifdef	PM_WORK_UNDER_APM_ONLY
;R65		test	byte ptr [Wait_APM_Flag],0F0h
		test	byte ptr [APM_STATUS],0F0h	;R65
		jnz	short APM_HOOK
		mov	PM_RAM:[DOZE_Time],0
		mov	PM_RAM:[Doze_Setting],0
		mov	PM_RAM:[SUSPEND_TIME],0
		mov	PM_RAM:[Suspend_Setting],0
		mov	[PM_TimeOut_Type],0
		mov	al,0ffh
		out	80h,al
		test	byte ptr PM_RAM:[ALARM_RESUME],40h ; If Press PowerButtom ?
		jz	short APM_HOOK			   ;No
		test	byte ptr PM_RAM:[ALARM_RESUME],02h ; If Setup set Instant-off ?
		jz	short APM_HOOK			   ;No
		mov	[PM_TimeOut_Type],3
APM_HOOK:
endif	;PM_WORK_UNDER_APM_ONLY
;R63 end

endif;	ADVANCE_POWER_MANAGEMENT
Go_PM_State:

;-------------------------------------------
;1. disable CRT according to setup settings
;-------------------------------------------

		mov	dl,4
		sub	dl,[PM_TimeOut_Type]

		cmp	[Video_Off_Mode],dl
		jb	short @F
ifdef	CRT_Control_Not_In_F000			
		call	Disable_CRT		
else	;CRT_Control_Not_In_F000		
		FAR_Call F000_Disable_CRT, 0F000h
endif	;CRT_Control_Not_In_F000		
	@@:

;-------------------------------------------
;2. Fix AT clock to 7.19Mhz
;-------------------------------------------

;-----------------------------------------------------------
;3. prg turbo/deturbo status according to MODBIN settings
;4. Prg General Purpose IO Pins according to MODBIN settings
;-----------------------------------------------------------

		cmp	[PM_TimeOut_Type],01h
		jne	short Seting_End

		mov	cl, 10h			;set Doze mode
		mov	al, 18h			;
		call	E000_Set_PMIO		;Enable throttling 

Seting_End:

;--------------------------------------------------------
;5. set indications
;--------------------------------------------------------

		mov	bh,[PM_TimeOut_Type]
		mov	[PM_MODE1],bh
		mov	[PM_MODE],bh

	;flash LED

;--------------------------------------------------------
;6. enable trigger source
;--------------------------------------------------------

		cmp	[PM_TimeOut_Type],3		;Suspend request?
		jne	short Not_Suspend_Request

		call	Go_Suspend

ifdef	USB_SUPPORT
 ifdef	USB_PM_SUPPORT				
		pushad
		push	ds
		push	es
		call	Usb_Smi
		pop	es
		pop	ds
		popad
 endif;	USB_PM_SUPPORT				
endif	;USB_SUPPORT
	;system wake up here
		test	[The_2nd_event],01h
		jnz	short Set_PM_State_Exit


Not_Suspend_Request:

		call	Update_PM_Timer
		mov	[PM_TimeOut_Type],00h		;clear request

Set_PM_State_Exit:
		ret

Set_PM_State	Endp

;--------------------------------
;--------------------------------
	ASSUME	DS:PM_RAM
Go_Suspend	Proc	Near
;R20 - starts
		mov	al,58h
		test	byte ptr PM_RAM:[ALARM_RESUME],40h ; If Press PowerButtom ?
		jz	short _Not_Instant_Off
		test	byte ptr PM_RAM:[ALARM_RESUME],02h ; If Setup set Instant-off ?
		jz	short _Not_Instant_Off
		mov	al,5Ah
_Not_Instant_Off:
		call	SMI_Soft_Off
;R20 - ends
;R51 - starts
ifdef	PM_Beep_Speaker			
	ifndef	PM_Beep_NUM		
		mov	cx, 3		
	else	;PM_Beep_NUM		
		mov	cx, BEEP_NUM	
	endif	;PM_Beep_NUM		
		call	PM_Warning_Beep	
endif	;PM_Beep_Speaker		
;R51 - ends
;---------------------------------------------------------------------------;
; If you want to have the function of turn off fan during suspend.	    ;
; You must define :							    ;
;   Suspend_TurnOff_Fan_By_GPIO_0_High	EQU 1h or 2h,4h,8h,10h,20h,40h,80h  ;
;	or								    ;
;   Suspend_TurnOff_Fan_By_GPIO_0_Low	EQU 1h or 2h,4h,8h,10h,20h,40h,80h  ;
;---------------------------------------------------------------------------;
;R41 - start
ifdef	W83782D_CPUFAN_CNTL_IN_SUSPEND
		Call	Turn_Off_CPU_Fan
endif;	W83782D_CPUFAN_CNTL_IN_SUSPEND
;R41 - end
;R57 - start
ifdef	ADM9240_CPUFAN_CNTL_IN_SUSPEND
		Call	Turn_Off_Fan
endif;	ADM9240_CPUFAN_CNTL_IN_SUSPEND
;R57 - end

;R42A - start
ifdef	Superio_Support_Sensor
		Call	Turn_Off_CPU_Fan
endif	;Superio_Support_Sensor
;R42A - end

ifdef	Suspend_TurnOff_Fan_By_GPIO_0_High
		mov	cl, 42h			;
		mov	bl, 01h			;GPIO 0 = High
		call	E000_Get_Set_PMIO_OR	;

		mov	cl, 40h			;
		mov	bl, 01h			;Active GPIO 0 is Output
		call	E000_Get_Set_PMIO_OR	
endif;	Suspend_TurnOff_Fan_By_GPIO_0_High
ifdef	Suspend_TurnOff_Fan_By_GPIO_0_Low
		mov	cl, 40h			;
		mov	bl, 01h			;Active GPIO 0 is Output
		call	E000_Get_Set_PMIO_OR	

		mov	cl, 42h			;
		mov	bl,not 01h		;GPIO 0 = Low
		call	E000_Get_Set_PMIO_AND	

endif;	Suspend_TurnOff_Fan_By_GPIO_0_Low

ifdef	Suspend_TurnOff_Fan_By_GPIO_2_High
		mov	cl, 42h			;GPIO 2 = High
		mov	bl, 04h			;
		call	E000_Get_Set_PMIO_OR	;

		mov	cl, 40h			;Active GPIO 2 is Output
		mov	bl, 04h			;
		call	E000_Get_Set_PMIO_OR	;
endif;	Suspend_TurnOff_Fan_By_GPIO_2_High
ifdef	Suspend_TurnOff_Fan_By_GPIO_2_Low
		mov	cl, 42h			;GPIO 2 = Low
		mov	bl,not 04h		;
		call	E000_Get_Set_PMIO_AND	;

		mov	cl, 40h			;Active GPIO 2 is Output
		mov	bl, 04h			;
		call	E000_Get_Set_PMIO_OR	;
endif;	Suspend_TurnOff_Fan_By_GPIO_2_Low

ifdef	Suspend_TurnOff_Fan_By_GPIO_3_High
		mov	cl, 42h			;GPIO 4 = High
		mov	bl, 08h			;
		call	E000_Get_Set_PMIO_OR	;

		mov	cl, 40h			;Active GPIO 4 is Output
		mov	bl, 08h			;
		call	E000_Get_Set_PMIO_OR	;
endif;	Suspend_TurnOff_Fan_By_GPIO_3_High
ifdef	Suspend_TurnOff_Fan_By_GPIO_3_Low
		mov	cl, 42h			;GPIO 4 = Low
		mov	bl,not 08h		;
		call	E000_Get_Set_PMIO_AND	;

		mov	cl, 40h			;Active GPIO 4 is Output
		mov	bl, 08h			;
		call	E000_Get_Set_PMIO_OR	;
endif;	Suspend_TurnOff_Fan_By_GPIO_3_Low

ifdef	Suspend_TurnOff_Fan_By_GPIO_4_High
		mov	cl, 42h			;GPIO 4 = High
		mov	bl, 10h			;
		call	E000_Get_Set_PMIO_OR	;

		mov	cl, 40h			;Active GPIO 4 is Output
		mov	bl, 10h			;
		call	E000_Get_Set_PMIO_OR	;
endif;	Suspend_TurnOff_Fan_By_GPIO_4_High
ifdef	Suspend_TurnOff_Fan_By_GPIO_4_Low
		mov	cl, 42h			;GPIO 4 = Low
		mov	bl,not 10h		;
		call	E000_Get_Set_PMIO_AND	;

		mov	cl, 40h			;Active GPIO 4 is Output
		mov	bl, 10h			;
		call	E000_Get_Set_PMIO_OR	;
endif;	Suspend_TurnOff_Fan_By_GPIO_4_Low

ifdef	Suspend_TurnOff_Fan_By_GPO_LowByte_Low
		mov	cl, 46h			;GPO Hi Byte = Low
		mov	bl,not Suspend_TurnOff_Fan_By_GPO_LowByte_Low
		call	E000_Get_Set_PMIO_AND	;
endif;	Suspend_TurnOff_Fan_By_GPO_LowByte_Low
ifdef	Suspend_TurnOff_Fan_By_GPO_HiByte_Low
		mov	cl, 47h			;GPO Hi Byte = Low
		mov	bl,not Suspend_TurnOff_Fan_By_GPO_HiByte_Low
	ifdef	ABIT_Have_Suspend_Fan_Item
		test	PM_RAM:[ALARM_RESUME], 04h
		jnz	short @f
		or	bl,80h
	@@:
	endif;	ABIT_Have_Suspend_Fan_Item
		call	E000_Get_Set_PMIO_AND	;
endif;	Suspend_TurnOff_Fan_By_GPO_HiByte_Low
ifdef	Suspend_TurnOff_Fan_By_GPO_LowByte_High
		mov	cl, 46h			;GPO Hi Byte = High
		mov	bl, Suspend_TurnOff_Fan_By_GPO_LowByte_High
		call	E000_Get_Set_PMIO_OR	;
endif;	Suspend_TurnOff_Fan_By_GPO_LowByte_High
ifdef	Suspend_TurnOff_Fan_By_GPO_HiByte_High
		mov	cl, 47h			;GPO Hi Byte = High
		mov	bl, Suspend_TurnOff_Fan_By_GPO_HiByte_High
		call	E000_Get_Set_PMIO_OR	;
endif;	Suspend_TurnOff_Fan_By_GPO_HiByte_High
ifdef	Suspend_TurnOff_Fan_By_GPO_Low		
		mov	dx, ACPI_Port + 46h	;GPO Word = Low
		in	ax,dx
		and	ax,not Suspend_TurnOff_Fan_By_GPO_Low
		out	dx,ax
		out	dx,ax
endif;	Suspend_TurnOff_Fan_By_GPO_Low		
IFDEF	VT596
		;---------------------------------------;
		;    >> 596(3050) : <<			;
		;  Control GPO to Low Before Suspend	;
		;---------------------------------------;
			;---------;
			; GPO0-7  ;
			;---------;
		GPO_Port_4C_VAL	= 00h
	ifdef	Suspend_Send_Low_To_GPO0
		GPO_Port_4C_VAL	= GPO_Port_4C_VAL OR 01h
	endif;	Suspend_Send_Low_To_GPO0
	ifdef	Suspend_Send_Low_To_GPO1
		GPO_Port_4C_VAL	= GPO_Port_4C_VAL OR 02h
	endif;	Suspend_Send_Low_To_GPO1
	ifdef	Suspend_Send_Low_To_GPO2
		GPO_Port_4C_VAL	= GPO_Port_4C_VAL OR 04h
	endif;	Suspend_Send_Low_To_GPO2
	ifdef	Suspend_Send_Low_To_GPO3
		GPO_Port_4C_VAL	= GPO_Port_4C_VAL OR 08h
	endif;	Suspend_Send_Low_To_GPO3
	ifdef	Suspend_Send_Low_To_GPO4
		GPO_Port_4C_VAL	= GPO_Port_4C_VAL OR 10h
	endif;	Suspend_Send_Low_To_GPO4
	ifdef	Suspend_Send_Low_To_GPO5
		GPO_Port_4C_VAL	= GPO_Port_4C_VAL OR 20h
	endif;	Suspend_Send_Low_To_GPO5
	ifdef	Suspend_Send_Low_To_GPO6
		GPO_Port_4C_VAL	= GPO_Port_4C_VAL OR 40h
	endif;	Suspend_Send_Low_To_GPO6
	ifdef	Suspend_Send_Low_To_GPO7
		GPO_Port_4C_VAL	= GPO_Port_4C_VAL OR 80h
	endif;	Suspend_Send_Low_To_GPO7
 ifdef	Suspend_Send_Low_To_GPO
  if	Suspend_Send_Low_To_GPO LE	7
GPO_Port_4C_VAL = GPO_Port_4C_VAL OR (01h SHL Suspend_Send_Low_To_GPO)
  endif;Suspend_Send_Low_To_GPO LE	7
 endif;	Suspend_Send_Low_To_GPO
if	GPO_Port_4C_VAL		NE	00h
		mov	cl, 4Ch
		mov	bl, not GPO_Port_4C_VAL
  IFDEF	Have_Fan_Control_Item_In_GPO_Low
    if	    Have_Fan_Control_Item_In_GPO_Low	LE 7
 		test	PM_RAM:[Video_Off_Mode],80h	; Is disable ?
		jz	short Suspend_Turn_Off_Fan
		or	bl,(01h shl Have_Fan_Control_Item_In_GPO_Low)
	Suspend_Turn_Off_Fan:
    endif;  Have_Fan_Control_Item_In_GPO_Low	LE 7
  ENDIF;Have_Fan_Control_Item_In_GPO_Low
		call	E000_Get_Set_PMIO_AND
endif;	GPO_Port_4C_VAL		NE	00h
			;---------;
			; GPO8-15 ;
			;---------;
		GPO_Port_4D_VAL	= 00h
	ifdef	Suspend_Send_Low_To_GPO8
		GPO_Port_4D_VAL	= GPO_Port_4D_VAL OR 01h
	endif;	Suspend_Send_Low_To_GPO8
	ifdef	Suspend_Send_Low_To_GPO9
		GPO_Port_4D_VAL	= GPO_Port_4D_VAL OR 02h
	endif;	Suspend_Send_Low_To_GPO9
	ifdef	Suspend_Send_Low_To_GPO10
		GPO_Port_4D_VAL	= GPO_Port_4D_VAL OR 04h
	endif;	Suspend_Send_Low_To_GPO10
	ifdef	Suspend_Send_Low_To_GPO11
		GPO_Port_4D_VAL	= GPO_Port_4D_VAL OR 08h
	endif;	Suspend_Send_Low_To_GPO11
	ifdef	Suspend_Send_Low_To_GPO12
		GPO_Port_4D_VAL	= GPO_Port_4D_VAL OR 10h
	endif;	Suspend_Send_Low_To_GPO12
	ifdef	Suspend_Send_Low_To_GPO13
		GPO_Port_4D_VAL	= GPO_Port_4D_VAL OR 20h
	endif;	Suspend_Send_Low_To_GPO13
	ifdef	Suspend_Send_Low_To_GPO14
		GPO_Port_4D_VAL	= GPO_Port_4D_VAL OR 40h
	endif;	Suspend_Send_Low_To_GPO14
	ifdef	Suspend_Send_Low_To_GPO15
		GPO_Port_4D_VAL	= GPO_Port_4D_VAL OR 80h
	endif;	Suspend_Send_Low_To_GPO15
 ifdef	Suspend_Send_Low_To_GPO
  if	Suspend_Send_Low_To_GPO LE	15
  if	Suspend_Send_Low_To_GPO GE	8
GPO_Port_4D_VAL = GPO_Port_4D_VAL OR (01h SHL (Suspend_Send_Low_To_GPO-8))
  endif;Suspend_Send_Low_To_GPO LE	8
  endif;Suspend_Send_Low_To_GPO LE	15
 endif;	Suspend_Send_Low_To_GPO
if	GPO_Port_4D_VAL		NE	00h
		mov	cl, 4Dh
		mov	bl, not GPO_Port_4D_VAL
  IFDEF	Have_Fan_Control_Item_In_GPO_Low
    if		Have_Fan_Control_Item_In_GPO_Low	LE 15
      IF	Have_Fan_Control_Item_In_GPO_Low	GE  8
 		test	PM_RAM:[Video_Off_Mode],80h	; Is disable ?
		jz	short Suspend_Turn_Off_Fan
		or	bl,(01h shl (Have_Fan_Control_Item_In_GPO_Low-8))
	Suspend_Turn_Off_Fan:
      ENDIF;	Have_Fan_Control_Item_In_GPO_Low	GE  8
    endif;	Have_Fan_Control_Item_In_GPO_Low	LE 15
  ENDIF;Have_Fan_Control_Item_In_GPO_Low
		call	E000_Get_Set_PMIO_AND
endif;	GPO_Port_4D_VAL		NE	00h
			;----------;
			; GPO16-23 ;
			;----------;
		GPO_Port_4E_VAL	= 00h
	ifdef	Suspend_Send_Low_To_GPO16
		GPO_Port_4E_VAL	= GPO_Port_4E_VAL OR 01h
	endif;	Suspend_Send_Low_To_GPO16
	ifdef	Suspend_Send_Low_To_GPO17
		GPO_Port_4E_VAL	= GPO_Port_4E_VAL OR 02h
	endif;	Suspend_Send_Low_To_GPO17
	ifdef	Suspend_Send_Low_To_GPO18
		GPO_Port_4E_VAL	= GPO_Port_4E_VAL OR 04h
	endif;	Suspend_Send_Low_To_GPO18
	ifdef	Suspend_Send_Low_To_GPO19
		GPO_Port_4E_VAL	= GPO_Port_4E_VAL OR 08h
	endif;	Suspend_Send_Low_To_GPO19
	ifdef	Suspend_Send_Low_To_GPO20
		GPO_Port_4E_VAL	= GPO_Port_4E_VAL OR 10h
	endif;	Suspend_Send_Low_To_GPO20
	ifdef	Suspend_Send_Low_To_GPO21
		GPO_Port_4E_VAL	= GPO_Port_4E_VAL OR 20h
	endif;	Suspend_Send_Low_To_GPO21
	ifdef	Suspend_Send_Low_To_GPO22
		GPO_Port_4E_VAL	= GPO_Port_4E_VAL OR 40h
	endif;	Suspend_Send_Low_To_GPO22
	ifdef	Suspend_Send_Low_To_GPO23
		GPO_Port_4E_VAL	= GPO_Port_4E_VAL OR 80h
	endif;	Suspend_Send_Low_To_GPO23
 ifdef	Suspend_Send_Low_To_GPO
  if	Suspend_Send_Low_To_GPO LE	23
  if	Suspend_Send_Low_To_GPO GE	16
GPO_Port_4E_VAL = GPO_Port_4E_VAL OR (01h SHL (Suspend_Send_Low_To_GPO-16))
  endif;Suspend_Send_Low_To_GPO LE	16
  endif;Suspend_Send_Low_To_GPO LE	23
 endif;	Suspend_Send_Low_To_GPO
if	GPO_Port_4E_VAL		NE	00h
		mov	cl, 4Eh
		mov	bl,not GPO_Port_4E_VAL
  IFDEF	Have_Fan_Control_Item_In_GPO_Low
    if		Have_Fan_Control_Item_In_GPO_Low	LE 23
      IF	Have_Fan_Control_Item_In_GPO_Low	GE 16
 		test	PM_RAM:[Video_Off_Mode],80h	; Is disable ?
		jz	short Suspend_Turn_Off_Fan
		or	bl,(01h shl (Have_Fan_Control_Item_In_GPO_Low-16))
	Suspend_Turn_Off_Fan:
      ENDIF;	Have_Fan_Control_Item_In_GPO_Low	GE 16
    endif;	Have_Fan_Control_Item_In_GPO_Low	LE 23
  ENDIF;Have_Fan_Control_Item_In_GPO_Low
		call	E000_Get_Set_PMIO_AND
endif;	GPO_Port_4E_VAL		NE	00h
			;----------;
			; GPO24-30 ;
			;----------;
		GPO_Port_4F_VAL	= 00h
	ifdef	Suspend_Send_Low_To_GPO24
		GPO_Port_4F_VAL	= GPO_Port_4F_VAL OR 01h
	endif;	Suspend_Send_Low_To_GPO24
	ifdef	Suspend_Send_Low_To_GPO25
		GPO_Port_4F_VAL	= GPO_Port_4F_VAL OR 02h
	endif;	Suspend_Send_Low_To_GPO25
	ifdef	Suspend_Send_Low_To_GPO26
		GPO_Port_4F_VAL	= GPO_Port_4F_VAL OR 04h
	endif;	Suspend_Send_Low_To_GPO26
	ifdef	Suspend_Send_Low_To_GPO27
		GPO_Port_4F_VAL	= GPO_Port_4F_VAL OR 08h
	endif;	Suspend_Send_Low_To_GPO27
	ifdef	Suspend_Send_Low_To_GPO28
		GPO_Port_4F_VAL	= GPO_Port_4F_VAL OR 10h
	endif;	Suspend_Send_Low_To_GPO28
	ifdef	Suspend_Send_Low_To_GPO29
		GPO_Port_4F_VAL	= GPO_Port_4F_VAL OR 20h
	endif;	Suspend_Send_Low_To_GPO29
	ifdef	Suspend_Send_Low_To_GPO30
		GPO_Port_4F_VAL	= GPO_Port_4F_VAL OR 40h
	endif;	Suspend_Send_Low_To_GPO30
 ifdef	Suspend_Send_Low_To_GPO
  if	Suspend_Send_Low_To_GPO LE	30
  if	Suspend_Send_Low_To_GPO GE	24
GPO_Port_4F_VAL = GPO_Port_4F_VAL OR (01h SHL (Suspend_Send_Low_To_GPO-24))
  endif;Suspend_Send_Low_To_GPO LE	24
  endif;Suspend_Send_Low_To_GPO LE	30
 endif;	Suspend_Send_Low_To_GPO
if	GPO_Port_4F_VAL		NE	00h
		mov	cl, 4Fh
		mov	bl,not GPO_Port_4F_VAL
  IFDEF	Have_Fan_Control_Item_In_GPO_Low
    if		Have_Fan_Control_Item_In_GPO_Low	LE 30
      IF	Have_Fan_Control_Item_In_GPO_Low	GE 24
 		test	PM_RAM:[Video_Off_Mode],80h	; Is disable ?
		jz	short Suspend_Turn_Off_Fan
		or	bl,(01h shl (Have_Fan_Control_Item_In_GPO_Low-24))
	Suspend_Turn_Off_Fan:
      ENDIF;	Have_Fan_Control_Item_In_GPO_Low	GE 24
    endif;	Have_Fan_Control_Item_In_GPO_Low	LE 30
  ENDIF;Have_Fan_Control_Item_In_GPO_Low
		call	E000_Get_Set_PMIO_AND
endif;	GPO_Port_4F_VAL		NE	00h

		;---------------------------------------;
		;    >> 596(3050) : <<			;
		;  Control GPO to High Before Suspend	;
		;---------------------------------------;
			;---------;
			; GPO0-7  ;
			;---------;
		GPO_Port_4C_VAL	= 00h
	ifdef	Suspend_Send_High_To_GPO0
		GPO_Port_4C_VAL	= GPO_Port_4C_VAL OR 01h
	endif;	Suspend_Send_High_To_GPO0
	ifdef	Suspend_Send_High_To_GPO1
		GPO_Port_4C_VAL	= GPO_Port_4C_VAL OR 02h
	endif;	Suspend_Send_High_To_GPO1
	ifdef	Suspend_Send_High_To_GPO2
		GPO_Port_4C_VAL	= GPO_Port_4C_VAL OR 04h
	endif;	Suspend_Send_High_To_GPO2
	ifdef	Suspend_Send_High_To_GPO3
		GPO_Port_4C_VAL	= GPO_Port_4C_VAL OR 08h
	endif;	Suspend_Send_High_To_GPO3
	ifdef	Suspend_Send_High_To_GPO4
		GPO_Port_4C_VAL	= GPO_Port_4C_VAL OR 10h
	endif;	Suspend_Send_High_To_GPO4
	ifdef	Suspend_Send_High_To_GPO5
		GPO_Port_4C_VAL	= GPO_Port_4C_VAL OR 20h
	endif;	Suspend_Send_High_To_GPO5
	ifdef	Suspend_Send_High_To_GPO6
		GPO_Port_4C_VAL	= GPO_Port_4C_VAL OR 40h
	endif;	Suspend_Send_High_To_GPO6
	ifdef	Suspend_Send_High_To_GPO7
		GPO_Port_4C_VAL	= GPO_Port_4C_VAL OR 80h
	endif;	Suspend_Send_High_To_GPO7
 ifdef	Suspend_Send_High_To_GPO
  if	Suspend_Send_High_To_GPO LE	7
GPO_Port_4C_VAL = GPO_Port_4C_VAL OR (01h SHL Suspend_Send_High_To_GPO)
  endif;Suspend_Send_High_To_GPO LE	7
 endif;	Suspend_Send_High_To_GPO
if	GPO_Port_4C_VAL		NE	00h
		mov	cl, 4Ch
		mov	bl, GPO_Port_4C_VAL
  IFDEF	Have_Fan_Control_Item_In_GPO_High
    if		Have_Fan_Control_Item_In_GPO_High	LE 7
 		test	PM_RAM:[Video_Off_Mode],80h	; Is disable ?
		jz	short Suspend_Turn_Off_Fan
		and	bl,(01h shl Have_Fan_Control_Item_In_GPO_High)
	Suspend_Turn_Off_Fan:
    endif;	Have_Fan_Control_Item_In_GPO_High	LE 7
  ENDIF;Have_Fan_Control_Item_In_GPO_High
		call	E000_Get_Set_PMIO_OR
endif;	GPO_Port_4C_VAL		NE	00h
			;---------;
			; GPO8-15 ;
			;---------;
		GPO_Port_4D_VAL	= 00h
	ifdef	Suspend_Send_High_To_GPO8
		GPO_Port_4D_VAL	= GPO_Port_4D_VAL OR 01h
	endif;	Suspend_Send_High_To_GPO8
	ifdef	Suspend_Send_High_To_GPO9
		GPO_Port_4D_VAL	= GPO_Port_4D_VAL OR 02h
	endif;	Suspend_Send_High_To_GPO9
	ifdef	Suspend_Send_High_To_GPO10
		GPO_Port_4D_VAL	= GPO_Port_4D_VAL OR 04h
	endif;	Suspend_Send_High_To_GPO10
	ifdef	Suspend_Send_High_To_GPO11
		GPO_Port_4D_VAL	= GPO_Port_4D_VAL OR 08h
	endif;	Suspend_Send_High_To_GPO11
	ifdef	Suspend_Send_High_To_GPO12
		GPO_Port_4D_VAL	= GPO_Port_4D_VAL OR 10h
	endif;	Suspend_Send_High_To_GPO12
	ifdef	Suspend_Send_High_To_GPO13
		GPO_Port_4D_VAL	= GPO_Port_4D_VAL OR 20h
	endif;	Suspend_Send_High_To_GPO13
	ifdef	Suspend_Send_High_To_GPO14
		GPO_Port_4D_VAL	= GPO_Port_4D_VAL OR 40h
	endif;	Suspend_Send_High_To_GPO14
	ifdef	Suspend_Send_High_To_GPO15
		GPO_Port_4D_VAL	= GPO_Port_4D_VAL OR 80h
	endif;	Suspend_Send_High_To_GPO15
 ifdef	Suspend_Send_High_To_GPO
  if	Suspend_Send_High_To_GPO LE	15
  if	Suspend_Send_High_To_GPO GE	8
GPO_Port_4D_VAL = GPO_Port_4D_VAL OR (01h SHL (Suspend_Send_High_To_GPO-8))
  endif;Suspend_Send_High_To_GPO LE	8
  endif;Suspend_Send_High_To_GPO LE	15
 endif;	Suspend_Send_High_To_GPO
if	GPO_Port_4D_VAL		NE	00h
		mov	cl, 4Dh
		mov	bl, GPO_Port_4D_VAL
  IFDEF	Have_Fan_Control_Item_In_GPO_High
    if		Have_Fan_Control_Item_In_GPO_High	LE 15
      IF	Have_Fan_Control_Item_In_GPO_High	GE 8
 		test	PM_RAM:[Video_Off_Mode],80h	; Is disable ?
		jz	short Suspend_Turn_Off_Fan
		and	bl,(01h shl (Have_Fan_Control_Item_In_GPO_High-8))
	Suspend_Turn_Off_Fan:
      ENDIF;	Have_Fan_Control_Item_In_GPO_High	GE 8
    endif;	Have_Fan_Control_Item_In_GPO_High	LE 15
  ENDIF;Have_Fan_Control_Item_In_GPO_High
		call	E000_Get_Set_PMIO_OR
endif;	GPO_Port_4D_VAL		NE	00h
			;----------;
			; GPO16-23 ;
			;----------;
		GPO_Port_4E_VAL	= 00h
	ifdef	Suspend_Send_High_To_GPO16
		GPO_Port_4E_VAL	= GPO_Port_4E_VAL OR 01h
	endif;	Suspend_Send_High_To_GPO16
	ifdef	Suspend_Send_High_To_GPO17
		GPO_Port_4E_VAL	= GPO_Port_4E_VAL OR 02h
	endif;	Suspend_Send_High_To_GPO17
	ifdef	Suspend_Send_High_To_GPO18
		GPO_Port_4E_VAL	= GPO_Port_4E_VAL OR 04h
	endif;	Suspend_Send_High_To_GPO18
	ifdef	Suspend_Send_High_To_GPO19
		GPO_Port_4E_VAL	= GPO_Port_4E_VAL OR 08h
	endif;	Suspend_Send_High_To_GPO19
	ifdef	Suspend_Send_High_To_GPO20
		GPO_Port_4E_VAL	= GPO_Port_4E_VAL OR 10h
	endif;	Suspend_Send_High_To_GPO20
	ifdef	Suspend_Send_High_To_GPO21
		GPO_Port_4E_VAL	= GPO_Port_4E_VAL OR 20h
	endif;	Suspend_Send_High_To_GPO21
	ifdef	Suspend_Send_High_To_GPO22
		GPO_Port_4E_VAL	= GPO_Port_4E_VAL OR 40h
	endif;	Suspend_Send_High_To_GPO22
	ifdef	Suspend_Send_High_To_GPO23
		GPO_Port_4E_VAL	= GPO_Port_4E_VAL OR 80h
	endif;	Suspend_Send_High_To_GPO23
 ifdef	Suspend_Send_High_To_GPO
  if	Suspend_Send_High_To_GPO LE	23
  if	Suspend_Send_High_To_GPO GE	16
GPO_Port_4E_VAL = GPO_Port_4E_VAL OR (01h SHL (Suspend_Send_High_To_GPO-16))
  endif;Suspend_Send_High_To_GPO LE	16
  endif;Suspend_Send_High_To_GPO LE	23
 endif;	Suspend_Send_High_To_GPO
if	GPO_Port_4E_VAL		NE	00h
		mov	cl, 4Eh
		mov	bl, GPO_Port_4E_VAL
  IFDEF	Have_Fan_Control_Item_In_GPO_High
    if		Have_Fan_Control_Item_In_GPO_High	LE 23
      IF	Have_Fan_Control_Item_In_GPO_High	GE 16
 		test	PM_RAM:[Video_Off_Mode],80h	; Is disable ?
		jz	short Suspend_Turn_Off_Fan
		and	bl,(01h shl (Have_Fan_Control_Item_In_GPO_High-16))
	Suspend_Turn_Off_Fan:
      ENDIF;	Have_Fan_Control_Item_In_GPO_High	GE 16
    endif;	Have_Fan_Control_Item_In_GPO_High	LE 23
  ENDIF;Have_Fan_Control_Item_In_GPO_High
		call	E000_Get_Set_PMIO_OR
endif;	GPO_Port_4E_VAL		NE	00h
			;----------;
			; GPO24-30 ;
			;----------;
		GPO_Port_4F_VAL	= 00h
	ifdef	Suspend_Send_High_To_GPO24
		GPO_Port_4F_VAL	= GPO_Port_4F_VAL OR 01h
	endif;	Suspend_Send_High_To_GPO24
	ifdef	Suspend_Send_High_To_GPO25
		GPO_Port_4F_VAL	= GPO_Port_4F_VAL OR 02h
	endif;	Suspend_Send_High_To_GPO25
	ifdef	Suspend_Send_High_To_GPO26
		GPO_Port_4F_VAL	= GPO_Port_4F_VAL OR 04h
	endif;	Suspend_Send_High_To_GPO26
	ifdef	Suspend_Send_High_To_GPO27
		GPO_Port_4F_VAL	= GPO_Port_4F_VAL OR 08h
	endif;	Suspend_Send_High_To_GPO27
	ifdef	Suspend_Send_High_To_GPO28
		GPO_Port_4F_VAL	= GPO_Port_4F_VAL OR 10h
	endif;	Suspend_Send_High_To_GPO28
	ifdef	Suspend_Send_High_To_GPO29
		GPO_Port_4F_VAL	= GPO_Port_4F_VAL OR 20h
	endif;	Suspend_Send_High_To_GPO29
	ifdef	Suspend_Send_High_To_GPO30
		GPO_Port_4F_VAL	= GPO_Port_4F_VAL OR 40h
	endif;	Suspend_Send_High_To_GPO30
 ifdef	Suspend_Send_High_To_GPO
  if	Suspend_Send_High_To_GPO LE	30
  if	Suspend_Send_High_To_GPO GE	24
GPO_Port_4F_VAL = GPO_Port_4F_VAL OR (01h SHL (Suspend_Send_High_To_GPO-24))
  endif;Suspend_Send_High_To_GPO LE	24
  endif;Suspend_Send_High_To_GPO LE	30
 endif;	Suspend_Send_High_To_GPO
if	GPO_Port_4F_VAL		NE	00h
		mov	cl, 4Fh
		mov	bl, GPO_Port_4F_VAL
  IFDEF	Have_Fan_Control_Item_In_GPO_High
    if		Have_Fan_Control_Item_In_GPO_High	LE 30
      IF	Have_Fan_Control_Item_In_GPO_High	GE 24
 		test	PM_RAM:[Video_Off_Mode],80h	; Is disable ?
		jz	short Suspend_Turn_Off_Fan
		and	bl,(01h shl (Have_Fan_Control_Item_In_GPO_High-24))
	Suspend_Turn_Off_Fan:
      ENDIF;	Have_Fan_Control_Item_In_GPO_High	GE 24
    endif;	Have_Fan_Control_Item_In_GPO_High	LE 30
  ENDIF;Have_Fan_Control_Item_In_GPO_High
		call	E000_Get_Set_PMIO_OR
endif;	GPO_Port_4F_VAL		NE	00h
ENDIF;	VT596
	ifdef	Blink_Suspend_LED_In_GPO0			;R50
		ifdef	VT686					;R50
		mov	cx,VT586_ACPI + 54h			;R50
		mov	bx,02FCh				;R50
	  if	Blink_Suspend_LED_In_GPO0 EQ	0		;R50
		mov	bx,01FCh				;R50
	  endif;Blink_Suspend_LED_In_GPO0 EQ	0		;R50
	  if	Blink_Suspend_LED_In_GPO0 EQ	16		;R50
		mov	bx,03FCh				;R50
	  endif;Blink_Suspend_LED_In_GPO0 EQ	16		;R50
		call	E000_Get_Set_PMU			;R50
		endif;	VT686					;R50
	endif;	Blink_Suspend_LED_In_GPO0			;R50

ifdef	SMBus_Port					;R12
		;-------------------------------;	;R12
		;    Clear SMBus Host Status	;	;R12
		;-------------------------------;	;R12
		mov	dx,SMBus_Port			;R12
		in	al,dx				;R12
		out	dx,al				;R12
endif;	SMBus_Port					;R12

		call    Set_Modem_Ring_Status

ifndef	New_Superio_Led_Function			;R42
ifdef	PM_LED_USE_GPIO				
		pushad				
		mov	al, 2			
		Call 	far ptr F000_SET_PM_LED	
		popad				
endif;	PM_LED_USE_GPIO				
ifdef	LED_Blinking_at_PM			
		pushad				
		mov	al, 1			
		Call 	far ptr F000_SET_PM_LED_Blinking
		popad					
endif;	LED_Blinking_at_PM				
ifndef	Special_For_TYAN				;R55
ifdef	POWER_LED_USE					
		pushad					
		mov	al, 2				
		Call 	far ptr F000_SET_POWER_LED	
		popad					
endif;	POWER_LED_USE					
endif	;Special_For_TYAN				;R55
;R42 - start
else	;New_Superio_Led_Function
;R42Bifdef	Superio_support_Fan
ifdef	LED_Blinking_at_PM				;R42B
		pushad				
		mov	al, 1
		Call 	far ptr F000_LED_Flash
		popad					
endif;	LED_Blinking_at_PM				;R42B
;R42Bendif;	Superio_support_Fan
endif	;New_Superio_Led_Function
;R42Aifdef	Superio_support_Fan
;R42A		pushad				
;R42A		Call 	far ptr F000_Fan_Power_Off
;R42A		popad					
;R42Aendif;	Superio_support_Fan
;R42 - end
		mov	cx, VT586_ACPI + 53h
		mov	bx,0000100111110000b
		call	E000_Get_Set_PMU

		mov	cl, 2ah			;enable 2nd event
		mov	bx, 03FBh		
		call	E000_Get_Set_PMIO	

;--------------------------------------------------------
;1. turn off HDDs according setup settings
;   & save register 67h status
;
;	1. HDD_Timer_Setting = 16
;	     	===> HDD off when suspend
;	2. To turn off HDD, we must turn off
;     	   HDD event in the first place!
;--------------------------------------------------------

		cmp	byte ptr PM_RAM:[The_2nd_Event],1	
		je	short @F				
		mov	cx,3
@@:								

;4. stop clock
	;save speaker status

ifdef	Suspend_LED_Control			
;Set bit 6 to "0" to turn off suspend LED
		xor	ah,ah		 
		call	Send_Smout	 
endif;	Suspend_LED_Control			

;R49 ;R37 - starts
;R49 IFDEF	NoteBook_Power_Management
;R49 		cmp	PM_RAM:Suspend_Option,Zero_V_Suspend
;R49 		jne	short @F
;R49 
;R49 		cmp	dword ptr PM_RAM:[ZV_HDD_Sector],0
;R49 		je	short @F
;R49		Call	far ptr F_Suspend_0V
;R49 
;R49 	ifdef	ADVANCE_POWER_MANAGEMENT
;R49 	; Set resume notify flag for APM to update time
;R49 		mov	PM_RAM:[APMEventSave],RESUME_NORMAL_NOTIFY
;R49 	endif;	ADVANCE_POWER_MANAGEMENT
;R49 		jmp	WakeUpByResumeTimer
;R49 
;R49 	@@:
;R49 ENDIF	;NoteBook_Power_Management
;R49 ;R37 - ends

;Disable clock throttling
		mov	cl, 10h
		xor	al, al
		call	E000_Set_PMIO

		cli

		mov	bl,0ffh
		in	al,021h
		test	al,08h
		jz	short @F
		and	bl,0f7h
@@:
		test	al,10h
		jz	short @F
		and	bl,0efh
@@:
		mov	cx, VT586_ACPI + 44h
		call	E000_Get_PMU

		push	ax
		mov	al,[WAKE_MODEM0]
		and	al,bl
		or	al,02h		
		call	E000_Set_PMU

ifndef VT3044
		mov	cx,VT586 + 91h
else ;VT3044
		mov	cx,VT586_ACPI + 45h
endif ;VT3044
		mov	al,[WAKE_MODEM1]
		call	E000_Set_PMU

		mov	cl, 34h
		mov	bl, 02h			
		call	E000_Get_Set_PMIO_OR	

		in	al,0a1h
		mov	ah,al
		in	al,21h
		push	ax		;Store IRQ0
		mov	cx, VT586_ACPI + 44h
                call    E000_Get_PMU
                mov     bl, al
                mov     cx, VT586_ACPI + 46h
                call    E000_Get_PMU
                or      al, bl
                not     al
                and     al, NOT 02h     ; unmask 02
                or      al, 01h
                out     21h, al
		mov	 cx, VT586_ACPI + 45h
                call    E000_Get_PMU
                mov     bl, al
                mov     cx, VT586_ACPI + 47h
                call    E000_Get_PMU
                or      bl, al
                not     bl
                or      bl, 01h
		test	byte ptr PM_RAM:[PS2_INST],04h		;PS2 Mouse ?
		jz	short @F
                and     bl, NOT 010h
		mov	cx, VT586_ACPI + 45h
		call	E000_Get_PMU		
		or	al, 10h			
		call	E000_Set_PMU		
@@:
                mov     al, bl
                out     0a1h, al

	;assert STPCLK#	inside SMI routine		

		mov	cl, 28h
		call	E000_Get_PMIO
		call	E000_Set_PMIO
		mov	cl, 20h
		call	E000_Get_PMIO
		call	E000_Set_PMIO

		mov	cx, VT586_ACPI + 50h
		xor	al,al
		call	E000_Set_PMU

		mov	cl, 30h
		call	E000_Set_PMIO_Clear

ifdef	HDD_PWRDOWN_IN_SUSPEND					
ifdef	HDD_PWRDOWN_IN_SUSPEND_After_1Min			

	       	mov	al,byte ptr PM_RAM:[HDD_OFF_Timer]	
		cmp 	al,0					
		jz	short @f				
								
		Call	HDD_Power_Down				
@@:								
;R68 start
else	;HDD_PWRDOWN_IN_SUSPEND_After_1Min
		mov	cl,34h
		mov	bl,not 0Ch
		Call	E000_Get_Set_PMIO_AND

		Call	HDD_Power_Down
;R68 end
endif;	HDD_PWRDOWN_IN_SUSPEND_After_1Min			
endif;	HDD_PWRDOWN_IN_SUSPEND

ifdef	Break_Suspend_In_Mouse_CMOS

		xor	cx,cx
		mov	bl,byte ptr PM_RAM:[MISC_CNTL1]
		and	bl,Mouse_WakeUp_Mask
								
		cmp	bl,Mouse_No_WakeUp
		je	short Mouse_Mask_IRQ_START
								
		cmp	bl,Mouse_Use_IRQ4			
		jne	short @F				
		mov	cx,0010h				
		jmp	short Mouse_Mask_IRQ_START		
	   @@:							
								
		cmp	bl,Mouse_Use_IRQ3			
		jne	short @F				
		mov	cx,0008h				
		jmp	short Mouse_Mask_IRQ_START		
	   @@:							
								
	;Disable PS2 mouse interface if PS2 mouse exist		
		push	es
		mov	ax,0f000H	;BIOS segment
		mov	es,ax
		assume	es:nothing
		test	byte ptr es:system1_byte, 04H	;PS2 existed ?
		pop	es
		jnz	short Ps2Exist

		and	byte ptr PM_RAM:[MISC_CNTL1],not Mouse_WakeUp_Mask
		jmp	short Ps2Absent

Ps2Exist:
		mov	al,0A7H		;disable PS2 mouse interface
		out	64H,al
		NEWIODELAY
Ps2Absent:

Mouse_Mask_IRQ_START:

		in	al,21h
		newiodelay
		mov	ah,al
		or	al,cl
		out	21h,al

		in	al,0a1h
		newiodelay
		push	ax

endif;	Break_Suspend_In_Mouse_CMOS

;R23A ifdef	Cover_Garbage_IRQ12			;R23 - starts
;R23A 		test	PM_RAM:[ALARM_RESUME], 80h	;Wake Event IRQ12 Enabled.
;R23A 		jnz	short W_IRQ12_En
;R23A 		mov	al,0A7H		;disable PS2 mouse interface
;R23A 		out	64H,al
;R23A 		NEWIODELAY
;R23A 	W_IRQ12_En:
;R23A endif;	Cover_Garbage_IRQ12			;R23 - ends

;R58 - starts
ifdef	Patch_WIN98_OSR1_BUG
		mov	cx, VT586_ACPI + 44h
		call	E000_Get_PMU
		mov	bl,al

		mov	cx,VT586_ACPI + 45h
		call	E000_Get_PMU
		mov	bh,al

		mov	cx, VT586_ACPI + 46h
		call	E000_Get_PMU
		or	bl,al

		mov	cx, VT586_ACPI + 47h
		call	E000_Get_PMU
		or	bh,al

 		mov	word ptr [DEASSERT_STPCLK_IRQS],bx
		
endif;	Patch_WIN98_OSR1_BUG
;R58 - ends

ifdef	V_ALARM_IN_E000						
		call	Virtual_Resume_Timer			
else	;V_ALARM_IN_E000					
		FAR_Call F000_Virtual_Resume_Timer, 0F000h
endif	;V_ALARM_IN_E000					
		jnc	short WakeUpByResumeTimer


;align	4
	;-----------------------------------------------;
	;  Set USB to Suspend/Enable USB Resume Event	;
	;-----------------------------------------------;
ifdef	USB_SUPPORT
 ifdef	USB_PM_SUPPORT
		call	Usb_Suspend		
		call	Clear_Power_Buttom_Status
;R15 - starts
		call	Check_Legacy_Enable	;legacy support disabled?
		jz	short Usb_Legacy_Enable_1

		mov	cl, 21h			; Clear USB Resume Status
		mov	bl, 02h			; (Index 21h Bit 1)
		call	E000_Get_Set_PMIO_AND	;

		mov	cl, 25h			; Enable USB Resume SMI
		mov	bl, 02h			; (Index 25h Bit 4)
		call	E000_Get_Set_PMIO_OR	;
	Usb_Legacy_Enable_1:
;R15 - ends
 else;	USB_PM_SUPPORT				
   ifdef	USB_Legacy_PM_Support		
		call	Clear_Power_Buttom_Status	
		mov	cx, VT586_USB + 3Ch	; Disbale IRQ of USB
		call	E000_Get_PMU		; 
		mov	bh, al			; & Save IRQ of USB
		xor	al,al			;
		call	E000_Set_PMU		;
   else;	USB_Legacy_PM_Support
		mov	cl, 2Ah			; Index 2Ah Bit 4.
		mov	bl, not 10h		;
		call	E000_Get_Set_PMIO_AND	;
   endif;	USB_Legacy_PM_Support
 endif;	USB_PM_SUPPORT
endif	;USB_SUPPORT

;R16B ifdef	VT596					;R16A - starts
;R16B 		call	Clear_Power_Buttom_Status	;R20
;R16B 		mov	cl, 2Ch			; Set PowerButtom to
;R16B 		mov	bl, not 04h		;	Rising Edge Triger
;R16B 		call	E000_Get_Set_PMIO_AND	;
;R16B endif;	VT596					;R16A - ends
		test	byte ptr PM_RAM:[ALARM_RESUME],01h
		jz	short @F
		mov	cl, 01h
		call	E000_Set_PMIO_Clear	; clear RTC status
		mov	cl, 03h
		mov	bl, 04h			
		call	E000_Get_Set_PMIO_OR	
;R20		mov	al,1				; Turn On
;R20		call	far ptr RTC_Alarm_Resume
@@:

ifdef	VT596					;R16B - starts
		call	Clear_Power_Buttom_Status	;R20
		mov	cl, 2Ch			; Set PowerButtom to
		mov	bl, not 04h		;	Rising Edge Triger
		call	E000_Get_Set_PMIO_AND	;
endif;	VT596					;R16B - ends


@@:
;R49 - starts
IFDEF	NoteBook_Power_Management
		cmp	PM_RAM:Suspend_Option,Zero_V_Suspend
		jne	short @F

		cmp	dword ptr PM_RAM:[ZV_HDD_Sector],0
		je	short @F
		Call	far ptr F_Suspend_0V

	ifdef	ADVANCE_POWER_MANAGEMENT
	; Set resume notify flag for APM to update time
		mov	PM_RAM:[APMEventSave],RESUME_NORMAL_NOTIFY
	endif;	ADVANCE_POWER_MANAGEMENT
		jmp	WakeUpByResumeTimer

	@@:
ENDIF	;NoteBook_Power_Management
;R49 - ends
Stop_Clock:				
		mov	cl, 15h
		call	E000_Get_PMIO

	;CPU stop here
		xor	cx,cx  		;delay for a while
		loop	short $

ifdef	Disable_PowerButton_When_Suspend
		mov	cl, 01h
		call	E000_Get_PMIO
		test	al,01
		pushf
		and	al,01h
		call	E000_Set_PMIO
		popf
		jnz	short Stop_Clock
endif;	Disable_PowerButton_When_Suspend

	;-----------------------------------------------;
	;  Set USB to WakeUp/Disable USB Resume Event	;
	;-----------------------------------------------;
ifdef	USB_SUPPORT
 ifdef	USB_PM_SUPPORT				
;R15 - starts
		call	Check_Legacy_Enable	;legacy support disabled?
		jz	short Usb_Legacy_Enable_2

		mov	cl, 21h			; Clear USB Resume Status
		mov	bl, 02h			; (Index 21h Bit 1)
		call	E000_Get_Set_PMIO_AND	;

		mov	cl, 25h			; Disable USB Resume SMI
		mov	bl, not 02h		; (Index 25h Bit 4)
		call	E000_Get_Set_PMIO_AND	;
Usb_Legacy_Enable_2:
;R15 - ends
		call	Usb_Resume		
 else;	USB_PM_SUPPORT				
   ifdef	USB_Legacy_PM_Support		
		mov	cl, 01h			
		call	E000_Get_PMIO		
		test	al, 01h			
		jnz	short @f		

		call	Usb_Smi
		jc	Short @f       
		in 	al, 64h	       
		test    al, 01h
		jz	short Stop_Clock
@@:
		mov	cx, VT586_USB + 3Ch	; Restore IRQ of USB
		mov	al, bh			;
		call	E000_Set_PMU		;
   else;	USB_Legacy_PM_Support
		mov	cl, 2Ah			; Index 2Ah Bit 4.
		mov	bl, 10h			;
		call	E000_Get_Set_PMIO_OR	;
   endif;	USB_Legacy_PM_Support
 endif;	USB_PM_SUPPORT
endif	;USB_SUPPORT

ifdef	VT596					;R16A - starts
		mov	cl, 2Ch			; Set PowerButtom to
		mov	bl, 04h			;	Level Triger
		call	E000_Get_Set_PMIO_OR	;
endif;	VT596					;R16A - ends
;R51 - starts
ifdef	PM_Beep_Speaker			
		mov	cx, 1		
		call	PM_Warning_Beep	
endif	;PM_Beep_Speaker		
;R51 - ends
WakeUpByResumeTimer:

;deassert STPCLK# for next asserting function
ifdef	Break_Suspend_In_Mouse_CMOS
		pop	ax
		out	0a1h,al
		mov	al,ah
		out	21h,al

		mov	al,byte ptr PM_RAM:[MISC_CNTL1]
		and	al,Mouse_WakeUp_Mask
		cmp	al,Mouse_Use_IRQ12
		jne	short NotIrq12

		mov	al,0A8H		;enable PS2 mouse interface
		out	64H,al
		NEWIODELAY

NotIrq12:
endif;	Break_Suspend_In_Mouse_CMOS
;R23A ifdef	Cover_Garbage_IRQ12			;R23 - starts
;R23A 		test	PM_RAM:[ALARM_RESUME], 80h	;Wake Event IRQ12 Enabled.
;R23A 		jnz	short W_IRQ12_En_
;R23A 		mov	al,0A8H		;enable PS2 mouse interface
;R23A 		out	64H,al
;R23A 		NEWIODELAY
;R23A 	W_IRQ12_En_:
;R23A endif;	Cover_Garbage_IRQ12			;R23 - ends

ifdef	HDD_PWRDOWN_IN_SUSPEND			
ifdef	HDD_PWRDOWN_IN_SUSPEND_After_1Min	

	       	mov	al,byte ptr PM_RAM:[HDD_OFF_Timer]
		cmp 	al,0				  
		jz	short @f			  

		Call	HDD_Timer_Restore	
@@:
;R68 start
else;	HDD_PWRDOWN_IN_SUSPEND_After_1Min	
		mov	cl,34h
		mov	bl,0Ch
		Call	E000_Get_Set_PMIO_OR
;R68 end
endif;	HDD_PWRDOWN_IN_SUSPEND_After_1Min	
endif;	HDD_PWRDOWN_IN_SUSPEND			

		mov	cl, 10h
		mov	al, 18h
		call	E000_Set_PMIO

		test	byte ptr PM_RAM:[ALARM_RESUME],01h		
		jz	short @F
		mov	cl, 01h		
		call	E000_Get_PMIO
		test	al, 04h
		jz	short @F
		push	ax
		mov	al, 0ch			;clear RTC 
		out	70h, al
		in	al, 71h
		pop	ax
		call	E000_Set_PMIO			
		mov	cl, 03h
		mov	bl, NOT 04h		
		call	E000_Get_Set_PMIO_AND	
;R20		mov	al,0				; Turn Off
;R20		call	far ptr RTC_Alarm_Resume
@@:
		mov	bh,0				;R20 Turn Off
		call	RTC_Alarm_Resume		;R20


;Enable decouple refresh before suspend

		pop	ax
		out	021h,al
		NEWIODELAY

		mov	al,ah
		out	0a1h,al

		pop	ax
		mov	cx, VT586_ACPI + 44h
		call	E000_Set_PMU

	;restore speaker status

	;restore reserved register

		in	al,80h
		mov	[POST_MODE],al
		mov	cx, VT586_ACPI + 53h
		call	E000_Get_PMU		;Is 2nd event ?
		mov	byte ptr PM_RAM:[The_2nd_Event],1
		test	al,00000010b
		jnz	short Susp_Exit
		mov	byte ptr PM_RAM:[The_2nd_Event],0
                
		mov	bx,(0 shl 8)+0feh
		call	E000_Get_Set_PMU

		call	Set_Full_On_State
		mov     al, 0FFh
		out     80h, al
Susp_Exit:						

;---------------------------------------------------------------------------;
; If you want to have the function of turn off fan during suspend.	    ;
; You must define :							    ;
;   Suspend_TurnOff_Fan_By_GPIO_0_High	EQU 1h or 2h,4h,8h,10h,20h,40h,80h  ;
;	or								    ;
;   Suspend_TurnOff_Fan_By_GPIO_0_Low	EQU 1h or 2h,4h,8h,10h,20h,40h,80h  ;
;---------------------------------------------------------------------------;
ifdef	Suspend_TurnOff_Fan_By_GPIO_0_High
		mov	cl, 42h			;
		mov	bl,not 01h		;GPIO 0 = Low
		call	E000_Get_Set_PMIO_AND	

		mov	cl, 40h			;
		mov	bl, 01h			;Active GPIO 0 is Output
		call	E000_Get_Set_PMIO_OR	
endif;	Suspend_TurnOff_Fan_By_GPIO_0_High
ifdef	Suspend_TurnOff_Fan_By_GPIO_0_Low
		mov	cl, 42h			;
		mov	bl, 01h			; GPIO 0 = High
		call	E000_Get_Set_PMIO_OR	

		mov	cl, 40h			;
		mov	bl, 01h			; Active GPIO 0 is Output
		call	E000_Get_Set_PMIO_OR	
ifdef	Suspend_SW_USE_EXTSMI			
if	Suspend_SW_USE_EXTSMI	EQ	01h	
		mov	cl, 40h			; Active GPIO 0 is Input
		mov	bl, not 01h		
		call	E000_Get_Set_PMIO_AND	
endif;	Suspend_SW_USE_EXTSMI			
endif;	Suspend_SW_USE_EXTSMI			
endif;	Suspend_TurnOff_Fan_By_GPIO_0_Low

ifdef	Suspend_TurnOff_Fan_By_GPIO_2_High
		mov	cl, 42h			;GPIO 2 = Low
		mov	bl,not 04h		;
		call	E000_Get_Set_PMIO_AND	;

		mov	cl, 40h			;Active GPIO 2 is Output
		mov	bl, 04h			;
		call	E000_Get_Set_PMIO_OR	;
endif;	Suspend_TurnOff_Fan_By_GPIO_2_High
ifdef	Suspend_TurnOff_Fan_By_GPIO_2_Low
		mov	cl, 42h			;GPIO 2 = High
		mov	bl, 04h			;
		call	E000_Get_Set_PMIO_OR	;

		mov	cl, 40h			;Active GPIO 2 is Output
		mov	bl, 04h			;
		call	E000_Get_Set_PMIO_OR	;
endif;	Suspend_TurnOff_Fan_By_GPIO_2_Low

ifdef	Suspend_TurnOff_Fan_By_GPIO_3_High
		mov	cl, 42h			;GPIO 4 = Low
		mov	bl,not 08h
		call	E000_Get_Set_PMIO_AND	;

		mov	cl, 40h			;Active GPIO 4 is Output
		mov	bl, 08h
		call	E000_Get_Set_PMIO_OR	;
endif;	Suspend_TurnOff_Fan_By_GPIO_3_High
ifdef	Suspend_TurnOff_Fan_By_GPIO_3_Low
		mov	cl, 42h			;GPIO 4 = High
		mov	bl, 08h
		call	E000_Get_Set_PMIO_OR	;

		mov	cl, 40h			;Active GPIO 4 is Output
		mov	bl, 08h
		call	E000_Get_Set_PMIO_OR	;
endif;	Suspend_TurnOff_Fan_By_GPIO_3_Low

ifdef	Suspend_TurnOff_Fan_By_GPIO_4_High
		mov	cl, 42h			;GPIO 4 = Low
		mov	bl,not 10h
		call	E000_Get_Set_PMIO_AND	;

		mov	cl, 40h			;Active GPIO 4 is Output
		mov	bl, 10h
		call	E000_Get_Set_PMIO_OR	;
endif;	Suspend_TurnOff_Fan_By_GPIO_4_High
ifdef	Suspend_TurnOff_Fan_By_GPIO_4_Low
		mov	cl, 42h			;GPIO 4 = High
		mov	bl, 10h
		call	E000_Get_Set_PMIO_OR	;

		mov	cl, 40h			;Active GPIO 4 is Output
		mov	bl, 10h
		call	E000_Get_Set_PMIO_OR	;
endif;	Suspend_TurnOff_Fan_By_GPIO_4_Low

ifdef	Suspend_TurnOff_Fan_By_GPO_LowByte_Low
		mov	cl, 46h			;GPO Hi Byte = High
		mov	bl, Suspend_TurnOff_Fan_By_GPO_LowByte_Low
		call	E000_Get_Set_PMIO_OR	;
endif;	Suspend_TurnOff_Fan_By_GPO_LowByte_Low
ifdef	Suspend_TurnOff_Fan_By_GPO_HiByte_Low
		mov	cl, 47h			;GPO Hi Byte = High
		mov	bl, Suspend_TurnOff_Fan_By_GPO_HiByte_Low
		call	E000_Get_Set_PMIO_OR	;
endif;	Suspend_TurnOff_Fan_By_GPO_HiByte_Low
ifdef	Suspend_TurnOff_Fan_By_GPO_LowByte_High
		mov	cl, 46h			;GPO Hi Byte = Low
		mov	bl,not Suspend_TurnOff_Fan_By_GPO_LowByte_High
		call	E000_Get_Set_PMIO_AND	;
endif;	Suspend_TurnOff_Fan_By_GPO_LowByte_High
ifdef	Suspend_TurnOff_Fan_By_GPO_HiByte_High
		mov	cl, 47h			;GPO Hi Byte = Low
		mov	bl,not Suspend_TurnOff_Fan_By_GPO_HiByte_High
		call	E000_Get_Set_PMIO_AND	;
endif;	Suspend_TurnOff_Fan_By_GPO_HiByte_High
ifdef	Suspend_TurnOff_Fan_By_GPO_Low		
		mov	dx, ACPI_Port + 46h	;GPO Word = High
		in	ax,dx
		or	ax, Suspend_TurnOff_Fan_By_GPO_Low
		out	dx,ax
		out	dx,ax
endif;	Suspend_TurnOff_Fan_By_GPO_Low		
IFDEF	VT596
		;---------------------------------------;
		;    >> 596(3050) : <<			;
		;  Control GPO to High After Suspend	;
		;---------------------------------------;
			;---------;
			; GPO0-7  ;
			;---------;
		GPO_Port_4C_VAL	= 00h
	ifdef	Suspend_Send_Low_To_GPO0
		GPO_Port_4C_VAL	= GPO_Port_4C_VAL OR 01h
	endif;	Suspend_Send_Low_To_GPO0
	ifdef	Suspend_Send_Low_To_GPO1
		GPO_Port_4C_VAL	= GPO_Port_4C_VAL OR 02h
	endif;	Suspend_Send_Low_To_GPO1
	ifdef	Suspend_Send_Low_To_GPO2
		GPO_Port_4C_VAL	= GPO_Port_4C_VAL OR 04h
	endif;	Suspend_Send_Low_To_GPO2
	ifdef	Suspend_Send_Low_To_GPO3
		GPO_Port_4C_VAL	= GPO_Port_4C_VAL OR 08h
	endif;	Suspend_Send_Low_To_GPO3
	ifdef	Suspend_Send_Low_To_GPO4
		GPO_Port_4C_VAL	= GPO_Port_4C_VAL OR 10h
	endif;	Suspend_Send_Low_To_GPO4
	ifdef	Suspend_Send_Low_To_GPO5
		GPO_Port_4C_VAL	= GPO_Port_4C_VAL OR 20h
	endif;	Suspend_Send_Low_To_GPO5
	ifdef	Suspend_Send_Low_To_GPO6
		GPO_Port_4C_VAL	= GPO_Port_4C_VAL OR 40h
	endif;	Suspend_Send_Low_To_GPO6
	ifdef	Suspend_Send_Low_To_GPO7
		GPO_Port_4C_VAL	= GPO_Port_4C_VAL OR 80h
	endif;	Suspend_Send_Low_To_GPO7
 ifdef	Suspend_Send_Low_To_GPO
  if	Suspend_Send_Low_To_GPO LE	7
GPO_Port_4C_VAL = GPO_Port_4C_VAL OR (01h SHL Suspend_Send_Low_To_GPO)
  endif;Suspend_Send_Low_To_GPO LE	7
 endif;	Suspend_Send_Low_To_GPO
if	GPO_Port_4C_VAL		NE	00h
		mov	cl, 4Ch
		mov	bl, GPO_Port_4C_VAL
		call	E000_Get_Set_PMIO_OR
endif;	GPO_Port_4C_VAL		NE	00h
			;---------;
			; GPO8-15 ;
			;---------;
		GPO_Port_4D_VAL	= 00h
	ifdef	Suspend_Send_Low_To_GPO8
		GPO_Port_4D_VAL	= GPO_Port_4D_VAL OR 01h
	endif;	Suspend_Send_Low_To_GPO8
	ifdef	Suspend_Send_Low_To_GPO9
		GPO_Port_4D_VAL	= GPO_Port_4D_VAL OR 02h
	endif;	Suspend_Send_Low_To_GPO9
	ifdef	Suspend_Send_Low_To_GPO10
		GPO_Port_4D_VAL	= GPO_Port_4D_VAL OR 04h
	endif;	Suspend_Send_Low_To_GPO10
	ifdef	Suspend_Send_Low_To_GPO11
		GPO_Port_4D_VAL	= GPO_Port_4D_VAL OR 08h
	endif;	Suspend_Send_Low_To_GPO11
	ifdef	Suspend_Send_Low_To_GPO12
		GPO_Port_4D_VAL	= GPO_Port_4D_VAL OR 10h
	endif;	Suspend_Send_Low_To_GPO12
	ifdef	Suspend_Send_Low_To_GPO13
		GPO_Port_4D_VAL	= GPO_Port_4D_VAL OR 20h
	endif;	Suspend_Send_Low_To_GPO13
	ifdef	Suspend_Send_Low_To_GPO14
		GPO_Port_4D_VAL	= GPO_Port_4D_VAL OR 40h
	endif;	Suspend_Send_Low_To_GPO14
	ifdef	Suspend_Send_Low_To_GPO15
		GPO_Port_4D_VAL	= GPO_Port_4D_VAL OR 80h
	endif;	Suspend_Send_Low_To_GPO15
 ifdef	Suspend_Send_Low_To_GPO
  if	Suspend_Send_Low_To_GPO LE	15
  if	Suspend_Send_Low_To_GPO GE	8
GPO_Port_4D_VAL = GPO_Port_4D_VAL OR (01h SHL (Suspend_Send_Low_To_GPO-8))
  endif;Suspend_Send_Low_To_GPO LE	8
  endif;Suspend_Send_Low_To_GPO LE	15
 endif;	Suspend_Send_Low_To_GPO
if	GPO_Port_4D_VAL		NE	00h
		mov	cl, 4Dh
		mov	bl, GPO_Port_4D_VAL
		call	E000_Get_Set_PMIO_OR
endif;	GPO_Port_4D_VAL		NE	00h
			;----------;
			; GPO16-23 ;
			;----------;
		GPO_Port_4E_VAL	= 00h
	ifdef	Suspend_Send_Low_To_GPO16
		GPO_Port_4E_VAL	= GPO_Port_4E_VAL OR 01h
	endif;	Suspend_Send_Low_To_GPO16
	ifdef	Suspend_Send_Low_To_GPO17
		GPO_Port_4E_VAL	= GPO_Port_4E_VAL OR 02h
	endif;	Suspend_Send_Low_To_GPO17
	ifdef	Suspend_Send_Low_To_GPO18
		GPO_Port_4E_VAL	= GPO_Port_4E_VAL OR 04h
	endif;	Suspend_Send_Low_To_GPO18
	ifdef	Suspend_Send_Low_To_GPO19
		GPO_Port_4E_VAL	= GPO_Port_4E_VAL OR 08h
	endif;	Suspend_Send_Low_To_GPO19
	ifdef	Suspend_Send_Low_To_GPO20
		GPO_Port_4E_VAL	= GPO_Port_4E_VAL OR 10h
	endif;	Suspend_Send_Low_To_GPO20
	ifdef	Suspend_Send_Low_To_GPO21
		GPO_Port_4E_VAL	= GPO_Port_4E_VAL OR 20h
	endif;	Suspend_Send_Low_To_GPO21
	ifdef	Suspend_Send_Low_To_GPO22
		GPO_Port_4E_VAL	= GPO_Port_4E_VAL OR 40h
	endif;	Suspend_Send_Low_To_GPO22
	ifdef	Suspend_Send_Low_To_GPO23
		GPO_Port_4E_VAL	= GPO_Port_4E_VAL OR 80h
	endif;	Suspend_Send_Low_To_GPO23
 ifdef	Suspend_Send_Low_To_GPO
  if	Suspend_Send_Low_To_GPO LE	23
  if	Suspend_Send_Low_To_GPO GE	16
GPO_Port_4E_VAL = GPO_Port_4E_VAL OR (01h SHL (Suspend_Send_Low_To_GPO-16))
  endif;Suspend_Send_Low_To_GPO LE	16
  endif;Suspend_Send_Low_To_GPO LE	23
 endif;	Suspend_Send_Low_To_GPO
if	GPO_Port_4E_VAL		NE	00h
		mov	cl, 4Eh
		mov	bl, GPO_Port_4E_VAL
		call	E000_Get_Set_PMIO_OR
endif;	GPO_Port_4E_VAL		NE	00h
			;----------;
			; GPO24-30 ;
			;----------;
		GPO_Port_4F_VAL	= 00h
	ifdef	Suspend_Send_Low_To_GPO24
		GPO_Port_4F_VAL	= GPO_Port_4F_VAL OR 01h
	endif;	Suspend_Send_Low_To_GPO24
	ifdef	Suspend_Send_Low_To_GPO25
		GPO_Port_4F_VAL	= GPO_Port_4F_VAL OR 02h
	endif;	Suspend_Send_Low_To_GPO25
	ifdef	Suspend_Send_Low_To_GPO26
		GPO_Port_4F_VAL	= GPO_Port_4F_VAL OR 04h
	endif;	Suspend_Send_Low_To_GPO26
	ifdef	Suspend_Send_Low_To_GPO27
		GPO_Port_4F_VAL	= GPO_Port_4F_VAL OR 08h
	endif;	Suspend_Send_Low_To_GPO27
	ifdef	Suspend_Send_Low_To_GPO28
		GPO_Port_4F_VAL	= GPO_Port_4F_VAL OR 10h
	endif;	Suspend_Send_Low_To_GPO28
	ifdef	Suspend_Send_Low_To_GPO29
		GPO_Port_4F_VAL	= GPO_Port_4F_VAL OR 20h
	endif;	Suspend_Send_Low_To_GPO29
	ifdef	Suspend_Send_Low_To_GPO30
		GPO_Port_4F_VAL	= GPO_Port_4F_VAL OR 40h
	endif;	Suspend_Send_Low_To_GPO30
 ifdef	Suspend_Send_Low_To_GPO
  if	Suspend_Send_Low_To_GPO LE	30
  if	Suspend_Send_Low_To_GPO GE	24
GPO_Port_4F_VAL = GPO_Port_4F_VAL OR (01h SHL (Suspend_Send_Low_To_GPO-24))
  endif;Suspend_Send_Low_To_GPO LE	24
  endif;Suspend_Send_Low_To_GPO LE	30
 endif;	Suspend_Send_Low_To_GPO
if	GPO_Port_4F_VAL		NE	00h
		mov	cl, 4Fh
		mov	bl, GPO_Port_4F_VAL
		call	E000_Get_Set_PMIO_OR
endif;	GPO_Port_4F_VAL		NE	00h

		;---------------------------------------;
		;    >> 596(3050) : <<			;
		;  Control GPO to Low After Suspend	;
		;---------------------------------------;
			;---------;
			; GPO0-7  ;
			;---------;
		GPO_Port_4C_VAL	= 00h
	ifdef	Suspend_Send_High_To_GPO0
		GPO_Port_4C_VAL	= GPO_Port_4C_VAL OR 01h
	endif;	Suspend_Send_High_To_GPO0
	ifdef	Suspend_Send_High_To_GPO1
		GPO_Port_4C_VAL	= GPO_Port_4C_VAL OR 02h
	endif;	Suspend_Send_High_To_GPO1
	ifdef	Suspend_Send_High_To_GPO2
		GPO_Port_4C_VAL	= GPO_Port_4C_VAL OR 04h
	endif;	Suspend_Send_High_To_GPO2
	ifdef	Suspend_Send_High_To_GPO3
		GPO_Port_4C_VAL	= GPO_Port_4C_VAL OR 08h
	endif;	Suspend_Send_High_To_GPO3
	ifdef	Suspend_Send_High_To_GPO4
		GPO_Port_4C_VAL	= GPO_Port_4C_VAL OR 10h
	endif;	Suspend_Send_High_To_GPO4
	ifdef	Suspend_Send_High_To_GPO5
		GPO_Port_4C_VAL	= GPO_Port_4C_VAL OR 20h
	endif;	Suspend_Send_High_To_GPO5
	ifdef	Suspend_Send_High_To_GPO6
		GPO_Port_4C_VAL	= GPO_Port_4C_VAL OR 40h
	endif;	Suspend_Send_High_To_GPO6
	ifdef	Suspend_Send_High_To_GPO7
		GPO_Port_4C_VAL	= GPO_Port_4C_VAL OR 80h
	endif;	Suspend_Send_High_To_GPO7
 ifdef	Suspend_Send_High_To_GPO
  if	Suspend_Send_High_To_GPO LE	7
GPO_Port_4C_VAL = GPO_Port_4C_VAL OR (01h SHL Suspend_Send_High_To_GPO)
  endif;Suspend_Send_High_To_GPO LE	7
 endif;	Suspend_Send_High_To_GPO
if	GPO_Port_4C_VAL		NE	00h
		mov	cl, 4Ch
		mov	bl,not GPO_Port_4C_VAL
		call	E000_Get_Set_PMIO_AND
endif;	GPO_Port_4C_VAL		NE	00h
			;---------;
			; GPO8-15 ;
			;---------;
		GPO_Port_4D_VAL	= 00h
	ifdef	Suspend_Send_High_To_GPO8
		GPO_Port_4D_VAL	= GPO_Port_4D_VAL OR 01h
	endif;	Suspend_Send_High_To_GPO8
	ifdef	Suspend_Send_High_To_GPO9
		GPO_Port_4D_VAL	= GPO_Port_4D_VAL OR 02h
	endif;	Suspend_Send_High_To_GPO9
	ifdef	Suspend_Send_High_To_GPO10
		GPO_Port_4D_VAL	= GPO_Port_4D_VAL OR 04h
	endif;	Suspend_Send_High_To_GPO10
	ifdef	Suspend_Send_High_To_GPO11
		GPO_Port_4D_VAL	= GPO_Port_4D_VAL OR 08h
	endif;	Suspend_Send_High_To_GPO11
	ifdef	Suspend_Send_High_To_GPO12
		GPO_Port_4D_VAL	= GPO_Port_4D_VAL OR 10h
	endif;	Suspend_Send_High_To_GPO12
	ifdef	Suspend_Send_High_To_GPO13
		GPO_Port_4D_VAL	= GPO_Port_4D_VAL OR 20h
	endif;	Suspend_Send_High_To_GPO13
	ifdef	Suspend_Send_High_To_GPO14
		GPO_Port_4D_VAL	= GPO_Port_4D_VAL OR 40h
	endif;	Suspend_Send_High_To_GPO14
	ifdef	Suspend_Send_High_To_GPO15
		GPO_Port_4D_VAL	= GPO_Port_4D_VAL OR 80h
	endif;	Suspend_Send_High_To_GPO15
 ifdef	Suspend_Send_High_To_GPO
  if	Suspend_Send_High_To_GPO LE	15
  if	Suspend_Send_High_To_GPO GE	8
GPO_Port_4D_VAL = GPO_Port_4D_VAL OR (01h SHL (Suspend_Send_High_To_GPO-8))
  endif;Suspend_Send_High_To_GPO LE	8
  endif;Suspend_Send_High_To_GPO LE	15
 endif;	Suspend_Send_High_To_GPO
if	GPO_Port_4D_VAL		NE	00h
		mov	cl, 4Dh
		mov	bl,not GPO_Port_4D_VAL
		call	E000_Get_Set_PMIO_AND
endif;	GPO_Port_4D_VAL		NE	00h
			;----------;
			; GPO16-23 ;
			;----------;
		GPO_Port_4E_VAL	= 00h
	ifdef	Suspend_Send_High_To_GPO16
		GPO_Port_4E_VAL	= GPO_Port_4E_VAL OR 01h
	endif;	Suspend_Send_High_To_GPO16
	ifdef	Suspend_Send_High_To_GPO17
		GPO_Port_4E_VAL	= GPO_Port_4E_VAL OR 02h
	endif;	Suspend_Send_High_To_GPO17
	ifdef	Suspend_Send_High_To_GPO18
		GPO_Port_4E_VAL	= GPO_Port_4E_VAL OR 04h
	endif;	Suspend_Send_High_To_GPO18
	ifdef	Suspend_Send_High_To_GPO19
		GPO_Port_4E_VAL	= GPO_Port_4E_VAL OR 08h
	endif;	Suspend_Send_High_To_GPO19
	ifdef	Suspend_Send_High_To_GPO20
		GPO_Port_4E_VAL	= GPO_Port_4E_VAL OR 10h
	endif;	Suspend_Send_High_To_GPO20
	ifdef	Suspend_Send_High_To_GPO21
		GPO_Port_4E_VAL	= GPO_Port_4E_VAL OR 20h
	endif;	Suspend_Send_High_To_GPO21
	ifdef	Suspend_Send_High_To_GPO22
		GPO_Port_4E_VAL	= GPO_Port_4E_VAL OR 40h
	endif;	Suspend_Send_High_To_GPO22
	ifdef	Suspend_Send_High_To_GPO23
		GPO_Port_4E_VAL	= GPO_Port_4E_VAL OR 80h
	endif;	Suspend_Send_High_To_GPO23
 ifdef	Suspend_Send_High_To_GPO
  if	Suspend_Send_High_To_GPO LE	23
  if	Suspend_Send_High_To_GPO GE	16
GPO_Port_4E_VAL = GPO_Port_4E_VAL OR (01h SHL (Suspend_Send_High_To_GPO-16))
  endif;Suspend_Send_High_To_GPO LE	16
  endif;Suspend_Send_High_To_GPO LE	23
 endif;	Suspend_Send_High_To_GPO
if	GPO_Port_4E_VAL		NE	00h
		mov	cl, 4Eh
		mov	bl,not GPO_Port_4E_VAL
		call	E000_Get_Set_PMIO_AND
endif;	GPO_Port_4E_VAL		NE	00h
			;----------;
			; GPO24-30 ;
			;----------;
		GPO_Port_4F_VAL	= 00h
	ifdef	Suspend_Send_High_To_GPO24
		GPO_Port_4F_VAL	= GPO_Port_4F_VAL OR 01h
	endif;	Suspend_Send_High_To_GPO24
	ifdef	Suspend_Send_High_To_GPO25
		GPO_Port_4F_VAL	= GPO_Port_4F_VAL OR 02h
	endif;	Suspend_Send_High_To_GPO25
	ifdef	Suspend_Send_High_To_GPO26
		GPO_Port_4F_VAL	= GPO_Port_4F_VAL OR 04h
	endif;	Suspend_Send_High_To_GPO26
	ifdef	Suspend_Send_High_To_GPO27
		GPO_Port_4F_VAL	= GPO_Port_4F_VAL OR 08h
	endif;	Suspend_Send_High_To_GPO27
	ifdef	Suspend_Send_High_To_GPO28
		GPO_Port_4F_VAL	= GPO_Port_4F_VAL OR 10h
	endif;	Suspend_Send_High_To_GPO28
	ifdef	Suspend_Send_High_To_GPO29
		GPO_Port_4F_VAL	= GPO_Port_4F_VAL OR 20h
	endif;	Suspend_Send_High_To_GPO29
	ifdef	Suspend_Send_High_To_GPO30
		GPO_Port_4F_VAL	= GPO_Port_4F_VAL OR 40h
	endif;	Suspend_Send_High_To_GPO30
 ifdef	Suspend_Send_High_To_GPO
  if	Suspend_Send_High_To_GPO LE	30
  if	Suspend_Send_High_To_GPO GE	24
GPO_Port_4F_VAL = GPO_Port_4F_VAL OR (01h SHL (Suspend_Send_High_To_GPO-24))
  endif;Suspend_Send_High_To_GPO LE	24
  endif;Suspend_Send_High_To_GPO LE	30
 endif;	Suspend_Send_High_To_GPO
if	GPO_Port_4F_VAL		NE	00h
		mov	cl, 4Fh
		mov	bl,not GPO_Port_4F_VAL
		call	E000_Get_Set_PMIO_AND
endif;	GPO_Port_4F_VAL		NE	00h
ENDIF;	VT596
	ifdef	Blink_Suspend_LED_In_GPO0			;R50
		ifdef	VT686					;R50
		mov	cx,VT586_ACPI + 54h			;R50
		mov	bl,not 03h				;R50
		call	E000_Get_Set_PMU_AND			;R50
		endif;	VT686					;R50
	endif;	Blink_Suspend_LED_In_GPO0			;R50

ifndef	New_Superio_Led_Function		;R42
ifdef	PM_LED_USE_GPIO					
		pushad					
		mov	al, 0				
		Call 	far ptr F000_SET_PM_LED		
		popad					
endif;	PM_LED_USE_GPIO					
ifdef	LED_Blinking_at_PM				
		pushad					
		mov	al, 0				
		Call 	far ptr F000_SET_PM_LED_Blinking
		popad					
endif;	LED_Blinking_at_PM				
ifdef	POWER_LED_USE					
		pushad					
		mov	al, 0				
		Call 	far ptr F000_SET_POWER_LED	
		popad					
endif;	POWER_LED_USE					
;R42 - start
else	;New_Superio_Led_Function
ifdef	LED_Blinking_at_PM				
		pushad					
		mov	al, 0				
		Call 	far ptr F000_LED_Flash
		popad					
endif;	LED_Blinking_at_PM				
endif	;New_Superio_Led_Function

;R42Aifdef	Superio_Support_Fan
;R42A		pushad
;R42A		Call	far ptr F000_Fan_Power_On
;R42A		popad
;R42Aendif;	Superio_Support_Fan
;R42 - end
		call	Clear_Power_Buttom_Status	

 		call	Clear_Modem_Ring_Status		

		ret

Go_Suspend	Endp

;R41 - start
ifdef	W83782D_CPUFAN_CNTL_IN_SUSPEND		       
Software_I2C_In_SMBase		EQU	1	       
endif;	W83782D_CPUFAN_CNTL_IN_SUSPEND		       
;R57 - start
ifdef	ADM9240_CPUFAN_CNTL_IN_SUSPEND
Software_I2C_In_SMBase		EQU	1
endif;	ADM9240_CPUFAN_CNTL_IN_SUSPEND
;R57 - end

ifdef	Software_I2C_In_SMBase		
ifndef	VT596
  IFDEF	Software_I2C
GPIO_Dir        EQU     ACPI_Port+40h
GPIO_WPort      EQU     ACPI_Port+42h
GPIO_RdPort     EQU     ACPI_Port+44h
		Public	Set_Pointer
		Public	Rd_Data
		Public	Set_NoACK
		Public	Set_ACK

    ifdef	SDA_In_GPIO1
SDA             EQU     02	;GPIO1 Data
SCL             EQU     04	;GPIO2 Clock
    else;	SDA_In_GPIO1
SDA             EQU     04	;GPIO2 Data (Normal)
SCL             EQU     02	;GPIO1 Clock
    endif;	SDA_In_GPIO1
;ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
;º  X_Dir_Out                                                                 º
;º                                                                          º
;º  Input:  None                                                            º
;º  Output: None                                                            º
;ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ¼
		Public	X_Dir_Out
X_Dir_Out	proc	Near
        push    ax
        push    dx
        mov     cl,40h
        mov     bl,06h
        call    X_Get_Set_PMIO_OR
        pop     dx
        pop     ax
        ret
X_Dir_Out endp

;ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
;º  Set_Pointer                                                             º
;º  Input:  BX = pointer                                                    º
;º  Output: CLC = PK                                                        º
;º          STC = Fail                                                      º
;ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ¼
Set_Pointer     proc
        push    bx              ;Save Register Pointer
	push	cx
        call    	Dir_Out
        call    Set_Start
	pop	cx
        mov     bl,ch		;ch is Device ID
        call    Wr_Byte
        call    Wait_ACK
        pop     bx
        jc      ErrSet_Pointer
        call    Wr_Byte         ;bx = pointer
        call    Wait_ACK
        jc      ErrSet_Pointer
        clc
        ret
ErrSet_Pointer:
        stc
        ret
Set_Pointer     endp

;ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
;º  Rd_Data                                                                 º
;º                                                                          º
;º  Input:  None                                                            º
;º  Output: BL: return data                                                 º
;ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ¼
Rd_Data proc
        mov     cx,40h                  
        mov     bl, NOT SDA		
	mov	bh, SCL			
        call    E000_Get_Set_PMIO       

        xor     bx, bx          ;Frank
        xor     ax, ax
        mov     cx, 8
Rd_byte:
        push    cx
        mov     cx, 8                           ;T(low) = 4.7 us
@@:
        out     0ebh, al
        loop    short @B
        mov     dx,GPIO_WPort		
	in	al, dx			
        or      al, SCL			
        out     dx, al                  ;SCL high, receiver will read data
        mov     cx, 8                           ;T(high) = 4 us
@@:
        out     0ebh, al
        loop    short @B

        mov     cx,44h			;
        call    E000_Get_PMIO		;

        and     al, SDA 
ifdef	SDA_In_GPIO1
        shr     al, 1		;;if SDA=02h, SCL=04h
else;	SDA_In_GPIO1
        shr     al, 2		;;if SDA=04h, SCL=02h
endif;	SDA_In_GPIO1
        shl     bl, 1           
        or      bl, al

		mov     dx, GPIO_WPort		
		in	al, dx			
		and     al, NOT SCL             ;SCL low
		out	dx, al			

        pop     cx
        loop    Rd_byte

        mov     cx, 8                           ;T(hd)
@@:
        out     0ebh, al
        loop    short @B

        mov     dx,GPIO_Dir		
        in      al, dx			
        or      al, SDA			
        or      al, SCL			
        out     dx, al                  ;Set SCL O/P , SDA I/P

        ret
Rd_Data endp


;ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
;º  Set_NoACK                                                               º
;º                                                                          º
;º  Input:  None                                                            º
;º  Output: None                                                            º
;ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ¼
Set_NoACK       proc
        mov     dx,GPIO_WPort		
        in      al, dx			
        and     al, NOT SCL		
        or      al, SDA			
        out     dx, al                  ;out No ACK

        out     0ebh, al                ;T(setup) = 250 ns

        or      al, SCL
        out     dx, al                  ;SCL ,SDA = high
        mov     cx, 8                   ;T(high) = 4 us
@@:
        out     0ebh, al
        loop    short @B

        and     al, NOT SCL
        out     dx, al                  ;SCL = low
        out     0ebh, al

        and     al, NOT SDA
        out     dx, al                  ;SDA = low
        out     0ebh, al

        ret
Set_NoACK       endp

;ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
;º  Set_ACK                                                                 º
;º                                                                          º
;º  Input:  None                                                            º
;º  Output: None                                                            º
;ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ¼
Set_ACK proc
        mov     cx,42h                  
	in	al, dx			
        mov     bl, NOT SCL             
        and	bl, NOT SDA		
        call    E000_Get_Set_PMIO_AND	

        out     0ebh, al                ;T(setup) = 250 ns

	mov	dx,GPIO_WPort		
        or      al, SCL
        out     dx, al                  ;SCL ,SDA = high
        mov     cx, 8                   ;T(high) = 4 us
@@:
        out     0ebh, al
        loop    short @B
        and     al, NOT SCL
        out     dx, al                  ;SCL = low
        out     0ebh, al

        and     al, NOT SDA
        out     dx, al                  ;SDA = low
        out     0ebh, al
        ret
Set_ACK endp

I2CReadByte   Proc    Near

	push	cx		;save Device ID
        mov     bl,cl
        call    Set_Pointer
        NEWIODELAY
        NEWIODELAY
        call    Set_Start
	pop	cx		;restore Device ID
        mov     bl,ch		;ch is Device ID
        inc     bl              ;for read operation
        call    Wr_Byte
        call    Wait_ACK
        jc      Rd_1ByteReg_Fail
        call    Rd_Data         ;bl = data
        shl     ebx,16
        call    Set_NoACK
        call    Set_Stop
        shr     ebx,16
        xor     bh,bh   ;BL = value
        mov     al,bl
        clc
        ret
Rd_1ByteReg_Fail:
        stc
        ret

Ct_I2CReadByte   Endp

;[]==============================================================[]
;Input : CL - register index
;        AL - Value to write
;Output: none
;[]==============================================================[]
I2CWriteByte   Proc    Near

        push    ax      
        mov     bl,cl
        cli

        call    Set_Pointer
        newiodelay
        newiodelay
        pop     ax
        mov     bl,al
        call    Wr_Byte

        call    Wait_ACK

        jc      Wr_1ByteReg_Fail
        call    Set_Stop

        clc
        sti
        ret
Wr_1ByteReg_Fail:

        stc
        sti
        ret
Ct_I2CWriteByte   Endp
  ENDIF;	Software_I2C
endif;	VT596

ifdef	VT596
  IFDEF	SMBus_Port
		extrn	WaitSMBus:near
;[]==============================================================[]
;Input	: CL - register index
;	  CH - device ID 
;Output : AL - Value read
;[]==============================================================[]
I2CReadByte	Proc	Near

		push	cx

		mov	dx,SMBus_Port +04h
		inc	ch
		mov	al,ch			;ID cmd(read)
		out	dx,al
		NEWIODELAY
		NEWIODELAY

		call	Chk_SMBus_READY 

		pop	ax
		mov	dl,03h
		out	dx,al			;Index
		NEWIODELAY
		NEWIODELAY

		mov	dl,02h
		mov	al,48h
		out	dx,al			;read data
		NEWIODELAY
		NEWIODELAY

		mov	cx,1000h
	@@:				
		newiodelay			
		loop	short @B			

		call	Chk_SMBus_READY 

		mov	dl,05
		in	al,dx			;Data0
		NEWIODELAY
		NEWIODELAY

		ret
I2CReadByte	Endp

;[]==============================================================[]
;Input : CL - register index
;	 CH - device ID 
;	 AL - Value to write
;Output: none
;[]==============================================================[]
I2CWriteByte	Proc	Near

		push	ax
		push	cx

		mov	dx,SMBus_Port +04h
		mov	al,ch			;ID cmd(Write)
		out	dx,al
		NEWIODELAY
		NEWIODELAY

		call	Chk_SMBus_READY 

		pop	ax
		mov	dl,03h
		out	dx,al			;Index
		NEWIODELAY
		NEWIODELAY

		pop	ax
		mov	dl,05
		out	dx,al			;Data0
		NEWIODELAY
		NEWIODELAY

		mov	dl,02h
		mov	al,48h
		out	dx,al			;write data
		NEWIODELAY
		NEWIODELAY

		mov	cx, 1000h
	@@:				
		newiodelay			
		loop	short @B			

		call	Chk_SMBus_READY 

		ret
I2CWriteByte	Endp

Chk_SMBus_READY	Proc	Near
		mov	dx,SMBus_Port + 0
		clc
		mov	cx,0100h
Chk_I2C_OK:
		in	al,dx		;get status
		or	al,al
		jz	short Clear_final

		test	al,04h		       
		jnz	short SMBus_Err	       

		test	al,01h		;busy ?
		jz	short Not_Smbusy
		call	WaitSmbus
Not_Smbusy:
		out 	dx,al
		loop	short Chk_I2C_OK
SMBus_Err:	
		out	dx,al			    
		NEWIODELAY			    
		in	al,dx		;get status 
		NEWIODELAY			    
		test	al,04h			    
		jnz	short SMBus_Err			
		stc
Clear_final:
		ret
Chk_SMBus_READY	Endp

  ENDIF;SMBus_Port
endif;	VT596
endif;	Software_I2C_In_SMBase

ifdef	W83782D_CPUFAN_CNTL_IN_SUSPEND
ifdef	W83783S_Support			
W83782D_USE_SMBUS	equ	1	
else;	W83783S_Support			
W83782D_PORT	equ	295h
endif;	W83783S_Support			
IF	CPU1_FAN_USE_PWM  EQ 	1
ifdef	W83783S_Support			
CPU1_FAN_INDX	equ	5Ah
else;	W83783S_Support			
CPU1_FAN_INDX	equ	5Bh
endif;	W83783S_Support			
ENDIF;	CPU1_FAN_USE_PWM  EQ 	1
IF	CPU1_FAN_USE_PWM  EQ 	2
ifdef	W83783S_Support			
CPU1_FAN_INDX	equ	5Bh		
else;	W83783S_Support			
CPU1_FAN_INDX	equ	5Ah
endif;	W83783S_Support			
ENDIF;	CPU1_FAN_USE_PWM  EQ 	2
ifndef	W83783S_Support			
IF	CPU1_FAN_USE_PWM  EQ 	3
CPU1_FAN_INDX	equ	5Eh
ENDIF;	CPU1_FAN_USE_PWM  EQ 	3
IF	CPU1_FAN_USE_PWM  EQ 	4
CPU1_FAN_INDX	equ	5Fh
ENDIF;	CPU1_FAN_USE_PWM  EQ 	4

ifdef	Show_CPU2_Temp
IF	CPU2_FAN_USE_PWM  EQ 	1
CPU2_FAN_INDX	equ	5Bh
ENDIF;	CPU2_FAN_USE_PWM  EQ 	1
IF	CPU2_FAN_USE_PWM  EQ 	2
CPU2_FAN_INDX	equ	5Ah
ENDIF;	CPU2_FAN_USE_PWM  EQ 	2
IF	CPU2_FAN_USE_PWM  EQ 	3
CPU2_FAN_INDX	equ	5Eh
ENDIF;	CPU2_FAN_USE_PWM  EQ 	3
IF	CPU2_FAN_USE_PWM  EQ 	4
CPU2_FAN_INDX	equ	5Fh
ENDIF;	CPU2_FAN_USE_PWM  EQ 	4
endif;	Show_CPU2_Temp
endif;	W83783S_Support			

Turn_Off_CPU_Fan	proc	near
		mov	cl, CPU1_FAN_INDX
		xor	al, al
		call	Set_W83782D
ifndef	W83783S_Support			
ifdef	Show_CPU2_Temp
		mov	cl, CPU2_FAN_INDX
		xor	al, al
		call	Set_W83782D
endif;	Show_CPU2_Temp
;R43 - start
ifdef	FAN3_CNTL_USE_PWM
		mov	cl, Fan3_FAN_INDX
		xor	al, al
		call	Set_W83782D
endif;	FAN3_CNTL_USE_PWM
;R43 - end
endif;	W83783S_Support			
		ret
Turn_Off_CPU_Fan	endp

Turn_On_CPU_Fan	proc	near
		mov	cl, CPU1_FAN_INDX
		mov	al, 0ffh
		call	Set_W83782D
ifndef	W83783S_Support			
ifdef	Show_CPU2_Temp
		mov	cl, CPU2_FAN_INDX
		mov	al, 0ffh
		call	Set_W83782D
endif;	Show_CPU2_Temp
;R43 - start
ifdef	FAN3_CNTL_USE_PWM
		mov	cl, Fan3_FAN_INDX
		mov	al, 0ffh
		call	Set_W83782D
endif;	FAN3_CNTL_USE_PWM
;R43 - end
endif;	W83783S_Support			
		ret
Turn_On_CPU_Fan	endp

;[]==============================================================[]
;Input : CL - register index
;	 AL - Value to write
;Output: none
;[]==============================================================[]
Set_W83782D	Proc	Near

ifdef	W83782D_USE_SMBUS

		pushf
		push	dx
		mov	ch, 5ah
		call	I2CWriteByte
		pop	dx
		popf

else;	W83782D_USE_SMBUS
		pushf
		push	dx
		push	ax

		mov	dx,W83782D_PORT
		mov	al,cl
		out	dx,al

		push	cx
		mov	cx,100h
	     @@:
		newiodelay
		loop	short @B
		pop	cx

		inc	dx
		pop	ax
		out	dx,al
		newiodelay
		newiodelay

		pop	dx
		popf
endif;	W83782D_USE_SMBUS
		ret
Set_W83782D	Endp

endif;	W83782D_CPUFAN_CNTL_IN_SUSPEND
;R41 - end
;R57 - start
ifdef	ADM9240_CPUFAN_CNTL_IN_SUSPEND		       
Turn_On_Fan	Proc	Near
		pushf
		push	dx
		mov	al, 0ffh
		mov	cl, 019h
		mov	ch, ADM9240_ID
		call	I2CWriteByte
		pop	dx
		popf
		ret
Turn_On_Fan	ENDP
Turn_Off_Fan	Proc	Near
		pushf
		push	dx
		xor	al,al
		mov	cl, 19h
		mov	ch, ADM9240_ID
		call	I2CWriteByte
		pop	dx
		popf
		ret
Turn_Off_Fan	ENDP
endif;	ADM9240_CPUFAN_CNTL_IN_SUSPEND		       
;R57 - end

;R42A - start
ifdef	Superio_Support_Sensor
		COMPILE_FOR_PMUPOST_ASM	= 1
		include	Sensor.SSR
endif	;Superio_Support_Sensor
;R42A - end

Clear_Modem_Ring_Status	Proc	Near

		xor	bx,bx				
@@:
		dec	bx				
		jz	short @f			
		mov	cl, 21h				;Clear RI# status
		call	E000_Get_PMIO			
		and	al,01h
		call	E000_Set_PMIO			
		call	E000_Get_PMIO			
		cmp	al,al
		test	al,01h
		jnz	short @b
@@:							
		mov	cl, 25h				;Disable RI# SMI
		mov	bl,not 01h			
		call	E000_Get_Set_PMIO_AND		

		ret
Clear_Modem_Ring_Status	Endp

Set_Modem_Ring_Status	Proc	Near

ifndef	RI_AlWAYS_Wakeup_SUSPEND			;R69
		test	PM_RAM:[ALARM_RESUME], 08h
		jz	short	@f
endif	;RI_AlWAYS_Wakeup_SUSPEND			;R69
		mov	cl, 25h				;Enable RI# SMI
		mov	bl, 01h
		call	E000_Get_Set_PMIO_OR
@@:
		ret
Set_Modem_Ring_Status	Endp
;R69 start
ifdef	RI_AlWAYS_Wakeup_SUSPEND
Restore_Ring_Setting	proc	near
		pusha
		xor	bl,bl
		test	PM_RAM:[ALARM_RESUME], 08h
		jz	short RI_dis
		mov	bl,1
	RI_dis:
		mov	cl,25h
		call	E000_Get_PMIO
		and	al,not 01h
		or	al,bl
		call	E000_SeT_PMIO
		popa
		ret
Restore_Ring_Setting	ENDP
endif	;RI_AlWAYS_Wakeup_SUSPEND
;R69 end

ifdef	HDD_PWRDOWN_IN_SUSPEND
		Public	HDD_power_Down
HDD_power_Down	Proc	Near

		push	es

		mov	ax,G_RAM
		mov	es,ax
		ASSUME	ES:G_RAM

		mov	cl,G_RAM:[NUMHDSKS]
		or	cl,cl
		jz	short No_HDD_Exist

		in	al,0a1h
		or	al,0c0h
		out	0a1h,al

		mov	al,G_RAM:[HDD_Drive_Port]
		xor	ah,ah
@@:
		mov	bl,al
		and	bl,03h
ifndef	HDD_PWRDOWN_IN_SUSPEND_After_1Min	;R68	
		Call	HDD_Power_Off		;R68
endif	;HDD_PWRDOWN_IN_SUSPEND_After_1Min	;R68	
		shr	al,2
		loop	short @B

No_HDD_Exist:
		pop	es
		ret

HDD_power_Down	Endp

ifndef	HDD_PWRDOWN_IN_SUSPEND_After_1Min		
HDD_Power_Off	Proc	Near

		push	ax

		mov	dx,1f6h
		test	bl,02h
		jz	short @F
		mov	dx,176h
@@:	
		mov	al,0A0h
		test	bl,01h
		jz	short @F
		mov	al,0B0h
@@:	
		
		out	dx,al			;setlect HDD
		iodelay

		inc	dx
		mov	al,0E0h
		out	dx,al			;HDD power down immediately
		iodelay

		and	es:[FDD_VERIFY_CMD_FLAG],not 40h;tell INT 13 
							;  to wait HDD
		pop	ax
		ret

HDD_Power_Off	Endp

else;	HDD_PWRDOWN_IN_SUSPEND_After_1Min
HDD_Timer_Restore	Proc	Near

		push	es

		mov	ax,G_RAM
		mov	es,ax
		ASSUME	ES:G_RAM

		mov	cl,G_RAM:[NUMHDSKS]
		or	cl,cl
		jz	short No_HDD_Exist2

		mov	al,G_RAM:[HDD_Drive_Port]
		xor	ah,ah
@@:
		mov	bl,al
		and	bl,03h

		Call	Set_HDD_Timer

		shr	al,2
		loop	short @B

No_HDD_Exist2:
		pop	es
		ret

HDD_Timer_Restore 	Endp
Set_HDD_Timer	Proc	Near

		push	ax

		mov	dx,1f2h
		test	bl,02h
		jz	short @F
		mov	dx,172h
	@@:	
		mov	bl,0ch			;set 1 min
		mov	al,byte ptr [HDD_OFF_Timer]
		mul	bl
		out	dx,al			;set the seconds
		iodelay
		iodelay

		mov	al,0a0h
		test	bl,01h
		jz	short @F
		mov	al,0b0h
	@@:	
		add	dl,4
		out	dx,al			;setlect HDD
		iodelay
		iodelay

		inc	dx
		mov	al,0E3h
		out	dx,al			;HDD idle timer
		iodelay

		and	es:[FDD_VERIFY_CMD_FLAG],not 40h;tell INT 13 
							;  to wait HDD
		pop	ax
		ret

Set_HDD_Timer	Endp

endif;	HDD_PWRDOWN_IN_SUSPEND_After_1Min
endif;	HDD_PWRDOWN_IN_SUSPEND

ifdef	V_ALARM_IN_E000
Chk_more_V_Alarm_wakeup_source	equ	1 	;R52
		include	v_alarm.inc
;R59 - strats
ifdef	Chk_more_V_Alarm_wakeup_source 
Chkwakeup_source	proc	near 
		mov	cx, 01h	     
		call    E000_Get_PMIO
		test	al,5h	     
		jnz	short @F     
		mov	cx, 20h	     
		call    E000_Get_PMIO
		test	al,0ffh	     
		jnz	short @F     
		mov	cx, 21h	     
		call    E000_Get_PMIO
		test	al,03h	     
	@@:			     
		ret		     
Chkwakeup_source	ENDP	     
endif	;Chk_more_V_Alarm_wakeup_source
;R59 - ends

Low_Power_Throttling	Proc	Near
		mov	cx,VT586 +8eh
		mov	al,0fh
		call	E000_Set_PMU
		ret
Low_Power_Throttling	Endp
endif	;V_ALARM_IN_E000

ifdef	Suspend_LED_Control
;Send output to SMOUT pin
;Input : AH - 1 = SMOUT high
;	 AH - 0 = SMOUT low
Send_Smout	proc	near
		push	dx
		mov	dx,0a8h
		mov	al,0c8h
		out	dx,al
		xor	al,al
		test	ah,1
		jnz	short @F
		mov	al,0ffh
@@:
		inc	dx
		out	dx,al
		pop	dx
		ret
Send_Smout	endp
endif;	Suspend_LED_Control			

		ALIGN	4
Enable_WakeUp_Source	Proc	Near

		mov	cl, 30h			;clear primary status
		call	E000_Set_PMIO_Clear	

		mov	al,PM_RAM:[VT586PM_I34h_Value]
		mov	cl, 34h			;set dector
		call	E000_Set_PMIO

		mov	cl, 2ah			;enable Primary Active
		mov	bl, 01h			;
		call	E000_Get_Set_PMIO_OR	;

ifdef	LID_SUPPORT					;R13
		mov	cl, 23h				;R13
		mov	bl, 10h				;R13
		call	E000_Get_Set_PMIO_OR		;R13
endif;	LID_SUPPORT					;R13

;R65A start
ifdef	PME_SUPPORT
ifdef	PME_AlWAYS_Wakeup_SUSPEND
		call	Enable_PME
endif	;PME_AlWAYS_Wakeup_SUSPEND
endif	;PME_SUPPORT
;R65A end
		ret

Enable_WakeUp_Source	Endp

SMI_F0call_Proc:
		;push	Func_Addr			;[bp+8]
		;push	Ret_Addr			;[bp+6]
		push	offset F000_Func_End		;[bp+4]
		push	cs				;[bp+2]
		push	ax				;[bp]
		xchg	bp,sp
		mov	ax,[bp+2]
		xchg	ax,[bp+8]
		mov	[bp+2],ax
		xchg	bp,sp
		pop	ax
		FAR_JMP <offset F000_Vect>,0F000h

ifdef 	ACPI_Support
;Need to include chip set dependent EQU for SMI_CMD port.
;
	include	ACPI.INC
	include	ACPI_CT.INC
;[]========================================================================[]
;ACPIOnOff
;Check if this SW SMI is ACPI on/off request or not.  If yes, set the
;SCI_EN bit in PM1a_CNT_BLK accordingly, clear the flag, and return.  If not
;set the flag and return.
;Entry: None
;
;Exit:  NC=This SW SMI is OS requests disable/enable ACPI
;	CF=Other SW SMI
;Destroy : Flag
;
;[]========================================================================[]
		Public	ACPIOnOff
ACPIOnOff	Proc	Near
		push	ax
		push	dx
		mov	edx, SMI_CMD_RD		;
		in	al, dx			;Read SMI_CMD (APMC) port
ifdef	S4_SUPPORT
		cmp	al, S4BIOS_REQ
		jne	short @F
		cmp	dword ptr PM_RAM:[ZV_HDD_Sector],0
		je	short @F

		Far_Call <offset WakeUP_VGA>,<seg WakeUP_VGA> 	;R38

		FAR_Call F000_Enable_CRT, 0F000h

		Far_Call <offset Do_S4_Suspend>,<seg Do_S4_Suspend>

		clc
		jmp	short ACPIOnOffExit	;Exit
@@:
endif	;S4_SUPPORT
		cmp	al, ACPI_Enable		;Is OS request to turn on ACPI
		jne	short @f 		;Nah!
;OS requests ACPI on
;
;R65 start
ifdef	PME_SUPPORT
		call	Enable_PME		;R65A
;R65A 		mov	cl,24h
;R65A 		or	bl,20h
;R65A 		call	E000_Get_Set_PMIO_OR
endif	;PME_SUPPORT
;R65 end
;R69 start
ifdef	RI_AlWAYS_Wakeup_SUSPEND
		call	Set_Modem_Ring_Status
endif	;RI_AlWAYS_Wakeup_SUSPEND
;R69 end

		Call	Save_Legacy_PM		
		Call	Disable_PM_Timer	
		xor	al,al					;R29 
		Far_Call fPROC_Set_HDD_Standby_Timer,0F000h	;R29

		mov	dx, PM1a_CNT_BLK      	;
		in	al, dx			;Read control register
		or	al, SCI_EN		;Set SCI_EN bit 
		out	dx, al

;R05 - start
;R05A		mov	cx, VT586_ACPI + 44h	; Enabe IRQ 1 ,IRQ 9
;R05A		mov	al, 0bah		;	IRQ 3 ,IRQ 10
;R05A		call	E000_Set_PMU		;	IRQ 4 ,IRQ 11
;R05A		mov	cx, VT586_ACPI + 45h	;	IRQ 5 ,IRQ 12
;R05A		mov	al, 01fh		;	IRQ 7
;R05A		call	E000_Set_PMU		;	IRQ 8
		mov	cx, VT586_ACPI + 44h	;R05A Enable IRQ1
		mov	bl, 02h			;R05A Others according to SETUP.
		call	E000_Get_Set_PMU_OR	;R05A
		mov	cx, VT586_ACPI + 45h	;R05A Disable IRQ14,15
		mov	bl, not 0C0h		;R05A Others according to SETUP.
		call	E000_Get_Set_PMU_AND	;R05A
;R05 - end

  IFDEF	No_PowerBottom_Debounce_In_Memphis	;R03
    ifndef	Special_PowerButton_In_Memphis	
		mov	cx, VT586_ACPI + 40h	; Disable Power Button
		mov	bl,not 20h		; Debounce !!
		call	E000_Get_Set_PMU_AND
    endif;	Special_PowerButton_In_Memphis	
		mov	cl, 2ch			; Power Button use 'Edge'
		mov	bl, 15h			; trigger.
		call	E000_Get_Set_PMIO_OR	;
  ENDIF;No_PowerBottom_Debounce_In_Memphis	;R03
		clc				;Clear the flag
		jmp	short ACPIOnOffExit	;Exit
@@:		cmp	al, ACPI_Disable     	;Is OS request to turn off ACPI
       		jne	short @f     		;Nah!
;OS requests ACPI off
;
;R65A start
ifdef	PME_SUPPORT
ifdef	PME_AlWAYS_Wakeup_SUSPEND
		call	Restore_PME_Setting
endif	;PME_AlWAYS_Wakeup_SUSPEND
endif	;PME_SUPPORT
;R65A end
;R69 start
ifdef	RI_AlWAYS_Wakeup_SUSPEND
		call	Restore_Ring_Setting
endif	;RI_AlWAYS_Wakeup_SUSPEND
;R69 end
		mov	al,1					;R29
		Far_Call fPROC_Set_HDD_Standby_Timer,0F000h	;R29
		Call	Restore_Legacy_PM	
		Call	Set_Full_On_State	

		mov	dx, PM1a_CNT_BLK 	
		in	al, dx			;Read control register
		and	al, NOT SCI_EN 		;Clear SCI_EN bit
		out	dx, al
		clc	    			;Clear the flag
		jmp	short ACPIOnOffExit	;Exit
@@:		stc
ACPIOnOffExit:
		pop	dx
		pop	ax
		ret
ACPIOnOff	Endp
Save_Legacy_PM	Proc	Near

		push	es
		pushad				     

		mov	ax,Seg DGROUP
		mov	es,ax
		mov	di,offset Legacy_PM_Offset

		mov	dx, ACPI_PORT
		mov     cx, VT586_ACPI+20h 		
		mov	bx, 50h	       			
	@@:
		in	al, dx
		stosb
		inc	dl
		push	dx
		push	cx
		Call	E000_Get_PMU
		stosb
		pop	cx
		pop	dx

		inc	cl
		dec	bx
		jnz	short @B

		popad				
		pop	es
	
		ret
Save_Legacy_PM	Endp

Restore_Legacy_PM	Proc	Near

		push	ds
		pushad				

		mov	ax,Seg DGROUP
		mov	ds,ax
		mov	si,offset Legacy_PM_Offset

		mov	dx, ACPI_PORT			
                mov     cx, VT586_ACPI+20h   		
		mov	bx, 50h		       		
	@@:
		lodsb
		out	dx, al
		inc	dl
		lodsb
		pushad
		Call	E000_Set_PMU
		popad

		inc	cl
		dec	bx
		jnz	short @B

		popad				
		pop	ds
	
		ret
Restore_Legacy_PM	Endp

Disable_PM_Timer	Proc	Near
		mov	cl, 2ah
		mov	bl, not 0ch
		Call	E000_Get_Set_PMIO_AND
		mov	cx, VT586_ACPI+50h
		mov	bl, not 33h
		call	E000_Get_Set_PMU_AND
ifdef   OverHot_Use_ExtSmi
                mov     cl,24h
                mov     bl,not OVERHOT_USE_EXTSMI	;EXTSMI ?
                call    E000_Get_Set_PMIO_AND
endif;	OverHot_Use_ExtSmi
ifdef   LM75_USE_EXTSMI4			
                mov     cl,24h
                mov     bl,not 10h              
                call    E000_Get_Set_PMIO_AND
endif;	LM75_USE_EXTSMI4			
ifdef   LM75_USE_EXTSMI3			
                mov     cl,24h
                mov     bl,not 08h              
                call    E000_Get_Set_PMIO_AND
endif;	LM75_USE_EXTSMI3			

ifdef   VT596					
                mov     cl,24h				
                mov     bl,not 01H
                call    E000_Get_Set_PMIO_AND		
endif;	VT596					

ifdef   Suspend_SW_USE_EXTSMI				
                mov     cl,24h				
                mov     bl,not Suspend_SW_USE_EXTSMI	
                call    E000_Get_Set_PMIO_AND		
endif;	Suspend_SW_USE_EXTSMI				
ifdef   Suspend_SW_USE_EXTSMI4			
                mov     cl,24h
                mov     bl,not 10h              
                call    E000_Get_Set_PMIO_AND
endif;	Suspend_SW_USE_EXTSMI4			
Disable_PM_Timer	Endp

endif;	ACPI_Support

IFDEF		USB_SUPPORT
;[]========================================================================[]
;Procedure:	Ct_USB_SMI_Entry
;Function:	Chipset process before USB SMI code executed.
;Input:		none
;Output:	none
;[]========================================================================[]

Ct_USB_SMI_Entry:
		mov	cl, 28h			; Index 28h : Global SMI Status
		call	E000_Get_PMIO		; Clear Global SMI Status !
		call	E000_Set_PMIO		;
		mov	cl, 2Dh			;
		mov	al,01h			;
		call	E000_Set_PMIO		;
		ret

;[]========================================================================[]
;Procedure:	Ct_USB_SMI_Exit
;Function:	Exit SMI procedure after USB SMI process completed
;Input:		none
;Output:	none
;[]========================================================================[]

Ct_USB_SMI_Exit:
		ret
COMPILE_FOR_USBBIOS	=	3
		include	USBBIOS.ASM
;R15 - starts
  ifdef	USB_PM_SUPPORT				
;[]========================================================================[]
;Procedure:	Check_Legacy_Enable
;Function:	Check if USB keyboard Legacy Support enable ?
;Input:		none
;Output:	ZE : Legacy Enable
;		NZ : Legacy Disable
;[]========================================================================[]
Check_Legacy_Enable	Proc	Near
		push	ds
		assume	ds:USB_RAM
		call	Get_USBRAM
		mov	ds, ax
		mov	dx, FRBASEADD
		call	Get_Host_Dword
		and	ax, 0F000h		;discard reserved bits
		cmp	eax, ds:dFrameListAddr
		pop	ds
		ret
Check_Legacy_Enable	Endp
  endif;USB_PM_SUPPORT				
;R15 - ends

;R66 - starts
ifdef	IOTRAP_SUPPORT
;[]========================================================================[]
;Procedure:	Ct_CheckUsbLegacySmi
;Function:	Read chipset register to identify USB legacy supporting SMI
;Input:		none
;Output:	CF = 0 USB legacy SMI
;		CF = 1 not USB legacy SMI
;[]========================================================================[]

Ct_CheckUsbLegacySmi:
		mov	cx, 28h
                call    E000_Get_PMIO
		test	al, 00010000b		;Legacy USB Status
		clc
		jnz	short @f
		stc
@@:
		ret

;[]========================================================================[]
;Procedure:	Ct_ClearUsbLegacySmi
;Function:	Clear chipset dependent USB legacy supporting SMI event
;Input:		none
;Output:	none
;[]========================================================================[]

Ct_ClearUsbLegacySmi:
		mov	cx, 28h
		mov	bl, 00010000b		;clear Legacy USB Status
                call    E000_Get_Set_PMIO_AND
		mov	cl, 2Dh			;R66A Clear this SMI.
		mov	al,01h			;R66A
		call	E000_Set_PMIO		;R66A
		ret

;[]========================================================================[]
;Procedure:	Ct_DisableUsbLegacySmi
;Function:	Disable USB legacy supporting SMI
;Input:		none
;Output:	none
;[]========================================================================[]

Ct_DisableUsbLegacySmi:
		mov	cx, 2Ah
		mov	bl,not 00010000b	;Disable Legacy USB SMI
                call    E000_Get_Set_PMIO_AND
		ret

;[]========================================================================[]
;Procedure:	Ct_EnableUsbLegacySmi
;Function:	Enable USB legacy supporting SMI
;Input:		none
;Output:	none
;[]========================================================================[]

Ct_EnableUsbLegacySmi:
		mov	cx, 2Ah
		mov	bl, 00010000b		;Enable Legacy USB SMI
                call    E000_Get_Set_PMIO_OR
		ret
endif	;IOTRAP_SUPPORT
;R66 - ends
ENDIF		;USB_SUPPORT

ifdef	SUPERIO_SOFT_OFF_SUPPORT			;R20 - starts

;========================================================================
; IO_Soft_Off:
;	      I/O Soft Off
;
;Input:		AL Bit3 = 1	not call from Software SMI.(use "call")
;		        = 0	call from Software SMI.
;		AL bit1 = 1  :  Do PowerOff 
;		        = 0  :  Don't PowerOff
;
;		AL = 51h  call from S1
;		AL = 55h  call from S5
;		AL = 57h  call from APM16 PowerOff
;		AL = 5Ah  call from PowerButtom to Power Off
;		AL = 58h  call from PowerButtom/EXTSMI Buttom to Suspend
;
;Output:	None
;
;Note: Don't Destory AL
;
;========================================================================
IO_Soft_Off	Proc	Near
		pushad
;---------------------------------------;
; For Super I/O Soft Off Coding Area	;
;---------------------------------------;

;R22 - start
		cmp	al,55h
;R46		jz	short @F
;R46 - start
		jnz	IO_Soft_Off_Not_S5
		push	es
		mov	ax,G_RAM
		mov	es,ax
		mov	ax,word ptr es:[HARDWARE]
		pop	es
		test	al,4			;Is PS2 mouse ready ?
		jnz	@F
		mov	al,55h
IO_Soft_Off_Not_S5:
;R46 - end
		cmp	al,57h
		jz	short @F
		cmp	al,5Ah
		jz	short @F
		jmp	IO_Soft_Off_Exit
@@:
		call	PS2_Mouse_Reset_Before_Power_Down
IO_Soft_Off_Exit:
;R22 - end

		popad
		ret
IO_Soft_Off	Endp

;R22 - start
ifdef	Password_ON_NOW_SUPPORT
ifdef	MOUSE_BUTTON_ON_SUPPORT
PS2_Mouse_Reset_Before_Power_Down	Proc	Near
	mov	al, 0ADh		;disable KBD
	out	64h, al
	call	Test_64h_Bit1

;KBC Reset start
	mov	cx, 256
@@:
	NEWIODELAY
	loop	short @B

	in	al, 60h			;read return garbage byte
	NEWIODELAY
	call	Test_64h_Bit1

	mov	al, 0FFh		;KBC RESET cmd
	out	60h, al
	call	Test_64h_Bit1

	NEWIODELAY
	call	Test_64h_Bit1
	call	Test_64h_Bit0

	mov	al, 55H			;clear bus
	in	al, 60h			;get returned value
	NEWIODELAY
	cmp	al, 0FAh		;ACK
	jne	short KBC_Reset_Done

	mov	cx, 2
@@:
	call	Test_64h_Bit1
	loop	@B
	in	al,60h
	NEWIODELAY
	cmp	al,0AAh 		

KBC_Reset_Done:
	mov	al, 0AEh		;enable keyboard interface
	out	64h, al
	call	Test_64h_Bit1
;KBC Reset End

;R31 - start
;R31A	mov	al, 0ADh		;disable KBD
;R31A	out	64h, al
;R31A	call	Test_64h_Bit1
;R31 - end

ifdef	Use_4_Frame_PS2_Mouse		;R22A
	mov	al, 060h
	out	64h, al
	call	Test_64h_Bit1

	mov	al, 065h
	out	60h, al
  	mov	al, 0D4h
	out	64h, al
	call	Test_64h_Bit1

	mov	al, 0FFh
	out	60h, al

	mov	dx, 60h
@@:
	in	al, dx
	or	al, al
	jnz	@B

	mov	al, 060h
	out	64h, al
	call	Test_64h_Bit1

	mov	al, 047h
	out	60h, al
endif	;Use_4_Frame_PS2_Mouse		;R22A

	mov	al, 0A8h
	out	64h, al
	call	Test_64h_Bit1

	mov	al, 60h
	out	64h, al
	call	Test_64h_Bit1

	mov	al, 47h
	out	60h, al
	mov	al, 0D4h
	out	64h, al
	call	Test_64h_Bit1

	mov	al, 0F4h
	out	60h, al

;R31 - start
;R31A	mov	al, 0AEh		;enable keyboard interface
;R31A	out	64h, al
;R31A	call	Test_64h_Bit1
;R31 - end

	ret

Test_64h_Bit1:
	in	al, 64h
	and	al, 02h
	jnz	short Test_64h_Bit1
	ret

Test_64h_Bit0:
	in	al, 64h
	and	al, 01h
	jnz	short Test_64h_Bit1
	ret
PS2_Mouse_Reset_Before_Power_Down	Endp
endif;	MOUSE_BUTTON_ON_SUPPORT
endif;	Password_ON_NOW_SUPPORT
;R22 - end

endif;	SUPERIO_SOFT_OFF_SUPPORT			;R20 - ends

		align	4
		public	SMI_Handler_End
SMI_Handler_End label	near

		Public	SMI_Handler_Len
SMI_Handler_Len EQU	$ - offset SMI_Handler_Start
;R37 - starts
ifdef	NoteBook_Power_Management
;[]=========================================================================[]
;Procedure:	Software_SMI_0V_Resume
;
;Function :	Routine to Handle software SMI resume from 0V suspend
;
;Input    :	DS = PM_RAM
;
;Output   :	None
;[]=========================================================================[]
		ASSUME	DS:PM_RAM
		Public	Software_SMI_0V_Resume
Software_SMI_0V_Resume	Proc	Far
		jmp	F_Resume_0V
Software_SMI_0V_Resume	Endp

;[]=========================================================================[]
;Procedure:	Software_SMI_BIOS_RSM
;
;Function :	Routine to save system BIOS SMBASE.
;
;Input    :	DS = PM_RAM
;
;Output   :	None
;[]=========================================================================[]
		ASSUME	DS:PM_RAM
		Public	Software_SMI_BIOS_RSM
Software_SMI_BIOS_RSM	Proc	Far
ifdef	NO_ZV_REALTIME_MESSAGE
		extrn	Save_SMRAM_State:near
		jmp	Save_SMRAM_State		
else	;NO_ZV_REALTIME_MESSAGE
		ret
endif	;NO_ZV_REALTIME_MESSAGE
Software_SMI_BIOS_RSM	endp
			
;ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ
;Û
;Û		Chipset depand for Notebook Power Management
;Û
;ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ

;[]========================================================================[]
;Procedure:	CT_Restore_VGA
;
;Function :	Restore VGA extended registers and states
;
;Input	  :	DS = Segment for save buffer.
;		ESI = Offset for save buffer.
;
;Output   :	None
;
;Preserve :
;
;[]========================================================================[]
		Public	CT_Restore_VGA
CT_Restore_VGA	Proc	Near
		ret
CT_Restore_VGA	Endp

;[]========================================================================[]
;Procedure:	CT_Save_VGA
;
;Function :	Save VGA extended registers and states
;
;Input	  :	ES = Segment for save buffer.
;
;Output   :	None
;
;Preserve :
;
;[]========================================================================[]
		Public	CT_Save_VGA
CT_Save_VGA	Proc	Near
		ret
CT_Save_VGA	Endp

;[]===============================================================[]
;
; Ct_Save_COMA:
;
; Function :	Save transmit holding buffer and FIFO control of COM1
;
; Input    :	ES = PM Save area
;		DS = G_RAM
;		ESI+6 = offset es:[COMA_STAT+6]
;			--- byte to save COM1's transmit holding
;			    buffer which is write only
;		ESI+7 = offset es:[COMA_STAT+7]
;			--- byte to save COM1's FIFO control which
;			    is write only
;
; Output   :	None
;
; Saves    :	ESI,EBX,ES,DS
;
; Note	   :	Called from Suspend_Handler after saving COMA
;
;[]===============================================================[]
		Public	Ct_Save_COMA
Ct_Save_COMA	Proc	Near
		ret
Ct_Save_COMA	Endp

;[]===============================================================[]
;
; Ct_Save_COMB:
;
;		Save transmit holding buffer and FIFO control of COM2
;
; Input    :	ES = PM Save area
;		ESI+6 = offset ES:[COMB_STAT+6]
;			--- byte to save COM2's transmit holding
;			    buffer which is write only
;
;		ESI+7 = offset es:[COMA_STAT+7]
;			--- byte to save COM2's FIFO control which
;			    is write only
;
; Output   :	None
;
; Saves    :	ESI,EBX,ES,DS
;
; Note	   :	Called from Suspend_Handler after saving COMA
;
;[]===============================================================[]
		Public	Ct_Save_COMB
Ct_Save_COMB	Proc	Near
		ret
Ct_Save_COMB	Endp

;[]===============================================================[]
;
; Ct_Save_FDC:
;
; Function :	Save FDD controller ports 3F2h & 3F7h which are
;		normally write only
;
; Input    :	ES    = PM Save area
;		ESI    = offset ES:[SHADOW_FDC_3F2]
;			--- byte to save FDC 3F2h
;		ESI+1  = offset ES:[SHADOW_FDC_3F7]
;			--- byte to save FDC 3F7h
;
; Output   :	None
;
; Note	   :	1. Called from Suspend_Handler
;		2. Fill this routine only if the PMU has shadow
;		   register for this port
;
;[]===============================================================[]
		Public	Ct_Save_FDC
Ct_Save_FDC	Proc	Near
		ret
Ct_Save_FDC	Endp

;[]===============================================================[]
;
; Ct_Restore_FDC:
;
; Function :	Save FDD controller ports 3F2h & 3F7h which are
;		normally write only
;
; Input    :	ES    = PM Save area
;		EBX + Save_FDC_3F2 =
;			--- byte to save FDC 3F2h
;		EBX + Save_FDC_3F7 =
;			--- byte to save FDC 3F7h
;
; Output   :	None
;
; Note	   :	1. Called from Suspend_Handler
;		2. Fill this routine only if the PMU has shadow
;		   register for this port
;
;[]===============================================================[]
		Public	Ct_Restore_FDC
Ct_Restore_FDC	Proc	Near
		ret
Ct_Restore_FDC	Endp

;[]===============================================================[]
;
; CT_Save_8259:
;
; Function :	Save 8259 when chipset shadow support
;
; Input    :	ES = PM Save area
;
; Output   :	CF clear = Shadow 8259 support and save it.
;		CF set	 = Shadow 8259 not support.
;
; Note	   :	1. Called from Suspend_Handler
;		2. Fill this routine only if the PMU has shadow
;		   register for this port
;
;		3. The following is save 8259 buffer location brief
;
;		Master ICW1:	Save_8259_Area+0
;		Master ICW2:	Save_8259_Area+1
;		Master ICW3:	Save_8259_Area+2
;		Master ICW4:	Save_8259_Area+3
;		Master OCW1:	Save_8259_Area+4
;		Master OCW2:	Save_8259_Area+5
;		Master OCW3:	Save_8259_Area+6
;		Reserve    :	Save_8259_Area+7
;		Slave ICW1 :	Save_8259_Area+8
;		Slave ICW2 :	Save_8259_Area+9
;		Slave ICW3 :	Save_8259_Area+10
;		Slave ICW4 :	Save_8259_Area+11
;		Slave OCW1 :	Save_8259_Area+12
;		Slave OCW2 :	Save_8259_Area+13
;		Slave OCW3 :	Save_8259_Area+14
;		Reserve    :	Save_8259_Area+15
;
;[]===============================================================[]
		Public	CT_Save_8259
CT_Save_8259	Proc	Near
;R49 - starts
		push	ebx
		mov	edi,offset Save_8259_Area
		add	edi,ebx	

		push	ds			   
		mov	ax,PM_RAM_SEGMENT	   
		mov	ds,ax			   
		xor	ah,ah			   
		mov	al,byte ptr ds:OS_TYPE_BYTE
		pop	ds			   

		mov	si,offset EGROUP:DOS_8259_TBL
		mov	bl,12
		mul	bl
		add	si,ax
		
		mov	al,byte ptr cs:[si]
		stos	byte ptr es:[edi]		; Master ICW1

		inc	si
		mov	al,byte ptr cs:[si]
		stos	byte ptr es:[edi]		; Master ICW2

		inc	si
		mov	al,byte ptr cs:[si]
		stos	byte ptr es:[edi]		; Master ICW3

		inc	si
		mov	al,byte ptr cs:[si]
		stos	byte ptr es:[edi]		; Master ICW4

		inc	edi

		inc	si
		mov	al,byte ptr cs:[si]
		stos	byte ptr es:[edi]		; Master OCW2

		inc	si
		mov	al,byte ptr cs:[si]
		stos	byte ptr es:[edi]		; Master OCW3

		inc	edi

		inc	si
		mov	al,byte ptr cs:[si]
		stos	byte ptr es:[edi]		; Slave ICW1

		inc	si
		mov	al,byte ptr cs:[si]
		stos	byte ptr es:[edi]		; Slave ICW2

		inc	si
		mov	al,byte ptr cs:[si]
		stos	byte ptr es:[edi]		; Slave ICW3

		inc	si
		mov	al,byte ptr cs:[si]
		stos	byte ptr es:[edi]		; Slave ICW4

		inc	edi

		inc	si
		mov	al,byte ptr cs:[si]
		stos	byte ptr es:[edi]		; Slave OCW2

		inc	si
		mov	al,byte ptr cs:[si]
		stos	byte ptr es:[edi]		; Slave OCW3

		pop	ebx
		clc
		ret
;R49 - ends
;R49
;R49		mov	edi,ebx
;R49		add	edi,offset Save_8259_Area
;R49		mov	cx,084Ch
;R49@@:			
;R49		call	E000_GET_PMU
;R49		stos	byte ptr es:[edi]		; Master ICW1~4
;R49		inc	cx
;R49		cmp	cl,4Fh
;R49		jbe	short @B
;R49
;R49		inc	edi				; Skip	 OCW1
;R49		mov	cl,54h
;R49@@:
;R49		call	E000_GET_PMU
;R49		stos	byte ptr es:[edi]		; Master OCW2~3
;R49		inc	cx
;R49		cmp	cl,55h
;R49		jbe	short @B
;R49
;R49		inc	edi				; Skip Reserve
;R49
;R49		mov	cl,50h
;R49@@:
;R49		call	E000_GET_PMU
;R49		stos	byte ptr es:[edi]		; Slave ICW1~4
;R49		inc	cx
;R49		cmp	cl,53h
;R49		jbe	short @B
;R49
;R49		inc	edi				; Skip	OCW1
;R49		mov	cl,56h
;R49@@:
;R49		call	E000_GET_PMU
;R49		stos	byte ptr es:[edi]		; Slave OCW2~3
;R49		inc	cx
;R49		cmp	cl,57h
;R49		jbe	short @B
;R49
;R49		clc
;R49		ret
CT_Save_8259	Endp

;R49 - starts
DOS_8259_TBL:
		db	11h,08h,04h,01h		;ICW 1-4 master
		db	20h,0bh			;OCW 2-3 master
		db	11h,70h,02h,01h		;ICW 1-4 slave
		db	20h,0bh			;OCW 2-3 slave

Win31_8259_TBL:				
		db	11h,50h,04h,01h		;ICW 1-4 master
		db	60h,0ah			;OCW 2-3 master
		db	11h,58h,02h,01h		;ICW 1-4 slave
		db	66h,0bh			;OCW 2-3 slave

Win95_8259_TBL:
		db	11h,50h,04h,01h		;ICW 1-4 master
		db	60h,0ah			;OCW 2-3 master
		db	11h,58h,02h,01h		;ICW 1-4 slave
		db	66h,0ah			;OCW 2-3 slave
;R49 - ends

;[]==================================================================[]
;
; Procedure Name: CT_GET_SUSPEND_MODE
;
;	This routine is return suspend method to kernal
;
; Saves: DS,ES
; Input:
;	none
;
; Output:
;	Al = 0	Static_Suspend	(Asserts STPCLK#)
;	   = 1	Zero_V_Suspend	(Suspend to Disk)
;	   = 2	Five_V_Suspend	(Suspend to DRAM)
;
; [Note]:
;
; Author: Daniel Huang
; Date: September, 09, 1995
;
; Name	| Date		| Description
; -----------------------------------------------------------------
; DNL	| 09/09/95	| Initial version for Intel MOBIL TRITON
;[]==================================================================[]
		Public	Ct_Get_Suspend_Mode
Ct_Get_Suspend_Mode	Proc	Near

		extrn	Suspend_Option_Item:near
		mov	si,offset DGROUP:Suspend_Option_Item
		F000_Call	GetItem_Value

		ret

Ct_Get_Suspend_Mode	endp

;[]==================================================================[]
; Procedure Name: Ct_Save_VRAM
; Saves: All but Flag
; Input: none
; Output: CF	:	Normal VRAM save method
;	  NC	:	Special VRAM save method ,
;			do it on this procedure
;[]==================================================================[]
		Public	Ct_Save_VRAM
Ct_Save_VRAM	Proc	Near
		stc
		ret
Ct_Save_VRAM	Endp

;[]==================================================================[]
; Procedure Name: Ct_Restore_VRAM
; Saves: All but Flag
; Input: none
; Output: CF	:	Normal VRAM restore method
;	  NC	:	Special VRAM restore method ,
;			do it on this procedure
;[]==================================================================[]
		Public	Ct_Restore_VRAM
Ct_Restore_VRAM	Proc	Near
		stc
		ret
Ct_Restore_VRAM	Endp

;[]==================================================================[]
; Procedure Name: Set_Full_On_SMM
; Saves: All
; Input: none
; Output: none
; Function:
;	to wakeup system in this procedure
;[]==================================================================[]
		Public	Set_Full_On_SMM
Set_Full_On_SMM	Proc	Near
		ret
Set_Full_On_SMM	Endp

endif	;Notebook_Power_Management
;R37 - ends

ECODE		ENDS
XGROUP		GROUP	XCODE
XCODE		SEGMENT USE16 PARA PUBLIC 'XCODE'
		ASSUME	CS:XGROUP,ES:XGROUP

XCODE		ENDS
		END

