1/* 2 * Copyright (c) 2015-2017, ARM Limited and Contributors. All rights reserved. 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6#include <asm_macros.S> 7 8 .globl console_init 9 .globl console_uninit 10 .globl console_putc 11 .globl console_getc 12 .globl console_flush 13 14 /* 15 * The console base is in the data section and not in .bss 16 * even though it is zero-init. In particular, this allows 17 * the console functions to start using this variable before 18 * the runtime memory is initialized for images which do not 19 * need to copy the .data section from ROM to RAM. 20 */ 21.section .data.console_base ; .align 3 22 console_base: .quad 0x0 23 24 /* ----------------------------------------------- 25 * int console_init(uintptr_t base_addr, 26 * unsigned int uart_clk, unsigned int baud_rate) 27 * Function to initialize the console without a 28 * C Runtime to print debug information. It saves 29 * the console base to the data section. 30 * In: x0 - console base address 31 * w1 - Uart clock in Hz 32 * w2 - Baud rate 33 * out: return 1 on success else 0 on error 34 * Clobber list : x1 - x4 35 * ----------------------------------------------- 36 */ 37func console_init 38 /* Check the input base address */ 39 cbz x0, init_fail 40 adrp x3, console_base 41 str x0, [x3, :lo12:console_base] 42 b console_core_init 43init_fail: 44 ret 45endfunc console_init 46 47 /* ----------------------------------------------- 48 * void console_uninit(void) 49 * Function to finish the use of console driver. 50 * It sets the console_base as NULL so that any 51 * further invocation of `console_putc` or 52 * `console_getc` APIs would return error. 53 * ----------------------------------------------- 54 */ 55func console_uninit 56 mov x0, #0 57 adrp x3, console_base 58 str x0, [x3, :lo12:console_base] 59 ret 60endfunc console_uninit 61 62 /* --------------------------------------------- 63 * int console_putc(int c) 64 * Function to output a character over the 65 * console. It returns the character printed on 66 * success or -1 on error. 67 * In : x0 - character to be printed 68 * Out : return -1 on error else return character. 69 * Clobber list : x1, x2 70 * --------------------------------------------- 71 */ 72func console_putc 73 adrp x2, console_base 74 ldr x1, [x2, :lo12:console_base] 75 b console_core_putc 76endfunc console_putc 77 78 /* --------------------------------------------- 79 * int console_getc(void) 80 * Function to get a character from the console. 81 * It returns the character grabbed on success 82 * or -1 on error. 83 * Clobber list : x0, x1 84 * --------------------------------------------- 85 */ 86func console_getc 87 adrp x1, console_base 88 ldr x0, [x1, :lo12:console_base] 89 b console_core_getc 90endfunc console_getc 91 92 /* --------------------------------------------- 93 * int console_flush(void) 94 * Function to force a write of all buffered 95 * data that hasn't been output. It returns 0 96 * upon successful completion, otherwise it 97 * returns -1. 98 * Clobber list : x0, x1 99 * --------------------------------------------- 100 */ 101func console_flush 102 adrp x1, console_base 103 ldr x0, [x1, :lo12:console_base] 104 b console_core_flush 105endfunc console_flush 106