1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
|
TITLE AMTINT9.ASM -- OEM INTERRUPT IMPLEMENTATION
;*************************************************************************
;*************************************************************************
;** **
;** (C)Copyright 1985-2010, American Megatrends, Inc. **
;** **
;** All Rights Reserved. **
;** **
;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
;** **
;** Phone: (770)-246-8600 **
;** **
;*************************************************************************
;*************************************************************************
;
; $Header: /Alaska/SOURCE/Modules/SharkBayRefCodes/ME/AmtWrapper/AmtLockKBD/AmtInt9.asm 1 2/08/12 1:10a Klzhan $
;
; $Date: 2/08/12 1:10a $
;
;****************************************************************************
; Revision History
; ----------------
; $Log: /Alaska/SOURCE/Modules/SharkBayRefCodes/ME/AmtWrapper/AmtLockKBD/AmtInt9.asm $
;
; 1 2/08/12 1:10a Klzhan
; Initial Check in
;
; 2 7/13/11 4:03a Klzhan
; Fix Lock KBD can't work without SOL enable.
;
; 1 2/25/11 1:45a Klzhan
; Initial Check-in
;
; 1 12/03/10 5:11a Klzhan
; Initial Check-in.
;
;
;****************************************************************************
;<AMI_FHDR_START>
;
; Name: AMTInt9.asm
;
; Description: Hook Int 9 for Legacy Serial Redirection.
;
;<AMI_FHDR_END>
;****************************************************************************
;----------------------------------------------------------------------------
; INCLUDE FILES
;----------------------------------------------------------------------------
include token.equ
;----------------------------------------------------------------------------
; EQUATES & STRUCTURES
;----------------------------------------------------------------------------
refresh_port equ 61h
kb_data_port equ 60h ; keyboard data port
kb_stat_port equ 64h ; keyboard status port
kbcCMDPort EQU 64h ; Keyboard controller command port
enKeyboardCMD EQU 0aeh ; Enable keyboard command
diKeyboardCMD EQU 0adh ; Disable keyboard command
IBFTimeoutCount EQU 0f000h ; Check keyboart input buffer count
kbcIBF EQU 00000010b; Keyboard input buffer full
;----------------------------------------------------------------------------
; EXTERNS USED
;----------------------------------------------------------------------------
;----------------------------------------------------------------------------
; CSMOEM_CSEG S E G M E N T STARTS
;----------------------------------------------------------------------------
CSMOEM_CSEG SEGMENT PARA PUBLIC 'CODE' USE16
ASSUME cs:CSMOEM_CSEG, ds:CSMOEM_CSEG
.386p
;----------------------------------------------------------------------------
OldIntHandler LABEL DWORD
IntSegSav dw 0
IntOfsSav dw 0
;<AMI_PHDR_START>
;----------------------------------------------------------------------------
;
; Procedure: AMTINT09Proc
;
; Description:
;
; Input:
;
; Output:
;
; Modified:
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>
AMTINT09Proc PROC NEAR PUBLIC
pushf
cmp cs:dSredirInterruptPtr, 0
jnz lock_local_keyboard
popf
jmp DWORD PTR cs:[OldIntHandler]
lock_local_keyboard:
push ds
push si
; DS:SI = *dSredirInterruptPtr
lds si, DWORD PTR cs:dSredirInterruptPtr
; cmp WORD PTR ds:[si], 0 ; does interrutp come from redirection ?
test BYTE PTR ds:[si], 1 ; does interrutp come from redirection ?
jz not_serial_redirection_interrupt ; br not redirection interrupt
; jmp to original Int 9 vector to service redirection interrupt
pushf
push cs
push OFFSET returnFromInt9
push DWORD PTR cs:OldIntHandler
retf
returnFromInt9:
; mov WORD PTR ds:[si], 0 ; clear redirection interrupt flag
mov BYTE PTR ds:[si], 0 ; clear redirection interrupt flag
jmp redirection_return_to_caller
not_serial_redirection_interrupt:
; do nothing and return to caller.
push ax
call disable_keyboard
call enable_keyboard
; clear EOI
mov al, 20h ; end of INT code
out 20h, al ; out to INT CONTROLLER port
pop ax
redirection_return_to_caller:
pop si
pop ds
popf
retf 2
AMTINT09Proc ENDP
;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure: CheckKBCController
;
; Description: Check KBC controller present.
;
; Input: None.
;
; Output: None.
;
; Modified: ZF = 0 KBC controller present.
; = 1 No KBC controller.
;
; Referrals:
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>
CheckKBCController PROC NEAR
push ax
in al, kb_stat_port
cmp al, 0ffh
pop ax
ret
CheckKBCController ENDP
;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure: enable_keyboard
;
; Description: Enables KBD interface. Also CPU interrupt will be enabled
; here.
;
; Input: None.
;
; Output: None.
;
; Modified: AL.
;
; Referrals: ib_free.
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>
enable_keyboard PROC NEAR PUBLIC
call CheckKBCController
jz short Enable_keyboardExit
call ib_free ; Wait for input buffer free.
mov al, enKeyboardCMD ; CMD to enable KBD interface.
out kbcCMDPort, al ; Write command to KBC.
call ib_free ; Wait for input buffer free.
Enable_keyboardExit: ;(BUG4128+)
sti
ret
enable_keyboard ENDP
;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure: disable_keyboard
;
; Description: Disables KBD interface and reads the data from KBC data port.
;
; Input: None.
;
; Output: AL - Data read from KBC data port.
;
; Modified: AL.
;
; Referrals: ib_free.
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>
disable_keyboard PROC NEAR PUBLIC
call CheckKBCController
jz short Disable_keyboardExit
call ib_free ; Wait for input buffer free.
mov al, diKeyboardCMD ; CMD to disable KBD interface.
out kbcCMDPort, al ; Write command to KBC.
call ib_free ; Wait for input buffer free.
in al, kb_data_port ; Read the data.(BUG2673+)
Disable_keyboardExit: ;
ret
disable_keyboard ENDP
;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure: ib_free
;
; Description: This routine waits until the KBC input buffer is free.
;
; Input: None.
;
; Output: None.
;
; Modified: AL.
;
; Referrals: None.
;
; Notes: DO NOT USE STACK. This routine may be called with RET_SP
; macro.
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>
ib_free PROC NEAR PUBLIC
push cx
mov cx, IBFTimeoutCount
IbFreeLp:
in al, kb_stat_port
call CheckKBCController
jz short IbFreeExit
out 0ebh, al
out 0ebh, al
out 0ebh, al
test al, kbcIBF
loopnz IbFreeLp
IbFreeExit:
pop cx
ret
ib_free ENDP
;----------------------------------------------------------------------------
LockKeyBoardSignature DB '$LKb'
dSredirInterruptPtr DD 0
dLockKBD DD 0
;----------------------------------------------------------------------------
; CSMOEM_CSEG S E G M E N T ENDS
;----------------------------------------------------------------------------
CSMOEM_CSEG ENDS
END
;****************************************************************************
;****************************************************************************
;** **
;** (C)Copyright 1985-2009, American Megatrends, Inc. **
;** **
;** All Rights Reserved. **
;** **
;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
;** **
;** Phone (770)-246-8600 **
;** **
;****************************************************************************
;****************************************************************************
|