From: alex@nospicedham.rivadpm.com   
      
   On 29-Aug-17 17:23, Anton Ertl wrote:   
   > Alex writes:   
   >> On 64 bit Windows, stack alignment on a 16 byte boundary is required   
   >> before calling all except a leaf function. In the called function, the   
   >> stack is 8 mod 16.   
   >>   
   >> Now, I'm struggling to come up with a way of doing it beyond this code   
   >> (which I didn't invent, but I can't for the life of me remember where I   
   >> found it.)   
   >>   
   >> push rsp   
   >> push [rsp]   
   >> and spl $F0   
   >> call funkychicken   
   >> pop rsp   
   >>   
   >> It seems to be the only way of doing this without branches, flags or   
   >> other expensive nonsense. But, as ever, there may be a better way. Any   
   >> suggestions?   
   >   
   > The usual way (when you are in an ABI-compliant function yourself) is   
   > that your function adjusts the stack pointer by 8 mod 16 in a   
   > statically known way.   
   >   
   > - anton   
   >   
      
   I'm using a two stack model (as you will know, this is Forth) where the   
   return stack is RSP based and the data stack is based on another   
   register, say RBP.   
      
   On my 32 bit system (ESP and EBP respectively) calling into Windows is   
   most easily achieved by switching the stacks, doing the call, and   
   switching back again, since all the parameters are already on the data   
   stack pointed by EBP, and there is no special alignment required.   
      
   For 64 bit Windows, that technique is not as easy since Windows passes 4   
   parameters in registers, the rest on the stack, and has this oddball 16   
   byte alignment; so there is no static way of ensuring either of the   
   stacks is 16 byte aligned, regardless of whether I switch stacks or not.   
      
   --   
   Alex   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|