From 7014d34576dd57ff8a4a208fb0264375132ab781 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ciro=20Santilli=20=E5=85=AD=E5=9B=9B=E4=BA=8B=E4=BB=B6=20?= =?UTF-8?q?=E6=B3=95=E8=BD=AE=E5=8A=9F?= Date: Thu, 9 May 2019 00:00:01 +0000 Subject: [PATCH] gas data sizes --- README.adoc | 61 ++++++++++++++++++++++++-- userland/arch/aarch64/gas_data_sizes.S | 29 ++++++++++++ userland/arch/arm/gas_data_sizes.S | 28 ++++++++++++ userland/arch/x86_64/gas_data_sizes.S | 28 ++++++++++++ 4 files changed, 143 insertions(+), 3 deletions(-) create mode 100644 userland/arch/aarch64/gas_data_sizes.S create mode 100644 userland/arch/arm/gas_data_sizes.S create mode 100644 userland/arch/x86_64/gas_data_sizes.S diff --git a/README.adoc b/README.adoc index 6b72364..ddf6c3b 100644 --- a/README.adoc +++ b/README.adoc @@ -9,7 +9,7 @@ :toclevels: 6 :toc-title: -The perfect emulation setup to study and develop the <>, kernel modules, <> and <> and <> assembly. Highly automated. Thoroughly documented. <> and <> just work. Automated <>. Powered by <> and <>. "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 <> v5.0, kernel modules, <> and x86_64, ARMv7 and ARMv8 <> and <> assembly. <> and <> just work. Powered by <> and <>. Highly automated. Thoroughly documented. Automated <>. "Tested" in an Ubuntu 18.04 host. TL;DR: <> @@ -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 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[] * `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! -=== Inline assembly +=== GCC inline assembly Examples under `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 * 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 Arch agnostic infrastructure getting started at: <>. @@ -14449,6 +14499,11 @@ We haven't found the ultimate distro yet, here is a summary table of trade-offs * (7): `ls recipes-* | wc` * (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 ==== Fairy tale diff --git a/userland/arch/aarch64/gas_data_sizes.S b/userland/arch/aarch64/gas_data_sizes.S new file mode 100644 index 0000000..b24af13 --- /dev/null +++ b/userland/arch/aarch64/gas_data_sizes.S @@ -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: diff --git a/userland/arch/arm/gas_data_sizes.S b/userland/arch/arm/gas_data_sizes.S new file mode 100644 index 0000000..801a271 --- /dev/null +++ b/userland/arch/arm/gas_data_sizes.S @@ -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 diff --git a/userland/arch/x86_64/gas_data_sizes.S b/userland/arch/x86_64/gas_data_sizes.S new file mode 100644 index 0000000..2219ea9 --- /dev/null +++ b/userland/arch/x86_64/gas_data_sizes.S @@ -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: