2 * Emulation of Linux signals
4 * Copyright (c) 2003 Fabrice Bellard
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.
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.
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/>.
19 #include "qemu/osdep.h"
21 #include "signal-common.h"
22 #include "linux-user/trace.h"
24 struct target_sigcontext
{
25 struct target_pt_regs regs
; /* needs to be first */
27 uint32_t usp
; /* usp before stacking this gunk on it */
31 struct target_signal_frame
{
32 struct target_sigcontext sc
;
33 uint32_t extramask
[TARGET_NSIG_WORDS
- 1];
34 uint16_t retcode
[4]; /* Trampoline code. */
37 struct rt_signal_frame
{
42 uint16_t retcode
[4]; /* Trampoline code. */
45 static void setup_sigcontext(struct target_sigcontext
*sc
, CPUCRISState
*env
)
47 __put_user(env
->regs
[0], &sc
->regs
.r0
);
48 __put_user(env
->regs
[1], &sc
->regs
.r1
);
49 __put_user(env
->regs
[2], &sc
->regs
.r2
);
50 __put_user(env
->regs
[3], &sc
->regs
.r3
);
51 __put_user(env
->regs
[4], &sc
->regs
.r4
);
52 __put_user(env
->regs
[5], &sc
->regs
.r5
);
53 __put_user(env
->regs
[6], &sc
->regs
.r6
);
54 __put_user(env
->regs
[7], &sc
->regs
.r7
);
55 __put_user(env
->regs
[8], &sc
->regs
.r8
);
56 __put_user(env
->regs
[9], &sc
->regs
.r9
);
57 __put_user(env
->regs
[10], &sc
->regs
.r10
);
58 __put_user(env
->regs
[11], &sc
->regs
.r11
);
59 __put_user(env
->regs
[12], &sc
->regs
.r12
);
60 __put_user(env
->regs
[13], &sc
->regs
.r13
);
61 __put_user(env
->regs
[14], &sc
->usp
);
62 __put_user(env
->regs
[15], &sc
->regs
.acr
);
63 __put_user(env
->pregs
[PR_MOF
], &sc
->regs
.mof
);
64 __put_user(env
->pregs
[PR_SRP
], &sc
->regs
.srp
);
65 __put_user(env
->pc
, &sc
->regs
.erp
);
68 static void restore_sigcontext(struct target_sigcontext
*sc
, CPUCRISState
*env
)
70 __get_user(env
->regs
[0], &sc
->regs
.r0
);
71 __get_user(env
->regs
[1], &sc
->regs
.r1
);
72 __get_user(env
->regs
[2], &sc
->regs
.r2
);
73 __get_user(env
->regs
[3], &sc
->regs
.r3
);
74 __get_user(env
->regs
[4], &sc
->regs
.r4
);
75 __get_user(env
->regs
[5], &sc
->regs
.r5
);
76 __get_user(env
->regs
[6], &sc
->regs
.r6
);
77 __get_user(env
->regs
[7], &sc
->regs
.r7
);
78 __get_user(env
->regs
[8], &sc
->regs
.r8
);
79 __get_user(env
->regs
[9], &sc
->regs
.r9
);
80 __get_user(env
->regs
[10], &sc
->regs
.r10
);
81 __get_user(env
->regs
[11], &sc
->regs
.r11
);
82 __get_user(env
->regs
[12], &sc
->regs
.r12
);
83 __get_user(env
->regs
[13], &sc
->regs
.r13
);
84 __get_user(env
->regs
[14], &sc
->usp
);
85 __get_user(env
->regs
[15], &sc
->regs
.acr
);
86 __get_user(env
->pregs
[PR_MOF
], &sc
->regs
.mof
);
87 __get_user(env
->pregs
[PR_SRP
], &sc
->regs
.srp
);
88 __get_user(env
->pc
, &sc
->regs
.erp
);
91 static abi_ulong
get_sigframe(CPUCRISState
*env
, int framesize
)
94 /* Align the stack downwards to 4. */
95 sp
= (env
->regs
[R_SP
] & ~3);
96 return sp
- framesize
;
99 void setup_frame(int sig
, struct target_sigaction
*ka
,
100 target_sigset_t
*set
, CPUCRISState
*env
)
102 struct target_signal_frame
*frame
;
103 abi_ulong frame_addr
;
106 frame_addr
= get_sigframe(env
, sizeof *frame
);
107 trace_user_setup_frame(env
, frame_addr
);
108 if (!lock_user_struct(VERIFY_WRITE
, frame
, frame_addr
, 0))
112 * The CRIS signal return trampoline. A real linux/CRIS kernel doesn't
113 * use this trampoline anymore but it sets it up for GDB.
114 * In QEMU, using the trampoline simplifies things a bit so we use it.
116 * This is movu.w __NR_sigreturn, r9; break 13;
118 __put_user(0x9c5f, frame
->retcode
+0);
119 __put_user(TARGET_NR_sigreturn
,
121 __put_user(0xe93d, frame
->retcode
+ 2);
124 __put_user(set
->sig
[0], &frame
->sc
.oldmask
);
126 for(i
= 1; i
< TARGET_NSIG_WORDS
; i
++) {
127 __put_user(set
->sig
[i
], &frame
->extramask
[i
- 1]);
130 setup_sigcontext(&frame
->sc
, env
);
132 /* Move the stack and setup the arguments for the handler. */
133 env
->regs
[R_SP
] = frame_addr
;
135 env
->pc
= (unsigned long) ka
->_sa_handler
;
136 /* Link SRP so the guest returns through the trampoline. */
137 env
->pregs
[PR_SRP
] = frame_addr
+ offsetof(typeof(*frame
), retcode
);
139 unlock_user_struct(frame
, frame_addr
, 1);
145 void setup_rt_frame(int sig
, struct target_sigaction
*ka
,
146 target_siginfo_t
*info
,
147 target_sigset_t
*set
, CPUCRISState
*env
)
149 qemu_log_mask(LOG_UNIMP
, "setup_rt_frame: not implemented\n");
152 long do_sigreturn(CPUCRISState
*env
)
154 struct target_signal_frame
*frame
;
155 abi_ulong frame_addr
;
156 target_sigset_t target_set
;
160 frame_addr
= env
->regs
[R_SP
];
161 trace_user_do_sigreturn(env
, frame_addr
);
162 /* Make sure the guest isn't playing games. */
163 if (!lock_user_struct(VERIFY_WRITE
, frame
, frame_addr
, 1)) {
167 /* Restore blocked signals */
168 __get_user(target_set
.sig
[0], &frame
->sc
.oldmask
);
169 for(i
= 1; i
< TARGET_NSIG_WORDS
; i
++) {
170 __get_user(target_set
.sig
[i
], &frame
->extramask
[i
- 1]);
172 target_to_host_sigset_internal(&set
, &target_set
);
175 restore_sigcontext(&frame
->sc
, env
);
176 unlock_user_struct(frame
, frame_addr
, 0);
177 return -TARGET_QEMU_ESIGRETURN
;
179 force_sig(TARGET_SIGSEGV
);
180 return -TARGET_QEMU_ESIGRETURN
;
183 long do_rt_sigreturn(CPUCRISState
*env
)
185 trace_user_do_rt_sigreturn(env
, 0);
186 qemu_log_mask(LOG_UNIMP
, "do_rt_sigreturn: not implemented\n");
187 return -TARGET_ENOSYS
;