1 ; $NetBSD: siop.ss,v 1.20 2005/11/18 23:10:32 bouyer Exp $
4 ; Copyright (c) 2000 Manuel Bouyer.
6 ; Redistribution and use in source and binary forms, with or without
7 ; modification, are permitted provided that the following conditions
9 ; 1. Redistributions of source code must retain the above copyright
10 ; notice, this list of conditions and the following disclaimer.
11 ; 2. Redistributions in binary form must reproduce the above copyright
12 ; notice, this list of conditions and the following disclaimer in the
13 ; documentation and/or other materials provided with the distribution.
15 ; THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 ; IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 ; OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 ; IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 ; INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 ; NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 ; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 ; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 ; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 ; THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 ; offsets in siop_common_xfer
30 ABSOLUTE t_msg_in = 48;
31 ABSOLUTE t_ext_msg_in = 56;
32 ABSOLUTE t_ext_msg_data = 64;
33 ABSOLUTE t_msg_out = 72;
35 ABSOLUTE t_status = 88;
39 ; interrupts that need a valid DSA
40 ABSOLUTE int_done = 0xff00;
41 ABSOLUTE int_msgin = 0xff01;
42 ABSOLUTE int_extmsgin = 0xff02;
43 ABSOLUTE int_extmsgdata = 0xff03;
44 ABSOLUTE int_disc = 0xff04;
45 ABSOLUTE int_saveoffset = 0xff05;
46 ; interrupts that don't have a valid DSA
47 ABSOLUTE int_reseltarg = 0xff80;
48 ABSOLUTE int_resellun = 0xff81;
49 ABSOLUTE int_reseltag = 0xff82;
50 ABSOLUTE int_resfail = 0xff83;
51 ABSOLUTE int_err = 0xffff;
54 ABSOLUTE flag_sdp = 0x01 ; got save data pointer
55 ABSOLUTE flag_data = 0x02 ; we're in data phase
56 ABSOLUTE flag_data_mask = 0xfd ; ~flag_data
75 ENTRY script_sched_slot0;
83 EXTERN abs_script_sched_slot0;
88 ENTRY lun_switch_entry;
91 EXTERN abs_lunsw_return;
94 ENTRY tag_switch_entry;
98 ; command reselect script symbols
103 ENTRY ldsa_reload_dsa;
107 EXTERN ldsa_abs_reselected;
108 EXTERN ldsa_abs_reselect;
109 EXTERN ldsa_abs_selected;
110 EXTERN ldsa_abs_data;
111 EXTERN ldsa_abs_slot;
118 ; starting a new session, init 'local variables'
119 MOVE 0 to SCRATCHA0 ; flags
120 MOVE 0 to SCRATCHA1 ; DSA offset (for S/G save data pointer)
121 MOVE SCRATCHA3 to SFBR ; pending message ?
122 JUMP REL(handle_msgin), IF not 0x20;
124 JUMP REL(msgout), WHEN MSG_OUT;
125 JUMP REL(msgin), WHEN MSG_IN;
126 JUMP REL(dataout), WHEN DATA_OUT;
127 JUMP REL(datain), WHEN DATA_IN;
128 JUMP REL(cmdout), WHEN CMD;
129 JUMP REL(status), WHEN STATUS;
133 ; check that host asserted SIGP, this'll clear SIGP in ISTAT
134 MOVE CTEST2 & 0x40 TO SFBR;
135 INT int_resfail, IF 0x00;
136 ; a NOP by default; patched with MOVE GPREG & 0xfe to GPREG on compile-time
137 ; option "SIOP_SYMLED"
141 ; Clear DSA and init status
146 MOVE 0 to SCRATCHA0 ; flags
147 MOVE 0 to SCRATCHA1 ; DSA offset (for S/G save data pointer)
148 ; the script scheduler: siop_start() we set the absolute jump addr, and then
149 ; changes the FALSE to TRUE. The select script will change it back to false
150 ; once the target is selected.
151 ; The RAM could hold 370 slot entry, we limit it to 40. Should be more than
154 JUMP abs_script_sched_slot0, IF FALSE;
155 JUMP abs_script_sched_slot0, IF FALSE;
156 JUMP abs_script_sched_slot0, IF FALSE;
157 JUMP abs_script_sched_slot0, IF FALSE;
158 JUMP abs_script_sched_slot0, IF FALSE;
159 JUMP abs_script_sched_slot0, IF FALSE;
160 JUMP abs_script_sched_slot0, IF FALSE;
161 JUMP abs_script_sched_slot0, IF FALSE;
162 JUMP abs_script_sched_slot0, IF FALSE;
163 JUMP abs_script_sched_slot0, IF FALSE;
164 JUMP abs_script_sched_slot0, IF FALSE;
165 JUMP abs_script_sched_slot0, IF FALSE;
166 JUMP abs_script_sched_slot0, IF FALSE;
167 JUMP abs_script_sched_slot0, IF FALSE;
168 JUMP abs_script_sched_slot0, IF FALSE;
169 JUMP abs_script_sched_slot0, IF FALSE;
170 JUMP abs_script_sched_slot0, IF FALSE;
171 JUMP abs_script_sched_slot0, IF FALSE;
172 JUMP abs_script_sched_slot0, IF FALSE;
173 JUMP abs_script_sched_slot0, IF FALSE;
174 JUMP abs_script_sched_slot0, IF FALSE;
175 JUMP abs_script_sched_slot0, IF FALSE;
176 JUMP abs_script_sched_slot0, IF FALSE;
177 JUMP abs_script_sched_slot0, IF FALSE;
178 JUMP abs_script_sched_slot0, IF FALSE;
179 JUMP abs_script_sched_slot0, IF FALSE;
180 JUMP abs_script_sched_slot0, IF FALSE;
181 JUMP abs_script_sched_slot0, IF FALSE;
182 JUMP abs_script_sched_slot0, IF FALSE;
183 JUMP abs_script_sched_slot0, IF FALSE;
184 JUMP abs_script_sched_slot0, IF FALSE;
185 JUMP abs_script_sched_slot0, IF FALSE;
186 JUMP abs_script_sched_slot0, IF FALSE;
187 JUMP abs_script_sched_slot0, IF FALSE;
188 JUMP abs_script_sched_slot0, IF FALSE;
189 JUMP abs_script_sched_slot0, IF FALSE;
190 JUMP abs_script_sched_slot0, IF FALSE;
191 JUMP abs_script_sched_slot0, IF FALSE;
192 JUMP abs_script_sched_slot0, IF FALSE;
193 JUMP abs_script_sched_slot0, IF FALSE;
194 ; Nothing to do, wait for reselect
196 ; Clear DSA and init status
201 MOVE 0x00 to SCRATCHA2; no tag
202 MOVE 0x20 to SCRATCHA3; simple tag msg, ignored by reselected:
203 ; a NOP by default; patched with MOVE GPREG | 0x01 to GPREG on compile-time
204 ; option "SIOP_SYMLED"
207 WAIT RESELECT REL(reselect_fail)
208 ; a NOP by default; patched with MOVE GPREG & 0xfe to GPREG on compile-time
209 ; option "SIOP_SYMLED"
212 MOVE SSID & 0x8f to SFBR
213 MOVE SFBR to SCRATCHA0 ; save reselect ID
214 ; find the right param for this target
216 JUMP abs_targ0, IF 0xff;
217 JUMP abs_targ0, IF 0xff;
218 JUMP abs_targ0, IF 0xff;
219 JUMP abs_targ0, IF 0xff;
220 JUMP abs_targ0, IF 0xff;
221 JUMP abs_targ0, IF 0xff;
222 JUMP abs_targ0, IF 0xff;
223 JUMP abs_targ0, IF 0xff;
224 JUMP abs_targ0, IF 0xff;
225 JUMP abs_targ0, IF 0xff;
226 JUMP abs_targ0, IF 0xff;
227 JUMP abs_targ0, IF 0xff;
228 JUMP abs_targ0, IF 0xff;
229 JUMP abs_targ0, IF 0xff;
230 JUMP abs_targ0, IF 0xff;
233 MOVE 1, abs_msgin, WHEN MSG_IN;
234 MOVE SFBR & 0x07 to SCRATCHA1; save LUN
236 RETURN, WHEN NOT MSG_IN; If no more message, jump to lun sw
237 MOVE 1, abs_msgin, WHEN MSG_IN;
239 MOVE SFBR to SCRATCHA3; save message
240 RETURN, IF NOT 0x20; jump to lun sw if not simple tag msg
241 MOVE 1, abs_msgin, WHEN MSG_IN; get tag
243 MOVE SFBR to SCRATCHA2; save tag
244 RETURN; jump to lun sw
248 MOVE SCRATCHA0 | flag_sdp TO SCRATCHA0;
249 ; should get a disconnect message now
252 MOVE FROM t_msg_in, WHEN MSG_IN;
254 JUMP REL(handle_cmpl), IF 0x00 ; command complete message
255 JUMP REL(handle_sdp), IF 0x02 ; save data pointer message
256 JUMP REL(handle_extin), IF 0x01 ; extended message
257 INT int_msgin, IF not 0x04;
258 CALL REL(disconnect) ; disconnect message;
259 ; if we didn't get sdp, no need to interrupt
260 MOVE SCRATCHA0 & flag_sdp TO SFBR;
261 INT int_disc, IF not 0x00;
262 ; update offset if we did some data transfer
263 MOVE SCRATCHA1 TO SFBR;
264 JUMP REL(script_sched), if 0x00;
272 ; entry point for msgout after a msgin or status phase
277 MOVE FROM t_msg_out, WHEN MSG_OUT;
281 MOVE FROM t_cmd, WHEN CMD;
284 MOVE FROM t_status, WHEN STATUS;
288 MOVE SCRATCHA0 | flag_data TO SCRATCHA0;
290 MOVE FROM t_data, WHEN DATA_IN;
291 MOVE SCRATCHA1 + 1 TO SCRATCHA1 ; adjust offset
292 MOVE DSA0 + 8 to DSA0;
293 MOVE DSA1 + 0 to DSA1 WITH CARRY;
294 MOVE DSA2 + 0 to DSA2 WITH CARRY;
295 MOVE DSA3 + 0 to DSA3 WITH CARRY;
296 JUMP REL(datain_loop), WHEN DATA_IN;
297 CALL REL(restoredsa);
298 MOVE SCRATCHA0 & flag_data_mask TO SCRATCHA0;
303 MOVE SCRATCHA0 | flag_data TO SCRATCHA0;
305 MOVE FROM t_data, WHEN DATA_OUT;
306 MOVE SCRATCHA1 + 1 TO SCRATCHA1 ; adjust offset
307 MOVE DSA0 + 8 to DSA0;
308 MOVE DSA1 + 0 to DSA1 WITH CARRY;
309 MOVE DSA2 + 0 to DSA2 WITH CARRY;
310 MOVE DSA3 + 0 to DSA3 WITH CARRY;
311 JUMP REL(dataout_loop), WHEN DATA_OUT;
312 CALL REL(restoredsa);
313 MOVE SCRATCHA0 & flag_data_mask TO SCRATCHA0;
318 MOVE SFBR to SCRATCHB0;
320 MOVE SFBR to SCRATCHB1;
322 MOVE SFBR to SCRATCHB2;
324 MOVE SFBR to SCRATCHB3;
328 MOVE SCRATCHB0 TO SFBR;
330 MOVE SCRATCHB1 TO SFBR;
332 MOVE SCRATCHB2 TO SFBR;
334 MOVE SCRATCHB3 TO SFBR;
339 MOVE SCNTL2 & 0x7f TO SCNTL2;
346 CALL REL(disconnect);
351 MOVE FROM t_ext_msg_in, WHEN MSG_IN;
352 INT int_extmsgin; /* let host fill in t_ext_msg_data */
355 MOVE FROM t_ext_msg_data, WHEN MSG_IN;
358 NOP; space to store msgin when reselect
361 ;; per-target switch script for LUNs
362 ; hack: we first do a call to the target-specific code, so that a return
363 ; in the main switch will jump to the lun switch.
368 JUMP abs_lunsw_return;
370 CALL REL(restore_scntl3);
371 MOVE SCRATCHA1 TO SFBR;
375 ;; Per-device switch script for tag
378 MOVE SCRATCHA2 TO SFBR; restore tag
380 JUMP abs_tag0, IF 0x00;
381 JUMP abs_tag0, IF 0x01;
382 JUMP abs_tag0, IF 0x02;
383 JUMP abs_tag0, IF 0x03;
384 JUMP abs_tag0, IF 0x04;
385 JUMP abs_tag0, IF 0x05;
386 JUMP abs_tag0, IF 0x06;
387 JUMP abs_tag0, IF 0x07;
388 JUMP abs_tag0, IF 0x08;
389 JUMP abs_tag0, IF 0x09;
390 JUMP abs_tag0, IF 0x0a;
391 JUMP abs_tag0, IF 0x0b;
392 JUMP abs_tag0, IF 0x0c;
393 JUMP abs_tag0, IF 0x0d;
394 JUMP abs_tag0, IF 0x0e;
395 JUMP abs_tag0, IF 0x0f;
398 ;; per-command script: select, and called after a reselect to load DSA
401 ; Can't use MOVE MEMORY to load DSA, doesn't work I/O mapped
413 JUMP ldsa_abs_reselected;
416 SELECT ATN FROM t_id, ldsa_abs_reselect;
417 MOVE MEMORY 4, ldsa_abs_data, ldsa_abs_slot;
418 JUMP ldsa_abs_selected;
420 NOP; contains data used by the MOVE MEMORY
423 MOVE GPREG & 0xfe TO GPREG;
426 MOVE GPREG | 0x01 TO GPREG;