Skip to content

Commit d01869c

Browse files
wtarreaupaulmckrcu
authored andcommitted
tools/nolibc: add auxiliary vector retrieval for mips
In the _start block we now iterate over envp to find the auxiliary vector after the NULL. The pointer is saved into an _auxv variable that is marked as weak so that it's accessible from multiple units. Signed-off-by: Willy Tarreau <[email protected]> Signed-off-by: Paul E. McKenney <[email protected]>
1 parent 041fa97 commit d01869c

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

tools/include/nolibc/arch-mips.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ struct sys_stat_struct {
177177
})
178178

179179
char **environ __attribute__((weak));
180+
const unsigned long *_auxv __attribute__((weak));
180181

181182
/* startup code, note that it's called __start on MIPS */
182183
void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) __start(void)
@@ -196,6 +197,16 @@ void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) __start(void)
196197
"lui $a3, %hi(environ)\n" // load environ into a3 (hi)
197198
"addiu $a3, %lo(environ)\n" // load environ into a3 (lo)
198199
"sw $a2,($a3)\n" // store envp(a2) into environ
200+
201+
"move $t0, $a2\n" // iterate t0 over envp, look for NULL
202+
"0:" // do {
203+
"lw $a3, ($t0)\n" // a3=*(t0);
204+
"bne $a3, $0, 0b\n" // } while (a3);
205+
"addiu $t0, $t0, 4\n" // delayed slot: t0+=4;
206+
"lui $a3, %hi(_auxv)\n" // load _auxv into a3 (hi)
207+
"addiu $a3, %lo(_auxv)\n" // load _auxv into a3 (lo)
208+
"sw $t0, ($a3)\n" // store t0 into _auxv
209+
199210
"li $t0, -8\n"
200211
"and $sp, $sp, $t0\n" // sp must be 8-byte aligned
201212
"addiu $sp,$sp,-16\n" // the callee expects to save a0..a3 there!

0 commit comments

Comments
 (0)