src/os/linux/vm/os_linux.cpp

Print this page
rev 9708 : 8073139: PPC64: User-visible arch directory and os.arch value on ppc64le cause issues with Java tooling
Summary: Set LIBARCH to ppc64le, make SA and hsdis work, have os.arch return ppc64le on PowerPC64 LE
Reviewed-by: david.holmes@oracle.com, magnus.ihse.bursie@oracle.com
Contributed-by: Andrew Hughes gnu.andrew@redhat.com, Alexander Smundak asmundak@google.com


1716 
1717 #ifndef EM_486
1718   #define EM_486          6               /* Intel 80486 */
1719 #endif
1720 #ifndef EM_AARCH64
1721   #define EM_AARCH64    183               /* ARM AARCH64 */
1722 #endif
1723 
1724   static const arch_t arch_array[]={
1725     {EM_386,         EM_386,     ELFCLASS32, ELFDATA2LSB, (char*)"IA 32"},
1726     {EM_486,         EM_386,     ELFCLASS32, ELFDATA2LSB, (char*)"IA 32"},
1727     {EM_IA_64,       EM_IA_64,   ELFCLASS64, ELFDATA2LSB, (char*)"IA 64"},
1728     {EM_X86_64,      EM_X86_64,  ELFCLASS64, ELFDATA2LSB, (char*)"AMD 64"},
1729     {EM_SPARC,       EM_SPARC,   ELFCLASS32, ELFDATA2MSB, (char*)"Sparc 32"},
1730     {EM_SPARC32PLUS, EM_SPARC,   ELFCLASS32, ELFDATA2MSB, (char*)"Sparc 32"},
1731     {EM_SPARCV9,     EM_SPARCV9, ELFCLASS64, ELFDATA2MSB, (char*)"Sparc v9 64"},
1732     {EM_PPC,         EM_PPC,     ELFCLASS32, ELFDATA2MSB, (char*)"Power PC 32"},
1733 #if defined(VM_LITTLE_ENDIAN)
1734     {EM_PPC64,       EM_PPC64,   ELFCLASS64, ELFDATA2LSB, (char*)"Power PC 64"},
1735 #else
1736     {EM_PPC64,       EM_PPC64,   ELFCLASS64, ELFDATA2MSB, (char*)"Power PC 64"},
1737 #endif
1738     {EM_ARM,         EM_ARM,     ELFCLASS32,   ELFDATA2LSB, (char*)"ARM"},
1739     {EM_S390,        EM_S390,    ELFCLASSNONE, ELFDATA2MSB, (char*)"IBM System/390"},
1740     {EM_ALPHA,       EM_ALPHA,   ELFCLASS64, ELFDATA2LSB, (char*)"Alpha"},
1741     {EM_MIPS_RS3_LE, EM_MIPS_RS3_LE, ELFCLASS32, ELFDATA2LSB, (char*)"MIPSel"},
1742     {EM_MIPS,        EM_MIPS,    ELFCLASS32, ELFDATA2MSB, (char*)"MIPS"},
1743     {EM_PARISC,      EM_PARISC,  ELFCLASS32, ELFDATA2MSB, (char*)"PARISC"},
1744     {EM_68K,         EM_68K,     ELFCLASS32, ELFDATA2MSB, (char*)"M68k"},
1745     {EM_AARCH64,     EM_AARCH64, ELFCLASS64, ELFDATA2LSB, (char*)"AARCH64"},
1746   };
1747 
1748 #if  (defined IA32)
1749   static  Elf32_Half running_arch_code=EM_386;
1750 #elif   (defined AMD64)
1751   static  Elf32_Half running_arch_code=EM_X86_64;
1752 #elif  (defined IA64)
1753   static  Elf32_Half running_arch_code=EM_IA_64;
1754 #elif  (defined __sparc) && (defined _LP64)
1755   static  Elf32_Half running_arch_code=EM_SPARCV9;
1756 #elif  (defined __sparc) && (!defined _LP64)


2159     }
2160     fclose(fp);
2161   }
2162 #endif // x86 platforms
2163   return false;
2164 }
2165 
2166 void os::pd_print_cpu_info(outputStream* st, char* buf, size_t buflen) {
2167   // Only print the model name if the platform provides this as a summary
2168   if (!print_model_name_and_flags(st, buf, buflen)) {
2169     st->print("\n/proc/cpuinfo:\n");
2170     if (!_print_ascii_file("/proc/cpuinfo", st)) {
2171       st->print_cr("  <Not Available>");
2172     }
2173   }
2174 }
2175 
2176 #if defined(AMD64) || defined(IA32) || defined(X32)
2177 const char* search_string = "model name";
2178 #elif defined(SPARC)


