m1x/x86_64: Implement processor primitives

Signed-off-by: Ian Moffett <ian@mirocom.org>
This commit is contained in:
2026-03-25 22:15:46 -04:00
parent 5b7cc41d32
commit 47fcd53739
3 changed files with 53 additions and 0 deletions

View File

@@ -0,0 +1,46 @@
/*
* Copyright (c) 2026, Mirocom Laboratories
* Provided under the BSD-3 clause
*/
#ifndef _MACHINE_PRIM_H_
#define _MACHINE_PRIM_H_ 1
#include <sys/types.h>
#include <sys/cdefs.h>
/* Hint to the processor that we are in a spinloop */
#define hal_cpu_spinwait() \
__asmv("pause" ::: "memory")
/* Halt the current processor core */
#define hal_cpu_halt() \
__asmv("hlt" ::: "memory")
/*
* Atomic swap operation
*
* @p: Location to swap with `v`
* @v: Value to swap to `p`
*/
__always_inline static inline size_t
hal_cpu_aswap(size_t *p, size_t v)
{
size_t vret;
if (p == NULL) {
return 0;
}
vret = *(volatile size_t *)p;
__asmv(
"xchg %0, %1\n"
: "+m" (*p), "+r" (v)
:
: "memory"
);
return vret;
}
#endif /* !_MACHINE_PRIM_H_ */

View File

@@ -6,6 +6,12 @@
#ifndef _HAL_CPU_H_
#define _HAL_CPU_H_ 1
/*
* Each architecture is to implement their own version
* of the standard processor primitives.
*/
#include <machine/prim.h>
/*
* Initialize the current processor
*/

View File

@@ -17,6 +17,7 @@ CFLAGS = \
-MMD \
-I../../sdk/include/ \
-I../include/ \
-I../target/ \
-I../foreign/flanterm/src \
-DPRINTF_DISABLE_SUPPORT_PTRDIFF_T \
-DPRINTF_DISABLE_SUPPORT_FLOAT \