1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 09:37:45 +00:00

Kernel: Add a Timer class for aarch64

For now, this can only query microseconds since boot.

Use this to print a timestamp every second. This busy-loops
until a second has passed. This might be a good first use of
interrupts soon.

qemu used to not implement this timer at some point, but
it seems to work fine even in qemu now (qemu v 5.2.0).
This commit is contained in:
Nico Weber 2021-10-02 15:50:23 -04:00 committed by Linus Groh
parent 496d2e3c29
commit bc213ad7a2
4 changed files with 91 additions and 1 deletions

View file

@ -6,6 +6,7 @@
#include <AK/Types.h>
#include <Kernel/Prekernel/Arch/aarch64/Mailbox.h>
#include <Kernel/Prekernel/Arch/aarch64/Timer.h>
#include <Kernel/Prekernel/Arch/aarch64/UART.h>
extern "C" [[noreturn]] void halt();
@ -24,7 +25,17 @@ extern "C" [[noreturn]] void init()
uart.print_num(firmware_version);
uart.print_str("\r\n");
halt();
auto& timer = Prekernel::Timer::the();
u64 start_musec = 0;
for (;;) {
u64 now_musec;
while ((now_musec = timer.microseconds_since_boot()) - start_musec < 1'000'000)
;
start_musec = now_musec;
uart.print_str("Timer: ");
uart.print_num(now_musec);
uart.print_str("\r\n");
}
}
// FIXME: Share this with the Intel Prekernel.