;	[]===========================================================[]
;
;	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
;----------------------------------------------------------------------------
;R16	01/04/99 MCH	Added "KEY_SETUP_CTRL_ALT_KEY" define for supporting
;			"Ctrl+Alt"+special key for entering CMOS Setup with
;			"KEY_SETUP_SCAN_CODE" define.
;R15	12/30/98 KEN	For USB_MOUSE_SUPPORT.
;			Fixed bug that if pressing DEL key frequently and
;			successively to enter SETUP, the PS/2 keyboard
;			occasionally can't work after entering SETUP unless
;			re-plugging it.
;			(PS:This bug has been fixed for the BIOS without
;			"Graphics_Post" definition. The fixed codes are the
;			same with "MISC.ASM".)
;R14	11/11/98 RCH	Support pressing Hotkey to force boot to network 
;			before booting from local storages. For example,
;			"HOTKEY_TO_BOOT_LAN EQU 058H" use function key F12 to
;			force boot to LAN.
;R13	07/11/98 RAY	Some people do not want the end users to return to
;			the text screen for full screen logo. 
;			Add switch: NO_RETURN_TO_TEXT
;
;R12	06/26/98 DRS	Add No_Automatic_Load_Awdflash_InPOST definition
;			Some customers want to automatically load awdflash.exe,
;			but they don't want this function during POST.
;			They just want to autmaticlly load awdflash.exe in BootBlock.
;R11	05/12/98 RAX	Added code for Cyrix VSA save to disk support.
;R10	04/22/98 KGN	Add code For HPM resume from disk post information
;R09	03/10/98 DNL	Reduce ACPI S4/BIOS code size to save more space
;R08	01/19/98 DRS	Support run awdflash.exe during POST 
;R07	01/06/98 RCH	Added using "ESC" instead of "TAB" to return to
;			text POST screen.
;R06	12/18/97 LAW	check FULL_SCREEN_LOGO or EPA_LOGO_Use_Graphics to 
;			switch screen mode by keyin TAB key
;R05	03/11/97 RCH	Added special keystroke combination for entering
;			setup & POST screen
;R02A	11/20/96 RAY	Add special option key for entering setup
;R04	08/25/96 DNL	Fixed coding mistake
;R03	07/29/96 DNL	Fixed coding mistake
;R02	04/17/96 RAY	Somebody don't want 'DEL' key to enter setup
;R01	03/08/96 KVN	Fixed BP be destroy when enter setup occur on
;			FULL_SCREEN_LOGO BIOS

		PAGE	62,132
		TITLE	POSTINT9
.386
;		+---------------+
;		|		|
;		|  POST INT 9	|
;		|		|
;		+---------------+

;
.XLIST
		INCLUDE BIOS.CFG

		INCLUDE 8042.EQU
		INCLUDE 8259.EQU
		INCLUDE	PORT61.EQU
		INCLUDE AKBRD.EQU
		INCLUDE POST.EQU

		INCLUDE COMMON.MAC
		INCLUDE	POST.MAC

		extrn	KB_CNTRLR_OUT:near
		extrn	BUFFER_8042_FULL:near
		extrn	CT_BEFORE_SETUP:near
		extrn	CP_INSTALL:near
		extrn	UPDATE_LED:near
		extrn	SETUP:near
		extrn	REDO:near
		extrn	F000_call_proc:near
;R06ifdef FULL_SCREEN_LOGO
ifdef	Graphics_Post					;R06
;R09 IFDEF	NoteBook_Power_Management		;R03
if	STD_Function		EQ	1		;R09
		extrn	Check_0V_Resume:near		;R03
endif	;STD_Function		EQ	1		;R09
;R09 ENDIF	;NoteBook_Power_Management		;R03
		extrn	INT_KB_ENABLE:near
		extrn	KYB_ENABLE:near
		extrn	PostInt9_to_AKBRD_Entry:near
		extrn	Switch_LOGO_To_Text:near
endif;	Graphics_Post					;R06
;R06endif ;FULL_SCREEN_LOGO

ifdef	HPM_Support					;R10
		extrn	Check_HPM_Resume:Near		;R10
endif	;HPM_Support					;R10

;R11 start
ifdef	VSA_VGA
ifdef	S2D_SUPPORT
		extrn	Check_VSA_resume:near
endif	;S2D_SUPPORT
endif	;VSA_VGA
;R11 end

.LIST
		PAGE

G_RAM		SEGMENT	USE16 AT 40H
		INCLUDE	G_RAM.INC
G_RAM		ENDS

EGROUP		GROUP	ECODE

ECODE		SEGMENT	USE16 DWORD PUBLIC 'ECODE'
		ASSUME	CS:EGROUP

;R06ifdef FULL_SCREEN_LOGO
ifdef	Graphics_Post					;R06
		public	POST_INT9_Vect
