mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-27 14:58:30 +00:00
Make progress towards aarch64 build
This commit is contained in:
parent
08ff26c817
commit
ca2860947f
15428 changed files with 25694 additions and 23138 deletions
14
libc/aarch64/aarch64.mk
Normal file
14
libc/aarch64/aarch64.mk
Normal file
|
@ -0,0 +1,14 @@
|
|||
#-*-mode:makefile-gmake;indent-tabs-mode:t;tab-width:8;coding:utf-8-*-┐
|
||||
#───vi: set et ft=make ts=8 tw=8 fenc=utf-8 :vi───────────────────────┘
|
||||
|
||||
o/$(MODE)/libc/aarch64/%.o: libc/aarch64/%.S
|
||||
@$(COMPILE) -AOBJECTIFY.S $(OBJECTIFY.S) $(OUTPUT_OPTION) -c $<
|
||||
|
||||
o/$(MODE)/libc/aarch64/start.o: \
|
||||
libc/aarch64/start.c \
|
||||
libc/runtime/runtime.h
|
||||
|
||||
o/$(MODE)/libc/aarch64: \
|
||||
o/$(MODE)/libc/aarch64/crt.o \
|
||||
o/$(MODE)/libc/aarch64/fenv.o \
|
||||
o/$(MODE)/libc/aarch64/start.o
|
53
libc/aarch64/crt.S
Normal file
53
libc/aarch64/crt.S
Normal file
|
@ -0,0 +1,53 @@
|
|||
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
|
||||
│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2023 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
│ above copyright notice and this permission notice appear in all copies. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
||||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
||||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
||||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
||||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
|
||||
.globl _start
|
||||
.type _start,%function
|
||||
_start: mov x29,#0
|
||||
mov x30,#0
|
||||
mov x0,sp
|
||||
and sp,x0,#-16
|
||||
b _start_c
|
||||
.size _start,.-_start
|
||||
|
||||
.section .initprologue
|
||||
.global _init
|
||||
.type _init,%function
|
||||
_init: stp x29,x30,[sp,-16]!
|
||||
mov x29,sp
|
||||
.previous/*
|
||||
...
|
||||
decentralized content
|
||||
...
|
||||
*/.section .initepilogue
|
||||
ldp x29,x30,[sp],#16
|
||||
ret
|
||||
|
||||
.section .finiprologue
|
||||
.global _fini
|
||||
.type _fini,%function
|
||||
_fini: stp x29,x30,[sp,-16]!
|
||||
mov x29,sp
|
||||
.previous/*
|
||||
...
|
||||
decentralized content
|
||||
...
|
||||
*/.section .finiepilogue
|
||||
ldp x29,x30,[sp],#16
|
||||
ret
|
67
libc/aarch64/fenv.S
Normal file
67
libc/aarch64/fenv.S
Normal file
|
@ -0,0 +1,67 @@
|
|||
.global fegetround
|
||||
.type fegetround,%function
|
||||
fegetround:
|
||||
mrs x0,fpcr
|
||||
and w0,w0,#0xc00000
|
||||
ret
|
||||
|
||||
.global __fesetround
|
||||
.hidden __fesetround
|
||||
.type __fesetround,%function
|
||||
__fesetround:
|
||||
mrs x1,fpcr
|
||||
bic w1,w1,#0xc00000
|
||||
orr w1,w1,w0
|
||||
msr fpcr,x1
|
||||
mov w0,#0
|
||||
ret
|
||||
|
||||
.global fetestexcept
|
||||
.type fetestexcept,%function
|
||||
fetestexcept:
|
||||
and w0,w0,#0x1f
|
||||
mrs x1,fpsr
|
||||
and w0,w0,w1
|
||||
ret
|
||||
|
||||
.global feclearexcept
|
||||
.type feclearexcept,%function
|
||||
feclearexcept:
|
||||
and w0,w0,#0x1f
|
||||
mrs x1,fpsr
|
||||
bic w1,w1,w0
|
||||
msr fpsr,x1
|
||||
mov w0,#0
|
||||
ret
|
||||
|
||||
.global feraiseexcept
|
||||
.type feraiseexcept,%function
|
||||
feraiseexcept:
|
||||
and w0,w0,#0x1f
|
||||
mrs x1,fpsr
|
||||
orr w1,w1,w0
|
||||
msr fpsr,x1
|
||||
mov w0,#0
|
||||
ret
|
||||
|
||||
.global fegetenv
|
||||
.type fegetenv,%function
|
||||
fegetenv:
|
||||
mrs x1,fpcr
|
||||
mrs x2,fpsr
|
||||
stp w1,w2,[x0]
|
||||
mov w0,#0
|
||||
ret
|
||||
|
||||
.global fesetenv
|
||||
.type fesetenv,%function
|
||||
fesetenv:
|
||||
mov x1,#0
|
||||
mov x2,#0
|
||||
cmn x0,#1
|
||||
b.eq 1f
|
||||
ldp w1,w2,[x0]
|
||||
1: msr fpcr,x1
|
||||
msr fpsr,x2
|
||||
mov w0,#0
|
||||
ret
|
56
libc/aarch64/start.c
Normal file
56
libc/aarch64/start.c
Normal file
|
@ -0,0 +1,56 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2023 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
│ above copyright notice and this permission notice appear in all copies. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
||||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
||||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
||||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
||||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/runtime/runtime.h"
|
||||
|
||||
int main(int, char **, char **);
|
||||
|
||||
int __argc;
|
||||
char **__argv;
|
||||
char **__envp;
|
||||
char **environ;
|
||||
|
||||
static inline long sys_set_tid_address(int *t) {
|
||||
register int64_t __r0 asm("x0") = (int64_t)t;
|
||||
register int64_t __res_x0 asm("x0");
|
||||
int64_t __res;
|
||||
asm volatile("mov x8, %1\n"
|
||||
"svc 0x0\n"
|
||||
: "=r"(__res_x0)
|
||||
: "i"(96), "r"(__r0)
|
||||
: "x8", "memory");
|
||||
return __res_x0;
|
||||
}
|
||||
|
||||
void _start_c(long *sp) {
|
||||
int argc;
|
||||
char **argv, **envp;
|
||||
unsigned long *auxv;
|
||||
argc = *sp;
|
||||
argv = (char **)(sp + 1);
|
||||
envp = (char **)(sp + 1 + argc + 1);
|
||||
auxv = (unsigned long *)(sp + 1 + argc + 1);
|
||||
for (;;) {
|
||||
if (!*auxv++) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
__auxv = auxv;
|
||||
environ = envp;
|
||||
exit(main(argc, argv, envp));
|
||||
}
|
|
@ -23,7 +23,6 @@
|
|||
#include "libc/calls/syscall_support-sysv.internal.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/intrin/bits.h"
|
||||
#include "libc/intrin/initializer.internal.h"
|
||||
#include "libc/intrin/safemacros.internal.h"
|
||||
#include "libc/intrin/strace.internal.h"
|
||||
#include "libc/macros.internal.h"
|
||||
|
|
|
@ -21,7 +21,6 @@
|
|||
#include "libc/calls/struct/timespec.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/intrin/bits.h"
|
||||
#include "libc/intrin/initializer.internal.h"
|
||||
#include "libc/intrin/safemacros.internal.h"
|
||||
#include "libc/intrin/strace.internal.h"
|
||||
#include "libc/macros.internal.h"
|
||||
|
|
|
@ -106,7 +106,11 @@
|
|||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
#ifdef __x86_64__
|
||||
extern const int __hostos;
|
||||
#else
|
||||
#define __hostos _HOSTLINUX
|
||||
#endif
|
||||
|
||||
bool IsWsl1(void);
|
||||
|
||||
|
|
|
@ -578,11 +578,15 @@ typedef struct {
|
|||
#define autotype(x) typeof(x)
|
||||
#endif
|
||||
|
||||
#ifdef __x86_64__
|
||||
#if __GNUC__ >= 7 || __has_attribute(__no_caller_saved_registers__)
|
||||
#define nocallersavedregisters __attribute__((__no_caller_saved_registers__))
|
||||
#else
|
||||
#define nocallersavedregisters "need modern compiler"
|
||||
#endif
|
||||
#else
|
||||
#define nocallersavedregisters
|
||||
#endif
|
||||
|
||||
#if (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 408 || \
|
||||
__has_attribute(__no_sanitize_address__)
|
||||
|
@ -608,11 +612,15 @@ typedef struct {
|
|||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef __x86_64__
|
||||
#define notpossible \
|
||||
do { \
|
||||
asm("nop\n\tud2\n\tnop"); \
|
||||
unreachable; \
|
||||
} while (0)
|
||||
#else
|
||||
#define notpossible __builtin_trap()
|
||||
#endif
|
||||
|
||||
#define donothing \
|
||||
do { \
|
||||
|
@ -667,7 +675,7 @@ typedef struct {
|
|||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef __llvm__
|
||||
#if defined(__x86_64__) && !defined(__llvm__)
|
||||
#define initarray _Section(".init_array,\"a\",@init_array #")
|
||||
#else
|
||||
#define initarray _Section(".init_array")
|
||||
|
@ -773,8 +781,12 @@ typedef struct {
|
|||
#endif /* -w */
|
||||
|
||||
#ifndef __STRICT_ANSI__
|
||||
#ifdef __x86_64__
|
||||
#define DebugBreak() asm("int3")
|
||||
#else
|
||||
#define DebugBreak() __builtin_trap()
|
||||
#endif
|
||||
#else
|
||||
#define DebugBreak() (void)0
|
||||
#endif
|
||||
|
||||
|
@ -810,14 +822,14 @@ typedef struct {
|
|||
#define EXPROPRIATE(EXPRESSION) (EXPRESSION)
|
||||
#endif
|
||||
|
||||
#if !defined(__STRICT_ANSI__) && !defined(__APPLE__)
|
||||
#if !defined(__STRICT_ANSI__) && !defined(__APPLE__) && defined(__x86_64__)
|
||||
#define YOINK(SYMBOL) \
|
||||
asm(".section .yoink\n\tnopl\t%a0\n\t.previous" : : "X"(SYMBOL))
|
||||
#else
|
||||
#define YOINK(SYMBOL) (void)0
|
||||
#endif
|
||||
|
||||
#if !defined(__STRICT_ANSI__) && !defined(__APPLE__)
|
||||
#if !defined(__STRICT_ANSI__) && !defined(__APPLE__) && defined(__x86_64__)
|
||||
#define STATIC_YOINK(SYMBOLSTR) \
|
||||
asm(".section .yoink\n\tnopl\t\"" SYMBOLSTR "\"\n\t.previous")
|
||||
#else
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.internal.h"
|
||||
.privileged
|
||||
.alignfunc
|
||||
.balignfunc
|
||||
|
||||
// Returns 𝑥+𝑦, aborting on overflow.
|
||||
//
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.internal.h"
|
||||
.privileged
|
||||
.alignfunc
|
||||
.balignfunc
|
||||
|
||||
// Returns 𝑥+𝑦, aborting on overflow.
|
||||
//
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.internal.h"
|
||||
.privileged
|
||||
.alignfunc
|
||||
.balignfunc
|
||||
|
||||
// Returns 𝑥+𝑦, aborting on overflow.
|
||||
//
|
||||
|
|
|
@ -9,6 +9,7 @@ int _bsfll(long long) pureconst;
|
|||
int _bsf128(uintmax_t) pureconst;
|
||||
|
||||
#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
|
||||
#ifdef __x86_64__
|
||||
#define _bsf(u) \
|
||||
({ \
|
||||
unsigned BiTs; \
|
||||
|
@ -22,6 +23,11 @@ int _bsf128(uintmax_t) pureconst;
|
|||
(unsigned)BiTs; \
|
||||
})
|
||||
#define _bsfll(u) _bsfl(u)
|
||||
#else
|
||||
#define _bsf(x) __builtin_ctz(x)
|
||||
#define _bsfl(x) __builtin_ctzl(x)
|
||||
#define _bsfll(x) __builtin_ctzll(x)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
|
|
|
@ -7,7 +7,8 @@ int _bsr(int) pureconst;
|
|||
int _bsrl(long) pureconst;
|
||||
int _bsrll(long long) pureconst;
|
||||
|
||||
#if defined(__GNUC__) && defined(__x86_64__) && !defined(__STRICT_ANSI__)
|
||||
#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
|
||||
#ifdef __x86_64__
|
||||
int _bsr128(uint128_t) pureconst;
|
||||
#define _bsr(u) \
|
||||
({ \
|
||||
|
@ -22,6 +23,11 @@ int _bsr128(uint128_t) pureconst;
|
|||
(unsigned)BiTs; \
|
||||
})
|
||||
#define _bsrll(u) _bsrl(u)
|
||||
#else
|
||||
#define _bsr(x) (__builtin_clz(x) ^ (sizeof(int) * CHAR_BIT - 1))
|
||||
#define _bsrl(x) (__builtin_clzl(x) ^ (sizeof(long) * CHAR_BIT - 1))
|
||||
#define _bsrll(x) (__builtin_clzll(x) ^ (sizeof(long long) * CHAR_BIT - 1))
|
||||
#endif
|
||||
#endif
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
|
|
|
@ -43,6 +43,7 @@ static dontinline antiquity void bzero_sse(char *p, size_t n) {
|
|||
}
|
||||
}
|
||||
|
||||
#ifdef __x86_64__
|
||||
microarchitecture("avx") static void bzero_avx(char *p, size_t n) {
|
||||
xmm_t v = {0};
|
||||
if (IsAsan()) __asan_verify(p, n);
|
||||
|
@ -73,6 +74,7 @@ microarchitecture("avx") static void bzero_avx(char *p, size_t n) {
|
|||
*(xmm_t *)p = v;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Sets memory to zero.
|
||||
|
@ -134,7 +136,11 @@ void bzero(void *p, size_t n) {
|
|||
char *b;
|
||||
uint64_t x;
|
||||
b = p;
|
||||
#ifdef __x86_64__
|
||||
asm("xorl\t%k0,%k0" : "=r"(x));
|
||||
#else
|
||||
x = 0;
|
||||
#endif
|
||||
if (n <= 16) {
|
||||
if (n >= 8) {
|
||||
__builtin_memcpy(b, &x, 8);
|
||||
|
@ -148,11 +154,13 @@ void bzero(void *p, size_t n) {
|
|||
b[--n] = x;
|
||||
} while (n);
|
||||
}
|
||||
#ifdef __x86_64__
|
||||
} else if (IsTiny()) {
|
||||
asm("rep stosb" : "+D"(b), "+c"(n), "=m"(*(char(*)[n])b) : "a"(0));
|
||||
return;
|
||||
} else if (X86_HAVE(AVX)) {
|
||||
bzero_avx(b, n);
|
||||
#endif
|
||||
} else {
|
||||
bzero_sse(b, n);
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
#if defined(__GNUC__) && !defined(__STRICT_ANSI__) && !defined(__x86__)
|
||||
#if defined(__GNUC__) && !defined(__STRICT_ANSI__) && defined(__x86__)
|
||||
#define _cmpxchg(IFTHING, ISEQUALTOME, REPLACEITWITHME) \
|
||||
({ \
|
||||
bool DidIt; \
|
||||
|
|
|
@ -40,6 +40,7 @@ size_t _countbits(const void *a, size_t n) {
|
|||
p = a;
|
||||
e = p + n;
|
||||
if (!IsTiny()) {
|
||||
#ifdef __x86_64__
|
||||
if (X86_HAVE(POPCNT)) {
|
||||
while (p + sizeof(long) * 4 <= e) {
|
||||
__builtin_memcpy(&Ai, p + 000, sizeof(long));
|
||||
|
@ -60,6 +61,7 @@ size_t _countbits(const void *a, size_t n) {
|
|||
t += Ao;
|
||||
}
|
||||
} else {
|
||||
#endif
|
||||
while (p + 8 <= e) {
|
||||
__builtin_memcpy(&x, p, 8);
|
||||
x = x - ((x >> 1) & 0x5555555555555555);
|
||||
|
@ -71,7 +73,9 @@ size_t _countbits(const void *a, size_t n) {
|
|||
t += x;
|
||||
p += 8;
|
||||
}
|
||||
#ifdef __x86_64__
|
||||
}
|
||||
#endif
|
||||
}
|
||||
while (p < e) {
|
||||
b = *p++ & 255;
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/consts/prot.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
#ifdef __x86_64__
|
||||
|
||||
#define MAP_ANONYMOUS_linux 0x00000020
|
||||
#define MAP_FIXED_linux 0x00000010
|
||||
|
@ -109,3 +110,5 @@ noasan struct DirectMap sys_mmap_metal(void *vaddr, size_t size, int prot,
|
|||
res.maphandle = -1;
|
||||
return res;
|
||||
}
|
||||
|
||||
#endif /* __x86_64__ */
|
||||
|
|
|
@ -39,6 +39,7 @@
|
|||
privileged wontreturn void _Exit(int exitcode) {
|
||||
int i;
|
||||
STRACE("_Exit(%d)", exitcode);
|
||||
#ifdef __x86_64__
|
||||
if (!IsWindows() && !IsMetal()) {
|
||||
// On Linux _Exit1 (exit) must be called in pledge("") mode. If we
|
||||
// call _Exit (exit_group) when we haven't used pledge("stdio") then
|
||||
|
@ -64,4 +65,13 @@ privileged wontreturn void _Exit(int exitcode) {
|
|||
"cli\n\t"
|
||||
"lidt\t(%rsp)");
|
||||
for (;;) asm("ud2");
|
||||
#elif defined(__aarch64__)
|
||||
register long x0 asm("x0") = exitcode;
|
||||
asm volatile("mov\tx8,%1\n"
|
||||
"svc\t0"
|
||||
: /* no outputs */
|
||||
: "i"(94), "r"(x0)
|
||||
: "x8", "memory");
|
||||
notpossible;
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -43,6 +43,7 @@ __msabi extern typeof(ExitThread) *const __imp_ExitThread;
|
|||
* @noreturn
|
||||
*/
|
||||
privileged wontreturn void _Exit1(int rc) {
|
||||
#ifdef __x86_64__
|
||||
char cf;
|
||||
int ax, dx, di, si;
|
||||
if (!IsWindows() && !IsMetal()) {
|
||||
|
@ -72,4 +73,13 @@ privileged wontreturn void _Exit1(int rc) {
|
|||
unreachable;
|
||||
}
|
||||
notpossible;
|
||||
#elif defined(__aarch64__)
|
||||
register long r0 asm("x0") = rc;
|
||||
asm volatile("mov\tx8,%1\n"
|
||||
"svc\t0"
|
||||
: /* no outputs */
|
||||
: "i"(93), "r"(r0)
|
||||
: "x8", "memory");
|
||||
notpossible;
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ void *_wrfsbase(void *);
|
|||
void *_wrgsbase(void *);
|
||||
int _have_fsgsbase(void);
|
||||
|
||||
#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
|
||||
#if defined(__GNUC__) && !defined(__STRICT_ANSI__) && defined(__x86_64__)
|
||||
#define _rdfsbase() \
|
||||
({ \
|
||||
void *_p; \
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/runtime/runtime.h"
|
||||
#ifdef __x86_64__
|
||||
|
||||
void GetCpuidBrand(char s[13], uint32_t leaf) {
|
||||
int ax, cx;
|
||||
|
@ -32,3 +33,5 @@ void GetCpuidBrand(char s[13], uint32_t leaf) {
|
|||
: "rdx");
|
||||
s[12] = 0;
|
||||
}
|
||||
|
||||
#endif /* __x86_64__ */
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include "libc/errno.h"
|
||||
#include "libc/intrin/fsgsbase.h"
|
||||
#include "libc/nexgen32e/x86feature.h"
|
||||
#ifdef __x86_64__
|
||||
|
||||
/**
|
||||
* Returns true if FSGSBASE ISA can be used.
|
||||
|
@ -61,3 +62,5 @@ privileged int _have_fsgsbase(void) {
|
|||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* __x86_64__ */
|
||||
|
|
|
@ -1,22 +0,0 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_BITS_INITIALIZER_H_
|
||||
#define COSMOPOLITAN_LIBC_BITS_INITIALIZER_H_
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
|
||||
/* TODO: DELETE */
|
||||
|
||||
/**
|
||||
* Teleports code fragment inside _init().
|
||||
*/
|
||||
#ifndef INITIALIZER
|
||||
#define INITIALIZER(PRI, NAME, CODE) \
|
||||
asm(".section .init." #PRI "." #NAME ",\"ax\",@progbits\n\t" \
|
||||
"call\t" #NAME "\n\t" \
|
||||
".previous"); \
|
||||
textstartup optimizesize void NAME(char *rdi, const char *rsi) { \
|
||||
CODE; \
|
||||
asm volatile("" : /* no outputs */ : "D"(rdi), "S"(rsi)); \
|
||||
}
|
||||
#endif /* INITIALIZER */
|
||||
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_BITS_INITIALIZER_H_ */
|
|
@ -89,7 +89,7 @@ o/$(MODE)/libc/intrin/kprintf.greg.o: private \
|
|||
-fpie \
|
||||
-fwrapv \
|
||||
-x-no-pg \
|
||||
-mno-fentry \
|
||||
$(MNO_FENTRY) \
|
||||
-ffreestanding \
|
||||
-fno-sanitize=all \
|
||||
-fno-stack-protector
|
||||
|
@ -105,7 +105,7 @@ o/$(MODE)/libc/intrin/_spinlock_debug_4.o: private \
|
|||
OVERRIDE_CFLAGS += \
|
||||
-fwrapv \
|
||||
-x-no-pg \
|
||||
-mno-fentry \
|
||||
$(MNO_FENTRY) \
|
||||
-ffreestanding \
|
||||
-fno-sanitize=all \
|
||||
-mgeneral-regs-only \
|
||||
|
@ -186,6 +186,10 @@ o/$(MODE)/libc/intrin/memmove.o: private \
|
|||
OVERRIDE_CFLAGS += \
|
||||
-fpie
|
||||
|
||||
# these assembly files are safe to build on aarch64
|
||||
o/$(MODE)/libc/intrin/kclocknames.o: libc/intrin/kclocknames.S
|
||||
@$(COMPILE) -AOBJECTIFY.S $(OBJECTIFY.S) $(OUTPUT_OPTION) -c $<
|
||||
|
||||
LIBC_INTRIN_LIBS = $(foreach x,$(LIBC_INTRIN_ARTIFACTS),$($(x)))
|
||||
LIBC_INTRIN_HDRS = $(foreach x,$(LIBC_INTRIN_ARTIFACTS),$($(x)_HDRS))
|
||||
LIBC_INTRIN_INCS = $(foreach x,$(LIBC_INTRIN_ARTIFACTS),$($(x)_INCS))
|
||||
|
|
|
@ -28,18 +28,18 @@
|
|||
.endm
|
||||
|
||||
.section .rodata,"a",@progbits
|
||||
.align 4
|
||||
.balign 4
|
||||
.underrun
|
||||
kClockNames:
|
||||
.e CLOCK_REALTIME,"REALTIME"
|
||||
.e CLOCK_REALTIME_FAST,"REALTIME_FAST" # order matters
|
||||
.e CLOCK_REALTIME_PRECISE,"REALTIME_PRECISE" # order matters
|
||||
.e CLOCK_REALTIME_COARSE,"REALTIME_COARSE" # order matters
|
||||
.e CLOCK_REALTIME_FAST,"REALTIME_FAST" // order matters
|
||||
.e CLOCK_REALTIME_PRECISE,"REALTIME_PRECISE" // order matters
|
||||
.e CLOCK_REALTIME_COARSE,"REALTIME_COARSE" // order matters
|
||||
.e CLOCK_MONOTONIC,"MONOTONIC"
|
||||
.e CLOCK_MONOTONIC_FAST,"MONOTONIC_FAST" # order matters
|
||||
.e CLOCK_MONOTONIC_RAW,"MONOTONIC_RAW" # order matters
|
||||
.e CLOCK_MONOTONIC_PRECISE,"MONOTONIC_PRECISE" # order matters
|
||||
.e CLOCK_MONOTONIC_COARSE,"MONOTONIC_COARSE" # order matters
|
||||
.e CLOCK_MONOTONIC_FAST,"MONOTONIC_FAST" // order matters
|
||||
.e CLOCK_MONOTONIC_RAW,"MONOTONIC_RAW" // order matters
|
||||
.e CLOCK_MONOTONIC_PRECISE,"MONOTONIC_PRECISE" // order matters
|
||||
.e CLOCK_MONOTONIC_COARSE,"MONOTONIC_COARSE" // order matters
|
||||
.e CLOCK_PROCESS_CPUTIME_ID,"PROCESS_CPUTIME_ID"
|
||||
.e CLOCK_THREAD_CPUTIME_ID,"THREAD_CPUTIME_ID"
|
||||
.e CLOCK_TAI,"TAI"
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
// @see libc/sysv/dos2errno.sh for the numbers
|
||||
|
||||
.section .sort.rodata.dos2errno.1,"a",@progbits
|
||||
.align 8
|
||||
.balign 8
|
||||
kDos2Errno:/*
|
||||
...decentralized content...
|
||||
*/.endobj kDos2Errno,globl
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
.endm
|
||||
|
||||
.section .rodata
|
||||
.align 4
|
||||
.balign 4
|
||||
.underrun
|
||||
kErrnoDocs:
|
||||
.e EINVAL,"Invalid argument"
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
.endm
|
||||
|
||||
.section .rodata
|
||||
.align 4
|
||||
.balign 4
|
||||
.underrun
|
||||
kErrnoNames:
|
||||
.e EINVAL
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
.endm
|
||||
|
||||
.section .rodata,"a",@progbits
|
||||
.align 4
|
||||
.balign 4
|
||||
.underrun
|
||||
kFcntlCmds:
|
||||
.e F_GETFD,"GETFD"
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
.endm
|
||||
|
||||
.section .rodata
|
||||
.align 4
|
||||
.balign 4
|
||||
.underrun
|
||||
kIpOptnames:
|
||||
.e IP_TOS,"TOS" # int
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
.endm
|
||||
|
||||
.section .rodata
|
||||
.align 4
|
||||
.balign 4
|
||||
.underrun
|
||||
kOpenFlags:
|
||||
.e O_RDWR,"RDWR" // order matters
|
||||
|
|
|
@ -165,6 +165,7 @@ privileged bool kisdangerous(const void *p) {
|
|||
}
|
||||
|
||||
privileged static void klog(const char *b, size_t n) {
|
||||
#ifdef __x86_64__
|
||||
int e;
|
||||
bool cf;
|
||||
size_t i;
|
||||
|
@ -196,6 +197,17 @@ privileged static void klog(const char *b, size_t n) {
|
|||
: "0"(__NR_write), "1"(2), "2"(b), "3"(n)
|
||||
: "rcx", "r8", "r9", "r10", "r11", "memory", "cc");
|
||||
}
|
||||
#else
|
||||
register long r0 asm("x0") = (long)2;
|
||||
register long r1 asm("x1") = (long)b;
|
||||
register long r2 asm("x2") = (long)n;
|
||||
register long res_x0 asm("x0");
|
||||
asm volatile("mov\tx8,%1\n"
|
||||
"svc\t0"
|
||||
: "=r"(res_x0)
|
||||
: "i"(64), "r"(r0), "r"(r1), "r"(r2)
|
||||
: "x8", "memory");
|
||||
#endif
|
||||
}
|
||||
|
||||
privileged static size_t kformat(char *b, size_t n, const char *fmt,
|
||||
|
@ -798,7 +810,6 @@ privileged size_t kvsnprintf(char *b, size_t n, const char *fmt, va_list v) {
|
|||
privileged void kvprintf(const char *fmt, va_list v) {
|
||||
size_t n;
|
||||
char b[4000];
|
||||
if (!v) return;
|
||||
n = kformat(b, sizeof(b), fmt, v);
|
||||
klog(b, MIN(n, sizeof(b) - 1));
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
.endm
|
||||
|
||||
.section .rodata
|
||||
.align 4
|
||||
.balign 4
|
||||
.underrun
|
||||
kRlimitNames:
|
||||
.e RLIMIT_AS,"AS"
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
.endm
|
||||
|
||||
.section .rodata
|
||||
.align 4
|
||||
.balign 4
|
||||
.underrun
|
||||
kSignalNames:
|
||||
.e SIGHUP,"SIGHUP"
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
.endm
|
||||
|
||||
.section .rodata
|
||||
.align 4
|
||||
.balign 4
|
||||
.underrun
|
||||
kSockOptnames:
|
||||
.e SO_DEBUG,"DEBUG" # bool32
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
.endm
|
||||
|
||||
.section .rodata
|
||||
.align 4
|
||||
.balign 4
|
||||
.underrun
|
||||
kTcpOptnames:
|
||||
.e TCP_NODELAY,"NODELAY" # bool32
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
.globl _leaky_start,_leaky_end
|
||||
.hidden _leaky_start,_leaky_end
|
||||
.byte 0
|
||||
.align __SIZEOF_POINTER__
|
||||
.balign __SIZEOF_POINTER__
|
||||
.underrun
|
||||
_leaky_start:
|
||||
.previous/*
|
||||
|
|
|
@ -3,9 +3,11 @@
|
|||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
/* TODO(jart): DELETE */
|
||||
|
||||
intptr_t lockxchg(void *, void *, size_t);
|
||||
|
||||
#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
|
||||
#if defined(__GNUC__) && !defined(__STRICT_ANSI__) && defined(__x86_64__)
|
||||
/**
|
||||
* Exchanges *MEMORY into *LOCALVAR w/ one operation.
|
||||
*
|
||||
|
|
|
@ -25,6 +25,8 @@
|
|||
|
||||
typedef char xmm_t __attribute__((__vector_size__(16), __aligned__(1)));
|
||||
|
||||
#ifdef __x86_64__
|
||||
|
||||
static dontinline antiquity int memcmp_sse(const unsigned char *p,
|
||||
const unsigned char *q, size_t n) {
|
||||
unsigned u;
|
||||
|
@ -99,6 +101,8 @@ microarchitecture("avx") static int memcmp_avx(const unsigned char *p,
|
|||
}
|
||||
}
|
||||
|
||||
#endif /* __x86_64__ */
|
||||
|
||||
/**
|
||||
* Compares memory byte by byte.
|
||||
*
|
||||
|
@ -136,6 +140,7 @@ int memcmp(const void *a, const void *b, size_t n) {
|
|||
const unsigned char *p, *q;
|
||||
if ((p = a) == (q = b) || !n) return 0;
|
||||
if ((c = *p - *q)) return c;
|
||||
#ifdef __x86_64__
|
||||
if (!IsTiny()) {
|
||||
if (n <= 16) {
|
||||
if (n >= 8) {
|
||||
|
@ -187,6 +192,7 @@ int memcmp(const void *a, const void *b, size_t n) {
|
|||
return memcmp_sse(p, q, n);
|
||||
}
|
||||
}
|
||||
#endif /* __x86_64__ */
|
||||
for (; n; ++p, ++q, --n) {
|
||||
if ((c = *p - *q)) {
|
||||
return c;
|
||||
|
|
|
@ -93,6 +93,8 @@ void *memmove(void *dst, const void *src, size_t n) {
|
|||
xmm_t v, w, x, y, V, W, X, Y, wut;
|
||||
d = dst;
|
||||
s = src;
|
||||
|
||||
#ifdef __x86__
|
||||
if (IsTiny()) {
|
||||
uint16_t w1, w2;
|
||||
uint32_t l1, l2;
|
||||
|
@ -133,6 +135,8 @@ void *memmove(void *dst, const void *src, size_t n) {
|
|||
}
|
||||
return dst;
|
||||
}
|
||||
#endif
|
||||
|
||||
switch (n) {
|
||||
case 0:
|
||||
return d;
|
||||
|
@ -208,6 +212,8 @@ void *memmove(void *dst, const void *src, size_t n) {
|
|||
return d;
|
||||
default:
|
||||
if (d == s) return d;
|
||||
|
||||
#ifdef __x86__
|
||||
if (n < kHalfCache3 || !kHalfCache3) {
|
||||
if (d > s) {
|
||||
if (IsAsan() || n < 900 || !X86_HAVE(ERMS)) {
|
||||
|
@ -280,6 +286,31 @@ void *memmove(void *dst, const void *src, size_t n) {
|
|||
}
|
||||
asm("sfence");
|
||||
}
|
||||
#else
|
||||
|
||||
if (d > s) {
|
||||
do {
|
||||
n -= 32;
|
||||
v = *(const xmm_t *)(s + n);
|
||||
w = *(const xmm_t *)(s + n + 16);
|
||||
*(xmm_t *)(d + n) = v;
|
||||
*(xmm_t *)(d + n + 16) = w;
|
||||
} while (n >= 32);
|
||||
} else {
|
||||
i = 0;
|
||||
do {
|
||||
v = *(const xmm_t *)(s + i);
|
||||
w = *(const xmm_t *)(s + i + 16);
|
||||
*(xmm_t *)(d + i) = v;
|
||||
*(xmm_t *)(d + i + 16) = w;
|
||||
} while ((i += 32) + 32 <= n);
|
||||
d += i;
|
||||
s += i;
|
||||
n -= i;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
if (n) {
|
||||
if (n >= 16) {
|
||||
v = *(const xmm_t *)s;
|
||||
|
@ -305,6 +336,7 @@ void *memmove(void *dst, const void *src, size_t n) {
|
|||
*d = *s;
|
||||
}
|
||||
}
|
||||
|
||||
return dst;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,6 +44,7 @@ static dontinline antiquity void *memset_sse(char *p, char c, size_t n) {
|
|||
return p;
|
||||
}
|
||||
|
||||
#ifdef __x86_64__
|
||||
microarchitecture("avx") static void *memset_avx(char *p, char c, size_t n) {
|
||||
char *t;
|
||||
xmm_t v = {c, c, c, c, c, c, c, c, c, c, c, c, c, c, c, c};
|
||||
|
@ -76,6 +77,7 @@ microarchitecture("avx") static void *memset_avx(char *p, char c, size_t n) {
|
|||
}
|
||||
return p;
|
||||
}
|
||||
#endif /* __x86_64__ */
|
||||
|
||||
/**
|
||||
* Sets memory.
|
||||
|
@ -155,11 +157,13 @@ void *memset(void *p, int c, size_t n) {
|
|||
} while (n);
|
||||
}
|
||||
return b;
|
||||
#ifdef __x86_64__
|
||||
} else if (IsTiny()) {
|
||||
asm("rep stosb" : "+D"(b), "+c"(n), "=m"(*(char(*)[n])b) : "0"(p), "a"(c));
|
||||
return p;
|
||||
} else if (X86_HAVE(AVX)) {
|
||||
return memset_avx(b, c, n);
|
||||
#endif
|
||||
} else {
|
||||
return memset_sse(b, c, n);
|
||||
}
|
||||
|
|
|
@ -42,6 +42,7 @@
|
|||
#include "libc/runtime/metalprintf.internal.h"
|
||||
#include "libc/runtime/pc.internal.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#ifdef __x86_64__
|
||||
|
||||
#define INVERT(x) (BANE + PHYSICAL(x))
|
||||
#define NOPAGE ((uint64_t)-1)
|
||||
|
@ -313,3 +314,5 @@ noasan textreal void __reclaim_boot_pages(struct mman *mm, uint64_t skip_start,
|
|||
}
|
||||
mm->frp = p;
|
||||
}
|
||||
|
||||
#endif /* __x86_64__ */
|
||||
|
|
|
@ -6,7 +6,7 @@ COSMOPOLITAN_C_START_
|
|||
|
||||
void mpsadbw(uint16_t[8], const uint8_t[16], const uint8_t[16], uint8_t);
|
||||
|
||||
#ifndef __STRICT_ANSI__
|
||||
#if defined(__x86_64__) && !defined(__STRICT_ANSI__)
|
||||
__intrin_xmm_t __mpsadbws(__intrin_xmm_t, __intrin_xmm_t);
|
||||
#define mpsadbw(C, B, A, I) \
|
||||
do { \
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
//
|
||||
// @note needs sse4 cf. core c. 2006 cf. bulldozer c. 2011
|
||||
// @see mpsadbw()
|
||||
.align 8
|
||||
.balign 8
|
||||
__mpsadbws:
|
||||
i = 0
|
||||
.rept 8
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.internal.h"
|
||||
.privileged
|
||||
.alignfunc
|
||||
.balignfunc
|
||||
|
||||
// Returns 𝑥*𝑦, aborting on overflow.
|
||||
//
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.internal.h"
|
||||
.privileged
|
||||
.alignfunc
|
||||
.balignfunc
|
||||
|
||||
// Returns 𝑥*𝑦, aborting on overflow.
|
||||
//
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.internal.h"
|
||||
.privileged
|
||||
.alignfunc
|
||||
.balignfunc
|
||||
|
||||
// Returns 𝑥*𝑦, aborting on overflow.
|
||||
//
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.internal.h"
|
||||
.privileged
|
||||
.alignfunc
|
||||
.balignfunc
|
||||
|
||||
// Returns -𝑥, aborting on overflow (two's complement bane).
|
||||
//
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.internal.h"
|
||||
.privileged
|
||||
.alignfunc
|
||||
.balignfunc
|
||||
|
||||
// Returns -𝑥, aborting on overflow (two's complement bane).
|
||||
//
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.internal.h"
|
||||
.privileged
|
||||
.alignfunc
|
||||
.balignfunc
|
||||
|
||||
// Returns -𝑥, aborting on overflow.
|
||||
//
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_INTRIN_NOPL_H_
|
||||
#define COSMOPOLITAN_LIBC_INTRIN_NOPL_H_
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0) && defined(__GNUC__) && \
|
||||
!defined(__llvm__) && !defined(__chibicc__) && !defined(__STRICT_ANSI__)
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0) && defined(__x86_64__) && \
|
||||
defined(__GNUC__) && !defined(__llvm__) && !defined(__chibicc__) && \
|
||||
!defined(__STRICT_ANSI__)
|
||||
|
||||
/**
|
||||
* @fileoverview Turns CALLs into NOPs that are fixupable at runtime.
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/nt/struct/teb.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#ifdef __x86_64__
|
||||
|
||||
/**
|
||||
* Returns New Technology version, e.g.
|
||||
|
@ -29,3 +30,5 @@
|
|||
textwindows noasan int NtGetVersion(void) {
|
||||
return (NtGetPeb()->OSMajorVersion & 0xff) << 8 | NtGetPeb()->OSMinorVersion;
|
||||
}
|
||||
|
||||
#endif /* __x86_64__ */
|
||||
|
|
|
@ -7,7 +7,7 @@ COSMOPOLITAN_C_START_
|
|||
|
||||
void palignr(void *, const void *, const void *, unsigned long);
|
||||
|
||||
#if !defined(__STRICT_ANSI__) && !defined(__chibicc__)
|
||||
#if !defined(__STRICT_ANSI__) && !defined(__chibicc__) && defined(__x86_64__)
|
||||
__intrin_xmm_t __palignrs(__intrin_xmm_t, __intrin_xmm_t);
|
||||
#define palignr(C, B, A, I) \
|
||||
do { \
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
//
|
||||
// @note needs ssse3 cf. prescott c. 2004 cf. bulldozer c. 2011
|
||||
// @see palignr()
|
||||
.align 8
|
||||
.balign 8
|
||||
__palignrs:
|
||||
palignr $0,%xmm1,%xmm0
|
||||
ret
|
||||
|
|
|
@ -7,7 +7,7 @@ COSMOPOLITAN_C_START_
|
|||
size_t _countbits(const void *, size_t);
|
||||
unsigned long popcnt(unsigned long) pureconst;
|
||||
|
||||
#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
|
||||
#if defined(__GNUC__) && !defined(__STRICT_ANSI__) && defined(__x86_64__)
|
||||
#define popcnt(X) \
|
||||
(__builtin_constant_p(X) ? __builtin_popcountll(X) : ({ \
|
||||
unsigned long PoP = (X); \
|
||||
|
@ -18,6 +18,8 @@ unsigned long popcnt(unsigned long) pureconst;
|
|||
} \
|
||||
PoP; \
|
||||
}))
|
||||
#else
|
||||
#define popcnt(x) __builtin_popcountll(x)
|
||||
#endif /* GNUC && !ANSI */
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
|
|
|
@ -6,7 +6,7 @@ COSMOPOLITAN_C_START_
|
|||
|
||||
void pslldq(uint8_t[16], const uint8_t[16], unsigned long);
|
||||
|
||||
#ifndef __STRICT_ANSI__
|
||||
#if defined(__x86_64__) && !defined(__STRICT_ANSI__)
|
||||
__intrin_xmm_t __pslldqs(__intrin_xmm_t);
|
||||
#define pslldq(B, A, I) \
|
||||
do { \
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
#include "libc/macros.internal.h"
|
||||
|
||||
// Jump table for pslldq() with non-constexpr immediate parameter.
|
||||
.align 8
|
||||
.balign 8
|
||||
__pslldqs:
|
||||
pslldq $0,%xmm0
|
||||
ret
|
||||
|
|
|
@ -6,7 +6,7 @@ COSMOPOLITAN_C_START_
|
|||
|
||||
void psrldq(uint8_t[16], const uint8_t[16], unsigned long);
|
||||
|
||||
#ifndef __STRICT_ANSI__
|
||||
#if defined(__x86_64__) && !defined(__STRICT_ANSI__)
|
||||
__intrin_xmm_t __psrldqs(__intrin_xmm_t);
|
||||
#define psrldq(B, A, I) \
|
||||
do { \
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
#include "libc/macros.internal.h"
|
||||
|
||||
// Jump table for psrldq() with non-constexpr immediate parameter.
|
||||
.align 8
|
||||
.balign 8
|
||||
__psrldqs:
|
||||
psrldq $0,%xmm0
|
||||
ret
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
#include "libc/macros.internal.h"
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
|
||||
#if !defined(__GNUC__) || defined(__STRICT_ANSI__)
|
||||
#if !defined(__GNUC__) || defined(__STRICT_ANSI__) || !defined(__x86_64__)
|
||||
#define pushpop(x) (x)
|
||||
#else
|
||||
/**
|
||||
|
@ -31,7 +31,7 @@
|
|||
})
|
||||
#endif
|
||||
|
||||
#if !defined(__GNUC__) || defined(__STRICT_ANSI__)
|
||||
#if !defined(__GNUC__) || defined(__STRICT_ANSI__) || !defined(__x86_64__)
|
||||
#define pushmov(d, x) (*(d) = (x))
|
||||
#else
|
||||
#define pushmov(d, x) \
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/intrin/fsgsbase.h"
|
||||
#ifdef __x86_64__
|
||||
|
||||
/**
|
||||
* Reads `%fs` base address.
|
||||
|
@ -26,3 +27,5 @@
|
|||
void *(_rdfsbase)(void) {
|
||||
return _rdfsbase();
|
||||
}
|
||||
|
||||
#endif /* __x86_64__ */
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/intrin/fsgsbase.h"
|
||||
#ifdef __x86_64__
|
||||
|
||||
/**
|
||||
* Reads `%gs` base address.
|
||||
|
@ -26,3 +27,5 @@
|
|||
void *(_rdgsbase)(void) {
|
||||
return _rdgsbase();
|
||||
}
|
||||
|
||||
#endif /* __x86_64__ */
|
||||
|
|
|
@ -18,13 +18,13 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.internal.h"
|
||||
|
||||
.align 8
|
||||
.balign 8
|
||||
shufpdjt:
|
||||
i=0
|
||||
.rept 256
|
||||
shufpd $i,%xmm1,%xmm0
|
||||
ret
|
||||
.align 8
|
||||
.balign 8
|
||||
i=i+1
|
||||
.endr
|
||||
.endfn shufpdjt,globl
|
||||
|
|
|
@ -18,13 +18,13 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.internal.h"
|
||||
|
||||
.align 8
|
||||
.balign 8
|
||||
shufpsjt:
|
||||
i=0
|
||||
.rept 256
|
||||
shufps $i,%xmm1,%xmm0
|
||||
ret
|
||||
.align 8
|
||||
.balign 8
|
||||
i=i+1
|
||||
.endr
|
||||
.endfn shufpsjt,globl
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
typedef char xmm_u __attribute__((__vector_size__(16), __aligned__(1)));
|
||||
typedef char xmm_t __attribute__((__vector_size__(16), __aligned__(16)));
|
||||
|
||||
#ifdef __x86_64__
|
||||
static inline noasan size_t stpcpy_sse2(char *d, const char *s, size_t i) {
|
||||
xmm_t v, z = {0};
|
||||
for (;;) {
|
||||
|
@ -34,6 +35,7 @@ static inline noasan size_t stpcpy_sse2(char *d, const char *s, size_t i) {
|
|||
}
|
||||
return i;
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Copies bytes from 𝑠 to 𝑑 until a NUL is encountered.
|
||||
|
@ -45,13 +47,15 @@ static inline noasan size_t stpcpy_sse2(char *d, const char *s, size_t i) {
|
|||
* @asyncsignalsafe
|
||||
*/
|
||||
char *stpcpy(char *d, const char *s) {
|
||||
size_t i;
|
||||
for (i = 0; (uintptr_t)(s + i) & 15; ++i) {
|
||||
size_t i = 0;
|
||||
#ifdef __x86_64__
|
||||
for (; (uintptr_t)(s + i) & 15; ++i) {
|
||||
if (!(d[i] = s[i])) {
|
||||
return d + i;
|
||||
}
|
||||
}
|
||||
i = stpcpy_sse2(d, s, i);
|
||||
#endif
|
||||
for (;;) {
|
||||
if (!(d[i] = s[i])) {
|
||||
return d + i;
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
typedef char xmm_u __attribute__((__vector_size__(16), __aligned__(1)));
|
||||
typedef char xmm_t __attribute__((__vector_size__(16), __aligned__(16)));
|
||||
|
||||
#ifdef __x86_64__
|
||||
static inline noasan size_t strcpy_sse2(char *d, const char *s, size_t i) {
|
||||
xmm_t v, z = {0};
|
||||
for (;;) {
|
||||
|
@ -34,6 +35,7 @@ static inline noasan size_t strcpy_sse2(char *d, const char *s, size_t i) {
|
|||
}
|
||||
return i;
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Copies bytes from 𝑠 to 𝑑 until a NUL is encountered.
|
||||
|
@ -45,13 +47,15 @@ static inline noasan size_t strcpy_sse2(char *d, const char *s, size_t i) {
|
|||
* @asyncsignalsafe
|
||||
*/
|
||||
char *strcpy(char *d, const char *s) {
|
||||
size_t i;
|
||||
for (i = 0; (uintptr_t)(s + i) & 15; ++i) {
|
||||
size_t i = 0;
|
||||
#ifdef __x86_64__
|
||||
for (; (uintptr_t)(s + i) & 15; ++i) {
|
||||
if (!(d[i] = s[i])) {
|
||||
return d;
|
||||
}
|
||||
}
|
||||
i = strcpy_sse2(d, s, i);
|
||||
#endif
|
||||
for (;;) {
|
||||
if (!(d[i] = s[i])) {
|
||||
return d;
|
||||
|
|
|
@ -30,6 +30,7 @@ typedef char xmm_t __attribute__((__vector_size__(16), __aligned__(16)));
|
|||
* @asyncsignalsafe
|
||||
*/
|
||||
noasan size_t strlen(const char *s) {
|
||||
#ifdef __x86_64__
|
||||
size_t n;
|
||||
xmm_t z = {0};
|
||||
unsigned m, k = (uintptr_t)s & 15;
|
||||
|
@ -39,4 +40,9 @@ noasan size_t strlen(const char *s) {
|
|||
while (!m) m = __builtin_ia32_pmovmskb128(*++p == z);
|
||||
n = (const char *)p + __builtin_ctzl(m) - s;
|
||||
return n;
|
||||
#else
|
||||
size_t n = 0;
|
||||
while (*s++) ++n;
|
||||
return n;
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.internal.h"
|
||||
.privileged
|
||||
.alignfunc
|
||||
.balignfunc
|
||||
|
||||
// Returns 𝑥-𝑦, aborting on overflow.
|
||||
//
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.internal.h"
|
||||
.privileged
|
||||
.alignfunc
|
||||
.balignfunc
|
||||
|
||||
// Returns 𝑥-𝑦, aborting on overflow.
|
||||
//
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.internal.h"
|
||||
.privileged
|
||||
.alignfunc
|
||||
.balignfunc
|
||||
|
||||
// Returns 𝑥-𝑦, aborting on overflow.
|
||||
//
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
__msabi extern typeof(GetCurrentThreadId) *const __imp_GetCurrentThreadId;
|
||||
|
||||
privileged int sys_gettid(void) {
|
||||
#ifdef __x86_64__
|
||||
int tid;
|
||||
int64_t wut;
|
||||
if (IsWindows()) {
|
||||
|
@ -61,4 +62,13 @@ privileged int sys_gettid(void) {
|
|||
tid = __pid;
|
||||
}
|
||||
return tid;
|
||||
#elif defined(__aarch64__)
|
||||
register long res_x0 asm("x0");
|
||||
asm volatile("mov\tx8,%1\n"
|
||||
"svc\t0"
|
||||
: "=r"(res_x0)
|
||||
: "i"(178)
|
||||
: "x8", "memory");
|
||||
return res_x0;
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -55,7 +55,7 @@ __syscall__:
|
|||
.endfn __syscall__,globl,hidden
|
||||
|
||||
.bss
|
||||
.align 8
|
||||
.balign 8
|
||||
.Lrcx: .quad 0 # clobbered by syscall
|
||||
.Lrdi: .quad 0 # just in case
|
||||
.Lrsi: .quad 0 # just in case
|
||||
|
|
|
@ -45,7 +45,7 @@ _tpenc: .leafprologue
|
|||
.endfn _tpenc,globl
|
||||
|
||||
.rodata
|
||||
.align 4
|
||||
.balign 4
|
||||
.underrun
|
||||
kTpenc: .rept 4 # MSB≤10 (0x7FF)
|
||||
.byte 1,0b11000000 # len,mark
|
||||
|
|
|
@ -4,10 +4,11 @@
|
|||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
#ifndef __STRICT_ANSI__
|
||||
|
||||
#define _weaken(symbol) \
|
||||
({ \
|
||||
asm(".weak\t" #symbol); \
|
||||
&symbol; \
|
||||
#define _weaken(symbol) \
|
||||
({ \
|
||||
typeof(&symbol) _p = &symbol; \
|
||||
asm(".weak\t" #symbol : "+r"(_p)); \
|
||||
_p; \
|
||||
})
|
||||
|
||||
#define _strongaddr(symbolstr) \
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/intrin/fsgsbase.h"
|
||||
#ifdef __x86_64__
|
||||
|
||||
/**
|
||||
* Changes `%fs` base address.
|
||||
|
@ -26,3 +27,5 @@
|
|||
void *(_wrfsbase)(void *p) {
|
||||
return _wrfsbase(p);
|
||||
}
|
||||
|
||||
#endif /* __x86_64__ */
|
||||
|
|
|
@ -67,10 +67,10 @@ noinstrument noasan int PrintBacktraceUsingSymbols(int fd,
|
|||
break;
|
||||
}
|
||||
addr = frame->addr;
|
||||
if (addr == _weakaddr("__gc")) {
|
||||
if (addr == (intptr_t)_weaken(__gc)) {
|
||||
do {
|
||||
--gi;
|
||||
} while ((addr = garbage->p[gi].ret) == _weakaddr("__gc"));
|
||||
} while ((addr = garbage->p[gi].ret) == (intptr_t)_weaken(__gc));
|
||||
}
|
||||
/*
|
||||
* we subtract one to handle the case of noreturn functions with a
|
||||
|
|
|
@ -21,14 +21,14 @@
|
|||
.yoink countbranch_report
|
||||
|
||||
.section .sort.data.countbranch.1,"a",@progbits
|
||||
.align 8
|
||||
.balign 8
|
||||
.underrun
|
||||
.globl countbranch_data
|
||||
countbranch_data:
|
||||
.previous
|
||||
|
||||
.section .sort.data.countbranch.3,"a",@progbits
|
||||
.align 8
|
||||
.balign 8
|
||||
.rept 5
|
||||
.quad -1
|
||||
.endr
|
||||
|
|
|
@ -22,14 +22,14 @@
|
|||
.yoink countexpr_report
|
||||
|
||||
.section .sort.data.countexpr.1,"a",@progbits
|
||||
.align 8
|
||||
.balign 8
|
||||
.globl countexpr_data
|
||||
.underrun
|
||||
countexpr_data:
|
||||
.previous
|
||||
|
||||
.section .sort.data.countexpr.3,"a",@progbits
|
||||
.align 8
|
||||
.balign 8
|
||||
.quad 0
|
||||
.overrun
|
||||
.previous
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_LOG_GDB_H_
|
||||
#define COSMOPOLITAN_LIBC_LOG_GDB_H_
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/struct/rusage.h"
|
||||
#include "libc/calls/wait4.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/sysv/consts/nr.h"
|
||||
|
@ -41,6 +42,7 @@ int AttachDebugger(intptr_t);
|
|||
Pid; \
|
||||
})
|
||||
|
||||
#ifdef __x86_64__
|
||||
#define __inline_wait4(PID, OPT_OUT_WSTATUS, OPTIONS, OPT_OUT_RUSAGE) \
|
||||
({ \
|
||||
int64_t WaAx; \
|
||||
|
@ -56,6 +58,9 @@ int AttachDebugger(intptr_t);
|
|||
} \
|
||||
WaAx; \
|
||||
})
|
||||
#else
|
||||
#define __inline_wait4 wait4
|
||||
#endif
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
|
|
|
@ -17,6 +17,15 @@ forceinline long __sysv_exit(long rc) {
|
|||
: "=a"(ax)
|
||||
: "0"(__NR_exit_group), "D"(rc)
|
||||
: "memory", "cc");
|
||||
#elif defined(__aarch64__)
|
||||
register long r0 asm("x0") = rc;
|
||||
register long res_x0 asm("x0");
|
||||
asm volatile("mov\tx8,%1\n"
|
||||
"svc\t0"
|
||||
: "=r"(res_x0)
|
||||
: "i"(94), "r"(r0)
|
||||
: "x8", "memory");
|
||||
ax = res_x0;
|
||||
#else
|
||||
ax = syscall(__NR_exit_group, rc);
|
||||
#endif
|
||||
|
@ -30,6 +39,15 @@ forceinline int __sysv_close(long fd) {
|
|||
: "=a"(ax)
|
||||
: "0"(__NR_close), "D"(fd)
|
||||
: "rdx", "memory", "cc");
|
||||
#elif defined(__aarch64__)
|
||||
register long r0 asm("x0") = fd;
|
||||
register long res_x0 asm("x0");
|
||||
asm volatile("mov\tx8,%1\n"
|
||||
"svc\t0"
|
||||
: "=r"(res_x0)
|
||||
: "i"(57), "r"(r0)
|
||||
: "x8", "memory");
|
||||
ax = res_x0;
|
||||
#else
|
||||
ax = syscall(__NR_close, fd);
|
||||
#endif
|
||||
|
@ -43,6 +61,18 @@ forceinline int __sysv_open(const char *path, long flags, long mode) {
|
|||
: "=a"(ax), "=d"(dx)
|
||||
: "0"(__NR_open), "D"(path), "S"(flags), "1"(mode)
|
||||
: "memory", "cc");
|
||||
#elif defined(__aarch64__)
|
||||
register long r0 asm("x0") = -100;
|
||||
register long r1 asm("x1") = (long)path;
|
||||
register long r2 asm("x2") = (long)flags;
|
||||
register long r3 asm("x3") = (long)mode;
|
||||
register long res_x0 asm("x0");
|
||||
asm volatile("mov\tx8,%1\n"
|
||||
"svc\t0"
|
||||
: "=r"(res_x0)
|
||||
: "i"(56), "r"(r0), "r"(r1), "r"(r2), "r"(r3)
|
||||
: "x8", "memory");
|
||||
ax = res_x0;
|
||||
#else
|
||||
ax = syscall(__NR_open, path, flags, mode);
|
||||
#endif
|
||||
|
@ -56,6 +86,17 @@ forceinline long __sysv_read(long fd, void *data, unsigned long size) {
|
|||
: "=a"(ax), "=d"(dx)
|
||||
: "0"(__NR_read), "D"(fd), "S"(data), "1"(size)
|
||||
: "memory", "cc");
|
||||
#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 res_x0 asm("x0");
|
||||
asm volatile("mov\tx8,%1\n"
|
||||
"svc\t0"
|
||||
: "=r"(res_x0)
|
||||
: "i"(63), "r"(r0), "r"(r1), "r"(r2)
|
||||
: "x8", "memory");
|
||||
ax = res_x0;
|
||||
#else
|
||||
ax = syscall(__NR_read, fd, data, size);
|
||||
#endif
|
||||
|
@ -69,6 +110,17 @@ forceinline long __sysv_write(long fd, const void *data, unsigned long size) {
|
|||
: "=a"(ax), "=d"(dx)
|
||||
: "0"(__NR_write), "D"(fd), "S"(data), "1"(size)
|
||||
: "memory", "cc");
|
||||
#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 res_x0 asm("x0");
|
||||
asm volatile("mov\tx8,%1\n"
|
||||
"svc\t0"
|
||||
: "=r"(res_x0)
|
||||
: "i"(64), "r"(r0), "r"(r1), "r"(r2)
|
||||
: "x8", "memory");
|
||||
ax = res_x0;
|
||||
#else
|
||||
ax = syscall(__NR_write, fd, data, size);
|
||||
#endif
|
||||
|
@ -82,6 +134,17 @@ forceinline long __sysv_mprotect(void *addr, size_t size, long prot) {
|
|||
: "=a"(ax), "=d"(dx)
|
||||
: "0"(__NR_mprotect), "D"(addr), "S"(size), "1"(prot)
|
||||
: "memory", "cc");
|
||||
#elif defined(__aarch64__)
|
||||
register long r0 asm("x0") = (long)addr;
|
||||
register long r1 asm("x1") = (long)size;
|
||||
register long r2 asm("x2") = (long)prot;
|
||||
register long res_x0 asm("x0");
|
||||
asm volatile("mov\tx8,%1\n"
|
||||
"svc\t0"
|
||||
: "=r"(res_x0)
|
||||
: "i"(226), "r"(r0), "r"(r1), "r"(r2)
|
||||
: "x8", "memory");
|
||||
ax = res_x0;
|
||||
#else
|
||||
ax = syscall(__NR_mprotect, addr, size, prot);
|
||||
#endif
|
||||
|
@ -95,6 +158,14 @@ forceinline int __sysv_getpid(void) {
|
|||
: "=a"(ax)
|
||||
: "0"(__NR_getpid)
|
||||
: "rdx", "memory", "cc");
|
||||
#elif defined(__aarch64__)
|
||||
register long res_x0 asm("x0");
|
||||
asm volatile("mov\tx8,%1\n"
|
||||
"svc\t0"
|
||||
: "=r"(res_x0)
|
||||
: "i"(172)
|
||||
: "x8", "memory");
|
||||
ax = res_x0;
|
||||
#else
|
||||
ax = syscall(__NR_getpid);
|
||||
#endif
|
||||
|
|
|
@ -210,7 +210,7 @@ void _log_exit(int) wontreturn;
|
|||
|
||||
#define ARGS unsigned, const char *, int, FILE *, const char *
|
||||
#define ATTR paramsnonnull((5)) printfesque(5)
|
||||
#define ATTRV paramsnonnull((5, 6))
|
||||
#define ATTRV paramsnonnull((5))
|
||||
void flogf(ARGS, ...) ATTR libcesque;
|
||||
void vflogf(ARGS, va_list) ATTRV libcesque;
|
||||
void fverbosef(ARGS, ...) asm("flogf") ATTR relegated libcesque;
|
||||
|
|
26
libc/log/logfile.c
Normal file
26
libc/log/logfile.c
Normal file
|
@ -0,0 +1,26 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2020 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
│ above copyright notice and this permission notice appear in all copies. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
||||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
||||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
||||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
||||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/log/log.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
|
||||
FILE *__log_file;
|
||||
|
||||
__attribute__((__constructor__)) static void init(void) {
|
||||
__log_file = stderr;
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2020 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
│ above copyright notice and this permission notice appear in all copies. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
||||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
||||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
||||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
||||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/intrin/initializer.internal.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
|
||||
FILE *__log_file;
|
||||
|
||||
INITIALIZER(401, _init_log_file, (__log_file = stderr));
|
|
@ -20,7 +20,7 @@
|
|||
#include "libc/macros.internal.h"
|
||||
|
||||
.bss
|
||||
.align 4
|
||||
.balign 4
|
||||
__log_level:
|
||||
.long 0
|
||||
.endobj __log_level,globl
|
||||
|
|
|
@ -13,20 +13,20 @@
|
|||
#define TRUE 1
|
||||
#define FALSE 0
|
||||
|
||||
#define IS2POW(X) (!((X) & ((X)-1)))
|
||||
#define ROUNDUP(X, K) (((X) + (K)-1) & -(K))
|
||||
#define ROUNDDOWN(X, K) ((X) & -(K))
|
||||
#define IS2POW(X) (!((X) & ((X)-1)))
|
||||
#define ROUNDUP(X, K) (((X) + (K)-1) & -(K))
|
||||
#define ROUNDDOWN(X, K) ((X) & -(K))
|
||||
#ifndef __ASSEMBLER__
|
||||
#define ABS(X) ((X) >= 0 ? (X) : -(X))
|
||||
#define MIN(X, Y) ((Y) > (X) ? (X) : (Y))
|
||||
#define MAX(X, Y) ((Y) < (X) ? (X) : (Y))
|
||||
#define ABS(X) ((X) >= 0 ? (X) : -(X))
|
||||
#define MIN(X, Y) ((Y) > (X) ? (X) : (Y))
|
||||
#define MAX(X, Y) ((Y) < (X) ? (X) : (Y))
|
||||
#else
|
||||
// The GNU assembler does not grok the ?: ternary operator; furthermore,
|
||||
// boolean expressions yield -1 and 0 for "true" and "false", not 1 and 0.
|
||||
#define __MAPBOOL(P) (!!(P) / (!!(P) + !(P)))
|
||||
#define __IFELSE(P, X, Y) (__MAPBOOL(P) * (X) + __MAPBOOL(!(P)) * (Y))
|
||||
#define MIN(X, Y) (__IFELSE((Y) > (X), (X), (Y)))
|
||||
#define MAX(X, Y) (__IFELSE((Y) < (X), (X), (Y)))
|
||||
#define __MAPBOOL(P) (!!(P) / (!!(P) + !(P)))
|
||||
#define __IFELSE(P, X, Y) (__MAPBOOL(P) * (X) + __MAPBOOL(!(P)) * (Y))
|
||||
#define MIN(X, Y) (__IFELSE((Y) > (X), (X), (Y)))
|
||||
#define MAX(X, Y) (__IFELSE((Y) < (X), (X), (Y)))
|
||||
#endif
|
||||
#define PASTE(A, B) __PASTE(A, B)
|
||||
#define STRINGIFY(A) __STRINGIFY(A)
|
||||
|
@ -43,9 +43,31 @@
|
|||
#ifdef __ASSEMBLER__
|
||||
// clang-format off
|
||||
|
||||
#if __MNO_VZEROUPPER__ + 0
|
||||
#define vzeroupper
|
||||
#endif
|
||||
// Ends function definition.
|
||||
// @cost saves 1-3 lines of code
|
||||
.macro .endfn name:req bnd vis
|
||||
.size "\name",.-"\name"
|
||||
.type "\name",@function
|
||||
.ifnb \bnd
|
||||
.\bnd "\name"
|
||||
.endif
|
||||
.ifnb \vis
|
||||
.\vis "\name"
|
||||
.endif
|
||||
.endm
|
||||
|
||||
// Ends variable definition.
|
||||
// @cost saves 1-3 lines of code
|
||||
.macro .endobj name:req bnd vis
|
||||
.size "\name",.-"\name"
|
||||
.type "\name",@object
|
||||
.ifnb \bnd
|
||||
.\bnd "\name"
|
||||
.endif
|
||||
.ifnb \vis
|
||||
.\vis "\name"
|
||||
.endif
|
||||
.endm
|
||||
|
||||
// Shorthand notation for widely-acknowledged sections.
|
||||
.macro .rodata
|
||||
|
@ -77,7 +99,7 @@
|
|||
.endm
|
||||
.macro .text.modernity
|
||||
.section .text.modernity,"ax",@progbits
|
||||
.align 16
|
||||
.balign 16
|
||||
.endm
|
||||
.macro .text.antiquity
|
||||
.section .text.antiquity,"ax",@progbits
|
||||
|
@ -95,6 +117,51 @@
|
|||
.section .text.windows,"ax",@progbits
|
||||
.endm
|
||||
|
||||
// Mergeable NUL-terminated UTF-8 string constant section.
|
||||
//
|
||||
// @note linker de-dupes C strings here across whole compile
|
||||
// @note therefore item/values are reordered w.r.t. link order
|
||||
// @note therefore no section relative addressing
|
||||
.macro .rodata.str1.1
|
||||
.section .rodata.str1.1,"aMS",@progbits,1
|
||||
.align 1
|
||||
.endm
|
||||
|
||||
// Locates unreferenced code invulnerable to --gc-sections.
|
||||
.macro .keep.text
|
||||
.section .keep.text,"ax",@progbits
|
||||
.endm
|
||||
|
||||
// Flags code as only allowed for testing purposes.
|
||||
.macro .testonly
|
||||
.section .test,"ax",@progbits
|
||||
.endm
|
||||
|
||||
// Makes code runnable while code morphing.
|
||||
.macro .privileged
|
||||
.section .privileged,"ax",@progbits
|
||||
.endm
|
||||
|
||||
// Pulls unrelated module into linkage.
|
||||
//
|
||||
// In order for this technique to work with --gc-sections, another
|
||||
// module somewhere might want to weakly reference whats yoinked.
|
||||
.macro .yoink symbol:req
|
||||
.section .yoink
|
||||
#ifdef __x86_64__
|
||||
nopl "\symbol"(%rip)
|
||||
#elif defined(__aarch64__)
|
||||
b "\symbol"
|
||||
#endif
|
||||
.previous
|
||||
.endm
|
||||
|
||||
#ifdef __x86_64__
|
||||
|
||||
#if __MNO_VZEROUPPER__ + 0
|
||||
#define vzeroupper
|
||||
#endif
|
||||
|
||||
// Mergeable numeric constant sections.
|
||||
//
|
||||
// @note linker de-dupes item/values across whole compile
|
||||
|
@ -129,31 +196,6 @@
|
|||
.align 4
|
||||
.endm
|
||||
|
||||
// Mergeable NUL-terminated UTF-8 string constant section.
|
||||
//
|
||||
// @note linker de-dupes C strings here across whole compile
|
||||
// @note therefore item/values are reordered w.r.t. link order
|
||||
// @note therefore no section relative addressing
|
||||
.macro .rodata.str1.1
|
||||
.section .rodata.str1.1,"aMS",@progbits,1
|
||||
.align 1
|
||||
.endm
|
||||
|
||||
// Locates unreferenced code invulnerable to --gc-sections.
|
||||
.macro .keep.text
|
||||
.section .keep.text,"ax",@progbits
|
||||
.endm
|
||||
|
||||
// Flags code as only allowed for testing purposes.
|
||||
.macro .testonly
|
||||
.section .test,"ax",@progbits
|
||||
.endm
|
||||
|
||||
// Makes code runnable while code morphing.
|
||||
.macro .privileged
|
||||
.section .privileged,"ax",@progbits
|
||||
.endm
|
||||
|
||||
// Loads address of errno into %rcx
|
||||
.macro .errno
|
||||
call __errno_location
|
||||
|
@ -197,32 +239,6 @@
|
|||
.weak \canonical
|
||||
.endm
|
||||
|
||||
// Ends function definition.
|
||||
// @cost saves 1-3 lines of code
|
||||
.macro .endfn name:req bnd vis
|
||||
.size "\name",.-"\name"
|
||||
.type "\name",@function
|
||||
.ifnb \bnd
|
||||
.\bnd "\name"
|
||||
.endif
|
||||
.ifnb \vis
|
||||
.\vis "\name"
|
||||
.endif
|
||||
.endm
|
||||
|
||||
// Ends variable definition.
|
||||
// @cost saves 1-3 lines of code
|
||||
.macro .endobj name:req bnd vis
|
||||
.size "\name",.-"\name"
|
||||
.type "\name",@object
|
||||
.ifnb \bnd
|
||||
.\bnd "\name"
|
||||
.endif
|
||||
.ifnb \vis
|
||||
.\vis "\name"
|
||||
.endif
|
||||
.endm
|
||||
|
||||
// LOOP Instruction Replacement.
|
||||
.macro .loop label:req
|
||||
.byte 0x83
|
||||
|
@ -341,16 +357,6 @@
|
|||
.byte 0x0f,0x1f,0x40,0x00
|
||||
.endm
|
||||
|
||||
// Pulls unrelated module into linkage.
|
||||
//
|
||||
// In order for this technique to work with --gc-sections, another
|
||||
// module somewhere might want to weakly reference whats yoinked.
|
||||
.macro .yoink symbol:req
|
||||
.section .yoink
|
||||
nopl "\symbol"(%rip)
|
||||
.previous
|
||||
.endm
|
||||
|
||||
// Calls Windows function.
|
||||
//
|
||||
// @param cx,dx,r8,r9,stack
|
||||
|
@ -542,6 +548,14 @@
|
|||
#endif
|
||||
.endm
|
||||
|
||||
#else
|
||||
|
||||
.macro .underrun
|
||||
.endm
|
||||
.macro .overrun
|
||||
.endm
|
||||
|
||||
// clang-format on
|
||||
#endif /* __x86_64__ */
|
||||
#endif /* __ASSEMBLER__ */
|
||||
#endif /* COSMOPOLITAN_LIBC_MACROS_H_ */
|
||||
|
|
23
libc/nexgen32e/auxv2.c
Normal file
23
libc/nexgen32e/auxv2.c
Normal file
|
@ -0,0 +1,23 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2023 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
│ above copyright notice and this permission notice appear in all copies. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
||||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
||||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
||||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
||||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/runtime/runtime.h"
|
||||
|
||||
#ifdef __aarch64__
|
||||
unsigned long *__auxv;
|
||||
#endif
|
|
@ -21,7 +21,7 @@
|
|||
|
||||
// Environment variable pointer list.
|
||||
.bss
|
||||
.align 8
|
||||
.balign 8
|
||||
environ:
|
||||
.quad 0
|
||||
.endobj environ,globl
|
||||
|
|
23
libc/nexgen32e/environ2.c
Normal file
23
libc/nexgen32e/environ2.c
Normal file
|
@ -0,0 +1,23 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2023 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
│ above copyright notice and this permission notice appear in all copies. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
||||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
||||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
||||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
||||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/runtime/runtime.h"
|
||||
|
||||
#ifdef __aarch64__
|
||||
char **environ;
|
||||
#endif
|
|
@ -30,7 +30,7 @@ imapxlatab:
|
|||
pushpop 32,%rcx
|
||||
mov $0x0706050403020100,%rax
|
||||
mov $0x0808080808080808,%rdx
|
||||
.align 8
|
||||
.balign 8
|
||||
1: stosq
|
||||
add %rdx,%rax
|
||||
.loop 1b
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.internal.h"
|
||||
.rodata
|
||||
.align 16
|
||||
.balign 16
|
||||
|
||||
// ibm cp437 unicode table w/ string literal safety
|
||||
//
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
#include "libc/macros.internal.h"
|
||||
|
||||
.rodata
|
||||
.align 64
|
||||
.balign 64
|
||||
kSha256:
|
||||
.long 0x428a2f98,0x71374491,0xb5c0fbcf,0xe9b5dba5
|
||||
.long 0x3956c25b,0x59f111f1,0x923f82a4,0xab1c5ed5
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
#include "libc/macros.internal.h"
|
||||
|
||||
.rodata
|
||||
.align 64
|
||||
.balign 64
|
||||
kSha512:
|
||||
.quad 0x428a2f98d728ae22,0x7137449123ef65cd
|
||||
.quad 0xb5c0fbcfec4d3b2f,0xe9b5dba58189dbbc
|
||||
|
|
|
@ -47,6 +47,10 @@ o/$(MODE)/libc/nexgen32e/threaded.o: private \
|
|||
$(NO_MAGIC) \
|
||||
-fno-sanitize=all
|
||||
|
||||
# these assembly files are safe to build on aarch64
|
||||
o/$(MODE)/libc/nexgen32e/kreversebits.o: libc/nexgen32e/kreversebits.S
|
||||
@$(COMPILE) -AOBJECTIFY.S $(OBJECTIFY.S) $(OUTPUT_OPTION) -c $<
|
||||
|
||||
LIBC_NEXGEN32E_LIBS = $(foreach x,$(LIBC_NEXGEN32E_ARTIFACTS),$($(x)))
|
||||
LIBC_NEXGEN32E_SRCS = $(foreach x,$(LIBC_NEXGEN32E_ARTIFACTS),$($(x)_SRCS))
|
||||
LIBC_NEXGEN32E_HDRS = $(foreach x,$(LIBC_NEXGEN32E_ARTIFACTS),$($(x)_HDRS))
|
||||
|
|
|
@ -32,12 +32,21 @@ COSMOPOLITAN_C_START_
|
|||
#define mfence_lfence_rdtsc_lfence() \
|
||||
__RDTSC("mfence\n\tlfence\n\trdtsc\n\tlfence")
|
||||
|
||||
#ifdef __x86__
|
||||
#define __RDTSC(ASM) \
|
||||
({ \
|
||||
uint64_t Rax, Rdx; \
|
||||
asm volatile(ASM : "=a"(Rax), "=d"(Rdx) : /* no inputs */ : "memory"); \
|
||||
Rdx << 32 | Rax; \
|
||||
})
|
||||
#elif defined(__aarch64__)
|
||||
#define __RDTSC(ASM) \
|
||||
({ \
|
||||
uint64_t _Ts; \
|
||||
asm volatile("mrs\t%0,cntvct_el0" : "=r"(_Ts)); \
|
||||
_Ts * 48; /* the fudge factor */ \
|
||||
})
|
||||
#endif
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
|
|
|
@ -432,7 +432,7 @@ Copyright 2014 Intel Corporation\n"
|
|||
ADD_IF_GE BUFFER_PTR2, BLOCKS_CTR, 4, 128
|
||||
xchg WK_BUF, PRECALC_BUF
|
||||
|
||||
.align 32
|
||||
.balign 32
|
||||
.L_loop:
|
||||
|
||||
// code loops through more than one block
|
||||
|
@ -440,10 +440,10 @@ Copyright 2014 Intel Corporation\n"
|
|||
// it is set below by: cmovae BUFFER_PTR, K_BASE
|
||||
test BLOCKS_CTR, BLOCKS_CTR
|
||||
jnz .L_begin
|
||||
.align 32
|
||||
.balign 32
|
||||
jmp .L_end
|
||||
|
||||
.align 32
|
||||
.balign 32
|
||||
.L_begin:
|
||||
|
||||
// process first block
|
||||
|
@ -562,7 +562,7 @@ Copyright 2014 Intel Corporation\n"
|
|||
|
||||
jmp .L_loop
|
||||
|
||||
.align 32
|
||||
.balign 32
|
||||
.L_end:
|
||||
|
||||
.endm
|
||||
|
@ -574,7 +574,7 @@ Copyright 2014 Intel Corporation\n"
|
|||
#define K3 0x8f1bbcdc
|
||||
#define K4 0xca62c1d6
|
||||
|
||||
.align 128
|
||||
.balign 128
|
||||
K_XMM_AR:
|
||||
.long K1,K1,K1,K1
|
||||
.long K1,K1,K1,K1
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
#include "libc/macros.internal.h"
|
||||
|
||||
.text
|
||||
.align 32
|
||||
.balign 32
|
||||
.ident "\n\
|
||||
Intel SHA-NI (BSD-3 License)\n\
|
||||
Copyright 2015 Intel Corporation\n\
|
||||
|
@ -276,11 +276,11 @@ sha1_transform_ni:
|
|||
.endfn sha1_transform_ni,globl
|
||||
|
||||
.section .rodata.cst16.PSHUFFLE_BYTE_FLIP_MASK, "aM", @progbits, 16
|
||||
.align 16
|
||||
.balign 16
|
||||
PSHUFFLE_BYTE_FLIP_MASK:
|
||||
.octa 0x000102030405060708090a0b0c0d0e0f
|
||||
|
||||
.section .rodata.cst16.UPPER_WORD_MASK, "aM", @progbits, 16
|
||||
.align 16
|
||||
.balign 16
|
||||
UPPER_WORD_MASK:
|
||||
.octa 0xFFFFFFFF000000000000000000000000
|
||||
|
|
|
@ -529,7 +529,7 @@ STACK_SIZE = _RSP + _RSP_SIZE
|
|||
## arg 3 : Num blocks
|
||||
########################################################################
|
||||
.text
|
||||
.align 32
|
||||
.balign 32
|
||||
sha256_transform_rorx:
|
||||
push %rbp
|
||||
mov %rsp,%rbp
|
||||
|
@ -596,7 +596,7 @@ sha256_transform_rorx:
|
|||
## schedule 48 input dwords, by doing 3 rounds of 12 each
|
||||
xor SRND, SRND
|
||||
|
||||
.align 16
|
||||
.balign 16
|
||||
.Loop1:
|
||||
vpaddd kSha256x2+0*32(SRND), X0, XFER
|
||||
vmovdqa XFER, 0*32+_XFER(%rsp, SRND)
|
||||
|
@ -652,7 +652,7 @@ sha256_transform_rorx:
|
|||
|
||||
#### Do second block using previously scheduled results
|
||||
xor SRND, SRND
|
||||
.align 16
|
||||
.balign 16
|
||||
.Loop3:
|
||||
DO_4ROUNDS _XFER + 0*32 + 16
|
||||
DO_4ROUNDS _XFER + 1*32 + 16
|
||||
|
@ -739,7 +739,7 @@ _SHUF_DC00:
|
|||
.octa 0x0b0a090803020100FFFFFFFFFFFFFFFF
|
||||
|
||||
.bss
|
||||
.align 64
|
||||
.balign 64
|
||||
kSha256x2:
|
||||
.zero 512
|
||||
.endobj kSha256x2,globl
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
#include "libc/macros.internal.h"
|
||||
|
||||
.text
|
||||
.align 32
|
||||
.balign 32
|
||||
.ident "\n\
|
||||
Intel SHA-NI (BSD-3 License)\n\
|
||||
Copyright 2015 Intel Corporation\n\
|
||||
|
@ -312,7 +312,7 @@ sha256_transform_ni:
|
|||
.endfn sha256_transform_ni,globl
|
||||
|
||||
.section .rodata.cst16.PSHUFFLE_BYTE_FLIP_MASK,"aM",@progbits,16
|
||||
.align 16
|
||||
.balign 16
|
||||
PSHUFFLE_BYTE_FLIP_MASK:
|
||||
.octa 0x0c0d0e0f08090a0b0405060700010203
|
||||
.endobj PSHUFFLE_BYTE_FLIP_MASK
|
||||
|
|
|
@ -622,7 +622,7 @@ sha512_transform_rorx:
|
|||
## schedule 64 input dwords, by doing 12 rounds of 4 each
|
||||
movq $4, frame_SRND(%rsp)
|
||||
|
||||
.align 16
|
||||
.balign 16
|
||||
.Loop1:
|
||||
vpaddq (TBL), Y_0, XFER
|
||||
vmovdqa XFER, frame_XFER(%rsp)
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue