blob: d2b2c79a31ad2058a461c92802b994fbb6d33c91 [file] [log] [blame]
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +02001/*
2 * Copyright (c) 2018, Arm Limited. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <arch.h>
8#include <asm_macros.S>
9
10#if ENABLE_ASSERTIONS
11
12 .globl asm_assert
13
14/* 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.assert_str, "aS"
21assert_msg1:
22 .asciz "ASSERT: File "
23assert_msg2:
24 .asciz " Line "
25
26/* ---------------------------------------------------------------------------
27 * Assertion support in assembly.
28 * The below function helps to support assertions in assembly where we do not
29 * have a C runtime stack. Arguments to the function are :
30 * r0 - File name
31 * r1 - Line no
32 * Clobber list : lr, r0 - r6
33 * ---------------------------------------------------------------------------
34 */
35func asm_assert
36 /*
37 * Only print the output if LOG_LEVEL is higher or equal to
38 * LOG_LEVEL_INFO, which is the default value for builds with DEBUG=1.
39 */
40 /* Stash the parameters already in r0 and r1 */
41 mov r5, r0
42 mov r6, r1
43
44 /* Initialize crash console and verify success */
45 bl plat_crash_console_init
46 cmp r0, #0
47 beq 1f
48
49 /* Print file name */
50 ldr r4, =assert_msg1
51 bl asm_print_str
52 mov r4, r5
53 bl asm_print_str
54
55 /* Print line number string */
56 ldr r4, =assert_msg2
57 bl asm_print_str
58
59 /* Test for maximum supported line number */
60 ldr r4, =~0xffff
61 tst r6, r4
62 bne 1f
63 mov r4, r6
64
65 /* Print line number in decimal */
66 mov r6, #10 /* Divide by 10 after every loop iteration */
67 ldr r5, =MAX_DEC_DIVISOR
68dec_print_loop:
69 udiv r0, r4, r5 /* Quotient */
70 mls r4, r0, r5, r4 /* Remainder */
71 add r0, r0, #ASCII_OFFSET_NUM /* Convert to ASCII */
72 bl plat_crash_console_putc
73 udiv r5, r5, r6 /* Reduce divisor */
74 cmp r5, #0
75 bne dec_print_loop
76
77 bl plat_crash_console_flush
78
791:
80 wfi
81 b 1b
82endfunc asm_assert
83
84/*
85 * This function prints a string from address in r4
86 * Clobber: lr, r0 - r4
87 */
88func asm_print_str
89 mov r3, lr
901:
91 ldrb r0, [r4], #0x1
92 cmp r0, #0
93 beq 2f
94 bl plat_crash_console_putc
95 b 1b
962:
97 bx r3
98endfunc asm_print_str
99
100/*
101 * This function prints a hexadecimal number in r4.
102 * In: r4 = the hexadecimal to print.
103 * Clobber: lr, r0 - r3, r5
104 */
105func asm_print_hex
106 mov r3, lr
107 mov r5, #32 /* No of bits to convert to ascii */
1081:
109 sub r5, r5, #4
110 lsr r0, r4, r5
111 and r0, r0, #0xf
112 cmp r0, #0xa
113 blo 2f
114 /* Add by 0x27 in addition to ASCII_OFFSET_NUM
115 * to get ascii for characters 'a - f'.
116 */
117 add r0, r0, #0x27
1182:
119 add r0, r0, #ASCII_OFFSET_NUM
120 bl plat_crash_console_putc
121 cmp r5, #0
122 bne 1b
123 bx r3
124endfunc asm_print_hex
125
126#endif /* ENABLE_ASSERTIONS */