blob: d966f0d36bbc15159ff48a062e27f047d6027953 [file] [log] [blame]
Dan Handleyc863fa42015-04-01 16:51:20 +01001/*
2 * Copyright (c) 2015, 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_putc
34 .globl console_getc
35
36 /*
37 * The console base is in the data section and not in .bss
38 * even though it is zero-init. In particular, this allows
39 * the console functions to start using this variable before
40 * the runtime memory is initialized for images which do not
41 * need to copy the .data section from ROM to RAM.
42 */
43.section .data.console_base ; .align 3
44 console_base: .quad 0x0
45
46 /* -----------------------------------------------
Juan Castillo7f1f0622014-09-09 09:49:23 +010047 * int console_init(uintptr_t base_addr,
Dan Handleyc863fa42015-04-01 16:51:20 +010048 * unsigned int uart_clk, unsigned int baud_rate)
49 * Function to initialize the console without a
50 * C Runtime to print debug information. It saves
51 * the console base to the data section.
52 * In: x0 - console base address
53 * w1 - Uart clock in Hz
54 * w2 - Baud rate
55 * out: return 1 on success else 0 on error
56 * Clobber list : x1 - x3
57 * -----------------------------------------------
58 */
59func console_init
60 /* Check the input base address */
61 cbz x0, init_fail
62 adrp x3, console_base
63 str x0, [x3, :lo12:console_base]
64 b console_core_init
65init_fail:
66 ret
67endfunc console_init
68
69 /* ---------------------------------------------
70 * int console_putc(int c)
71 * Function to output a character over the
72 * console. It returns the character printed on
73 * success or -1 on error.
74 * In : x0 - character to be printed
75 * Out : return -1 on error else return character.
76 * Clobber list : x1, x2
77 * ---------------------------------------------
78 */
79func console_putc
80 adrp x2, console_base
81 ldr x1, [x2, :lo12:console_base]
82 b console_core_putc
83endfunc console_putc
84
85 /* ---------------------------------------------
86 * int console_getc(void)
87 * Function to get a character from the console.
88 * It returns the character grabbed on success
89 * or -1 on error.
90 * Clobber list : x0, x1
91 * ---------------------------------------------
92 */
93func console_getc
94 adrp x1, console_base
95 ldr x0, [x1, :lo12:console_base]
96 b console_core_getc
97endfunc console_getc