blob: 77298a12e6aa07247033f4f015dc0b7383c64fb1 [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 *
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 Viswambharanff640c42016-11-28 09:59:27 +000034 .globl asm_assert
Soby Mathewd29f67b2016-05-05 12:31:57 +010035 .globl do_panic
Yatharth Kocharf528faf2016-06-28 16:58:26 +010036 .globl report_exception
Soby Mathewd29f67b2016-05-05 12:31:57 +010037
Jeenu Viswambharanff640c42016-11-28 09:59:27 +000038/* 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"
45panic_msg:
46 .asciz "PANIC at PC : 0x"
47panic_end:
48 .asciz "\r\n"
49
Soby Mathewd29f67b2016-05-05 12:31:57 +010050 /***********************************************************
51 * The common implementation of do_panic for all BL stages
52 ***********************************************************/
53func do_panic
Jeenu Viswambharanff640c42016-11-28 09:59:27 +000054 /* 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 Diazd3ec5432017-02-17 17:11:27 +000073
74 bl plat_crash_console_flush
75
Jeenu Viswambharanff640c42016-11-28 09:59:27 +0000761:
77 mov lr, r6
Antonio Nino Diaze98fa3a2017-02-16 16:49:18 +000078 no_ret plat_panic_handler
Soby Mathewd29f67b2016-05-05 12:31:57 +010079endfunc do_panic
80
Yatharth Kocharf528faf2016-06-28 16:58:26 +010081 /***********************************************************
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 ***********************************************************/
86func report_exception
87 mrs r0, cpsr
88 and r0, #MODE32_MASK
89 bl plat_report_exception
Jeenu Viswambharan68aef102016-11-30 15:21:11 +000090 no_ret plat_panic_handler
Yatharth Kocharf528faf2016-06-28 16:58:26 +010091endfunc report_exception
Jeenu Viswambharanff640c42016-11-28 09:59:27 +000092
93#if ASM_ASSERTION
94.section .rodata.assert_str, "aS"
95assert_msg1:
96 .asciz "ASSERT: File "
97assert_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 */
109func asm_assert
110 /* Stash the parameters already in r0 and r1 */
111 mov r5, r0
112 mov r6, r1
113
114 /* Initialize crash console and verify success */
115 bl plat_crash_console_init
116 cmp r0, #0
117 beq 1f
118
119 /* Print file name */
120 ldr r4, =assert_msg1
121 bl asm_print_str
122 mov r4, r5
123 bl asm_print_str
124
125 /* Print line number string */
126 ldr r4, =assert_msg2
127 bl asm_print_str
128
129 /* Test for maximum supported line number */
130 ldr r4, =~0xffff
131 tst r6, r4
132 bne 1f
133 mov r4, r6
134
135 /* Print line number in decimal */
136 mov r6, #10 /* Divide by 10 after every loop iteration */
137 ldr r5, =MAX_DEC_DIVISOR
138dec_print_loop:
139 udiv r0, r4, r5 /* Quotient */
140 mls r4, r0, r5, r4 /* Remainder */
141 add r0, r0, #ASCII_OFFSET_NUM /* Convert to ASCII */
142 bl plat_crash_console_putc
143 udiv r5, r5, r6 /* Reduce divisor */
144 cmp r5, #0
145 bne dec_print_loop
Antonio Nino Diazd3ec5432017-02-17 17:11:27 +0000146
147 bl plat_crash_console_flush
148
Jeenu Viswambharanff640c42016-11-28 09:59:27 +00001491:
150 no_ret plat_panic_handler
151endfunc asm_assert
152#endif
153
154/*
155 * This function prints a string from address in r4
156 * Clobber: lr, r0 - r4
157 */
158func asm_print_str
159 mov r3, lr
1601:
161 ldrb r0, [r4], #0x1
162 cmp r0, #0
163 beq 2f
164 bl plat_crash_console_putc
165 b 1b
1662:
167 bx r3
168endfunc asm_print_str
169
170/*
171 * This function prints a hexadecimal number in r4.
172 * In: r4 = the hexadecimal to print.
173 * Clobber: lr, r0 - r3, r5
174 */
175func asm_print_hex
176 mov r3, lr
177 mov r5, #32 /* No of bits to convert to ascii */
1781:
179 sub r5, r5, #4
180 lsr r0, r4, r5
181 and r0, r0, #0xf
182 cmp r0, #0xa
183 blo 2f
184 /* Add by 0x27 in addition to ASCII_OFFSET_NUM
185 * to get ascii for characters 'a - f'.
186 */
187 add r0, r0, #0x27
1882:
189 add r0, r0, #ASCII_OFFSET_NUM
190 bl plat_crash_console_putc
191 cmp r5, #0
192 bne 1b
193 bx r3
194endfunc asm_print_hex