summaryrefslogtreecommitdiffstats
path: root/private/ntos/miniport/symbios/symc810/scrpt810.asm
blob: 2e6fe2eb5b67560782da19b1b26bffd868558c9f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
;/************************************************************************
;*                                                                       *
;*         Copyright 1994 Symbios Logic Inc.  All rights reserved.       *
;*                                                                       *
;*   This file is confidential and a trade secret of Symbios Logic       *
;*   The receipt of or possession of this file does not convey any       *
;*   rights to reproduce or disclose its contents or to manufacture,     *
;*   use, or sell anything is may describe, in whole, or in part,        *
;*   without the specific written consent of Symbios Logic               *
;*                                                                       *
;************************************************************************/
;
;/*+++HDR
; *
; *  Version History
; *  ---------------
; *
; *    Date    Who?  Description
; *  --------  ----  -------------------------------------------------------
; *
; *	 1/12/96	SPD	 Add new script entry point to restart negotiations for
; *					 synch transfer mode on same IO as wide negotiation.
; *					 Fix for parity error on wide data transfers.
; *
;---*/
;

;
; Successful operation codes
;

Absolute CommandOk          = 0x0aa00 ; command completed successfully
Absolute Save_Pointers      = 0x0aa01 ; SDP message received
Absolute Save_with_Disc     = 0x0aa02 ; SDP + Disconnect messages received
Absolute Device_Discon      = 0x0aa03 ; Disconnect message received
Absolute Restore_Pointers   = 0x0aa04 ; RDP message received.
Absolute ScriptsAborted     = 0x0aa05 ; scripts aborted by device driver
Absolute Tag_Received       = 0x0aa06 ; RDP message received.
Absolute SynchNegotComp     = 0x0aa0c ; synchronous negotiation completed
Absolute WideNegotComp      = 0x0aa1c ; wide negotiation completed

;
; Error codes
;

Absolute DeviceReset                    = 0x0ff07 ; had to bail out
Absolute ResetFailed                    = 0x0ff08 ; ...but couldn't.
Absolute RestSenseComplete              = 0x0ff09 ; request sense has completed
Absolute ParityMessageSent              = 0x0ff0a ; parity message has been sent
Absolute SynchNotSupported              = 0x0ff0b ; synchronous xfer is not supported
Absolute WideNotSupported               = 0x0ff1b ; wide xfer is not supported
Absolute InvalidReselector              = 0x0ff0d ; reselecting drive id invalid
Absolute MessageRejected                = 0x0ff0e ; target rejected our message
Absolute InvalidTaggedMessage   = 0x0ff0f ; target did not send a tagged message.

Absolute DeviceAborted                  = 0x0ff10 ; device accepted abort message
Absolute AbortFailed                    = 0x0ff11 ; abort message failed 

Absolute ReselByTarget  = 0x0080


;
; offsets in DSA structure follow
; THESE OFFSETS MUST BE CHANGED IF SCRIPT DATA STRUCTURE IN DEVICE EXTENSION
; CHANGES.
;

Absolute SelectDataOff  = 0
Absolute CDBDataOff     = SelectDataOff  + 4 
Absolute MsgOutOff      = CDBDataOff     + 8 
Absolute StatusDataOff  = MsgOutOff      + 8
Absolute OneByteMsgOff  = StatusDataOff  + 8
Absolute RejectMsgOff   = OneByteMsgOff  + 8
Absolute ParityMsgOff   = RejectMsgOff   + 8
Absolute AbortMsgOff    = ParityMsgOff   + 8
Absolute BDRMsgOff      = AbortMsgOff    + 8
Absolute TwoByteMsgOff  = BDRMsgOff      + 8
Absolute SGEntry18Off   = TwoByteMsgOff  + 8
Absolute SGEntry17Off   = SGEntry18Off   + 8
Absolute SGEntry16Off   = SGEntry17Off   + 8
Absolute SGEntry15Off   = SGEntry16Off   + 8
Absolute SGEntry14Off   = SGEntry15Off   + 8
Absolute SGEntry13Off   = SGEntry14Off   + 8
Absolute SGEntry12Off   = SGEntry13Off   + 8
Absolute SGEntry11Off   = SGEntry12Off   + 8
Absolute SGEntry10Off   = SGEntry11Off   + 8
Absolute SGEntry09Off   = SGEntry10Off   + 8
Absolute SGEntry08Off   = SGEntry09Off   + 8
Absolute SGEntry07Off   = SGEntry08Off   + 8
Absolute SGEntry06Off   = SGEntry07Off   + 8
Absolute SGEntry05Off   = SGEntry06Off   + 8
Absolute SGEntry04Off   = SGEntry05Off   + 8
Absolute SGEntry03Off   = SGEntry04Off   + 8
Absolute SGEntry02Off   = SGEntry03Off   + 8
Absolute SGEntry01Off   = SGEntry02Off   + 8

