blob: 6f85a21f0da035c66011e02fb434fb95b52e4cf2 [file] [log] [blame]
Soby Mathew420cc372016-03-24 16:52:40 +00001/*
Antonio Nino Diaz8377ae42017-02-06 16:03:41 +00002 * Copyright (c) 2016-2017, ARM Limited and Contributors. All rights reserved.
Soby Mathew420cc372016-03-24 16:52:40 +00003 *
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 Mathew420cc372016-03-24 16:52:40 +000037
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 2
46 console_base: .word 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: r0 - console base address
55 * r1 - Uart clock in Hz
56 * r2 - Baud rate
57 * out: return 1 on success else 0 on error
58 * Clobber list : r1 - r3
59 * -----------------------------------------------
60 */
61func console_init
62 /* Check the input base address */
63 cmp r0, #0
64 beq init_fail
65 ldr r3, =console_base
66 str r0, [r3]
67 b console_core_init
68init_fail:
69 bx lr
70endfunc console_init
71
72 /* -----------------------------------------------
73 * void console_uninit(void)
74 * Function to finish the use of console driver.
75 * It sets the console_base as NULL so that any
76 * further invocation of `console_putc` or
77 * `console_getc` APIs would return error.
78 * -----------------------------------------------
79 */
80func console_uninit
81 mov r0, #0
82 ldr r3, =console_base
83 str r0, [r3]
84 bx lr
85endfunc console_uninit
86
87 /* ---------------------------------------------
88 * int console_putc(int c)
89 * Function to output a character over the
90 * console. It returns the character printed on
91 * success or -1 on error.
92 * In : r0 - character to be printed
93 * Out : return -1 on error else return character.
94 * Clobber list : r1, r2
95 * ---------------------------------------------
96 */
97func console_putc
98 ldr r2, =console_base
99 ldr r1, [r2]
100 b console_core_putc
101endfunc console_putc
102
103 /* ---------------------------------------------
104 * int console_getc(void)
105 * Function to get a character from the console.
106 * It returns the character grabbed on success
107 * or -1 on error.
108 * Clobber list : r0, r1
109 * ---------------------------------------------
110 */
111func console_getc
112 ldr r1, =console_base
113 ldr r0, [r1]
114 b console_core_getc
115endfunc console_getc
Antonio Nino Diaz8377ae42017-02-06 16:03:41 +0000116
117 /* ---------------------------------------------
118 * int console_flush(void)
119 * Function to force a write of all buffered
120 * data that hasn't been output. It returns 0
121 * upon successful completion, otherwise it
122 * returns -1.
123 * Clobber list : r0, r1
124 * ---------------------------------------------
125 */
126func console_flush
127 ldr r1, =console_base
128 ldr r0, [r1]
129 b console_core_flush
130endfunc console_flush