stos/amd64: Add processor primitives

Signed-off-by: Chloe M. <chloe@mensia.org>
This commit is contained in:
Chloe M.
2026-06-23 20:13:49 +00:00
parent b6d4a1c963
commit 69ddd09500
2 changed files with 61 additions and 0 deletions
+43
View File
@@ -0,0 +1,43 @@
/*
* Copyright (c) 2026, Chloe M.
* Provided under the BSD-3 clause.
*
* Description: Processor primitives
* Author: Chloe M.
*/
#ifndef _MACHINE_PRIM_H_
#define _MACHINE_PRIM_H_ 1
#include <stdef.h>
#define MdCpuSuspend() ASMV("hlt")
#define MdCpuSpinWait() ASMV("pause")
/*
* Atomic swap operation
*
* @Ptr: Location to swap with @Value
* @Value: Value to swap to @Ptr
*/
ALWAYS_INLINE static inline QUAD
MdCpuAswap(QUAD *Ptr, QUAD Value)
{
QUAD RetVal;
if (Ptr == NULL) {
return 0;
}
RetVal = *(volatile QUAD *)Ptr;
ASMV(
"xchg %0, %1\n"
: "+m" (*Ptr), "+r" (Value)
:
: "memory"
);
return RetVal;
}
#endif /* !_MACHINE_PRIM_H_ */