Wed Jul 27 15:08:43 2011 UTC ()
Make atoi() use strtoll from libkern.


(njoly)
diff -r1.49 -r1.50 src/sys/arch/alpha/alpha/autoconf.c

cvs diff -r1.49 -r1.50 src/sys/arch/alpha/alpha/autoconf.c (switch to unified diff)

--- src/sys/arch/alpha/alpha/autoconf.c 2011/07/26 14:59:03 1.49
+++ src/sys/arch/alpha/alpha/autoconf.c 2011/07/27 15:08:42 1.50
@@ -1,201 +1,183 @@ @@ -1,201 +1,183 @@
1/* $NetBSD: autoconf.c,v 1.49 2011/07/26 14:59:03 njoly Exp $ */ 1/* $NetBSD: autoconf.c,v 1.50 2011/07/27 15:08:42 njoly Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1992, 1993 4 * Copyright (c) 1992, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * This software was developed by the Computer Systems Engineering group 7 * This software was developed by the Computer Systems Engineering group
8 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and 8 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
9 * contributed to Berkeley. 9 * contributed to Berkeley.
10 * 10 *
11 * All advertising materials mentioning features or use of this software 11 * All advertising materials mentioning features or use of this software
12 * must display the following acknowledgement: 12 * must display the following acknowledgement:
13 * This product includes software developed by the University of 13 * This product includes software developed by the University of
14 * California, Lawrence Berkeley Laboratory. 14 * California, Lawrence Berkeley Laboratory.
15 * 15 *
16 * Redistribution and use in source and binary forms, with or without 16 * Redistribution and use in source and binary forms, with or without
17 * modification, are permitted provided that the following conditions 17 * modification, are permitted provided that the following conditions
18 * are met: 18 * are met:
19 * 1. Redistributions of source code must retain the above copyright 19 * 1. Redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer. 20 * notice, this list of conditions and the following disclaimer.
21 * 2. Redistributions in binary form must reproduce the above copyright 21 * 2. Redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the 22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution. 23 * documentation and/or other materials provided with the distribution.
24 * 3. Neither the name of the University nor the names of its contributors 24 * 3. Neither the name of the University nor the names of its contributors
25 * may be used to endorse or promote products derived from this software 25 * may be used to endorse or promote products derived from this software
26 * without specific prior written permission. 26 * without specific prior written permission.
27 * 27 *
28 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 28 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
29 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 29 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 30 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 31 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 32 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 34 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 36 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 37 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 * SUCH DAMAGE. 38 * SUCH DAMAGE.
39 * 39 *
40 * @(#)autoconf.c 8.4 (Berkeley) 10/1/93 40 * @(#)autoconf.c 8.4 (Berkeley) 10/1/93
41 */ 41 */
42 42
43#include <sys/cdefs.h> /* RCS ID & Copyright macro defns */ 43#include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
44 44
45__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.49 2011/07/26 14:59:03 njoly Exp $"); 45__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.50 2011/07/27 15:08:42 njoly Exp $");
46 46
47#include <sys/param.h> 47#include <sys/param.h>
48#include <sys/systm.h> 48#include <sys/systm.h>
49#include <sys/buf.h> 49#include <sys/buf.h>
50#include <sys/disklabel.h> 50#include <sys/disklabel.h>
51#include <sys/reboot.h> 51#include <sys/reboot.h>
52#include <sys/device.h> 52#include <sys/device.h>
53#include <sys/conf.h> 53#include <sys/conf.h>
54#include <dev/cons.h> 54#include <dev/cons.h>
55 55
56#include <machine/autoconf.h> 56#include <machine/autoconf.h>
57#include <machine/alpha.h> 57#include <machine/alpha.h>
58#include <machine/cpu.h> 58#include <machine/cpu.h>
59#include <machine/prom.h> 59#include <machine/prom.h>
60#include <machine/cpuconf.h> 60#include <machine/cpuconf.h>
61#include <machine/intr.h> 61#include <machine/intr.h>
62 62
63struct bootdev_data *bootdev_data; 63struct bootdev_data *bootdev_data;
64 64
65void parse_prom_bootdev(void); 65void parse_prom_bootdev(void);
66static int atoi(const char *); 66static inline int atoi(const char *);
67 67
68/* 68/*
69 * cpu_configure: 69 * cpu_configure:
70 * called at boot time, configure all devices on system 70 * called at boot time, configure all devices on system
71 */ 71 */
72void 72void
73cpu_configure(void) 73cpu_configure(void)
74{ 74{
75 75
76 parse_prom_bootdev(); 76 parse_prom_bootdev();
77 77
78 /* 78 /*
79 * Disable interrupts during autoconfiguration. splhigh() won't 79 * Disable interrupts during autoconfiguration. splhigh() won't
80 * work, because it simply _raises_ the IPL, so if machine checks 80 * work, because it simply _raises_ the IPL, so if machine checks
81 * are disabled, they'll stay disabled. Machine checks are needed 81 * are disabled, they'll stay disabled. Machine checks are needed
82 * during autoconfig. 82 * during autoconfig.
83 */ 83 */
84 (void)alpha_pal_swpipl(ALPHA_PSL_IPL_HIGH); 84 (void)alpha_pal_swpipl(ALPHA_PSL_IPL_HIGH);
85 if (config_rootfound("mainbus", NULL) == NULL) 85 if (config_rootfound("mainbus", NULL) == NULL)
86 panic("no mainbus found"); 86 panic("no mainbus found");
87 (void)spl0(); 87 (void)spl0();
88 88
89 /* 89 /*
90 * Note that bootstrapping is finished, and set the HWRPB up  90 * Note that bootstrapping is finished, and set the HWRPB up
91 * to do restarts. 91 * to do restarts.
92 */ 92 */
93 hwrpb_restart_setup(); 93 hwrpb_restart_setup();
94} 94}
95 95
96void 96void
97cpu_rootconf(void) 97cpu_rootconf(void)
98{ 98{
99 99
100 if (booted_device == NULL) 100 if (booted_device == NULL)
101 printf("WARNING: can't figure what device matches \"%s\"\n", 101 printf("WARNING: can't figure what device matches \"%s\"\n",
102 bootinfo.booted_dev); 102 bootinfo.booted_dev);
103 setroot(booted_device, booted_partition); 103 setroot(booted_device, booted_partition);
104} 104}
105 105
106void 106void
107parse_prom_bootdev(void) 107parse_prom_bootdev(void)
108{ 108{
109 static char hacked_boot_dev[128]; 109 static char hacked_boot_dev[128];
110 static struct bootdev_data bd; 110 static struct bootdev_data bd;
111 char *cp, *scp, *boot_fields[8]; 111 char *cp, *scp, *boot_fields[8];
112 int i, done; 112 int i, done;
113 113
114 booted_device = NULL; 114 booted_device = NULL;
115 booted_partition = 0; 115 booted_partition = 0;
116 bootdev_data = NULL; 116 bootdev_data = NULL;
117 117
118 memcpy(hacked_boot_dev, bootinfo.booted_dev, 118 memcpy(hacked_boot_dev, bootinfo.booted_dev,
119 min(sizeof bootinfo.booted_dev, sizeof hacked_boot_dev)); 119 min(sizeof bootinfo.booted_dev, sizeof hacked_boot_dev));
120#if 0 120#if 0
121 printf("parse_prom_bootdev: boot dev = \"%s\"\n", hacked_boot_dev); 121 printf("parse_prom_bootdev: boot dev = \"%s\"\n", hacked_boot_dev);
122#endif 122#endif
123 123
124 i = 0; 124 i = 0;
125 scp = cp = hacked_boot_dev; 125 scp = cp = hacked_boot_dev;
126 for (done = 0; !done; cp++) { 126 for (done = 0; !done; cp++) {
127 if (*cp != ' ' && *cp != '\0') 127 if (*cp != ' ' && *cp != '\0')
128 continue; 128 continue;
129 if (*cp == '\0') 129 if (*cp == '\0')
130 done = 1; 130 done = 1;
131 131
132 *cp = '\0'; 132 *cp = '\0';
133 boot_fields[i++] = scp; 133 boot_fields[i++] = scp;
134 scp = cp + 1; 134 scp = cp + 1;
135 if (i == 8) 135 if (i == 8)
136 done = 1; 136 done = 1;
137 } 137 }
138 if (i != 8) 138 if (i != 8)
139 return; /* doesn't look like anything we know! */ 139 return; /* doesn't look like anything we know! */
140 140
141#if 0 141#if 0
142 printf("i = %d, done = %d\n", i, done); 142 printf("i = %d, done = %d\n", i, done);
143 for (i--; i >= 0; i--) 143 for (i--; i >= 0; i--)
144 printf("%d = %s\n", i, boot_fields[i]); 144 printf("%d = %s\n", i, boot_fields[i]);
145#endif 145#endif
146 146
147 bd.protocol = boot_fields[0]; 147 bd.protocol = boot_fields[0];
148 bd.bus = atoi(boot_fields[1]); 148 bd.bus = atoi(boot_fields[1]);
149 bd.slot = atoi(boot_fields[2]); 149 bd.slot = atoi(boot_fields[2]);
150 bd.channel = atoi(boot_fields[3]); 150 bd.channel = atoi(boot_fields[3]);
151 bd.remote_address = boot_fields[4]; 151 bd.remote_address = boot_fields[4];
152 bd.unit = atoi(boot_fields[5]); 152 bd.unit = atoi(boot_fields[5]);
153 bd.boot_dev_type = atoi(boot_fields[6]); 153 bd.boot_dev_type = atoi(boot_fields[6]);
154 bd.ctrl_dev_type = boot_fields[7]; 154 bd.ctrl_dev_type = boot_fields[7];
155 155
156#if 0 156#if 0
157 printf("parsed: proto = %s, bus = %d, slot = %d, channel = %d,\n", 157 printf("parsed: proto = %s, bus = %d, slot = %d, channel = %d,\n",
158 bd.protocol, bd.bus, bd.slot, bd.channel); 158 bd.protocol, bd.bus, bd.slot, bd.channel);
159 printf("\tremote = %s, unit = %d, dev_type = %d, ctrl_type = %s\n", 159 printf("\tremote = %s, unit = %d, dev_type = %d, ctrl_type = %s\n",
160 bd.remote_address, bd.unit, bd.boot_dev_type, bd.ctrl_dev_type); 160 bd.remote_address, bd.unit, bd.boot_dev_type, bd.ctrl_dev_type);
161#endif 161#endif
162 162
163 bootdev_data = &bd; 163 bootdev_data = &bd;
164} 164}
165 165
166static int 166static inline int
167atoi(const char *s) 167atoi(const char *s)
168{ 168{
169 int n, neg; 169 return (int)strtoll(s, NULL, 10);
170 
171 n = 0; 
172 neg = 0; 
173 
174 while (*s == '-') { 
175 s++; 
176 neg = !neg; 
177 } 
178 
179 while (*s != '\0') { 
180 if (*s < '0' && *s > '9') 
181 break; 
182 
183 n = (10 * n) + (*s - '0'); 
184 s++; 
185 } 
186 
187 return (neg ? -n : n); 
188} 170}
189 171
190void 172void
191device_register(device_t dev, void *aux) 173device_register(device_t dev, void *aux)
192{ 174{
193 if (bootdev_data == NULL) { 175 if (bootdev_data == NULL) {
194 /* 176 /*
195 * There is no hope. 177 * There is no hope.
196 */ 178 */
197 return; 179 return;
198 } 180 }
199 if (platform.device_register) 181 if (platform.device_register)
200 (*platform.device_register)(dev, aux); 182 (*platform.device_register)(dev, aux);
201} 183}