diff --git a/arch/arm/Makefile b/arch/arm/Makefile index 69be5239..9b7fe83b 100644 --- a/arch/arm/Makefile +++ b/arch/arm/Makefile @@ -10,6 +10,8 @@ ifneq (,$(findstring v7a,$(TARGET_SUFF))) include arch/arm/v7a/Makefile else ifneq (,$(findstring v7m,$(TARGET_SUFF))) include arch/arm/v7m/Makefile +else ifneq (,$(findstring v8m,$(TARGET_SUFF))) + include arch/arm/v8m/Makefile else ifneq (,$(findstring v8r,$(TARGET_SUFF))) include arch/arm/v8r/Makefile else diff --git a/arch/arm/v8m/Makefile b/arch/arm/v8m/Makefile new file mode 100644 index 00000000..470b2fb9 --- /dev/null +++ b/arch/arm/v8m/Makefile @@ -0,0 +1,8 @@ +# +# Makefile for libphoenix/arch/arm/v8m +# +# Copyright 2017, 2020, 2024 Phoenix Systems +# Author: Pawel Pisarczyk +# + +OBJS += $(addprefix $(PREFIX_O)arch/arm/v8m/, syscalls.o reboot.o tls.o) diff --git a/arch/arm/v8m/reboot.c b/arch/arm/v8m/reboot.c new file mode 100644 index 00000000..2b7d8ff1 --- /dev/null +++ b/arch/arm/v8m/reboot.c @@ -0,0 +1,56 @@ +/* + * Phoenix-RTOS + * + * libphoenix + * + * reboot.c + * + * Copyright 2019, 2024 Phoenix Systems + * Author: Jan Sikorski, Aleksander Kaminski + * + * This file is part of Phoenix-RTOS. + * + * %LICENSE% + */ + +#include +#include + +#if defined(__CPU_NRF9160) +#include +#elif defined(__CPU_MCXN94X) +#include +#else +#error "Unsupported TARGET" +#endif + + +int reboot(int magic) +{ + platformctl_t pctl = { + .action = pctl_set, + .type = pctl_reboot, + .reboot = { + .magic = magic, + } + }; + + return platformctl(&pctl); +} + + +int reboot_reason(uint32_t *val) +{ + platformctl_t pctl = { + .action = pctl_get, + .type = pctl_reboot, + }; + + *val = 0; + if (platformctl(&pctl) < 0) { + return -1; + } + + *val = pctl.reboot.reason; + return 0; +} diff --git a/arch/arm/v8m/syscalls.S b/arch/arm/v8m/syscalls.S new file mode 100644 index 00000000..df4fd47a --- /dev/null +++ b/arch/arm/v8m/syscalls.S @@ -0,0 +1,42 @@ +/* + * Phoenix-RTOS + * + * libphoenix + * + * syscalls (armv8m) + * + * Copyright 2017, 2024 Phoenix Systems + * Author; Pawel Pisarczyk, Aleksander Kaminski + * + * This file is part of Phoenix-RTOS. + * + * %LICENSE% + */ + +#define __ASSEMBLY__ +#include + +.text + + +#define SYSCALLDEF(sym, sn) \ +.globl sym; \ +.type sym, %function; \ +sym: \ + svc $sn; \ + bx lr; \ +.size sym, .-sym + + +.globl vfork; +.type vfork, %function; +vfork: + b vforksvc +.size vfork, .-vfork + + +#define SYSCALLS_LIBC(name) \ + SYSCALLDEF(name, __COUNTER__); + + +SYSCALLS(SYSCALLS_LIBC) diff --git a/arch/arm/v8m/tls.c b/arch/arm/v8m/tls.c new file mode 100644 index 00000000..840b93d9 --- /dev/null +++ b/arch/arm/v8m/tls.c @@ -0,0 +1,34 @@ +/* + * Phoenix-RTOS + * + * libphoenix + * + * tls.c + * + * Copyright 2022, 2024 Phoenix Systems + * Author: Lukasz Leczkowski + * + * This file is part of Phoenix-RTOS. + * + * %LICENSE% + */ + +#include + + +volatile uintptr_t arm_tls_ptr __attribute__((section("armtls"))) = 0; + + +void *read_tls_ptr(void) +{ + return (void *)arm_tls_ptr; +} + + +void __attribute__((naked)) __aeabi_read_tp(void) +{ + __asm__ volatile( + "push {r1-r4,r12,lr};" + "bl read_tls_ptr;" + "pop {r1-r4,r12,pc}"); +} diff --git a/include/arch.h b/include/arch.h index f964aef6..d8cff06f 100644 --- a/include/arch.h +++ b/include/arch.h @@ -1,6 +1,6 @@ #if defined(__i386__) || defined(__x86_64__) #include -#elif defined(__ARM_ARCH_6M__) || defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__) || defined(__ARM_ARCH_8M_BASE__) || defined(__ARM_ARCH_8M_MAIN__) +#elif defined(__ARM_ARCH_6M__) || defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__) #include #elif defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_8A__) || defined(__ARM_ARCH_7__) #include @@ -8,6 +8,8 @@ #include #elif defined(__ARM_ARCH_8R__) #include +#elif defined(__ARM_ARCH_8M_BASE__) || defined(__ARM_ARCH_8M_MAIN__) +#include #elif defined(__riscv) && (__riscv_xlen == 64) #include #elif defined(__sparc__) diff --git a/include/arch/armv8m/arch.h b/include/arch/armv8m/arch.h new file mode 100644 index 00000000..abf78c6c --- /dev/null +++ b/include/arch/armv8m/arch.h @@ -0,0 +1,69 @@ +/* + * Phoenix-RTOS + * + * libphoenix + * + * Architecture dependent part (arch/armv8m) + * + * Copyright 2017, 2024 Phoenix Systems + * Author: Pawel Pisarczyk, Aleksander Kaminski + * + * This file is part of Phoenix-RTOS. + * + * %LICENSE% + */ + +#ifndef _LIBPHOENIX_ARCH_ARMV8M_ARCH_H_ +#define _LIBPHOENIX_ARCH_ARMV8M_ARCH_H_ + +#define __ARCH_STDINT +#define __ARCH_LIMITS + +#define __MEMCPY +#define __MEMCMP +#define __MEMSET +#define __STRLEN +#define __STRNLEN +#define __STRCMP +#define __STRNCMP +#define __STRCPY +#define __STRNCPY +#define __MEMMOVE + +#if __ARM_PCS_VFP || (__VFP_FP__ && !__SOFTFP__) +#if __ARM_FP & 8 +#define __IEEE754_SQRT + +static inline double __ieee754_sqrt(double x) +{ + /* clang-format off */ + __asm__ volatile ("vsqrt.f64 %P0, %P1" : "=w"(x) : "w"(x)); + /* clang-format on */ + + return x; +} +#endif + +#define __IEEE754_SQRTF + +static inline float __ieee754_sqrtf(float x) +{ + /* clang-format off */ + __asm__ volatile ("vsqrt.f32 %0, %1" : "=t"(x) : "t"(x)); + /* clang-format on */ + + return x; +} +#endif + +#define _PAGE_SIZE 0x200 +#define SIZE_PAGE _Pragma("GCC warning \"'SIZE_PAGE' is deprecated. Use _PAGE_SIZE from arch.h or PAGE_SIZE from limits.h (POSIX only)\"") _PAGE_SIZE + +/* FIXME provide libphoenix config to be able to + * selectively disable/enable features on per + * project basis. + * Disabled for now as TLS consumes too much + * memory to be advantageous on some targets. */ +// #define __LIBPHOENIX_ARCH_TLS_SUPPORTED + +#endif diff --git a/include/arch/armv8m/limits.h b/include/arch/armv8m/limits.h new file mode 100644 index 00000000..2dacc28c --- /dev/null +++ b/include/arch/armv8m/limits.h @@ -0,0 +1,66 @@ +/* + * Phoenix-RTOS + * + * libphoenix + * + * Architecture dependent part of limits (arch/armv8m) + * + * Copyright 2017-2019, 2024 Phoenix Systems + * Author: Pawel Pisarczyk, Aleksander Kaminski, Andrzej Glowinski, Marek Bialowas + * + * This file is part of Phoenix-RTOS. + * + * %LICENSE% + */ + +#ifndef _LIBPHOENIX_ARCH_ARMV8M_LIMITS_H_ +#define _LIBPHOENIX_ARCH_ARMV8M_LIMITS_H_ + +#include "arch.h" + +#define SCHAR_MIN -128 +#define SCHAR_MAX 127 +#define UCHAR_MAX 255 + +#define CHAR_MIN 0 +#define CHAR_MAX UCHAR_MAX +#define CHAR_BIT 8 + +#define MB_LEN_MAX 4 + +#define SHRT_MIN -32768 +#define SHRT_MAX 32767 +#define USHRT_MAX 65535 + +#define INT_MIN -2147483648 +#define INT_MAX 0x7fffffff +#define UINT_MAX 0xffffffff + +#define LONG_MIN INT_MIN +#define LONG_MAX INT_MAX +#define ULONG_MAX UINT_MAX + +#define LONG_LONG_MIN 0x8000000000000000LL +#define LONG_LONG_MAX 0x7fffffffffffffffLL +#define ULONG_LONG_MAX 0xffffffffffffffffLL +#define LLONG_MIN LONG_LONG_MIN +#define LLONG_MAX LONG_LONG_MAX +#define ULLONG_MAX ULONG_LONG_MAX + +#define SSIZE_MAX INT_MAX + +#define PAGE_SIZE _PAGE_SIZE +#define PAGESIZE _PAGE_SIZE + +#define PTHREAD_STACK_MIN 256 + +/*** POSIX-required defines ***/ + +#define PATH_MAX 256 /* Maximum number of bytes the implementation will store as a pathname in a user-supplied buffer of unspecified size, including the terminating null character. MIN: 256 */ +#define NAME_MAX 64 /* Maximum number of bytes in a filename (not including the terminating null of a filename string). MIN: 14 */ +#define ARG_MAX 1500 /* Maximum length of argument to the exec functions including environment data. MIN: 4096 */ +#define SYMLOOP_MAX 8 /* Maximum number of symbolic links that can be reliably traversed in the resolution of a pathname in the absence of a loop. MIN: 8 */ + +#define _POSIX2_RE_DUP_MAX 255 + +#endif diff --git a/include/arch/armv8m/setjmp.h b/include/arch/armv8m/setjmp.h new file mode 100644 index 00000000..8eeaec7c --- /dev/null +++ b/include/arch/armv8m/setjmp.h @@ -0,0 +1,37 @@ +/* + * Phoenix-RTOS + * + * libphoenix + * + * arch-dependent part of setjmp.h + * + * Copyright 2024 Phoenix Systems + * Author: Lukasz Leczkowski + * + * This file is part of Phoenix-RTOS. + * + * %LICENSE% + */ + +#ifndef _LIBPHOENIX_ARCH_ARMV8M_SETJMP_H_ +#define _LIBPHOENIX_ARCH_ARMV8M_SETJMP_H_ + + +#include + + +struct __jmp_buf { + __u32 sigFlg; + __u32 sigMsk; + __u32 sp; + __u32 r[8]; + __u32 lr; + +#ifndef __SOFTFP__ + __u64 d[8]; + __u32 fpscr; +#endif +} __attribute__((packed, aligned(8))); + + +#endif diff --git a/include/arch/armv8m/stdint.h b/include/arch/armv8m/stdint.h new file mode 100644 index 00000000..5ba5aed1 --- /dev/null +++ b/include/arch/armv8m/stdint.h @@ -0,0 +1,125 @@ +/* + * Phoenix-RTOS + * + * libphoenix + * + * Architecture dependent part of stdint (arch/armv8m) + * + * Copyright 2019-2021, 2024 Phoenix Systems + * Author: Andrzej Glowinski, Daniel Sawka, Lukasz Leczkowski + * + * This file is part of Phoenix-RTOS. + * + * %LICENSE% + */ + +#ifndef _LIBPHOENIX_ARCH_ARMV8M_STDINT_H_ +#define _LIBPHOENIX_ARCH_ARMV8M_STDINT_H_ + +#include + +/* The following sections refer to ISO/IEC 9899:1999 */ + +/* 7.18.1.3 Fastest minimum-width integer types */ + +typedef __s32 int_fast8_t; +typedef __s32 int_fast16_t; +typedef __s32 int_fast32_t; +typedef __s64 int_fast64_t; + +typedef __u32 uint_fast8_t; +typedef __u32 uint_fast16_t; +typedef __u32 uint_fast32_t; +typedef __u64 uint_fast64_t; + + +/* Define other fixed types along with defines/macros */ + +#define _USE_STANDARD_TYPES_STDINT + +/* 7.18.1.4 Integer types capable of holding object pointers */ + +typedef __s32 intptr_t; +typedef __u32 uintptr_t; + +/* 7.18.1.5 Greatest-width integer types */ + +typedef __s64 intmax_t; +typedef __u64 uintmax_t; + +/* 7.18.2.3 Limits of fastest minimum-width integer types */ + +#define INT_FAST8_MIN INT32_MIN +#define INT_FAST16_MIN INT32_MIN +#define INT_FAST32_MIN INT32_MIN +#define INT_FAST64_MIN INT64_MIN + +#define INT_FAST8_MAX INT32_MAX +#define INT_FAST16_MAX INT32_MAX +#define INT_FAST32_MAX INT32_MAX +#define INT_FAST64_MAX INT64_MAX + +#define UINT_FAST8_MAX UINT32_MAX +#define UINT_FAST16_MAX UINT32_MAX +#define UINT_FAST32_MAX UINT32_MAX +#define UINT_FAST64_MAX UINT64_MAX + +/* 7.18.2.4 Limits of integer types capable of holding object pointers */ + +#define INTPTR_MIN INT32_MIN +#define INTPTR_MAX INT32_MAX +#define UINTPTR_MAX UINT32_MAX + +/* 7.18.2.5 Limits of greatest-width integer types */ + +#define INTMAX_MIN INT64_MIN +#define INTMAX_MAX INT64_MAX +#define UINTMAX_MAX UINT64_MAX + +/* 7.18.3 Limits of other integer types */ + +#define PTRDIFF_MIN INT32_MIN +#define PTRDIFF_MAX INT32_MAX + +#define SIZE_MAX UINT32_MAX + +/* 7.18.4.1 Macros for minimum-width integer constants */ + +#define INT8_C(c) c +#define INT16_C(c) c +#define INT32_C(c) c +#define INT64_C(c) c##LL + +#define UINT8_C(c) c##U +#define UINT16_C(c) c##U +#define UINT32_C(c) c##U +#define UINT64_C(c) c##ULL + +/* 7.18.4.2 Macros for greatest-width integer constants */ + +#define INTMAX_C(c) c##LL +#define UINTMAX_C(c) c##ULL + + +/* Additional definitions */ + +#define _PRI_8 "" +#define _PRI_16 "" +#define _PRI_32 "" +#define _PRI_64 "ll" +#define _SCN_8 "hh" +#define _SCN_16 "h" +#define _SCN_32 "" +#define _SCN_64 "ll" +#define _PRI_PTR "" + +#define _SCN_LEAST8 _SCN_8 +#define _SCN_LEAST16 _SCN_16 +#define _SCN_LEAST32 _SCN_32 +#define _SCN_LEAST64 _SCN_64 +#define _SCN_FAST8 _SCN_32 +#define _SCN_FAST16 _SCN_32 +#define _SCN_FAST32 _SCN_32 +#define _SCN_FAST64 _SCN_64 + +#endif