Moving the IDT/GDT/TSS
Posted: Thu Jul 09, 2020 3:01 am
If I move the IDT, GDT, or TSS in physical memory but it stays mapped to the same location in linear memory, do I need to call lidt/lgdt/ltr so the CPU picks it up?
The Place to Start for Operating System Developers
http://f.osdev.org/
No. Since the linear address isn't changing, there's no need to reload any registers.AndrewAPrice wrote:If I move the IDT, GDT, or TSS in physical memory but it stays mapped to the same location in linear memory, do I need to call lidt/lgdt/ltr so the CPU picks it up?
This is wrong. The CPU does not cache the GDT, LDT, IDT, or TSS. The CPU does cache segment descriptors, which are used by the ordinary segment registers (CS/DS/ES/FS/GS/SS) as well as the LDTR and TR. Loading a selector into any of the aforementioned registers requires a valid descriptor table to be present so the CPU can fill that register's shadow register, even if the selector refers to a descriptor already in one of the shadow registers.bzt wrote:No, the CPU uses so called shadow registers. These are just like cache. When you use lgdt for example, it reads the memory and fills up those shadow registers. After that one could zero out the GDT in RAM, the CPU will still work correctly.
This goes for GDT/LDT/IDT, not entirely sure about TSS though.
Then what are those GDTR, LDTR, IDTR, LTR things that the AMD spec calls "Descriptor-Table Registers" in Volume 2 section 6.3, and Intel refers to as "Memory Management Registers" in Volume 3a section 2.4? Just asking, because those are definitely NOT cache segment descriptors.Octocontrabass wrote:The CPU does not cache the GDT, LDT, IDT, or TSS. The CPU does cache segment descriptors
They are segment registers.bzt wrote:Then what are those GDTR, LDTR, IDTR, LTR things that the AMD spec calls "Descriptor-Table Registers" in Volume 2 section 6.3, and Intel refers to as "Memory Management Registers" in Volume 3a section 2.4? Just asking, because those are definitely NOT cache segment descriptors.
I was thinking about DMA, and how to handle it in my microkernel in a very generic way that doesn't know about the specifics of DMA. So I'm thinking if having a syscall such as "allocate X of memory below linear address Y", and if the kernel can't find unallocated memory, it can move things out of the way. So, I'm covering my bases to see what could potentially break if I moved the kernel's virtual memory out of the way.bzt wrote:But frankly, I don't see any benefit why would one move GDT/IDT/TSS
I have, but I don't see where I've said anything that disagrees with them.bzt wrote:@Octocontrabass: please read the referenced parts of the specs.