Documented GVF_SAVE_VAR alongside other flags, and removed a query/doubt
[AROS.git] / arch / all-unix / bootstrap / kickstart.c
blob537d5b5e7937f999a11963d9d5e825e7f440f40d
1 /*
2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <sys/wait.h>
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <unistd.h>
12 /* These macros are defined in both UNIX and AROS headers. Get rid of warnings. */
13 #undef __pure
14 #undef __const
15 #undef __pure2
16 #undef __deprecated
18 #include <aros/kernel.h>
19 #include <runtime.h>
21 #include "kickstart.h"
22 #include "platform.h"
24 #define D(x)
27 * This is the UNIX-hosted kicker. Theory of operation:
28 * We want to run the loaded code multiple times, every time as a new process (in order
29 * to drop all open file descriptors etc).
30 * We have already loaded our kickstart and allocated RAM. Now we use fork() to mark
31 * the point where we are started.
32 * AROS is executed inside child process. The parent just sits and waits for the return
33 * code.
34 * When AROS shuts down, it sets exit status in order to indicate a reason. There are
35 * three status codes:
36 * 1. Shutdown
37 * 2. Cold reboot.
38 * 3. Warm reboot.
39 * We pick up this code and see what we need to do. Warm reboot means just creating a
40 * new AROS process using the same kickstart and RAM image. When the RAM is made shared,
41 * this will effectively keep KickTags etc.
42 * Cold reboot is the same as before, re-running everything from scratch.
43 * Shutdown is just plain exit.
45 int kick(int (*addr)(), struct TagItem *msg)
47 int i;
51 pid_t child = fork();
53 switch (child)
55 case -1:
56 DisplayError("Failed to run kickstart!");
57 return -1;
59 case 0:
60 fprintf(stderr, "[Bootstrap] Entering kernel at %p...\n", addr);
61 Host_PreBoot();
62 i = addr(msg, AROS_BOOT_MAGIC);
63 exit(i);
66 /* Wait until AROS process exits */
67 waitpid(child, &i, 0);
69 if (!WIFEXITED(i))
71 D(fprintf(stderr, "AROS process died with error\n"));
72 return -1;
75 D(fprintf(stderr, "AROS exited with status 0x%08X\n", WEXITSTATUS(i)));
77 /* ColdReboot() returns 0x8F */
78 } while (WEXITSTATUS(i) == 0x8F);
80 if (WEXITSTATUS(i) == 0x81)
83 * Perform cold boot if requested.
84 * Before rebooting, we clean up. Otherwise execvp()'ed process will
85 * inherit what we allocated here, then again... This will cause memory leak.
87 Host_FreeMem();
88 Host_ColdBoot();
91 return WEXITSTATUS(i);