HRTmon & Updating NMI vector

One of the features added on the 68010+ Motorola CPUs is a special register called VBR – Vector Base Register, which allows the OS or user program to move the CPU’s vector table away from 68000‘s fixed address $00000 to some other address. On the Amiga, this was usually used to move the vector table to fastRAM, enabling somewhat faster interrupt processing. One of the utilities that allowed this was VBRMove.

I usually have VBRMove installed on my minimig (you can never have enough speed!), and when I implemented HRTmon for the minimig-de1 project, this posed a problem, as once you move the vector table, the HRTmon handling code can no longer detect that access to the NMI vector (vector table offset $7c) has happened. HRTmon code uses a special hook that detects the start of the NMI, which on minimig-de1 is mapped to a button (F11) on the keyboard. In the event of a NMI button being pressed, the Verilog cart code waits for the CPU to access RAM location $7c and instead of allowing the CPU to read the specified RAM location, overrides decoding the address as a RAM access and returns the address of the HRTmon ROM entry point to the CPU. This way no program can disable HRTmon by writing over the NMI vector location, unless of course it does something really mean, like pointing the stack to an odd address.

Since the cart verilog code is inside the minimig design, it can only see the CPU accessing NMI vector if it resides in chipRAM, because the TG68K CPU core has a special bus for fastRAM that completely bypasses the minimig core. I should really fix this someday by moving the NMI detection code in the TG68K core wrapper, but for now I wrote a simple utility that can be used if the vector table resides in fastRAM.

It works by putting the CPU in the Superuser state, reading the VBR, and updating the NMI vector location (VBR+$7c) to point to HRTmon entry, as used in minimig. It than enters user mode and exits. Simple!

; SetNMI.s
; 2013,
; gets VBR and updates NMI vector to address of HRTmon entry point

execbase = 4
superstate = -150
userstate = -156
NMI_vec = $7c
HRTmon_entry = $00a0000c

 move.l execbase,a6
 jsr superstate(a6)
 move.l d0,SaveSP
 movec vbr,d0
 add.l #NMI_vec,d0
 move.l d0,a6
 move.l #HRTmon_entry,(a6)
 move.l execbase,a6
 move.l SaveSP,d0
 jsr userstate(a6)
SaveSP: blk.l 1

Compiled program attached bellow:

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.