Soby Mathew | d29f67b | 2016-05-05 12:31:57 +0100 | [diff] [blame] | 1 | /* |
Antonio Nino Diaz | d3ec543 | 2017-02-17 17:11:27 +0000 | [diff] [blame] | 2 | * Copyright (c) 2016-2017, ARM Limited and Contributors. All rights reserved. |
Soby Mathew | d29f67b | 2016-05-05 12:31:57 +0100 | [diff] [blame] | 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions are met: |
| 6 | * |
| 7 | * Redistributions of source code must retain the above copyright notice, this |
| 8 | * list of conditions and the following disclaimer. |
| 9 | * |
| 10 | * Redistributions in binary form must reproduce the above copyright notice, |
| 11 | * this list of conditions and the following disclaimer in the documentation |
| 12 | * and/or other materials provided with the distribution. |
| 13 | * |
| 14 | * Neither the name of ARM nor the names of its contributors may be used |
| 15 | * to endorse or promote products derived from this software without specific |
| 16 | * prior written permission. |
| 17 | * |
| 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
| 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 28 | * POSSIBILITY OF SUCH DAMAGE. |
| 29 | */ |
| 30 | |
| 31 | #include <arch.h> |
| 32 | #include <asm_macros.S> |
| 33 | |
Jeenu Viswambharan | ff640c4 | 2016-11-28 09:59:27 +0000 | [diff] [blame] | 34 | .globl asm_assert |
Soby Mathew | d29f67b | 2016-05-05 12:31:57 +0100 | [diff] [blame] | 35 | .globl do_panic |
Yatharth Kochar | f528faf | 2016-06-28 16:58:26 +0100 | [diff] [blame] | 36 | .globl report_exception |
Soby Mathew | d29f67b | 2016-05-05 12:31:57 +0100 | [diff] [blame] | 37 | |
Jeenu Viswambharan | ff640c4 | 2016-11-28 09:59:27 +0000 | [diff] [blame] | 38 | /* Since the max decimal input number is 65536 */ |
| 39 | #define MAX_DEC_DIVISOR 10000 |
| 40 | |
| 41 | /* The offset to add to get ascii for numerals '0 - 9' */ |
| 42 | #define ASCII_OFFSET_NUM '0' |
| 43 | |
| 44 | .section .rodata.panic_str, "aS" |
| 45 | panic_msg: |
| 46 | .asciz "PANIC at PC : 0x" |
| 47 | panic_end: |
| 48 | .asciz "\r\n" |
| 49 | |
Soby Mathew | d29f67b | 2016-05-05 12:31:57 +0100 | [diff] [blame] | 50 | /*********************************************************** |
| 51 | * The common implementation of do_panic for all BL stages |
| 52 | ***********************************************************/ |
| 53 | func do_panic |
Jeenu Viswambharan | ff640c4 | 2016-11-28 09:59:27 +0000 | [diff] [blame] | 54 | /* Have LR copy point to PC at the time of panic */ |
| 55 | sub r6, lr, #4 |
| 56 | |
| 57 | /* Initialize crash console and verify success */ |
| 58 | bl plat_crash_console_init |
| 59 | cmp r0, #0 |
| 60 | beq 1f |
| 61 | |
| 62 | /* Print panic message */ |
| 63 | ldr r4, =panic_msg |
| 64 | bl asm_print_str |
| 65 | |
| 66 | /* Print LR in hex */ |
| 67 | mov r4, r6 |
| 68 | bl asm_print_hex |
| 69 | |
| 70 | /* Print new line */ |
| 71 | ldr r4, =panic_end |
| 72 | bl asm_print_str |
Antonio Nino Diaz | d3ec543 | 2017-02-17 17:11:27 +0000 | [diff] [blame] | 73 | |
| 74 | bl plat_crash_console_flush |
| 75 | |
Jeenu Viswambharan | ff640c4 | 2016-11-28 09:59:27 +0000 | [diff] [blame] | 76 | 1: |
| 77 | mov lr, r6 |
Antonio Nino Diaz | e98fa3a | 2017-02-16 16:49:18 +0000 | [diff] [blame] | 78 | no_ret plat_panic_handler |
Soby Mathew | d29f67b | 2016-05-05 12:31:57 +0100 | [diff] [blame] | 79 | endfunc do_panic |
| 80 | |
Yatharth Kochar | f528faf | 2016-06-28 16:58:26 +0100 | [diff] [blame] | 81 | /*********************************************************** |
| 82 | * This function is called from the vector table for |
| 83 | * unhandled exceptions. It reads the current mode and |
| 84 | * passes it to platform. |
| 85 | ***********************************************************/ |
| 86 | func report_exception |
| 87 | mrs r0, cpsr |
| 88 | and r0, #MODE32_MASK |
| 89 | bl plat_report_exception |
Jeenu Viswambharan | 68aef10 | 2016-11-30 15:21:11 +0000 | [diff] [blame] | 90 | no_ret plat_panic_handler |
Yatharth Kochar | f528faf | 2016-06-28 16:58:26 +0100 | [diff] [blame] | 91 | endfunc report_exception |
Jeenu Viswambharan | ff640c4 | 2016-11-28 09:59:27 +0000 | [diff] [blame] | 92 | |
Antonio Nino Diaz | 7c65c1e | 2017-04-20 09:58:28 +0100 | [diff] [blame] | 93 | #if ENABLE_ASSERTIONS |
Jeenu Viswambharan | ff640c4 | 2016-11-28 09:59:27 +0000 | [diff] [blame] | 94 | .section .rodata.assert_str, "aS" |
| 95 | assert_msg1: |
| 96 | .asciz "ASSERT: File " |
| 97 | assert_msg2: |
| 98 | .asciz " Line " |
| 99 | |
| 100 | /* --------------------------------------------------------------------------- |
| 101 | * Assertion support in assembly. |
| 102 | * The below function helps to support assertions in assembly where we do not |
| 103 | * have a C runtime stack. Arguments to the function are : |
| 104 | * r0 - File name |
| 105 | * r1 - Line no |
| 106 | * Clobber list : lr, r0 - r6 |
| 107 | * --------------------------------------------------------------------------- |
| 108 | */ |
| 109 | func asm_assert |
Antonio Nino Diaz | 808c229 | 2017-04-18 15:16:05 +0100 | [diff] [blame] | 110 | #if LOG_LEVEL >= LOG_LEVEL_INFO |
| 111 | /* |
| 112 | * Only print the output if LOG_LEVEL is higher or equal to |
| 113 | * LOG_LEVEL_INFO, which is the default value for builds with DEBUG=1. |
| 114 | */ |
Jeenu Viswambharan | ff640c4 | 2016-11-28 09:59:27 +0000 | [diff] [blame] | 115 | /* Stash the parameters already in r0 and r1 */ |
| 116 | mov r5, r0 |
| 117 | mov r6, r1 |
| 118 | |
| 119 | /* Initialize crash console and verify success */ |
| 120 | bl plat_crash_console_init |
| 121 | cmp r0, #0 |
| 122 | beq 1f |
| 123 | |
| 124 | /* Print file name */ |
| 125 | ldr r4, =assert_msg1 |
| 126 | bl asm_print_str |
| 127 | mov r4, r5 |
| 128 | bl asm_print_str |
| 129 | |
| 130 | /* Print line number string */ |
| 131 | ldr r4, =assert_msg2 |
| 132 | bl asm_print_str |
| 133 | |
| 134 | /* Test for maximum supported line number */ |
| 135 | ldr r4, =~0xffff |
| 136 | tst r6, r4 |
| 137 | bne 1f |
| 138 | mov r4, r6 |
| 139 | |
| 140 | /* Print line number in decimal */ |
| 141 | mov r6, #10 /* Divide by 10 after every loop iteration */ |
| 142 | ldr r5, =MAX_DEC_DIVISOR |
| 143 | dec_print_loop: |
| 144 | udiv r0, r4, r5 /* Quotient */ |
| 145 | mls r4, r0, r5, r4 /* Remainder */ |
| 146 | add r0, r0, #ASCII_OFFSET_NUM /* Convert to ASCII */ |
| 147 | bl plat_crash_console_putc |
| 148 | udiv r5, r5, r6 /* Reduce divisor */ |
| 149 | cmp r5, #0 |
| 150 | bne dec_print_loop |
Antonio Nino Diaz | d3ec543 | 2017-02-17 17:11:27 +0000 | [diff] [blame] | 151 | |
| 152 | bl plat_crash_console_flush |
| 153 | |
Jeenu Viswambharan | ff640c4 | 2016-11-28 09:59:27 +0000 | [diff] [blame] | 154 | 1: |
Antonio Nino Diaz | 808c229 | 2017-04-18 15:16:05 +0100 | [diff] [blame] | 155 | #endif /* LOG_LEVEL >= LOG_LEVEL_INFO */ |
Jeenu Viswambharan | ff640c4 | 2016-11-28 09:59:27 +0000 | [diff] [blame] | 156 | no_ret plat_panic_handler |
| 157 | endfunc asm_assert |
Antonio Nino Diaz | 7c65c1e | 2017-04-20 09:58:28 +0100 | [diff] [blame] | 158 | #endif /* ENABLE_ASSERTIONS */ |
Jeenu Viswambharan | ff640c4 | 2016-11-28 09:59:27 +0000 | [diff] [blame] | 159 | |
| 160 | /* |
| 161 | * This function prints a string from address in r4 |
| 162 | * Clobber: lr, r0 - r4 |
| 163 | */ |
| 164 | func asm_print_str |
| 165 | mov r3, lr |
| 166 | 1: |
| 167 | ldrb r0, [r4], #0x1 |
| 168 | cmp r0, #0 |
| 169 | beq 2f |
| 170 | bl plat_crash_console_putc |
| 171 | b 1b |
| 172 | 2: |
| 173 | bx r3 |
| 174 | endfunc asm_print_str |
| 175 | |
| 176 | /* |
| 177 | * This function prints a hexadecimal number in r4. |
| 178 | * In: r4 = the hexadecimal to print. |
| 179 | * Clobber: lr, r0 - r3, r5 |
| 180 | */ |
| 181 | func asm_print_hex |
| 182 | mov r3, lr |
| 183 | mov r5, #32 /* No of bits to convert to ascii */ |
| 184 | 1: |
| 185 | sub r5, r5, #4 |
| 186 | lsr r0, r4, r5 |
| 187 | and r0, r0, #0xf |
| 188 | cmp r0, #0xa |
| 189 | blo 2f |
| 190 | /* Add by 0x27 in addition to ASCII_OFFSET_NUM |
| 191 | * to get ascii for characters 'a - f'. |
| 192 | */ |
| 193 | add r0, r0, #0x27 |
| 194 | 2: |
| 195 | add r0, r0, #ASCII_OFFSET_NUM |
| 196 | bl plat_crash_console_putc |
| 197 | cmp r5, #0 |
| 198 | bne 1b |
| 199 | bx r3 |
| 200 | endfunc asm_print_hex |