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