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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | #include <errno.h> |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 7 | #include <signal.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | #include <string.h> |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 9 | #include "kern_constants.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | #include "os.h" |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 11 | #include "task.h" |
| 12 | #include "user.h" |
Karol Swietlicki | 235a6f0 | 2008-02-04 22:30:38 -0800 | [diff] [blame] | 13 | #include "sysdep/archsetjmp.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | /* Set during early boot */ |
| 16 | int host_has_cmov = 1; |
Karol Swietlicki | 235a6f0 | 2008-02-04 22:30:38 -0800 | [diff] [blame] | 17 | static jmp_buf cmov_test_return; |
| 18 | |
| 19 | static void cmov_sigill_test_handler(int sig) |
| 20 | { |
| 21 | host_has_cmov = 0; |
| 22 | longjmp(cmov_test_return, 1); |
| 23 | } |
| 24 | |
| 25 | static void test_for_host_cmov(void) |
| 26 | { |
| 27 | struct sigaction old, new; |
| 28 | |
| 29 | printk(UM_KERN_INFO "Checking for host processor cmov support..."); |
| 30 | new.sa_handler = cmov_sigill_test_handler; |
| 31 | |
| 32 | /* Make sure that SIGILL is enabled after the handler longjmps back */ |
| 33 | new.sa_flags = SA_NODEFER; |
| 34 | sigemptyset(&new.sa_mask); |
| 35 | sigaction(SIGILL, &new, &old); |
| 36 | |
| 37 | if (setjmp(cmov_test_return) == 0) { |
| 38 | unsigned long foo = 0; |
| 39 | __asm__ __volatile__("cmovz %0, %1" : "=r" (foo) : "0" (foo)); |
| 40 | printk(UM_KERN_CONT "Yes\n"); |
| 41 | } else |
| 42 | printk(UM_KERN_CONT "No\n"); |
| 43 | |
| 44 | sigaction(SIGILL, &old, &new); |
| 45 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | void arch_init_thread(void) |
| 48 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | void arch_check_bugs(void) |
| 52 | { |
Karol Swietlicki | 235a6f0 | 2008-02-04 22:30:38 -0800 | [diff] [blame] | 53 | test_for_host_cmov(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | } |
| 55 | |
Jeff Dike | 77bf440 | 2007-10-16 01:26:58 -0700 | [diff] [blame] | 56 | int arch_handle_signal(int sig, struct uml_pt_regs *regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | { |
| 58 | unsigned char tmp[2]; |
| 59 | |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 60 | /* |
| 61 | * This is testing for a cmov (0x0f 0x4x) instruction causing a |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | * SIGILL in init. |
| 63 | */ |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 64 | if ((sig != SIGILL) || (TASK_PID(get_current()) != 1)) |
Jeff Dike | a5ed1ff | 2007-05-06 14:50:58 -0700 | [diff] [blame] | 65 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | |
| 67 | if (copy_from_user_proc(tmp, (void *) UPT_IP(regs), 2)) |
| 68 | panic("SIGILL in init, could not read instructions!\n"); |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 69 | if ((tmp[0] != 0x0f) || ((tmp[1] & 0xf0) != 0x40)) |
Jeff Dike | a5ed1ff | 2007-05-06 14:50:58 -0700 | [diff] [blame] | 70 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 72 | if (host_has_cmov == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | panic("SIGILL caused by cmov, which this processor doesn't " |
| 74 | "implement, boot a filesystem compiled for older " |
| 75 | "processors"); |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 76 | else if (host_has_cmov == 1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | panic("SIGILL caused by cmov, which this processor claims to " |
| 78 | "implement"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | else panic("Bad value for host_has_cmov (%d)", host_has_cmov); |
Jeff Dike | a5ed1ff | 2007-05-06 14:50:58 -0700 | [diff] [blame] | 80 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | } |