blob: 583ee4a520533106f7cf34062a12bdcd337e2c80 [file] [log] [blame]
Soby Mathewd29f67b2016-05-05 12:31:57 +01001/*
Antonio Nino Diazd3ec5432017-02-17 17:11:27 +00002 * Copyright (c) 2016-2017, ARM Limited and Contributors. All rights reserved.
Soby Mathewd29f67b2016-05-05 12:31:57 +01003 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Soby Mathewd29f67b2016-05-05 12:31:57 +01005 */
6
7#include <arch.h>
8#include <asm_macros.S>
9
Jeenu Viswambharanff640c42016-11-28 09:59:27 +000010 .globl asm_assert
Soby Mathewd29f67b2016-05-05 12:31:57 +010011 .globl do_panic
Yatharth Kocharf528faf2016-06-28 16:58:26 +010012 .globl report_exception
Soby Mathewd29f67b2016-05-05 12:31:57 +010013
Jeenu Viswambharanff640c42016-11-28 09:59:27 +000014/* Since the max decimal input number is 65536 */
15#define MAX_DEC_DIVISOR 10000
16
17/* The offset to add to get ascii for numerals '0 - 9' */
18#define ASCII_OFFSET_NUM '0'
19
20 .section .rodata.panic_str, "aS"
21panic_msg:
22 .asciz "PANIC at PC : 0x"
23panic_end:
24 .asciz "\r\n"
25
Soby Mathewd29f67b2016-05-05 12:31:57 +010026 /***********************************************************
27 * The common implementation of do_panic for all BL stages
28 ***********************************************************/
29func do_panic
Jeenu Viswambharanff640c42016-11-28 09:59:27 +000030 /* Have LR copy point to PC at the time of panic */
31 sub r6, lr, #4
32
33 /* Initialize crash console and verify success */
34 bl plat_crash_console_init
35 cmp r0, #0
36 beq 1f
37
38 /* Print panic message */
39 ldr r4, =panic_msg
40 bl asm_print_str
41
42 /* Print LR in hex */
43 mov r4, r6
44 bl asm_print_hex
45
46 /* Print new line */
47 ldr r4, =panic_end
48 bl asm_print_str
Antonio Nino Diazd3ec5432017-02-17 17:11:27 +000049
50 bl plat_crash_console_flush
51
Jeenu Viswambharanff640c42016-11-28 09:59:27 +0000521:
53 mov lr, r6
Julius Werner67ebde72017-07-27 14:59:34 -070054 b plat_panic_handler
Soby Mathewd29f67b2016-05-05 12:31:57 +010055endfunc do_panic
56
Yatharth Kocharf528faf2016-06-28 16:58:26 +010057 /***********************************************************
58 * This function is called from the vector table for
59 * unhandled exceptions. It reads the current mode and
60 * passes it to platform.
61 ***********************************************************/
62func report_exception
63 mrs r0, cpsr
64 and r0, #MODE32_MASK
65 bl plat_report_exception
Jeenu Viswambharan68aef102016-11-30 15:21:11 +000066 no_ret plat_panic_handler
Yatharth Kocharf528faf2016-06-28 16:58:26 +010067endfunc report_exception
Jeenu Viswambharanff640c42016-11-28 09:59:27 +000068
Antonio Nino Diaz7c65c1e2017-04-20 09:58:28 +010069#if ENABLE_ASSERTIONS
Jeenu Viswambharanff640c42016-11-28 09:59:27 +000070.section .rodata.assert_str, "aS"
71assert_msg1:
72 .asciz "ASSERT: File "
73assert_msg2:
74 .asciz " Line "
75
76/* ---------------------------------------------------------------------------
77 * Assertion support in assembly.
78 * The below function helps to support assertions in assembly where we do not
79 * have a C runtime stack. Arguments to the function are :
80 * r0 - File name
81 * r1 - Line no
82 * Clobber list : lr, r0 - r6
83 * ---------------------------------------------------------------------------
84 */
85func asm_assert
Antonio Nino Diaz808c2292017-04-18 15:16:05 +010086#if LOG_LEVEL >= LOG_LEVEL_INFO
87 /*
88 * Only print the output if LOG_LEVEL is higher or equal to
89 * LOG_LEVEL_INFO, which is the default value for builds with DEBUG=1.
90 */
Jeenu Viswambharanff640c42016-11-28 09:59:27 +000091 /* Stash the parameters already in r0 and r1 */
92 mov r5, r0
93 mov r6, r1
94
95 /* Initialize crash console and verify success */
96 bl plat_crash_console_init
97 cmp r0, #0
98 beq 1f
99
100 /* Print file name */
101 ldr r4, =assert_msg1
102 bl asm_print_str
103 mov r4, r5
104 bl asm_print_str
105
106 /* Print line number string */
107 ldr r4, =assert_msg2
108 bl asm_print_str
109
110 /* Test for maximum supported line number */
111 ldr r4, =~0xffff
112 tst r6, r4
113 bne 1f
114 mov r4, r6
115
116 /* Print line number in decimal */
117 mov r6, #10 /* Divide by 10 after every loop iteration */
118 ldr r5, =MAX_DEC_DIVISOR
119dec_print_loop:
120 udiv r0, r4, r5 /* Quotient */
121 mls r4, r0, r5, r4 /* Remainder */
122 add r0, r0, #ASCII_OFFSET_NUM /* Convert to ASCII */
123 bl plat_crash_console_putc
124 udiv r5, r5, r6 /* Reduce divisor */
125 cmp r5, #0
126 bne dec_print_loop
Antonio Nino Diazd3ec5432017-02-17 17:11:27 +0000127
128 bl plat_crash_console_flush
129
Jeenu Viswambharanff640c42016-11-28 09:59:27 +00001301:
Antonio Nino Diaz808c2292017-04-18 15:16:05 +0100131#endif /* LOG_LEVEL >= LOG_LEVEL_INFO */
Jeenu Viswambharanff640c42016-11-28 09:59:27 +0000132 no_ret plat_panic_handler
133endfunc asm_assert
Antonio Nino Diaz7c65c1e2017-04-20 09:58:28 +0100134#endif /* ENABLE_ASSERTIONS */
Jeenu Viswambharanff640c42016-11-28 09:59:27 +0000135
136/*
137 * This function prints a string from address in r4
138 * Clobber: lr, r0 - r4
139 */
140func asm_print_str
141 mov r3, lr
1421:
143 ldrb r0, [r4], #0x1
144 cmp r0, #0
145 beq 2f
146 bl plat_crash_console_putc
147 b 1b
1482:
149 bx r3
150endfunc asm_print_str
151
152/*
153 * This function prints a hexadecimal number in r4.
154 * In: r4 = the hexadecimal to print.
155 * Clobber: lr, r0 - r3, r5
156 */
157func asm_print_hex
158 mov r3, lr
159 mov r5, #32 /* No of bits to convert to ascii */
1601:
161 sub r5, r5, #4
162 lsr r0, r4, r5
163 and r0, r0, #0xf
164 cmp r0, #0xa
165 blo 2f
166 /* Add by 0x27 in addition to ASCII_OFFSET_NUM
167 * to get ascii for characters 'a - f'.
168 */
169 add r0, r0, #0x27
1702:
171 add r0, r0, #ASCII_OFFSET_NUM
172 bl plat_crash_console_putc
173 cmp r5, #0
174 bne 1b
175 bx r3
176endfunc asm_print_hex