bugs.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. * Copyright 2003 PathScale, Inc.
  3. *
  4. * Licensed under the GPL
  5. */
  6. #include "linux/sched.h"
  7. #include "linux/errno.h"
  8. #include "asm/system.h"
  9. #include "asm/pda.h"
  10. #include "sysdep/ptrace.h"
  11. #include "os.h"
  12. void arch_init_thread(void)
  13. {
  14. }
  15. void arch_check_bugs(void)
  16. {
  17. }
  18. int arch_handle_signal(int sig, union uml_pt_regs *regs)
  19. {
  20. return(0);
  21. }
  22. #define MAXTOKEN 64
  23. /* Set during early boot */
  24. int host_has_cmov = 1;
  25. int host_has_xmm = 0;
  26. static char token(int fd, char *buf, int len, char stop)
  27. {
  28. int n;
  29. char *ptr, *end, c;
  30. ptr = buf;
  31. end = &buf[len];
  32. do {
  33. n = os_read_file(fd, ptr, sizeof(*ptr));
  34. c = *ptr++;
  35. if(n != sizeof(*ptr)){
  36. if(n == 0) return(0);
  37. printk("Reading /proc/cpuinfo failed, err = %d\n", -n);
  38. if(n < 0)
  39. return(n);
  40. else
  41. return(-EIO);
  42. }
  43. } while((c != '\n') && (c != stop) && (ptr < end));
  44. if(ptr == end){
  45. printk("Failed to find '%c' in /proc/cpuinfo\n", stop);
  46. return(-1);
  47. }
  48. *(ptr - 1) = '\0';
  49. return(c);
  50. }
  51. static int find_cpuinfo_line(int fd, char *key, char *scratch, int len)
  52. {
  53. int n;
  54. char c;
  55. scratch[len - 1] = '\0';
  56. while(1){
  57. c = token(fd, scratch, len - 1, ':');
  58. if(c <= 0)
  59. return(0);
  60. else if(c != ':'){
  61. printk("Failed to find ':' in /proc/cpuinfo\n");
  62. return(0);
  63. }
  64. if(!strncmp(scratch, key, strlen(key)))
  65. return(1);
  66. do {
  67. n = os_read_file(fd, &c, sizeof(c));
  68. if(n != sizeof(c)){
  69. printk("Failed to find newline in "
  70. "/proc/cpuinfo, err = %d\n", -n);
  71. return(0);
  72. }
  73. } while(c != '\n');
  74. }
  75. return(0);
  76. }
  77. int cpu_feature(char *what, char *buf, int len)
  78. {
  79. int fd, ret = 0;
  80. fd = os_open_file("/proc/cpuinfo", of_read(OPENFLAGS()), 0);
  81. if(fd < 0){
  82. printk("Couldn't open /proc/cpuinfo, err = %d\n", -fd);
  83. return(0);
  84. }
  85. if(!find_cpuinfo_line(fd, what, buf, len)){
  86. printk("Couldn't find '%s' line in /proc/cpuinfo\n", what);
  87. goto out_close;
  88. }
  89. token(fd, buf, len, '\n');
  90. ret = 1;
  91. out_close:
  92. os_close_file(fd);
  93. return(ret);
  94. }
  95. /* Overrides for Emacs so that we follow Linus's tabbing style.
  96. * Emacs will notice this stuff at the end of the file and automatically
  97. * adjust the settings for this buffer only. This must remain at the end
  98. * of the file.
  99. * ---------------------------------------------------------------------------
  100. * Local variables:
  101. * c-file-style: "linux"
  102. * End:
  103. */