blob: d6ecc4df246d6b309729be4bc8c1bb533c60cd78 [file] [log] [blame]
Julius Werner94f89072017-07-31 18:15:11 -07001/*
Dan Handley6fa89a22018-02-27 16:03:58 +00002 * Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved.
Julius Werner94f89072017-07-31 18:15:11 -07003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6#include <asm_macros.S>
7
8/*
9 * This is the common console core code for the deprecated single-console API.
10 * New platforms should set MULTI_CONSOLE_API=1 and not use this file.
11 */
Dan Handley6fa89a22018-02-27 16:03:58 +000012#warning "Using deprecated console implementation. Please migrate to MULTI_CONSOLE_API"
Julius Werner94f89072017-07-31 18:15:11 -070013
14 .globl console_init
15 .globl console_uninit
16 .globl console_putc
17 .globl console_getc
18 .globl console_flush
19
20 /*
21 * The console base is in the data section and not in .bss
22 * even though it is zero-init. In particular, this allows
23 * the console functions to start using this variable before
24 * the runtime memory is initialized for images which do not
25 * need to copy the .data section from ROM to RAM.
26 */
27.section .data.console_base ; .align 3
28 console_base: .quad 0x0
29
30 /* -----------------------------------------------
31 * int console_init(uintptr_t base_addr,
32 * unsigned int uart_clk, unsigned int baud_rate)
33 * Function to initialize the console without a
34 * C Runtime to print debug information. It saves
35 * the console base to the data section.
36 * In: x0 - console base address
37 * w1 - Uart clock in Hz
38 * w2 - Baud rate
39 * out: return 1 on success else 0 on error
40 * Clobber list : x1 - x4
41 * -----------------------------------------------
42 */
43func console_init
44 /* Check the input base address */
45 cbz x0, init_fail
46 adrp x3, console_base
47 str x0, [x3, :lo12:console_base]
48 b console_core_init
49init_fail:
50 ret
51endfunc console_init
52
53 /* -----------------------------------------------
54 * void console_uninit(void)
55 * Function to finish the use of console driver.
56 * It sets the console_base as NULL so that any
57 * further invocation of `console_putc` or
58 * `console_getc` APIs would return error.
59 * -----------------------------------------------
60 */
61func console_uninit
62 mov x0, #0
63 adrp x3, console_base
64 str x0, [x3, :lo12:console_base]
65 ret
66endfunc console_uninit
67
68 /* ---------------------------------------------
69 * int console_putc(int c)
70 * Function to output a character over the
71 * console. It returns the character printed on
72 * success or -1 on error.
73 * In : x0 - character to be printed
74 * Out : return -1 on error else return character.
75 * Clobber list : x1, x2
76 * ---------------------------------------------
77 */
78func console_putc
79 adrp x2, console_base
80 ldr x1, [x2, :lo12:console_base]
81 b console_core_putc
82endfunc console_putc
83
84 /* ---------------------------------------------
85 * int console_getc(void)
86 * Function to get a character from the console.
87 * It returns the character grabbed on success
88 * or -1 on error.
89 * Clobber list : x0, x1
90 * ---------------------------------------------
91 */
92func console_getc
93 adrp x1, console_base
94 ldr x0, [x1, :lo12:console_base]
95 b console_core_getc
96endfunc console_getc
97
98 /* ---------------------------------------------
99 * int console_flush(void)
100 * Function to force a write of all buffered
101 * data that hasn't been output. It returns 0
102 * upon successful completion, otherwise it
103 * returns -1.
104 * Clobber list : x0, x1
105 * ---------------------------------------------
106 */
107func console_flush
108 adrp x1, console_base
109 ldr x0, [x1, :lo12:console_base]
110 b console_core_flush
111endfunc console_flush