BusError Handler

All 680x0 related coding posts in this section please.

Moderators: simonsunnyboy, Mug UK, Zorro 2, Moderator Team

User avatar
Arne
Captain Atari
Captain Atari
Posts: 437
Joined: Thu Nov 01, 2007 10:01 am

BusError Handler

Postby Arne » Wed Mar 14, 2018 6:59 pm

I'm writing some code to handle a hardware device I am working on. It is mapped into the 68k's address space and my hardware will generate /DTACK if addressed. Now I want to detect it via software i.e. access it and in case of a bus-error handle the exception instead of letting TOS throw two bombs. Is this a good solution for 68000/68020+ or does it need improvement?

Code: Select all

; **************************************************
; CheckForHardware68000
;
; If hardware is present on a 68000 ST then the
; result in D0.w is set to $0000. If no hardware
; is present D0.w will be set to $DEAD.
; Call this function via Supexec()
;
; Uses: A0 : address where to continue in case of exception
;       A1 : used to store old bus-error handler
;       D0 : return value
;       D1 : for saving the SP
CheckForHardware68000:
    movem.l     A0-A1/D1,-(SP)
    move.l      $08,A1                          ; store old bus-error handler into A1
    lea         BusErrorHandler,A0              ; store new bus-error handler in vector table
    move.l      A0,$08                          ;             -- " --
    lea         CheckForHardware68000Exit,A0    ; In case of bus-error continue here
    move.l      SP,D1                           ; store the SSP as 68000 and 68010+ stack different amount of data
    tst.b       $FF1000                         ; it might crash here
    clr.w       D0                              ; clear return value
CheckForHardware68000Exit:
    move.l      A1,$08                          ; restore old bus-error handler
    movem.l     (SP)+,A0-A1/D1
    rts

; **************************************************
; CheckForHardware68020
;
; If hardware is present on a 68020+ ST then the
; result in D0.w is set to $0000. If no hardware
; is present D0.w will be set to $DEAD.
; Call this function via Supexec()
;
; Uses: A0 : address where to continue in case of exception
;       A1 : used to store old bus-error handler
;       A2 : points to absolute bus--error vector address (VBR + 8)
;       D0 : return value
;       D1 : for saving the SP
CheckForHardware68020:
    movem.l     A0-A2/D1,-(SP)
    movec       VBR,A2                          ; get VBR
    move.l      8(A2),A1                        ; store old bus-error handler into A1
    lea         BusErrorHandler,A0              ; store new bus-error handler in vector table
    move.l      A0,8(A2)                        ;             -- " --
    lea         CheckForHardware68020Exit,A0    ; In case of bus-error continue here
    move.l      SP,D1                           ; store the SSP as 68000 and 68010+ stack different amount of data
    tst.b       $FF1000                         ; it might crash here
    clr.w       D0                              ; clear return value
CheckForHardware68020Exit:
    move.l      A1,8(A2)                        ; restore old bus-error handler
    movem.l     (SP)+,A0-A2/D1
    rts

BusErrorHandler:
    move.l      D1,SP                           ; restore the SSP - no stack correction needed :-)
    move.w      #$DEAD,D0                       ; Bad Hardware result
    jmp         (A0)                            ; return to CheckForHardwareExit680x0


Thanx, Arne
Image

Social Media

     

Return to “680x0”

Who is online

Users browsing this forum: No registered users and 5 guests