xref: /freebsd/stand/kboot/libkboot/arch/aarch64/start_arch.h (revision a03411e84728e9b267056fd31c7d1d9d1dc1b01e)
1*a03411e8SWarner Losh /*
2*a03411e8SWarner Losh  * Copyright (c) 2022, Netflix, Inc.
3*a03411e8SWarner Losh  *
4*a03411e8SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
5*a03411e8SWarner Losh  */
6*a03411e8SWarner Losh 
7*a03411e8SWarner Losh /*
8*a03411e8SWarner Losh  * Provides a _start routine that calls a _start_c routine that takes a pointer
9*a03411e8SWarner Losh  * to the stack as documented in crt1.c. We skip the pointer to _DYNAMIC since
10*a03411e8SWarner Losh  * we don't support dynamic libraries, at all. And while _start_c is our own
11*a03411e8SWarner Losh  * thing and doesn't have a second arg, we comport to the calling conventions
12*a03411e8SWarner Losh  * that glibc and musl have by passing x1 as 0 for the dynamic pointer. We
13*a03411e8SWarner Losh  * likely could call main directly with only a few more lines of code, but this
14*a03411e8SWarner Losh  * is simple enough and concentrates all the expressable in C stuff there.  We
15*a03411e8SWarner Losh  * also generate eh_frames should we need to debug things (it doesn't change the
16*a03411e8SWarner Losh  * genreated code, but leaves enough breadcrumbs to keep gdb happy)
17*a03411e8SWarner Losh  */
18*a03411e8SWarner Losh 
19*a03411e8SWarner Losh __asm__(
20*a03411e8SWarner Losh ".text\n"		/* ENTRY(_start) -- can't expand and stringify, so by hand */
21*a03411e8SWarner Losh ".align 2\n"
22*a03411e8SWarner Losh ".global _start\n"
23*a03411e8SWarner Losh ".type _start, #function\n"
24*a03411e8SWarner Losh "_start:\n"
25*a03411e8SWarner Losh ".cfi_startproc\n"
26*a03411e8SWarner Losh /*
27*a03411e8SWarner Losh  * Linux zeros all registers so x29 (frame pointer) and x30 (link register) are 0.
28*a03411e8SWarner Losh  */
29*a03411e8SWarner Losh "	mov	x0, sp\n"	/* Pointer to argc, etc kernel left on the stack */
30*a03411e8SWarner Losh "	and	sp, x0, #-16\n"	/* Align stack to 16-byte boundary */
31*a03411e8SWarner Losh "	b	_start_c\n"	/* Our MI code takes it from here */
32*a03411e8SWarner Losh /* NORETURN */
33*a03411e8SWarner Losh ".ltorg\n"		/* END(_start) */
34*a03411e8SWarner Losh ".cfi_endproc\n"
35*a03411e8SWarner Losh ".size _start, .-_start\n"
36*a03411e8SWarner Losh );
37