Make considerably more progress on AARCH64

- Utilities like pledge.com now build
- kprintf() will no longer balk at 48-bit addresses
- There's a new aarch64-dbg build mode that should work
- gc() and defer() are mostly pacified; avoid using them on aarch64
- THIRD_PART_STB now has Arm Neon intrinsics for fast image handling
This commit is contained in:
Justine Tunney 2023-05-12 22:42:57 -07:00
parent 1bfb3aab1b
commit fd34ef732d
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
91 changed files with 1288 additions and 1192 deletions

View file

@ -27,6 +27,8 @@
#include "libc/sysv/consts/nr.h"
#include "libc/testlib/testlib.h"
#ifdef __x86_64__
#define Z 0x5555555555555555
#define FLAGS_cf 0
@ -137,3 +139,5 @@ TEST(diagnose_syscall, testWriteFailed) {
ASSERT_STREQ("rax rcx r11", _gc(DiffContexts(&x, &y)));
}
}
#endif /* __x86_64__ */

View file

@ -22,6 +22,8 @@
#include "libc/testlib/ezbench.h"
#include "libc/testlib/testlib.h"
#ifdef __x86_64__
int x;
bool ok1;
bool ok2;
@ -62,3 +64,5 @@ void SetGetContext(void) {
BENCH(getcontext, bench) {
EZBENCH2("get/setcontext", donothing, SetGetContext());
}
#endif /* __x86_64__ */

View file

@ -16,6 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/sysv/consts/poll.h"
#include "libc/calls/calls.h"
#include "libc/calls/pledge.h"
#include "libc/calls/struct/sigaction.h"
@ -32,7 +33,6 @@
#include "libc/sysv/consts/af.h"
#include "libc/sysv/consts/inaddr.h"
#include "libc/sysv/consts/ipproto.h"
#include "libc/sysv/consts/poll.h"
#include "libc/sysv/consts/sig.h"
#include "libc/sysv/consts/sock.h"
#include "libc/testlib/testlib.h"
@ -40,7 +40,6 @@
#include "libc/x/xasprintf.h"
#include "third_party/chibicc/test/test.h"
#include "tool/decode/lib/flagger.h"
#include "tool/decode/lib/pollnames.h"
bool gotsig;
@ -60,8 +59,7 @@ void OnSig(int sig) {
dontdiscard char *FormatPollFd(struct pollfd p[2]) {
return xasprintf("fd:%d revents:%s\n"
"fd:%d revents:%s\n",
p[0].fd, _gc(RecreateFlags(kPollNames, p[0].revents)),
p[1].fd, _gc(RecreateFlags(kPollNames, p[1].revents)));
p[0].fd, "<TODO:kPollNames>", p[1].fd, "<TODO:kPollNames>");
}
TEST(poll, allZero_doesNothingPrettyMuch) {

View file

@ -16,11 +16,13 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/assert.h"
#include "libc/calls/calls.h"
#include "libc/calls/internal.h"
#include "libc/calls/struct/iovec.h"
#include "libc/calls/struct/iovec.internal.h"
#include "libc/calls/syscall-sysv.internal.h"
#include "libc/dce.h"
#include "libc/sock/internal.h"
#include "libc/sysv/consts/nr.h"
#include "libc/sysv/consts/o.h"
@ -44,12 +46,25 @@ TEST(read, eof) {
////////////////////////////////////////////////////////////////////////////////
static long Read(long fd, void *buf, unsigned long size) {
#ifdef __x86_64__
long ax, di, si, dx;
asm volatile("syscall"
: "=a"(ax), "=D"(di), "=S"(si), "=d"(dx)
: "0"(__NR_read), "1"(fd), "2"(buf), "3"(size)
: "rcx", "r8", "r9", "r10", "r11", "memory", "cc");
return ax;
#elif defined(__aarch64__)
register long r0 asm("x0") = (long)fd;
register long r1 asm("x1") = (long)buf;
register long r2 asm("x2") = (long)size;
register long r8 asm("x8") = (long)__NR_read;
register long res_x0 asm("x0");
asm volatile("svc\t0"
: "=r"(res_x0)
: "r"(r0), "r"(r1), "r"(r2), "r"(r8)
: "memory");
return res_x0;
#endif
}
BENCH(read, bench) {

View file

@ -16,9 +16,9 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/calls/struct/sigaction.h"
#include "libc/calls/calls.h"
#include "libc/calls/struct/rusage.h"
#include "libc/calls/struct/sigaction.h"
#include "libc/calls/struct/siginfo.h"
#include "libc/calls/struct/sigset.h"
#include "libc/calls/struct/sigset.internal.h"
@ -112,6 +112,8 @@ TEST(sigaction, testPingPongParentChildWithSigint) {
EXPECT_SYS(0, 0, sigprocmask(SIG_BLOCK, &oldmask, 0));
}
#ifdef __x86_64__
////////////////////////////////////////////////////////////////////////////////
// test int3 crash
// we expect this to be recoverable by default
@ -164,6 +166,8 @@ TEST(sigaction, sigFpe_handlerCanEditProcessStateAndRecoverExecution) {
ubsanTrumpsSystemsEngineering();
}
#endif /* __x86_64__ */
static unsigned OnSignalCnt = 0;
void OnSignal(int sig, siginfo_t *si, void *ctx) {
OnSignalCnt++;

View file

@ -48,7 +48,7 @@ void OnSigTrap(int sig, struct siginfo *si, void *ctx) {
void TrapBench(int n) {
for (int i = 0; i < n; ++i) {
asm("int3");
__builtin_trap();
}
}
@ -72,6 +72,8 @@ BENCH(signal, trapBenchSiginfo) {
sigaction(SIGTRAP, &old, 0);
}
#ifdef __x86_64__
void OnSigHlt(int sig, struct siginfo *si, void *vctx) {
struct ucontext *ctx = vctx;
ctx->uc_mcontext.rip += 1;
@ -94,3 +96,5 @@ BENCH(signal, hltBenchSiginfo) {
sigaction(SIGSEGV, old + 0, 0);
sigaction(SIGBUS, old + 1, 0);
}
#endif /* __x86_64__ */

View file

@ -16,10 +16,11 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/calls/struct/stat.h"
#include "libc/assert.h"
#include "libc/calls/calls.h"
#include "libc/calls/internal.h"
#include "libc/calls/struct/metastat.internal.h"
#include "libc/calls/struct/stat.h"
#include "libc/dce.h"
#include "libc/errno.h"
#include "libc/mem/gc.internal.h"
@ -71,16 +72,8 @@ TEST(stat, zipos) {
EXPECT_SYS(0, 0, stat("/zip/.python/", &st));
}
static long Stat(const char *path, struct stat *st) {
long ax, di, si, dx;
asm volatile("syscall"
: "=a"(ax), "=D"(di), "=S"(si), "=d"(dx)
: "0"(__NR_stat), "1"(path), "2"(st)
: "rcx", "r8", "r9", "r10", "r11", "memory", "cc");
return ax;
}
static long Fstatat(const char *path, struct stat *st) {
#ifdef __x86_64__
long ax, di, si, dx;
register long r10 asm("r10") = 0;
asm volatile("syscall"
@ -88,6 +81,21 @@ static long Fstatat(const char *path, struct stat *st) {
: "0"(__NR_fstatat), "1"(AT_FDCWD), "2"(path), "3"(st)
: "rcx", "r8", "r9", "r11", "memory", "cc");
return ax;
#elif defined(__aarch64__)
register long r0 asm("x0") = (long)AT_FDCWD;
register long r1 asm("x1") = (long)path;
register long r2 asm("x2") = (long)st;
register long r3 asm("x3") = (long)0;
register long r8 asm("x8") = (long)__NR_fstatat;
register long res_x0 asm("x0");
asm volatile("svc\t0"
: "=r"(res_x0)
: "r"(r0), "r"(r1), "r"(r2), "r"(r3), "r"(r8)
: "memory");
return res_x0;
#else
#error "unsupported architecture"
#endif
}
BENCH(stat, bench) {
@ -100,10 +108,6 @@ BENCH(stat, bench) {
"tokenize_tests-latin1-coding-cookie-and-utf8-bom-sig.txt",
0644));
if (!IsWindows() && !IsFreebsd()) {
EZBENCH2("stat syscall", donothing,
Stat(".python/test/"
"tokenize_tests-latin1-coding-cookie-and-utf8-bom-sig.txt",
&st));
EZBENCH2("fstatat syscall", donothing,
Fstatat(".python/test/"
"tokenize_tests-latin1-coding-cookie-and-utf8-bom-sig.txt",

View file

@ -52,6 +52,7 @@ TEST_LIBC_CALLS_DIRECTDEPS = \
LIBC_X \
LIBC_ZIPOS \
TOOL_DECODE_LIB \
THIRD_PARTY_COMPILER_RT \
THIRD_PARTY_XED
TEST_LIBC_CALLS_DEPS := \

View file

@ -16,6 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/assert.h"
#include "libc/calls/calls.h"
#include "libc/calls/internal.h"
#include "libc/calls/struct/iovec.h"
@ -96,12 +97,27 @@ TEST(write, rlimitFsizeExceeded_raisesEfbig) {
}
static long Write(long fd, const void *data, unsigned long size) {
#ifdef __x86_64__
long ax, di, si, dx;
asm volatile("syscall"
: "=a"(ax), "=D"(di), "=S"(si), "=d"(dx)
: "0"(__NR_write), "1"(fd), "2"(data), "3"(size)
: "rcx", "r8", "r9", "r10", "r11", "memory", "cc");
return ax;
#elif defined(__aarch64__)
register long r0 asm("x0") = (long)fd;
register long r1 asm("x1") = (long)data;
register long r2 asm("x2") = (long)size;
register long r8 asm("x8") = (long)__NR_write;
register long res_x0 asm("x0");
asm volatile("svc\t0"
: "=r"(res_x0)
: "r"(r0), "r"(r1), "r"(r2), "r"(r8)
: "memory");
return res_x0;
#else
#error "unsupported architecture"
#endif
}
BENCH(write, bench) {

View file

@ -50,6 +50,7 @@ void insertionsort(int32_t *a, size_t n) {
}
}
#ifdef __x86_64__
TEST(djbsort, test4) {
static const int kA[] = {4, 3, 2, 1};
n = ARRAYLEN(kA);
@ -62,6 +63,7 @@ TEST(djbsort, test4) {
ASSERT_EQ(0, memcmp(a, b, n * 4));
ASSERT_EQ(0, memcmp(a, c, n * 4));
}
#endif /* __x86_64__ */
TEST(djbsort, test64) {
static const int kA[64] = {
@ -86,10 +88,12 @@ TEST(djbsort, test64) {
insertionsort(a, n);
djbsort(c, n);
ASSERT_EQ(0, memcmp(a, c, n * 4));
#ifdef __x86_64__
if (X86_HAVE(AVX2)) {
djbsort_avx2(b, n);
ASSERT_EQ(0, memcmp(a, b, n * 4));
}
#endif /* __x86_64__ */
}
static int CompareInt(const void *a, const void *b) {

View file

@ -87,13 +87,15 @@ o/$(MODE)/test/libc/mem/prog/life.com.dbg: \
o/$(MODE)/test/libc/mem/prog/life.elf: \
o/$(MODE)/tool/build/assimilate.com \
o/$(MODE)/test/libc/mem/prog/life.com
o/$(MODE)/test/libc/mem/prog/life.com \
$(VM)
@$(COMPILE) -wACP -T$@ \
build/bootstrap/cp.com \
o/$(MODE)/test/libc/mem/prog/life.com \
o/$(MODE)/test/libc/mem/prog/life.elf
@$(COMPILE) -wAASSIMILATE -T$@ \
o/$(MODE)/tool/build/assimilate.com \
$(VM) \
o/$(MODE)/tool/build/assimilate.com -f \
o/$(MODE)/test/libc/mem/prog/life.elf
o/$(MODE)/test/libc/mem/prog/life.elf.zip.o: private \
@ -112,13 +114,15 @@ o/$(MODE)/test/libc/mem/prog/sock.com.dbg: \
o/$(MODE)/test/libc/mem/prog/sock.elf: \
o/$(MODE)/tool/build/assimilate.com \
o/$(MODE)/test/libc/mem/prog/sock.com
o/$(MODE)/test/libc/mem/prog/sock.com \
$(VM)
@$(COMPILE) -wACP -T$@ \
build/bootstrap/cp.com \
o/$(MODE)/test/libc/mem/prog/sock.com \
o/$(MODE)/test/libc/mem/prog/sock.elf
@$(COMPILE) -wAASSIMILATE -T$@ \
o/$(MODE)/tool/build/assimilate.com \
$(VM) \
o/$(MODE)/tool/build/assimilate.com -f \
o/$(MODE)/test/libc/mem/prog/sock.elf
o/$(MODE)/test/libc/mem/prog/sock.elf.zip.o: private \