Changeset 624 for trunk/kernel/kern


Ignore:
Timestamp:
Mar 12, 2019, 1:37:38 PM (5 years ago)
Author:
alain
Message:

Fix several bugs to use the instruction MMU in kernel mode
in replacement of the instruction address extension register,
and remove the "kentry" segment.

This version is running on the tsar_generic_iob" platform.

One interesting bug: the cp0_ebase defining the kernel entry point
(for interrupts, exceptions and syscalls) must be initialized
early in kernel_init(), because the VFS initialisation done by
kernel_ini() uses RPCs, and RPCs uses Inter-Processor-Interrup.

Location:
trunk/kernel/kern
Files:
6 edited

Legend:

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

    r623 r624  
    9797process_t            process_zero                            CONFIG_CACHE_LINE_ALIGNED;
    9898
    99 // This variable defines extended pointers on the distributed chdevs
     99// This variable defines a set of extended pointers on the distributed chdevs
    100100__attribute__((section(".kdata")))
    101101chdev_directory_t    chdev_dir                               CONFIG_CACHE_LINE_ALIGNED;
     
    125125vfs_ctx_t            fs_context[FS_TYPES_NR]                 CONFIG_CACHE_LINE_ALIGNED;
    126126
    127 // kernel_init is the entry point defined in hal/tsar_mips32/kernel.ld
    128 // It is used by the bootloader to tranfer control to kernel.
    129 extern void kernel_init( boot_info_t * info );
    130 
    131127// This array is used for debug, and describes the kernel locks usage,
    132128// It must be kept consistent with the defines in kernel_config.h file.
     129__attribute__((section(".kdata")))
    133130char * lock_type_str[] =
    134131{
     
    229226
    230227// intrumentation variables : cumulated costs per syscall type in cluster
     228
     229#if CONFIG_INSTRUMENTATION_SYSCALLS
     230__attribute__((section(".kdata")))
    231231uint32_t   syscalls_cumul_cost[SYSCALLS_NR];
    232232
    233 // intrumentation variables : number of syscalls per syscal type in cluster
     233__attribute__((section(".kdata")))
    234234uint32_t   syscalls_occurences[SYSCALLS_NR];
     235#endif
    235236
    236237///////////////////////////////////////////////////////////////////////////////////////////
     
    978979#if DEBUG_KERNEL_INIT
    979980if( (core_lid ==  0) & (local_cxy == 0) )
    980 printk("\n[%s] : exit barrier 1 : TXT0 initialized / cycle %d\n",
     981printk("\n[%s] exit barrier 1 : TXT0 initialized / cycle %d\n",
    981982__FUNCTION__, (uint32_t)hal_get_cycles() );
    982983#endif
     
    10111012#if DEBUG_KERNEL_INIT
    10121013if( (core_lid ==  0) & (local_cxy == 0) )
    1013 printk("\n[%s] : exit barrier 2 : cluster manager initialized / cycle %d\n",
     1014printk("\n[%s] exit barrier 2 : cluster manager initialized / cycle %d\n",
    10141015__FUNCTION__, (uint32_t)hal_get_cycles() );
    10151016#endif
    10161017
    10171018    /////////////////////////////////////////////////////////////////////////////////
    1018     // STEP 3 : core[0] initializes the process_zero descriptor,
     1019    // STEP 3 : all cores initialize the idle thread descriptor.
     1020    //          core[0] initializes the process_zero descriptor,
    10191021    //          including the kernel VMM (both GPT and VSL)
    10201022    /////////////////////////////////////////////////////////////////////////////////
     
    10241026    core    = &cluster->core_tbl[core_lid];
    10251027
     1028    // all cores update the register(s) defining the kernel
     1029    // entry points for interrupts, exceptions and syscalls,
     1030    // this must be done before VFS initialisation, because
     1031    // kernel_init() uses RPCs requiring IPIs...
     1032    hal_set_kentry();
     1033
     1034    // all cores initialize the idle thread descriptor
     1035    thread_idle_init( thread,
     1036                      THREAD_IDLE,
     1037                      &thread_idle_func,
     1038                      NULL,
     1039                      core_lid );
     1040
    10261041    // core[0] initializes the process_zero descriptor,
    10271042    if( core_lid == 0 ) process_zero_create( &process_zero , info );
     
    10351050#if DEBUG_KERNEL_INIT
    10361051if( (core_lid ==  0) & (local_cxy == 0) )
    1037 printk("\n[%s] : exit barrier 3 : kernel processs initialized / cycle %d\n",
     1052printk("\n[%s] exit barrier 3 : kernel processs initialized / cycle %d\n",
    10381053__FUNCTION__, (uint32_t)hal_get_cycles() );
    10391054#endif
     
    10581073#if DEBUG_KERNEL_INIT
    10591074if( (core_lid ==  0) & (local_cxy == 0) )
    1060 printk("\n[%s] : exit barrier 4 : MMU and IOPIC initialized / cycle %d\n",
     1075printk("\n[%s] exit barrier 4 : MMU and IOPIC initialized / cycle %d\n",
    10611076__FUNCTION__, (uint32_t)hal_get_cycles() );
    10621077#endif
     
    10911106#if DEBUG_KERNEL_INIT
    10921107if( (core_lid ==  0) & (local_cxy == 0) )
    1093 printk("\n[%s] : exit barrier 5 : all chdevs initialised / cycle %d\n",
     1108printk("\n[%s] exit barrier 5 : chdevs initialised / cycle %d\n",
    10941109__FUNCTION__, (uint32_t)hal_get_cycles() );
    10951110#endif
     
    11011116   
    11021117    /////////////////////////////////////////////////////////////////////////////////
    1103     // STEP 6 : All cores enable IPI (Inter Procesor Interrupt),
    1104     //          Alh cores initialize IDLE thread.
    1105     //          Only core[0] in cluster[0] creates the VFS root inode.
     1118    // STEP 6 : all cores enable IPI (Inter Procesor Interrupt),
     1119    //          all cores unblock the idle thread, and register it in scheduler.
     1120    //          core[0] in cluster[0] creates the VFS root inode.
    11061121    //          It access the boot device to initialize the file system context.
    11071122    /////////////////////////////////////////////////////////////////////////////////
     
    11111126    hal_enable_irq( &status );
    11121127
    1113     // all cores initialize the idle thread descriptor
    1114     thread_idle_init( thread,
    1115                       THREAD_IDLE,
    1116                       &thread_idle_func,
    1117                       NULL,
    1118                       core_lid );
    1119 
    1120     // all cores unblock idle thread, and register it in scheduler
     1128    // all cores unblock the idle thread, and register it in scheduler
    11211129    thread_unblock( XPTR( local_cxy , thread ) , THREAD_BLOCKED_GLOBAL );
    11221130    core->scheduler.idle = thread;
     
    11711179            cxy_t         vfs_root_cxy = GET_CXY( vfs_root_inode_xp );
    11721180            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 );
     1181            hal_remote_s32( XPTR( vfs_root_cxy , &vfs_root_ptr->type ), INODE_TYPE_DIR );
    11741182            hal_remote_spt( XPTR( vfs_root_cxy , &vfs_root_ptr->extend ),
    11751183                            (void*)(intptr_t)root_dir_cluster );
     
    12081216#if DEBUG_KERNEL_INIT
    12091217if( (core_lid ==  0) & (local_cxy == 0) )
    1210 printk("\n[%s] : exit barrier 6 : VFS root (%x,%x) in cluster 0 / cycle %d\n",
     1218printk("\n[%s] exit barrier 6 : VFS root (%x,%x) in cluster 0 / cycle %d\n",
    12111219__FUNCTION__, GET_CXY(process_zero.vfs_root_xp),
    12121220GET_PTR(process_zero.vfs_root_xp), (uint32_t)hal_get_cycles() );
     
    12781286#if DEBUG_KERNEL_INIT
    12791287if( (core_lid ==  0) & (local_cxy == 1) )
    1280 printk("\n[%s] : exit barrier 7 : VFS root (%x,%x) in cluster 1 / cycle %d\n",
     1288printk("\n[%s] exit barrier 7 : VFS root (%x,%x) in cluster 1 / cycle %d\n",
    12811289__FUNCTION__, GET_CXY(process_zero.vfs_root_xp),
    12821290GET_PTR(process_zero.vfs_root_xp), (uint32_t)hal_get_cycles() );
     
    13281336#if DEBUG_KERNEL_INIT
    13291337if( (core_lid ==  0) & (local_cxy == 0) )
    1330 printk("\n[%s] : exit barrier 8 : DEVFS root initialized in cluster 0 / cycle %d\n",
     1338printk("\n[%s] exit barrier 8 : DEVFS root initialized in cluster 0 / cycle %d\n",
    13311339__FUNCTION__, (uint32_t)hal_get_cycles() );
    13321340#endif
    13331341
    13341342    /////////////////////////////////////////////////////////////////////////////////
    1335     // STEP 9 : All core[0]s complete in parallel the DEVFS initialization.
     1343    // STEP 9 : In all clusters in parallel, core[0] completes DEVFS initialization.
    13361344    //          Each core[0] get the "dev" and "external" extended pointers from
    1337     //          values stored in cluster 0.
    1338     //          Then each core[0] in cluster(i) creates the DEVFS "internal" directory,
    1339     //          and creates the pseudo-files for all chdevs in cluster (i).
     1345    //          values stored in cluster(0), creates the DEVFS "internal" directory,
     1346    //          and creates the pseudo-files for all chdevs in local cluster.
    13401347    /////////////////////////////////////////////////////////////////////////////////
    13411348
     
    13651372#if DEBUG_KERNEL_INIT
    13661373if( (core_lid ==  0) & (local_cxy == 0) )
    1367 printk("\n[%s] : exit barrier 9 : DEVFS initialized in cluster 0 / cycle %d\n",
     1374printk("\n[%s] exit barrier 9 : DEVFS initialized in cluster 0 / cycle %d\n",
    13681375__FUNCTION__, (uint32_t)hal_get_cycles() );
    13691376#endif
     
    13841391       process_init_create();
    13851392    }
     1393
     1394#if DEBUG_KERNEL_INIT
     1395if( (core_lid ==  0) & (local_cxy == 0) )
     1396printk("\n[%s] exit barrier 10 : process_init created in cluster 0 / cycle %d\n",
     1397__FUNCTION__, (uint32_t)hal_get_cycles() );
     1398#endif
    13861399
    13871400#if (DEBUG_KERNEL_INIT & 1)
     
    14441457#endif
    14451458
    1446     // each core updates the register(s) definig the kernel
    1447     // entry points for interrupts, exceptions and syscalls...
    1448     hal_set_kentry();
    1449 
    14501459    // each core activates its private TICK IRQ
    14511460    dev_pic_enable_timer( CONFIG_SCHED_TICK_MS_PERIOD );
  • trunk/kernel/kern/process.c

    r623 r624  
    12091209
    12101210// check th_nr value
    1211 assert( (count > 0) , "process th_nr cannot be 0\n" );
     1211assert( (count > 0) , "process th_nr cannot be 0" );
    12121212
    12131213    // remove thread from th_tbl[]
     
    12491249// check parent process is the reference process
    12501250assert( (parent_process_xp == ref_xp ) ,
    1251 "parent process must be the reference process\n" );
     1251"parent process must be the reference process" );
    12521252
    12531253#if DEBUG_PROCESS_MAKE_FORK
     
    13521352// check main thread LTID
    13531353assert( (LTID_FROM_TRDID(thread->trdid) == 0) ,
    1354 "main thread must have LTID == 0\n" );
     1354"main thread must have LTID == 0" );
    13551355
    13561356#if( DEBUG_PROCESS_MAKE_FORK & 1 )
     
    15521552#endif
    15531553
     1554    // get pointer on VMM
     1555    vmm_t * vmm = &process->vmm;
     1556
    15541557    // get PID from local cluster manager for this kernel process
    15551558    error = cluster_pid_alloc( process , &pid );
     
    15711574    process->term_state = 0;
    15721575
    1573     // initialise kernel GPT and VSL, depending on architecture
    1574     hal_vmm_kernel_init( info );
     1576    // initilise VSL as empty
     1577    vmm->vsegs_nr = 0;
     1578        xlist_root_init( XPTR( local_cxy , &vmm->vsegs_root ) );
     1579        remote_rwlock_init( XPTR( local_cxy , &vmm->vsegs_lock ) , LOCK_VMM_VSL );
     1580
     1581    // initialise GPT as empty
     1582    error = hal_gpt_create( &vmm->gpt );
     1583
     1584    if( error )
     1585    {
     1586        printk("\n[PANIC] in %s : cannot create empty GPT\n", __FUNCTION__ );
     1587        hal_core_sleep();
     1588    }
     1589
     1590    // initialize GPT lock
     1591    remote_rwlock_init( XPTR( local_cxy , &vmm->gpt_lock ) , LOCK_VMM_GPT );
     1592   
     1593    // create kernel vsegs in GPT and VSL, as required by the hardware architecture
     1594    error = hal_vmm_kernel_init( info );
     1595
     1596    if( error )
     1597    {
     1598        printk("\n[PANIC] in %s : cannot create kernel vsegs in VMM\n", __FUNCTION__ );
     1599        hal_core_sleep();
     1600    }
    15751601
    15761602    // reset th_tbl[] array and associated fields
     
    16291655// check memory allocator
    16301656assert( (process != NULL),
    1631 "no memory for process descriptor in cluster %x\n", local_cxy  );
     1657"no memory for process descriptor in cluster %x", local_cxy  );
    16321658
    16331659    // set the CWD and VFS_ROOT fields in process descriptor
     
    16401666// check PID allocator
    16411667assert( (error == 0),
    1642 "cannot allocate PID in cluster %x\n", local_cxy );
     1668"cannot allocate PID in cluster %x", local_cxy );
    16431669
    16441670// check PID value
    16451671assert( (pid == 1) ,
    1646 "process INIT must be first process in cluster 0\n" );
     1672"process INIT must be first process in cluster 0" );
    16471673
    16481674    // initialize process descriptor / parent is local process_zero
     
    16691695
    16701696assert( (error == 0),
    1671 "failed to open file <%s>\n", CONFIG_PROCESS_INIT_PATH );
     1697"failed to open file <%s>", CONFIG_PROCESS_INIT_PATH );
    16721698
    16731699#if(DEBUG_PROCESS_INIT_CREATE & 1)
     
    16821708
    16831709assert( (error == 0),
    1684 "cannot access .elf file <%s>\n", CONFIG_PROCESS_INIT_PATH );
     1710"cannot access .elf file <%s>", CONFIG_PROCESS_INIT_PATH );
    16851711
    16861712#if(DEBUG_PROCESS_INIT_CREATE & 1)
     
    17261752
    17271753assert( (error == 0),
    1728 "cannot create main thread for <%s>\n", CONFIG_PROCESS_INIT_PATH );
     1754"cannot create main thread for <%s>", CONFIG_PROCESS_INIT_PATH );
    17291755
    17301756assert( (thread->trdid == 0),
    1731 "main thread must have index 0 for <%s>\n", CONFIG_PROCESS_INIT_PATH );
     1757"main thread must have index 0 for <%s>", CONFIG_PROCESS_INIT_PATH );
    17321758
    17331759#if(DEBUG_PROCESS_INIT_CREATE & 1)
     
    18161842
    18171843        assert( (txt_file_xp != XPTR_NULL) ,
    1818         "process must be attached to one TXT terminal\n" );
     1844        "process must be attached to one TXT terminal" );
    18191845
    18201846        // get TXT_RX chdev pointers
     
    20122038    // check owner cluster
    20132039    assert( (process_cxy == CXY_FROM_PID( process_pid )) ,
    2014     "process descriptor not in owner cluster\n" );
     2040    "process descriptor not in owner cluster" );
    20152041
    20162042    // get extended pointer on stdin pseudo file
     
    20672093    // check owner cluster
    20682094    assert( (process_cxy == CXY_FROM_PID( process_pid )) ,
    2069     "process descriptor not in owner cluster\n" );
     2095    "process descriptor not in owner cluster" );
    20702096
    20712097    // get extended pointer on stdin pseudo file
     
    21982224pid_t process_pid = hal_remote_l32( XPTR( process_cxy , &process_ptr->pid ) );
    21992225assert( (process_cxy == CXY_FROM_PID( process_pid )) ,
    2200 "process descriptor not in owner cluster\n" );
     2226"process descriptor not in owner cluster" );
    22012227
    22022228    // get extended pointer on stdin pseudo file
  • trunk/kernel/kern/rpc.c

    r623 r624  
    8181    &rpc_vmm_create_vseg_server,           // 27
    8282    &rpc_vmm_set_cow_server,               // 28
    83     &rpc_vmm_display_server,               // 29
     83    &rpc_hal_vmm_display_server,               // 29
    8484};
    8585
     
    27292729
    27302730/////////////////////////////////////////////
    2731 void rpc_vmm_display_client( cxy_t       cxy,
     2731void rpc_hal_vmm_display_client( cxy_t       cxy,
    27322732                             process_t * process,
    27332733                             bool_t      detailed )
     
    27652765
    27662766////////////////////////////////////////
    2767 void rpc_vmm_display_server( xptr_t xp )
     2767void rpc_hal_vmm_display_server( xptr_t xp )
    27682768{
    27692769#if DEBUG_RPC_VMM_DISPLAY
     
    27872787   
    27882788    // call local kernel function
    2789     vmm_display( process , detailed );
     2789    hal_vmm_display( process , detailed );
    27902790
    27912791#if DEBUG_RPC_VMM_DISPLAY
  • trunk/kernel/kern/rpc.h

    r623 r624  
    683683 * @ detailed    : [in]  detailed display if true.
    684684 **********************************************************************************/
    685 void rpc_vmm_display_client( cxy_t              cxy,
     685void rpc_hal_vmm_display_client( cxy_t              cxy,
    686686                             struct process_s * process,
    687687                             bool_t             detailed );
    688688
    689 void rpc_vmm_display_server( xptr_t xp );
     689void rpc_hal_vmm_display_server( xptr_t xp );
    690690
    691691
  • trunk/kernel/kern/scheduler.c

    r619 r624  
    488488 
    489489#if (DEBUG_SCHED_YIELD & 0x1)
    490 if( sched->trace )
     490// if( sched->trace )
     491if( (uint32_t)hal_get_cycles() > DEBUG_SCHED_YIELD )
    491492sched_display( lid );
    492493#endif
     
    541542
    542543#if DEBUG_SCHED_YIELD
    543 if( sched->trace )
     544// if( sched->trace )
     545if( (uint32_t)hal_get_cycles() > DEBUG_SCHED_YIELD )
    544546printk("\n[%s] core[%x,%d] / cause = %s\n"
    545547"      thread %x (%s) (%x,%x) => thread %x (%s) (%x,%x) / cycle %d\n",
     
    558560
    559561#if (DEBUG_SCHED_YIELD & 1)
    560 if( sched->trace )
     562// if( sched->trace )
     563if(uint32_t)hal_get_cycles() > DEBUG_SCHED_YIELD )
    561564printk("\n[%s] core[%x,%d] / cause = %s\n"
    562565"      thread %x (%s) (%x,%x) continue / cycle %d\n",
     
    601604
    602605    nolock_printk("\n***** threads on core[%x,%d] / current %x / rpc_threads %d / cycle %d\n",
    603     local_cxy , core->lid, sched->current, LOCAL_CLUSTER->rpc_threads[lid],
     606    local_cxy , lid, sched->current, LOCAL_CLUSTER->rpc_threads[lid],
    604607    (uint32_t)hal_get_cycles() );
    605608
  • trunk/kernel/kern/thread.c

    r623 r624  
    389389printk("\n[%s] CPU & FPU contexts created\n",
    390390__FUNCTION__, thread->trdid );
    391 vmm_display( process , true );
     391hal_vmm_display( process , true );
    392392#endif
    393393
     
    689689printk("\n[%s] thread[%x,%x] set CPU context & jump to user code / cycle %d\n",
    690690__FUNCTION__, process->pid, thread->trdid, cycle );
    691 vmm_display( process , true );
     691hal_vmm_display( process , true );
    692692#endif
    693693
     
    13521352        "hold %d busylock(s) / cycle %d\n",
    13531353        func_str, thread->process->pid, thread->trdid,
    1354         thread->busylocks, (uint32_t)hal_get_cycles() );
     1354        thread->busylocks - 1, (uint32_t)hal_get_cycles() );
    13551355
    13561356#if DEBUG_BUSYLOCK
Note: See TracChangeset for help on using the changeset viewer.