This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

SH: makecontext: Fix calculation of ARGC > 4


Hi!

With this patch, stdlib/tst-setcontext and stdlib/tst-makecontext3 now
pass.  Kaz, does this make sense?

	* sysdeps/unix/sysv/linux/sh/makecontext.S (__makecontext): Fix
	calculation of ARGC > 4.

diff --git a/sysdeps/unix/sysv/linux/sh/makecontext.S b/sysdeps/unix/sysv/linux/sh/makecontext.S
index 0a9e079..6132cf9 100644
--- a/sysdeps/unix/sysv/linux/sh/makecontext.S
+++ b/sysdeps/unix/sysv/linux/sh/makecontext.S
@@ -36,7 +36,7 @@ ENTRY(__makecontext)
 	mov.l	@(oSS_SP,r4), r1
 	mov.l	@(oSS_SIZE,r4), r2
 	add	r1, r2
-	cmp/gt	r6, r3
+	cmp/gt	r3, r6
 	bf/s	1f
 	 shlr2	r2
 	sub	r6, r2


During review of that file, I annotated the assembler code as in the
following -- enough to now have this in the mailing list archives or
would that be worth committing, too?

--- sysdeps/unix/sysv/linux/sh/makecontext.S	2012-06-14 11:39:40.326148740 +0200
+++ makecontext.S-with-comments	2012-06-14 11:52:15.890121058 +0200
@@ -34,49 +33,53 @@
 	.align	5
 ENTRY(__makecontext)
 	mov	#4, r3
-	mov.l	@(oSS_SP,r4), r1
-	mov.l	@(oSS_SIZE,r4), r2
-	add	r1, r2
-	cmp/gt	r3, r6
+	mov.l	@(oSS_SP,r4), r1        /* r1 <- ucb->stack_base */
+	mov.l	@(oSS_SIZE,r4), r2      /* r2 <- ucb->stack_size */
+	add	r1, r2                  /* r2 <- stack_top */
+#if ORIG
+	cmp/gt	r6, r3                  /* 4 > argc? */
+#else
+	cmp/gt	r3, r6                  /* argc > 4? */
+#endif
 	bf/s	1f
-	 shlr2	r2
+	 shlr2	r2                      /* r2 <- stack_top / 4 */
 	sub	r6, r2
 	add	r3, r2
 1:
-	shll2	r2
+	shll2	r2              /* r2 <- stack_top - ((argc > 4) ? 4 * (argc - 4) : 0 */
 	mov	#oR15, r0
 	mov.l	@(oLINK,r4), r1
-	mov.l	r2, @(r0,r4)
-	mov.l	r1, @(oR8,r4)
+	mov.l	r2, @(r0,r4)    /* ucp->r15 <- r2 */
+	mov.l	r1, @(oR8,r4)   /* ucp->r8 <- ucp->uc_link */
 	mov	#oPC, r0
-	mov.l	r5, @(r0,r4)
+	mov.l	r5, @(r0,r4)    /* ucp->PC <- func */
 
-	cmp/pl	r6
+	cmp/pl	r6              /* argc > 0? */
 	bf/s	.L1
 	 dt	r6
-	mov.l	r7, @(oR4,r4)
-	cmp/pl	r6
+	mov.l	r7, @(oR4,r4)   /* ucp->r4 <- argv[0] */
+	cmp/pl	r6              /* argc > 1? */
 	bf/s	.L1
 	 dt	r6
 	mov.l	@(0,r15), r1
-	mov.l	r1, @(oR5,r4)
-	cmp/pl	r6
+	mov.l	r1, @(oR5,r4)   /* ucp->r4 <- argv[1] */
+	cmp/pl	r6              /* argc > 2? */
 	bf/s	.L1
 	 dt	r6
 	mov.l	@(4,r15), r1
-	mov.l	r1, @(oR6,r4)
-	cmp/pl	r6
+	mov.l	r1, @(oR6,r4)   /* ucp->r5 <- argv[2] */
+	cmp/pl	r6              /* argc > 3? */
 	bf/s	.L1
 	 dt	r6
 	mov.l	@(8,r15), r1
-	mov.l	r1, @(oR7,r4)
+	mov.l	r1, @(oR7,r4)   /* ucp->r7 <- argv[3] */
 	mov	#12,r0
 .L0:
-	cmp/pl	r6
+	cmp/pl	r6              /* argc > 4...? */
 	bf/s	.L1
 	 dt	r6
 	mov.l	@(r0,r15), r1
-	mov.l	r1, @r2
+	mov.l	r1, @r2         /* ... */
 	add	#4, r0
 	bra	.L0
 	 add	#4, r2
@@ -88,7 +91,7 @@
 #endif
 	add	#oPR, r4
 	rts
-	 mov.l	r0, @r4
+	 mov.l	r0, @r4	        /* ucp->pr <- exitcode */
 #ifndef PIC
 	.align	2
 .L2:
@@ -103,9 +107,9 @@
 	mov.l	.Lgot, r12
 	add	r0, r12
 #endif
-	tst	r8, r8
+	tst	r8, r8          /* ucb->uc_link == NULL? */
 	bt/s	2f
-	 mov	r8, r4
+	 mov	r8, r4          /* r4 <- ucb->uc_link */
 	mov.l	.Lsetcontext, r1
 #ifdef PIC
 	bsrf	r1


GrÃÃe,
 Thomas

Attachment: pgp00000.pgp
Description: PGP signature


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]