cpu.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. if (msg_strs[0] < i ||
  52. (msg_strs[0] == i && msg_strs[1] < j)) {
  53. /* Skip to the next string */
  54. msg_strs += 2;
  55. while (*msg_strs++)
  56. ;
  57. }
  58. if (e & 1) {
  59. if (msg_strs[0] == i &&
  60. msg_strs[1] == j &&
  61. msg_strs[2])
  62. printf("%s ", msg_strs+2);
  63. else
  64. printf("%d:%d ", i, j);
  65. }
  66. e >>= 1;
  67. }
  68. }
  69. putchar('\n');
  70. return -1;
  71. } else {
  72. return 0;
  73. }
  74. }