1/*
2 * Copyright 2021, Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 *
5 */
6
7#include <OS.h>
8#include <boot/platform.h>
9/*
10#include <boot/stdio.h>
11#include <boot/kernel_args.h>
12#include <boot/stage2.h>
13#include <arch/cpu.h>
14#include <arch_kernel.h>
15#include <arch_system_info.h>
16#include <string.h>
17*/
18
19extern "C" status_t
20boot_arch_cpu_init(void)
21{
22	return B_OK;
23}
24
25
26extern "C" void
27arch_ucode_load(BootVolume& volume)
28{
29	// Yes, we have no bananas!
30}
31
32
33extern "C" bigtime_t
34system_time()
35{
36
37	#warning Implement system_time in ARM64 bootloader!
38	//https://en.wikipedia.org/wiki/Time_Stamp_Counter
39	// read system time register:  cntpct_el0 / cntvct_el0
40	// frequency of the system timer can be discovered by reading cntfrq_el0
41	// https://wiki.osdev.org/ARMv7_Generic_Timers#CNTPCT
42
43	uint64_t ticks;
44	__asm__ volatile("mrs %0, cntpct_el0" : "=r"(ticks));
45	//conversion factor stuff
46	return ticks;
47	//return u64_mul_u64_fp32_64(ticks, ns_per_cntpct);
48}
49
50
51extern "C" void
52spin(bigtime_t microseconds)
53{
54	auto time = system_time();
55
56	while ((system_time() - time) < microseconds)
57		asm volatile ("yield;");
58}
59