2005-09-26 10:04:21 +04:00
/ *
* FPU s u p p o r t c o d e , m o v e d h e r e f r o m h e a d . S s o t h a t i t c a n b e u s e d
* by c h i p s w h i c h u s e o t h e r h e a d - w h a t e v e r . S f i l e s .
*
2006-08-30 08:45:35 +04:00
* Copyright ( C ) 1 9 9 5 - 1 9 9 6 G a r y T h o m a s ( g d t @linuxppc.org)
* Copyright ( C ) 1 9 9 6 C o r t D o u g a n < c o r t @cs.nmt.edu>
* Copyright ( C ) 1 9 9 6 P a u l M a c k e r r a s .
* Copyright ( C ) 1 9 9 7 D a n M a l e k ( d m a l e k @jlc.net).
*
2005-09-26 10:04:21 +04:00
* This p r o g r a m i s f r e e s o f t w a r e ; you can redistribute it and/or
* modify i t u n d e r t h e t e r m s o f t h e G N U G e n e r a l P u b l i c L i c e n s e
* as p u b l i s h e d b y t h e F r e e S o f t w a r e F o u n d a t i o n ; either version
* 2 of t h e L i c e n s e , o r ( a t y o u r o p t i o n ) a n y l a t e r v e r s i o n .
*
* /
2005-10-10 16:20:10 +04:00
# include < a s m / r e g . h >
2005-09-26 10:04:21 +04:00
# include < a s m / p a g e . h >
# include < a s m / m m u . h >
# include < a s m / p g t a b l e . h >
# include < a s m / c p u t a b l e . h >
# include < a s m / c a c h e . h >
# include < a s m / t h r e a d _ i n f o . h >
# include < a s m / p p c _ a s m . h >
# include < a s m / a s m - o f f s e t s . h >
2010-11-18 18:06:17 +03:00
# include < a s m / p t r a c e . h >
2005-09-26 10:04:21 +04:00
2008-06-25 08:07:18 +04:00
# ifdef C O N F I G _ V S X
2012-06-25 17:33:23 +04:00
# define _ _ R E S T _ 3 2 F P V S R S ( n ,c ,b a s e ) \
2008-06-25 08:07:18 +04:00
BEGIN_ F T R _ S E C T I O N \
b 2 f ; \
END_ F T R _ S E C T I O N _ I F S E T ( C P U _ F T R _ V S X ) ; \
REST_ 3 2 F P R S ( n ,b a s e ) ; \
b 3 f ; \
2 : REST_ 3 2 V S R S ( n ,c ,b a s e ) ; \
3 :
2012-06-25 17:33:23 +04:00
# define _ _ S A V E _ 3 2 F P V S R S ( n ,c ,b a s e ) \
2008-06-25 08:07:18 +04:00
BEGIN_ F T R _ S E C T I O N \
b 2 f ; \
END_ F T R _ S E C T I O N _ I F S E T ( C P U _ F T R _ V S X ) ; \
SAVE_ 3 2 F P R S ( n ,b a s e ) ; \
b 3 f ; \
2 : SAVE_ 3 2 V S R S ( n ,c ,b a s e ) ; \
3 :
# else
2012-06-25 17:33:23 +04:00
# define _ _ R E S T _ 3 2 F P V S R S ( n ,b ,b a s e ) R E S T _ 3 2 F P R S ( n , b a s e )
# define _ _ S A V E _ 3 2 F P V S R S ( n ,b ,b a s e ) S A V E _ 3 2 F P R S ( n , b a s e )
2008-06-25 08:07:18 +04:00
# endif
2012-06-25 17:33:23 +04:00
# define R E S T _ 3 2 F P V S R S ( n ,c ,b a s e ) _ _ R E S T _ 3 2 F P V S R S ( n ,_ _ R E G _ ## c , _ _ R E G _ # # b a s e )
# define S A V E _ 3 2 F P V S R S ( n ,c ,b a s e ) _ _ S A V E _ 3 2 F P V S R S ( n ,_ _ R E G _ ## c , _ _ R E G _ # # b a s e )
2008-06-25 08:07:18 +04:00
2013-02-13 20:21:36 +04:00
# ifdef C O N F I G _ P P C _ T R A N S A C T I O N A L _ M E M
/ * void d o _ l o a d _ u p _ t r a n s a c t _ f p u ( s t r u c t t h r e a d _ s t r u c t * t h r e a d )
*
* This i s s i m i l a r t o l o a d _ u p _ f p u b u t f o r t h e t r a n s a c t i o n a l v e r s i o n o f t h e F P
* register s e t . I t d o e s n ' t m e s s w i t h t h e t a s k M S R o r v a l i d f l a g s .
* Furthermore, w e d o n ' t d o l a z y F P w i t h T M c u r r e n t l y .
* /
_ GLOBAL( d o _ l o a d _ u p _ t r a n s a c t _ f p u )
mfmsr r6
ori r5 ,r6 ,M S R _ F P
# ifdef C O N F I G _ V S X
BEGIN_ F T R _ S E C T I O N
oris r5 ,r5 ,M S R _ V S X @h
END_ F T R _ S E C T I O N _ I F S E T ( C P U _ F T R _ V S X )
# endif
SYNC
MTMSRD( r5 )
2013-09-10 14:20:42 +04:00
addi r7 ,r3 ,T H R E A D _ T R A N S A C T _ F P S T A T E
lfd f r0 ,F P S T A T E _ F P S C R ( r7 )
2013-02-13 20:21:36 +04:00
MTFSF_ L ( f r0 )
2013-09-10 14:20:42 +04:00
REST_ 3 2 F P V S R S ( 0 , R 4 , R 7 )
2013-02-13 20:21:36 +04:00
/* FP/VSX off again */
MTMSRD( r6 )
SYNC
blr
# endif / * C O N F I G _ P P C _ T R A N S A C T I O N A L _ M E M * /
powerpc: Don't corrupt transactional state when using FP/VMX in kernel
Currently, when we have a process using the transactional memory
facilities on POWER8 (that is, the processor is in transactional
or suspended state), and the process enters the kernel and the
kernel then uses the floating-point or vector (VMX/Altivec) facility,
we end up corrupting the user-visible FP/VMX/VSX state. This
happens, for example, if a page fault causes a copy-on-write
operation, because the copy_page function will use VMX to do the
copy on POWER8. The test program below demonstrates the bug.
The bug happens because when FP/VMX state for a transactional process
is stored in the thread_struct, we store the checkpointed state in
.fp_state/.vr_state and the transactional (current) state in
.transact_fp/.transact_vr. However, when the kernel wants to use
FP/VMX, it calls enable_kernel_fp() or enable_kernel_altivec(),
which saves the current state in .fp_state/.vr_state. Furthermore,
when we return to the user process we return with FP/VMX/VSX
disabled. The next time the process uses FP/VMX/VSX, we don't know
which set of state (the current register values, .fp_state/.vr_state,
or .transact_fp/.transact_vr) we should be using, since we have no
way to tell if we are still in the same transaction, and if not,
whether the previous transaction succeeded or failed.
Thus it is necessary to strictly adhere to the rule that if FP has
been enabled at any point in a transaction, we must keep FP enabled
for the user process with the current transactional state in the
FP registers, until we detect that it is no longer in a transaction.
Similarly for VMX; once enabled it must stay enabled until the
process is no longer transactional.
In order to keep this rule, we add a new thread_info flag which we
test when returning from the kernel to userspace, called TIF_RESTORE_TM.
This flag indicates that there is FP/VMX/VSX state to be restored
before entering userspace, and when it is set the .tm_orig_msr field
in the thread_struct indicates what state needs to be restored.
The restoration is done by restore_tm_state(). The TIF_RESTORE_TM
bit is set by new giveup_fpu/altivec_maybe_transactional helpers,
which are called from enable_kernel_fp/altivec, giveup_vsx, and
flush_fp/altivec_to_thread instead of giveup_fpu/altivec.
The other thing to be done is to get the transactional FP/VMX/VSX
state from .fp_state/.vr_state when doing reclaim, if that state
has been saved there by giveup_fpu/altivec_maybe_transactional.
Having done this, we set the FP/VMX bit in the thread's MSR after
reclaim to indicate that that part of the state is now valid
(having been reclaimed from the processor's checkpointed state).
Finally, in the signal handling code, we move the clearing of the
transactional state bits in the thread's MSR a bit earlier, before
calling flush_fp_to_thread(), so that we don't unnecessarily set
the TIF_RESTORE_TM bit.
This is the test program:
/* Michael Neuling 4/12/2013
*
* See if the altivec state is leaked out of an aborted transaction due to
* kernel vmx copy loops.
*
* gcc -m64 htm_vmxcopy.c -o htm_vmxcopy
*
*/
/* We don't use all of these, but for reference: */
int main(int argc, char *argv[])
{
long double vecin = 1.3;
long double vecout;
unsigned long pgsize = getpagesize();
int i;
int fd;
int size = pgsize*16;
char tmpfile[] = "/tmp/page_faultXXXXXX";
char buf[pgsize];
char *a;
uint64_t aborted = 0;
fd = mkstemp(tmpfile);
assert(fd >= 0);
memset(buf, 0, pgsize);
for (i = 0; i < size; i += pgsize)
assert(write(fd, buf, pgsize) == pgsize);
unlink(tmpfile);
a = mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0);
assert(a != MAP_FAILED);
asm __volatile__(
"lxvd2x 40,0,%[vecinptr] ; " // set 40 to initial value
TBEGIN
"beq 3f ;"
TSUSPEND
"xxlxor 40,40,40 ; " // set 40 to 0
"std 5, 0(%[map]) ;" // cause kernel vmx copy page
TABORT
TRESUME
TEND
"li %[res], 0 ;"
"b 5f ;"
"3: ;" // Abort handler
"li %[res], 1 ;"
"5: ;"
"stxvd2x 40,0,%[vecoutptr] ; "
: [res]"=r"(aborted)
: [vecinptr]"r"(&vecin),
[vecoutptr]"r"(&vecout),
[map]"r"(a)
: "memory", "r0", "r3", "r4", "r5", "r6", "r7");
if (aborted && (vecin != vecout)){
printf("FAILED: vector state leaked on abort %f != %f\n",
(double)vecin, (double)vecout);
exit(1);
}
munmap(a, size);
close(fd);
printf("PASSED!\n");
return 0;
}
Signed-off-by: Paul Mackerras <paulus@samba.org>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
2014-01-13 08:56:29 +04:00
/ *
* Enable u s e o f t h e F P U , a n d V S X i f p o s s i b l e , f o r t h e c a l l e r .
* /
_ GLOBAL( f p _ e n a b l e )
mfmsr r3
ori r3 ,r3 ,M S R _ F P
# ifdef C O N F I G _ V S X
BEGIN_ F T R _ S E C T I O N
oris r3 ,r3 ,M S R _ V S X @h
END_ F T R _ S E C T I O N _ I F S E T ( C P U _ F T R _ V S X )
# endif
SYNC
MTMSRD( r3 )
isync / * ( n o t n e c e s s a r y f o r a r c h 2 . 0 2 a n d l a t e r ) * /
blr
2013-09-10 14:21:10 +04:00
/ *
* Load s t a t e f r o m m e m o r y i n t o F P r e g i s t e r s i n c l u d i n g F P S C R .
* Assumes t h e c a l l e r h a s e n a b l e d F P i n t h e M S R .
* /
_ GLOBAL( l o a d _ f p _ s t a t e )
lfd f r0 ,F P S T A T E _ F P S C R ( r3 )
MTFSF_ L ( f r0 )
REST_ 3 2 F P V S R S ( 0 , R 4 , R 3 )
blr
/ *
* Store F P s t a t e i n t o m e m o r y , i n c l u d i n g F P S C R
* Assumes t h e c a l l e r h a s e n a b l e d F P i n t h e M S R .
* /
_ GLOBAL( s t o r e _ f p _ s t a t e )
SAVE_ 3 2 F P V S R S ( 0 , R 4 , R 3 )
mffs f r0
stfd f r0 ,F P S T A T E _ F P S C R ( r3 )
blr
2005-09-26 10:04:21 +04:00
/ *
* This t a s k w a n t s t o u s e t h e F P U n o w .
* On U P , d i s a b l e F P f o r t h e t a s k w h i c h h a d t h e F P U p r e v i o u s l y ,
* and s a v e i t s f l o a t i n g - p o i n t r e g i s t e r s i n i t s t h r e a d _ s t r u c t .
* Load u p t h i s t a s k ' s F P r e g i s t e r s f r o m i t s t h r e a d _ s t r u c t ,
* enable t h e F P U f o r t h e c u r r e n t t a s k a n d r e t u r n t o t h e t a s k .
2013-10-23 12:40:02 +04:00
* Note t h a t o n 3 2 - b i t t h i s c a n o n l y u s e r e g i s t e r s t h a t w i l l b e
* restored b y f a s t _ e x c e p t i o n _ r e t u r n , i . e . r3 - r6 , r10 a n d r11 .
2005-09-26 10:04:21 +04:00
* /
2005-10-06 04:59:19 +04:00
_ GLOBAL( l o a d _ u p _ f p u )
2005-09-26 10:04:21 +04:00
mfmsr r5
ori r5 ,r5 ,M S R _ F P
2008-06-25 08:07:18 +04:00
# ifdef C O N F I G _ V S X
BEGIN_ F T R _ S E C T I O N
oris r5 ,r5 ,M S R _ V S X @h
END_ F T R _ S E C T I O N _ I F S E T ( C P U _ F T R _ V S X )
# endif
2005-09-26 10:04:21 +04:00
SYNC
MTMSRD( r5 ) / * e n a b l e u s e o f f p u n o w * /
isync
/ *
* For S M P , w e d o n ' t d o l a z y F P U s w i t c h i n g b e c a u s e i t j u s t g e t s t o o
* horrendously c o m p l e x , e s p e c i a l l y w h e n a t a s k s w i t c h e s f r o m o n e C P U
* to a n o t h e r . I n s t e a d w e c a l l g i v e u p _ f p u i n s w i t c h _ t o .
* /
# ifndef C O N F I G _ S M P
2006-01-13 06:56:25 +03:00
LOAD_ R E G _ A D D R B A S E ( r3 , l a s t _ t a s k _ u s e d _ m a t h )
2005-10-27 16:44:39 +04:00
toreal( r3 )
2006-01-13 06:56:25 +03:00
PPC_ L L r4 ,A D D R O F F ( l a s t _ t a s k _ u s e d _ m a t h ) ( r3 )
[PATCH] powerpc: Consolidate asm compatibility macros
This patch consolidates macros used to generate assembly for
compatibility across different CPUs or configs. A new header,
asm-powerpc/asm-compat.h contains the main compatibility macros. It
uses some preprocessor magic to make the macros suitable both for use
in .S files, and in inline asm in .c files. Headers (bitops.h,
uaccess.h, atomic.h, bug.h) which had their own such compatibility
macros are changed to use asm-compat.h.
ppc_asm.h is now for use in .S files *only*, and a #error enforces
that. As such, we're a lot more careless about namespace pollution
here than in asm-compat.h.
While we're at it, this patch adds a call to the PPC405_ERR77 macro in
futex.h which should have had it already, but didn't.
Built and booted on pSeries, Maple and iSeries (ARCH=powerpc). Built
for 32-bit powermac (ARCH=powerpc) and Walnut (ARCH=ppc).
Signed-off-by: David Gibson <dwg@au1.ibm.com>
Signed-off-by: Paul Mackerras <paulus@samba.org>
2005-11-10 04:56:55 +03:00
PPC_ L C M P I 0 ,r4 ,0
2005-09-26 10:04:21 +04:00
beq 1 f
2005-10-27 16:44:39 +04:00
toreal( r4 )
2005-09-26 10:04:21 +04:00
addi r4 ,r4 ,T H R E A D / * w a n t l a s t _ t a s k _ u s e d _ m a t h - > t h r e a d * /
2013-10-23 12:40:02 +04:00
addi r10 ,r4 ,T H R E A D _ F P S T A T E
SAVE_ 3 2 F P V S R S ( 0 , R 5 , R 1 0 )
2005-09-26 10:04:21 +04:00
mffs f r0
2013-10-23 12:40:02 +04:00
stfd f r0 ,F P S T A T E _ F P S C R ( r10 )
[PATCH] powerpc: Consolidate asm compatibility macros
This patch consolidates macros used to generate assembly for
compatibility across different CPUs or configs. A new header,
asm-powerpc/asm-compat.h contains the main compatibility macros. It
uses some preprocessor magic to make the macros suitable both for use
in .S files, and in inline asm in .c files. Headers (bitops.h,
uaccess.h, atomic.h, bug.h) which had their own such compatibility
macros are changed to use asm-compat.h.
ppc_asm.h is now for use in .S files *only*, and a #error enforces
that. As such, we're a lot more careless about namespace pollution
here than in asm-compat.h.
While we're at it, this patch adds a call to the PPC405_ERR77 macro in
futex.h which should have had it already, but didn't.
Built and booted on pSeries, Maple and iSeries (ARCH=powerpc). Built
for 32-bit powermac (ARCH=powerpc) and Walnut (ARCH=ppc).
Signed-off-by: David Gibson <dwg@au1.ibm.com>
Signed-off-by: Paul Mackerras <paulus@samba.org>
2005-11-10 04:56:55 +03:00
PPC_ L L r5 ,P T _ R E G S ( r4 )
2005-10-27 16:44:39 +04:00
toreal( r5 )
[PATCH] powerpc: Consolidate asm compatibility macros
This patch consolidates macros used to generate assembly for
compatibility across different CPUs or configs. A new header,
asm-powerpc/asm-compat.h contains the main compatibility macros. It
uses some preprocessor magic to make the macros suitable both for use
in .S files, and in inline asm in .c files. Headers (bitops.h,
uaccess.h, atomic.h, bug.h) which had their own such compatibility
macros are changed to use asm-compat.h.
ppc_asm.h is now for use in .S files *only*, and a #error enforces
that. As such, we're a lot more careless about namespace pollution
here than in asm-compat.h.
While we're at it, this patch adds a call to the PPC405_ERR77 macro in
futex.h which should have had it already, but didn't.
Built and booted on pSeries, Maple and iSeries (ARCH=powerpc). Built
for 32-bit powermac (ARCH=powerpc) and Walnut (ARCH=ppc).
Signed-off-by: David Gibson <dwg@au1.ibm.com>
Signed-off-by: Paul Mackerras <paulus@samba.org>
2005-11-10 04:56:55 +03:00
PPC_ L L r4 ,_ M S R - S T A C K _ F R A M E _ O V E R H E A D ( r5 )
2005-09-26 10:04:21 +04:00
li r10 ,M S R _ F P | M S R _ F E 0 | M S R _ F E 1
andc r4 ,r4 ,r10 / * d i s a b l e F P f o r p r e v i o u s t a s k * /
[PATCH] powerpc: Consolidate asm compatibility macros
This patch consolidates macros used to generate assembly for
compatibility across different CPUs or configs. A new header,
asm-powerpc/asm-compat.h contains the main compatibility macros. It
uses some preprocessor magic to make the macros suitable both for use
in .S files, and in inline asm in .c files. Headers (bitops.h,
uaccess.h, atomic.h, bug.h) which had their own such compatibility
macros are changed to use asm-compat.h.
ppc_asm.h is now for use in .S files *only*, and a #error enforces
that. As such, we're a lot more careless about namespace pollution
here than in asm-compat.h.
While we're at it, this patch adds a call to the PPC405_ERR77 macro in
futex.h which should have had it already, but didn't.
Built and booted on pSeries, Maple and iSeries (ARCH=powerpc). Built
for 32-bit powermac (ARCH=powerpc) and Walnut (ARCH=ppc).
Signed-off-by: David Gibson <dwg@au1.ibm.com>
Signed-off-by: Paul Mackerras <paulus@samba.org>
2005-11-10 04:56:55 +03:00
PPC_ S T L r4 ,_ M S R - S T A C K _ F R A M E _ O V E R H E A D ( r5 )
2005-09-26 10:04:21 +04:00
1 :
# endif / * C O N F I G _ S M P * /
/* enable use of FP after return */
2005-10-06 04:59:19 +04:00
# ifdef C O N F I G _ P P C 3 2
2013-09-10 14:20:42 +04:00
mfspr r5 ,S P R N _ S P R G _ T H R E A D / * c u r r e n t t a s k ' s T H R E A D ( p h y s ) * /
2005-09-26 10:04:21 +04:00
lwz r4 ,T H R E A D _ F P E X C _ M O D E ( r5 )
ori r9 ,r9 ,M S R _ F P / * e n a b l e F P f o r c u r r e n t * /
or r9 ,r9 ,r4
2005-10-06 04:59:19 +04:00
# else
ld r4 ,P A C A C U R R E N T ( r13 )
addi r5 ,r4 ,T H R E A D / * G e t T H R E A D * /
2006-02-07 05:55:30 +03:00
lwz r4 ,T H R E A D _ F P E X C _ M O D E ( r5 )
2005-10-06 04:59:19 +04:00
ori r12 ,r12 ,M S R _ F P
or r12 ,r12 ,r4
std r12 ,_ M S R ( r1 )
# endif
2013-10-23 12:40:02 +04:00
addi r10 ,r5 ,T H R E A D _ F P S T A T E
lfd f r0 ,F P S T A T E _ F P S C R ( r10 )
2006-06-10 14:18:39 +04:00
MTFSF_ L ( f r0 )
2013-10-23 12:40:02 +04:00
REST_ 3 2 F P V S R S ( 0 , R 4 , R 1 0 )
2005-09-26 10:04:21 +04:00
# ifndef C O N F I G _ S M P
subi r4 ,r5 ,T H R E A D
2005-10-27 16:44:39 +04:00
fromreal( r4 )
2006-01-13 06:56:25 +03:00
PPC_ S T L r4 ,A D D R O F F ( l a s t _ t a s k _ u s e d _ m a t h ) ( r3 )
2005-09-26 10:04:21 +04:00
# endif / * C O N F I G _ S M P * /
/* restore registers and return */
/* we haven't used ctr or xer or lr */
2008-06-25 08:07:18 +04:00
blr
2005-09-26 10:04:21 +04:00
/ *
* giveup_ f p u ( t s k )
* Disable F P f o r t h e t a s k g i v e n a s t h e a r g u m e n t ,
* and s a v e t h e f l o a t i n g - p o i n t r e g i s t e r s i n i t s t h r e a d _ s t r u c t .
* Enables t h e F P U f o r u s e i n t h e k e r n e l o n r e t u r n .
* /
2005-10-06 04:59:19 +04:00
_ GLOBAL( g i v e u p _ f p u )
2005-09-26 10:04:21 +04:00
mfmsr r5
ori r5 ,r5 ,M S R _ F P
2008-06-25 08:07:18 +04:00
# ifdef C O N F I G _ V S X
BEGIN_ F T R _ S E C T I O N
oris r5 ,r5 ,M S R _ V S X @h
END_ F T R _ S E C T I O N _ I F S E T ( C P U _ F T R _ V S X )
# endif
2005-09-26 10:04:21 +04:00
SYNC_ 6 0 1
ISYNC_ 6 0 1
MTMSRD( r5 ) / * e n a b l e u s e o f f p u n o w * /
SYNC_ 6 0 1
isync
[PATCH] powerpc: Consolidate asm compatibility macros
This patch consolidates macros used to generate assembly for
compatibility across different CPUs or configs. A new header,
asm-powerpc/asm-compat.h contains the main compatibility macros. It
uses some preprocessor magic to make the macros suitable both for use
in .S files, and in inline asm in .c files. Headers (bitops.h,
uaccess.h, atomic.h, bug.h) which had their own such compatibility
macros are changed to use asm-compat.h.
ppc_asm.h is now for use in .S files *only*, and a #error enforces
that. As such, we're a lot more careless about namespace pollution
here than in asm-compat.h.
While we're at it, this patch adds a call to the PPC405_ERR77 macro in
futex.h which should have had it already, but didn't.
Built and booted on pSeries, Maple and iSeries (ARCH=powerpc). Built
for 32-bit powermac (ARCH=powerpc) and Walnut (ARCH=ppc).
Signed-off-by: David Gibson <dwg@au1.ibm.com>
Signed-off-by: Paul Mackerras <paulus@samba.org>
2005-11-10 04:56:55 +03:00
PPC_ L C M P I 0 ,r3 ,0
2005-09-26 10:04:21 +04:00
beqlr- / * i f n o p r e v i o u s o w n e r , d o n e * /
addi r3 ,r3 ,T H R E A D / * w a n t T H R E A D o f t a s k * /
2013-09-10 14:21:10 +04:00
PPC_ L L r6 ,T H R E A D _ F P S A V E A R E A ( r3 )
[PATCH] powerpc: Consolidate asm compatibility macros
This patch consolidates macros used to generate assembly for
compatibility across different CPUs or configs. A new header,
asm-powerpc/asm-compat.h contains the main compatibility macros. It
uses some preprocessor magic to make the macros suitable both for use
in .S files, and in inline asm in .c files. Headers (bitops.h,
uaccess.h, atomic.h, bug.h) which had their own such compatibility
macros are changed to use asm-compat.h.
ppc_asm.h is now for use in .S files *only*, and a #error enforces
that. As such, we're a lot more careless about namespace pollution
here than in asm-compat.h.
While we're at it, this patch adds a call to the PPC405_ERR77 macro in
futex.h which should have had it already, but didn't.
Built and booted on pSeries, Maple and iSeries (ARCH=powerpc). Built
for 32-bit powermac (ARCH=powerpc) and Walnut (ARCH=ppc).
Signed-off-by: David Gibson <dwg@au1.ibm.com>
Signed-off-by: Paul Mackerras <paulus@samba.org>
2005-11-10 04:56:55 +03:00
PPC_ L L r5 ,P T _ R E G S ( r3 )
2013-09-10 14:21:10 +04:00
PPC_ L C M P I 0 ,r6 ,0
bne 2 f
2013-09-10 14:20:42 +04:00
addi r6 ,r3 ,T H R E A D _ F P S T A T E
2013-09-10 14:21:10 +04:00
2 : PPC_ L C M P I 0 ,r5 ,0
2013-09-10 14:20:42 +04:00
SAVE_ 3 2 F P V S R S ( 0 , R 4 , R 6 )
2005-09-26 10:04:21 +04:00
mffs f r0
2013-09-10 14:20:42 +04:00
stfd f r0 ,F P S T A T E _ F P S C R ( r6 )
2005-09-26 10:04:21 +04:00
beq 1 f
[PATCH] powerpc: Consolidate asm compatibility macros
This patch consolidates macros used to generate assembly for
compatibility across different CPUs or configs. A new header,
asm-powerpc/asm-compat.h contains the main compatibility macros. It
uses some preprocessor magic to make the macros suitable both for use
in .S files, and in inline asm in .c files. Headers (bitops.h,
uaccess.h, atomic.h, bug.h) which had their own such compatibility
macros are changed to use asm-compat.h.
ppc_asm.h is now for use in .S files *only*, and a #error enforces
that. As such, we're a lot more careless about namespace pollution
here than in asm-compat.h.
While we're at it, this patch adds a call to the PPC405_ERR77 macro in
futex.h which should have had it already, but didn't.
Built and booted on pSeries, Maple and iSeries (ARCH=powerpc). Built
for 32-bit powermac (ARCH=powerpc) and Walnut (ARCH=ppc).
Signed-off-by: David Gibson <dwg@au1.ibm.com>
Signed-off-by: Paul Mackerras <paulus@samba.org>
2005-11-10 04:56:55 +03:00
PPC_ L L r4 ,_ M S R - S T A C K _ F R A M E _ O V E R H E A D ( r5 )
2005-09-26 10:04:21 +04:00
li r3 ,M S R _ F P | M S R _ F E 0 | M S R _ F E 1
2009-04-01 22:02:42 +04:00
# ifdef C O N F I G _ V S X
BEGIN_ F T R _ S E C T I O N
oris r3 ,r3 ,M S R _ V S X @h
END_ F T R _ S E C T I O N _ I F S E T ( C P U _ F T R _ V S X )
# endif
2005-09-26 10:04:21 +04:00
andc r4 ,r4 ,r3 / * d i s a b l e F P f o r p r e v i o u s t a s k * /
[PATCH] powerpc: Consolidate asm compatibility macros
This patch consolidates macros used to generate assembly for
compatibility across different CPUs or configs. A new header,
asm-powerpc/asm-compat.h contains the main compatibility macros. It
uses some preprocessor magic to make the macros suitable both for use
in .S files, and in inline asm in .c files. Headers (bitops.h,
uaccess.h, atomic.h, bug.h) which had their own such compatibility
macros are changed to use asm-compat.h.
ppc_asm.h is now for use in .S files *only*, and a #error enforces
that. As such, we're a lot more careless about namespace pollution
here than in asm-compat.h.
While we're at it, this patch adds a call to the PPC405_ERR77 macro in
futex.h which should have had it already, but didn't.
Built and booted on pSeries, Maple and iSeries (ARCH=powerpc). Built
for 32-bit powermac (ARCH=powerpc) and Walnut (ARCH=ppc).
Signed-off-by: David Gibson <dwg@au1.ibm.com>
Signed-off-by: Paul Mackerras <paulus@samba.org>
2005-11-10 04:56:55 +03:00
PPC_ S T L r4 ,_ M S R - S T A C K _ F R A M E _ O V E R H E A D ( r5 )
2005-09-26 10:04:21 +04:00
1 :
# ifndef C O N F I G _ S M P
li r5 ,0
2006-01-13 06:56:25 +03:00
LOAD_ R E G _ A D D R B A S E ( r4 ,l a s t _ t a s k _ u s e d _ m a t h )
PPC_ S T L r5 ,A D D R O F F ( l a s t _ t a s k _ u s e d _ m a t h ) ( r4 )
2005-09-26 10:04:21 +04:00
# endif / * C O N F I G _ S M P * /
blr
[PATCH] powerpc: Fix handling of fpscr on 64-bit
The recent merge of fpu.S broken the handling of fpscr for
ARCH=powerpc and CONFIG_PPC64=y. FP registers could be corrupted,
leading to strange random application crashes.
The confusion arises, because the thread_struct has (and requires) a
64-bit area to save the fpscr, because we use load/store double
instructions to get it in to/out of the FPU. However, only the low
32-bits are actually used, so we want to treat it as a 32-bit quantity
when manipulating its bits to avoid extra load/stores on 32-bit. This
patch replaces the current definition with a structure of two 32-bit
quantities (pad and val), to clarify things as much as is possible.
The 'val' field is used when manipulating bits, the structure itself
is used when obtaining the address for loading/unloading the value
from the FPU.
While we're at it, consolidate the 4 (!) almost identical versions of
cvt_fd() and cvt_df() (arch/ppc/kernel/misc.S,
arch/ppc64/kernel/misc.S, arch/powerpc/kernel/misc_32.S,
arch/powerpc/kernel/misc_64.S) into a single version in fpu.S. The
new version takes a pointer to thread_struct and applies the correct
offset itself, rather than a pointer to the fpscr field itself, again
to avoid confusion as to which is the correct field to use.
Finally, this patch makes ARCH=ppc64 also use the consolidated fpu.S
code, which it previously did not.
Built for G5 (ARCH=ppc64 and ARCH=powerpc), 32-bit powermac (ARCH=ppc
and ARCH=powerpc) and Walnut (ARCH=ppc, CONFIG_MATH_EMULATION=y).
Booted on G5 (ARCH=powerpc) and things which previously fell over no
longer do.
Signed-off-by: David Gibson <dwg@au1.ibm.com>
Signed-off-by: Paul Mackerras <paulus@samba.org>
2005-10-27 10:27:25 +04:00
/ *
* These a r e u s e d i n t h e a l i g n m e n t t r a p h a n d l e r w h e n e m u l a t i n g
* single- p r e c i s i o n l o a d s a n d s t o r e s .
* /
_ GLOBAL( c v t _ f d )
lfs 0 ,0 ( r3 )
stfd 0 ,0 ( r4 )
blr
_ GLOBAL( c v t _ d f )
lfd 0 ,0 ( r3 )
stfs 0 ,0 ( r4 )
blr