From 4b847810bf4eb2308d13e1e99eb11090ce8622b6 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Fri, 22 May 2020 13:34:53 +0200 Subject: Kernel: Simplify scanning BIOS/EBDA and MP parser initialization Add a MappedROM::find_chunk_starting_with() helper since that's a very common usage pattern in clients of this code. Also convert MultiProcessorParser from a persistent singleton object to a temporary object constructed via a failable factory function. --- Kernel/VM/MappedROM.h | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'Kernel/VM') diff --git a/Kernel/VM/MappedROM.h b/Kernel/VM/MappedROM.h index 5eb37f57ce..9be57c2f45 100644 --- a/Kernel/VM/MappedROM.h +++ b/Kernel/VM/MappedROM.h @@ -39,6 +39,15 @@ struct MappedROM { size_t offset { 0 }; PhysicalAddress paddr; + Optional find_chunk_starting_with(StringView prefix, size_t chunk_size) const + { + for (auto* candidate = base(); candidate < end(); candidate += chunk_size) { + if (!__builtin_memcmp(prefix.characters_without_null_termination(), candidate, prefix.length())) + return paddr_of(candidate); + } + return {}; + } + PhysicalAddress paddr_of(const u8* ptr) const { return paddr.offset(ptr - this->base()); } }; -- cgit v1.2.3