2 * Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
3 * Licensed under the GPL
9 #include <sys/signal.h>
11 #include "kern_util.h"
13 #include "sysdep/ptrace.h"
19 /* Set during early boot */
20 int host_has_cmov = 1;
23 static char token(int fd, char *buf, int len, char stop)
31 n = os_read_file(fd, ptr, sizeof(*ptr));
33 if(n != sizeof(*ptr)){
36 printk("Reading /proc/cpuinfo failed, err = %d\n", -n);
41 } while((c != '\n') && (c != stop) && (ptr < end));
44 printk("Failed to find '%c' in /proc/cpuinfo\n", stop);
51 static int find_cpuinfo_line(int fd, char *key, char *scratch, int len)
56 scratch[len - 1] = '\0';
58 c = token(fd, scratch, len - 1, ':');
62 printk("Failed to find ':' in /proc/cpuinfo\n");
66 if(!strncmp(scratch, key, strlen(key)))
70 n = os_read_file(fd, &c, sizeof(c));
72 printk("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("Checking for host processor %s support...", feature);
87 fd = os_open_file("/proc/cpuinfo", of_read(OPENFLAGS()), 0);
89 printk("Couldn't open /proc/cpuinfo, err = %d\n", -fd);
94 if(!find_cpuinfo_line(fd, "flags", buf, ARRAY_SIZE(buf)))
97 c = token(fd, buf, len - 1, ' ');
101 printk("Failed to find ' ' in /proc/cpuinfo\n");
106 c = token(fd, buf, len - 1, ' ');
109 else if(c == '\n') break;
111 if(!strcmp(buf, feature)){
119 else if(*have_it == 1)
125 #if 0 /* This doesn't work in tt mode, plus it's causing compilation problems
128 static void disable_lcall(void)
130 struct modify_ldt_ldt_s ldt;
133 bzero(&ldt, sizeof(ldt));
134 ldt.entry_number = 7;
137 err = modify_ldt(1, &ldt, sizeof(ldt));
139 printk("Failed to disable lcall7 - errno = %d\n", errno);
143 void arch_init_thread(void)
150 void arch_check_bugs(void)
154 if(os_access("/proc/cpuinfo", OS_ACC_R_OK) < 0){
155 printk("/proc/cpuinfo not available - skipping CPU capability "
159 if(check_cpu_flag("cmov", &have_it))
160 host_has_cmov = have_it;
161 if(check_cpu_flag("xmm", &have_it))
162 host_has_xmm = have_it;
165 int arch_handle_signal(int sig, union uml_pt_regs *regs)
167 unsigned char tmp[2];
169 /* This is testing for a cmov (0x0f 0x4x) instruction causing a
172 if((sig != SIGILL) || (TASK_PID(get_current()) != 1))
175 if (copy_from_user_proc(tmp, (void *) UPT_IP(regs), 2))
176 panic("SIGILL in init, could not read instructions!\n");
177 if((tmp[0] != 0x0f) || ((tmp[1] & 0xf0) != 0x40))
180 if(host_has_cmov == 0)
181 panic("SIGILL caused by cmov, which this processor doesn't "
182 "implement, boot a filesystem compiled for older "
184 else if(host_has_cmov == 1)
185 panic("SIGILL caused by cmov, which this processor claims to "
187 else if(host_has_cmov == -1)
188 panic("SIGILL caused by cmov, couldn't tell if this processor "
189 "implements it, boot a filesystem compiled for older "
191 else panic("Bad value for host_has_cmov (%d)", host_has_cmov);