tkernel_2/kernel/sysinit/src/sysstartup.c | bare source | permlink (0.03 seconds) |
1: /* 2: *---------------------------------------------------------------------- 3: * T-Kernel 2.0 Software Package 4: * 5: * Copyright 2011 by Ken Sakamura. 6: * This software is distributed under the latest version of T-License 2.x. 7: *---------------------------------------------------------------------- 8: * 9: * Released by T-Engine Forum(http://www.t-engine.org/) at 2011/05/17. 10: * Modified by TRON Forum(http://www.tron.org/) at 2015/06/01. 11: * 12: *---------------------------------------------------------------------- 13: */ 14: 15: /* 16: * sysstartup.c (sysinit) 17: * Start/Stop System 18: */ 19: 20: #include "sysinit.h" 21: #include "kernel.h" 22: 23: /* 24: * Subsystem 25: */ 26: IMPORT ER init_subsystems( void ); 27: IMPORT ER start_subsystems( void ); 28: IMPORT ER finish_subsystems( void ); 29: 30: /* 31: * Manager/Driver 32: */ 33: IMPORT ER init_segmgr( void ); /* Segment management */ 34: IMPORT ER start_segmgr( void ); /* Segment management */ 35: IMPORT ER finish_segmgr( void ); /* Segment management */ 36: IMPORT ER init_memmgr( void ); /* Memory management */ 37: IMPORT ER start_memmgr( void ); /* Memory management */ 38: IMPORT ER finish_memmgr( void ); /* Memory management */ 39: IMPORT ER SystemManager( INT ac, UB *av[] ); /* T-Kernel/SM */ 40: IMPORT ER init_Imalloc( void ); /* T-Kernel/SM */ 41: IMPORT void _InitLibtk(void); /* libtk */ 42: IMPORT void _FinishLibtk(void); /* libtk */ 43: IMPORT void t_kernel_exit( void ); /* T-Kernel/OS */ 44: 45: /* 46: * Initial task priority 47: */ 48: #define InitTaskPri (138) 49: 50: /* 51: * Initialize sequence before T-Kernel starts 52: */ 53: EXPORT void init_system( void ) 54: { 55: ER ercd; 56: 57: /* Platform dependent initialize sequence */ 58: DispProgress(0x10); 59: ercd = init_device(); 60: if ( ercd < E_OK ) { 61: goto err_ret; 62: } 63: 64: /* Initialize subsystem */ 65: DispProgress(0x11); 66: ercd = init_subsystems(); 67: if ( ercd < E_OK ) { 68: goto err_ret; 69: } 70: 71: /* Initialize segment manager */ 72: DispProgress(0x12); 73: ercd = init_segmgr(); 74: if ( ercd < E_OK ) { 75: goto err_ret; 76: } 77: 78: /* Initialize memory manager */ 79: DispProgress(0x13); 80: ercd = init_memmgr(); 81: if ( ercd < E_OK ) { 82: goto err_ret; 83: } 84: 85: /* Initialize Imalloc */ 86: DispProgress(0x14); 87: ercd = init_Imalloc(); 88: if ( ercd < E_OK ) { 89: goto err_ret; 90: } 91: 92: return; 93: 94: err_ret: 95: #if USE_KERNEL_MESSAGE 96: tm_putstring((UB*)"!ERROR! init_kernel\n"); 97: #endif 98: tm_monitor(); /* Stop */ 99: } 100: 101: /* 102: * Start system 103: */ 104: EXPORT void start_system( void ) 105: { 106: ER ercd; 107: 108: /* Initialize segment manager */ 109: DispProgress(0x30); 110: ercd = start_segmgr(); 111: if ( ercd < E_OK ) { 112: goto err_ret; 113: } 114: 115: /* Start memory manager */ 116: DispProgress(0x31); 117: ercd = start_memmgr(); 118: if ( ercd < E_OK ) { 119: goto err_ret; 120: } 121: 122: /* Initialize system manager */ 123: DispProgress(0x32); 124: ercd = SystemManager(0, NULL); 125: if ( ercd < E_OK ) { 126: goto err_ret; 127: } 128: 129: /* Initialize library (libtk) 130: V/K/Smalloc is available after this. */ 131: DispProgress(0x33); 132: _InitLibtk(); 133: 134: /* Lower the initial task priority to initialize sequence 135: for the subsystem task at first. */ 136: tk_chg_pri(TSK_SELF, InitTaskPri); 137: 138: /* Start system dependent sequence */ 139: DispProgress(0x34); 140: ercd = start_device(); 141: if ( ercd < E_OK ) { 142: goto err_ret; 143: } 144: 145: /* Start subsystem */ 146: DispProgress(0x35); 147: ercd = start_subsystems(); 148: if ( ercd < E_OK ) { 149: goto err_ret; 150: } 151: 152: return; 153: 154: err_ret: 155: #if USE_KERNEL_MESSAGE 156: tm_putstring((UB*)"!ERROR! start_system\n"); 157: #endif 158: tm_monitor(); /* Stop */ 159: } 160: 161: /* 162: * Stop system 163: */ 164: EXPORT void shutdown_system( INT fin ) 165: { 166: /* Stop subsystem */ 167: finish_subsystems(); 168: 169: /* Platform dependent finalize sequence */ 170: finish_device(); 171: 172: /* Stop library (libtk) */ 173: _FinishLibtk(); 174: 175: /* Shutdown message output */ 176: #if USE_KERNEL_MESSAGE 177: if ( fin >= 0 ) { 178: tm_putstring((UB*)"\n<< SYSTEM SHUTDOWN >>\n"); 179: } 180: #endif 181: /* Stop T-Kernel/SM */ 182: SystemManager(-1, NULL); 183: 184: /* Stop memory manager */ 185: finish_memmgr(); 186: 187: /* Stop segment manager */ 188: finish_segmgr(); 189: 190: if ( fin < 0 ) { 191: /* Re-start sequence (platform dependent) */ 192: restart_device(fin); 193: } 194: 195: /* Stop system */ 196: t_kernel_exit(); 197: }