2 * Hosted file support for semihosting syscalls.
4 * Copyright (c) 2005, 2007 CodeSourcery.
5 * Copyright (c) 2019 Linaro
6 * Copyright © 2020 by Keith Packard <keithp@keithp.com>
8 * SPDX-License-Identifier: GPL-2.0-or-later
11 #ifndef SEMIHOSTING_GUESTFD_H
12 #define SEMIHOSTING_GUESTFD_H
14 typedef enum GuestFDType
{
23 * Guest file descriptors are integer indexes into an array of
24 * these structures (we will dynamically resize as necessary).
26 typedef struct GuestFD
{
39 * For ARM semihosting, we have a separate structure for routing
40 * data for the console which is outside the guest fd address space.
42 extern GuestFD console_in_gf
;
43 extern GuestFD console_out_gf
;
48 * Allocate an unused GuestFD index. The associated guestfd index
49 * will still be GuestFDUnused until it is initialized.
51 int alloc_guestfd(void);
55 * @guestfd: GuestFD index
57 * Deallocate a GuestFD index. The associated GuestFD structure
58 * will be recycled for a subsequent allocation.
60 void dealloc_guestfd(int guestfd
);
64 * @guestfd: GuestFD index
66 * Return the GuestFD structure associated with an initialized @guestfd,
67 * or NULL if it has not been allocated, or hasn't been initialized.
69 GuestFD
*get_guestfd(int guestfd
);
73 * @guestfd: GuestFD index
74 * @hostfd: host file descriptor
76 * Initialize the GuestFD for @guestfd to GuestFDHost using @hostfd.
78 void associate_guestfd(int guestfd
, int hostfd
);
82 * @guestfd: GuestFD index
83 * @data: data to be read
84 * @len: length of @data
86 * Initialize the GuestFD for @guestfd to GuestFDStatic.
87 * The @len bytes at @data will be returned to the guest on reads.
89 void staticfile_guestfd(int guestfd
, const uint8_t *data
, size_t len
);
91 #endif /* SEMIHOSTING_GUESTFD_H */