From: "Jeremy Friesner" <jaf@lcsaudio.com>
To: linuxppc-embedded@ozlabs.org
Subject: RE: Floating point math in kernel interrupt -- am I doing this right?(repost)
Date: Wed, 08 Feb 2006 00:32:12 PST (-0800) [thread overview]
Message-ID: <1193761678-BeMail@jeremy.lcsaudio.com> (raw)
In-Reply-To: <mailman.294.1139321937.857.linuxppc-embedded@ozlabs.org>
Hi all,
I figured out what was wrong with my FPU save/restore code: I was neglecting to save and restore the state of the FPSCR register. Thanks to all who helped me figure it out!
For the sake of the list archives, I've pasted my fixed FP save/restore routines below.
-Jeremy
---------------------- snip -------------------------------
/* macros to save and restore floating point register state */
# define SAVE=5FFPR(x) {=5F=5Fasm=5F=5F =5F=5Fvolatile=5F=5F ("stfd " #x ", " #x "*8(%0)\n" : : "b" (saved=5Ffpr));}
# define RESTORE=5FFPR(x) {=5F=5Fasm=5F=5F =5F=5Fvolatile=5F=5F ("lfd " #x ", " #x "*8(%0)\n" : : "b" (saved=5Ffpr));}
/* Set up floating-point-enabled-mode */
uint32 saved=5Fmsr; /* space for the MSR register (32 bits) */
uint32 saved=5Ffpscr[1*2]; /* space for the FPSCR register (64 bits) */
uint32 saved=5Ffpr[14*2]; /* space for the 14 floating point registers I'll use (64 bits each) */
{
uint32 msr;
/* Save existing MSR for later */
=5F=5Fasm=5F=5F =5F=5Fvolatile=5F=5F ("mfmsr %0" : "=3Dr" (msr) : );
saved=5Fmsr =3D msr;
/* Enable floating point */
msr |=3D MSR=5FFP;
msr &=3D ~(MSR=5FFE0 | MSR=5FFE1);
=5F=5Fasm=5F=5F =5F=5Fvolatile=5F=5F ("mtmsr %0\n\tisync" : : "r" (msr));
/* Save the floating point registers that will be used, so that we won't screw up user processes */
SAVE=5FFPR(0); SAVE=5FFPR(1); SAVE=5FFPR(2); SAVE=5FFPR(3); SAVE=5FFPR(4);
SAVE=5FFPR(5); SAVE=5FFPR(6); SAVE=5FFPR(7); SAVE=5FFPR(8); SAVE=5FFPR(9);
SAVE=5FFPR(10); SAVE=5FFPR(11); SAVE=5FFPR(12); SAVE=5FFPR(13);
/* Save existing FPSCR, by first retrieving it into FPR0, then storing FPR0 to the stack */
=5F=5Fasm=5F=5F =5F=5Fvolatile=5F=5F ("mffs 0\n\tstfd 0, 0(%0)\n" : : "b" (saved=5Ffpscr));
}
DoFloatingPointMathHere();
/* End floating-point-enabled-mode */
{
/* Restore FPSCR, by first loading it into FPR0, then calling mtfsf to put it back into the register */
=5F=5Fasm=5F=5F =5F=5Fvolatile=5F=5F ("lfd 0, 0(%0)\n\tmtfsf 0xFF,0" : : "b" (saved=5Ffpscr));
/* Restore the FP registers that may have been munged */
RESTORE=5FFPR(0); RESTORE=5FFPR(1); RESTORE=5FFPR(2); RESTORE=5FFPR(3); RESTORE=5FFPR(4);
RESTORE=5FFPR(5); RESTORE=5FFPR(6); RESTORE=5FFPR(7); RESTORE=5FFPR(8); RESTORE=5FFPR(9);
RESTORE=5FFPR(10); RESTORE=5FFPR(11); RESTORE=5FFPR(12); RESTORE=5FFPR(13);
/* Restore MSR */
=5F=5Fasm=5F=5F =5F=5Fvolatile=5F=5F ("mtmsr %0\n" "isync" : : "r" (saved=5Fmsr));
}
next prev parent reply other threads:[~2006-02-08 8:32 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <mailman.294.1139321937.857.linuxppc-embedded@ozlabs.org>
2006-02-07 19:20 ` Voyager Video support color depths? Russell McGuire
2006-02-08 8:32 ` Jeremy Friesner [this message]
2006-02-07 7:20 Floating point math in kernel interrupt -- am I doing this right?(repost) Joyeau Sylvain
-- strict thread matches above, loose matches on Subject: below --
2006-02-06 12:57 Fillod Stephane
2006-02-06 2:29 Floating point math in kernel interrupt -- am I doing this right? (repost) Jeremy Friesner
2006-02-06 12:27 ` Dan Malek
2006-02-06 16:55 ` Jeremy Friesner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1193761678-BeMail@jeremy.lcsaudio.com \
--to=jaf@lcsaudio.com \
--cc=linuxppc-embedded@ozlabs.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).