KallistiOS git master
Independent SDK for the Sega Dreamcast
Loading...
Searching...
No Matches
syscalls.h
Go to the documentation of this file.
1/* KallistiOS ##version##
2
3 dc/syscalls.h
4 Copyright (C) 2024 Andy Barajas
5*/
6
7/** \file dc/syscalls.h
8 \brief Functions to access the system calls of the Dreamcast ROM.
9 \ingroup system_calls
10
11\todo
12 - syscall_sysinfo_icon(): Discover + document icon format.
13 - Look into additional syscall vector for GD-ROM - 0x0C0000C0
14
15 \author Marcus Comstedt
16 \author Andy Barajas
17*/
18
19/** \defgroup system_calls System Calls
20 \brief API for the Dreamcast's system calls
21 \ingroup system
22
23 This module encapsulates all the system calls available in the Dreamcast
24 BIOS, allowing direct interaction with system hardware
25 components such as the GDROM drive, flash ROM, and bios fonts. These
26 functions are essential for performing low-level operations that are not
27 handled by standard user-space APIs.
28
29 @{
30*/
31
32#ifndef __DC_SYSCALLS_H
33#define __DC_SYSCALLS_H
34
35#include <sys/cdefs.h>
36__BEGIN_DECLS
37
38#include <stdint.h>
39#include <sys/types.h>
40
41/** \brief Inits data needed by sysinfo id/icon
42 \note This is called automatically by KOS during initialization.
43 This function prepares syscall_sysinfo_icon and syscall_sysinfo_id
44 calls for use by copying the relevant data from the system flashrom
45 into 8C000068-8C00007F.
46*/
48
49/** \brief Reads an icon from the flashrom.
50
51 This function reads an icon from the flashrom into a destination
52 buffer.
53
54 \note
55 The format of these icons is not known.
56
57 \param icon The icon number (0-9, 5-9 seems to really
58 be icons).
59 \param dest The destination buffer (704 bytes in size).
60
61 \return Number of bytes read on success, or -1 on
62 failure.
63*/
64int syscall_sysinfo_icon(uint32_t icon, uint8_t *dest);
65
66/** \brief Reads the ID of the Dreamcast.
67
68 This function returns the unique 64-bit ID for the Dreamcast.
69
70 \return The Dreamcast ID.
71*/
72uint64_t syscall_sysinfo_id(void);
73
74/** \brief Gets the romfont address.
75
76 This function returns the address of the ROM font.
77
78 \warning
79 Before attempting to access the font data, you should always call
80 syscall_font_lock() to ensure that you have exclusive access to the
81 G1 BUS the ROM is located on. Call syscall_font_unlock() when you're
82 done accessing the data.
83
84 \note
85 Defined in syscall_font.s
86
87 \return The address of the font.
88*/
89uint8_t *syscall_font_address(void);
90
91/** \brief Locks access to ROM font.
92
93 This function tries to lock a mutex for exclusive access to the ROM
94 font. This is needed because you can't access the BIOS font during
95 G1 DMA.
96
97 \note
98 Defined in syscall_font.s
99
100 \retval 0 On success.
101 \retval -1 On failure.
102
103 \sa syscall_font_unlock()
104*/
106
107/** \brief Unlocks access to ROM font.
108 \ingroup system_calls
109
110 This function releases the mutex locked with syscall_font_lock().
111
112 \note
113 Defined in syscall_font.s
114
115 \sa syscall_font_lock()
116*/
118
119/** \brief Gets info on partition in the flashrom.
120
121 This function fetches the info of a partition in the flashrom.
122
123 \param part The partition number (0-4).
124 \param info The buffer to store info (8 bytes in size).
125
126 \retval 0 On success.
127 \retval -1 On failure.
128*/
129int syscall_flashrom_info(uint32_t part, void *info);
130
131/** \brief Read data from the flashrom.
132
133 This function reads data from an offset into the flashrom to the
134 destination buffer.
135
136 \param pos The read start position into the flashrom.
137 \param dest The destination buffer.
138 \param n The number of bytes to read.
139
140 \return Number of bytes read on success, or -1 on
141 failure.
142
143 \sa syscall_flashrom_write(), syscall_flashrom_delete()
144*/
145int syscall_flashrom_read(uint32_t pos, void *dest, size_t n);
146
147/** \brief Write data to the flashrom.
148
149 This function writes data to an offset into the flashrom from the
150 source buffer.
151
152 \warning
153 It is only possible to overwrite 1's with 0's. 0's can not be written
154 back to 1's so general overwriting is therefore not possible. You
155 would need to delete a whole partition to overwrite it.
156
157 \param pos The start position to write into the flashrom.
158 \param src The source buffer.
159 \param n The number of bytes to write.
160
161 \return Number of bytes written on success, or -1 on
162 failure.
163
164 \sa syscall_flashrom_read(), syscall_flashrom_delete()
165*/
166int syscall_flashrom_write(uint32_t pos, const void *src, size_t n);
167
168/** \brief Delete a partition of the flashrom.
169
170 This function returns a flashrom partition to all 1's, so that it may
171 be rewritten.
172
173 \warning
174 ALL data in the entire partition will be lost.
175
176 \param pos The offset from the start of the flashrom you
177 want to delete.
178
179 \retval 0 On success.
180 \retval -1 On failure.
181
182 \sa syscall_flashrom_read(), syscall_flashrom_write()
183*/
184int syscall_flashrom_delete(uint32_t pos);
185
186/** \brief Initialize the GDROM drive.
187
188 This function initializes the GDROM drive. Should be called before any
189 commands are sent.
190*/
192
193/** \brief Reset the GDROM drive.
194
195 This function resets the GDROM drive.
196*/
198
199/** \brief Checks the GDROM drive status.
200
201 This function retrieves the general condition of the GDROM drive. It
202 populates a provided array with two elements. The first element
203 indicates the current drive status, and the second element identifies
204 the type of disk inserted (if any).
205
206 \param status The pointer to two 32-bit unsigned integers to
207 receive extended status information.
208
209 \return 0 on success, or non-zero on
210 failure.
211*/
212int syscall_gdrom_check_drive(uint32_t status[2]);
213
214/** \brief Send a command to the GDROM command queue.
215
216 This function sends a command to the GDROM queue.
217
218 \note
219 Call syscall_gdrom_exec_server() to run queued commands.
220
221 \param cmd The command code (see CMD_* in \ref dc/cdrom.h).
222 \param params The pointer to parameter block for the command,
223 can be NULL if the command does not take
224 parameters.
225
226 \return The request id (>=1) on success, or 0 on failure.
227
228 \sa syscall_gdrom_check_command(), syscall_gdrom_exec_server()
229*/
230uint32_t syscall_gdrom_send_command(uint32_t cmd, void *params);
231
232/** \brief Check status of queued command for the GDROM.
233
234 This function checks if a queued command has completed.
235
236 \param id The request id (>=1).
237 \param status The pointer to four 32-bit integers to
238 receive status information.
239
240 \retval -1 Request has failed.
241 \retval 0 Request not found.
242 \retval 1 Request is still being processed.
243 \retval 2 Request completed successfully.
244 \retval 3 Stream type command is in progress.
245 \retval 4 GD syscalls are busy.
246
247 \sa syscall_gdrom_send_command(), syscall_gdrom_exec_server()
248*/
249int syscall_gdrom_check_command(uint32_t id, int32_t status[4]);
250
251/** \brief Process queued GDROM commands.
252
253 This function starts processing queued commands. This must be
254 called a few times to process all commands. An example of it in
255 use can be seen in \sa cdrom_exec_cmd_timed() (see hardware/cdrom.c).
256
257 \sa syscall_gdrom_send_command(), syscall_gdrom_check_command()
258*/
260
261/** \brief Abort a queued GDROM command.
262
263 This function tries to abort a previously queued command.
264
265 \param id The request id (>=1) to abort.
266
267 \return 0 on success, or non-zero on
268 failure.
269*/
271
272/** \brief Sets/gets the sector mode for read commands.
273
274 This function sets/gets the sector mode for read commands.
275
276 \param mode The pointer to a struct of four 32 bit integers
277 containing new values, or to receive the old
278 values.
279
280 \retval 0 On success.
281 \retval -1 On failure.
282*/
283int syscall_gdrom_sector_mode(uint32_t mode[4]);
284
285/** \brief Setup GDROM DMA callback.
286
287 This function sets up DMA transfer end callback for
288 \ref CMD_DMAREAD_STREAM_EX (\ref dc/cdrom.h).
289
290 \param callback The function to call upon completion of the DM.
291 \param param The data to pass to the callback function.
292*/
293void syscall_gdrom_dma_callback(uintptr_t callback, void *param);
294
295/** \brief Initiates a GDROM DMA transfer.
296
297 This function initiates a DMA transfer for
298 \ref CMD_DMAREAD_STREAM_EX (\ref dc/cdrom.h).
299
300 \param id The request id (>=1).
301 \param params The pointer to two 32-bit integers. The first
302 element indicates the destination address, and
303 the second element identifies how many bytes to
304 transfer.
305
306 \return 0 on success, or non-zero on
307 failure.
308*/
309int syscall_gdrom_dma_transfer(uint32_t id, const int32_t params[2]);
310
311/** \brief Checks a GDROM DMA transfer.
312
313 This function checks the progress of a DMA transfer for
314 \ref CMD_DMAREAD_STREAM_EX (see \ref dc/cdrom.h).
315
316 \param id The request id (>=1).
317 \param size The pointer to receive the remaining amount of
318 bytes to transfer.
319
320 \retval 0 On success.
321 \retval -1 On failure.
322*/
323int syscall_gdrom_dma_check(uint32_t id, size_t *size);
324
325/** \brief Setup GDROM PIO callback.
326
327 This function sets up PIO transfer end callback for
328 \ref CMD_PIOREAD_STREAM_EX (see \ref dc/cdrom.h).
329
330 \param callback The function to call upon completion of the
331 transfer.
332 \param param The data to pass to the callback function.
333*/
334void syscall_gdrom_pio_callback(uintptr_t callback, void *param);
335
336/** \brief Initiates a GDROM PIO transfer.
337
338 This function initiates a PIO transfer for
339 \ref CMD_PIOREAD_STREAM_EX (see \ref dc/cdrom.h).
340
341 \param id The request id (>=1).
342 \param params The pointer to two 32-bit integers. The first
343 element indicates the destination address, and
344 the second element identifies how many bytes to
345 transfer.
346
347 \return 0 on success, or non-zero on
348 failure.
349*/
350int syscall_gdrom_pio_transfer(uint32_t id, const int32_t params[2]);
351
352/** \brief Checks a GDROM PIO transfer.
353
354 This function checks the progress of a PIO transfer for
355 \ref CMD_PIOREAD_STREAM_EX (see \ref dc/cdrom.h).
356
357 \param id The request id (>=1).
358 \param size The pointer to receive the remaining amount of
359 bytes to transfer.
360
361 \retval 0 On success.
362 \retval -1 On failure.
363*/
364int syscall_gdrom_pio_check(uint32_t id, size_t *size);
365
366/** \brief Initializes all the syscall vectors.
367
368 This function initializes all the syscall vectors to their default values.
369
370 \return 0
371*/
373
374/** \brief Set/Clear a user defined super function.
375
376 This function sets/clears the handler for one of the seven user defined
377 super functions. Setting a handler is only allowed if it not currently set.
378
379 \param super The super function number (1-7).
380 \param handler The pointer to handler function, or NULL to
381 clear.
382
383 \retval 0 On success.
384 \retval -1 On failure.
385*/
386int syscall_misc_setvector(uint32_t super, uintptr_t handler);
387
388/** \brief Resets the Dreamcast.
389
390 This function soft resets the Dreamcast console.
391*/
393
394/** \brief Go to the BIOS menu.
395
396 This function exits the program to the BIOS menu.
397*/
399
400/** \brief Exit to CD menu.
401
402 This function exits the program to the BIOS CD menu.
403*/
405
406/** @} */
407
408__END_DECLS
409
410#endif
411
int syscall_misc_setvector(uint32_t super, uintptr_t handler)
Set/Clear a user defined super function.
int syscall_gdrom_check_drive(uint32_t status[2])
Checks the GDROM drive status.
int syscall_gdrom_pio_transfer(uint32_t id, const int32_t params[2])
Initiates a GDROM PIO transfer.
void syscall_system_bios_menu(void) __noreturn
Go to the BIOS menu.
void syscall_gdrom_dma_callback(uintptr_t callback, void *param)
Setup GDROM DMA callback.
uint8_t * syscall_font_address(void)
Gets the romfont address.
uint64_t syscall_sysinfo_id(void)
Reads the ID of the Dreamcast.
int syscall_gdrom_abort_command(uint32_t id)
Abort a queued GDROM command.
int syscall_gdrom_check_command(uint32_t id, int32_t status[4])
Check status of queued command for the GDROM.
void syscall_sysinfo_init(void)
Inits data needed by sysinfo id/icon.
void syscall_gdrom_pio_callback(uintptr_t callback, void *param)
Setup GDROM PIO callback.
uint32_t syscall_gdrom_send_command(uint32_t cmd, void *params)
Send a command to the GDROM command queue.
int syscall_flashrom_write(uint32_t pos, const void *src, size_t n)
Write data to the flashrom.
int syscall_gdrom_dma_check(uint32_t id, size_t *size)
Checks a GDROM DMA transfer.
void syscall_system_cd_menu(void) __noreturn
Exit to CD menu.
int syscall_misc_init(void)
Initializes all the syscall vectors.
void syscall_gdrom_exec_server(void)
Process queued GDROM commands.
void syscall_system_reset(void) __noreturn
Resets the Dreamcast.
int syscall_flashrom_info(uint32_t part, void *info)
Gets info on partition in the flashrom.
void syscall_gdrom_reset(void)
Reset the GDROM drive.
int syscall_gdrom_dma_transfer(uint32_t id, const int32_t params[2])
Initiates a GDROM DMA transfer.
void syscall_font_unlock(void)
Unlocks access to ROM font.
int syscall_gdrom_pio_check(uint32_t id, size_t *size)
Checks a GDROM PIO transfer.
int syscall_sysinfo_icon(uint32_t icon, uint8_t *dest)
Reads an icon from the flashrom.
void syscall_gdrom_init(void)
Initialize the GDROM drive.
int syscall_flashrom_delete(uint32_t pos)
Delete a partition of the flashrom.
int syscall_gdrom_sector_mode(uint32_t mode[4])
Sets/gets the sector mode for read commands.
int syscall_flashrom_read(uint32_t pos, void *dest, size_t n)
Read data from the flashrom.
int syscall_font_lock(void)
Locks access to ROM font.
#define __noreturn
Identify a function that will never return.
Definition cdefs.h:45