Skip to content

Commit 45b32b9

Browse files
xhackerustcpalmer-dabbelt
authored andcommitted
riscv: entry: Consolidate general regs saving/restoring
Consolidate the saving/restoring GPs (except zero, ra, sp, gp, tp and t0) into save_from_x6_to_x31/restore_from_x6_to_x31 macros. No functional change intended. Signed-off-by: Jisheng Zhang <jszhang@kernel.org> Reviewed-by: Guo Ren <guoren@kernel.org> Reviewed-by: Björn Töpel <bjorn@rivosinc.com> Tested-by: Guo Ren <guoren@kernel.org> Signed-off-by: Guo Ren <guoren@kernel.org> Link: https://lore.kernel.org/r/20230222033021.983168-8-guoren@kernel.org Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
1 parent ab9164d commit 45b32b9

3 files changed

Lines changed: 68 additions & 131 deletions

File tree

arch/riscv/include/asm/asm.h

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
#endif
7070

7171
#ifdef __ASSEMBLY__
72+
#include <asm/asm-offsets.h>
7273

7374
/* Common assembly source macros */
7475

@@ -81,6 +82,66 @@
8182
.endr
8283
.endm
8384

85+
/* save all GPs except x1 ~ x5 */
86+
.macro save_from_x6_to_x31
87+
REG_S x6, PT_T1(sp)
88+
REG_S x7, PT_T2(sp)
89+
REG_S x8, PT_S0(sp)
90+
REG_S x9, PT_S1(sp)
91+
REG_S x10, PT_A0(sp)
92+
REG_S x11, PT_A1(sp)
93+
REG_S x12, PT_A2(sp)
94+
REG_S x13, PT_A3(sp)
95+
REG_S x14, PT_A4(sp)
96+
REG_S x15, PT_A5(sp)
97+
REG_S x16, PT_A6(sp)
98+
REG_S x17, PT_A7(sp)
99+
REG_S x18, PT_S2(sp)
100+
REG_S x19, PT_S3(sp)
101+
REG_S x20, PT_S4(sp)
102+
REG_S x21, PT_S5(sp)
103+
REG_S x22, PT_S6(sp)
104+
REG_S x23, PT_S7(sp)
105+
REG_S x24, PT_S8(sp)
106+
REG_S x25, PT_S9(sp)
107+
REG_S x26, PT_S10(sp)
108+
REG_S x27, PT_S11(sp)
109+
REG_S x28, PT_T3(sp)
110+
REG_S x29, PT_T4(sp)
111+
REG_S x30, PT_T5(sp)
112+
REG_S x31, PT_T6(sp)
113+
.endm
114+
115+
/* restore all GPs except x1 ~ x5 */
116+
.macro restore_from_x6_to_x31
117+
REG_L x6, PT_T1(sp)
118+
REG_L x7, PT_T2(sp)
119+
REG_L x8, PT_S0(sp)
120+
REG_L x9, PT_S1(sp)
121+
REG_L x10, PT_A0(sp)
122+
REG_L x11, PT_A1(sp)
123+
REG_L x12, PT_A2(sp)
124+
REG_L x13, PT_A3(sp)
125+
REG_L x14, PT_A4(sp)
126+
REG_L x15, PT_A5(sp)
127+
REG_L x16, PT_A6(sp)
128+
REG_L x17, PT_A7(sp)
129+
REG_L x18, PT_S2(sp)
130+
REG_L x19, PT_S3(sp)
131+
REG_L x20, PT_S4(sp)
132+
REG_L x21, PT_S5(sp)
133+
REG_L x22, PT_S6(sp)
134+
REG_L x23, PT_S7(sp)
135+
REG_L x24, PT_S8(sp)
136+
REG_L x25, PT_S9(sp)
137+
REG_L x26, PT_S10(sp)
138+
REG_L x27, PT_S11(sp)
139+
REG_L x28, PT_T3(sp)
140+
REG_L x29, PT_T4(sp)
141+
REG_L x30, PT_T5(sp)
142+
REG_L x31, PT_T6(sp)
143+
.endm
144+
84145
#endif /* __ASSEMBLY__ */
85146

86147
#endif /* _ASM_RISCV_ASM_H */

arch/riscv/kernel/entry.S

