Ignore:
Timestamp:
Dec 5, 2017, 4:20:07 PM (4 years ago)
Author:
alain
Message:

Fix several bugs in the fork() syscall.

File:
1 edited

Legend:

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

    r407 r408  
    9999xcode_values_t;
    100100
     101////////////////////////////////////////////////////
     102static char * hal_mmu_exception_str( uint32_t code )
     103{
     104    if     ( code == MMU_WRITE_PT1_UNMAPPED        ) return "WRITE_PT1_UNMAPPED";
     105    else if( code == MMU_WRITE_PT2_UNMAPPED        ) return "WRITE_PT2_UNMAPPED";
     106    else if( code == MMU_WRITE_PRIVILEGE_VIOLATION ) return "WRITE_PRIVILEGE_VIOLATION";
     107    else if( code == MMU_WRITE_ACCESS_VIOLATION    ) return "WRITE_ACCESS_VIOLATION";
     108    else if( code == MMU_WRITE_UNDEFINED_XTN       ) return "WRITE_UNDEFINED_XTN";
     109    else if( code == MMU_WRITE_PT1_ILLEGAL_ACCESS  ) return "WRITE_PT1_ILLEGAL_ACCESS";
     110    else if( code == MMU_WRITE_PT2_ILLEGAL_ACCESS  ) return "WRITE_PT2_ILLEGAL_ACCESS";
     111    else if( code == MMU_WRITE_DATA_ILLEGAL_ACCESS ) return "WRITE_DATA_ILLEGAL_ACCESS";
     112    else if( code == MMU_READ_PT1_UNMAPPED         ) return "READ_PT1_UNMAPPED";
     113    else if( code == MMU_READ_PT2_UNMAPPED         ) return "READ_PT2_UNMAPPED";
     114    else if( code == MMU_READ_PRIVILEGE_VIOLATION  ) return "READ_PRIVILEGE_VIOLATION";
     115    else if( code == MMU_READ_EXEC_VIOLATION       ) return "READ_EXEC_VIOLATION";
     116    else if( code == MMU_READ_UNDEFINED_XTN        ) return "READ_UNDEFINED_XTN";
     117    else if( code == MMU_READ_PT1_ILLEGAL_ACCESS   ) return "READ_PT1_ILLEGAL_ACCESS";
     118    else if( code == MMU_READ_PT2_ILLEGAL_ACCESS   ) return "READ_PT2_ILLEGAL_ACCESS";
     119    else if( code == MMU_READ_DATA_ILLEGAL_ACCESS  ) return "READ_DATA_ILLEGAL_ACCESS";
     120    else                                             return "undefined";
     121}
     122
    101123//////////////////////////////////////////////////////////////////////////////////////////
    102124// This function is called when a FPU Coprocessor Unavailable exception has been
     
    120142        if( core->fpu_owner != this )
    121143            {
    122                     hal_fpu_context_save ( core->fpu_owner->fpu_context );
     144                    hal_fpu_context_save( XPTR( local_cxy , core->fpu_owner ) );
    123145        }
    124146        }
     
    179201    }
    180202
    181  excp_dmsg("\n[DBG] %s : core[%x,%d] / is_ins %d / code %x / vaddr %x\n",
    182 __FUNCTION__ , local_cxy , this->core->lid , is_ins, excp_code, bad_vaddr );
     203// @@@
     204thread_t * parent = (thread_t *)0xa4000;
     205uint32_t cond = (this == 0xe0000) && (hal_time_stamp() > 5380000);
     206
     207if( cond ) hal_gpt_display( this->process );
     208if( cond ) hal_gpt_display( parent->process );
     209if( cond ) printk("\n[DBG] %s : core[%x,%d] / is_ins %d / %s / vaddr %x\n",
     210__FUNCTION__ , local_cxy , this->core->lid , is_ins,
     211hal_mmu_exception_str(excp_code) , bad_vaddr );
    183212
    184213   // analyse exception code
     
    217246            return EXCP_USER_ERROR;
    218247        }
    219         case MMU_WRITE_ACCESS_VIOLATION:     // user error or Copy-on-Write
     248        case MMU_WRITE_ACCESS_VIOLATION:     // user error, or Copy-on-Write
    220249        {
    221250            // access page table to get GPT_COW flag
    222251            bool_t cow = hal_gpt_pte_is_cow( &(process->vmm.gpt),
    223                                              bad_vaddr >> CONFIG_PPM_PAGE_SHIFT );  // vpn
     252                                             bad_vaddr >> CONFIG_PPM_PAGE_SHIFT );
    224253
    225254            if( cow )                        // Copy-on-Write
    226255            {
    227256                // try to allocate and copy the page
    228                 error = vmm_copy_on_write( process,
    229                                            bad_vaddr >> CONFIG_PPM_PAGE_SHIFT );  // vpn
     257                error = vmm_handle_cow( process,
     258                                        bad_vaddr >> CONFIG_PPM_PAGE_SHIFT ); 
    230259                if( error )
    231260                {
     
    238267                {
    239268
    240 excp_dmsg("\n[DBG] %s : core[%x,%d] / copy-on-write handled for vaddr = %x\n",
     269if( cond ) printk("\n[DBG] %s : core[%x,%d] / copy-on-write handled for vaddr = %x\n",
    241270__FUNCTION__ , local_cxy , this->core->lid , bad_vaddr );
    242271
     
    274303//////////////////////////////////////////////////////////////////////////////////////////
    275304// @ this     : pointer on faulty thread descriptor.
    276 // @ regs_tbl : pointer on register array.
     305// @ uzone : pointer on register array.
    277306// @ error    : EXCP_USER_ERROR or EXCP_KERNEL_PANIC
    278307//////////////////////////////////////////////////////////////////////////////////////////
    279308static void hal_exception_dump( thread_t * this,
    280                                 reg_t    * regs_tbl,
     309                                reg_t    * uzone,
    281310                                error_t    error )
    282311{
    283     uint32_t  save_sr;
    284     core_t  * core = this->core;
     312    uint32_t    save_sr;
     313    core_t    * core    = this->core;
     314    process_t * process = this->process;
    285315
    286316    // get pointers on TXT0 chdev
     
    297327    if( error == EXCP_USER_ERROR )
    298328    {
    299         nolock_printk("\n========= USER ERROR / core[%x,%d] / cycle %d ==============\n",
    300         local_cxy , core->lid , (uint32_t)hal_get_cycles() );
     329        nolock_printk("\n=== USER ERROR / trdid %x / pid %x / core[%x,%d] / cycle %d ===\n",
     330        this->trdid, process->pid, local_cxy, core->lid , (uint32_t)hal_get_cycles() );
    301331    }
    302332    else
    303333    {
    304         nolock_printk("\n======= KERNEL PANIC / core[%x,%d] / cycle %d ==============\n",
    305         local_cxy , core->lid , (uint32_t)hal_get_cycles() );
     334        nolock_printk("\n=== KERNEL PANIC / trdid %x / pid %x / core[%x,%d] / cycle %d ===\n",
     335        this->trdid, process->pid, local_cxy, core->lid , (uint32_t)hal_get_cycles() );
    306336    }
    307337
    308         nolock_printk("  thread type = %s / trdid = %x / pid %x / core[%x,%d]\n"
    309            "  local locks = %d / remote locks = %d / blocked_vector = %X\n\n",
    310            thread_type_str(this->type), this->trdid, this->process->pid, local_cxy,
    311            this->core->lid, this->local_locks, this->remote_locks, this->blocked );
    312 
    313         nolock_printk("cp0_cr %X   cp0_epc %X   cp0_sr %X   cp2_mode %X\n",
    314                    regs_tbl[UZ_CR], regs_tbl[UZ_EPC], regs_tbl[UZ_SR], regs_tbl[UZ_MODE]);
    315 
    316     nolock_printk("at_01 %X  v0_2  %X  v1_3  %X  a0_4   %X  a1_5   %X\n",
    317                regs_tbl[UZ_AT],regs_tbl[UZ_V0],regs_tbl[UZ_V1],regs_tbl[UZ_A0],regs_tbl[UZ_A1]);
    318 
    319     nolock_printk("a2_6  %X  a3_7  %X  t0_8  %X  t1_9   %X  t2_10  %X\n",
    320                    regs_tbl[UZ_A2],regs_tbl[UZ_A3],regs_tbl[UZ_T0],regs_tbl[UZ_T1],regs_tbl[UZ_T2]);
     338        nolock_printk("local locks = %d / remote locks = %d / blocked_vector = %X\n\n",
     339    this->local_locks, this->remote_locks, this->blocked );
     340
     341    nolock_printk("c0_cr   %X  c0_epc  %X  c0_sr  %X  c0_th  %X\n",
     342    uzone[UZ_CR], uzone[UZ_EPC], uzone[UZ_SR], uzone[UZ_TH] );
     343
     344    nolock_printk("c2_mode %X  c2_ptpr %X\n",
     345    uzone[UZ_MODE], uzone[UZ_PTPR] );
     346
     347    nolock_printk("at_01   %X  v0_2    %X  v1_3   %X  a0_4   %X  a1_5   %X\n",
     348        uzone[UZ_AT], uzone[UZ_V0], uzone[UZ_V1], uzone[UZ_A0], uzone[UZ_A1] );
     349
     350    nolock_printk("a2_6    %X  a3_7    %X  t0_8   %X  t1_9   %X  t2_10  %X\n",
     351        uzone[UZ_A2], uzone[UZ_A3], uzone[UZ_T0], uzone[UZ_T1], uzone[UZ_T2] );
    321352 
    322     nolock_printk("t3_11 %X  t4_12 %X  t5_13 %X  t6_14  %X  t7_15  %X\n",
    323                    regs_tbl[UZ_T3],regs_tbl[UZ_T4],regs_tbl[UZ_T5],regs_tbl[UZ_T6],regs_tbl[UZ_T7]);
    324 
    325     nolock_printk("s0_16 %X  s1_17 %X  s2_18 %X  s3_19  %X  s4_20  %X\n",
    326                    regs_tbl[UZ_S0],regs_tbl[UZ_S1],regs_tbl[UZ_S2],regs_tbl[UZ_S3],regs_tbl[UZ_S4]);
     353    nolock_printk("t3_11   %X  t4_12   %X  t5_13 %X  t6_14  %X  t7_15  %X\n",
     354        uzone[UZ_T3], uzone[UZ_T4], uzone[UZ_T5], uzone[UZ_T6], uzone[UZ_T7] );
     355
     356    nolock_printk("s0_16   %X  s1_17   %X  s2_18 %X  s3_19  %X  s4_20  %X\n",
     357        uzone[UZ_S0], uzone[UZ_S1], uzone[UZ_S2], uzone[UZ_S3], uzone[UZ_S4] );
    327358 
    328     nolock_printk("s5_21 %X  s6_22 %X  s7_23 %X  s8_24  %X  ra_25  %X\n",
    329                regs_tbl[UZ_S5],regs_tbl[UZ_S6],regs_tbl[UZ_S7],regs_tbl[UZ_T8],regs_tbl[UZ_T9]);
    330 
    331     nolock_printk("gp_28 %X  sp_29 %X  S8_30 %X  ra_31  %X\n",
    332                    regs_tbl[UZ_GP],regs_tbl[UZ_SP],regs_tbl[UZ_S8],regs_tbl[UZ_RA]);
     359    nolock_printk("s5_21   %X  s6_22   %X  s7_23 %X  s8_24  %X  ra_25  %X\n",
     360        uzone[UZ_S5], uzone[UZ_S6], uzone[UZ_S7], uzone[UZ_T8], uzone[UZ_T9] );
     361
     362    nolock_printk("gp_28   %X  sp_29   %X  S8_30 %X  ra_31  %X\n",
     363        uzone[UZ_GP], uzone[UZ_SP], uzone[UZ_S8], uzone[UZ_RA] );
    333364
    334365    // release the lock
     
    337368}  // end hal_exception_dump()
    338369
    339 
    340 ///////////////////////////////////////////////////////////////////////////////
    341 // TODO replace the hal_core_sleep() by the generic panic() function.
    342 ///////////////////////////////////////////////////////////////////////////////
    343 void hal_do_exception( thread_t * this,
    344                        reg_t    * regs_tbl )
    345 {
    346         error_t             error;
    347         uint32_t            excCode;                  // 4 bits XCODE from CP0_CR
     370///////////////////////
     371void hal_do_exception()
     372{
     373    uint32_t   * uzone;
     374    thread_t   * this;
     375        error_t      error;
     376        uint32_t     excCode;                  // 4 bits XCODE from CP0_CR
     377
     378    // get pointer on faulty thread uzone
     379    this  = CURRENT_THREAD;
     380    uzone = (uint32_t *)CURRENT_THREAD->uzone;
    348381
    349382    // get 4 bits XCODE from CP0_CR register
    350         excCode        = (regs_tbl[UZ_CR] >> 2) & 0xF;
     383        excCode        = (uzone[UZ_CR] >> 2) & 0xF;
    351384
    352385excp_dmsg("\n[DBG] %s : core[%x,%d] / thread %x in process %x / xcode %x / cycle %d\n",
    353386__FUNCTION__, local_cxy, this->core->lid, this->trdid,
    354 this->process->pid, excCode, (uint32_t)hal_get_cycle() );
     387this->process->pid, excCode, (uint32_t)hal_get_cycles() );
    355388
    356389        switch(excCode)
     
    368401            case XCODE_CPU:    // can be non fatal
    369402        {
    370             if( ((regs_tbl[UZ_CR] >> 28) & 0x3) == 1 )  // unavailable FPU
     403            if( ((uzone[UZ_CR] >> 28) & 0x3) == 1 )     // unavailable FPU
    371404            {
    372405                error = hal_fpu_exception( this );
     
    395428        if( error == EXCP_USER_ERROR )          //  user error => kill user process
    396429        {
    397         hal_exception_dump( this , regs_tbl , error );
     430        hal_exception_dump( this , uzone , error );
    398431
    399432        // FIXME : replace this loop by sys_kill()
     
    403436    else if( error == EXCP_KERNEL_PANIC )   // kernel error => kernel panic
    404437    {
    405         hal_exception_dump( this , regs_tbl , error );
    406         hal_core_sleep();
     438        hal_exception_dump( this , uzone , error );
     439        panic( "KERNEL_PANIC for thread %x in process %x on core [%x,%d]/n",
     440        this->trdid , this->process->pid , local_cxy , this->core->lid );
    407441    }
    408442
    409443excp_dmsg("\n[DBG] %s : core[%x,%d] exit / thread %x in process %x / cycle %d\n",
    410 __FUNCTION__, local_cxy, this->core->lid, this->trdid, this->process->pid, hal_time_stamp() );
     444__FUNCTION__, local_cxy, this->core->lid, this->trdid, this->process->pid,
     445(uint32_t)hal_get_cycles() );
    411446
    412447}  // end hal_do_exception()
Note: See TracChangeset for help on using the changeset viewer.