;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; V3.EFI ;;
;; Voltage in millivolts ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
format PE64 dll efiboot at 0 on 'nul'
include 'efi3.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 readable executable
entry $
push rbx
push rcx
push rdx
push rdi
push rsi
push r15
push r14
push r13
push r12
push rbp
sub rsp,21h*8
xor r12,r12
mov r14,rcx ; ImageHandle
mov r15,rdx ; pointer to SystemTable
mov ebp,80000000h
xor eax,eax
xor edx,edx
mov ecx,8bh
wrmsr
xor ecx,ecx
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,ebp
inc edx
xor eax,eax
wrmsr
rdmsr
cmp dl,0
jne MailBoxError
mov [TopCore],al
mov edx,ebp ; Get Cache OC ratio and capabilities
mov dx,201h
xor eax,eax
wrmsr
rdmsr
cmp dl,0
jne MailBoxError
mov [TopCache],al
; mov edx,ebp
; mov dl,10h
; xor eax,eax
; wrmsr
; rdmsr
; cmp dl,0
; jne MailBoxError
mov eax,CoreVoltage
mov al,[TopCore]
mov edx,ebp ; Set Core OC ratio
mov dl,11h
wrmsr
rdmsr
cmp dl,0
jne MailBoxError
; mov edx,ebp
; mov dx,210h ; Set Cache OC ratio
; xor eax,eax
; wrmsr
; rdmsr
; cmp dl,0
; jne MailBoxError
mov eax,CacheVoltage
mov al,[TopCache]
mov edx,ebp
mov dx,211h
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,ebp
wrmsr
mov ecx,620h ; Set Cache Min/Max Ratios
rdmsr
mov al,[TopCache]
mov ah,al
wrmsr
mov ecx,194h ; Lock OC
rdmsr
bts eax,20
wrmsr
lea rdx,[_Success]
call TextOut
jmp @f
WrongCPU:
lea rdx,[_WrongCPU]
call TextOut
xor rax,rax
jmp @f
MicroCodePresent:
lea rdx,[_MicroCodePresent]
call TextOut
xor rax,rax
jmp @f
OC_Locked:
lea rdx,[_OC_Locked]
call TextOut
xor rax,rax
jmp @f
MailBoxError:
lea rdx,[_MailBoxError]
call TextOut
xor rax,rax
jmp @f
@@:
xor rax,rax
add rsp,21h*8
pop rbp
pop r12
pop r13
pop r14
pop r15
pop rsi
pop rdi
pop rdx
pop rcx
pop rbx
ret
TextOut:
sub rsp,5*8
mov rcx, [r15 + EFI_SYSTEM_TABLE.ConOut]
call [rcx + SIMPLE_TEXT_OUTPUT_INTERFACE.OutputString]
add rsp,5*8
retn
section '.data' data readable writeable
TopCore db ?
TopCache db ?
_WrongCPU du 13,10,'V3 - Wrong CPU.',13,10,0
_MicroCodePresent du 13,10,'V3 - Microcode present.',13,10,0
_OC_Locked du 13,10,'V3 - Overclocking Locked.',13,10,0
_MailBoxError du 13,10,'V3 - Mailbox Error.',13,10,0
_Success du 13,10,'V3 - All Turbo Set',13,10,0