Merge origin/netpush (networking code) (XCC)
[akaros.git] / kern / src / init.c
index 5aff619..2f323f5 100644 (file)
@@ -1,7 +1,11 @@
 /* See COPYRIGHT for copyright information. */
 
-#ifdef __BSD_ON_CORE_0__
-#include Everything For Free -- It just works!!
+#ifdef __SHARC__
+#pragma nosharc
+#endif
+
+#ifdef __CONFIG_BSD_ON_CORE0__
+#error "Yeah, it's not possible to build ROS with BSD on Core 0, sorry......"
 #else
 
 #include <arch/arch.h>
@@ -10,6 +14,7 @@
 #include <stab.h>
 #include <smp.h>
 
+#include <time.h>
 #include <atomic.h>
 #include <stdio.h>
 #include <string.h>
 #include <syscall.h>
 #include <kclock.h>
 #include <manager.h>
-
-#include <arch/rl8168.h>
-#include <arch/ne2k.h>
-#include <arch/mptables.h>
-#include <arch/pci.h>
-#include <arch/ioapic.h>
+#include <testing.h>
+#include <kmalloc.h>
+#include <hashtable.h>
+#include <radix.h>
+#include <mm.h>
+#include <frontend.h>
+
+#include <arch/init.h>
+#include <bitmask.h>
+#include <slab.h>
+#include <kfs.h>
+#include <vfs.h>
+#include <devfs.h>
+#include <blockdev.h>
+#include <ext2fs.h>
+#include <kthread.h>
+#include <net.h>
+#include <socket.h>
+#include <eth_audio.h>
+#include <console.h>
+
+// zra: flag for Ivy
+int booting = 1;
 
 void kernel_init(multiboot_info_t *mboot_info)
 {
-       extern char (BND(__this, end) edata)[], (SNT end)[];
+       extern char (RO BND(__this, end) edata)[], (RO SNT end)[];
 
        // Before doing anything else, complete the ELF loading process.
        // Clear the uninitialized global data (BSS) section of our program.
@@ -43,39 +65,52 @@ void kernel_init(multiboot_info_t *mboot_info)
 
        print_cpuinfo();
 
-       // zra: using KADDR macro gives a runtime warning, but it is possibly more
-    //      clear what's going on this way?
+       // Old way, pre Zach's Ivy annotations
        //multiboot_detect_memory((multiboot_info_t*)((uint32_t)mboot_info + KERNBASE));
        //multiboot_print_memory_map((multiboot_info_t*)((uint32_t)mboot_info + KERNBASE));
-       multiboot_detect_memory((multiboot_info_t*COUNT(1))KADDR((physaddr_t)mboot_info));
-       multiboot_print_memory_map((multiboot_info_t*COUNT(1))KADDR((physaddr_t)mboot_info));
-
-       vm_init();
-
-       cache_init();
-       page_init();
+       
+       // Paul: Can't use KADDR as arg to multiboot_detect_memory
+       //  since multiboot_detect_memory is what sets npages. 
+       //  Must simulate KADDR macro (ugly).
+       multiboot_detect_memory((multiboot_info_t*CT(1))TC((physaddr_t)mboot_info + KERNBASE));
+
+       multiboot_print_memory_map((multiboot_info_t*CT(1))KADDR((physaddr_t)mboot_info));
+
+       vm_init();                      // Sets up pages tables, turns on paging
+       cache_init();                                   // Determine systems's cache properties
+       page_init();                                    // Initializes free page list, etc
+       kmem_cache_init();              // Sets up slab allocator
+       kmalloc_init();
+       hashtable_init();
+       radix_init();
+       cache_color_alloc_init();       // Inits data structs
+       colored_page_alloc_init();      // Allocates colors for agnostic processes
+       kthread_init();                                 /* might need to tweak when this happens */
+       vmr_init();
+       file_init();
        page_check();
-
-       env_init();
-
+       vfs_init();
+       devfs_init();
        idt_init();
+       kernel_msg_init();
        sysenter_init();
        timer_init();
+       train_timing();
+       kb_buf_init(&cons_buf);
        
-       #ifdef __i386__
-       mptables_parse();
-       pci_init();
-       ioapic_init(); // MUST BE AFTER PCI/ISA INIT!
-       #endif // __i386__
-       
-       
-       // this returns when all other cores are done and ready to receive IPIs
-       smp_boot();
-       
-       #ifdef __i386__
-       rl8168_init();          
-       ne2k_init();
-       #endif // __i386__
+       arch_init();
+       block_init();
+       enable_irq();
+       socket_init();
+#ifdef __CONFIG_EXT2FS__
+       mount_fs(&ext2_fs_type, "/dev/ramdisk", "/mnt", 0);
+#endif /* __CONFIG_EXT2FS__ */
+#ifdef __CONFIG_ETH_AUDIO__
+       eth_audio_init();
+#endif /* __CONFIG_ETH_AUDIO__ */
+
+       // zra: let's Ivy know we're done booting
+       booting = 0;
 
        manager();
 }
@@ -87,7 +122,10 @@ void kernel_init(multiboot_info_t *mboot_info)
 void _panic(const char *file, int line, const char *fmt,...)
 {
        va_list ap;
+       struct per_cpu_info *pcpui = &per_cpu_info[core_id()];
 
+       /* We're panicing, possibly in a place that can't handle the lock checker */
+       pcpui->__lock_depth_disabled++;
        va_start(ap, fmt);
        cprintf("kernel panic at %s:%d, from core %d: ", file, line, core_id());
        vcprintf(fmt, ap);
@@ -95,13 +133,12 @@ void _panic(const char *file, int line, const char *fmt,...)
        va_end(ap);
 
 dead:
-       /* break into the kernel monitor, if we're core 0 */
-       if (core_id()) {
-               smp_idle();
-               panic("should never see me");
-       }
-       while (1)
-               monitor(NULL);
+       monitor(NULL);
+       /* We could consider turning the lock checker back on here, but things are
+        * probably a mess anyways, and with it on we would probably lock up right
+        * away when we idle. */
+       //pcpui->__lock_depth_disabled--;
+       smp_idle();
 }
 
 /* like panic, but don't */