blob: fb6924ea19c75de065faffbfeded7a172ce9bc6b [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
44#if ASM_ASSERTION
45.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
81 mov x5, x0
82 mov x6, x1
83 /* Ensure the console is initialized */
84 bl plat_crash_console_init
85 /* Check if the console is initialized */
86 cbz x0, _assert_loop
87 /* The console is initialized */
88 adr x4, assert_msg1
89 bl asm_print_str
90 mov x4, x5
91 bl asm_print_str
92 adr x4, assert_msg2
93 bl asm_print_str
94 /* Check if line number higher than max permitted */
95 tst x6, #~0xffff
96 b.ne _assert_loop
97 mov x4, x6
98 asm_print_line_dec
Antonio Nino Diazd3ec5432017-02-17 17:11:27 +000099 bl plat_crash_console_flush
Soby Mathew041f62a2014-07-14 16:58:03 +0100100_assert_loop:
Antonio Nino Diaze98fa3a2017-02-16 16:49:18 +0000101 no_ret plat_panic_handler
Kévin Petita877c252015-03-24 14:03:57 +0000102endfunc asm_assert
Soby Mathew041f62a2014-07-14 16:58:03 +0100103#endif
104
105/*
106 * This function prints a string from address in x4.
107 * In: x4 = pointer to string.
108 * Clobber: x30, x0, x1, x2, x3
109 */
110func asm_print_str
111 mov x3, x30
1121:
113 ldrb w0, [x4], #0x1
114 cbz x0, 2f
115 bl plat_crash_console_putc
116 b 1b
1172:
118 ret x3
Kévin Petita877c252015-03-24 14:03:57 +0000119endfunc asm_print_str
Soby Mathew041f62a2014-07-14 16:58:03 +0100120
121/*
122 * This function prints a hexadecimal number in x4.
123 * In: x4 = the hexadecimal to print.
Antonio Nino Diaz1f21bcf2016-02-01 13:57:25 +0000124 * Clobber: x30, x0 - x3, x5
Soby Mathew041f62a2014-07-14 16:58:03 +0100125 */
126func asm_print_hex
127 mov x3, x30
128 mov x5, #64 /* No of bits to convert to ascii */
1291:
130 sub x5, x5, #4
131 lsrv x0, x4, x5
132 and x0, x0, #0xf
133 cmp x0, #0xA
134 b.lo 2f
135 /* Add by 0x27 in addition to ASCII_OFFSET_NUM
136 * to get ascii for characters 'a - f'.
137 */
138 add x0, x0, #0x27
1392:
140 add x0, x0, #ASCII_OFFSET_NUM
141 bl plat_crash_console_putc
142 cbnz x5, 1b
143 ret x3
Kévin Petita877c252015-03-24 14:03:57 +0000144endfunc asm_print_hex
Soby Mathew041f62a2014-07-14 16:58:03 +0100145
Soby Mathewc1adbbc2014-06-25 10:07:40 +0100146 /***********************************************************
147 * The common implementation of do_panic for all BL stages
148 ***********************************************************/
149
150.section .rodata.panic_str, "aS"
151 panic_msg: .asciz "PANIC at PC : 0x"
152
153/* ---------------------------------------------------------------------------
154 * do_panic assumes that it is invoked from a C Runtime Environment ie a
155 * valid stack exists. This call will not return.
156 * Clobber list : if CRASH_REPORTING is not enabled then x30, x0 - x6
157 * ---------------------------------------------------------------------------
158 */
159
160/* This is for the non el3 BL stages to compile through */
161 .weak el3_panic
162
163func do_panic
164#if CRASH_REPORTING
165 str x0, [sp, #-0x10]!
166 mrs x0, currentel
167 ubfx x0, x0, #2, #2
168 cmp x0, #0x3
169 ldr x0, [sp], #0x10
170 b.eq el3_panic
171#endif
172
173panic_common:
174/*
175 * el3_panic will be redefined by the BL31
176 * crash reporting mechanism (if enabled)
177 */
178el3_panic:
179 mov x6, x30
180 bl plat_crash_console_init
181 /* Check if the console is initialized */
Antonio Nino Diaz1f21bcf2016-02-01 13:57:25 +0000182 cbz x0, _panic_handler
Soby Mathewc1adbbc2014-06-25 10:07:40 +0100183 /* The console is initialized */
184 adr x4, panic_msg
185 bl asm_print_str
186 mov x4, x6
187 /* The panic location is lr -4 */
188 sub x4, x4, #4
189 bl asm_print_hex
Soby Mathewc1adbbc2014-06-25 10:07:40 +0100190
Antonio Nino Diazd3ec5432017-02-17 17:11:27 +0000191 bl plat_crash_console_flush
192
Antonio Nino Diaz1f21bcf2016-02-01 13:57:25 +0000193_panic_handler:
194 /* Pass to plat_panic_handler the address from where el3_panic was
195 * called, not the address of the call from el3_panic. */
196 mov x30,x6
Jeenu Viswambharan68aef102016-11-30 15:21:11 +0000197 no_ret plat_panic_handler
Antonio Nino Diaz1f21bcf2016-02-01 13:57:25 +0000198endfunc do_panic