]> xenbits.xensource.com Git - people/andrewcoop/seabios.git/commitdiff
Add "romfile" code to assist with extract integer config settings.
authorKevin O'Connor <kevin@koconnor.net>
Wed, 6 Jul 2011 00:32:44 +0000 (20:32 -0400)
committerKevin O'Connor <kevin@koconnor.net>
Wed, 6 Jul 2011 00:32:44 +0000 (20:32 -0400)
Add romfile_loadint() function which can be used to extract a
little-endian binary encoded integer from rom.

src/paravirt.c
src/paravirt.h

index 09e3d23b73ebd0c35da24b9c9934eb36522e911b..9cf77def2892eb51ade6e445a7edb1706603631e 100644 (file)
@@ -409,3 +409,22 @@ romfile_loadfile(const char *name, int *psize)
     data[filesize] = '\0';
     return data;
 }
+
+// Attempt to load an integer from the given file - return 'defval'
+// if unsuccesful.
+u64
+romfile_loadint(const char *name, u64 defval)
+{
+    u32 file = romfile_find(name);
+    if (!file)
+        return defval;
+
+    int filesize = romfile_size(file);
+    if (!filesize || filesize > sizeof(u64) || (filesize & (filesize-1)))
+        // Doesn't look like a valid integer.
+        return defval;
+
+    u64 val = 0;
+    romfile_copy(file, &val, sizeof(val));
+    return val;
+}
index 7bf34b1465b344c19fd3f9ca8c18fc263f503621..83166f498a75c61027497104d76af2338589d3b3 100644 (file)
@@ -101,6 +101,7 @@ static inline const char* romfile_name(u32 fileid) {
     return qemu_cfg_name_file(fileid);
 }
 void *romfile_loadfile(const char *name, int *psize);
+u64 romfile_loadint(const char *name, u64 defval);
 
 u32 qemu_cfg_e820_entries(void);
 void* qemu_cfg_e820_load_next(void *addr);