skeleton_console.S 5.51 KB
Newer Older
Soby Mathew's avatar
Soby Mathew committed
1
/*
Ambroise Vincent's avatar
Ambroise Vincent committed
2
 * Copyright (c) 2016-2019, ARM Limited and Contributors. All rights reserved.
Soby Mathew's avatar
Soby Mathew committed
3
 *
dp-arm's avatar
dp-arm committed
4
 * SPDX-License-Identifier: BSD-3-Clause
Soby Mathew's avatar
Soby Mathew committed
5
6
 */
#include <asm_macros.S>
Ambroise Vincent's avatar
Ambroise Vincent committed
7
#include <console_macros.S>
Soby Mathew's avatar
Soby Mathew committed
8
9

	/*
Ambroise Vincent's avatar
Ambroise Vincent committed
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
	 * This file contains a skeleton console driver that can be used as a
	 * basis for a real console driver. Console drivers in Trusted Firmware
	 * can be instantiated multiple times. Each instance is described by a
	 * separate console_t structure which must be registered with the common
	 * console framework via console_register(). Console drivers should
	 * define a console_xxx_register() function that initializes a new
	 * console_t structure passed in from the caller and registers it after
	 * initializing the console hardware. Drivers may define their own
	 * structures extending console_t to store private driver information.
	 * Console drivers *MUST* ensure that the console callbacks they
	 * implement only change registers allowed in the clobber lists defined
	 * in this file. (Note that in addition to the explicit clobber lists,
	 * any function may always clobber the intra-procedure-call register
	 * r12, but may never depend on it retaining its value across any
	 * function call.)
Soby Mathew's avatar
Soby Mathew committed
25
26
	 */

Ambroise Vincent's avatar
Ambroise Vincent committed
27
28
29
30
	.globl	console_xxx_register
	.globl	console_xxx_putc
	.globl	console_xxx_getc
	.globl	console_xxx_flush
Soby Mathew's avatar
Soby Mathew committed
31
32

	/* -----------------------------------------------
Ambroise Vincent's avatar
Ambroise Vincent committed
33
34
35
36
37
38
39
40
41
42
43
	 * int console_xxx_register(console_xxx_t *console,
	 * 	...additional parameters as desired...)
	 * Function to initialize and register the console.
	 * The caller needs to pass an empty console_xxx_t
	 * structure in which *MUST* be allocated in
	 * persistent memory (e.g. a global or static local
	 * variable, *NOT* on the stack).
	 * In : r0 - pointer to empty console_t structure
	 *      r1 through r7: additional parameters as desired
	 * Out: r0 - 1 on success, 0 on error
	 * Clobber list : r0 - r7
Soby Mathew's avatar
Soby Mathew committed
44
45
	 * -----------------------------------------------
	 */
