1 /* SPDX-License-Identifier: GPL-2.0
3 * arch/sh/kernel/cpu/sh5/switchto.S
7 * Copyright (C) 2004 Richard Curnow
10 .section .text..SHmedia32,"ax"
15 .type sh64_switch_to,@function
16 .global sh64_switch_to
17 .global __sh64_switch_to_end
27 r2 - last (=prev) : this just stays in r2 throughout
29 Want to create a full (struct pt_regs) on the stack to allow backtracing
30 functions to work. However, we only need to populate the callee-save
31 register slots in this structure; since we're a function our ancestors must
32 have themselves preserved all caller saved state in the stack. This saves
33 some wasted effort since we won't need to look at the values.
35 In particular, all caller-save registers are immediately available for
40 #define FRAME_SIZE (76*8 + 8)
44 ! Do normal-style register save to support backtrace
46 st.l r15, 0, r18 ! save link reg
47 st.l r15, 4, r14 ! save fp
48 add.l r15, r63, r14 ! setup frame pointer
50 ! hopefully this looks normal to the backtrace now.
52 addi.l r15, 8, r1 ! base of pt_regs
53 addi.l r1, 24, r0 ! base of pt_regs.regs
54 addi.l r0, (63*8), r8 ! base of pt_regs.trregs
56 /* Note : to be fixed?
57 struct pt_regs is really designed for holding the state on entry
58 to an exception, i.e. pc,sr,regs etc. However, for the context
59 switch state, some of this is not required. But the unwinder takes
60 struct pt_regs * as an arg so we have to build this structure
61 to allow unwinding switched tasks in show_state() */
68 st.q r0, (14*8), r14 ! for unwind, want to look as though we took a trap at
69 ! the point where the process is left in suspended animation, i.e. current
70 ! fp here, not the saved one.
103 ! do this early as pta->gettr has no pipeline forwarding (=> 5 cycle latency)
104 ! Use a local label to avoid creating a symbol that will confuse the !
117 st.l r3, 0, r15 ! prev->thread.sp
118 st.l r3, 8, r1 ! prev->thread.kregs
119 st.l r3, 4, r9 ! prev->thread.pc
120 st.q r1, 0, r9 ! save prev->thread.pc into pt_regs->pc
122 ! Load PC for next task (init value or save_pc later)
123 ld.l r5, 4, r18 ! next->thread.pc
125 ld.l r5, 0, r15 ! next->thread.sp
129 ld.l r4, 4, r9 ! next->thread_info (2nd element of next task_struct)
130 putcon r9, kcr0 ! current = next->thread_info
132 ! go to save_pc for a reschedule, or the initial thread.pc for a new process
135 ! Restore (when we come back to a previously saved task)
137 addi.l r15, 32, r0 ! r0 = next's regs
138 addi.l r0, (63*8), r8 ! r8 = next's tr_regs
192 __sh64_switch_to_end:
194 .size sh64_switch_to,.LFE1-sh64_switch_to