KallistiOS git master
Independent SDK for the Sega Dreamcast
Loading...
Searching...
No Matches
dbgio.h
Go to the documentation of this file.
1/* KallistiOS ##version##
2
3 kos/include/dbgio.h
4 Copyright (C) 2000, 2004 Megan Potter
5 Copyright (C) 2026 Eric Fradella
6
7*/
8
9/** \file kos/dbgio.h
10 \brief Debug I/O.
11 \ingroup logging
12
13 This file contains the Debug I/O system, which abstracts things so that
14 various types of debugging tools can be used by programs in KOS. Included
15 among these tools is the dcload console (dcload-serial, dcload-ip, and
16 fs_dclsocket), a raw serial console, and a framebuffer based console.
17
18 \author Megan Potter
19*/
20
21#ifndef __KOS_DBGIO_H
22#define __KOS_DBGIO_H
23
24#include <kos/cdefs.h>
25__BEGIN_DECLS
26
27#include <stdint.h>
28#include <sys/queue.h>
29
30/** \brief Debug I/O Interface.
31 \ingroup logging
32
33 This struct represents a single dbgio interface. This should represent
34 a generic pollable console interface. We store an ordered, singly-linked
35 list of these and fall back from one to the next until one returns true
36 for detected(). Users may create and add their own dbgio interfaces using
37 the dbgio_add_handler() function. Note that the last device in this chain
38 is the null console, which will always return true.
39
40 \headerfile kos/dbgio.h
41*/
42typedef struct dbgio_handler {
43 /** \brief Name of the dbgio handler */
44 const char *name;
45
46 /** \brief Detect this debug interface.
47 \retval 1 If the device is available and usable
48 \retval 0 If the device is unavailable
49 */
50 int (*detected)(void);
51
52 /** \brief Initialize this debug interface with default parameters.
53 \retval 0 On success
54 \retval -1 On failure
55 */
56 int (*init)(void);
57
58 /** \brief Shutdown this debug interface.
59 \retval 0 On success
60 \retval -1 On failure
61 */
62 int (*shutdown)(void);
63
64 /** \brief Set either polled or IRQ usage for this interface.
65 \param mode 1 for IRQ-based usage, 0 for polled I/O
66 \retval 0 On success
67 \retval -1 On failure
68 */
69 int (*set_irq_usage)(int mode);
70
71 /** \brief Read one character from the console.
72 \retval 0 On success
73 \retval -1 On failure (set errno as appropriate)
74 */
75 int (*read)(void);
76
77 /** \brief Write one character to the console.
78 \param c The character to write
79 \retval 1 On success
80 \retval -1 On error (set errno as appropriate)
81 \note Interfaces may require a call to flush() before the
82 output is actually flushed to the console.
83 */
84 int (*write)(int c);
85
86 /** \brief Flush any queued output.
87 \retval 0 On success
88 \retval -1 On error (set errno as appropriate)
89 */
90 int (*flush)(void);
91
92 /** \brief Write an entire buffer of data to the console.
93 \param data The buffer to write
94 \param len The length of the buffer
95 \param xlat If non-zero, newline transformations may occur
96 \return Number of characters written on success, or -1 on
97 failure (set errno as appropriate)
98 */
99 int (*write_buffer)(const uint8_t *data, int len, int xlat);
100
101 /** \brief Read an entire buffer of data from the console.
102 \param data The buffer to read into
103 \param len The length of the buffer
104 \return Number of characters read on success, or -1 on
105 failure (set errno as appropriate)
106 */
107 int (*read_buffer)(uint8_t *data, int len);
108
109 /** \brief dbgio handler list handle.
110
111 Contrary to what doxygen might think, this is not a function.
112 */
113 SLIST_ENTRY(dbgio_handler) entry;
115
116/** \cond */
117/* This is defined by the shared code, in case there's no valid handler. */
118extern dbgio_handler_t dbgio_null;
119/** \endcond */
120
121/** \brief Add a new dbgio handler to the list.
122 \ingroup logging
123
124 This function adds a new dbgio handler to the top of the list.
125
126 \retval 0 On success
127 \retval -1 On error
128*/
130
131/** \brief Remove a dbgio handler from the list.
132 \ingroup logging
133
134 This function removes a dbgio handler from the list. If the removed handler
135 was the currently selected dbgio handler, the first valid dbgio interface
136 in the list will then be selected.
137
138 \retval 0 On success
139 \retval -1 On error
140*/
142
143/** \brief Select a new dbgio interface by name.
144 \ingroup logging
145
146 This function manually selects a new dbgio interface by name. This function
147 will allow you to select a device, even if it is not detected.
148
149 \param name The dbgio interface to select
150 \retval 0 On success
151
152 \retval -1 On error
153
154 \par Error Conditions:
155 \em ENODEV - The specified device could not be initialized
156*/
157int dbgio_dev_select(const char *name);
158
159/** \brief Select a valid dbgio interface automatically.
160 \ingroup logging
161
162 This function selects the first detected dbgio interface in the list.
163
164 \retval 0 On success
165
166 \retval -1 On error
167
168 \par Error Conditions:
169 \em ENODEV - No devices could be detected/initialized
170*/
172
173/** \brief Fetch the name of the currently selected dbgio interface.
174 \ingroup logging
175
176 \return The name of the current dbgio interface (or NULL if
177 no device is selected)
178*/
179const char *dbgio_dev_get(void);
180
181/** \brief Initialize the dbgio console.
182 \ingroup logging
183
184 This function is called internally, and shouldn't need to be called by any
185 user programs.
186
187 \retval 0 On success
188
189 \retval -1 On error
190
191 \par Error Conditions:
192 \em ENODEV - No devices could be detected/initialized
193*/
194int dbgio_init(void);
195
196/** \brief Set IRQ usage.
197 \ingroup logging
198
199 The dbgio system defaults to polled usage. Some devices may not support IRQ
200 mode at all.
201
202 \param mode The mode to use
203
204 \retval 0 On success
205 \retval -1 On error (errno should be set as appropriate)
206*/
208
209/** \brief Polled I/O mode.
210 \ingroup logging
211
212 \see dbgio_set_irq_usage()
213*/
214#define DBGIO_MODE_POLLED 0
215
216/** \brief IRQ-based I/O mode.
217 \ingroup logging
218
219 \see dbgio_set_irq_usage()
220*/
221#define DBGIO_MODE_IRQ 1
222
223/** \brief Read one character from the console.
224 \ingroup logging
225
226 \retval 0 On success
227 \retval -1 On error (errno should be set as appropriate)
228*/
229int dbgio_read(void);
230
231/** \brief Write one character to the console.
232 \ingroup logging
233
234 \note Interfaces may require a call to flush() before the
235 output is actually flushed to the console.
236
237 \param c The character to write
238
239 \retval 1 On success (number of characters written)
240 \retval -1 On error (errno should be set as appropriate)
241*/
242int dbgio_write(int c);
243
244/** \brief Flush any queued output.
245 \ingroup logging
246
247 \retval 0 On success
248 \retval -1 On error (errno should be set as appropriate)
249*/
250int dbgio_flush(void);
251
252/** \brief Write an entire buffer of data to the console.
253 \ingroup logging
254
255 \param data The buffer to write
256 \param len The length of the buffer
257
258 \return Number of characters written on success, or -1 on
259 failure (errno should be set as appropriate)
260*/
261int dbgio_write_buffer(const uint8_t *data, int len);
262
263/** \brief Read an entire buffer of data from the console.
264 \ingroup logging
265
266 \param data The buffer to read into
267 \param len The length of the buffer
268
269 \return Number of characters read on success, or -1 on
270 failure (errno should be set as appropriate)
271*/
272int dbgio_read_buffer(uint8_t *data, int len);
273
274/** \brief Write an entire buffer of data to the console (potentially with
275 newline transformations).
276 \ingroup logging
277
278 \param data The buffer to write
279 \param len The length of the buffer
280
281 \return Number of characters written on success, or -1 on
282 failure (errno should be set as appropriate)
283*/
284int dbgio_write_buffer_xlat(const uint8_t *data, int len);
285
286/** \brief Write a NUL-terminated string to the console.
287 \ingroup logging
288
289 \param str The string to write
290
291 \return Number of characters written on success, or -1 on
292 failure (errno should be set as appropriate)
293*/
294int dbgio_write_str(const char *str);
295
296/** \brief Disable debug I/O globally.
297 \ingroup logging
298*/
299void dbgio_disable(void);
300
301/** \brief Enable debug I/O globally.
302 \ingroup logging
303*/
304void dbgio_enable(void);
305
306/** \brief Built-in debug I/O printf function.
307 \ingroup logging
308
309 \param fmt A printf() style format string
310 \param ... Format arguments
311
312 \return The number of bytes written, or <0 on error (errno
313 should be set as appropriate)
314*/
315int dbgio_printf(const char *fmt, ...) __printflike(1, 2);
316
317__END_DECLS
318
319#endif /* __KOS_DBGIO_H */
320
int mode
Definition 2ndmix.c:539
static struct @69 data[BARRIER_COUNT]
Various common macros used throughout the codebase.
int dbgio_read_buffer(uint8_t *data, int len)
Read an entire buffer of data from the console.
int dbgio_set_irq_usage(int mode)
Set IRQ usage.
int dbgio_init(void)
Initialize the dbgio console.
int dbgio_add_handler(dbgio_handler_t *handler)
Add a new dbgio handler to the list.
int dbgio_printf(const char *fmt,...) __printflike(1
Built-in debug I/O printf function.
void dbgio_enable(void)
Enable debug I/O globally.
const char * dbgio_dev_get(void)
Fetch the name of the currently selected dbgio interface.
void dbgio_disable(void)
Disable debug I/O globally.
int dbgio_dev_select_auto(void)
Select a valid dbgio interface automatically.
int dbgio_read(void)
Read one character from the console.
int dbgio_write_str(const char *str)
Write a NUL-terminated string to the console.
int dbgio_dev_select(const char *name)
Select a new dbgio interface by name.
int dbgio_write_buffer_xlat(const uint8_t *data, int len)
Write an entire buffer of data to the console (potentially with newline transformations).
int dbgio_write_buffer(const uint8_t *data, int len)
Write an entire buffer of data to the console.
int dbgio_flush(void)
Flush any queued output.
int dbgio_remove_handler(dbgio_handler_t *handler)
Remove a dbgio handler from the list.
int dbgio_write(int c)
Write one character to the console.
int shutdown(int socket, int how)
Shutdown socket send and receive operations.
Debug I/O Interface.
Definition dbgio.h:42
SLIST_ENTRY(dbgio_handler) entry
dbgio handler list handle.
const char * name
Name of the dbgio handler.
Definition dbgio.h:44