;
; 53C8xx register bits used by scripts
;
;
;Absolute CTEST2_sigp    = 0x40
;Absolute CTEST7_notime = 0x10
;
;
; SCSI definitions used by scripts
;

Absolute SCSIMESS_ABORT                = 0x06
Absolute SCSIMESS_ABORT_WITH_TAG       = 0x0D
Absolute SCSIMESS_BUS_DEVICE_RESET     = 0X0C
Absolute SCSIMESS_CLEAR_QUEUE          = 0X0E
Absolute SCSIMESS_DISCONNECT           = 0X04
Absolute SCSIMESS_EXTENDED_MESSAGE     = 0X01
Absolute SCSIMESS_IDENTIFY             = 0X80
Absolute SCSIMESS_IDENTIFY_WITH_DISCON = 0XC0
Absolute SCSIMESS_IGNORE_WIDE_RESIDUE  = 0X23
Absolute SCSIMESS_INITIATE_RECOVERY    = 0X0F
Absolute SCSIMESS_INIT_DETECTED_ERROR  = 0X05
Absolute SCSIMESS_LINK_CMD_COMP        = 0X0A
Absolute SCSIMESS_LINK_CMD_COMP_W_FLAG = 0X0B
Absolute SCSIMESS_MESS_PARITY_ERROR    = 0X09
Absolute SCSIMESS_MESSAGE_REJECT       = 0X07
Absolute SCSIMESS_NO_OPERATION         = 0X08
Absolute SCSIMESS_HEAD_OF_QUEUE_TAG    = 0X21
Absolute SCSIMESS_ORDERED_QUEUE_TAG    = 0X22
Absolute SCSIMESS_SIMPLE_QUEUE_TAG     = 0X20
Absolute SCSIMESS_RELEASE_RECOVERY     = 0X10
Absolute SCSIMESS_RESTORE_POINTERS     = 0X03
Absolute SCSIMESS_SAVE_DATA_POINTER    = 0X02
Absolute SCSIMESS_TERMINATE_IO_PROCESS = 0X11
Absolute SCSIMESS_COMMAND_COMPLETE     = 0X00
Absolute SCSIMESS_SYNCHRONOUS_DATA_REQ = 0X01
Absolute SCSIMESS_WIDE_DATA_REQUEST    = 0X03
Absolute SCSISTAT_CHECK_CONDITION      = 0x02

;
; Script entry point declarations follow
;

Entry EndOfScript
Entry ResetDevice
Entry AbortDevice
Entry AbortExecution
Entry ProcessSelectReselect
Entry ReselectScript
Entry SendErrorMessage
Entry RejectReceived
Entry RejectIN
Entry SendReject
Entry RejectMessage
Entry ExtMsgRcvd
Entry ProcessDisconnect
Entry RestPtrsRcvd
Entry SaveDataPointers
Entry MessageIn
Entry RestartScript
Entry SyncMsgNegot 

Entry DataOutJump
Entry DataInJump
Entry DataOut18
Entry DataOut01
Entry DataIn18
Entry DataIn01

Entry GetStatus
Entry SendCommand
Entry SendID
Entry CommandScriptStart
Entry QueueTagMessage
Entry ContNegScript

