cpu.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 "cpustr.h"
  18. static char *cpu_name(int level)
  19. {
  20. static char buf[6];
  21. if (level == 64) {
  22. return "x86-64";
  23. } else {
  24. if (level == 15)
  25. level = 6;
  26. sprintf(buf, "i%d86", level);
  27. return buf;
  28. }
  29. }
  30. int validate_cpu(void)
  31. {
  32. u32 *err_flags;
  33. int cpu_level, req_level;
  34. const unsigned char *msg_strs;
  35. check_cpu(&cpu_level, &req_level, &err_flags);
  36. if (cpu_level < req_level) {
  37. printf("This kernel requires an %s CPU, ",
  38. cpu_name(req_level));
  39. printf("but only detected an %s CPU.\n",
  40. cpu_name(cpu_level));
  41. return -1;
  42. }
  43. if (err_flags) {
  44. int i, j;
  45. puts("This kernel requires the following features "
  46. "not present on the CPU:\n");
  47. msg_strs = (const unsigned char *)x86_cap_strs;
  48. for (i = 0; i < NCAPINTS; i++) {
  49. u32 e = err_flags[i];
  50. for (j = 0; j < 32; j++) {
  51. int n = (i << 5)+j;
  52. if (*msg_strs < n) {
  53. /* Skip to the next string */
  54. do {
  55. msg_strs++;
  56. } while (*msg_strs);
  57. msg_strs++;
  58. }
  59. if (e & 1) {
  60. if (*msg_strs == n && msg_strs[1])
  61. printf("%s ", msg_strs+1);
  62. else
  63. printf("%d:%d ", i, j);
  64. }
  65. e >>= 1;
  66. }
  67. }
  68. putchar('\n');
  69. return -1;
  70. } else {
  71. return 0;
  72. }
  73. }