blob: cd6579cfe1222c48a421b3f4ef22eaadc5858e6d [file] [log] [blame]
Soby Mathew7abebe82016-08-08 12:38:52 +01001/*
Antonio Nino Diaz8377ae42017-02-06 16:03:41 +00002 * Copyright (c) 2015-2017, ARM Limited and Contributors. All rights reserved.
Soby Mathew7abebe82016-08-08 12:38:52 +01003 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 *
7 * Redistributions of source code must retain the above copyright notice, this
8 * list of conditions and the following disclaimer.
9 *
10 * Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 *
14 * Neither the name of ARM nor the names of its contributors may be used
15 * to endorse or promote products derived from this software without specific
16 * prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
29 */
30#include <asm_macros.S>
31
32 .globl console_init
33 .globl console_uninit
34 .globl console_putc
35 .globl console_getc
Antonio Nino Diaz8377ae42017-02-06 16:03:41 +000036 .globl console_flush
Soby Mathew7abebe82016-08-08 12:38:52 +010037
38 /*
39 * The console base is in the data section and not in .bss
40 * even though it is zero-init. In particular, this allows
41 * the console functions to start using this variable before
42 * the runtime memory is initialized for images which do not
43 * need to copy the .data section from ROM to RAM.
44 */
45.section .data.console_base ; .align 3
46 console_base: .quad 0x0
47
48 /* -----------------------------------------------
49 * int console_init(uintptr_t base_addr,
50 * unsigned int uart_clk, unsigned int baud_rate)
51 * Function to initialize the console without a
52 * C Runtime to print debug information. It saves
53 * the console base to the data section.
54 * In: x0 - console base address
55 * w1 - Uart clock in Hz
56 * w2 - Baud rate
57 * out: return 1 on success else 0 on error
58 * Clobber list : x1 - x4
59 * -----------------------------------------------
60 */
61func console_init
62 /* Check the input base address */
63 cbz x0, init_fail
64 adrp x3, console_base
65 str x0, [x3, :lo12:console_base]
66 b console_core_init
67init_fail:
68 ret
69endfunc console_init
70
71 /* -----------------------------------------------
72 * void console_uninit(void)
73 * Function to finish the use of console driver.
74 * It sets the console_base as NULL so that any
75 * further invocation of `console_putc` or
76 * `console_getc` APIs would return error.
77 * -----------------------------------------------
78 */
79func console_uninit
80 mov x0, #0
81 adrp x3, console_base
82 str x0, [x3, :lo12:console_base]
83 ret
84endfunc console_uninit
85
86 /* ---------------------------------------------
87 * int console_putc(int c)
88 * Function to output a character over the
89 * console. It returns the character printed on
90 * success or -1 on error.
91 * In : x0 - character to be printed
92 * Out : return -1 on error else return character.
93 * Clobber list : x1, x2
94 * ---------------------------------------------
95 */
96func console_putc
97 adrp x2, console_base
98 ldr x1, [x2, :lo12:console_base]
99 b console_core_putc
100endfunc console_putc
101
102 /* ---------------------------------------------
103 * int console_getc(void)
104 * Function to get a character from the console.
105 * It returns the character grabbed on success
106 * or -1 on error.
107 * Clobber list : x0, x1
108 * ---------------------------------------------
109 */
110func console_getc
111 adrp x1, console_base
112 ldr x0, [x1, :lo12:console_base]
113 b console_core_getc
114endfunc console_getc
Antonio Nino Diaz8377ae42017-02-06 16:03:41 +0000115
116 /* ---------------------------------------------
117 * int console_flush(void)
118 * Function to force a write of all buffered
119 * data that hasn't been output. It returns 0
120 * upon successful completion, otherwise it
121 * returns -1.
122 * Clobber list : x0, x1
123 * ---------------------------------------------
124 */
125func console_flush
126 adrp x1, console_base
127 ldr x0, [x1, :lo12:console_base]
128 b console_core_flush
129endfunc console_flush