Hi I'm a kernel learner and have some questions about swapgs.
According to AMD's documentation, it swaps the gs.base
hidden register and KernelGSBase MSR.
Furthermore, the addressing with "gs:XXXX" are calculated as "gs.base + base + (scale*index) + displacement"
Now my first question is:
- gs.base is the hidden part of segment register
- displacement is the "XXXX" part of "gs:XXXX"
- index may be the selector index in gs
Then where I should store the "base" and "scale"?
Furthermore, where I should use it, my current project put upper half of the virtual memory space as kernel, and the compiler will not usually add "gs:XXXX" as addressing reference.
So where, in particular, I should use the swapgs
instruction.