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