/*
	This file is part of Lynx Bootloader.

	Lynx Bootloader is free software: you can redistribute it and/or
	modify it under the terms of the GNU General Public License as
	published by the Free Software Foundation, either version 3 of
	the License, or (at your option) any later version.

	Lynx Bootloader 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 General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with Lynx Bootloader. If not, see <https://www.gnu.org/licenses/>.
*/

.section ".text.boot"

.extern __bss_start
.extern __bss_end
.extern __bss_size

.global _start
_start:
	/* Keep only the main core */
	mrs x1, mpidr_el1
	and x1, x1, #3
	cbz x1, 2f

	/* Halt */
1:	wfe
	b 1b

	/* Initialize the stack */
2:	ldr x1, =_start
	mov sp, x1

	/* Clear the BSS */
	ldr x1, =__bss_start
	ldr w2, =__bss_size
3:	cbz w2, 4f
	str xzr, [x1], #8
	sub w2, w2, #1
	cbnz w2, 3b

	/* Start the kernel */
4:	bl _aarch64_start
	b 1b
