diff options
| author | Alexey Gavrilov <90127298+rebovas@users.noreply.github.com> | 2024-03-25 11:31:02 +0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-03-25 11:31:02 +0700 |
| commit | 91b4d8fa6bed598e2969f16a7a953e293a1b7f89 (patch) | |
| tree | 86bdf89403027760ce567927ec0f1af14d0e4a79 /include | |
| parent | 1abc315e02a33cd62194b93898263eefd46cbfab (diff) | |
| parent | bbac386769210a8ecccba5826cfaf75d431cc2af (diff) | |
Merge pull request #4 from rebovas/acpi_classes
Implementation ACPI tables through classes
Diffstat (limited to 'include')
| -rw-r--r-- | include/StringOperations.cpp | 67 | ||||
| -rw-r--r-- | include/StringOperations.h | 31 | ||||
| -rw-r--r-- | include/types.h | 6 |
3 files changed, 104 insertions, 0 deletions
diff --git a/include/StringOperations.cpp b/include/StringOperations.cpp new file mode 100644 index 0000000..01e7a76 --- /dev/null +++ b/include/StringOperations.cpp @@ -0,0 +1,67 @@ +#include "StringOperations.h" + + +MemArea::MemArea() +{ + start = final = NULL; +}; + +MemArea::MemArea(const memAddr start, const memAddr final) +{ + this->start = start; + this->final = final; + + if(!valid()) + { + *this = MemArea(); + } +}; + +memAddr MemArea::begin() +{ + return start; +} + +memAddr MemArea::end() +{ + if(start == final) return start; + else return final + 1; +}; + +bool MemArea::valid() +{ + if(start > final + or start == NULL + or final == NULL) return false; + else return true; +}; + +uint32 StringOperations::sequenceSize(const char *chars) +{ + uint32 indx = 0; + while(chars[indx++]){} + + return --indx; +}; + +void *StringOperations::findInMemory(const char *sequence, MemArea memory) +{ + if(sequence == nullptr or !memory.valid()) return NULL; + + uint32 seqIndx = 0; + for(MemArea::iterator it = memory.begin(); it != memory.end(); it++) + { + char ch = sequence[seqIndx], chMem = (*((char *)it)); + + if(ch == '\0') return (void *)(it - sequenceSize(sequence)); + else if(ch != chMem) + { + seqIndx = 0; + } + else if(ch == chMem) + { + seqIndx++; + } + } + return NULL; +}; diff --git a/include/StringOperations.h b/include/StringOperations.h new file mode 100644 index 0000000..81d7144 --- /dev/null +++ b/include/StringOperations.h @@ -0,0 +1,31 @@ +#ifndef STRINGOPERATIONS_H +#define STRINGOPERATIONS_H + +#include <types.h> + + +class MemArea +{ + private: + memAddr start, final; + public: + MemArea(); + MemArea(const memAddr start, const memAddr final); + memAddr begin(); + memAddr end(); + bool valid(); + + typedef memAddr iterator; +}; + +class StringOperations +{ + public: + // Return the starting address where is sequence is allocated + // else NULL + static void *findInMemory(const char *sequence, MemArea memory); + // Return size of ASCIZ sequence without 0-symbol, NULL on failure + static uint32 sequenceSize(const char *chars); +}; + +#endif diff --git a/include/types.h b/include/types.h index 54dcc25..e578adb 100644 --- a/include/types.h +++ b/include/types.h @@ -5,3 +5,9 @@ typedef unsigned char uint8; typedef unsigned short int uint16; typedef unsigned long uint32; typedef unsigned long long uint64; + +#if defined(__x86_64) + typedef uint64 memAddr; +#else + typedef uint32 memAddr; +#endif |
