[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 | |
---|
| 24 | #include <hal_types.h> |
---|
| 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 <signal.h> |
---|
| 36 | #include <syscalls.h> |
---|
| 37 | #include <remote_spinlock.h> |
---|
[406] | 38 | #include <hal_kentry.h> |
---|
[16] | 39 | |
---|
[380] | 40 | |
---|
[16] | 41 | ////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 42 | // Extern global variables |
---|
| 43 | ////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 44 | |
---|
[380] | 45 | extern chdev_directory_t chdev_dir; // allocated in the kernel_init.c file. |
---|
[16] | 46 | |
---|
| 47 | ////////////////////////////////////////////////////////////////////////////////////////// |
---|
[381] | 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 | ////////////////////////////////////////////////////////////////////////////////////////// |
---|
[407] | 60 | // This enum defines the mask values for an MMU exception code reported by the mips32. |
---|
[381] | 61 | ////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 62 | |
---|
| 63 | typedef enum |
---|
| 64 | { |
---|
[407] | 65 | MMU_WRITE_PT1_UNMAPPED = 0x0001, |
---|
| 66 | MMU_WRITE_PT2_UNMAPPED = 0x0002, |
---|
| 67 | MMU_WRITE_PRIVILEGE_VIOLATION = 0x0004, |
---|
| 68 | MMU_WRITE_ACCESS_VIOLATION = 0x0008, |
---|
| 69 | MMU_WRITE_UNDEFINED_XTN = 0x0020, |
---|
| 70 | MMU_WRITE_PT1_ILLEGAL_ACCESS = 0x0040, |
---|
| 71 | MMU_WRITE_PT2_ILLEGAL_ACCESS = 0x0080, |
---|
| 72 | MMU_WRITE_DATA_ILLEGAL_ACCESS = 0x0100, |
---|
| 73 | |
---|
| 74 | MMU_READ_PT1_UNMAPPED = 0x1001, |
---|
| 75 | MMU_READ_PT2_UNMAPPED = 0x1002, |
---|
| 76 | MMU_READ_PRIVILEGE_VIOLATION = 0x1004, |
---|
| 77 | MMU_READ_EXEC_VIOLATION = 0x1010, |
---|
| 78 | MMU_READ_UNDEFINED_XTN = 0x1020, |
---|
| 79 | MMU_READ_PT1_ILLEGAL_ACCESS = 0x1040, |
---|
| 80 | MMU_READ_PT2_ILLEGAL_ACCESS = 0x1080, |
---|
| 81 | MMU_READ_DATA_ILLEGAL_ACCESS = 0x1100, |
---|
[381] | 82 | } |
---|
| 83 | mmu_exception_subtype_t; |
---|
| 84 | |
---|
| 85 | ////////////////////////////////////////////////////////////////////////////////////////// |
---|
[16] | 86 | // This enum defines the relevant values for XCODE field in mips32 CP0_CR register. |
---|
| 87 | ////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 88 | |
---|
| 89 | typedef enum |
---|
| 90 | { |
---|
[296] | 91 | XCODE_ADEL = 0x4, // Illegal address for data load |
---|
| 92 | XCODE_ADES = 0x5, // Illegal address for data store |
---|
| 93 | XCODE_IBE = 0x6, // Instruction MMU exception (can be NON-FATAL) |
---|
| 94 | XCODE_DBE = 0x7, // Data MMU exception (can be NON-FATAL) |
---|
| 95 | XCODE_RI = 0xA, // Reserved instruction exception |
---|
| 96 | XCODE_CPU = 0xB, // Coprocessor unusable exception (can be NON-FATAl) |
---|
| 97 | XCODE_OVR = 0xC, // Arithmetic Overflow exception |
---|
[16] | 98 | } |
---|
| 99 | xcode_values_t; |
---|
| 100 | |
---|
[408] | 101 | //////////////////////////////////////////////////// |
---|
| 102 | static 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 | |
---|
[380] | 123 | ////////////////////////////////////////////////////////////////////////////////////////// |
---|
[406] | 124 | // This function is called when a FPU Coprocessor Unavailable exception has been |
---|
[380] | 125 | // detected for the calling thread. |
---|
| 126 | // It enables the FPU, It saves the current FPU context in the current owner thread |
---|
| 127 | // descriptor if required, and restore the FPU context from the calling thread descriptor. |
---|
| 128 | ////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 129 | // @ this : pointer on faulty thread descriptor. |
---|
| 130 | // @ return always EXCP_NON_FATAL |
---|
| 131 | ////////////////////////////////////////////////////////////////////////////////////////// |
---|
[406] | 132 | error_t hal_fpu_exception( thread_t * this ) |
---|
[380] | 133 | { |
---|
| 134 | core_t * core = this->core; |
---|
| 135 | |
---|
| 136 | // enable FPU |
---|
| 137 | hal_fpu_enable(); |
---|
| 138 | |
---|
| 139 | // save FPU context in current owner thread if required |
---|
| 140 | if( core->fpu_owner != NULL ) |
---|
| 141 | { |
---|
| 142 | if( core->fpu_owner != this ) |
---|
| 143 | { |
---|
[408] | 144 | hal_fpu_context_save( XPTR( local_cxy , core->fpu_owner ) ); |
---|
[380] | 145 | } |
---|
| 146 | } |
---|
| 147 | |
---|
| 148 | // attach the FPU to the requesting thread |
---|
| 149 | hal_fpu_context_restore( this->fpu_context ); |
---|
| 150 | core->fpu_owner = this; |
---|
| 151 | |
---|
| 152 | return EXCP_NON_FATAL; |
---|
| 153 | |
---|
| 154 | } // end hal_fpu_exception() |
---|
| 155 | |
---|
| 156 | ////////////////////////////////////////////////////////////////////////////////////////// |
---|
[406] | 157 | // This function is called when an MMU exception has been detected. |
---|
[380] | 158 | // It get the relevant exception arguments from the MMU. |
---|
| 159 | // It signal a fatal error in case of illegal access. In case of page unmapped |
---|
| 160 | // it checks that the faulty address belongs to a registered vseg. It update the local |
---|
| 161 | // vseg list from the reference cluster if required, and signal a fatal user error |
---|
| 162 | // in case of illegal virtual address. Finally, it updates the local page table from the |
---|
| 163 | // reference cluster. |
---|
| 164 | ////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 165 | // @ this : pointer on faulty thread descriptor. |
---|
[406] | 166 | // @ is_ins : IBE if true / DBE if false. |
---|
[380] | 167 | // @ return EXCP_NON_FATAL / EXCP_USER_ERROR / EXCP_KERNEL_PANIC |
---|
| 168 | ////////////////////////////////////////////////////////////////////////////////////////// |
---|
[406] | 169 | error_t hal_mmu_exception( thread_t * this, |
---|
| 170 | bool_t is_ins ) |
---|
[380] | 171 | { |
---|
[406] | 172 | process_t * process; |
---|
| 173 | error_t error; |
---|
[380] | 174 | |
---|
[406] | 175 | uint32_t mmu_ins_excp_code; |
---|
| 176 | uint32_t mmu_ins_bad_vaddr; |
---|
| 177 | uint32_t mmu_dat_excp_code; |
---|
| 178 | uint32_t mmu_dat_bad_vaddr; |
---|
[380] | 179 | |
---|
[406] | 180 | uint32_t bad_vaddr; |
---|
[380] | 181 | uint32_t excp_code; |
---|
| 182 | |
---|
[406] | 183 | process = this->process; |
---|
[380] | 184 | |
---|
| 185 | // get relevant values from MMU |
---|
| 186 | hal_get_mmu_excp( &mmu_ins_excp_code, |
---|
| 187 | &mmu_ins_bad_vaddr, |
---|
| 188 | &mmu_dat_excp_code, |
---|
| 189 | &mmu_dat_bad_vaddr ); |
---|
| 190 | |
---|
[406] | 191 | // get exception code and faulty vaddr, depending on IBE/DBE |
---|
| 192 | if( is_ins ) |
---|
[380] | 193 | { |
---|
| 194 | excp_code = mmu_ins_excp_code; |
---|
| 195 | bad_vaddr = mmu_ins_bad_vaddr; |
---|
| 196 | } |
---|
[406] | 197 | else |
---|
[380] | 198 | { |
---|
| 199 | excp_code = mmu_dat_excp_code; |
---|
| 200 | bad_vaddr = mmu_dat_bad_vaddr; |
---|
| 201 | } |
---|
| 202 | |
---|
[408] | 203 | // @@@ |
---|
| 204 | thread_t * parent = (thread_t *)0xa4000; |
---|
| 205 | uint32_t cond = (this == 0xe0000) && (hal_time_stamp() > 5380000); |
---|
[380] | 206 | |
---|
[408] | 207 | if( cond ) hal_gpt_display( this->process ); |
---|
| 208 | if( cond ) hal_gpt_display( parent->process ); |
---|
| 209 | if( cond ) printk("\n[DBG] %s : core[%x,%d] / is_ins %d / %s / vaddr %x\n", |
---|
| 210 | __FUNCTION__ , local_cxy , this->core->lid , is_ins, |
---|
| 211 | hal_mmu_exception_str(excp_code) , bad_vaddr ); |
---|
| 212 | |
---|
[407] | 213 | // analyse exception code |
---|
| 214 | switch( excp_code ) |
---|
[380] | 215 | { |
---|
[407] | 216 | case MMU_WRITE_PT1_UNMAPPED: // non fatal |
---|
| 217 | case MMU_WRITE_PT2_UNMAPPED: |
---|
| 218 | case MMU_READ_PT1_UNMAPPED: |
---|
| 219 | case MMU_READ_PT2_UNMAPPED: |
---|
| 220 | { |
---|
| 221 | // try to map the unmapped PTE |
---|
| 222 | error = vmm_handle_page_fault( process, |
---|
| 223 | bad_vaddr >> CONFIG_PPM_PAGE_SHIFT ); // vpn |
---|
| 224 | if( error ) |
---|
| 225 | { |
---|
| 226 | printk("\n[ERROR] in %s for thread %x : cannot map vaddr = %x\n", |
---|
| 227 | __FUNCTION__ , this->trdid , bad_vaddr ); |
---|
[406] | 228 | |
---|
[407] | 229 | return EXCP_USER_ERROR; |
---|
| 230 | } |
---|
| 231 | else // page fault successfull |
---|
| 232 | { |
---|
[391] | 233 | |
---|
[407] | 234 | excp_dmsg("\n[DBG] %s : core[%x,%d] / page-fault handled for vaddr = %x\n", |
---|
| 235 | __FUNCTION__ , local_cxy , this->core->lid , bad_vaddr ); |
---|
| 236 | |
---|
| 237 | return EXCP_NON_FATAL; |
---|
| 238 | } |
---|
| 239 | } |
---|
| 240 | case MMU_WRITE_PRIVILEGE_VIOLATION: // illegal access user error |
---|
| 241 | case MMU_READ_PRIVILEGE_VIOLATION: |
---|
[380] | 242 | { |
---|
[407] | 243 | printk("\n[ERROR] in %s for thread %x : illegal user access to vaddr = %x\n", |
---|
| 244 | __FUNCTION__ , this->trdid , bad_vaddr ); |
---|
[380] | 245 | |
---|
[407] | 246 | return EXCP_USER_ERROR; |
---|
| 247 | } |
---|
[408] | 248 | case MMU_WRITE_ACCESS_VIOLATION: // user error, or Copy-on-Write |
---|
[380] | 249 | { |
---|
[407] | 250 | // access page table to get GPT_COW flag |
---|
| 251 | bool_t cow = hal_gpt_pte_is_cow( &(process->vmm.gpt), |
---|
[408] | 252 | bad_vaddr >> CONFIG_PPM_PAGE_SHIFT ); |
---|
[380] | 253 | |
---|
[407] | 254 | if( cow ) // Copy-on-Write |
---|
| 255 | { |
---|
| 256 | // try to allocate and copy the page |
---|
[408] | 257 | error = vmm_handle_cow( process, |
---|
| 258 | bad_vaddr >> CONFIG_PPM_PAGE_SHIFT ); |
---|
[407] | 259 | if( error ) |
---|
| 260 | { |
---|
| 261 | printk("\n[ERROR] in %s for thread %x : cannot cow vaddr = %x\n", |
---|
| 262 | __FUNCTION__ , this->trdid , bad_vaddr ); |
---|
[380] | 263 | |
---|
[407] | 264 | return EXCP_USER_ERROR; |
---|
| 265 | } |
---|
| 266 | else // Copy on write successfull |
---|
| 267 | { |
---|
[380] | 268 | |
---|
[408] | 269 | if( cond ) printk("\n[DBG] %s : core[%x,%d] / copy-on-write handled for vaddr = %x\n", |
---|
[407] | 270 | __FUNCTION__ , local_cxy , this->core->lid , bad_vaddr ); |
---|
[380] | 271 | |
---|
[407] | 272 | return EXCP_NON_FATAL; |
---|
| 273 | } |
---|
| 274 | } |
---|
| 275 | else // non writable user error |
---|
| 276 | { |
---|
| 277 | printk("\n[ERROR] in %s for thread %x : write to non-writable vaddr = %x\n", |
---|
| 278 | __FUNCTION__ , this->trdid , bad_vaddr ); |
---|
| 279 | |
---|
| 280 | return EXCP_USER_ERROR; |
---|
| 281 | } |
---|
| 282 | } |
---|
| 283 | case MMU_READ_EXEC_VIOLATION: // user error |
---|
| 284 | { |
---|
| 285 | printk("\n[ERROR] in %s for thread %x : read to non-executable vaddr = %x\n", |
---|
| 286 | __FUNCTION__ , this->trdid , bad_vaddr ); |
---|
| 287 | |
---|
| 288 | return EXCP_USER_ERROR; |
---|
| 289 | } |
---|
| 290 | default: // this is a kernel error => panic |
---|
| 291 | { |
---|
| 292 | printk("\n[PANIC] in %s for thread %x : kernel exception = %x / vaddr = %x\n", |
---|
| 293 | __FUNCTION__ , this->trdid , excp_code , bad_vaddr ); |
---|
| 294 | |
---|
| 295 | return EXCP_KERNEL_PANIC; |
---|
| 296 | } |
---|
| 297 | } |
---|
[380] | 298 | } // end hal_mmu_exception() |
---|
| 299 | |
---|
| 300 | ////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 301 | // This static function prints on the kernel terminal the saved context (core registers) |
---|
| 302 | // and the thread state of a faulty thread. |
---|
| 303 | ////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 304 | // @ this : pointer on faulty thread descriptor. |
---|
[408] | 305 | // @ uzone : pointer on register array. |
---|
[407] | 306 | // @ error : EXCP_USER_ERROR or EXCP_KERNEL_PANIC |
---|
[380] | 307 | ////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 308 | static void hal_exception_dump( thread_t * this, |
---|
[408] | 309 | reg_t * uzone, |
---|
[407] | 310 | error_t error ) |
---|
[380] | 311 | { |
---|
[408] | 312 | uint32_t save_sr; |
---|
| 313 | core_t * core = this->core; |
---|
| 314 | process_t * process = this->process; |
---|
[380] | 315 | |
---|
| 316 | // get pointers on TXT0 chdev |
---|
[407] | 317 | xptr_t txt0_xp = chdev_dir.txt_tx[0]; |
---|
[380] | 318 | cxy_t txt0_cxy = GET_CXY( txt0_xp ); |
---|
| 319 | chdev_t * txt0_ptr = GET_PTR( txt0_xp ); |
---|
| 320 | |
---|
| 321 | // get extended pointer on remote TXT0 chdev lock |
---|
| 322 | xptr_t lock_xp = XPTR( txt0_cxy , &txt0_ptr->wait_lock ); |
---|
| 323 | |
---|
| 324 | // get TXT0 lock in busy waiting mode |
---|
| 325 | remote_spinlock_lock_busy( lock_xp , &save_sr ); |
---|
| 326 | |
---|
[407] | 327 | if( error == EXCP_USER_ERROR ) |
---|
| 328 | { |
---|
[408] | 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() ); |
---|
[407] | 331 | } |
---|
[380] | 332 | else |
---|
[407] | 333 | { |
---|
[408] | 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() ); |
---|
[407] | 336 | } |
---|
[380] | 337 | |
---|
[408] | 338 | nolock_printk("local locks = %d / remote locks = %d / blocked_vector = %X\n\n", |
---|
| 339 | this->local_locks, this->remote_locks, this->blocked ); |
---|
[380] | 340 | |
---|
[408] | 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] ); |
---|
[380] | 343 | |
---|
[408] | 344 | nolock_printk("c2_mode %X c2_ptpr %X\n", |
---|
| 345 | uzone[UZ_MODE], uzone[UZ_PTPR] ); |
---|
[380] | 346 | |
---|
[408] | 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] ); |
---|
[380] | 352 | |
---|
[408] | 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] ); |
---|
[380] | 355 | |
---|
[408] | 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] ); |
---|
[380] | 358 | |
---|
[408] | 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] ); |
---|
[380] | 361 | |
---|
[408] | 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] ); |
---|
[407] | 364 | |
---|
[380] | 365 | // release the lock |
---|
| 366 | remote_spinlock_unlock_busy( lock_xp , save_sr ); |
---|
| 367 | |
---|
| 368 | } // end hal_exception_dump() |
---|
| 369 | |
---|
[408] | 370 | /////////////////////// |
---|
| 371 | void hal_do_exception() |
---|
[16] | 372 | { |
---|
[408] | 373 | uint32_t * uzone; |
---|
| 374 | thread_t * this; |
---|
| 375 | error_t error; |
---|
| 376 | uint32_t excCode; // 4 bits XCODE from CP0_CR |
---|
[16] | 377 | |
---|
[408] | 378 | // get pointer on faulty thread uzone |
---|
| 379 | this = CURRENT_THREAD; |
---|
| 380 | uzone = (uint32_t *)CURRENT_THREAD->uzone; |
---|
| 381 | |
---|
[16] | 382 | // get 4 bits XCODE from CP0_CR register |
---|
[408] | 383 | excCode = (uzone[UZ_CR] >> 2) & 0xF; |
---|
[16] | 384 | |
---|
[407] | 385 | excp_dmsg("\n[DBG] %s : core[%x,%d] / thread %x in process %x / xcode %x / cycle %d\n", |
---|
| 386 | __FUNCTION__, local_cxy, this->core->lid, this->trdid, |
---|
[408] | 387 | this->process->pid, excCode, (uint32_t)hal_get_cycles() ); |
---|
[406] | 388 | |
---|
[16] | 389 | switch(excCode) |
---|
| 390 | { |
---|
| 391 | case XCODE_DBE: // can be non fatal |
---|
[406] | 392 | { |
---|
| 393 | error = hal_mmu_exception( this , false ); // data MMU exception |
---|
| 394 | break; |
---|
| 395 | } |
---|
[380] | 396 | case XCODE_IBE: // can be non fatal |
---|
[16] | 397 | { |
---|
[406] | 398 | error = hal_mmu_exception( this , true ); // ins MMU exception |
---|
| 399 | break; |
---|
[16] | 400 | } |
---|
| 401 | case XCODE_CPU: // can be non fatal |
---|
| 402 | { |
---|
[408] | 403 | if( ((uzone[UZ_CR] >> 28) & 0x3) == 1 ) // unavailable FPU |
---|
[16] | 404 | { |
---|
[380] | 405 | error = hal_fpu_exception( this ); |
---|
[16] | 406 | } |
---|
| 407 | else |
---|
| 408 | { |
---|
| 409 | error = EXCP_USER_ERROR; |
---|
| 410 | } |
---|
[406] | 411 | break; |
---|
[16] | 412 | } |
---|
[380] | 413 | case XCODE_OVR: // user fatal error |
---|
| 414 | case XCODE_RI: // user fatal error |
---|
| 415 | case XCODE_ADEL: // user fatal error |
---|
| 416 | case XCODE_ADES: // user fatal error |
---|
[16] | 417 | { |
---|
| 418 | error = EXCP_USER_ERROR; |
---|
[406] | 419 | break; |
---|
[16] | 420 | } |
---|
| 421 | default: |
---|
| 422 | { |
---|
[317] | 423 | error = EXCP_KERNEL_PANIC; |
---|
[16] | 424 | } |
---|
| 425 | } |
---|
| 426 | |
---|
| 427 | // analyse error code |
---|
[317] | 428 | if( error == EXCP_USER_ERROR ) // user error => kill user process |
---|
[16] | 429 | { |
---|
[408] | 430 | hal_exception_dump( this , uzone , error ); |
---|
[407] | 431 | |
---|
| 432 | // FIXME : replace this loop by sys_kill() |
---|
| 433 | while( 1 ) asm volatile ("nop"); |
---|
| 434 | // sys_kill( this->process->pid , SIGKILL ); |
---|
[16] | 435 | } |
---|
| 436 | else if( error == EXCP_KERNEL_PANIC ) // kernel error => kernel panic |
---|
| 437 | { |
---|
[408] | 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 ); |
---|
[16] | 441 | } |
---|
[406] | 442 | |
---|
[407] | 443 | excp_dmsg("\n[DBG] %s : core[%x,%d] exit / thread %x in process %x / cycle %d\n", |
---|
[408] | 444 | __FUNCTION__, local_cxy, this->core->lid, this->trdid, this->process->pid, |
---|
| 445 | (uint32_t)hal_get_cycles() ); |
---|
[406] | 446 | |
---|
[16] | 447 | } // end hal_do_exception() |
---|
| 448 | |
---|
| 449 | |
---|