Ignore:
Timestamp:
Nov 1, 2018, 12:39:27 PM (5 years ago)
Author:
alain
Message:

Modify the GPT (Generic Page Table) API to support remote accesses,
in order to improve page faults and COW handling.

File:
1 edited

Legend:

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

    r570 r587  
    4646
    4747//////////////////////////////////////////////////////////////////////////////////////////
    48 // This enum defines the global exception types after analysis by the exception handler.
    49 //////////////////////////////////////////////////////////////////////////////////////////
    50 
    51 typedef enum
    52 {
    53     EXCP_NON_FATAL,
    54     EXCP_USER_ERROR,
    55     EXCP_KERNEL_PANIC,
    56 }
    57 exception_handling_type_t;
    58 
    59 //////////////////////////////////////////////////////////////////////////////////////////
    6048// This enum defines the mask values for an MMU exception code reported by the mips32.
    6149//////////////////////////////////////////////////////////////////////////////////////////
     
    219207uint32_t cycle = (uint32_t)hal_get_cycles();
    220208if( DEBUG_HAL_EXCEPTIONS < cycle )
    221 printk("\n[DBG] %s : thread %x in process %x enter / is_ins %d / %s / vaddr %x / cycle %d\n",
    222 __FUNCTION__, this->trdid, process->pid,
     209printk("\n[DBG] %s : thread[%x,%x] enter / is_ins %d / %s / vaddr %x / cycle %d\n",
     210__FUNCTION__, process->pid, this->trdid,
    223211is_ins, hal_mmu_exception_str(excp_code), bad_vaddr, cycle);
    224212#endif
     
    234222            // try to map the unmapped PTE
    235223            error = vmm_handle_page_fault( process,
    236                                            bad_vaddr >> CONFIG_PPM_PAGE_SHIFT,  // vpn
    237                                            false );                             // not a COW
    238             if( error )   
    239             {
    240                 printk("\n[USER ERROR] in %s for thread %x in process %x\n"
    241                 "   cannot map vaddr = %x / is_ins %d / epc %x\n",
    242                 __FUNCTION__, this->trdid, this->process->pid, bad_vaddr, is_ins, excPC );
    243 
    244                         return EXCP_USER_ERROR;
    245             }
    246             else            // page fault successfull
     224                                           bad_vaddr >> CONFIG_PPM_PAGE_SHIFT );
     225
     226            if( error == EXCP_NON_FATAL )            // page-fault successfully handled
    247227            {
    248228
     
    250230cycle = (uint32_t)hal_get_cycles();
    251231if( DEBUG_HAL_EXCEPTIONS < cycle )
    252 printk("\n[DBG] %s : thread %x in process %x exit / page-fault handled for vaddr = %x\n",
    253 __FUNCTION__, this->trdid, process->pid, bad_vaddr );
     232printk("\n[DBG] %s : thread[%x,%x] exit / page-fault handled for vaddr = %x\n",
     233__FUNCTION__, process->pid, this->trdid, bad_vaddr );
    254234#endif
    255235 
    256236                return EXCP_NON_FATAL;
    257237            }
     238            else if( error == EXCP_USER_ERROR )      // illegal vaddr
     239            {
     240                printk("\n[USER ERROR] in %s for thread %x in process %x\n"
     241                "   illegal vaddr = %x / is_ins %d / epc %x\n",
     242                __FUNCTION__, this->trdid, this->process->pid, bad_vaddr, is_ins, excPC );
     243
     244                        return EXCP_USER_ERROR;
     245            }
     246            else  // error == EXCP_KERNEL_PANIC 
     247            {
     248                printk("\n[KERNEL ERROR] in %s for thread %x in process %x\n"
     249                "   no memory to map vaddr = %x / is_ins %d / epc %x\n",
     250                __FUNCTION__, this->trdid, this->process->pid, bad_vaddr, is_ins, excPC );
     251
     252                        return EXCP_KERNEL_PANIC;
     253            }
    258254        }
    259255        case MMU_WRITE_PRIVILEGE_VIOLATION:  // illegal access user error
    260256        case MMU_READ_PRIVILEGE_VIOLATION:
    261257        {
    262             printk("\n[USER ERROR] in %s for thread %x in process %x\n"
     258            printk("\n[USER ERROR] in %s : thread %x in process %x\n"
    263259            "   illegal user access to vaddr = %x / is_ins %d / epc %x\n",
    264260            __FUNCTION__, this->trdid, this->process->pid, bad_vaddr, is_ins, excPC );
     
    275271            {
    276272                // try to allocate and copy the page
    277                 error = vmm_handle_page_fault( process,
    278                                                bad_vaddr >> CONFIG_PPM_PAGE_SHIFT,  // vpn
    279                                                true );                              // COW
    280                 if( error )
    281                 {
    282                     printk("\n[USER ERROR] in %s for thread %x in process %x\n"
    283                     "   cannot cow vaddr = %x / is_ins %d / epc %x\n",
    284                     __FUNCTION__, this->trdid, this->process->pid, bad_vaddr, is_ins, excPC );
    285 
    286                             return EXCP_USER_ERROR;
    287                 }
    288                 else         // Copy on write successfull
     273                error = vmm_handle_cow( process,
     274                                        bad_vaddr >> CONFIG_PPM_PAGE_SHIFT );
     275
     276                if( error == EXCP_NON_FATAL )        // Copy on write successfull
    289277                {
    290278
     
    292280cycle = (uint32_t)hal_get_cycles();
    293281if( DEBUG_HAL_EXCEPTIONS < cycle )
    294 printk("\n[DBG] %s : thread %x in process %x exit / copy-on-write handled for vaddr = %x\n",
    295 __FUNCTION__, this->trdid, process->pid, bad_vaddr );
     282printk("\n[DBG] %s : thread[%x,%x] exit / copy-on-write handled for vaddr = %x\n",
     283__FUNCTION__, process->pid, this->trdid, bad_vaddr );
    296284#endif
    297285
    298286                    return EXCP_NON_FATAL;
    299287                }
     288                else if( error == EXCP_USER_ERROR )  // illegal user access
     289                {
     290                    printk("\n[USER ERROR] in %s : thread %x in process %x\n"
     291                    "   cannot cow vaddr = %x / is_ins %d / epc %x\n",
     292                    __FUNCTION__, this->trdid, this->process->pid, bad_vaddr, is_ins, excPC );
     293
     294                            return EXCP_USER_ERROR;
     295                }
     296                else   // error == EXCP_KERNEL_PANIC
     297                {
     298                    printk("\n[KERNEL ERROR] in %s : thread %x in process %x\n"
     299                    "   no memoty to cow vaddr = %x / is_ins %d / epc %x\n",
     300                    __FUNCTION__, this->trdid, this->process->pid, bad_vaddr, is_ins, excPC );
     301
     302                            return EXCP_USER_ERROR;
     303                }
    300304            }
    301305            else                             // non writable user error
    302306            {
    303                 printk("\n[USER ERROR] in %s for thread %x in process %x\n"
     307                printk("\n[USER ERROR] in %s : thread %x in process %x\n"
    304308                "   non-writable vaddr = %x / is_ins %d / epc %x\n",
    305309                __FUNCTION__, this->trdid, this->process->pid, bad_vaddr, is_ins, excPC );
     
    310314        case MMU_READ_EXEC_VIOLATION:        // user error
    311315        {
    312             printk("\n[USER_ERROR] in %s for thread %x in process %x\n"
     316            printk("\n[USER_ERROR] in %s : thread %x in process %x\n"
    313317            "   non-executable vaddr = %x / is_ins %d / epc %x\n",
    314318            __FUNCTION__, this->trdid, this->process->pid, bad_vaddr, is_ins, excPC );
     
    318322        default:                             // this is a kernel error   
    319323        {
    320             printk("\n[KERNEL ERROR] in %s for thread %x in process %x\n"
     324            printk("\n[KERNEL ERROR] in %s : thread %x in process %x\n"
    321325            "  epc %x / badvaddr %x / is_ins %d\n",
    322326            __FUNCTION__, this->trdid, this->process->pid, excPC, bad_vaddr, is_ins );
Note: See TracChangeset for help on using the changeset viewer.