Dan Handley | c863fa4 | 2015-04-01 16:51:20 +0100 | [diff] [blame] | 1 | /* |
| 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 |
Soby Mathew | ceb6187 | 2015-10-28 10:29:42 +0000 | [diff] [blame] | 33 | .globl console_uninit |
Dan Handley | c863fa4 | 2015-04-01 16:51:20 +0100 | [diff] [blame] | 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 | /* ----------------------------------------------- |
Juan Castillo | 7f1f062 | 2014-09-09 09:49:23 +0100 | [diff] [blame] | 48 | * int console_init(uintptr_t base_addr, |
Dan Handley | c863fa4 | 2015-04-01 16:51:20 +0100 | [diff] [blame] | 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 - x3 |
| 58 | * ----------------------------------------------- |
| 59 | */ |
| 60 | func 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 |
| 66 | init_fail: |
| 67 | ret |
| 68 | endfunc console_init |
| 69 | |
Soby Mathew | ceb6187 | 2015-10-28 10:29:42 +0000 | [diff] [blame] | 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 | */ |
| 78 | func console_uninit |
| 79 | mov x0, #0 |
| 80 | adrp x3, console_base |
| 81 | str x0, [x3, :lo12:console_base] |
| 82 | endfunc console_uninit |
| 83 | |
Dan Handley | c863fa4 | 2015-04-01 16:51:20 +0100 | [diff] [blame] | 84 | /* --------------------------------------------- |
| 85 | * int console_putc(int c) |
| 86 | * Function to output a character over the |
| 87 | * console. It returns the character printed on |
| 88 | * success or -1 on error. |
| 89 | * In : x0 - character to be printed |
| 90 | * Out : return -1 on error else return character. |
| 91 | * Clobber list : x1, x2 |
| 92 | * --------------------------------------------- |
| 93 | */ |
| 94 | func console_putc |
| 95 | adrp x2, console_base |
| 96 | ldr x1, [x2, :lo12:console_base] |
| 97 | b console_core_putc |
| 98 | endfunc console_putc |
| 99 | |
| 100 | /* --------------------------------------------- |
| 101 | * int console_getc(void) |
| 102 | * Function to get a character from the console. |
| 103 | * It returns the character grabbed on success |
| 104 | * or -1 on error. |
| 105 | * Clobber list : x0, x1 |
| 106 | * --------------------------------------------- |
| 107 | */ |
| 108 | func console_getc |
| 109 | adrp x1, console_base |
| 110 | ldr x0, [x1, :lo12:console_base] |
| 111 | b console_core_getc |
| 112 | endfunc console_getc |