xref: /qemu/bsd-user/riscv/signal.c (revision 2931709ed917bf7e0db545bda941625e3c3aee1e)
1 /*
2  *  RISC-V signal definitions
3  *
4  *  Copyright (c) 2019 Mark Corbin
5  *
6  *  This program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2 of the License, or
9  *  (at your option) any later version.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, see <http://www.gnu.org/licenses/>.
18  */
19 #include "qemu/osdep.h"
20 
21 #include "qemu.h"
22 
23 /*
24  * Compare with sendsig() in riscv/riscv/exec_machdep.c
25  * Assumes that target stack frame memory is locked.
26  */
27 abi_long
28 set_sigtramp_args(CPURISCVState *regs, int sig, struct target_sigframe *frame,
29     abi_ulong frame_addr, struct target_sigaction *ka)
30 {
31     /*
32      * Arguments to signal handler:
33      *  a0 (10) = signal number
34      *  a1 (11) = siginfo pointer
35      *  a2 (12) = ucontext pointer
36      *  pc      = signal pointer handler
37      *  sp (2)  = sigframe pointer
38      *  ra (1)  = sigtramp at base of user stack
39      */
40 
41      regs->gpr[xA0] = sig;
42      regs->gpr[xA1] = frame_addr +
43          offsetof(struct target_sigframe, sf_si);
44      regs->gpr[xA2] = frame_addr +
45          offsetof(struct target_sigframe, sf_uc);
46      regs->pc = ka->_sa_handler;
47      regs->gpr[xSP] = frame_addr;
48      regs->gpr[xRA] = TARGET_PS_STRINGS - TARGET_SZSIGCODE;
49      return 0;
50 }
51 
52 /*
53  * Compare to riscv/riscv/exec_machdep.c sendsig()
54  * Assumes that the memory is locked if frame points to user memory.
55  */
56 abi_long setup_sigframe_arch(CPURISCVState *env, abi_ulong frame_addr,
57                              struct target_sigframe *frame, int flags)
58 {
59     target_mcontext_t *mcp = &frame->sf_uc.uc_mcontext;
60 
61     get_mcontext(env, mcp, flags);
62     return 0;
63 }
64