home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 2
/
FFMCD02.bin
/
new
/
hard
/
drivr
/
zeusscsi
/
patchzeus.asm
< prev
next >
Wrap
Assembly Source File
|
1993-12-21
|
15KB
|
587 lines
; PatchZeus.asm - resident module to patch PPI Zeus SCSI driver
;
; Written by Michael L. Hitch
; Montana State University
; osymh@msu.oscs.montana.edu
;
include "exec/types.i"
include "exec/nodes.i"
include "exec/memory.i"
include "exec/resident.i"
include "exec/execbase.i"
include "exec/libraries.i"
include "exec/io.i"
include "exec/errors.i"
include "devices/scsidisk.i"
include "libraries/configvars.i"
include "libraries/expansion.i"
include "hardware/cia.i"
include "hardware/custom.i"
; xref _LVOOpenLibrary
; xref _LVOCloseLibrary
; xref _LVOFindConfigDev
xref _LVOAllocSignal
xref _LVOFreeSignal
xref _LVOFindTask
xref _LVOFindName
xref _LVOSignal
xref _LVOWait
xref _LVOAllocMem
xref _LVOSumKickData
xref _LVOForbid
xref _LVOPermit
xref _LVODisable
xref _LVOEnable
xref _LVOSupervisor
xref _ciaa
xref _custom
csect text
;
; Program entry point
;
movem.l d2-d3/a2/a5/a6,-(sp)
move.l 4,a6
;
; *** process command line arguments
;
jsr AddResident(pc) ; Add program to KickMemPtr list
;*** check status?
;
movem.l (sp)+,d2-d3/a2/a5/a6
rts
;
;
AddResident
move.l KickMemPtr(a6),a0
1$:
move.l a0,d0
beq.s NewResident ; Not found
move.l LN_NAME(a0),a1 ; name of this entry
lea TagName(pc),a2 ; my name
2$:
move.b (a1)+,d0
cmp.b (a2)+,d0
bne.s 3$
tst.b d0
bne 2$
; found entry
moveq #1,d0
rts
3$:
move.l (a0),a0 ; Next entry
bra 1$
;
; Layout of memory block
; ds.b 8 Overhead space for AllocAbs
; ds.b ML_SIZE Memory entry list
; ds.b ME_SIZE Memory entry
; ds.b 8 RomTab pointer array
; ds.b nnn Resident module
;
KM_RTPTR equ ML_SIZE+ME_SIZE ; Location of RomTag pointer array
KM_SIZE equ KM_RTPTR+8 ; Size of KickMem info header
;
NewResident:
moveq #KM_SIZE+8,d0 ; size of KickMem header + 8 byte overhead
add.l RomTag+6(pc),d0
sub.l RomTag+2(pc),d0 ; add length of resident module
move.l #MEMF_24BITDMA!MEMF_CLEAR,d1
jsr _LVOAllocMem(a6) ; allocate memory
tst.l d0
bne.s 1$
moveq #KM_SIZE+8,d0 ; size of KickMem header + 8 byte overhead
add.l RomTag+6(pc),d0
sub.l RomTag+2(pc),d0 ; add length of resident module
move.l #MEMF_CHIP!MEMF_CLEAR,d1
jsr _LVOAllocMem(a6) ; allocate memory
tst.l d0
bne.s 1$
moveq #2,d0
rts
1$:
move.l d0,a0 ; a0 = address of allocated memory
lea 8(a0),a2 ; a2 = address of MemList
move.b #NT_MEMORY,LN_TYPE(a2) ; initialize MemList
move.w #1,ML_NUMENTRIES(a2)
move.l a0,ML_ME(a2)
moveq #KM_SIZE+8,d0 ; size of KickMem header + 8 byte overhead
move.l d0,ML_ME+ME_LENGTH(a2)
move.l RomTag+6(pc),d0
sub.l RomTag+2(pc),d0 ; d0 = length of resident module
add.l d0,ML_ME+ME_LENGTH(a2)
lea KM_SIZE+8(a0),a0 ; point to RomTag structure
lea RomTag(pc),a1
move.l a0,d1
sub.l a1,d1 ; relocation offset for RomTag addresses
move.l a0,KM_RTPTR(a2) ; RomTag Pointer
subq.l #1,d0
2$: move.b (a1)+,(a0)+ ; copy resident module
dbra d0,2$
move.l KM_RTPTR(a2),a0 ; Point to RomTag structure
add.l d1,RT_MATCHTAG(a0) ; relocate absolute addresses
add.l d1,RT_ENDSKIP(a0)
add.l d1,RT_NAME(a0)
add.l d1,RT_IDSTRING(a0)
add.l d1,RT_INIT(a0)
move.l RT_NAME(a0),LN_NAME(a2) ; set MemList name same as RomTag name
;*** add to KickMemPtr & KickTagPtr
jsr _LVOForbid(a6)
lea KickMemPtr(a6),a0
3$: move.l (a0),d0
beq.s 4$
move.l d0,a0
bra 3$
4$: tst.l KickMemPtr(a6)
beq.s 5$
move.l a0,LN_PRED(a2) ; is this really needed?
move.l a2,(a0)
bra.s 6$
5$: move.l a2,KickMemPtr(a6)
6$: move.l KickTagPtr(a6),d0
beq.s 7$
bset #31,d0
move.l d0,KM_RTPTR+4(a2) ; link to existing RomTag pointer array
7$: lea KM_RTPTR(a2),a0 ; address of our RomTag pointer array
move.l a0,KickTagPtr(a6)
jsr _LVOSumKickData(a6)
move.l d0,KickCheckSum(a6)
jsr _LVOPermit(a6)
;*** call resident initialization routine?
lea myClearCache(pc),a5 ; clear caches before executing
jsr _LVOSupervisor(a6) ; the initialization code
move.l KM_RTPTR(a2),a0
move.l RT_INIT(a0),a0
jsr (a0) ; Call initialization routine
moveq #0,d0
rts
;
myClearCache:
cpusha bc ; push and invalid both caches
rte
;
;
; The resident RomTag structure
;
RomTag: dc.w RTC_MATCHWORD
dc.l RomTag
dc.l EndModule
dc.b RTF_COLDSTART
dc.b 37
dc.b NT_KICKMEM
dc.b 0
dc.l TagName
dc.l TagID
dc.l TagInit
TagName: dc.b "PatchZeus",0
dc.b "$VER: "
TagID: dc.b "PatchZeus 1.0 (19.10.93)",$0d,$0a,0
ZeusName: dc.b "PPSscsi2.device",0
ExpName: EXPANSIONNAME
ds.w 0
PATCHLOC1 equ $19b0 ; setup prior to starting 53C710 script
PATCHLOC2 equ $1a38 ; wait for 53C710 completion
PATCHLOC3 equ $1f88 ; Interrupt - signal completion
PATCHLOC4 equ $1ff8 ; Interrupt - phase mismatch
PATCHLOC5 equ $20ee ; 53C170 setup - set SCNTL0
PATCHLOC6 equ $210c ; 53C710 setup - set SIEN
PATCHLOC7 equ $1d32 ; Interrupt - received interrupt
PATCHLOC8 equ $28ae ; SCSIcmd - adjust scsi_Actual
PATCHLOC9 equ $28a0 ; SCSIcmd - adjust scsi_SenseActual
PATCHLOC10 equ $0ef0 ; Compare partition name with BSTR name
PATCHLOC11 equ $1ec0 ; Interrupt - code $ff01
PATCHLOC12 equ $136c ; Device Open - return HFERR_NoBoard
PATCHLOC13 equ $27fc ; ScsiCmd - return HFERR_BadStatus
PATCHLOC14 equ $1b5a ; Sync request period
;
; Entry when resident module is initialized
;
TagInit:
movem.l d2/d3/a2/a4,-(sp)
lea _custom,a0 ; Address of custom chip
move.w potinp(a0),d0 ; Read register
ori.w #$0c00,d0 ; Set output, data = 1
move.w d0,potgo(a0)
move.w potinp(a0),d0 ; Read data
andi.w #$0400,d0 ; Test if Mouse right button pressed
beq.s SkipMouse ; Yes, don't check left button
lea _ciaa,a0
btst #6,ciapra(a0) ; Test if Mouse left button pressed
beq.s TagExit ; Yes, skip it
SkipMouse:
btst #AFB_68040,AttnFlags+1(a6) ; is it 68040?
bne.s Is_68040
cmp.w #36,LIB_VERSION(a6) ; if version 2.0 or later
bge.s TagExit ; then AFB_68040 is valid
; *** 68040 not detected on WB1.3
moveq #AFF_68030!AFF_68020,d0
and.w AttnFlags(a6),d0 ; Kludge for WB1.3
bne.s Is_68040
TagExit:
moveq #0,d0
movem.l (sp)+,d2/d3/a2/a4
rts
Is_68040:
lea DeviceList(a6),a0 ; get address of device list
lea ZeusName(pc),a1 ; Device driver name
jsr _LVOFindName(a6) ; Find device driver
tst.l d0
beq TagExit ; Didn't find it
move.l d0,a2
;
; Found device driver; make sure it's the correct version and validate
; the places we are going to patch
;
bra.s debug1 ; ** DEBUG ** nop to enable color changes
move.w #$00ff,$00dff180 ; ** DEBUG ** set screen color = cyan
move.l #$00800000,d0
delay1: subq.l #1,d0
bgt delay1
move.w #$0888,$00dff180
debug1:
cmp.w #98,LIB_REVISION(a2) ; Check if revision 98
bne TagExit ; Nope, skip it
move.l LN_NAME(a2),a4
lea -$521(a4),a4 ; Base relative to start of ROM
cmp.l #$584f206d,PATCHLOC1(a4) ; verify patch points
bne TagExit
cmp.l #$206d0008,PATCHLOC2(a4)
bne TagExit
cmp.l #$217c0000,PATCHLOC3(a4)
bne TagExit
cmp.l #$02800000,PATCHLOC4(a4)
bne TagExit
cmp.l #$117c00cc,PATCHLOC5(a4)
bne TagExit
cmp.l #$10bc00bf,PATCHLOC6(a4)
bne TagExit
cmp.l #$02800000,PATCHLOC7(a4)
bne TagExit
cmp.l #$23680004,PATCHLOC8(a4)
bne TagExit
cmp.l #$3368001a,PATCHLOC9(a4)
bne TagExit
cmp.l #$e5802b40,PATCHLOC10(a4)
bne TagExit
cmp.l #$20280030,PATCHLOC11(a4)
bne TagExit
cmp.l #$0cad0000,PATCHLOC12(a4)
bne TagExit
cmp.l #$2b7c0000,PATCHLOC13(a4)
bne TagExit
cmp.l #$001e0104,PATCHLOC14(a4)
bne TagExit
bra.s debug2 ; ** DEBUG ** nop to enable color changes
move.w #$0f0f,$00dff180 ; ** DEBUG ** set screen color = magenta
move.l #$00800000,d0
delay2: subq.l #1,d0
bgt delay2
move.w #$0888,$00dff180
debug2:
;
; install patches
;
; relocate jumps back into the driver
;
move.l a4,d0
lea Patch1end(pc),a0
move.l (a0),-(a0)
add.l d0,(a0)
lea Patch2end(pc),a0
move.l (a0),-(a0)
add.l d0,(a0)
lea Patch3end(pc),a0
move.l (a0),-(a0)
add.l d0,(a0)
lea Patch4end(pc),a0
move.l (a0),-(a0)
add.l d0,(a0)
lea Patch7end(pc),a0
move.l (a0),-(a0)
add.l d0,(a0)
lea Patch8end(pc),a0
move.l (a0),-(a0)
add.l d0,(a0)
lea Patch9end(pc),a0
move.l (a0),-(a0)
add.l d0,(a0)
lea Patch10end(pc),a0
move.l (a0),-(a0)
add.l d0,(a0)
lea Patch11end(pc),a0
move.l (a0),-(a0)
add.l d0,(a0)
lea Patch11end2(pc),a0
move.l (a0),-(a0)
add.l d0,(a0)
lea Patch12end(pc),a0
move.l (a0),-(