blob: 6ec6bb6e9957a0319259f966c0ac7b2ca4ff69a0 [file] [log] [blame]
H. Peter Anvin31b54f42007-07-11 12:18:47 -07001/* -*- linux-c -*- ------------------------------------------------------- *
2 *
3 * Copyright (C) 1991, 1992 Linus Torvalds
H. Peter Anvinf0be6c62008-02-04 16:48:00 +01004 * Copyright 2007-2008 rPath, Inc. - All Rights Reserved
H. Peter Anvin31b54f42007-07-11 12:18:47 -07005 *
6 * This file is part of the Linux kernel, and is made available under
7 * the terms of the GNU General Public License version 2.
8 *
9 * ----------------------------------------------------------------------- */
10
11/*
H. Peter Anvinf0be6c62008-02-04 16:48:00 +010012 * arch/x86/boot/cpu.c
H. Peter Anvin31b54f42007-07-11 12:18:47 -070013 *
14 * Check for obligatory CPU features and abort if the features are not
15 * present.
16 */
17
18#include "boot.h"
H. Peter Anvinf0be6c62008-02-04 16:48:00 +010019#include "cpustr.h"
20
H. Peter Anvin31b54f42007-07-11 12:18:47 -070021static char *cpu_name(int level)
22{
23 static char buf[6];
24
25 if (level == 64) {
26 return "x86-64";
27 } else {
Dave Jonesc7d624d2008-05-28 12:57:13 -040028 if (level == 15)
29 level = 6;
H. Peter Anvin31b54f42007-07-11 12:18:47 -070030 sprintf(buf, "i%d86", level);
31 return buf;
32 }
33}
34
35int validate_cpu(void)
36{
37 u32 *err_flags;
38 int cpu_level, req_level;
H. Peter Anvinf0be6c62008-02-04 16:48:00 +010039 const unsigned char *msg_strs;
H. Peter Anvin31b54f42007-07-11 12:18:47 -070040
41 check_cpu(&cpu_level, &req_level, &err_flags);
42
43 if (cpu_level < req_level) {
44 printf("This kernel requires an %s CPU, ",
45 cpu_name(req_level));
46 printf("but only detected an %s CPU.\n",
47 cpu_name(cpu_level));
48 return -1;
49 }
50
51 if (err_flags) {
52 int i, j;
53 puts("This kernel requires the following features "
54 "not present on the CPU:\n");
55
H. Peter Anvinf0be6c62008-02-04 16:48:00 +010056 msg_strs = (const unsigned char *)x86_cap_strs;
57
H. Peter Anvin31b54f42007-07-11 12:18:47 -070058 for (i = 0; i < NCAPINTS; i++) {
59 u32 e = err_flags[i];
60
61 for (j = 0; j < 32; j++) {
H. Peter Anvin97fc0552008-09-16 15:09:26 -070062 if (msg_strs[0] < i ||
63 (msg_strs[0] == i && msg_strs[1] < j)) {
H. Peter Anvinf0be6c62008-02-04 16:48:00 +010064 /* Skip to the next string */
H. Peter Anvin97fc0552008-09-16 15:09:26 -070065 msg_strs += 2;
66 while (*msg_strs++)
67 ;
H. Peter Anvinf0be6c62008-02-04 16:48:00 +010068 }
69 if (e & 1) {
H. Peter Anvin97fc0552008-09-16 15:09:26 -070070 if (msg_strs[0] == i &&
71 msg_strs[1] == j &&
72 msg_strs[2])
73 printf("%s ", msg_strs+2);
H. Peter Anvinf0be6c62008-02-04 16:48:00 +010074 else
75 printf("%d:%d ", i, j);
76 }
H. Peter Anvin31b54f42007-07-11 12:18:47 -070077 e >>= 1;
78 }
79 }
80 putchar('\n');
81 return -1;
82 } else {
83 return 0;
84 }
85}