arm WFE: add some userland examples

This commit is contained in:
Ciro Santilli 六四事件 法轮功
2019-12-16 00:00:00 +00:00
parent 10946a7d80
commit 89a981aaf2
5 changed files with 119 additions and 2 deletions

View File

@@ -0,0 +1,12 @@
/* https://cirosantilli.com/linux-kernel-module-cheat#arm-wfe-and-sev-instructions */
.text
.global _start
_start:
asm_main_after_prologue:
wfe
/* exit */
mov x0, 0
mov x8, 93
svc 0

View File

@@ -0,0 +1,13 @@
/* https://cirosantilli.com/linux-kernel-module-cheat#arm-wfe-and-sev-instructions */
.text
.global _start
_start:
asm_main_after_prologue:
wfe
wfe
/* exit */
mov x0, 0
mov x8, 93
svc 0

View File

@@ -0,0 +1,29 @@
// https://cirosantilli.com/linux-kernel-module-cheat#arm-wfe-and-sev-instructions
#include <atomic>
#include <iostream>
#include <mutex>
#include <thread>
std::atomic_ulong done;
void myfunc() {
unsigned long new_val = 1;
__asm__ __volatile__ ("wfe;wfe;" : "+r" (new_val) : :);
done.store(new_val);
}
int main(int argc, char **argv) {
bool do_sev = true;
if (argc > 1) {
do_sev = (argv[1][0] != '0');
}
done.store(0);
std::thread thread;
thread = std::thread(myfunc);
while (!done.load()) {
if (do_sev)
__asm__ __volatile__ ("sev");
}
thread.join();
}