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