Illegal instruction exception generated when executing rts

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Illegal instruction exception generated when executing rts

3,994 Views
NOPz
Contributor I
Hi all, I've been trying to fix an illegal exception for a couple of hours now with no success.

What happens is that I have a piece of code that checks for imputs and branches to appropriate subroutine. But after the subroutine finishes when executing the RTS to return to the called throws an Illegal exception. The address in PC seems to be 00000000 which is complete garbage. At the same time I did check my stack manipulation and it looks fine to me. The code snip:

Caller:


Code:

process_input
move.l A0, -(A7)
move.l D0, -(A7)
clr D0
lea BUFFER, A0
move.b (A0), D0
cmpi.l #$31, D0
beq return_to_monitor
cmpi.l #$32, D0
beq calculator_mode
cmpi.l #$33, D0
beq clock_mode
cmpi.l #$34, D0
beq clock_display
move.l (A7)+, D0
move.l (A7)+, A0
rts

Called sub:

clock_mode
move.l A1, -(A7)
lea ERROR_OPTION_UNAVAILABLE, A1
bsr.w out_string
move.l (A7)+, A1
rts
This final RTS instruction generates (snip of trace):

PC: 1020010A SR: A704 [T.Sm.111...xnZvc]
An: 10220000 00000000 00000000 00000000 00000000 00000000 00000000 1023FFEC
Dn: 00000033 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1020010A: 4E75 RTS

trace>

PC: 00000000 SR: A704 [T.Sm.111...xnZvc]
An: 10220000 00000000 00000000 00000000 00000000 00000000 00000000 1023FFF0
Dn: 00000033 00000000 00000000 00000000 00000000 00000000 00000000 00000000

trace>


PC: 00000000 SR: A704 [T.Sm.111...xnZvc]
An: 10220000 00000000 00000000 00000000 00000000 00000000 00000000 1023FFF0
Dn: 00000033 00000000 00000000 00000000 00000000 00000000 00000000 00000000

Exception:
Illegal Instruction
format: 0x04 fault status: 0x0
vector: 0x04 status reg: 0xA704

I do not know how to approach this, I'm thinking maybe the stack is broken, but I checked my pushes and pops and they match. What causes this exception to arise when executing an rts?

Message Edited by NOPz on 2006-06-17 08:48 PM

Message Edited by NOPz on 2006-06-17 08:49 PM

Labels (1)
0 Kudos
Reply
2 Replies

1,098 Views
NOPz
Contributor I
Thanks for answering. This post was truly an epiphany. I'm saying this because after 6+ hours of not understanding why my code crashes, late in the AMs, someone had replied with a similar explanation on another forum. But since my brain was already turned off, I was quick to dismiss it because, I didn't notice that although what I wanted to do is call a subroutine, what I had actually done is just do a conditional jump. After a couple of hours of sleep...my brain is back in business.
0 Kudos
Reply

1,098 Views
rocco
Senior Contributor II
I may be off base, as I haven't used the ColdFire before.

But those look like branch instructions to your subroutines, not call instructions. In other words, I don't believe there is a return address on the stack for the RTS to return to.
0 Kudos
Reply