Blame view

arch/x86/boot/cpu.c 1.74 KB
31b54f40e   H. Peter Anvin   CPU features veri...
1
2
3
  /* -*- linux-c -*- ------------------------------------------------------- *
   *
   *   Copyright (C) 1991, 1992 Linus Torvalds
f0be6c6a6   H. Peter Anvin   x86 setup: print ...
4
   *   Copyright 2007-2008 rPath, Inc. - All Rights Reserved
31b54f40e   H. Peter Anvin   CPU features veri...
5
6
7
8
9
10
11
   *
   *   This file is part of the Linux kernel, and is made available under
   *   the terms of the GNU General Public License version 2.
   *
   * ----------------------------------------------------------------------- */
  
  /*
f0be6c6a6   H. Peter Anvin   x86 setup: print ...
12
   * arch/x86/boot/cpu.c
31b54f40e   H. Peter Anvin   CPU features veri...
13
14
15
16
17
18
   *
   * Check for obligatory CPU features and abort if the features are not
   * present.
   */
  
  #include "boot.h"
f0be6c6a6   H. Peter Anvin   x86 setup: print ...
19
  #include "cpustr.h"
31b54f40e   H. Peter Anvin   CPU features veri...
20
21
22
23
24
25
26
  static char *cpu_name(int level)
  {
  	static char buf[6];
  
  	if (level == 64) {
  		return "x86-64";
  	} else {
c7d624d1e   Dave Jones   x86: Fix up silly...
27
28
  		if (level == 15)
  			level = 6;
31b54f40e   H. Peter Anvin   CPU features veri...
29
30
31
32
33
34
35
36
37
  		sprintf(buf, "i%d86", level);
  		return buf;
  	}
  }
  
  int validate_cpu(void)
  {
  	u32 *err_flags;
  	int cpu_level, req_level;
f0be6c6a6   H. Peter Anvin   x86 setup: print ...
38
  	const unsigned char *msg_strs;
31b54f40e   H. Peter Anvin   CPU features veri...
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
  
  	check_cpu(&cpu_level, &req_level, &err_flags);
  
  	if (cpu_level < req_level) {
  		printf("This kernel requires an %s CPU, ",
  		       cpu_name(req_level));
  		printf("but only detected an %s CPU.
  ",
  		       cpu_name(cpu_level));
  		return -1;
  	}
  
  	if (err_flags) {
  		int i, j;
  		puts("This kernel requires the following features "
  		     "not present on the CPU:
  ");
f0be6c6a6   H. Peter Anvin   x86 setup: print ...
56
  		msg_strs = (const unsigned char *)x86_cap_strs;
31b54f40e   H. Peter Anvin   CPU features veri...
57
58
59
60
  		for (i = 0; i < NCAPINTS; i++) {
  			u32 e = err_flags[i];
  
  			for (j = 0; j < 32; j++) {
97fc0555d   H. Peter Anvin   x86 setup: handle...
61
62
  				if (msg_strs[0] < i ||
  				    (msg_strs[0] == i && msg_strs[1] < j)) {
f0be6c6a6   H. Peter Anvin   x86 setup: print ...
63
  					/* Skip to the next string */
97fc0555d   H. Peter Anvin   x86 setup: handle...
64
65
66
  					msg_strs += 2;
  					while (*msg_strs++)
  						;
f0be6c6a6   H. Peter Anvin   x86 setup: print ...
67
68
  				}
  				if (e & 1) {
97fc0555d   H. Peter Anvin   x86 setup: handle...
69
70
71
72
  					if (msg_strs[0] == i &&
  					    msg_strs[1] == j &&
  					    msg_strs[2])
  						printf("%s ", msg_strs+2);
f0be6c6a6   H. Peter Anvin   x86 setup: print ...
73
74
75
  					else
  						printf("%d:%d ", i, j);
  				}
31b54f40e   H. Peter Anvin   CPU features veri...
76
77
78
79
80
81
82
83
84
85
  				e >>= 1;
  			}
  		}
  		putchar('
  ');
  		return -1;
  	} else {
  		return 0;
  	}
  }