xref: /linux/arch/riscv/include/asm/compat.h (revision 9c93c0b44be36fd5267fb79ae33453f989fbe909)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 #ifndef __ASM_COMPAT_H
3 #define __ASM_COMPAT_H
4 
5 #define COMPAT_UTS_MACHINE	"riscv\0\0"
6 
7 /*
8  * Architecture specific compatibility types
9  */
10 #include <linux/types.h>
11 #include <linux/sched.h>
12 #include <linux/sched/task_stack.h>
13 #include <asm-generic/compat.h>
14 
15 static inline int is_compat_task(void)
16 {
17 	if (!IS_ENABLED(CONFIG_COMPAT))
18 		return 0;
19 
20 	return test_thread_flag(TIF_32BIT);
21 }
22 
23 static inline int is_compat_thread(struct thread_info *thread)
24 {
25 	if (!IS_ENABLED(CONFIG_COMPAT))
26 		return 0;
27 
28 	return test_ti_thread_flag(thread, TIF_32BIT);
29 }
30 
31 static inline void set_compat_task(bool is_compat)
32 {
33 	if (is_compat)
34 		set_thread_flag(TIF_32BIT);
35 	else
36 		clear_thread_flag(TIF_32BIT);
37 }
38 
39 struct compat_user_regs_struct {
40 	compat_ulong_t pc;
41 	compat_ulong_t ra;
42 	compat_ulong_t sp;
43 	compat_ulong_t gp;
44 	compat_ulong_t tp;
45 	compat_ulong_t t0;
46 	compat_ulong_t t1;
47 	compat_ulong_t t2;
48 	compat_ulong_t s0;
49 	compat_ulong_t s1;
50 	compat_ulong_t a0;
51 	compat_ulong_t a1;
52 	compat_ulong_t a2;
53 	compat_ulong_t a3;
54 	compat_ulong_t a4;
55 	compat_ulong_t a5;
56 	compat_ulong_t a6;
57 	compat_ulong_t a7;
58 	compat_ulong_t s2;
59 	compat_ulong_t s3;
60 	compat_ulong_t s4;
61 	compat_ulong_t s5;
62 	compat_ulong_t s6;
63 	compat_ulong_t s7;
64 	compat_ulong_t s8;
65 	compat_ulong_t s9;
66 	compat_ulong_t s10;
67 	compat_ulong_t s11;
68 	compat_ulong_t t3;
69 	compat_ulong_t t4;
70 	compat_ulong_t t5;
71 	compat_ulong_t t6;
72 };
73 
74 static inline void regs_to_cregs(struct compat_user_regs_struct *cregs,
75 				 struct pt_regs *regs)
76 {
77 	cregs->pc	= (compat_ulong_t) regs->epc;
78 	cregs->ra	= (compat_ulong_t) regs->ra;
79 	cregs->sp	= (compat_ulong_t) regs->sp;
80 	cregs->gp	= (compat_ulong_t) regs->gp;
81 	cregs->tp	= (compat_ulong_t) regs->tp;
82 	cregs->t0	= (compat_ulong_t) regs->t0;
83 	cregs->t1	= (compat_ulong_t) regs->t1;
84 	cregs->t2	= (compat_ulong_t) regs->t2;
85 	cregs->s0	= (compat_ulong_t) regs->s0;
86 	cregs->s1	= (compat_ulong_t) regs->s1;
87 	cregs->a0	= (compat_ulong_t) regs->a0;
88 	cregs->a1	= (compat_ulong_t) regs->a1;
89 	cregs->a2	= (compat_ulong_t) regs->a2;
90 	cregs->a3	= (compat_ulong_t) regs->a3;
91 	cregs->a4	= (compat_ulong_t) regs->a4;
92 	cregs->a5	= (compat_ulong_t) regs->a5;
93 	cregs->a6	= (compat_ulong_t) regs->a6;
94 	cregs->a7	= (compat_ulong_t) regs->a7;
95 	cregs->s2	= (compat_ulong_t) regs->s2;
96 	cregs->s3	= (compat_ulong_t) regs->s3;
97 	cregs->s4	= (compat_ulong_t) regs->s4;
98 	cregs->s5	= (compat_ulong_t) regs->s5;
99 	cregs->s6	= (compat_ulong_t) regs->s6;
100 	cregs->s7	= (compat_ulong_t) regs->s7;
101 	cregs->s8	= (compat_ulong_t) regs->s8;
102 	cregs->s9	= (compat_ulong_t) regs->s9;
103 	cregs->s10	= (compat_ulong_t) regs->s10;
104 	cregs->s11	= (compat_ulong_t) regs->s11;
105 	cregs->t3	= (compat_ulong_t) regs->t3;
106 	cregs->t4	= (compat_ulong_t) regs->t4;
107 	cregs->t5	= (compat_ulong_t) regs->t5;
108 	cregs->t6	= (compat_ulong_t) regs->t6;
109 };
110 
111 static inline void cregs_to_regs(struct compat_user_regs_struct *cregs,
112 				 struct pt_regs *regs)
113 {
114 	regs->epc	= (unsigned long) cregs->pc;
115 	regs->ra	= (unsigned long) cregs->ra;
116 	regs->sp	= (unsigned long) cregs->sp;
117 	regs->gp	= (unsigned long) cregs->gp;
118 	regs->tp	= (unsigned long) cregs->tp;
119 	regs->t0	= (unsigned long) cregs->t0;
120 	regs->t1	= (unsigned long) cregs->t1;
121 	regs->t2	= (unsigned long) cregs->t2;
122 	regs->s0	= (unsigned long) cregs->s0;
123 	regs->s1	= (unsigned long) cregs->s1;
124 	regs->a0	= (unsigned long) cregs->a0;
125 	regs->a1	= (unsigned long) cregs->a1;
126 	regs->a2	= (unsigned long) cregs->a2;
127 	regs->a3	= (unsigned long) cregs->a3;
128 	regs->a4	= (unsigned long) cregs->a4;
129 	regs->a5	= (unsigned long) cregs->a5;
130 	regs->a6	= (unsigned long) cregs->a6;
131 	regs->a7	= (unsigned long) cregs->a7;
132 	regs->s2	= (unsigned long) cregs->s2;
133 	regs->s3	= (unsigned long) cregs->s3;
134 	regs->s4	= (unsigned long) cregs->s4;
135 	regs->s5	= (unsigned long) cregs->s5;
136 	regs->s6	= (unsigned long) cregs->s6;
137 	regs->s7	= (unsigned long) cregs->s7;
138 	regs->s8	= (unsigned long) cregs->s8;
139 	regs->s9	= (unsigned long) cregs->s9;
140 	regs->s10	= (unsigned long) cregs->s10;
141 	regs->s11	= (unsigned long) cregs->s11;
142 	regs->t3	= (unsigned long) cregs->t3;
143 	regs->t4	= (unsigned long) cregs->t4;
144 	regs->t5	= (unsigned long) cregs->t5;
145 	regs->t6	= (unsigned long) cregs->t6;
146 };
147 
148 #endif /* __ASM_COMPAT_H */
149