1 // SPDX-License-Identifier: GPL-2.0-only
3 * fpu.c - save/restore of Floating Point Unit Registers on task switch
5 * Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
8 #include <linux/sched.h>
11 #ifdef CONFIG_ISA_ARCOMPACT
14 * To save/restore FPU regs, simplest scheme would use LR/SR insns.
15 * However since SR serializes the pipeline, an alternate "hack" can be used
16 * which uses the FPU Exchange insn (DEXCL) to r/w FPU regs.
18 * Store to 64bit dpfp1 reg from a pair of core regs:
19 * dexcl1 0, r1, r0 ; where r1:r0 is the 64 bit val
21 * Read from dpfp1 into pair of core regs (w/o clobbering dpfp1)
23 * daddh11 r1, r3, r3 ; get "hi" into r1 (dpfp1 unchanged)
24 * dexcl1 r0, r1, r3 ; get "low" into r0 (dpfp1 low clobbered)
25 * dexcl1 0, r1, r0 ; restore dpfp1 to orig value
27 * However we can tweak the read, so that read-out of outgoing task's FPU regs
28 * and write of incoming task's regs happen in one shot. So all the work is
29 * done before context switch
32 void fpu_save_restore(struct task_struct
*prev
, struct task_struct
*next
)
34 unsigned int *saveto
= &prev
->thread
.fpu
.aux_dpfp
[0].l
;
35 unsigned int *readfrom
= &next
->thread
.fpu
.aux_dpfp
[0].l
;
37 const unsigned int zero
= 0;
40 "daddh11 %0, %2, %2\n"
42 : "=&r" (*(saveto
+ 1)), /* early clobber must here */
44 : "r" (zero
), "r" (*(readfrom
+ 1)), "r" (*(readfrom
))
48 "daddh22 %0, %2, %2\n"
50 : "=&r"(*(saveto
+ 3)), /* early clobber must here */
52 : "r" (zero
), "r" (*(readfrom
+ 3)), "r" (*(readfrom
+ 2))
58 void fpu_init_task(struct pt_regs
*regs
)
60 /* default rounding mode */
61 write_aux_reg(ARC_REG_FPU_CTRL
, 0x100);
63 /* set "Write enable" to allow explicit write to exception flags */
64 write_aux_reg(ARC_REG_FPU_STATUS
, 0x80000000);
67 void fpu_save_restore(struct task_struct
*prev
, struct task_struct
*next
)
69 struct arc_fpu
*save
= &prev
->thread
.fpu
;
70 struct arc_fpu
*restore
= &next
->thread
.fpu
;
72 save
->ctrl
= read_aux_reg(ARC_REG_FPU_CTRL
);
73 save
->status
= read_aux_reg(ARC_REG_FPU_STATUS
);
75 write_aux_reg(ARC_REG_FPU_CTRL
, restore
->ctrl
);
76 write_aux_reg(ARC_REG_FPU_STATUS
, restore
->status
);