CommandScriptStart:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; This is the entry point for initiating SCSI I/O
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

	select  ATN from SelectDataOff, rel( ReselectScript )   ; Select device
	move GPREG & 0xFE to GPREG                                                              ; turn LED on
	jump    rel ( GetStatus ), when STATUS                                  ; If status exit
	jump    rel ( ResetSelectedDev ), if not MSG_OUT                             ; Bad phase check

SendID:
	move    from MsgOutOff, when MSG_OUT            ; Send ID message
	jump    rel ( SendCommand ) when CMD            ; Expected next phase
	jump    rel ( GetStatus ) if STATUS                     ; Handle status phase
	jump    rel ( MessageIn ) if MSG_IN                     ; Handle message phase
	jump    rel ( ResetSelectedDev )                          ; Error - reset device

SendCommand:
	move    from CDBDataOff, when CMD                       ; Move the CDB
;; new entry to take care of a posible SCSI parity error
	move    SOCL & 0xFD to SOCL

	jump    rel ( ResetSelectedDev ) when CMD               ; Error - reset device
	
	jump    rel ( GetStatus ) if STATUS                     ; Handle status phase
	jump    rel ( MessageIn ) if MSG_IN                     ; Handle message phase


ProcessDataPhase:

;       Jump to the data in handling when in data-in phase.  This jump
;       may be patched by the miniport.

DataInJump:

	jump    rel ( DataIn18 ) if DATA_IN                     ; Handle data in 

;       Jump to the data in handling when in data-in phase.  This jump
;       may be patched by the miniport.

DataOutJump:
	jump    rel ( DataOut18 ) if DATA_OUT           ; Handle data out

	jump    rel ( ResetSelectedDev )                                     ; Bad phase encountered

GetStatus:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; This script routine handles status phase
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	move    from StatusDataOff, when STATUS         ; Get status 

;
; MESSAGE IN phase should follow STATUS phase.
;

	jump    rel ( MessageIn ) when MSG_IN           ; Handle message in phase
	jump    rel ( ResetSelectedDev )                ; Error - reset device

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; This the data out section of scripts.
; Up to 18 gather moves can be processed at once.
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

DataOut18:
	 chmov     from SGEntry18Off, when DATA_OUT
	 chmov     from SGEntry17Off, when DATA_OUT
	 chmov     from SGEntry16Off, when DATA_OUT
	 chmov     from SGEntry15Off, when DATA_OUT
	 chmov     from SGEntry14Off, when DATA_OUT
	 chmov     from SGEntry13Off, when DATA_OUT
	 chmov     from SGEntry12Off, when DATA_OUT
	 chmov     from SGEntry11Off, when DATA_OUT
	 chmov     from SGEntry10Off, when DATA_OUT
	 chmov     from SGEntry09Off, when DATA_OUT
	 chmov     from SGEntry08Off, when DATA_OUT
	 chmov     from SGEntry07Off, when DATA_OUT
	 chmov     from SGEntry06Off, when DATA_OUT
	 chmov     from SGEntry05Off, when DATA_OUT
	 chmov     from SGEntry04Off, when DATA_OUT
	 chmov     from SGEntry03Off, when DATA_OUT
	 chmov     from SGEntry02Off, when DATA_OUT
		
DataOut01:
	 chmov     from SGEntry01Off, when DATA_OUT
		  
	 jump     rel ( GetStatus) when STATUS          ; Handle status
	 jump     rel ( MessageIn) if MSG_IN            ; Handle messages
	 jump     rel ( ResetSelectedDev)               ; Error - reset device


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; This the data in section of scripts.
; Up to 18 scatter moves can be processed at once.
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


