Soby Mathew | 420cc37 | 2016-03-24 16:52:40 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 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 2 |
| 45 | console_base: .word 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: r0 - console base address |
| 54 | * r1 - Uart clock in Hz |
| 55 | * r2 - Baud rate |
| 56 | * out: return 1 on success else 0 on error |
| 57 | * Clobber list : r1 - r3 |
| 58 | * ----------------------------------------------- |
| 59 | */ |
| 60 | func console_init |
| 61 | /* Check the input base address */ |
| 62 | cmp r0, #0 |
| 63 | beq init_fail |
| 64 | ldr r3, =console_base |
| 65 | str r0, [r3] |
| 66 | b console_core_init |
| 67 | init_fail: |
| 68 | bx lr |
| 69 | endfunc 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 | */ |
| 79 | func console_uninit |
| 80 | mov r0, #0 |
| 81 | ldr r3, =console_base |
| 82 | str r0, [r3] |
| 83 | bx lr |
| 84 | endfunc 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 : r0 - character to be printed |
| 92 | * Out : return -1 on error else return character. |
| 93 | * Clobber list : r1, r2 |
| 94 | * --------------------------------------------- |
| 95 | */ |
| 96 | func console_putc |
| 97 | ldr r2, =console_base |
| 98 | ldr r1, [r2] |
| 99 | b console_core_putc |
| 100 | endfunc 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 : r0, r1 |
| 108 | * --------------------------------------------- |
| 109 | */ |
| 110 | func console_getc |
| 111 | ldr r1, =console_base |
| 112 | ldr r0, [r1] |
| 113 | b console_core_getc |
| 114 | endfunc console_getc |