Changeset 623 for trunk/kernel/kern/kernel_init.c
- Timestamp:
- Mar 6, 2019, 4:37:15 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/kern/kernel_init.c
r619 r623 3 3 * 4 4 * Authors : Mohamed Lamine Karaoui (2015) 5 * Alain Greiner (2016,2017,2018 )5 * Alain Greiner (2016,2017,2018,2019) 6 6 * 7 7 * Copyright (c) Sorbonne Universites … … 113 113 cxy_t local_cxy CONFIG_CACHE_LINE_ALIGNED; 114 114 115 // This variable is used for CP0cores synchronisation in kernel_init()115 // This variable is used for core[0] cores synchronisation in kernel_init() 116 116 __attribute__((section(".kdata"))) 117 117 xbarrier_t global_barrier CONFIG_CACHE_LINE_ALIGNED; … … 126 126 127 127 // kernel_init is the entry point defined in hal/tsar_mips32/kernel.ld 128 // It is used by the bootloader .128 // It is used by the bootloader to tranfer control to kernel. 129 129 extern void kernel_init( boot_info_t * info ); 130 130 … … 466 466 // These chdev descriptors are distributed on all clusters, using a modulo on a global 467 467 // index, identically computed in all clusters. 468 // This function is executed in all clusters by the CP0core, that computes a global index469 // for all external chdevs. Each CP0core creates only the chdevs that must be placed in468 // This function is executed in all clusters by the core[0] core, that computes a global index 469 // for all external chdevs. Each core[0] core creates only the chdevs that must be placed in 470 470 // the local cluster, because the global index matches the local index. 471 471 // The relevant entries in all copies of the devices directory are initialised. … … 626 626 627 627 /////////////////////////////////////////////////////////////////////////////////////////// 628 // This function is called by CP0in cluster 0 to allocate memory and initialize the PIC628 // This function is called by core[0] in cluster 0 to allocate memory and initialize the PIC 629 629 // device, namely the informations attached to the external IOPIC controller, that 630 630 // must be replicated in all clusters (struct iopic_input). … … 791 791 792 792 /////////////////////////////////////////////////////////////////////////////////////////// 793 // This function is called by all CP0s in all cluster to complete the PIC device793 // This function is called by all core[0]s in all cluster to complete the PIC device 794 794 // initialisation, namely the informations attached to the LAPIC controller. 795 795 // This initialisation must be done after the IOPIC initialisation, but before other … … 899 899 /////////////////////////////////////////////////////////////////////////////////////////// 900 900 // This function is the entry point for the kernel initialisation. 901 // It is executed by all cores in all clusters, but only core[0] , called CP0,902 // initializesthe shared resources such as the cluster manager, or the local peripherals.901 // It is executed by all cores in all clusters, but only core[0] initializes 902 // the shared resources such as the cluster manager, or the local peripherals. 903 903 // To comply with the multi-kernels paradigm, it accesses only local cluster memory, using 904 904 // only information contained in the local boot_info_t structure, set by the bootloader. 905 // Only CP0in cluster 0 print the log messages.905 // Only core[0] in cluster 0 print the log messages. 906 906 /////////////////////////////////////////////////////////////////////////////////////////// 907 907 // @ info : pointer on the local boot-info structure. … … 925 925 926 926 ///////////////////////////////////////////////////////////////////////////////// 927 // STEP 0: Each core get its core identifier from boot_info, and makes927 // STEP 1 : Each core get its core identifier from boot_info, and makes 928 928 // a partial initialisation of its private idle thread descriptor. 929 // CP0initializes the "local_cxy" global variable.930 // CP0 in cluster IO initializes the TXT0 chdev to printlog messages.929 // core[0] initializes the "local_cxy" global variable. 930 // core[0] in cluster[0] initializes the TXT0 chdev for log messages. 931 931 ///////////////////////////////////////////////////////////////////////////////// 932 932 … … 936 936 &core_gid ); 937 937 938 // all CP0sinitialize cluster identifier938 // core[0] initialize cluster identifier 939 939 if( core_lid == 0 ) local_cxy = info->cxy; 940 940 … … 956 956 #endif 957 957 958 // all CP0s initializecluster info958 // core[0] initializes cluster info 959 959 if( core_lid == 0 ) cluster_info_init( info ); 960 960 961 // CP0 in cluster 0initialises TXT0 chdev descriptor961 // core[0] in cluster[0] initialises TXT0 chdev descriptor 962 962 if( (core_lid == 0) && (core_cxy == 0) ) txt0_device_init( info ); 963 964 // all cores check identifiers 965 if( error ) 966 { 967 printk("\n[PANIC] in %s : illegal core : gid %x / cxy %x / lid %d", 968 __FUNCTION__, core_lid, core_cxy, core_lid ); 969 hal_core_sleep(); 970 } 963 971 964 972 ///////////////////////////////////////////////////////////////////////////////// … … 970 978 #if DEBUG_KERNEL_INIT 971 979 if( (core_lid == 0) & (local_cxy == 0) ) 972 printk("\n[%s] : exit barrier 0: TXT0 initialized / cycle %d\n",980 printk("\n[%s] : exit barrier 1 : TXT0 initialized / cycle %d\n", 973 981 __FUNCTION__, (uint32_t)hal_get_cycles() ); 974 982 #endif 975 983 976 ///////////////////////////////////////////////////////////////////////////// 977 // STEP 1 : all cores check core identifier. 978 // CP0 initializes the local cluster manager. 979 // This includes the memory allocators. 980 ///////////////////////////////////////////////////////////////////////////// 981 982 // all cores check identifiers 983 if( error ) 984 { 985 printk("\n[PANIC] in %s : illegal core : gid %x / cxy %x / lid %d", 986 __FUNCTION__, core_lid, core_cxy, core_lid ); 987 hal_core_sleep(); 988 } 989 990 // all CP0s initialise DQDT (only CPO in cluster 0 build the quad-tree) 984 ///////////////////////////////////////////////////////////////////////////////// 985 // STEP 2 : core[0] initializes the cluter manager, 986 // including the physical memory allocator. 987 ///////////////////////////////////////////////////////////////////////////////// 988 989 // core[0] initialises DQDT (only core[0] in cluster 0 build the quad-tree) 991 990 if( core_lid == 0 ) dqdt_init(); 992 991 993 // all CP0sinitialize other cluster manager complex structures992 // core[0] initialize other cluster manager complex structures 994 993 if( core_lid == 0 ) 995 994 { … … 1012 1011 #if DEBUG_KERNEL_INIT 1013 1012 if( (core_lid == 0) & (local_cxy == 0) ) 1014 printk("\n[%s] : exit barrier 1 : clusters initialised / cycle %d\n",1013 printk("\n[%s] : exit barrier 2 : cluster manager initialized / cycle %d\n", 1015 1014 __FUNCTION__, (uint32_t)hal_get_cycles() ); 1016 1015 #endif 1017 1016 1018 1017 ///////////////////////////////////////////////////////////////////////////////// 1019 // STEP 2 : CP0 initializes the process_zero descriptor.1020 // CP0 in cluster 0 initializes the IOPIC device.1018 // STEP 3 : core[0] initializes the process_zero descriptor, 1019 // including the kernel VMM (both GPT and VSL) 1021 1020 ///////////////////////////////////////////////////////////////////////////////// 1022 1021 … … 1025 1024 core = &cluster->core_tbl[core_lid]; 1026 1025 1027 // all CP0s initialize the process_zero descriptor 1028 if( core_lid == 0 ) process_zero_create( &process_zero ); 1029 1030 // CP0 in cluster 0 initializes the PIC chdev, 1026 // core[0] initializes the process_zero descriptor, 1027 if( core_lid == 0 ) process_zero_create( &process_zero , info ); 1028 1029 ///////////////////////////////////////////////////////////////////////////////// 1030 if( core_lid == 0 ) xbarrier_wait( XPTR( 0 , &global_barrier ), 1031 (info->x_size * info->y_size) ); 1032 barrier_wait( &local_barrier , info->cores_nr ); 1033 ///////////////////////////////////////////////////////////////////////////////// 1034 1035 #if DEBUG_KERNEL_INIT 1036 if( (core_lid == 0) & (local_cxy == 0) ) 1037 printk("\n[%s] : exit barrier 3 : kernel processs initialized / cycle %d\n", 1038 __FUNCTION__, (uint32_t)hal_get_cycles() ); 1039 #endif 1040 1041 ///////////////////////////////////////////////////////////////////////////////// 1042 // STEP 4 : all cores initialize their private MMU 1043 // core[0] in cluster 0 initializes the IOPIC device. 1044 ///////////////////////////////////////////////////////////////////////////////// 1045 1046 // all cores initialise their MMU 1047 hal_mmu_init( &process_zero.vmm.gpt ); 1048 1049 // core[0] in cluster[0] initializes the PIC chdev, 1031 1050 if( (core_lid == 0) && (local_cxy == 0) ) iopic_init( info ); 1032 1051 … … 1039 1058 #if DEBUG_KERNEL_INIT 1040 1059 if( (core_lid == 0) & (local_cxy == 0) ) 1041 printk("\n[%s] : exit barrier 2 : PIC initialised / cycle %d\n",1060 printk("\n[%s] : exit barrier 4 : MMU and IOPIC initialized / cycle %d\n", 1042 1061 __FUNCTION__, (uint32_t)hal_get_cycles() ); 1043 1062 #endif 1044 1063 1045 1064 //////////////////////////////////////////////////////////////////////////////// 1046 // STEP 3 : CP0initializes the distibuted LAPIC descriptor.1047 // CP0initializes the internal chdev descriptors1048 // CP0initialize the local external chdev descriptors1065 // STEP 5 : core[0] initializes the distibuted LAPIC descriptor. 1066 // core[0] initializes the internal chdev descriptors 1067 // core[0] initialize the local external chdev descriptors 1049 1068 //////////////////////////////////////////////////////////////////////////////// 1050 1069 1051 // all CP0s initialize their local LAPIC extension,1070 // all core[0]s initialize their local LAPIC extension, 1052 1071 if( core_lid == 0 ) lapic_init( info ); 1053 1072 1054 // CP0scan the internal (private) peripherals,1073 // core[0] scan the internal (private) peripherals, 1055 1074 // and allocates memory for the corresponding chdev descriptors. 1056 1075 if( core_lid == 0 ) internal_devices_init( info ); 1057 1076 1058 1077 1059 // All CP0s contribute to initialise external peripheral chdev descriptors.1060 // Each CP0[cxy] scan the set of external (shared) peripherals (but the TXT0),1078 // All core[0]s contribute to initialise external peripheral chdev descriptors. 1079 // Each core[0][cxy] scan the set of external (shared) peripherals (but the TXT0), 1061 1080 // and allocates memory for the chdev descriptors that must be placed 1062 1081 // on the (cxy) cluster according to the global index value. … … 1072 1091 #if DEBUG_KERNEL_INIT 1073 1092 if( (core_lid == 0) & (local_cxy == 0) ) 1074 printk("\n[%s] : exit barrier 3: all chdevs initialised / cycle %d\n",1093 printk("\n[%s] : exit barrier 5 : all chdevs initialised / cycle %d\n", 1075 1094 __FUNCTION__, (uint32_t)hal_get_cycles() ); 1076 1095 #endif … … 1082 1101 1083 1102 ///////////////////////////////////////////////////////////////////////////////// 1084 // STEP 4: All cores enable IPI (Inter Procesor Interrupt),1103 // STEP 6 : All cores enable IPI (Inter Procesor Interrupt), 1085 1104 // Alh cores initialize IDLE thread. 1086 // Only CP0 in cluster 0creates the VFS root inode.1105 // Only core[0] in cluster[0] creates the VFS root inode. 1087 1106 // It access the boot device to initialize the file system context. 1088 1107 ///////////////////////////////////////////////////////////////////////////////// … … 1107 1126 #endif 1108 1127 1109 // CPO in cluster 0creates the VFS root1128 // core[O] in cluster[0] creates the VFS root 1110 1129 if( (core_lid == 0) && (local_cxy == 0 ) ) 1111 1130 { … … 1137 1156 // 4. create VFS root inode in cluster 0 1138 1157 error = vfs_inode_create( FS_TYPE_FATFS, // fs_type 1139 INODE_TYPE_DIR, // inode_type1140 1158 0, // attr 1141 1159 0, // rights … … 1150 1168 } 1151 1169 1152 // 5. update FATFS root inode extension1170 // 5. update FATFS root inode "type" and "extend" fields 1153 1171 cxy_t vfs_root_cxy = GET_CXY( vfs_root_inode_xp ); 1154 1172 vfs_inode_t * vfs_root_ptr = GET_PTR( vfs_root_inode_xp ); 1173 hal_remote_s32( XPTR( vfs_root_cxy , &vfs_root_ptr->extend ), INODE_TYPE_DIR ); 1155 1174 hal_remote_spt( XPTR( vfs_root_cxy , &vfs_root_ptr->extend ), 1156 1175 (void*)(intptr_t)root_dir_cluster ); … … 1189 1208 #if DEBUG_KERNEL_INIT 1190 1209 if( (core_lid == 0) & (local_cxy == 0) ) 1191 printk("\n[%s] : exit barrier 4: VFS root (%x,%x) in cluster 0 / cycle %d\n",1210 printk("\n[%s] : exit barrier 6 : VFS root (%x,%x) in cluster 0 / cycle %d\n", 1192 1211 __FUNCTION__, GET_CXY(process_zero.vfs_root_xp), 1193 1212 GET_PTR(process_zero.vfs_root_xp), (uint32_t)hal_get_cycles() ); … … 1195 1214 1196 1215 ///////////////////////////////////////////////////////////////////////////////// 1197 // STEP 5 : Other CP0s allocate memory for the selected FS context,1198 // and initialise both the local FS context and the local VFS context1199 // from values stored in cluster 0.1216 // STEP 7 : In all other clusters than cluster[0], the core[0] allocates memory 1217 // for the selected FS context, and initialise the local FS context and 1218 // the local VFS context from values stored in cluster 0. 1200 1219 // They get the VFS root inode extended pointer from cluster 0. 1201 1220 ///////////////////////////////////////////////////////////////////////////////// … … 1259 1278 #if DEBUG_KERNEL_INIT 1260 1279 if( (core_lid == 0) & (local_cxy == 1) ) 1261 printk("\n[%s] : exit barrier 5: VFS root (%x,%x) in cluster 1 / cycle %d\n",1280 printk("\n[%s] : exit barrier 7 : VFS root (%x,%x) in cluster 1 / cycle %d\n", 1262 1281 __FUNCTION__, GET_CXY(process_zero.vfs_root_xp), 1263 1282 GET_PTR(process_zero.vfs_root_xp), (uint32_t)hal_get_cycles() ); … … 1265 1284 1266 1285 ///////////////////////////////////////////////////////////////////////////////// 1267 // STEP 6 : CP0 in cluster 0 makes the global DEVFS treeinitialisation:1286 // STEP 8 : core[0] in cluster 0 makes the global DEVFS initialisation: 1268 1287 // It initializes the DEVFS context, and creates the DEVFS 1269 1288 // "dev" and "external" inodes in cluster 0. … … 1309 1328 #if DEBUG_KERNEL_INIT 1310 1329 if( (core_lid == 0) & (local_cxy == 0) ) 1311 printk("\n[%s] : exit barrier 6: DEVFS root initialized in cluster 0 / cycle %d\n",1330 printk("\n[%s] : exit barrier 8 : DEVFS root initialized in cluster 0 / cycle %d\n", 1312 1331 __FUNCTION__, (uint32_t)hal_get_cycles() ); 1313 1332 #endif 1314 1333 1315 1334 ///////////////////////////////////////////////////////////////////////////////// 1316 // STEP 7 : All CP0s complete in parallel the DEVFS treeinitialization.1317 // Each CP0get the "dev" and "external" extended pointers from1335 // STEP 9 : All core[0]s complete in parallel the DEVFS initialization. 1336 // Each core[0] get the "dev" and "external" extended pointers from 1318 1337 // values stored in cluster 0. 1319 // Then each CP0in cluster(i) creates the DEVFS "internal" directory,1338 // Then each core[0] in cluster(i) creates the DEVFS "internal" directory, 1320 1339 // and creates the pseudo-files for all chdevs in cluster (i). 1321 1340 ///////////////////////////////////////////////////////////////////////////////// … … 1346 1365 #if DEBUG_KERNEL_INIT 1347 1366 if( (core_lid == 0) & (local_cxy == 0) ) 1348 printk("\n[%s] : exit barrier 7 : DEVinitialized in cluster 0 / cycle %d\n",1367 printk("\n[%s] : exit barrier 9 : DEVFS initialized in cluster 0 / cycle %d\n", 1349 1368 __FUNCTION__, (uint32_t)hal_get_cycles() ); 1350 1369 #endif 1351 1370 1352 ///////////////////////////////////////////////////////////////////////////////// 1353 // STEP 8 : CP0 in cluster 0 creates the first user process (process_init) 1371 #if( DEBUG_KERNEL_INIT & 1 ) 1372 if( (core_lid == 0) & (local_cxy == 0) ) 1373 vfs_display( vfs_root_inode_xp ); 1374 #endif 1375 1376 ///////////////////////////////////////////////////////////////////////////////// 1377 // STEP 10 : core[0] in cluster 0 creates the first user process (process_init). 1378 // This include the first user process VMM (GPT and VSL) creation. 1379 // Finally, it prints the ALMOS-MKH banner. 1354 1380 ///////////////////////////////////////////////////////////////////////////////// 1355 1381 1356 1382 if( (core_lid == 0) && (local_cxy == 0) ) 1357 1383 { 1358 1359 #if( DEBUG_KERNEL_INIT & 1 )1360 vfs_display( vfs_root_inode_xp );1361 #endif1362 1363 1384 process_init_create(); 1364 1385 } 1365 1366 /////////////////////////////////////////////////////////////////////////////////1367 if( core_lid == 0 ) xbarrier_wait( XPTR( 0 , &global_barrier ),1368 (info->x_size * info->y_size) );1369 barrier_wait( &local_barrier , info->cores_nr );1370 /////////////////////////////////////////////////////////////////////////////////1371 1372 #if DEBUG_KERNEL_INIT1373 if( (core_lid == 0) & (local_cxy == 0) )1374 printk("\n[%s] : exit barrier 8 : process init created / cycle %d\n",1375 __FUNCTION__, (uint32_t)hal_get_cycles() );1376 #endif1377 1386 1378 1387 #if (DEBUG_KERNEL_INIT & 1) … … 1381 1390 #endif 1382 1391 1383 /////////////////////////////////////////////////////////////////////////////////1384 // STEP 9 : CP0 in cluster 0 print banner1385 /////////////////////////////////////////////////////////////////////////////////1386 1387 1392 if( (core_lid == 0) && (local_cxy == 0) ) 1388 1393 { 1389 1394 print_banner( (info->x_size * info->y_size) , info->cores_nr ); 1395 } 1390 1396 1391 1397 #if( DEBUG_KERNEL_INIT & 1 ) 1398 if( (core_lid == 0) & (local_cxy == 0) ) 1392 1399 printk("\n\n***** memory fooprint for main kernel objects\n\n" 1393 1400 " - thread descriptor : %d bytes\n" … … 1437 1444 #endif 1438 1445 1439 } 1446 // each core updates the register(s) definig the kernel 1447 // entry points for interrupts, exceptions and syscalls... 1448 hal_set_kentry(); 1440 1449 1441 1450 // each core activates its private TICK IRQ … … 1448 1457 ///////////////////////////////////////////////////////////////////////////////// 1449 1458 1450 #if DEBUG_KERNEL_INIT1459 #if( DEBUG_KERNEL_INIT & 1 ) 1451 1460 thread_t * this = CURRENT_THREAD; 1452 1461 printk("\n[%s] : thread[%x,%x] on core[%x,%d] jumps to thread_idle_func() / cycle %d\n",
Note: See TracChangeset
for help on using the changeset viewer.