1*50a00122SPaolo Bonzini /*
2*50a00122SPaolo Bonzini * host-signal.h: signal info dependent on the host architecture
3*50a00122SPaolo Bonzini *
4*50a00122SPaolo Bonzini * Copyright (c) 2003-2005 Fabrice Bellard
5*50a00122SPaolo Bonzini * Copyright (c) 2021 Linaro Limited
6*50a00122SPaolo Bonzini *
7*50a00122SPaolo Bonzini * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
8*50a00122SPaolo Bonzini * See the COPYING file in the top-level directory.
9*50a00122SPaolo Bonzini */
10*50a00122SPaolo Bonzini
11*50a00122SPaolo Bonzini #ifndef S390_HOST_SIGNAL_H
12*50a00122SPaolo Bonzini #define S390_HOST_SIGNAL_H
13*50a00122SPaolo Bonzini
14*50a00122SPaolo Bonzini /* The third argument to a SA_SIGINFO handler is ucontext_t. */
15*50a00122SPaolo Bonzini typedef ucontext_t host_sigcontext;
16*50a00122SPaolo Bonzini
host_signal_pc(host_sigcontext * uc)17*50a00122SPaolo Bonzini static inline uintptr_t host_signal_pc(host_sigcontext *uc)
18*50a00122SPaolo Bonzini {
19*50a00122SPaolo Bonzini return uc->uc_mcontext.psw.addr;
20*50a00122SPaolo Bonzini }
21*50a00122SPaolo Bonzini
host_signal_set_pc(host_sigcontext * uc,uintptr_t pc)22*50a00122SPaolo Bonzini static inline void host_signal_set_pc(host_sigcontext *uc, uintptr_t pc)
23*50a00122SPaolo Bonzini {
24*50a00122SPaolo Bonzini uc->uc_mcontext.psw.addr = pc;
25*50a00122SPaolo Bonzini }
26*50a00122SPaolo Bonzini
host_signal_mask(host_sigcontext * uc)27*50a00122SPaolo Bonzini static inline void *host_signal_mask(host_sigcontext *uc)
28*50a00122SPaolo Bonzini {
29*50a00122SPaolo Bonzini return &uc->uc_sigmask;
30*50a00122SPaolo Bonzini }
31*50a00122SPaolo Bonzini
host_signal_write(siginfo_t * info,host_sigcontext * uc)32*50a00122SPaolo Bonzini static inline bool host_signal_write(siginfo_t *info, host_sigcontext *uc)
33*50a00122SPaolo Bonzini {
34*50a00122SPaolo Bonzini uint16_t *pinsn = (uint16_t *)host_signal_pc(uc);
35*50a00122SPaolo Bonzini
36*50a00122SPaolo Bonzini /*
37*50a00122SPaolo Bonzini * ??? On linux, the non-rt signal handler has 4 (!) arguments instead
38*50a00122SPaolo Bonzini * of the normal 2 arguments. The 4th argument contains the "Translation-
39*50a00122SPaolo Bonzini * Exception Identification for DAT Exceptions" from the hardware (aka
40*50a00122SPaolo Bonzini * "int_parm_long"), which does in fact contain the is_write value.
41*50a00122SPaolo Bonzini * The rt signal handler, as far as I can tell, does not give this value
42*50a00122SPaolo Bonzini * at all. Not that we could get to it from here even if it were.
43*50a00122SPaolo Bonzini * So fall back to parsing instructions. Treat read-modify-write ones as
44*50a00122SPaolo Bonzini * writes, which is not fully correct, but for tracking self-modifying code
45*50a00122SPaolo Bonzini * this is better than treating them as reads. Checking si_addr page flags
46*50a00122SPaolo Bonzini * might be a viable improvement, albeit a racy one.
47*50a00122SPaolo Bonzini */
48*50a00122SPaolo Bonzini /* ??? This is not even close to complete. */
49*50a00122SPaolo Bonzini switch (pinsn[0] >> 8) {
50*50a00122SPaolo Bonzini case 0x50: /* ST */
51*50a00122SPaolo Bonzini case 0x42: /* STC */
52*50a00122SPaolo Bonzini case 0x40: /* STH */
53*50a00122SPaolo Bonzini case 0x44: /* EX */
54*50a00122SPaolo Bonzini case 0xba: /* CS */
55*50a00122SPaolo Bonzini case 0xbb: /* CDS */
56*50a00122SPaolo Bonzini return true;
57*50a00122SPaolo Bonzini case 0xc4: /* RIL format insns */
58*50a00122SPaolo Bonzini switch (pinsn[0] & 0xf) {
59*50a00122SPaolo Bonzini case 0xf: /* STRL */
60*50a00122SPaolo Bonzini case 0xb: /* STGRL */
61*50a00122SPaolo Bonzini case 0x7: /* STHRL */
62*50a00122SPaolo Bonzini return true;
63*50a00122SPaolo Bonzini }
64*50a00122SPaolo Bonzini break;
65*50a00122SPaolo Bonzini case 0xc6: /* RIL-b format insns */
66*50a00122SPaolo Bonzini switch (pinsn[0] & 0xf) {
67*50a00122SPaolo Bonzini case 0x0: /* EXRL */
68*50a00122SPaolo Bonzini return true;
69*50a00122SPaolo Bonzini }
70*50a00122SPaolo Bonzini break;
71*50a00122SPaolo Bonzini case 0xc8: /* SSF format insns */
72*50a00122SPaolo Bonzini switch (pinsn[0] & 0xf) {
73*50a00122SPaolo Bonzini case 0x2: /* CSST */
74*50a00122SPaolo Bonzini return true;
75*50a00122SPaolo Bonzini }
76*50a00122SPaolo Bonzini break;
77*50a00122SPaolo Bonzini case 0xe3: /* RXY format insns */
78*50a00122SPaolo Bonzini switch (pinsn[2] & 0xff) {
79*50a00122SPaolo Bonzini case 0x50: /* STY */
80*50a00122SPaolo Bonzini case 0x24: /* STG */
81*50a00122SPaolo Bonzini case 0x72: /* STCY */
82*50a00122SPaolo Bonzini case 0x70: /* STHY */
83*50a00122SPaolo Bonzini case 0x8e: /* STPQ */
84*50a00122SPaolo Bonzini case 0x3f: /* STRVH */
85*50a00122SPaolo Bonzini case 0x3e: /* STRV */
86*50a00122SPaolo Bonzini case 0x2f: /* STRVG */
87*50a00122SPaolo Bonzini return true;
88*50a00122SPaolo Bonzini }
89*50a00122SPaolo Bonzini break;
90*50a00122SPaolo Bonzini case 0xe6:
91*50a00122SPaolo Bonzini switch (pinsn[2] & 0xff) {
92*50a00122SPaolo Bonzini case 0x09: /* VSTEBRH */
93*50a00122SPaolo Bonzini case 0x0a: /* VSTEBRG */
94*50a00122SPaolo Bonzini case 0x0b: /* VSTEBRF */
95*50a00122SPaolo Bonzini case 0x0e: /* VSTBR */
96*50a00122SPaolo Bonzini case 0x0f: /* VSTER */
97*50a00122SPaolo Bonzini case 0x3f: /* VSTRLR */
98*50a00122SPaolo Bonzini return true;
99*50a00122SPaolo Bonzini }
100*50a00122SPaolo Bonzini break;
101*50a00122SPaolo Bonzini case 0xe7:
102*50a00122SPaolo Bonzini switch (pinsn[2] & 0xff) {
103*50a00122SPaolo Bonzini case 0x08: /* VSTEB */
104*50a00122SPaolo Bonzini case 0x09: /* VSTEH */
105*50a00122SPaolo Bonzini case 0x0a: /* VSTEG */
106*50a00122SPaolo Bonzini case 0x0b: /* VSTEF */
107*50a00122SPaolo Bonzini case 0x0e: /* VST */
108*50a00122SPaolo Bonzini case 0x1a: /* VSCEG */
109*50a00122SPaolo Bonzini case 0x1b: /* VSCEF */
110*50a00122SPaolo Bonzini case 0x3e: /* VSTM */
111*50a00122SPaolo Bonzini case 0x3f: /* VSTL */
112*50a00122SPaolo Bonzini return true;
113*50a00122SPaolo Bonzini }
114*50a00122SPaolo Bonzini break;
115*50a00122SPaolo Bonzini case 0xeb: /* RSY format insns */
116*50a00122SPaolo Bonzini switch (pinsn[2] & 0xff) {
117*50a00122SPaolo Bonzini case 0x14: /* CSY */
118*50a00122SPaolo Bonzini case 0x30: /* CSG */
119*50a00122SPaolo Bonzini case 0x31: /* CDSY */
120*50a00122SPaolo Bonzini case 0x3e: /* CDSG */
121*50a00122SPaolo Bonzini case 0xe4: /* LANG */
122*50a00122SPaolo Bonzini case 0xe6: /* LAOG */
123*50a00122SPaolo Bonzini case 0xe7: /* LAXG */
124*50a00122SPaolo Bonzini case 0xe8: /* LAAG */
125*50a00122SPaolo Bonzini case 0xea: /* LAALG */
126*50a00122SPaolo Bonzini case 0xf4: /* LAN */
127*50a00122SPaolo Bonzini case 0xf6: /* LAO */
128*50a00122SPaolo Bonzini case 0xf7: /* LAX */
129*50a00122SPaolo Bonzini case 0xfa: /* LAAL */
130*50a00122SPaolo Bonzini case 0xf8: /* LAA */
131*50a00122SPaolo Bonzini return true;
132*50a00122SPaolo Bonzini }
133*50a00122SPaolo Bonzini break;
134*50a00122SPaolo Bonzini }
135*50a00122SPaolo Bonzini return false;
136*50a00122SPaolo Bonzini }
137*50a00122SPaolo Bonzini
138*50a00122SPaolo Bonzini #endif
139