source: mainline/uspace/app/init/init.c@ f1938c6

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since f1938c6 was acc7ce4, checked in by Martin Decky <martin@…>, 15 years ago

uspace interrupt controller drivers for i8259 and APIC (non-functional yet)
convert NE2000 driver to use these drivers (not enabling the IRQ in kernel), this solves the "spurious interrupt" issue
(however, on SMP machines this renders the driver unusable for now since the APIC driver does not do anything yet)

  • Property mode set to 100644
File size: 7.7 KB
Line 
1/*
2 * Copyright (c) 2005 Martin Decky
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - 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.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup init Init
30 * @brief Init process for user space environment configuration.
31 * @{
32 */
33/**
34 * @file
35 */
36
37#include <stdio.h>
38#include <unistd.h>
39#include <ipc/ipc.h>
40#include <vfs/vfs.h>
41#include <bool.h>
42#include <errno.h>
43#include <fcntl.h>
44#include <sys/stat.h>
45#include <task.h>
46#include <malloc.h>
47#include <macros.h>
48#include <str.h>
49#include <devmap.h>
50#include <str_error.h>
51#include "init.h"
52
53#define ROOT_DEVICE "bd/initrd"
54#define ROOT_MOUNT_POINT "/"
55
56#define DEVFS_FS_TYPE "devfs"
57#define DEVFS_MOUNT_POINT "/dev"
58
59#define TMPFS_FS_TYPE "tmpfs"
60#define TMPFS_MOUNT_POINT "/tmp"
61
62#define DATA_FS_TYPE "fat"
63#define DATA_DEVICE "bd/ata1disk0"
64#define DATA_MOUNT_POINT "/data"
65
66#define SRV_CONSOLE "/srv/console"
67#define APP_GETTERM "/app/getterm"
68
69static void info_print(void)
70{
71 printf("%s: HelenOS init\n", NAME);
72}
73
74static bool mount_report(const char *desc, const char *mntpt,
75 const char *fstype, const char *dev, int rc)
76{
77 switch (rc) {
78 case EOK:
79 if (dev != NULL)
80 printf("%s: %s mounted on %s (%s at %s)\n", NAME, desc, mntpt,
81 fstype, dev);
82 else
83 printf("%s: %s mounted on %s (%s)\n", NAME, desc, mntpt, fstype);
84 break;
85 case EBUSY:
86 printf("%s: %s already mounted on %s\n", NAME, desc, mntpt);
87 return false;
88 case ELIMIT:
89 printf("%s: %s limit exceeded\n", NAME, desc);
90 return false;
91 case ENOENT:
92 printf("%s: %s unknown type (%s)\n", NAME, desc, fstype);
93 return false;
94 default:
95 printf("%s: %s not mounted on %s (%s)\n", NAME, desc, mntpt,
96 str_error(rc));
97 return false;
98 }
99
100 return true;
101}
102
103static bool mount_root(const char *fstype)
104{
105 const char *opts = "";
106
107 if (str_cmp(fstype, "tmpfs") == 0)
108 opts = "restore";
109
110 int rc = mount(fstype, ROOT_MOUNT_POINT, ROOT_DEVICE, opts,
111 IPC_FLAG_BLOCKING);
112 return mount_report("Root filesystem", ROOT_MOUNT_POINT, fstype,
113 ROOT_DEVICE, rc);
114}
115
116static bool mount_devfs(void)
117{
118 int rc = mount(DEVFS_FS_TYPE, DEVFS_MOUNT_POINT, "", "",
119 IPC_FLAG_BLOCKING);
120 return mount_report("Device filesystem", DEVFS_MOUNT_POINT, DEVFS_FS_TYPE,
121 NULL, rc);
122}
123
124static void spawn(const char *fname)
125{
126 int rc;
127 struct stat s;
128
129 if (stat(fname, &s) == ENOENT)
130 return;
131
132 printf("%s: Spawning %s\n", NAME, fname);
133 rc = task_spawnl(NULL, fname, fname, NULL);
134 if (rc != EOK) {
135 printf("%s: Error spawning %s (%s)\n", NAME, fname,
136 str_error(rc));
137 }
138}
139
140static void srv_start(const char *fname)
141{
142 task_id_t id;
143 task_exit_t texit;
144 int rc, retval;
145 struct stat s;
146
147 if (stat(fname, &s) == ENOENT)
148 return;
149
150 printf("%s: Starting %s\n", NAME, fname);
151 rc = task_spawnl(&id, fname, fname, NULL);
152 if (!id) {
153 printf("%s: Error spawning %s (%s)\n", NAME, fname,
154 str_error(rc));
155 return;
156 }
157
158 rc = task_wait(id, &texit, &retval);
159 if (rc != EOK) {
160 printf("%s: Error waiting for %s (%s(\n", NAME, fname,
161 str_error(rc));
162 return;
163 }
164
165 if (texit != TASK_EXIT_NORMAL) {
166 printf("%s: Server %s failed to start (unexpectedly "
167 "terminated)\n", NAME, fname);
168 return;
169 }
170
171 if (retval != 0) {
172 printf("%s: Server %s failed to start (exit code %d)\n", NAME,
173 fname, retval);
174 }
175}
176
177static void console(const char *dev)
178{
179 char hid_in[DEVMAP_NAME_MAXLEN];
180 int rc;
181
182 snprintf(hid_in, DEVMAP_NAME_MAXLEN, "%s/%s", DEVFS_MOUNT_POINT, dev);
183
184 printf("%s: Spawning %s %s\n", NAME, SRV_CONSOLE, hid_in);
185
186 /* Wait for the input device to be ready */
187 devmap_handle_t handle;
188 rc = devmap_device_get_handle(dev, &handle, IPC_FLAG_BLOCKING);
189 if (rc != EOK) {
190 printf("%s: Error waiting on %s (%s)\n", NAME, hid_in,
191 str_error(rc));
192 return;
193 }
194
195 rc = task_spawnl(NULL, SRV_CONSOLE, SRV_CONSOLE, hid_in, NULL);
196 if (rc != EOK) {
197 printf("%s: Error spawning %s %s (%s)\n", NAME, SRV_CONSOLE,
198 hid_in, str_error(rc));
199 }
200}
201
202static void getterm(const char *dev, const char *app, bool wmsg)
203{
204 char term[DEVMAP_NAME_MAXLEN];
205 int rc;
206
207 snprintf(term, DEVMAP_NAME_MAXLEN, "%s/%s", DEVFS_MOUNT_POINT, dev);
208
209 printf("%s: Spawning %s %s %s\n", NAME, APP_GETTERM, term, app);
210
211 /* Wait for the terminal device to be ready */
212 devmap_handle_t handle;
213 rc = devmap_device_get_handle(dev, &handle, IPC_FLAG_BLOCKING);
214 if (rc != EOK) {
215 printf("%s: Error waiting on %s (%s)\n", NAME, term,
216 str_error(rc));
217 return;
218 }
219
220 if (wmsg) {
221 rc = task_spawnl(NULL, APP_GETTERM, APP_GETTERM, "-w", term,
222 app, NULL);
223 if (rc != EOK) {
224 printf("%s: Error spawning %s -w %s %s (%s)\n", NAME,
225 APP_GETTERM, term, app, str_error(rc));
226 }
227 } else {
228 rc = task_spawnl(NULL, APP_GETTERM, APP_GETTERM, term, app,
229 NULL);
230 if (rc != EOK) {
231 printf("%s: Error spawning %s %s %s (%s)\n", NAME,
232 APP_GETTERM, term, app, str_error(rc));
233 }
234 }
235}
236
237static bool mount_tmpfs(void)
238{
239 int rc = mount(TMPFS_FS_TYPE, TMPFS_MOUNT_POINT, "", "", 0);
240 return mount_report("Temporary filesystem", TMPFS_MOUNT_POINT,
241 TMPFS_FS_TYPE, NULL, rc);
242}
243
244static bool mount_data(void)
245{
246 int rc = mount(DATA_FS_TYPE, DATA_MOUNT_POINT, DATA_DEVICE, "wtcache", 0);
247 return mount_report("Data filesystem", DATA_MOUNT_POINT, DATA_FS_TYPE,
248 DATA_DEVICE, rc);
249}
250
251int main(int argc, char *argv[])
252{
253 info_print();
254
255 if (!mount_root(STRING(RDFMT))) {
256 printf("%s: Exiting\n", NAME);
257 return -1;
258 }
259
260 /* Make sure tmpfs is running. */
261 if (str_cmp(STRING(RDFMT), "tmpfs") != 0) {
262 spawn("/srv/tmpfs");
263 }
264
265 spawn("/srv/devfs");
266 spawn("/srv/taskmon");
267
268 if (!mount_devfs()) {
269 printf("%s: Exiting\n", NAME);
270 return -2;
271 }
272
273 mount_tmpfs();
274
275 spawn("/srv/apic");
276 spawn("/srv/i8259");
277 spawn("/srv/fhc");
278 spawn("/srv/obio");
279 srv_start("/srv/cuda_adb");
280 srv_start("/srv/i8042");
281 srv_start("/srv/s3c24ser");
282 srv_start("/srv/adb_ms");
283 srv_start("/srv/char_ms");
284 srv_start("/srv/s3c24ts");
285
286 spawn("/srv/fb");
287 spawn("/srv/kbd");
288 console("hid_in/kbd");
289
290 spawn("/srv/clip");
291
292 /*
293 * Start these synchronously so that mount_data() can be
294 * non-blocking.
295 */
296#ifdef CONFIG_START_BD
297 srv_start("/srv/ata_bd");
298 srv_start("/srv/gxe_bd");
299#else
300 (void) srv_start;
301#endif
302
303#ifdef CONFIG_MOUNT_DATA
304 mount_data();
305#else
306 (void) mount_data;
307#endif
308
309 getterm("term/vc0", "/app/bdsh", true);
310 getterm("term/vc1", "/app/bdsh", false);
311 getterm("term/vc2", "/app/bdsh", false);
312 getterm("term/vc3", "/app/bdsh", false);
313 getterm("term/vc4", "/app/bdsh", false);
314 getterm("term/vc5", "/app/bdsh", false);
315 getterm("term/vc6", "/app/klog", false);
316
317 return 0;
318}
319
320/** @}
321 */
Note: See TracBrowser for help on using the repository browser.