userland/arch/aarch64/inline_asm/reg_var.c: use 64 bit variables

32-bit ones likely copy paste error from coming from arm v7.

Also create userland/arch/aarch64/inline_asm/int_32.c:

Also create aarch64_ldaxr_stlxr.cpp and start documenting LDAXR and STLXR.
This commit is contained in:
Ciro Santilli 六四事件 法轮功
2019-12-18 00:00:00 +00:00
parent c2c962e214
commit a59c773124
5 changed files with 87 additions and 20 deletions

View File

@@ -0,0 +1,15 @@
/* https://cirosantilli.com/linux-kernel-module-cheat#gcc-inline-assembly */
#include <assert.h>
#include <inttypes.h>
int main(void) {
uint32_t io = 1;
__asm__ (
"add %w[io], %w[io], 1;"
: [io] "+r" (io)
:
:
);
assert(io == 2);
}

View File

@@ -4,10 +4,10 @@
#include <inttypes.h>
int main(void) {
register uint32_t x0 __asm__ ("x0");
register uint32_t x1 __asm__ ("x1");
uint32_t new_x0;
uint32_t new_x1;
register uint64_t x0 __asm__ ("x0");
register uint64_t x1 __asm__ ("x1");
uint64_t new_x0;
uint64_t new_x1;
{
x0 = 1;
x1 = 2;

View File

@@ -0,0 +1,2 @@
#define LKMC_USERLAND_ATOMIC_LDAXR_STLXR 1
#include "main.hpp"

View File

@@ -51,11 +51,28 @@ void threadMain() {
:
:
);
#elif LKMC_USERLAND_ATOMIC_LDAXR_STLXR
// Was used by std::atomic before LDADD was added
uint64_t scratch64;
uint64_t scratch32;
__asm__ __volatile__ (
"1:"
"ldaxr %[scratch64], [%[addr]];"
"add %[scratch64], %[scratch64], 1;"
"stlxr %w[scratch32], %[scratch64], [%[addr]];"
"cbnz %w[scratch32], 1b;"
: "=m" (global), // indicate that global is modified
"+g" (i), // to prevent loop unrolling
[scratch64] "=&r" (scratch64),
[scratch32] "=&r" (scratch32)
: [addr] "r" (&global)
:
);
#elif LKMC_USERLAND_ATOMIC_AARCH64_LDADD
// https://cirosantilli.com/linux-kernel-module-cheat#arm-lse
__asm__ __volatile__ (
"ldadd %[inc], xzr, [%[addr]];"
: "=m" (global),
: "=m" (global), // indicate that global is modified
"+g" (i) // to prevent loop unrolling
: [inc] "r" (1),
[addr] "r" (&global)