blob: c80f097382717a2b1ccf492776a19ffdcbfad46c [file] [log] [blame]
Travis Geiselbrecht68372232009-01-24 21:21:08 -08001/*
2 * Copyright (c) 2009 Travis Geiselbrecht
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files
6 * (the "Software"), to deal in the Software without restriction,
7 * including without limitation the rights to use, copy, modify, merge,
8 * publish, distribute, sublicense, and/or sell copies of the Software,
9 * and to permit persons to whom the Software is furnished to do so,
10 * subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */
23#include <debug.h>
24#include <app.h>
25#include <kernel/thread.h>
26
27extern const struct _app_descriptor __apps_start;
28extern const struct _app_descriptor __apps_end;
29
30static void start_app(const struct _app_descriptor *app);
31
32/* one time setup */
33void apps_init(void)
34{
35 const struct _app_descriptor *app;
36 for (app = &__apps_start; app != &__apps_end; app++) {
37// printf("app '%s'\n", app->name);
38
39 if (app->entry && app->flags & APP_FLAG_BOOT_START) {
40 start_app(app);
41 }
42 }
43}
44
45static int app_thread_entry(void *arg)
46{
47 const struct _app_descriptor *app = (const struct _app_descriptor *)arg;
48
49 app->entry(app, NULL);
50
51 return 0;
52}
53
54static void start_app(const struct _app_descriptor *app)
55{
56 printf("starting app %s\n", app->name);
57 if (app->flags & APP_FLAG_THREAD) {
58 thread_resume(thread_create(app->name, &app_thread_entry, (void *)app, DEFAULT_PRIORITY, DEFAULT_STACK_SIZE));
59 } else {
60 app->entry(app, NULL);
61 }
62}
63