1*f4b4f15bSkettenis/* $OpenBSD: ldasm.S,v 1.34 2019/07/01 15:57:34 kettenis Exp $ */ 289c547eeSrahnds 389c547eeSrahnds/* 489c547eeSrahnds * Copyright (c) 1999 Dale Rahn 589c547eeSrahnds * 689c547eeSrahnds * Redistribution and use in source and binary forms, with or without 789c547eeSrahnds * modification, are permitted provided that the following conditions 889c547eeSrahnds * are met: 989c547eeSrahnds * 1. Redistributions of source code must retain the above copyright 1089c547eeSrahnds * notice, this list of conditions and the following disclaimer. 1189c547eeSrahnds * 2. Redistributions in binary form must reproduce the above copyright 1289c547eeSrahnds * notice, this list of conditions and the following disclaimer in the 1389c547eeSrahnds * documentation and/or other materials provided with the distribution. 1489c547eeSrahnds * 1589c547eeSrahnds * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS 1689c547eeSrahnds * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 1789c547eeSrahnds * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1889c547eeSrahnds * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 1989c547eeSrahnds * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2089c547eeSrahnds * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2189c547eeSrahnds * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2289c547eeSrahnds * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2389c547eeSrahnds * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2489c547eeSrahnds * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2589c547eeSrahnds * SUCH DAMAGE. 2689c547eeSrahnds * 2789c547eeSrahnds */ 2889c547eeSrahnds 2989c547eeSrahnds#define AUX_entry 9 3089c547eeSrahnds 3189c547eeSrahnds#include <machine/asm.h> 328fcfbbf8Sdrahn#include <sys/syscall.h> 3389c547eeSrahnds 34c0197e40Sguenther .section .boot.text,"ax",@progbits 35c0197e40Sguenther .align 2 36c0197e40Sguenther .globl _dl_start 37c0197e40Sguenther .type _dl_start,@function 38c0197e40Sguenther_dl_start: 3989c547eeSrahnds mr 19, 1 407db17cdeSdrahn stwu 1, (-16 -((AUX_entry+3)*4))(1) # Some space. 4189c547eeSrahnds 4289c547eeSrahnds mflr 27 /* save off old link register */ 4389c547eeSrahnds stw 27, 4(19) /* save in normal location */ 4489c547eeSrahnds 4589c547eeSrahnds # squirrel away the arguments for main 4689c547eeSrahnds mr 20, 3 #argc 4789c547eeSrahnds mr 21, 4 #argv 4889c547eeSrahnds mr 22, 5 #envp 4989c547eeSrahnds mr 23, 6 # ??? 5089c547eeSrahnds 517fac78edSkettenis bcl 20, 31, 1f 527fac78edSkettenis1: mflr 30 537fac78edSkettenis addis 30, 30, _GLOBAL_OFFSET_TABLE_-1b@ha 547fac78edSkettenis addi 30, 30, _GLOBAL_OFFSET_TABLE_-1b@l 5589c547eeSrahnds 567fac78edSkettenis bcl 20, 31, 1f 57*f4b4f15bSkettenis1: mflr 18 587fac78edSkettenis addis 18, 18, _DYNAMIC-1b@ha 597fac78edSkettenis addi 18, 18, _DYNAMIC-1b@l 607fac78edSkettenis lwz 4, 0(30) # load address of _DYNAMIC according to got. 6109075f47Sdrahn sub 4, 18, 4 # determine load offset 6289c547eeSrahnds 6309075f47Sdrahn mr 17, 4 # save for _dl_boot 6489c547eeSrahnds 657db17cdeSdrahn subi 3, 21, 4 # Get stack pointer (arg0 for _dl_boot). 66e513d93fSdrahn addi 4, 1, 8 # dl_data 6709075f47Sdrahn mr 5, 18 # dynamicp 6889c547eeSrahnds 6989c547eeSrahnds bl _dl_boot_bind@local 7089c547eeSrahnds 7189c547eeSrahnds mr 3, 21 # argv 7289c547eeSrahnds mr 4, 22 # envp 7389c547eeSrahnds mr 5, 17 # loff 74e51a6280Sdrahn addi 6, 1, 8 # dl_data 7589c547eeSrahnds 7689c547eeSrahnds bl _dl_boot@local 7789c547eeSrahnds 7889c547eeSrahnds mtctr 3 # put return value into ctr to execute 7989c547eeSrahnds 8089c547eeSrahnds # get back the squirreled away the arguments for main 8189c547eeSrahnds mr 3, 20 8289c547eeSrahnds mr 4, 21 8389c547eeSrahnds mr 5, 22 8489c547eeSrahnds mr 6, 23 8589c547eeSrahnds 867fac78edSkettenis lwz 7, _dl_dtors@got(30) 8789c547eeSrahnds 8889c547eeSrahnds mtlr 27 8989c547eeSrahnds lwz 1, 0(1) # Restore stack pointer. 9089c547eeSrahnds bctr # Go execute the 'real' program. 91c0197e40SguentherEND(_dl_start) 9289c547eeSrahnds 93ddabb23eSdrahnENTRY(_dl_bind_start) 941f6e7696Smiod stwu 1,-72(1) 95ddabb23eSdrahn 96ddabb23eSdrahn stw 0,8(1) # save r0 - cerror ;-) 97ddabb23eSdrahn mflr 0 98ddabb23eSdrahn stw 0,68(1) # save lr 99ddabb23eSdrahn 100ddabb23eSdrahn stw 3,12(1) # save r3-r10, C calling convention 101ddabb23eSdrahn stw 4,20(1) # r13 - r31 are preserved by called code 102ddabb23eSdrahn stw 5,24(1) 103ddabb23eSdrahn stw 6,28(1) 104ddabb23eSdrahn stw 7,32(1) 105ddabb23eSdrahn stw 8,36(1) 106ddabb23eSdrahn stw 9,40(1) 107ddabb23eSdrahn stw 10,44(1) 108ddabb23eSdrahn 109ddabb23eSdrahn mr 3,12 # obj 110ddabb23eSdrahn mr 4,11 # reloff 111ddabb23eSdrahn bl _dl_bind@plt # _rtld_bind(obj, reloff) 112ddabb23eSdrahn mtctr 3 113ddabb23eSdrahn 114ddabb23eSdrahn lwz 3,12(1) 115ddabb23eSdrahn lwz 4,20(1) 116ddabb23eSdrahn lwz 5,24(1) 117ddabb23eSdrahn lwz 6,28(1) 118ddabb23eSdrahn lwz 7,32(1) 119ddabb23eSdrahn lwz 8,36(1) 120ddabb23eSdrahn lwz 9,40(1) 121ddabb23eSdrahn lwz 10,44(1) 122ddabb23eSdrahn 123ddabb23eSdrahn lwz 0,68(1) # restore lr 124ddabb23eSdrahn mtlr 0 125ddabb23eSdrahn lwz 0,8(1) 126ddabb23eSdrahn 1271f6e7696Smiod addi 1,1,72 128ddabb23eSdrahn bctr 129c0197e40SguentherEND(_dl_bind_start) 130