Skip to content

Commit 60c4ba9

Browse files
author
Richard Kuo
committed
Hexagon: add support for new v4+ registers
Add support for a couple new v4+ registers, along with newer save/restore pt_regs. Signed-off-by: Richard Kuo <rkuo@codeaurora.org>
1 parent 444dd74 commit 60c4ba9

8 files changed

Lines changed: 206 additions & 48 deletions

File tree

‎arch/hexagon/include/uapi/asm/registers.h‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,17 @@ struct pt_regs {
5757
};
5858
union {
5959
struct {
60-
unsigned long gp;
6160
unsigned long ugp;
61+
unsigned long gp;
62+
};
63+
long long int gpugp;
64+
};
65+
union {
66+
struct {
67+
unsigned long cs0;
68+
unsigned long cs1;
6269
};
63-
long long int ugpgp;
70+
long long int cs1cs0;
6471
};
6572
/*
6673
* Be extremely careful with rearranging these, if at all. Some code

‎arch/hexagon/include/uapi/asm/user.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,15 @@ struct user_regs_struct {
5555
unsigned long pc;
5656
unsigned long cause;
5757
unsigned long badva;
58+
#if CONFIG_HEXAGON_ARCH_VERSION < 4
5859
unsigned long pad1; /* pad out to 48 words total */
5960
unsigned long pad2; /* pad out to 48 words total */
6061
unsigned long pad3; /* pad out to 48 words total */
62+
#else
63+
unsigned long cs0;
64+
unsigned long cs1;
65+
unsigned long pad1; /* pad out to 48 words total */
66+
#endif
6167
};
6268

6369
#endif

‎arch/hexagon/kernel/asm-offsets.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ int main(void)
4444

4545
COMMENT("Hexagon pt_regs definitions");
4646
OFFSET(_PT_SYSCALL_NR, pt_regs, syscall_nr);
47-
OFFSET(_PT_UGPGP, pt_regs, ugpgp);
47+
OFFSET(_PT_GPUGP, pt_regs, gpugp);
48+
OFFSET(_PT_CS1CS0, pt_regs, cs1cs0);
4849
OFFSET(_PT_R3130, pt_regs, r3130);
4950
OFFSET(_PT_R2928, pt_regs, r2928);
5051
OFFSET(_PT_R2726, pt_regs, r2726);

