diff options
| author | Alexey Gavrilov <90127298+rebovas@users.noreply.github.com> | 2024-03-31 14:40:50 +0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-03-31 14:40:50 +0700 |
| commit | 18b4f9d1bff908fd91a48c1953ebcb8363855a59 (patch) | |
| tree | d309b630a161823c79dab9a48f67a41a40d76b24 /arch/x86/gdt/Gdt.cpp | |
| parent | a276644952ed018e77ca64181059434a6bc4ee62 (diff) | |
| parent | 49cfee4e370892df8404e56d53b04dde196f82f2 (diff) | |
Merge pull request #6 from rebovas/idt
IDT + uintptr update
Diffstat (limited to 'arch/x86/gdt/Gdt.cpp')
| -rwxr-xr-x | arch/x86/gdt/Gdt.cpp | 60 |
1 files changed, 32 insertions, 28 deletions
diff --git a/arch/x86/gdt/Gdt.cpp b/arch/x86/gdt/Gdt.cpp index 21941b4..70f30cd 100755 --- a/arch/x86/gdt/Gdt.cpp +++ b/arch/x86/gdt/Gdt.cpp @@ -2,6 +2,21 @@ uint64 MngGdt::gdt[MngGdt::size]; +bool MngGdt::isInitialize = false; +bool MngGdt::gdtLoaded = false; +MngGdt mngGdt; + +MngGdt::MngGdt() +{ + if(!isInitialize) + { + MemoryOperations::set(gdt, 0, sizeof(uint64) * size); + currIdx = 1; + gdtLoaded = false; + isInitialize = true; + codeSegmentKern = NULL; + } +}; DescSeg32::DescSeg32(uint32 base, uint32 limit, uint8 access, uint8 flags) { @@ -57,59 +72,48 @@ uint64 DescSeg32::flatDataUser() , PAGEGRAN | HIGHSIZE).getDescriptor(); }; -MngGdt::MngGdt() -{ - gdt[0] = 0; - currIdx = 1; - isGdtLoaded = 0; -}; - bool MngGdt::addDescriptor(uint64 desc) { - if(currIdx >= size || currIdx == 0) + if(currIdx >= size or currIdx == 0 or gdtLoaded) { return false; } + if(desc == DescSeg32::flatCodeKernel()) codeSegmentKern = currIdx * 8; this->gdt[currIdx++] = desc; return true; }; bool MngGdt::loadGdt() { - if(isGdtLoaded) + if(gdtLoaded) { return false; } - uint64 pointer = 0; + // Set pointer + uint64 descriptor = 0; uint16 size = sizeof(uint64) * this->size - 1; - uint32 offset = (uint32)((void *)(&gdt)); + uint32 offset = (uint32)(&gdt); - pointer |= offset; - pointer <<= 16; - pointer |= size; + descriptor |= offset; + descriptor <<= 16; + descriptor |= size; - SWITCHTOGDT(pointer); + SWITCHTOGDT(descriptor); - isGdtLoaded = 1; + gdtLoaded = 1; return true; }; -bool MngGdt::getIsGdtLoaded() +// Get static instance of MngGdt initialized once +MngGdt &MngGdt::getInstance() { - return isGdtLoaded; + if(!isInitialize) mngGdt = MngGdt(); + return mngGdt; }; -void MngGdt::operator=(const MngGdt& src) +uint16 MngGdt::getCodeSegmentKernel() { - if(this->isGdtLoaded == 1 || src.isGdtLoaded == 1) - { - return; - } - - // Fix it. Write method to copy from ... to ... - for(int i = 0; i < this->size; i++) this->gdt[i] = src.gdt[i]; - this->isGdtLoaded = src.isGdtLoaded; - this->currIdx = src.currIdx; + return codeSegmentKern; }; |
