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/processor.h>
18 #include <asm/coprocessor.h>
19 #include <asm/thread_info.h>
20 #include <asm/asm-uaccess.h>
21 #include <asm/unistd.h>
22 #include <asm/ptrace.h>
23 #include <asm/current.h>
24 #include <asm/pgtable.h>
26 #include <asm/signal.h>
27 #include <asm/tlbflush.h>
29 #if XTENSA_HAVE_COPROCESSORS
32 * Macros for lazy context switch.
35 #define SAVE_CP_REGS(x) \
36 .if XTENSA_HAVE_COPROCESSOR(x); \
38 .Lsave_cp_regs_cp##x: \
39 xchal_cp##x##_store a2 a4 a5 a6 a7; \
43 #define SAVE_CP_REGS_TAB(x) \
44 .if XTENSA_HAVE_COPROCESSOR(x); \
45 .long .Lsave_cp_regs_cp##x; \
49 .long THREAD_XTREGS_CP##x
52 #define LOAD_CP_REGS(x) \
53 .if XTENSA_HAVE_COPROCESSOR(x); \
55 .Lload_cp_regs_cp##x: \
56 xchal_cp##x##_load a2 a4 a5 a6 a7; \
60 #define LOAD_CP_REGS_TAB(x) \
61 .if XTENSA_HAVE_COPROCESSOR(x); \
62 .long .Lload_cp_regs_cp##x; \
66 .long THREAD_XTREGS_CP##x
86 .section ".rodata", "a"
88 .Lsave_cp_regs_jump_table:
98 .Lload_cp_regs_jump_table:
111 * coprocessor_flush(struct thread_info*, index)
114 * Save coprocessor registers for coprocessor 'index'.
115 * The register values are saved to or loaded from the coprocessor area
116 * inside the task_info structure.
118 * Note that this function doesn't update the coprocessor_owner information!
122 ENTRY(coprocessor_flush)
126 movi a0, .Lsave_cp_regs_jump_table
136 ENDPROC(coprocessor_flush)
141 * a0: trashed, original value saved on stack (PT_AREG0)
143 * a2: new stack pointer, original in DEPC
145 * depc: a2, original value saved on stack (PT_DEPC)
146 * excsave_1: dispatch table
148 * PT_DEPC >= VALID_DOUBLE_EXCEPTION_ADDRESS: double exception, DEPC
149 * < VALID_DOUBLE_EXCEPTION_ADDRESS: regular exception
152 ENTRY(fast_coprocessor_double)
155 call0 unrecoverable_exception
157 ENDPROC(fast_coprocessor_double)
159 ENTRY(fast_coprocessor)
161 /* Save remaining registers a1-a3 and SAR */
163 s32i a3, a2, PT_AREG3
165 s32i a1, a2, PT_AREG1
169 s32i a2, a1, PT_AREG2
172 * The hal macros require up to 4 temporary registers. We use a3..a6.
175 s32i a4, a1, PT_AREG4
176 s32i a5, a1, PT_AREG5
177 s32i a6, a1, PT_AREG6
179 /* Find coprocessor number. Subtract first CP EXCCAUSE from EXCCAUSE */
182 addi a3, a3, -EXCCAUSE_COPROCESSOR0_DISABLED
184 /* Set corresponding CPENABLE bit -> (sar:cp-index, a3: 1<<cp-index)*/
186 ssl a3 # SAR: 32 - coprocessor_number
194 /* Retrieve previous owner. (a3 still holds CP number) */
196 movi a0, coprocessor_owner # list of owners
197 addx4 a0, a3, a0 # entry for CP
200 beqz a4, 1f # skip 'save' if no previous owner
202 /* Disable coprocessor for previous owner. (a2 = 1 << CP number) */
204 l32i a5, a4, THREAD_CPENABLE
205 xor a5, a5, a2 # (1 << cp-id) still in a2
206 s32i a5, a4, THREAD_CPENABLE
209 * Get context save area and 'call' save routine.
210 * (a4 still holds previous owner (thread_info), a3 CP number)
213 movi a5, .Lsave_cp_regs_jump_table
214 movi a0, 2f # a0: 'return' address
215 addx8 a3, a3, a5 # a3: coprocessor number
216 l32i a2, a3, 4 # a2: xtregs offset
217 l32i a3, a3, 0 # a3: jump address
221 /* Note that only a0 and a1 were preserved. */
224 addi a3, a3, -EXCCAUSE_COPROCESSOR0_DISABLED
225 movi a0, coprocessor_owner
228 /* Set new 'owner' (a0 points to the CP owner, a3 contains the CP nr) */
230 1: GET_THREAD_INFO (a4, a1)
233 /* Get context save area and 'call' load routine. */
235 movi a5, .Lload_cp_regs_jump_table
238 l32i a2, a3, 4 # a2: xtregs offset
239 l32i a3, a3, 0 # a3: jump address
243 /* Restore all registers and return from exception handler. */
245 1: l32i a6, a1, PT_AREG6
246 l32i a5, a1, PT_AREG5
247 l32i a4, a1, PT_AREG4
250 l32i a3, a1, PT_AREG3
251 l32i a2, a1, PT_AREG2
253 l32i a0, a1, PT_AREG0
254 l32i a1, a1, PT_AREG1
258 ENDPROC(fast_coprocessor)
262 ENTRY(coprocessor_owner)
264 .fill XCHAL_CP_MAX, 4, 0
266 END(coprocessor_owner)
268 #endif /* XTENSA_HAVE_COPROCESSORS */