2 * arch/xtensa/kernel/coprocessor.S
4 * Xtensa processor configuration-specific table of coprocessor and
5 * other custom register layout information.
7 * This file is subject to the terms and conditions of the GNU General Public
8 * License. See the file "COPYING" in the main directory of this archive
11 * Copyright (C) 2003 - 2007 Tensilica Inc.
15 #include <linux/linkage.h>
16 #include <asm/asm-offsets.h>
17 #include <asm/asmmacro.h>
18 #include <asm/processor.h>
19 #include <asm/coprocessor.h>
20 #include <asm/thread_info.h>
21 #include <asm/asm-uaccess.h>
22 #include <asm/unistd.h>
23 #include <asm/ptrace.h>
24 #include <asm/current.h>
25 #include <asm/pgtable.h>
27 #include <asm/signal.h>
28 #include <asm/tlbflush.h>
30 #if XTENSA_HAVE_COPROCESSORS
33 * Macros for lazy context switch.
36 #define SAVE_CP_REGS(x) \
37 .if XTENSA_HAVE_COPROCESSOR(x); \
39 .Lsave_cp_regs_cp##x: \
40 xchal_cp##x##_store a2 a3 a4 a5 a6; \
44 #define SAVE_CP_REGS_TAB(x) \
45 .if XTENSA_HAVE_COPROCESSOR(x); \
46 .long .Lsave_cp_regs_cp##x; \
50 .long THREAD_XTREGS_CP##x
53 #define LOAD_CP_REGS(x) \
54 .if XTENSA_HAVE_COPROCESSOR(x); \
56 .Lload_cp_regs_cp##x: \
57 xchal_cp##x##_load a2 a3 a4 a5 a6; \
61 #define LOAD_CP_REGS_TAB(x) \
62 .if XTENSA_HAVE_COPROCESSOR(x); \
63 .long .Lload_cp_regs_cp##x; \
67 .long THREAD_XTREGS_CP##x
87 .section ".rodata", "a"
89 .Lsave_cp_regs_jump_table:
99 .Lload_cp_regs_jump_table:
114 * a0: trashed, original value saved on stack (PT_AREG0)
116 * a2: new stack pointer, original in DEPC
118 * depc: a2, original value saved on stack (PT_DEPC)
119 * excsave_1: dispatch table
121 * PT_DEPC >= VALID_DOUBLE_EXCEPTION_ADDRESS: double exception, DEPC
122 * < VALID_DOUBLE_EXCEPTION_ADDRESS: regular exception
125 ENTRY(fast_coprocessor_double)
128 call0 unrecoverable_exception
130 ENDPROC(fast_coprocessor_double)
132 ENTRY(fast_coprocessor)
134 /* Save remaining registers a1-a3 and SAR */
136 s32i a3, a2, PT_AREG3
138 s32i a1, a2, PT_AREG1
142 s32i a2, a1, PT_AREG2
145 * The hal macros require up to 4 temporary registers. We use a3..a6.
148 s32i a4, a1, PT_AREG4
149 s32i a5, a1, PT_AREG5
150 s32i a6, a1, PT_AREG6
152 /* Find coprocessor number. Subtract first CP EXCCAUSE from EXCCAUSE */
155 addi a3, a3, -EXCCAUSE_COPROCESSOR0_DISABLED
157 /* Set corresponding CPENABLE bit -> (sar:cp-index, a3: 1<<cp-index)*/
159 ssl a3 # SAR: 32 - coprocessor_number
167 /* Retrieve previous owner. (a3 still holds CP number) */
169 movi a0, coprocessor_owner # list of owners
170 addx4 a0, a3, a0 # entry for CP
173 beqz a4, 1f # skip 'save' if no previous owner
175 /* Disable coprocessor for previous owner. (a2 = 1 << CP number) */
177 l32i a5, a4, THREAD_CPENABLE
178 xor a5, a5, a2 # (1 << cp-id) still in a2
179 s32i a5, a4, THREAD_CPENABLE
182 * Get context save area and 'call' save routine.
183 * (a4 still holds previous owner (thread_info), a3 CP number)
186 movi a5, .Lsave_cp_regs_jump_table
187 movi a0, 2f # a0: 'return' address
188 addx8 a3, a3, a5 # a3: coprocessor number
189 l32i a2, a3, 4 # a2: xtregs offset
190 l32i a3, a3, 0 # a3: jump address
194 /* Note that only a0 and a1 were preserved. */
197 addi a3, a3, -EXCCAUSE_COPROCESSOR0_DISABLED
198 movi a0, coprocessor_owner
201 /* Set new 'owner' (a0 points to the CP owner, a3 contains the CP nr) */
203 1: GET_THREAD_INFO (a4, a1)
206 /* Get context save area and 'call' load routine. */
208 movi a5, .Lload_cp_regs_jump_table
211 l32i a2, a3, 4 # a2: xtregs offset
212 l32i a3, a3, 0 # a3: jump address
216 /* Restore all registers and return from exception handler. */
218 1: l32i a6, a1, PT_AREG6
219 l32i a5, a1, PT_AREG5
220 l32i a4, a1, PT_AREG4
223 l32i a3, a1, PT_AREG3
224 l32i a2, a1, PT_AREG2
226 l32i a0, a1, PT_AREG0
227 l32i a1, a1, PT_AREG1
231 ENDPROC(fast_coprocessor)
236 * coprocessor_flush(struct thread_info*, index)
239 * Save coprocessor registers for coprocessor 'index'.
240 * The register values are saved to or loaded from the coprocessor area
241 * inside the task_info structure.
243 * Note that this function doesn't update the coprocessor_owner information!
247 ENTRY(coprocessor_flush)
249 /* reserve 4 bytes on stack to save a0 */
253 movi a0, .Lsave_cp_regs_jump_table
264 ENDPROC(coprocessor_flush)
268 ENTRY(coprocessor_owner)
270 .fill XCHAL_CP_MAX, 4, 0
272 END(coprocessor_owner)
274 #endif /* XTENSA_HAVE_COPROCESSORS */