blob: 33daff4dade46cf32ffa1163190cdf8fe5c77f30 [file] [log] [blame]
Jeff Dikea5ed1ff2007-05-06 14:50:58 -07001/*
Jeff Dikeba180fd2007-10-16 01:27:00 -07002 * Copyright (C) 2002 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 * Licensed under the GPL
4 */
5
Jeff Dikeba180fd2007-10-16 01:27:00 -07006#include <signal.h>
Al Viro37185b32012-10-08 03:27:32 +01007#include <kern_util.h>
8#include <longjmp.h>
9#include <sysdep/ptrace.h>
Al Viro5ade8872011-08-18 20:07:39 +010010#include <generated/asm-offsets.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070011
Linus Torvalds1da177e2005-04-16 15:20:36 -070012/* Set during early boot */
WANG Cong99764fa2008-07-23 21:28:49 -070013static int host_has_cmov = 1;
Karol Swietlicki235a6f02008-02-04 22:30:38 -080014static jmp_buf cmov_test_return;
15
16static void cmov_sigill_test_handler(int sig)
17{
18 host_has_cmov = 0;
19 longjmp(cmov_test_return, 1);
20}
21
Jeff Dike9226b832008-02-04 22:30:40 -080022void arch_check_bugs(void)
Karol Swietlicki235a6f02008-02-04 22:30:38 -080023{
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}
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
Jeff Dike9226b832008-02-04 22:30:40 -080044void arch_examine_signal(int sig, struct uml_pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -070045{
46 unsigned char tmp[2];
47
Jeff Dikeba180fd2007-10-16 01:27:00 -070048 /*
49 * This is testing for a cmov (0x0f 0x4x) instruction causing a
Linus Torvalds1da177e2005-04-16 15:20:36 -070050 * SIGILL in init.
51 */
Al Viroc2220b22012-01-30 16:30:48 -050052 if ((sig != SIGILL) || (get_current_pid() != 1))
Jeff Dike9226b832008-02-04 22:30:40 -080053 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
Jeff Dike9226b832008-02-04 22:30:40 -080055 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 }
60
Jeff Dikeba180fd2007-10-16 01:27:00 -070061 if ((tmp[0] != 0x0f) || ((tmp[1] & 0xf0) != 0x40))
Jeff Dike9226b832008-02-04 22:30:40 -080062 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -070063
Jeff Dikeba180fd2007-10-16 01:27:00 -070064 if (host_has_cmov == 0)
Jeff Dike9226b832008-02-04 22:30:40 -080065 printk(UM_KERN_ERR "SIGILL caused by cmov, which this "
66 "processor doesn't implement. Boot a filesystem "
67 "compiled for older processors");
Jeff Dikeba180fd2007-10-16 01:27:00 -070068 else if (host_has_cmov == 1)
Jeff Dike9226b832008-02-04 22:30:40 -080069 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -070074}