tech-toolchain archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: alpha stack alignment: 8- or 16-byte
Hi,
On 2021/07/06 6:24, Jason Thorpe wrote:
On Jul 5, 2021, at 8:53 AM, Jason Thorpe <thorpej%me.com@localhost> wrote:
On Jul 5, 2021, at 7:09 AM, Rin Okuyama <rokuyama.rk%gmail.com@localhost> wrote:
(1) Align sp to 8-byte boundary: keep our kernel and libraries as well,
and fix GCC, or
(2) Align sp to 16-byte boundary: fix our kernel and libraries.
My preference is (2). The kernel already does this for its own functions in locore.s (look for the functions declared NESTED).
This should take care of the kernel portion of the change:
https://www.netbsd.org/~thorpej/alpha-stack-patch.txt
The only libc routine that looks broken to me is swapcontext() (it pushes a 24-byte stack frame). Do you see any other broken ones?
FYI -- I built an alpha release with the above patch, plus a fix to swapcontext(), with the HACKS removed, and I'm doing an ATF run in Qemu now.
Thank you for your comment and patch for kernel!
In addition to swapcontext(), few more routines should be fixed for
userland. Please find the attached patch.
With your and my patches, at least the system boots multiuser, and
GDB and pkgsrc/devel/gettext-tools work fine. I'm now running ATF.
(I finally, at long last, have some real Alpha hardware nearly in my possession after many years of lacking it... and an early-ish model, at that, so I should be able to verify on real hardware again very soon...)
Good news! Have fun :)
Thanks,
rin
Index: lib/libc/arch/alpha/gen/__setjmp14.S
===================================================================
RCS file: /home/netbsd/src/lib/libc/arch/alpha/gen/__setjmp14.S,v
retrieving revision 1.8
diff -p -u -r1.8 __setjmp14.S
--- lib/libc/arch/alpha/gen/__setjmp14.S 21 Oct 2020 01:24:05 -0000 1.8
+++ lib/libc/arch/alpha/gen/__setjmp14.S 5 Jul 2021 22:24:01 -0000
@@ -68,12 +68,12 @@ LEAF(__setjmp14, 1)
lda a2, SC_MASK(s0) /* point to mask in sc */
CALL(__sigprocmask14)
- lda sp, -24(sp) /* sizeof struct sigaltstack */
+ lda sp, -32(sp) /* roundup(sizeof(struct sigaltstack), 16) */
mov zero, a0
mov sp, a1
CALL(__sigaltstack14)
ldl t0, 16(sp) /* offset of ss_flags */
- lda sp, 24(sp) /* sizeof struct sigaltstack */
+ lda sp, 32(sp) /* see above */
ldq ra, (SC_REGS+_REG_RA*8)(s0) /* restore return address */
blt v0, botch /* check for error */
and t0, 0x1, t0 /* get SA_ONSTACK flag */
Index: lib/libc/arch/alpha/gen/_lwp.c
===================================================================
RCS file: /home/netbsd/src/lib/libc/arch/alpha/gen/_lwp.c,v
retrieving revision 1.7
diff -p -u -r1.7 _lwp.c
--- lib/libc/arch/alpha/gen/_lwp.c 12 Sep 2012 14:13:43 -0000 1.7
+++ lib/libc/arch/alpha/gen/_lwp.c 5 Jul 2021 22:25:36 -0000
@@ -58,7 +58,7 @@ _lwp_makecontext(ucontext_t *u, void (*s
gr[_REG_T12] = (unsigned long) start;
gr[_REG_RA] = (unsigned long) _lwp_exit;
gr[_REG_A0] = (unsigned long) arg;
- gr[_REG_SP] = ((unsigned long) (stack_base + stack_size)) & ~0x7;
+ gr[_REG_SP] = ((unsigned long) (stack_base + stack_size)) & ~0xf;
gr[_REG_S6] = 0;
gr[_REG_UNIQUE] = (unsigned long)private;
Index: lib/libc/arch/alpha/gen/makecontext.c
===================================================================
RCS file: /home/netbsd/src/lib/libc/arch/alpha/gen/makecontext.c,v
retrieving revision 1.6
diff -p -u -r1.6 makecontext.c
--- lib/libc/arch/alpha/gen/makecontext.c 20 Sep 2011 08:42:29 -0000 1.6
+++ lib/libc/arch/alpha/gen/makecontext.c 5 Jul 2021 22:30:34 -0000
@@ -51,12 +51,14 @@ makecontext(ucontext_t *ucp, void (*func
unsigned long *sp;
va_list ap;
- /* Compute and align stack pointer. */
+ /* Compute stack pointer. */
sp = (unsigned long *)
- (((uintptr_t)ucp->uc_stack.ss_sp + ucp->uc_stack.ss_size) & ~0x7);
+ ((uintptr_t)ucp->uc_stack.ss_sp + ucp->uc_stack.ss_size);
/* Allocate necessary stack space for arguments exceeding a0-5. */
if (argc > 6)
sp -= (argc - 6);
+ /* Align stack pointer. */
+ sp = (unsigned long *)((uintptr_t)sp & ~0xf);
gr[_REG_SP] = (__greg_t)sp;
/* Arrange for return via the trampoline code. */
gr[_REG_RA] = (__greg_t)__resumecontext;
Index: lib/libc/arch/alpha/gen/swapcontext.S
===================================================================
RCS file: /home/netbsd/src/lib/libc/arch/alpha/gen/swapcontext.S,v
retrieving revision 1.4
diff -p -u -r1.4 swapcontext.S
--- lib/libc/arch/alpha/gen/swapcontext.S 21 Oct 2020 01:24:05 -0000 1.4
+++ lib/libc/arch/alpha/gen/swapcontext.S 5 Jul 2021 22:45:51 -0000
@@ -34,23 +34,23 @@
NESTED(swapcontext, 2, 24, ra, IM_RA|IM_A0|IM_A1, 0)
LDGP(pv)
- lda sp, -24(sp)
- stq ra, (24- 8)(sp) /* must save ra, oucp, ucp */
- stq a0, (24-16)(sp)
- stq a1, (24-24)(sp)
+ lda sp, -32(sp)
+ stq ra, (32- 8)(sp) /* must save ra, oucp, ucp */
+ stq a0, (32-16)(sp)
+ stq a1, (32-24)(sp)
CALL(_getcontext) /* getcontext(oucp) */
- ldq t0, (24-16)(sp)
+ ldq t0, (32-16)(sp)
bne v0, Lerr
- ldq t1, (24- 8)(sp)
+ ldq t1, (32- 8)(sp)
stq t1, (UC_GREGS + _REG_RA*8)(t0) /* Adjust saved RA */
stq t1, (UC_GREGS + _REG_PC*8)(t0) /* Adjust saved PC */
- lda t1, 24(sp)
+ lda t1, 32(sp)
stq t1, (UC_GREGS + _REG_SP*8)(t0) /* Adjust saved SP */
- ldq a0, (24-24)(sp)
+ ldq a0, (32-24)(sp)
CALL(setcontext) /* setcontext(ucp) */
Lerr:
- ldq ra, (24- 8)(sp)
- lda sp, 24(sp)
+ ldq ra, (32- 8)(sp)
+ lda sp, 32(sp)
RET
END(swapcontext)
Index: lib/libm/arch/alpha/lrint.S
===================================================================
RCS file: /home/netbsd/src/lib/libm/arch/alpha/lrint.S,v
retrieving revision 1.3
diff -p -u -r1.3 lrint.S
--- lib/libm/arch/alpha/lrint.S 13 Oct 2004 15:18:31 -0000 1.3
+++ lib/libm/arch/alpha/lrint.S 5 Jul 2021 22:37:32 -0000
@@ -12,10 +12,10 @@ LEAF(lrint, 1)
#if 0
ftoit ft0,v0
#else
- lda sp,-8(sp)
+ lda sp,-16(sp)
stt ft0,0(sp)
ldq v0,0(sp)
- lda sp,8(sp)
+ lda sp,16(sp)
#endif
ret
END(lrint)
Home |
Main Index |
Thread Index |
Old Index