aboutsummaryrefslogtreecommitdiffstats
path: root/arch/mn10300/kernel/fpu-low.S
blob: 78df25cfae2936f8071ab5d7f312dc363d58c2d6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
/* MN10300 Low level FPU management operations
 *
 * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
 * Written by David Howells (dhowells@redhat.com)
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public Licence
 * as published by the Free Software Foundation; either version
 * 2 of the Licence, or (at your option) any later version.
 */
#include <linux/linkage.h>
#include <asm/cpu-regs.h>
#include <asm/smp.h>
#include <asm/thread_info.h>
#include <asm/asm-offsets.h>
#include <asm/frame.inc>

.macro FPU_INIT_STATE_ALL
	fmov	0,fs0
	fmov	fs0,fs1
	fmov	fs0,fs2
	fmov	fs0,fs3
	fmov	fs0,fs4
	fmov	fs0,fs5
	fmov	fs0,fs6
	fmov	fs0,fs7
	fmov	fs0,fs8
	fmov	fs0,fs9
	fmov	fs0,fs10
	fmov	fs0,fs11
	fmov	fs0,fs12
	fmov	fs0,fs13
	fmov	fs0,fs14
	fmov	fs0,fs15
	fmov	fs0,fs16
	fmov	fs0,fs17
	fmov	fs0,fs18
	fmov	fs0,fs19
	fmov	fs0,fs20
	fmov	fs0,fs21
	fmov	fs0,fs22
	fmov	fs0,fs23
	fmov	fs0,fs24
	fmov	fs0,fs25
	fmov	fs0,fs26
	fmov	fs0,fs27
	fmov	fs0,fs28
	fmov	fs0,fs29
	fmov	fs0,fs30
	fmov	fs0,fs31
	fmov	FPCR_INIT,fpcr
.endm

.macro FPU_SAVE_ALL areg,dreg
	fmov	fs0,(\areg+)
	fmov	fs1,(\areg+)
	fmov	fs2,(\areg+)
	fmov	fs3,(\areg+)
	fmov	fs4,(\areg+)
	fmov	fs5,(\areg+)
	fmov	fs6,(\areg+)
	fmov	fs7,(\areg+)
	fmov	fs8,(\areg+)
	fmov	fs9,(\areg+)
	fmov	fs10,(\areg+)
	fmov	fs11,(\areg+)
	fmov	fs12,(\areg+)
	fmov	fs13,(\areg+)
	fmov	fs14,(\areg+)
	fmov	fs15,(\areg+)
	fmov	fs16,(\areg+)
	fmov	fs17,(\areg+)
	fmov	fs18,(\areg+)
	fmov	fs19,(\areg+)
	fmov	fs20,(\areg+)
	fmov	fs21,(\areg+)
	fmov	fs22,(\areg+)
	fmov	fs23,(\areg+)
	fmov	fs24,(\areg+)
	fmov	fs25,(\areg+)
	fmov	fs26,(\areg+)
	fmov	fs27,(\areg+)
	fmov	fs28,(\areg+)
	fmov	fs29,(\areg+)
	fmov	fs30,(\areg+)
	fmov	fs31,(\areg+)
	fmov	fpcr,\dreg
	mov	\dreg,(\areg)
.endm

.macro FPU_RESTORE_ALL areg,dreg
	fmov	(\areg+),fs0
	fmov	(\areg+),fs1
	fmov	(\areg+),fs2
	fmov	(\areg+),fs3
	fmov	(\areg+),fs4
	fmov	(\areg+),fs5
	fmov	(\areg+),fs6
	fmov	(\areg+),fs7
	fmov	(\areg+),fs8
	fmov	(\areg+),fs9
	fmov	(\areg+),fs10
	fmov	(\areg+),fs11
	fmov	(\areg+),fs12
	fmov	(\areg+),fs13
	fmov	(\areg+),fs14
	fmov	(\areg+),fs15
	fmov	(\areg+),fs16
	fmov	(\areg+),fs17
	fmov	(\areg+),fs18
	fmov	(\areg+),fs19
	fmov	(\areg+),fs20
	fmov	(\areg+),fs21
	fmov	(\areg+),fs22
	fmov	(\areg+),fs23
	fmov	(\areg+),fs24
	fmov	(\areg+),fs25
	fmov	(\areg+),fs26
	fmov	(\areg+),fs27
	fmov	(\areg+),fs28
	fmov	(\areg+),fs29
	fmov	(\areg+),fs30
	fmov	(\areg+),fs31
	mov	(\areg),\dreg
	fmov	\dreg,fpcr
