Skip to content

Commit a14e11b

Browse files
committedOct 20, 2022
Support for LoongArch64
1 parent f07aa2b commit a14e11b

File tree

3 files changed

+80
-2
lines changed

3 files changed

+80
-2
lines changed
 

‎pom.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,13 @@
6161
<dependency>
6262
<groupId>com.github.jnr</groupId>
6363
<artifactId>jffi</artifactId>
64-
<version>1.3.9</version>
64+
<version>1.3.10-SNAPSHOT</version>
6565
<scope>compile</scope>
6666
</dependency>
6767
<dependency>
6868
<groupId>com.github.jnr</groupId>
6969
<artifactId>jffi</artifactId>
70-
<version>1.3.9</version>
70+
<version>1.3.10-SNAPSHOT</version>
7171
<scope>runtime</scope>
7272
<classifier>native</classifier>
7373
</dependency>

‎src/main/java/jnr/ffi/Platform.java

+6
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ public enum CPU {
127127
/** 64 bit MIPS */
128128
MIPS64EL,
129129

130+
/** 64 bit LOONGARCH */
131+
LOONGARCH64,
132+
130133
/**
131134
* Unknown CPU architecture. A best effort will be made to infer architecture
132135
* specific values such as address and long size.
@@ -241,6 +244,8 @@ private static CPU determineCPU() {
241244
return CPU.ARM;
242245
} else if (equalsIgnoreCase("mips64", archString) || equalsIgnoreCase("mips64el", archString)) {
243246
return CPU.MIPS64EL;
247+
} else if (equalsIgnoreCase("loongarch64", archString)) {
248+
return CPU.LOONGARCH64;
244249
}
245250

246251
// Try to find by lookup up in the CPU list
@@ -302,6 +307,7 @@ private static int calculateAddressSize(CPU cpu) {
302307
case S390X:
303308
case AARCH64:
304309
case MIPS64EL:
310+
case LOONGARCH64:
305311
dataModel = 64;
306312
break;
307313
default:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
* Copyright (C) 2022 Wayne Meissner
3+
*
4+
* This file is part of the JNR project.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
package jnr.ffi.provider.jffi.platform.loongarch64.linux;
20+
21+
import jnr.ffi.NativeType;
22+
import jnr.ffi.TypeAlias;
23+
24+
import java.util.EnumMap;
25+
import java.util.Map;
26+
27+
public final class TypeAliases {
28+
public static final Map<TypeAlias, jnr.ffi.NativeType> ALIASES = buildTypeMap();
29+
private static Map<TypeAlias, jnr.ffi.NativeType> buildTypeMap() {
30+
Map<TypeAlias, jnr.ffi.NativeType> m = new EnumMap<TypeAlias, jnr.ffi.NativeType>(TypeAlias.class);
31+
m.put(TypeAlias.int8_t, NativeType.SCHAR);
32+
m.put(TypeAlias.u_int8_t, NativeType.UCHAR);
33+
m.put(TypeAlias.int16_t, NativeType.SSHORT);
34+
m.put(TypeAlias.u_int16_t, NativeType.USHORT);
35+
m.put(TypeAlias.int32_t, NativeType.SINT);
36+
m.put(TypeAlias.u_int32_t, NativeType.UINT);
37+
m.put(TypeAlias.int64_t, NativeType.SLONGLONG);
38+
m.put(TypeAlias.u_int64_t, NativeType.ULONGLONG);
39+
m.put(TypeAlias.intptr_t, NativeType.SLONG);
40+
m.put(TypeAlias.uintptr_t, NativeType.ULONG);
41+
m.put(TypeAlias.caddr_t, NativeType.ADDRESS);
42+
m.put(TypeAlias.dev_t, NativeType.ULONG);
43+
m.put(TypeAlias.blkcnt_t, NativeType.SLONG);
44+
m.put(TypeAlias.blksize_t, NativeType.SINT);
45+
m.put(TypeAlias.gid_t, NativeType.UINT);
46+
m.put(TypeAlias.in_addr_t, NativeType.UINT);
47+
m.put(TypeAlias.in_port_t, NativeType.USHORT);
48+
m.put(TypeAlias.ino_t, NativeType.ULONG);
49+
m.put(TypeAlias.ino64_t, NativeType.ULONG);
50+
m.put(TypeAlias.key_t, NativeType.SINT);
51+
m.put(TypeAlias.mode_t, NativeType.UINT);
52+
m.put(TypeAlias.nlink_t, NativeType.UINT);
53+
m.put(TypeAlias.id_t, NativeType.UINT);
54+
m.put(TypeAlias.pid_t, NativeType.SINT);
55+
m.put(TypeAlias.off_t, NativeType.SLONG);
56+
m.put(TypeAlias.swblk_t, NativeType.SLONG);
57+
m.put(TypeAlias.uid_t, NativeType.UINT);
58+
m.put(TypeAlias.clock_t, NativeType.SLONG);
59+
m.put(TypeAlias.size_t, NativeType.ULONG);
60+
m.put(TypeAlias.ssize_t, NativeType.SLONG);
61+
m.put(TypeAlias.time_t, NativeType.SLONG);
62+
m.put(TypeAlias.fsblkcnt_t, NativeType.ULONG);
63+
m.put(TypeAlias.fsfilcnt_t, NativeType.ULONG);
64+
m.put(TypeAlias.sa_family_t, NativeType.USHORT);
65+
m.put(TypeAlias.socklen_t, NativeType.UINT);
66+
m.put(TypeAlias.rlim_t, NativeType.ULONG);
67+
m.put(TypeAlias.cc_t, NativeType.UCHAR);
68+
m.put(TypeAlias.speed_t, NativeType.UINT);
69+
m.put(TypeAlias.tcflag_t, NativeType.UINT);
70+
return m;
71+
}
72+
}

0 commit comments

Comments
 (0)
Please sign in to comment.