1 /* See COPYRIGHT for copyright information. */
7 #ifdef CONFIG_BSD_ON_CORE0
8 #error "Yeah, it's not possible to build ROS with BSD on Core 0, sorry......"
11 #include <arch/arch.h>
12 #include <arch/console.h>
13 #include <multiboot.h>
31 #include <hashtable.h>
36 #include <arch/init.h>
46 #include <linker_func.h>
49 #include <coreboot_tables.h>
53 struct sysinfo_t sysinfo;
54 static void run_linker_funcs(void);
55 static int run_init_script(void);
57 void kernel_init(multiboot_info_t *mboot_info)
59 extern char (RO BND(__this, end) edata)[], (RO SNT end)[];
61 memset(edata, 0, end - edata);
62 /* mboot_info is a physical address. while some arches currently have the
63 * lower memory mapped, everyone should have it mapped at kernbase by now.
64 * also, it might be in 'free' memory, so once we start dynamically using
65 * memory, we may clobber it. */
66 multiboot_kaddr = (struct multiboot_info*)((physaddr_t)mboot_info
71 cache_init(); // Determine systems's cache properties
72 pmem_init(multiboot_kaddr);
73 kmem_cache_init(); // Sets up slab allocator
77 cache_color_alloc_init(); // Inits data structs
78 colored_page_alloc_init(); // Allocates colors for agnostic processes
80 kthread_init(); /* might need to tweak when this happens */
90 kb_buf_init(&cons_buf);
95 /* reset/init devtab after linker funcs 3 and 4. these run NIC and medium
96 * pre-inits, which need to happen before devether. */
101 mount_fs(&ext2_fs_type, "/dev/ramdisk", "/mnt", 0);
102 #endif /* CONFIG_EXT2FS */
103 #ifdef CONFIG_ETH_AUDIO
105 #endif /* CONFIG_ETH_AUDIO */
106 get_coreboot_info(&sysinfo);
107 // zra: let's Ivy know we're done booting
110 #ifdef CONFIG_RUN_INIT_SCRIPT
111 if (run_init_script()) {
112 printk("Configured to run init script, but no script specified!\n");
120 #ifdef CONFIG_RUN_INIT_SCRIPT
121 static int run_init_script(void)
123 /* If we have an init script path specified */
124 if (strlen(CONFIG_INIT_SCRIPT_PATH_AND_ARGS) != 0) {
126 char *sptr = &CONFIG_INIT_SCRIPT_PATH_AND_ARGS[0];
128 /* Figure out how many arguments there are, by finding the spaces */
129 /* TODO: consider rewriting this stuff with parsecmd */
130 while (*sptr != '\0') {
131 if (*(sptr++) != ' ') {
133 while ((*sptr != ' ') && (*sptr != '\0'))
138 /* Initialize l_argv with its first three arguments, but allocate space
139 * for all arguments as calculated above */
141 int total_args = vargs + static_args;
142 char *l_argv[total_args];
144 l_argv[1] = "busybox";
147 /* Initialize l_argv with the rest of the arguments */
149 sptr = &CONFIG_INIT_SCRIPT_PATH_AND_ARGS[0];
150 while (*sptr != '\0') {
153 while ((*sptr != ' ') && (*sptr != '\0'))
162 /* Run the script with its arguments */
163 mon_bin_run(total_args, l_argv, NULL);
170 * Panic is called on unresolvable fatal errors.
171 * It prints "panic: mesg", and then enters the kernel monitor.
173 void _panic(const char *file, int line, const char *fmt,...)
176 struct per_cpu_info *pcpui;
177 /* We're panicing, possibly in a place that can't handle the lock checker */
178 pcpui = &per_cpu_info[core_id_early()];
179 pcpui->__lock_checking_enabled--;
181 printk("kernel panic at %s:%d, from core %d: ", file, line,
189 /* We could consider turning the lock checker back on here, but things are
190 * probably a mess anyways, and with it on we would probably lock up right
191 * away when we idle. */
192 //pcpui->__lock_checking_enabled++;
196 /* like panic, but don't */
197 void _warn(const char *file, int line, const char *fmt,...)
202 printk("kernel warning at %s:%d, from core %d: ", file, line,
209 static void run_links(linker_func_t *linkstart, linker_func_t *linkend)
211 /* Unlike with devtab, our linker sections for the function pointers are
212 * 8 byte aligned (4 on 32 bit) (done by the linker/compiler), so we don't
213 * have to worry about that. */
214 printd("linkstart %p, linkend %p\n", linkstart, linkend);
215 for (int i = 0; &linkstart[i] < linkend; i++) {
216 printd("i %d, linkfunc %p\n", i, linkstart[i]);
221 static void run_linker_funcs(void)
223 run_links(__linkerfunc1start, __linkerfunc1end);
224 run_links(__linkerfunc2start, __linkerfunc2end);
225 run_links(__linkerfunc3start, __linkerfunc3end);
226 run_links(__linkerfunc4start, __linkerfunc4end);
229 /* You need to reference PROVIDE symbols somewhere, or they won't be included.
230 * Only really a problem for debugging. */
231 void debug_linker_tables(void)
233 extern struct dev __devtabstart[];
234 extern struct dev __devtabend[];
235 printk("devtab %p %p\nlink1 %p %p\nlink2 %p %p\nlink3 %p %p\nlink4 %p %p\n",
248 #endif //Everything For Free