.endm

###############################################################################
#
# void fpu_init_state(void)
# - initialise the FPU
#
###############################################################################
	.globl	fpu_init_state
	.type	fpu_init_state,@function
fpu_init_state:
	mov	epsw,d0
	or	EPSW_FE,epsw

#ifdef CONFIG_MN10300_PROC_MN103E010
	nop
	nop
	nop
#endif
	FPU_INIT_STATE_ALL
#ifdef CONFIG_MN10300_PROC_MN103E010
	nop
	nop
	nop
#endif
	mov	d0,epsw
	ret	[],0

	.size	fpu_init_state,.-fpu_init_state

###############################################################################
#
# void fpu_save(struct fpu_state_struct *)
# - save the fpu state
# - note that an FPU Operational exception might occur during this process
#
###############################################################################
	.globl	fpu_save
	.type	fpu_save,@function
fpu_save:
	mov	epsw,d1
	or	EPSW_FE,epsw		/* enable the FPU so we can access it */

#ifdef CONFIG_MN10300_PROC_MN103E010
	nop
	nop
#endif
	mov	d0,a0
	FPU_SAVE_ALL	a0,d0
#ifdef CONFIG_MN10300_PROC_MN103E010
	nop
	nop
#endif

	mov	d1,epsw
	ret	[],0

	.size	fpu_save,.-fpu_save

###############################################################################
#
# void fpu_disabled(void)
# - handle an exception due to the FPU being disabled
#   when CONFIG_FPU is enabled
#
###############################################################################
	.type	fpu_disabled,@function
	.globl	fpu_disabled
fpu_disabled:
	or	EPSW_nAR|EPSW_FE,epsw
	nop
	nop
	nop

	mov	sp,a1
	mov	(a1),d1			/* get epsw of user context */
	and	~(THREAD_SIZE-1),a1	/* a1: (thread_info *ti) */
	mov	(TI_task,a1),a2		/* a2: (task_struct *tsk) */
	btst	EPSW_nSL,d1
	beq	fpu_used_in_kernel

	or	EPSW_FE,d1
	mov	d1,(sp)
	mov	(TASK_THREAD+THREAD_FPU_FLAGS,a2),d1
#ifndef CONFIG_LAZY_SAVE_FPU
	or	__THREAD_HAS_FPU,d1
	mov	d1,(TASK_THREAD+THREAD_FPU_FLAGS,a2)
#else  /* !CONFIG_LAZY_SAVE_FPU */
	mov	(fpu_state_owner),a0
	cmp	0,a0
	beq	fpu_regs_save_end

	mov	(TASK_THREAD+THREAD_UREGS,a0),a1
	add	TASK_THREAD+THREAD_FPU_STATE,a0
	FPU_SAVE_ALL a0,d0

	mov	(REG_EPSW,a1),d0
	and	~EPSW_FE,d0
	mov	d0,(REG_EPSW,a1)

fpu_regs_save_end:
	mov	a2,(fpu_state_owner)
#endif /* !CONFIG_LAZY_SAVE_FPU */

	btst	__THREAD_USING_FPU,d1
	beq	fpu_regs_init
	add	TASK_THREAD+THREAD_FPU_STATE,a2
	FPU_RESTORE_ALL a2,d0
	rti

fpu_regs_init:
	FPU_INIT_STATE_ALL
	add	TASK_THREAD+THREAD_FPU_FLAGS,a2
	bset	__THREAD_USING_FPU,(0,a2)
	rti

fpu_used_in_kernel:
	and	~(EPSW_nAR|EPSW_FE),epsw
	nop
	nop

	add	-4,sp
	SAVE_ALL
	mov	-1,d0
	mov	d0,(REG_ORIG_D0,fp)

	and	~EPSW_NMID,epsw

	mov	fp,d0
	call	fpu_disabled_in_kernel[],0
	jmp	ret_from_exception

	.size	fpu_disabled,.-fpu_disabled