1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * linux/arch/arm/vfp/vfphw.S
5 * Copyright (C) 2004 ARM Limited.
6 * Written by Deep Blue Solutions Limited.
8 #include <linux/init.h>
9 #include <linux/linkage.h>
10 #include <asm/thread_info.h>
11 #include <asm/vfpmacros.h>
12 #include <linux/kern_levels.h>
13 #include <asm/assembler.h>
14 #include <asm/asm-offsets.h>
16 .macro DBGSTR1, str, arg
18 stmfd sp!, {r0-r3, ip, lr}
22 ldmfd sp!, {r0-r3, ip, lr}
24 .pushsection .rodata, "a"
25 1: .ascii KERN_DEBUG "VFP: \str\n"
32 @ Load the current VFP state
35 DBGSTR1 "load VFP state %p", r0
36 @ Load the saved state back into the VFP
37 VFPFLDMIA r0, r1 @ reload the working registers while
38 @ FPEXC is in a safe state
39 ldmia r0, {r0-r3} @ load FPEXC, FPSCR, FPINST, FPINST2
40 tst r0, #FPEXC_EX @ is there additional state to restore?
42 VFPFMXR FPINST, r2 @ restore FPINST (only if FPEXC.EX is set)
43 tst r0, #FPEXC_FP2V @ is there an FPINST2 to write?
45 VFPFMXR FPINST2, r3 @ FPINST2 if needed (and present)
47 VFPFMXR FPSCR, r1 @ restore status
49 ENDPROC(vfp_load_state)
52 @ Save the current VFP state
55 DBGSTR1 "save VFP state %p", r0
56 VFPFSTMIA r0, r2 @ save the working registers
57 VFPFMRX r2, FPSCR @ current status
58 tst r1, #FPEXC_EX @ is there additional state to save?
60 VFPFMRX r3, FPINST @ FPINST (only if FPEXC.EX is set)
61 tst r1, #FPEXC_FP2V @ is there an FPINST2 to read?
63 VFPFMRX r12, FPINST2 @ FPINST2 if needed (and present)
65 stmia r0, {r1, r2, r3, r12} @ save FPEXC, FPSCR, FPINST, FPINST2
67 ENDPROC(vfp_save_state)
69 .macro tbl_branch, base, tmp, shift
70 #ifdef CONFIG_THUMB2_KERNEL
72 add \tmp, \tmp, \base, lsl \shift
75 add pc, pc, \base, lsl \shift
84 .irp dr,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
89 .irp dr,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31
94 ENDPROC(vfp_get_float)
99 .irp dr,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
104 .irp dr,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31
109 ENDPROC(vfp_put_float)
111 ENTRY(vfp_get_double)
112 tbl_branch r0, r3, #3
114 .irp dr,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
120 @ d16 - d31 registers
122 .irp dr,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31
129 @ virtual register 16 (or 32 if VFPv3) for compare with zero
133 ENDPROC(vfp_get_double)
135 ENTRY(vfp_put_double)
136 tbl_branch r2, r3, #3
138 .irp dr,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
145 @ d16 - d31 registers
146 .irp dr,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31
152 ENDPROC(vfp_put_double)