11.2Sriastrad/* $NetBSD: execsp.S,v 1.2 2025/04/27 16:49:54 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 16:49:54 riastradh Exp $") 341.1Sriastrad 351.1Sriastrad#include "SYS.h" 361.1Sriastrad 371.1Sriastrad .text 381.1Sriastrad 391.1Sriastrad/* 401.1Sriastrad * void execsp_start(void *stackpointer@a0, void (*cleanup@a1)(void), 411.1Sriastrad * void *obj_main@a2, struct ps_strings *ps_strings@a3) 421.1Sriastrad * 431.1Sriastrad * ELF entry point. Saves the stack pointer in startsp and defers 441.1Sriastrad * to the usual csu __start routine. 451.1Sriastrad */ 461.1SriastradLEAF(execsp_start) 471.1Sriastrad PIC_PROLOGUE(execsp_start) /* gp setup, sets t3 */ 481.1Sriastrad 491.1Sriastrad PTR_LA t1, _C_LABEL(startsp) /* load t1 := &startsp */ 501.1Sriastrad NOP_L /* load hazard */ 511.2Sriastrad PTR_S sp, 0(t1) /* store startsp := stack pointer */ 521.1Sriastrad 531.1Sriastrad PIC_TAILCALL(__start) /* gp restore, uses t3 */ 541.1SriastradEND(execsp_start) 551.1Sriastrad 561.1Sriastrad/* 571.1Sriastrad * void execsp_ctor(void) 581.1Sriastrad * 591.1Sriastrad * ELF constructor. Saves the stack pointer in ctorsp and 601.1Sriastrad * returns. 611.1Sriastrad */ 621.1SriastradLEAF(execsp_ctor) 631.1Sriastrad PIC_PROLOGUE(execsp_ctor) /* gp setup, sets t3 */ 641.1Sriastrad 651.1Sriastrad PTR_LA t1, _C_LABEL(ctorsp) /* load t1 := &ctorsp */ 661.1Sriastrad NOP_L /* load hazard */ 671.2Sriastrad PTR_S sp, 0(t1) /* store ctorsp := stack pointer */ 681.1Sriastrad 691.1Sriastrad PIC_RETURN() /* gp restore, uses t3 */ 701.1SriastradEND(execsp_ctor) 711.1Sriastrad 721.1Sriastrad /* Make execsp_ctor a constructor. */ 731.1Sriastrad .pushsection .ctors,"aw",@progbits 741.1Sriastrad .p2align PTR_SCALESHIFT 751.1Sriastrad PTR_WORD _C_LABEL(execsp_ctor) 761.1Sriastrad .popsection 771.1Sriastrad 781.1Sriastrad/* 791.1Sriastrad * int main(int argc@a0, char **argv@a1, ...) 801.1Sriastrad * 811.1Sriastrad * Main function. Saves the stack pointer in mainsp and returns 821.1Sriastrad * zero. We will call execsp_main in execsp_dtor once dtorsp has 831.1Sriastrad * been initialized. 841.1Sriastrad */ 851.1SriastradLEAF(main) 861.1Sriastrad PIC_PROLOGUE(main) /* gp setup, sets t3 */ 871.1Sriastrad 881.1Sriastrad PTR_LA t1, _C_LABEL(mainsp) /* load t1 := &mainsp */ 891.1Sriastrad NOP_L /* load hazard */ 901.2Sriastrad PTR_S sp, 0(t1) /* store mainsp := stack pointer */ 911.1Sriastrad 921.1Sriastrad move v0, zero /* return 0 */ 931.1Sriastrad 941.1Sriastrad PIC_RETURN() /* gp restore, uses t3 */ 951.1SriastradEND(main) 961.1Sriastrad 971.1Sriastrad/* 981.1Sriastrad * void execsp_dtor(void) 991.1Sriastrad * 1001.1Sriastrad * ELF destructor. Saves the stack pointer in dtorsp and defers 1011.1Sriastrad * to the C execsp_main in h_execsp.c to report the stack pointers 1021.1Sriastrad * back to the t_signal_and_sp parent. 1031.1Sriastrad */ 1041.1SriastradLEAF(execsp_dtor) 1051.1Sriastrad PIC_PROLOGUE(execsp_dtor) /* gp setup, sets t3 */ 1061.1Sriastrad 1071.1Sriastrad PTR_LA t1, _C_LABEL(dtorsp) /* load t1 := &dtorsp */ 1081.1Sriastrad NOP_L /* load hazard */ 1091.2Sriastrad PTR_S sp, 0(t1) /* store dtorsp := stack pointer */ 1101.1Sriastrad 1111.1Sriastrad PIC_TAILCALL(execsp_main) /* gp restore, uses t3 */ 1121.1SriastradEND(execsp_dtor) 1131.1Sriastrad 1141.1Sriastrad /* Make execsp_ctor a destructor. */ 1151.1Sriastrad .pushsection .dtors,"aw",@progbits 1161.1Sriastrad .p2align PTR_SCALESHIFT 1171.1Sriastrad PTR_WORD _C_LABEL(execsp_dtor) 1181.1Sriastrad .popsection 119