Debian Codegraph @

src/security/intel/txt/getsec_mtrr_setup.inc

raw
1 /* SPDX-License-Identifier: GPL-2.0-only */
2
3 #include <cpu/x86/mtrr.h>
4 #include <cpu/x86/msr.h>
5
6 /*
7 * Configure the MTRRs to cache the BIOS ACM. No general-purpose
8 * registers are preserved. Inputs are taken from SSE registers:
9 *
10 * %xmm0: BIOS ACM base
11 * %xmm1: BIOS ACM size
12 *
13 * These two SSE registers are not preserved, but the others are.
14 */
15 .macro SET_UP_MTRRS_FOR_BIOS_ACM
16
17 /* Determine CPU_ADDR_BITS and load PHYSMASK high word to %edx. */
18 movl $0x80000008, %eax
19 cpuid
20 movb %al, %cl
21 sub $32, %cl
22 movl $1, %edx
23 shl %cl, %edx
24 subl $1, %edx
25 movl %edx, %edi /* %edi contains the MTRR_HIGH_MASK */
26
27 /* Get the number of variable MTRRs */
28 movl $(MTRR_CAP_MSR), %ecx
29 rdmsr
30 andl $(0xff), %eax
31
32 /* Initialize ECX */
33 movl $(MTRR_PHYS_BASE(0)), %ecx
34
35 jmp cond_allocate_var_mtrrs
36
37 body_allocate_var_mtrrs:
38
39 /* Program MTRR base */
40 xorl %edx, %edx
41 movd %xmm0, %eax
42 orl $(MTRR_TYPE_WRBACK), %eax
43 wrmsr
44 incl %ecx /* Move index to MTRR_PHYS_MASK */
45
46 /* Temporarily transfer MSR index to EDX so that CL can be used */
47 movl %ecx, %edx
48
49 /* Determine next size to cache */
50 bsr %ebx, %ecx
51 movl $(1), %ebx
52 shl %cl, %ebx /* Can only use CL here */
53
54 /* Restore ECX */
55 movl %edx, %ecx
56
57 /* Update saved base address */
58 addl %ebx, %eax
59 movd %eax, %xmm0
60
61 /* Update saved remaining size */
62 movd %xmm1, %eax
63 subl %ebx, %eax
64 movd %eax, %xmm1
65
66 /* Program MTRR mask */
67 movl %edi, %edx
68 xorl %eax, %eax
69 subl %ebx, %eax /* %eax = 4GIB - size to cache */
70 orl $(MTRR_PHYS_MASK_VALID), %eax
71 wrmsr
72 incl %ecx /* Move index to next MTRR_PHYS_BASE */
73
74 cond_allocate_var_mtrrs:
75
76 /* Check if we still need to cache something */
77 movd %xmm1, %ebx
78 andl %ebx, %ebx
79
80 jnz body_allocate_var_mtrrs
81
82 .endm