I went through AMD's Tech Doc's and Intel's Tech Doc's
...and it seems that the x86-64 does not support pusha, so I was wondering if I should do a stack-based task switching mechanism without the pusha opcode or should I use TSS Task Switches, even through segmentation is completely removed in the x86-64?
And how would you recommend that I implement them?
Multitasking in x86-64
Re:Multitasking in x86-64
Hi,
Long mode doesn't support hardware task switching, so you have to use stack-based task switches.
Cheers,
Brendan
Long mode doesn't support hardware task switching, so you have to use stack-based task switches.
AFAIK It's the same as it would be in protected mode. During initialization:BobFrank wrote:And how would you recommend that I implement them?
- * Build a single TSS (containing IST, ESP and ESP0)
* Make a TSS gate
* Do LTR
- * Store everything on the stack
* Switch to another stack
* Set ESP0 in the TSS
* Restore everything from the new stack
Cheers,
Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:Multitasking in x86-64
That sounded completely surrealist at first sight, but yetBobFrank wrote: I went through AMD's Tech Doc's and Intel's Tech Doc's
...and it seems that the x86-64 does not support pusha
So i guess we'll have to explicitly push every register we want to be task-local.Using the PUSHA or PUSHAD instruction in 64-bit mode generates an invalid-opcode exception.
Re:Multitasking in x86-64
It indeed does not "exist" (it'll produce an invalid opcode if you do use it according to the AMD docs). I'm thinking they may have done this to make the programmer more aware of what you are actually doing. Consider the following:
PUSHA in 16 bit mode uses 16 bytes
PUSHA in 32 bit mode uses 32 bytes
PUSHA in 64 bit mode would use 128 bytes of memory (assuming it would also push R8-15, without it would be 64 bytes)
Of course you can build your own macro (PUSH64 & POP64?) that does it in 16 instructions (or less if you don't use certain registers). It may be an instruction waste, but then again enough address / memory space to play with...
Hopefully they'll let us know why it wasn't included.
PUSHA in 16 bit mode uses 16 bytes
PUSHA in 32 bit mode uses 32 bytes
PUSHA in 64 bit mode would use 128 bytes of memory (assuming it would also push R8-15, without it would be 64 bytes)
Of course you can build your own macro (PUSH64 & POP64?) that does it in 16 instructions (or less if you don't use certain registers). It may be an instruction waste, but then again enough address / memory space to play with...
Hopefully they'll let us know why it wasn't included.