xref: /rk3399_ARM-atf/include/arch/aarch32/console_macros.S (revision 09d40e0e08283a249e7dce0e106c07c5141f9b7e)
1f5478dedSAntonio Nino Diaz/*
2f5478dedSAntonio Nino Diaz * Copyright (c) 2018, ARM Limited and Contributors. All rights reserved.
3f5478dedSAntonio Nino Diaz *
4f5478dedSAntonio Nino Diaz * SPDX-License-Identifier: BSD-3-Clause
5f5478dedSAntonio Nino Diaz */
6f5478dedSAntonio Nino Diaz#ifndef CONSOLE_MACROS_S
7f5478dedSAntonio Nino Diaz#define CONSOLE_MACROS_S
8f5478dedSAntonio Nino Diaz
9*09d40e0eSAntonio Nino Diaz#include <drivers/console.h>
10f5478dedSAntonio Nino Diaz
11f5478dedSAntonio Nino Diaz/*
12f5478dedSAntonio Nino Diaz * This macro encapsulates the common setup that has to be done at the end of
13f5478dedSAntonio Nino Diaz * a console driver's register function. It will register all of the driver's
14f5478dedSAntonio Nino Diaz * callbacks in the console_t structure and initialize the flags field (by
15f5478dedSAntonio Nino Diaz * default consoles are enabled for the "boot" and "crash" states, this can be
16f5478dedSAntonio Nino Diaz * changed after registration with the console_set_scope() function). It ends
17f5478dedSAntonio Nino Diaz * with a tail call that will include return to the caller.
18f5478dedSAntonio Nino Diaz * REQUIRES console_t pointer in x0 and a valid return address in x30.
19f5478dedSAntonio Nino Diaz */
20f5478dedSAntonio Nino Diaz/*
21f5478dedSAntonio Nino Diaz * The USE_FINISH_CONSOLE_REG_2 guard is introduced to allow selection between
22f5478dedSAntonio Nino Diaz * the 2 variants of the finish_console_register macro and will be removed
23f5478dedSAntonio Nino Diaz * once the deprecated variant is removed.
24f5478dedSAntonio Nino Diaz */
25f5478dedSAntonio Nino Diaz#ifndef USE_FINISH_CONSOLE_REG_2
26f5478dedSAntonio Nino Diaz#if !ERROR_DEPRECATED
27f5478dedSAntonio Nino Diaz	/* This version of the macro is deprecated. Use the new version */
28f5478dedSAntonio Nino Diaz	.macro	finish_console_register _driver
29f5478dedSAntonio Nino Diaz	/*
30f5478dedSAntonio Nino Diaz	 * Add these weak definitions so we will automatically write a 0 if the
31f5478dedSAntonio Nino Diaz	 * function doesn't exist. I'd rather use .ifdef but that only works if
32f5478dedSAntonio Nino Diaz	 * the function was defined (not just declared .global) above this point
33f5478dedSAntonio Nino Diaz	 * in the file, which we can't guarantee.
34f5478dedSAntonio Nino Diaz	 */
35f5478dedSAntonio Nino Diaz	.weak console_\_driver\()_putc
36f5478dedSAntonio Nino Diaz	.weak console_\_driver\()_getc
37f5478dedSAntonio Nino Diaz	.weak console_\_driver\()_flush
38f5478dedSAntonio Nino Diaz
39f5478dedSAntonio Nino Diaz	/* Don't use adrp on weak funcs! See GNU ld bugzilla issue 22589. */
40f5478dedSAntonio Nino Diaz	ldr	r1, =console_\_driver\()_putc
41f5478dedSAntonio Nino Diaz	str	r1, [r0, #CONSOLE_T_PUTC]
42f5478dedSAntonio Nino Diaz	ldr	r1, =console_\_driver\()_getc
43f5478dedSAntonio Nino Diaz	str	r1, [r0, #CONSOLE_T_GETC]
44f5478dedSAntonio Nino Diaz	ldr	r1, =console_\_driver\()_flush
45f5478dedSAntonio Nino Diaz	str	r1, [r0, #CONSOLE_T_FLUSH]
46f5478dedSAntonio Nino Diaz	mov	r1, #(CONSOLE_FLAG_BOOT | CONSOLE_FLAG_CRASH)
47f5478dedSAntonio Nino Diaz	str	r1, [r0, #CONSOLE_T_FLAGS]
48f5478dedSAntonio Nino Diaz	b	console_register
49f5478dedSAntonio Nino Diaz	.endm
50f5478dedSAntonio Nino Diaz#endif /* ERROR_DEPRECATED */
51f5478dedSAntonio Nino Diaz#else /* USE_FINISH_CONSOLE_REG_2 */
52f5478dedSAntonio Nino Diaz	/* The new version of the macro not using weak references */
53f5478dedSAntonio Nino Diaz	.macro	finish_console_register _driver, putc=0, getc=0, flush=0
54f5478dedSAntonio Nino Diaz	/*
55f5478dedSAntonio Nino Diaz	 * If any of the callback is not specified or set as 0, then the
56f5478dedSAntonio Nino Diaz	 * corresponding callback entry in console_t is set to 0.
57f5478dedSAntonio Nino Diaz	 */
58f5478dedSAntonio Nino Diaz	.ifne \putc
59f5478dedSAntonio Nino Diaz	  ldr	r1, =console_\_driver\()_putc
60f5478dedSAntonio Nino Diaz	.else
61f5478dedSAntonio Nino Diaz	  mov	r1, #0
62f5478dedSAntonio Nino Diaz	.endif
63f5478dedSAntonio Nino Diaz	str	r1, [r0, #CONSOLE_T_PUTC]
64f5478dedSAntonio Nino Diaz
65f5478dedSAntonio Nino Diaz	.ifne \getc
66f5478dedSAntonio Nino Diaz	  ldr	r1, =console_\_driver\()_getc
67f5478dedSAntonio Nino Diaz	.else
68f5478dedSAntonio Nino Diaz	  mov	r1, #0
69f5478dedSAntonio Nino Diaz	.endif
70f5478dedSAntonio Nino Diaz	str	r1, [r0, #CONSOLE_T_GETC]
71f5478dedSAntonio Nino Diaz
72f5478dedSAntonio Nino Diaz	.ifne \flush
73f5478dedSAntonio Nino Diaz	  ldr	r1, =console_\_driver\()_flush
74f5478dedSAntonio Nino Diaz	.else
75f5478dedSAntonio Nino Diaz	  mov	r1, #0
76f5478dedSAntonio Nino Diaz	.endif
77f5478dedSAntonio Nino Diaz	str	r1, [r0, #CONSOLE_T_FLUSH]
78f5478dedSAntonio Nino Diaz
79f5478dedSAntonio Nino Diaz	mov	r1, #(CONSOLE_FLAG_BOOT | CONSOLE_FLAG_CRASH)
80f5478dedSAntonio Nino Diaz	str	r1, [r0, #CONSOLE_T_FLAGS]
81f5478dedSAntonio Nino Diaz	b	console_register
82f5478dedSAntonio Nino Diaz	.endm
83f5478dedSAntonio Nino Diaz#endif /* USE_FINISH_CONSOLE_REG_2 */
84f5478dedSAntonio Nino Diaz#endif /* CONSOLE_MACROS_S */
85