1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22/*
23 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
24 */
25
26#include <sys/asm_linkage.h>
27#include <brand_misc.h>
28
29#if defined(lint)
30
31/*ARGSUSED*/
32void
33brand_runexe(void *argv, ulong_t entry)
34{
35}
36
37#else	/* lint */
38	/*
39	 * Prepare to jump to the target program we actually want to run.
40	 * If this program is dynamically linked then we'll be jumping to
41	 * another copy of the linker.  If it's a statically linked program
42	 * we'll be jumping directy to it's main entry point.  In any case,
43	 * we need to reset our current state stack and register state to
44	 * something similar to the initial process state setup by the kernel
45	 * and documented at:
46	 *	usr/src/cmd/sgs/rtld/i386/boot.s
47	 *	usr/src/cmd/sgs/rtld/sparcv9/boot.s
48	 *
49	 * Of course this is the same stack format as when this executable
50	 * was first started, so here we'll just roll back the stack and
51	 * frame pointers to their values when this processes first started
52	 * execution.
53	 */
54	ENTRY_NP(brand_runexe)
55
56	movq	%rdi, %rax		/ %rax = &argv[0]
57	movq	%rsi, %rbx		/ Brand app entry point in %rbx
58	subq	$8, %rax		/ Top of stack - must point at argc
59	movq	%rax, %rsp		/ Set %rsp to what linkers expect
60
61	/*
62	 * We also have to make sure to clear %rdx since nornally ld.so.1 will
63	 * set that to non-zero if there is an exit function that should be
64	 * invoked when the process is terminating.  This isn't actually
65	 * necessary if the target program we're jumping to is a dynamically
66	 * linked program since in that case we're actually jumping to another
67	 * copy of ld.so.1 and it will just reset %rdx, but if the target
68	 * program we're jumping to is a statically linked binary that uses
69	 * the standard sun compiler supplied crt1.o`_start(), it will check
70	 * to see if %g1 is set.
71	 */
72	movq	$0, %rdx
73
74	jmp	*%rbx			/ And away we go...
75	/*
76	 * target will never return.
77	 */
78	SET_SIZE(brand_runexe)
79#endif	/* lint */
80