Changeset 369 for trunk/kernel


Ignore:
Timestamp:
Aug 14, 2017, 12:36:52 PM (7 years ago)
Author:
max@…
Message:

style

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/kernel/kern/do_exception.c

    r325 r369  
    11/*
    22 * do_exception.c - architecture independant exception handler implementation.
    3  * 
     3 *
    44 * Author        Alain Greiner (2016)
    55 *
     
    4545
    4646/////////////////////////////////////////////////////////////////////////////////////////
    47 // This remote_spinlock is a kernel global variable defined in all clusters. 
     47// This remote_spinlock is a kernel global variable defined in all clusters.
    4848// It must be used by the architecture-specific exception handlers to display
    4949// error messages on the kernel terminal. Only the spinlock in the I/O cluster is used.
     
    5555//////////////////////////////////////////////////////////////////////////////////////////
    5656// This static function is called by the generic do_exception() handler when an MMU
    57 // exception has been detected. 
     57// exception has been detected.
    5858// It get the relevant exception arguments from the MMU.
    5959// It signal a fatal error in case of illegal access. In case of page fault,
     
    6666// @ return EXCP_NON_FATAL / EXCP_USER_ERROR / EXCP_KERNEL_PANIC
    6767//////////////////////////////////////////////////////////////////////////////////////////
    68 static error_t mmu_exception( thread_t * this ) 
     68static error_t mmu_exception( thread_t * this )
    6969{
    70         vseg_t         * vseg;        // vseg containing the bad_vaddr
    71         process_t      * process;     // local process descriptor
     70    vseg_t         * vseg;        // vseg containing the bad_vaddr
     71    process_t      * process;     // local process descriptor
    7272    error_t          error;       // return value
    7373
     
    7979    intptr_t         bad_vaddr;
    8080    uint32_t         excp_code;
    81        
     81
    8282    process     = this->process;
    8383
    8484    // get relevant values from MMU
    85         hal_get_mmu_excp( &mmu_ins_excp_code,
    86                           &mmu_ins_bad_vaddr,
    87                           &mmu_dat_excp_code,
    88                           &mmu_dat_bad_vaddr );
     85    hal_get_mmu_excp( &mmu_ins_excp_code,
     86                      &mmu_ins_bad_vaddr,
     87                      &mmu_dat_excp_code,
     88                      &mmu_dat_bad_vaddr );
    8989
    9090    // get exception code and faulty vaddr
     
    104104    }
    105105
    106         vmm_dmsg("\n[INFO] %s : enters for thread %x / process %x"
    107              " / bad_vaddr = %x / excep_code = %x\n", 
    108                      __FUNCTION__, this->trdid , process->pid , bad_vaddr , excp_code );
     106    vmm_dmsg("\n[INFO] %s : enters for thread %x / process %x"
     107             " / bad_vaddr = %x / excep_code = %x\n",
     108             __FUNCTION__, this->trdid , process->pid , bad_vaddr , excp_code );
    109109
    110110    // a kernel thread should not rise an MMU exception
    111         if( this->type != THREAD_USER )
    112         {
    113                 printk("\n[PANIC] in %s : thread %x is a kernel thread / vaddr = %x\n",
    114                        __FUNCTION__ , this->trdid , bad_vaddr );
    115                 return EXCP_KERNEL_PANIC;
    116         }
    117  
    118     // enable IRQs 
    119         hal_enable_irq( NULL );
     111    if( this->type != THREAD_USER )
     112    {
     113        printk("\n[PANIC] in %s : thread %x is a kernel thread / vaddr = %x\n",
     114               __FUNCTION__ , this->trdid , bad_vaddr );
     115        return EXCP_KERNEL_PANIC;
     116    }
     117
     118    // enable IRQs
     119    hal_enable_irq( NULL );
    120120
    121121    // vaddr must be contained in a registered vseg
     
    123123
    124124    if( vseg == NULL )   // vseg not found in local cluster
    125         {
     125    {
    126126        // get extended pointer on reference process
    127127        xptr_t ref_xp = process->ref_xp;
    128128
    129         // get cluster and local pointer on reference process 
     129        // get cluster and local pointer on reference process
    130130        cxy_t       ref_cxy = GET_CXY( ref_xp );
    131131        process_t * ref_ptr = (process_t *)GET_PTR( ref_xp );
     
    136136            xptr_t vseg_xp;
    137137            rpc_vmm_get_ref_vseg_client( ref_cxy , ref_ptr , bad_vaddr , &vseg_xp );
    138            
    139        
    140             if( vseg == NULL )          // vseg not found => illegal user vaddr
     138
     139            if( vseg == NULL )          // vseg not found => illegal user vaddr
    141140            {
    142141                printk("\n[ERROR] in %s for thread %x : illegal vaddr = %x\n",
     
    144143
    145144                hal_disable_irq( NULL );
    146                         return EXCP_USER_ERROR;
     145                return EXCP_USER_ERROR;
    147146            }
    148147            else                        // vseg found => make a local copy
     
    153152                if( vseg == NULL )
    154153                {
    155                             printk("\n[PANIC] in %s : no memory for vseg / thread = %x\n",
    156                                    __FUNCTION__ , this->trdid );
     154                    printk("\n[PANIC] in %s : no memory for vseg / thread = %x\n",
     155                           __FUNCTION__ , this->trdid );
    157156                    hal_disable_irq( NULL );
    158                             return EXCP_KERNEL_PANIC;
     157                    return EXCP_KERNEL_PANIC;
    159158                }
    160159
     
    172171
    173172            hal_disable_irq( NULL );
    174                     return EXCP_USER_ERROR;
    175         }
    176     }
    177 
    178         vmm_dmsg("\n[INFO] %s : found vseg for thread %x / vseg_min = %x / vseg_max = %x\n",
    179                         __FUNCTION__ , this->trdid , vseg->min , vseg->max );
     173            return EXCP_USER_ERROR;
     174        }
     175    }
     176
     177    vmm_dmsg("\n[INFO] %s : found vseg for thread %x / vseg_min = %x / vseg_max = %x\n",
     178            __FUNCTION__ , this->trdid , vseg->min , vseg->max );
    180179
    181180    // analyse exception code
     
    183182    {
    184183        // try to map the unmapped PTE
    185         error = vmm_handle_page_fault( process, 
     184        error = vmm_handle_page_fault( process,
    186185                                       vseg,
    187186                                       bad_vaddr >> CONFIG_PPM_PAGE_SHIFT );  // vpn
     
    193192
    194193            hal_disable_irq( NULL );
    195                     return EXCP_KERNEL_PANIC;
     194            return EXCP_KERNEL_PANIC;
    196195        }
    197196        else
    198197        {
    199198            vmm_dmsg("\n[INFO] %s : page fault handled for vaddr = %x in thread %x\n",
    200                              __FUNCTION__ , bad_vaddr , this->trdid );
    201  
     199                     __FUNCTION__ , bad_vaddr , this->trdid );
     200
    202201            // page fault successfully handled
    203202            hal_disable_irq( NULL );
    204203
    205204            // TODO Pourquoi ce yield ? [AG]
    206             // sched_yield(); 
     205            // sched_yield();
    207206
    208207            return EXCP_NON_FATAL;
     
    234233    }
    235234
    236     else  // this is a kernel error => panic   
     235    else  // this is a kernel error => panic
    237236    {
    238237        printk("\n[PANIC] in %s for thread %x : kernel exception = %x / vaddr = %x\n",
     
    242241        return EXCP_KERNEL_PANIC;
    243242    }
    244  
     243
    245244} // end mmu_exception_handler()
    246245
    247246//////////////////////////////////////////////////////////////////////////////////////////
    248 // This static function is called by the generic do_exception() handler when a 
    249 // FPU Coprocessor Unavailable exception has been detected by the calling thread. 
    250 // It enables the FPU, It saves the current FPU context in the current owner thread 
     247// This static function is called by the generic do_exception() handler when a
     248// FPU Coprocessor Unavailable exception has been detected by the calling thread.
     249// It enables the FPU, It saves the current FPU context in the current owner thread
    251250// descriptor if required, and restore the FPU context from the calling thread descriptor.
    252251//////////////////////////////////////////////////////////////////////////////////////////
     
    256255static error_t fpu_exception( thread_t * this )
    257256{
    258         core_t   * core = this->core;
    259 
    260     // enable FPU 
    261         hal_fpu_enable();
    262 
    263     // save FPU context in current owner thread if required 
    264         if( core->fpu_owner != NULL )
     257    core_t   * core = this->core;
     258
     259    // enable FPU
     260    hal_fpu_enable();
     261
     262    // save FPU context in current owner thread if required
     263    if( core->fpu_owner != NULL )
    265264    {
    266265        if( core->fpu_owner != this )
    267             {
    268                     hal_fpu_context_save ( core->fpu_owner->fpu_context );
    269         }
    270         }
     266        {
     267            hal_fpu_context_save ( core->fpu_owner->fpu_context );
     268        }
     269    }
    271270
    272271    // attach the FPU to the requesting thread
    273         hal_fpu_context_restore( this->fpu_context );
    274         core->fpu_owner = this;
    275 
    276         return EXCP_NON_FATAL;
     272    hal_fpu_context_restore( this->fpu_context );
     273    core->fpu_owner = this;
     274
     275    return EXCP_NON_FATAL;
    277276}
    278277
     
    284283    error_t error;
    285284
    286         // update user time     
    287         thread_user_time_update( this );
     285    // update user time
     286    thread_user_time_update( this );
    288287
    289288    // try to handle non fatal exception
    290289    if( is_mmu ) error = mmu_exception( this );
    291290    else         error = fpu_exception( this );
    292            
     291
    293292    // handle pending signals for interrupted thread
    294293    thread_signals_handle( this );
    295294
    296         // update kernel time
    297         thread_kernel_time_update( this );
     295    // update kernel time
     296    thread_kernel_time_update( this );
    298297
    299298    return error;
Note: See TracChangeset for help on using the changeset viewer.