DataIn18:
	 chmov     from SGEntry18Off, when DATA_IN
	 chmov     from SGEntry17Off, when DATA_IN
	 chmov     from SGEntry16Off, when DATA_IN
	 chmov     from SGEntry15Off, when DATA_IN
	 chmov     from SGEntry14Off, when DATA_IN
	 chmov     from SGEntry13Off, when DATA_IN
	 chmov     from SGEntry12Off, when DATA_IN
	 chmov     from SGEntry11Off, when DATA_IN
	 chmov     from SGEntry10Off, when DATA_IN
	 chmov     from SGEntry09Off, when DATA_IN
	 chmov     from SGEntry08Off, when DATA_IN
	 chmov     from SGEntry07Off, when DATA_IN
	 chmov     from SGEntry06Off, when DATA_IN
	 chmov     from SGEntry05Off, when DATA_IN
	 chmov     from SGEntry04Off, when DATA_IN
	 chmov     from SGEntry03Off, when DATA_IN
	 chmov     from SGEntry02Off, when DATA_IN
		
DataIn01:
	 chmov     from SGEntry01Off, when DATA_IN
		  
	 jump     rel ( GetStatus) when STATUS          ; Handle status
	 jump     rel ( MessageIn) if MSG_IN            ; Handle messages
	 jump     rel ( ResetSelectedDev)               ; Error - reset device


ContNegScript:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; ContNegScript
;
; Entry point for continuing negotiations for sync after wide negotiations
;  have occurred.
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

	set     ATN											; bring target back to
														;   msg in phase
	clear   ACK         								; still need to ack
														;   last wide neg. byte
	jump    rel ( ResetSelectedDev ), when not MSG_OUT  ; Bad phase check
	move    from MsgOutOff, when MSG_OUT                ; Send synch messages
	jump	rel ( RestartPlus ), when MSG_IN
	jump	rel ( ResetSelectedDev )


RestartScript:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; RestartScript
;
; Entry point for restarting script after reselect, etc.
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; new command to take care of possibel parity error
	move SOCL & 0xFD to SOCL
	clear ACK and ATN                                                       ; Clear pending conditions

RestartPlus:
;
; note that the call to message in will return only if the message is IDENTIFY
;
	
	jump    rel ( SendCommand ) when CMD                    ; Process phase
	call    rel ( MessageIn ) if MSG_IN                             ; Handle messages
	jump    rel ( GetStatus ) if STATUS                             ; Handle status
	jump    rel ( ProcessDataPhase )  if DATA_IN    ; 
	jump    rel ( ProcessDataPhase ) if DATA_OUT    ;
	jump    rel ( SendErrorMessage ) if MSG_OUT             ;
	jump    rel ( ResetSelectedDev )                                             ; Error - reset device


MessageIn:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; This script routine processes message from target
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	move    from OneByteMsgOff, when MSG_IN

;       steved - 
;               do we need to move identify further up?

;
;       Handle command complete message
;

	jump    rel ( ProcessCommandComplete ) if SCSIMESS_COMMAND_COMPLETE

;
;       Handle disconnect
;

	jump    rel ( ProcessDisconnect ) if SCSIMESS_DISCONNECT

;
;       Handle Save Data Pointers
;

	jump    rel ( SaveDataPointers ) if SCSIMESS_SAVE_DATA_POINTER

;
;       Handle Restore Pointers
;

	jump    rel ( RestPtrsRcvd ) if SCSIMESS_RESTORE_POINTERS

;
;       Handle extended message
;

	jump    rel ( ExtMsgRcvd ) if SCSIMESS_EXTENDED_MESSAGE

;
;       Handle Message Reject
;

	jump    rel ( RejectReceived ) if SCSIMESS_MESSAGE_REJECT

;
;       If not Identify, reject the message
;

	jump    rel ( RejectMessage ) if not SCSIMESS_IDENTIFY and mask 0x0F

;
;       Process Identify message.  Note that we throw away the Identify message
;       at this point because it has already been processed by the driver.
;

	clear   ACK                                                                             ; Throw message away
	jump    rel ( MessageIn ) when MSG_IN                   ; Handle more messages

;
; Note that this routine is CALLed only by the reselection script routine.
; We should only receive an identify message immediately after a 
; reselection. Therefore, the RETURN below will be executed only when this 
; routine is called by the reselection code.
;
	return                                                                                  ; Return to caller

SaveDataPointers:
	clear   ACK                                                                             ; Acknowledge SDP

