Rewrite init app in C, introduce MSL (MOP3 System Library)
All checks were successful
Build documentation / build-and-deploy (push) Successful in 35s

This commit is contained in:
2026-01-04 01:11:31 +01:00
parent 2c954a9ca9
commit e077d322f4
57 changed files with 214 additions and 120 deletions

View File

@@ -28,8 +28,8 @@
static bool hpet_32bits = 1;
/// Physical address for HPET MMIO
static uintptr_t hpet_paddr;
/// HPET nanoseconds for conversion
static uint64_t hpet_clock_nano;
/// HPET period in femtoseconds
static uint64_t hpet_period_fs;
/// Lock, which protects concurrent access. See \ref amd64/smp.c
static spin_lock_t hpet_lock = SPIN_LOCK_INIT;
@@ -54,32 +54,22 @@ static void amd64_hpet_write (uint32_t reg, uint64_t value) {
/// Read current value of \ref HPET_MCVR register.
static uint64_t amd64_hpet_timestamp (void) { return amd64_hpet_read (HPET_MCVR); }
/**
* @brief Get current HPET timestamp in nanoseconds
*
* @param lock
* if true, hold \ref hpet_lock
*/
uint64_t amd64_hpet_current_nano (bool lock) {
if (lock)
spin_lock (&hpet_lock);
uint64_t t = amd64_hpet_timestamp () * hpet_clock_nano;
if (lock)
spin_unlock (&hpet_lock);
return t;
}
/// Sleep for a given amount of microseconds. This time can last longer due to \ref hpet_lock being held.
void amd64_hpet_sleep_micro (uint64_t us) {
spin_lock (&hpet_lock);
uint64_t start = amd64_hpet_timestamp ();
uint64_t conv = us * 1000;
while (((amd64_hpet_timestamp () - start) * hpet_clock_nano) < conv)
uint64_t target_fs = us * 1000000000ULL;
for (;;) {
uint64_t current = amd64_hpet_timestamp ();
uint64_t dt = current - start;
if ((dt * hpet_period_fs) >= target_fs)
break;
__asm__ volatile ("pause" ::: "memory");
}
spin_unlock (&hpet_lock);
}
@@ -114,7 +104,5 @@ void amd64_hpet_init (void) {
gcidr = (((uint64_t)high << 32) | low);
}
uint64_t period_fs = (gcidr >> 32);
hpet_clock_nano = period_fs / 1000000;
hpet_period_fs = (gcidr >> 32);
}