Skip to content

Commit

Permalink
druntime: add support for LoongArch64
Browse files Browse the repository at this point in the history
  • Loading branch information
liushuyu committed Sep 23, 2023
1 parent f9efc98 commit f327462
Show file tree
Hide file tree
Showing 23 changed files with 449 additions and 1 deletion.
3 changes: 3 additions & 0 deletions compiler/src/dmd/cond.d
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,9 @@ extern (C++) final class VersionCondition : DVCondition
case "LDC":
case "linux":
case "LittleEndian":
case "LoongArch64":
case "LoongArch_HardFloat":
case "LoongArch_SoftFloat":
case "MinGW":
case "MIPS32":
case "MIPS64":
Expand Down
103 changes: 103 additions & 0 deletions druntime/src/core/stdc/errno.d
Original file line number Diff line number Diff line change
Expand Up @@ -1117,6 +1117,109 @@ else version (linux)
enum ERFKILL = 132; ///
enum EHWPOISON = 133; ///
}
else version (LoongArch64)
{
enum EDEADLK = 35; ///
enum ENAMETOOLONG = 36; ///
enum ENOLCK = 37; ///
enum ENOSYS = 38; ///
enum ENOTEMPTY = 39; ///
enum ELOOP = 40; ///
enum EWOULDBLOCK = EAGAIN; ///
enum ENOMSG = 42; ///
enum EIDRM = 43; ///
enum ECHRNG = 44; ///
enum EL2NSYNC = 45; ///
enum EL3HLT = 46; ///
enum EL3RST = 47; ///
enum ELNRNG = 48; ///
enum EUNATCH = 49; ///
enum ENOCSI = 50; ///
enum EL2HLT = 51; ///
enum EBADE = 52; ///
enum EBADR = 53; ///
enum EXFULL = 54; ///
enum ENOANO = 55; ///
enum EBADRQC = 56; ///
enum EBADSLT = 57; ///
enum EDEADLOCK = EDEADLK; ///
enum EBFONT = 59; ///
enum ENOSTR = 60; ///
enum ENODATA = 61; ///
enum ETIME = 62; ///
enum ENOSR = 63; ///
enum ENONET = 64; ///
enum ENOPKG = 65; ///
enum EREMOTE = 66; ///
enum ENOLINK = 67; ///
enum EADV = 68; ///
enum ESRMNT = 69; ///
enum ECOMM = 70; ///
enum EPROTO = 71; ///
enum EMULTIHOP = 72; ///
enum EDOTDOT = 73; ///
enum EBADMSG = 74; ///
enum EOVERFLOW = 75; ///
enum ENOTUNIQ = 76; ///
enum EBADFD = 77; ///
enum EREMCHG = 78; ///
enum ELIBACC = 79; ///
enum ELIBBAD = 80; ///
enum ELIBSCN = 81; ///
enum ELIBMAX = 82; ///
enum ELIBEXEC = 83; ///
enum EILSEQ = 84; ///
enum ERESTART = 85; ///
enum ESTRPIPE = 86; ///
enum EUSERS = 87; ///
enum ENOTSOCK = 88; ///
enum EDESTADDRREQ = 89; ///
enum EMSGSIZE = 90; ///
enum EPROTOTYPE = 91; ///
enum ENOPROTOOPT = 92; ///
enum EPROTONOSUPPORT = 93; ///
enum ESOCKTNOSUPPORT = 94; ///
enum EOPNOTSUPP = 95; ///
enum ENOTSUP = EOPNOTSUPP; ///
enum EPFNOSUPPORT = 96; ///
enum EAFNOSUPPORT = 97; ///
enum EADDRINUSE = 98; ///
enum EADDRNOTAVAIL = 99; ///
enum ENETDOWN = 100; ///
enum ENETUNREACH = 101; ///
enum ENETRESET = 102; ///
enum ECONNABORTED = 103; ///
enum ECONNRESET = 104; ///
enum ENOBUFS = 105; ///
enum EISCONN = 106; ///
enum ENOTCONN = 107; ///
enum ESHUTDOWN = 108; ///
enum ETOOMANYREFS = 109; ///
enum ETIMEDOUT = 110; ///
enum ECONNREFUSED = 111; ///
enum EHOSTDOWN = 112; ///
enum EHOSTUNREACH = 113; ///
enum EALREADY = 114; ///
enum EINPROGRESS = 115; ///
enum ESTALE = 116; ///
enum EUCLEAN = 117; ///
enum ENOTNAM = 118; ///
enum ENAVAIL = 119; ///
enum EISNAM = 120; ///
enum EREMOTEIO = 121; ///
enum EDQUOT = 122; ///
enum ENOMEDIUM = 123; ///
enum EMEDIUMTYPE = 124; ///
enum ECANCELED = 125; ///
enum ENOKEY = 126; ///
enum EKEYEXPIRED = 127; ///
enum EKEYREVOKED = 128; ///
enum EKEYREJECTED = 129; ///
enum EOWNERDEAD = 130; ///
enum ENOTRECOVERABLE = 131; ///
enum ERFKILL = 132; ///
enum EHWPOISON = 133; ///
}
else
{
static assert(false, "Architecture not supported.");
Expand Down
31 changes: 31 additions & 0 deletions druntime/src/core/stdc/fenv.d
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,15 @@ version (GNUFP)

alias fexcept_t = uint;
}
else version (LoongArch64)
{
struct fenv_t
{
uint __fp_control_register;
}

alias fexcept_t = uint;
}
else
{
static assert(0, "Unimplemented architecture");
Expand Down Expand Up @@ -786,6 +795,28 @@ else
FE_TOWARDZERO = 0x1, ///
}
}
else version (LoongArch64)
{
// Define bits representing exceptions in the FPSR status word.
enum
{
FE_INEXACT = 0x010000, ///
FE_UNDERFLOW = 0x020000, ///
FE_OVERFLOW = 0x040000, ///
FE_DIVBYZERO = 0x080000, ///
FE_INVALID = 0x100000, ///
FE_ALL_EXCEPT = 0x1f0000, ///
}

// Define bits representing rounding modes in the FPCR Rmode field.
enum
{
FE_TONEAREST = 0x000, ///
FE_TOWARDZERO = 0x100, ///
FE_DOWNWARD = 0x200, ///
FE_UPWARD = 0x300, ///
}
}
else
{
static assert(0, "Unimplemented architecture");
Expand Down
7 changes: 7 additions & 0 deletions druntime/src/core/stdc/math.d
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,13 @@ else version (CRuntime_Glibc)
///
enum int FP_ILOGBNAN = int.max;
}
else version (LoongArch64)
{
///
enum int FP_ILOGB0 = -int.max;
///
enum int FP_ILOGBNAN = int.max;
}
else
{
static assert(false, "Architecture not supported.");
Expand Down
14 changes: 14 additions & 0 deletions druntime/src/core/sys/linux/dlfcn.d
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,20 @@ else version (IBMZ_Any)
void _dl_mcount_wrapper_check(void* __selfpc);
}
}
else version (LoongArch64)
{
// http://sourceware.org/git/?p=glibc.git;a=blob;f=bits/dlfcn.h
static if (_GNU_SOURCE)
{
RT DL_CALL_FCT(RT, Args...)(RT function(Args) fctp, auto ref Args args)
{
_dl_mcount_wrapper_check(cast(void*)fctp);
return fctp(args);
}

void _dl_mcount_wrapper_check(void* __selfpc);
}
}
else
static assert(0, "unimplemented");

