www.pudn.com > hpbios.rar > APM.VSA


;	[]===========================================================[] 
; 
;	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 
;---------------------------------------------------------------------------- 
;R01	03/27/98 RAX	Change compiler to MASM6.X. 
;R00	04/28/97 RCH	Initial revision for GX86/VSA support. 
;			Note : Both APM/APM32 services are in VSA code 
 
;R01 start 
ifdef	MASM611 
.MODEL  SMALL, BASIC 
OPTION	PROC: PRIVATE 
endif	;MASM611 
;R01 end 
 
.386p 
		PAGE	56,132 
		TITLE	APM.ASM   --   APM Real/16 bit Interface 
.XLIST 
		INCLUDE	BIOS.CFG 
		INCLUDE	COMMON.EQU 
		INCLUDE	COMMON.MAC 
		INCLUDE	POST.MAC 
		INCLUDE	BSETUP.INC 
		include	CMOS.EQU 
 
ifdef	ADVANCE_POWER_MANAGEMENT 
		extrn	Get_Cmos:near			;ATORGS.ASM 
		extrn	Set_Cmos:near			;ATORGS.ASM 
		extrn	BIOS_IDT:WORD			;ATORGS.ASM 
		extrn	Open_PM_RAM:near		;PMU.ASM 
		extrn	Close_PM_RAM:near		;PMU.ASM 
		extrn	Get_PMU:near			;PMU.ASM 
		extrn	Set_PMU:near			;PMU.ASM 
		extrn	Ct_APM_Func01:near		;PMU.ASM 
		extrn	Ct_APM_Func04:near		;PMU.ASM 
		extrn	Ct_APM_Func05:near		;PMU.ASM 
		extrn	Ct_APM_Func06:near		;PMU.ASM 
		extrn	APM_16_Standby:near		;PMU.ASM 
		extrn	APM_16_Suspend:near		;PMU.ASM 
		extrn	APM_16_PowerOff:near 
		extrn	Ct_Check_If_LowBat:near		;PMU.ASM 
		extrn	Get_PM_RAM_Seg:near		;PMU.ASM 
 
	ifndef	NO_SUPPORT_APM12 
		extrn	CT_RING_WAKEUP_STATUS:near	;pmu.asm 
		extrn	CT_PMU_TIMER_STATUS:near	;pmu.asm 
		extrn	CT_APM_FUNC10:near		;pmu.asm 
	endif	;NO_SUPPORT_APM12 
 
		extrn	Issue_SW_SMI:near 
 
ifdef	VGA_Chip_Control 
		extrn	Ct_VGA_Control:near 
endif	;VGA_Chip_Control 
 
endif	;ADVANCE_POWER_MANAGEMENT 
 
ifdef	PM_SUPPORT				 
		extrn	APM_R31_Added:near 
endif	;PM_SUPPORT				 
 
ifdef	Notebook_Power_Management 
	ifndef	NO_LCD_DISPLAY 
		LCD_CRT_OPTION		EQU	1 
	endif	;NO_LCD_DISPLAY 
	ifndef	NO_BATTERY_SYSTEM 
		BATTERY_SYSTEM		EQU	1 
	endif	;NO_BATTERY_SYSTEM 
endif	;Notebook_Power_Management 
 
ifdef	LCD_CRT_OPTION 
	ifdef	CHIP_65545 
		CHIP_655XX		EQU	1 
	endif	;CHIP_65545 
endif	;LCD_CRT_OPTION 
 
G_RAM		SEGMENT	USE16 AT 0 
 
		ORG	04H*4 
		INCLUDE	SEG_0.INC 
 
		ORG	400H 
		INCLUDE	G_RAM.INC 
 
G_RAM		ENDS 
 
PM_RAM		SEGMENT	USE16 AT 0 	; define PM RAM segment 
 
		ORG	0 
		INCLUDE	PM_RAM.INC 
 
PM_RAM		ENDS 
 
.LIST 
 
DGROUP		GROUP	FCODE 
FCODE		SEGMENT	USE16 DWORD Public 'CODE' 
		ASSUME	CS:DGROUP 
 
ifndef	ADVANCE_POWER_MANAGEMENT 
 
		Public	APM_Service 
APM_Service	Proc	Far 
		mov	ah,ERROR_APM_NOT_PRESENT	;APM not supported! 
		stc 
		retf	2 
APM_Service	Endp 
 
else	;ADVANCE_POWER_MANAGEMENT 
 
		ASSUME	DS:PM_RAM 
 
;$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ 
 
