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/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>
32 * a0: trashed, original value saved on stack (PT_AREG0)
34 * a2: new stack pointer, original in DEPC
36 * depc: a2, original value saved on stack (PT_DEPC)
37 * excsave_1: dispatch table
39 * PT_DEPC >= VALID_DOUBLE_EXCEPTION_ADDRESS: double exception, DEPC
40 * < VALID_DOUBLE_EXCEPTION_ADDRESS: regular exception
43 /* IO protection is currently unsupported. */
45 ENTRY(fast_io_protect)
48 movi a0, unrecoverable_exception
51 ENDPROC(fast_io_protect)
53 #if XTENSA_HAVE_COPROCESSORS
56 * Macros for lazy context switch.
59 #define SAVE_CP_REGS(x) \
61 .Lsave_cp_regs_cp##x: \
62 .if XTENSA_HAVE_COPROCESSOR(x); \
63 xchal_cp##x##_store a2 a4 a5 a6 a7; \
67 #define SAVE_CP_REGS_TAB(x) \
68 .if XTENSA_HAVE_COPROCESSOR(x); \
69 .long .Lsave_cp_regs_cp##x - .Lsave_cp_regs_jump_table; \
73 .long THREAD_XTREGS_CP##x
76 #define LOAD_CP_REGS(x) \
78 .Lload_cp_regs_cp##x: \
79 .if XTENSA_HAVE_COPROCESSOR(x); \
80 xchal_cp##x##_load a2 a4 a5 a6 a7; \
84 #define LOAD_CP_REGS_TAB(x) \
85 .if XTENSA_HAVE_COPROCESSOR(x); \
86 .long .Lload_cp_regs_cp##x - .Lload_cp_regs_jump_table; \
90 .long THREAD_XTREGS_CP##x
111 .Lsave_cp_regs_jump_table:
121 .Lload_cp_regs_jump_table:
132 * coprocessor_save(buffer, index)
134 * coprocessor_load(buffer, index)
137 * Save or load coprocessor registers for coprocessor 'index'.
138 * The register values are saved to or loaded from them 'buffer' address.
140 * Note that these functions don't update the coprocessor_owner information!
144 ENTRY(coprocessor_save)
148 movi a0, .Lsave_cp_regs_jump_table
157 ENDPROC(coprocessor_save)
159 ENTRY(coprocessor_load)
163 movi a0, .Lload_cp_regs_jump_table
172 ENDPROC(coprocessor_load)
175 * coprocessor_flush(struct task_info*, index)
177 * coprocessor_restore(struct task_info*, index)
180 * Save or load coprocessor registers for coprocessor 'index'.
181 * The register values are saved to or loaded from the coprocessor area
182 * inside the task_info structure.
184 * Note that these functions don't update the coprocessor_owner information!
189 ENTRY(coprocessor_flush)
193 movi a0, .Lsave_cp_regs_jump_table
204 ENDPROC(coprocessor_flush)
206 ENTRY(coprocessor_restore)
209 movi a0, .Lload_cp_regs_jump_table
220 ENDPROC(coprocessor_restore)
225 * a0: trashed, original value saved on stack (PT_AREG0)
227 * a2: new stack pointer, original in DEPC
229 * depc: a2, original value saved on stack (PT_DEPC)
230 * excsave_1: dispatch table
232 * PT_DEPC >= VALID_DOUBLE_EXCEPTION_ADDRESS: double exception, DEPC
233 * < VALID_DOUBLE_EXCEPTION_ADDRESS: regular exception
236 ENTRY(fast_coprocessor_double)
239 movi a0, unrecoverable_exception
242 ENDPROC(fast_coprocessor_double)
244 ENTRY(fast_coprocessor)
246 /* Save remaining registers a1-a3 and SAR */
248 s32i a3, a2, PT_AREG3
250 s32i a1, a2, PT_AREG1
254 s32i a2, a1, PT_AREG2
257 * The hal macros require up to 4 temporary registers. We use a3..a6.
260 s32i a4, a1, PT_AREG4
261 s32i a5, a1, PT_AREG5
262 s32i a6, a1, PT_AREG6
264 /* Find coprocessor number. Subtract first CP EXCCAUSE from EXCCAUSE */
267 addi a3, a3, -EXCCAUSE_COPROCESSOR0_DISABLED
269 /* Set corresponding CPENABLE bit -> (sar:cp-index, a3: 1<<cp-index)*/
271 ssl a3 # SAR: 32 - coprocessor_number
279 /* Retrieve previous owner. (a3 still holds CP number) */
281 movi a0, coprocessor_owner # list of owners
282 addx4 a0, a3, a0 # entry for CP
285 beqz a4, 1f # skip 'save' if no previous owner
287 /* Disable coprocessor for previous owner. (a2 = 1 << CP number) */
289 l32i a5, a4, THREAD_CPENABLE
290 xor a5, a5, a2 # (1 << cp-id) still in a2
291 s32i a5, a4, THREAD_CPENABLE
294 * Get context save area and 'call' save routine.
295 * (a4 still holds previous owner (thread_info), a3 CP number)
298 movi a5, .Lsave_cp_regs_jump_table
299 movi a0, 2f # a0: 'return' address
300 addx8 a3, a3, a5 # a3: coprocessor number
301 l32i a2, a3, 4 # a2: xtregs offset
302 l32i a3, a3, 0 # a3: jump offset
304 add a4, a3, a5 # a4: address of save routine
307 /* Note that only a0 and a1 were preserved. */
310 addi a3, a3, -EXCCAUSE_COPROCESSOR0_DISABLED
311 movi a0, coprocessor_owner
314 /* Set new 'owner' (a0 points to the CP owner, a3 contains the CP nr) */
316 1: GET_THREAD_INFO (a4, a1)
319 /* Get context save area and 'call' load routine. */
321 movi a5, .Lload_cp_regs_jump_table
324 l32i a2, a3, 4 # a2: xtregs offset
325 l32i a3, a3, 0 # a3: jump offset
330 /* Restore all registers and return from exception handler. */
332 1: l32i a6, a1, PT_AREG6
333 l32i a5, a1, PT_AREG5
334 l32i a4, a1, PT_AREG4
337 l32i a3, a1, PT_AREG3
338 l32i a2, a1, PT_AREG2
340 l32i a0, a1, PT_AREG0
341 l32i a1, a1, PT_AREG1
345 ENDPROC(fast_coprocessor)
349 ENTRY(coprocessor_owner)
351 .fill XCHAL_CP_MAX, 4, 0
353 END(coprocessor_owner)
355 #endif /* XTENSA_HAVE_COPROCESSORS */