Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add armv8m architecture support #371

Merged
merged 1 commit into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions arch/arm/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions arch/arm/v8m/Makefile
Original file line number Diff line number Diff line change
@@ -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)
56 changes: 56 additions & 0 deletions arch/arm/v8m/reboot.c
Original file line number Diff line number Diff line change
@@ -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 <sys/reboot.h>
#include <sys/platform.h>

#if defined(__CPU_NRF9160)
#include <phoenix/arch/armv8m/nrf/91/nrf9160.h>
#elif defined(__CPU_MCXN94X)
#include <phoenix/arch/armv8m/mcx/n94x/mcxn94x.h>
#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;
}
42 changes: 42 additions & 0 deletions arch/arm/v8m/syscalls.S
Original file line number Diff line number Diff line change
@@ -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 <phoenix/syscalls.h>

.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)
34 changes: 34 additions & 0 deletions arch/arm/v8m/tls.c
Original file line number Diff line number Diff line change
@@ -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 <sys/types.h>


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}");
}
4 changes: 3 additions & 1 deletion include/arch.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
#if defined(__i386__) || defined(__x86_64__)
#include <arch/ia32/arch.h>
#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 <arch/armv7m/arch.h>
#elif defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_8A__) || defined(__ARM_ARCH_7__)
#include <arch/armv7a/arch.h>
#elif defined(__ARM_ARCH_4T__) || defined(__ARM_ARCH_5TE__) /* not currently supported, map to 7M for libgcc to compile */
#include <arch/armv7m/arch.h>
#elif defined(__ARM_ARCH_8R__)
#include <arch/armv8r/arch.h>
#elif defined(__ARM_ARCH_8M_BASE__) || defined(__ARM_ARCH_8M_MAIN__)
#include <arch/armv8m/arch.h>
#elif defined(__riscv) && (__riscv_xlen == 64)
#include <arch/riscv64/arch.h>
#elif defined(__sparc__)
Expand Down
69 changes: 69 additions & 0 deletions include/arch/armv8m/arch.h
Original file line number Diff line number Diff line change
@@ -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 <arch/armv8m/stdint.h>
#define __ARCH_LIMITS <arch/armv8m/limits.h>

#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
66 changes: 66 additions & 0 deletions include/arch/armv8m/limits.h
Original file line number Diff line number Diff line change
@@ -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
37 changes: 37 additions & 0 deletions include/arch/armv8m/setjmp.h
Original file line number Diff line number Diff line change
@@ -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 <phoenix/arch/armv8m/stdtypes.h>


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
Loading
Loading