format pe64 dll efiboot
entry main
include 'efi.inc'
;-------------------------------------------------------------------------------------------------------
CoreVOffset = -70
CoreVStatic = 0
CoreMulti = 0
CoreFixed = 0
if CoreVOffset > 999
CoreVOffset = 999
else if CoreVOffset < -1000
CoreVOffset = -1000
end if
CoreAdjVOffset = ((CoreVOffset shl 15)/1000) and 0ffe0h
CoreAdjVStatic = ((CoreVStatic shl 18)/1000) and 0fff00h
CoreVoltage = ((CoreAdjVOffset shl 16) or CoreAdjVStatic) or CoreMulti or (CoreFixed shl 20)
;-------------------------------------------------------------------------------------------------------
CacheVOffset = -50
CacheVStatic = 0
CacheMulti = 0
CacheFixed = 0
if CacheVOffset > 999
CacheVOffset = 999
else if CacheVOffset < -1000
CacheVOffset = -1000
end if
CacheAdjVOffset = ((CacheVOffset shl 15)/1000) and 0ffe0h
CacheAdjVStatic = ((CacheVStatic shl 18)/1000) and 0fff00h
CacheVoltage = ((CacheAdjVOffset shl 16) or CacheAdjVStatic) or CacheMulti or (CacheFixed shl 20)
;-------------------------------------------------------------------------------------------------------
section '.text' code executable readable
main:
mov [Handle], rcx ; ImageHandle
mov [SystemTable], rdx ; pointer to SystemTable
lea rdx, [_Start]
mov rcx, [SystemTable]
mov rcx, [rcx + EFI_SYSTEM_TABLE.ConOut]
sub rsp, 4*8
call [rcx + SIMPLE_TEXT_OUTPUT_INTERFACE.OutputString]
add rsp, 4*8
mov eax,0
mov edx,0
mov ecx,8bh
wrmsr
mov ecx,0
inc eax
cpuid
cmp eax,306f2h
jne WrongCPU
mov ecx,8bh
rdmsr
cmp edx,0
jne MicroCodePresent
mov ecx,194h
rdmsr
bt eax,20
jc OC_Locked
mov ecx,150h ; Get Core OC ratio and capabilities
mov edx,80000001h
mov eax,0
wrmsr
rdmsr
cmp dl,0
jne MailBoxError
mov [TopCore],al
mov edx,80000201h ; Get Cache OC ratio and capabilities
mov eax,0
wrmsr
rdmsr
cmp dl,0
jne MailBoxError
mov [TopCache],al
mov eax,CoreVoltage ; Set Core voltage
mov al,[TopCore]
mov edx,80000011h
wrmsr
rdmsr
cmp dl,0
jne MailBoxError
mov eax,CacheVoltage ; Set Cache voltage
mov al,[TopCache]
mov edx,80000211h
wrmsr
rdmsr
cmp dl,0
jne MailBoxError
mov al,[TopCore] ; Set turbo ratio's
mov ah,al
mov dx,ax
shl eax,16
mov ax,dx
mov edx,eax
mov ecx,1adh
wrmsr
inc ecx
wrmsr
inc ecx
or edx,80000000h
wrmsr
mov ecx,620h ; Set Cache Min/Max Ratios
rdmsr
mov al,[TopCache]
mov ah,al
wrmsr
mov ecx,194h
rdmsr
bts eax,20
wrmsr
lea rdx, [_Success]
jmp Text_Exit
WrongCPU:
lea rdx, [_WrongCPU]
jmp Text_Exit
MicroCodePresent:
lea rdx, [_MicroCodePresent]
jmp Text_Exit
OC_Locked:
lea rdx, [_OC_Locked]
jmp Text_Exit
MailBoxError:
lea rdx, [_MailBoxError]
jmp Text_Exit
Text_Exit:
mov rcx, [SystemTable]
mov rcx, [rcx + EFI_SYSTEM_TABLE.ConOut]
sub rsp, 4*8
call [rcx + SIMPLE_TEXT_OUTPUT_INTERFACE.OutputString]
add rsp, 4*8
mov rax, EFI_SUCCESS
retn
section '.data' data readable writeable
TopCore db ?
TopCache db ?
Handle dq ?
SystemTable dq ?
_Start du 13,10,'Xeon v3 All-Core Turbo Boost EFI Driver by C_Payne v0.1 (Single CPU)',13,10,0
_WrongCPU du 'Failure - Wrong CPU.',13,10,0
_MicroCodePresent du 'Failure - Microcode present.',13,10,0
_OC_Locked du 'Failure - Overclocking Locked.',13,10,0
_MailBoxError du 'Failure - Mailbox Error.',13,10,0
_Success du 'Success.',13,10,0