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