execsp.S revision 1.2
11.2Sriastrad/* $NetBSD: execsp.S,v 1.2 2025/04/27 15:43:43 riastradh Exp $ */ 21.1Sriastrad 31.1Sriastrad/*- 41.1Sriastrad * Copyright (c) 2025 The NetBSD Foundation, Inc. 51.1Sriastrad * All rights reserved. 61.1Sriastrad * 71.1Sriastrad * Redistribution and use in source and binary forms, with or without 81.1Sriastrad * modification, are permitted provided that the following conditions 91.1Sriastrad * are met: 101.1Sriastrad * 1. Redistributions of source code must retain the above copyright 111.1Sriastrad * notice, this list of conditions and the following disclaimer. 121.1Sriastrad * 2. Redistributions in binary form must reproduce the above copyright 131.1Sriastrad * notice, this list of conditions and the following disclaimer in the 141.1Sriastrad * documentation and/or other materials provided with the distribution. 151.1Sriastrad * 161.1Sriastrad * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 171.1Sriastrad * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 181.1Sriastrad * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 191.1Sriastrad * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 201.1Sriastrad * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 211.1Sriastrad * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 221.1Sriastrad * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 231.1Sriastrad * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 241.1Sriastrad * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 251.1Sriastrad * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 261.1Sriastrad * POSSIBILITY OF SUCH DAMAGE. 271.1Sriastrad */ 281.1Sriastrad 291.1Sriastrad#define _LOCORE 301.1Sriastrad 311.1Sriastrad#include <machine/asm.h> 321.1Sriastrad 331.2SriastradRCSID("$NetBSD: execsp.S,v 1.2 2025/04/27 15:43:43 riastradh Exp $") 341.1Sriastrad 351.1Sriastrad/* 361.1Sriastrad * void execsp_start(struct ps_strings *ps_strings@r0, void *obj_main@r1, 371.1Sriastrad * void (*cleanup@r2)(void)) 381.1Sriastrad * 391.1Sriastrad * ELF entry point. Saves the stack pointer in startsp and defers 401.1Sriastrad * to the usual csu __start routine. 411.1Sriastrad */ 421.1SriastradENTRY(execsp_start) 431.2Sriastrad GOT_INIT(r3, .Lgot.execsp_start, .Lpc.execsp_start) 441.2Sriastrad mov r4, sp 451.2Sriastrad GOT_GET(r5, r3, .Lstartsp) 461.2Sriastrad str r4, [r5] 471.1Sriastrad b PLT_SYM(_C_LABEL(__start)) 481.1Sriastrad 491.1Sriastrad GOT_INITSYM(.Lgot.execsp_start, .Lpc.execsp_start) 501.1Sriastrad.Lstartsp: 511.1Sriastrad .word GOT_SYM(startsp) 521.1SriastradEND(execsp_start) 531.1Sriastrad 541.1Sriastrad/* 551.1Sriastrad * void execsp_ctor(void) 561.1Sriastrad * 571.1Sriastrad * ELF constructor. Saves the stack pointer in ctorsp and 581.1Sriastrad * returns. 591.1Sriastrad */ 601.1SriastradENTRY(execsp_ctor) 611.1Sriastrad GOT_INIT(r0, .Lgot.execsp_ctor, .Lpc.execsp_ctor) 621.1Sriastrad mov r1, sp 631.1Sriastrad GOT_GET(r2, r0, .Lctorsp) 641.1Sriastrad str r1, [r2] 651.1Sriastrad RET 661.1Sriastrad 671.1Sriastrad GOT_INITSYM(.Lgot.execsp_ctor, .Lpc.execsp_ctor) 681.1Sriastrad.Lctorsp: 691.1Sriastrad .word GOT_SYM(ctorsp) 701.1SriastradEND(execsp_ctor) 711.1Sriastrad 721.1Sriastrad /* Make execsp_ctor a constructor. */ 731.1Sriastrad .section .init_array,"aw",%init_array 741.1Sriastrad .p2align 2 751.1Sriastrad .word _C_LABEL(execsp_ctor) 761.1Sriastrad 771.1Sriastrad/* 781.1Sriastrad * int main(int argc@r0, char **argv@r1, ...) 791.1Sriastrad * 801.1Sriastrad * Main function. Saves the stack pointer in mainsp and returns 811.1Sriastrad * zero. We will call execsp_main in execsp_dtor once dtorsp has 821.1Sriastrad * been initialized. 831.1Sriastrad */ 841.1SriastradENTRY(main) 851.1Sriastrad GOT_INIT(r0, .Lgot.main, .Lpc.main) 861.1Sriastrad mov r1, sp 871.1Sriastrad GOT_GET(r2, r0, .Lmainsp) 881.1Sriastrad str r1, [r2] 891.1Sriastrad RET 901.1Sriastrad 911.1Sriastrad GOT_INITSYM(.Lgot.main, .Lpc.main) 921.1Sriastrad.Lmainsp: 931.1Sriastrad .word GOT_SYM(mainsp) 941.1SriastradEND(main) 951.1Sriastrad 961.1Sriastrad/* 971.1Sriastrad * void execsp_dtor(void) 981.1Sriastrad * 991.1Sriastrad * ELF destructor. Saves the stack pointer in dtorsp and defers 1001.1Sriastrad * to the C execsp_main in h_execsp.c to report the stack pointers 1011.1Sriastrad * back to the t_signal_and_sp parent. 1021.1Sriastrad */ 1031.1SriastradENTRY(execsp_dtor) 1041.1Sriastrad GOT_INIT(r0, .Lgot.execsp_dtor, .Lpc.execsp_dtor) 1051.1Sriastrad mov r1, sp 1061.1Sriastrad GOT_GET(r2, r0, .Ldtorsp) 1071.1Sriastrad str r1, [r2] 1081.1Sriastrad b PLT_SYM(_C_LABEL(execsp_main)) 1091.1Sriastrad 1101.1Sriastrad GOT_INITSYM(.Lgot.execsp_dtor, .Lpc.execsp_dtor) 1111.1Sriastrad.Ldtorsp: 1121.1Sriastrad .word GOT_SYM(dtorsp) 1131.1SriastradEND(execsp_dtor) 1141.1Sriastrad 1151.1Sriastrad /* Make execsp_ctor a destructor. */ 1161.1Sriastrad .section .fini_array,"aw",%fini_array 1171.1Sriastrad .p2align 2 1181.1Sriastrad .word _C_LABEL(execsp_dtor) 119