POST_INT9_Vect:
; This routine handles the interrupts generated by the POST int9
;
; ENTRY: NONE
; EXIT:  NONE

		sti				; enable int
		cld

		push	ds
		pusha

		mov	bx,G_RAM		; set data seg
		mov	ds,bx
		ASSUME	DS:G_RAM

		mov	ax,DISABLE_KBRD		; disable keyboard
		F000_call	kb_cntrlr_out

; READ SCAN FROM KEYBOARD (8042)

		cli
		F000_call	buffer_8042_full	; wait for controller to
						; process disable keyboard
		in	al,DATA8042		; READ DATA FROM 8042

;R14 - start
ifdef	HOTKEY_TO_BOOT_LAN
		cmp	al, HOTKEY_TO_BOOT_LAN 		;LAN boot hot key ?
		jne	short NotF12Key			;no
		or	byte ptr ds:SYSTEM_FLAG,BOOT_LAN;yes,boot from LAN
NotF12Key:
endif;	HOTKEY_TO_BOOT_LAN
;R14 - end

		cmp	al,KEY_OVERRIDE		; insert key pressed?
		jne	short @F
		or	byte ptr POST_FLAG,OVERRIDE_ON	;override key
save_for_post:
Jump_AKBRD:
; MAKE 2 BYTE VARIABLES (scan_char,temp)

		mov	bp,sp
		sub	sp,2

		far_jmp	<offset PostInt9_to_AKBRD_Entry>,0f000h
@@:

;R08 -start
ifdef	Bootblock_16K_Support				
ifdef	Automatic_Load_Awdflash				
ifNdef	No_Automatic_Load_Awdflash_InPOST		;R12
		test	byte ptr POST_Flag,AWDFLASH_ON	; will run AWDLFASH.EXE ?
		jnz	short @f			; YES
endif	;No_Automatic_Load_Awdflash_InPOST		;R12
endif	;Automatic_Load_Awdflash				
endif	;Bootblock_16K_Support				
;R08 -end

		mov	bl,SHFT_STAT
		cmp	al,KEY_SETUP		; del key pressed?
		jne	short @F
ifdef	KEY_SETUP_CTRL_ALT_KEY			;R16
		and	bl,ALT+CTRL		;R16
		cmp	bl,ALT+CTRL		;R16
		jne	short @F		;R16
else;	KEY_SETUP_CTRL_ALT_KEY			;R16
		test	bl,ALT+CTRL
endif;	KEY_SETUP_CTRL_ALT_KEY			;R16
		
ifndef	NO_DEL_KEY_ENTER_SETUP		;R02
		jz	short Setup_Check
else	;NO_DEL_KEY_ENTER_SETUP		;R02A
	ifdef	KEY_SETUP_SCAN_CODE	;R02A
;R16		jmp	Setup_Check	;R02A
		jz	short Setup_Check	;R16
	endif	;KEY_SETUP_SCAN_CODE	;R02A
endif	;NO_DEL_KEY_ENTER_SETUP		;R02

@@:
		cmp	byte ptr EPALOGO_FLAG[bp], 055h	;R06;check is not EPALOGO
		jne	short Jump_AKBRD		;R06;

		cmp	al,ESC_KEY		; ESC key pressed?
 ifdef	ESC_INSTEAD_TAB	      					;R07
		je	short GoTextPost			;R07
 endif;	ESC_INSTEAD_TAB						;R07
		jne	short @F
		and	bl,ALT+CTRL
ifdef	CTRL_ESC_FOR_SETUP					;R05
		cmp	bl,CTRL					;R05
else;	CTRL_ESC_FOR_SETUP					;R05
		cmp	bl,ALT+CTRL
endif;	CTRL_ESC_FOR_SETUP					;R05
		je	short Setup_Check
@@:
		cmp	al,TAB_KEY
		jne	short Jump_AKBRD
ifdef	CTRL_TAB_FOR_POSTSCRN					;R05
		cmp	bl,CTRL		;CTRL+TAB ?		;R05
		jne	short Jump_Akbrd			;R05
endif;	CTRL_TAB_FOR_POSTSCRN					;R05
GoTextPost:							;R07
ifdef	NO_RETURN_TO_TEXT					;R13
		jmp	short Jump_AKBRD			;R13
endif	;NO_RETURN_TO_TEXT					;R13
		test	byte ptr EQUIPMENT[bp],DT_MONO
		jnz	short Jump_AKBRD
		test	byte ptr POST_TEMP_BYTE[bp],Text_POST
		jnz	short Jump_AKBRD
		call	Switch_LOGO_To_Text
		jmp	short Jump_AKBRD
