Browse Source

* make InvokeKernelRegister work for caller cleared stack/fixed stack and keep stack 16 byte aligned if needed

git-svn-id: trunk@43009 -
florian 5 years ago
parent
commit
48c5636fbc
1 changed files with 28 additions and 5 deletions
  1. 28 5
      packages/rtl-objpas/src/i386/invoke.inc

+ 28 - 5
packages/rtl-objpas/src/i386/invoke.inc

@@ -68,15 +68,20 @@ procedure InvokeKernelRegister(aCodeAddress: CodePointer; aArgs: Pointer; aArgCo
 label
   nostackargs;
 asm
-  pushl %ebp
+  pushl %ebp  
   movl %esp, %ebp
 
+  { keep stack aligned to 16 bytes? }
+{$if FPC_STACKALIGNMENT=16}
+  leal  -8(%esp),%esp
+{$endif FPC_STACKALIGNMENT=16}
+  
   pushl %edi
   pushl %esi
 
   pushl %eax
   pushl %edx
-
+  
   cmpl $3, %ecx
   jle nostackargs
 
@@ -88,10 +93,17 @@ asm
   movl %ecx, %eax
   shll $2, %eax
 
+  { keep stack aligned to 16 bytes? }
+{$if FPC_STACKALIGNMENT=16}
+  addl $15, %eax
+  movl %eax, %esi
+  andl $15, %esi
+  subl %esi, %eax
+{$endif FPC_STACKALIGNMENT=16}
+  
   sub %eax, %esp
 
-  movl %esp, %edi
-
+  movl %esp, %edi  
   lea 12(%edx), %esi
 
   cld
@@ -103,8 +115,14 @@ nostackargs:
   movl (%edx), %eax
   movl 4(%edx), %edx
 
+{$if FPC_STACKALIGNMENT=16}
+  call -20(%ebp)
+  { ensure stack is cleared }
+  leal -24(%ebp),%esp
+{$else FPC_STACKALIGNMENT=16}  
   call -12(%ebp)
-
+{$endif FPC_STACKALIGNMENT=16}
+  
   popl %ecx
   movl %eax, (%ecx)
   movl %edx, 4(%ecx)
@@ -476,6 +494,11 @@ asm
   { store pointer to stack area (including GP registers) }
   lea (%esp), %edx
 
+{$if FPC_STACKALIGNMENT=16}
+  { keep stack aligned, before the call below stack must be aligned to a 16 byte boundary }
+  leal -8(%esp),%esp
+{$endif FPC_STACKALIGNMENT=16}
+  
   { also store ebx as we'll use that for the function address }
   pushl %ebx