Changeset 702 for soft


Ignore:
Timestamp:
Aug 12, 2015, 4:10:58 PM (9 years ago)
Author:
alain
Message:

Introduce the _load_writable_segments() function (used by the _ctx_exec_task() function).

Location:
soft/giet_vm/giet_kernel
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • soft/giet_vm/giet_kernel/ctx_handler.c

    r700 r702  
    1313#include <tty0.h>
    1414#include <xcu_driver.h>
     15#include <fat32.h>
     16#include <elf-types.h>
    1517
    1618/////////////////////////////////////////////////////////////////////////////////
     
    2426extern static_scheduler_t* _schedulers[X_SIZE][Y_SIZE][NB_PROCS_MAX];
    2527
    26 //////////////////
     28
     29///////////////////////////////////////////////
    2730static void _ctx_kill_task( unsigned int ltid )
    2831{
     
    7477    // set NORUN_MASK_TASK bit
    7578    _atomic_or( &psched->context[ltid][CTX_NORUN_ID], NORUN_MASK_TASK );
    76 }
    77 
    78 
    79 //////////////////
     79
     80} // end _ctx_kill_task()
     81
     82
     83
     84////////////////////////////////////////////////////////////////////////
     85static unsigned int _load_writable_segments( mapping_vspace_t*  vspace )
     86{
     87
     88#if GIET_DEBUG_SWITCH
     89unsigned int gpid       = _get_procid();
     90unsigned int cluster_xy = gpid >> P_WIDTH;
     91unsigned int p          = gpid & ((1<<P_WIDTH)-1);
     92unsigned int x          = cluster_xy >> Y_WIDTH;
     93unsigned int y          = cluster_xy & ((1<<Y_WIDTH)-1);
     94if ( _get_proctime() > GIET_DEBUG_SWITCH )
     95_printf("\n[DEBUG SWITCH] P[%d,%d,%d] _load_writable_segments() : enters for %s\n",
     96        x , y , p , vspace->name );
     97#endif
     98
     99    mapping_header_t*  header  = (mapping_header_t *)SEG_BOOT_MAPPING_BASE;
     100    mapping_vseg_t*    vseg    = _get_vseg_base(header);
     101
     102    // buffer to store one cluster
     103    char  buf[4096];
     104
     105    // open the .elf file associated to vspace
     106    unsigned int      vseg_id;
     107    unsigned int      fd = 0;
     108   
     109    for (vseg_id = vspace->vseg_offset;
     110         vseg_id < (vspace->vseg_offset + vspace->vsegs);
     111         vseg_id++)
     112    {
     113        if(vseg[vseg_id].type == VSEG_TYPE_ELF)
     114        {   
     115            fd = _fat_open( vseg[vseg_id].binpath , O_RDONLY );
     116
     117#if GIET_DEBUG_SWITCH
     118if ( _get_proctime() > GIET_DEBUG_SWITCH )
     119_printf("\n[DEBUG SWITCH] P[%d,%d,%d] _load_writable_segments() : open %s / fd = %d\n",
     120        x , y , p , vseg[vseg_id].binpath , fd );
     121#endif
     122
     123            if ( fd < 0 ) return 1;
     124            break;
     125        }
     126    }
     127
     128    // load Elf-Header into buffer from .elf file
     129    if ( _fat_lseek( fd, 0, SEEK_SET ) ) return 1;
     130    if ( _fat_read( fd, buf, 4096 ) ) return 1;
     131
     132#if GIET_DEBUG_SWITCH
     133if ( _get_proctime() > GIET_DEBUG_SWITCH )
     134_printf("\n[DEBUG SWITCH] P[%d,%d,%d] _load_writable_segments() : load Elf-Header\n",
     135        x , y , p );
     136#endif
     137
     138    // get nsegments and Program-Header-Table offset from Elf-Header
     139    Elf32_Ehdr*  elf_header_ptr = (Elf32_Ehdr*)buf;
     140    unsigned int offset         = elf_header_ptr->e_phoff;
     141    unsigned int nsegments      = elf_header_ptr->e_phnum;
     142
     143    // load Program-Header-Table from .elf file
     144    if ( _fat_lseek( fd, offset, SEEK_SET ) ) return 1;
     145    if ( _fat_read( fd, buf, 4096 ) ) return 1;
     146
     147#if GIET_DEBUG_SWITCH
     148if ( _get_proctime() > GIET_DEBUG_SWITCH )
     149_printf("\n[DEBUG SWITCH] P[%d,%d,%d] _load_writable_segments() : "
     150        "load Program-Header-Table\n", x , y , p );
     151#endif
     152
     153    // set Program-Header-Table pointer
     154    Elf32_Phdr*  elf_pht_ptr = (Elf32_Phdr*)buf;
     155   
     156    // scan segments to  load all loadable & writable segments
     157    unsigned int seg_id;
     158    for (seg_id = 0 ; seg_id < nsegments ; seg_id++)
     159    {
     160        if ( (elf_pht_ptr[seg_id].p_type == PT_LOAD) &&    // loadable
     161             (elf_pht_ptr[seg_id].p_flags & PF_W) )        // writable
     162        {
     163            // Get segment attributes
     164            unsigned int seg_vaddr  = elf_pht_ptr[seg_id].p_vaddr;
     165            unsigned int seg_offset = elf_pht_ptr[seg_id].p_offset;
     166            unsigned int seg_size   = elf_pht_ptr[seg_id].p_filesz;
     167
     168            // load the segment
     169            if ( _fat_lseek( fd, seg_offset, SEEK_SET ) ) return 1;
     170            if ( _fat_read( fd, (void*)seg_vaddr, seg_size ) ) return 1;
     171
     172#if GIET_DEBUG_SWITCH
     173if ( _get_proctime() > GIET_DEBUG_SWITCH )
     174_printf("\n[DEBUG SWITCH] P[%d,%d,%d] _load_writable_segments() : load segment %x\n",
     175        x , y , p , seg_vaddr );
     176#endif
     177
     178        }
     179    }  // end loop on writable & loadable segments
     180
     181    // close .elf file
     182    _fat_close( fd );
     183
     184    return 0;
     185}  // end load_writable_segments()
     186                             
     187
     188
     189///////////////////////////////////////////////
    80190static void _ctx_exec_task( unsigned int ltid )
    81191{
    82     // get scheduler address
    83     static_scheduler_t* psched = (static_scheduler_t*)_get_sched();
    84 
    85     // TODO: reload .data segment
    86 
    87     // find initial stack pointer
     192    // get pointers in mapping
    88193    mapping_header_t * header  = (mapping_header_t *)SEG_BOOT_MAPPING_BASE;
    89194    mapping_task_t   * task    = _get_task_base(header);
    90195    mapping_vseg_t   * vseg    = _get_vseg_base(header);
     196    mapping_vspace_t * vspace  = _get_vspace_base(header);
     197
     198    // get scheduler address for processor running the calling task
     199    static_scheduler_t* psched = (static_scheduler_t*)_get_sched();
     200
     201    // get global task index, vspace index, and stack vseg index
    91202    unsigned int task_id       = psched->context[ltid][CTX_GTID_ID];
     203    unsigned int vspace_id     = psched->context[ltid][CTX_VSID_ID];
    92204    unsigned int vseg_id       = task[task_id].stack_vseg_id;
     205
     206#if GIET_DEBUG_SWITCH
     207unsigned int gpid       = _get_procid();
     208unsigned int cluster_xy = gpid >> P_WIDTH;
     209unsigned int p          = gpid & ((1<<P_WIDTH)-1);
     210unsigned int x          = cluster_xy >> Y_WIDTH;
     211unsigned int y          = cluster_xy & ((1<<Y_WIDTH)-1);
     212if ( _get_proctime() > GIET_DEBUG_SWITCH )
     213_printf("\n[DEBUG SWITCH] P[%d,%d,%d] _ctx_exec_task() : enters for %s\n",
     214        x , y , p , task[task_id].name );
     215#endif
     216
     217    // reload writable segments
     218    if ( _load_writable_segments( &vspace[vspace_id] ) )
     219    {
     220         _printf("[GIET ERROR] in _ctx_exec_task() for task %s\n",
     221                 task[task_id].name );
     222         return;
     223    }
     224
     225    // find initial stack pointer
    93226    unsigned int sp_value      = vseg[vseg_id].vbase + vseg[vseg_id].length;
    94227
     
    190323    if (found == 0) next_task_id = IDLE_TASK_INDEX;
    191324
    192 #if GIET_DEBUG_SWITCH
     325#if ( GIET_DEBUG_SWITCH & 0x1 )
    193326unsigned int x = cluster_xy >> Y_WIDTH;
    194327unsigned int y = cluster_xy & ((1<<Y_WIDTH)-1);
     328if ( _get_proctime() > GIET_DEBUG_SWITCH )
    195329_printf("\n[DEBUG SWITCH] (%d) -> (%d) on processor[%d,%d,%d] at cycle %d\n",
    196330        curr_task_id, next_task_id, x, y , lpid, _get_proctime() );
  • soft/giet_vm/giet_kernel/irq_handler.c

    r697 r702  
    415415    _xcu_timer_reset_irq( cluster_xy, irq_id );
    416416
    417 #if GIET_DEBUG_SWITCH
     417#if (GIET_DEBUG_SWITCH & 0x1)
    418418unsigned int ltid  = _get_current_task_id();
     419if ( _get_proctime() > GIET_DEBUG_SWITCH )
    419420_printf("\n[DEBUG SWITCH] P[%d,%d,%d] enters _isr_tick() at cycle %d\n"
    420421        "  WTI index = %d / current ltid = %d\n",
Note: See TracChangeset for help on using the changeset viewer.