2 * Copyright (C) 2002 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
3 * Licensed under the GPL
9 #include "kern_constants.h"
16 /* Set during early boot */
17 int host_has_cmov = 1;
20 static char token(int fd, char *buf, int len, char stop)
28 n = os_read_file(fd, ptr, sizeof(*ptr));
30 if (n != sizeof(*ptr)) {
33 printk(UM_KERN_ERR "Reading /proc/cpuinfo failed, "
39 } while ((c != '\n') && (c != stop) && (ptr < end));
42 printk(UM_KERN_ERR "Failed to find '%c' in /proc/cpuinfo\n",
50 static int find_cpuinfo_line(int fd, char *key, char *scratch, int len)
55 scratch[len - 1] = '\0';
57 c = token(fd, scratch, len - 1, ':');
61 printk(UM_KERN_ERR "Failed to find ':' in "
66 if (!strncmp(scratch, key, strlen(key)))
70 n = os_read_file(fd, &c, sizeof(c));
72 printk(UM_KERN_ERR "Failed to find newline in "
73 "/proc/cpuinfo, err = %d\n", -n);
81 static int check_cpu_flag(char *feature, int *have_it)
83 char buf[MAXTOKEN], c;
84 int fd, len = ARRAY_SIZE(buf);
86 printk(UM_KERN_INFO "Checking for host processor %s support...",
88 fd = os_open_file("/proc/cpuinfo", of_read(OPENFLAGS()), 0);
90 printk(UM_KERN_ERR "Couldn't open /proc/cpuinfo, err = %d\n",
96 if (!find_cpuinfo_line(fd, "flags", buf, ARRAY_SIZE(buf)))
99 c = token(fd, buf, len - 1, ' ');
103 printk(UM_KERN_ERR "Failed to find ' ' in /proc/cpuinfo\n");
108 c = token(fd, buf, len - 1, ' ');
114 if (!strcmp(buf, feature)) {
122 else if (*have_it == 1)
129 * This doesn't work in tt mode, plus it's causing compilation problems
132 static void disable_lcall(void)
134 struct modify_ldt_ldt_s ldt;
137 bzero(&ldt, sizeof(ldt));
138 ldt.entry_number = 7;
141 err = modify_ldt(1, &ldt, sizeof(ldt));
143 printk(UM_KERN_ERR "Failed to disable lcall7 - errno = %d\n",
148 void arch_init_thread(void)
155 void arch_check_bugs(void)
159 if (os_access("/proc/cpuinfo", OS_ACC_R_OK) < 0) {
160 printk(UM_KERN_ERR "/proc/cpuinfo not available - skipping CPU "
161 "capability checks\n");
164 if (check_cpu_flag("cmov", &have_it))
165 host_has_cmov = have_it;
166 if (check_cpu_flag("xmm", &have_it))
167 host_has_xmm = have_it;
170 int arch_handle_signal(int sig, struct uml_pt_regs *regs)
172 unsigned char tmp[2];
175 * This is testing for a cmov (0x0f 0x4x) instruction causing a
178 if ((sig != SIGILL) || (TASK_PID(get_current()) != 1))
181 if (copy_from_user_proc(tmp, (void *) UPT_IP(regs), 2))
182 panic("SIGILL in init, could not read instructions!\n");
183 if ((tmp[0] != 0x0f) || ((tmp[1] & 0xf0) != 0x40))
186 if (host_has_cmov == 0)
187 panic("SIGILL caused by cmov, which this processor doesn't "
188 "implement, boot a filesystem compiled for older "
190 else if (host_has_cmov == 1)
191 panic("SIGILL caused by cmov, which this processor claims to "
193 else if (host_has_cmov == -1)
194 panic("SIGILL caused by cmov, couldn't tell if this processor "
195 "implements it, boot a filesystem compiled for older "
197 else panic("Bad value for host_has_cmov (%d)", host_has_cmov);