;[]==================================================================[] 
; 
; Procedure Name: APM_Service 
; 
;	APM service routines entry point. 
; 
; Saves: all 
; 
; Input: 
;	ah=53h 
;       al=00h : Installation check 
;	  =01h : Interface connect 
;	  =02h : 16 bit protect mode connect 
;	  =03h : 32 bit protect mode connect 
;	  =04h : Interface disconnect 
;	  =05h : CPU idle 
;	  =06h : CPU busy 
;	  =07h : Set power state, standby,suspend 
;	  =08h : Enable/disable power management function 
;	  =09h : Restore power on defaults 
;	  =0ah : Get power status 
;	  =0bh : Get PM event 
;	bx,cx,dx dependent on the function requested 
; 
; Output: 
;	ax,bx,cx,dx depend the function requested 
; 
; [Note]: 
;	This is the high level dispatch routine for APM interface. 
;[]==================================================================[] 
 
PUSH_REGS MACRO 
	pusha 
	push    es 
	push    ds 
	mov     bp, sp 
ENDM 
 
POP_REGS MACRO 
	pop     ds 
	pop     es 
	popa 
ENDM 
 
		Public	APM_Service 
APM_Service	Proc	Far 
 
		cmp	al, 7 
		jne	short @F 
		cmp	bx, 1 
		jne	short @F 
		cmp	cx, 3 
		jne	short @F 
		stc					;for dummy return 
		pushad 
		call	APM_16_PowerOff 
		popad 
		jnc	short Return 
		mov	ah, ERROR_NO_STATE_REQUEST 
		jmp	short Return 
	@@: 
 
 
; CPU Idle is done here so we can do a HLT instruction for maximum 
; power savings. 
	cmp		al, 5			; Is it CPU idle ? 
	jne		@f 
	sti						; Yes, halt the CPU 
	hlt 
	clc 
	jmp		short Return 
@@: 
 
 
 
; Is function 16-bit protected mode connect ? 
	cmp		al, 2 
	jne		short @f 
	call	protMode16Connect 
	jmp		short FinishConnect 
	 
; Is function 32-bit protected mode connect ?	 
@@:	cmp		al, 3 
	jne		short @f 
	call	protMode32Connect 
FinishConnect: 
	jc		short Return	; If bad ID, return error code 
	call	doSMI 
	jc		short Return 
	mov		ax, cs			; Else return AX = F000h 
	jmp		short Return 
 
@@:	call	doSMI			; Let VSA code do its thing 
Return: 
	ret		2 
 
APM_Service endp 
 
 
 
 
doSMI	PROC	NEAR 
	push	bp 
	push	dx 
	mov		bp, dx			; APM code will get DX in BP !!!! 
	sti 
	stc						; In case there is no VSA 
 
WaitLoop: 
	push	eax				; Invoke an SMI 
	mov		dx, 0cf8h 
	mov		eax, 800090d0h 
	out		dx, eax 
	pop		eax 
	mov		dx, 0cfch 
 
	mov		ah, 53h			; Restore APM major function 
 
; If function returns a value in DX, then handle separately 
	cmp		al, 0Ah 
	je		short @f 
	cmp		al, 11h 
	je		short @f 
 
	out		dx, ax	    
	jc		short SmiReturn 
	jnz		WaitLoop		; Loop if requested by VSA 
SmiReturn: 
	pop		dx 
	pop		bp 
	ret 
 
@@:	out		dx, ax 
	jc		short @f 
	jnz		WaitLoop 
@@:	pop		bp				; Throw away original DX 
	pop		bp 
	ret 
 
 
 
doSMI	ENDP 
 
SYSTEM_BIOS_ID            EQU   0000H 
BAD_ID_ERR                EQU   09H 
BAD_FUNCTION_ERR          EQU   86H 
PRT16_NOT_SUPPORTED_ERR   EQU   06H 
PRT32_NOT_SUPPORTED_ERR   EQU   08H 
 
;---------------------------------------------------------------------------- 
; 
;       protMode16Connect - Establish 16Bit protected mode connection 
; 
;	Entry: 
;	  BX - device ID 
; 
; 
;   	Exit: 
;	  Carry Flag = 0 means Succesful connection 
;	  AX - PM 16Bit code segment 
; 	  BX - PM Offset of 16Bit Interface entry point 
; 	  CX - PM 16Bit data segment 
;	  SI - APM Bios code segment length 
;	  DI - APM Bios data segment length 
; 
;   	  Carry Flag = 1 means Error 
;	  AH - error code 
;	     = 02H Real mode interface connection already established 
;	     = 05H 16-bit protected mode interface already established 
;	     = 06H 16-bit protected mode interface not supported 
;	     = 07H 32-bit protected mode interface already established 
;	     = 09H Unrecognized device ID 
; 
; 
;	Modifies: 
;	  All general purpose regs may be modified except EBP, ESP. 
; 
; 
;   	Processing: 
;   	  Returns with error status if the 16bit connect is already active 
;   	  or if a 16bit protected mode entry is not supported. 
;   	  If not connected, set a flag in PM memory to indicate the 16bit 
;   	  connect and return parameters as indicated above. 
; 
protMode16Connect PROC NEAR 
	cmp		bx, SYSTEM_BIOS_ID	; Valid ID ? 
	jne		short @f			; No - return error and exit 
		 