‎arch/hexagon/kernel/kgdb.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ struct dbg_reg_def_t dbg_reg_def[DBG_MAX_REG_NUM] = {
7070
{ "lc1", GDB_SIZEOF_REG, offsetof(struct pt_regs, lc1)},
7171
{ " gp", GDB_SIZEOF_REG, offsetof(struct pt_regs, gp)},
7272
{ "ugp", GDB_SIZEOF_REG, offsetof(struct pt_regs, ugp)},
73+
{ "cs0", GDB_SIZEOF_REG, offsetof(struct pt_regs, cs0)},
74+
{ "cs1", GDB_SIZEOF_REG, offsetof(struct pt_regs, cs1)},
7375
{ "psp", GDB_SIZEOF_REG, offsetof(struct pt_regs, hvmer.vmpsp)},
7476
{ "elr", GDB_SIZEOF_REG, offsetof(struct pt_regs, hvmer.vmel)},
7577
{ "est", GDB_SIZEOF_REG, offsetof(struct pt_regs, hvmer.vmest)},

‎arch/hexagon/kernel/ptrace.c‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ static int genregs_get(struct task_struct *target,
7676
dummy = pt_cause(regs);
7777
ONEXT(&dummy, cause);
7878
ONEXT(&pt_badva(regs), badva);
79+
#if CONFIG_HEXAGON_ARCH_VERSION >=4
80+
ONEXT(&regs->cs0, cs0);
81+
ONEXT(&regs->cs1, cs1);
82+
#endif
7983

8084
/* Pad the rest with zeros, if needed */
8185
if (!ret)
@@ -123,6 +127,11 @@ static int genregs_set(struct task_struct *target,
123127
INEXT(&bucket, cause);
124128
INEXT(&bucket, badva);
125129

130+
#if CONFIG_HEXAGON_ARCH_VERSION >=4
131+
INEXT(&regs->cs0, cs0);
132+
INEXT(&regs->cs1, cs1);
133+
#endif
134+
126135
/* Ignore the rest, if needed */
127136
if (!ret)
128137
ret = user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,

‎arch/hexagon/kernel/signal.c‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,10 @@ static int setup_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc)
6666
err |= __put_user(regs->preds, &sc->sc_regs.p3_0);
6767
err |= __put_user(regs->gp, &sc->sc_regs.gp);
6868
err |= __put_user(regs->ugp, &sc->sc_regs.ugp);
69-
69+
#if CONFIG_HEXAGON_ARCH_VERSION >= 4
70+
err |= __put_user(regs->cs0, &sc->sc_regs.cs0);
71+
err |= __put_user(regs->cs1, &sc->sc_regs.cs1);
72+
#endif
7073
tmp = pt_elr(regs); err |= __put_user(tmp, &sc->sc_regs.pc);
7174
tmp = pt_cause(regs); err |= __put_user(tmp, &sc->sc_regs.cause);
7275
tmp = pt_badva(regs); err |= __put_user(tmp, &sc->sc_regs.badva);
@@ -93,7 +96,10 @@ static int restore_sigcontext(struct pt_regs *regs,
9396
err |= __get_user(regs->preds, &sc->sc_regs.p3_0);
9497
err |= __get_user(regs->gp, &sc->sc_regs.gp);
9598
err |= __get_user(regs->ugp, &sc->sc_regs.ugp);
96-
99+
#if CONFIG_HEXAGON_ARCH_VERSION >= 4
100+
err |= __get_user(regs->cs0, &sc->sc_regs.cs0);
101+
err |= __get_user(regs->cs1, &sc->sc_regs.cs1);
102+
#endif
97103
err |= __get_user(tmp, &sc->sc_regs.pc); pt_set_elr(regs, tmp);
98104

99105
return err;

‎arch/hexagon/kernel/vm_entry.S‎

Lines changed: 168 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -45,55 +45,96 @@
4545
* number in the case where we decode a system call (trap0(#1)).
4646
*/
4747

48+
#if CONFIG_HEXAGON_ARCH_VERSION < 4
4849
#define save_pt_regs()\
49-
memd(R0 + #_PT_R3130) = R31:30; \
50+
memd(R0 + #_PT_R3130) = R31:30; \
51+
{ memw(R0 + #_PT_R2928) = R28; \
52+
R31 = memw(R0 + #_PT_ER_VMPSP); }\
53+
{ memw(R0 + #(_PT_R2928 + 4)) = R31; \
54+
R31 = ugp; } \
55+
{ memd(R0 + #_PT_R2726) = R27:26; \
56+
R30 = gp ; } \
57+
memd(R0 + #_PT_R2524) = R25:24; \
58+
memd(R0 + #_PT_R2322) = R23:22; \
59+
memd(R0 + #_PT_R2120) = R21:20; \
60+
memd(R0 + #_PT_R1918) = R19:18; \
61+
memd(R0 + #_PT_R1716) = R17:16; \
62+
memd(R0 + #_PT_R1514) = R15:14; \
63+
memd(R0 + #_PT_R1312) = R13:12; \
64+
{ memd(R0 + #_PT_R1110) = R11:10; \
65+
R15 = lc0; } \
66+
{ memd(R0 + #_PT_R0908) = R9:8; \
67+
R14 = sa0; } \
68+
{ memd(R0 + #_PT_R0706) = R7:6; \
69+
R13 = lc1; } \
70+
{ memd(R0 + #_PT_R0504) = R5:4; \
71+
R12 = sa1; } \
72+
{ memd(R0 + #_PT_GPUGP) = R31:30; \
73+
R11 = m1; \
74+
R2.H = #HI(_THREAD_SIZE); } \
75+
{ memd(R0 + #_PT_LC0SA0) = R15:14; \
76+
R10 = m0; \
77+
R2.L = #LO(_THREAD_SIZE); } \
78+
{ memd(R0 + #_PT_LC1SA1) = R13:12; \
79+
R15 = p3:0; \
80+
R2 = neg(R2); } \
81+
{ memd(R0 + #_PT_M1M0) = R11:10; \
82+
R14 = usr; \
83+
R2 = and(R0,R2); } \
84+
{ memd(R0 + #_PT_PREDSUSR) = R15:14; \
85+
THREADINFO_REG = R2; } \
86+
{ r24 = memw(THREADINFO_REG + #_THREAD_INFO_PT_REGS); \
87+
memw(THREADINFO_REG + #_THREAD_INFO_PT_REGS) = R0; \
88+
R2 = #-1; } \
89+
{ memw(R0 + #_PT_SYSCALL_NR) = R2; \
90+
R30 = #0; }
91+
#else
92+
/* V4+ */
93+
/* the # ## # syntax inserts a literal ## */
94+
#define save_pt_regs()\
95+
{ memd(R0 + #_PT_R3130) = R31:30; \
96+
R30 = memw(R0 + #_PT_ER_VMPSP); }\
5097
{ memw(R0 + #_PT_R2928) = R28; \
51-
R31 = memw(R0 + #_PT_ER_VMPSP); }\
52-
{ memw(R0 + #(_PT_R2928 + 4)) = R31; \
53-
R31 = ugp; } \
54-
{ memd(R0 + #_PT_R2726) = R27:26; \
55-
R30 = gp ; } \
56-
memd(R0 + #_PT_R2524) = R25:24; \
57-
memd(R0 + #_PT_R2322) = R23:22; \
58-
memd(R0 + #_PT_R2120) = R21:20; \
59-
memd(R0 + #_PT_R1918) = R19:18; \
60-
memd(R0 + #_PT_R1716) = R17:16; \
61-
memd(R0 + #_PT_R1514) = R15:14; \
62-
memd(R0 + #_PT_R1312) = R13:12; \
98+
memw(R0 + #(_PT_R2928 + 4)) = R30; }\
99+
{ R31:30 = C11:10; \
100+
memd(R0 + #_PT_R2726) = R27:26; \
101+
memd(R0 + #_PT_R2524) = R25:24; }\
102+
{ memd(R0 + #_PT_R2322) = R23:22; \
103+
memd(R0 + #_PT_R2120) = R21:20; }\
104+
{ memd(R0 + #_PT_R1918) = R19:18; \
105+
memd(R0 + #_PT_R1716) = R17:16; }\
106+
{ memd(R0 + #_PT_R1514) = R15:14; \
107+
memd(R0 + #_PT_R1312) = R13:12; \
108+
R17:16 = C13:12; }\
63109
{ memd(R0 + #_PT_R1110) = R11:10; \
64-
R15 = lc0; } \
65-
{ memd(R0 + #_PT_R0908) = R9:8; \
66-
R14 = sa0; } \
110+
memd(R0 + #_PT_R0908) = R9:8; \
111+
R15:14 = C1:0; } \
67112
{ memd(R0 + #_PT_R0706) = R7:6; \
68-
R13 = lc1; } \
69-
{ memd(R0 + #_PT_R0504) = R5:4; \
70-
R12 = sa1; } \
71-
{ memd(R0 + #_PT_UGPGP) = R31:30; \
72-
R11 = m1; \
73-
R2.H = #HI(_THREAD_SIZE); } \
74-
{ memd(R0 + #_PT_LC0SA0) = R15:14; \
75-
R10 = m0; \
76-
R2.L = #LO(_THREAD_SIZE); } \
77-
{ memd(R0 + #_PT_LC1SA1) = R13:12; \
78-
R15 = p3:0; \
79-
R2 = neg(R2); } \
113+
memd(R0 + #_PT_R0504) = R5:4; \
114+
R13:12 = C3:2; } \
115+
{ memd(R0 + #_PT_GPUGP) = R31:30; \
116+
memd(R0 + #_PT_LC0SA0) = R15:14; \
117+
R11:10 = C7:6; }\
118+
{ THREADINFO_REG = and(R0, # ## #-_THREAD_SIZE); \
119+
memd(R0 + #_PT_LC1SA1) = R13:12; \
120+
R15 = p3:0; }\
80121
{ memd(R0 + #_PT_M1M0) = R11:10; \
81-
R14 = usr; \
82-
R2 = and(R0,R2); } \
83-
{ memd(R0 + #_PT_PREDSUSR) = R15:14; \
84-
THREADINFO_REG = R2; } \
122+
memw(R0 + #_PT_PREDSUSR + 4) = R15; }\
85123
{ r24 = memw(THREADINFO_REG + #_THREAD_INFO_PT_REGS); \
86124
memw(THREADINFO_REG + #_THREAD_INFO_PT_REGS) = R0; \
87125
R2 = #-1; } \
88126
{ memw(R0 + #_PT_SYSCALL_NR) = R2; \
127+
memd(R0 + #_PT_CS1CS0) = R17:16; \
89128
R30 = #0; }
129+
#endif
90130

91131
/*
92132
* Restore registers and thread_info.regs state. THREADINFO_REG
93133
* is assumed to still be sane, and R24 to have been correctly
94134
* preserved. Don't restore R29 (SP) until later.
95135
*/
96136

137+
#if CONFIG_HEXAGON_ARCH_VERSION < 4
97138
#define restore_pt_regs() \
98139
{ memw(THREADINFO_REG + #_THREAD_INFO_PT_REGS) = R24; \
99140
R15:14 = memd(R0 + #_PT_PREDSUSR); } \
@@ -121,11 +162,44 @@
121162
R23:22 = memd(R0 + #_PT_R2322); } \
122163
{ R25:24 = memd(R0 + #_PT_R2524); \
123164
R27:26 = memd(R0 + #_PT_R2726); } \
124-
R31:30 = memd(R0 + #_PT_UGPGP); \
165+
R31:30 = memd(R0 + #_PT_GPUGP); \
125166
{ R28 = memw(R0 + #_PT_R2928); \
126167
ugp = R31; } \
127168
{ R31:30 = memd(R0 + #_PT_R3130); \
128169
gp = R30; }
170+
#else
171+
/* V4+ */
172+
#define restore_pt_regs() \
173+
{ memw(THREADINFO_REG + #_THREAD_INFO_PT_REGS) = R24; \
174+
R15:14 = memd(R0 + #_PT_PREDSUSR); } \
175+
{ R11:10 = memd(R0 + #_PT_M1M0); \
176+
R13:12 = memd(R0 + #_PT_LC1SA1); \
177+
p3:0 = R15; } \
178+
{ R15:14 = memd(R0 + #_PT_LC0SA0); \
179+
R3:2 = memd(R0 + #_PT_R0302); \
180+
usr = R14; } \
181+
{ R5:4 = memd(R0 + #_PT_R0504); \
182+
R7:6 = memd(R0 + #_PT_R0706); \
183+
C7:6 = R11:10; }\
184+
{ R9:8 = memd(R0 + #_PT_R0908); \
185+
R11:10 = memd(R0 + #_PT_R1110); \
186+
C3:2 = R13:12; }\
187+
{ R13:12 = memd(R0 + #_PT_R1312); \
188+
R15:14 = memd(R0 + #_PT_R1514); \
189+
C1:0 = R15:14; }\
190+
{ R17:16 = memd(R0 + #_PT_R1716); \
191+
R19:18 = memd(R0 + #_PT_R1918); } \
192+
{ R21:20 = memd(R0 + #_PT_R2120); \
193+
R23:22 = memd(R0 + #_PT_R2322); } \
194+
{ R25:24 = memd(R0 + #_PT_R2524); \
195+
R27:26 = memd(R0 + #_PT_R2726); } \
196+
R31:30 = memd(R0 + #_PT_CS1CS0); \
197+
{ C13:12 = R31:30; \
198+
R31:30 = memd(R0 + #_PT_GPUGP) ; \
199+
R28 = memw(R0 + #_PT_R2928); }\
200+
{ C11:10 = R31:30; \
201+
R31:30 = memd(R0 + #_PT_R3130); }
202+
#endif
129203

130204
/*
131205
* Clears off enough space for the rest of pt_regs; evrec is a part
@@ -139,6 +213,7 @@
139213
* Need to save off R0, R1, R2, R3 immediately.
140214
*/
141215

216+
#if CONFIG_HEXAGON_ARCH_VERSION < 4
142217
#define vm_event_entry(CHandler) \
143218
{ \
144219
R29 = add(R29, #-(_PT_REGS_SIZE)); \
@@ -158,6 +233,34 @@
158233
R1.H = #HI(CHandler); \
159234
jump event_dispatch; \
160235
}
236+
#else
237+
/* V4+ */
238+
/* turn on I$ prefetch early */
239+
/* the # ## # syntax inserts a literal ## */
240+
#define vm_event_entry(CHandler) \
241+
{ \
242+
R29 = add(R29, #-(_PT_REGS_SIZE)); \
243+
memd(R29 + #(_PT_R0100 + -_PT_REGS_SIZE)) = R1:0; \
244+
memd(R29 + #(_PT_R0302 + -_PT_REGS_SIZE)) = R3:2; \
245+
R0 = usr; \
246+
} \
247+
{ \
248+
memw(R29 + #_PT_PREDSUSR) = R0; \
249+
R0 = setbit(R0, #16); \
250+
} \
251+
usr = R0; \
252+
R1:0 = G1:0; \
253+
{ \
254+
memd(R29 + #_PT_ER_VMEL) = R1:0; \
255+
R1 = # ## #(CHandler); \
256+
R3:2 = G3:2; \
257+
} \
258+
{ \
259+
R0 = R29; \
260+
memd(R29 + #_PT_ER_VMPSP) = R3:2; \
261+
jump event_dispatch; \
262+
}
263+
#endif
161264

162265
.text
163266
/*
@@ -184,8 +287,10 @@ event_dispatch:
184287

185288
/* "Nested control path" -- if the previous mode was kernel */
186289
R0 = memw(R29 + #_PT_ER_VMEST);
187-
P0 = tstbit(R0, #HVM_VMEST_UM_SFT);
188-
if !P0 jump restore_all;
290+
{
291+
P0 = tstbit(R0, #HVM_VMEST_UM_SFT);
292+
if (!P0.new) jump:nt restore_all;
293+
}
189294
/*
190295
* Returning from system call, normally coming back from user mode
191296
*/
@@ -198,11 +303,18 @@ return_from_syscall:
198303
* Coming back from the C-world, our thread info pointer
199304
* should be in the designated register (usually R19)
200305
*/
306+
#if CONFIG_HEXAGON_ARCH_VERSION < 4
201307
R1.L = #LO(_TIF_ALLWORK_MASK)
202308
{
203309
R1.H = #HI(_TIF_ALLWORK_MASK);
204310
R0 = memw(THREADINFO_REG + #_THREAD_INFO_FLAGS);
205311
}
312+
#else
313+
{
314+
R1 = ##_TIF_ALLWORK_MASK;
315+
R0 = memw(THREADINFO_REG + #_THREAD_INFO_FLAGS);
316+
}
317+
#endif
206318

207319
/*
208320
* Compare against the "return to userspace" _TIF_WORK_MASK
@@ -222,10 +334,14 @@ work_pending:
222334
work_notifysig:
223335
/* this is the part that's kind of fuzzy. */
224336
R1 = and(R0, #(_TIF_SIGPENDING | _TIF_NOTIFY_RESUME));
225-
P0 = cmp.eq(R1, #0);
226-
if P0 jump restore_all
227-
R1 = R0; /* unsigned long thread_info_flags */
228-
R0 = R29; /* regs should still be at top of stack */
337+
{
338+
P0 = cmp.eq(R1, #0);
339+
if P0.new jump:t restore_all;
340+
}
341+
{
342+
R1 = R0; /* unsigned long thread_info_flags */
343+
R0 = R29; /* regs should still be at top of stack */
344+
}
229345
call do_notify_resume
230346

231347
restore_all:
@@ -235,14 +351,23 @@ restore_all:
235351

236352
/* do the setregs here for VM 0.5 */
237353
/* R29 here should already be pointing at pt_regs */
238-
R1:0 = memd(R29 + #_PT_ER_VMEL);
239-
R3:2 = memd(R29 + #_PT_ER_VMPSP);
354+
{
355+
R1:0 = memd(R29 + #_PT_ER_VMEL);
356+
R3:2 = memd(R29 + #_PT_ER_VMPSP);
357+
}
358+
#if CONFIG_HEXAGON_ARCH_VERSION < 4
240359
trap1(#HVM_TRAP1_VMSETREGS);
360+
#else
361+
G1:0 = R1:0;
362+
G3:2 = R3:2;
363+
#endif
241364

242365
R0 = R29
243366
restore_pt_regs()
244-
R1:0 = memd(R29 + #_PT_R0100);
245-
R29 = add(R29, #_PT_REGS_SIZE);
367+
{
368+
R1:0 = memd(R29 + #_PT_R0100);
369+
R29 = add(R29, #_PT_REGS_SIZE);
370+
}
246371
trap1(#HVM_TRAP1_VMRTE)
247372
/* Notreached */
248373

0 commit comments

Comments
 (0)