xref: /netbsd/sys/arch/arm/arm/bootconfig.c (revision bf9ec67e)
1 /*	$NetBSD: bootconfig.c,v 1.2 2002/03/10 19:56:39 lukem Exp $	*/
2 
3 /*
4  * Copyright (c) 1994-1998 Mark Brinicombe.
5  * Copyright (c) 1994 Brini.
6  * All rights reserved.
7  *
8  * This code is derived from software written for Brini by Mark Brinicombe
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. All advertising materials mentioning features or use of this software
19  *    must display the following acknowledgement:
20  *	This product includes software developed by Mark Brinicombe
21  *	for the NetBSD Project.
22  * 4. The name of the company nor the name of the author may be used to
23  *    endorse or promote products derived from this software without specific
24  *    prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
27  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
28  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
29  * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
30  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
31  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
32  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36  * SUCH DAMAGE.
37  */
38 
39 #include <sys/param.h>
40 
41 __KERNEL_RCSID(0, "$NetBSD: bootconfig.c,v 1.2 2002/03/10 19:56:39 lukem Exp $");
42 
43 #include <sys/systm.h>
44 
45 #include <machine/bootconfig.h>
46 
47 #include "opt_md.h"
48 #include "opt_pmap_debug.h"
49 #include "md.h"
50 
51 /*
52  * Function to identify and process different types of boot argument
53  */
54 
55 int
56 get_bootconf_option(opts, opt, type, result)
57 	char *opts;
58 	char *opt;
59 	int type;
60 	void *result;
61 {
62 	char *ptr;
63 	char *optstart;
64 	int not;
65 
66 	ptr = opts;
67 
68 	while (*ptr) {
69 		/* Find start of option */
70 		while (*ptr == ' ' || *ptr == '\t')
71 			++ptr;
72 
73 		if (*ptr == 0)
74 			break;
75 
76 		not = 0;
77 
78 		/* Is it a negate option */
79 		if ((type & BOOTOPT_TYPE_MASK) == BOOTOPT_TYPE_BOOLEAN && *ptr == '!') {
80 			not = 1;
81 			++ptr;
82 		}
83 
84 		/* Find the end of option */
85 		optstart = ptr;
86 		while (*ptr != 0 && *ptr != ' ' && *ptr != '\t' && *ptr != '=')
87 			++ptr;
88 
89 		if ((*ptr == '=')
90 		    || (*ptr != '=' && ((type & BOOTOPT_TYPE_MASK) == BOOTOPT_TYPE_BOOLEAN))) {
91 			/* compare the option */
92 			if (strncmp(optstart, opt, (ptr - optstart)) == 0) {
93 				/* found */
94 
95 				if (*ptr == '=')
96 					++ptr;
97 
98 				switch(type & BOOTOPT_TYPE_MASK) {
99 				case BOOTOPT_TYPE_BOOLEAN :
100 					if (*(ptr - 1) == '=')
101 						*((int *)result) = ((u_int)strtoul(ptr, NULL, 10) != 0);
102 					else
103 						*((int *)result) = !not;
104 					break;
105 				case BOOTOPT_TYPE_STRING :
106 					*((char **)result) = ptr;
107 					break;
108 				case BOOTOPT_TYPE_INT :
109 					*((int *)result) = (u_int)strtoul(ptr, NULL, 10);
110 					break;
111 				case BOOTOPT_TYPE_BININT :
112 					*((int *)result) = (u_int)strtoul(ptr, NULL, 2);
113 					break;
114 				case BOOTOPT_TYPE_HEXINT :
115 					*((int *)result) = (u_int)strtoul(ptr, NULL, 16);
116 					break;
117 				default:
118 					return(0);
119 				}
120 				return(1);
121 			}
122 		}
123 		/* skip to next option */
124 		while (*ptr != ' ' && *ptr != '\t' && *ptr != 0)
125 			++ptr;
126 	}
127 	return(0);
128 }
129