Ticket #6032: ppc_arch_debug_call_with_fault_handler_2010-05-18.diff

File ppc_arch_debug_call_with_fault_handler_2010-05-18.diff, 2.5 KB (added by andreasf, 11 years ago)

draft patch: Implement arch_debug_call_with_fault_handler in assembly

  • src/system/kernel/arch/ppc/arch_asm.S

    diff --git a/src/system/kernel/arch/ppc/arch_asm.S b/src/system/kernel/arch/ppc/arch_asm.S
    index 2a07bdc..50f470c 100644
    a b  
    77 */
    88
    99
     10#include "asm_offsets.h"
     11
    1012#define FUNCTION(x) .global x; .type x,@function; x
    1113
    1214#define MSR_EXCEPTIONS_ENABLED 15
    FUNCTION(ppc_kernel_thread_root):  
    330332    li          %r3, 0
    331333    b           kernel_debugger
    332334
     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*/
     353FUNCTION(arch_debug_call_with_fault_handler):
     354    // store jump buffer pointer on stack
     355    stwu    %r4, -4(%r1)
     356    // set CPU's fault handler
     357    lis     %r13, 1b@ha
     358    ori     %r13, %r13, 1b@l
     359    stw     %r13, CPU_ENT_fault_handler(%r3)
     360    // set CPU's fault_handler_stack_pointer
     361    stw     %r1, CPU_ENT_fault_handler_stack_pointer(%r3)
     362    // call the given function
     363    stwu    %r3, -4(%r1)
     364    mflr    %r3
     365    stwu    %r3, -4(%r1)
     366
     367    mr      %r3, %r6
     368    mtlr    %r5
     369    blr
     370   
     371    lwzu    %r3, 4(%r1)
     372    mtlr    %r3
     373    lwzu    %r3, 4(%r1)
     374    lwzu    %r4, 4(%r1)
     375    blr
     376
     377    // fault -- return via longjmp(jumpBuffer, 1)
     3781:
     379    lwzu    %r3, 4(%r1)
     380    li      %r4, 1
     381    mflr    %r13
     382    stwu    %r13, -4(%r1)
     383    lis     %r13, longjmp@ha
     384    ori     %r13, %r13, longjmp@l
     385    mtlr    %r13
     386    blr
     387    lwzu    %r13, 4(%r1)
     388    mtlr    %r13
     389    blr
     390
  • src/system/kernel/arch/ppc/arch_debug.cpp

    diff --git a/src/system/kernel/arch/ppc/arch_debug.cpp b/src/system/kernel/arch/ppc/arch_debug.cpp
    index 8da8ae6..f62ac29 100644
    a b arch_debug_unset_current_thread(void)  
    308308}
    309309
    310310
    311 void
    312 arch_debug_call_with_fault_handler(cpu_ent* cpu, jmp_buf jumpBuffer,
    313     void (*function)(void*), void* parameter)
    314 {
    315     // TODO: Implement! Most likely in assembly.
    316     longjmp(jumpBuffer, 1);
    317 }
    318 
    319 
    320311bool
    321312arch_is_debug_variable_defined(const char* variableName)
    322313{