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