1256905Sray/* $OpenBSD: ldasm.S,v 1.32 2017/08/27 21:59:52 deraadt Exp $ */ 2256905Sray 3256905Sray/* 4256905Sray * Copyright (c) 2002 Dale Rahn 5256905Sray * All rights reserved. 6256905Sray * 7256905Sray * Redistribution and use in source and binary forms, with or without 8256905Sray * modification, are permitted provided that the following conditions 9256905Sray * are met: 10256905Sray * 1. Redistributions of source code must retain the above copyright 11256905Sray * notice, this list of conditions and the following disclaimer. 12256905Sray * 2. Redistributions in binary form must reproduce the above copyright 13256905Sray * notice, this list of conditions and the following disclaimer in the 14256905Sray * documentation and/or other materials provided with the distribution. 15256905Sray * 16256905Sray * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS 17256905Sray * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18256905Sray * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19256905Sray * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 20256905Sray * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21256905Sray * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22256905Sray * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23256905Sray * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24256905Sray * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25256905Sray * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26256905Sray * SUCH DAMAGE. 27256905Sray * 28256905Sray */ 29256905Sray 30256905Sray 31256905Sray#define DL_DATA_SIZE (16*4) 32256905Sray#include <sys/syscall.h> 33256905Sray#include <machine/asm.h> 34256905Sray 35256905Sray .text 36256905Sray .align 16,0xcc 37256905Sray .globl _dl_start 38256905Sray .type _dl_start,@function 39256905Sray_dl_start: 40256905Sray movl %esp,%eax # save stack pointer for _rtld 41256905Sray subl $DL_DATA_SIZE,%esp # allocate dl_data 42256905Sray call 1f # push &_DYNAMIC... 43256905Sray1: addl $(_DYNAMIC-1b),(%esp) # ...for dl_boot_bind 44256905Sray movl %esp,%ebx 45256905Sray movl %ebx,%edi # save dl_data arg for dl_boot 46256905Sray pushl %ebx # push dl_data for dl_boot_bind 47256905Sray 48256905Sray mov %eax, %esi # save stack for dl_boot 49256905Sray 50256905Sray pushl %eax # load saved SP for dl_boot_bind 51256905Sray 52256905Sray call _dl_boot_bind@PLT # _dl_boot_bind(sp,dl_data) 53256905Sray 54256905Sray pushl %edi # push saved dl_data 55256905Sray movl %edi,%ebp 56256905Sray movl (7*4)(%ebp),%eax 57256905Sray pushl %eax # push loff from dl_data 58256905Sray 59256905Sray movl %esi,%ebp 60256905Sray movl $4,%eax 61256905Sray imull 0(%ebp),%eax 62256905Sray addl $8,%eax 63256905Sray addl %ebp,%eax 64256905Sray push %eax # push envp 65256905Sray 66256905Sray leal 4(%ebp),%eax 67256905Sray push %eax # push argv 68256905Sray 69256905Sray call _dl_boot@PLT # _dl_boot(argv,envp,loff,dl_data) 70256905Sray 71256905Sray addl $7*4,%esp # pop args 72256905Sray 73256905Sray addl $DL_DATA_SIZE,%esp # return dl_data 74256905Sray 75256905Sray call 1f # %edx = cleanup 76256905Sray1: popl %ebx 77256905Sray addl $_GLOBAL_OFFSET_TABLE_+[.-1b], %ebx 78256905Sray leal _dl_dtors@GOTOFF(%ebx), %edx 79256905Sray 80256905Sray jmp *%eax 81256905Sray 82256905Sray .align 16,0xcc 83256905Sray .global _dl_bind_start 84256905Sray .type _dl_bind_start,@function 85256905Sray_dl_bind_start: 86256905Sray pushf # save registers 87256905Sray pushl %eax 88256905Sray pushl %ecx 89256905Sray pushl %edx 90256905Sray pushl %ebx 91256905Sray pushl %ebp 92256905Sray pushl %esi 93256905Sray pushl %edi 94256905Sray pushl %ds 95256905Sray pushl %es 96256905Sray 97256905Sray pushl 44(%esp) # Copy of reloff 98256905Sray pushl 44(%esp) # Copy of obj 99256905Sray call _dl_bind@PLT # Call the binder 100256905Sray addl $8,%esp # pop binder args 101256905Sray movl %eax,44(%esp) # Store function to be called in obj 102256905Sray 103256905Sray popl %es # restore registers 104256905Sray popl %ds 105256905Sray popl %edi 106256905Sray popl %esi 107256905Sray popl %ebp 108256905Sray popl %ebx 109256905Sray popl %edx 110256905Sray popl %ecx 111256905Sray popl %eax 112256905Sray popf 113256905Sray 114256905Sray leal 4(%esp),%esp # Discard reloff, do not change eflags 115256905Sray ret 116256905Sray