;
; Normally, disconnect message will follow SDP. We save ourselves an interrupt
; by assuming this is the case.
;

	int             Save_Pointers when not MSG_IN                   ; Another message?
	move    from OneByteMsgOff, when MSG_IN                 ; If so move it

;
; bugbug-
; although it is very improbable that a device would send a message other
; than DISCONNECT after an SDP, we need to handle this case more gracefully.
;
	jump    rel ( ResetSelectedDev ) if not SCSIMESS_DISCONNECT  
												; If not disconnect,
												;  error - reset device

	move    SCNTL2 & 0x7F to SCNTL2             ; Disable unexpected disconnect
	move    GPREG | 0x01 to GPREG                           ; LED off                                                                     ; Clear disconnect message
	clear   ACK
	wait    DISCONNECT                                                      ;
	int             Save_with_Disc                                          ; Indicate SDP and
												;  disconnect

RestPtrsRcvd:
	clear   ACK                                                                     ; Accept message
	int             Restore_Pointers                                        ; Indicate restore pointers
	

ProcessDisconnect:

	move    SCNTL2 & 0x7F to SCNTL2                         ; Disable unexpected disconnect
	move    GPREG | 0x01 to GPREG                           ; LED off                                                                     ; Clear disconnect message
	clear   ACK                                                                     ; Clear disconnect message
	wait    DISCONNECT                                                      ; Wait for disconnect to happen
	int             Device_Discon                                           ; Indicate device disconnected


ProcessCommandComplete:

	move    SCNTL2 & 0x7F to SCNTL2                         ; Disable unexpected disconnect
	move    GPREG | 0x01 to GPREG                           ; LED off                                                                     ; Clear disconnect message
	clear   ACK                                                                     ; Acknowledge message
	wait    DISCONNECT                                                      ; Wait for disconnect to happen
	int             CommandOk                                                       ; Indicate command complete

ExtMsgRcvd:
	clear   ACK                                                                             ; Accept first byte of message
	jump    rel ( ResetSelectedDev ) when not MSG_IN     ; If not MSG-IN, error - reset device 
	move    from OneByteMsgOff, when MSG_IN         ; Get next message byte

	jump    rel ( SyncMsgNegot ) if 3               ; If not two byte message,
	jump    rel ( RejectMessage ) if not 2

	clear   ACK                                                                     ; Accept first byte of wide message
	move    from OneByteMsgOff, when MSG_IN         ; Get next byte of message
	
	jump    rel ( RejectMessage ) if not SCSIMESS_WIDE_DATA_REQUEST
	
	
	clear   ACK                                                                     ; Accept SDTR byte
;
; the following code processes the SDTR extended message
;
	move    from OneByteMsgOff, when MSG_IN          ; Get wide parameters
	
	int     WideNegotComp                           ; Indicate wide supported


SyncMsgNegot:
;
; NOTE: the following extended message lengths are currently supported:
;
;       3 byte messages
;
	clear   ACK                                                                     ; Accept first byte of sync message
	move    from OneByteMsgOff, when MSG_IN         ; Get next byte of message
	jump    rel ( RejectMessage ) if not SCSIMESS_SYNCHRONOUS_DATA_REQ
	 
	clear   ACK                                                                     ; Accept SDTR byte
;
; the following code processes the SDTR extended message
;

	move    from TwoByteMsgOff, when MSG_IN         ; Get sync parameters
	int     SynchNegotComp                                          ; Indicate synchronous supported


RejectMessage:
	set             ATN
	clear   ACK						; Clear the message
	jump    rel ( RejectIN ) when MSG_IN            ; If still MSG IN, jump to
												;  clear extended message
SendReject:
	jump    ResetSelectedDev, if not MSG_OUT        ; If not MSG OUT, error - reset device
	move    from RejectMsgOff, when MSG_OUT         ; Send REJECT message
	jump    rel ( ResetSelectedDev) when MSG_OUT    ; If not accepted, error - reset device
	jump    rel ( RestartScript )                           ; Reject successful - restart
												;  the state machine

