xref: /linux/arch/riscv/include/asm/compat.h (revision 702648721db590b3425c31ade294000e18808345)
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 	return test_thread_flag(TIF_32BIT);
18 }
19 
20 struct compat_user_regs_struct {
21 	compat_ulong_t pc;
22 	compat_ulong_t ra;
23 	compat_ulong_t sp;
24 	compat_ulong_t gp;
25 	compat_ulong_t tp;
26 	compat_ulong_t t0;
27 	compat_ulong_t t1;
28 	compat_ulong_t t2;
29 	compat_ulong_t s0;
30 	compat_ulong_t s1;
31 	compat_ulong_t a0;
32 	compat_ulong_t a1;
33 	compat_ulong_t a2;
34 	compat_ulong_t a3;
35 	compat_ulong_t a4;
36 	compat_ulong_t a5;
37 	compat_ulong_t a6;
38 	compat_ulong_t a7;
39 	compat_ulong_t s2;
40 	compat_ulong_t s3;
41 	compat_ulong_t s4;
42 	compat_ulong_t s5;
43 	compat_ulong_t s6;
44 	compat_ulong_t s7;
45 	compat_ulong_t s8;
46 	compat_ulong_t s9;
47 	compat_ulong_t s10;
48 	compat_ulong_t s11;
49 	compat_ulong_t t3;
50 	compat_ulong_t t4;
51 	compat_ulong_t t5;
52 	compat_ulong_t t6;
53 };
54 
55 static inline void regs_to_cregs(struct compat_user_regs_struct *cregs,
56 				 struct pt_regs *regs)
57 {
58 	cregs->pc	= (compat_ulong_t) regs->epc;
59 	cregs->ra	= (compat_ulong_t) regs->ra;
60 	cregs->sp	= (compat_ulong_t) regs->sp;
61 	cregs->gp	= (compat_ulong_t) regs->gp;
62 	cregs->tp	= (compat_ulong_t) regs->tp;
63 	cregs->t0	= (compat_ulong_t) regs->t0;
64 	cregs->t1	= (compat_ulong_t) regs->t1;
65 	cregs->t2	= (compat_ulong_t) regs->t2;
66 	cregs->s0	= (compat_ulong_t) regs->s0;
67 	cregs->s1	= (compat_ulong_t) regs->s1;
68 	cregs->a0	= (compat_ulong_t) regs->a0;
69 	cregs->a1	= (compat_ulong_t) regs->a1;
70 	cregs->a2	= (compat_ulong_t) regs->a2;
71 	cregs->a3	= (compat_ulong_t) regs->a3;
72 	cregs->a4	= (compat_ulong_t) regs->a4;
73 	cregs->a5	= (compat_ulong_t) regs->a5;
74 	cregs->a6	= (compat_ulong_t) regs->a6;
75 	cregs->a7	= (compat_ulong_t) regs->a7;
76 	cregs->s2	= (compat_ulong_t) regs->s2;
77 	cregs->s3	= (compat_ulong_t) regs->s3;
78 	cregs->s4	= (compat_ulong_t) regs->s4;
79 	cregs->s5	= (compat_ulong_t) regs->s5;
80 	cregs->s6	= (compat_ulong_t) regs->s6;
81 	cregs->s7	= (compat_ulong_t) regs->s7;
82 	cregs->s8	= (compat_ulong_t) regs->s8;
83 	cregs->s9	= (compat_ulong_t) regs->s9;
84 	cregs->s10	= (compat_ulong_t) regs->s10;
85 	cregs->s11	= (compat_ulong_t) regs->s11;
86 	cregs->t3	= (compat_ulong_t) regs->t3;
87 	cregs->t4	= (compat_ulong_t) regs->t4;
88 	cregs->t5	= (compat_ulong_t) regs->t5;
89 	cregs->t6	= (compat_ulong_t) regs->t6;
90 };
91 
92 static inline void cregs_to_regs(struct compat_user_regs_struct *cregs,
93 				 struct pt_regs *regs)
94 {
95 	regs->epc	= (unsigned long) cregs->pc;
96 	regs->ra	= (unsigned long) cregs->ra;
97 	regs->sp	= (unsigned long) cregs->sp;
98 	regs->gp	= (unsigned long) cregs->gp;
99 	regs->tp	= (unsigned long) cregs->tp;
100 	regs->t0	= (unsigned long) cregs->t0;
101 	regs->t1	= (unsigned long) cregs->t1;
102 	regs->t2	= (unsigned long) cregs->t2;
103 	regs->s0	= (unsigned long) cregs->s0;
104 	regs->s1	= (unsigned long) cregs->s1;
105 	regs->a0	= (unsigned long) cregs->a0;
106 	regs->a1	= (unsigned long) cregs->a1;
107 	regs->a2	= (unsigned long) cregs->a2;
108 	regs->a3	= (unsigned long) cregs->a3;
109 	regs->a4	= (unsigned long) cregs->a4;
110 	regs->a5	= (unsigned long) cregs->a5;
111 	regs->a6	= (unsigned long) cregs->a6;
112 	regs->a7	= (unsigned long) cregs->a7;
113 	regs->s2	= (unsigned long) cregs->s2;
114 	regs->s3	= (unsigned long) cregs->s3;
115 	regs->s4	= (unsigned long) cregs->s4;
116 	regs->s5	= (unsigned long) cregs->s5;
117 	regs->s6	= (unsigned long) cregs->s6;
118 	regs->s7	= (unsigned long) cregs->s7;
119 	regs->s8	= (unsigned long) cregs->s8;
120 	regs->s9	= (unsigned long) cregs->s9;
121 	regs->s10	= (unsigned long) cregs->s10;
122 	regs->s11	= (unsigned long) cregs->s11;
123 	regs->t3	= (unsigned long) cregs->t3;
124 	regs->t4	= (unsigned long) cregs->t4;
125 	regs->t5	= (unsigned long) cregs->t5;
126 	regs->t6	= (unsigned long) cregs->t6;
127 };
128 
129 #endif /* __ASM_COMPAT_H */
130