aboutsummaryrefslogtreecommitdiff
path: root/EfiGuardDxe/X64/Cet.asm
blob: 74433c297d304d2f14f38b9dcee1f4100b5f89f1 (plain)
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
MSR_S_CET					EQU 6A2h
MSR_S_CET_SH_STK_EN			EQU 1
CR4_CET						EQU (1 SHL 23)
N_CR4_CET					EQU 23

.code

align 16
AsmDisableCet PROC
	mov ecx, MSR_S_CET
	rdmsr
	test al, MSR_S_CET_SH_STK_EN
	jz @F						; if z, shadow stack not enabled

	; Pop pushed data for 'call'
	mov rax, 1
	incsspq rax

@@:
	mov rax, cr4
	btr eax, N_CR4_CET			; clear CR4_CET
	mov cr4, rax
	ret
AsmDisableCet ENDP

align 16
AsmEnableCet PROC
	mov rax, cr4
	bts eax, N_CR4_CET			; set CR4_CET
	mov cr4, rax

	; Use jmp to skip check for 'ret'
	pop rax
	jmp rax
AsmEnableCet ENDP

end