ptos/amd64+hal: Add processor primitives
Signed-off-by: Chloe M <chloe@mensia.org>
This commit is contained in:
@@ -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_ */
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2026, Chloe M.
|
||||||
|
* Provided under the BSD-3 clause.
|
||||||
|
*
|
||||||
|
* Description: Processor primitives
|
||||||
|
* Author: Chloe M.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _HAL_PRIM_H_
|
||||||
|
#define _HAL_PRIM_H_ 1
|
||||||
|
|
||||||
|
#include <machine/prim.h>
|
||||||
|
#include <ptdef.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Suspend the current processor until the next
|
||||||
|
* interrupt.
|
||||||
|
*/
|
||||||
|
ALWAYS_INLINE static inline VOID
|
||||||
|
HalCpuSuspend(VOID)
|
||||||
|
{
|
||||||
|
MdCpuSuspend();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Hint to the processor core that it is in a spin
|
||||||
|
* loop.
|
||||||
|
*/
|
||||||
|
ALWAYS_INLINE static inline VOID
|
||||||
|
HalCpuSpinWait(VOID)
|
||||||
|
{
|
||||||
|
MdCpuSpinWait();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Perform an atomic swap operation
|
||||||
|
*
|
||||||
|
* @Ptr: Location to swap with @Value
|
||||||
|
* @Value: Value to swap with data at @Ptr
|
||||||
|
*/
|
||||||
|
ALWAYS_INLINE static inline VOID
|
||||||
|
HalCpuAswap(UQUAD *Ptr, UQUAD Value)
|
||||||
|
{
|
||||||
|
MdCpuAswap(Ptr, Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* !_HAL_PRIM_H_ */
|
||||||
Reference in New Issue
Block a user