nicholso@ihlpm.ATT.COM (B E Nicholson) (11/16/87)
[ Line eater, come and get it] I've recently been developing some code which installs it's own interrupt, and trap handlers. Unfortunately, whenever the code tries to return to the original code a bus error results. For example, if the routine _clock_int is installed as either a trap, timer interrupt, or any other exception handler by the main routine when the rte instruction is executed at the end of the _restart routine a bus error will result. I'm a little lost as to why. _start: lea main,a0 * 41F9 0000 00D6 ; use the os routine to move.l a0,-(a7) * 2F08 ; execute main in move.w #$26,d0 * 303C 0026 ; supervisor state move.w d0,-(a7) * 3F00 trap #$E * 4E4E adda.w #$6,a7 * DEFC 0006 jsr _fault * 4EB9 0000 08BA ; this should never happen _save: move #$2700,sr * 46FC 2700 move.l a6,-(a7) * 2F0E lea proc_ptr,a6 * 4DF9 0000 0BDC ; proc_ptr is a temporary move.l $0(a6),d0 * 202E 0000 ; storage location movea.l d0,a6 * 2C40 adda.w #$46,a6 * DCFC 0046 movem.l d0-d7/a0-a5,-(a6) * 48E6 FFFC move.l (a7)+,d0 * 201F move.l (a7)+,d1 * 221F movea.l d1,a1 * 2241 move.l d0,$FFFC(a6) * 2D40 FFFC move usp,a0 * 4E68 move.l a0,d0 * 2008 move.l d0,$FFF8(a6) * 2D40 FFF8 move.l (a7)+,d0 * 201F movea.l d0,a0 * 2040 move.l a0,$FFF4(a6) * 2D48 FFF4 move.w (a7)+,d0 * 301F move.w d0,$FFF2(a6) * 3D40 FFF2 jmp (a1) * 4ED1 _restart: move #$2700,sr * 46FC 2700 lea proc_ptr,a6 * 4DF9 0000 0BDC move.l $0(a6),d0 * 202E 0000 movea.l d0,a6 * 2C40 move.w $0(a6),d0 * 302E 0000 move.w d0,-(a7) * 3F00 move.l $2(a6),d0 * 202E 0002 move.l d0,-(a7) * 2F00 move.l $6(a6),d0 * 202E 0006 movea.l d0,a0 * 2040 move a0,usp * 4E60 move.l $A(a6),d0 * 202E 000A move.l d0,-(a7) * 2F00 adda.w #$E,a6 * DCFC 000E movem.l (a6)+,d0-d7/a0-a5 * 4CDE 3FFF movea.l (a7)+,a6 * 2C5F rte * 4E73 _clock_i: jsr _save * 4EB9 0000 0020 jsr switch * 4EB9 0000 0372 bra.b _restart * 60BC Thanks, Barry Nicholson
koreth@ssyx.ucsc.edu (Steven Grimm) (11/16/87)
In article <1498@ihlpm.ATT.COM> nicholso@ihlpm.ATT.COM (B E Nicholson) writes: >[ Line eater, come and get it] > > >I've recently been developing some code which installs it's own interrupt, >and trap handlers. Unfortunately, whenever the code tries to return to >the original code a bus error results. For example, if the routine >_clock_int is installed as either a trap, timer interrupt, or any other >exception handler by the main routine when the rte instruction is executed >at the end of the _restart routine a bus error will result. I'm a little >lost as to why. > > (assembly code follows) What is that routine supposed to do? Knowing that makes debugging it a lot easier. At first glance, it looks like it could be a task-switcher for a multitasking kernel; is that it? It looks like you aren't doing the same number of pushes and pops to the stack. That could be intentional (if you're doing multitasking), but is a pretty sure way to get a bus error. My advice to you is to trace your code on paper, keeping track of exactly what's on the user and supervisor stacks. Remember that exceptions push the status register and return address to the supervisor stack before running the exception code; make sure you know in what order those are pushed, as that can mess you up too. Hope that helps. +New! Improved! Now 100% Artificial-+-+-----------------------------------+ |# # @@@ **** &&&&& $$$$$ % %| |Steven Grimm | |# # @ @ * * & $ % %+-+ ARPA: koreth@ucscb.ucsc.edu | |### @ @ **** &&&& $ %%%%%| | UUCP: ...!ucbvax!ucscc!ssyx!koreth| |# # @ @ * * & $ % %+-+ ______________________________| |# # @@@ * ** &&&&& $ % %| | |"Let's see what's out there."| +-----with NutraSour(TM)! No natural colors or preservatives!------------+