Path: blob/master/arch/xtensa/kernel/coprocessor.S
10817 views
/*1* arch/xtensa/kernel/coprocessor.S2*3* Xtensa processor configuration-specific table of coprocessor and4* other custom register layout information.5*6* This file is subject to the terms and conditions of the GNU General Public7* License. See the file "COPYING" in the main directory of this archive8* for more details.9*10* Copyright (C) 2003 - 2007 Tensilica Inc.11*/121314#include <linux/linkage.h>15#include <asm/asm-offsets.h>16#include <asm/processor.h>17#include <asm/coprocessor.h>18#include <asm/thread_info.h>19#include <asm/uaccess.h>20#include <asm/unistd.h>21#include <asm/ptrace.h>22#include <asm/current.h>23#include <asm/pgtable.h>24#include <asm/page.h>25#include <asm/signal.h>26#include <asm/tlbflush.h>2728/*29* Entry condition:30*31* a0: trashed, original value saved on stack (PT_AREG0)32* a1: a133* a2: new stack pointer, original in DEPC34* a3: dispatch table35* depc: a2, original value saved on stack (PT_DEPC)36* excsave_1: a337*38* PT_DEPC >= VALID_DOUBLE_EXCEPTION_ADDRESS: double exception, DEPC39* < VALID_DOUBLE_EXCEPTION_ADDRESS: regular exception40*/4142/* IO protection is currently unsupported. */4344ENTRY(fast_io_protect)45wsr a0, EXCSAVE_146movi a0, unrecoverable_exception47callx0 a04849#if XTENSA_HAVE_COPROCESSORS5051/*52* Macros for lazy context switch.53*/5455#define SAVE_CP_REGS(x) \56.align 4; \57.Lsave_cp_regs_cp##x: \58.if XTENSA_HAVE_COPROCESSOR(x); \59xchal_cp##x##_store a2 a4 a5 a6 a7; \60.endif; \61jx a06263#define SAVE_CP_REGS_TAB(x) \64.if XTENSA_HAVE_COPROCESSOR(x); \65.long .Lsave_cp_regs_cp##x - .Lsave_cp_regs_jump_table; \66.else; \67.long 0; \68.endif; \69.long THREAD_XTREGS_CP##x707172#define LOAD_CP_REGS(x) \73.align 4; \74.Lload_cp_regs_cp##x: \75.if XTENSA_HAVE_COPROCESSOR(x); \76xchal_cp##x##_load a2 a4 a5 a6 a7; \77.endif; \78jx a07980#define LOAD_CP_REGS_TAB(x) \81.if XTENSA_HAVE_COPROCESSOR(x); \82.long .Lload_cp_regs_cp##x - .Lload_cp_regs_jump_table; \83.else; \84.long 0; \85.endif; \86.long THREAD_XTREGS_CP##x8788SAVE_CP_REGS(0)89SAVE_CP_REGS(1)90SAVE_CP_REGS(2)91SAVE_CP_REGS(3)92SAVE_CP_REGS(4)93SAVE_CP_REGS(5)94SAVE_CP_REGS(6)95SAVE_CP_REGS(7)9697LOAD_CP_REGS(0)98LOAD_CP_REGS(1)99LOAD_CP_REGS(2)100LOAD_CP_REGS(3)101LOAD_CP_REGS(4)102LOAD_CP_REGS(5)103LOAD_CP_REGS(6)104LOAD_CP_REGS(7)105106.align 4107.Lsave_cp_regs_jump_table:108SAVE_CP_REGS_TAB(0)109SAVE_CP_REGS_TAB(1)110SAVE_CP_REGS_TAB(2)111SAVE_CP_REGS_TAB(3)112SAVE_CP_REGS_TAB(4)113SAVE_CP_REGS_TAB(5)114SAVE_CP_REGS_TAB(6)115SAVE_CP_REGS_TAB(7)116117.Lload_cp_regs_jump_table:118LOAD_CP_REGS_TAB(0)119LOAD_CP_REGS_TAB(1)120LOAD_CP_REGS_TAB(2)121LOAD_CP_REGS_TAB(3)122LOAD_CP_REGS_TAB(4)123LOAD_CP_REGS_TAB(5)124LOAD_CP_REGS_TAB(6)125LOAD_CP_REGS_TAB(7)126127/*128* coprocessor_save(buffer, index)129* a2 a3130* coprocessor_load(buffer, index)131* a2 a3132*133* Save or load coprocessor registers for coprocessor 'index'.134* The register values are saved to or loaded from them 'buffer' address.135*136* Note that these functions don't update the coprocessor_owner information!137*138*/139140ENTRY(coprocessor_save)141entry a1, 32142s32i a0, a1, 0143movi a0, .Lsave_cp_regs_jump_table144addx8 a3, a3, a0145l32i a3, a3, 0146beqz a3, 1f147add a0, a0, a3148callx0 a01491: l32i a0, a1, 0150retw151152ENTRY(coprocessor_load)153entry a1, 32154s32i a0, a1, 0155movi a0, .Lload_cp_regs_jump_table156addx4 a3, a3, a0157l32i a3, a3, 0158beqz a3, 1f159add a0, a0, a3160callx0 a01611: l32i a0, a1, 0162retw163164/*165* coprocessor_flush(struct task_info*, index)166* a2 a3167* coprocessor_restore(struct task_info*, index)168* a2 a3169*170* Save or load coprocessor registers for coprocessor 'index'.171* The register values are saved to or loaded from the coprocessor area172* inside the task_info structure.173*174* Note that these functions don't update the coprocessor_owner information!175*176*/177178179ENTRY(coprocessor_flush)180entry a1, 32181s32i a0, a1, 0182movi a0, .Lsave_cp_regs_jump_table183addx8 a3, a3, a0184l32i a4, a3, 4185l32i a3, a3, 0186add a2, a2, a4187beqz a3, 1f188add a0, a0, a3189callx0 a01901: l32i a0, a1, 0191retw192193ENTRY(coprocessor_restore)194entry a1, 32195s32i a0, a1, 0196movi a0, .Lload_cp_regs_jump_table197addx4 a3, a3, a0198l32i a4, a3, 4199l32i a3, a3, 0200add a2, a2, a4201beqz a3, 1f202add a0, a0, a3203callx0 a02041: l32i a0, a1, 0205retw206207/*208* Entry condition:209*210* a0: trashed, original value saved on stack (PT_AREG0)211* a1: a1212* a2: new stack pointer, original in DEPC213* a3: dispatch table214* depc: a2, original value saved on stack (PT_DEPC)215* excsave_1: a3216*217* PT_DEPC >= VALID_DOUBLE_EXCEPTION_ADDRESS: double exception, DEPC218* < VALID_DOUBLE_EXCEPTION_ADDRESS: regular exception219*/220221ENTRY(fast_coprocessor_double)222wsr a0, EXCSAVE_1223movi a0, unrecoverable_exception224callx0 a0225226227ENTRY(fast_coprocessor)228229/* Save remaining registers a1-a3 and SAR */230231xsr a3, EXCSAVE_1232s32i a3, a2, PT_AREG3233rsr a3, SAR234s32i a1, a2, PT_AREG1235s32i a3, a2, PT_SAR236mov a1, a2237rsr a2, DEPC238s32i a2, a1, PT_AREG2239240/*241* The hal macros require up to 4 temporary registers. We use a3..a6.242*/243244s32i a4, a1, PT_AREG4245s32i a5, a1, PT_AREG5246s32i a6, a1, PT_AREG6247248/* Find coprocessor number. Subtract first CP EXCCAUSE from EXCCAUSE */249250rsr a3, EXCCAUSE251addi a3, a3, -EXCCAUSE_COPROCESSOR0_DISABLED252253/* Set corresponding CPENABLE bit -> (sar:cp-index, a3: 1<<cp-index)*/254255ssl a3 # SAR: 32 - coprocessor_number256movi a2, 1257rsr a0, CPENABLE258sll a2, a2259or a0, a0, a2260wsr a0, CPENABLE261rsync262263/* Retrieve previous owner. (a3 still holds CP number) */264265movi a0, coprocessor_owner # list of owners266addx4 a0, a3, a0 # entry for CP267l32i a4, a0, 0268269beqz a4, 1f # skip 'save' if no previous owner270271/* Disable coprocessor for previous owner. (a2 = 1 << CP number) */272273l32i a5, a4, THREAD_CPENABLE274xor a5, a5, a2 # (1 << cp-id) still in a2275s32i a5, a4, THREAD_CPENABLE276277/*278* Get context save area and 'call' save routine.279* (a4 still holds previous owner (thread_info), a3 CP number)280*/281282movi a5, .Lsave_cp_regs_jump_table283movi a0, 2f # a0: 'return' address284addx8 a3, a3, a5 # a3: coprocessor number285l32i a2, a3, 4 # a2: xtregs offset286l32i a3, a3, 0 # a3: jump offset287add a2, a2, a4288add a4, a3, a5 # a4: address of save routine289jx a4290291/* Note that only a0 and a1 were preserved. */2922932: rsr a3, EXCCAUSE294addi a3, a3, -EXCCAUSE_COPROCESSOR0_DISABLED295movi a0, coprocessor_owner296addx4 a0, a3, a0297298/* Set new 'owner' (a0 points to the CP owner, a3 contains the CP nr) */2993001: GET_THREAD_INFO (a4, a1)301s32i a4, a0, 0302303/* Get context save area and 'call' load routine. */304305movi a5, .Lload_cp_regs_jump_table306movi a0, 1f307addx8 a3, a3, a5308l32i a2, a3, 4 # a2: xtregs offset309l32i a3, a3, 0 # a3: jump offset310add a2, a2, a4311add a4, a3, a5312jx a4313314/* Restore all registers and return from exception handler. */3153161: l32i a6, a1, PT_AREG6317l32i a5, a1, PT_AREG5318l32i a4, a1, PT_AREG4319320l32i a0, a1, PT_SAR321l32i a3, a1, PT_AREG3322l32i a2, a1, PT_AREG2323wsr a0, SAR324l32i a0, a1, PT_AREG0325l32i a1, a1, PT_AREG1326327rfe328329.data330ENTRY(coprocessor_owner)331.fill XCHAL_CP_MAX, 4, 0332333#endif /* XTENSA_HAVE_COPROCESSORS */334335336337