Index: lib/libc/mips/gen/makecontext.c =================================================================== --- lib/libc/mips/gen/makecontext.c +++ lib/libc/mips/gen/makecontext.c @@ -103,11 +103,14 @@ for (i = 0; i < argc && i < 8; i++) /* LINTED register_t is safe */ mc->mc_regs[A0 + i] = va_arg(ap, register_t); - /* Pass remaining arguments on the stack above the $a0-3 gap. */ + /* Pass remaining arguments on the stack above the $a0-7 gap. */ + /* + * XXX: Is this comment accurate? There is no sp += i here to + * match it for NEWABI. + */ #endif - /* Pass remaining arguments on the stack above the $a0-3 gap. */ for (; i < argc; i++) - /* LINTED uintptr_t is safe */ + /* LINTED register_t is safe */ *sp++ = va_arg(ap, register_t); va_end(ap); } Index: sys/mips/include/md_var.h =================================================================== --- sys/mips/include/md_var.h +++ sys/mips/include/md_var.h @@ -41,6 +41,17 @@ /* * Miscellaneous machine-dependent declarations. */ + +/* + * Use 16-byte stack alignment for N32 and N64 and 8-byte alignment + * for O32. This matches the expectations of both GCC and LLVM. + */ +#if defined(__mips_n32) || defined(__mips_n64) +#define STACK_ALIGN 16 +#else +#define STACK_ALIGN 8 +#endif + extern long Maxmem; extern char sigcode[]; extern int szsigcode; Index: sys/mips/mips/pm_machdep.c =================================================================== --- sys/mips/mips/pm_machdep.c +++ sys/mips/mips/pm_machdep.c @@ -74,6 +74,12 @@ #define UCONTEXT_MAGIC 0xACEDBADE +#if defined(__mips_n32) || defined(__mips_n64) +#define STACK_ALIGN 16 +#else +#define STACK_ALIGN 8 +#endif + /* * Send an interrupt to process. * @@ -132,10 +138,10 @@ SIGISMEMBER(psp->ps_sigonstack, sig)) { sfp = (struct sigframe *)(((uintptr_t)td->td_sigstk.ss_sp + td->td_sigstk.ss_size - sizeof(struct sigframe)) - & ~(sizeof(__int64_t) - 1)); + & ~(STACK_ALIGN - 1)); } else sfp = (struct sigframe *)((vm_offset_t)(regs->sp - - sizeof(struct sigframe)) & ~(sizeof(__int64_t) - 1)); + sizeof(struct sigframe)) & ~(STACK_ALIGN - 1)); /* Build the argument list for the signal handler. */ regs->a0 = sig; @@ -408,12 +414,7 @@ bzero((caddr_t)td->td_frame, sizeof(struct trapframe)); - /* - * The stack pointer has to be aligned to accommodate the largest - * datatype at minimum. This probably means it should be 16-byte - * aligned, but for now we're 8-byte aligning it. - */ - td->td_frame->sp = ((register_t) stack) & ~(sizeof(__int64_t) - 1); + td->td_frame->sp = ((register_t)stack) & ~(STACK_ALIGN - 1); /* * If we're running o32 or n32 programs but have 64-bit registers, Index: sys/mips/mips/vm_machdep.c =================================================================== --- sys/mips/mips/vm_machdep.c +++ sys/mips/mips/vm_machdep.c @@ -430,13 +430,7 @@ struct trapframe *tf; register_t sp; - /* - * At the point where a function is called, sp must be 8 - * byte aligned[for compatibility with 64-bit CPUs] - * in ``See MIPS Run'' by D. Sweetman, p. 269 - * align stack - */ - sp = (((intptr_t)stack->ss_sp + stack->ss_size) & ~0x7) - + sp = (((intptr_t)stack->ss_sp + stack->ss_size) & ~(STACK_ALIGN - 1)) - CALLFRAME_SIZ; /*