[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [MiNT] what's wrong with this code?



 Hi,

ons, 10,.08.2005 kl. 10.49 +0200, skrev mikro:
> Hi,
> 
> I use this dirty trick:
> 
> 		move.l	#set_ssp,$80.w			; install new trap
> 
> 		...
> 
> ; this is an exception after trap #0 -> we're in
> ; supervisor and we set S bit to get into supervisor
> ; after receiving from exception
> 
> set_ssp:	bset	#5,(a7)				; set S flag
> 		rte
> 
> 		...

 I didnt read all the replies, but I'll comment on this code. First of
all, the access to $80.w should give you bus error _UNLESSS_ you are
already in SV mode. Second, when you do trap #0 and get to the 'set_ssp'
function, forcing the SV mode in the save SR stack will cause havoc once
the RTE instruction executes. Why? Because now you use the SV stack in
user code after the SR is reloaded and the user stack is just lost. Bad!
Bad! Bad! ;-)

> 
> and in my program loop I use:
> 
> 		andi.w	#%1101111111111111,sr		; S = 0 -> User mode
> 		move.l	a7,save_usp			; save User SP
> 
> 		[here do some stuff with a7]
> 
> 		movea.l	save_usp,a7			; restore user SP
> 		trap	#0				; switch to
> 							; supervisor

 Here you have lost your usp! This is a real mess! Just clearing the SV
bit does not reload the usp with the value it had before you did your
first trap #0. And this goes on, and on..

> 
> With TOS, Magic, FreeMiNT it works ok. But to the moment I switch MP in FreeMiNT
> on. Could someone tell me, what I do wrong? And why it appears just with MP?

 From the snippet you have here, it amazes me that this works under
anything at all.



 Best Regards,
Odd Skancke