]> git.proxmox.com Git - mirror_qemu.git/blob - linux-user/host/loongarch64/host-signal.h
meson: reuse common_user_inc when building files specific to user-mode emulators
[mirror_qemu.git] / linux-user / host / loongarch64 / host-signal.h
1 /*
2 * host-signal.h: signal info dependent on the host architecture
3 *
4 * Copyright (c) 2003-2005 Fabrice Bellard
5 * Copyright (c) 2021 WANG Xuerui <git@xen0n.name>
6 *
7 * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
8 * See the COPYING file in the top-level directory.
9 */
10
11 #ifndef LOONGARCH64_HOST_SIGNAL_H
12 #define LOONGARCH64_HOST_SIGNAL_H
13
14 static inline uintptr_t host_signal_pc(ucontext_t *uc)
15 {
16 return uc->uc_mcontext.__pc;
17 }
18
19 static inline void host_signal_set_pc(ucontext_t *uc, uintptr_t pc)
20 {
21 uc->uc_mcontext.__pc = pc;
22 }
23
24 static inline bool host_signal_write(siginfo_t *info, ucontext_t *uc)
25 {
26 const uint32_t *pinsn = (const uint32_t *)host_signal_pc(uc);
27 uint32_t insn = pinsn[0];
28
29 /* Detect store by reading the instruction at the program counter. */
30 switch ((insn >> 26) & 0b111111) {
31 case 0b001000: /* {ll,sc}.[wd] */
32 switch ((insn >> 24) & 0b11) {
33 case 0b01: /* sc.w */
34 case 0b11: /* sc.d */
35 return true;
36 }
37 break;
38 case 0b001001: /* {ld,st}ox4.[wd] ({ld,st}ptr.[wd]) */
39 switch ((insn >> 24) & 0b11) {
40 case 0b01: /* stox4.w (stptr.w) */
41 case 0b11: /* stox4.d (stptr.d) */
42 return true;
43 }
44 break;
45 case 0b001010: /* {ld,st}.* family */
46 switch ((insn >> 22) & 0b1111) {
47 case 0b0100: /* st.b */
48 case 0b0101: /* st.h */
49 case 0b0110: /* st.w */
50 case 0b0111: /* st.d */
51 case 0b1101: /* fst.s */
52 case 0b1111: /* fst.d */
53 return true;
54 }
55 break;
56 case 0b001110: /* indexed, atomic, bounds-checking memory operations */
57 switch ((insn >> 15) & 0b11111111111) {
58 case 0b00000100000: /* stx.b */
59 case 0b00000101000: /* stx.h */
60 case 0b00000110000: /* stx.w */
61 case 0b00000111000: /* stx.d */
62 case 0b00001110000: /* fstx.s */
63 case 0b00001111000: /* fstx.d */
64 case 0b00011101100: /* fstgt.s */
65 case 0b00011101101: /* fstgt.d */
66 case 0b00011101110: /* fstle.s */
67 case 0b00011101111: /* fstle.d */
68 case 0b00011111000: /* stgt.b */
69 case 0b00011111001: /* stgt.h */
70 case 0b00011111010: /* stgt.w */
71 case 0b00011111011: /* stgt.d */
72 case 0b00011111100: /* stle.b */
73 case 0b00011111101: /* stle.h */
74 case 0b00011111110: /* stle.w */
75 case 0b00011111111: /* stle.d */
76 case 0b00011000000 ... 0b00011100011: /* am* insns */
77 return true;
78 }
79 break;
80 }
81
82 return false;
83 }
84
85 #endif