Daniel Boulby | ec24928 | 2018-09-19 13:55:47 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2016-2017, ARM Limited and Contributors. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | #include <asm_macros.S> |
| 7 | |
| 8 | /* |
| 9 | * This is the common console core code for the deprecated single-console API. |
| 10 | * New platforms should set MULTI_CONSOLE_API=1 and not use this file. |
| 11 | */ |
| 12 | #warning "Using deprecated console implementation. Please migrate to MULTI_CONSOLE_API" |
| 13 | |
| 14 | .globl console_init |
| 15 | .globl console_uninit |
| 16 | .globl console_putc |
| 17 | .globl console_getc |
| 18 | .globl console_flush |
| 19 | |
| 20 | /* |
| 21 | * The console base is in the data section and not in .bss |
| 22 | * even though it is zero-init. In particular, this allows |
| 23 | * the console functions to start using this variable before |
| 24 | * the runtime memory is initialized for images which do not |
| 25 | * need to copy the .data section from ROM to RAM. |
| 26 | */ |
| 27 | .section .data.console_base ; .align 2 |
| 28 | console_base: .word 0x0 |
| 29 | |
| 30 | /* ----------------------------------------------- |
| 31 | * int console_init(uintptr_t base_addr, |
| 32 | * unsigned int uart_clk, unsigned int baud_rate) |
| 33 | * Function to initialize the console without a |
| 34 | * C Runtime to print debug information. It saves |
| 35 | * the console base to the data section. |
| 36 | * In: r0 - console base address |
| 37 | * r1 - Uart clock in Hz |
| 38 | * r2 - Baud rate |
| 39 | * out: return 1 on success else 0 on error |
| 40 | * Clobber list : r1 - r3 |
| 41 | * ----------------------------------------------- |
| 42 | */ |
| 43 | func console_init |
| 44 | /* Check the input base address */ |
| 45 | cmp r0, #0 |
| 46 | beq init_fail |
| 47 | ldr r3, =console_base |
| 48 | str r0, [r3] |
| 49 | b console_core_init |
| 50 | init_fail: |
| 51 | bx lr |
| 52 | endfunc console_init |
| 53 | |
| 54 | /* ----------------------------------------------- |
| 55 | * void console_uninit(void) |
| 56 | * Function to finish the use of console driver. |
| 57 | * It sets the console_base as NULL so that any |
| 58 | * further invocation of `console_putc` or |
| 59 | * `console_getc` APIs would return error. |
| 60 | * ----------------------------------------------- |
| 61 | */ |
| 62 | func console_uninit |
| 63 | mov r0, #0 |
| 64 | ldr r3, =console_base |
| 65 | str r0, [r3] |
| 66 | bx lr |
| 67 | endfunc console_uninit |
| 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 : r0 - character to be printed |
| 75 | * Out : return -1 on error else return character. |
| 76 | * Clobber list : r1, r2 |
| 77 | * --------------------------------------------- |
| 78 | */ |
| 79 | func console_putc |
| 80 | ldr r2, =console_base |
| 81 | ldr r1, [r2] |
| 82 | b console_core_putc |
| 83 | endfunc 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 : r0, r1 |
| 91 | * --------------------------------------------- |
| 92 | */ |
| 93 | func console_getc |
| 94 | ldr r1, =console_base |
| 95 | ldr r0, [r1] |
| 96 | b console_core_getc |
| 97 | endfunc console_getc |
| 98 | |
| 99 | /* --------------------------------------------- |
| 100 | * int console_flush(void) |
| 101 | * Function to force a write of all buffered |
| 102 | * data that hasn't been output. It returns 0 |
| 103 | * upon successful completion, otherwise it |
| 104 | * returns -1. |
| 105 | * Clobber list : r0, r1 |
| 106 | * --------------------------------------------- |
| 107 | */ |
| 108 | func console_flush |
| 109 | ldr r1, =console_base |
| 110 | ldr r0, [r1] |
| 111 | b console_core_flush |
| 112 | endfunc console_flush |