blob: cdb4ec6cd0ab8a4d1dc7e9bdb86bf80669a606c6 [file] [log] [blame]
Soby Mathew041f62a2014-07-14 16:58:03 +01001/*
Antonio Nino Diazd3ec5432017-02-17 17:11:27 +00002 * Copyright (c) 2014-2017, ARM Limited and Contributors. All rights reserved.
Soby Mathew041f62a2014-07-14 16:58:03 +01003 *
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
34 .globl asm_print_str
35 .globl asm_print_hex
36 .globl asm_assert
37 .globl do_panic
38
39/* Since the max decimal input number is 65536 */
40#define MAX_DEC_DIVISOR 10000
41/* The offset to add to get ascii for numerals '0 - 9' */
42#define ASCII_OFFSET_NUM 0x30
43
Antonio Nino Diaz7c65c1e2017-04-20 09:58:28 +010044#if ENABLE_ASSERTIONS
Soby Mathew041f62a2014-07-14 16:58:03 +010045.section .rodata.assert_str, "aS"
46assert_msg1:
47 .asciz "ASSERT: File "
48assert_msg2:
49 .asciz " Line "
50
51 /*
52 * This macro is intended to be used to print the
53 * line number in decimal. Used by asm_assert macro.
54 * The max number expected is 65536.
55 * In: x4 = the decimal to print.
56 * Clobber: x30, x0, x1, x2, x5, x6
57 */
58 .macro asm_print_line_dec
59 mov x6, #10 /* Divide by 10 after every loop iteration */
60 mov x5, #MAX_DEC_DIVISOR
Soby Mathew1218f112014-08-19 11:26:00 +010061dec_print_loop:
Soby Mathew041f62a2014-07-14 16:58:03 +010062 udiv x0, x4, x5 /* Get the quotient */
63 msub x4, x0, x5, x4 /* Find the remainder */
64 add x0, x0, #ASCII_OFFSET_NUM /* Convert to ascii */
65 bl plat_crash_console_putc
66 udiv x5, x5, x6 /* Reduce divisor */
Soby Mathew1218f112014-08-19 11:26:00 +010067 cbnz x5, dec_print_loop
Soby Mathew041f62a2014-07-14 16:58:03 +010068 .endm
69
70
71/* ---------------------------------------------------------------------------
72 * Assertion support in assembly.
73 * The below function helps to support assertions in assembly where we do not
74 * have a C runtime stack. Arguments to the function are :
75 * x0 - File name
76 * x1 - Line no
77 * Clobber list : x30, x0, x1, x2, x3, x4, x5, x6.
78 * ---------------------------------------------------------------------------
79 */
80func asm_assert
Antonio Nino Diaz808c2292017-04-18 15:16:05 +010081#if LOG_LEVEL >= LOG_LEVEL_INFO
82 /*
83 * Only print the output if LOG_LEVEL is higher or equal to
84 * LOG_LEVEL_INFO, which is the default value for builds with DEBUG=1.
85 */
Soby Mathew041f62a2014-07-14 16:58:03 +010086 mov x5, x0
87 mov x6, x1
88 /* Ensure the console is initialized */
89 bl plat_crash_console_init
90 /* Check if the console is initialized */
91 cbz x0, _assert_loop
92 /* The console is initialized */
93 adr x4, assert_msg1
94 bl asm_print_str
95 mov x4, x5
96 bl asm_print_str
97 adr x4, assert_msg2
98 bl asm_print_str
99 /* Check if line number higher than max permitted */
100 tst x6, #~0xffff
101 b.ne _assert_loop
102 mov x4, x6
103 asm_print_line_dec
Antonio Nino Diazd3ec5432017-02-17 17:11:27 +0000104 bl plat_crash_console_flush
Soby Mathew041f62a2014-07-14 16:58:03 +0100105_assert_loop:
Antonio Nino Diaz808c2292017-04-18 15:16:05 +0100106#endif /* LOG_LEVEL >= LOG_LEVEL_INFO */
Antonio Nino Diaze98fa3a2017-02-16 16:49:18 +0000107 no_ret plat_panic_handler
Kévin Petita877c252015-03-24 14:03:57 +0000108endfunc asm_assert
Antonio Nino Diaz7c65c1e2017-04-20 09:58:28 +0100109#endif /* ENABLE_ASSERTIONS */
Soby Mathew041f62a2014-07-14 16:58:03 +0100110
111/*
112 * This function prints a string from address in x4.
113 * In: x4 = pointer to string.
114 * Clobber: x30, x0, x1, x2, x3
115 */
116func asm_print_str
117 mov x3, x30
1181:
119 ldrb w0, [x4], #0x1
120 cbz x0, 2f
121 bl plat_crash_console_putc
122 b 1b
1232:
124 ret x3
Kévin Petita877c252015-03-24 14:03:57 +0000125endfunc asm_print_str
Soby Mathew041f62a2014-07-14 16:58:03 +0100126
127/*
128 * This function prints a hexadecimal number in x4.
129 * In: x4 = the hexadecimal to print.
Antonio Nino Diaz1f21bcf2016-02-01 13:57:25 +0000130 * Clobber: x30, x0 - x3, x5
Soby Mathew041f62a2014-07-14 16:58:03 +0100131 */
132func asm_print_hex
133 mov x3, x30
134 mov x5, #64 /* No of bits to convert to ascii */
1351:
136 sub x5, x5, #4
137 lsrv x0, x4, x5
138 and x0, x0, #0xf
139 cmp x0, #0xA
140 b.lo 2f
141 /* Add by 0x27 in addition to ASCII_OFFSET_NUM
142 * to get ascii for characters 'a - f'.
143 */
144 add x0, x0, #0x27
1452:
146 add x0, x0, #ASCII_OFFSET_NUM
147 bl plat_crash_console_putc
148 cbnz x5, 1b
149 ret x3
Kévin Petita877c252015-03-24 14:03:57 +0000150endfunc asm_print_hex
Soby Mathew041f62a2014-07-14 16:58:03 +0100151
Soby Mathewc1adbbc2014-06-25 10:07:40 +0100152 /***********************************************************
153 * The common implementation of do_panic for all BL stages
154 ***********************************************************/
155
156.section .rodata.panic_str, "aS"
157 panic_msg: .asciz "PANIC at PC : 0x"
158
159/* ---------------------------------------------------------------------------
160 * do_panic assumes that it is invoked from a C Runtime Environment ie a
161 * valid stack exists. This call will not return.
162 * Clobber list : if CRASH_REPORTING is not enabled then x30, x0 - x6
163 * ---------------------------------------------------------------------------
164 */
165
166/* This is for the non el3 BL stages to compile through */
167 .weak el3_panic
168
169func do_panic
170#if CRASH_REPORTING
171 str x0, [sp, #-0x10]!
172 mrs x0, currentel
173 ubfx x0, x0, #2, #2
174 cmp x0, #0x3
175 ldr x0, [sp], #0x10
176 b.eq el3_panic
177#endif
178
179panic_common:
180/*
181 * el3_panic will be redefined by the BL31
182 * crash reporting mechanism (if enabled)
183 */
184el3_panic:
185 mov x6, x30
186 bl plat_crash_console_init
187 /* Check if the console is initialized */
Antonio Nino Diaz1f21bcf2016-02-01 13:57:25 +0000188 cbz x0, _panic_handler
Soby Mathewc1adbbc2014-06-25 10:07:40 +0100189 /* The console is initialized */
190 adr x4, panic_msg
191 bl asm_print_str
192 mov x4, x6
193 /* The panic location is lr -4 */
194 sub x4, x4, #4
195 bl asm_print_hex
Soby Mathewc1adbbc2014-06-25 10:07:40 +0100196
Antonio Nino Diazd3ec5432017-02-17 17:11:27 +0000197 bl plat_crash_console_flush
198
Antonio Nino Diaz1f21bcf2016-02-01 13:57:25 +0000199_panic_handler:
200 /* Pass to plat_panic_handler the address from where el3_panic was
201 * called, not the address of the call from el3_panic. */
202 mov x30,x6
Jeenu Viswambharan68aef102016-11-30 15:21:11 +0000203 no_ret plat_panic_handler
Antonio Nino Diaz1f21bcf2016-02-01 13:57:25 +0000204endfunc do_panic