1 /* 2 * Copyright 2003-2010, Axel Dörfler, axeld@pinc-software.de. 3 * Copyright 2008, François Revol, revol@free.fr. All rights reserved. 4 * Distributed under the terms of the MIT License. 5 */ 6 7 8 #include <KernelExport.h> 9 #include <boot/platform.h> 10 #include <boot/heap.h> 11 #include <boot/stage2.h> 12 #include <arch/cpu.h> 13 14 #include <string.h> 15 16 #include "console.h" 17 #include "cpu.h" 18 #include "mmu.h" 19 #include "keyboard.h" 20 #include "toscalls.h" 21 22 23 #define HEAP_SIZE 65536 24 25 // GCC defined globals 26 extern void (*__ctor_list)(void); 27 extern void (*__ctor_end)(void); 28 extern uint8 __bss_start; 29 extern uint8 _end; 30 31 extern "C" int main(stage2_args *args); 32 extern "C" void _start(void); 33 34 35 static uint32 sBootOptions; 36 37 38 static void 39 clear_bss(void) 40 { 41 memset(&__bss_start, 0, &_end - &__bss_start); 42 } 43 44 45 static void 46 call_ctors(void) 47 { 48 void (**f)(void); 49 50 for (f = &__ctor_list; f < &__ctor_end; f++) { 51 (**f)(); 52 } 53 } 54 55 56 extern "C" uint32 57 platform_boot_options(void) 58 { 59 #if 0 60 if (!gKernelArgs.fb.enabled) 61 sBootOptions |= check_for_boot_keys(); 62 #endif 63 return sBootOptions; 64 } 65 66 67 extern "C" void 68 platform_start_kernel(void) 69 { 70 static struct kernel_args *args = &gKernelArgs; 71 // something goes wrong when we pass &gKernelArgs directly 72 // to the assembler inline below - might be a bug in GCC 73 // or I don't see something important... 74 addr_t stackTop 75 = gKernelArgs.cpu_kstack[0].start + gKernelArgs.cpu_kstack[0].size; 76 77 //smp_init_other_cpus(); 78 //serial_cleanup(); 79 mmu_init_for_kernel(); 80 //smp_boot_other_cpus(); 81 82 #warning M68K: stop ints 83 84 dprintf("kernel entry at %lx\n", 85 gKernelArgs.kernel_image.elf_header.e_entry); 86 87 asm volatile ( 88 "move.l %0,%%sp; " // move stack out of way 89 : : "m" (stackTop)); 90 91 asm volatile ( 92 "or #0x0700,%%sr; " : : ); // disable interrupts 93 94 asm volatile ( 95 "move.l #0x0,-(%%sp); " // we're the BSP cpu (0) 96 "move.l %0,-(%%sp); " // kernel args 97 "move.l #0x0,-(%%sp);" // dummy retval for call to main 98 "move.l %1,-(%%sp); " // this is the start address 99 "rts; " // jump. 100 : : "g" (args), "g" (gKernelArgs.kernel_image.elf_header.e_entry)); 101 102 // Huston, we have a problem! 103 104 asm volatile ( 105 "and #0xf8ff,%%sr; " : : ); // reenable interrupts 106 107 panic("kernel returned!\n"); 108 109 } 110 111 112 extern "C" void 113 platform_exit(void) 114 { 115 // Terminate 116 // TODO: Puntaes() instead ? 117 Pterm0(); 118 } 119 120 121 extern "C" void 122 _start(void) 123 { 124 stage2_args args; 125 Bconout(DEV_CON, 'H'); 126 127 //asm("cld"); // Ain't nothing but a GCC thang. 128 //asm("fninit"); // initialize floating point unit 129 130 clear_bss(); 131 Bconout(DEV_CON, 'A'); 132 call_ctors(); 133 // call C++ constructors before doing anything else 134 Bconout(DEV_CON, 'I'); 135 136 args.heap_size = HEAP_SIZE; 137 args.arguments = NULL; 138 139 // so we can dprintf 140 init_nat_features(); 141 142 //serial_init(); 143 Bconout(DEV_CON, 'K'); 144 console_init(); 145 Bconout(DEV_CON, 'U'); 146 dprintf("membot = %p\n", (void*)*TOSVAR_membot); 147 dprintf("memtop = %p\n", (void*)*TOSVAR_memtop); 148 dprintf("v_bas_ad = %p\n", *TOSVAR_v_bas_ad); 149 dprintf("phystop = %p\n", (void*)*TOSVARphystop); 150 dprintf("ramtop = %p\n", (void*)*TOSVARramtop); 151 cpu_init(); 152 mmu_init(); 153 154 // wait a bit to give the user the opportunity to press a key 155 spin(750000); 156 157 // reading the keyboard doesn't seem to work in graphics mode (maybe a bochs problem) 158 sBootOptions = check_for_boot_keys(); 159 //if (sBootOptions & BOOT_OPTION_DEBUG_OUTPUT) 160 //serial_enable(); 161 162 //apm_init(); 163 //smp_init(); 164 main(&args); 165 } 166