2179 const char* search_string = "cpu";
2180 #else
2181 const char* search_string = "Processor";
2182 #endif
2183 
2184 // Parses the cpuinfo file for string representing the model name.
2185 void os::get_summary_cpu_info(char* cpuinfo, size_t length) {
2186   FILE* fp = fopen("/proc/cpuinfo", "r");
2187   if (fp != NULL) {
2188     while (!feof(fp)) {
2189       char buf[256];
2190       if (fgets(buf, sizeof(buf), fp)) {
2191         char* start = strstr(buf, search_string);
2192         if (start != NULL) {
2193           char *ptr = start + strlen(search_string);
2194           char *end = buf + strlen(buf);
2195           while (ptr != end) {
2196              // skip whitespace and colon for the rest of the name.
2197              if (*ptr != ' ' && *ptr != '\t' && *ptr != ':') {
2198                break;




1716 
1717 #ifndef EM_486
1718   #define EM_486          6               /* Intel 80486 */
1719 #endif
1720 #ifndef EM_AARCH64
1721   #define EM_AARCH64    183               /* ARM AARCH64 */
1722 #endif
1723 
1724   static const arch_t arch_array[]={
1725     {EM_386,         EM_386,     ELFCLASS32, ELFDATA2LSB, (char*)"IA 32"},
1726     {EM_486,         EM_386,     ELFCLASS32, ELFDATA2LSB, (char*)"IA 32"},
1727     {EM_IA_64,       EM_IA_64,   ELFCLASS64, ELFDATA2LSB, (char*)"IA 64"},
1728     {EM_X86_64,      EM_X86_64,  ELFCLASS64, ELFDATA2LSB, (char*)"AMD 64"},
1729     {EM_SPARC,       EM_SPARC,   ELFCLASS32, ELFDATA2MSB, (char*)"Sparc 32"},
1730     {EM_SPARC32PLUS, EM_SPARC,   ELFCLASS32, ELFDATA2MSB, (char*)"Sparc 32"},
1731     {EM_SPARCV9,     EM_SPARCV9, ELFCLASS64, ELFDATA2MSB, (char*)"Sparc v9 64"},
1732     {EM_PPC,         EM_PPC,     ELFCLASS32, ELFDATA2MSB, (char*)"Power PC 32"},
1733 #if defined(VM_LITTLE_ENDIAN)
1734     {EM_PPC64,       EM_PPC64,   ELFCLASS64, ELFDATA2LSB, (char*)"Power PC 64"},
1735 #else
1736     {EM_PPC64,       EM_PPC64,   ELFCLASS64, ELFDATA2MSB, (char*)"Power PC 64 LE"},
1737 #endif
1738     {EM_ARM,         EM_ARM,     ELFCLASS32,   ELFDATA2LSB, (char*)"ARM"},
1739     {EM_S390,        EM_S390,    ELFCLASSNONE, ELFDATA2MSB, (char*)"IBM System/390"},
1740     {EM_ALPHA,       EM_ALPHA,   ELFCLASS64, ELFDATA2LSB, (char*)"Alpha"},
1741     {EM_MIPS_RS3_LE, EM_MIPS_RS3_LE, ELFCLASS32, ELFDATA2LSB, (char*)"MIPSel"},
1742     {EM_MIPS,        EM_MIPS,    ELFCLASS32, ELFDATA2MSB, (char*)"MIPS"},
1743     {EM_PARISC,      EM_PARISC,  ELFCLASS32, ELFDATA2MSB, (char*)"PARISC"},
1744     {EM_68K,         EM_68K,     ELFCLASS32, ELFDATA2MSB, (char*)"M68k"},
1745     {EM_AARCH64,     EM_AARCH64, ELFCLASS64, ELFDATA2LSB, (char*)"AARCH64"},
1746   };
1747 
1748 #if  (defined IA32)
1749   static  Elf32_Half running_arch_code=EM_386;
1750 #elif   (defined AMD64)
1751   static  Elf32_Half running_arch_code=EM_X86_64;
1752 #elif  (defined IA64)
1753   static  Elf32_Half running_arch_code=EM_IA_64;
1754 #elif  (defined __sparc) && (defined _LP64)
1755   static  Elf32_Half running_arch_code=EM_SPARCV9;
1756 #elif  (defined __sparc) && (!defined _LP64)


2159     }
2160     fclose(fp);
2161   }
2162 #endif // x86 platforms
2163   return false;
2164 }
2165 
2166 void os::pd_print_cpu_info(outputStream* st, char* buf, size_t buflen) {
2167   // Only print the model name if the platform provides this as a summary
2168   if (!print_model_name_and_flags(st, buf, buflen)) {
2169     st->print("\n/proc/cpuinfo:\n");
2170     if (!_print_ascii_file("/proc/cpuinfo", st)) {
2171       st->print_cr("  <Not Available>");
2172     }
2173   }
2174 }
2175 
2176 #if defined(AMD64) || defined(IA32) || defined(X32)
2177 const char* search_string = "model name";
2178 #elif defined(SPARC)
2179 const char* search_string = "cpu";
2180 #elif defined(PPC64)
2181 const char* search_string = "cpu";
2182 #else
2183 const char* search_string = "Processor";
2184 #endif
2185 
2186 // Parses the cpuinfo file for string representing the model name.
2187 void os::get_summary_cpu_info(char* cpuinfo, size_t length) {
2188   FILE* fp = fopen("/proc/cpuinfo", "r");
2189   if (fp != NULL) {
2190     while (!feof(fp)) {
2191       char buf[256];
2192       if (fgets(buf, sizeof(buf), fp)) {
2193         char* start = strstr(buf, search_string);
2194         if (start != NULL) {
2195           char *ptr = start + strlen(search_string);
2196           char *end = buf + strlen(buf);
2197           while (ptr != end) {
2198              // skip whitespace and colon for the rest of the name.
2199              if (*ptr != ' ' && *ptr != '\t' && *ptr != ':') {
2200                break;