| 335 | |
| 336 | /*! \fn void arch_debug_call_with_fault_handler(cpu_ent* cpu, |
| 337 | jmp_buf jumpBuffer, void (*function)(void*), void* parameter) |
| 338 | |
| 339 | Called by debug_call_with_fault_handler() to do the dirty work of setting |
| 340 | the fault handler and calling the function. If the function causes a page |
| 341 | fault, the arch_debug_call_with_fault_handler() calls longjmp() with the |
| 342 | given \a jumpBuffer. Otherwise it returns normally. |
| 343 | |
| 344 | debug_call_with_fault_handler() has already saved the CPU's fault_handler |
| 345 | and fault_handler_stack_pointer and will reset them later, so |
| 346 | arch_debug_call_with_fault_handler() doesn't need to care about it. |
| 347 | |
| 348 | \param cpu The \c cpu_ent for the current CPU. |
| 349 | \param jumpBuffer Buffer to be used for longjmp(). |
| 350 | \param function The function to be called. |
| 351 | \param parameter The parameter to be passed to the function to be called. |
| 352 | */ |
| 353 | FUNCTION(arch_debug_call_with_fault_handler): |
| 354 | // prolog: setup stack frame (16-byte aligned) |
| 355 | mflr %r0 |
| 356 | stw %r0, 4(%r1) // store LR |
| 357 | stwu %r1, -16(%r1) // store back chain |
| 358 | stw %r4, 8(%r1) // store jumpBuffer |
| 359 | |
| 360 | // set cpu->fault_handler_stack_pointer |
| 361 | stw %r1, CPU_ENT_fault_handler_stack_pointer(%r3) |
| 362 | |
| 363 | // set cpu->fault_handler |
| 364 | lis %r11, 1f@ha |
| 365 | ori %r11, %r11, 1f@l |
| 366 | stw %r11, CPU_ENT_fault_handler(%r3) |
| 367 | |
| 368 | // call the given function |
| 369 | mr %r3, %r6 |
| 370 | mtlr %r5 |
| 371 | blrl |
| 372 | |
| 373 | // epilog: restore stack frame |
| 374 | lwz %r0, 16 + 4(%r1) // load LR |
| 375 | mtlr %r0 |
| 376 | addi %r1, %r1, 16 // restore SP |
| 377 | |
| 378 | blr |
| 379 | |
| 380 | // fault -- return via longjmp(jumpBuffer, 1) |
| 381 | 1: |
| 382 | lwz %r3, 8(%r1) // load jumpBuffer |
| 383 | |
| 384 | // call longjmp |
| 385 | li %r4, 1 |
| 386 | lis %r0, longjmp@ha |
| 387 | ori %r0, %r0, longjmp@l |
| 388 | mtlr %r0 |
| 389 | blr |