Ignore:
Timestamp:
Mar 6, 2019, 4:37:15 PM (5 years ago)
Author:
alain
Message:

Introduce three new types of vsegs (KCODE,KDATA,KDEV)
to map the kernel vsegs in the process VSL and GPT.
This now used by both the TSAR and the I86 architectures.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/kernel/kern/kernel_init.c

    r619 r623  
    33 *
    44 * Authors :  Mohamed Lamine Karaoui (2015)
    5  *            Alain Greiner  (2016,2017,2018)
     5 *            Alain Greiner  (2016,2017,2018,2019)
    66 *
    77 * Copyright (c) Sorbonne Universites
     
    113113cxy_t                local_cxy                               CONFIG_CACHE_LINE_ALIGNED;
    114114
    115 // This variable is used for CP0 cores synchronisation in kernel_init()
     115// This variable is used for core[0] cores synchronisation in kernel_init()
    116116__attribute__((section(".kdata")))
    117117xbarrier_t           global_barrier                          CONFIG_CACHE_LINE_ALIGNED;
     
    126126
    127127// 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.
    129129extern void kernel_init( boot_info_t * info );
    130130
     
    466466// These chdev descriptors are distributed on all clusters, using a modulo on a global
    467467// index, identically computed in all clusters.
    468 // This function is executed in all clusters by the CP0 core, that computes a global index
    469 // for all external chdevs. Each CP0 core creates only the chdevs that must be placed in
     468// 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
    470470// the local cluster, because the global index matches the local index.
    471471// The relevant entries in all copies of the devices directory are initialised.
     
    626626
    627627///////////////////////////////////////////////////////////////////////////////////////////
    628 // This function is called by CP0 in cluster 0 to allocate memory and initialize the PIC
     628// This function is called by core[0] in cluster 0 to allocate memory and initialize the PIC
    629629// device, namely the informations attached to the external IOPIC controller, that
    630630// must be replicated in all clusters (struct iopic_input).
     
    791791
    792792///////////////////////////////////////////////////////////////////////////////////////////
    793 // This function is called by all CP0s in all cluster to complete the PIC device
     793// This function is called by all core[0]s in all cluster to complete the PIC device
    794794// initialisation, namely the informations attached to the LAPIC controller.
    795795// This initialisation must be done after the IOPIC initialisation, but before other
     
    899899///////////////////////////////////////////////////////////////////////////////////////////
    900900// 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 // initializes the 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.
    903903// To comply with the multi-kernels paradigm, it accesses only local cluster memory, using
    904904// only information contained in the local boot_info_t structure, set by the bootloader.
    905 // Only CP0 in cluster 0 print the log messages.
     905// Only core[0] in cluster 0 print the log messages.
    906906///////////////////////////////////////////////////////////////////////////////////////////
    907907// @ info    : pointer on the local boot-info structure.
     
    925925
    926926    /////////////////////////////////////////////////////////////////////////////////
    927     // STEP 0 : Each core get its core identifier from boot_info, and makes
     927    // STEP 1 : Each core get its core identifier from boot_info, and makes
    928928    //          a partial initialisation of its private idle thread descriptor.
    929     //          CP0 initializes the "local_cxy" global variable.
    930     //          CP0 in cluster IO initializes the TXT0 chdev to print log messages.
     929    //          core[0] initializes the "local_cxy" global variable.
     930    //          core[0] in cluster[0] initializes the TXT0 chdev for log messages.
    931931    /////////////////////////////////////////////////////////////////////////////////
    932932
     
    936936                                  &core_gid );
    937937
    938     // all CP0s initialize cluster identifier
     938    // core[0] initialize cluster identifier
    939939    if( core_lid == 0 ) local_cxy = info->cxy;
    940940
     
    956956#endif
    957957
    958     // all CP0s initialize cluster info
     958    // core[0] initializes cluster info
    959959    if( core_lid == 0 ) cluster_info_init( info );
    960960
    961     // CP0 in cluster 0 initialises TXT0 chdev descriptor
     961    // core[0] in cluster[0] initialises TXT0 chdev descriptor
    962962    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    }
    963971
    964972    /////////////////////////////////////////////////////////////////////////////////
     
    970978#if DEBUG_KERNEL_INIT
    971979if( (core_lid ==  0) & (local_cxy == 0) )
    972 printk("\n[%s] : exit barrier 0 : TXT0 initialized / cycle %d\n",
     980printk("\n[%s] : exit barrier 1 : TXT0 initialized / cycle %d\n",
    973981__FUNCTION__, (uint32_t)hal_get_cycles() );
    974982#endif
    975983
    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)
    991990    if( core_lid == 0 ) dqdt_init();
    992991   
    993     // all CP0s initialize other cluster manager complex structures
     992    // core[0] initialize other cluster manager complex structures
    994993    if( core_lid == 0 )
    995994    {
     
    10121011#if DEBUG_KERNEL_INIT
    10131012if( (core_lid ==  0) & (local_cxy == 0) )
    1014 printk("\n[%s] : exit barrier 1 : clusters initialised / cycle %d\n",
     1013printk("\n[%s] : exit barrier 2 : cluster manager initialized / cycle %d\n",
    10151014__FUNCTION__, (uint32_t)hal_get_cycles() );
    10161015#endif
    10171016
    10181017    /////////////////////////////////////////////////////////////////////////////////
    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)
    10211020    /////////////////////////////////////////////////////////////////////////////////
    10221021
     
    10251024    core    = &cluster->core_tbl[core_lid];
    10261025
    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
     1036if( (core_lid ==  0) & (local_cxy == 0) )
     1037printk("\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,
    10311050    if( (core_lid == 0) && (local_cxy == 0) ) iopic_init( info );
    10321051   
     
    10391058#if DEBUG_KERNEL_INIT
    10401059if( (core_lid ==  0) & (local_cxy == 0) )
    1041 printk("\n[%s] : exit barrier 2 : PIC initialised / cycle %d\n",
     1060printk("\n[%s] : exit barrier 4 : MMU and IOPIC initialized / cycle %d\n",
    10421061__FUNCTION__, (uint32_t)hal_get_cycles() );
    10431062#endif
    10441063
    10451064    ////////////////////////////////////////////////////////////////////////////////
    1046     // STEP 3 : CP0 initializes the distibuted LAPIC descriptor.
    1047     //          CP0 initializes the internal chdev descriptors
    1048     //          CP0 initialize the local external chdev descriptors
     1065    // 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
    10491068    ////////////////////////////////////////////////////////////////////////////////
    10501069
    1051     // all CP0s initialize their local LAPIC extension,
     1070    // all core[0]s initialize their local LAPIC extension,
    10521071    if( core_lid == 0 ) lapic_init( info );
    10531072
    1054     // CP0 scan the internal (private) peripherals,
     1073    // core[0] scan the internal (private) peripherals,
    10551074    // and allocates memory for the corresponding chdev descriptors.
    10561075    if( core_lid == 0 ) internal_devices_init( info );
    10571076       
    10581077
    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),
    10611080    // and allocates memory for the chdev descriptors that must be placed
    10621081    // on the (cxy) cluster according to the global index value.
     
    10721091#if DEBUG_KERNEL_INIT
    10731092if( (core_lid ==  0) & (local_cxy == 0) )
    1074 printk("\n[%s] : exit barrier 3 : all chdevs initialised / cycle %d\n",
     1093printk("\n[%s] : exit barrier 5 : all chdevs initialised / cycle %d\n",
    10751094__FUNCTION__, (uint32_t)hal_get_cycles() );
    10761095#endif
     
    10821101   
    10831102    /////////////////////////////////////////////////////////////////////////////////
    1084     // STEP 4 : All cores enable IPI (Inter Procesor Interrupt),
     1103    // STEP 6 : All cores enable IPI (Inter Procesor Interrupt),
    10851104    //          Alh cores initialize IDLE thread.
    1086     //          Only CP0 in cluster 0 creates the VFS root inode.
     1105    //          Only core[0] in cluster[0] creates the VFS root inode.
    10871106    //          It access the boot device to initialize the file system context.
    10881107    /////////////////////////////////////////////////////////////////////////////////
     
    11071126#endif
    11081127
    1109     // CPO in cluster 0 creates the VFS root
     1128    // core[O] in cluster[0] creates the VFS root
    11101129    if( (core_lid ==  0) && (local_cxy == 0 ) )
    11111130    {
     
    11371156            // 4. create VFS root inode in cluster 0
    11381157            error = vfs_inode_create( FS_TYPE_FATFS,                       // fs_type
    1139                                       INODE_TYPE_DIR,                      // inode_type
    11401158                                      0,                                   // attr
    11411159                                      0,                                   // rights
     
    11501168            }
    11511169
    1152             // 5. update FATFS root inode extension 
     1170            // 5. update FATFS root inode "type" and "extend" fields 
    11531171            cxy_t         vfs_root_cxy = GET_CXY( vfs_root_inode_xp );
    11541172            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 );
    11551174            hal_remote_spt( XPTR( vfs_root_cxy , &vfs_root_ptr->extend ),
    11561175                            (void*)(intptr_t)root_dir_cluster );
     
    11891208#if DEBUG_KERNEL_INIT
    11901209if( (core_lid ==  0) & (local_cxy == 0) )
    1191 printk("\n[%s] : exit barrier 4 : VFS root (%x,%x) in cluster 0 / cycle %d\n",
     1210printk("\n[%s] : exit barrier 6 : VFS root (%x,%x) in cluster 0 / cycle %d\n",
    11921211__FUNCTION__, GET_CXY(process_zero.vfs_root_xp),
    11931212GET_PTR(process_zero.vfs_root_xp), (uint32_t)hal_get_cycles() );
     
    11951214
    11961215    /////////////////////////////////////////////////////////////////////////////////
    1197     // STEP 5 : Other CP0s allocate memory for the selected FS context,
    1198     //          and initialise both the local FS context and the local VFS context
    1199     //          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.
    12001219    //          They get the VFS root inode extended pointer from cluster 0.
    12011220    /////////////////////////////////////////////////////////////////////////////////
     
    12591278#if DEBUG_KERNEL_INIT
    12601279if( (core_lid ==  0) & (local_cxy == 1) )
    1261 printk("\n[%s] : exit barrier 5 : VFS root (%x,%x) in cluster 1 / cycle %d\n",
     1280printk("\n[%s] : exit barrier 7 : VFS root (%x,%x) in cluster 1 / cycle %d\n",
    12621281__FUNCTION__, GET_CXY(process_zero.vfs_root_xp),
    12631282GET_PTR(process_zero.vfs_root_xp), (uint32_t)hal_get_cycles() );
     
    12651284
    12661285    /////////////////////////////////////////////////////////////////////////////////
    1267     // STEP 6 : CP0 in cluster 0 makes the global DEVFS tree initialisation:
     1286    // STEP 8 : core[0] in cluster 0 makes the global DEVFS initialisation:
    12681287    //          It initializes the DEVFS context, and creates the DEVFS
    12691288    //          "dev" and "external" inodes in cluster 0.
     
    13091328#if DEBUG_KERNEL_INIT
    13101329if( (core_lid ==  0) & (local_cxy == 0) )
    1311 printk("\n[%s] : exit barrier 6 : DEVFS root initialized in cluster 0 / cycle %d\n",
     1330printk("\n[%s] : exit barrier 8 : DEVFS root initialized in cluster 0 / cycle %d\n",
    13121331__FUNCTION__, (uint32_t)hal_get_cycles() );
    13131332#endif
    13141333
    13151334    /////////////////////////////////////////////////////////////////////////////////
    1316     // STEP 7 : All CP0s complete in parallel the DEVFS tree initialization.
    1317     //          Each CP0 get the "dev" and "external" extended pointers from
     1335    // STEP 9 : All core[0]s complete in parallel the DEVFS initialization.
     1336    //          Each core[0] get the "dev" and "external" extended pointers from
    13181337    //          values stored in cluster 0.
    1319     //          Then each CP0 in cluster(i) creates the DEVFS "internal" directory,
     1338    //          Then each core[0] in cluster(i) creates the DEVFS "internal" directory,
    13201339    //          and creates the pseudo-files for all chdevs in cluster (i).
    13211340    /////////////////////////////////////////////////////////////////////////////////
     
    13461365#if DEBUG_KERNEL_INIT
    13471366if( (core_lid ==  0) & (local_cxy == 0) )
    1348 printk("\n[%s] : exit barrier 7 : DEV initialized in cluster 0 / cycle %d\n",
     1367printk("\n[%s] : exit barrier 9 : DEVFS initialized in cluster 0 / cycle %d\n",
    13491368__FUNCTION__, (uint32_t)hal_get_cycles() );
    13501369#endif
    13511370
    1352     /////////////////////////////////////////////////////////////////////////////////
    1353     // STEP 8 : CP0 in cluster 0 creates the first user process (process_init)
     1371#if( DEBUG_KERNEL_INIT & 1 )
     1372if( (core_lid ==  0) & (local_cxy == 0) )
     1373vfs_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.
    13541380    /////////////////////////////////////////////////////////////////////////////////
    13551381
    13561382    if( (core_lid == 0) && (local_cxy == 0) )
    13571383    {
    1358 
    1359 #if( DEBUG_KERNEL_INIT & 1 )
    1360 vfs_display( vfs_root_inode_xp );
    1361 #endif
    1362 
    13631384       process_init_create();
    13641385    }
    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_INIT
    1373 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 #endif
    13771386
    13781387#if (DEBUG_KERNEL_INIT & 1)
     
    13811390#endif
    13821391
    1383     /////////////////////////////////////////////////////////////////////////////////
    1384     // STEP 9 : CP0 in cluster 0 print banner
    1385     /////////////////////////////////////////////////////////////////////////////////
    1386    
    13871392    if( (core_lid == 0) && (local_cxy == 0) )
    13881393    {
    13891394        print_banner( (info->x_size * info->y_size) , info->cores_nr );
     1395    }
    13901396
    13911397#if( DEBUG_KERNEL_INIT & 1 )
     1398if( (core_lid ==  0) & (local_cxy == 0) )
    13921399printk("\n\n***** memory fooprint for main kernel objects\n\n"
    13931400                   " - thread descriptor  : %d bytes\n"
     
    14371444#endif
    14381445
    1439     }
     1446    // each core updates the register(s) definig the kernel
     1447    // entry points for interrupts, exceptions and syscalls...
     1448    hal_set_kentry();
    14401449
    14411450    // each core activates its private TICK IRQ
     
    14481457    /////////////////////////////////////////////////////////////////////////////////
    14491458
    1450 #if DEBUG_KERNEL_INIT
     1459#if( DEBUG_KERNEL_INIT & 1 )
    14511460thread_t * this = CURRENT_THREAD;
    14521461printk("\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.