xref: /aosp_15_r20/external/arm-trusted-firmware/include/arch/aarch64/console_macros.S (revision 54fd6939e177f8ff529b10183254802c76df6d08)
1*54fd6939SJiyong Park/*
2*54fd6939SJiyong Park * Copyright (c) 2017-2019, ARM Limited and Contributors. All rights reserved.
3*54fd6939SJiyong Park *
4*54fd6939SJiyong Park * SPDX-License-Identifier: BSD-3-Clause
5*54fd6939SJiyong Park */
6*54fd6939SJiyong Park#ifndef CONSOLE_MACROS_S
7*54fd6939SJiyong Park#define CONSOLE_MACROS_S
8*54fd6939SJiyong Park
9*54fd6939SJiyong Park#include <drivers/console.h>
10*54fd6939SJiyong Park
11*54fd6939SJiyong Park/*
12*54fd6939SJiyong Park * This macro encapsulates the common setup that has to be done at the end of
13*54fd6939SJiyong Park * a console driver's register function. It will register all of the driver's
14*54fd6939SJiyong Park * callbacks in the console_t structure and initialize the flags field (by
15*54fd6939SJiyong Park * default consoles are enabled for the "boot" and "crash" states, this can be
16*54fd6939SJiyong Park * changed after registration with the console_set_scope() function). It ends
17*54fd6939SJiyong Park * with a tail call that will include return to the caller.
18*54fd6939SJiyong Park * REQUIRES console_t pointer in x0 and a valid return address in x30.
19*54fd6939SJiyong Park */
20*54fd6939SJiyong Park	.macro	finish_console_register _driver, putc=0, getc=0, flush=0
21*54fd6939SJiyong Park	/*
22*54fd6939SJiyong Park	 * If any of the callback is not specified or set as 0, then the
23*54fd6939SJiyong Park	 * corresponding callback entry in console_t is set to 0.
24*54fd6939SJiyong Park	 */
25*54fd6939SJiyong Park	.ifne \putc
26*54fd6939SJiyong Park	  adrp	x1, console_\_driver\()_putc
27*54fd6939SJiyong Park	  add	x1, x1, :lo12:console_\_driver\()_putc
28*54fd6939SJiyong Park	  str	x1, [x0, #CONSOLE_T_PUTC]
29*54fd6939SJiyong Park	.else
30*54fd6939SJiyong Park	  str	xzr, [x0, #CONSOLE_T_PUTC]
31*54fd6939SJiyong Park	.endif
32*54fd6939SJiyong Park
33*54fd6939SJiyong Park	.ifne \getc
34*54fd6939SJiyong Park	  adrp	x1, console_\_driver\()_getc
35*54fd6939SJiyong Park	  add	x1, x1, :lo12:console_\_driver\()_getc
36*54fd6939SJiyong Park	  str	x1, [x0, #CONSOLE_T_GETC]
37*54fd6939SJiyong Park	.else
38*54fd6939SJiyong Park	  str	xzr, [x0, #CONSOLE_T_GETC]
39*54fd6939SJiyong Park	.endif
40*54fd6939SJiyong Park
41*54fd6939SJiyong Park	.ifne \flush
42*54fd6939SJiyong Park	  adrp	x1, console_\_driver\()_flush
43*54fd6939SJiyong Park	  add	x1, x1, :lo12:console_\_driver\()_flush
44*54fd6939SJiyong Park	  str	x1, [x0, #CONSOLE_T_FLUSH]
45*54fd6939SJiyong Park	.else
46*54fd6939SJiyong Park	  str	xzr, [x0, #CONSOLE_T_FLUSH]
47*54fd6939SJiyong Park	.endif
48*54fd6939SJiyong Park
49*54fd6939SJiyong Park	mov	x1, #(CONSOLE_FLAG_BOOT | CONSOLE_FLAG_CRASH)
50*54fd6939SJiyong Park	str	x1, [x0, #CONSOLE_T_FLAGS]
51*54fd6939SJiyong Park	b	console_register
52*54fd6939SJiyong Park	.endm
53*54fd6939SJiyong Park
54*54fd6939SJiyong Park#endif /* CONSOLE_MACROS_S */
55