Expand Down
8 changes: 8 additions & 0 deletions druntime/src/core/sys/linux/epoll.d
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,14 @@ else version (IBMZ_Any)
epoll_data_t data;
}
}
else version (LoongArch64)
{
struct epoll_event
{
uint events;
epoll_data_t data;
}
}
else
{
static assert(false, "Platform not supported");
Expand Down
6 changes: 6 additions & 0 deletions druntime/src/core/sys/linux/link.d
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ else version (IBMZ_Any)
else
alias uint32_t Elf_Symndx;
}
else version (LoongArch64)
{
// http://sourceware.org/git/?p=glibc.git;a=blob;f=bits/elfclass.h
alias __WORDSIZE __ELF_NATIVE_CLASS;
alias uint32_t Elf_Symndx;
}
else
static assert(0, "unimplemented");
// <bits/elfclass.h>
Expand Down
4 changes: 4 additions & 0 deletions druntime/src/core/sys/linux/perf_event.d
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ else version (SPARC_Any)
{
enum __NR_perf_event_open = 327;
}
else version (LoongArch64)
{
enum __NR_perf_event_open = 241;
}
else
{
static assert(0, "Architecture not supported");
Expand Down
6 changes: 6 additions & 0 deletions druntime/src/core/sys/linux/sys/eventfd.d
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,11 @@ else version (IBMZ_Any)
enum EFD_CLOEXEC = 0x80000; // octal!2000000
enum EFD_NONBLOCK = 0x800; // octal!4000
}
else version (LoongArch64)
{
enum EFD_SEMAPHORE = 1;
enum EFD_CLOEXEC = 0x80000; // octal!2000000
enum EFD_NONBLOCK = 0x800; // octal!4000
}
else
static assert(0, "unimplemented");
5 changes: 5 additions & 0 deletions druntime/src/core/sys/linux/sys/inotify.d
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ else version (IBMZ_Any)
enum IN_CLOEXEC = 0x80000; // octal!2000000
enum IN_NONBLOCK = 0x800; // octal!4000
}
else version (LoongArch64)
{
enum IN_CLOEXEC = 0x80000; // octal!2000000
enum IN_NONBLOCK = 0x800; // octal!4000
}
else
static assert(0, "unimplemented");

