Add and use SuperToUser macro to handle super->user mode switch SDL-1.2
authorPatrice Mandin
Tue, 10 Jan 2012 21:12:45 +0100
branchSDL-1.2
changeset 6206ceb6db0058f1
parent 6203 bc960ba38aae
child 6209 beb988469d26
Add and use SuperToUser macro to handle super->user mode switch
src/audio/mint/SDL_mintaudio_stfa.c
src/audio/mint/SDL_mintaudio_xbios.c
src/timer/mint/SDL_systimer.c
src/video/ataricommon/SDL_atarisuper.h
src/video/ataricommon/SDL_xbiosevents.c
     1.1 --- a/src/audio/mint/SDL_mintaudio_stfa.c	Mon Jan 09 07:06:36 2012 -0500
     1.2 +++ b/src/audio/mint/SDL_mintaudio_stfa.c	Tue Jan 10 21:12:45 2012 +0100
     1.3 @@ -38,6 +38,7 @@
     1.4  #include "../SDL_sysaudio.h"
     1.5  
     1.6  #include "../../video/ataricommon/SDL_atarimxalloc_c.h"
     1.7 +#include "../../video/ataricommon/SDL_atarisuper.h"
     1.8  
     1.9  #include "SDL_mintaudio.h"
    1.10  #include "SDL_mintaudio_stfa.h"
    1.11 @@ -164,7 +165,7 @@
    1.12  	/* Stop replay */
    1.13  	oldpile=(void *)Super(0);
    1.14  	cookie_stfa->sound_enable=STFA_PLAY_DISABLE;
    1.15 -	Super(oldpile);
    1.16 +	SuperToUser(oldpile);
    1.17  }
    1.18  
    1.19  static void Mint_UnlockAudio(_THIS)
    1.20 @@ -174,7 +175,7 @@
    1.21  	/* Restart replay */
    1.22  	oldpile=(void *)Super(0);
    1.23  	cookie_stfa->sound_enable=STFA_PLAY_ENABLE|STFA_PLAY_REPEAT;
    1.24 -	Super(oldpile);
    1.25 +	SuperToUser(oldpile);
    1.26  }
    1.27  
    1.28  static void Mint_CloseAudio(_THIS)
    1.29 @@ -184,7 +185,7 @@
    1.30  	/* Stop replay */
    1.31  	oldpile=(void *)Super(0);
    1.32  	cookie_stfa->sound_enable=STFA_PLAY_DISABLE;
    1.33 -	Super(oldpile);
    1.34 +	SuperToUser(oldpile);
    1.35  
    1.36  	/* Wait if currently playing sound */
    1.37  	while (SDL_MintAudio_mutex != 0) {
    1.38 @@ -283,7 +284,7 @@
    1.39  	/* Restart replay */
    1.40  	cookie_stfa->sound_enable=STFA_PLAY_ENABLE|STFA_PLAY_REPEAT;
    1.41  
    1.42 -	Super(oldpile);
    1.43 +	SuperToUser(oldpile);
    1.44  
    1.45  	DEBUG_PRINT((DEBUG_NAME "hardware initialized\n"));
    1.46  }
     2.1 --- a/src/audio/mint/SDL_mintaudio_xbios.c	Mon Jan 09 07:06:36 2012 -0500
     2.2 +++ b/src/audio/mint/SDL_mintaudio_xbios.c	Tue Jan 10 21:12:45 2012 +0100
     2.3 @@ -41,6 +41,7 @@
     2.4  #include "../SDL_sysaudio.h"
     2.5  
     2.6  #include "../../video/ataricommon/SDL_atarimxalloc_c.h"
     2.7 +#include "../../video/ataricommon/SDL_atarisuper.h"
     2.8  
     2.9  #include "SDL_mintaudio.h"
    2.10  #include "SDL_mintaudio_dma8.h"
    2.11 @@ -258,7 +259,7 @@
    2.12  	DMAAUDIO_IO.dest_ctrl = dest_ctrl;
    2.13  	DMAAUDIO_IO.sync_div = sync_div;
    2.14  
    2.15 -	Super(oldstack);
    2.16 +	SuperToUser(oldstack);
    2.17  }
    2.18  
    2.19  static void Mint_CheckExternalClock(_THIS)
     3.1 --- a/src/timer/mint/SDL_systimer.c	Mon Jan 09 07:06:36 2012 -0500
     3.2 +++ b/src/timer/mint/SDL_systimer.c	Tue Jan 10 21:12:45 2012 +0100
     3.3 @@ -46,6 +46,8 @@
     3.4  #include "../SDL_timer_c.h"
     3.5  #include "SDL_thread.h"
     3.6  
     3.7 +#include "../../video/ataricommon/SDL_atarisuper.h"
     3.8 +
     3.9  #include "SDL_vbltimer_s.h"
    3.10  
    3.11  /* from audio/mint */
    3.12 @@ -64,7 +66,7 @@
    3.13  	/* Set first ticks value */
    3.14  	old_stack = (void *)Super(0);
    3.15  	start = *((volatile long *)_hz_200);
    3.16 -	Super(old_stack);
    3.17 +	SuperToUser(old_stack);
    3.18  
    3.19  	start *= 5;	/* One _hz_200 tic is 5ms */
    3.20  
    3.21 @@ -80,7 +82,7 @@
    3.22  	} else {
    3.23  		void *old_stack = (void *)Super(0);
    3.24  		now = *((volatile long *)_hz_200);
    3.25 -		Super(old_stack);
    3.26 +		SuperToUser(old_stack);
    3.27  	}
    3.28  
    3.29  	return((now*5)-start);
    3.30 @@ -111,7 +113,7 @@
    3.31  	/* Install RunTimer in vbl vector */
    3.32  	old_stack = (void *)Super(0);
    3.33  	timer_installed = !SDL_AtariVblInstall(SDL_ThreadedTimerCheck);
    3.34 -	Super(old_stack);
    3.35 +	SuperToUser(old_stack);
    3.36  
    3.37  	if (!timer_installed) {
    3.38  		return(-1);
    3.39 @@ -127,7 +129,7 @@
    3.40  	if (timer_installed) {
    3.41  		void *old_stack = (void *)Super(0);
    3.42  		SDL_AtariVblUninstall(SDL_ThreadedTimerCheck);
    3.43 -		Super(old_stack);
    3.44 +		SuperToUser(old_stack);
    3.45  		timer_installed = SDL_FALSE;
    3.46  	}
    3.47  	read_hz200_from_vbl = SDL_FALSE;
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/src/video/ataricommon/SDL_atarisuper.h	Tue Jan 10 21:12:45 2012 +0100
     4.3 @@ -0,0 +1,61 @@
     4.4 +/*
     4.5 +    SDL - Simple DirectMedia Layer
     4.6 +    Copyright (C) 1997-2012 Sam Lantinga
     4.7 +
     4.8 +    This library is free software; you can redistribute it and/or
     4.9 +    modify it under the terms of the GNU Lesser General Public
    4.10 +    License as published by the Free Software Foundation; either
    4.11 +    version 2.1 of the License, or (at your option) any later version.
    4.12 +
    4.13 +    This library is distributed in the hope that it will be useful,
    4.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    4.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    4.16 +    Lesser General Public License for more details.
    4.17 +
    4.18 +    You should have received a copy of the GNU Lesser General Public
    4.19 +    License along with this library; if not, write to the Free Software
    4.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    4.21 +
    4.22 +    Sam Lantinga
    4.23 +    slouken@libsdl.org
    4.24 +*/
    4.25 +#include "SDL_config.h"
    4.26 +
    4.27 +#ifndef _ATARI_SUPER_h
    4.28 +#define _ATARI_SUPER_h
    4.29 +
    4.30 +#include "SDL_stdinc.h"
    4.31 +
    4.32 +#ifndef SuperToUser
    4.33 +
    4.34 +/*
    4.35 + * Safe binding to switch back from supervisor to user mode.
    4.36 + * On TOS or EmuTOS, if the stack pointer has changed between Super(0)
    4.37 + * and Super(oldssp), the resulting user stack pointer is wrong.
    4.38 + * This bug does not occur with FreeMiNT.
    4.39 + * So the safe way to return from supervisor to user mode is to backup
    4.40 + * the stack pointer then restore it after the trap.
    4.41 + * Sometimes, GCC optimizes the stack usage, so this matters.
    4.42 + */
    4.43 +#define SuperToUser(ptr)						\
    4.44 +(void)__extension__							\
    4.45 +({									\
    4.46 +	register long retvalue __asm__("d0");				\
    4.47 +	register long sp_backup;					\
    4.48 +									\
    4.49 +	__asm__ volatile						\
    4.50 +	(								\
    4.51 +		"movl	sp,%1\n\t"					\
    4.52 +		"movl	%2,sp@-\n\t"					\
    4.53 +		"movw	#0x20,sp@-\n\t"					\
    4.54 +		"trap	#1\n\t"						\
    4.55 +		"movl	%1,sp\n\t"					\
    4.56 +	: "=r"(retvalue), "=&r"(sp_backup)	/* outputs */		\
    4.57 +	: "g"((long)(ptr)) 			/* inputs */		\
    4.58 +	: "d1", "d2", "a0", "a1", "a2"		\
    4.59 +	);								\
    4.60 +})
    4.61 +
    4.62 +#endif /* SuperToUser */
    4.63 +
    4.64 +#endif /* _ATARI_SUPER_h */
     5.1 --- a/src/video/ataricommon/SDL_xbiosevents.c	Mon Jan 09 07:06:36 2012 -0500
     5.2 +++ b/src/video/ataricommon/SDL_xbiosevents.c	Tue Jan 10 21:12:45 2012 +0100
     5.3 @@ -30,6 +30,7 @@
     5.4  #include <mint/osbind.h>
     5.5  
     5.6  #include "../../events/SDL_events_c.h"
     5.7 +#include "SDL_atarisuper.h"
     5.8  #include "SDL_xbiosevents_c.h"
     5.9  #include "SDL_xbiosinterrupt_s.h"
    5.10  
    5.11 @@ -75,7 +76,7 @@
    5.12  	);
    5.13  
    5.14  	/* Back to user mode */
    5.15 -	Super(oldpile);
    5.16 +	SuperToUser(oldpile);
    5.17  
    5.18  	SDL_AtariXbios_enabled=1;
    5.19  }
    5.20 @@ -98,7 +99,7 @@
    5.21  	SDL_AtariXbios_Restore(kbdvecs);
    5.22  
    5.23  	/* Back to user mode */
    5.24 -	Super(oldpile);
    5.25 +	SuperToUser(oldpile);
    5.26  }
    5.27  
    5.28  static int atari_GetButton(int button)