4 * Copyright (C) 2009, 2012 Imagination Technologies.
6 * This program is free software; you can redistribute it and/or modify it under
7 * the terms of the GNU General Public License version 2 as published by the
8 * Free Software Foundation.
10 * Explicit state save and restore routines forming part of the thread binary
11 * interface for META processors
16 #include <asm/metag_regs.h>
21 * void *__TBICtxFPUSave( TBIRES State, void *pExt )
23 * D0Ar2 contains TBICTX_*_BIT values that control what
24 * extended data is to be saved.
25 * These bits must be ored into the SaveMask of this structure.
27 * Virtually all possible scratch registers are used.
31 .global ___TBICtxFPUSave
32 .type ___TBICtxFPUSave,function
35 /* D1Ar1:D0Ar2 - State
37 * D0Ar4 - Value of METAC_CORE_ID
42 /* If the FPAC bit isnt set then there is nothing to do */
43 TSTT D0Ar2,#TBICTX_FPAC_BIT
46 /* Obtain the Core config */
47 MOVT D0Ar4, #HI(METAC_CORE_ID)
48 ADD D0Ar4, D0Ar4, #LO(METAC_CORE_ID)
51 /* Detect FX.8 - FX.15 and add to core config */
53 AND D0Ar6, D0Ar6, #(TXENABLE_CLASSALT_FPUR8 << TXENABLE_CLASS_S)
54 AND D0Ar4, D0Ar4, #LO(0x0000FFFF)
55 ORT D0Ar4, D0Ar4, #HI(TBICTX_CFGFPU_FX16_BIT)
56 XOR D0Ar4, D0Ar4, D0Ar6
58 /* Save the relevant bits to the buffer */
61 /* Save the relevant bits of TXDEFR (Assumes TXDEFR is coherent) ... */
64 AND D0Re0, D0Re0, #LO(TXDEFR_FPE_FE_BITS>>8)
65 AND D0Ar6, D0Ar6, #LO(TXDEFR_FPE_ICTRL_BITS)
66 OR D0Re0, D0Re0, D0Ar6
68 /* ... along with relevant bits of TXMODE to buffer */
70 ANDT D0Ar6, D0Ar6, #HI(TXMODE_FPURMODE_BITS)
71 ORT D0Ar6, D0Ar6, #HI(TXMODE_FPURMODEWRITE_BIT)
72 OR D0Ar6, D0Ar6, D0Re0
75 GETD D0Ar6,[D1Ar1+#TBICTX_SaveMask-2] /* Get the current SaveMask */
76 /* D0Ar6 - pCtx->SaveMask */
78 TSTT D0Ar4, #HI(TBICTX_CFGFPU_FX16_BIT) /* Perform test here for extended FPU registers
81 /* Save the standard FPU registers */
82 F MSETL [D1Ar3++], FX.0, FX.2, FX.4, FX.6
84 /* Save the extended FPU registers if they are present */
85 BZ $Lskip_save_fx8_fx16
86 F MSETL [D1Ar3++], FX.8, FX.10, FX.12, FX.14
89 /* Save the FPU Accumulator if it is present */
90 TST D0Ar4, #METAC_COREID_NOFPACC_BIT
92 F SETL [D1Ar3++], ACF.0
93 F SETL [D1Ar3++], ACF.1
94 F SETL [D1Ar3++], ACF.2
97 /* Update pCtx->SaveMask */
98 ANDT D0Ar2, D0Ar2, #TBICTX_FPAC_BIT
99 OR D0Ar6, D0Ar6, D0Ar2
100 SETD [D1Ar1+#TBICTX_SaveMask-2],D0Ar6/* Add in XCBF bit to TBICTX */
102 MOV D0Re0, D1Ar3 /* Return end of save area */
105 .size ___TBICtxFPUSave,.-___TBICtxFPUSave
108 * void *__TBICtxFPURestore( TBIRES State, void *pExt )
110 * D0Ar2 contains TBICTX_*_BIT values that control what
111 * extended data is to be recovered from D1Ar3 (pExt).
113 * Virtually all possible scratch registers are used.
116 * If TBICTX_XEXT_BIT is specified in State. Then the saved state of
117 * the orginal A0.2 and A1.2 is restored from pExt and the XEXT
118 * related flags are removed from State.pCtx->SaveMask.
122 .global ___TBICtxFPURestore
123 .type ___TBICtxFPURestore,function
126 /* D1Ar1:D0Ar2 - State
128 * D0Ar4 - Value of METAC_CORE_ID
134 /* If the FPAC bit isnt set then there is nothing to do */
135 TSTT D0Ar2,#TBICTX_FPAC_BIT
138 /* Obtain the relevant bits of the Core config */
139 GETD D0Ar4, [D1Ar3++]
141 /* Restore FPU related parts of TXDEFR. Assumes TXDEFR is coherent */
142 GETD D1Ar5, [D1Ar3++]
145 ANDT D1Re0, D1Re0, #HI(TXDEFR_FPE_FE_BITS|TXDEFR_FPE_ICTRL_BITS)
146 AND D1Ar5, D1Ar5, #LO(TXDEFR_FPE_FE_BITS|TXDEFR_FPE_ICTRL_BITS)
147 OR D1Re0, D1Re0, D1Ar5
150 ANDMT D1Ar5, D1Ar5, #HI(~(TXDEFR_FPE_FE_BITS|TXDEFR_FPE_ICTRL_BITS))
151 ANDMB D1Ar5, D1Ar5, #LO(~(TXDEFR_FPE_FE_BITS|TXDEFR_FPE_ICTRL_BITS))
152 OR D1Re0, D1Re0, D1Ar5
155 /* Restore relevant bits of TXMODE */
157 ANDMT D1Ar5, D1Ar5, #HI(~TXMODE_FPURMODE_BITS)
158 ANDT D0Ar6, D0Ar6, #HI(TXMODE_FPURMODE_BITS|TXMODE_FPURMODEWRITE_BIT)
159 OR D0Ar6, D0Ar6, D1Ar5
162 TSTT D0Ar4, #HI(TBICTX_CFGFPU_FX16_BIT) /* Perform test here for extended FPU registers
165 /* Save the standard FPU registers */
166 F MGETL FX.0, FX.2, FX.4, FX.6, [D1Ar3++]
168 /* Save the extended FPU registers if they are present */
169 BZ $Lskip_restore_fx8_fx16
170 F MGETL FX.8, FX.10, FX.12, FX.14, [D1Ar3++]
171 $Lskip_restore_fx8_fx16:
173 /* Save the FPU Accumulator if it is present */
174 TST D0Ar4, #METAC_COREID_NOFPACC_BIT
175 BNZ $Lskip_restore_fpacc
176 F GETL ACF.0, [D1Ar3++]
177 F GETL ACF.1, [D1Ar3++]
178 F GETL ACF.2, [D1Ar3++]
179 $Lskip_restore_fpacc:
181 MOV D0Re0, D1Ar3 /* Return end of save area */
184 .size ___TBICtxFPURestore,.-___TBICtxFPURestore