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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
|
;**********************************************************************
;**********************************************************************
;** **
;** (C)Copyright 1985-2009, American Megatrends, Inc. **
;** **
;** All Rights Reserved. **
;** **
;** 5555 Oakbrook Pkwy, Suite 200, Norcross, GA 30093 **
;** **
;** Phone: (770)-246-8600 **
;** **
;**********************************************************************
;**********************************************************************
; $Header: /Alaska/SOURCE/Modules/CMOS Manager/CMOS SEC/CmosManagerSec.asm 11 12/04/09 7:30p Michaela $
;
; $Revision: 11 $
;
; $Date: 12/04/09 7:30p $
;
;****************************************************************************
; Revision History
; ----------------
; $Log: /Alaska/SOURCE/Modules/CMOS Manager/CMOS SEC/CmosManagerSec.asm $
;
; 11 12/04/09 7:30p Michaela
;
; 10 7/29/09 9:55a Michaela
; updates Aptio Enhancement EIP 22205
; (no code changes)
;
; 9 7/23/09 2:28p Michaela
;
; 8 7/23/09 1:35p Michaela
; Fixed build issue related to PE32 binaries
;
; 7 6/02/09 3:26p Michaela
; For label: 4.6.3_CMOSMGR_11
;
; 6 3/11/09 3:37p Michaela
;
; 5 2/23/09 6:01p Michaela
; --Fix token name
;
; 4 2/16/09 10:15p Michaela
; - Use CMOS_BANK0_INDEX/CMOS_BANK0_INDEX SDL token
; - OR CMOS_NMI_BIT_VALUE with index port
; values
;
; 3 1/21/09 3:30p Michaela
; fixed build issue
;
; 2 1/21/09 2:59p Michaela
; **Implemented check for CMOS_MGR_SET_NMI_BIT when
; writing the address
; **Now using CMOS_STD_INDEX and CMOS_STD_DATA
; for all CMOS access in SEC (this restricts all SEC-phase CMOS
; locations to below 0x80, which is not expected to be an issue)
;
; 1 11/25/08 3:12p Michaela
; Organize SEC-related initialization code
;
; 4 11/17/08 3:44p Michaela
; --Port and register constants are initialized using SDL tokens
; --CMOS-based API pointer and all other SEC accesses are assumed
; to be located in the 0xF to 0x7F standard CMOS region.
;
; 3 11/14/08 9:16a Michaela
; **CmosReadWrite procedure is used for all CMOS access in the SEC
; phase.
; **Include CmosAccessSec.inc for the prototype, error codes
; and jump macros
;
; 2 11/07/08 5:30p Michaela
; Added SS header
;
;*************************************************************************
;<AMI_FHDR_START>
;
; Name: CmosManagerSec.asm
;
; Description:
; This file contains all code necessary to support CMOS Manager's SEC
; phase initialization and external services.
;
;<AMI_FHDR_END>
;*************************************************************************
;----------------------------------------------------------------------------
; Assembler build options
;----------------------------------------------------------------------------
.586P
.XMM
.MODEL SMALL
INCLUDE TOKEN.EQU
INCLUDE TOKENEQU.EQU
CMOS_NO_EXTERNS equ 1
INCLUDE CmosAccessSec.inc
; Externs
EXTERN SEC_CmosManagerEnd:NEAR32
IF SEC_LAST_ADDRESS_VALID
EXTERN LAST_ADDRESS:ABS
ENDIF
; Equates
bcmos_addr_port equ MKF_CMOS_BANK0_INDEX
bcmos_data_port equ MKF_CMOS_BANK0_DATA
MKF_stnd_storage_size equ 00Fh ; size of standard
CLOCK_STATUS_REG EQU MKF_CMOS_RTC_STATUS_REGISTER
BATT_BIT EQU 080h ; bit 8 is battery status (set == good)
MSR_XAPIC_BASE EQU 01Bh ; standard APIC base MSR
XAPIC_BASE_BSP_BIT EQU 008h
IO_DELAY_bb MACRO
jmp $+2
jmp $+2
ENDM
;----------------------------------------------------------------------------
; STARTUP_SEG S E G M E N T STARTS
;----------------------------------------------------------------------------
STARTUP_SEG SEGMENT PARA PUBLIC 'CODE' USE32
;<AMI_PHDR_START>
;----------------------------------------------------------------------------
;
; Procedure: CmosReadWrite
;
; Description:
; Returns the CMOS value associated with the given CMOS token
; from the actual CMOS storage. CMOS checksum is don't care. Upon detecting
; an error, the carry flag is set and an error code is returned in AX.
;
; Input:
; AX - CMOS Token.
; DL - Set for write or Clear for read
; DH - Value to write
;
; Output:
; AX - CMOS value if reading
; NC - If success
; CY - If error & AX = Error code
;
; Modified:
; AX, MM0, MM1, MM2, MM3
; (EDX upper word and EAX upper word are unmodified)
; All other registers are preserved
;
; Referrals:
; None
;
; Notes:
; An error code is returned in AX with Carry Flag set upon detected
; error condition. The following error code constants (defined in
; CmosAccessSec.inc) are used:
;
; CMOS_BATTERY_ERR
; CMOS_BITSIZE_ERR
; CMOS_OVERFLOW_ERR
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>
CmosReadWrite PROC NEAR PUBLIC
; Token[2:0] = Bit offset within a byte of item's start address in CMOS
; Token[11:3] = Byte offset of item's start address in CMOS
; Token[15:12] = Size of item (in units of bits)
movd mm1, ebx ; save registers
movd mm2, ecx
movd mm3, edx
mov bx, ax
shr bx, 12
cmp bx, 8 ; BX has the size in Bits
ja CmosReadWriteSizeError
cmp bx, 0
je CmosReadWriteSizeError
mov cx, ax
and cx, 07h ; CX has the bit position.
and ax, 0FFFh
shr ax, 3 ; AL has the CMOS address
;-----------------------------------------------------
; return error if battery is bad (using standard ports)
;-----------------------------------------------------
xchg ah, al ; save address in AH
mov al, CLOCK_STATUS_REG
or al, MKF_CMOS_NMI_BIT_VALUE ; set value of NMI bit
out bcmos_addr_port, al
io_delay_bb
io_delay_bb
in al, bcmos_data_port ; AL = battery status
test al, BATT_BIT ; bit is set if OK
.if (zero?)
mov ax, CMOS_BATTERY_ERR ; CMOS battery is low.
jmp CmosReadWriteError
.endif
xchg ah, al ; restore address to AL
;-----------------------------------------------------
; Create an AND mask in CX with bits set corresponding
; the destination bit field
;-----------------------------------------------------
ror ecx, 16 ; ECX upper = bit position
xor cx, cx
.while (bx > 0)
shl cx, 1
or cx, 1
dec bx
.endw
mov bx, cx ; BX = mask
ror ecx, 16 ; CX = bit position
shl bx, cl ; BX = shifted mask
ror ecx, 16 ; ECX upper = bit position
mov cx, bx ; CX = shifted mask
;-----------------------------------------------------
; If writing, encode the value:
;
; 1) shift the value in DH to its position,
; 2) complement the mask so that it can be used to clear
; the destination bit field
; 3) apply/test mask to DH to ensure adjacent bits are not
; overwritten, returning an error if there is overflow
;
; Note: error checking here will detect an error
; if attempted write is not within the owned
; bits of a token.
;-----------------------------------------------------
.if (dl == CMOS_WRITE_ACCESS)
ror ecx, 16 ; CX = bit position & ECX upper = mask
movzx bx, dh ; test upper bit overflow
shl bx, cl
or bh, bh
.if (!zero?) ; error if bits are shifted into BH
mov ax, CMOS_OVERFLOW_ERR
jmp CmosReadWriteError
.endif
shl dh, cl ; do the shift for real
ror ecx, 16 ; CX = mask & ECX upper = bit position
not cx ; CX = complemented mask
test dh, cl ; ensure no overwriting of destination
.if (!zero?)
mov ax, CMOS_OVERFLOW_ERR
jmp CmosReadWriteError
.endif
mov bl, dh ; BL = value to write
.endif
;-----------------------------------------------------
; Note: EDX will contain value/access type information
; or data/index port information as needed.
; MM0/MM3 are used as a swap registers for this
; purpose.
;-----------------------------------------------------
mov dx, bcmos_data_port
ror edx, 16
mov dx, bcmos_addr_port
movd mm0, edx ; save data|index in MM0
; data port in EDX upper word
; index port in DX
;-----------------------------------------------------
; Read/write the CMOS register
;
; Note: A read always occurs. If a write is requested,
; only the bits that are owned by the token
; are modified and written back.
;-----------------------------------------------------
or al, MKF_CMOS_NMI_BIT_VALUE ; set value of NMI bit
out dx, al ; AL = address
io_delay_bb
io_delay_bb
xchg ah, al ; AH contains address
ror edx, 16 ; DX = data port
in al, dx ; AL = value from CMOS
movd edx, mm3 ; EDX = value|access type
.if (dl == CMOS_WRITE_ACCESS)
movd edx, mm0 ; EDX = data|index ports
xchg ah, al ; AL = address & AH = register value
out dx, al
io_delay_bb
io_delay_bb
xchg al, ah ; AL = register value & AH = address
and al, cl ; clear the destination field
or al, bl ; set the value in AL
ror edx, 16 ; DX = data port
out dx, al
clc ; clear error flag
jmp CmosReadWriteExit
;-----------------------------------------------------
; If reading, decode the value:
;
; 1) AND with mask to clear unused bits
; 2) Shift down to zero by bit position
;-----------------------------------------------------
.else
and al, cl ; CL is shifted, uncomplemented mask
ror ecx, 16 ; CL = bit position & ECX upper = mask
shr al, cl
movzx ax, al ; AX = value
clc ; clear error flag
jmp CmosReadWriteExit
.endif
CmosReadWriteSizeError:
mov ax, CMOS_BITSIZE_ERR
CmosReadWriteError:
stc ; set error flag
CmosReadWriteExit:
movd ebx, mm1 ; restore registers
movd ecx, mm2
movd edx, mm3
jmp edi
CmosReadWrite ENDP
;<AMI_PHDR_START>
;----------------------------------------------------------------------------
;
; Procedure: SEC_CmosManager
;
; Description:
; This is the entrypoint for CMOS Manager SEC code.
;
; Input:
; None
;
; Output:
; None
;
; Modified:
; None
;
; Referrals:
; None
;
; Notes:
; Currently, there are no SEC tasks for the CMOS Manager.
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>
SEC_CmosManager PROC PUBLIC
jmp SEC_CmosManagerEnd
SEC_CmosManager ENDP
;----------------------------------------------------------------------------
; STARTUP_SEG S E G M E N T ENDS
;----------------------------------------------------------------------------
STARTUP_SEG ENDS
END
;**********************************************************************
;**********************************************************************
;** **
;** (C)Copyright 1985-2009, American Megatrends, Inc. **
;** **
;** All Rights Reserved. **
;** **
;** 5555 Oakbrook Pkwy, Suite 200, Norcross, GA 30093 **
;** **
;** Phone: (770)-246-8600 **
;** **
;**********************************************************************
;**********************************************************************
|