|
7 | 7 | * Copyright (c) 2007 Andi Kleen (ak@suse.de) |
8 | 8 | * Copyright (c) 2007 Eric Biederman (ebiederm@xmission.com) |
9 | 9 | * Copyright (c) 2007 Vivek Goyal (vgoyal@in.ibm.com) |
| 10 | + * Copyright (c) 2010 Kees Cook (kees.cook@canonical.com) |
10 | 11 | * |
11 | 12 | * This source code is licensed under the GNU General Public License, |
12 | 13 | * Version 2. See the file COPYING for more details. |
13 | 14 | * |
14 | 15 | * This is a common code for verification whether CPU supports |
15 | 16 | * long mode and SSE or not. It is not called directly instead this |
16 | 17 | * file is included at various places and compiled in that context. |
17 | | - * Following are the current usage. |
| 18 | + * This file is expected to run in 32bit code. Currently: |
18 | 19 | * |
19 | | - * This file is included by both 16bit and 32bit code. |
| 20 | + * arch/x86/boot/compressed/head_64.S: Boot cpu verification |
| 21 | + * arch/x86/kernel/trampoline_64.S: secondary processor verfication |
| 22 | + * arch/x86/kernel/head_32.S: processor startup |
20 | 23 | * |
21 | | - * arch/x86_64/boot/setup.S : Boot cpu verification (16bit) |
22 | | - * arch/x86_64/boot/compressed/head.S: Boot cpu verification (32bit) |
23 | | - * arch/x86_64/kernel/trampoline.S: secondary processor verfication (16bit) |
24 | | - * arch/x86_64/kernel/acpi/wakeup.S:Verfication at resume (16bit) |
25 | | - * |
26 | | - * verify_cpu, returns the status of cpu check in register %eax. |
| 24 | + * verify_cpu, returns the status of longmode and SSE in register %eax. |
27 | 25 | * 0: Success 1: Failure |
28 | 26 | * |
| 27 | + * On Intel, the XD_DISABLE flag will be cleared as a side-effect. |
| 28 | + * |
29 | 29 | * The caller needs to check for the error code and take the action |
30 | 30 | * appropriately. Either display a message or halt. |
31 | 31 | */ |
@@ -62,8 +62,41 @@ verify_cpu: |
62 | 62 | cmpl $0x444d4163,%ecx |
63 | 63 | jnz verify_cpu_noamd |
64 | 64 | mov $1,%di # cpu is from AMD |
| 65 | + jmp verify_cpu_check |
65 | 66 |
|
66 | 67 | verify_cpu_noamd: |
| 68 | + cmpl $0x756e6547,%ebx # GenuineIntel? |
| 69 | + jnz verify_cpu_check |
| 70 | + cmpl $0x49656e69,%edx |
| 71 | + jnz verify_cpu_check |
| 72 | + cmpl $0x6c65746e,%ecx |
| 73 | + jnz verify_cpu_check |
| 74 | + |
| 75 | + # only call IA32_MISC_ENABLE when: |
| 76 | + # family > 6 || (family == 6 && model >= 0xd) |
| 77 | + movl $0x1, %eax # check CPU family and model |
| 78 | + cpuid |
| 79 | + movl %eax, %ecx |
| 80 | + |
| 81 | + andl $0x0ff00f00, %eax # mask family and extended family |
| 82 | + shrl $8, %eax |
| 83 | + cmpl $6, %eax |
| 84 | + ja verify_cpu_clear_xd # family > 6, ok |
| 85 | + jb verify_cpu_check # family < 6, skip |
| 86 | + |
| 87 | + andl $0x000f00f0, %ecx # mask model and extended model |
| 88 | + shrl $4, %ecx |
| 89 | + cmpl $0xd, %ecx |
| 90 | + jb verify_cpu_check # family == 6, model < 0xd, skip |
| 91 | + |
| 92 | +verify_cpu_clear_xd: |
| 93 | + movl $MSR_IA32_MISC_ENABLE, %ecx |
| 94 | + rdmsr |
| 95 | + btrl $2, %edx # clear MSR_IA32_MISC_ENABLE_XD_DISABLE |
| 96 | + jnc verify_cpu_check # only write MSR if bit was changed |
| 97 | + wrmsr |
| 98 | + |
| 99 | +verify_cpu_check: |
67 | 100 | movl $0x1,%eax # Does the cpu have what it takes |
68 | 101 | cpuid |
69 | 102 | andl $REQUIRED_MASK0,%edx |
|
0 commit comments