Changeset 204 for trunk/kernel/kern


Ignore:
Timestamp:
Jul 17, 2017, 8:42:59 AM (7 years ago)
Author:
alain
Message:

Bug fix in kernel_init
-This line, and those below, will be ignored--

M params.mk
M kernel_config.h
M Makefile
M hdd/virt_hdd.dmg
M tools/bootloader_tsar/boot.c
M kernel/libk/bits.h
M kernel/libk/elf.c
M kernel/libk/xhtab.c
M kernel/libk/elf.h
M kernel/libk/xhtab.h
M kernel/devices/dev_pic.c
M kernel/mm/vmm.c
M kernel/mm/mapper.c
M kernel/mm/mapper.h
M kernel/vfs/devfs.h
M kernel/vfs/vfs.c
M kernel/vfs/vfs.h
M kernel/vfs/devfs.c
M kernel/kern/chdev.h
M kernel/kern/kernel_init.c
M kernel/kern/process.c
M kernel/kern/process.h
M hal/tsar_mips32/core/hal_remote.c
M hal/tsar_mips32/drivers/soclib_pic.c

Location:
trunk/kernel/kern
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/kernel/kern/chdev.h

    r188 r204  
    4848 * Therefore a given I/O operation involve generally three clusters:
    4949 * - the client cluster, containing the client thread,
    50  * - the server cluster, containing the chdev and the client thread,
    51  * - the I/O cluster containing the physical device.
     50 * - the server cluster, containing the chdev and the server thread,
     51 * - the I/O cluster, containing the physical device.
    5252 *****************************************************************************************/
    5353
     
    6666
    6767/******************************************************************************************
    68  * This define the generic prototypes for the three functions that must be defined
     68 * This define the generic prototypes for the two functions that must be defined
    6969 * by all drivers implementing a generic device:
    70  * - "init"    : device initialisation.
    7170 * - "cmd"     : start an I/O operation.
    7271 * - "isr"     : complete an I/O operation.
    73  * The "init" function is called by kernel_init() to initialise the hardware device.
    74  * The "cmd" and "isr" are registered in the generic chdev descriptor by kernel_init(),
     72 * The "cmd" and "isr" are registered in the generic chdev descriptor at kernel init,
    7573 * and are called to start and complete an I/O operation. 
    7674*****************************************************************************************/
     
    8583 * provide the same set of operations and the same driver API.
    8684 * This enum must be consistent with the enum in files arch_info.h, and arch_class.py.
     85 *
     86 * WARNING : The ICU device exist in boot_info to specify the base address of the
     87 *           distributed LAPIC controler, but it does not exist as a chdev in the kernel,
     88 *           as it is hidden in the driver associated to the PIC device.
    8789 *****************************************************************************************/
    8890 
     
    99101        DEV_FUNC_TIM   =  8,
    100102        DEV_FUNC_TXT   =  9,
    101     DEV_FUNC_ICU   = 10,
     103    DEV_FUNC_ICU   = 10,   
    102104    DEV_FUNC_PIC   = 11,
    103105
  • trunk/kernel/kern/kernel_init.c

    r188 r204  
    3333#include <list.h>
    3434#include <xlist.h>
     35#include <xhtab.h>
    3536#include <thread.h>
    3637#include <scheduler.h>
     
    245246        func        = FUNC_FROM_TYPE( dev_tbl[i].type );
    246247        impl        = IMPL_FROM_TYPE( dev_tbl[i].type );
    247 
     248 
    248249        //////////////////////////
    249250        if( func == DEV_FUNC_MMC ) 
     
    553554    }
    554555
    555     kinit_dmsg("\n[INFO] %s created IOPIC chdev in cluster %x at cycle %d\n",
     556    kinit_dmsg("\n[INFO] %s created PIC chdev in cluster %x at cycle %d\n",
    556557               __FUNCTION__ , local_cxy , (uint32_t)hal_time_stamp() );
    557558   
     
    672673void kernel_init( boot_info_t * info )
    673674{
    674     lid_t        core_lid = -1;        // running core local index
    675     cxy_t        core_cxy = -1;        // running core cluster identifier
    676     gid_t        core_gid;             // running core hardware identifier
    677     cluster_t  * cluster;              // pointer on local cluster manager
    678     core_t     * core;                 // pointer on running core descriptor
    679     thread_t   * thread;               // pointer on idle thread descriptor
    680     xptr_t       vfs_root_inode_xp;    // extended pointer on VFS root inode
    681 //  xptr_t       devfs_root_inode_xp;  // extended pointer on DEVFS root inode
     675    lid_t        core_lid = -1;             // running core local index
     676    cxy_t        core_cxy = -1;             // running core cluster identifier
     677    gid_t        core_gid;                  // running core hardware identifier
     678    cluster_t  * cluster;                   // pointer on local cluster manager
     679    core_t     * core;                      // pointer on running core descriptor
     680    thread_t   * thread;                    // pointer on idle thread descriptor
     681
     682    xptr_t       vfs_root_inode_xp;         // extended pointer on VFS root inode
     683    xptr_t       devfs_dev_inode_xp;        // extended pointer on DEVFS dev inode   
     684    xptr_t       devfs_external_inode_xp;   // extended pointer on DEVFS external inode       
     685    xptr_t       devfs_internal_inode_xp;   // extended pointer on DEVFS internal inode       
     686
    682687    error_t      error;
    683688
     
    958963
    959964    /////////////////////////////////////////////////////////////////////////////////
    960     // global &local synchro to protect File System initialisation
    961965    if( core_lid == 0 ) remote_barrier( XPTR( io_cxy , &global_barrier ),
    962966                                        (info->x_size * info->y_size) );
    963967    barrier_wait( &local_barrier , info->cores_nr );
     968    /////////////////////////////////////////////////////////////////////////////////
    964969
    965970    if( (core_lid ==  0) && (local_cxy == 0) )
     
    970975    /////////////////////////////////////////////////////////////////////////////////
    971976    // STEP 6 : CP0 in cluster IO makes the global DEVFS tree initialisation:
    972     //          It creates the DEVFS root directory and the DEVFS "external"
    973     //          diretory in cluster IO and mount these inodes into VFS.
     977    //          It creates the DEVFS directory "dev", and the DEVFS "external"
     978    //          directory in cluster IO and mount these inodes into VFS.
    974979    /////////////////////////////////////////////////////////////////////////////////
    975980
    976981    if( (core_lid ==  0) && (local_cxy == io_cxy) )
    977982    {
    978         xptr_t  devfs_root_inode_xp;       // extended pointer on DEVFS root directory
    979         xptr_t  devfs_external_inode_xp;   // extended pointer on DEVFS external directory   
    980 
    981983        // create "dev" and "external" directories.
    982984        devfs_global_init( process_zero.vfs_root_xp,
    983                            &devfs_root_inode_xp,
     985                           &devfs_dev_inode_xp,
    984986                           &devfs_external_inode_xp );
    985987
     
    991993
    992994        // register DEVFS root and external directories
    993         devfs_ctx_init( devfs_ctx, devfs_root_inode_xp, devfs_external_inode_xp );
     995        devfs_ctx_init( devfs_ctx, devfs_dev_inode_xp, devfs_external_inode_xp );
    994996    }   
    995997
    996998    /////////////////////////////////////////////////////////////////////////////////
    997     // global &local synchro to protect File System initialisation
    998999    if( core_lid == 0 ) remote_barrier( XPTR( io_cxy , &global_barrier ),
    9991000                                        (info->x_size * info->y_size) );
    10001001    barrier_wait( &local_barrier , info->cores_nr );
     1002    /////////////////////////////////////////////////////////////////////////////////
    10011003
    10021004    if( (core_lid ==  0) && (local_cxy == 0) )
     
    10071009    // STEP 7 : All CP0s complete in parallel the DEVFS tree initialization.
    10081010    //          Each CP0 get the "dev" and "external" extended pointers from
    1009     //          values storred in cluster IO. Then CP0 in cluster(i) creates the
    1010     //          DEVFS "internal directory, and creates the pseudo-files for all
    1011     //          chdevs contained in cluster (i).
     1011    //          values stored in cluster IO.
     1012    //          Then CP0 in cluster(i) creates the DEVFS "internal directory,
     1013    //          and creates the pseudo-files for all chdevs in cluster (i).
    10121014    /////////////////////////////////////////////////////////////////////////////////
    10131015
    10141016    if( core_lid == 0 )
    10151017    {
    1016         xptr_t  root_inode_xp;       // extended pointer on DEVFS root directory
    1017         xptr_t  external_inode_xp;   // extended pointer on DEVFS external directory   
    1018 
    10191018        // get extended pointer on "extend" field of VFS context for DEVFS in cluster IO
    10201019        xptr_t  extend_xp = XPTR( io_cxy , &fs_context[FS_TYPE_DEVFS].extend );
     
    10231022        devfs_ctx_t * devfs_ctx = hal_remote_lpt( extend_xp );
    10241023       
    1025         root_inode_xp     = hal_remote_lwd( XPTR( io_cxy , &devfs_ctx->root_inode_xp ) );
    1026         external_inode_xp = hal_remote_lwd( XPTR( io_cxy , &devfs_ctx->external_inode_xp ) );
    1027 
    1028         devfs_local_init( root_inode_xp,
    1029                           external_inode_xp );
    1030     }
    1031 
    1032     /////////////////////////////////////////////////////////////////////////////////
    1033     // global &local synchro to protect File System initialisation
     1024        devfs_dev_inode_xp      = hal_remote_lwd( XPTR( io_cxy ,
     1025                                                        &devfs_ctx->dev_inode_xp ) );
     1026        devfs_external_inode_xp = hal_remote_lwd( XPTR( io_cxy ,
     1027                                                        &devfs_ctx->external_inode_xp ) );
     1028
     1029        // populate DEVFS in all clusters
     1030        devfs_local_init( devfs_dev_inode_xp,
     1031                          devfs_external_inode_xp,
     1032                          &devfs_internal_inode_xp );
     1033    }
     1034
     1035    /////////////////////////////////////////////////////////////////////////////////
    10341036    if( core_lid == 0 ) remote_barrier( XPTR( io_cxy , &global_barrier ),
    10351037                                        (info->x_size * info->y_size) );
    10361038    barrier_wait( &local_barrier , info->cores_nr );
     1039    /////////////////////////////////////////////////////////////////////////////////
    10371040
    10381041    if( (core_lid ==  0) && (local_cxy == 0) )
     
    10401043               __FUNCTION__, (uint32_t)hal_time_stamp());
    10411044
    1042     /////////////////////////////////////////////////////////////////////////////////
    1043     // STEP 8 : CP0 in I/O cluster creates the process_init and print banner.
     1045    #if CONFIG_KINIT_DEBUG
     1046    vfs_display( vfs_root_inode_xp );
     1047    #endif
     1048
     1049    /////////////////////////////////////////////////////////////////////////////////
     1050    // STEP 8 : CP0 in I/O cluster creates the first user process (process_init)
    10441051    /////////////////////////////////////////////////////////////////////////////////
    10451052
     
    10501057
    10511058    /////////////////////////////////////////////////////////////////////////////////
    1052     // global syncho to protect access to File System
    10531059    if( core_lid == 0 ) remote_barrier( XPTR( info->io_cxy , &global_barrier ),
    10541060                                        (info->x_size * info->y_size) );
    10551061    barrier_wait( &local_barrier , info->cores_nr );
     1062    /////////////////////////////////////////////////////////////////////////////////
    10561063
    10571064    if( (core_lid ==  0) && (local_cxy == 0) )
  • trunk/kernel/kern/process.c

    r188 r204  
    112112    }
    113113
     114    // initialize PID and PPID
     115        process->pid   = pid;
     116    process->ppid  = parent_pid;
     117
    114118    // reset reference process vmm (not for kernel process)
    115119    if( pid ) vmm_init( process );
     
    152156    spinlock_init( &process->th_lock );
    153157
    154     // initialize PID and PPID
    155         process->pid   = pid;
    156     process->ppid  = parent_pid;
    157 
    158158    // set ref_xp field
    159159    process->ref_xp = XPTR( local_cxy , process );
     
    171171    process_dmsg("\n[INFO] %s : exit for process %x in cluster %x\n",
    172172                 __FUNCTION__ , pid );
    173 }
     173
     174}  // process_reference init()
    174175
    175176/////////////////////////////////////////////////////
     
    230231
    231232    return 0;
    232 }
     233
     234} // end process_copy_init()
    233235
    234236///////////////////////////////////////////
     
    578580
    579581    return (found) ? 0 : ENOMEM;
    580 }
     582
     583}  // end process_register_thread()
     584
    581585///////////////////////////////////////////////
    582586void process_remove_thread( thread_t * thread )
     
    596600    process->th_tbl[ltid] = NULL;
    597601    process->th_nr--;
    598 }
     602
     603}  // process_remove_thread()
    599604
    600605/////////////////////////////////////////////////////
     
    623628    parent_pid = hal_remote_lw( XPTR( parent_cxy , &parent_ptr->pid ) );
    624629
    625     exec_dmsg("\n[INFO] %s enters in cluster %x for path = %s\n",
     630    exec_dmsg("\n[INFO] %s : enters in cluster %x for path = %s\n",
    626631                __FUNCTION__ , local_cxy , path );
    627632
     
    650655    process_reference_init( process , pid , parent_xp );
    651656
    652     exec_dmsg("\n[INFO] %s created process %x cluster %x / path = %s\n",
    653                 __FUNCTION__, parent_pid , local_cxy , path );
     657    exec_dmsg("\n[INFO] %s : created process %x in cluster %x / path = %s\n",
     658                __FUNCTION__, pid , local_cxy , path );
    654659
    655660    // initialize vfs_root and vfs_cwd from parent process
     
    663668
    664669    // initialize embedded fd_array from parent process
    665     process_fd_remote_copy( XPTR( local_cxy , &process->fd_array ),
     670    process_fd_remote_copy( XPTR( local_cxy  , &process->fd_array ),
    666671                            XPTR( parent_cxy , &parent_ptr->fd_array) );
     672
     673    exec_dmsg("\n[INFO] %s : fd_array copied from process %x to process %x\n",
     674                __FUNCTION__, parent_pid , pid );
    667675
    668676        // initialize signal manager TODO ??? [AG]
    669677        // signal_manager_init( process );
    670 
    671     // initialize process VMM
    672         vmm_init( process );
    673 
    674     exec_dmsg("\n[INFO] %s initialized VMM in cluster %x for process %x / path = %s\n",
    675                 __FUNCTION__ , local_cxy , pid , path );
    676678
    677679    // register "code" and "data" vsegs as well as the process entry-point in VMM,
     
    687689        }
    688690
    689     // register "heap" vseg descriptor in VMM
    690     vseg_t * heap_vseg = vmm_create_vseg( process,
    691                                           CONFIG_VMM_HEAP_BASE,
    692                                           CONFIG_VMM_HEAP_SIZE,
    693                                           VSEG_TYPE_HEAP );
    694     if( heap_vseg == NULL )
    695         {
    696                 printk("\n[ERROR] in %s : cannot create heap vseg for process %x / path = %s\n",
    697                        __FUNCTION__, pid , path );
    698         process_destroy( process );
    699         return error;
    700         }
     691    exec_dmsg("\n[INFO] %s : code and data vsegs from <%s> registered for process %x\n",
     692                __FUNCTION__ , path , pid );
    701693
    702694    // select a core in cluster
     
    718710        {
    719711                printk("\n[ERROR] in %s : cannot create thread for process %x / path = %s\n",
    720                        __FUNCTION__, pid , path );
     712                       __FUNCTION__, pid );
    721713        process_destroy( process );
    722714        return error;
    723715        }
     716
     717        exec_dmsg("\n[INFO] %s : thread created for process %x on core %d in cluster %x\n",
     718               __FUNCTION__ , pid , core->lid , local_cxy );
    724719
    725720    // update children list in parent process
     
    731726        sched_register_thread( core , thread );
    732727
    733         exec_dmsg("\n[INFO] %s created thread for process %x on core %d in cluster %x\n",
    734                __FUNCTION__ , pid , core->lid , local_cxy );
    735 
    736728    // activate new thread
    737729        thread_unblock( XPTR( local_cxy , thread ) , THREAD_BLOCKED_GLOBAL );
    738730
     731    exec_dmsg("\n[INFO] %s : exit for process %x\n",
     732                __FUNCTION__, process->pid );
     733
    739734        return 0;
    740 }
     735
     736}  // end proces_make_exec()
    741737
    742738//////////////////////////
     
    755751    uint32_t  stderr_id;
    756752
    757         process_dmsg("\n[INFO] %s enters in cluster %x\n", __FUNCTION__ , local_cxy );
     753        process_dmsg("\n[INFO] %s : enters in cluster %x\n", __FUNCTION__ , local_cxy );
    758754
    759755    // open stdin / stdout / stderr pseudo-files
     
    762758        error3 = vfs_open( XPTR_NULL, CONFIG_DEV_STDERR, O_WRONLY, 0, &stderr_xp, &stderr_id );
    763759
    764         if( error1 || error2 || error3 )
    765         {
    766                 if( !error1 ) vfs_close( stdin_xp  , stdin_id );
    767                 if( !error2 ) vfs_close( stdout_xp , stdout_id );
    768                 if( !error3 ) vfs_close( stderr_xp , stderr_id );
    769                 printk("\n[PANIC] in %s : cannot open stdin/stdout/stderr in cluster %x\n",
    770                __FUNCTION__ , local_cxy );
    771         hal_core_sleep();
    772         }
    773 
    774     // check stdin / stdout / stderr indexes
    775     if( (stdin_id != 0) || (stdout_id != 1) || (stderr_id != 2) )
    776     {
    777                 vfs_close( stdin_xp  , stdin_id );
    778                 vfs_close( stdout_xp , stdout_id );
    779                 vfs_close( stderr_xp , stderr_id );
    780                 printk("\n[PANIC] in %s : bad indexes for stdin/stdout/stderr in cluster %x\n",
    781             __FUNCTION__ , local_cxy );
    782         hal_core_sleep();
    783     }
     760        assert( ((error1 == 0) && (error2 == 0) && (error3 == 0)) , __FUNCTION__ ,
     761            "cannot open stdin/stdout/stderr pseudo files\n");
     762
     763    assert( ((stdin_id == 0) && (stdout_id == 1) && (stderr_id == 2)) , __FUNCTION__ ,
     764            "bad indexes for stdin/stdout/stderr\n");
    784765
    785766    // initialize the exec_info structure
     
    792773        error1 = process_make_exec( &exec_info );
    793774
    794         if( error1 )
    795         {
    796         printk("\n[PANIC] in %s : cannot create main thread in cluster %x\n",
    797                __FUNCTION__ , local_cxy );
    798                 hal_core_sleep();
    799     }
    800 
    801         process_dmsg("\n[INFO] %s successfully exit in cluster %x\n", __FUNCTION__ , local_cxy );
     775        assert( (error1 == 0) , __FUNCTION__ , "cannot create process_init\n");
     776
     777        process_dmsg("\n[INFO] %s : exit in cluster %x\n", __FUNCTION__ , local_cxy );
    802778               
    803779    hal_fence();
    804 }
    805 
     780
     781}  // end process_init_create()
     782
  • trunk/kernel/kern/process.h

    r173 r204  
    144144    xptr_t             parent_xp;      /*! extended pointer on parent process descriptor    */
    145145
    146     xptr_t             stdin_xp;       /*! extended pointer on stdin  pseudo-file           */
    147146    char               path[CONFIG_VFS_MAX_PATH_LENGTH];   /*!  .elf file path              */
    148147
Note: See TracChangeset for help on using the changeset viewer.