Ignore:
Timestamp:
Nov 20, 2020, 12:30:31 AM (3 years ago)
Author:
alain
Message:

Mainly cosmetic.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/hal/tsar_mips32/core/hal_context.c

    r654 r679  
    120120error_t hal_cpu_context_alloc( thread_t * thread )
    121121{
    122     assert( (sizeof(hal_cpu_context_t) <= CONFIG_CPU_CTX_SIZE) ,
    123     "illegal CPU context size" );
     122
     123assert( __FUNCTION__, (sizeof(hal_cpu_context_t) <= CONFIG_CPU_CTX_SIZE), "illegal CPU context size" );
    124124
    125125    // allocate memory for cpu_context
     
    139139}   // end hal_cpu_context_alloc()
    140140
    141 /////////////////////////////////////////////////
    142 // The following context slots are initialised
    143 // GPR : a0_04 / sp_29 / ra_31
     141//////////////////////////////////////////////////////////////////////////////
     142// The following context slots are initialised for the MIPS32 architecture
     143// GPR : a0_04 / a1_05 / sp_29 / ra_31
    144144// CP0 : c0_sr / c0_th / c0_epc
    145145// CP2 : c2_ptpr / c2_mode
    146 /////////////////////////////////////////////////
    147 void hal_cpu_context_init( thread_t * thread )
     146//////////////////////////////////////////////////////////////////////////////
     147void hal_cpu_context_init( thread_t * thread,
     148                           bool_t     is_main,
     149                           uint32_t   argc,
     150                           intptr_t   argv )
    148151{
    149152    hal_cpu_context_t * context = (hal_cpu_context_t *)thread->cpu_context;
    150153
    151     assert( (context != NULL ), "CPU context not allocated" );
     154assert( __FUNCTION__, (context != NULL ), "CPU context not allocated" );
    152155
    153156    // compute the PPN for the GPT PT1
     
    155158
    156159    // initialisation depends on thread type
    157     if( thread->type == THREAD_USER )
     160    if( (thread->type == THREAD_USER) && (is_main != 0) )
     161    {
     162        context->a0_04   = (uint32_t)argc;
     163        context->a1_05   = (uint32_t)argv;
     164        context->sp_29   = (uint32_t)thread->user_stack_vseg->max - 8;
     165        context->ra_31   = (uint32_t)&hal_kentry_eret;
     166        context->c0_epc  = (uint32_t)thread->entry_func;
     167        context->c0_sr   = SR_USR_MODE;
     168            context->c0_th   = (uint32_t)thread;
     169            context->c2_ptpr = (uint32_t)(gpt_pt1_ppn >> 1);
     170        context->c2_mode = 0xF;
     171    }
     172    else if( (thread->type == THREAD_USER) && (is_main == 0) )
    158173    {
    159174        context->a0_04   = (uint32_t)thread->entry_args;
     
    353368}  // end hal_cpu_context_fork()
    354369
    355 //////////////////////////////////////////////
    356 void hal_cpu_context_exec( thread_t * thread )
    357 {
    358     // re_initialize CPU context
    359     hal_cpu_context_init( thread );
    360 
    361     // restore CPU registers ... and jump to user code
    362     hal_do_cpu_restore( (hal_cpu_context_t *)thread->cpu_context );
    363 
    364 } // end hal_cpu_context_exec()
    365 
    366370/////////////////////////////////////////////////
    367371void hal_cpu_context_display( xptr_t  thread_xp )
     
    379383    uint32_t sp_29   = hal_remote_l32( XPTR( cxy , &ctx->sp_29   ) );
    380384    uint32_t ra_31   = hal_remote_l32( XPTR( cxy , &ctx->ra_31   ) );
     385    uint32_t a0_04   = hal_remote_l32( XPTR( cxy , &ctx->a0_04   ) );
     386    uint32_t a1_05   = hal_remote_l32( XPTR( cxy , &ctx->a1_05   ) );
    381387    uint32_t c0_sr   = hal_remote_l32( XPTR( cxy , &ctx->c0_sr   ) );
    382388    uint32_t c0_epc  = hal_remote_l32( XPTR( cxy , &ctx->c0_epc  ) );
     
    386392   
    387393    printk("\n***** CPU context for thread %x in process %x / cycle %d\n"
    388            " sp_29   = %X    ra_31  = %X\n"
    389            " c0_sr   = %X    c0_epc  = %X    c0_th = %X\n"
    390            " c2_ptpr = %X    c2_mode = %X\n",
     394           " sp_29   = %X  ra_31   = %X  a0_04 = %X   a1_05 = %X\n"
     395           " c0_sr   = %X  c0_epc  = %X  c0_th = %X\n"
     396           " c2_ptpr = %X  c2_mode = %X\n",
    391397           ptr, ptr->process->pid, (uint32_t)hal_get_cycles(),
    392            sp_29   , ra_31,
     398           sp_29   , ra_31   , a0_04 , a1_05,
    393399           c0_sr   , c0_epc  , c0_th,
    394400           c2_ptpr , c2_mode );
     
    417423
    418424
     425
     426
     427
     428
    419429//////////////////////////////////////////////////
    420430error_t hal_fpu_context_alloc( thread_t * thread )
    421431{
    422     assert( (sizeof(hal_fpu_context_t) <= CONFIG_FPU_CTX_SIZE) ,
     432    assert( __FUNCTION__, (sizeof(hal_fpu_context_t) <= CONFIG_FPU_CTX_SIZE) ,
    423433    "illegal CPU context size" );
    424434
     
    444454    hal_fpu_context_t * context = thread->fpu_context;
    445455
    446     assert( (context != NULL) , "fpu context not allocated" );
     456    assert( __FUNCTION__, (context != NULL) , "fpu context not allocated" );
    447457
    448458    memset( context , 0 , sizeof(hal_fpu_context_t) );
     
    453463                           thread_t * src )
    454464{
    455     assert( (src != NULL) , "src thread pointer is NULL\n");
    456     assert( (dst != NULL) , "dst thread pointer is NULL\n");
     465    assert( __FUNCTION__, (src != NULL) , "src thread pointer is NULL\n");
     466    assert( __FUNCTION__, (dst != NULL) , "dst thread pointer is NULL\n");
    457467
    458468    // get fpu context pointers
Note: See TracChangeset for help on using the changeset viewer.