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) \
37 .Lsave_cp_regs_cp##x: \
38 .if XTENSA_HAVE_COPROCESSOR(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 - .Lsave_cp_regs_jump_table; \
49 .long THREAD_XTREGS_CP##x
52 #define LOAD_CP_REGS(x) \
54 .Lload_cp_regs_cp##x: \
55 .if XTENSA_HAVE_COPROCESSOR(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 - .Lload_cp_regs_jump_table; \
66 .long THREAD_XTREGS_CP##x
87 .Lsave_cp_regs_jump_table:
97 .Lload_cp_regs_jump_table:
108 * coprocessor_save(buffer, index)
110 * coprocessor_load(buffer, index)
113 * Save or load coprocessor registers for coprocessor 'index'.
114 * The register values are saved to or loaded from them 'buffer' address.
116 * Note that these functions don't update the coprocessor_owner information!
120 ENTRY(coprocessor_save)
124 movi a0, .Lsave_cp_regs_jump_table
133 ENDPROC(coprocessor_save)
135 ENTRY(coprocessor_load)
139 movi a0, .Lload_cp_regs_jump_table
148 ENDPROC(coprocessor_load)
151 * coprocessor_flush(struct task_info*, index)
153 * coprocessor_restore(struct task_info*, index)
156 * Save or load coprocessor registers for coprocessor 'index'.
157 * The register values are saved to or loaded from the coprocessor area
158 * inside the task_info structure.
160 * Note that these functions don't update the coprocessor_owner information!
165 ENTRY(coprocessor_flush)
169 movi a0, .Lsave_cp_regs_jump_table
180 ENDPROC(coprocessor_flush)
182 ENTRY(coprocessor_restore)
185 movi a0, .Lload_cp_regs_jump_table
196 ENDPROC(coprocessor_restore)
201 * a0: trashed, original value saved on stack (PT_AREG0)
203 * a2: new stack pointer, original in DEPC
205 * depc: a2, original value saved on stack (PT_DEPC)
206 * excsave_1: dispatch table
208 * PT_DEPC >= VALID_DOUBLE_EXCEPTION_ADDRESS: double exception, DEPC
209 * < VALID_DOUBLE_EXCEPTION_ADDRESS: regular exception
212 ENTRY(fast_coprocessor_double)
215 call0 unrecoverable_exception
217 ENDPROC(fast_coprocessor_double)
219 ENTRY(fast_coprocessor)
221 /* Save remaining registers a1-a3 and SAR */
223 s32i a3, a2, PT_AREG3
225 s32i a1, a2, PT_AREG1
229 s32i a2, a1, PT_AREG2
232 * The hal macros require up to 4 temporary registers. We use a3..a6.
235 s32i a4, a1, PT_AREG4
236 s32i a5, a1, PT_AREG5
237 s32i a6, a1, PT_AREG6
239 /* Find coprocessor number. Subtract first CP EXCCAUSE from EXCCAUSE */
242 addi a3, a3, -EXCCAUSE_COPROCESSOR0_DISABLED
244 /* Set corresponding CPENABLE bit -> (sar:cp-index, a3: 1<<cp-index)*/
246 ssl a3 # SAR: 32 - coprocessor_number
254 /* Retrieve previous owner. (a3 still holds CP number) */
256 movi a0, coprocessor_owner # list of owners
257 addx4 a0, a3, a0 # entry for CP
260 beqz a4, 1f # skip 'save' if no previous owner
262 /* Disable coprocessor for previous owner. (a2 = 1 << CP number) */
264 l32i a5, a4, THREAD_CPENABLE
265 xor a5, a5, a2 # (1 << cp-id) still in a2
266 s32i a5, a4, THREAD_CPENABLE
269 * Get context save area and 'call' save routine.
270 * (a4 still holds previous owner (thread_info), a3 CP number)
273 movi a5, .Lsave_cp_regs_jump_table
274 movi a0, 2f # a0: 'return' address
275 addx8 a3, a3, a5 # a3: coprocessor number
276 l32i a2, a3, 4 # a2: xtregs offset
277 l32i a3, a3, 0 # a3: jump offset
279 add a4, a3, a5 # a4: address of save routine
282 /* Note that only a0 and a1 were preserved. */
285 addi a3, a3, -EXCCAUSE_COPROCESSOR0_DISABLED
286 movi a0, coprocessor_owner
289 /* Set new 'owner' (a0 points to the CP owner, a3 contains the CP nr) */
291 1: GET_THREAD_INFO (a4, a1)
294 /* Get context save area and 'call' load routine. */
296 movi a5, .Lload_cp_regs_jump_table
299 l32i a2, a3, 4 # a2: xtregs offset
300 l32i a3, a3, 0 # a3: jump offset
305 /* Restore all registers and return from exception handler. */
307 1: l32i a6, a1, PT_AREG6
308 l32i a5, a1, PT_AREG5
309 l32i a4, a1, PT_AREG4
312 l32i a3, a1, PT_AREG3
313 l32i a2, a1, PT_AREG2
315 l32i a0, a1, PT_AREG0
316 l32i a1, a1, PT_AREG1
320 ENDPROC(fast_coprocessor)
324 ENTRY(coprocessor_owner)
326 .fill XCHAL_CP_MAX, 4, 0
328 END(coprocessor_owner)
330 #endif /* XTENSA_HAVE_COPROCESSORS */