ptos/amd64+hal: Add processor primitives

Signed-off-by: Chloe M <chloe@mensia.org>
This commit is contained in:
2026-07-10 21:07:24 -04:00
parent eb009076b2
commit abad8f8cfe
2 changed files with 90 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 <ptdef.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 UQUAD
MdCpuAswap(UUQUAD *Ptr, UQUAD Value)
{
UQUAD RetVal;
if (Ptr == NULL) {
return 0;
}
RetVal = *(volatile UQUAD *)Ptr;
ASMV(
"xchg %0, %1\n"
: "+m" (*Ptr), "+r" (Value)
:
: "memory"
);
return RetVal;
}
#endif /* !_MACHINE_PRIM_H_ */