Re: [AD] Bug in MMX linear_clear_to_color8 with asynchronous usage

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


> It's only a matter of filling the sound buffer in time.
> It worked well until using a float.
> (Which I may end converting to a fixed point value, but it's good
> indeed to find a solution for Allegro is possible)

Using FP code in DOS interrupt context is not very recommended.

> I'm sorry, I currently work on a big program, I'll have to write a
> separate test program. I did not know however was what the exact problem
> before, and now that Robert provided some code (below) it seems obvious
> to fix (although I apparently can't do it @!#*).

The FPU state is not saved across interrupts.

> The patch unfortunately doesn't compile as is since the FSAVE/FRSTOR
> opcodes apparently require a memory address as operand (doesn't work
> with %esp).

Bob certainly meant (%esp).

> Robert's mail:
> ----------
> Eric and Omar,
>
> It seems that I am unable to post on AD/AL/alleg5 any longer because of
> SF's policy conflicting with my ISP's :(
>
> Here's a potential patch for the problem mentioned below. This patch is
> completely untested (I didn't compile it) as I do not have DJGPP
> installed, nor a DOS environment to try it on.
>
> The patch adds the ability for Allegro to save/restore the FPU state on
> interrupts. This is my first time programming the x87 FPU, so I'm not
> entirely sure this is the correct way of doing it.

It doesn't work because you didn't take into account the selector. Namely, 
you need to load the __djgpp_ds_alias into %ds to be able to access the 
global variable 'cpu_capabilities'. But there is sort of a chicken-and-egg 
problem, because you need afterwards to push in the interrupt context.

As I didn't want to revamp the whole code, I simply scrapped the check for 
the CPU_FPU flag. The result is attached.

But it is probably not sufficient because the FPU is not usable from within 
the interrupt if it has been clobbered by MMX instructions. So we would need 
to call 'emms' in the assembly stub, which is not conceivable for 
performance reasons.

-- 
Eric Botcazou
--- /cvs/allegro/src/dos/djirqs.s	Thu Feb 15 00:55:12 2001
+++ allegro/src/dos/djirqs.s	Mon Feb 10 21:00:54 2003
@@ -32,6 +32,8 @@
    pushw %fs                                                               ; \
    pushw %gs                                                               ; \
    pushal                                                                  ; \
+   subl $108, %esp                                                         ; \
+   fsave (%esp)                                                            ; \
 									   ; \
    .byte 0x2e                             /* cs: override */               ; \
    movw GLOBL(__djgpp_ds_alias), %ax                                       ; \
@@ -82,6 +84,8 @@
    orl %eax, %eax                         /* check return value */         ; \
    jz get_out_##x                                                          ; \
 									   ; \
+   frstor (%esp)                                                           ; \
+   addl $108, %esp                                                         ; \
    popal                                  /* chain to old handler */       ; \
    popw %gs                                                                ; \
    popw %fs                                                                ; \
@@ -90,6 +94,8 @@
    ljmp *%cs:GLOBL(_irq_handler) + IRQ_OLDVEC + IRQ_SIZE*x                 ; \
 									   ; \
 get_out_##x:                                                               ; \
+   frstor (%esp)                                                           ; \
+   addl $108, %esp                                                         ; \
    popal                                  /* iret */                       ; \
    popw %gs                                                                ; \
    popw %fs                                                                ; \


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/