semihosting: Add GuestFDConsole
[qemu/rayw.git] / include / semihosting / guestfd.h
bloba7ea1041ea0b6ece93c8071658cb7381675ba15c
1 /*
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
9 */
11 #ifndef SEMIHOSTING_GUESTFD_H
12 #define SEMIHOSTING_GUESTFD_H
14 typedef enum GuestFDType {
15 GuestFDUnused = 0,
16 GuestFDHost,
17 GuestFDGDB,
18 GuestFDStatic,
19 GuestFDConsole,
20 } 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 {
27 GuestFDType type;
28 union {
29 int hostfd;
30 struct {
31 const uint8_t *data;
32 size_t len;
33 size_t off;
34 } staticfile;
36 } GuestFD;
38 /**
39 * alloc_guestfd:
41 * Allocate an unused GuestFD index. The associated guestfd index
42 * will still be GuestFDUnused until it is initialized.
44 int alloc_guestfd(void);
46 /**
47 * dealloc_guestfd:
48 * @guestfd: GuestFD index
50 * Deallocate a GuestFD index. The associated GuestFD structure
51 * will be recycled for a subsequent allocation.
53 void dealloc_guestfd(int guestfd);
55 /**
56 * get_guestfd:
57 * @guestfd: GuestFD index
59 * Return the GuestFD structure associated with an initialized @guestfd,
60 * or NULL if it has not been allocated, or hasn't been initialized.
62 GuestFD *get_guestfd(int guestfd);
64 /**
65 * associate_guestfd:
66 * @guestfd: GuestFD index
67 * @hostfd: host file descriptor
69 * Initialize the GuestFD for @guestfd to GuestFDHost using @hostfd.
71 void associate_guestfd(int guestfd, int hostfd);
73 /**
74 * staticfile_guestfd:
75 * @guestfd: GuestFD index
76 * @data: data to be read
77 * @len: length of @data
79 * Initialize the GuestFD for @guestfd to GuestFDStatic.
80 * The @len bytes at @data will be returned to the guest on reads.
82 void staticfile_guestfd(int guestfd, const uint8_t *data, size_t len);
84 #endif /* SEMIHOSTING_GUESTFD_H */