1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Event entry/exit for Hexagon
5 * Copyright (c) 2010-2013, The Linux Foundation. All rights reserved.
8 #include <asm/asm-offsets.h> /* assembly-safer versions of C defines */
9 #include <asm/mem-layout.h> /* sigh, except for page_offset */
10 #include <asm/hexagon_vm.h>
11 #include <asm/thread_info.h>
14 * Entry into guest-mode Linux under Hexagon Virtual Machine.
15 * Stack pointer points to event record - build pt_regs on top of it,
16 * set up a plausible C stack frame, and dispatch to the C handler.
17 * On return, do vmrte virtual instruction with SP where we started.
19 * VM Spec 0.5 uses a trap to fetch HVM record now.
23 * Save full register state, while setting up thread_info struct
24 * pointer derived from kernel stack pointer in THREADINFO_REG
25 * register, putting prior thread_info.regs pointer in a callee-save
26 * register (R24, which had better not ever be assigned to THREADINFO_REG),
27 * and updating thread_info.regs to point to current stack frame,
28 * so as to support nested events in kernel mode.
30 * As this is common code, we set the pt_regs system call number
31 * to -1 for all events. It will be replaced with the system call
32 * number in the case where we decode a system call (trap0(#1)).
35 #if CONFIG_HEXAGON_ARCH_VERSION < 4
36 #define save_pt_regs()\
37 memd(R0 + #_PT_R3130) = R31:30; \
38 { memw(R0 + #_PT_R2928) = R28; \
39 R31 = memw(R0 + #_PT_ER_VMPSP); }\
40 { memw(R0 + #(_PT_R2928 + 4)) = R31; \
42 { memd(R0 + #_PT_R2726) = R27:26; \
44 memd(R0 + #_PT_R2524) = R25:24; \
45 memd(R0 + #_PT_R2322) = R23:22; \
46 memd(R0 + #_PT_R2120) = R21:20; \
47 memd(R0 + #_PT_R1918) = R19:18; \
48 memd(R0 + #_PT_R1716) = R17:16; \
49 memd(R0 + #_PT_R1514) = R15:14; \
50 memd(R0 + #_PT_R1312) = R13:12; \
51 { memd(R0 + #_PT_R1110) = R11:10; \
53 { memd(R0 + #_PT_R0908) = R9:8; \
55 { memd(R0 + #_PT_R0706) = R7:6; \
57 { memd(R0 + #_PT_R0504) = R5:4; \
59 { memd(R0 + #_PT_GPUGP) = R31:30; \
61 R2.H = #HI(_THREAD_SIZE); } \
62 { memd(R0 + #_PT_LC0SA0) = R15:14; \
64 R2.L = #LO(_THREAD_SIZE); } \
65 { memd(R0 + #_PT_LC1SA1) = R13:12; \
68 { memd(R0 + #_PT_M1M0) = R11:10; \
71 { memd(R0 + #_PT_PREDSUSR) = R15:14; \
72 THREADINFO_REG = R2; } \
73 { r24 = memw(THREADINFO_REG + #_THREAD_INFO_PT_REGS); \
74 memw(THREADINFO_REG + #_THREAD_INFO_PT_REGS) = R0; \
76 { memw(R0 + #_PT_SYSCALL_NR) = R2; \
80 /* the # ## # syntax inserts a literal ## */
81 #define save_pt_regs()\
82 { memd(R0 + #_PT_R3130) = R31:30; \
83 R30 = memw(R0 + #_PT_ER_VMPSP); }\
84 { memw(R0 + #_PT_R2928) = R28; \
85 memw(R0 + #(_PT_R2928 + 4)) = R30; }\
87 memd(R0 + #_PT_R2726) = R27:26; \
88 memd(R0 + #_PT_R2524) = R25:24; }\
89 { memd(R0 + #_PT_R2322) = R23:22; \
90 memd(R0 + #_PT_R2120) = R21:20; }\
91 { memd(R0 + #_PT_R1918) = R19:18; \
92 memd(R0 + #_PT_R1716) = R17:16; }\
93 { memd(R0 + #_PT_R1514) = R15:14; \
94 memd(R0 + #_PT_R1312) = R13:12; \
96 { memd(R0 + #_PT_R1110) = R11:10; \
97 memd(R0 + #_PT_R0908) = R9:8; \
99 { memd(R0 + #_PT_R0706) = R7:6; \
100 memd(R0 + #_PT_R0504) = R5:4; \
102 { memd(R0 + #_PT_GPUGP) = R31:30; \
103 memd(R0 + #_PT_LC0SA0) = R15:14; \
105 { THREADINFO_REG = and(R0, # ## #-_THREAD_SIZE); \
106 memd(R0 + #_PT_LC1SA1) = R13:12; \
108 { memd(R0 + #_PT_M1M0) = R11:10; \
109 memw(R0 + #_PT_PREDSUSR + 4) = R15; }\
110 { r24 = memw(THREADINFO_REG + #_THREAD_INFO_PT_REGS); \
111 memw(THREADINFO_REG + #_THREAD_INFO_PT_REGS) = R0; \
113 { memw(R0 + #_PT_SYSCALL_NR) = R2; \
114 memd(R0 + #_PT_CS1CS0) = R17:16; \
119 * Restore registers and thread_info.regs state. THREADINFO_REG
120 * is assumed to still be sane, and R24 to have been correctly
121 * preserved. Don't restore R29 (SP) until later.
124 #if CONFIG_HEXAGON_ARCH_VERSION < 4
125 #define restore_pt_regs() \
126 { memw(THREADINFO_REG + #_THREAD_INFO_PT_REGS) = R24; \
127 R15:14 = memd(R0 + #_PT_PREDSUSR); } \
128 { R11:10 = memd(R0 + #_PT_M1M0); \
130 { R13:12 = memd(R0 + #_PT_LC1SA1); \
132 { R15:14 = memd(R0 + #_PT_LC0SA0); \
134 { R3:2 = memd(R0 + #_PT_R0302); \
136 { R5:4 = memd(R0 + #_PT_R0504); \
138 { R7:6 = memd(R0 + #_PT_R0706); \
140 { R9:8 = memd(R0 + #_PT_R0908); \
142 { R11:10 = memd(R0 + #_PT_R1110); \
144 { R13:12 = memd(R0 + #_PT_R1312); \
145 R15:14 = memd(R0 + #_PT_R1514); } \
146 { R17:16 = memd(R0 + #_PT_R1716); \
147 R19:18 = memd(R0 + #_PT_R1918); } \
148 { R21:20 = memd(R0 + #_PT_R2120); \
149 R23:22 = memd(R0 + #_PT_R2322); } \
150 { R25:24 = memd(R0 + #_PT_R2524); \
151 R27:26 = memd(R0 + #_PT_R2726); } \
152 R31:30 = memd(R0 + #_PT_GPUGP); \
153 { R28 = memw(R0 + #_PT_R2928); \
155 { R31:30 = memd(R0 + #_PT_R3130); \
159 #define restore_pt_regs() \
160 { memw(THREADINFO_REG + #_THREAD_INFO_PT_REGS) = R24; \
161 R15:14 = memd(R0 + #_PT_PREDSUSR); } \
162 { R11:10 = memd(R0 + #_PT_M1M0); \
163 R13:12 = memd(R0 + #_PT_LC1SA1); \
165 { R15:14 = memd(R0 + #_PT_LC0SA0); \
166 R3:2 = memd(R0 + #_PT_R0302); \
168 { R5:4 = memd(R0 + #_PT_R0504); \
169 R7:6 = memd(R0 + #_PT_R0706); \
171 { R9:8 = memd(R0 + #_PT_R0908); \
172 R11:10 = memd(R0 + #_PT_R1110); \
174 { R13:12 = memd(R0 + #_PT_R1312); \
175 R15:14 = memd(R0 + #_PT_R1514); \
177 { R17:16 = memd(R0 + #_PT_R1716); \
178 R19:18 = memd(R0 + #_PT_R1918); } \
179 { R21:20 = memd(R0 + #_PT_R2120); \
180 R23:22 = memd(R0 + #_PT_R2322); } \
181 { R25:24 = memd(R0 + #_PT_R2524); \
182 R27:26 = memd(R0 + #_PT_R2726); } \
183 R31:30 = memd(R0 + #_PT_CS1CS0); \
185 R31:30 = memd(R0 + #_PT_GPUGP) ; \
186 R28 = memw(R0 + #_PT_R2928); }\
188 R31:30 = memd(R0 + #_PT_R3130); }
192 * Clears off enough space for the rest of pt_regs; evrec is a part
193 * of pt_regs in HVM mode. Save R0/R1, set handler's address in R1.
194 * R0 is the address of pt_regs and is the parameter to save_pt_regs.
198 * Since the HVM isn't automagically pushing the EVREC onto the stack anymore,
199 * we'll subract the entire size out and then fill it in ourselves.
200 * Need to save off R0, R1, R2, R3 immediately.
203 #if CONFIG_HEXAGON_ARCH_VERSION < 4
204 #define vm_event_entry(CHandler) \
206 R29 = add(R29, #-(_PT_REGS_SIZE)); \
207 memd(R29 + #(_PT_R0100 + -_PT_REGS_SIZE)) = R1:0; \
210 memd(R29 +#_PT_R0302) = R3:2; \
212 trap1(#HVM_TRAP1_VMGETREGS); \
214 memd(R29 + #_PT_ER_VMEL) = R1:0; \
216 R1.L = #LO(CHandler); \
219 memd(R29 + #_PT_ER_VMPSP) = R3:2; \
220 R1.H = #HI(CHandler); \
221 jump event_dispatch; \
225 /* turn on I$ prefetch early */
226 /* the # ## # syntax inserts a literal ## */
227 #define vm_event_entry(CHandler) \
229 R29 = add(R29, #-(_PT_REGS_SIZE)); \
230 memd(R29 + #(_PT_R0100 + -_PT_REGS_SIZE)) = R1:0; \
231 memd(R29 + #(_PT_R0302 + -_PT_REGS_SIZE)) = R3:2; \
235 memw(R29 + #_PT_PREDSUSR) = R0; \
236 R0 = setbit(R0, #16); \
241 memd(R29 + #_PT_ER_VMEL) = R1:0; \
242 R1 = # ## #(CHandler); \
247 memd(R29 + #_PT_ER_VMPSP) = R3:2; \
248 jump event_dispatch; \
254 * Do bulk save/restore in one place.
255 * Adds a jump to dispatch latency, but
256 * saves hundreds of bytes.
264 * Coming back from the C-world, our thread info pointer
265 * should be in the designated register (usually R19)
267 * If we were in kernel mode, we don't need to check scheduler
268 * or signals if CONFIG_PREEMPTION is not set. If set, then it has
269 * to jump to a need_resched kind of block.
270 * BTW, CONFIG_PREEMPTION is not supported yet.
273 #ifdef CONFIG_PREEMPTION
275 trap1(#HVM_TRAP1_VMSETIE)
278 /* "Nested control path" -- if the previous mode was kernel */
280 R0 = memw(R29 + #_PT_ER_VMEST);
281 R26.L = #LO(do_work_pending);
284 P0 = tstbit(R0, #HVM_VMEST_UM_SFT);
285 if (!P0.new) jump:nt restore_all;
286 R26.H = #HI(do_work_pending);
287 R0 = #VM_INT_DISABLE;
291 * Check also the return from fork/system call, normally coming back from
294 * R26 needs to have do_work_pending, and R0 should have VM_INT_DISABLE
298 /* Disable interrupts while checking TIF */
299 trap1(#HVM_TRAP1_VMSETIE)
301 R0 = R29; /* regs should still be at top of stack */
302 R1 = memw(THREADINFO_REG + #_THREAD_INFO_FLAGS);
307 P0 = cmp.eq(R0, #0); if (!P0.new) jump:nt check_work_pending;
308 R0 = #VM_INT_DISABLE;
313 * Disable interrupts, if they weren't already, before reg restore.
314 * R0 gets preloaded with #VM_INT_DISABLE before we get here.
316 trap1(#HVM_TRAP1_VMSETIE)
318 /* do the setregs here for VM 0.5 */
319 /* R29 here should already be pointing at pt_regs */
321 R1:0 = memd(R29 + #_PT_ER_VMEL);
322 R3:2 = memd(R29 + #_PT_ER_VMPSP);
324 #if CONFIG_HEXAGON_ARCH_VERSION < 4
325 trap1(#HVM_TRAP1_VMSETREGS);
334 R1:0 = memd(R29 + #_PT_R0100);
335 R29 = add(R29, #_PT_REGS_SIZE);
337 trap1(#HVM_TRAP1_VMRTE)
341 .globl _K_enter_genex
343 vm_event_entry(do_genex)
345 .globl _K_enter_interrupt
347 vm_event_entry(arch_do_IRQ)
349 .globl _K_enter_trap0
351 vm_event_entry(do_trap0)
353 .globl _K_enter_machcheck
355 vm_event_entry(do_machcheck)
357 .globl _K_enter_debug
359 vm_event_entry(do_debug_exception)
365 R26.H = #HI(do_work_pending);
368 P0 = cmp.eq(R24, #0);
369 R26.L = #LO(do_work_pending);
370 R0 = #VM_INT_DISABLE;
372 if (P0) jump check_work_pending
378 jump check_work_pending
379 R0 = #VM_INT_DISABLE;