18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci#ifndef _M68K_SIGNAL_H
38c2ecf20Sopenharmony_ci#define _M68K_SIGNAL_H
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci#include <uapi/asm/signal.h>
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ci/* Most things should be clean enough to redefine this at will, if care
88c2ecf20Sopenharmony_ci   is taken to make libc match.  */
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci#define _NSIG		64
118c2ecf20Sopenharmony_ci#define _NSIG_BPW	32
128c2ecf20Sopenharmony_ci#define _NSIG_WORDS	(_NSIG / _NSIG_BPW)
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_citypedef unsigned long old_sigset_t;		/* at least 32 bits */
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_citypedef struct {
178c2ecf20Sopenharmony_ci	unsigned long sig[_NSIG_WORDS];
188c2ecf20Sopenharmony_ci} sigset_t;
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ci#define __ARCH_HAS_SA_RESTORER
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ci#include <asm/sigcontext.h>
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ci#ifndef CONFIG_CPU_HAS_NO_BITFIELDS
258c2ecf20Sopenharmony_ci#define __HAVE_ARCH_SIG_BITOPS
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_cistatic inline void sigaddset(sigset_t *set, int _sig)
288c2ecf20Sopenharmony_ci{
298c2ecf20Sopenharmony_ci	asm ("bfset %0{%1,#1}"
308c2ecf20Sopenharmony_ci		: "+o" (*set)
318c2ecf20Sopenharmony_ci		: "id" ((_sig - 1) ^ 31)
328c2ecf20Sopenharmony_ci		: "cc");
338c2ecf20Sopenharmony_ci}
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_cistatic inline void sigdelset(sigset_t *set, int _sig)
368c2ecf20Sopenharmony_ci{
378c2ecf20Sopenharmony_ci	asm ("bfclr %0{%1,#1}"
388c2ecf20Sopenharmony_ci		: "+o" (*set)
398c2ecf20Sopenharmony_ci		: "id" ((_sig - 1) ^ 31)
408c2ecf20Sopenharmony_ci		: "cc");
418c2ecf20Sopenharmony_ci}
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_cistatic inline int __const_sigismember(sigset_t *set, int _sig)
448c2ecf20Sopenharmony_ci{
458c2ecf20Sopenharmony_ci	unsigned long sig = _sig - 1;
468c2ecf20Sopenharmony_ci	return 1 & (set->sig[sig / _NSIG_BPW] >> (sig % _NSIG_BPW));
478c2ecf20Sopenharmony_ci}
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_cistatic inline int __gen_sigismember(sigset_t *set, int _sig)
508c2ecf20Sopenharmony_ci{
518c2ecf20Sopenharmony_ci	int ret;
528c2ecf20Sopenharmony_ci	asm ("bfextu %1{%2,#1},%0"
538c2ecf20Sopenharmony_ci		: "=d" (ret)
548c2ecf20Sopenharmony_ci		: "o" (*set), "id" ((_sig-1) ^ 31)
558c2ecf20Sopenharmony_ci		: "cc");
568c2ecf20Sopenharmony_ci	return ret;
578c2ecf20Sopenharmony_ci}
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ci#define sigismember(set,sig)			\
608c2ecf20Sopenharmony_ci	(__builtin_constant_p(sig) ?		\
618c2ecf20Sopenharmony_ci	 __const_sigismember(set,sig) :		\
628c2ecf20Sopenharmony_ci	 __gen_sigismember(set,sig))
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_ci#endif /* !CONFIG_CPU_HAS_NO_BITFIELDS */
658c2ecf20Sopenharmony_ci
668c2ecf20Sopenharmony_ci#endif /* _M68K_SIGNAL_H */
67