mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-02 07:13:54 -06:00
semihosting: Split out guestfd.c
In arm-compat-semi.c, we have more advanced treatment of guest file descriptors than we do in other implementations. Split out GuestFD and related functions to a new file so that they can be shared. Reviewed-by: Alex Bennée <alex.bennee@linaro.org> Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
This commit is contained in:
parent
3d5e2b4f26
commit
1c6ff7205b
10 changed files with 233 additions and 142 deletions
83
include/semihosting/guestfd.h
Normal file
83
include/semihosting/guestfd.h
Normal file
|
@ -0,0 +1,83 @@
|
|||
/*
|
||||
* Hosted file support for semihosting syscalls.
|
||||
*
|
||||
* Copyright (c) 2005, 2007 CodeSourcery.
|
||||
* Copyright (c) 2019 Linaro
|
||||
* Copyright © 2020 by Keith Packard <keithp@keithp.com>
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0-or-later
|
||||
*/
|
||||
|
||||
#ifndef SEMIHOSTING_GUESTFD_H
|
||||
#define SEMIHOSTING_GUESTFD_H
|
||||
|
||||
typedef enum GuestFDType {
|
||||
GuestFDUnused = 0,
|
||||
GuestFDHost = 1,
|
||||
GuestFDGDB = 2,
|
||||
GuestFDStatic = 3,
|
||||
} GuestFDType;
|
||||
|
||||
/*
|
||||
* Guest file descriptors are integer indexes into an array of
|
||||
* these structures (we will dynamically resize as necessary).
|
||||
*/
|
||||
typedef struct GuestFD {
|
||||
GuestFDType type;
|
||||
union {
|
||||
int hostfd;
|
||||
struct {
|
||||
const uint8_t *data;
|
||||
size_t len;
|
||||
size_t off;
|
||||
} staticfile;
|
||||
};
|
||||
} GuestFD;
|
||||
|
||||
/**
|
||||
* alloc_guestfd:
|
||||
*
|
||||
* Allocate an unused GuestFD index. The associated guestfd index
|
||||
* will still be GuestFDUnused until it is initialized.
|
||||
*/
|
||||
int alloc_guestfd(void);
|
||||
|
||||
/**
|
||||
* dealloc_guestfd:
|
||||
* @guestfd: GuestFD index
|
||||
*
|
||||
* Deallocate a GuestFD index. The associated GuestFD structure
|
||||
* will be recycled for a subsequent allocation.
|
||||
*/
|
||||
void dealloc_guestfd(int guestfd);
|
||||
|
||||
/**
|
||||
* get_guestfd:
|
||||
* @guestfd: GuestFD index
|
||||
*
|
||||
* Return the GuestFD structure associated with an initialized @guestfd,
|
||||
* or NULL if it has not been allocated, or hasn't been initialized.
|
||||
*/
|
||||
GuestFD *get_guestfd(int guestfd);
|
||||
|
||||
/**
|
||||
* associate_guestfd:
|
||||
* @guestfd: GuestFD index
|
||||
* @hostfd: host file descriptor
|
||||
*
|
||||
* Initialize the GuestFD for @guestfd to GuestFDHost using @hostfd.
|
||||
*/
|
||||
void associate_guestfd(int guestfd, int hostfd);
|
||||
|
||||
/**
|
||||
* staticfile_guestfd:
|
||||
* @guestfd: GuestFD index
|
||||
* @data: data to be read
|
||||
* @len: length of @data
|
||||
*
|
||||
* Initialize the GuestFD for @guestfd to GuestFDStatic.
|
||||
* The @len bytes at @data will be returned to the guest on reads.
|
||||
*/
|
||||
void staticfile_guestfd(int guestfd, const uint8_t *data, size_t len);
|
||||
|
||||
#endif /* SEMIHOSTING_GUESTFD_H */
|
Loading…
Add table
Add a link
Reference in a new issue