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