1 /*
   2  * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 package jdk.tools.jaotc.binformat.elf;
  25 
  26 import java.nio.ByteOrder;
  27 import jdk.tools.jaotc.binformat.elf.Elf.Elf64_Ehdr;
  28 
  29 /**
  30  * Class that abstracts MACH-O target details.
  31  *
  32  */
  33 final class ElfTargetInfo {
  34     /**
  35      * Target architecture.
  36      */
  37     private static final char arch;
  38 
  39     /**
  40      * Architecture endian-ness.
  41      */
  42     private static final int endian = Elf64_Ehdr.ELFDATA2LSB;
  43 
  44     /**
  45      * Target OS string.
  46      */
  47     private static String osName;
  48 
  49     static {
  50         // Find the target arch details
  51         String archStr = System.getProperty("os.arch").toLowerCase();
  52         if (ByteOrder.nativeOrder() != ByteOrder.LITTLE_ENDIAN) {
  53             System.out.println("Only Little Endian byte order supported!");
  54         }
  55 
  56         if (archStr.equals("amd64") || archStr.equals("x86_64")) {
  57             arch = Elf64_Ehdr.EM_X86_64;
  58         } else {
  59             System.out.println("Unsupported architecture " + archStr);
  60             arch = Elf64_Ehdr.EM_NONE;
  61         }
  62 
  63         osName = System.getProperty("os.name").toLowerCase();
  64         if (!osName.equals("linux") && !osName.equals("sunos")) {
  65             System.out.println("Unsupported Operating System " + osName);
  66             osName = "Unknown";
  67         }
  68     }
  69 
  70     static char getElfArch() {
  71         return arch;
  72     }
  73 
  74     static int getElfEndian() {
  75         return endian;
  76     }
  77 
  78     static String getOsName() {
  79         return osName;
  80     }
  81 }