Chaining a non-ISR routine to an ISR

All 680x0 related coding posts in this section please.

Moderators: simonsunnyboy, Mug UK, Zorro 2, Moderator Team

Post Reply
simonsunnyboy
Moderator
Moderator
Posts: 5238
Joined: Wed Oct 23, 2002 4:36 pm
Location: Friedrichshafen, Germany
Contact:

Chaining a non-ISR routine to an ISR

Post by simonsunnyboy »

Hello all,

I want to chain a routine from an ISR. The routine shall not run with the privileges as granted by the interrupt but be a standard rts ended routine.

I think I can do this by stack manipulation:

Code: Select all

my_interrupt:
; does stuffs
pea rout_without_priv
rte

rout_without_priv:
; do stuff without privileges right after the interrupt but still interrupting the original thread
rts

I have done something like this in the past to chain interrupts with priviliges:

Code: Select all

vbl:
; do stuffs
move.l old_vbl_vect, -(sp)
rts
Is there something I did not understand?
Simon Sunnyboy/Paradize - http://paradize.atari.org/

Stay cool, stay Atari!

1x2600jr, 1x1040STFm, 1x1040STE 4MB+TOS2.06+SatanDisk, 1xF030 14MB+FPU+NetUS-Bee
SteveBagley
Captain Atari
Captain Atari
Posts: 187
Joined: Mon Jan 21, 2013 9:31 am

Re: Chaining a non-ISR routine to an ISR

Post by SteveBagley »

You can definitely do something like that to achieve this but you'll need to do a bit more stack fiddling to get it to work -- it may also vary between 68000 machines and everything else.

Basically, you need to manipulate the stack to go from:

Code: Select all

PC (return address)
SR
to:

Code: Select all

PC (return address)
address of subroutine
SR
So that the RTE has the effect you are after.

One thing to be aware of though is that your subroutine will need to be reentrant since there is nothing to stop the interrupt firing again while it is running. Your stack pointers will change to (since you'll have switched back from SSP to USP during the RTE).

I have to say it feels like a very hacky way of doing things (you certainly wouldn't want to do it on a modern CPU since it would throw the branch predictor out), and I can't help feel their might not be a nicer way to achieve the same result (i.e. is there any reason you can't run the subroutine in supervisor mode?).

Hope this helps,

Steve
simonsunnyboy
Moderator
Moderator
Posts: 5238
Joined: Wed Oct 23, 2002 4:36 pm
Location: Friedrichshafen, Germany
Contact:

Re: Chaining a non-ISR routine to an ISR

Post by simonsunnyboy »

I am aware of reentrancy problems with my proposal.

I want to avoid running in Supervisor mode...and experiment with context switches aswell.
If there is no easy way, I'll probably just run the routine in Super and things are ok.
Simon Sunnyboy/Paradize - http://paradize.atari.org/

Stay cool, stay Atari!

1x2600jr, 1x1040STFm, 1x1040STE 4MB+TOS2.06+SatanDisk, 1xF030 14MB+FPU+NetUS-Bee
SteveBagley
Captain Atari
Captain Atari
Posts: 187
Joined: Mon Jan 21, 2013 9:31 am

Re: Chaining a non-ISR routine to an ISR

Post by SteveBagley »

simonsunnyboy wrote:I am aware of reentrancy problems with my proposal.

I want to avoid running in Supervisor mode...and experiment with context switches aswell.
If there is no easy way, I'll probably just run the routine in Super and things are ok.
Well the mechanism described will work fine and is the way to do a context switch.

Try:

Code: Select all

subq.l #4,a7
move.w 4(a7), (a7)
move.l #addr, 2(a7)
rte
That should work on a 68000 anyway.

Steve
User avatar
charles
10 GOTO 10
10 GOTO 10
Posts: 2718
Joined: Tue Aug 17, 2004 12:11 am
Location: ont. Canada
Contact:

Re: Chaining a non-ISR routine to an ISR

Post by charles »

is this worthy to say again or even mentioning , but i think there is a time default of a millisecond for what happens in you exception handler for the interupt routine
= interupt routines must be less than a millisecond to execute

i read that somewhere

charlie
The radioactive half-life : )
Atari is a lifestyle,not a hobby.
HOLD ON ! ! ! Im printing unreadable characters ...!
Dio
Captain Atari
Captain Atari
Posts: 451
Joined: Thu Feb 28, 2008 3:51 pm

Re: Chaining a non-ISR routine to an ISR

Post by Dio »

I don't think this is possible with any stack address tweak. If the interrupt comes in the middle of an OS call or during another interrupt, already in supervisor mode, you can't drop the S flag but still get it back at the end of the usermode ISR.

You would have to drop the usermode flag, do the ISR, then afterwards transfer control back to supervisor mode with an unused exception.
SteveBagley
Captain Atari
Captain Atari
Posts: 187
Joined: Mon Jan 21, 2013 9:31 am

Re: Chaining a non-ISR routine to an ISR

Post by SteveBagley »

Dio wrote:I don't think this is possible with any stack address tweak. If the interrupt comes in the middle of an OS call or during another interrupt, already in supervisor mode, you can't drop the S flag but still get it back at the end of the usermode ISR.
That's a good point actually, I hadn't thought of that.
You would have to drop the usermode flag, do the ISR, then afterwards transfer control back to supervisor mode with an unused exception.
Yea, although if the interrupt is periodic then you could just wait until the interrupt fires with the processor is in user mode -- depends how important it is that the routine runs at that exact point.

Steve
AtariZoll
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 2978
Joined: Mon Feb 20, 2012 4:42 pm
Contact:

Re: Chaining a non-ISR routine to an ISR

Post by AtariZoll »

I don't think that whole idea is good. Running in supervisor mode is not something so dangerous.

But, if you want it at all cost, you need some extra measures when want to go back in ISR routine.

Here is how it is possible:

ISR rutine:
...
...
pea retHere(pc)
and.w #$FDFF,sr * in user mode
jmp UserSubrut
retHere
.....


UserSubrut
....
....
trap #3 * this returns


myTrap3
* now again in supervisor mode
addq.l #6,sp * drop what is on stack
rts * this will jump to retHere
Famous Schrodinger's cat hypothetical experiment says that cat is dead or alive until we open box and see condition of poor animal, which deserved better logic. Cat is always in some certain state - regardless from is observer able or not to see what the state is.
Post Reply

Return to “680x0”