1/* start, OpenRISC version.
2 Copyright (C) 2022 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
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.
9
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.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
19
20/* This is the canonical entry point, usually the first thing in the text
21 segment.
22
23 sp The stack contains the arguments and environment:
24 0(sp) argc
25 4(sp) argv[0]
26 ...
27 (4*argc)(sp) NULL
28 (4*(argc+1))(sp) envp[0]
29 ...
30 NULL
31 */
32
33#define __ASSEMBLY__
34#include <sysdep.h>
35#include <entry.h>
36
37ENTRY (ENTRY_POINT)
38
39 /* Setup Arguments to the __libc_start_main function. */
40
41 /* Take values for argc and argv off the stack.
42 These will be passed as arguments two and three to main
43 and thus go in registers r4 and r5, respectively. */
44 l.lwz r4, 0(r1)
45 l.addi r5, r1, 4
46
47 /* Pass in rtld_fini from dl-start.S. */
48 l.or r8, r3, r3
49
50#ifdef PIC
51 /* Obtain a pointer to .got in r16 */
52 l.jal 0x8
53 l.movhi r16, gotpchi(_GLOBAL_OFFSET_TABLE_-4)
54 l.ori r16, r16, gotpclo(_GLOBAL_OFFSET_TABLE_+0)
55 l.add r16, r16, r9
56
57 /* Pass in the the main symbol. */
58 l.lwz r3, got(main)(r16)
59#else
60 /* Pass in the the main symbol. */
61 l.movhi r3, hi(main)
62 l.ori r3, r3, lo(main)
63#endif
64 /* Used to be init and fini. */
65 l.movhi r6, 0x0
66 l.movhi r7, 0x0
67
68 /* Push stack limit onto the stack.
69 This provides the highest stack address to user code (as stack grows
70 downwards.
71 This is the seventh argument to __libc_start_main and thus needs to
72 be passed on the stack. */
73 l.sw -4(r1), r1
74
75 /* Adjust stack to account for a total of 7 args (i.e. the last one is
76 on the stack. */
77 l.addi r1, r1, -4
78
79 /* Clear the frame pointer and link register since this is the
80 outermost frame. */
81 l.movhi r2, 0x0
82 l.movhi r9, 0x0
83
84 /* Let the libc call main and exit with its return code. */
85#ifdef PIC
86 l.j plt(__libc_start_main)
87#else
88 l.j __libc_start_main
89#endif
90 l.nop
91END (ENTRY_POINT)
92
93 /* Define a symbol for the first piece of initialized data. */
94 .data
95 .globl __data_start
96__data_start:
97 .long 0
98 .weak data_start
99 data_start = __data_start
100

source code of glibc/sysdeps/or1k/start.S