Furquan Shaikh | 668316b | 2014-08-30 21:59:11 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
Furquan Shaikh | 668316b | 2014-08-30 21:59:11 -0700 | [diff] [blame] | 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License as published by |
| 6 | * the Free Software Foundation; version 2 of the License. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
Furquan Shaikh | 668316b | 2014-08-30 21:59:11 -0700 | [diff] [blame] | 12 | */ |
| 13 | |
| 14 | /* |
| 15 | * transition_asm.S: This file handles the entry and exit from an exception |
| 16 | * |
| 17 | * Flow: exception --> exc_vectors --> exc_entry --> exc_dispatch --> |
| 18 | * exc_exit |
| 19 | * Transition Flow: transition --> trans_switch --> exc_exit |
| 20 | * |
| 21 | * |---| Exception Entry |---| |
| 22 | * |
| 23 | * On exception entry, it saves all the xregs on SP_ELx since SP_ELx is |
| 24 | * selected on entry. Some dummy pushes are performed to create space for |
| 25 | * elx_state structure. It then passes pointer to this saved set of regs and |
| 26 | * a unique id(for identifying exception) to exc_entry. |
| 27 | * |
| 28 | * |---| Exception Transition Dispatch |---| |
| 29 | * |
| 30 | * This is the C-component of exception entry. It does the work of initializing |
| 31 | * the exc_state registers. Finally it calls exception dispatch implemented by |
| 32 | * the user. This is point of no-return. |
| 33 | * |
| 34 | * |---| Exception Dispatch |---| |
| 35 | * |
| 36 | * User of this functionality is expected to implement exc_dispatch which |
| 37 | * acts as entry point for it. Once exception handling is complete, the user |
| 38 | * needs to call exc_exit with pointer to struct regs. |
| 39 | * |
| 40 | * |---| Exception Exit |---| |
| 41 | * |
| 42 | * Once exc_dispatch is done with handling the exception based on the id passed |
| 43 | * to it, it needs to call exc_exit with pointer to struct regs. This is done to |
| 44 | * unwind the exception stack by popping off all the xregs. |
| 45 | * |
| 46 | * |---| Exception Transition Exit |---| |
| 47 | * |
| 48 | * This routine makes SP_EL0 point to the regs structure passed and continues |
| 49 | * onto the exception exit routine described above. This is the reason that |
| 50 | * transition library does not handle initialization of SP_EL0 for the program |
| 51 | * to be executed. |
| 52 | */ |
| 53 | |
Furquan Shaikh | 668316b | 2014-08-30 21:59:11 -0700 | [diff] [blame] | 54 | #include <arch/asm.h> |
| 55 | #include <arch/lib_helpers.h> |
| 56 | #include <arch/transition.h> |
| 57 | |
| 58 | .macro eentry lbl id |
| 59 | .align 7 |
| 60 | \lbl: |
| 61 | stp x29, x30, [sp, #STACK_PUSH_BYTES]! |
| 62 | bl exc_prologue |
| 63 | mov x1, \id |
| 64 | mov x0, sp |
| 65 | b exc_entry |
| 66 | .endm |
| 67 | |
| 68 | /* |
| 69 | * exc_vectors: Entry point for an exception |
| 70 | */ |
| 71 | ENTRY_WITH_ALIGN(exc_vectors, 11) |
| 72 | |
Aaron Durbin | 4f89d97 | 2014-09-16 22:23:57 -0500 | [diff] [blame] | 73 | eentry sync_curr_sp0, #EXC_VID_CUR_SP_EL0_SYNC |
| 74 | eentry irq_curr_sp0, #EXC_VID_CUR_SP_EL0_IRQ |
| 75 | eentry fiq_curr_sp0, #EXC_VID_CUR_SP_EL0_FIRQ |
| 76 | eentry serror_curr_sp0, #EXC_VID_CUR_SP_EL0_SERR |
| 77 | eentry sync_curr_spx, #EXC_VID_CUR_SP_ELX_SYNC |
| 78 | eentry irq_curr_spx, #EXC_VID_CUR_SP_ELX_IRQ |
| 79 | eentry fiq_curr_spx, #EXC_VID_CUR_SP_ELX_FIQ |
| 80 | eentry serror_curr_spx, #EXC_VID_CUR_SP_ELX_SERR |
| 81 | eentry sync_lower_64, #EXC_VID_LOW64_SYNC |
| 82 | eentry irq_lower_64, #EXC_VID_LOW64_IRQ |
| 83 | eentry fiq_lower_64, #EXC_VID_LOW64_FIQ |
| 84 | eentry serror_lower_64, #EXC_VID_LOW64_SERR |
| 85 | eentry sync_lower_32, #EXC_VID_LOW32_SYNC |
| 86 | eentry irq_lower_32, #EXC_VID_LOW32_IRQ |
| 87 | eentry fiq_lower_32, #EXC_VID_LOW32_FIQ |
| 88 | eentry serror_lower_32, #EXC_VID_LOW32_SERR |
Furquan Shaikh | 668316b | 2014-08-30 21:59:11 -0700 | [diff] [blame] | 89 | |
| 90 | ENDPROC(exc_vectors) |
| 91 | |
| 92 | ENTRY(exc_prologue) |
| 93 | stp x27, x28, [sp, #STACK_PUSH_BYTES]! |
| 94 | stp x25, x26, [sp, #STACK_PUSH_BYTES]! |
| 95 | stp x23, x24, [sp, #STACK_PUSH_BYTES]! |
| 96 | stp x21, x22, [sp, #STACK_PUSH_BYTES]! |
| 97 | stp x19, x20, [sp, #STACK_PUSH_BYTES]! |
| 98 | stp x17, x18, [sp, #STACK_PUSH_BYTES]! |
| 99 | stp x15, x16, [sp, #STACK_PUSH_BYTES]! |
| 100 | stp x13, x14, [sp, #STACK_PUSH_BYTES]! |
| 101 | stp x11, x12, [sp, #STACK_PUSH_BYTES]! |
| 102 | stp x9, x10, [sp, #STACK_PUSH_BYTES]! |
| 103 | stp x7, x8, [sp, #STACK_PUSH_BYTES]! |
| 104 | stp x5, x6, [sp, #STACK_PUSH_BYTES]! |
| 105 | stp x3, x4, [sp, #STACK_PUSH_BYTES]! |
| 106 | stp x1, x2, [sp, #STACK_PUSH_BYTES]! |
| 107 | /* xzr pushed as place holder for sp */ |
| 108 | stp xzr, x0, [sp, #STACK_PUSH_BYTES]! |
| 109 | /* |
| 110 | * xzr pushed as place holder for: |
| 111 | * 1. sp_elx and elr |
| 112 | */ |
| 113 | stp xzr, xzr, [sp, #STACK_PUSH_BYTES]! |
| 114 | /* 2. spsr and sp_el0 */ |
| 115 | stp xzr, xzr, [sp, #STACK_PUSH_BYTES]! |
| 116 | ret |
| 117 | ENDPROC(exc_prologue) |
| 118 | |
| 119 | /* |
| 120 | * trans_switch: Set SPSel to use SP_EL0 |
| 121 | * x0 = regs structure |
| 122 | */ |
| 123 | ENTRY(trans_switch) |
Elyes HAOUAS | 6b72787 | 2016-09-03 08:28:48 +0200 | [diff] [blame] | 124 | msr SPSel, #SPSR_USE_L |
| 125 | b exc_exit |
Furquan Shaikh | 668316b | 2014-08-30 21:59:11 -0700 | [diff] [blame] | 126 | ENDPROC(trans_switch) |
| 127 | |
| 128 | /* |
| 129 | * exc_exit: Return from exception by restoring saved state of xregs |
| 130 | * x0 = regs structure |
| 131 | */ |
| 132 | ENTRY(exc_exit) |
| 133 | /* Unwind the stack by making sp point to regs structure */ |
| 134 | mov sp, x0 |
| 135 | /* Load registers x0-x30 */ |
| 136 | ldp xzr, x0, [sp], #STACK_POP_BYTES |
| 137 | ldp x1, x2, [sp], #STACK_POP_BYTES |
| 138 | ldp x3, x4, [sp], #STACK_POP_BYTES |
| 139 | ldp x5, x6, [sp], #STACK_POP_BYTES |
| 140 | ldp x7, x8, [sp], #STACK_POP_BYTES |
| 141 | ldp x9, x10, [sp], #STACK_POP_BYTES |
| 142 | ldp x11, x12, [sp], #STACK_POP_BYTES |
| 143 | ldp x13, x14, [sp], #STACK_POP_BYTES |
| 144 | ldp x15, x16, [sp], #STACK_POP_BYTES |
| 145 | ldp x17, x18, [sp], #STACK_POP_BYTES |
| 146 | ldp x19, x20, [sp], #STACK_POP_BYTES |
| 147 | ldp x21, x22, [sp], #STACK_POP_BYTES |
| 148 | ldp x23, x24, [sp], #STACK_POP_BYTES |
| 149 | ldp x25, x26, [sp], #STACK_POP_BYTES |
| 150 | ldp x27, x28, [sp], #STACK_POP_BYTES |
| 151 | ldp x29, x30, [sp], #STACK_POP_BYTES |
| 152 | eret |
| 153 | ENDPROC(exc_exit) |
| 154 | |
Julius Werner | 66a476a | 2015-10-12 16:45:21 -0700 | [diff] [blame] | 155 | /* |
| 156 | * exception_init_asm: Initialize VBAR and point SP_EL3 to exception stack. |
Julius Werner | bb345ab | 2019-12-03 22:47:01 -0800 | [diff] [blame] | 157 | * Also unmask aborts now that we can report them. x0 = end of exception stack |
Julius Werner | 66a476a | 2015-10-12 16:45:21 -0700 | [diff] [blame] | 158 | */ |
| 159 | ENTRY(exception_init_asm) |
| 160 | msr SPSel, #SPSR_USE_H |
| 161 | mov sp, x0 |
| 162 | msr SPSel, #SPSR_USE_L |
| 163 | |
Furquan Shaikh | 668316b | 2014-08-30 21:59:11 -0700 | [diff] [blame] | 164 | adr x0, exc_vectors |
Julius Werner | 0c5f61a | 2018-08-03 17:14:45 -0700 | [diff] [blame] | 165 | msr vbar_el3, x0 |
Julius Werner | bb345ab | 2019-12-03 22:47:01 -0800 | [diff] [blame] | 166 | |
| 167 | msr DAIFClr, #0xf |
| 168 | |
Furquan Shaikh | 668316b | 2014-08-30 21:59:11 -0700 | [diff] [blame] | 169 | dsb sy |
| 170 | isb |
| 171 | ret |
Julius Werner | 66a476a | 2015-10-12 16:45:21 -0700 | [diff] [blame] | 172 | ENDPROC(exception_init_asm) |