1*1e43641eSderaadt /* $OpenBSD: md_init.h,v 1.12 2023/11/18 16:26:16 deraadt Exp $ */ 28d0ba7c9Sdrahn 38d0ba7c9Sdrahn /*- 48d0ba7c9Sdrahn * Copyright (c) 2001 Ross Harvey 58d0ba7c9Sdrahn * All rights reserved. 68d0ba7c9Sdrahn * 78d0ba7c9Sdrahn * Redistribution and use in source and binary forms, with or without 88d0ba7c9Sdrahn * modification, are permitted provided that the following conditions 98d0ba7c9Sdrahn * are met: 108d0ba7c9Sdrahn * 1. Redistributions of source code must retain the above copyright 118d0ba7c9Sdrahn * notice, this list of conditions and the following disclaimer. 128d0ba7c9Sdrahn * 2. Redistributions in binary form must reproduce the above copyright 138d0ba7c9Sdrahn * notice, this list of conditions and the following disclaimer in the 148d0ba7c9Sdrahn * documentation and/or other materials provided with the distribution. 158d0ba7c9Sdrahn * 3. All advertising materials mentioning features or use of this software 168d0ba7c9Sdrahn * must display the following acknowledgement: 178d0ba7c9Sdrahn * This product includes software developed by the NetBSD 188d0ba7c9Sdrahn * Foundation, Inc. and its contributors. 198d0ba7c9Sdrahn * 4. Neither the name of The NetBSD Foundation nor the names of its 208d0ba7c9Sdrahn * contributors may be used to endorse or promote products derived 218d0ba7c9Sdrahn * from this software without specific prior written permission. 228d0ba7c9Sdrahn * 238d0ba7c9Sdrahn * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 248d0ba7c9Sdrahn * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 258d0ba7c9Sdrahn * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 268d0ba7c9Sdrahn * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 278d0ba7c9Sdrahn * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 288d0ba7c9Sdrahn * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 298d0ba7c9Sdrahn * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 308d0ba7c9Sdrahn * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 318d0ba7c9Sdrahn * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 328d0ba7c9Sdrahn * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 338d0ba7c9Sdrahn * POSSIBILITY OF SUCH DAMAGE. 348d0ba7c9Sdrahn */ 358d0ba7c9Sdrahn 368d0ba7c9Sdrahn #define MD_SECT_CALL_FUNC(section, func) \ 378d0ba7c9Sdrahn __asm (".section "#section", \"ax\"\n" \ 388d0ba7c9Sdrahn " bl " #func "\n" \ 398d0ba7c9Sdrahn " .previous") 408d0ba7c9Sdrahn 418d0ba7c9Sdrahn #define MD_SECTION_PROLOGUE(sect, entry_pt) \ 428d0ba7c9Sdrahn __asm ( \ 438d0ba7c9Sdrahn ".section "#sect",\"ax\",@progbits \n" \ 448d0ba7c9Sdrahn " .globl " #entry_pt " \n" \ 458d0ba7c9Sdrahn " .type " #entry_pt ",@function \n" \ 468d0ba7c9Sdrahn " .align 4 \n" \ 478d0ba7c9Sdrahn #entry_pt": \n" \ 488d0ba7c9Sdrahn " stwu %r1,-16(%r1) \n" \ 498d0ba7c9Sdrahn " mflr %r0 \n" \ 508d0ba7c9Sdrahn " stw %r0,12(%r1) \n" \ 518d0ba7c9Sdrahn " /* fall thru */ \n" \ 528d0ba7c9Sdrahn " .previous") 538d0ba7c9Sdrahn 548d0ba7c9Sdrahn 558d0ba7c9Sdrahn #define MD_SECTION_EPILOGUE(sect) \ 568d0ba7c9Sdrahn __asm ( \ 578d0ba7c9Sdrahn ".section "#sect",\"ax\",@progbits \n" \ 588d0ba7c9Sdrahn " lwz %r0,12(%r1) \n" \ 598d0ba7c9Sdrahn " mtlr %r0 \n" \ 608d0ba7c9Sdrahn " addi %r1,%r1,16 \n" \ 618d0ba7c9Sdrahn " blr \n" \ 628d0ba7c9Sdrahn " .previous") 63453b49cdSguenther 64453b49cdSguenther #define MD_CRT0_START \ 65453b49cdSguenther __asm( \ 66453b49cdSguenther " .text \n" \ 67453b49cdSguenther " .section \".text\" \n" \ 68453b49cdSguenther " .align 2 \n" \ 69453b49cdSguenther " .globl _start \n" \ 70453b49cdSguenther " .type _start, @function \n" \ 71453b49cdSguenther " .globl __start \n" \ 72453b49cdSguenther " .type __start, @function \n" \ 73453b49cdSguenther "_start: \n" \ 74453b49cdSguenther "__start: \n" \ 7547ce292aSkettenis " # put cleanup in r6 instead of r7 \n" \ 7647ce292aSkettenis " mr %r6, %r7 \n" \ 77453b49cdSguenther " b ___start \n" \ 78453b49cdSguenther ) 7991b3131dSkurt 8091b3131dSkurt #define MD_RCRT0_START \ 8191b3131dSkurt __asm( \ 8291b3131dSkurt " .text \n" \ 8391b3131dSkurt " .section \".text\" \n" \ 8491b3131dSkurt " .align 2 \n" \ 8591b3131dSkurt " .globl _start \n" \ 8691b3131dSkurt " .type _start, @function \n" \ 8791b3131dSkurt " .globl __start \n" \ 8891b3131dSkurt " .type __start, @function \n" \ 8991b3131dSkurt "_start: \n" \ 9091b3131dSkurt "__start: \n" \ 9191b3131dSkurt " mr %r19, %r1 # save stack in r19 \n" \ 9291b3131dSkurt " stwu 1, (-16 -((9+3)*4))(%r1) # allocate dl_data \n" \ 9391b3131dSkurt " \n" \ 9491b3131dSkurt " # move argument registers to saved registers for startup flush \n" \ 9591b3131dSkurt " mr %r20, %r3 # argc \n" \ 9691b3131dSkurt " mr %r21, %r4 # argv \n" \ 9791b3131dSkurt " mr %r22, %r5 # envp \n" \ 9891b3131dSkurt " mflr %r27 /* save off old link register */ \n" \ 9991b3131dSkurt " stw %r27, 4(%r19) # save in normal location \n" \ 10091b3131dSkurt " \n" \ 1012955bdabSkettenis " bcl 20, 31, 1f \n" \ 1022955bdabSkettenis "1: mflr %r18 \n" \ 1032955bdabSkettenis " addis %r18, %r18, _DYNAMIC-1b@ha \n" \ 1042955bdabSkettenis " addi %r18, %r18, _DYNAMIC-1b@l \n" \ 10591b3131dSkurt " \n" \ 10691b3131dSkurt " subi %r3, %r21, 4 # Get stack pointer (arg0 for _dl_boot). \n" \ 10791b3131dSkurt " addi %r4, %r1, 8 # dl_data \n" \ 10891b3131dSkurt " mr %r5, %r18 # dynamicp \n" \ 10991b3131dSkurt " \n" \ 11091b3131dSkurt " bl _dl_boot_bind@local \n" \ 11191b3131dSkurt " \n" \ 11291b3131dSkurt " mtlr %r27 \n" \ 11391b3131dSkurt " # move argument registers back from saved registers \n" \ 11491b3131dSkurt " mr %r3, %r20 \n" \ 11591b3131dSkurt " mr %r4, %r21 \n" \ 11691b3131dSkurt " mr %r5, %r22 \n" \ 11791b3131dSkurt " li %r6, 0 \n" \ 11891b3131dSkurt " b ___start \n" \ 11991b3131dSkurt " \n" \ 12091b3131dSkurt " .text \n" \ 12191b3131dSkurt " .align 2 \n" \ 122*1e43641eSderaadt " .globl _csu_abort \n" \ 123*1e43641eSderaadt " .type _csu_abort, @function \n" \ 124*1e43641eSderaadt "_csu_abort: \n" \ 1252bc3a8c0Sderaadt " .long 0 # illegal \n" \ 12691b3131dSkurt ) 127