Lines changed: 3 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -42,32 +42,7 @@ _save_context:
4242
REG_S x1, PT_RA(sp)
4343
REG_S x3, PT_GP(sp)
4444
REG_S x5, PT_T0(sp)
45-
REG_S x6, PT_T1(sp)
46-
REG_S x7, PT_T2(sp)
47-
REG_S x8, PT_S0(sp)
48-
REG_S x9, PT_S1(sp)
49-
REG_S x10, PT_A0(sp)
50-
REG_S x11, PT_A1(sp)
51-
REG_S x12, PT_A2(sp)
52-
REG_S x13, PT_A3(sp)
53-
REG_S x14, PT_A4(sp)
54-
REG_S x15, PT_A5(sp)
55-
REG_S x16, PT_A6(sp)
56-
REG_S x17, PT_A7(sp)
57-
REG_S x18, PT_S2(sp)
58-
REG_S x19, PT_S3(sp)
59-
REG_S x20, PT_S4(sp)
60-
REG_S x21, PT_S5(sp)
61-
REG_S x22, PT_S6(sp)
62-
REG_S x23, PT_S7(sp)
63-
REG_S x24, PT_S8(sp)
64-
REG_S x25, PT_S9(sp)
65-
REG_S x26, PT_S10(sp)
66-
REG_S x27, PT_S11(sp)
67-
REG_S x28, PT_T3(sp)
68-
REG_S x29, PT_T4(sp)
69-
REG_S x30, PT_T5(sp)
70-
REG_S x31, PT_T6(sp)
45+
save_from_x6_to_x31
7146

