Skip to content

Commit

Permalink
rework signal handling
Browse files Browse the repository at this point in the history
JIRA: RTOS-539
  • Loading branch information
lukileczo committed Aug 22, 2023
1 parent 49bd220 commit 9f96af2
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 80 deletions.
21 changes: 10 additions & 11 deletions arch/armv7a/signal.S
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*
* Signal trampoline (arm-imx)
*
* Copyright 2019 Phoenix Systems
* Copyright 2019, 2023 Phoenix Systems
* Author: Jan Sikorski
*
* This file is part of Phoenix-RTOS.
Expand All @@ -20,15 +20,14 @@
.globl _signal_trampoline
.type _signal_trampoline, %function
_signal_trampoline:
// stack: return address, signal number
push {r0-r3,r9,r12,lr}
mrs r0, apsr
push {r0}
ldr r0, [sp, #32]
blx _signal_handler
/* Get signal number from stack */
pop {r0}
msr apsr_nzcvqg, r0
pop {r0-r3,r9,r12,lr}
add sp, #4
pop {pc}
blx _signal_handler

/* Old signal mask in r0 */
pop {r1} /* cpu context * */
pop {r2} /* pc */
pop {r3} /* sp */
/* psr on stack */
bl sigreturn
.size _signal_trampoline, .-_signal_trampoline
17 changes: 15 additions & 2 deletions arch/armv7m/signal.S
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*
* Signal trampoline (armv7)
*
* Copyright 2019 Phoenix Systems
* Copyright 2019, 2023 Phoenix Systems
* Author: Jan Sikorski
*
* This file is part of Phoenix-RTOS.
Expand All @@ -19,5 +19,18 @@
.globl _signal_trampoline
.type _signal_trampoline, %function
_signal_trampoline:
// TODO!
/* Get signal number from stack */
pop {r0}
blx _signal_handler

/* Old signal mask in r0 */
pop {r1} /* cpu context * */
pop {r2} /* pc */
pop {r3} /* sp */
pop {r4} /* psr */

/* keep 8-byte alignment */
sub sp, sp, #4
push {r4}
bl sigreturn
.size _signal_trampoline, .-_signal_trampoline
21 changes: 6 additions & 15 deletions arch/ia32/signal.S
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,13 @@
.globl _signal_trampoline
.type _signal_trampoline, %function
_signal_trampoline:
// stack: return address, signal number
xchgl (%esp), %eax
push %ebx
push %ecx
push %edx
pushf

push %eax
/* Signal number on stack */
call _signal_handler
addl $4, %esp

popf
pop %edx
pop %ecx
pop %ebx
pop %eax
ret
addl $4, %esp
/* Put old mask on stack */
push %eax
/* cpu context *, eip, esp on stack */
call sigreturn
.size _signal_trampoline, .-_signal_trampoline

55 changes: 9 additions & 46 deletions arch/riscv64/signal.S
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*
* Signal trampoline (RISCV64)
*
* Copyright 2019 Phoenix Systems
* Copyright 2019, 2023 Phoenix Systems
* Author: Jan Sikorski
*
* This file is part of Phoenix-RTOS.
Expand All @@ -20,51 +20,14 @@
.globl _signal_trampoline
.type _signal_trampoline, %function
_signal_trampoline:

// stack: return address, signal number
addi sp, sp, -136
sd x1, (sp) /* ra */
sd x3, 8(sp) /* gp */
sd x5, 16(sp) /* t0 */
sd x6, 24(sp) /* t1 */
sd x7, 32(sp) /* t2 */
sd x10, 40(sp) /* a0 */
sd x11, 48(sp) /* a1 */
sd x12, 56(sp) /* a2 */
sd x13, 64(sp) /* a3 */
sd x14, 72(sp) /* a4 */
sd x15, 80(sp) /* a5 */
sd x16, 88(sp) /* a6 */
sd x17, 96(sp) /* a7 */
sd x28, 104(sp) /* t3 */
sd x29, 112(sp) /* t4 */
sd x30, 120(sp) /* t5 */
sd x31, 128(sp) /* t6 */

ld a0, 136(sp) /* signal number is 1st argument */
/* Get signal number from stack */
lw a0, (sp)
call _signal_handler

ld x1, (sp) /* ra */
ld x3, 8(sp) /* gp */
ld x5, 16(sp) /* t0 */
ld x6, 24(sp) /* t1 */
ld x7, 32(sp) /* t2 */
ld x10, 40(sp) /* a0 */
ld x11, 48(sp) /* a1 */
ld x12, 56(sp) /* a2 */
ld x13, 64(sp) /* a3 */
ld x14, 72(sp) /* a4 */
ld x15, 80(sp) /* a5 */
ld x16, 88(sp) /* a6 */
ld x17, 96(sp) /* a7 */
ld x28, 104(sp) /* t3 */
ld x29, 112(sp) /* t4 */
ld x30, 120(sp) /* t5 */
ld x31, 128(sp) /* t6 */
addi sp, sp, 144 /* saved state, signal number and return address on stack */

/* TODO correct this, it is wrong, we need a way to load pc without touching any other register */
ld t4, -8(sp)
jr t4

/* Old signal mask in a0 */
ld a1, 8(sp) /* cpu context * */
ld a2, 16(sp) /* sepc */
ld a3, 24(sp) /* sp */
addi sp, sp, 32
call sigreturn
.size _signal_trampoline, .-_signal_trampoline
13 changes: 10 additions & 3 deletions arch/sparcv8leon3/signal.S
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,14 @@
.globl _signal_trampoline
.type _signal_trampoline, #function
_signal_trampoline:
/* TODO */
retl
nop
save %sp, -0x60, %sp

call _signal_handler
ld [%i0], %o0 /* signal number */

/* oldmask in %o0 */
ld [%i0 + 0x04], %o1 /* cpu_context * */
ldd [%i0 + 0x08], %o2 /* pc, sp */
call sigreturn
ld [%i0 + 0x10], %o4 /* psr */
.size _signal_trampoline, .-_signal_trampoline
8 changes: 5 additions & 3 deletions signal/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,14 @@ static int _signal_ismutable(int sig)
}


void _signal_handler(int phxsig)
unsigned int _signal_handler(int phxsig)
{
int sig;
unsigned int oldmask;

if (phxsig < 0 || phxsig >= NSIG) {
/* Don't know what to do, ignore it */
return;
return signalMask(0U, 0U);
}

/* Received Phoenix signal, need to convert it to POSIX signal */
Expand All @@ -141,7 +141,9 @@ void _signal_handler(int phxsig)
/* Invoke handler */
(signal_common.sightab[sig])(sig);

signalMask(oldmask, 0xffffffffUL);
/* Mask restored by sigreturn */

return oldmask;
}


Expand Down

0 comments on commit 9f96af2

Please sign in to comment.