4 ; * Agesa library 32bit
6 ; * Contains AMD AGESA Library
8 ; * @xrefitem bom "File Content Label" "Release Content"
10 ; * @e sub-project: Lib
11 ; * @e \$Revision: 17071 $ @e \$Date: 2009-07-30 10:13:11 -0700 (Thu, 30 Jul 2009) $
13 ;*****************************************************************************
15 ; Copyright (C) 2012 Advanced Micro Devices, Inc.
16 ; All rights reserved.
18 ; Redistribution and use in source and binary forms, with or without
19 ; modification, are permitted provided that the following conditions are met:
20 ; * Redistributions of source code must retain the above copyright
21 ; notice, this list of conditions and the following disclaimer.
22 ; * Redistributions in binary form must reproduce the above copyright
23 ; notice, this list of conditions and the following disclaimer in the
24 ; documentation and/or other materials provided with the distribution.
25 ; * Neither the name of Advanced Micro Devices, Inc. nor the names of
26 ; its contributors may be used to endorse or promote products derived
27 ; from this software without specific prior written permission.
29 ; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
30 ; ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
31 ; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
32 ; DISCLAIMED. IN NO EVENT SHALL ADVANCED MICRO DEVICES, INC. BE LIABLE FOR ANY
33 ; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
34 ; (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
35 ; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
36 ; ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 ; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
38 ; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 ;*****************************************************************************
48 ;/*---------------------------------------------------------------------------------------*/
52 ; * @param[in] Address IO port address
53 ; * @param[in] Data IO port Value
57 WriteIo8 PROC NEAR C USES DX AX Address:WORD, Data:Byte
64 ;/*---------------------------------------------------------------------------------------*/
68 ; * @param[in] Address IO port address
69 ; * @param[in] Data IO port Value
72 WriteIo16 PROC NEAR C USES DX AX Address:WORD, Data:WORD
79 ;/*---------------------------------------------------------------------------------------*/
83 ; * @param[in] Address IO port address
84 ; * @param[in] Data IO port Value
88 WriteIo32 PROC NEAR C USES DX EAX Address:WORD, Data:DWORD
95 ;/*---------------------------------------------------------------------------------------*/
99 ; * @param[in] - IO port address
100 ; * @retval IO port Value
103 ReadIo8 PROC NEAR C USES DX Address:WORD
109 ;/*---------------------------------------------------------------------------------------*/
113 ; * @param[in] Address IO port address
114 ; * @retval IO port Value
117 ReadIo16 PROC NEAR C USES DX Address:WORD
123 ;/*---------------------------------------------------------------------------------------*/
127 ; * @param[in] Address IO port address
128 ; * @retval IO port Value
131 ReadIo32 PROC NEAR C USES DX Address:WORD
138 ;/*---------------------------------------------------------------------------------------*/
142 ; * @param[in] Address MSR Address
143 ; * @param[in] Data Pointer to data
144 ; * @param[in] ConfigPtr (Optional)
147 LibAmdMsrRead PROC NEAR C USES ECX ESI EDX Address:DWORD, Value:PTR, ConfigPtr:PTR
148 mov esi, ConfigPtr ;Dummy read to avoid compilation warning
157 ;/*---------------------------------------------------------------------------------------*/
161 ; * @param[in] Address MSR Address
162 ; * @param[in] Data Pointer to data
163 ; * @param[in] ConfigPtr (Optional)
165 public LibAmdMsrWrite
166 LibAmdMsrWrite PROC NEAR C USES ECX ESI EDX Address:DWORD, Data:PTR, ConfigPtr:PTR
167 mov esi, ConfigPtr ;Dummy read to avoid compilation warning
176 ;/*---------------------------------------------------------------------------------------*/
180 ; * @param[in] Func CPUID function
181 ; * @param[in] DATA Pointer to CPUID_DATA to save cpuid data
182 ; * @param[in] ConfigPtr (Optional)
184 public LibAmdCpuidRead
185 LibAmdCpuidRead PROC NEAR C Func:DWORD, DATA:PTR, ConfigPtr:PTR
187 mov esi, ConfigPtr ;Dummy read to avoid compilation warning
199 ;/*---------------------------------------------------------------------------------------*/
214 ;/*---------------------------------------------------------------------------------------*/
220 ; * @param[in] esi - Low Dword of physical address
221 ; * @param[in] edi - High Dword of physical address
223 SetFsBase PROC NEAR PUBLIC USES EAX EBX ECX EDX EDI
226 mov ecx, 0C0010015h ; HWCR
229 bts eax, 17 ; HWCR.Wrap32Dis
235 mov ecx, 0C0000100h ; FS_BASE
242 ;/*---------------------------------------------------------------------------------------*/
244 ; * Restore MSR0C001_0015
246 ; * @param[in] esi - Low Dword
247 ; * @param[in] edi - High Dword
249 RestoreHwcr PROC NEAR PUBLIC USES EAX ECX EDX
260 ;/*---------------------------------------------------------------------------------------*/
262 ; * Read memory/MMIO byte
264 ; * @param[in] Address - Memory Address
265 ; * @retval Memory byte at given address
267 Read64Mem8 PROC NEAR C PUBLIC USES EBX EDI ESI Address:QWORD
269 mov esi, DWORD PTR Address[0]
270 mov edi, DWORD PTR Address[4]
289 ;/*---------------------------------------------------------------------------------------*/
291 ; * Read memory/MMIO word
293 ; * @param[in] Address - Memory Address
294 ; * @retval Memory word at given address
296 Read64Mem16 PROC NEAR C PUBLIC USES EBX EDI ESI Address:QWORD
298 mov esi, DWORD PTR Address[0]
299 mov edi, DWORD PTR Address[4]
318 ;/*---------------------------------------------------------------------------------------*/
320 ; * Read memory/MMIO dword
322 ; * @param[in] Address - Memory Address
323 ; * @retval Memory dword at given address
325 Read64Mem32 PROC NEAR C PUBLIC USES EBX EDI ESI Address:QWORD
327 mov esi, DWORD PTR Address[0]
328 mov edi, DWORD PTR Address[4]
347 ;/*---------------------------------------------------------------------------------------*/
349 ; * Write memory/MMIO byte
351 ; * @param[in] Address - Memory Address
352 ; * @param[in] Value - Value to write
355 Write64Mem8 PROC NEAR C PUBLIC USES EBX EDI ESI Address:QWORD, Data:BYTE
357 mov esi, DWORD PTR Address[0]
358 mov edi, DWORD PTR Address[4]
379 ;/*---------------------------------------------------------------------------------------*/
381 ; * Write memory/MMIO word
383 ; * @param[in] Address - Memory Address
384 ; * @param[in] Value - Value to write
386 Write64Mem16 PROC NEAR C PUBLIC USES EBX EDI ESI Address:QWORD, Data:WORD
388 mov esi, DWORD PTR Address[0]
389 mov edi, DWORD PTR Address[4]
409 ;/*---------------------------------------------------------------------------------------*/
411 ; * Write memory/MMIO dword
413 ; * @param[in] Address - Memory Address
414 ; * @param[in] Value - Value to write
416 Write64Mem32 PROC NEAR C PUBLIC USES EBX EDI ESI Address:QWORD, Data:DWORD
418 mov esi, DWORD PTR Address[0]
419 mov edi, DWORD PTR Address[4]
441 ;/*---------------------------------------------------------------------------------------*/
443 ; * Read various CPU registers
445 ; * @param[in] Reg Register ID (0/4 - CR0/CR4, 10h/11h/12h/13h/17h - DR0/DR1/DR2/DR3/DR7)
446 ; * @param[in] Value Value to write
449 LibAmdReadCpuReg PROC NEAR C Reg:BYTE, Value:NEAR PTR DWORD
477 LibAmdReadCpuReg ENDP
481 ;/*---------------------------------------------------------------------------------------*/
483 ; * Write various CPU registers
485 ; * @param[in] Reg Register ID (0/4 - CR0/CR4, 10h/11h/12h/13h/17h - DR0/DR1/DR2/DR3/DR7)
486 ; * @param[in] Value Value to write
489 LibAmdWriteCpuReg PROC NEAR C Reg:BYTE, Value:DWORD
508 LibAmdWriteCpuReg ENDP
510 ;/*---------------------------------------------------------------------------------------*/
512 ; * Write back invalidate caches using wbinvd.
518 PUBLIC LibAmdWriteBackInvalidateCache
519 LibAmdWriteBackInvalidateCache PROC NEAR C
522 LibAmdWriteBackInvalidateCache ENDP
524 ;/*---------------------------------------------------------------------------------------*/
538 ;/*---------------------------------------------------------------------------------------*/
540 ; * Enter debugger on SimNow
545 PUBLIC LibAmdSimNowEnterDebugger
546 LibAmdSimNowEnterDebugger PROC NEAR C
548 mov eax, 0BACCD00Bh ; Backdoor in SimNow
549 mov ebx, 2 ; Select breakpoint feature
555 LibAmdSimNowEnterDebugger ENDP
557 ;/*---------------------------------------------------------------------------------------*/
559 ; * IDS IO port write
561 ; * @param[in] Address IO Port Address
562 ; * @param[in] Value Value to write
563 ; * @param[in] Flag IDS flags
568 IdsOutPort PROC NEAR C Address:DWORD, Value:DWORD ,Flag:DWORD
582 ;/*---------------------------------------------------------------------------------------*/
584 ; * Force breakpoint on HDT
588 PUBLIC LibAmdHDTBreakPoint
589 LibAmdHDTBreakPoint PROC NEAR C
593 mov ecx, 0C001100Ah ;bit 0 = HDT redirect
594 mov edi, 09C5A203Ah ;Password
598 mov al, 0B2h ;Marker = B2
604 LibAmdHDTBreakPoint ENDP
606 ;/*---------------------------------------------------------------------------------------*/
608 ; * Find the most right hand side non-zero bit with .
610 ; * @param[in] Value Value
612 PUBLIC LibAmdBitScanForward
613 LibAmdBitScanForward PROC NEAR C Value:DWORD
620 LibAmdBitScanForward ENDP
622 ;/*---------------------------------------------------------------------------------------*/
624 ; * Find the most left hand side non-zero bit.
626 ; * @param[in] Value Value
628 PUBLIC LibAmdBitScanReverse
629 LibAmdBitScanReverse PROC NEAR C Value:DWORD
636 LibAmdBitScanReverse ENDP
638 ;/*---------------------------------------------------------------------------------------*/
640 ; * Flush specified number of cache line
642 ; * @param[in] Address Physical address to be flushed
643 ; * @param[in] Count number of cachelines to be flushed
646 LibAmdCLFlush PROC NEAR C Address:QWORD, Count:BYTE
648 mov ecx, 0C0010015h ; HWCR
652 bts eax, 17 ; HWCR.Wrap32Dis
655 mov edx, DWORD PTR Address[4]
656 mov ecx, 0C0000100h ; FS_BASE
658 mov eax, DWORD PTR Address[0]