mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-23 02:05:57 +01:00
x86 asm: mov
This commit is contained in:
41
README.adoc
41
README.adoc
@@ -11742,23 +11742,20 @@ As a quick reminder, the fastest setups to get started are:
|
|||||||
|
|
||||||
However, as usual, it is saner to build your toolchain as explained at: <<qemu-user-mode-getting-started>>.
|
However, as usual, it is saner to build your toolchain as explained at: <<qemu-user-mode-getting-started>>.
|
||||||
|
|
||||||
The first example that you want to run for each arch is:
|
The first examples that you want to run for each arch are:
|
||||||
|
|
||||||
....
|
* how to move data between registers and memory
|
||||||
./run --userland userland/arch/<arch>/add.S
|
* how to add two numbers!
|
||||||
....
|
|
||||||
|
|
||||||
e.g.:
|
These examples are located at:
|
||||||
|
|
||||||
....
|
* x86
|
||||||
./run --userland userland/arch/x86_64/add.S
|
** link:userland/arch/x86_64/add.S[]
|
||||||
....
|
** link:userland/arch/x86_64/mov.S[]
|
||||||
|
* arm
|
||||||
Sources:
|
** <<arm-mov-instruction>>
|
||||||
|
** link:userland/arch/arm/add.S[]
|
||||||
* link:userland/arch/x86_64/add.S[]
|
** link:userland/arch/aarch64/add.S[]
|
||||||
* link:userland/arch/arm/add.S[]
|
|
||||||
* link:userland/arch/aarch64/add.S[]
|
|
||||||
|
|
||||||
These examples use the venerable ADD instruction to:
|
These examples use the venerable ADD instruction to:
|
||||||
|
|
||||||
@@ -12288,15 +12285,7 @@ Bibliography: https://stackoverflow.com/questions/27147043/n-suffix-to-branch-in
|
|||||||
|
|
||||||
Arch agnostic infrastructure getting started at: <<userland-assembly>>.
|
Arch agnostic infrastructure getting started at: <<userland-assembly>>.
|
||||||
|
|
||||||
=== x86 userland assembly getting started
|
=== x86 SIMD
|
||||||
|
|
||||||
These are the main concepts and instructions that you should learn to be able to understand what is going on.
|
|
||||||
|
|
||||||
Once those are done, everything else left on userland is just to learn a huge list of instructions: <<x86-userland-assembly-instructions>>
|
|
||||||
|
|
||||||
=== x86 userland assembly instructions
|
|
||||||
|
|
||||||
==== x86 SIMD
|
|
||||||
|
|
||||||
History:
|
History:
|
||||||
|
|
||||||
@@ -12309,15 +12298,15 @@ History:
|
|||||||
* AVX2:2013
|
* AVX2:2013
|
||||||
* AVX-512: 2016. 512-bit ZMM registers. Extension of YMM.
|
* AVX-512: 2016. 512-bit ZMM registers. Extension of YMM.
|
||||||
|
|
||||||
===== x86 SSE2
|
==== x86 SSE2
|
||||||
|
|
||||||
====== x86 addpd instruction
|
===== x86 addpd instruction
|
||||||
|
|
||||||
link:userland/arch/x86_64/addpd.S[]: `addps`, `addpd`
|
link:userland/arch/x86_64/addpd.S[]: `addps`, `addpd`
|
||||||
|
|
||||||
Good first instruction to learn SIMD: <<simd-assembly>>
|
Good first instruction to learn SIMD: <<simd-assembly>>
|
||||||
|
|
||||||
====== x86 paddq instruction
|
===== x86 paddq instruction
|
||||||
|
|
||||||
link:userland/arch/x86_64/paddq.S[]: `paddq`, `paddl`, `paddw`, `paddb`
|
link:userland/arch/x86_64/paddq.S[]: `paddq`, `paddl`, `paddw`, `paddb`
|
||||||
|
|
||||||
|
|||||||
37
userland/arch/x86_64/mov.S
Normal file
37
userland/arch/x86_64/mov.S
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
/* https://github.com/cirosantilli/linux-kernel-module-cheat#userland-assembly */
|
||||||
|
|
||||||
|
#include <lkmc.h>
|
||||||
|
|
||||||
|
.data
|
||||||
|
myint: .long 0x12345678
|
||||||
|
LKMC_PROLOGUE
|
||||||
|
/* Immediate and register. */
|
||||||
|
mov $0, %rax
|
||||||
|
mov $1, %rax
|
||||||
|
LKMC_ASSERT_EQ(%rax, $1)
|
||||||
|
|
||||||
|
/* Register and register. */
|
||||||
|
mov $0, %rax
|
||||||
|
mov $1, %rbx
|
||||||
|
mov %rbx, %rax
|
||||||
|
LKMC_ASSERT_EQ(%rax, $1)
|
||||||
|
|
||||||
|
/* Memory and register. */
|
||||||
|
mov myint, %rax
|
||||||
|
LKMC_ASSERT_EQ(%rax, $0x12345678)
|
||||||
|
|
||||||
|
/* Memory and immediate. */
|
||||||
|
movl $0x9ABCDEF0, myint
|
||||||
|
LKMC_ASSERT_EQ(myint, $0x9ABCDEF0)
|
||||||
|
|
||||||
|
/* Memory via pointer to address. */
|
||||||
|
/* eax = &myint */
|
||||||
|
mov $myint, %rax
|
||||||
|
movl $0x11112222, (%rax)
|
||||||
|
LKMC_ASSERT_EQ(myint, $0x11112222)
|
||||||
|
|
||||||
|
/* Possible to move on itself, seems like a NOP and way to clear 32 high bits in x86-64:
|
||||||
|
* http://stackoverflow.com/questions/11910501/why-did-gcc-generate-mov-eax-eax-and-what-does-it-mean
|
||||||
|
*/
|
||||||
|
mov %rax, %rax
|
||||||
|
LKMC_EPILOGUE
|
||||||
Reference in New Issue
Block a user