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 Flush any queued output.
72 \retval 0 On success
73 \retval -1 On error (set errno as appropriate)
74 */
75 int (*flush)(void);
76
77 /** \brief Write an entire buffer of data to the console.
78 \param data The buffer to write
79 \param len The length of the buffer
80 \param xlat If non-zero, newline transformations may occur
81 \return Number of characters written on success, or -1 on
82 failure (set errno as appropriate)
83 */
84 int (*write_buffer)(const uint8_t *data, int len, int xlat);
85
86 /** \brief Read an entire buffer of data from the console.
87 \param data The buffer to read into
88 \param len The length of the buffer
89 \return Number of characters read on success, or -1 on
90 failure (set errno as appropriate)
91 */
92 int (*read_buffer)(uint8_t *data, int len);
93
94 /** \brief dbgio handler list handle.
95
96 Contrary to what doxygen might think, this is not a function.
97 */
98 SLIST_ENTRY(dbgio_handler) entry;
100
101/** \cond */
102/* This is defined by the shared code, in case there's no valid handler. */
103extern dbgio_handler_t dbgio_null;
104/** \endcond */
105
106/** \brief Add a new dbgio handler to the list.
107 \ingroup logging
108
109 This function adds a new dbgio handler to the top of the list.
110
111 \retval 0 On success
112 \retval -1 On error
113*/
115
116/** \brief Remove a dbgio handler from the list.
117 \ingroup logging
118
119 This function removes a dbgio handler from the list. If the removed handler
120 was the currently selected dbgio handler, the first valid dbgio interface
121 in the list will then be selected.
122
123 \retval 0 On success
124 \retval -1 On error
125*/
127
128/** \brief Select a new dbgio interface by name.
129 \ingroup logging
130
131 This function manually selects a new dbgio interface by name. This function
132 will allow you to select a device, even if it is not detected.
133
134 \param name The dbgio interface to select
135 \retval 0 On success
136
137 \retval -1 On error
138
139 \par Error Conditions:
140 \em ENODEV - The specified device could not be initialized
141*/
142int dbgio_dev_select(const char *name);
143
144/** \brief Select a valid dbgio interface automatically.
145 \ingroup logging
146
147 This function selects the first detected dbgio interface in the list.
148
149 \retval 0 On success
150
151 \retval -1 On error
152
153 \par Error Conditions:
154 \em ENODEV - No devices could be detected/initialized
155*/
157
158/** \brief Fetch the name of the currently selected dbgio interface.
159 \ingroup logging
160
161 \return The name of the current dbgio interface (or NULL if
162 no device is selected)
163*/
164const char *dbgio_dev_get(void);
165
166/** \brief Initialize the dbgio console.
167 \ingroup logging
168
169 This function is called internally, and shouldn't need to be called by any
170 user programs.
171
172 \retval 0 On success
173
174 \retval -1 On error
175
176 \par Error Conditions:
177 \em ENODEV - No devices could be detected/initialized
178*/
179int dbgio_init(void);
180
181/** \brief Set IRQ usage.
182 \ingroup logging
183
184 The dbgio system defaults to polled usage. Some devices may not support IRQ
185 mode at all.
186
187 \param mode The mode to use
188
189 \retval 0 On success
190 \retval -1 On error (errno should be set as appropriate)
191*/
193
194/** \brief Polled I/O mode.
195 \ingroup logging
196
197 \see dbgio_set_irq_usage()
198*/
199#define DBGIO_MODE_POLLED 0
200
201/** \brief IRQ-based I/O mode.
202 \ingroup logging
203
204 \see dbgio_set_irq_usage()
205*/
206#define DBGIO_MODE_IRQ 1
207
208/** \brief Flush any queued output.
209 \ingroup logging
210
211 \retval 0 On success
212 \retval -1 On error (errno should be set as appropriate)
213*/
214int dbgio_flush(void);
215
216/** \brief Write an entire buffer of data to the console.
217 \ingroup logging
218
219 \param data The buffer to write
220 \param len The length of the buffer
221
222 \return Number of characters written on success, or -1 on
223 failure (errno should be set as appropriate)
224*/
225int dbgio_write_buffer(const uint8_t *data, int len);
226
227/** \brief Read an entire buffer of data from the console.
228 \ingroup logging
229
230 \param data The buffer to read into
231 \param len The length of the buffer
232
233 \return Number of characters read on success, or -1 on
234 failure (errno should be set as appropriate)
235*/
236int dbgio_read_buffer(uint8_t *data, int len);
237
238/** \brief Write an entire buffer of data to the console (potentially with
239 newline transformations).
240 \ingroup logging
241
242 \param data The buffer to write
243 \param len The length of the buffer
244
245 \return Number of characters written on success, or -1 on
246 failure (errno should be set as appropriate)
247*/
248int dbgio_write_buffer_xlat(const uint8_t *data, int len);
249
250/** \brief Write a NUL-terminated string to the console.
251 \ingroup logging
252
253 \param str The string to write
254
255 \return Number of characters written on success, or -1 on
256 failure (errno should be set as appropriate)
257*/
258int dbgio_write_str(const char *str);
259
260/** \brief Disable debug I/O globally.
261 \ingroup logging
262*/
263void dbgio_disable(void);
264
265/** \brief Enable debug I/O globally.
266 \ingroup logging
267*/
268void dbgio_enable(void);
269
270/** \brief Built-in debug I/O printf function.
271 \ingroup logging
272
273 \param fmt A printf() style format string
274 \param ... Format arguments
275
276 \return The number of bytes written, or <0 on error (errno
277 should be set as appropriate)
278*/
279int dbgio_printf(const char *fmt, ...) __printflike(1, 2);
280
281__END_DECLS
282
283#endif /* __KOS_DBGIO_H */
284
int mode
Definition 2ndmix.c:539
static struct @68 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_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 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