Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jun 17th, 2006, 8:50 PM   #1
mika
Newbie
 
Join Date: Jun 2006
Posts: 3
Rep Power: 0 mika is on a distinguished road
coldfire assembly - rts causes Illegal Instruction Exception

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:

                           process_input
102000ac 2f08                           move.l A0, -(A7)
102000ae 2f00           		move.l D0, -(A7)
102000b0 4280           		clr D0
102000b2 41f9 1022 0000 		lea BUFFER, A0
102000b8 1010           		move.b (A0), D0
102000ba 0c80 0000 0031 		cmpi.l #$31, D0
102000c0 6700 0036      		beq  return_to_monitor
102000c4 0c80 0000 0032 		cmpi.l #$32, D0
102000ca 6700 002e      		beq  calculator_mode
102000ce 0c80 0000 0033 		cmpi.l #$33, D0
102000d4 6700 0026      		beq clock_mode
102000d8 0c80 0000 0034 		cmpi.l #$34, D0
102000de 6700 002c      		beq clock_display
102000e2 201f           		move.l (A7)+, D0
102000e4 205f           		move.l (A7)+, A0
102000e6 4e75           		rts


Called sub:
                        clock_mode
102000fc 2f09           	move.l A1, -(A7)
102000fe 43f9 1021 0055 	lea ERROR_OPTION_UNAVAILABLE, A1
10200104 6100 ff4c      	bsr.w out_string
10200108 225f           	move.l (A7)+, A1
1020010a 4e75           	rts

This final instruction generates (snip of trace):
PC: 10200108 SR: 2704 [t.Sm.111...znZvc] 
An: 1022000 00000000          
102000CA
An: 10220000 00000000 00000000 00000000 00000000 00000000 00000000 1023FFEC000000 00000000 00                                                         
Dn: 00000033 00000000 00000000 00000000 00000000 00000000 00000000 00000000 1020
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
mika is offline   Reply With Quote
Old Jun 17th, 2006, 9:41 PM   #2
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
I'm not familiar with that particular assembler, but I doubt it differes from most in this respect: one CALLS a subroutine, then returns. Branching to a subroutine transfers control without recording a return address on the stack. The return instruction then just loads whatever junk was on the stack into the IP and off you go into the weeds, barfing all the way. On the other hand, when you call, the current IP is put onto the stack before the branch is made, and is there for the return instruction. Again, I don't know your particular assembler, but I'll shit in my flat hat if it's all that different.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Jun 17th, 2006, 9:53 PM   #3
mika
Newbie
 
Join Date: Jun 2006
Posts: 3
Rep Power: 0 mika is on a distinguished road
Quote:
Originally Posted by DaWei
I'm not familiar with that particular assembler, but I doubt it differes from most in this respect: one CALLS a subroutine, then returns. Branching to a subroutine transfers control without recording a return address on the stack. The return instruction then just loads whatever junk was on the stack into the IP and off you go into the weeds, barfing all the way. On the other hand, when you call, the current IP is put onto the stack before the branch is made, and is there for the return instruction. Again, I don't know your particular assembler, but I'll shit in my flat hat if it's all that different.

This is not an issue in this case. When "branching" to a subroutine, (Beq in my case) coldfire saves PC on the stack, and then increments PC by the displacement needed to get to the branch location.
mika is offline   Reply With Quote
Old Jun 18th, 2006, 12:51 PM   #4
mika
Newbie
 
Join Date: Jun 2006
Posts: 3
Rep Power: 0 mika is on a distinguished road
Quote:
Originally Posted by mika
This is not an issue in this case. When "branching" to a subroutine, (Beq in my case) coldfire saves PC on the stack, and then increments PC by the displacement needed to get to the branch location.

Actually my reply to you is complete garbage. You are absolutely right. When I read your comments late in the AM's I was quick to dismiss it because my brain was not functioning anymore. What I was using was indeed a conditional branch Bcc and what I actually wanted to do was branch to a subroutine. Which by backwards rationalization was what I did hence I replied by saying Pc is indeed saved on the stack. Ah, stories, a good night's sleep and I'm back in business. Thanks for replying.
mika is offline   Reply With Quote
Old Jun 18th, 2006, 3:35 PM   #5
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
You're entirely welcome. I couldn't pursue it in view of my non-familiarity with the particular assembler, it just seemed reasonable.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

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

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




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 10:19 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC