xref: /linux/arch/alpha/lib/fpreg.c (revision 69bfec7548f4c1595bac0e3ddfc0458a5af31f4c)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * arch/alpha/lib/fpreg.c
4  *
5  * (C) Copyright 1998 Linus Torvalds
6  */
7 
8 #include <linux/compiler.h>
9 #include <linux/export.h>
10 #include <linux/preempt.h>
11 #include <asm/thread_info.h>
12 
13 #if defined(CONFIG_ALPHA_EV6) || defined(CONFIG_ALPHA_EV67)
14 #define STT(reg,val)  asm volatile ("ftoit $f"#reg",%0" : "=r"(val));
15 #else
16 #define STT(reg,val)  asm volatile ("stt $f"#reg",%0" : "=m"(val));
17 #endif
18 
19 unsigned long
20 alpha_read_fp_reg (unsigned long reg)
21 {
22 	unsigned long val;
23 
24 	if (unlikely(reg >= 32))
25 		return 0;
26 	preempt_disable();
27 	if (current_thread_info()->status & TS_SAVED_FP)
28 		val = current_thread_info()->fp[reg];
29 	else switch (reg) {
30 	      case  0: STT( 0, val); break;
31 	      case  1: STT( 1, val); break;
32 	      case  2: STT( 2, val); break;
33 	      case  3: STT( 3, val); break;
34 	      case  4: STT( 4, val); break;
35 	      case  5: STT( 5, val); break;
36 	      case  6: STT( 6, val); break;
37 	      case  7: STT( 7, val); break;
38 	      case  8: STT( 8, val); break;
39 	      case  9: STT( 9, val); break;
40 	      case 10: STT(10, val); break;
41 	      case 11: STT(11, val); break;
42 	      case 12: STT(12, val); break;
43 	      case 13: STT(13, val); break;
44 	      case 14: STT(14, val); break;
45 	      case 15: STT(15, val); break;
46 	      case 16: STT(16, val); break;
47 	      case 17: STT(17, val); break;
48 	      case 18: STT(18, val); break;
49 	      case 19: STT(19, val); break;
50 	      case 20: STT(20, val); break;
51 	      case 21: STT(21, val); break;
52 	      case 22: STT(22, val); break;
53 	      case 23: STT(23, val); break;
54 	      case 24: STT(24, val); break;
55 	      case 25: STT(25, val); break;
56 	      case 26: STT(26, val); break;
57 	      case 27: STT(27, val); break;
58 	      case 28: STT(28, val); break;
59 	      case 29: STT(29, val); break;
60 	      case 30: STT(30, val); break;
61 	      case 31: STT(31, val); break;
62 	}
63 	preempt_enable();
64 	return val;
65 }
66 EXPORT_SYMBOL(alpha_read_fp_reg);
67 
68 #if defined(CONFIG_ALPHA_EV6) || defined(CONFIG_ALPHA_EV67)
69 #define LDT(reg,val)  asm volatile ("itoft %0,$f"#reg : : "r"(val));
70 #else
71 #define LDT(reg,val)  asm volatile ("ldt $f"#reg",%0" : : "m"(val));
72 #endif
73 
74 void
75 alpha_write_fp_reg (unsigned long reg, unsigned long val)
76 {
77 	if (unlikely(reg >= 32))
78 		return;
79 
80 	preempt_disable();
81 	if (current_thread_info()->status & TS_SAVED_FP) {
82 		current_thread_info()->status |= TS_RESTORE_FP;
83 		current_thread_info()->fp[reg] = val;
84 	} else switch (reg) {
85 	      case  0: LDT( 0, val); break;
86 	      case  1: LDT( 1, val); break;
87 	      case  2: LDT( 2, val); break;
88 	      case  3: LDT( 3, val); break;
89 	      case  4: LDT( 4, val); break;
90 	      case  5: LDT( 5, val); break;
91 	      case  6: LDT( 6, val); break;
92 	      case  7: LDT( 7, val); break;
93 	      case  8: LDT( 8, val); break;
94 	      case  9: LDT( 9, val); break;
95 	      case 10: LDT(10, val); break;
96 	      case 11: LDT(11, val); break;
97 	      case 12: LDT(12, val); break;
98 	      case 13: LDT(13, val); break;
99 	      case 14: LDT(14, val); break;
100 	      case 15: LDT(15, val); break;
101 	      case 16: LDT(16, val); break;
102 	      case 17: LDT(17, val); break;
103 	      case 18: LDT(18, val); break;
104 	      case 19: LDT(19, val); break;
105 	      case 20: LDT(20, val); break;
106 	      case 21: LDT(21, val); break;
107 	      case 22: LDT(22, val); break;
108 	      case 23: LDT(23, val); break;
109 	      case 24: LDT(24, val); break;
110 	      case 25: LDT(25, val); break;
111 	      case 26: LDT(26, val); break;
112 	      case 27: LDT(27, val); break;
113 	      case 28: LDT(28, val); break;
114 	      case 29: LDT(29, val); break;
115 	      case 30: LDT(30, val); break;
116 	      case 31: LDT(31, val); break;
117 	}
118 	preempt_enable();
119 }
120 EXPORT_SYMBOL(alpha_write_fp_reg);
121 
122 #if defined(CONFIG_ALPHA_EV6) || defined(CONFIG_ALPHA_EV67)
123 #define STS(reg,val)  asm volatile ("ftois $f"#reg",%0" : "=r"(val));
124 #else
125 #define STS(reg,val)  asm volatile ("sts $f"#reg",%0" : "=m"(val));
126 #endif
127 
128 unsigned long
129 alpha_read_fp_reg_s (unsigned long reg)
130 {
131 	unsigned long val;
132 
133 	if (unlikely(reg >= 32))
134 		return 0;
135 
136 	preempt_disable();
137 	if (current_thread_info()->status & TS_SAVED_FP) {
138 		LDT(0, current_thread_info()->fp[reg]);
139 		STS(0, val);
140 	} else switch (reg) {
141 	      case  0: STS( 0, val); break;
142 	      case  1: STS( 1, val); break;
143 	      case  2: STS( 2, val); break;
144 	      case  3: STS( 3, val); break;
145 	      case  4: STS( 4, val); break;
146 	      case  5: STS( 5, val); break;
147 	      case  6: STS( 6, val); break;
148 	      case  7: STS( 7, val); break;
149 	      case  8: STS( 8, val); break;
150 	      case  9: STS( 9, val); break;
151 	      case 10: STS(10, val); break;
152 	      case 11: STS(11, val); break;
153 	      case 12: STS(12, val); break;
154 	      case 13: STS(13, val); break;
155 	      case 14: STS(14, val); break;
156 	      case 15: STS(15, val); break;
157 	      case 16: STS(16, val); break;
158 	      case 17: STS(17, val); break;
159 	      case 18: STS(18, val); break;
160 	      case 19: STS(19, val); break;
161 	      case 20: STS(20, val); break;
162 	      case 21: STS(21, val); break;
163 	      case 22: STS(22, val); break;
164 	      case 23: STS(23, val); break;
165 	      case 24: STS(24, val); break;
166 	      case 25: STS(25, val); break;
167 	      case 26: STS(26, val); break;
168 	      case 27: STS(27, val); break;
169 	      case 28: STS(28, val); break;
170 	      case 29: STS(29, val); break;
171 	      case 30: STS(30, val); break;
172 	      case 31: STS(31, val); break;
173 	}
174 	preempt_enable();
175 	return val;
176 }
177 EXPORT_SYMBOL(alpha_read_fp_reg_s);
178 
179 #if defined(CONFIG_ALPHA_EV6) || defined(CONFIG_ALPHA_EV67)
180 #define LDS(reg,val)  asm volatile ("itofs %0,$f"#reg : : "r"(val));
181 #else
182 #define LDS(reg,val)  asm volatile ("lds $f"#reg",%0" : : "m"(val));
183 #endif
184 
185 void
186 alpha_write_fp_reg_s (unsigned long reg, unsigned long val)
187 {
188 	if (unlikely(reg >= 32))
189 		return;
190 
191 	preempt_disable();
192 	if (current_thread_info()->status & TS_SAVED_FP) {
193 		current_thread_info()->status |= TS_RESTORE_FP;
194 		LDS(0, val);
195 		STT(0, current_thread_info()->fp[reg]);
196 	} else switch (reg) {
197 	      case  0: LDS( 0, val); break;
198 	      case  1: LDS( 1, val); break;
199 	      case  2: LDS( 2, val); break;
200 	      case  3: LDS( 3, val); break;
201 	      case  4: LDS( 4, val); break;
202 	      case  5: LDS( 5, val); break;
203 	      case  6: LDS( 6, val); break;
204 	      case  7: LDS( 7, val); break;
205 	      case  8: LDS( 8, val); break;
206 	      case  9: LDS( 9, val); break;
207 	      case 10: LDS(10, val); break;
208 	      case 11: LDS(11, val); break;
209 	      case 12: LDS(12, val); break;
210 	      case 13: LDS(13, val); break;
211 	      case 14: LDS(14, val); break;
212 	      case 15: LDS(15, val); break;
213 	      case 16: LDS(16, val); break;
214 	      case 17: LDS(17, val); break;
215 	      case 18: LDS(18, val); break;
216 	      case 19: LDS(19, val); break;
217 	      case 20: LDS(20, val); break;
218 	      case 21: LDS(21, val); break;
219 	      case 22: LDS(22, val); break;
220 	      case 23: LDS(23, val); break;
221 	      case 24: LDS(24, val); break;
222 	      case 25: LDS(25, val); break;
223 	      case 26: LDS(26, val); break;
224 	      case 27: LDS(27, val); break;
225 	      case 28: LDS(28, val); break;
226 	      case 29: LDS(29, val); break;
227 	      case 30: LDS(30, val); break;
228 	      case 31: LDS(31, val); break;
229 	}
230 	preempt_enable();
231 }
232 EXPORT_SYMBOL(alpha_write_fp_reg_s);
233