fpu.S 3.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
/*
 *  FPU support code, moved here from head.S so that it can be used
 *  by chips which use other head-whatever.S files.
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU General Public License
 *  as published by the Free Software Foundation; either version
 *  2 of the License, or (at your option) any later version.
 *
 */

#include <linux/config.h>
13
#include <asm/reg.h>
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
#include <asm/page.h>
#include <asm/mmu.h>
#include <asm/pgtable.h>
#include <asm/cputable.h>
#include <asm/cache.h>
#include <asm/thread_info.h>
#include <asm/ppc_asm.h>
#include <asm/asm-offsets.h>

/*
 * This task wants to use the FPU now.
 * On UP, disable FP for the task which had the FPU previously,
 * and save its floating-point registers in its thread_struct.
 * Load up this task's FP registers from its thread_struct,
 * enable the FPU for the current task and return to the task.
 */
30
_GLOBAL(load_up_fpu)
31 32 33 34 35 36 37 38 39 40 41
	mfmsr	r5
	ori	r5,r5,MSR_FP
	SYNC
	MTMSRD(r5)			/* enable use of fpu now */
	isync
/*
 * For SMP, we don't do lazy FPU switching because it just gets too
 * horrendously complex, especially when a task switches from one CPU
 * to another.  Instead we call giveup_fpu in switch_to.
 */
#ifndef CONFIG_SMP
42
	LOAD_REG_ADDRBASE(r3, last_task_used_math)
43
	toreal(r3)
44
	PPC_LL	r4,ADDROFF(last_task_used_math)(r3)
45
	PPC_LCMPI	0,r4,0
46
	beq	1f
47
	toreal(r4)
48 49 50
	addi	r4,r4,THREAD		/* want last_task_used_math->thread */
	SAVE_32FPRS(0, r4)
	mffs	fr0
51
	stfd	fr0,THREAD_FPSCR(r4)
52
	PPC_LL	r5,PT_REGS(r4)
53
	toreal(r5)
54
	PPC_LL	r4,_MSR-STACK_FRAME_OVERHEAD(r5)
55 56
	li	r10,MSR_FP|MSR_FE0|MSR_FE1
	andc	r4,r4,r10		/* disable FP for previous task */
57
	PPC_STL	r4,_MSR-STACK_FRAME_OVERHEAD(r5)
58 59 60
1:
#endif /* CONFIG_SMP */
	/* enable use of FP after return */
61
#ifdef CONFIG_PPC32
62 63 64 65
	mfspr	r5,SPRN_SPRG3		/* current task's THREAD (phys) */
	lwz	r4,THREAD_FPEXC_MODE(r5)
	ori	r9,r9,MSR_FP		/* enable FP for current */
	or	r9,r9,r4
66 67 68
#else
	ld	r4,PACACURRENT(r13)
	addi	r5,r4,THREAD		/* Get THREAD */
69
	lwz	r4,THREAD_FPEXC_MODE(r5)
70 71 72 73
	ori	r12,r12,MSR_FP
	or	r12,r12,r4
	std	r12,_MSR(r1)
#endif
74
	lfd	fr0,THREAD_FPSCR(r5)
75 76 77 78
	mtfsf	0xff,fr0
	REST_32FPRS(0, r5)
#ifndef CONFIG_SMP
	subi	r4,r5,THREAD
79
	fromreal(r4)
80
	PPC_STL	r4,ADDROFF(last_task_used_math)(r3)
81 82 83 84 85 86 87 88 89 90 91
#endif /* CONFIG_SMP */
	/* restore registers and return */
	/* we haven't used ctr or xer or lr */
	b	fast_exception_return

/*
 * giveup_fpu(tsk)
 * Disable FP for the task given as the argument,
 * and save the floating-point registers in its thread_struct.
 * Enables the FPU for use in the kernel on return.
 */
92
_GLOBAL(giveup_fpu)
93 94 95 96 97 98 99
	mfmsr	r5
	ori	r5,r5,MSR_FP
	SYNC_601
	ISYNC_601
	MTMSRD(r5)			/* enable use of fpu now */
	SYNC_601
	isync
100
	PPC_LCMPI	0,r3,0
101 102
	beqlr-				/* if no previous owner, done */
	addi	r3,r3,THREAD	        /* want THREAD of task */
103 104
	PPC_LL	r5,PT_REGS(r3)
	PPC_LCMPI	0,r5,0
105 106
	SAVE_32FPRS(0, r3)
	mffs	fr0
107
	stfd	fr0,THREAD_FPSCR(r3)
108
	beq	1f
109
	PPC_LL	r4,_MSR-STACK_FRAME_OVERHEAD(r5)
110 111
	li	r3,MSR_FP|MSR_FE0|MSR_FE1
	andc	r4,r4,r3		/* disable FP for previous task */
112
	PPC_STL	r4,_MSR-STACK_FRAME_OVERHEAD(r5)
113 114 115
1:
#ifndef CONFIG_SMP
	li	r5,0
116 117
	LOAD_REG_ADDRBASE(r4,last_task_used_math)
	PPC_STL	r5,ADDROFF(last_task_used_math)(r4)
118 119
#endif /* CONFIG_SMP */
	blr
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

/*
 * These are used in the alignment trap handler when emulating
 * single-precision loads and stores.
 * We restore and save the fpscr so the task gets the same result
 * and exceptions as if the cpu had performed the load or store.
 */

_GLOBAL(cvt_fd)
	lfd	0,THREAD_FPSCR(r5)	/* load up fpscr value */
	mtfsf	0xff,0
	lfs	0,0(r3)
	stfd	0,0(r4)
	mffs	0
	stfd	0,THREAD_FPSCR(r5)	/* save new fpscr value */
	blr

_GLOBAL(cvt_df)
	lfd	0,THREAD_FPSCR(r5)	/* load up fpscr value */
	mtfsf	0xff,0
	lfd	0,0(r3)
	stfs	0,0(r4)
	mffs	0
	stfd	0,THREAD_FPSCR(r5)	/* save new fpscr value */
	blr