Update to Unicode 15.0.0 [BZ #29604]
[glibc.git] / sysdeps / or1k / dl-start.S
blobe2c990c0e203d5ce3e5a60aa930721756426081d
1 /* Machine-dependent ELF startup code.  OpenRISC version.
2    Copyright (C) 2022 Free Software Foundation, Inc.
3    This file is part of the GNU C Library.
5    The GNU C Library is free software; you can redistribute it and/or
6    modify it under the terms of the GNU Lesser General Public
7    License as published by the Free Software Foundation; either
8    version 2.1 of the License, or (at your option) any later version.
10    The GNU C Library is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    Lesser General Public License for more details.
15    You should have received a copy of the GNU Lesser General Public
16    License along with the GNU C Library; if not, see
17    <https://www.gnu.org/licenses/>.  */
19 #include <sysdep.h>
21 /* Initial entry point code for the dynamic linker.
22    The function _dl_start is the real entry point;
23    it's return value is the user program's entry point.  */
24 ENTRY (_start)
25         /* Count arguments in r11 */
26         l.ori   r3, r1, 0
27         l.movhi r11, 0
29         l.addi  r3, r3, 4
30         l.lwz   r12, 0(r3)
31         l.sfnei r12, 0
32         l.addi  r11, r11, 1
33         l.bf    1b
34          l.nop
35         l.addi  r11, r11, -1
36         /* store argument counter to stack.  */
37         l.sw    0(r1), r11
39         /* Load the PIC register.  */
40         l.jal   0x8
41          l.movhi r16, gotpchi(_GLOBAL_OFFSET_TABLE_-4)
42         l.ori   r16, r16, gotpclo(_GLOBAL_OFFSET_TABLE_+0)
43         l.add   r16, r16, r9
45         l.ori   r3, r1, 0
47         l.jal   _dl_start
48          l.nop
49         /* Save user entry in a call saved reg.  */
50         l.ori   r22, r11, 0
51         /* Fall through to _dl_start_user.  */
53 _dl_start_user:
54         /* Set up for _dl_init.  */
56         /* Load _rtld_local (a.k.a _dl_loaded).  */
57         l.lwz   r12, got(_rtld_local)(r16)
58         l.lwz   r3, 0(r12)
60         /* Load argc */
61         l.lwz   r18, got(_dl_argc)(r16)
62         l.lwz   r4, 0(r18)
64         /* Load argv */
65         l.lwz   r20, got(_dl_argv)(r16)
66         l.lwz   r5, 0(r20)
68         /* Load envp = &argv[argc + 1].  */
69         l.slli  r6, r4, 2
70         l.addi  r6, r6, 4
71         l.add   r6, r6, r5
73         l.jal   plt(_dl_init)
74          l.nop
76         /* Now set up for user entry.
77            The already defined ABI loads argc and argv from the stack.
79            argc = 0(r1)
80            argv = r1 + 4
81         */
83         /* Load SP as argv - 4.  */
84         l.lwz   r3, 0(r20)
85         l.addi  r1, r3, -4
87         /* Save argc.  */
88         l.lwz   r3, 0(r18)
89         l.sw    0(r1), r3
91         /* Pass _dl_fini function address to _start.
92            Next start.S will then pass this as rtld_fini to __libc_start_main.  */
93         l.lwz   r3, got(_dl_fini)(r16)
95         l.jr    r22
96          l.nop
98 END (_start)