Ignore:
Timestamp:
Feb 12, 2013, 6:33:31 PM (11 years ago)
Author:
meunier
Message:

Added support for memspaces and const.
Added an interrupt masking to the "giet_context_switch" syscall
Corrected two bugs in boot/boot_init.c (one minor and one regarding barriers initialization)
Reformatted the code in all files.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • soft/giet_vm/sys/kernel_init.c

    r220 r228  
    3737
    3838__attribute__((section (".kdata")))
    39 unsigned int                    _ptabs_paddr[GIET_NB_VSPACE_MAX];
    40 
    41 __attribute__((section (".kdata")))
    42 unsigned int                    _ptabs_vaddr[GIET_NB_VSPACE_MAX];
     39unsigned int _ptabs_paddr[GIET_NB_VSPACE_MAX];
     40
     41__attribute__((section (".kdata")))
     42unsigned int _ptabs_vaddr[GIET_NB_VSPACE_MAX];
    4343
    4444///////////////////////////////////////////////////////////////////////////////////
     
    4747
    4848__attribute__((section (".kdata")))
    49 static_scheduler_t*             _schedulers_paddr[NB_CLUSTERS*NB_PROCS_MAX];
     49static_scheduler_t * _schedulers_paddr[NB_CLUSTERS * NB_PROCS_MAX];
    5050
    5151///////////////////////////////////////////////////////////////////////////////////
     
    5454
    5555__attribute__((section (".kdata")))
    56 unsigned int                    _idle_stack[NB_CLUSTERS*NB_PROCS_MAX*64];
    57 
    58 void _sys_exit()
    59 {
    60     while(1);
     56unsigned int _idle_stack[NB_CLUSTERS*NB_PROCS_MAX * 64];
     57
     58void _sys_exit() {
     59    while (1);
    6160}
     61
    6262
    6363//////////////////////////////////////////////////////////////////////////////////
    6464// This function is the entry point for the last step of the boot sequence.
    6565//////////////////////////////////////////////////////////////////////////////////
    66 __attribute__((section (".kinit"))) void _kernel_init()
    67 {
     66__attribute__((section (".kinit"))) void _kernel_init() {
    6867    // compute cluster and local processor index
    69     unsigned int        global_pid = _procid();
    70     unsigned int    cluster_id = global_pid / NB_PROCS_MAX;
    71     unsigned int    proc_id    = global_pid % NB_PROCS_MAX;
     68    unsigned int global_pid = _procid();
     69    unsigned int cluster_id = global_pid / NB_PROCS_MAX;
     70    unsigned int proc_id = global_pid % NB_PROCS_MAX;
    7271
    7372    // Step 0 : Compute number of tasks allocated to proc
     
    7675
    7776#if GIET_DEBUG_INIT
    78 _get_lock(&_tty_put_lock);
    79 _puts("\n[GIET DEBUG] step 0 for processor ");
    80 _putd( global_pid );
    81 _puts(" : tasks = ");
    82 _putd( tasks );
    83 _puts("\n");
    84 _release_lock(&_tty_put_lock);
     77    _get_lock(&_tty_put_lock);
     78    _puts("\n[GIET DEBUG] step 0 for processor ");
     79    _putd(global_pid);
     80    _puts(" : tasks = ");
     81    _putd(tasks);
     82    _puts("\n");
     83    _release_lock(&_tty_put_lock);
    8584#endif
    8685
     
    8887    //          get scheduler physical address (from CP0 register)
    8988
    90     static_scheduler_t*         psched = (static_scheduler_t*)_get_sched();
    91     _schedulers_paddr[global_pid]  = psched;
    92 
    93 #if GIET_DEBUG_INIT
    94 _get_lock(&_tty_put_lock);
    95 _puts("\n[GIET DEBUG] step 1 for processor ");
    96 _putd( global_pid );
    97 _puts(" / scheduler pbase = ");
    98 _putx( (unsigned int)psched );
    99 _puts("\n");
    100 _release_lock(&_tty_put_lock);
     89    static_scheduler_t * psched = (static_scheduler_t *) _get_sched();
     90    _schedulers_paddr[global_pid] = psched;
     91
     92#if GIET_DEBUG_INIT
     93    _get_lock(&_tty_put_lock);
     94    _puts("\n[GIET DEBUG] step 1 for processor ");
     95    _putd(global_pid);
     96    _puts(" / scheduler pbase = ");
     97    _putx((unsigned int) psched);
     98    _puts("\n");
     99    _release_lock(&_tty_put_lock);
    101100#endif
    102101
     
    107106    unsigned int ltid;
    108107
    109     for ( ltid = 0 ; ltid < tasks ; ltid++ )
    110     {
    111         unsigned int vspace_id  = _get_context_slot( ltid , CTX_VSID_ID );
    112         unsigned int ptab_vaddr = _get_context_slot( ltid , CTX_PTAB_ID );
    113         unsigned int ptab_paddr = _get_context_slot( ltid , CTX_PTPR_ID ) << 13;
     108    for (ltid = 0; ltid < tasks; ltid++) {
     109        unsigned int vspace_id = _get_context_slot(ltid , CTX_VSID_ID);
     110        unsigned int ptab_vaddr = _get_context_slot(ltid , CTX_PTAB_ID);
     111        unsigned int ptab_paddr = _get_context_slot(ltid , CTX_PTPR_ID) << 13;
    114112
    115113        _ptabs_vaddr[vspace_id] = ptab_vaddr;
     
    117115
    118116#if GIET_DEBUG_INIT
    119 _get_lock(&_tty_put_lock);
    120 _puts("\n[GIET DEBUG] step 2 for processor ");
    121 _putd( global_pid );
    122 _puts(" / vspace ");
    123 _putd( vspace_id );
    124 _puts("\n- ptab vbase = ");
    125 _putx( ptab_vaddr );
    126 _puts("\n- ptab pbase = ");
    127 _putx( ptab_paddr );
    128 _puts("\n");
    129 _release_lock(&_tty_put_lock);
    130 #endif
    131 
    132     }
    133  
     117        _get_lock(&_tty_put_lock);
     118        _puts("\n[GIET DEBUG] step 2 for processor ");
     119        _putd(global_pid);
     120        _puts(" / vspace ");
     121        _putd(vspace_id);
     122        _puts("\n- ptab vbase = ");
     123        _putx(ptab_vaddr);
     124        _puts("\n- ptab pbase = ");
     125        _putx(ptab_paddr);
     126        _puts("\n");
     127        _release_lock(&_tty_put_lock);
     128#endif
     129
     130    }
     131
    134132    unsigned int isr_switch_channel = 0xFFFFFFFF;
    135133
     
    142140    unsigned int pti_mask = 0;
    143141
    144     for ( irq_id = 0 ; irq_id < 32 ; irq_id++ )
    145     {
    146         unsigned int entry  = _get_interrupt_vector_entry(irq_id);
    147         unsigned int isr    = entry & 0x000000FF;
    148 
    149         if ( (isr == ISR_DMA) || (isr == ISR_IOC) || (isr == ISR_TTY) )
    150         {
    151              hwi_mask = hwi_mask | 0x1<< irq_id;
    152         }
    153         else if ( (isr == ISR_SWITCH) )
    154         {
    155             pti_mask = pti_mask | 0x1<< irq_id;
     142    for (irq_id = 0; irq_id < 32; irq_id++) {
     143        unsigned int entry = _get_interrupt_vector_entry(irq_id);
     144        unsigned int isr = entry & 0x000000FF;
     145
     146        if ((isr == ISR_DMA) || (isr == ISR_IOC) || (isr == ISR_TTY)) {
     147            hwi_mask = hwi_mask | 0x1 << irq_id;
     148        }
     149        else if ((isr == ISR_SWITCH)) {
     150            pti_mask = pti_mask | 0x1 << irq_id;
    156151            isr_switch_channel = irq_id;
    157152        }
    158         else if ( (isr == ISR_TIMER) )
    159         {
    160             pti_mask = pti_mask | 0x1<< irq_id;
    161         }
    162     }
    163     _icu_set_mask( cluster_id, proc_id, hwi_mask, 0 ); // set HWI_MASK
    164     _icu_set_mask( cluster_id, proc_id, pti_mask, 1 );  // set PTI_MASK
    165    
    166 #if GIET_DEBUG_INIT
    167 _get_lock(&_tty_put_lock);
    168 _puts("\n[GIET DEBUG] step 3 for processor ");
    169 _putd( global_pid );
    170 _puts("\n - ICU HWI_MASK = ");
    171 _putx( hwi_mask );
    172 _puts("\n - ICU PTI_MASK = ");
    173 _putx( pti_mask );
    174 _puts("\n");
    175 _release_lock(&_tty_put_lock);
     153        else if ((isr == ISR_TIMER)) {
     154            pti_mask = pti_mask | 0x1 << irq_id;
     155        }
     156    }
     157    _icu_set_mask(cluster_id, proc_id, hwi_mask, 0); // set HWI_MASK
     158    _icu_set_mask(cluster_id, proc_id, pti_mask, 1); // set PTI_MASK
     159
     160#if GIET_DEBUG_INIT
     161    _get_lock(&_tty_put_lock);
     162    _puts("\n[GIET DEBUG] step 3 for processor ");
     163    _putd(global_pid);
     164    _puts("\n - ICU HWI_MASK = ");
     165    _putx(hwi_mask);
     166    _puts("\n - ICU PTI_MASK = ");
     167    _putx(pti_mask);
     168    _puts("\n");
     169    _release_lock(&_tty_put_lock);
    176170#endif
    177171
    178172    // step 4 : start TICK timer if more than one task
    179     if ( tasks > 1 )
    180     {
    181         if(isr_switch_channel == 0xFFFFFFFF)
    182         {
     173    if (tasks > 1) {
     174        if (isr_switch_channel == 0xFFFFFFFF) {
    183175            _get_lock(&_tty_put_lock);
    184176            _puts("\n[GIET ERROR] ISR_SWITCH not found on proc ");
    185             _putd( proc_id);
     177            _putd(proc_id);
    186178            _puts("\n");
    187179            _release_lock(&_tty_put_lock);
     
    189181        }
    190182
    191         if(_timer_start( cluster_id, isr_switch_channel, GIET_TICK_VALUE ))
    192         {
     183        if (_timer_start( cluster_id, isr_switch_channel, GIET_TICK_VALUE)) {
    193184            _get_lock(&_tty_put_lock);
    194185            _puts("\n[GIET ERROR] ISR_SWITCH init error for proc ");
    195             _putd( proc_id);
     186            _putd(proc_id);
    196187            _puts("\n");
    197188            _release_lock(&_tty_put_lock);
    198189            _sys_exit();
    199190        }
    200        
    201 #if GIET_DEBUG_INIT
    202 _get_lock(&_tty_put_lock);
    203 _puts("\n[GIET DEBUG] Step 4 for processor ");
    204 _putd( global_pid );
    205 _puts(" / context switch activated\n");
    206 _release_lock(&_tty_put_lock);
    207 #endif
    208    
     191
     192#if GIET_DEBUG_INIT
     193        _get_lock(&_tty_put_lock);
     194        _puts("\n[GIET DEBUG] Step 4 for processor ");
     195        _putd(global_pid);
     196        _puts(" / context switch activated\n");
     197        _release_lock(&_tty_put_lock);
     198#endif
     199
    209200    }
    210201
     
    214205    //          it uses the page table of vspace[0]
    215206    //          the stack size is 256 bytes
    216  
    217     _set_context_slot( IDLE_TASK_INDEX, CTX_RUN_ID,  1 );
    218     _set_context_slot( IDLE_TASK_INDEX, CTX_SR_ID,   0xFF03 );
    219     _set_context_slot( IDLE_TASK_INDEX, CTX_SP_ID,   (unsigned int)_idle_stack + ((global_pid+1)<<8) );
    220     _set_context_slot( IDLE_TASK_INDEX, CTX_RA_ID,   (unsigned int)&_ctx_eret );
    221     _set_context_slot( IDLE_TASK_INDEX, CTX_EPC_ID,  (unsigned int)&_ctx_idle );
    222     _set_context_slot( IDLE_TASK_INDEX, CTX_LTID_ID, IDLE_TASK_INDEX );
    223     _set_context_slot( IDLE_TASK_INDEX, CTX_PTPR_ID, _ptabs_paddr[0] >> 13 );
    224 
    225 #if GIET_DEBUG_INIT
    226 _get_lock(&_tty_put_lock);
    227 _puts("\n[GIET DEBUG] Step 5 for processor ");
    228 _putd( global_pid );
    229 _puts(" / idle task context set\n");
    230 _release_lock(&_tty_put_lock);
    231 #endif
    232    
     207
     208    _set_context_slot( IDLE_TASK_INDEX, CTX_RUN_ID, 1);
     209    _set_context_slot( IDLE_TASK_INDEX, CTX_SR_ID,  0xFF03);
     210    _set_context_slot( IDLE_TASK_INDEX, CTX_SP_ID,  (unsigned int) _idle_stack + ((global_pid + 1) << 8));
     211    _set_context_slot( IDLE_TASK_INDEX, CTX_RA_ID,  (unsigned int) &_ctx_eret);
     212    _set_context_slot( IDLE_TASK_INDEX, CTX_EPC_ID, (unsigned int) &_ctx_idle);
     213    _set_context_slot( IDLE_TASK_INDEX, CTX_LTID_ID, IDLE_TASK_INDEX);
     214    _set_context_slot( IDLE_TASK_INDEX, CTX_PTPR_ID, _ptabs_paddr[0] >> 13);
     215
     216#if GIET_DEBUG_INIT
     217    _get_lock(&_tty_put_lock);
     218    _puts("\n[GIET DEBUG] Step 5 for processor ");
     219    _putd(global_pid);
     220    _puts(" / idle task context set\n");
     221    _release_lock(&_tty_put_lock);
     222#endif
     223
    233224    // step 6 : each processor initialises SP, SR, PTPR, EPC, registers
    234225    //          with the values corresponding to the first allocated task,
     
    237228    unsigned int task_id;
    238229
    239     if ( tasks == 0 )
    240     {
     230    if (tasks == 0) {
    241231        task_id = IDLE_TASK_INDEX;
    242232
    243         _get_lock( &_tty_put_lock );
     233        _get_lock(&_tty_put_lock);
    244234        _puts("\n[GIET WARNING] No task allocated to processor ");
    245         _putd( global_pid );
     235        _putd(global_pid);
    246236        _puts(" => idle\n");
    247         _release_lock ( &_tty_put_lock );
    248     }
    249     else
    250     {
    251         task_id = 0;
    252     }
    253        
    254     unsigned int    sp_value   = _get_context_slot( task_id, CTX_SP_ID );
    255     unsigned int    sr_value   = _get_context_slot( task_id, CTX_SR_ID );
    256     unsigned int    ptpr_value = _get_context_slot( task_id, CTX_PTPR_ID );
    257     unsigned int    epc_value  = _get_context_slot( task_id, CTX_EPC_ID );
    258 
    259 #if GIET_DEBUG_INIT
    260 _get_lock(&_tty_put_lock);
    261 _puts("\n[GIET DEBUG] step 6 for processor ");
    262 _putd( global_pid );
    263 _puts(" / registers initialised \n");
    264 _puts("- sp   = ");
    265 _putx( sp_value );
    266 _puts("\n");
    267 _puts("- sr   = ");
    268 _putx( sr_value );
    269 _puts("\n");
    270 _puts("- ptpr = ");
    271 _putx( ptpr_value<<13 );
    272 _puts("\n");
    273 _puts("- epc  = ");
    274 _putx( epc_value );
    275 _puts("\n");
    276 _release_lock(&_tty_put_lock);
     237        _release_lock (&_tty_put_lock);
     238    }
     239    else {
     240        task_id = 0;
     241    }
     242
     243    unsigned int sp_value = _get_context_slot(task_id, CTX_SP_ID);
     244    unsigned int sr_value = _get_context_slot(task_id, CTX_SR_ID);
     245    unsigned int ptpr_value = _get_context_slot(task_id, CTX_PTPR_ID);
     246    unsigned int epc_value = _get_context_slot(task_id, CTX_EPC_ID);
     247
     248#if GIET_DEBUG_INIT
     249    _get_lock(&_tty_put_lock);
     250    _puts("\n[GIET DEBUG] step 6 for processor ");
     251    _putd(global_pid);
     252    _puts(" / registers initialised \n");
     253    _puts("- sp   = ");
     254    _putx(sp_value);
     255    _puts("\n");
     256    _puts("- sr   = ");
     257    _putx(sr_value);
     258    _puts("\n");
     259    _puts("- ptpr = ");
     260    _putx(ptpr_value << 13);
     261    _puts("\n");
     262    _puts("- epc  = ");
     263    _putx(epc_value);
     264    _puts("\n");
     265    _release_lock(&_tty_put_lock);
    277266#endif
    278267
    279268    // set  registers and jump to user code
    280     asm volatile ( "move        $29,    %0              \n"             /* SP <= ctx[CTX_SP_ID] */
    281                    "mtc0        %1,             $12             \n"             /* SR <= ctx[CTX_SR_ID] */
    282                    "mtc2        %2,             $0              \n"             /* PTPR <= ctx[CTX_PTPR_ID] */
    283                    "mtc0        %3,             $14             \n"             /* EPC <= ctx[CTX_EPC_ID] */
    284                    "eret                                        \n"             /* jump to user code */
    285                    "nop                                         \n"
    286                    :
    287                    : "r"(sp_value), "r"(sr_value), "r"(ptpr_value), "r"(epc_value) );
     269    asm volatile (
     270            "move    $29,       %0    \n"        /* SP <= ctx[CTX_SP_ID] */
     271            "mtc0    %1,        $12   \n"        /* SR <= ctx[CTX_SR_ID] */
     272            "mtc2    %2,        $0    \n"        /* PTPR <= ctx[CTX_PTPR_ID] */
     273            "mtc0    %3,        $14   \n"        /* EPC <= ctx[CTX_EPC_ID] */
     274            "eret                     \n"        /* jump to user code */
     275            "nop                      \n"
     276            :
     277            : "r" (sp_value), "r" (sr_value), "r" (ptpr_value), "r" (epc_value));
    288278
    289279} // end _kernel_init()
     280
     281// Local Variables:
     282// tab-width: 4
     283// c-basic-offset: 4
     284// c-file-offsets:((innamespace . 0)(inline-open . 0))
     285// indent-tabs-mode: nil
     286// End:
     287// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
     288
Note: See TracChangeset for help on using the changeset viewer.