Home | History | Annotate | Download | only in aarch32
      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 	.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 2
     22 	console_base: .word 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: r0 - console base address
     31 	 *     r1 - Uart clock in Hz
     32 	 *     r2 - Baud rate
     33 	 * out: return 1 on success else 0 on error
     34 	 * Clobber list : r1 - r3
     35 	 * -----------------------------------------------
     36 	 */
     37 func console_init
     38 	/* Check the input base address */
     39 	cmp	r0, #0
     40 	beq	init_fail
     41 	ldr	r3, =console_base
     42 	str	r0, [r3]
     43 	b	console_core_init
     44 init_fail:
     45 	bx	lr
     46 endfunc console_init
     47 
     48 	/* -----------------------------------------------
     49 	 * void console_uninit(void)
     50 	 * Function to finish the use of console driver.
     51 	 * It sets the console_base as NULL so that any
     52 	 * further invocation of `console_putc` or
     53 	 * `console_getc` APIs would return error.
     54 	 * -----------------------------------------------
     55 	 */
     56 func console_uninit
     57 	mov	r0, #0
     58 	ldr	r3, =console_base
     59 	str	r0, [r3]
     60 	bx	lr
     61 endfunc console_uninit
     62 
     63 	/* ---------------------------------------------
     64 	 * int console_putc(int c)
     65 	 * Function to output a character over the
     66 	 * console. It returns the character printed on
     67 	 * success or -1 on error.
     68 	 * In : r0 - character to be printed
     69 	 * Out : return -1 on error else return character.
     70 	 * Clobber list : r1, r2
     71 	 * ---------------------------------------------
     72 	 */
     73 func console_putc
     74 	ldr	r2, =console_base
     75 	ldr	r1, [r2]
     76 	b	console_core_putc
     77 endfunc console_putc
     78 
     79 	/* ---------------------------------------------
     80 	 * int console_getc(void)
     81 	 * Function to get a character from the console.
     82 	 * It returns the character grabbed on success
     83 	 * or -1 on error.
     84 	 * Clobber list : r0, r1
     85 	 * ---------------------------------------------
     86 	 */
     87 func console_getc
     88 	ldr	r1, =console_base
     89 	ldr	r0, [r1]
     90 	b	console_core_getc
     91 endfunc console_getc
     92 
     93 	/* ---------------------------------------------
     94 	 * int console_flush(void)
     95 	 * Function to force a write of all buffered
     96 	 * data that hasn't been output. It returns 0
     97 	 * upon successful completion, otherwise it
     98 	 * returns -1.
     99 	 * Clobber list : r0, r1
    100 	 * ---------------------------------------------
    101 	 */
    102 func console_flush
    103 	ldr	r1, =console_base
    104 	ldr	r0, [r1]
    105 	b	console_core_flush
    106 endfunc console_flush
    107