cpu.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /* -*- linux-c -*- ------------------------------------------------------- *
  2. *
  3. * Copyright (C) 1991, 1992 Linus Torvalds
  4. * Copyright 2007-2008 rPath, Inc. - All Rights Reserved
  5. *
  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. * arch/x86/boot/cpu.c
  12. *
  13. * Check for obligatory CPU features and abort if the features are not
  14. * present.
  15. */
  16. #include "boot.h"
  17. #include "bitops.h"
  18. #include <asm/cpufeature.h>
  19. #include "cpustr.h"
  20. static char *cpu_name(int level)
  21. {
  22. static char buf[6];
  23. if (level == 64) {
  24. return "x86-64";
  25. } else {
  26. if (level == 15)
  27. level = 6;
  28. sprintf(buf, "i%d86", level);
  29. return buf;
  30. }
  31. }
  32. int validate_cpu(void)
  33. {
  34. u32 *err_flags;
  35. int cpu_level, req_level;
  36. const unsigned char *msg_strs;
  37. check_cpu(&cpu_level, &req_level, &err_flags);
  38. if (cpu_level < req_level) {
  39. printf("This kernel requires an %s CPU, ",
  40. cpu_name(req_level));
  41. printf("but only detected an %s CPU.\n",
  42. cpu_name(cpu_level));
  43. return -1;
  44. }
  45. if (err_flags) {
  46. int i, j;
  47. puts("This kernel requires the following features "
  48. "not present on the CPU:\n");
  49. msg_strs = (const unsigned char *)x86_cap_strs;
  50. for (i = 0; i < NCAPINTS; i++) {
  51. u32 e = err_flags[i];
  52. for (j = 0; j < 32; j++) {
  53. int n = (i << 5)+j;
  54. if (*msg_strs < n) {
  55. /* Skip to the next string */
  56. do {
  57. msg_strs++;
  58. } while (*msg_strs);
  59. msg_strs++;
  60. }
  61. if (e & 1) {
  62. if (*msg_strs == n && msg_strs[1])
  63. printf("%s ", msg_strs+1);
  64. else
  65. printf("%d:%d ", i, j);
  66. }
  67. e >>= 1;
  68. }
  69. }
  70. putchar('\n');
  71. return -1;
  72. } else {
  73. return 0;
  74. }
  75. }