diff --git a/include/arch.h b/include/arch.h index 6559c629..6c70f2c0 100644 --- a/include/arch.h +++ b/include/arch.h @@ -1,7 +1,9 @@ #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_8M_BASE__) || defined(__ARM_ARCH_8M_MAIN__) +#include #elif defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_8A__) || defined(__ARM_ARCH_7__) #include #elif defined(__ARM_ARCH_4T__) || defined(__ARM_ARCH_5TE__) /* not currently supported, map to 7M for libgcc to compile */ diff --git a/include/arch/armv8m/arch.h b/include/arch/armv8m/arch.h new file mode 100644 index 00000000..3f21053c --- /dev/null +++ b/include/arch/armv8m/arch.h @@ -0,0 +1,70 @@ +/* + * Phoenix-RTOS + * + * libphoenix + * + * Architecture dependent part (arch/armv8m) + * + * Copyright 2024 Phoenix Systems + * Author: Damian Loewnau + * + * 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..33f50aff --- /dev/null +++ b/include/arch/armv8m/limits.h @@ -0,0 +1,66 @@ +/* + * Phoenix-RTOS + * + * libphoenix + * + * Architecture dependent part of limits (arch/armv8m) + * + * Copyright 2024 Phoenix Systems + * Author: Damian Loewnau + * + * 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/stdint.h b/include/arch/armv8m/stdint.h new file mode 100644 index 00000000..358d9171 --- /dev/null +++ b/include/arch/armv8m/stdint.h @@ -0,0 +1,125 @@ +/* + * Phoenix-RTOS + * + * libphoenix + * + * Architecture dependent part of stdint (arch/armv7m) + * + * Copyright 2024 Phoenix Systems + * Author: Damian Loewnau + * + * This file is part of Phoenix-RTOS. + * + * %LICENSE% + */ + +#ifndef _LIBPHOENIX_ARCH_ARMV7M_STDINT_H_ +#define _LIBPHOENIX_ARCH_ARMV7M_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