Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!rutgers!dayton!viper!john From: john@viper.Lynx.MN.Org (John Stanley) Newsgroups: comp.sys.atari.st Subject: Re: strange bug? Message-ID: <342@viper.Lynx.MN.Org> Date: Fri, 27-Nov-87 13:31:03 EST Article-I.D.: viper.342 Posted: Fri Nov 27 13:31:03 1987 Date-Received: Mon, 30-Nov-87 01:27:37 EST References: <21951@ucbvax.BERKELEY.EDU> Reply-To: john@viper.UUCP (John Stanley) Organization: DynaSoft Systems Lines: 51 In article <21951@ucbvax.BERKELEY.EDU> brianp@ernie.Berkeley.EDU.UUCP (Brian Peterson) writes: >I wrote a little routine which just jumped to an exception handling routine, >and put the address of my routine in the exception vector in place of the >original. If the exception was the divide by zero, it worked as expected. >When it was the midi/kboard exception, the results were strange. >My routine was like this: > move.l #fc281c a0 > jmp (a0) If it's any consolation, this is a common mistake made by people who aren't used to writing dirty-tricks code on the 68000. The method you're using to jump to the original exception handler is the problem. First off, do-NOT use a constant address for the jump. Save the address originaly contained in the exception vector and jump to -that- location. This will allow your code to work on machines where the roms may have changed, and with any other code that may have already "hooked the vector". Secondly, if you've saved the original vector in a long (4 byte) variable called olvect, use this code to jump to it: move.l olvect,-(a7) rts This allows you to make an indirect jump without modifying any registers. Third, be sure you restore the original vector before you exit your program. Not doing so can cause very very bad things to happen. >The result varied depending on whether I used a0, a1, or a2. ..because altering a0, a1, or a2 had the effect of altering the contents of those registers in-the-program-making-the-exception(!). After your routine changed a0/1/2, the exception handler (doing it's job by-the-rules) would then store and restore the altered values and then RTE to the program running when the exception occured. Remember, never alter the contents of a register from within an exception unless you can restore that register before your code releases control of the machine -or- you're really sure what you're doing. > Brian Peterson, ...!ucbvax!ucbernie!brianp (brianp@ernie.berkeley.edu) PS, just out of curiosity, what are you writing that needs to replace an exception vector? --- John Stanley (john@viper.UUCP) Software Consultant - DynaSoft Systems UUCP: ...{amdahl,ihnp4,rutgers}!meccts!viper!john