diff options
| author | Alexey Gavrilov <90127298+rebovas@users.noreply.github.com> | 2024-03-08 12:25:05 +0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-03-08 12:25:05 +0700 |
| commit | 32e05e127197275bc4931e0beb6e1f7f29fb5d4d (patch) | |
| tree | d5f23cdcbc6af79eb9b789d57086c8e3c9ec9c79 | |
| parent | 301dc22ee57b7c46cb033358170ffad615fef6ab (diff) | |
| parent | fa4729c08f02a5c2c958da5142a9b4fef99a4b4f (diff) | |
Merge pull request #3 from rebovas/cpuinfo_refactor
Cpuinfo refactor
| -rw-r--r-- | arch/x86/cpuinfo/Cpuinfo.cpp | 34 | ||||
| -rw-r--r-- | arch/x86/cpuinfo/Cpuinfo.h | 3 | ||||
| -rw-r--r-- | include/MemoryOperations.cpp | 4 |
3 files changed, 11 insertions, 30 deletions
diff --git a/arch/x86/cpuinfo/Cpuinfo.cpp b/arch/x86/cpuinfo/Cpuinfo.cpp index c6c551e..4db7c84 100644 --- a/arch/x86/cpuinfo/Cpuinfo.cpp +++ b/arch/x86/cpuinfo/Cpuinfo.cpp @@ -1,4 +1,5 @@ #include "Cpuinfo.h" +#include "MemoryOperations.h" inline Cpuinfo::cpuidFunctionIndex operator++(Cpuinfo::cpuidFunctionIndex& command) @@ -52,12 +53,8 @@ Cpuinfo::Cpuinfo() currentCpuType = processorType::NotRead; serialNumber = 0; - // Write memset!!! - // memset(internalInfoDescriptors, 0, sizeof(uint8) * amountDescriptors) - - // Rewrite it! Create method memset() - for(uint8 i = 0; i < vendorStringSize; i++) vendorString[i] = '\0'; - for(uint8 i = 0; i < brandStringSize; i++) brandString[i] = '\0'; + MemoryOperations::set(vendorString, '\0', vendorStringSize); + MemoryOperations::set(brandString, '\0', brandStringSize); dataFilling(Cpuinfo::BasicInfo, Cpuinfo::ExtendedCpuidEnd); }; @@ -87,15 +84,7 @@ void Cpuinfo::setBasicData() uint32 vendorStringInt[3] = {ebx, edx, ecx}; - // Rewrite it! Create method memcpy() - for(int i = 0; i < 3; i++) - { - uint8 upperCharIndex = i * 4 + 3; - vendorString[upperCharIndex--] = vendorStringInt[i] >> 24; - vendorString[upperCharIndex--] = vendorStringInt[i] >> 16; - vendorString[upperCharIndex--] = vendorStringInt[i] >> 8; - vendorString[upperCharIndex--] = vendorStringInt[i]; - } + MemoryOperations::copy(vendorStringInt, vendorString, sizeof(uint32) * 3); }; void Cpuinfo::setVersionData() @@ -182,16 +171,7 @@ void Cpuinfo::setBrandString(brandStringPart part) uint8 partUint = uint8(part); uint32 regs[4] = {eax, ebx, ecx, edx}; - // memCpy()!!! - for(uint8 regIndex = 0; regIndex < 4; regIndex++) - { - uint32 reg = regs[regIndex]; - for(uint8 bytesInRegister = 0; bytesInRegister < 4; bytesInRegister++) - { - brandString[partUint++] = reg; - reg >>= 8; - } - } + MemoryOperations::copy(regs, &brandString[partUint], sizeof(uint32) * 4); } }; @@ -355,9 +335,9 @@ uint32 Cpuinfo::getMaxFunctionIndexExtended() return maximumInputValueExtended; }; -uint8* Cpuinfo::getBrandString() +const char* Cpuinfo::getBrandString() { - return brandString; + return (const char*)brandString; }; uint8* Cpuinfo::getInternalDescriptors() diff --git a/arch/x86/cpuinfo/Cpuinfo.h b/arch/x86/cpuinfo/Cpuinfo.h index 4baa76f..6adce11 100644 --- a/arch/x86/cpuinfo/Cpuinfo.h +++ b/arch/x86/cpuinfo/Cpuinfo.h @@ -1,6 +1,7 @@ #ifndef CPUID_H #define CPUID_H #include <types.h> +#include <MemoryOperations.h> #ifdef __cplusplus @@ -358,7 +359,7 @@ class Cpuinfo uint8 getStepping(); uint8 getMaxFunctionIndex(); uint32 getMaxFunctionIndexExtended(); - uint8* getBrandString(); + const char* getBrandString(); uint8* getInternalDescriptors(); }; #endif diff --git a/include/MemoryOperations.cpp b/include/MemoryOperations.cpp index 882a133..5d82dac 100644 --- a/include/MemoryOperations.cpp +++ b/include/MemoryOperations.cpp @@ -4,7 +4,7 @@ uint32 MemoryOperations::copy(void *source, void *destination, uint32 sizeBytes) { if(source == nullptr || destination == nullptr) return NULL; - char *src = (char *)source, *dst = (char*)destination; + uint8 *src = (uint8 *)source, *dst = (uint8*)destination; uint32 byteNumber = 1; while(byteNumber <= sizeBytes) @@ -20,7 +20,7 @@ uint32 MemoryOperations::set(void *field, uint8 value, uint32 sizeBytes) { if(field == nullptr) return NULL; - char *charField = (char*)field; + uint8 *charField = (uint8*)field; uint32 byteNumber = 1; while(byteNumber <= sizeBytes) |
