Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 
 

109 lignes
2.9 KiB

  1. /*
  2. * libcaca Colour ASCII-Art library
  3. * Copyright (c) 2006 Sam Hocevar <sam@hocevar.net>
  4. * 2009 Jean-Yves Lamoureux <jylam@lnxscene.org>
  5. * All Rights Reserved
  6. *
  7. * This library is free software. It comes without any warranty, to
  8. * the extent permitted by applicable law. You can redistribute it
  9. * and/or modify it under the terms of the Do What the Fuck You Want
  10. * to Public License, Version 2, as published by Sam Hocevar. See
  11. * http://www.wtfpl.net/ for more details.
  12. */
  13. #include "kernel.h"
  14. #include "klibc.h"
  15. #include "drivers/timer.h"
  16. #include "processor.h"
  17. int processor_get_info(struct processor_info *processor_info)
  18. {
  19. processor_info->id = 0;
  20. /* Vendor String */
  21. int code = CPUID_GETVENDORSTRING;
  22. unsigned int where[5];
  23. char *s;
  24. asm volatile ("cpuid":"=a" (*where), "=b"(*(where + 1)),
  25. "=c"(*(where + 2)), "=d"(*(where + 3)):"0"(code));
  26. s = (char *)where;
  27. unsigned int a = 0;
  28. unsigned int b = where[1];
  29. unsigned int d = where[3];
  30. unsigned int c = where[2];
  31. where[0] = b;
  32. where[1] = d;
  33. where[2] = c;
  34. where[3] = 0;
  35. memcpy(processor_info->vendor, where, 13);
  36. /* Features */
  37. code = CPUID_GETFEATURES;
  38. asm volatile ("cpuid":"=a" (a), "=d"(d):"0"(code):"ecx", "ebx");
  39. processor_info->features = a;
  40. processor_info->frequency = 0;
  41. processor_info->frequency = processor_get_frequency(processor_info);
  42. return 0;
  43. }
  44. u32 processor_get_frequency(struct processor_info * processor_info)
  45. {
  46. if (processor_info->frequency)
  47. return processor_info->frequency;
  48. u64 srdtsc64, erdtsc64;
  49. u32 srdtsc_l, srdtsc_h;
  50. u32 erdtsc_l, erdtsc_h;
  51. rdtsc(srdtsc_l, srdtsc_h); /* Get RDTSC */
  52. sleep(2); /* Sleep for 2 seconds */
  53. rdtsc(erdtsc_l, erdtsc_h); /* Get RDTSC again */
  54. srdtsc64 = srdtsc_h;
  55. srdtsc64 <<= 32;
  56. srdtsc64 |= srdtsc_l;
  57. erdtsc64 = erdtsc_h;
  58. erdtsc64 <<= 32;
  59. erdtsc64 |= erdtsc_l;
  60. u32 diff = erdtsc64 - srdtsc64; /* Cycle count for 2 seconds */
  61. diff /= 2; /* Divide by 2 to get cycles per sec */
  62. return diff;
  63. }
  64. void processor_print_info(struct processor_info *processor_info)
  65. {
  66. printf("CPU%d\n", processor_info->id);
  67. printf("Vendor ID : %s\n", processor_info->vendor);
  68. printf("Frequency : ");
  69. if (processor_info->frequency > 1000000000)
  70. {
  71. printf("%dGhz",
  72. processor_info->frequency / 1000000000);
  73. }
  74. else if (processor_info->frequency > 1000000)
  75. {
  76. printf("%dMhz",
  77. processor_info->frequency / 1000000);
  78. }
  79. else if (processor_info->frequency > 1000)
  80. {
  81. printf("%dKhz\n",
  82. processor_info->frequency / 1000);
  83. }
  84. else
  85. {
  86. printf("%dhz\n",
  87. processor_info->frequency);
  88. }
  89. printf(" (or something like that)\n");
  90. printf("Features : 0x%x\n", processor_info->features);
  91. }