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"
16 #include "user_util.h"
20 /* Set during early boot */
21 int host_has_cmov = 1;
24 static char token(int fd, char *buf, int len, char stop)
32 n = os_read_file(fd, ptr, sizeof(*ptr));
34 if(n != sizeof(*ptr)){
37 printk("Reading /proc/cpuinfo failed, err = %d\n", -n);
42 } while((c != '\n') && (c != stop) && (ptr < end));
45 printk("Failed to find '%c' in /proc/cpuinfo\n", stop);
52 static int find_cpuinfo_line(int fd, char *key, char *scratch, int len)
57 scratch[len - 1] = '\0';
59 c = token(fd, scratch, len - 1, ':');
63 printk("Failed to find ':' in /proc/cpuinfo\n");
67 if(!strncmp(scratch, key, strlen(key)))
71 n = os_read_file(fd, &c, sizeof(c));
73 printk("Failed to find newline in "
74 "/proc/cpuinfo, err = %d\n", -n);
82 static int check_cpu_flag(char *feature, int *have_it)
84 char buf[MAXTOKEN], c;
85 int fd, len = ARRAY_SIZE(buf);
87 printk("Checking for host processor %s support...", feature);
88 fd = os_open_file("/proc/cpuinfo", of_read(OPENFLAGS()), 0);
90 printk("Couldn't open /proc/cpuinfo, err = %d\n", -fd);
95 if(!find_cpuinfo_line(fd, "flags", buf, ARRAY_SIZE(buf)))
98 c = token(fd, buf, len - 1, ' ');
102 printk("Failed to find ' ' in /proc/cpuinfo\n");
107 c = token(fd, buf, len - 1, ' ');
110 else if(c == '\n') break;
112 if(!strcmp(buf, feature)){
120 else if(*have_it == 1)
126 #if 0 /* This doesn't work in tt mode, plus it's causing compilation problems
129 static void disable_lcall(void)
131 struct modify_ldt_ldt_s ldt;
134 bzero(&ldt, sizeof(ldt));
135 ldt.entry_number = 7;
138 err = modify_ldt(1, &ldt, sizeof(ldt));
140 printk("Failed to disable lcall7 - errno = %d\n", errno);
144 void arch_init_thread(void)
151 void arch_check_bugs(void)
155 if(os_access("/proc/cpuinfo", OS_ACC_R_OK) < 0){
156 printk("/proc/cpuinfo not available - skipping CPU capability "
160 if(check_cpu_flag("cmov", &have_it))
161 host_has_cmov = have_it;
162 if(check_cpu_flag("xmm", &have_it))
163 host_has_xmm = have_it;
166 int arch_handle_signal(int sig, union uml_pt_regs *regs)
168 unsigned char tmp[2];
170 /* This is testing for a cmov (0x0f 0x4x) instruction causing a
173 if((sig != SIGILL) || (TASK_PID(get_current()) != 1))
176 if (copy_from_user_proc(tmp, (void *) UPT_IP(regs), 2))
177 panic("SIGILL in init, could not read instructions!\n");
178 if((tmp[0] != 0x0f) || ((tmp[1] & 0xf0) != 0x40))
181 if(host_has_cmov == 0)
182 panic("SIGILL caused by cmov, which this processor doesn't "
183 "implement, boot a filesystem compiled for older "
185 else if(host_has_cmov == 1)
186 panic("SIGILL caused by cmov, which this processor claims to "
188 else if(host_has_cmov == -1)
189 panic("SIGILL caused by cmov, couldn't tell if this processor "
190 "implements it, boot a filesystem compiled for older "
192 else panic("Bad value for host_has_cmov (%d)", host_has_cmov);