mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-23 02:05:57 +01:00
arm WFE: add some userland examples
This commit is contained in:
12
userland/arch/aarch64/freestanding/linux/wfe.S
Normal file
12
userland/arch/aarch64/freestanding/linux/wfe.S
Normal 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
|
||||
13
userland/arch/aarch64/freestanding/linux/wfe_wfe.S
Normal file
13
userland/arch/aarch64/freestanding/linux/wfe_wfe.S
Normal 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
|
||||
29
userland/arch/aarch64/inline_asm/wfe_sev.cpp
Normal file
29
userland/arch/aarch64/inline_asm/wfe_sev.cpp
Normal 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();
|
||||
}
|
||||
Reference in New Issue
Block a user