;aaaa
;aaaaPost_Int9_Exit:
;aaaa		cli
;aaaa		mov	al,END_OF_INT		; END_OF_INT
;aaaa		out	A8259,al
;aaaa
;aaaa		F000_call	kyb_enable
;aaaa
;aaaa; RETURN FROM POST INT 9
;aaaa
;aaaa		popa
;aaaa		pop	ds
;aaaa
;aaaa		iret
;aaaa

Setup_Check:
		TEST	INIT_ERR_FLG,IEF_IN_POST	; in POST?
		JZ	SHORT SAVE_FOR_POST		; no...
		or	byte ptr POST_FLAG,SETUP_ON

		TEST	INIT_ERR_FLG,IEF_SETUP_OK	; is POST occurring
		jz	short save_for_post

		AND	INIT_ERR_FLG,NOT IEF_SETUP_OK	; prevent further  
							; setup invocations
;R09 IFDEF	NoteBook_Power_Management		;R04
if	STD_Function		EQ	1		;R09
		F000_call	Check_0V_Resume		;R04
		jnz	short save_for_post		;R04
endif	;STD_Function		EQ	1		;R09

;R11 start
ifdef	VSA_VGA
ifdef	S2D_SUPPORT
 		F000_call	Check_VSA_resume
		jnz	short save_for_post
endif	;S2D_SUPPORT
endif	;VSA_VGA
;R11 end

ifdef	HPM_Support					;R10
		F000_Call	Check_HPM_Resume	;R10
		jnz	short save_for_post		;R10
endif	;HPM_Support					;R10

;R09 ENDIF	;NoteBook_Power_Management		;R04
;
;	Here we allow the user to enter SETUP while in POST. We must
;	allow keyboard interrupts again, restore BP (which the POST
;	user interface routines and Setup use), call Setup then
;	reboot.
;


		F000_call	Int_Kb_Enable

;R01 start
		popa					; restore all registers
		mov	bp,[Temp_BP]			; get POST BP		
		pop	ds				; restore DS
;R01 end
		jmp	short Enter_Setup

		public	Enter_Setup_Check
Enter_Setup_Check	proc	near
		push	ds
		mov	ax,G_RAM
		mov	ds,ax
		ASSUME	DS:G_RAM
		test	byte ptr POST_FLAG,SETUP_ON
		pop	ds
		jz	short Not_To_Setup

;R09 IFDEF	NoteBook_Power_Management
if	STD_Function		EQ	1		;R09
;R03		extrn	Check_0V_Resume:near
;R03		call	Check_0V_Resume
		F000_call	Check_0V_Resume		;R03
		jnz	short Not_To_Setup
endif	;STD_Function		EQ	1		;R09
;R09 ENDIF	;NoteBook_Power_Management

;R11 start
ifdef	VSA_VGA
ifdef	S2D_SUPPORT
 		F000_call	Check_VSA_resume
		jnz	short Not_To_Setup
endif	;S2D_SUPPORT
endif	;VSA_VGA
;R11 end

ifdef	HPM_Support					;R10
		F000_Call	Check_HPM_Resume	;R10
		jnz	short Not_To_Setup		;R10
endif	;HPM_Support					;R10

Enter_Setup:
		push	ds
		mov	ax,G_RAM
		mov	ds,ax
		ASSUME	DS:G_RAM
		mov	word ptr ds:USER_REBOOT, 0	;reset warm boot flag
		and	INIT_ERR_FLG,NOT IEF_SETUP_OK	; prevent further

		F000_call	Ct_Before_Setup

		pop	ds

PRINTER_0_INIT	EQU	15H
PRN_S_AF_IP_SI	EQU	37AH			;port to talk to strobe,
						; auto feed, initialize
						; printer, and select input
						; pins of parrallel adapter
INITIALIZE_PORT EQU	0100H
		call	Cp_Install
		push	ax
		push	dx
		mov	al, PRINTER_0_INIT
		mov	dx, PRN_S_AF_IP_SI
		out	dx, al
		mov	ax, INITIALIZE_PORT
		xor	dx, dx
		int	17H			;init printer port #0
		pop	dx
		pop	ax

;R15 - start
ifdef	USB_SUPPORT
		F000_call	Buffer_8042_Full	;wait IBF cleared
		mov	al, 0FFh			;reset keyboard
		out	60h, al
else	;USB_SUPPORT
;R15 - end
		mov	ax,g_ram
		mov	ds,ax
		assume	ds:g_ram
		or	byte ptr KB_FLAG_2,7
		F000_call	UPDATE_LED
endif	;USB_SUPPORT					;R15

		mov	al,0AAh
		F000_CALL	SETUP

		far_jmp	<offset REDO>,0f000h
Not_To_Setup:
		ret
Enter_Setup_Check	endp
endif;	Graphics_Post				;R06
;R06endif ;FULL_SCREEN_LOGO

ECODE		ENDS
		END
