2007-05-06 15:50:58 -06:00
|
|
|
/*
|
2007-10-16 02:27:00 -06:00
|
|
|
* Copyright (C) 2002 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
|
2005-04-16 16:20:36 -06:00
|
|
|
* Licensed under the GPL
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <errno.h>
|
2007-10-16 02:27:00 -06:00
|
|
|
#include <signal.h>
|
2005-04-16 16:20:36 -06:00
|
|
|
#include <string.h>
|
2007-10-16 02:27:00 -06:00
|
|
|
#include "kern_constants.h"
|
2005-04-16 16:20:36 -06:00
|
|
|
#include "os.h"
|
2007-10-16 02:27:00 -06:00
|
|
|
#include "task.h"
|
|
|
|
#include "user.h"
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
#define MAXTOKEN 64
|
|
|
|
|
|
|
|
/* Set during early boot */
|
|
|
|
int host_has_cmov = 1;
|
|
|
|
int host_has_xmm = 0;
|
|
|
|
|
|
|
|
static char token(int fd, char *buf, int len, char stop)
|
|
|
|
{
|
|
|
|
int n;
|
|
|
|
char *ptr, *end, c;
|
|
|
|
|
|
|
|
ptr = buf;
|
|
|
|
end = &buf[len];
|
|
|
|
do {
|
2007-05-06 15:51:43 -06:00
|
|
|
n = os_read_file(fd, ptr, sizeof(*ptr));
|
2005-04-16 16:20:36 -06:00
|
|
|
c = *ptr++;
|
2007-10-16 02:27:00 -06:00
|
|
|
if (n != sizeof(*ptr)) {
|
|
|
|
if (n == 0)
|
2007-05-06 15:50:58 -06:00
|
|
|
return 0;
|
2007-10-16 02:27:00 -06:00
|
|
|
printk(UM_KERN_ERR "Reading /proc/cpuinfo failed, "
|
|
|
|
"err = %d\n", -n);
|
|
|
|
if (n < 0)
|
2007-05-06 15:50:58 -06:00
|
|
|
return n;
|
|
|
|
else return -EIO;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
2007-10-16 02:27:00 -06:00
|
|
|
} while ((c != '\n') && (c != stop) && (ptr < end));
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2007-10-16 02:27:00 -06:00
|
|
|
if (ptr == end) {
|
|
|
|
printk(UM_KERN_ERR "Failed to find '%c' in /proc/cpuinfo\n",
|
|
|
|
stop);
|
2007-05-06 15:50:58 -06:00
|
|
|
return -1;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
*(ptr - 1) = '\0';
|
2007-05-06 15:50:58 -06:00
|
|
|
return c;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static int find_cpuinfo_line(int fd, char *key, char *scratch, int len)
|
|
|
|
{
|
|
|
|
int n;
|
|
|
|
char c;
|
|
|
|
|
|
|
|
scratch[len - 1] = '\0';
|
2007-10-16 02:27:00 -06:00
|
|
|
while (1) {
|
2005-04-16 16:20:36 -06:00
|
|
|
c = token(fd, scratch, len - 1, ':');
|
2007-10-16 02:27:00 -06:00
|
|
|
if (c <= 0)
|
2007-05-06 15:50:58 -06:00
|
|
|
return 0;
|
2007-10-16 02:27:00 -06:00
|
|
|
else if (c != ':') {
|
|
|
|
printk(UM_KERN_ERR "Failed to find ':' in "
|
|
|
|
"/proc/cpuinfo\n");
|
2007-05-06 15:50:58 -06:00
|
|
|
return 0;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2007-10-16 02:27:00 -06:00
|
|
|
if (!strncmp(scratch, key, strlen(key)))
|
2007-05-06 15:50:58 -06:00
|
|
|
return 1;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
do {
|
2007-05-06 15:51:43 -06:00
|
|
|
n = os_read_file(fd, &c, sizeof(c));
|
2007-10-16 02:27:00 -06:00
|
|
|
if (n != sizeof(c)) {
|
|
|
|
printk(UM_KERN_ERR "Failed to find newline in "
|
2005-04-16 16:20:36 -06:00
|
|
|
"/proc/cpuinfo, err = %d\n", -n);
|
2007-05-06 15:50:58 -06:00
|
|
|
return 0;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
2007-10-16 02:27:00 -06:00
|
|
|
} while (c != '\n');
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
2007-05-06 15:50:58 -06:00
|
|
|
return 0;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static int check_cpu_flag(char *feature, int *have_it)
|
|
|
|
{
|
|
|
|
char buf[MAXTOKEN], c;
|
2006-09-26 00:33:00 -06:00
|
|
|
int fd, len = ARRAY_SIZE(buf);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2007-10-16 02:27:00 -06:00
|
|
|
printk(UM_KERN_INFO "Checking for host processor %s support...",
|
|
|
|
feature);
|
2005-04-16 16:20:36 -06:00
|
|
|
fd = os_open_file("/proc/cpuinfo", of_read(OPENFLAGS()), 0);
|
2007-10-16 02:27:00 -06:00
|
|
|
if (fd < 0) {
|
|
|
|
printk(UM_KERN_ERR "Couldn't open /proc/cpuinfo, err = %d\n",
|
|
|
|
-fd);
|
2006-09-26 00:33:00 -06:00
|
|
|
return 0;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
*have_it = 0;
|
2007-10-16 02:27:00 -06:00
|
|
|
if (!find_cpuinfo_line(fd, "flags", buf, ARRAY_SIZE(buf)))
|
2005-04-16 16:20:36 -06:00
|
|
|
goto out;
|
|
|
|
|
|
|
|
c = token(fd, buf, len - 1, ' ');
|
2007-10-16 02:27:00 -06:00
|
|
|
if (c < 0)
|
2007-05-06 15:50:58 -06:00
|
|
|
goto out;
|
2007-10-16 02:27:00 -06:00
|
|
|
else if (c != ' ') {
|
|
|
|
printk(UM_KERN_ERR "Failed to find ' ' in /proc/cpuinfo\n");
|
2005-04-16 16:20:36 -06:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2007-10-16 02:27:00 -06:00
|
|
|
while (1) {
|
2005-04-16 16:20:36 -06:00
|
|
|
c = token(fd, buf, len - 1, ' ');
|
2007-10-16 02:27:00 -06:00
|
|
|
if (c < 0)
|
2007-05-06 15:50:58 -06:00
|
|
|
goto out;
|
2007-10-16 02:27:00 -06:00
|
|
|
else if (c == '\n')
|
|
|
|
break;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2007-10-16 02:27:00 -06:00
|
|
|
if (!strcmp(buf, feature)) {
|
2005-04-16 16:20:36 -06:00
|
|
|
*have_it = 1;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
out:
|
2007-10-16 02:27:00 -06:00
|
|
|
if (*have_it == 0)
|
2007-05-06 15:50:58 -06:00
|
|
|
printk("No\n");
|
2007-10-16 02:27:00 -06:00
|
|
|
else if (*have_it == 1)
|
2007-05-06 15:50:58 -06:00
|
|
|
printk("Yes\n");
|
2005-04-16 16:20:36 -06:00
|
|
|
os_close_file(fd);
|
2006-09-26 00:33:00 -06:00
|
|
|
return 1;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2007-10-16 02:27:00 -06:00
|
|
|
#if 0 /*
|
|
|
|
* This doesn't work in tt mode, plus it's causing compilation problems
|
2005-04-16 16:20:36 -06:00
|
|
|
* for some people.
|
|
|
|
*/
|
|
|
|
static void disable_lcall(void)
|
|
|
|
{
|
|
|
|
struct modify_ldt_ldt_s ldt;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
bzero(&ldt, sizeof(ldt));
|
|
|
|
ldt.entry_number = 7;
|
|
|
|
ldt.base_addr = 0;
|
|
|
|
ldt.limit = 0;
|
|
|
|
err = modify_ldt(1, &ldt, sizeof(ldt));
|
2007-10-16 02:27:00 -06:00
|
|
|
if (err)
|
|
|
|
printk(UM_KERN_ERR "Failed to disable lcall7 - errno = %d\n",
|
|
|
|
errno);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void arch_init_thread(void)
|
|
|
|
{
|
|
|
|
#if 0
|
|
|
|
disable_lcall();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void arch_check_bugs(void)
|
|
|
|
{
|
|
|
|
int have_it;
|
|
|
|
|
2007-10-16 02:27:00 -06:00
|
|
|
if (os_access("/proc/cpuinfo", OS_ACC_R_OK) < 0) {
|
|
|
|
printk(UM_KERN_ERR "/proc/cpuinfo not available - skipping CPU "
|
|
|
|
"capability checks\n");
|
2005-04-16 16:20:36 -06:00
|
|
|
return;
|
|
|
|
}
|
2007-10-16 02:27:00 -06:00
|
|
|
if (check_cpu_flag("cmov", &have_it))
|
2005-04-16 16:20:36 -06:00
|
|
|
host_has_cmov = have_it;
|
2007-10-16 02:27:00 -06:00
|
|
|
if (check_cpu_flag("xmm", &have_it))
|
2005-04-16 16:20:36 -06:00
|
|
|
host_has_xmm = have_it;
|
|
|
|
}
|
|
|
|
|
2007-10-16 02:26:58 -06:00
|
|
|
int arch_handle_signal(int sig, struct uml_pt_regs *regs)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
|
|
|
unsigned char tmp[2];
|
|
|
|
|
2007-10-16 02:27:00 -06:00
|
|
|
/*
|
|
|
|
* This is testing for a cmov (0x0f 0x4x) instruction causing a
|
2005-04-16 16:20:36 -06:00
|
|
|
* SIGILL in init.
|
|
|
|
*/
|
2007-10-16 02:27:00 -06:00
|
|
|
if ((sig != SIGILL) || (TASK_PID(get_current()) != 1))
|
2007-05-06 15:50:58 -06:00
|
|
|
return 0;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
if (copy_from_user_proc(tmp, (void *) UPT_IP(regs), 2))
|
|
|
|
panic("SIGILL in init, could not read instructions!\n");
|
2007-10-16 02:27:00 -06:00
|
|
|
if ((tmp[0] != 0x0f) || ((tmp[1] & 0xf0) != 0x40))
|
2007-05-06 15:50:58 -06:00
|
|
|
return 0;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2007-10-16 02:27:00 -06:00
|
|
|
if (host_has_cmov == 0)
|
2005-04-16 16:20:36 -06:00
|
|
|
panic("SIGILL caused by cmov, which this processor doesn't "
|
|
|
|
"implement, boot a filesystem compiled for older "
|
|
|
|
"processors");
|
2007-10-16 02:27:00 -06:00
|
|
|
else if (host_has_cmov == 1)
|
2005-04-16 16:20:36 -06:00
|
|
|
panic("SIGILL caused by cmov, which this processor claims to "
|
|
|
|
"implement");
|
2007-10-16 02:27:00 -06:00
|
|
|
else if (host_has_cmov == -1)
|
2005-04-16 16:20:36 -06:00
|
|
|
panic("SIGILL caused by cmov, couldn't tell if this processor "
|
|
|
|
"implements it, boot a filesystem compiled for older "
|
|
|
|
"processors");
|
|
|
|
else panic("Bad value for host_has_cmov (%d)", host_has_cmov);
|
2007-05-06 15:50:58 -06:00
|
|
|
return 0;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|