github.com/f-secure-foundry/tamago@v0.0.0-20220307101044-d73fcdd7f11b/arm/exception.s (about)

     1  // ARM processor support
     2  // https://github.com/f-secure-foundry/tamago
     3  //
     4  // Copyright (c) F-Secure Corporation
     5  // https://foundry.f-secure.com
     6  //
     7  // Use of this source code is governed by the license
     8  // that can be found in the LICENSE file.
     9  
    10  #include "go_asm.h"
    11  #include "textflag.h"
    12  
    13  // func set_exc_stack(addr uint32)
    14  TEXT ·set_exc_stack(SB),NOSPLIT,$0-4
    15  	MOVW addr+0(FP), R0
    16  
    17  	// Set IRQ mode SP
    18  	WORD	$0xe321f0d2	// msr CPSR_c, 0xd2
    19  	MOVW R0, R13
    20  
    21  	// Set Supervisor mode SP
    22  	WORD	$0xe321f0d3	// msr CPSR_c, 0xd3
    23  	MOVW R0, R13
    24  
    25  	// Set Monitor mode SP
    26  	WORD	$0xe321f0d6	// msr CPSR_c, 0xd6
    27  	MOVW R0, R13
    28  
    29  	// Set Abort mode SP
    30  	WORD	$0xe321f0d7	// msr CPSR_c, 0xd7
    31  	MOVW R0, R13
    32  
    33  	// Set Undefined mode SP
    34  	WORD	$0xe321f0db	// msr CPSR_c, 0xdb
    35  	MOVW R0, R13
    36  
    37  	// Return to System mode
    38  	WORD	$0xe321f0df	// msr CPSR_c, 0xdf
    39  
    40  	RET
    41  
    42  // func set_vbar(addr uint32)
    43  TEXT ·set_vbar(SB),NOSPLIT,$0-4
    44  	MOVW	addr+0(FP), R0
    45  	MCR	15, 0, R0, C12, C0, 0
    46  	RET
    47  
    48  // func set_mvbar(addr uint32)
    49  TEXT ·set_mvbar(SB),NOSPLIT,$0-4
    50  	MOVW	addr+0(FP), R0
    51  	MCR	15, 0, R0, C12, C0, 1
    52  	RET
    53  
    54  #define EXCEPTION(OFFSET, FN, LROFFSET, RN, SAVE_SIZE)			\
    55  	/* restore stack pointer */					\
    56  	WORD	$0xe105d200			/* mrs sp, SP_usr */	\
    57  									\
    58  	/* remove exception specific LR offset */			\
    59  	SUB	$LROFFSET, R14, R14					\
    60  									\
    61  	/* save caller registers */					\
    62  	MOVM.DB.W	[R0-RN, R14], (R13)	/* push {r0-rN, r14} */	\
    63  									\
    64  	/* call exception handler on g0 */				\
    65  	MOVW	$OFFSET, R0						\
    66  	MOVW	$FN(SB), R1						\
    67  	MOVW	$SAVE_SIZE, R2						\
    68  	MOVW	R14, R3							\
    69  	CALL	runtime·CallOnG0(SB)					\
    70  									\
    71  	/* restore registers */						\
    72  	MOVM.IA.W	(R13), [R0-RN, R14]	/* pop {r0-rN, r14} */	\
    73  									\
    74  	/* restore PC from LR and mode */				\
    75  	ADD	$LROFFSET, R14, R14					\
    76  	MOVW.S	R14, R15
    77  
    78  TEXT ·resetHandler(SB),NOSPLIT|NOFRAME,$0
    79  	EXCEPTION(const_RESET, ·systemException, 0, R12, 56)
    80  
    81  TEXT ·undefinedHandler(SB),NOSPLIT|NOFRAME,$0
    82  	EXCEPTION(const_UNDEFINED, ·systemException, 4, R12, 56)
    83  
    84  TEXT ·supervisorHandler(SB),NOSPLIT|NOFRAME,$0
    85  	EXCEPTION(const_SUPERVISOR, ·systemException, 0, R12, 56)
    86  
    87  TEXT ·prefetchAbortHandler(SB),NOSPLIT|NOFRAME,$0
    88  	EXCEPTION(const_PREFETCH_ABORT, ·systemException, 4, R12, 56)
    89  
    90  TEXT ·dataAbortHandler(SB),NOSPLIT|NOFRAME,$0
    91  	EXCEPTION(const_DATA_ABORT, ·systemException, 8, R12, 56)
    92  
    93  TEXT ·irqHandler(SB),NOSPLIT|NOFRAME,$0
    94  	EXCEPTION(const_IRQ, ·systemException, 4, R12, 56)
    95  
    96  TEXT ·fiqHandler(SB),NOSPLIT|NOFRAME,$0
    97  	EXCEPTION(const_FIQ, ·systemException, 4, R7, 36)
    98  
    99  TEXT ·nullHandler(SB),NOSPLIT|NOFRAME,$0
   100  	MOVW.S	R14, R15