Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/alpha - Define STACK_ALIGNBYTES to override the def...



details:   https://anonhg.NetBSD.org/src/rev/0a8516c62a3d
branches:  trunk
changeset: 984411:0a8516c62a3d
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Tue Jul 06 12:20:52 2021 +0000

description:
- Define STACK_ALIGNBYTES to override the default and ensure that
  stacks are 16-byte aligned, an assumption made by the compiler
  and recommended by the Alpha Architecture Handbook.
- cpu_lwp_fork(): Ensure 16-byte stack alignment if the caller specified
  one.

Addresses root casue of PR port-alpha/54307 and PR toolchain/56153.

Many thanks to rin@ for performing the root cause analysis and testing
changes.

diffstat:

 sys/arch/alpha/alpha/vm_machdep.c |  12 +++++++-----
 sys/arch/alpha/include/param.h    |   8 +++++++-
 2 files changed, 14 insertions(+), 6 deletions(-)

diffs (56 lines):

diff -r c442df806b18 -r 0a8516c62a3d sys/arch/alpha/alpha/vm_machdep.c
--- a/sys/arch/alpha/alpha/vm_machdep.c Tue Jul 06 11:52:52 2021 +0000
+++ b/sys/arch/alpha/alpha/vm_machdep.c Tue Jul 06 12:20:52 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: vm_machdep.c,v 1.119 2021/07/04 22:42:35 thorpej Exp $ */
+/* $NetBSD: vm_machdep.c,v 1.120 2021/07/06 12:20:52 thorpej Exp $ */
 
 /*
  * Copyright (c) 1994, 1995, 1996 Carnegie-Mellon University.
@@ -29,7 +29,7 @@
 
 #include <sys/cdefs.h>                 /* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.119 2021/07/04 22:42:35 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.120 2021/07/06 12:20:52 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -116,10 +116,12 @@
         * Floating point state from the FP chip has already been saved.
         */
        *pcb2 = *pcb1;
-       if (stack != NULL)
-               pcb2->pcb_hw.apcb_usp = (u_long)stack + stacksize;
-       else
+       if (stack != NULL) {
+               pcb2->pcb_hw.apcb_usp =
+                   ((u_long)stack + stacksize) & ~((u_long)STACK_ALIGNBYTES);
+       } else {
                pcb2->pcb_hw.apcb_usp = alpha_pal_rdusp();
+       }
 
        /*
         * Put l2 on the kernel's page tables until its first trip
diff -r c442df806b18 -r 0a8516c62a3d sys/arch/alpha/include/param.h
--- a/sys/arch/alpha/include/param.h    Tue Jul 06 11:52:52 2021 +0000
+++ b/sys/arch/alpha/include/param.h    Tue Jul 06 12:20:52 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: param.h,v 1.48 2021/05/31 14:38:55 simonb Exp $ */
+/* $NetBSD: param.h,v 1.49 2021/07/06 12:20:52 thorpej Exp $ */
 
 /*
  * Copyright (c) 1988 University of Utah.
@@ -57,6 +57,12 @@
 #define ALPHA_PGSHIFT  13
 #endif
 
+/*
+ * Compiler assumes 16 byte stack alignment, per recommendation of
+ * Alpha Architecture Handbook.
+ */
+#define        STACK_ALIGNBYTES        (16 - 1)
+
 #define        NBPG            (1 << ALPHA_PGSHIFT)            /* bytes/page */
 #define        PGOFSET         (NBPG-1)                        /* byte off. into pg */
 #define        PGSHIFT         ALPHA_PGSHIFT                   /* LOG2(NBPG) */



Home | Main Index | Thread Index | Old Index