1 /* $OpenBSD: md_init.h,v 1.5 2016/03/24 05:27:19 guenther Exp $ */ 2 3 /* 4 * Copyright (c) 2012 Miodrag Vallat. 5 * 6 * Permission to use, copy, modify, and distribute this software for any 7 * purpose with or without fee is hereby granted, provided that the above 8 * copyright notice and this permission notice appear in all copies. 9 * 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 */ 18 19 #define MD_SECT_CALL_FUNC(section, func) __asm ( \ 20 "\t.section\t" #section ",\"ax\",@progbits\n" \ 21 "\tbsr\t" #func "\n" \ 22 "\t.previous") 23 24 #define MD_SECTION_PROLOGUE(section, entry) __asm ( \ 25 "\t.section\t" #section ",\"ax\",@progbits\n" \ 26 "\t.globl\t" #entry "\n" \ 27 "\t.type\t" #entry ",@function\n" \ 28 "\t.align\t2\n" \ 29 #entry ":\n" \ 30 "\tsubu\t%r31, %r31, 16\n" \ 31 "\tst\t%r1, %r31, 0\n" \ 32 "\t.previous") 33 34 #define MD_SECTION_EPILOGUE(section) __asm( \ 35 "\t.section\t" #section ",\"ax\",@progbits\n" \ 36 "\tld\t%r1, %r31, 0\n" \ 37 "\tjmp.n\t%r1\n" \ 38 "\taddu\t%r31, %r31, 16\n" \ 39 "\t.previous") 40 41 /* 42 * When a program begins, r31 points to a structure passed by the kernel. 43 * 44 * This structure contains argc, the argv[] NULL-terminated array, and 45 * the envp[] NULL-terminated array. 46 * 47 * Our start code starts with two nops because execution may skip up to 48 * two instructions; see setregs() in the kernel for details. 49 * 50 * The definitions of environ and __progname prevent the creation 51 * of COPY relocations for WEAK symbols. 52 */ 53 #define MD_CRT0_START \ 54 char **environ, *__progname; \ 55 __asm( \ 56 " .text \n" \ 57 " .align 3 \n" \ 58 " .globl __start \n" \ 59 " .globl _start \n" \ 60 "__start: \n" \ 61 "_start: \n" \ 62 " or %r0, %r0, %r0 \n" \ 63 " or %r0, %r0, %r0 \n" \ 64 " ld %r2, %r31, 0 /* argc */ \n" \ 65 " addu %r3, %r31, 4 /* argv */ \n" \ 66 " lda %r4, %r3[%r2] \n" \ 67 " br.n ___start \n" \ 68 " addu %r4, %r4, 4 \n" \ 69 " /* envp = argv + argc + 1 */ \n" \ 70 " .previous"); 71