OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/base/cpu.h" | 5 #include "src/base/cpu.h" |
6 | 6 |
7 #if V8_LIBC_MSVCRT | 7 #if V8_LIBC_MSVCRT |
8 #include <intrin.h> // __cpuid() | 8 #include <intrin.h> // __cpuid() |
9 #endif | 9 #endif |
10 #if V8_OS_LINUX | 10 #if V8_OS_LINUX |
11 #include <linux/auxvec.h> // AT_HWCAP | 11 #include <linux/auxvec.h> // AT_HWCAP |
12 #endif | 12 #endif |
13 #if V8_GLIBC_PREREQ(2, 16) | 13 #if V8_GLIBC_PREREQ(2, 16) |
14 #include <sys/auxv.h> // getauxval() | 14 #include <sys/auxv.h> // getauxval() |
15 #endif | 15 #endif |
16 #if V8_OS_QNX | 16 #if V8_OS_QNX |
17 #include <sys/syspage.h> // cpuinfo | 17 #include <sys/syspage.h> // cpuinfo |
18 #endif | 18 #endif |
| 19 #if V8_OS_LINUX && V8_HOST_ARCH_PPC |
| 20 #include <elf.h> |
| 21 #endif |
19 #if V8_OS_POSIX | 22 #if V8_OS_POSIX |
20 #include <unistd.h> // sysconf() | 23 #include <unistd.h> // sysconf() |
21 #endif | 24 #endif |
22 | 25 |
23 #include <ctype.h> | 26 #include <ctype.h> |
24 #include <limits.h> | 27 #include <limits.h> |
25 #include <stdio.h> | 28 #include <stdio.h> |
26 #include <stdlib.h> | 29 #include <stdlib.h> |
27 #include <string.h> | 30 #include <string.h> |
28 #include <algorithm> | 31 #include <algorithm> |
(...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
573 char* part = cpu_info.ExtractField("CPU part"); | 576 char* part = cpu_info.ExtractField("CPU part"); |
574 if (part != NULL) { | 577 if (part != NULL) { |
575 char* end; | 578 char* end; |
576 part_ = strtol(part, &end, 0); | 579 part_ = strtol(part, &end, 0); |
577 if (end == part) { | 580 if (end == part) { |
578 part_ = 0; | 581 part_ = 0; |
579 } | 582 } |
580 delete[] part; | 583 delete[] part; |
581 } | 584 } |
582 | 585 |
| 586 #elif V8_HOST_ARCH_PPC |
| 587 |
| 588 #ifndef USE_SIMULATOR |
| 589 #if V8_OS_LINUX |
| 590 // Read processor info from /proc/self/auxv. |
| 591 char* auxv_cpu_type = NULL; |
| 592 FILE* fp = fopen("/proc/self/auxv", "r"); |
| 593 if (fp != NULL) { |
| 594 #if V8_TARGET_ARCH_PPC64 |
| 595 Elf64_auxv_t entry; |
| 596 #else |
| 597 Elf32_auxv_t entry; |
583 #endif | 598 #endif |
| 599 for (;;) { |
| 600 size_t n = fread(&entry, sizeof(entry), 1, fp); |
| 601 if (n == 0 || entry.a_type == AT_NULL) { |
| 602 break; |
| 603 } |
| 604 if (entry.a_type == AT_PLATFORM) { |
| 605 auxv_cpu_type = reinterpret_cast<char*>(entry.a_un.a_val); |
| 606 break; |
| 607 } |
| 608 } |
| 609 fclose(fp); |
| 610 } |
| 611 |
| 612 part_ = -1; |
| 613 if (auxv_cpu_type) { |
| 614 if (strcmp(auxv_cpu_type, "power8") == 0) { |
| 615 part_ = PPC_POWER8; |
| 616 } else if (strcmp(auxv_cpu_type, "power7") == 0) { |
| 617 part_ = PPC_POWER7; |
| 618 } else if (strcmp(auxv_cpu_type, "power6") == 0) { |
| 619 part_ = PPC_POWER6; |
| 620 } else if (strcmp(auxv_cpu_type, "power5") == 0) { |
| 621 part_ = PPC_POWER5; |
| 622 } else if (strcmp(auxv_cpu_type, "ppc970") == 0) { |
| 623 part_ = PPC_G5; |
| 624 } else if (strcmp(auxv_cpu_type, "ppc7450") == 0) { |
| 625 part_ = PPC_G4; |
| 626 } else if (strcmp(auxv_cpu_type, "pa6t") == 0) { |
| 627 part_ = PPC_PA6T; |
| 628 } |
| 629 } |
| 630 |
| 631 #endif // V8_OS_LINUX |
| 632 #endif // !USE_SIMULATOR |
| 633 #endif // V8_HOST_ARCH_PPC |
584 } | 634 } |
585 | 635 |
586 } } // namespace v8::base | 636 } } // namespace v8::base |
OLD | NEW |