Commit | Line | Data |
---|---|---|
a5ed1ffa | 1 | /* |
ba180fd4 | 2 | * Copyright (C) 2002 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com) |
1da177e4 LT |
3 | * Licensed under the GPL |
4 | */ | |
5 | ||
ba180fd4 | 6 | #include <signal.h> |
edea1385 | 7 | #include "kern_util.h" |
9226b838 | 8 | #include "longjmp.h" |
9226b838 | 9 | #include "sysdep/ptrace.h" |
5ade8878 | 10 | #include <generated/asm-offsets.h> |
1da177e4 | 11 | |
1da177e4 | 12 | /* Set during early boot */ |
99764fa4 | 13 | static int host_has_cmov = 1; |
235a6f06 KS |
14 | static jmp_buf cmov_test_return; |
15 | ||
16 | static void cmov_sigill_test_handler(int sig) | |
17 | { | |
18 | host_has_cmov = 0; | |
19 | longjmp(cmov_test_return, 1); | |
20 | } | |
21 | ||
9226b838 | 22 | void arch_check_bugs(void) |
235a6f06 KS |
23 | { |
24 | struct sigaction old, new; | |
25 | ||
26 | printk(UM_KERN_INFO "Checking for host processor cmov support..."); | |
27 | new.sa_handler = cmov_sigill_test_handler; | |
28 | ||
29 | /* Make sure that SIGILL is enabled after the handler longjmps back */ | |
30 | new.sa_flags = SA_NODEFER; | |
31 | sigemptyset(&new.sa_mask); | |
32 | sigaction(SIGILL, &new, &old); | |
33 | ||
34 | if (setjmp(cmov_test_return) == 0) { | |
35 | unsigned long foo = 0; | |
36 | __asm__ __volatile__("cmovz %0, %1" : "=r" (foo) : "0" (foo)); | |
37 | printk(UM_KERN_CONT "Yes\n"); | |
38 | } else | |
39 | printk(UM_KERN_CONT "No\n"); | |
40 | ||
41 | sigaction(SIGILL, &old, &new); | |
42 | } | |
1da177e4 | 43 | |
9226b838 | 44 | void arch_examine_signal(int sig, struct uml_pt_regs *regs) |
1da177e4 LT |
45 | { |
46 | unsigned char tmp[2]; | |
47 | ||
ba180fd4 JD |
48 | /* |
49 | * This is testing for a cmov (0x0f 0x4x) instruction causing a | |
1da177e4 LT |
50 | * SIGILL in init. |
51 | */ | |
c2220b2a | 52 | if ((sig != SIGILL) || (get_current_pid() != 1)) |
9226b838 JD |
53 | return; |
54 | ||
55 | if (copy_from_user_proc(tmp, (void *) UPT_IP(regs), 2)) { | |
56 | printk(UM_KERN_ERR "SIGILL in init, could not read " | |
57 | "instructions!\n"); | |
58 | return; | |
59 | } | |
1da177e4 | 60 | |
ba180fd4 | 61 | if ((tmp[0] != 0x0f) || ((tmp[1] & 0xf0) != 0x40)) |
9226b838 | 62 | return; |
1da177e4 | 63 | |
ba180fd4 | 64 | if (host_has_cmov == 0) |
9226b838 JD |
65 | printk(UM_KERN_ERR "SIGILL caused by cmov, which this " |
66 | "processor doesn't implement. Boot a filesystem " | |
67 | "compiled for older processors"); | |
ba180fd4 | 68 | else if (host_has_cmov == 1) |
9226b838 JD |
69 | printk(UM_KERN_ERR "SIGILL caused by cmov, which this " |
70 | "processor claims to implement"); | |
71 | else | |
72 | printk(UM_KERN_ERR "Bad value for host_has_cmov (%d)", | |
73 | host_has_cmov); | |
1da177e4 | 74 | } |