1 /* $OpenBSD: md_init.h,v 1.9 2016/03/20 02:32:39 guenther Exp $ */ 2 3 /* 4 * Copyright (c) 2003 Dale Rahn. All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 */ 26 27 28 #ifdef __PIC__ 29 #define MD_SECT_CALL_FUNC(section, func) \ 30 __asm (".section "#section",\"ax\",@progbits \n" \ 31 " bl " #func ",%r2 \n" \ 32 " stw %r19,-80(%r30) \n" \ 33 " ldw -80(%r30),%r19 \n" \ 34 " .previous") 35 #else 36 #define MD_SECT_CALL_FUNC(section, func) \ 37 __asm (".section .rodata \n" \ 38 " .align 4 \n" \ 39 "L$" #func " \n" \ 40 " .word "#func " \n" \ 41 " .previous \n" \ 42 " .section "#section",\"ax\",@progbits \n" \ 43 " ldil LR'L$" #func ",%r1 \n" \ 44 " ldw RR'L$" #func "(%r1), %r31 \n" \ 45 " ble 0(%sr4,%r31) \n" \ 46 " copy %r31,%r2 \n" \ 47 " .previous") 48 #endif 49 50 #define MD_SECTION_PROLOGUE(sect, entry_pt) \ 51 __asm ( \ 52 " .section "#sect",\"ax\",@progbits \n" \ 53 " .EXPORT "#entry_pt",ENTRY,PRIV_LEV=3,ARGW0=NO,ARGW1=NO,ARGW2=NO,ARGW3=NO,RTNVAL=NO \n" \ 54 " .align 4 \n" \ 55 #entry_pt" \n" \ 56 " stw %r2, -20(%r30) \n" \ 57 " ldo 64(%r30),%r30 \n" \ 58 " /* fall thru */ \n" \ 59 " .previous") 60 61 62 #define MD_SECTION_EPILOGUE(sect) \ 63 __asm ( \ 64 " .section "#sect",\"ax\",@progbits \n" \ 65 " ldw -84(%r30),%r2 \n" \ 66 " bv %r0(%r2) \n" \ 67 " ldo -64(%r30),%r30 \n" \ 68 " .previous") 69 70 71 #include <sys/exec.h> /* for struct psstrings */ 72 73 #define MD_CRT0_START \ 74 __asm( \ 75 ".import $global$, data \n" \ 76 " .import ___start, code \n" \ 77 " .text \n" \ 78 " .align 4 \n" \ 79 " .export __start, entry \n" \ 80 " .type __start,@function \n" \ 81 " .label __start \n" \ 82 " .proc \n" \ 83 " .callinfo frame=0, calls \n" \ 84 " .entry \n" \ 85 " bl L$lpc, %r27 \n" \ 86 " depi 0, 31, 2, %r27 \n" \ 87 "L$lpc: addil L'$global$ - ($PIC_pcrel$0 - 8), %r27 \n" \ 88 " ldo R'$global$ - ($PIC_pcrel$0 - 12)(%r1),%r27 \n" \ 89 " .call \n" \ 90 " b ___start \n" \ 91 " copy %r27, %r19 \n" \ 92 " .exit \n" \ 93 " .procend") 94 95 96 #define MD_RCRT0_START \ 97 __asm( \ 98 ".import $global$, data \n" \ 99 " .import ___start, code \n" \ 100 " .text \n" \ 101 " .align 4 \n" \ 102 " .export __start, entry \n" \ 103 " .type __start,@function \n" \ 104 " .label __start \n" \ 105 " .proc \n" \ 106 " .callinfo frame=0, calls \n" \ 107 " .entry \n" \ 108 " copy %r3, %r1 \n" \ 109 " copy %sp, %r3 \n" \ 110 " stwm %r1, 64+16*4(%sp) \n" \ 111 " stw %arg0, -36(%r3) \n" \ 112 " bl 1f, %dp \n" \ 113 " depi 0, 31, 2, %dp \n" \ 114 "1: addil L'$global$ - ($PIC_pcrel$0 - 8), %dp \n" \ 115 " ldo R'$global$ - ($PIC_pcrel$0 - 12)(%r1), %dp \n" \ 116 " bl 1f, %arg2 \n" \ 117 " depi 0, 31, 2, %arg2 \n" \ 118 "1: addil L'_DYNAMIC - ($PIC_pcrel$0 - 8), %arg2 \n" \ 119 " ldo R'_DYNAMIC - ($PIC_pcrel$0 - 12)(%r1), %arg2 \n" \ 120 " stw %arg2, -40(%r3) \n" \ 121 " ldw 0(%arg0), %arg0 \n" \ 122 " ldo 4(%r3), %arg1 \n" \ 123 " ldo -4(%arg0), %arg0 \n" \ 124 " bl _dl_boot_bind, %rp \n" \ 125 " copy %dp, %r19 \n" \ 126 " ldw -36(%r3), %arg0 \n" \ 127 " copy %r0, %arg1 \n" \ 128 " ldo 64(%r3), %sp \n" \ 129 " ldwm -64(%sp), %r3 \n" \ 130 " .call \n" \ 131 " b ___start \n" \ 132 " copy %dp, %r19 \n" \ 133 " .exit \n" \ 134 " .procend \n" \ 135 " .export _dl_exit, entry \n" \ 136 " .type _dl_exit,@function \n" \ 137 " .label _dl_exit \n" \ 138 " .proc \n" \ 139 " .callinfo frame=0, calls \n" \ 140 " .entry \n" \ 141 "_dl_exit: \n" \ 142 " stw %rp, -24(%sp) \n" \ 143 " ldil L%0xc0000000, %r1 \n" \ 144 " ble 4(%sr7, %r1) \n" \ 145 " ldi 1, %t1 \n" \ 146 " comb,<> %r0, %t1, 1f \n" \ 147 " ldw -24(%sp), %rp \n" \ 148 " bv %r0(%rp) \n" \ 149 " nop \n" \ 150 "1: bv %r0(%rp) \n" \ 151 " sub %r0, %ret0, %ret0 \n" \ 152 " .exit \n" \ 153 " .procend \n" \ 154 " .export _dl_printf, entry \n" \ 155 " .type _dl_printf,@function \n" \ 156 " .label _dl_printf \n" \ 157 " .proc \n" \ 158 " .callinfo frame=0, calls \n" \ 159 " .entry \n" \ 160 "_dl_printf: \n" \ 161 " bv %r0(%rp) \n" \ 162 " nop \n" \ 163 " .exit \n" \ 164 " .procend") 165 166 167 #define MD_START_ARGS struct ps_strings *arginfo, void (*cleanup)(void) 168 #define MD_START_SETUP \ 169 char **argv, **envp; \ 170 int argc; \ 171 \ 172 argv = arginfo->ps_argvstr; \ 173 argc = arginfo->ps_nargvstr; \ 174 envp = arginfo->ps_envstr; 175 176 #define MD_EPROL_LABEL __asm (".export _eprol, entry\n\t.label _eprol") 177