/*
© [2024] Microchip Technology Inc. and its subsidiaries.

    Subject to your compliance with these terms, you may use Microchip 
    software and any derivatives exclusively with Microchip products. 
    You are responsible for complying with 3rd party license terms  
    applicable to your use of 3rd party software (including open source  
    software) that may accompany Microchip software. SOFTWARE IS ?AS IS.? 
    NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS 
    SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT,  
    MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT 
    WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, 
    INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY 
    KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF 
    MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE 
    FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP?S 
    TOTAL LIABILITY ON ALL CLAIMS RELATED TO THE SOFTWARE WILL NOT 
    EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR 
    THIS SOFTWARE.
*/
     
/**
*   12 bytes pushed to stack after the trap happens including the handler and where_was_i call.
*   substracting 12 from the current stack pointer will give the source of trap.
*
*   current SP                        +12
*   where_was_i   push.l w0           +8
*   rcall in      PC 23->16           +6
*   handler       PC 15->0            +4
*                 PC 23->16           +2
*   TRAP!         PC 15->0            +0
*/
    .section *,bss,near
    .global _trapSrcAddr
 _trapSrcAddr:   .space 4

    .text
    .global _where_was_i
 _where_was_i:
    push.l w0
    sub.l w15,#12,w0
    mov.l [w0], w0
    mov.l w0, _trapSrcAddr
    pop.l w0
    return