RejectIN:
	move    from OneByteMsgOff, when MSG_IN         ; Get message
	clear   ACK                                                                     ; Acknowledge it
	jump    rel ( RejectIN ) when MSG_IN            ; If more message bytes, process them
	jump    rel ( SendReject )                                      ; Send REJECT message

RejectReceived:
	;clear   ACK                                                             ; Clear the message
	int             MessageRejected                                 ; Indicate message rejected

SendErrorMessage:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Send either INITIATOR DETECTED ERROR or MESSAGE PARITY ERROR message
; (set by driver before calling) to target.
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	set             ATN                                                             ; Ask for message out
	clear   ACK                                                             ; Clear any pending msgs

;
; If the device does not go immediately to message out, we don't try to
; coax it. 
;
	jump    rel ( ResetSelectedDev ) when not MSG_OUT    ; Error - reset device
 
DoParityMove:
	move    from ParityMsgOff, when MSG_OUT         ; Move the error message
	int             ParityMessageSent                                       ; Indicate message sent

ReselectScript:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;  Wait for a Reselection/selection
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	wait    reselect rel ( AbortExecution )
	move    GPREG & 0xFE to GPREG                                           ;LED on

ProcessSelectReselect:

	jump    rel( ProcessSelectReselect ) if not MSG_IN

	move    from OneByteMsgOff, when MSG_IN

ReselectInterrupt:

	int             ReselByTarget

AbortExecution:

	move    CTEST2 to SFBR                  ; Signal that we are stalled
	int             ScriptsAborted


ResetDevice:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; ResetDevice:
;
;  Select device, reset device and exit. 
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;       First have to select the device.

	select  ATN from SelectDataOff, rel( ReselectScript )   ; Select device
	move    GPREG & 0xFE to GPREG                                                   ; LED on
	jump    rel ( ResetSendMsg )

ResetSelectedDev:

	set             ATN                                             ; Set ATN before releasing any messages
	clear   ACK                                             ; Release messages

;
; if the wayward device does not immediately go into message phase, we
; will bail out.  No attempt is made to coax the drive by transferring
; any additional data or message bytes.
;

ResetSendMsg:
	int             ResetFailed when not MSG_OUT    ; Interrupt the reset failed

DoBDRMove:
	move    SCNTL2 & 0x7F to SCNTL2                 ; Disable unexpected disconnect
	move    from BDRMsgOff, when MSG_OUT    ; Send BDR message

	move    GPREG | 0x01 to GPREG                   ; LED off
	wait    DISCONNECT                                              ; Wait for device to disconnect
	int             DeviceReset                                             ; Indicate device reset

AbortDevice:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; AbortDevice:
;
;  Abort all I/Os for the device and exit. 
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;       First have to select the device.

	select  ATN from SelectDataOff, rel( ReselectScript )   ; Select device
	move    GPREG & 0xFE to GPREG                                                   ; LED on

;
; if the wayward device does not immediately go into message phase, we
; will bail out.  No attempt is made to coax the drive by transferring
; any additional data or message bytes.
;

	int             AbortFailed when not MSG_OUT    ; Interrupt the abort failed


DoAbortMove:
	move    SCNTL2 & 0x7F to SCNTL2                 ; Disable unexpected disconnect
	move    from AbortMsgOff, when MSG_OUT  ; Send abort message

	move    GPREG | 0x01 to GPREG                   ; LED off
	wait    DISCONNECT                                              ; Wait for device to disconnect
	int             DeviceAborted                                   ; Indicate device aborted


QueueTagMessage:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; QueueTagMessage -
;
; This routine processes a queue tagged message.
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

	clear   ACK                                                                     ; Acknowledge identify message
	move    from OneByteMsgOff, when MSG_IN         ; Get the first message byte

	int             InvalidTaggedMessage, if not SCSIMESS_SIMPLE_QUEUE_TAG
												; If not simple queue tag message,
						;  indicate this to driver

	clear   ACK                                                                     ; Acknowledge queue tag message
	move    from OneByteMsgOff, when MSG_IN         ; Get the queue tag message
	int             Tag_Received                                            ; Indicate queue tag received


EndOfScript: