diff --git a/VERSION b/VERSION index 3eefcb9..9084fa2 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.0.0 +1.1.0 diff --git a/docs/usage.md b/docs/usage.md index baddb8a..c49eb95 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -15,9 +15,11 @@ Built by NBTFoundry from LLVM and picolibc sources; not an LLVM release. `-objcopy`, `-strip`, `-objdump`, `-readobj`, `-readelf`, `-size`, `-symbolizer`, `-addr2line`, `-cxxfilt`. Their only target is ARM. - `armv7a-nbt/include/`: the NBT C library headers (threads, semaphores, the - bridge's sockets, directories), implemented by the SDK's module runtime. + bridge's sockets, directories, anonymous and executable memory mappings, + ARM CPU feature bits), implemented by the SDK's module runtime. - `armv7a-nbt/aligned/` and `armv7a-nbt/unaligned/`: picolibc, compiler-rt - builtins (with emulated TLS) and libc++, libc++abi and libunwind, built with + builtins (with emulated TLS; `__clear_cache` comes from the SDK's module + runtime) and libc++, libc++abi and libunwind, built with strict alignment or allowing unaligned accesses. Each `target.mk` holds the flags code linking that runtime must be compiled with. - `share/licenses/`: the licences of everything above. diff --git a/libc/include/asm/hwcap.h b/libc/include/asm/hwcap.h new file mode 100644 index 0000000..ba61975 --- /dev/null +++ b/libc/include/asm/hwcap.h @@ -0,0 +1,39 @@ +/* SPDX-License-Identifier: MPL-2.0 */ +/* ARM CPU feature bits, as Linux numbers them for getauxval(AT_HWCAP) and + * getauxval(AT_HWCAP2) (), so portable feature probes compile. + * The SDK's module runtime reports none of these optional features: code + * takes its baseline paths (ARMv7-A, VFPv3-D16, no NEON). */ +#ifndef NBT_MODULE_ASM_HWCAP_H +#define NBT_MODULE_ASM_HWCAP_H + +#define HWCAP_SWP (1 << 0) +#define HWCAP_HALF (1 << 1) +#define HWCAP_THUMB (1 << 2) +#define HWCAP_26BIT (1 << 3) +#define HWCAP_FAST_MULT (1 << 4) +#define HWCAP_FPA (1 << 5) +#define HWCAP_VFP (1 << 6) +#define HWCAP_EDSP (1 << 7) +#define HWCAP_JAVA (1 << 8) +#define HWCAP_IWMMXT (1 << 9) +#define HWCAP_CRUNCH (1 << 10) +#define HWCAP_THUMBEE (1 << 11) +#define HWCAP_NEON (1 << 12) +#define HWCAP_VFPv3 (1 << 13) +#define HWCAP_VFPv3D16 (1 << 14) +#define HWCAP_TLS (1 << 15) +#define HWCAP_VFPv4 (1 << 16) +#define HWCAP_IDIVA (1 << 17) +#define HWCAP_IDIVT (1 << 18) +#define HWCAP_VFPD32 (1 << 19) +#define HWCAP_IDIV (HWCAP_IDIVA | HWCAP_IDIVT) +#define HWCAP_LPAE (1 << 20) +#define HWCAP_EVTSTRM (1 << 21) + +#define HWCAP2_AES (1 << 0) +#define HWCAP2_PMULL (1 << 1) +#define HWCAP2_SHA1 (1 << 2) +#define HWCAP2_SHA2 (1 << 3) +#define HWCAP2_CRC32 (1 << 4) + +#endif diff --git a/libc/include/pthread.h b/libc/include/pthread.h index e08e0b2..3add4a1 100644 --- a/libc/include/pthread.h +++ b/libc/include/pthread.h @@ -56,6 +56,12 @@ typedef struct { #define PTHREAD_CREATE_JOINABLE 0 #define PTHREAD_CREATE_DETACHED 1 +/* Threads take the application's scheduling: the policy and priority + * attributes are accepted and, as POSIX has it under PTHREAD_INHERIT_SCHED, + * unused; PTHREAD_EXPLICIT_SCHED is refused (ENOTSUP). */ +#define PTHREAD_INHERIT_SCHED 0 +#define PTHREAD_EXPLICIT_SCHED 1 + #define PTHREAD_MUTEX_INITIALIZER {0, PTHREAD_MUTEX_NORMAL, 0, 0} #define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP {0, PTHREAD_MUTEX_RECURSIVE, 0, 0} #define PTHREAD_COND_INITIALIZER {0, 0} @@ -70,6 +76,12 @@ int pthread_attr_setstacksize(pthread_attr_t* attr, size_t size); int pthread_attr_getstacksize(const pthread_attr_t* attr, size_t* size); int pthread_attr_setdetachstate(pthread_attr_t* attr, int state); int pthread_attr_getdetachstate(const pthread_attr_t* attr, int* state); +int pthread_attr_setinheritsched(pthread_attr_t* attr, int inherit); +int pthread_attr_getinheritsched(const pthread_attr_t* attr, int* inherit); +int pthread_attr_setschedpolicy(pthread_attr_t* attr, int policy); +int pthread_attr_getschedpolicy(const pthread_attr_t* attr, int* policy); +int pthread_attr_setschedparam(pthread_attr_t* attr, const struct sched_param* param); +int pthread_attr_getschedparam(const pthread_attr_t* attr, struct sched_param* param); int pthread_create(pthread_t* thread, const pthread_attr_t* attr, void* (*fn)(void*), void* arg); int pthread_join(pthread_t thread, void** result); diff --git a/libc/include/sys/mman.h b/libc/include/sys/mman.h new file mode 100644 index 0000000..4be72ee --- /dev/null +++ b/libc/include/sys/mman.h @@ -0,0 +1,38 @@ +/* SPDX-License-Identifier: MPL-2.0 */ +/* Memory mappings for NBT app modules, as JIT compilers use them: anonymous + * private mappings, protection changes (executable pages included) and, from + * the compiler, __clear_cache. The SDK's module runtime implements them over + * the host ABI (sdk/module/runtime/mman.c). There are no file mappings: mmap + * with a descriptor fails with ENODEV, MAP_FIXED with EINVAL, and an address + * hint is ignored. */ +#ifndef NBT_MODULE_SYS_MMAN_H +#define NBT_MODULE_SYS_MMAN_H + +#include /* off_t, size_t */ + +#ifdef __cplusplus +extern "C" { +#endif + +#define PROT_NONE 0x0 +#define PROT_READ 0x1 +#define PROT_WRITE 0x2 +#define PROT_EXEC 0x4 + +#define MAP_SHARED 0x01 +#define MAP_PRIVATE 0x02 +#define MAP_FIXED 0x10 +#define MAP_ANONYMOUS 0x20 +#define MAP_ANON MAP_ANONYMOUS + +#define MAP_FAILED ((void*)-1) + +void* mmap(void* addr, size_t len, int prot, int flags, int fd, off_t offset); +int munmap(void* addr, size_t len); +int mprotect(void* addr, size_t len, int prot); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/scripts/build-runtime.sh b/scripts/build-runtime.sh index 2e115b8..76a1092 100755 --- a/scripts/build-runtime.sh +++ b/scripts/build-runtime.sh @@ -108,6 +108,10 @@ EOF "$LLVM_BIN/clang" --target=$TRIPLE $FLAGS $DEFS $LIBC_INC -O2 -std=gnu11 -fvisibility=hidden -I"$SRC/compiler-rt/lib/builtins" \ -c "$SRC/compiler-rt/lib/builtins/emutls.c" -o "$W/emutls.o" "$LLVM_BIN/llvm-ar" rs "$V/builtins/libclang_rt.builtins.a" "$W/emutls.o" + # A bare-metal __clear_cache aborts: the module runtime has the real one + # (the host's instruction cache flush), so code linked without it fails to + # link instead of aborting when it first flushes. + "$LLVM_BIN/llvm-ar" d "$V/builtins/libclang_rt.builtins.a" clear_cache.c.obj # --- libc++, libc++abi, libunwind --- # Static, over picolibc (which libc++ treats as newlib) and the NBT diff --git a/tests/sdk b/tests/sdk index 663da19..d6e8eb8 160000 --- a/tests/sdk +++ b/tests/sdk @@ -1 +1 @@ -Subproject commit 663da19d082429408abdd8373e7e20fc91950758 +Subproject commit d6e8eb886ce2bbc849d80fa4b617170ac233409a