Ambroise Vincent's avatar
Ambroise Vincent committed
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
func console_xxx_register
	/*
	 * Store parameters (e.g. hardware base address) in driver-specific
	 * console_xxx_t structure field if they will need to be retrieved
	 * by later console callback (e.g. putc).
	 * Example:
	 */
	str	r1, [r0, #CONSOLE_T_XXX_BASE]
	str	r2, [r0, #CONSOLE_T_XXX_SOME_OTHER_VALUE]

	/*
	 * Initialize console hardware, using r1 - r7 parameters as needed.
	 * Keep console_t pointer in r0 for later.
	 */

	/*
	 * Macro to finish up registration and return (needs valid r0 + lr).
	 * If any of the argument is unspecified, then the corresponding
	 * entry in console_t is set to 0.
	 */
	finish_console_register xxx putc=1, getc=1, flush=1

	/* Jump here if hardware init fails or parameters are invalid. */
register_fail:
Soby Mathew's avatar
Soby Mathew committed
70
71
	mov	r0, #0
	bx	lr
Ambroise Vincent's avatar
Ambroise Vincent committed
72
endfunc console_xxx_register
Soby Mathew's avatar
Soby Mathew committed
73
74

	/* --------------------------------------------------------
Ambroise Vincent's avatar
Ambroise Vincent committed
75
	 * int console_xxx_putc(int c, console_xxx_t *console)
Soby Mathew's avatar
Soby Mathew committed
76
77
78
	 * Function to output a character over the console. It
	 * returns the character printed on success or -1 on error.
	 * In : r0 - character to be printed
Ambroise Vincent's avatar
Ambroise Vincent committed
79
80
81
	 *      r1 - pointer to console_t struct
	 * Out: r0 - printed character on success, < 0 on error.
	 * Clobber list : r0, r1, r2
Soby Mathew's avatar
Soby Mathew committed
82
83
	 * --------------------------------------------------------
	 */
Ambroise Vincent's avatar
Ambroise Vincent committed
84
85
86
87
88
89
90
91
92
93
94
95
func console_xxx_putc
	/*
	 * Retrieve values we need (e.g. hardware base address) from
	 * console_xxx_t structure pointed to by r1.
	 * Example:
	 */
	ldr	r1, [r1, #CONSOLE_T_XXX_BASE]

	/*
	 * Write r0 to hardware.
	 */

Soby Mathew's avatar
Soby Mathew committed
96
	bx	lr
Ambroise Vincent's avatar
Ambroise Vincent committed
97
98

	/* Jump here if output fails for any reason. */
Soby Mathew's avatar
Soby Mathew committed
99
100
101
putc_error:
	mov	r0, #-1
	bx	lr
Ambroise Vincent's avatar
Ambroise Vincent committed
102
endfunc console_xxx_putc
Soby Mathew's avatar
Soby Mathew committed
103
104

	/* ---------------------------------------------
Ambroise Vincent's avatar
Ambroise Vincent committed
105
	 * int console_xxx_getc(console_xxx_t *console)
Soby Mathew's avatar
Soby Mathew committed
106
	 * Function to get a character from the console.
Ambroise Vincent's avatar
Ambroise Vincent committed
107
108
109
110
111
112
113
114
115
116
117
118
	 * Even though console_getc() is blocking, this
	 * callback has to be non-blocking and always
	 * return immediately to allow polling multiple
	 * drivers concurrently.
	 * Returns the character grabbed on success,
	 * ERROR_NO_PENDING_CHAR if no character was
	 * available at this time, or any value
	 * between -2 and -127 if there was an error.
	 * In : r0 - pointer to console_t struct
	 * Out: r0 - character on success,
	 *           ERROR_NO_PENDING_CHAR if no char,
	 *           < -1 on error
Soby Mathew's avatar
Soby Mathew committed
119
120
121
	 * Clobber list : r0, r1
	 * ---------------------------------------------
	 */
Ambroise Vincent's avatar
Ambroise Vincent committed
122
123
124
125
126
127
128
129
130
131
132
133
func console_xxx_getc
	/*
	 * Retrieve values we need (e.g. hardware base address) from
	 * console_xxx_t structure pointed to by r0.
	 * Example:
	 */
	ldr	r1, [r0, #CONSOLE_T_XXX_BASE]

	/*
	 * Try to read character into r0 from hardware.
	 */

Soby Mathew's avatar
Soby Mathew committed
134
	bx	lr
Ambroise Vincent's avatar
Ambroise Vincent committed
135
136
137
138
139
140
141

	/* Jump here if there is no character available at this time. */
getc_no_char:
	mov	r0, #ERROR_NO_PENDING_CHAR
	bx	lr

	/* Jump here if there was any hardware error. */
Soby Mathew's avatar
Soby Mathew committed
142
getc_error:
Ambroise Vincent's avatar
Ambroise Vincent committed
143
	mov	r0, #-2		/* may pick error codes between -2 and -127 */
Soby Mathew's avatar
Soby Mathew committed
144
	bx	lr
Ambroise Vincent's avatar
Ambroise Vincent committed
145
endfunc console_xxx_getc
146
147

	/* ---------------------------------------------
Ambroise Vincent's avatar
Ambroise Vincent committed
148
	 * int console_xxx_flush(console_xxx_t *console)
149
150
	 * Function to force a write of all buffered
	 * data that hasn't been output.
Ambroise Vincent's avatar
Ambroise Vincent committed
151
152
153
	 * In : r0 - pointer to console_xxx_t struct
	 * Out: r0 - 0 on success, < 0 on error
	 * Clobber list : r0, r1, r2, r3, r4, r5
154
155
	 * ---------------------------------------------
	 */
Ambroise Vincent's avatar
Ambroise Vincent committed
156
157
158
159
160
161
162
163
164
165
166
167
168
func console_xxx_flush
	/*
	 * Retrieve values we need (e.g. hardware base address) from
	 * console_xxx_t structure pointed to by r0.
	 * Example:
	 */
	ldr	r1, [r0, #CONSOLE_T_XXX_BASE]

	/*
	 * Flush all remaining output from hardware FIFOs. Do not return until
	 * all data has been flushed or there was an unrecoverable error.
	 */

169
170
	mov	r0, #0
	bx	lr
Ambroise Vincent's avatar
Ambroise Vincent committed
171
172

	/* Jump here if an unrecoverable error has been encountered. */
173
174
175
flush_error:
	mov	r0, #-1
	bx	lr
Ambroise Vincent's avatar
Ambroise Vincent committed
176
endfunc console_xxx_flush