From 42f8de774aa7559ddf07094e077c73c811e8b69c 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: Sun, 5 May 2019 00:00:00 +0000 Subject: [PATCH] userland: add ported to all archs --- README.adoc | 10 ++++++---- userland/arch/x86_64/add.S | 9 +++++++++ userland/arch/x86_64/common_arch.h | 2 +- 3 files changed, 16 insertions(+), 5 deletions(-) create mode 100644 userland/arch/x86_64/add.S diff --git a/README.adoc b/README.adoc index b0e28f6..056c6f1 100644 --- a/README.adoc +++ b/README.adoc @@ -11362,10 +11362,12 @@ This verifies that the venerable `add` instruction and our setup are working. Then, modify that program to make the assertion fail: .... -TODO +ASSERT_EQ(%rax, $4) .... -and then watch the assertion fail: +because 1 + 2 tends to equal 3 instead of 4. + +And then watch the assertion fail: .... ./build-userland @@ -11375,10 +11377,10 @@ and then watch the assertion fail: with error message: .... -TODO +error 1 at line 8 .... -Notice how we give the actual assembly line number where the failing assert was! +and notice how we give the actual assembly line number where the failing assert was! Other setup sanity checks that you might want to look into include: diff --git a/userland/arch/x86_64/add.S b/userland/arch/x86_64/add.S new file mode 100644 index 0000000..978b1a3 --- /dev/null +++ b/userland/arch/x86_64/add.S @@ -0,0 +1,9 @@ +/* https://github.com/cirosantilli/linux-kernel-module-cheat#userland-assembly */ + +#include "common.h" + +ENTRY + mov $1, %rax + add $2, %rax + ASSERT_EQ(%rax, $3) +EXIT diff --git a/userland/arch/x86_64/common_arch.h b/userland/arch/x86_64/common_arch.h index 11490c3..d94e3d4 100644 --- a/userland/arch/x86_64/common_arch.h +++ b/userland/arch/x86_64/common_arch.h @@ -9,9 +9,9 @@ mov reg, %rax; \ mov const, %rbx; \ cmp %rax, %rbx; \ - ASSERT(je); \ pop %rbx; \ pop %rax; \ + ASSERT(je); \ ; # TODO