7247
/*
7348
* Disable user-mode memory access as it should only be set in the
@@ -182,32 +157,7 @@ SYM_CODE_START_NOALIGN(ret_from_exception)
182157
REG_L x3, PT_GP(sp)
183158
REG_L x4, PT_TP(sp)
184159
REG_L x5, PT_T0(sp)
185-
REG_L x6, PT_T1(sp)
186-
REG_L x7, PT_T2(sp)
187-
REG_L x8, PT_S0(sp)
188-
REG_L x9, PT_S1(sp)
189-
REG_L x10, PT_A0(sp)
190-
REG_L x11, PT_A1(sp)
191-
REG_L x12, PT_A2(sp)
192-
REG_L x13, PT_A3(sp)
193-
REG_L x14, PT_A4(sp)
194-
REG_L x15, PT_A5(sp)
195-
REG_L x16, PT_A6(sp)
196-
REG_L x17, PT_A7(sp)
197-
REG_L x18, PT_S2(sp)
198-
REG_L x19, PT_S3(sp)
199-
REG_L x20, PT_S4(sp)
200-
REG_L x21, PT_S5(sp)
201-
REG_L x22, PT_S6(sp)
202-
REG_L x23, PT_S7(sp)
203-
REG_L x24, PT_S8(sp)
204-
REG_L x25, PT_S9(sp)
205-
REG_L x26, PT_S10(sp)
206-
REG_L x27, PT_S11(sp)
207-
REG_L x28, PT_T3(sp)
208-
REG_L x29, PT_T4(sp)
209-
REG_L x30, PT_T5(sp)
210-
REG_L x31, PT_T6(sp)
160+
restore_from_x6_to_x31
211161

212162
REG_L x2, PT_SP(sp)
213163

@@ -287,32 +237,7 @@ restore_caller_reg:
287237
REG_S x1, PT_RA(sp)
288238
REG_S x3, PT_GP(sp)
289239
REG_S x5, PT_T0(sp)
290-
REG_S x6, PT_T1(sp)
291-
REG_S x7, PT_T2(sp)
292-
REG_S x8, PT_S0(sp)
293-
REG_S x9, PT_S1(sp)
294-
REG_S x10, PT_A0(sp)
295-
REG_S x11, PT_A1(sp)
296-
REG_S x12, PT_A2(sp)
297-
REG_S x13, PT_A3(sp)
298-
REG_S x14, PT_A4(sp)
299-
REG_S x15, PT_A5(sp)
300-
REG_S x16, PT_A6(sp)
301-
REG_S x17, PT_A7(sp)
302-
REG_S x18, PT_S2(sp)
303-
REG_S x19, PT_S3(sp)
304-
REG_S x20, PT_S4(sp)
305-
REG_S x21, PT_S5(sp)
306-
REG_S x22, PT_S6(sp)
307-
REG_S x23, PT_S7(sp)
308-
REG_S x24, PT_S8(sp)
309-
REG_S x25, PT_S9(sp)
310-
REG_S x26, PT_S10(sp)
311-
REG_S x27, PT_S11(sp)
312-
REG_S x28, PT_T3(sp)
313-
REG_S x29, PT_T4(sp)
314-
REG_S x30, PT_T5(sp)
315-
REG_S x31, PT_T6(sp)
240+
save_from_x6_to_x31
316241

317242
REG_L s0, TASK_TI_KERNEL_SP(tp)
318243
csrr s1, CSR_STATUS

arch/riscv/kernel/mcount-dyn.S

Lines changed: 4 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -66,66 +66,17 @@
6666
REG_S x3, PT_GP(sp)
6767
REG_S x4, PT_TP(sp)
6868
REG_S x5, PT_T0(sp)
69-
REG_S x6, PT_T1(sp)
70-
REG_S x7, PT_T2(sp)
71-
REG_S x8, PT_S0(sp)
72-
REG_S x9, PT_S1(sp)
73-
REG_S x10, PT_A0(sp)
74-
REG_S x11, PT_A1(sp)
75-
REG_S x12, PT_A2(sp)
76-
REG_S x13, PT_A3(sp)
77-
REG_S x14, PT_A4(sp)
78-
REG_S x15, PT_A5(sp)
79-
REG_S x16, PT_A6(sp)
80-
REG_S x17, PT_A7(sp)
81-
REG_S x18, PT_S2(sp)
82-
REG_S x19, PT_S3(sp)
83-
REG_S x20, PT_S4(sp)
84-
REG_S x21, PT_S5(sp)
85-
REG_S x22, PT_S6(sp)
86-
REG_S x23, PT_S7(sp)
87-
REG_S x24, PT_S8(sp)
88-
REG_S x25, PT_S9(sp)
89-
REG_S x26, PT_S10(sp)
90-
REG_S x27, PT_S11(sp)
91-
REG_S x28, PT_T3(sp)
92-
REG_S x29, PT_T4(sp)
93-
REG_S x30, PT_T5(sp)
94-
REG_S x31, PT_T6(sp)
69+
save_from_x6_to_x31
9570
.endm
9671

9772
.macro RESTORE_ALL
98-
REG_L t0, PT_EPC(sp)
9973
REG_L x1, PT_RA(sp)
10074
REG_L x2, PT_SP(sp)
10175
REG_L x3, PT_GP(sp)
10276
REG_L x4, PT_TP(sp)
103-
REG_L x6, PT_T1(sp)
104-
REG_L x7, PT_T2(sp)
105-
REG_L x8, PT_S0(sp)
106-
REG_L x9, PT_S1(sp)
107-
REG_L x10, PT_A0(sp)
108-
REG_L x11, PT_A1(sp)
109-
REG_L x12, PT_A2(sp)
110-
REG_L x13, PT_A3(sp)
111-
REG_L x14, PT_A4(sp)
112-
REG_L x15, PT_A5(sp)
113-
REG_L x16, PT_A6(sp)
114-
REG_L x17, PT_A7(sp)
115-
REG_L x18, PT_S2(sp)
116-
REG_L x19, PT_S3(sp)
117-
REG_L x20, PT_S4(sp)
118-
REG_L x21, PT_S5(sp)
119-
REG_L x22, PT_S6(sp)
120-
REG_L x23, PT_S7(sp)
121-
REG_L x24, PT_S8(sp)
122-
REG_L x25, PT_S9(sp)
123-
REG_L x26, PT_S10(sp)
124-
REG_L x27, PT_S11(sp)
125-
REG_L x28, PT_T3(sp)
126-
REG_L x29, PT_T4(sp)
127-
REG_L x30, PT_T5(sp)
128-
REG_L x31, PT_T6(sp)
77+
/* Restore t0 with PT_EPC */
78+
REG_L x5, PT_EPC(sp)
79+
restore_from_x6_to_x31
12980

13081
addi sp, sp, PT_SIZE_ON_STACK
13182
.endm

0 commit comments

Comments
 (0)