dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / cmd / sgs / rtld / amd64 / boot.s
blob7b64fb3416e78c635709767bb9f52c58ee867a58
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
20 * CDDL HEADER END
23 * Copyright (c) 1988 AT&T
24 * All Rights Reserved
27 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
28 * Use is subject to license terms.
30 #pragma ident "%Z%%M% %I% %E% SMI"
33 * Bootstrap routine for run-time linker.
34 * We get control from exec which has loaded our text and
35 * data into the process' address space and created the process
36 * stack.
38 * On entry, the process stack looks like this:
40 * # # <- %rsp
41 * #_______________________# high addresses
42 * # strings #
43 * #_______________________#
44 * # 0 word #
45 * #_______________________#
46 * # Auxiliary #
47 * # entries #
48 * # ... #
49 * # (size varies) #
50 * #_______________________#
51 * # 0 word #
52 * #_______________________#
53 * # Environment #
54 * # pointers #
55 * # ... #
56 * # (one word each) #
57 * #_______________________#
58 * # 0 word #
59 * #_______________________#
60 * # Argument # low addresses
61 * # pointers #
62 * # Argc words #
63 * #_______________________#
64 * # argc #
65 * #_______________________# <- %rbp
68 * We must calculate the address at which ld.so was loaded,
69 * find the addr of the dynamic section of ld.so, of argv[0], and of
70 * the process' environment pointers - and pass the thing to _setup
71 * to handle. We then call _rtld - on return we jump to the entry
72 * point for the a.out.
76 #include <link.h>
78 .file "boot.s"
79 .text
80 .globl _rt_boot
81 .globl _setup
82 .globl _GLOBAL_OFFSET_TABLE_
83 .type _rt_boot,@function
84 .align 4
86 _rt_alias:
87 / in case we were invoked from libc.so
88 jmp .get_got
89 _rt_boot:
90 / save for referencing args
91 movq %rsp,%rbp
92 / make room for a max sized boot vector
93 subq $EB_MAX_SIZE64,%rsp
94 / use esi as a pointer to &eb[0]
95 movq %rsp,%rsi
96 / set up tag for argv
97 movq $EB_ARGV,0(%rsi)
98 / get address of argv
99 leaq 8(%rbp),%rax
100 / put after tag
101 movq %rax,8(%rsi)
102 / set up tag for envp
103 movq $EB_ENVP,16(%rsi)
104 / get # of args
105 movq (%rbp),%rax
106 / one for the zero & one for argc
107 addq $2,%rax
108 / now points past args & @ envp
109 leaq (%rbp,%rax,8),%rdi
110 / set envp
111 movq %rdi,24(%rsi)
112 / next
113 .L0: addq $8,%rdi
114 / search for 0 at end of env
115 cmpq $0,-8(%rdi)
116 jne .L0
117 / set up tag for auxv
118 movq $EB_AUXV,32(%rsi)
119 / point to auxv
120 movq %rdi,40(%rsi)
121 / set up NULL tag
122 movq $EB_NULL,48(%rsi)
124 / arg1 - address of &eb[0]
125 movq %rsi, %rdi
126 .get_got:
127 leaq _GLOBAL_OFFSET_TABLE_(%rip), %rbx
128 / addq $_GLOBAL_OFFSET_TABLE_, %rbx
129 movq %rbx,%r9
130 // addq $[.L2-.L1], %rbx
131 movq %rbx,%r10
133 movq (%rbx),%rsi
135 / _setup(&eb[0], _DYNAMIC)
136 call _setup@PLT
137 / release stack frame
138 movq %rbp,%rsp
140 movq atexit_fini@GOTPCREL(%rip), %rdx
141 / transfer control to a.out
142 jmp *%rax
143 .size _rt_boot,.-_rt_boot