diff options
author | Andreas Kling <kling@serenityos.org> | 2020-05-22 13:34:53 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-05-22 13:36:57 +0200 |
commit | 4b847810bf4eb2308d13e1e99eb11090ce8622b6 (patch) | |
tree | 7f6fb9ac3ec62bf3958a4dbfebd9ce520e470a50 /Kernel/VM | |
parent | 84b7bc5e14bcdaef0721143f8d99b40fde7e7c5e (diff) | |
download | serenity-4b847810bf4eb2308d13e1e99eb11090ce8622b6.zip |
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.
Diffstat (limited to 'Kernel/VM')
-rw-r--r-- | Kernel/VM/MappedROM.h | 9 |
1 files changed, 9 insertions, 0 deletions
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<PhysicalAddress> 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()); } }; |