Ignore:
Timestamp:
Nov 7, 2017, 3:08:12 PM (6 years ago)
Author:
alain
Message:

First implementation of fork/exec.

File:
1 edited

Legend:

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

    r406 r407  
    3232#include <barrier.h>
    3333#include <remote_barrier.h>
     34#include <remote_fifo.h>
    3435#include <core.h>
    3536#include <list.h>
     
    8586cluster_t            cluster_manager                         CONFIG_CACHE_LINE_ALIGNED;
    8687
    87 // This variable defines the TXT0 kernel terminal
     88// This variable defines the TXT0 kernel terminal (TX only)
    8889__attribute__((section(".kdata")))
    8990chdev_t              txt0_chdev                              CONFIG_CACHE_LINE_ALIGNED;
     
    121122vfs_ctx_t            fs_context[FS_TYPES_NR]                 CONFIG_CACHE_LINE_ALIGNED;
    122123
     124// These variables are used by the sched_yield function to save SR value
     125__attribute__((section(".kdata")))
     126uint32_t             switch_save_sr[CONFIG_MAX_LOCAL_CORES]  CONFIG_CACHE_LINE_ALIGNED;
     127
     128#if CONFIG_READ_DEBUG
     129uint32_t   enter_sys_read;
     130uint32_t   exit_sys_read;
     131
     132uint32_t   enter_devfs_move;
     133uint32_t   exit_devfs_move;
     134
     135uint32_t   enter_txt_read;
     136uint32_t   exit_txt_read;
     137
     138uint32_t   enter_chdev_cmd;
     139uint32_t   exit_chdev_cmd;
     140
     141uint32_t   enter_chdev_server;
     142uint32_t   exit_chdev_server;
     143
     144uint32_t   enter_tty_cmd;
     145uint32_t   exit_tty_cmd;
     146
     147uint32_t   enter_tty_isr;
     148uint32_t   exit_tty_isr;
     149#endif
    123150
    124151///////////////////////////////////////////////////////////////////////////////////////////
     
    137164           "    /_/        \\_\\ |______| |_|    |_|   \\_____/  |______/        |_|    |_|  |_|  \\_\\ |_|   |_|  \n"
    138165           "\n\n\t\t Advanced Locality Management Operating System / Multi Kernel Hybrid\n"
    139            "\n\n\t\t\t Version 0.0 / %d cluster(s) / %d core(s) per cluster\n\n", nclusters , ncores );
     166           "\n\n\t\t Version 0.0 / %d cluster(s) / %d core(s) per cluster / cycle %d\n\n",
     167           nclusters , ncores , hal_time_stamp() );
    140168}
    141169
     
    201229                {
    202230                    cxy_t  cxy = (x<<info->y_width) + y;
    203                     hal_remote_swd( XPTR( cxy , &chdev_dir.txt[0] ) ,
     231                    hal_remote_swd( XPTR( cxy , &chdev_dir.txt_tx[0] ) ,
    204232                                    XPTR( local_cxy , &txt0_chdev ) );
    205233                }
     
    273301            }
    274302
    275 #if( CONFIG_KINIT_DEBUG > 1 )
    276 printk("\n[DMSG] %s : created MMC in cluster %x / chdev = %x\n",
    277 __FUNCTION__ , channel , local_cxy , chdev_ptr );
     303#if( CONFIG_KINIT_DEBUG & 0x1 )
     304if( hal_time_stamp() > CONFIG_KINIT_DEBUG )
     305printk("\n[DBG] %s : created MMC in cluster %x / chdev = %x\n",
     306__FUNCTION__ , local_cxy , chdev_ptr );
    278307#endif
    279308        }
     
    301330                chdev_dir.dma[channel] = XPTR( local_cxy , chdev_ptr );
    302331
    303 #if( CONFIG_KINIT_DEBUG > 1 )
    304 printk("\n[DMSG] %s : created DMA[%d] in cluster %x / chdev = %x\n",
     332#if( CONFIG_KINIT_DEBUG & 0x1 )
     333if( hal_time_stamp() > CONFIG_KINIT_DEBUG )
     334printk("\n[DBG] %s : created DMA[%d] in cluster %x / chdev = %x\n",
    305335__FUNCTION__ , channel , local_cxy , chdev_ptr );
    306336#endif
     
    355385        impl     = IMPL_FROM_TYPE( dev_tbl[i].type );
    356386
    357         // There is one chdev per direction for NIC
    358         if (func == DEV_FUNC_NIC) directions = 2;
    359         else                      directions = 1;
     387        // There is one chdev per direction for NIC and for TXT
     388        if((func == DEV_FUNC_NIC) || (func == DEV_FUNC_TXT)) directions = 2;
     389        else                                                 directions = 1;
    360390
    361391        // The TXT0 chdev has already been created
     
    363393        else                      first_channel = 0;
    364394
    365         // do nothing for RO, that does not require a device descriptor.
     395        // do nothing for ROM, that does not require a device descriptor.
    366396        if( func == DEV_FUNC_ROM ) continue;
    367397
     
    394424
    395425                // allocate and initialize a local chdev
    396                 // if local cluster matches target cluster
     426                // when local cluster matches target cluster
    397427                if( target_cxy == local_cxy )
    398428                {
     
    420450                    if(func==DEV_FUNC_IOB             ) entry  = &chdev_dir.iob;
    421451                    if(func==DEV_FUNC_IOC             ) entry  = &chdev_dir.ioc[channel];
    422                     if(func==DEV_FUNC_TXT             ) entry  = &chdev_dir.txt[channel];
    423452                    if(func==DEV_FUNC_FBF             ) entry  = &chdev_dir.fbf[channel];
     453                    if((func==DEV_FUNC_TXT) && (rx==0)) entry  = &chdev_dir.txt_tx[channel];
     454                    if((func==DEV_FUNC_TXT) && (rx==1)) entry  = &chdev_dir.txt_rx[channel];
    424455                    if((func==DEV_FUNC_NIC) && (rx==0)) entry  = &chdev_dir.nic_tx[channel];
    425456                    if((func==DEV_FUNC_NIC) && (rx==1)) entry  = &chdev_dir.nic_rx[channel];
     
    435466                    }
    436467
    437 #if( CONFIG_KINIT_DEBUG > 1 )
    438 printk("\n[DMSG] %s : create chdev %s[%d] in cluster %x / chdev = %x\n",
    439 __FUNCTION__ , chdev_func_str( func ), channel , local_cxy , chdev );
     468#if( CONFIG_KINIT_DEBUG & 0x1 )
     469if( hal_time_stamp() > CONFIG_KINIT_DEBUG )
     470printk("\n[DBG] %s : create chdev %s / channel = %d / rx = %d / cluster %x / chdev = %x\n",
     471__FUNCTION__ , chdev_func_str( func ), channel , rx , local_cxy , chdev );
    440472#endif
    441473                }  // end if match
     
    451483///////////////////////////////////////////////////////////////////////////////////////////
    452484// This function is called by CP0 in cluster 0 to allocate memory and initialize the PIC
    453 // device, namely the informations attached to the external IOPIC controller.
     485// device, namely the informations attached to the external IOPIC controller, that
     486// must be replicated in all clusters (struct iopic_input).
    454487// This initialisation must be done before other devices initialisation because the IRQ
    455 // routing infrastructure is required for internal and external devices initialisation.
     488// routing infrastructure is required for both internal and external devices init.
    456489///////////////////////////////////////////////////////////////////////////////////////////
    457490// @ info    : pointer on the local boot-info structure.
     
    490523    assert( found , __FUNCTION__ , "PIC device not found\n" );
    491524
    492     // allocate and initialize the PIC chdev in local cluster
    493     chdev = chdev_create( func,
     525    // allocate and initialize the PIC chdev in cluster 0
     526    chdev = chdev_create( DEV_FUNC_PIC,
    494527                          impl,
    495528                          0,      // channel
     
    502535    dev_pic_init( chdev );
    503536
    504     // register extended pointer on PIC chdev in "chdev_dir" array in all clusters
     537    // register, in all clusters, the extended pointer
     538    // on PIC chdev in "chdev_dir" array
    505539    xptr_t * entry = &chdev_dir.pic;   
    506540               
     
    515549    }
    516550
    517     // initialize the "iopic_input" structure
     551    // initialize, in all clusters, the "iopic_input" structure
    518552    // defining how external IRQs are connected to IOPIC
    519     uint32_t   id;
    520     uint8_t    valid;
    521     uint32_t   type;
    522     uint8_t    channel;
    523     uint8_t    is_rx;
     553
     554    // register default value for unused inputs
     555    for( x = 0 ; x < info->x_size ; x++ )
     556    {
     557        for( y = 0 ; y < info->y_size ; y++ )
     558        {
     559            cxy_t  cxy = (x<<info->y_width) + y;
     560            hal_remote_memset( XPTR( cxy , &iopic_input ) , 0xFF , sizeof(iopic_input_t) );
     561        }
     562    }
     563
     564    // register input IRQ index for valid inputs
     565    uint32_t   id;         // input IRQ index
     566    uint8_t    valid;      // input IRQ is connected
     567    uint32_t   type;       // source device type
     568    uint8_t    channel;    // source device channel
     569    uint8_t    is_rx;      // source device direction
     570    uint32_t * ptr;        // local pointer on one field in iopic_input stucture
    524571
    525572    for( id = 0 ; id < CONFIG_MAX_EXTERNAL_IRQS ; id++ )
     
    529576        channel = dev_tbl[i].irq[id].channel;
    530577        is_rx   = dev_tbl[i].irq[id].is_rx;
    531 
    532         if( valid )  // only valid inputs are registered
    533         {
    534             uint32_t * index;  // local pointer on one entry
    535             uint16_t func = FUNC_FROM_TYPE( type );
    536 
    537             if     ( func == DEV_FUNC_TXT )
    538             index = &iopic_input.txt[channel];
    539             else if( func == DEV_FUNC_IOC )
    540             index = &iopic_input.ioc[channel];
    541             else if( (func == DEV_FUNC_NIC) && (is_rx == 0) )
    542             index = &iopic_input.nic_tx[channel];
    543             else if( (func == DEV_FUNC_NIC) && (is_rx != 0) )
    544             index = &iopic_input.nic_rx[channel];
    545             else if( func == DEV_FUNC_IOB )
    546             index = &iopic_input.iob;
    547             else
    548             assert( false , __FUNCTION__ , "illegal source device for IOPIC input" );
    549 
    550             // set entry in local structure
    551             *index = id;
     578        func    = FUNC_FROM_TYPE( type );
     579
     580        // get pointer on relevant field in iopic_input
     581        if( valid )
     582        {
     583            if     ( func == DEV_FUNC_IOC )                 ptr = &iopic_input.ioc[channel];
     584            else if((func == DEV_FUNC_TXT) && (is_rx == 0)) ptr = &iopic_input.txt_tx[channel];
     585            else if((func == DEV_FUNC_TXT) && (is_rx != 0)) ptr = &iopic_input.txt_rx[channel];
     586            else if((func == DEV_FUNC_NIC) && (is_rx == 0)) ptr = &iopic_input.nic_tx[channel];
     587            else if((func == DEV_FUNC_NIC) && (is_rx != 0)) ptr = &iopic_input.nic_rx[channel];
     588            else if( func == DEV_FUNC_IOB )                 ptr = &iopic_input.iob;
     589            else     panic( "illegal source device for IOPIC input" );
     590
     591            // set one entry in all "iopic_input" structures
     592            for( x = 0 ; x < info->x_size ; x++ )
     593            {
     594                for( y = 0 ; y < info->y_size ; y++ )
     595                {
     596                    cxy_t  cxy = (x<<info->y_width) + y;
     597                    hal_remote_swd( XPTR( cxy , ptr ) , id );
     598                }
     599            }
    552600        }
    553601    }
    554602
    555 #if( CONFIG_KINIT_DEBUG > 1 )
    556 printk("\n[DMSG] %s created PIC chdev in cluster %x at cycle %d\n",
    557 __FUNCTION__ , local_cxy , (uint32_t)hal_time_stamp() );
     603#if( CONFIG_KINIT_DEBUG & 0x1 )
     604if( hal_time_stamp() > CONFIG_KINIT_DEBUG )
     605{
     606    printk("\n[DBG] %s created PIC chdev in cluster %x at cycle %d\n",
     607    __FUNCTION__ , local_cxy , (uint32_t)hal_time_stamp() );
     608    dev_pic_inputs_display();
     609}
    558610#endif
    559611   
     
    715767    hal_set_current_thread( thread );
    716768
    717     // each core initializes the idle thread "locks_root" and "xlocks_root" fields
     769    // each core register core descriptor pointer in idle thread descriptor
     770    thread->core = &LOCAL_CLUSTER->core_tbl[core_lid];
     771
     772    // each core initializes locks_root" and "xlocks_root" in idle thread descriptor
    718773    list_root_init( &thread->locks_root );
    719774    xlist_root_init( XPTR( local_cxy , &thread->xlocks_root ) );
     
    728783
    729784    if( (core_lid ==  0) && (local_cxy == 0) )
    730     printk("\n[KINIT] %s : exit barrier 0 : TXT0 initialized / cycle %d\n",
     785    kinit_dmsg("\n[DBG] %s : exit barrier 0 : TXT0 initialized / cycle %d\n",
    731786    __FUNCTION__, hal_time_stamp() );
    732787
    733788    /////////////////////////////////////////////////////////////////////////////
    734     // STEP 1 : all cores check its core identifier.
     789    // STEP 1 : all cores check core identifier.
    735790    //          CP0 initializes the local cluster manager.
    736791    //          This includes the memory allocators.
     
    762817
    763818    if( (core_lid ==  0) && (local_cxy == 0) )
    764     printk("\n[KINIT] %s : exit barrier 1 : clusters initialised / cycle %d\n",
     819    kinit_dmsg("\n[DBG] %s : exit barrier 1 : clusters initialised / cycle %d\n",
    765820    __FUNCTION__, hal_time_stamp() );
    766821
    767822    /////////////////////////////////////////////////////////////////////////////////
    768     // STEP 2 : all CP0s initialize the process_zero descriptor.
     823    // STEP 2 : CP0 initializes the process_zero descriptor.
    769824    //          CP0 in cluster 0 initializes the IOPIC device.
    770825    /////////////////////////////////////////////////////////////////////////////////
     
    787842
    788843    if( (core_lid ==  0) && (local_cxy == 0) )
    789     printk("\n[KINIT] %s : exit barrier 2 : PIC initialised / cycle %d\n",
     844    kinit_dmsg("\n[DBG] %s : exit barrier 2 : PIC initialised / cycle %d\n",
    790845    __FUNCTION__, hal_time_stamp() );
    791846
    792847    ////////////////////////////////////////////////////////////////////////////////
    793     // STEP 3 : all CP0s initialize the distibuted LAPIC descriptor.
    794     //          all CP0s initialize the internal chdev descriptors
    795     //          all CP0s initialize the local external chdev descriptors
     848    // STEP 3 : CP0 initializes the distibuted LAPIC descriptor.
     849    //          CP0 initializes the internal chdev descriptors
     850    //          CP0 initialize the local external chdev descriptors
    796851    ////////////////////////////////////////////////////////////////////////////////
    797852
     
    818873
    819874    if( (core_lid ==  0) && (local_cxy == 0) )
    820     printk("\n[KINIT] %s : exit barrier 3 : all chdev initialised / cycle %d\n",
     875    kinit_dmsg("\n[DBG] %s : exit barrier 3 : all chdev initialised / cycle %d\n",
    821876               __FUNCTION__, hal_time_stamp());
    822877
    823878    /////////////////////////////////////////////////////////////////////////////////
    824879    // STEP 4 : All cores enable IPI (Inter Procesor Interrupt),
    825     //          All cores initialise specific core registers
    826880    //          Alh cores initialize IDLE thread.
    827881    //          Only CP0 in cluster 0 creates the VFS root inode.
     
    837891    hal_enable_irq( &status );
    838892
    839     // All cores initialize specific core registers
    840     hal_core_init( info );
    841 
    842893    // all cores initialize the idle thread descriptor
    843894    error = thread_kernel_init( thread,
     
    857908
    858909#if CONFIG_KINIT_DEBUG
    859 sched_display();
     910sched_display( core_lid );
    860911#endif
    861912
     
    928979
    929980    if( (core_lid ==  0) && (local_cxy == 0) )
    930     printk("\n[KINIT] %s : exit barrier 4 : VFS_root = %l in cluster 0 / cycle %d\n",
     981    kinit_dmsg("\n[DBG] %s : exit barrier 4 : VFS_root = %l in cluster 0 / cycle %d\n",
    931982               __FUNCTION__, vfs_root_inode_xp , hal_time_stamp());
    932983
     
    9871038
    9881039    if( (core_lid ==  0) && (local_cxy == 0) )
    989     printk("\n[KINIT] %s : exit barrier 5 : VFS_root = %l in cluster IO / cycle %d\n",
     1040    kinit_dmsg("\n[DBG] %s : exit barrier 5 : VFS_root = %l in cluster IO / cycle %d\n",
    9901041    __FUNCTION__, vfs_root_inode_xp , hal_time_stamp() );
    9911042
     
    10201071
    10211072    if( (core_lid ==  0) && (local_cxy == 0) )
    1022     printk("\n[KINIT] %s : exit barrier 6 : dev_root = %l in cluster IO / cycle %d\n",
     1073    kinit_dmsg("\n[DBG] %s : exit barrier 6 : dev_root = %l in cluster IO / cycle %d\n",
    10231074    __FUNCTION__, devfs_dev_inode_xp , hal_time_stamp() );
    10241075
     
    10571108
    10581109    if( (core_lid ==  0) && (local_cxy == 0) )
    1059     printk("\n[KINIT] %s : exit barrier 7 : dev_root = %l in cluster 0 / cycle %d\n",
     1110    kinit_dmsg("\n[DBG] %s : exit barrier 7 : dev_root = %l in cluster 0 / cycle %d\n",
    10601111    __FUNCTION__, devfs_dev_inode_xp , hal_time_stamp() );
    10611112
     
    10751126    /////////////////////////////////////////////////////////////////////////////////
    10761127
     1128#if CONFIG_KINIT_DEBUG
     1129sched_display( core_lid );
     1130#endif
     1131
    10771132    if( (core_lid ==  0) && (local_cxy == 0) )
    1078     printk("\n[KINIT] %s : exit barrier 8 : process init created / cycle %d\n",
     1133    kinit_dmsg("\n[DBG] %s : exit barrier 8 : process init created / cycle %d\n",
    10791134    __FUNCTION__ , hal_time_stamp() );
    10801135
     
    11181173                   sizeof( core_t            ),
    11191174                   sizeof( scheduler_t       ),
    1120                    sizeof( rpc_fifo_t        ),
     1175                   sizeof( remote_fifo_t     ),
    11211176                   sizeof( page_t            ),
    11221177                   sizeof( mapper_t          ),
     
    11391194    dev_pic_enable_timer( CONFIG_SCHED_TICK_MS_PERIOD );
    11401195
    1141     // each core jump to idle thread
     1196    // each core jump to thread_idle_func
    11421197    thread_idle_func();
    11431198}
Note: See TracChangeset for help on using the changeset viewer.