Skip to content

Commit 0f0f543

Browse files
authored
loongarch: add glibc start.S to make zig-bootstrap work for loongarch64-linux-gnu (#21015)
1 parent 9be10ea commit 0f0f543

File tree

5 files changed

+582
-0
lines changed

5 files changed

+582
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#ifndef _BITS_ENDIANNESS_H
2+
#define _BITS_ENDIANNESS_H 1
3+
4+
#ifndef _BITS_ENDIAN_H
5+
#error "Never use <bits/endianness.h> directly; include <endian.h> instead."
6+
#endif
7+
8+
/* LoongArch is little-endian. */
9+
#define __BYTE_ORDER __LITTLE_ENDIAN
10+
11+
#endif /* bits/endianness.h */
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/* Startup code compliant to the ELF LoongArch ABI.
2+
Copyright (C) 2022-2024 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+
In addition to the permissions in the GNU Lesser General Public
11+
License, the Free Software Foundation gives you unlimited
12+
permission to link the compiled version of this file with other
13+
programs, and to distribute those programs without any restriction
14+
coming from the use of this file. (The GNU Lesser General Public
15+
License restrictions do apply in other respects; for example, they
16+
cover modification of the file, and distribution when not linked
17+
into another program.)
18+
19+
Note that people who make modified versions of this file are not
20+
obligated to grant this special exception for their modified
21+
versions; it is their choice whether to do so. The GNU Lesser
22+
General Public License gives permission to release a modified
23+
version without this exception; this exception also makes it
24+
possible to release a modified version which carries forward this
25+
exception.
26+
27+
The GNU C Library is distributed in the hope that it will be useful,
28+
but WITHOUT ANY WARRANTY; without even the implied warranty of
29+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
30+
Lesser General Public License for more details.
31+
32+
You should have received a copy of the GNU Lesser General Public
33+
License along with the GNU C Library; if not, see
34+
<https://www.gnu.org/licenses/>. */
35+
36+
#define __ASSEMBLY__ 1
37+
#include <entry.h>
38+
#include <sys/asm.h>
39+
40+
/* The entry point's job is to call __libc_start_main. Per the ABI,
41+
a0 contains the address of a function to be passed to atexit.
42+
__libc_start_main wants this in a5. */
43+
44+
/*
45+
int
46+
__libc_start_main (int (*main) (int, char **, char **),
47+
int argc,
48+
char **argv,
49+
__typeof (main) init,
50+
void (*fini) (void),
51+
void (*rtld_fini) (void),
52+
void *stack_end);
53+
*/
54+
55+
ENTRY (ENTRY_POINT)
56+
57+
/* Terminate call stack by noting ra is undefined. Use a dummy
58+
.cfi_label to force starting the FDE. */
59+
.cfi_label .Ldummy
60+
cfi_undefined (1)
61+
or a5, a0, zero /* rtld_fini */
62+
63+
la.pcrel a0, t0, main
64+
REG_L a1, sp, 0
65+
ADDI a2, sp, SZREG
66+
67+
/* Adjust $sp for 16-aligned */
68+
BSTRINS sp, zero, 3, 0
69+
70+
move a3, zero /* used to be init */
71+
move a4, zero /* used to be fini */
72+
or a6, sp, zero /* stack_end */
73+
74+
la.pcrel ra, t0, __libc_start_main
75+
jirl ra, ra, 0
76+
77+
la.pcrel ra, t0, abort
78+
jirl ra, ra, 0
79+
END (ENTRY_POINT)
Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
/* Register Macro definitions
2+
Copyright (C) 2022-2024 Free Software Foundation, Inc.
3+
This file is part of the GNU C Library.
4+
5+
6+
The GNU C Library is free software; you can redistribute it and/or
7+
modify it under the terms of the GNU Lesser General Public
8+
License as published by the Free Software Foundation; either
9+
version 2.1 of the License, or (at your option) any later version.
10+
11+
The GNU C Library is distributed in the hope that it will be useful,
12+
but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+
Lesser General Public License for more details.
15+
16+
You should have received a copy of the GNU Lesser General Public
17+
License along with the GNU C Library. If not, see
18+
<https://www.gnu.org/licenses/>. */
19+
20+
#ifndef _SYS_REGDEF_H
21+
#define _SYS_REGDEF_H
22+
23+
#define zero $r0
24+
#define ra $r1
25+
#define tp $r2
26+
#define sp $r3
27+
#define a0 $r4
28+
#define a1 $r5
29+
#define a2 $r6
30+
#define a3 $r7
31+
#define a4 $r8
32+
#define a5 $r9
33+
#define a6 $r10
34+
#define a7 $r11
35+
#define v0 $r4
36+
#define v1 $r5
37+
#define t0 $r12
38+
#define t1 $r13
39+
#define t2 $r14
40+
#define t3 $r15
41+
#define t4 $r16
42+
#define t5 $r17
43+
#define t6 $r18
44+
#define t7 $r19
45+
#define t8 $r20
46+
#define x $r21
47+
#define fp $r22
48+
#define s0 $r23
49+
#define s1 $r24
50+
#define s2 $r25
51+
#define s3 $r26
52+
#define s4 $r27
53+
#define s5 $r28
54+
#define s6 $r29
55+
#define s7 $r30
56+
#define s8 $r31
57+
58+
#define fa0 $f0
59+
#define fa1 $f1
60+
#define fa2 $f2
61+
#define fa3 $f3
62+
#define fa4 $f4
63+
#define fa5 $f5
64+
#define fa6 $f6
65+
#define fa7 $f7
66+
#define fv0 $f0
67+
#define fv1 $f1
68+
#define ft0 $f8
69+
#define ft1 $f9
70+
#define ft2 $f10
71+
#define ft3 $f11
72+
#define ft4 $f12
73+
#define ft5 $f13
74+
#define ft6 $f14
75+
#define ft7 $f15
76+
#define ft8 $f16
77+
#define ft9 $f17
78+
#define ft10 $f18
79+
#define ft11 $f19
80+
#define ft12 $f20
81+
#define ft13 $f21
82+
#define ft14 $f22
83+
#define ft15 $f23
84+
#define fs0 $f24
85+
#define fs1 $f25
86+
#define fs2 $f26
87+
#define fs3 $f27
88+
#define fs4 $f28
89+
#define fs5 $f29
90+
#define fs6 $f30
91+
#define fs7 $f31
92+
#define fcc0 $fcc0
93+
#define fcc1 $fcc1
94+
#define fcc2 $fcc2
95+
#define fcc3 $fcc3
96+
#define fcc4 $fcc4
97+
#define fcc5 $fcc5
98+
#define fcc6 $fcc6
99+
#define fcc7 $fcc7
100+
#define fcsr0 $fcsr0
101+
102+
#define vr0 $vr0
103+
#define vr1 $vr1
104+
#define vr2 $vr2
105+
#define vr3 $vr3
106+
#define vr4 $vr4
107+
#define vr5 $vr5
108+
#define vr6 $vr6
109+
#define vr7 $vr7
110+
#define vr8 $vr8
111+
#define vr9 $vr9
112+
#define vr10 $vr10
113+
#define vr11 $vr11
114+
#define vr12 $vr12
115+
#define vr13 $vr13
116+
#define vr14 $vr14
117+
#define vr15 $vr15
118+
#define vr16 $vr16
119+
#define vr17 $vr17
120+
#define vr18 $vr18
121+
#define vr19 $vr19
122+
#define vr20 $vr20
123+
#define vr21 $vr21
124+
#define vr22 $vr22
125+
#define vr23 $vr23
126+
#define vr24 $vr24
127+
#define vr25 $vr25
128+
#define vr26 $vr26
129+
#define vr27 $vr27
130+
#define vr28 $vr28
131+
#define vr29 $vr29
132+
#define vr30 $vr30
133+
#define vr31 $vr31
134+
135+
#define xr0 $xr0
136+
#define xr1 $xr1
137+
#define xr2 $xr2
138+
#define xr3 $xr3
139+
#define xr4 $xr4
140+
#define xr5 $xr5
141+
#define xr6 $xr6
142+
#define xr7 $xr7
143+
#define xr7 $xr7
144+
#define xr8 $xr8
145+
#define xr9 $xr9
146+
#define xr10 $xr10
147+
#define xr11 $xr11
148+
#define xr12 $xr12
149+
#define xr13 $xr13
150+
#define xr14 $xr14
151+
#define xr15 $xr15
152+
#define xr16 $xr16
153+
#define xr17 $xr17
154+
#define xr18 $xr18
155+
#define xr19 $xr19
156+
#define xr20 $xr20
157+
#define xr21 $xr21
158+
#define xr22 $xr22
159+
#define xr23 $xr23
160+
#define xr24 $xr24
161+
#define xr25 $xr25
162+
#define xr26 $xr26
163+
#define xr27 $xr27
164+
#define xr28 $xr28
165+
#define xr29 $xr29
166+
#define xr30 $xr30
167+
#define xr31 $xr31
168+
169+
#endif /* _SYS_REGDEF_H */

0 commit comments

Comments
 (0)