Copyright clean-up (part 1):
[AROS.git] / arch / all-unix / bootstrap / kickstart.c
blob66e4525cfac5625dd3ad71d22ca6dcaabefc300b
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 i = addr(msg, AROS_BOOT_MAGIC);
62 exit(i);
65 /* Wait until AROS process exits */
66 waitpid(child, &i, 0);
68 if (!WIFEXITED(i))
70 D(fprintf(stderr, "AROS process died with error\n"));
71 return -1;
74 D(fprintf(stderr, "AROS exited with status 0x%08X\n", WEXITSTATUS(i)));
76 /* ColdReboot() returns 0x8F */
77 } while (WEXITSTATUS(i) == 0x8F);
79 if (WEXITSTATUS(i) == 0x81)
82 * Perform cold boot if requested.
83 * Before rebooting, we clean up. Otherwise execvp()'ed process will
84 * inherit what we allocated here, then again... This will cause memory leak.
86 Host_FreeMem();
87 Host_ColdBoot();
90 return WEXITSTATUS(i);