Expand Down
24 changes: 24 additions & 0 deletions druntime/src/core/sys/linux/sys/mman.d
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,30 @@ else version (MIPS_Any)
MAP_HUGETLB = 0x80000,
}
}
else version (LoongArch64)
{
static if (_DEFAULT_SOURCE) enum
{
MAP_GROWSDOWN = 0x00100,
MAP_DENYWRITE = 0x00800,
MAP_EXECUTABLE = 0x01000,
MAP_LOCKED = 0x02000,
MAP_NORESERVE = 0x04000,
MAP_POPULATE = 0x08000,
MAP_NONBLOCK = 0x10000,
MAP_STACK = 0x20000,
MAP_HUGETLB = 0x40000,
MAP_SYNC = 0x80000,
MAP_FIXED_NOREPLACE = 0x100000,
}

// in core.sys.posix.sys.mman
// enum
// {
// MCL_CURRENT = 0x1,
// MCL_FUTURE = 0x2,
// }
}
else
{
static assert(0, "unimplemented");
Expand Down
12 changes: 12 additions & 0 deletions druntime/src/core/sys/posix/dlfcn.d
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,18 @@ version (CRuntime_Glibc)
enum RTLD_LOCAL = 0;
enum RTLD_NODELETE = 0x01000;
}
else version (LoongArch64)
{
// http://sourceware.org/git/?p=glibc.git;a=blob;f=bits/dlfcn.h
enum RTLD_LAZY = 0x00001;
enum RTLD_NOW = 0x00002;
enum RTLD_BINDING_MASK = 0x3;
enum RTLD_NOLOAD = 0x00004;
enum RTLD_DEEPBIND = 0x00008;
enum RTLD_GLOBAL = 0x00100;
enum RTLD_LOCAL = 0;
enum RTLD_NODELETE = 0x01000;
}
else
static assert(0, "unimplemented");

Expand Down
35 changes: 34 additions & 1 deletion druntime/src/core/sys/posix/fcntl.d
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,13 @@ version (linux)
enum F_SETLKW = 7;
}
}
else
else version (LoongArch64)
{
static assert(off_t.sizeof == 8);
enum F_GETLK = 5;
enum F_SETLK = 6;
enum F_SETLKW = 7;
} else
static if ( __USE_FILE_OFFSET64 )
{
enum F_GETLK = 12;
Expand Down Expand Up @@ -391,6 +397,33 @@ version (linux)
enum O_PATH = 0x200000; // octal 010000000
enum O_NDELAY = O_NONBLOCK;
}
else version (LoongArch64)
{
enum O_CREAT = 0x40; // octal 0100
enum O_EXCL = 0x80; // octal 0200
enum O_NOCTTY = 0x100; // octal 0400
enum O_TRUNC = 0x200; // octal 01000

enum O_APPEND = 0x400; // octal 02000
enum O_NONBLOCK = 0x800; // octal 04000
enum O_CLOEXEC = 0x80000; // octal 02000000
enum O_SYNC = 0x101000; // octal 04010000
enum O_DSYNC = 0x1000; // octal 010000
enum O_RSYNC = O_SYNC;

enum O_DIRECTORY = 0x010000; // octal 200000
enum O_NOFOLLOW = 0x020000; // octal 400000
enum O_DIRECT = 0x004000; // octal 040000
version (D_LP64)
enum O_LARGEFILE = 0;
else
enum O_LARGEFILE = 0x8000; // octal 0100000
enum O_TMPFILE = 0x404000; // octal 020040000
enum O_ASYNC = 0x2000; // octal 020000
enum O_NOATIME = 0x40000; // octal 01000000
enum O_PATH = 0x200000; // octal 010000000
enum O_NDELAY = O_NONBLOCK;
}
else
static assert(0, "unimplemented");

Expand Down
15 changes: 15 additions & 0 deletions druntime/src/core/sys/posix/setjmp.d
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,21 @@ version (CRuntime_Glibc)
}
alias __jmp_buf = __s390_jmp_buf[1];
}
else version (LoongArch64)
{
struct __loongarch_jmp_buf
{
long __pc;
long __sp;
// reserved
long __r21;
long __fp;
long[9] __regs;
static if (__traits(getTargetInfo, "floatAbi") != "soft_float")
double[8] __fpregs;
}
alias __jmp_buf = __loongarch_jmp_buf[1];
}
else
static assert(0, "unimplemented");

Expand Down
Loading

0 comments on commit f327462

Please sign in to comment.