[16] | 1 | /* |
---|
| 2 | * hal_exception.c - implementation of exception handler for TSAR-MIPS32. |
---|
| 3 | * |
---|
| 4 | * Author Alain Greiner (2016, 2017) |
---|
| 5 | * |
---|
| 6 | * Copyright (c) UPMC Sorbonne Universites |
---|
| 7 | * |
---|
| 8 | * This file is part of ALMOS-MKH. |
---|
| 9 | * |
---|
| 10 | * ALMOS-MKH is free software; you can redistribute it and/or modify it |
---|
| 11 | * under the terms of the GNU General Public License as published by |
---|
| 12 | * the Free Software Foundation; version 2.0 of the License. |
---|
| 13 | * |
---|
| 14 | * ALMOS-MKH is distributed in the hope that it will be useful, but |
---|
| 15 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
| 17 | * General Public License for more details. |
---|
| 18 | * |
---|
| 19 | * You should have received a copy of the GNU General Public License |
---|
| 20 | * along with ALMOS-MKH; if not, write to the Free Software Foundation, |
---|
| 21 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
| 22 | */ |
---|
| 23 | |
---|
[457] | 24 | #include <hal_kernel_types.h> |
---|
[16] | 25 | #include <hal_irqmask.h> |
---|
[406] | 26 | #include <hal_special.h> |
---|
[16] | 27 | #include <hal_exception.h> |
---|
| 28 | #include <thread.h> |
---|
| 29 | #include <printk.h> |
---|
[380] | 30 | #include <chdev.h> |
---|
[16] | 31 | #include <vmm.h> |
---|
| 32 | #include <errno.h> |
---|
| 33 | #include <scheduler.h> |
---|
| 34 | #include <core.h> |
---|
| 35 | #include <syscalls.h> |
---|
[440] | 36 | #include <shared_syscalls.h> |
---|
[16] | 37 | #include <remote_spinlock.h> |
---|
[406] | 38 | #include <hal_kentry.h> |
---|
[16] | 39 | |
---|
[505] | 40 | #include <hal_exception.h> |
---|
[380] | 41 | |
---|
[16] | 42 | ////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 43 | // Extern global variables |
---|
| 44 | ////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 45 | |
---|
[380] | 46 | extern chdev_directory_t chdev_dir; // allocated in the kernel_init.c file. |
---|
[16] | 47 | |
---|
| 48 | ////////////////////////////////////////////////////////////////////////////////////////// |
---|
[381] | 49 | // This enum defines the global exception types after analysis by the exception handler. |
---|
| 50 | ////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 51 | |
---|
| 52 | typedef enum |
---|
| 53 | { |
---|
| 54 | EXCP_NON_FATAL, |
---|
| 55 | EXCP_USER_ERROR, |
---|
| 56 | EXCP_KERNEL_PANIC, |
---|
| 57 | } |
---|
| 58 | exception_handling_type_t; |
---|
| 59 | |
---|
| 60 | ////////////////////////////////////////////////////////////////////////////////////////// |
---|
[407] | 61 | // This enum defines the mask values for an MMU exception code reported by the mips32. |
---|
[381] | 62 | ////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 63 | |
---|
| 64 | typedef enum |
---|
| 65 | { |
---|
[407] | 66 | MMU_WRITE_PT1_UNMAPPED = 0x0001, |
---|
| 67 | MMU_WRITE_PT2_UNMAPPED = 0x0002, |
---|
| 68 | MMU_WRITE_PRIVILEGE_VIOLATION = 0x0004, |
---|
| 69 | MMU_WRITE_ACCESS_VIOLATION = 0x0008, |
---|
| 70 | MMU_WRITE_UNDEFINED_XTN = 0x0020, |
---|
| 71 | MMU_WRITE_PT1_ILLEGAL_ACCESS = 0x0040, |
---|
| 72 | MMU_WRITE_PT2_ILLEGAL_ACCESS = 0x0080, |
---|
| 73 | MMU_WRITE_DATA_ILLEGAL_ACCESS = 0x0100, |
---|
| 74 | |
---|
| 75 | MMU_READ_PT1_UNMAPPED = 0x1001, |
---|
| 76 | MMU_READ_PT2_UNMAPPED = 0x1002, |
---|
| 77 | MMU_READ_PRIVILEGE_VIOLATION = 0x1004, |
---|
| 78 | MMU_READ_EXEC_VIOLATION = 0x1010, |
---|
| 79 | MMU_READ_UNDEFINED_XTN = 0x1020, |
---|
| 80 | MMU_READ_PT1_ILLEGAL_ACCESS = 0x1040, |
---|
| 81 | MMU_READ_PT2_ILLEGAL_ACCESS = 0x1080, |
---|
| 82 | MMU_READ_DATA_ILLEGAL_ACCESS = 0x1100, |
---|
[381] | 83 | } |
---|
| 84 | mmu_exception_subtype_t; |
---|
| 85 | |
---|
| 86 | ////////////////////////////////////////////////////////////////////////////////////////// |
---|
[16] | 87 | // This enum defines the relevant values for XCODE field in mips32 CP0_CR register. |
---|
| 88 | ////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 89 | |
---|
| 90 | typedef enum |
---|
| 91 | { |
---|
[296] | 92 | XCODE_ADEL = 0x4, // Illegal address for data load |
---|
| 93 | XCODE_ADES = 0x5, // Illegal address for data store |
---|
| 94 | XCODE_IBE = 0x6, // Instruction MMU exception (can be NON-FATAL) |
---|
| 95 | XCODE_DBE = 0x7, // Data MMU exception (can be NON-FATAL) |
---|
| 96 | XCODE_RI = 0xA, // Reserved instruction exception |
---|
| 97 | XCODE_CPU = 0xB, // Coprocessor unusable exception (can be NON-FATAl) |
---|
| 98 | XCODE_OVR = 0xC, // Arithmetic Overflow exception |
---|
[16] | 99 | } |
---|
| 100 | xcode_values_t; |
---|
| 101 | |
---|
[409] | 102 | ///////////////////////////////////////////// |
---|
| 103 | char * hal_mmu_exception_str( uint32_t code ) |
---|
[408] | 104 | { |
---|
| 105 | if ( code == MMU_WRITE_PT1_UNMAPPED ) return "WRITE_PT1_UNMAPPED"; |
---|
| 106 | else if( code == MMU_WRITE_PT2_UNMAPPED ) return "WRITE_PT2_UNMAPPED"; |
---|
| 107 | else if( code == MMU_WRITE_PRIVILEGE_VIOLATION ) return "WRITE_PRIVILEGE_VIOLATION"; |
---|
| 108 | else if( code == MMU_WRITE_ACCESS_VIOLATION ) return "WRITE_ACCESS_VIOLATION"; |
---|
| 109 | else if( code == MMU_WRITE_UNDEFINED_XTN ) return "WRITE_UNDEFINED_XTN"; |
---|
| 110 | else if( code == MMU_WRITE_PT1_ILLEGAL_ACCESS ) return "WRITE_PT1_ILLEGAL_ACCESS"; |
---|
| 111 | else if( code == MMU_WRITE_PT2_ILLEGAL_ACCESS ) return "WRITE_PT2_ILLEGAL_ACCESS"; |
---|
| 112 | else if( code == MMU_WRITE_DATA_ILLEGAL_ACCESS ) return "WRITE_DATA_ILLEGAL_ACCESS"; |
---|
| 113 | else if( code == MMU_READ_PT1_UNMAPPED ) return "READ_PT1_UNMAPPED"; |
---|
| 114 | else if( code == MMU_READ_PT2_UNMAPPED ) return "READ_PT2_UNMAPPED"; |
---|
| 115 | else if( code == MMU_READ_PRIVILEGE_VIOLATION ) return "READ_PRIVILEGE_VIOLATION"; |
---|
| 116 | else if( code == MMU_READ_EXEC_VIOLATION ) return "READ_EXEC_VIOLATION"; |
---|
| 117 | else if( code == MMU_READ_UNDEFINED_XTN ) return "READ_UNDEFINED_XTN"; |
---|
| 118 | else if( code == MMU_READ_PT1_ILLEGAL_ACCESS ) return "READ_PT1_ILLEGAL_ACCESS"; |
---|
| 119 | else if( code == MMU_READ_PT2_ILLEGAL_ACCESS ) return "READ_PT2_ILLEGAL_ACCESS"; |
---|
| 120 | else if( code == MMU_READ_DATA_ILLEGAL_ACCESS ) return "READ_DATA_ILLEGAL_ACCESS"; |
---|
| 121 | else return "undefined"; |
---|
| 122 | } |
---|
| 123 | |
---|
[380] | 124 | ////////////////////////////////////////////////////////////////////////////////////////// |
---|
[406] | 125 | // This function is called when a FPU Coprocessor Unavailable exception has been |
---|
[380] | 126 | // detected for the calling thread. |
---|
| 127 | // It enables the FPU, It saves the current FPU context in the current owner thread |
---|
| 128 | // descriptor if required, and restore the FPU context from the calling thread descriptor. |
---|
| 129 | ////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 130 | // @ this : pointer on faulty thread descriptor. |
---|
| 131 | // @ return always EXCP_NON_FATAL |
---|
| 132 | ////////////////////////////////////////////////////////////////////////////////////////// |
---|
[406] | 133 | error_t hal_fpu_exception( thread_t * this ) |
---|
[380] | 134 | { |
---|
| 135 | core_t * core = this->core; |
---|
| 136 | |
---|
[457] | 137 | // enable FPU (in core SR) |
---|
[380] | 138 | hal_fpu_enable(); |
---|
| 139 | |
---|
[457] | 140 | // save FPU register values in current owner thread if required |
---|
[380] | 141 | if( core->fpu_owner != NULL ) |
---|
| 142 | { |
---|
| 143 | if( core->fpu_owner != this ) |
---|
| 144 | { |
---|
[457] | 145 | // save the FPU registers to current owner thread context |
---|
[408] | 146 | hal_fpu_context_save( XPTR( local_cxy , core->fpu_owner ) ); |
---|
[457] | 147 | |
---|
| 148 | // restore FPU registers from requesting thread context |
---|
[469] | 149 | hal_fpu_context_restore( this ); |
---|
[457] | 150 | |
---|
| 151 | // attach the FPU to the requesting thread |
---|
| 152 | core->fpu_owner = this; |
---|
[380] | 153 | } |
---|
| 154 | } |
---|
[457] | 155 | else |
---|
| 156 | { |
---|
| 157 | // restore FPU registers from requesting thread context |
---|
[469] | 158 | hal_fpu_context_restore( this ); |
---|
[380] | 159 | |
---|
[457] | 160 | // attach the FPU to the requesting thread |
---|
| 161 | core->fpu_owner = this; |
---|
| 162 | } |
---|
[380] | 163 | |
---|
| 164 | return EXCP_NON_FATAL; |
---|
| 165 | |
---|
| 166 | } // end hal_fpu_exception() |
---|
| 167 | |
---|
| 168 | ////////////////////////////////////////////////////////////////////////////////////////// |
---|
[437] | 169 | // This function is called when an MMU exception has been detected (IBE / DBE). |
---|
[380] | 170 | // It get the relevant exception arguments from the MMU. |
---|
| 171 | // It signal a fatal error in case of illegal access. In case of page unmapped |
---|
| 172 | // it checks that the faulty address belongs to a registered vseg. It update the local |
---|
| 173 | // vseg list from the reference cluster if required, and signal a fatal user error |
---|
| 174 | // in case of illegal virtual address. Finally, it updates the local page table from the |
---|
| 175 | // reference cluster. |
---|
| 176 | ////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 177 | // @ this : pointer on faulty thread descriptor. |
---|
[440] | 178 | // @ excPC : |
---|
[406] | 179 | // @ is_ins : IBE if true / DBE if false. |
---|
[380] | 180 | // @ return EXCP_NON_FATAL / EXCP_USER_ERROR / EXCP_KERNEL_PANIC |
---|
| 181 | ////////////////////////////////////////////////////////////////////////////////////////// |
---|
[406] | 182 | error_t hal_mmu_exception( thread_t * this, |
---|
[437] | 183 | uint32_t excPC, |
---|
[406] | 184 | bool_t is_ins ) |
---|
[380] | 185 | { |
---|
[406] | 186 | process_t * process; |
---|
| 187 | error_t error; |
---|
[380] | 188 | |
---|
[406] | 189 | uint32_t mmu_ins_excp_code; |
---|
| 190 | uint32_t mmu_ins_bad_vaddr; |
---|
| 191 | uint32_t mmu_dat_excp_code; |
---|
| 192 | uint32_t mmu_dat_bad_vaddr; |
---|
[380] | 193 | |
---|
[406] | 194 | uint32_t bad_vaddr; |
---|
[380] | 195 | uint32_t excp_code; |
---|
| 196 | |
---|
[406] | 197 | process = this->process; |
---|
[380] | 198 | |
---|
| 199 | // get relevant values from MMU |
---|
| 200 | hal_get_mmu_excp( &mmu_ins_excp_code, |
---|
| 201 | &mmu_ins_bad_vaddr, |
---|
| 202 | &mmu_dat_excp_code, |
---|
| 203 | &mmu_dat_bad_vaddr ); |
---|
| 204 | |
---|
[406] | 205 | // get exception code and faulty vaddr, depending on IBE/DBE |
---|
| 206 | if( is_ins ) |
---|
[380] | 207 | { |
---|
| 208 | excp_code = mmu_ins_excp_code; |
---|
| 209 | bad_vaddr = mmu_ins_bad_vaddr; |
---|
| 210 | } |
---|
[406] | 211 | else |
---|
[380] | 212 | { |
---|
| 213 | excp_code = mmu_dat_excp_code; |
---|
| 214 | bad_vaddr = mmu_dat_bad_vaddr; |
---|
| 215 | } |
---|
| 216 | |
---|
[438] | 217 | #if DEBUG_HAL_EXCEPTIONS |
---|
[432] | 218 | uint32_t cycle = (uint32_t)hal_get_cycles(); |
---|
[438] | 219 | if( DEBUG_HAL_EXCEPTIONS < cycle ) |
---|
[457] | 220 | printk("\n[DBG] %s : thread %x in process %x enter / is_ins %d / %s / vaddr %x / cycle %d\n", |
---|
[469] | 221 | __FUNCTION__, this->trdid, process->pid, |
---|
| 222 | is_ins, hal_mmu_exception_str(excp_code), bad_vaddr, cycle); |
---|
[432] | 223 | #endif |
---|
[408] | 224 | |
---|
[407] | 225 | // analyse exception code |
---|
| 226 | switch( excp_code ) |
---|
[380] | 227 | { |
---|
[407] | 228 | case MMU_WRITE_PT1_UNMAPPED: // non fatal |
---|
| 229 | case MMU_WRITE_PT2_UNMAPPED: |
---|
| 230 | case MMU_READ_PT1_UNMAPPED: |
---|
| 231 | case MMU_READ_PT2_UNMAPPED: |
---|
| 232 | { |
---|
| 233 | // try to map the unmapped PTE |
---|
| 234 | error = vmm_handle_page_fault( process, |
---|
[440] | 235 | bad_vaddr >> CONFIG_PPM_PAGE_SHIFT, // vpn |
---|
| 236 | false ); // not a COW |
---|
[407] | 237 | if( error ) |
---|
| 238 | { |
---|
[469] | 239 | printk("\n[USER ERROR] in %s for thread %x in process %x\n" |
---|
| 240 | " cannot map vaddr = %x / is_ins %d / epc %x\n", |
---|
| 241 | __FUNCTION__, this->trdid, this->process->pid, bad_vaddr, is_ins, excPC ); |
---|
[406] | 242 | |
---|
[407] | 243 | return EXCP_USER_ERROR; |
---|
| 244 | } |
---|
| 245 | else // page fault successfull |
---|
| 246 | { |
---|
[391] | 247 | |
---|
[438] | 248 | #if DEBUG_HAL_EXCEPTIONS |
---|
[432] | 249 | cycle = (uint32_t)hal_get_cycles(); |
---|
[438] | 250 | if( DEBUG_HAL_EXCEPTIONS < cycle ) |
---|
[457] | 251 | printk("\n[DBG] %s : thread %x in process %x exit / page-fault handled for vaddr = %x\n", |
---|
| 252 | __FUNCTION__, this->trdid, process->pid, bad_vaddr ); |
---|
[432] | 253 | #endif |
---|
[407] | 254 | |
---|
| 255 | return EXCP_NON_FATAL; |
---|
| 256 | } |
---|
| 257 | } |
---|
| 258 | case MMU_WRITE_PRIVILEGE_VIOLATION: // illegal access user error |
---|
| 259 | case MMU_READ_PRIVILEGE_VIOLATION: |
---|
[380] | 260 | { |
---|
[469] | 261 | printk("\n[USER ERROR] in %s for thread %x in process %x\n" |
---|
| 262 | " illegal user access to vaddr = %x / is_ins %d / epc %x\n", |
---|
| 263 | __FUNCTION__, this->trdid, this->process->pid, bad_vaddr, is_ins, excPC ); |
---|
[380] | 264 | |
---|
[407] | 265 | return EXCP_USER_ERROR; |
---|
| 266 | } |
---|
[408] | 267 | case MMU_WRITE_ACCESS_VIOLATION: // user error, or Copy-on-Write |
---|
[380] | 268 | { |
---|
[407] | 269 | // access page table to get GPT_COW flag |
---|
| 270 | bool_t cow = hal_gpt_pte_is_cow( &(process->vmm.gpt), |
---|
[408] | 271 | bad_vaddr >> CONFIG_PPM_PAGE_SHIFT ); |
---|
[380] | 272 | |
---|
[407] | 273 | if( cow ) // Copy-on-Write |
---|
| 274 | { |
---|
| 275 | // try to allocate and copy the page |
---|
[440] | 276 | error = vmm_handle_page_fault( process, |
---|
| 277 | bad_vaddr >> CONFIG_PPM_PAGE_SHIFT, // vpn |
---|
| 278 | true ); // COW |
---|
[407] | 279 | if( error ) |
---|
| 280 | { |
---|
[469] | 281 | printk("\n[USER ERROR] in %s for thread %x in process %x\n" |
---|
| 282 | " cannot cow vaddr = %x / is_ins %d / epc %x\n", |
---|
| 283 | __FUNCTION__, this->trdid, this->process->pid, bad_vaddr, is_ins, excPC ); |
---|
[380] | 284 | |
---|
[407] | 285 | return EXCP_USER_ERROR; |
---|
| 286 | } |
---|
| 287 | else // Copy on write successfull |
---|
| 288 | { |
---|
[380] | 289 | |
---|
[438] | 290 | #if DEBUG_HAL_EXCEPTIONS |
---|
[432] | 291 | cycle = (uint32_t)hal_get_cycles(); |
---|
[438] | 292 | if( DEBUG_HAL_EXCEPTIONS < cycle ) |
---|
[457] | 293 | printk("\n[DBG] %s : thread %x in process %x exit / copy-on-write handled for vaddr = %x\n", |
---|
| 294 | __FUNCTION__, this->trdid, process->pid, bad_vaddr ); |
---|
[432] | 295 | #endif |
---|
[380] | 296 | |
---|
[407] | 297 | return EXCP_NON_FATAL; |
---|
| 298 | } |
---|
| 299 | } |
---|
| 300 | else // non writable user error |
---|
| 301 | { |
---|
[469] | 302 | printk("\n[USER ERROR] in %s for thread %x in process %x\n" |
---|
| 303 | " non-writable vaddr = %x / is_ins %d / epc %x\n", |
---|
| 304 | __FUNCTION__, this->trdid, this->process->pid, bad_vaddr, is_ins, excPC ); |
---|
[407] | 305 | |
---|
| 306 | return EXCP_USER_ERROR; |
---|
| 307 | } |
---|
| 308 | } |
---|
| 309 | case MMU_READ_EXEC_VIOLATION: // user error |
---|
| 310 | { |
---|
[469] | 311 | printk("\n[USER_ERROR] in %s for thread %x in process %x\n" |
---|
| 312 | " non-executable vaddr = %x / is_ins %d / epc %x\n", |
---|
| 313 | __FUNCTION__, this->trdid, this->process->pid, bad_vaddr, is_ins, excPC ); |
---|
[407] | 314 | |
---|
| 315 | return EXCP_USER_ERROR; |
---|
| 316 | } |
---|
[469] | 317 | default: // this is a kernel error |
---|
[407] | 318 | { |
---|
[469] | 319 | printk("\n[KERNEL ERROR] in %s for thread %x in process %x\n" |
---|
| 320 | " epc %x / badvaddr %x / is_ins %d\n", |
---|
| 321 | __FUNCTION__, this->trdid, this->process->pid, excPC, bad_vaddr, is_ins ); |
---|
[407] | 322 | |
---|
| 323 | return EXCP_KERNEL_PANIC; |
---|
| 324 | } |
---|
| 325 | } |
---|
[380] | 326 | } // end hal_mmu_exception() |
---|
| 327 | |
---|
| 328 | ////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 329 | // This static function prints on the kernel terminal the saved context (core registers) |
---|
| 330 | // and the thread state of a faulty thread. |
---|
| 331 | ////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 332 | // @ this : pointer on faulty thread descriptor. |
---|
[425] | 333 | // @ uzone : pointer on register array. |
---|
[407] | 334 | // @ error : EXCP_USER_ERROR or EXCP_KERNEL_PANIC |
---|
[380] | 335 | ////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 336 | static void hal_exception_dump( thread_t * this, |
---|
[408] | 337 | reg_t * uzone, |
---|
[407] | 338 | error_t error ) |
---|
[380] | 339 | { |
---|
[408] | 340 | uint32_t save_sr; |
---|
| 341 | core_t * core = this->core; |
---|
| 342 | process_t * process = this->process; |
---|
[380] | 343 | |
---|
| 344 | // get pointers on TXT0 chdev |
---|
[407] | 345 | xptr_t txt0_xp = chdev_dir.txt_tx[0]; |
---|
[380] | 346 | cxy_t txt0_cxy = GET_CXY( txt0_xp ); |
---|
| 347 | chdev_t * txt0_ptr = GET_PTR( txt0_xp ); |
---|
| 348 | |
---|
| 349 | // get extended pointer on remote TXT0 chdev lock |
---|
| 350 | xptr_t lock_xp = XPTR( txt0_cxy , &txt0_ptr->wait_lock ); |
---|
| 351 | |
---|
| 352 | // get TXT0 lock in busy waiting mode |
---|
| 353 | remote_spinlock_lock_busy( lock_xp , &save_sr ); |
---|
| 354 | |
---|
[407] | 355 | if( error == EXCP_USER_ERROR ) |
---|
| 356 | { |
---|
[408] | 357 | nolock_printk("\n=== USER ERROR / trdid %x / pid %x / core[%x,%d] / cycle %d ===\n", |
---|
| 358 | this->trdid, process->pid, local_cxy, core->lid , (uint32_t)hal_get_cycles() ); |
---|
[407] | 359 | } |
---|
[380] | 360 | else |
---|
[407] | 361 | { |
---|
[469] | 362 | nolock_printk("\n=== KERNEL ERROR / trdid %x / pid %x / core[%x,%d] / cycle %d ===\n", |
---|
[408] | 363 | this->trdid, process->pid, local_cxy, core->lid , (uint32_t)hal_get_cycles() ); |
---|
[407] | 364 | } |
---|
[380] | 365 | |
---|
[408] | 366 | nolock_printk("local locks = %d / remote locks = %d / blocked_vector = %X\n\n", |
---|
| 367 | this->local_locks, this->remote_locks, this->blocked ); |
---|
[380] | 368 | |
---|
[408] | 369 | nolock_printk("c0_cr %X c0_epc %X c0_sr %X c0_th %X\n", |
---|
| 370 | uzone[UZ_CR], uzone[UZ_EPC], uzone[UZ_SR], uzone[UZ_TH] ); |
---|
[380] | 371 | |
---|
[408] | 372 | nolock_printk("c2_mode %X c2_ptpr %X\n", |
---|
| 373 | uzone[UZ_MODE], uzone[UZ_PTPR] ); |
---|
[380] | 374 | |
---|
[408] | 375 | nolock_printk("at_01 %X v0_2 %X v1_3 %X a0_4 %X a1_5 %X\n", |
---|
| 376 | uzone[UZ_AT], uzone[UZ_V0], uzone[UZ_V1], uzone[UZ_A0], uzone[UZ_A1] ); |
---|
| 377 | |
---|
| 378 | nolock_printk("a2_6 %X a3_7 %X t0_8 %X t1_9 %X t2_10 %X\n", |
---|
| 379 | uzone[UZ_A2], uzone[UZ_A3], uzone[UZ_T0], uzone[UZ_T1], uzone[UZ_T2] ); |
---|
[380] | 380 | |
---|
[408] | 381 | nolock_printk("t3_11 %X t4_12 %X t5_13 %X t6_14 %X t7_15 %X\n", |
---|
| 382 | uzone[UZ_T3], uzone[UZ_T4], uzone[UZ_T5], uzone[UZ_T6], uzone[UZ_T7] ); |
---|
[380] | 383 | |
---|
[408] | 384 | nolock_printk("s0_16 %X s1_17 %X s2_18 %X s3_19 %X s4_20 %X\n", |
---|
| 385 | uzone[UZ_S0], uzone[UZ_S1], uzone[UZ_S2], uzone[UZ_S3], uzone[UZ_S4] ); |
---|
[380] | 386 | |
---|
[408] | 387 | nolock_printk("s5_21 %X s6_22 %X s7_23 %X s8_24 %X ra_25 %X\n", |
---|
| 388 | uzone[UZ_S5], uzone[UZ_S6], uzone[UZ_S7], uzone[UZ_T8], uzone[UZ_T9] ); |
---|
[380] | 389 | |
---|
[408] | 390 | nolock_printk("gp_28 %X sp_29 %X S8_30 %X ra_31 %X\n", |
---|
| 391 | uzone[UZ_GP], uzone[UZ_SP], uzone[UZ_S8], uzone[UZ_RA] ); |
---|
[407] | 392 | |
---|
[380] | 393 | // release the lock |
---|
| 394 | remote_spinlock_unlock_busy( lock_xp , save_sr ); |
---|
| 395 | |
---|
| 396 | } // end hal_exception_dump() |
---|
| 397 | |
---|
[408] | 398 | /////////////////////// |
---|
[481] | 399 | void hal_do_exception( void ) |
---|
[16] | 400 | { |
---|
[408] | 401 | uint32_t * uzone; |
---|
| 402 | thread_t * this; |
---|
| 403 | error_t error; |
---|
| 404 | uint32_t excCode; // 4 bits XCODE from CP0_CR |
---|
[437] | 405 | uint32_t excPC; // fauty instruction address |
---|
[16] | 406 | |
---|
[408] | 407 | // get pointer on faulty thread uzone |
---|
| 408 | this = CURRENT_THREAD; |
---|
[425] | 409 | uzone = (uint32_t *)CURRENT_THREAD->uzone_current; |
---|
[408] | 410 | |
---|
[437] | 411 | // get XCODE and EPC from UZONE |
---|
[408] | 412 | excCode = (uzone[UZ_CR] >> 2) & 0xF; |
---|
[437] | 413 | excPC = uzone[UZ_EPC]; |
---|
[16] | 414 | |
---|
[438] | 415 | #if DEBUG_HAL_EXCEPTIONS |
---|
[432] | 416 | uint32_t cycle = (uint32_t)hal_get_cycles(); |
---|
[438] | 417 | if( DEBUG_HAL_EXCEPTIONS < cycle ) |
---|
[457] | 418 | printk("\n[DBG] %s : thread %x in process %x enter / core[%x,%d] / epc %x / xcode %x / cycle %d\n", |
---|
| 419 | __FUNCTION__, this->trdid, this->process->pid, local_cxy, this->core->lid, excPC, excCode, cycle ); |
---|
[432] | 420 | #endif |
---|
[406] | 421 | |
---|
[16] | 422 | switch(excCode) |
---|
| 423 | { |
---|
[469] | 424 | case XCODE_DBE: // Data Bus Error : can be non fatal if page fault |
---|
[406] | 425 | { |
---|
[437] | 426 | error = hal_mmu_exception( this , excPC , false ); // data MMU exception |
---|
[406] | 427 | break; |
---|
| 428 | } |
---|
[469] | 429 | case XCODE_IBE: // Instruction Bus Error : can be non fatal if page fault |
---|
[16] | 430 | { |
---|
[437] | 431 | error = hal_mmu_exception( this , excPC , true ); // ins MMU exception |
---|
[406] | 432 | break; |
---|
[16] | 433 | } |
---|
[469] | 434 | case XCODE_CPU: // Coprocessor unavailable : can be non fatal if FPU |
---|
[16] | 435 | { |
---|
[469] | 436 | if( ((uzone[UZ_CR] >> 28) & 0x3) == 1 ) // FPU |
---|
[16] | 437 | { |
---|
[469] | 438 | error = hal_fpu_exception( this ); |
---|
[16] | 439 | } |
---|
[469] | 440 | else // undefined coprocessor |
---|
[16] | 441 | { |
---|
[469] | 442 | printk("\n[USER_ERROR] in %s for thread %x in process %x\n" |
---|
| 443 | " undefined coprocessor / epc %x\n", |
---|
| 444 | __FUNCTION__, this->trdid, this->process->pid, excPC ); |
---|
| 445 | |
---|
[16] | 446 | error = EXCP_USER_ERROR; |
---|
| 447 | } |
---|
[406] | 448 | break; |
---|
[16] | 449 | } |
---|
[469] | 450 | case XCODE_OVR: // Arithmetic Overflow : user fatal error |
---|
| 451 | { |
---|
| 452 | printk("\n[USER_ERROR] in %s for thread %x in process %x\n" |
---|
| 453 | " arithmetic overflow / epc %x\n", |
---|
| 454 | __FUNCTION__, this->trdid, this->process->pid, excPC ); |
---|
| 455 | |
---|
| 456 | error = EXCP_USER_ERROR; |
---|
| 457 | break; |
---|
| 458 | } |
---|
| 459 | case XCODE_RI: // Reserved Instruction : user fatal error |
---|
| 460 | { |
---|
| 461 | printk("\n[USER_ERROR] in %s for thread %x in process %x\n" |
---|
| 462 | " reserved instruction / epc %x\n", |
---|
| 463 | __FUNCTION__, this->trdid, this->process->pid, excPC ); |
---|
| 464 | |
---|
| 465 | error = EXCP_USER_ERROR; |
---|
| 466 | break; |
---|
| 467 | } |
---|
[380] | 468 | case XCODE_ADEL: // user fatal error |
---|
[16] | 469 | { |
---|
[469] | 470 | printk("\n[USER_ERROR] in %s for thread %x in process %x\n" |
---|
| 471 | " illegal data load address / epc %x\n", |
---|
| 472 | __FUNCTION__, this->trdid, this->process->pid, excPC ); |
---|
| 473 | |
---|
[16] | 474 | error = EXCP_USER_ERROR; |
---|
[406] | 475 | break; |
---|
[16] | 476 | } |
---|
[469] | 477 | case XCODE_ADES: // user fatal error |
---|
| 478 | { |
---|
| 479 | printk("\n[USER_ERROR] in %s for thread %x in process %x\n" |
---|
| 480 | " illegal data store address / epc %x\n", |
---|
| 481 | __FUNCTION__, this->trdid, this->process->pid, excPC ); |
---|
| 482 | |
---|
| 483 | error = EXCP_USER_ERROR; |
---|
| 484 | break; |
---|
| 485 | } |
---|
[16] | 486 | default: |
---|
| 487 | { |
---|
[317] | 488 | error = EXCP_KERNEL_PANIC; |
---|
[16] | 489 | } |
---|
| 490 | } |
---|
| 491 | |
---|
| 492 | // analyse error code |
---|
[317] | 493 | if( error == EXCP_USER_ERROR ) // user error => kill user process |
---|
[16] | 494 | { |
---|
[408] | 495 | hal_exception_dump( this , uzone , error ); |
---|
[407] | 496 | |
---|
[440] | 497 | sys_exit( EXIT_FAILURE ); |
---|
[16] | 498 | } |
---|
| 499 | else if( error == EXCP_KERNEL_PANIC ) // kernel error => kernel panic |
---|
| 500 | { |
---|
[408] | 501 | hal_exception_dump( this , uzone , error ); |
---|
[425] | 502 | |
---|
[492] | 503 | assert( false , "Exception raised kernel panic see information below.\n" ); |
---|
[16] | 504 | } |
---|
[406] | 505 | |
---|
[438] | 506 | #if DEBUG_HAL_EXCEPTIONS |
---|
[432] | 507 | cycle = (uint32_t)hal_get_cycles(); |
---|
[438] | 508 | if( DEBUG_HAL_EXCEPTIONS < cycle ) |
---|
[457] | 509 | printk("\n[DBG] %s : thread %x in process %x exit / core[%x,%d] / epc %x / xcode %x / cycle %d\n", |
---|
| 510 | __FUNCTION__, this->trdid, this->process->pid, local_cxy, this->core->lid, excPC, excCode, cycle ); |
---|
[432] | 511 | #endif |
---|
[406] | 512 | |
---|
[16] | 513 | } // end hal_do_exception() |
---|
| 514 | |
---|
| 515 | |
---|