mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-27 12:04:27 +01:00
gas data sizes
This commit is contained in:
61
README.adoc
61
README.adoc
@@ -9,7 +9,7 @@
|
|||||||
:toclevels: 6
|
:toclevels: 6
|
||||||
:toc-title:
|
:toc-title:
|
||||||
|
|
||||||
The perfect emulation setup to study and develop the <<linux-kernel>>, kernel modules, <<qemu-buildroot-setup,QEMU>> and <<userland-assembly,userland>> and <<baremetal-setup,baremetal>> assembly. Highly automated. Thoroughly documented. <<gdb>> and <<kgdb>> just work. Automated <<test-this-repo,tests>>. Powered by <<about-the-qemu-buildroot-setup,Buildroot>> and <<about-the-baremetal-setup,crosstool-NG>>. "Tested" in Ubuntu 18.04 host, x86_64, ARMv7 and ARMv8 guests with kernel v5.0.
|
The perfect emulation setup to study and develop the <<linux-kernel>> v5.0, kernel modules, <<qemu-buildroot-setup,QEMU>> and x86_64, ARMv7 and ARMv8 <<userland-assembly,userland>> and <<baremetal-setup,baremetal>> assembly. <<gdb>> and <<kgdb>> just work. Powered by <<about-the-qemu-buildroot-setup,Buildroot>> and <<about-the-baremetal-setup,crosstool-NG>>. Highly automated. Thoroughly documented. Automated <<test-this-repo,tests>>. "Tested" in an Ubuntu 18.04 host.
|
||||||
|
|
||||||
TL;DR: <<qemu-buildroot-setup-getting-started>>
|
TL;DR: <<qemu-buildroot-setup-getting-started>>
|
||||||
|
|
||||||
@@ -11603,7 +11603,7 @@ and notice how the error message gives both:
|
|||||||
* the actual assembly source line number where the failing assert was
|
* the actual assembly source line number where the failing assert was
|
||||||
* the actual and expected values
|
* the actual and expected values
|
||||||
|
|
||||||
Other setup sanity checks that you might want to look into include:
|
Other infrastructure sanity checks that you might want to look into include:
|
||||||
|
|
||||||
* link:userland/arch/empty.S[]
|
* link:userland/arch/empty.S[]
|
||||||
* `FAIL` tests
|
* `FAIL` tests
|
||||||
@@ -11658,7 +11658,7 @@ In order to GDB step debug those executables, you will want to use `--no-continu
|
|||||||
|
|
||||||
You are now left on the very first instruction of our tiny executable!
|
You are now left on the very first instruction of our tiny executable!
|
||||||
|
|
||||||
=== Inline assembly
|
=== GCC inline assembly
|
||||||
|
|
||||||
Examples under `arch/<arch>/c/` directories show to how use inline assembly from higher level languages such as C:
|
Examples under `arch/<arch>/c/` directories show to how use inline assembly from higher level languages such as C:
|
||||||
|
|
||||||
@@ -11774,6 +11774,56 @@ Bibliography:
|
|||||||
* http://stackoverflow.com/questions/261419/arm-to-c-calling-convention-registers-to-save
|
* http://stackoverflow.com/questions/261419/arm-to-c-calling-convention-registers-to-save
|
||||||
* https://stackoverflow.com/questions/10494848/arm-whats-the-difference-between-apcs-and-aapcs-abi
|
* https://stackoverflow.com/questions/10494848/arm-whats-the-difference-between-apcs-and-aapcs-abi
|
||||||
|
|
||||||
|
=== GAS directives
|
||||||
|
|
||||||
|
==== GAS data sizes
|
||||||
|
|
||||||
|
Let's see how may bytes go into each data type:
|
||||||
|
|
||||||
|
* link:userland/arch/x86_64/gas_data_sizes.S[]
|
||||||
|
* link:userland/arch/arm/gas_data_sizes.S[]
|
||||||
|
* link:userland/arch/aarch64/gas_data_sizes.S[]
|
||||||
|
|
||||||
|
Conclusion:
|
||||||
|
|
||||||
|
[options="header"]
|
||||||
|
|===
|
||||||
|
|byte |word |long |quad |octa
|
||||||
|
|
||||||
|
|x86
|
||||||
|
|1
|
||||||
|
|2
|
||||||
|
|4
|
||||||
|
|8
|
||||||
|
|16
|
||||||
|
|
||||||
|
|arm
|
||||||
|
|1
|
||||||
|
|4
|
||||||
|
|4
|
||||||
|
|8
|
||||||
|
|16
|
||||||
|
|
||||||
|
|aarch64
|
||||||
|
|1
|
||||||
|
|4
|
||||||
|
|4
|
||||||
|
|8
|
||||||
|
|16
|
||||||
|
|
||||||
|
|===
|
||||||
|
|
||||||
|
and also keep in mind that:
|
||||||
|
|
||||||
|
* `.int` is the same as `.long`
|
||||||
|
* `.hword` is the same as `.short` which is usually the same as `.word`
|
||||||
|
|
||||||
|
Bibliography:
|
||||||
|
|
||||||
|
* https://sourceware.org/binutils/docs-2.32/as/Pseudo-Ops.html#Pseudo-Ops
|
||||||
|
* https://stackoverflow.com/questions/43005411/how-does-the-quad-directive-work-in-assembly/43006616
|
||||||
|
* https://gist.github.com/steakknife/d47d0b19a24817f48027
|
||||||
|
|
||||||
== x86 userland assembly
|
== x86 userland assembly
|
||||||
|
|
||||||
Arch agnostic infrastructure getting started at: <<userland-assembly>>.
|
Arch agnostic infrastructure getting started at: <<userland-assembly>>.
|
||||||
@@ -14449,6 +14499,11 @@ We haven't found the ultimate distro yet, here is a summary table of trade-offs
|
|||||||
* (7): `ls recipes-* | wc`
|
* (7): `ls recipes-* | wc`
|
||||||
* (8): Poky reference system: http://git.yoctoproject.org/cgit/cgit.cgi/poky
|
* (8): Poky reference system: http://git.yoctoproject.org/cgit/cgit.cgi/poky
|
||||||
|
|
||||||
|
Other interesting possibilities that I haven't evaluated well:
|
||||||
|
|
||||||
|
* NixOS https://nixos.org/ Seems to support full build from source well. Not much cross compilation information however.
|
||||||
|
* Gentoo https://en.wikipedia.org/wiki/Gentoo_Linux Seems to support full build from source well.
|
||||||
|
|
||||||
=== Soft topics
|
=== Soft topics
|
||||||
|
|
||||||
==== Fairy tale
|
==== Fairy tale
|
||||||
|
|||||||
29
userland/arch/aarch64/gas_data_sizes.S
Normal file
29
userland/arch/aarch64/gas_data_sizes.S
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
/* https://github.com/cirosantilli/linux-kernel-module-cheat#gas-data-sizes */
|
||||||
|
|
||||||
|
#include "common.h"
|
||||||
|
|
||||||
|
ENTRY
|
||||||
|
#define ASSERT_DIFF(label1, label2, result) \
|
||||||
|
adr x0, label1; \
|
||||||
|
adr x1, label2; \
|
||||||
|
sub x0, x1, x0; \
|
||||||
|
ASSERT_EQ(x0, result)
|
||||||
|
|
||||||
|
ASSERT_DIFF(mybyte, myword, 1)
|
||||||
|
ASSERT_DIFF(myword, mylong, 4)
|
||||||
|
ASSERT_DIFF(mylong, myquad, 4)
|
||||||
|
ASSERT_DIFF(myquad, myocta, 8)
|
||||||
|
ASSERT_DIFF(myocta, theend, 16)
|
||||||
|
#undef ASSERT_DIF
|
||||||
|
EXIT
|
||||||
|
mybyte:
|
||||||
|
.byte 0x12
|
||||||
|
myword:
|
||||||
|
.word 0x1234
|
||||||
|
mylong:
|
||||||
|
.long 0x12345678
|
||||||
|
myquad:
|
||||||
|
.quad 0x123456789ABCDEF0
|
||||||
|
myocta:
|
||||||
|
.octa 0x123456789ABCDEF0123456789ABCDEF0
|
||||||
|
theend:
|
||||||
28
userland/arch/arm/gas_data_sizes.S
Normal file
28
userland/arch/arm/gas_data_sizes.S
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
#include "common.h"
|
||||||
|
|
||||||
|
.data
|
||||||
|
mybyte:
|
||||||
|
.byte 0x12
|
||||||
|
myword:
|
||||||
|
.word 0x1234
|
||||||
|
mylong:
|
||||||
|
.long 0x12345678
|
||||||
|
myquad:
|
||||||
|
.quad 0x123456789ABCDEF0
|
||||||
|
myocta:
|
||||||
|
.octa 0x123456789ABCDEF0123456789ABCDEF0
|
||||||
|
theend:
|
||||||
|
ENTRY
|
||||||
|
#define ASSERT_DIFF(label1, label2, result) \
|
||||||
|
ldr r0, =label1; \
|
||||||
|
ldr r1, =label2; \
|
||||||
|
sub r0, r1, r0; \
|
||||||
|
ASSERT_EQ(r0, result)
|
||||||
|
|
||||||
|
ASSERT_DIFF(mybyte, myword, 1)
|
||||||
|
ASSERT_DIFF(myword, mylong, 4)
|
||||||
|
ASSERT_DIFF(mylong, myquad, 4)
|
||||||
|
ASSERT_DIFF(myquad, myocta, 8)
|
||||||
|
ASSERT_DIFF(myocta, theend, 16)
|
||||||
|
#undef ASSERT_DIF
|
||||||
|
EXIT
|
||||||
28
userland/arch/x86_64/gas_data_sizes.S
Normal file
28
userland/arch/x86_64/gas_data_sizes.S
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
/* https://github.com/cirosantilli/linux-kernel-module-cheat#gas-data-sizes */
|
||||||
|
|
||||||
|
#include "common.h"
|
||||||
|
|
||||||
|
ENTRY
|
||||||
|
#define ASSERT_DIFF(label1, label2, result) \
|
||||||
|
mov $label2, %rax; \
|
||||||
|
sub $label1, %rax; \
|
||||||
|
ASSERT_EQ(%rax, $result)
|
||||||
|
|
||||||
|
ASSERT_DIFF(mybyte, myword, 1)
|
||||||
|
ASSERT_DIFF(myword, mylong, 2)
|
||||||
|
ASSERT_DIFF(mylong, myquad, 4)
|
||||||
|
ASSERT_DIFF(myquad, myocta, 8)
|
||||||
|
ASSERT_DIFF(myocta, theend, 16)
|
||||||
|
#undef ASSERT_DIF
|
||||||
|
EXIT
|
||||||
|
mybyte:
|
||||||
|
.byte 0x12
|
||||||
|
myword:
|
||||||
|
.word 0x1234
|
||||||
|
mylong:
|
||||||
|
.long 0x12345678
|
||||||
|
myquad:
|
||||||
|
.quad 0x123456789ABCDEF0
|
||||||
|
myocta:
|
||||||
|
.octa 0x123456789ABCDEF0123456789ABCDEF0
|
||||||
|
theend:
|
||||||
Reference in New Issue
Block a user