* [Xenomai-help] Saving floating point registers inside ISR
@ 2008-06-04 21:19 Henry Bausley
2008-06-04 22:07 ` Jan Kiszka
2008-06-05 7:41 ` Gilles Chanteperdrix
0 siblings, 2 replies; 3+ messages in thread
From: Henry Bausley @ 2008-06-04 21:19 UTC (permalink / raw)
To: xenomai
I am converting a 440EP power pc FSM Labs RT-Linux application to a
Xenomai 2.4.2 posix application. Previously we saved the floating point
registers in the ISR. I had the following code with RTLinux.
//-----------------------------------------------------------------------------
int phase_intr(xnintr_t *cookie)
{
rthal_fpenv_t fpustate;
rthal_save_fpu(&fpustate);
phase();
rthal_restore_fpu(&fpustate);
return (XN_ISR_HANDLED);
}
with xenomai if we do the the same thing the system hangs.
However if we make the location where we save the registers global, or
declare it static inside the ISR we don't have a problem. I don't want
to do that since there are cases when the interrupt can be re-entered.
Does anyone have any ideas?
rthal_fpenv_t fpustate;
//-----------------------------------------------------------------------------
int phase_intr(xnintr_t *cookie)
{
rthal_save_fpu(&fpustate);
phase();
rthal_restore_fpu(&fpustate);
return (XN_ISR_HANDLED);
}
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [Xenomai-help] Saving floating point registers inside ISR
2008-06-04 21:19 [Xenomai-help] Saving floating point registers inside ISR Henry Bausley
@ 2008-06-04 22:07 ` Jan Kiszka
2008-06-05 7:41 ` Gilles Chanteperdrix
1 sibling, 0 replies; 3+ messages in thread
From: Jan Kiszka @ 2008-06-04 22:07 UTC (permalink / raw)
To: Henry Bausley; +Cc: xenomai
[-- Attachment #1: Type: text/plain, Size: 1556 bytes --]
Henry Bausley wrote:
> I am converting a 440EP power pc FSM Labs RT-Linux application to a
> Xenomai 2.4.2 posix application. Previously we saved the floating point
> registers in the ISR. I had the following code with RTLinux.
>
> //-----------------------------------------------------------------------------
> int phase_intr(xnintr_t *cookie)
> {
> rthal_fpenv_t fpustate;
Do you know how large this structure is? And do you know how much stack
space is still free when entering here, in the worst case? That may
differ from RTLinux, probably running on some older kernel.
>
> rthal_save_fpu(&fpustate);
>
> phase();
>
> rthal_restore_fpu(&fpustate);
> return (XN_ISR_HANDLED);
> }
>
> with xenomai if we do the the same thing the system hangs.
>
>
> However if we make the location where we save the registers global, or
> declare it static inside the ISR we don't have a problem. I don't want
That should ring the bell above...
> to do that since there are cases when the interrupt can be re-entered.
> Does anyone have any ideas?
>
> rthal_fpenv_t fpustate;
>
> //-----------------------------------------------------------------------------
> int phase_intr(xnintr_t *cookie)
> {
>
> rthal_save_fpu(&fpustate);
>
> phase();
>
> rthal_restore_fpu(&fpustate);
> return (XN_ISR_HANDLED);
> }
>
If the stack size is not the problem here, compare to disassembly of the
involved versions, local vs. global fpustate, and then the one from RTLinux.
Jan
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 254 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [Xenomai-help] Saving floating point registers inside ISR
2008-06-04 21:19 [Xenomai-help] Saving floating point registers inside ISR Henry Bausley
2008-06-04 22:07 ` Jan Kiszka
@ 2008-06-05 7:41 ` Gilles Chanteperdrix
1 sibling, 0 replies; 3+ messages in thread
From: Gilles Chanteperdrix @ 2008-06-05 7:41 UTC (permalink / raw)
To: Henry Bausley; +Cc: xenomai
On Wed, Jun 4, 2008 at 11:19 PM, Henry Bausley <hbausley@domain.hid> wrote:
>
> I am converting a 440EP power pc FSM Labs RT-Linux application to a
> Xenomai 2.4.2 posix application. Previously we saved the floating point
> registers in the ISR. I had the following code with RTLinux.
Maybe what kills your box is an exception: when a user-space task has
not used the FPU, or when a kernel-space task did not set the XNFPU
bit, any use of floating point instructions triggers an exception. You
should normally get a clear message in the kernel logs. So, you should
try and call rthal_enable_fpu right before rthal_save_fpu. Note
however that when doing so, you break Xenomai and Linux FPU "state
machine". So, what you should really do is save the exception bit,
enable it before calling rthal_save_fpu, then restore it after
rthal_restore_fpu.
You can use for instance
#define rthal_save_fp_bit() ({ \
register unsigned long _msr; \
__asm__ __volatile__ ( "mfmsr %0" : "=r"(_msr) ); \
__asm__ __volatile__ ( "mtmsrd %0" \
: /* no output */ \
: "r"(_msr | MSR_FP) \
: "memory" ); \
_msr & MSR_FP;
})
#define rthal_restore_fp_bit(msr) ({ \
register unsigned long _msr; \
__asm__ __volatile__ ( "mfmsr %0" : "=r"(_msr) ); \
__asm__ __volatile__ ( "mtmsrd %0" \
: /* no output */ \
: "r"((_msr & ~MSR_FP) | (msr)) \
: "memory" ); \
})
Then you would do:
int phase_intr(xnintr_t *cookie)
{
unsigned long fp_bit;
rthal_fpenv_t fpustate;
fp_bit = rthal_save_fp_bit();
rthal_save_fpu(&fpustate);
phase();
rthal_restore_fpu(&fpustate);
rthal_restore_fp_bit(fp_bit);
return (XN_ISR_HANDLED);
}
--
Gilles
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2008-06-05 7:41 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-06-04 21:19 [Xenomai-help] Saving floating point registers inside ISR Henry Bausley
2008-06-04 22:07 ` Jan Kiszka
2008-06-05 7:41 ` Gilles Chanteperdrix
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.