home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.asm.x86      Ahh, the lost art of x86 assembly      4,675 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 2,985 of 4,675   
   Alex to Anton Ertl   
   Re: 64 bit stack alignment   
   02 Sep 17 22:05:39   
   
   From: alex@nospicedham.rivadpm.com   
      
   Followups set to comp.lang.forth   
      
   On 02-Sep-17 16:58, Anton Ertl wrote:   
   > Alex  writes:   
   >> 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.   
   >   
   > This is already wrong, because the parameters are in the wrong order   
      
   FunctionName(a,b,c,d) becomes d c b a FunctionName. It hasn't proved to   
   be a problem so far. a b c d FunctionName requires FunctionName to   
   reverse 4 parameters; that's both inefficient and requires the count.   
   Varargs become significantly more difficult.   
      
   > and it breaks down when you need to pass an FP parameter.  Of course   
      
   How?   
      
   > there is the lure of letting the programmer do the parameter   
   > reversing, and many Forth system implementors fell into this trap, but   
   > the significant ones have seen the light, and do it mostly properly   
   > now.   
      
   I have to disagree; it's more a matter of taste and style.   
      
   >   
   >> 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.   
   >   
   > You could have the C stack separate from the data, return, and FP   
   > stacks, with the C stack always complying with the ABI.  You could   
   > store the C stack pointer in memory while executing Forth code to to avoid   
   > wasting a register on a value that is not used for a long time.   
      
   Yes, I am proposing using a non-volatile XMM register for that purpose.   
      
   \  Register usage   
   \   
   \    XMM15       save of Windows RSP   
   \    RAX         cached top of stack   
   \    RSP         return stack              RP   
   \    RBP         data stack                SP   
   \    RBX         per process user area   
   \    R12         locals stack              LP   
   \    R13         float stack               FP   
      
   >   
   > AFAIK you are planning to eventually have an analytical compiler; in   
      
   Eventually. It's hard getting the needed hours together.   
      
   > that case letting the compiler put the arguments of a C call in   
   > registers or on the C stack should not be particularly difficult.   
   >   
   > - anton   
   >   
      
      
   --   
   Alex   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca