Jeff Dike | a5ed1ff | 2007-05-06 14:50:58 -0700 | [diff] [blame] | 1 | /* |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 2 | * Copyright (C) 2002 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * Licensed under the GPL |
| 4 | */ |
| 5 | |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 6 | #include <signal.h> |
Jeff Dike | edea138 | 2008-02-04 22:30:46 -0800 | [diff] [blame] | 7 | #include "kern_util.h" |
Jeff Dike | 9226b83 | 2008-02-04 22:30:40 -0800 | [diff] [blame] | 8 | #include "longjmp.h" |
Jeff Dike | 9226b83 | 2008-02-04 22:30:40 -0800 | [diff] [blame] | 9 | #include "sysdep/ptrace.h" |
Al Viro | 5ade887 | 2011-08-18 20:07:39 +0100 | [diff] [blame] | 10 | #include <generated/asm-offsets.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | /* Set during early boot */ |
WANG Cong | 99764fa | 2008-07-23 21:28:49 -0700 | [diff] [blame] | 13 | static int host_has_cmov = 1; |
Karol Swietlicki | 235a6f0 | 2008-02-04 22:30:38 -0800 | [diff] [blame] | 14 | static jmp_buf cmov_test_return; |
| 15 | |
Al Viro | 5ade887 | 2011-08-18 20:07:39 +0100 | [diff] [blame] | 16 | #define TASK_PID(task) *((int *) &(((char *) (task))[HOST_TASK_PID])) |
| 17 | |
Karol Swietlicki | 235a6f0 | 2008-02-04 22:30:38 -0800 | [diff] [blame] | 18 | static void cmov_sigill_test_handler(int sig) |
| 19 | { |
| 20 | host_has_cmov = 0; |
| 21 | longjmp(cmov_test_return, 1); |
| 22 | } |
| 23 | |
Jeff Dike | 9226b83 | 2008-02-04 22:30:40 -0800 | [diff] [blame] | 24 | void arch_check_bugs(void) |
Karol Swietlicki | 235a6f0 | 2008-02-04 22:30:38 -0800 | [diff] [blame] | 25 | { |
| 26 | struct sigaction old, new; |
| 27 | |
| 28 | printk(UM_KERN_INFO "Checking for host processor cmov support..."); |
| 29 | new.sa_handler = cmov_sigill_test_handler; |
| 30 | |
| 31 | /* Make sure that SIGILL is enabled after the handler longjmps back */ |
| 32 | new.sa_flags = SA_NODEFER; |
| 33 | sigemptyset(&new.sa_mask); |
| 34 | sigaction(SIGILL, &new, &old); |
| 35 | |
| 36 | if (setjmp(cmov_test_return) == 0) { |
| 37 | unsigned long foo = 0; |
| 38 | __asm__ __volatile__("cmovz %0, %1" : "=r" (foo) : "0" (foo)); |
| 39 | printk(UM_KERN_CONT "Yes\n"); |
| 40 | } else |
| 41 | printk(UM_KERN_CONT "No\n"); |
| 42 | |
| 43 | sigaction(SIGILL, &old, &new); |
| 44 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | |
Jeff Dike | 9226b83 | 2008-02-04 22:30:40 -0800 | [diff] [blame] | 46 | void arch_examine_signal(int sig, struct uml_pt_regs *regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | { |
| 48 | unsigned char tmp[2]; |
| 49 | |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 50 | /* |
| 51 | * This is testing for a cmov (0x0f 0x4x) instruction causing a |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | * SIGILL in init. |
| 53 | */ |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 54 | if ((sig != SIGILL) || (TASK_PID(get_current()) != 1)) |
Jeff Dike | 9226b83 | 2008-02-04 22:30:40 -0800 | [diff] [blame] | 55 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | |
Jeff Dike | 9226b83 | 2008-02-04 22:30:40 -0800 | [diff] [blame] | 57 | if (copy_from_user_proc(tmp, (void *) UPT_IP(regs), 2)) { |
| 58 | printk(UM_KERN_ERR "SIGILL in init, could not read " |
| 59 | "instructions!\n"); |
| 60 | return; |
| 61 | } |
| 62 | |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 63 | if ((tmp[0] != 0x0f) || ((tmp[1] & 0xf0) != 0x40)) |
Jeff Dike | 9226b83 | 2008-02-04 22:30:40 -0800 | [diff] [blame] | 64 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 66 | if (host_has_cmov == 0) |
Jeff Dike | 9226b83 | 2008-02-04 22:30:40 -0800 | [diff] [blame] | 67 | printk(UM_KERN_ERR "SIGILL caused by cmov, which this " |
| 68 | "processor doesn't implement. Boot a filesystem " |
| 69 | "compiled for older processors"); |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 70 | else if (host_has_cmov == 1) |
Jeff Dike | 9226b83 | 2008-02-04 22:30:40 -0800 | [diff] [blame] | 71 | printk(UM_KERN_ERR "SIGILL caused by cmov, which this " |
| 72 | "processor claims to implement"); |
| 73 | else |
| 74 | printk(UM_KERN_ERR "Bad value for host_has_cmov (%d)", |
| 75 | host_has_cmov); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | } |