Ignore:
Timestamp:
Aug 2, 2018, 11:47:13 AM (6 years ago)
Author:
alain
Message:

This version modifies the exec syscall and fixes a large number of small bugs.
The version number has been updated (0.1)

Location:
trunk/hal/tsar_mips32/core
Files:
14 edited

Legend:

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

    r62 r457  
    2222 */
    2323
    24 #include <hal_types.h>
     24#include <hal_kernel_types.h>
    2525
    2626////////////////////////////////////
  • trunk/hal/tsar_mips32/core/hal_context.c

    r432 r457  
    2222 */
    2323
    24 #include <hal_types.h>
     24#include <hal_kernel_types.h>
    2525#include <hal_switch.h>
    2626#include <memcpy.h>
     
    136136}   // end hal_cpu_context_alloc()
    137137
    138 ///////////////////////////////////////////////////
    139 // The following context slots are initialised :
     138/////////////////////////////////////////////////
     139// The following context slots are initialised
    140140// GPR : a0_04 / sp_29 / ra_31
    141141// CP0 : c0_sr / c0_th / c0_epc
    142142// CP2 : c2_ptpr / c2_mode
    143 ///////////////////////////////////////////////////
    144 error_t hal_cpu_context_create( thread_t * thread )
    145 {
    146     // allocate memory for a CPU context
    147     error_t error = hal_cpu_context_alloc( thread );
    148 
    149     if( error ) return error;
    150 
     143/////////////////////////////////////////////////
     144void hal_cpu_context_init( thread_t * thread )
     145{
    151146    hal_cpu_context_t * context = (hal_cpu_context_t *)thread->cpu_context;
     147
     148    assert( (context != NULL ), __FUNCTION__, "CPU context not allocated" );
    152149
    153150    // initialisation depends on thread type
     
    173170        context->c2_mode = 0x3;
    174171    }
    175 
    176     return 0;
    177 
    178 }  // end hal_cpu_context_create()
     172}  // end hal_cpu_context_init()
    179173
    180174////////////////////////////////////////////
     
    243237        assert( (current == child_ptr) , __FUNCTION__ , "current = %x / child = %x\n");
    244238    }
    245 
    246239}  // end hal_cpu_context_fork()
     240
     241//////////////////////////////////////////////
     242void hal_cpu_context_exec( thread_t * thread )
     243{
     244    // re_initialize CPU context
     245    hal_cpu_context_init( thread );
     246
     247    // restore CPU registers ... and jump
     248    hal_do_cpu_restore( (hal_cpu_context_t *)thread->cpu_context );
     249
     250} // end hal_cpu_context_exec()
    247251
    248252/////////////////////////////////////////////////
     
    312316
    313317}   // end hal_fpu_context_alloc()
     318
     319//////////////////////////////////////////////
     320void hal_fpu_context_init( thread_t * thread )
     321{
     322    hal_fpu_context_t * context = thread->fpu_context;
     323
     324    assert( (context != NULL) , __FUNCTION__ , "fpu context not allocated" );
     325
     326    memset( context , 0 , sizeof(hal_fpu_context_t) );
     327}
    314328
    315329//////////////////////////////////////////
  • trunk/hal/tsar_mips32/core/hal_drivers.c

    r407 r457  
    2020 */
    2121
    22 #include <hal_types.h>
     22#include <hal_kernel_types.h>
    2323#include <chdev.h>
    2424#include <hal_drivers.h>
  • trunk/hal/tsar_mips32/core/hal_exception.c

    r440 r457  
    2222 */
    2323
    24 #include <hal_types.h>
     24#include <hal_kernel_types.h>
    2525#include <hal_irqmask.h>
    2626#include <hal_special.h>
     
    134134        core_t   * core = this->core;
    135135
    136     // enable FPU
     136    // enable FPU (in core SR)
    137137        hal_fpu_enable();
    138138
    139     // save FPU context in current owner thread if required
     139    // save FPU register values in current owner thread if required
    140140        if( core->fpu_owner != NULL )
    141141    {
    142142        if( core->fpu_owner != this )
    143143            {
     144            // save the FPU registers to current owner thread context
    144145                    hal_fpu_context_save( XPTR( local_cxy , core->fpu_owner ) );
     146
     147            // restore FPU registers from requesting thread context
     148                hal_fpu_context_restore( this->fpu_context );
     149
     150            // attach the FPU to the requesting thread
     151                core->fpu_owner = this;
    145152        }
    146153        }
    147 
    148     // attach the FPU to the requesting thread
    149         hal_fpu_context_restore( this->fpu_context );
    150         core->fpu_owner = this;
     154    else
     155    {
     156        // restore FPU registers from requesting thread context
     157            hal_fpu_context_restore( this->fpu_context );
     158
     159        // attach the FPU to the requesting thread
     160            core->fpu_owner = this;
     161    }
    151162
    152163        return EXCP_NON_FATAL;
     
    206217uint32_t cycle = (uint32_t)hal_get_cycles();
    207218if( DEBUG_HAL_EXCEPTIONS < cycle )
    208 printk("\n[DBG] %s : thread %x enter / is_ins %d / %s / vaddr %x / cycle %d\n",
    209 __FUNCTION__, this, is_ins, hal_mmu_exception_str(excp_code), bad_vaddr, cycle );
     219printk("\n[DBG] %s : thread %x in process %x enter / is_ins %d / %s / vaddr %x / cycle %d\n",
     220__FUNCTION__, this->trdid, process->pid, is_ins, hal_mmu_exception_str(excp_code), bad_vaddr, cycle);
    210221#endif
    211222
     
    235246cycle = (uint32_t)hal_get_cycles();
    236247if( DEBUG_HAL_EXCEPTIONS < cycle )
    237 printk("\n[DBG] %s : thread %x exit / page-fault handled for vaddr = %x\n",
    238 __FUNCTION__ , this , bad_vaddr );
     248printk("\n[DBG] %s : thread %x in process %x exit / page-fault handled for vaddr = %x\n",
     249__FUNCTION__, this->trdid, process->pid, bad_vaddr );
    239250#endif
    240251 
     
    275286cycle = (uint32_t)hal_get_cycles();
    276287if( DEBUG_HAL_EXCEPTIONS < cycle )
    277 printk("\n[DBG] %s : thread %x exit / copy-on-write handled for vaddr = %x\n",
    278 __FUNCTION__ , this , bad_vaddr );
     288printk("\n[DBG] %s : thread %x in process %x exit / copy-on-write handled for vaddr = %x\n",
     289__FUNCTION__, this->trdid, process->pid, bad_vaddr );
    279290#endif
    280291
     
    300311        {
    301312            assert( false , __FUNCTION__ ,
    302             "thread %x / core[%x,%d] / epc %x / vaddr %x / cycle %d\n",
    303             this, local_cxy, this->core->lid, excPC, bad_vaddr, (uint32_t)hal_get_cycles() );
     313            "thread %x in process %x / core[%x,%d] / epc %x / vaddr %x / cycle %d\n",
     314            this->trdid, this->process->pid, local_cxy, this->core->lid,
     315            excPC, bad_vaddr, (uint32_t)hal_get_cycles() );
    304316
    305317            return EXCP_KERNEL_PANIC;
     
    398410uint32_t cycle = (uint32_t)hal_get_cycles();
    399411if( DEBUG_HAL_EXCEPTIONS < cycle )
    400 printk("\n[DBG] %s : thread %x enter / core[%x,%d] / pid %x / epc %x / xcode %x / cycle %d\n",
    401 __FUNCTION__, this, local_cxy, this->core->lid, this->process->pid, excPC, excCode, cycle );
     412printk("\n[DBG] %s : thread %x in process %x enter / core[%x,%d] / epc %x / xcode %x / cycle %d\n",
     413__FUNCTION__, this->trdid, this->process->pid, local_cxy, this->core->lid, excPC, excCode, cycle );
    402414#endif
    403415
     
    458470cycle = (uint32_t)hal_get_cycles();
    459471if( DEBUG_HAL_EXCEPTIONS < cycle )
    460 printk("\n[DBG] %s : thread %x exit / core[%x,%d] / pid %x / epc %x / xcode %x / cycle %d\n",
    461 __FUNCTION__, this, local_cxy, this->core->lid, this->process->pid, excPC, excCode, cycle );
     472printk("\n[DBG] %s : thread %x in process %x exit / core[%x,%d] / epc %x / xcode %x / cycle %d\n",
     473__FUNCTION__, this->trdid, this->process->pid, local_cxy, this->core->lid, excPC, excCode, cycle );
    462474#endif
    463475
  • trunk/hal/tsar_mips32/core/hal_gpt.c

    r445 r457  
    2222 */
    2323
    24 #include <hal_types.h>
     24#include <hal_kernel_types.h>
    2525#include <hal_gpt.h>
    2626#include <hal_special.h>
  • trunk/hal/tsar_mips32/core/hal_interrupt.c

    r435 r457  
    2222 */
    2323
    24 #include <hal_types.h>
     24#include <hal_kernel_types.h>
    2525#include <hal_special.h>
    2626#include <kernel_config.h>
  • trunk/hal/tsar_mips32/core/hal_irqmask.c

    r285 r457  
    2323 */
    2424
    25 #include <hal_types.h>
     25#include <hal_kernel_types.h>
     26#include <hal_shared_types.h>
    2627
    2728//////////////////////////////////////////
  • trunk/hal/tsar_mips32/core/hal_ppm.c

    r443 r457  
    2323
    2424#include <kernel_config.h>
    25 #include <hal_types.h>
     25#include <hal_kernel_types.h>
    2626#include <hal_ppm.h>
    2727#include <hal_special.h>
  • trunk/hal/tsar_mips32/core/hal_remote.c

    r313 r457  
    2323 */
    2424
    25 #include <hal_types.h>
     25#include <hal_kernel_types.h>
    2626#include <hal_irqmask.h>
    2727
  • trunk/hal/tsar_mips32/core/hal_special.c

    r425 r457  
    2323
    2424
    25 #include <hal_types.h>
     25#include <hal_kernel_types.h>
    2626#include <hal_special.h>
    2727#include <core.h>
  • trunk/hal/tsar_mips32/core/hal_switch.S

    r408 r457  
    2626    .global  hal_do_cpu_switch
    2727    .global  hal_do_cpu_save
     28    .global  hal_do_cpu_restore
    2829
    2930    .set     noat
     
    9091        sw      $27,  33*4($26)           /* save c2_mode to slot 33 */
    9192
     93    sync                           
     94
    9295    /* restore new thread context */
    9396 
     
    144147        mtc2    $27,  $1                   /* restore c2_mode from slot 33 */
    145148    mtc0        $26,  $12                  /* restore c0_sr from slot 34 */
    146 
    147     sync                           
    148149
    149150    jr      $31                        /* return to caller */
     
    211212    nop
    212213
     214#---------------------------------------------------------------------------------
     215# The hal_do_cpu_restore()function makes the following assumption:
     216# - register $4 contains a pointer on the target thread context.
     217#---------------------------------------------------------------------------------
     218hal_do_cpu_restore:
     219
     220    move    $26,  $4                  /* $26 <= &context */
     221
     222    lw      $27,   0*4($26)         
     223    mtc0    $27,   $14                 /* restore C0_epc from slot 0 */
     224
     225    lw      $1,    1*4($26)         
     226    lw      $2,    2*4($26)         
     227    lw      $3,    3*4($26)         
     228    lw      $4,    4*4($26)         
     229    lw      $5,    5*4($26)         
     230    lw      $6,    6*4($26)         
     231    lw      $7,    7*4($26)         
     232    lw      $8,    8*4($26)         
     233    lw      $9,    9*4($26)         
     234    lw      $10,  10*4($26)         
     235    lw      $11,  11*4($26)         
     236    lw      $12,  12*4($26)         
     237    lw      $13,  13*4($26)         
     238    lw      $14,  14*4($26)         
     239    lw      $15,  15*4($26)         
     240        lw      $16,  16*4($26)         
     241        lw      $17,  17*4($26)         
     242    lw      $18,  18*4($26)         
     243    lw      $19,  19*4($26)         
     244    lw      $20,  20*4($26)         
     245    lw      $21,  21*4($26)         
     246    lw      $22,  22*4($26)         
     247    lw      $23,  23*4($26)         
     248    lw      $24,  24*4($26)         
     249    lw      $25,  25*4($26)         
     250
     251    lw      $27,  26*4($26)         
     252    mthi    $27                        /* restore hi from slot 26 */
     253    lw      $27,  27*4($26)         
     254    mtlo    $27                        /* restore lo from slot 27 */
     255
     256        lw      $28,  28*4($26)         
     257        lw      $29,  29*4($26)         
     258        lw      $30,  30*4($26)         
     259        lw      $31,  31*4($26)            /* restore ra from slot 31 */
     260
     261        lw      $27,  32*4($26)
     262        mtc2    $27,  $0                   /* restore c2_ptpr from slot 32 */
     263
     264        lw      $27,  35*4($26)     
     265    mtc0        $27,  $4, 2                /* restore c0_th from slot 35 */
     266
     267        lw      $27,  33*4($26)
     268        lw      $26,  34*4($26)
     269
     270        mtc2    $27,  $1                   /* restore c2_mode from slot 33 */
     271    mtc0        $26,  $12                  /* restore c0_sr from slot 34 */
     272
     273    jr      $31                        /* return to caller */
     274    nop
     275
    213276        .set reorder                   
    214277    .set at                         
  • trunk/hal/tsar_mips32/core/hal_syscall.c

    r425 r457  
    2222 */
    2323
    24 #include <hal_types.h>
     24#include <hal_kernel_types.h>
    2525#include <hal_syscall.h>
    2626#include <do_syscall.h>
     
    4848    enter_uzone = (uint32_t *)this->uzone_current;
    4949
    50 //printk("\n@@@ enter %s : thread = %x / enter_uzone = %x / EPC = %x\n",
    51 //__FUNCTION__ , this , enter_uzone , enter_uzone[UZ_EPC] );
    52 
    5350    // get syscall arguments from uzone
    5451        service_num = enter_uzone[UZ_V0];
     
    7168    exit_uzone = (uint32_t *)this->uzone_current;
    7269
    73 //printk("\n@@@ exit %s : thread = %x / exit_uzone = %x / EPC = %x\n",
    74 //__FUNCTION__ , this , exit_uzone , exit_uzone[UZ_EPC] );
    75 
    7670    // set return value to uzone
    7771        exit_uzone[UZ_V0] = retval;
  • trunk/hal/tsar_mips32/core/hal_uspace.c

    r425 r457  
    2525#include <errno.h>
    2626#include <vmm.h>
    27 #include <hal_types.h>
     27#include <hal_kernel_types.h>
    2828#include <hal_uspace.h>
    2929#include <hal_irqmask.h>
  • trunk/hal/tsar_mips32/core/hal_vmm.c

    r411 r457  
    2323
    2424#include <kernel_config.h>
    25 #include <hal_types.h>
     25#include <hal_kernel_types.h>
    2626#include <hal_vmm.h>
    2727#include <hal_gpt.h>
Note: See TracChangeset for help on using the changeset viewer.