about summary refs log tree commit diff
path: root/sysdeps/or1k/dl-start.S
diff options
context:
space:
mode:
authorStafford Horne <shorne@gmail.com>2021-10-20 06:48:11 +0900
committerStafford Horne <shorne@gmail.com>2022-01-05 06:40:06 +0900
commitde5c0edc804b6f2b09c05a0bde1e6679d57e4ca4 (patch)
tree993270b256fa7e57c20872c5581469fc54e0462f /sysdeps/or1k/dl-start.S
parent6e5964311d57c017ed0af3d87095e54805f2541e (diff)
downloadglibc-de5c0edc804b6f2b09c05a0bde1e6679d57e4ca4.tar.gz
glibc-de5c0edc804b6f2b09c05a0bde1e6679d57e4ca4.tar.xz
glibc-de5c0edc804b6f2b09c05a0bde1e6679d57e4ca4.zip
or1k: startup and dynamic linking code
Code for C runtime startup and dynamic loading including PLT layout.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
Diffstat (limited to 'sysdeps/or1k/dl-start.S')
-rw-r--r--sysdeps/or1k/dl-start.S98
1 files changed, 98 insertions, 0 deletions
diff --git a/sysdeps/or1k/dl-start.S b/sysdeps/or1k/dl-start.S
new file mode 100644
index 0000000000..e2c990c0e2
--- /dev/null
+++ b/sysdeps/or1k/dl-start.S
@@ -0,0 +1,98 @@
+/* Machine-dependent ELF startup code.  OpenRISC version.
+   Copyright (C) 2022 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+#include <sysdep.h>
+
+/* Initial entry point code for the dynamic linker.
+   The function _dl_start is the real entry point;
+   it's return value is the user program's entry point.  */
+ENTRY (_start)
+	/* Count arguments in r11 */
+	l.ori	r3, r1, 0
+	l.movhi	r11, 0
+1:
+	l.addi	r3, r3, 4
+	l.lwz	r12, 0(r3)
+	l.sfnei	r12, 0
+	l.addi	r11, r11, 1
+	l.bf	1b
+	 l.nop
+	l.addi	r11, r11, -1
+	/* store argument counter to stack.  */
+	l.sw	0(r1), r11
+
+	/* Load the PIC register.  */
+	l.jal	0x8
+	 l.movhi r16, gotpchi(_GLOBAL_OFFSET_TABLE_-4)
+	l.ori	r16, r16, gotpclo(_GLOBAL_OFFSET_TABLE_+0)
+	l.add	r16, r16, r9
+
+	l.ori	r3, r1, 0
+
+	l.jal	_dl_start
+	 l.nop
+	/* Save user entry in a call saved reg.  */
+	l.ori	r22, r11, 0
+	/* Fall through to _dl_start_user.  */
+
+_dl_start_user:
+	/* Set up for _dl_init.  */
+
+	/* Load _rtld_local (a.k.a _dl_loaded).  */
+	l.lwz	r12, got(_rtld_local)(r16)
+	l.lwz	r3, 0(r12)
+
+	/* Load argc */
+	l.lwz	r18, got(_dl_argc)(r16)
+	l.lwz	r4, 0(r18)
+
+	/* Load argv */
+	l.lwz	r20, got(_dl_argv)(r16)
+	l.lwz	r5, 0(r20)
+
+	/* Load envp = &argv[argc + 1].  */
+	l.slli	r6, r4, 2
+	l.addi	r6, r6, 4
+	l.add	r6, r6, r5
+
+	l.jal	plt(_dl_init)
+	 l.nop
+
+	/* Now set up for user entry.
+	   The already defined ABI loads argc and argv from the stack.
+
+	   argc = 0(r1)
+	   argv = r1 + 4
+	*/
+
+	/* Load SP as argv - 4.  */
+	l.lwz	r3, 0(r20)
+	l.addi	r1, r3, -4
+
+	/* Save argc.  */
+	l.lwz	r3, 0(r18)
+	l.sw	0(r1), r3
+
+	/* Pass _dl_fini function address to _start.
+	   Next start.S will then pass this as rtld_fini to __libc_start_main.  */
+	l.lwz	r3, got(_dl_fini)(r16)
+
+	l.jr	r22
+	 l.nop
+
+END (_start)