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

arch: add armv8m #342

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
9 changes: 9 additions & 0 deletions arch/armv8m/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#
# Makefile for libphoenix/arch/armv8
#
# Copyright 2024 Phoenix Systems
# Author: Damian Loewnau
#

OBJS += $(addprefix $(PREFIX_O)arch/armv8m/, syscalls.o jmp.o signal.o string.o reboot.o tls.o)
CRT0_OBJS += $(addprefix $(PREFIX_O)arch/armv8m/, crt0.o)
27 changes: 27 additions & 0 deletions arch/armv8m/crt0.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Phoenix-RTOS
*
* libphoenix
*
* Entrypoint (armv8m)
*
* Copyright 2018, 2023, 2024 Phoenix Systems
* Author: Aleksander Kaminski, Hubert Badocha, Damian Loewnau
*
* This file is part of Phoenix-RTOS.
*
* %LICENSE%
*/

#define __ASSEMBLY__

.text
.thumb
.syntax unified

.globl _start
.type _start, %function
_start:
pop {r0-r3}
b _startc
.size _start, .-_start
121 changes: 121 additions & 0 deletions arch/armv8m/jmp.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/*
* Phoenix-RTOS
*
* libphoenix
*
*
* _setjmp, _longjmp, setjmp, sigsetjmp
*
* Copyright 2018, 2019, 2024 Phoenix Systems
* Author: Kamil Amanowicz, Aleksander Kaminski, Jakub Sarzyński, Damian Loewnau
*
* This file is part of Phoenix-RTOS.
*
* %LICENSE%
*/

/* setjmp env buffer description
* Offset Description
* 0 Signal mask flag - if != 0 then next value stores a signal mask
* 4 Signal mask
* 8 SP register
* 12-43 r4-r11 registers
* 44 LR register
* 48-79 d8-d15 registers
* 80 fpscr register
*/

#define __ASSEMBLY__

.thumb
.syntax unified

.text
.align 2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alignment might cause some performance penalty. IMHO better to set it to 4, to make it predictable

Copy link
Contributor Author

@damianloew damianloew Mar 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to leave 2 for other arm architectures?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other arm archs aren't in the scope of this PR. Imho it's best to change alignment to 4 everywhere eventually, as @lukileczo found out it's faster indeed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see that it has been changed recently



.globl sigsetjmp
.type sigsetjmp, %function
.align 2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant

Suggested change
.align 2

sigsetjmp:
/* Store signal mask if savesigs != 0 */
movs r2, #0
cbz r1, 1f

/* Get signal mask */
/* Stack must be aligned to 8 bytes */
push {r0, r1, r3, lr}
movs r0, #0
mov r1, r0
bl signalMask
mov r2, r0
pop {r0, r1, r3, lr}

1:
/* Store mask (fake or real) and general registers */
mov r3, sp
stmia r0!, {r1-r11, lr}

#ifndef __SOFTFP__
/* Store fpu registers */
vstm r0!, {d8-d15}
vmrs r2, fpscr
str r2, [r0], #4
#endif

movs r0, #0
bx lr
.size sigsetjmp, .-sigsetjmp


.globl _setjmp
.type _setjmp, %function
.align 2
_setjmp:
movs r1, #0
b sigsetjmp
.size _setjmp, .-_setjmp


.globl setjmp
.type setjmp, %function
.align 2
setjmp:
movs r1, #1
b sigsetjmp
.size setjmp, .-setjmp


.globl _longjmp
.type _longjmp, %function
.align 2
_longjmp:
/* Check for signal mask in env buffer, if it's saved restore it */
ldmia r0!, {r2-r3}
cbz r2, 1f

/* Restore mask */
push {r0, r1}
mov r0, r3
mvn r1, #0
bl signalMask
pop {r0, r1}

1:
/* Restore general registers */
ldmia r0!, {r2, r4-r11, lr}
mov sp, r2

#ifndef __SOFTFP__
/* Restore fpu registers */
vldm r0!, {d8-d15}
ldr r2, [r0], #4
vmsr fpscr, r2
#endif

/* Set return value */
movs r0, r1
it eq
moveq r0, #1
bx lr
.size _longjmp, .-_longjmp
51 changes: 51 additions & 0 deletions arch/armv8m/reboot.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Phoenix-RTOS
*
* libphoenix
*
* reboot.c
*
* Copyright 2019, 2024 Phoenix Systems
* Author: Jan Sikorski, Damian Loewnau
*
* 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>
#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;
}
31 changes: 31 additions & 0 deletions arch/armv8m/signal.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Phoenix-RTOS
*
* libphoenix
*
* Signal trampoline (armv8)
*
* Copyright 2019, 2024 Phoenix Systems
* Author: Jan Sikorski, Damian Loewnau
*
* This file is part of Phoenix-RTOS.
*
* %LICENSE%
*/

#define __ASSEMBLY__

.text
.globl _signal_trampoline
.type _signal_trampoline, %function
_signal_trampoline:
/* Signal number, cpu_context * */
pop {r0,r4}
blx _signal_handler

/* Old signal mask in r0 */
mov r1, r4
pop {r2,r3} /* pc, sp */
/* psr on stack */
bl sigreturn
.size _signal_trampoline, .-_signal_trampoline
Loading
Loading