aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/tools
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/qemu-src/Makefile9
-rw-r--r--src/tools/qemu-src/test.s16
-rw-r--r--src/tools/qemu.md8
3 files changed, 33 insertions, 0 deletions
diff --git a/src/tools/qemu-src/Makefile b/src/tools/qemu-src/Makefile
new file mode 100644
index 0000000..1d21811
--- /dev/null
+++ b/src/tools/qemu-src/Makefile
@@ -0,0 +1,9 @@
+test: test.s
+ as -o test.o test.s
+ ld -o test test.o testc.o
+
+trace: test
+ qemu-x86_64 -singlestep -d nochain,cpu ./test 2>&1 | awk '/RIP/ { print $$1; }'
+
+clean:
+ $(RM) test test-bin test.o
diff --git a/src/tools/qemu-src/test.s b/src/tools/qemu-src/test.s
new file mode 100644
index 0000000..562b2ec
--- /dev/null
+++ b/src/tools/qemu-src/test.s
@@ -0,0 +1,16 @@
+.section .text, "ax"
+
+.global _start
+_start:
+ xor %rax, %rax
+ mov $0x8, %rax
+1:
+ cmp $0, %rax
+ je 2f
+ dec %rax
+ jmp 1b
+2:
+ # x86-64 exit(2) syscall
+ mov $0, %rdi
+ mov $60, %rax
+ syscall
diff --git a/src/tools/qemu.md b/src/tools/qemu.md
index 2a833e4..4351435 100644
--- a/src/tools/qemu.md
+++ b/src/tools/qemu.md
@@ -269,6 +269,14 @@ qemu-system-x86_64 \
```
Instructions to build a minimal [`Kernel` and `initrd`][blog-qemu-dbg].
+## Appendix: Cheap instruction tracer
+```make
+{{ #include qemu-src/Makefile }}
+```
+```x86asm
+{{ #include qemu-src/test.s }}
+```
+
## References
- [QEMU USB][doc-qemu-usb]