xref: /netbsd-src/sys/arch/sgimips/stand/common/iris_parse.c (revision d02e022db788ed4933c5904d9d6ce3af08f11fee)
1*d02e022dStsutsui /*	$NetBSD: iris_parse.c,v 1.1 2019/01/12 16:44:47 tsutsui Exp $	*/
2*d02e022dStsutsui 
3*d02e022dStsutsui /*
4*d02e022dStsutsui  * Copyright (c) 2018 Naruaki Etomi
5*d02e022dStsutsui  * All rights reserved.
6*d02e022dStsutsui  *
7*d02e022dStsutsui  * Redistribution and use in source and binary forms, with or without
8*d02e022dStsutsui  * modification, are permitted provided that the following conditions
9*d02e022dStsutsui  * are met:
10*d02e022dStsutsui  * 1. Redistributions of source code must retain the above copyright
11*d02e022dStsutsui  *    notice, this list of conditions and the following disclaimer.
12*d02e022dStsutsui  * 2. Redistributions in binary form must reproduce the above copyright
13*d02e022dStsutsui  *    notice, this list of conditions and the following disclaimer in the
14*d02e022dStsutsui  *    documentation and/or other materials provided with the distribution.
15*d02e022dStsutsui  *
16*d02e022dStsutsui  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17*d02e022dStsutsui  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18*d02e022dStsutsui  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19*d02e022dStsutsui  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20*d02e022dStsutsui  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21*d02e022dStsutsui  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22*d02e022dStsutsui  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23*d02e022dStsutsui  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24*d02e022dStsutsui  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25*d02e022dStsutsui  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*d02e022dStsutsui  */
27*d02e022dStsutsui 
28*d02e022dStsutsui /*
29*d02e022dStsutsui  * Silicon Graphics "IRIS" series MIPS processors machine bootloader.
30*d02e022dStsutsui  * Parse argv argument vector.
31*d02e022dStsutsui  */
32*d02e022dStsutsui 
33*d02e022dStsutsui #include <lib/libsa/stand.h>
34*d02e022dStsutsui #include <lib/libkern/libkern.h>
35*d02e022dStsutsui 
36*d02e022dStsutsui #include "iris_machdep.h"
37*d02e022dStsutsui #include "iris_scsivar.h"
38*d02e022dStsutsui 
39*d02e022dStsutsui uint8_t scsi_ctlr = 255, scsi_id = 255, scsi_part = 255;
40*d02e022dStsutsui 
41*d02e022dStsutsui void
parse(char * argv[],char * kernelname)42*d02e022dStsutsui parse(char *argv[], char *kernelname)
43*d02e022dStsutsui {
44*d02e022dStsutsui 	char disksetting[1 + 32];
45*d02e022dStsutsui 	char bootpath[1 + 64];
46*d02e022dStsutsui 	int i;
47*d02e022dStsutsui 
48*d02e022dStsutsui 	char *ep = strcpy(bootpath, argv[1]);
49*d02e022dStsutsui 	ep = strrchr(bootpath, '/');
50*d02e022dStsutsui 	if (ep == NULL)
51*d02e022dStsutsui 		again();
52*d02e022dStsutsui 
53*d02e022dStsutsui 	strcpy(kernelname, ep + 1);
54*d02e022dStsutsui 
55*d02e022dStsutsui 	i =  ep - bootpath;
56*d02e022dStsutsui 	bootpath[i - 1] = '\0';
57*d02e022dStsutsui 
58*d02e022dStsutsui 	ep = strchr(bootpath, '(');
59*d02e022dStsutsui 	if (ep == NULL)
60*d02e022dStsutsui 		/* horrible! */
61*d02e022dStsutsui 		again();
62*d02e022dStsutsui 
63*d02e022dStsutsui 	/* ctlr,id,part */
64*d02e022dStsutsui 	strcpy(disksetting, ep + 1);
65*d02e022dStsutsui 
66*d02e022dStsutsui 	i = 0;
67*d02e022dStsutsui 
68*d02e022dStsutsui 	while (disksetting[i] != '\0') {
69*d02e022dStsutsui 		if (disksetting[i] >= '0' && disksetting[i] <= '9') {
70*d02e022dStsutsui 			if (i == 0)
71*d02e022dStsutsui 				scsi_ctlr = atoi(&disksetting[i]);
72*d02e022dStsutsui 			if (i == 2)
73*d02e022dStsutsui 				scsi_id = atoi(&disksetting[i]);
74*d02e022dStsutsui 			if (i == 4)
75*d02e022dStsutsui 				scsi_part = atoi(&disksetting[i]);
76*d02e022dStsutsui 		}
77*d02e022dStsutsui 		i++;
78*d02e022dStsutsui 	}
79*d02e022dStsutsui 
80*d02e022dStsutsui 	if ((scsi_ctlr == 255) || (scsi_id == 255) || (scsi_part == 255))
81*d02e022dStsutsui 		again();
82*d02e022dStsutsui }
83