English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Asm / Hardware

 
 
Thread Tools
Old 14 September 2021, 20:23   #1
leonard
Registered User
 
leonard's Avatar
 
Join Date: Apr 2013
Location: paris
Posts: 133
move sr and rtr

Hi!

I need to call a subroutine but save/restore X cpu flag. To do that I'm using the nice RTR instruction like:

Code:
     bsr   foo
     ...

foo:   move.w sr,-(a7)
         ; code that could scratch X flag
         rtr
It works pretty well. But now I wonder if that kind of code runs on any CPU, including a context without operating system ( so I can't rely on any software emulated instruction on 68060)

Is that kind of code ( move sr,-(a7) and rtr ) fully ocmpatible with any amiga CPUs?
leonard is offline  
Old 14 September 2021, 20:47   #2
a/b
Registered User
 
Join Date: Jun 2016
Location: europe
Posts: 1,039
Yeah, it's implemented in hardware in 000-060. Just have to run it in supervisor mode because 010+ requires supervisor for move sr,<ea>, while providing move ccr,<ea> (which 000 doesn't have) for user mode.
a/b is offline  
Old 14 September 2021, 21:09   #3
leonard
Registered User
 
leonard's Avatar
 
Join Date: Apr 2013
Location: paris
Posts: 133
Quote:
Originally Posted by a/b View Post
Yeah, it's implemented in hardware in 000-060. Just have to run it in supervisor mode because 010+ requires supervisor for move sr,<ea>, while providing move ccr,<ea> (which 000 doesn't have) for user mode.
oh you're right the supervisor thing is an issue in my context. I'll go with that kind of simple stuff then:

Code:
		subx.b d1,d1		; read X flag in d1
		move.w	d1,-(a7)
                bsr MFMDecodeTrackCallback
		move.w (a7)+,d1
		add.b d1,d1		; restore X flag
leonard is offline  
Old 14 September 2021, 21:44   #4
ross
Defendit numerus
 
ross's Avatar
 
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 53
Posts: 4,468
This?:

Code:
    subx.w  d1,d1
    move.w  d1,-(sp) 
    ; code that could scratch X flag
    rtr

Last edited by ross; 14 September 2021 at 22:05. Reason: first version with roxr.b #4, but who cares for other CCR flags :)
ross is offline  
Old 15 September 2021, 01:11   #5
leonard
Registered User
 
leonard's Avatar
 
Join Date: Apr 2013
Location: paris
Posts: 133
Quote:
Originally Posted by ross View Post
This?:

Code:
    subx.w  d1,d1
    move.w  d1,-(sp) 
    ; code that could scratch X flag
    rtr
oh it scratchs other ccr flags but I don't care in my case. Pretty smart!
leonard is offline  
Old 17 September 2021, 13:03   #6
admiral
Engineer
 
Join Date: Oct 2018
Location: Shadow realm
Posts: 165
Quote:
Originally Posted by leonard View Post
Is that kind of code ( move sr,-(a7) and rtr ) fully ocmpatible with any amiga CPUs?
In 010+, if not in supervisor mode (normally Amiga software runs in user mode), it will break.

Whereas move from CCR is 010+, so it will break on plain 68000.

A reliable (and fast!) alternative is to call exec.library's GetCC().

Of course, that assumes execbase is available and consistent. If it's not, what I would do is:

* Make a function for it, and use get from SR or CCR depending on CPU model. Then call as needed.
* If it's used in a single place, implement the detection right there, or set up the right code via self-modifying code.

Last edited by admiral; 17 September 2021 at 13:08. Reason: self-modifying code
admiral is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
Is move.l atomic sparhawk Coders. Asm / Hardware 1 25 December 2019 20:43
Move it Move it... (68000) Gilloo Coders. Asm / Hardware 19 04 December 2011 17:36
Move Em amigapd request.Old Rare Games 1 13 March 2011 02:22
Please delete or move if necessary JSemple3 support.Games 7 30 June 2003 13:59

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 19:59.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.07165 seconds with 13 queries