Implement standard file operation with QEMU
Hi all,
I am trying to implment standard file operation (stdio) with QEMU for DSP architecture. The manufacture (TI) provides a runtime library that support posix standard IO, but it left the device level implmentation as hook function calls, like in the library source , it contains add_device() function, and write(),read(),open() are not implemented:
int add_device(char *name,
unsigned flags, int (*dopen) (const char *path, unsigned flags, int foo), int (*dclose) (int fno), int (*dread) (int fno, char *buf, unsigned count), int (*dwrite) (int fno, const char *buf, unsigned count), fpos_t (*dlseek) (int fno, fpos_t offset, int origin), int (*dunlink)(const char *path), int (*drename)(const char *old_name, const char *new_name)) {
_DEVICE *dt;
strncpy(dt->name,name,8);
dt->name[8] = '\0';
dt->flags = flags;
dt->OPEN = dopen;
dt->CLOSE = dclose;
dt->READ = dread;
dt->WRITE = dwrite;
dt->LSEEK = dlseek;
dt->UNLINK = dunlink;
dt->RENAME = drename;
}
int write(int fildes, const char *bufptr, unsigned cnt) {
/*------------------------------------------------------------------------*/ /* CALL FUNCTION FROM DEVICE TABLE TO PERFORM WRITE FOR THIS DEVICE/FILE */ /*------------------------------------------------------------------------*/ return (*(_stream[fildes]->WRITE)) (fildes,bufptr,cnt);
}
Then, how can we use this runtime library together with QEMu to implement full-stack file oerations? I really appreaciate any advice.
Thanks.
regards,
xiaolei
Hi Xiaolei,
+Laurent (user-mode)
+Alex (semihosting)
+Marc-André (chardev)
Quoted 47 lines · casmac
Hi all,
I am trying to implment standard file operation (stdio) with QEMU for DSP architecture. The manufacture (TI) provides a runtime library that support posix standard IO, but it left the device level implmentation as hook function calls, like in the library source , it containsadd_device()function, and write(),read(),open() are not implemented:int add_device(char *name,
unsigned flags,
int (*dopen) (const char *path, unsigned flags, int foo),
int (*dclose) (int fno),
int (*dread) (int fno, char *buf, unsigned count), int (*dwrite) (int fno, const char *buf, unsigned count),
fpos_t (*dlseek) (int fno,fpos_toffset, int origin), int (*dunlink)(const char *path),
int (*drename)(const char*old_name, const char*new_name))
{
_DEVICE*dt;
strncpy(dt->name,name,8);
dt->name[8] = '\0';
dt->flags= flags;
dt->OPEN = dopen;
dt->CLOSE= dclose;
dt->READ = dread;
dt->WRITE= dwrite;
dt->LSEEK= dlseek;
dt->UNLINK = dunlink;
dt->RENAME = drename;
}int write(int fildes,
const char *bufptr,
unsigned cnt)
{
/*------------------------------------------------------------------------*/ /* CALL FUNCTION FROM DEVICE TABLE TO PERFORM WRITE FOR THIS DEVICE/FILE */
/*------------------------------------------------------------------------*/ return (*(_stream[fildes]->WRITE)) (fildes,bufptr,cnt);
}
Quoted 2 lines
Then, how can we use this runtime library together with QEMu to implement full-stack file oerations? I really appreaciate any advice.
Trying to understand...
Are you trying to ask "how to implement semihosting for my qemu-user-tidsp fork"?
Have a look at "hw/semihosting/console.h" and the implementation (so far only ARM) of qemu_semihosting_console_[in/out]. This might help to plug read/write. Using other stream than stdin/stdout is not supported (but you can add support) so open/lseek/close/rename/unlink are not considered.
(for QEMU 'console' is the stdin/stdout subset of stdio).
You can redirect semihosted files with any host chardev, this is done in qemu_semihosting_connect_chardevs().
You might also have a look at the functions declared in "hw/semihosting/semihost.h" and how the different TCG helpers use them.
Regards,
Phil.