Skip to content
Snippets Groups Projects
Commit 43c8a820 authored by Raymond Toy's avatar Raymond Toy
Browse files

Make stack 16-byte aligned.

lisp/x86-assem.S:
o Make sure the stack is 16-byte aligned in the alloc_overflow_foo and
  alloc_to_foo routines.  These eventually call into C code, and the
  stack is required to be 16-byte aligned on Darwin.  We apply this to
  all x86 implementations since it's harmless.
o Did not update the alloc_8/16_to_foo routines because they are going
  to be deleted.

x86/macros.lisp:
o Don't call the alloc_8/16_to_foo routines when we're not doing
  inline allocation.  I don't think there's much to be gained with
  these special functions and maintainence is a pain with assembly
  code.
parent 57ca5217
No related branches found
No related tags found
No related merge requests found
...@@ -181,65 +181,29 @@ ...@@ -181,65 +181,29 @@
;; special entry point. The size may be a register or a constant. ;; special entry point. The size may be a register or a constant.
(ecase (tn-offset alloc-tn) (ecase (tn-offset alloc-tn)
(#.eax-offset (#.eax-offset
(case size (load-size alloc-tn eax-tn size)
(8 (inst call (make-fixup (extern-alien-name "alloc_8_to_eax") (inst call (make-fixup (extern-alien-name "alloc_to_eax")
:foreign))) :foreign)))
(16 (inst call (make-fixup (extern-alien-name "alloc_16_to_eax")
:foreign)))
(t
(load-size alloc-tn eax-tn size)
(inst call (make-fixup (extern-alien-name "alloc_to_eax")
:foreign)))))
(#.ecx-offset (#.ecx-offset
(case size (load-size alloc-tn ecx-tn size)
(8 (inst call (make-fixup (extern-alien-name "alloc_8_to_ecx") (inst call (make-fixup (extern-alien-name "alloc_to_ecx")
:foreign))) :foreign)))
(16 (inst call (make-fixup (extern-alien-name "alloc_16_to_ecx")
:foreign)))
(t
(load-size alloc-tn ecx-tn size)
(inst call (make-fixup (extern-alien-name "alloc_to_ecx")
:foreign)))))
(#.edx-offset (#.edx-offset
(case size (load-size alloc-tn edx-tn size)
(8 (inst call (make-fixup (extern-alien-name "alloc_8_to_edx") (inst call (make-fixup (extern-alien-name "alloc_to_edx")
:foreign))) :foreign)))
(16 (inst call (make-fixup (extern-alien-name "alloc_16_to_edx")
:foreign)))
(t
(load-size alloc-tn edx-tn size)
(inst call (make-fixup (extern-alien-name "alloc_to_edx")
:foreign)))))
(#.ebx-offset (#.ebx-offset
(case size (load-size alloc-tn ebx-tn size)
(8 (inst call (make-fixup (extern-alien-name "alloc_8_to_ebx") (inst call (make-fixup (extern-alien-name "alloc_to_ebx")
:foreign))) :foreign)))
(16 (inst call (make-fixup (extern-alien-name "alloc_16_to_ebx")
:foreign)))
(t
(load-size alloc-tn ebx-tn size)
(inst call (make-fixup (extern-alien-name "alloc_to_ebx")
:foreign)))))
(#.esi-offset (#.esi-offset
(case size (load-size alloc-tn esi-tn size)
(8 (inst call (make-fixup (extern-alien-name "alloc_8_to_esi") (inst call (make-fixup (extern-alien-name "alloc_to_esi")
:foreign))) :foreign)))
(16 (inst call (make-fixup (extern-alien-name "alloc_16_to_esi")
:foreign)))
(t
(load-size alloc-tn esi-tn size)
(inst call (make-fixup (extern-alien-name "alloc_to_esi")
:foreign)))))
(#.edi-offset (#.edi-offset
(case size (load-size alloc-tn edi-tn size)
(8 (inst call (make-fixup (extern-alien-name "alloc_8_to_edi") (inst call (make-fixup (extern-alien-name "alloc_to_edi")
:foreign))) :foreign))))
(16 (inst call (make-fixup (extern-alien-name "alloc_16_to_edi")
:foreign)))
(t
(load-size alloc-tn edi-tn size)
(inst call (make-fixup (extern-alien-name "alloc_to_edi")
:foreign))))))
(values)) (values))
;;; ;;;
......
...@@ -63,6 +63,22 @@ GNAME(x): ; ...@@ -63,6 +63,22 @@ GNAME(x): ;
#define align_16byte 4 #define align_16byte 4
#endif #endif
/*
* Allocate |bytes| on the stack, and make sure the stack pointer is
* aligned on a 16-byte boundary. (Needed on Darwin, and harmless on
* others that don't need such alignment.)
*/
#define STACK_PROLOGUE(bytes) \
pushl %ebp ; \
mov %esp, %ebp ; \
subl $##bytes, %esp ; \
andl $-16, %esp ;
/* Undo STACK_PROLOGUE */
#define STACK_EPILOGUE \
movl %ebp, %esp ; \
popl %ebp ;
.text .text
.globl GNAME(foreign_function_call_active) .globl GNAME(foreign_function_call_active)
...@@ -453,13 +469,14 @@ ENDFUNC(fastcopy16) ...@@ -453,13 +469,14 @@ ENDFUNC(fastcopy16)
So only eax, ecx, and edx need special care here. */ So only eax, ecx, and edx need special care here. */
FUNCDEF(alloc_to_eax) FUNCDEF(alloc_to_eax)
pushl %ecx # Save ecx and edx as C could destroy them. STACK_PROLOGUE(12)
pushl %edx movl %ecx, 8(%esp) # Save ecx and edx as C could destroy them.
pushl %eax # Push the size movl %edx, 4(%esp)
movl %eax, (%esp) # Push the size
call GNAME(alloc) call GNAME(alloc)
addl $4,%esp # pop the size arg. movl 4(%esp), %edx # Restore ecx and edx.
popl %edx # Restore ecx and edx. movl 8(%esp), %ecx
popl %ecx STACK_EPILOGUE
ret ret
ENDFUNC(alloc_to_eax) ENDFUNC(alloc_to_eax)
...@@ -473,7 +490,7 @@ FUNCDEF(alloc_8_to_eax) ...@@ -473,7 +490,7 @@ FUNCDEF(alloc_8_to_eax)
popl %ecx popl %ecx
ret ret
ENDFUNC(alloc_8_to_eax) ENDFUNC(alloc_8_to_eax)
FUNCDEF(alloc_16_to_eax) FUNCDEF(alloc_16_to_eax)
pushl %ecx # Save ecx and edx as C could destroy them. pushl %ecx # Save ecx and edx as C could destroy them.
pushl %edx pushl %edx
...@@ -486,14 +503,15 @@ FUNCDEF(alloc_16_to_eax) ...@@ -486,14 +503,15 @@ FUNCDEF(alloc_16_to_eax)
ENDFUNC(alloc_16_to_eax) ENDFUNC(alloc_16_to_eax)
FUNCDEF(alloc_to_ecx) FUNCDEF(alloc_to_ecx)
pushl %eax # Save eax and edx as C could destroy them. STACK_PROLOGUE(12)
pushl %edx movl %eax, 8(%esp) # Save eax and edx as C could destroy them.
pushl %ecx # Push the size movl %edx, 4(%esp)
movl %ecx, (%esp) # Push the size
call GNAME(alloc) call GNAME(alloc)
addl $4,%esp # pop the size arg.
movl %eax,%ecx # setup the destination. movl %eax,%ecx # setup the destination.
popl %edx # Restore eax and edx. movl 4(%esp), %edx # Restore eax and edx.
popl %eax movl 8(%esp), %eax
STACK_EPILOGUE
ret ret
ENDFUNC(alloc_to_ecx) ENDFUNC(alloc_to_ecx)
...@@ -522,14 +540,15 @@ FUNCDEF(alloc_16_to_ecx) ...@@ -522,14 +540,15 @@ FUNCDEF(alloc_16_to_ecx)
ENDFUNC(alloc_16_to_ecx) ENDFUNC(alloc_16_to_ecx)
FUNCDEF(alloc_to_edx) FUNCDEF(alloc_to_edx)
pushl %eax # Save eax and ecx as C could destroy them. STACK_PROLOGUE(12)
pushl %ecx movl %eax, 8(%esp) # Save eax and ecx as C could destroy them.
pushl %edx # Push the size movl %ecx, 4(%esp)
movl %edx, (%esp) # Push the size
call GNAME(alloc) call GNAME(alloc)
addl $4,%esp # pop the size arg.
movl %eax,%edx # setup the destination. movl %eax,%edx # setup the destination.
popl %ecx # Restore eax and ecx. movl 4(%esp), %ecx # Restore eax and ecx.
popl %eax movl 8(%esp), %eax
STACK_EPILOGUE
ret ret
ENDFUNC(alloc_to_edx) ENDFUNC(alloc_to_edx)
...@@ -558,16 +577,17 @@ FUNCDEF(alloc_16_to_edx) ...@@ -558,16 +577,17 @@ FUNCDEF(alloc_16_to_edx)
ENDFUNC(alloc_16_to_edx) ENDFUNC(alloc_16_to_edx)
FUNCDEF(alloc_to_ebx) FUNCDEF(alloc_to_ebx)
pushl %eax # Save eax, ecx, and edx as C could destroy them. STACK_PROLOGUE(16)
pushl %ecx movl %eax, 12(%esp) # Save eax, ecx, and edx as C could destroy them.
pushl %edx movl %ecx, 8(%esp)
pushl %ebx # Push the size movl %edx, 4(%esp)
movl %ebx, (%esp) # Push the size
call GNAME(alloc) call GNAME(alloc)
addl $4,%esp # pop the size arg.
movl %eax,%ebx # setup the destination. movl %eax,%ebx # setup the destination.
popl %edx # Restore eax, ecx and edx. movl 4(%esp), %edx # Restore eax, ecx and edx.
popl %ecx movl 8(%esp), %ecx
popl %eax movl 12(%esp), %eax
STACK_EPILOGUE
ret ret
ENDFUNC(alloc_to_ebx) ENDFUNC(alloc_to_ebx)
...@@ -600,16 +620,17 @@ FUNCDEF(alloc_16_to_ebx) ...@@ -600,16 +620,17 @@ FUNCDEF(alloc_16_to_ebx)
ENDFUNC(alloc_16_to_ebx) ENDFUNC(alloc_16_to_ebx)
FUNCDEF(alloc_to_esi) FUNCDEF(alloc_to_esi)
pushl %eax # Save eax, ecx, and edx as C could destroy them. STACK_PROLOGUE(16)
pushl %ecx movl %eax, 12(%esp) # Save eax, ecx, and edx as C could destroy them.
pushl %edx movl %ecx, 8(%esp)
pushl %esi # Push the size movl %edx, 4(%esp)
movl %esi, (%esp) # Push the size
call GNAME(alloc) call GNAME(alloc)
addl $4,%esp # pop the size arg.
movl %eax,%esi # setup the destination. movl %eax,%esi # setup the destination.
popl %edx # Restore eax, ecx and edx. movl 4(%esp), %edx # Restore eax, ecx and edx.
popl %ecx movl 8(%esp), %ecx
popl %eax movl 12(%esp), %eax
STACK_EPILOGUE
ret ret
ENDFUNC(alloc_to_esi) ENDFUNC(alloc_to_esi)
...@@ -642,16 +663,17 @@ FUNCDEF(alloc_16_to_esi) ...@@ -642,16 +663,17 @@ FUNCDEF(alloc_16_to_esi)
ENDFUNC(alloc_16_to_esi) ENDFUNC(alloc_16_to_esi)
FUNCDEF(alloc_to_edi) FUNCDEF(alloc_to_edi)
pushl %eax # Save eax, ecx, and edx as C could destroy them. STACK_PROLOGUE(16)
pushl %ecx movl %eax, 12(%esp) # Save eax, ecx, and edx as C could destroy them.
pushl %edx movl %ecx, 8(%esp)
pushl %edi # Push the size movl %edx, 4(%esp)
movl %edi, (%esp) # Push the size
call GNAME(alloc) call GNAME(alloc)
addl $4,%esp # pop the size arg.
movl %eax,%edi # setup the destination. movl %eax,%edi # setup the destination.
popl %edx # Restore eax, ecx and edx. movl 4(%esp), %edx # Restore eax, ecx and edx.
popl %ecx movl 8(%esp), %ecx
popl %eax movl 12(%esp), %eax
STACK_EPILOGUE
ret ret
ENDFUNC(alloc_to_edi) ENDFUNC(alloc_to_edi)
...@@ -683,7 +705,6 @@ FUNCDEF(alloc_16_to_edi) ...@@ -683,7 +705,6 @@ FUNCDEF(alloc_16_to_edi)
ret ret
ENDFUNC(alloc_16_to_edi) ENDFUNC(alloc_16_to_edi)
#ifdef GENCGC #ifdef GENCGC
/* Called from lisp when an inline allocation overflows. /* Called from lisp when an inline allocation overflows.
...@@ -694,15 +715,16 @@ ENDFUNC(alloc_16_to_edi) ...@@ -694,15 +715,16 @@ ENDFUNC(alloc_16_to_edi)
/* This routine handles an overflow with eax=crfp+size. So the /* This routine handles an overflow with eax=crfp+size. So the
size=eax-crfp. */ size=eax-crfp. */
FUNCDEF(alloc_overflow_eax) FUNCDEF(alloc_overflow_eax)
pushl %ecx # Save ecx STACK_PROLOGUE(12)
pushl %edx # Save edx movl %ecx, 8(%esp) # Save ecx
movl %edx, 4(%esp) # Save edx
/* Calculate the size for the allocation. */ /* Calculate the size for the allocation. */
subl CURRENT_REGION_FREE_POINTER + SYMBOL_VALUE_OFFSET,%eax subl CURRENT_REGION_FREE_POINTER + SYMBOL_VALUE_OFFSET,%eax
pushl %eax # Push the size movl %eax, (%esp) # Push the size
call GNAME(alloc) call GNAME(alloc)
addl $4,%esp # pop the size arg. movl 4(%esp), %edx # Restore edx.
popl %edx # Restore edx. movl 8(%esp), %ecx # Restore ecx.
popl %ecx # Restore ecx. STACK_EPILOGUE
addl $6,(%esp) # Adjust the return address to skip the next inst. addl $6,(%esp) # Adjust the return address to skip the next inst.
ret ret
ENDFUNC(alloc_overflow_eax) ENDFUNC(alloc_overflow_eax)
...@@ -710,16 +732,17 @@ ENDFUNC(alloc_overflow_eax) ...@@ -710,16 +732,17 @@ ENDFUNC(alloc_overflow_eax)
/* This routine handles an overflow with ecx=crfp+size. So the /* This routine handles an overflow with ecx=crfp+size. So the
size=ecx-crfp. */ size=ecx-crfp. */
FUNCDEF(alloc_overflow_ecx) FUNCDEF(alloc_overflow_ecx)
pushl %eax # Save eax STACK_PROLOGUE(12)
pushl %edx # Save edx movl %eax, 8(%esp) # Save eax
movl %edx, 4(%esp) # Save edx
/* Calculate the size for the allocation. */ /* Calculate the size for the allocation. */
subl CURRENT_REGION_FREE_POINTER + SYMBOL_VALUE_OFFSET,%ecx subl CURRENT_REGION_FREE_POINTER + SYMBOL_VALUE_OFFSET,%ecx
pushl %ecx # Push the size movl %ecx, (%esp) # Push the size
call GNAME(alloc) call GNAME(alloc)
addl $4,%esp # pop the size arg.
movl %eax,%ecx # setup the destination. movl %eax,%ecx # setup the destination.
popl %edx # Restore edx. movl 4(%esp), %edx # Restore edx.
popl %eax # Restore eax. movl 8(%esp), %eax # Restore eax.
STACK_EPILOGUE
addl $6,(%esp) # Adjust the return address to skip the next inst. addl $6,(%esp) # Adjust the return address to skip the next inst.
ret ret
ENDFUNC(alloc_overflow_ecx) ENDFUNC(alloc_overflow_ecx)
...@@ -727,16 +750,17 @@ ENDFUNC(alloc_overflow_ecx) ...@@ -727,16 +750,17 @@ ENDFUNC(alloc_overflow_ecx)
/* This routine handles an overflow with edx=crfp+size. So the /* This routine handles an overflow with edx=crfp+size. So the
size=edx-crfp. */ size=edx-crfp. */
FUNCDEF(alloc_overflow_edx) FUNCDEF(alloc_overflow_edx)
pushl %eax # Save eax STACK_PROLOGUE(12)
pushl %ecx # Save ecx movl %eax, 8(%esp) # Save eax
movl %ecx, 4(%esp) # Save ecx
/* Calculate the size for the allocation. */ /* Calculate the size for the allocation. */
subl CURRENT_REGION_FREE_POINTER + SYMBOL_VALUE_OFFSET,%edx subl CURRENT_REGION_FREE_POINTER + SYMBOL_VALUE_OFFSET,%edx
pushl %edx # Push the size movl %edx, (%esp) # Push the size
call GNAME(alloc) call GNAME(alloc)
addl $4,%esp # pop the size arg.
movl %eax,%edx # setup the destination. movl %eax,%edx # setup the destination.
popl %ecx # Restore ecx. movl 4(%esp), %ecx # Restore ecx.
popl %eax # Restore eax. movl 8(%esp), %eax # Restore eax.
STACK_EPILOGUE
addl $6,(%esp) # Adjust the return address to skip the next inst. addl $6,(%esp) # Adjust the return address to skip the next inst.
ret ret
ENDFUNC(alloc_overflow_edx) ENDFUNC(alloc_overflow_edx)
...@@ -744,18 +768,19 @@ ENDFUNC(alloc_overflow_edx) ...@@ -744,18 +768,19 @@ ENDFUNC(alloc_overflow_edx)
/* This routine handles an overflow with ebx=crfp+size. So the /* This routine handles an overflow with ebx=crfp+size. So the
size=ebx-crfp. */ size=ebx-crfp. */
FUNCDEF(alloc_overflow_ebx) FUNCDEF(alloc_overflow_ebx)
pushl %eax # Save eax STACK_PROLOGUE(16)
pushl %ecx # Save ecx movl %eax, 12(%esp) # Save eax
pushl %edx # Save edx movl %ecx, 8(%esp) # Save ecx
movl %edx, 4(%esp) # Save edx
/* Calculate the size for the allocation. */ /* Calculate the size for the allocation. */
subl CURRENT_REGION_FREE_POINTER + SYMBOL_VALUE_OFFSET,%ebx subl CURRENT_REGION_FREE_POINTER + SYMBOL_VALUE_OFFSET,%ebx
pushl %ebx # Push the size movl %ebx, (%esp) # Push the size
call GNAME(alloc) call GNAME(alloc)
addl $4,%esp # pop the size arg.
movl %eax,%ebx # setup the destination. movl %eax,%ebx # setup the destination.
popl %edx # Restore edx. movl 4(%esp), %edx # Restore edx.
popl %ecx # Restore ecx. movl 8(%esp), %ecx # Restore ecx.
popl %eax # Restore eax. movl 12(%esp), %eax # Restore eax.
STACK_EPILOGUE
addl $6,(%esp) # Adjust the return address to skip the next inst. addl $6,(%esp) # Adjust the return address to skip the next inst.
ret ret
ENDFUNC(alloc_overflow_ebx) ENDFUNC(alloc_overflow_ebx)
...@@ -763,18 +788,19 @@ ENDFUNC(alloc_overflow_ebx) ...@@ -763,18 +788,19 @@ ENDFUNC(alloc_overflow_ebx)
/* This routine handles an overflow with esi=crfp+size. So the /* This routine handles an overflow with esi=crfp+size. So the
size=esi-crfp. */ size=esi-crfp. */
FUNCDEF(alloc_overflow_esi) FUNCDEF(alloc_overflow_esi)
pushl %eax # Save eax STACK_PROLOGUE(16)
pushl %ecx # Save ecx movl %eax, 12(%esp) # Save eax
pushl %edx # Save edx movl %ecx, 8(%esp) # Save ecx
movl %edx, 4(%esp) # Save edx
/* Calculate the size for the allocation. */ /* Calculate the size for the allocation. */
subl CURRENT_REGION_FREE_POINTER + SYMBOL_VALUE_OFFSET,%esi subl CURRENT_REGION_FREE_POINTER + SYMBOL_VALUE_OFFSET,%esi
pushl %esi # Push the size movl %esi, (%esp) # Push the size
call GNAME(alloc) call GNAME(alloc)
addl $4,%esp # pop the size arg.
movl %eax,%esi # setup the destination. movl %eax,%esi # setup the destination.
popl %edx # Restore edx. movl 4(%esp), %edx # Restore edx.
popl %ecx # Restore ecx. movl 8(%esp), %ecx # Restore ecx.
popl %eax # Restore eax. movl 12(%esp), %eax # Restore eax.
STACK_EPILOGUE
addl $6,(%esp) # Adjust the return address to skip the next inst. addl $6,(%esp) # Adjust the return address to skip the next inst.
ret ret
ENDFUNC(alloc_overflow_esi) ENDFUNC(alloc_overflow_esi)
...@@ -782,18 +808,19 @@ ENDFUNC(alloc_overflow_esi) ...@@ -782,18 +808,19 @@ ENDFUNC(alloc_overflow_esi)
/* This routine handles an overflow with edi=crfp+size. So the /* This routine handles an overflow with edi=crfp+size. So the
size=edi-crfp. */ size=edi-crfp. */
FUNCDEF(alloc_overflow_edi) FUNCDEF(alloc_overflow_edi)
pushl %eax # Save eax STACK_PROLOGUE(16)
pushl %ecx # Save ecx movl %eax, 12(%esp) # Save eax
pushl %edx # Save edx movl %ecx, 8(%esp) # Save ecx
movl %edx, 4(%esp) # Save edx
/* Calculate the size for the allocation. */ /* Calculate the size for the allocation. */
subl CURRENT_REGION_FREE_POINTER + SYMBOL_VALUE_OFFSET,%edi subl CURRENT_REGION_FREE_POINTER + SYMBOL_VALUE_OFFSET,%edi
pushl %edi # Push the size movl %edi, (%esp) # Push the size
call GNAME(alloc) call GNAME(alloc)
addl $4,%esp # pop the size arg.
movl %eax,%edi # setup the destination. movl %eax,%edi # setup the destination.
popl %edx # Restore edx. movl 4(%esp), %edx # Restore edx.
popl %ecx # Restore ecx. movl 8(%esp), %ecx # Restore ecx.
popl %eax # Restore eax. movl 12(%esp), %eax # Restore eax.
STACK_EPILOGUE
addl $6,(%esp) # Adjust the return address to skip the next inst. addl $6,(%esp) # Adjust the return address to skip the next inst.
ret ret
ENDFUNC(alloc_overflow_edi) ENDFUNC(alloc_overflow_edi)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment