2007-05-06 23:50:58 +02:00
|
|
|
/*
|
2007-10-16 10:27:00 +02:00
|
|
|
* Copyright (C) 2002 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
|
2005-04-17 00:20:36 +02:00
|
|
|
* Licensed under the GPL
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <errno.h>
|
2007-10-16 10:27:00 +02:00
|
|
|
#include <signal.h>
|
2005-04-17 00:20:36 +02:00
|
|
|
#include <string.h>
|
2007-10-16 10:27:00 +02:00
|
|
|
#include "kern_constants.h"
|
2005-04-17 00:20:36 +02:00
|
|
|
#include "os.h"
|
2007-10-16 10:27:00 +02:00
|
|
|
#include "task.h"
|
|
|
|
#include "user.h"
|
2008-02-05 07:30:38 +01:00
|
|
|
#include "sysdep/archsetjmp.h"
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
/* Set during early boot */
|
|
|
|
int host_has_cmov = 1;
|
2008-02-05 07:30:38 +01:00
|
|
|
static jmp_buf cmov_test_return;
|
|
|
|
|
|
|
|
static void cmov_sigill_test_handler(int sig)
|
|
|
|
{
|
|
|
|
host_has_cmov = 0;
|
|
|
|
longjmp(cmov_test_return, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_for_host_cmov(void)
|
|
|
|
{
|
|
|
|
struct sigaction old, new;
|
|
|
|
|
|
|
|
printk(UM_KERN_INFO "Checking for host processor cmov support...");
|
|
|
|
new.sa_handler = cmov_sigill_test_handler;
|
|
|
|
|
|
|
|
/* Make sure that SIGILL is enabled after the handler longjmps back */
|
|
|
|
new.sa_flags = SA_NODEFER;
|
|
|
|
sigemptyset(&new.sa_mask);
|
|
|
|
sigaction(SIGILL, &new, &old);
|
|
|
|
|
|
|
|
if (setjmp(cmov_test_return) == 0) {
|
|
|
|
unsigned long foo = 0;
|
|
|
|
__asm__ __volatile__("cmovz %0, %1" : "=r" (foo) : "0" (foo));
|
|
|
|
printk(UM_KERN_CONT "Yes\n");
|
|
|
|
} else
|
|
|
|
printk(UM_KERN_CONT "No\n");
|
|
|
|
|
|
|
|
sigaction(SIGILL, &old, &new);
|
|
|
|
}
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
void arch_init_thread(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void arch_check_bugs(void)
|
|
|
|
{
|
2008-02-05 07:30:38 +01:00
|
|
|
test_for_host_cmov();
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
2007-10-16 10:26:58 +02:00
|
|
|
int arch_handle_signal(int sig, struct uml_pt_regs *regs)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
|
|
|
unsigned char tmp[2];
|
|
|
|
|
2007-10-16 10:27:00 +02:00
|
|
|
/*
|
|
|
|
* This is testing for a cmov (0x0f 0x4x) instruction causing a
|
2005-04-17 00:20:36 +02:00
|
|
|
* SIGILL in init.
|
|
|
|
*/
|
2007-10-16 10:27:00 +02:00
|
|
|
if ((sig != SIGILL) || (TASK_PID(get_current()) != 1))
|
2007-05-06 23:50:58 +02:00
|
|
|
return 0;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
if (copy_from_user_proc(tmp, (void *) UPT_IP(regs), 2))
|
|
|
|
panic("SIGILL in init, could not read instructions!\n");
|
2007-10-16 10:27:00 +02:00
|
|
|
if ((tmp[0] != 0x0f) || ((tmp[1] & 0xf0) != 0x40))
|
2007-05-06 23:50:58 +02:00
|
|
|
return 0;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2007-10-16 10:27:00 +02:00
|
|
|
if (host_has_cmov == 0)
|
2005-04-17 00:20:36 +02:00
|
|
|
panic("SIGILL caused by cmov, which this processor doesn't "
|
|
|
|
"implement, boot a filesystem compiled for older "
|
|
|
|
"processors");
|
2007-10-16 10:27:00 +02:00
|
|
|
else if (host_has_cmov == 1)
|
2005-04-17 00:20:36 +02:00
|
|
|
panic("SIGILL caused by cmov, which this processor claims to "
|
|
|
|
"implement");
|
|
|
|
else panic("Bad value for host_has_cmov (%d)", host_has_cmov);
|
2007-05-06 23:50:58 +02:00
|
|
|
return 0;
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|