1// Copyright 2017 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "asm.h"
6
7// Call the C _dl_start, which returns a dl_start_return_t containing the
8// user entry point and its argument.  Then jump to that entry point with
9// the argument in the first argument register, pushing a zero return
10// address and clearing the frame pointer register so the user entry point
11// is the base of the call stack.
12
13.hidden _start
14ENTRY(_start)
15    // We can be pretty sure that we were started with the stack pointer
16    // correctly aligned, which is (rsp % 16) = 8 at function entry.
17    // Since we'd need to adjust down by 8 to make an immediate call with
18    // correct stack alignment, it's just as cheap to explicitly align and
19    // then we're resilient to process setup not having given us the
20    // ABI-required alignment, just in case.
21    and $-16,%rsp
22    xor %rbp,%rbp
23
24    call _dl_start
25    mov %rax,%rdi
26    push %rbp                   // Zero in the return address slot.
27    jmp *%rdx
28END(_start)
29