Useful for MXM structures for example: it needs to be in low memory, since the VGA BIOS needs to access it in real mode.
Signed-off-by: Riku Viitanen riku.viitanen@protonmail.com --- src/romfile.c | 30 ++++++++++++++++++++++++++++++ src/romfile.h | 1 + 2 files changed, 31 insertions(+)
diff --git a/src/romfile.c b/src/romfile.c index b598274e..5d80d809 100644 --- a/src/romfile.c +++ b/src/romfile.c @@ -78,6 +78,36 @@ romfile_loadfile(const char *name, int *psize) return data; }
+// Helper function to find, malloc_low, and copy a romfile. +void * +romfile_loadfile_low(const char *name, int *psize) +{ + struct romfile_s *file = romfile_find(name); + if (!file) + return NULL; + + int filesize = file->size; + if (!filesize) + return NULL; + + char *data = malloc_low(filesize); + if (!data) { + warn_noalloc(); + return NULL; + } + + dprintf(5, "Copying romfile '%s' (len %d) to low memory\n", + name, filesize); + int ret = file->copy(file, data, filesize); + if (ret < 0) { + free(data); + return NULL; + } + if (psize) + *psize = filesize; + return data; +} + // Attempt to load an integer from the given file - return 'defval' // if unsuccessful. u64 diff --git a/src/romfile.h b/src/romfile.h index 3e0f8200..70111ac2 100644 --- a/src/romfile.h +++ b/src/romfile.h @@ -14,6 +14,7 @@ void romfile_add(struct romfile_s *file); struct romfile_s *romfile_findprefix(const char *prefix, struct romfile_s *prev); struct romfile_s *romfile_find(const char *name); void *romfile_loadfile(const char *name, int *psize); +void *romfile_loadfile_low(const char *name, int *psize); u64 romfile_loadint(const char *name, u64 defval);
void const_romfile_add_int(char *name, u32 value); -- 2.43.2