[SeaBIOS] [PATCH v3 2/5] pmm: support looking up a given pattern in FSEG

Michael S. Tsirkin mst at redhat.com
Sun Sep 22 15:17:21 CEST 2013


Will be used to find RSDP there.

Signed-off-by: Michael S. Tsirkin <mst at redhat.com>
---
 src/util.h |  2 ++
 src/pmm.c  | 18 ++++++++++++++++++
 2 files changed, 20 insertions(+)

diff --git a/src/util.h b/src/util.h
index 6944cfb..f66e65a 100644
--- a/src/util.h
+++ b/src/util.h
@@ -431,6 +431,8 @@ static inline void free(void *data) {
     pmm_free(data);
 }
 
+void *pmm_find_fseg_pattern(void *pattern, unsigned pattern_size);
+
 // mtrr.c
 void mtrr_setup(void);
 
diff --git a/src/pmm.c b/src/pmm.c
index 8f993fd..86cf86f 100644
--- a/src/pmm.c
+++ b/src/pmm.c
@@ -374,6 +374,24 @@ calcRamSize(void)
     LegacyRamSize = rs >= 1024*1024 ? rs : 1024*1024;
 }
 
+// Find the data block in FSEG matching a given pattern.
+void *pmm_find_fseg_pattern(void *pattern, unsigned pattern_size)
+{
+    struct allocinfo_s *info;
+    hlist_for_each_entry(info, &ZoneFSeg.head, node) {
+        unsigned space = info->dataend - info->data;
+        int off;
+
+        if (space < pattern_size)
+            continue;
+        for (off = 0; off < space - pattern_size; ++off) {
+            if (!memcmp(info->data + off, pattern, pattern_size))
+                return info->data + off;
+        }
+    }
+    return NULL;
+}
+
 // Update pointers after code relocation.
 void
 malloc_init(void)
-- 
MST




More information about the SeaBIOS mailing list