no pusha or similar instruction in AMD64?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
hippykin
Posts: 11
Joined: Mon Feb 11, 2008 3:44 pm
Location: UK

no pusha or similar instruction in AMD64?

Post by hippykin »

Hello, i am now working on my interrupt handlers and currently i am pushing all the registers onto the stack and popping them all of before iret'ing however in IA-32 there are the popa and pusha instructions which do all this i imagine that they are faster and i am wondering if there is a similar pair of instructions in AMD64.
I have read the AMD manuals all i can gather from there is that the popa and pusha op-codes have been reassigned. Does anyone know of a equivalent pair of instructions that exist in AMD64 (long mode)?
thanks
The BBC micro could have become the world standard - it was so ahead of its time
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Post by AJ »

Unfortunately, there's not an equivalent. I use the following macros suggested by the NASM manual:

Code: Select all

%macro  multipush 1-* 

  %rep  %0 
        push    %1 
  %rotate 1 
  %endrep 

%endmacro

%macro  multipop 1-* 

  %rep %0 
  %rotate -1 
        pop     %1 
  %endrep 

%endmacro
With these, you can provide the registers to push and pop in the same order, which makes things a bit easier to remember.

Cheers,
Adam
hippykin
Posts: 11
Joined: Mon Feb 11, 2008 3:44 pm
Location: UK

Post by hippykin »

thank you AJ, i got interrupts working today (they would have worked first time if i had known that NASM wasn't cleaver enough to automatically use the long mode iret op-code, i had to manually specify iretq in the end)
The BBC micro could have become the world standard - it was so ahead of its time
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Post by AJ »

hippykin wrote:thank you AJ, i got interrupts working today (they would have worked first time if i had known that NASM wasn't cleaver enough to automatically use the long mode iret op-code, i had to manually specify iretq in the end)
#-o

Yup - that one got me first time too!

Cheers,
Adam
jackman
Posts: 7
Joined: Mon Mar 31, 2014 8:26 pm

Re: no pusha or similar instruction in AMD64?

Post by jackman »

I like the solution, but I'd like to know if (E)SP needs any special handling? I refer to the Intel opcode reference http://www.intel.com/content/dam/www/pu ... 325383.pdf, page 4-274.

The PUSHA instruction saves the SP to a temporary variable and then puts it on the stack. Is it sufficient to just push SP first? Thanks.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: no pusha or similar instruction in AMD64?

Post by Combuster »

There's actually no need to push/pop RSP specifically in long mode. An interrupt already does that for you in all cases, and any properly paired push/pop to RSP will only add or subtract 8 from it since pushes and pops implicitly use RSP.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Post Reply