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/coprocessor.h>
19 #include <asm/current.h>
22 #if XTENSA_HAVE_COPROCESSORS
25 * Macros for lazy context switch.
28 #define SAVE_CP_REGS(x) \
29 .if XTENSA_HAVE_COPROCESSOR(x); \
31 .Lsave_cp_regs_cp##x: \
32 xchal_cp##x##_store a2 a4 a5 a6 a7; \
36 #define SAVE_CP_REGS_TAB(x) \
37 .if XTENSA_HAVE_COPROCESSOR(x); \
38 .long .Lsave_cp_regs_cp##x; \
42 .long THREAD_XTREGS_CP##x
45 #define LOAD_CP_REGS(x) \
46 .if XTENSA_HAVE_COPROCESSOR(x); \
48 .Lload_cp_regs_cp##x: \
49 xchal_cp##x##_load a2 a4 a5 a6 a7; \
53 #define LOAD_CP_REGS_TAB(x) \
54 .if XTENSA_HAVE_COPROCESSOR(x); \
55 .long .Lload_cp_regs_cp##x; \
59 .long THREAD_XTREGS_CP##x
79 .section ".rodata", "a"
81 .Lsave_cp_regs_jump_table:
91 .Lload_cp_regs_jump_table:
104 * coprocessor_flush(struct thread_info*, index)
107 * Save coprocessor registers for coprocessor 'index'.
108 * The register values are saved to or loaded from the coprocessor area
109 * inside the task_info structure.
111 * Note that this function doesn't update the coprocessor_owner information!
115 ENTRY(coprocessor_flush)
117 /* reserve 4 bytes on stack to save a0 */
121 movi a0, .Lsave_cp_regs_jump_table
132 ENDPROC(coprocessor_flush)
137 * a0: trashed, original value saved on stack (PT_AREG0)
139 * a2: new stack pointer, original in DEPC
141 * depc: a2, original value saved on stack (PT_DEPC)
142 * excsave_1: dispatch table
144 * PT_DEPC >= VALID_DOUBLE_EXCEPTION_ADDRESS: double exception, DEPC
145 * < VALID_DOUBLE_EXCEPTION_ADDRESS: regular exception
148 ENTRY(fast_coprocessor_double)
151 call0 unrecoverable_exception
153 ENDPROC(fast_coprocessor_double)
155 ENTRY(fast_coprocessor)
157 /* Save remaining registers a1-a3 and SAR */
159 s32i a3, a2, PT_AREG3
161 s32i a1, a2, PT_AREG1
165 s32i a2, a1, PT_AREG2
168 * The hal macros require up to 4 temporary registers. We use a3..a6.
171 s32i a4, a1, PT_AREG4
172 s32i a5, a1, PT_AREG5
173 s32i a6, a1, PT_AREG6
175 /* Find coprocessor number. Subtract first CP EXCCAUSE from EXCCAUSE */
178 addi a3, a3, -EXCCAUSE_COPROCESSOR0_DISABLED
180 /* Set corresponding CPENABLE bit -> (sar:cp-index, a3: 1<<cp-index)*/
182 ssl a3 # SAR: 32 - coprocessor_number
190 /* Retrieve previous owner. (a3 still holds CP number) */
192 movi a0, coprocessor_owner # list of owners
193 addx4 a0, a3, a0 # entry for CP
196 beqz a4, 1f # skip 'save' if no previous owner
198 /* Disable coprocessor for previous owner. (a2 = 1 << CP number) */
200 l32i a5, a4, THREAD_CPENABLE
201 xor a5, a5, a2 # (1 << cp-id) still in a2
202 s32i a5, a4, THREAD_CPENABLE
205 * Get context save area and 'call' save routine.
206 * (a4 still holds previous owner (thread_info), a3 CP number)
209 movi a5, .Lsave_cp_regs_jump_table
210 movi a0, 2f # a0: 'return' address
211 addx8 a3, a3, a5 # a3: coprocessor number
212 l32i a2, a3, 4 # a2: xtregs offset
213 l32i a3, a3, 0 # a3: jump address
217 /* Note that only a0 and a1 were preserved. */
220 addi a3, a3, -EXCCAUSE_COPROCESSOR0_DISABLED
221 movi a0, coprocessor_owner
224 /* Set new 'owner' (a0 points to the CP owner, a3 contains the CP nr) */
226 1: GET_THREAD_INFO (a4, a1)
229 /* Get context save area and 'call' load routine. */
231 movi a5, .Lload_cp_regs_jump_table
234 l32i a2, a3, 4 # a2: xtregs offset
235 l32i a3, a3, 0 # a3: jump address
239 /* Restore all registers and return from exception handler. */
241 1: l32i a6, a1, PT_AREG6
242 l32i a5, a1, PT_AREG5
243 l32i a4, a1, PT_AREG4
246 l32i a3, a1, PT_AREG3
247 l32i a2, a1, PT_AREG2
249 l32i a0, a1, PT_AREG0
250 l32i a1, a1, PT_AREG1
254 ENDPROC(fast_coprocessor)
258 ENTRY(coprocessor_owner)
260 .fill XCHAL_CP_MAX, 4, 0
262 END(coprocessor_owner)
264 #endif /* XTENSA_HAVE_COPROCESSORS */