From appli.appli.se!appli.se!owner-amiga-mach@appli.se Sat Oct 17 13:47:21 1992
Received: by bruce (5.57/1.34)
	id AA26181; Sat, 17 Oct 92 13:47:01 +1000
Received: by mail.swip.net (5.65c8/1.2)
	id AA13382; Sat, 17 Oct 1992 04:45:55 +0100
Received: by appli.appli.se (/\=-/\ Smail3.1.17.5 #17.26)
	id <m0mg54s-0000t1C@appli.appli.se>; Sat, 17 Oct 92 05:43 MDT
Received: by appli.appli.se (/\=-/\ Smail3.1.17.5 #17.26)
	id <m0mg54q-0000siC@appli.appli.se>; Sat, 17 Oct 92 05:43 MDT
Return-Path: <msu.oscs.montana.edu!osymh>
Received: by appli.appli.se (/\=-/\ Smail3.1.17.5 #17.26)
	id <m0mg54h-0000t0C@appli.appli.se>; Sat, 17 Oct 92 05:43 MDT
Received: from maia.oscs.montana.edu by mail.swip.net (5.65c8/1.2)
	id AA12254; Sat, 17 Oct 1992 02:52:51 +0100
Received: by trex.oscs.montana.edu (MX V3.1C) id 8294; Fri, 16 Oct 1992
          19:52:28 MDT
Sender: osymh@trex.oscs.montana.edu
Date: Fri, 16 Oct 1992 19:52:24 MDT
From: "Michael L. Hitch" <osymh@trex.oscs.montana.edu>
Reply-To: osymh@trex.oscs.montana.edu
To: amiga-mach@appli.se
Message-Id: <00962314.F679E4A0.8294@trex.oscs.montana.edu>
Subject: Changes to kern/bootstrap.c to read scsi devices
Sender: owner-amiga-mach@appli.se
Status: OR

Here are my changes to bootstrap_create to add a command to read from a scsi
device to test it.  It looks for "read" in addition to "boot" and takes an
optional 'v' flag (which displays some information about the read data) and
an optional SCSI unit number.  The read_test procedure does direct calls to
rz_open, rz_close, and rz_read.  I'm not certain I'm doing everything
correctly, but it does cause read commands to be sent to the driver and the
data read back looks good.  I have a slight problem when attempting to read
from my Wangtek tape drive when there's no tape present.  After the read
attempts complete, something has modified the JMP instruction at $0002.  Also,
the sense data returned on the error doesn't print right.  It looks like the
request sense structure isn't being generated by gcc properly:  the sense key
should be in the third byte, but the assembly code generated by gcc gets it
out of the fourth byte.  It looks like gcc is aligning the union in the
structure on a word boundary.

I also check for a "break" string so I can drop into SIM when I get to the
prompt.

---------- cut here ----------------------------------------------------------
*** kern/bootstrap.c.orig	Mon Sep 14 15:35:11 1992
--- kern/bootstrap.c	Fri Oct 16 19:36:20 1992
***************
*** 323,328 ****
--- 323,334 ----
                    printf("You typed: %s\n",blah);
                    if(!strcmp(blah,"boot"))
                      asm("jmp 2");
+                   if(!strcmp(blah,"break"))
+                     gimmeabreak();
+                   if (!strncmp(blah,"read",4) && (blah[4] == 0 || blah[4] == ' '))
+                     read_test(blah+4);
+                   if(!strcmp(blah,"exit"))
+                     break;
                  }
  
  #if defined(iPSC386)|| defined(iPSC860)
***************
*** 361,366 ****
--- 367,442 ----
  	 */
  	thread_start(bootstrap_thread, user_bootstrap);
  	(void) thread_resume(bootstrap_thread);
+ }
+ 
+ /*
+  * Read some records from the specified SCSI unit
+  * Default read from unit 0
+  * Optional 'v' do display some data each record
+  */
+ 
+ #include <device/io_req.h>
+ 
+ read_test(arg)
+ char	*arg;
+ {
+ 	int i;
+ 	int dev = 0;
+ 	int verbose = 0;
+ 	int status;
+ 	io_req_t ior;
+ 	unsigned char *buf;
+ 	int read_test_done ();
+ 
+ 	if (*arg++ == ' ') {
+ 		if (*arg == 'v') {
+ 			verbose = 1;			/* Want verbose mode */
+ 			++arg;
+ 		}
+ 		if (*arg>='0' && *arg<='7')
+ 			dev = (*arg - '0') << 3;	/* get device number */
+ 	}
+ 	io_req_alloc(ior, 0);
+ 	ior->io_unit = dev;
+ 	i = rz_open (dev, 0, ior);
+ 	if (i != 0) {
+ 		printf ("rz_open status: %d\n", i);
+ 		io_req_free(ior);
+ 		return;
+ 	}
+ 	printf ("Beginning read test on %d\n", dev);
+ 	for (i = 0; i < (verbose ? 10 : 200); ++i) {
+ 		ior->io_unit = dev;
+ 		ior->io_recnum = i;
+ 		ior->io_count = 512;
+ 		ior->io_error = 0;
+ 		ior->io_next = 0;
+ 		ior->io_op = IO_READ;
+ 		ior->io_done = read_test_done;
+ 		status = rz_read (dev, ior);
+ 		if (status == -1) iowait (ior);
+ 		buf = ior->io_data;
+ 		if (verbose && ior->io_error) {
+ 			printf ("io_error = %d, io_residual=%d buf=%08X", ior->io_error,
+ 			 ior->io_residual, ior->io_data);
+ 			printf (" %02x %02x %02x %02x %02x %02x %02x %02x\n", buf[0],
+ 			 buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7]);
+ 		}
+ 		if (ior->io_alloc_size) {
+ 			vm_deallocate(kernel_map, buf, ior->io_alloc_size);
+ 			ior->io_alloc_size = 0;
+ 		}
+ 	}
+ 	printf ("End of read test on %d\n", dev);
+ 	rz_close (dev);
+ 	io_req_free(ior);
+ }
+ 
+ read_test_done (ior)
+ io_req_t ior;
+ {
+ 	printf ("read_test_done: buf=%08x\n", ior->io_data);
+ 	return (TRUE);
  }
  
  /*
---------- cut here ----------------------------------------------------------
---
Michael L. Hitch                        osymh@msu.oscs.montana.edu 
Computer Consultant                     OSYMH@MTSUNIX1.BITNET
Office of Systems and Computing Services
Montana State University
Bozeman, MT     USA