;	mov		ax, cs 				; Will be set later 
	mov		bx, OFFSET apm16BitInterface	; Set BX to entry point 
	mov		cx, 0040H	; Set CX to data segment 
	mov		si, 0FFFFh			; Set SI to APM Bios code segment length 
	mov		di, si				; Set DI to APM Bios data segment length 
    clc 
	ret 
 
@@:	mov		ah, BAD_ID_ERR		; Set AH to error code 
	stc 
	ret 
 
 
protMode16Connect ENDP 
 
;---------------------------------------------------------------------------- 
; 
;       protMode32Connect - Establish 32Bit protected mode connection 
; 
;	Entry: 
;	  BX - device ID 
; 
;   	Exit: 
;	  Carry Flag = 0 means Succesful connection 
; 	  AX  - APM 32Bit code segment (real mode segment base address) 
; 	  EBX - APM Offset of 32Bit Interface entry point 
; 	  CX  - APM 16Bit code segment (real mode segment base address) 
; 	  DX  - APM 16Bit data segment (real mode segment base address) 
;	  ESI - APM Bios 32-bit code segment length in lower word 
;                     APM Bios 16-bit code segment length in upper word 
;	  DI  - APM Bios data segment length 
; 
;   	  Carry Flag = 1 means Error 
;	  AH - error code 
;	     = 02H Real mode interface connection already established 
;	     = 05H 16-bit protected mode interface already established 
;	     = 07H 32-bit protected mode interface already established 
;	     = 08H 32-bit protected mode interface not supported 
;	     = 09H Unrecognized device ID 
; 
;	Modifies: 
;	  All general purpose regs may be modified except EBP, ESP. 
; 
;   	Processing: 
;   	  Return with error status if the 32bit connect is already active 
;   	  or if 32bit protected mode entry is not supported. 
;   	  If not connected, set internal flag to indicate the 32bit 
;   	  connect and return parameters as indicated above. 
; 
protMode32Connect PROC NEAR 
 
	cmp		bx, SYSTEM_BIOS_ID	; Valid ID ? 
	jne		short @f			; No - return error and exit 
 
;	mov		ax, cs				; Will be set later 
	xor		ebx, ebx 
 
 
	extrn	apm32BitInterface:near		;;;;;  
 
	mov		bx, OFFSET apm32BitInterface	; Set BX to 32bit entry OFFSET 
	mov		cx, cs				; Set CX to 16bit code seg 
	mov		dx, 0040H			; Set DX to data segment 
	mov		esi, 0FFFFFFFFh		; Set SI to len of Code segment 
	mov		di, si				; Set DI to len of Data segment 
	clc 
	ret 
 
@@:	mov		ah, BAD_ID_ERR		; Set AH to error code 
	stc 
	ret 
 
protMode32Connect ENDP 
 
 
 
 
 
;---------------------------------------------------------------------------- 
; 
;       apm16BitInterface - APM 16Bit protected mode entry point. 
; 
		Public	apm16BitInterface 	;;;;; 
apm16BitInterface PROC FAR 
; 
; The following change (the PUSHFD and associated PUSHFD in 32-bit entry 
; and associated POPFD in other exits) is required to prevent spurious 
; interrupt errors in various test applications (and very likely in the 
; real world).  This solution depends on the APM driver correctly setting 
; privilege levels per the APM spec.  If this proves to be unreliable, 
; a more complex solution is possible, but the core code would require more 
; modification. 
; 
 
	pushfd 
 
	cmp		ah, 53h	   		; Is it an APM call ? 
	mov		ah, BAD_FUNCTION_ERR ; No 
	jne		short Error_exit 
 
 
 
 
; CPU Idle is done here so we can do a HLT instruction for maximum 
; power savings. 
	cmp		al, 05h			; Is it CPU Idle function ? 
	jne		short @f 
	sti						; Yes, allow interrupts to wake us up 
	hlt 
OK_exit: 
	popfd 
	clc 
	ret 
 
 
@@:	cmp 	al, 02h			; Protected mode connections must be made from real mode 
    mov 	ah, PRT16_NOT_SUPPORTED_ERR 
    je	 	short Error_exit 
 
	cmp 	al, 03h			; Protected mode connections must be made from real mode 
    mov 	ah, PRT32_NOT_SUPPORTED_ERR 
	je		short Error_exit 
 
	cli 
	call	doSMI			; Dispatch to VSA 
	jnc		short OK_exit 
 
Error_exit: 
	popfd 
	stc 
	ret 
 
apm16BitInterface	ENDP 
 
;[]========================================================================[] 
;input	:	DS = PM_RAM 
;output	:	clear [APMEventSave] to NO_EVENTS 
;		      [APM_EVENT_POST] to 0 
;[]========================================================================[] 
		public	Clear_Events		 
Clear_Events	Proc	Near 
		ret 
Clear_Events	Endp 
 
endif	;ADVANCE_POWER_MANAGEMENT 
;$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ 
 
 
FCODE		ENDS 
		END