Ticket #6032: 0003-Implement-arch_debug_call_with_fault_handler-in-asse.patch

File 0003-Implement-arch_debug_call_with_fault_handler-in-asse.patch, 3.0 KB (added by andreasf, 11 years ago)

proposed patch: implement arch_debug_call_with_fault_handler

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

    From 8a82bfe8b8e1c70992cb6fcc0d4c3456c6d5ffea Mon Sep 17 00:00:00 2001
    From: Andreas Faerber <andreas.faerber@web.de>
    Date: Sat, 5 Jun 2010 14:00:35 +0200
    Subject: [PATCH 3/4] Implement arch_debug_call_with_fault_handler in assembler
    
    ---
     src/system/kernel/arch/ppc/arch_asm.S     |   57 +++++++++++++++++++++++++++++
     src/system/kernel/arch/ppc/arch_debug.cpp |    9 -----
     2 files changed, 57 insertions(+), 9 deletions(-)
    
    diff --git a/src/system/kernel/arch/ppc/arch_asm.S b/src/system/kernel/arch/ppc/arch_asm.S
    index 2a07bdc..0ed1593 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    // 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)
     3811:
     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
  • 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{