1*1e43641eSderaadt /* $OpenBSD: md_init.h,v 1.12 2023/11/18 16:26:16 deraadt Exp $ */ 2b2749fa9Spatrick 3b2749fa9Spatrick /*- 4b2749fa9Spatrick * Copyright (c) 2001 Ross Harvey 5b2749fa9Spatrick * All rights reserved. 6b2749fa9Spatrick * 7b2749fa9Spatrick * Redistribution and use in source and binary forms, with or without 8b2749fa9Spatrick * modification, are permitted provided that the following conditions 9b2749fa9Spatrick * are met: 10b2749fa9Spatrick * 1. Redistributions of source code must retain the above copyright 11b2749fa9Spatrick * notice, this list of conditions and the following disclaimer. 12b2749fa9Spatrick * 2. Redistributions in binary form must reproduce the above copyright 13b2749fa9Spatrick * notice, this list of conditions and the following disclaimer in the 14b2749fa9Spatrick * documentation and/or other materials provided with the distribution. 15b2749fa9Spatrick * 3. All advertising materials mentioning features or use of this software 16b2749fa9Spatrick * must display the following acknowledgement: 17b2749fa9Spatrick * This product includes software developed by the NetBSD 18b2749fa9Spatrick * Foundation, Inc. and its contributors. 19b2749fa9Spatrick * 4. Neither the name of The NetBSD Foundation nor the names of its 20b2749fa9Spatrick * contributors may be used to endorse or promote products derived 21b2749fa9Spatrick * from this software without specific prior written permission. 22b2749fa9Spatrick * 23b2749fa9Spatrick * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 24b2749fa9Spatrick * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 25b2749fa9Spatrick * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26b2749fa9Spatrick * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 27b2749fa9Spatrick * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28b2749fa9Spatrick * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29b2749fa9Spatrick * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30b2749fa9Spatrick * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31b2749fa9Spatrick * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32b2749fa9Spatrick * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33b2749fa9Spatrick * POSSIBILITY OF SUCH DAMAGE. 34b2749fa9Spatrick */ 35b2749fa9Spatrick 36b2749fa9Spatrick #define MD_SECT_CALL_FUNC(section, func) \ 37b2749fa9Spatrick __asm (".section "#section", \"ax\" \n" \ 38b2749fa9Spatrick " bl " #func " \n" \ 39b2749fa9Spatrick " .previous") 40b2749fa9Spatrick 41b2749fa9Spatrick #define MD_SECTION_PROLOGUE(sect, entry_pt) \ 42b2749fa9Spatrick __asm ( \ 43b2749fa9Spatrick ".section "#sect",\"ax\",%progbits \n" \ 44b2749fa9Spatrick " .globl " #entry_pt " \n" \ 45b2749fa9Spatrick " .type " #entry_pt ",%function \n" \ 46b2749fa9Spatrick " .align 4 \n" \ 47b2749fa9Spatrick #entry_pt": \n" \ 48e1c483ccSkettenis " bti c \n" \ 49b2749fa9Spatrick " sub sp, sp, #16 \n" \ 50b2749fa9Spatrick " str lr, [sp] \n" \ 51b2749fa9Spatrick " /* fall thru */ \n" \ 52b2749fa9Spatrick " .previous") 53b2749fa9Spatrick 54b2749fa9Spatrick 55b2749fa9Spatrick #define MD_SECTION_EPILOGUE(sect) \ 56b2749fa9Spatrick __asm ( \ 57b2749fa9Spatrick ".section "#sect",\"ax\",%progbits \n" \ 58b2749fa9Spatrick " ldr lr, [sp] \n" \ 59b2749fa9Spatrick " add sp, sp, #16 \n" \ 60b2749fa9Spatrick " ret \n" \ 61b2749fa9Spatrick " .previous") 62b2749fa9Spatrick 63b2749fa9Spatrick 64b2749fa9Spatrick #define MD_CRT0_START \ 65b2749fa9Spatrick __asm( \ 66b2749fa9Spatrick ".text \n" \ 67b2749fa9Spatrick " .align 0 \n" \ 68b2749fa9Spatrick " .globl _start \n" \ 69b2749fa9Spatrick " .globl __start \n" \ 70b2749fa9Spatrick "_start: \n" \ 71b2749fa9Spatrick "__start: \n" \ 72e1c483ccSkettenis " bti c \n" \ 73b2749fa9Spatrick " mov x3, x2 /* cleanup */ \n" \ 74b2749fa9Spatrick "/* Get argc/argv/envp from stack */ \n" \ 75b2749fa9Spatrick " ldr x0, [sp] \n" \ 76b2749fa9Spatrick " add x1, sp, #0x0008 \n" \ 77b2749fa9Spatrick " add x2, x1, x0, lsl #3 \n" \ 78b2749fa9Spatrick " add x2, x2, #0x0008 \n" \ 79b2749fa9Spatrick " \n" \ 80b2749fa9Spatrick " b ___start \n" \ 81b2749fa9Spatrick ".previous"); 82b2749fa9Spatrick 83b2749fa9Spatrick #define MD_RCRT0_START \ 84b2749fa9Spatrick char **environ, *__progname; \ 85b2749fa9Spatrick __asm( \ 86b2749fa9Spatrick ".text \n" \ 87b2749fa9Spatrick " .align 0 \n" \ 88b2749fa9Spatrick " .globl _start \n" \ 89b2749fa9Spatrick " .globl __start \n" \ 90b2749fa9Spatrick "_start: \n" \ 91b2749fa9Spatrick "__start: \n" \ 92b2749fa9Spatrick " mov fp, sp \n" \ 93b2749fa9Spatrick " mov x0, fp \n" \ 94b2749fa9Spatrick " \n" \ 95b2749fa9Spatrick " sub sp, sp, #8+8+(16*8) \n" \ 968a743555Skettenis " add x1, sp, #4 \n" \ 97b2749fa9Spatrick " \n" \ 984e61412aSkettenis " adrp x2, _DYNAMIC \n" \ 998a743555Skettenis " add x2, x2, #:lo12:_DYNAMIC \n" \ 100b2749fa9Spatrick " \n" \ 101b2749fa9Spatrick " bl _dl_boot_bind \n" \ 102b2749fa9Spatrick " \n" \ 103b2749fa9Spatrick " mov sp, fp \n" \ 104b2749fa9Spatrick " mov fp, #0 \n" \ 105b2749fa9Spatrick " \n" \ 106b2749fa9Spatrick " mov x3, #0 /* cleanup */ \n" \ 107b2749fa9Spatrick "/* Get argc/argv/envp from stack */ \n" \ 108b2749fa9Spatrick " ldr x0, [sp] \n" \ 109b2749fa9Spatrick " add x1, sp, #0x0008 \n" \ 110b2749fa9Spatrick " add x2, x1, x0, lsl #3 \n" \ 111b2749fa9Spatrick " add x2, x2, #0x0008 \n" \ 112b2749fa9Spatrick " \n" \ 113b2749fa9Spatrick " b ___start \n" \ 114b2749fa9Spatrick " \n" \ 115*1e43641eSderaadt "_csu_abort: \n" \ 1165bbf8832Snaddy " udf #0 \n" \ 117b2749fa9Spatrick ".previous"); 118