changeset 2027:d48ead2d2ba5

Save/restore FPU registers in interrupt
author Patrice Mandin <patmandin@gmail.com>
date Sat, 16 Sep 2006 16:59:46 +0000
parents a5d0758f88d8
children 6dbe2a67b23b
files src/audio/mint/SDL_mintaudio.c src/audio/mint/SDL_mintaudio.h src/audio/mint/SDL_mintaudio_dma8.c src/audio/mint/SDL_mintaudio_gsxb.c src/audio/mint/SDL_mintaudio_it.S src/audio/mint/SDL_mintaudio_mcsn.c src/audio/mint/SDL_mintaudio_stfa.c src/audio/mint/SDL_mintaudio_xbios.c
diffstat 8 files changed, 95 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/audio/mint/SDL_mintaudio.c	Wed Sep 13 04:47:46 2006 +0000
+++ b/src/audio/mint/SDL_mintaudio.c	Sat Sep 16 16:59:46 2006 +0000
@@ -145,6 +145,26 @@
     return MINTAUDIO_freqcount - 1;
 }
 
+/* Check if FPU is present */
+void SDL_MintAudio_CheckFpu(void)
+{
+	unsigned long cookie_fpu;
+
+	SDL_MintAudio_hasfpu = 0;
+	if (Getcookie(C__FPU, &cookie_fpu) != C_FOUND) {
+		return;
+	}
+	switch ((cookie_fpu>>16)&0xfffe) {
+		case 2:
+		case 4:
+		case 6:
+		case 8:
+		case 16:
+			SDL_MintAudio_hasfpu = 1;
+			break;
+	}
+}
+
 /* The thread function, used under MiNT with xbios */
 int
 SDL_MintAudio_Thread(long param)
--- a/src/audio/mint/SDL_mintaudio.h	Wed Sep 13 04:47:46 2006 +0000
+++ b/src/audio/mint/SDL_mintaudio.h	Sat Sep 16 16:59:46 2006 +0000
@@ -128,6 +128,7 @@
 extern volatile unsigned short SDL_MintAudio_mutex;
 extern cookie_stfa_t *SDL_MintAudio_stfa;
 extern volatile unsigned long SDL_MintAudio_clocktics;
+extern unsigned short SDL_MintAudio_hasfpu;	/* To preserve fpu registers if needed */
 
 /* MiNT thread variables */
 extern SDL_bool SDL_MintAudio_mint_present;
@@ -140,6 +141,7 @@
 void SDL_MintAudio_AddFrequency(_THIS, Uint32 frequency, Uint32 clock,
                                 Uint32 prediv, int gpio_bits);
 int SDL_MintAudio_SearchFrequency(_THIS, int desired_freq);
+void SDL_MintAudio_CheckFpu(void);
 
 /* MiNT thread functions */
 int SDL_MintAudio_Thread(long param);
--- a/src/audio/mint/SDL_mintaudio_dma8.c	Wed Sep 13 04:47:46 2006 +0000
+++ b/src/audio/mint/SDL_mintaudio_dma8.c	Sat Sep 16 16:59:46 2006 +0000
@@ -367,6 +367,8 @@
     DEBUG_PRINT((DEBUG_NAME "buffer 1 at 0x%08x\n",
                  SDL_MintAudio_audiobuf[1]));
 
+    SDL_MintAudio_CheckFpu();
+
     /* Setup audio hardware */
     Mint_InitAudio(this, spec);
 
--- a/src/audio/mint/SDL_mintaudio_gsxb.c	Wed Sep 13 04:47:46 2006 +0000
+++ b/src/audio/mint/SDL_mintaudio_gsxb.c	Sat Sep 16 16:59:46 2006 +0000
@@ -438,6 +438,8 @@
     DEBUG_PRINT((DEBUG_NAME "buffer 1 at 0x%08x\n",
                  SDL_MintAudio_audiobuf[1]));
 
+    SDL_MintAudio_CheckFpu();
+
     /* Setup audio hardware */
     Mint_InitAudio(this, spec);
 
--- a/src/audio/mint/SDL_mintaudio_it.S	Wed Sep 13 04:47:46 2006 +0000
+++ b/src/audio/mint/SDL_mintaudio_it.S	Sat Sep 16 16:59:46 2006 +0000
@@ -40,6 +40,7 @@
 	.globl	_SDL_MintAudio_numbuf
 	.globl	_SDL_MintAudio_audiosize
 	.globl	_SDL_MintAudio_clocktics
+	.globl	_SDL_MintAudio_hasfpu
 
 	.globl	_SDL_MintAudio_stfa
 
@@ -85,9 +86,29 @@
 
 	moveml	d0-d7/a0-a6,sp@-
 
+	/* Save FPU if needed */
+	tstw	_SDL_MintAudio_hasfpu
+	beqs	SDL_MintAudio_Xbios_nofpu1
+	.chip	68060
+	fsave	sp@-
+	fmoveml fpcr/fpsr/fpiar,sp@-
+	fmovemx	fp0-fp7,sp@-
+	.chip	68000
+SDL_MintAudio_Xbios_nofpu1:
+
 	/* Callback */
 	jsr	_SDL_MintAudio_Callback
 
