ref: 2994fccbe1b881c3fa2838926d22af8aeda89640
parent: dfd915892a662216fa1f422ea56b89c8b34e3175
author: cinap_lenrek <[email protected]>
date: Fri May 3 17:06:46 EDT 2019
ape: initial support for arm64
--- /dev/null
+++ b/arm64/include/ape/float.h
@@ -1,0 +1,73 @@
+#ifndef __FLOAT
+#define __FLOAT
+/* IEEE, default rounding */
+
+#define FLT_ROUNDS 1
+#define FLT_RADIX 2
+
+#define FLT_DIG 6
+#define FLT_EPSILON 1.19209290e-07
+#define FLT_MANT_DIG 24
+#define FLT_MAX 3.40282347e+38
+#define FLT_MAX_10_EXP 38
+#define FLT_MAX_EXP 128
+#define FLT_MIN 1.17549435e-38
+#define FLT_MIN_10_EXP -37
+#define FLT_MIN_EXP -125
+
+#define DBL_DIG 15
+#define DBL_EPSILON 2.2204460492503131e-16
+#define DBL_MANT_DIG 53
+#define DBL_MAX 1.797693134862315708145e+308
+#define DBL_MAX_10_EXP 308
+#define DBL_MAX_EXP 1024
+#define DBL_MIN 2.225073858507201383090233e-308
+#define DBL_MIN_10_EXP -307
+#define DBL_MIN_EXP -1021
+#define LDBL_MANT_DIG DBL_MANT_DIG
+#define LDBL_EPSILON DBL_EPSILON
+#define LDBL_DIG DBL_DIG
+#define LDBL_MIN_EXP DBL_MIN_EXP
+#define LDBL_MIN DBL_MIN
+#define LDBL_MIN_10_EXP DBL_MIN_10_EXP
+#define LDBL_MAX_EXP DBL_MAX_EXP
+#define LDBL_MAX DBL_MAX
+#define LDBL_MAX_10_EXP DBL_MAX_10_EXP
+
+typedef union FPdbleword FPdbleword;
+union FPdbleword
+{
+ double x;
+ struct { /* little endian */
+ long lo;
+ long hi;
+ };
+};
+
+#ifdef _RESEARCH_SOURCE
+/* define stuff needed for floating conversion */
+#define IEEE_8087 1
+#define Sudden_Underflow 1
+#endif
+#ifdef _PLAN9_SOURCE
+/* FCR */
+#define FPINEX (1<<5)
+#define FPOVFL (1<<3)
+#define FPUNFL ((1<<4)|(1<<1))
+#define FPZDIV (1<<2)
+#define FPRNR (0<<10)
+#define FPRZ (3<<10)
+#define FPRPINF (2<<10)
+#define FPRNINF (1<<10)
+#define FPRMASK (3<<10)
+#define FPPEXT (3<<8)
+#define FPPSGL (0<<8)
+#define FPPDBL (2<<8)
+#define FPPMASK (3<<8)
+/* FSR */
+#define FPAINEX FPINEX
+#define FPAOVFL FPOVFL
+#define FPAUNFL FPUNFL
+#define FPAZDIV FPZDIV
+#endif
+#endif /* __FLOAT */
--- /dev/null
+++ b/arm64/include/ape/math.h
@@ -1,0 +1,79 @@
+#ifndef __MATH
+#define __MATH
+#pragma lib "/$M/lib/ape/libap.a"
+
+/* a HUGE_VAL appropriate for IEEE double-precision */
+/* the correct value, 1.797693134862316e+308, causes a ken overflow */
+#define HUGE_VAL 1.79769313486231e+308
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern double acos(double);
+extern double asin(double);
+extern double atan(double);
+extern double atan2(double, double);
+extern double cos(double);
+extern double hypot(double, double);
+extern double sin(double);
+extern double tan(double);
+extern double cosh(double);
+extern double sinh(double);
+extern double tanh(double);
+extern double exp(double);
+extern double frexp(double, int *);
+extern double ldexp(double, int);
+extern double log(double);
+extern double log10(double);
+extern double modf(double, double *);
+extern double pow(double, double);
+extern double sqrt(double);
+extern double ceil(double);
+extern double fabs(double);
+extern double floor(double);
+extern double fmod(double, double);
+extern double NaN(void);
+extern int isNaN(double);
+extern double Inf(int);
+extern int isInf(double, int);
+extern double fmin(double, double);
+
+#ifdef _RESEARCH_SOURCE
+/* does >> treat left operand as unsigned ? */
+#define Unsigned_Shifts 1
+#define M_E 2.7182818284590452354 /* e */
+#define M_LOG2E 1.4426950408889634074 /* log 2e */
+#define M_LOG10E 0.43429448190325182765 /* log 10e */
+#define M_LN2 0.69314718055994530942 /* log e2 */
+#define M_LN10 2.30258509299404568402 /* log e10 */
+#define M_PI 3.14159265358979323846 /* pi */
+#define M_PI_2 1.57079632679489661923 /* pi/2 */
+#define M_PI_4 0.78539816339744830962 /* pi/4 */
+#define M_1_PI 0.31830988618379067154 /* 1/pi */
+#define M_2_PI 0.63661977236758134308 /* 2/pi */
+#define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */
+#define M_SQRT2 1.41421356237309504880 /* sqrt(2) */
+#define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */
+
+extern double hypot(double, double);
+extern double erf(double);
+extern double erfc(double);
+extern double j0(double);
+extern double y0(double);
+extern double j1(double);
+extern double y1(double);
+extern double jn(int, double);
+extern double yn(int, double);
+
+#endif
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#define isnan(x) isNaN(x)
+#define isinf(x) isInf(x)
+
+#endif /* __MATH */
--- /dev/null
+++ b/arm64/include/ape/stdarg.h
@@ -1,0 +1,18 @@
+#ifndef __STDARG
+#define __STDARG
+
+typedef char *va_list;
+
+#define va_start(list, start) list = (sizeof(start)<8 ? (char *)((long long *)&(start)+1) : \
+(char *)(&(start)+1))
+#define va_end(list)
+#define va_arg(list, mode)\
+ ((sizeof(mode) == 1)?\
+ ((mode*)(list += 8))[-8]:\
+ (sizeof(mode) == 2)?\
+ ((mode*)(list += 8))[-4]:\
+ (sizeof(mode) == 4)?\
+ ((mode*)(list += 8))[-2]:\
+ ((mode*)(list += sizeof(mode)))[-1])
+
+#endif /* __STDARG */
--- /dev/null
+++ b/arm64/include/ape/stdint.h
@@ -1,0 +1,31 @@
+#ifndef _STDINT_H_
+#define _STDINT_H_ 1
+
+typedef char int8_t;
+typedef short int16_t;
+typedef int int32_t;
+typedef long long int64_t;
+typedef unsigned char uint8_t;
+typedef unsigned short uint16_t;
+typedef unsigned int uint32_t;
+typedef unsigned long long uint64_t;
+
+typedef long long intptr_t;
+typedef unsigned long long uintptr_t;
+
+#define INT8_MIN 0x80
+#define INT16_MIN 0x8000
+#define INT32_MIN 0x80000000
+#define INT64_MIN 0x8000000000000000LL
+
+#define INT8_MAX 0x7f
+#define INT16_MAX 0x7fff
+#define INT32_MAX 0x7fffffff
+#define INT64_MAX 0x7fffffffffffffffULL
+
+#define UINT8_MAX 0xff
+#define UINT16_MAX 0xffff
+#define UINT32_MAX 0xffffffffL
+#define UINT64_MAX 0xffffffffffffffffULL
+
+#endif
--- /dev/null
+++ b/arm64/include/ape/ureg.h
@@ -1,0 +1,50 @@
+#ifndef __UREG_H
+#define __UREG_H
+#if !defined(_PLAN9_SOURCE)
+ This header file is an extension to ANSI/POSIX
+#endif
+
+struct Ureg {
+ unsigned long long r0;
+ unsigned long long r1;
+ unsigned long long r2;
+ unsigned long long r3;
+ unsigned long long r4;
+ unsigned long long r5;
+ unsigned long long r6;
+ unsigned long long r7;
+ unsigned long long r8;
+ unsigned long long r9;
+ unsigned long long r10;
+ unsigned long long r11;
+ unsigned long long r12;
+ unsigned long long r13;
+ unsigned long long r14;
+ unsigned long long r15;
+ unsigned long long r16;
+ unsigned long long r17;
+ unsigned long long r18;
+ unsigned long long r19;
+ unsigned long long r20;
+ unsigned long long r21;
+ unsigned long long r22;
+ unsigned long long r23;
+ unsigned long long r24;
+ unsigned long long r25;
+ unsigned long long r26;
+ unsigned long long r27;
+ unsigned long long r28; /* sb */
+ union {
+ unsigned long long r29;
+ unsigned long long sp;
+ };
+ union {
+ unsigned long long r30;
+ unsigned long long link;
+ };
+ unsigned long long type; /* of exception */
+ unsigned long long psr;
+ unsigned long long pc; /* interrupted addr */
+};
+
+#endif
--- /dev/null
+++ b/sys/src/ape/lib/9/arm64/getcallerpc.s
@@ -1,0 +1,3 @@
+TEXT getcallerpc(SB), $0
+ MOV 0(SP), R0
+ RETURN
--- /dev/null
+++ b/sys/src/ape/lib/9/arm64/getfcr.s
@@ -1,0 +1,21 @@
+#define SYSARG5(op0,op1,Cn,Cm,op2) ((op0)<<19|(op1)<<16|(Cn)<<12|(Cm)<<8|(op2)<<5)
+
+#define FPCR SPR(SYSARG5(3,3,4,4,0))
+#define FPSR SPR(SYSARG5(3,3,4,4,1))
+
+TEXT setfcr(SB), $0
+ MSR R0, FPCR
+ RETURN
+
+TEXT getfcr(SB), $0
+ MRS FPCR, R0
+ RETURN
+
+TEXT getfsr(SB), $0
+ MRS FPSR, R0
+ RETURN
+
+TEXT setfsr(SB), $0
+ MSR R0, FPSR
+ RETURN
+
--- /dev/null
+++ b/sys/src/ape/lib/ap/arm64/_seek.c
@@ -1,0 +1,11 @@
+extern long __SEEK(long long*, int, long long, int);
+
+long long
+_SEEK(int fd, long long o, int p)
+{
+ long long l;
+
+ if(__SEEK(&l, fd, o, p) < 0)
+ l = -1;
+ return l;
+}
--- /dev/null
+++ b/sys/src/ape/lib/ap/arm64/getfcr.s
@@ -1,0 +1,21 @@
+#define SYSARG5(op0,op1,Cn,Cm,op2) ((op0)<<19|(op1)<<16|(Cn)<<12|(Cm)<<8|(op2)<<5)
+
+#define FPCR SPR(SYSARG5(3,3,4,4,0))
+#define FPSR SPR(SYSARG5(3,3,4,4,1))
+
+TEXT setfcr(SB), 1, $-4
+ MSR R0, FPCR
+ RETURN
+
+TEXT getfcr(SB), 1, $-4
+ MRS FPCR, R0
+ RETURN
+
+TEXT getfsr(SB), 1, $-4
+ MRS FPSR, R0
+ RETURN
+
+TEXT setfsr(SB), 1, $-4
+ MSR R0, FPSR
+ RETURN
+
--- /dev/null
+++ b/sys/src/ape/lib/ap/arm64/lock.c
@@ -1,0 +1,43 @@
+#define _LOCK_EXTENSION
+#include "../plan9/sys9.h"
+#include <lock.h>
+
+extern int tas(int*);
+extern unsigned long long _barrier(unsigned long long);
+
+void
+lock(Lock *lk)
+{
+ int i;
+
+ /* once fast */
+ if(!tas(&lk->val))
+ return;
+ /* a thousand times pretty fast */
+ for(i=0; i<1000; i++){
+ if(!tas(&lk->val))
+ return;
+ _SLEEP(0);
+ }
+ /* now nice and slow */
+ for(i=0; i<1000; i++){
+ if(!tas(&lk->val))
+ return;
+ _SLEEP(100);
+ }
+ /* take your time */
+ while(tas(&lk->val))
+ _SLEEP(1000);
+}
+
+int
+canlock(Lock *lk)
+{
+ return tas(&lk->val) == 0;
+}
+
+void
+unlock(Lock *lk)
+{
+ lk->val = _barrier(0);
+}
--- /dev/null
+++ b/sys/src/ape/lib/ap/arm64/main9.s
@@ -1,0 +1,39 @@
+#define NPRIVATES 16
+
+GLOBL _tos(SB), $8
+GLOBL _errnoloc(SB), $8
+GLOBL _plan9err(SB), $128
+GLOBL _privates(SB), $8
+GLOBL _nprivates(SB), $4
+
+TEXT _main(SB), 1, $(32 + 8+128 + NPRIVATES*8)
+ MOV $setSB(SB), R28
+ MOV R0, _tos(SB)
+
+ ADD $32, RSP, R1
+
+ MOV R1, _errnoloc(SB)
+ ADD $8, R1
+
+ MOV R1, _plan9err(SB)
+ ADD $128, R1
+
+ MOV R1, _privates(SB)
+ MOVW $NPRIVATES, R2
+ MOVW R2, _nprivates(SB)
+
+ BL _envsetup(SB)
+
+ MOV environ(SB), R2
+ MOV R2, 24(RSP)
+
+ MOV $inargv+0(FP), R1
+ MOV R1, 16(RSP)
+
+ MOVW inargc-8(FP), R0
+ MOV R0, 8(RSP)
+
+ BL main(SB)
+loop:
+ BL exit(SB)
+ B loop
--- /dev/null
+++ b/sys/src/ape/lib/ap/arm64/mkfile
@@ -1,0 +1,16 @@
+APE=/sys/src/ape
+<$APE/config
+LIB=/$objtype/lib/ape/libap.a
+OFILES=\
+ _seek.$O\
+ getfcr.$O\
+ lock.$O\
+ main9.$O\
+ notetramp.$O\
+ setjmp.$O\
+ tas.$O\
+
+</sys/src/cmd/mksyslib
+
+CFLAGS=-c -D_POSIX_SOURCE -D_PLAN9_SOURCE
+
--- /dev/null
+++ b/sys/src/ape/lib/ap/arm64/notetramp.c
@@ -1,0 +1,72 @@
+#include "../plan9/lib.h"
+#include "../plan9/sys9.h"
+#include <signal.h>
+#include <setjmp.h>
+
+/* A stack to hold pcs when signals nest */
+#define MAXSIGSTACK 20
+typedef struct Pcstack Pcstack;
+static struct Pcstack {
+ int sig;
+ void (*hdlr)(int, char*, Ureg*);
+ unsigned long long restorepc;
+ Ureg *u;
+} pcstack[MAXSIGSTACK];
+static int nstack = 0;
+
+static void notecont(Ureg*, char*);
+
+void
+_notetramp(int sig, void (*hdlr)(int, char*, Ureg*), Ureg *u)
+{
+ Pcstack *p;
+
+ if(nstack >= MAXSIGSTACK)
+ _NOTED(1); /* nesting too deep; just do system default */
+ p = &pcstack[nstack];
+ p->restorepc = u->pc;
+ p->sig = sig;
+ p->hdlr = hdlr;
+ p->u = u;
+ nstack++;
+ u->pc = (unsigned long long) notecont;
+ _NOTED(2); /* NSAVE: clear note but hold state */
+}
+
+static void
+notecont(Ureg *u, char *s)
+{
+ Pcstack *p;
+ void(*f)(int, char*, Ureg*);
+
+ p = &pcstack[nstack-1];
+ f = p->hdlr;
+ u->pc = p->restorepc;
+ nstack--;
+ (*f)(p->sig, s, u);
+ _NOTED(3); /* NRSTR */
+}
+
+#define JMPBUFPC 1
+#define JMPBUFSP 0
+
+extern sigset_t _psigblocked;
+
+void
+siglongjmp(sigjmp_buf j, int ret)
+{
+ struct Ureg *u;
+
+ if(j[0])
+ _psigblocked = j[1];
+ if(nstack == 0 || pcstack[nstack-1].u->sp > j[2+JMPBUFSP])
+ longjmp(j+2, ret);
+ u = pcstack[nstack-1].u;
+ nstack--;
+ u->r0 = ret;
+ if(ret == 0)
+ u->r0 = 1;
+ u->pc = j[2+JMPBUFPC];
+ u->sp = j[2+JMPBUFSP];
+ _NOTED(3); /* NRSTR */
+}
--- /dev/null
+++ b/sys/src/ape/lib/ap/arm64/setjmp.s
@@ -1,0 +1,26 @@
+TEXT sigsetjmp(SB), 1, $-4
+ MOVW savemask+8(FP), R1
+ MOVW _psigblocked(SB), R2
+ MOVW R1, 0(R0)
+ MOVW R2, 4(R0)
+ ADD $8, R0
+ /* wet floor */
+
+TEXT setjmp(SB), 1, $-4
+ MOV LR, 8(R0)
+ MOV SP, R1
+ MOV R1, 0(R0)
+ MOV $0, R0
+ RETURN
+
+
+TEXT longjmp(SB), 1, $-4
+ MOV 8(R0), LR
+ MOV 0(R0), R1
+ MOVW arg+8(FP), R0
+ MOV R1, SP
+ CBZ R0, _one
+ RETURN
+_one:
+ MOV $1, R0
+ RETURN
--- /dev/null
+++ b/sys/src/ape/lib/ap/arm64/tas.s
@@ -1,0 +1,11 @@
+TEXT tas(SB), 1, $-4
+ MOVW $1, R2
+_tas1:
+ LDXRW (R0), R1
+ STXRW R2, (R0), R3
+ CBNZ R3, _tas1
+ MOVW R1, R0
+
+TEXT _barrier(SB), 1, $-4
+ DMB $0xB // ISH
+ RETURN
--- /dev/null
+++ b/sys/src/ape/lib/mp/arm64/mkfile
@@ -1,0 +1,8 @@
+APE=/sys/src/ape
+<$APE/config
+
+objtype=arm64
+</$objtype/mkfile
+
+install clean all update:V:
+
--- /dev/null
+++ b/sys/src/ape/lib/sec/arm64/mkfile
@@ -1,0 +1,8 @@
+APE=/sys/src/ape
+<$APE/config
+
+objtype=arm64
+</$objtype/mkfile
+
+install clean all update:V:
+
--- a/sys/src/cmd/pcc.c
+++ b/sys/src/cmd/pcc.c
@@ -16,6 +16,7 @@
{"68020", "2c", "2l", "2", "2.out"},
{"arm", "5c", "5l", "5", "5.out"},
{"amd64", "6c", "6l", "6", "6.out"},
+ {"arm64", "7c", "7l", "7", "7.out"},
{"386", "8c", "8l", "8", "8.out"},
{"power64", "9c", "9l", "9", "9.out"},
{"sparc", "kc", "kl", "k", "k.out"},