+	/* Restore FPU if needed */
+	tstw	_SDL_MintAudio_hasfpu
+	beqs	SDL_MintAudio_Xbios_nofpu2
+	.chip	68060
+	fmovemx	sp@+,fp0-fp7
+	fmoveml	sp@+,fpcr/fpsr/fpiar
+	frestore	sp@+
+	.chip	68000
+SDL_MintAudio_Xbios_nofpu2:
+
 	/* Reserve space for registers */
 	subl	#savamt,savptr
 
@@ -137,11 +158,31 @@
 	/* Swap buffers */
 	eorw	#1,_SDL_MintAudio_numbuf
 
-	moveml	d0-d7/a0-a6,sp@-
+	moveml	d0-d1/a0-a1,sp@-
+
+	/* Save FPU if needed */
+	tstw	_SDL_MintAudio_hasfpu
+	beqs	SDL_MintAudio_Dma8_nofpu1
+	.chip	68060
+	fsave	sp@-
+	fmoveml fpcr/fpsr/fpiar,sp@-
+	fmovemx	fp0-fp7,sp@-
+	.chip	68000
+SDL_MintAudio_Dma8_nofpu1:
 
 	/* Callback */
 	jsr	_SDL_MintAudio_Callback
 
+	/* Restore FPU if needed */
+	tstw	_SDL_MintAudio_hasfpu
+	beqs	SDL_MintAudio_Dma8_nofpu2
+	.chip	68060
+	fmovemx	sp@+,fp0-fp7
+	fmoveml	sp@+,fpcr/fpsr/fpiar
+	frestore	sp@+
+	.chip	68000
+SDL_MintAudio_Dma8_nofpu2:
+
 	/* Set new buffer */
 
 	moveq	#0,d0
@@ -169,7 +210,7 @@
 	rorl	#8,d1
 	moveb	d1,a0@(0x0f)
 
-	moveml	sp@+,d0-d7/a0-a6
+	moveml	sp@+,d0-d1/a0-a1
 
 	clrw	_SDL_MintAudio_mutex
 SDL_MintAudio_Dma8End:
@@ -195,9 +236,29 @@
 
 	moveml	d0-d7/a0-a6,sp@-
 
+	/* Save FPU if needed */
+	tstw	_SDL_MintAudio_hasfpu
+	beqs	SDL_MintAudio_Stfa_nofpu1
+	.chip	68060
+	fsave	sp@-
+	fmoveml fpcr/fpsr/fpiar,sp@-
+	fmovemx	fp0-fp7,sp@-
+	.chip	68000
+SDL_MintAudio_Stfa_nofpu1:
+
 	/* Callback */
 	jsr	_SDL_MintAudio_Callback
 
+	/* Restore FPU if needed */
+	tstw	_SDL_MintAudio_hasfpu
+	beqs	SDL_MintAudio_Stfa_nofpu2
+	.chip	68060
+	fmovemx	sp@+,fp0-fp7
+	fmoveml	sp@+,fpcr/fpsr/fpiar
+	frestore	sp@+
+	.chip	68000
+SDL_MintAudio_Stfa_nofpu2:
+
 	/* Set new buffer */
 
 	moveq	#0,d0
--- a/src/audio/mint/SDL_mintaudio_mcsn.c	Wed Sep 13 04:47:46 2006 +0000
+++ b/src/audio/mint/SDL_mintaudio_mcsn.c	Sat Sep 16 16:59:46 2006 +0000
@@ -415,6 +415,8 @@
     DEBUG_PRINT((DEBUG_NAME "buffer 1 at 0x%08x\n",
                  SDL_MintAudio_audiobuf[1]));
 
+    SDL_MintAudio_CheckFpu();
+
     /* Setup audio hardware */
     Mint_InitAudio(this, spec);
 
--- a/src/audio/mint/SDL_mintaudio_stfa.c	Wed Sep 13 04:47:46 2006 +0000
+++ b/src/audio/mint/SDL_mintaudio_stfa.c	Sat Sep 16 16:59:46 2006 +0000
@@ -332,6 +332,8 @@
     DEBUG_PRINT((DEBUG_NAME "buffer 1 at 0x%08x\n",
                  SDL_MintAudio_audiobuf[1]));
 
+    SDL_MintAudio_CheckFpu();
+
     /* Setup audio hardware */
     Mint_InitAudio(this, spec);
 
--- a/src/audio/mint/SDL_mintaudio_xbios.c	Wed Sep 13 04:47:46 2006 +0000
+++ b/src/audio/mint/SDL_mintaudio_xbios.c	Sat Sep 16 16:59:46 2006 +0000
@@ -519,6 +519,8 @@
     DEBUG_PRINT((DEBUG_NAME "buffer 1 at 0x%08x\n",
                  SDL_MintAudio_audiobuf[1]));
 
+    SDL_MintAudio_CheckFpu();
+
     /* Setup audio hardware */
     Mint_InitAudio(this, spec);