mgorny created this revision.
mgorny added reviewers: labath, krytarowski.
Herald added a project: LLDB.
mgorny requested review of this revision.
Herald added a subscriber: JDevlieghere.
Add a partial read/write tests for x87 FPU registers. This includes
reading and writing ST registers, reading basic control registers
in exception state (including operand code) and writing basic control
registers in non-exception state (marking the registers as used,
practically speaking).
The tests assume the current (roughly incorrect) behavior of reporting
the 'abridged' 8-bit ftag state as 16-bit ftag.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D88583
Files:
lldb/test/Shell/Register/Inputs/x86-fp-read.cpp
lldb/test/Shell/Register/Inputs/x86-fp-write.cpp
lldb/test/Shell/Register/x86-fp-read.test
lldb/test/Shell/Register/x86-fp-write.test
Index: lldb/test/Shell/Register/x86-fp-write.test
===================================================================
--- /dev/null
+++ lldb/test/Shell/Register/x86-fp-write.test
@@ -0,0 +1,35 @@
+# REQUIRES: native && (target-x86 || target-x86_64)
+# RUN: %clangxx_host %p/Inputs/x86-fp-write.cpp -o %t
+# RUN: %lldb -b -s %s %t | FileCheck %s
+process launch
+
+register write fctrl 0x037f
+register write fstat 0x0841
+# note: this needs to enable all registers for writes to be effective
+# TODO: fix it to use proper ftag values instead of 'abridged'
+register write ftag 0x00ff
+register write st0 "{0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x80 0x00 0x40}"
+register write st1 "{0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x3f 0x00 0x00}"
+register write st2 "{0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00}"
+register write st3 "{0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x80}"
+register write st4 "{0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x80 0xff 0x7f}"
+register write st5 "{0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x80 0xff 0xff}"
+register write st6 "{0x00 0x00 0x00 0x00 0x00 0x00 0x00 0xc0 0xff 0xff}"
+register write st7 "{0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00}"
+
+process continue
+
+# CHECK-DAG: fctrl = 0x037f
+# CHECK-DAG: fstat = 0x0841
+# CHECK-DAG: ftag = 0xa961
+
+# CHECK-DAG: st0 = { 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x80 0x00 0x40 }
+# CHECK-DAG: st1 = { 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x3f 0x00 0x00 }
+# CHECK-DAG: st2 = { 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 }
+# CHECK-DAG: st3 = { 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x80 }
+# CHECK-DAG: st4 = { 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x80 0xff 0x7f }
+# CHECK-DAG: st5 = { 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x80 0xff 0xff }
+# CHECK-DAG: st6 = { 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0xc0 0xff 0xff }
+# CHECK-DAG: st7 = { 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 }
+
+# CHECK: Process {{[0-9]+}} exited with status = 0
Index: lldb/test/Shell/Register/x86-fp-read.test
===================================================================
--- /dev/null
+++ lldb/test/Shell/Register/x86-fp-read.test
@@ -0,0 +1,24 @@
+# REQUIRES: native && (target-x86 || target-x86_64)
+# RUN: %clangxx_host %p/Inputs/x86-fp-read.cpp -o %t
+# RUN: %lldb -b -s %s %t | FileCheck %s
+process launch
+
+register read --all
+# CHECK-DAG: fctrl = 0x037e
+# CHECK-DAG: fstat = 0x88c1
+# TODO: the following value is incorrect, it's a bug in the way
+# FXSAVE/XSAVE is interpreted; it should be 0xa963 once fixed
+# CHECK-DAG: ftag = 0x00fe
+# CHECK-DAG: fop = 0x04f7
+
+# CHECK-DAG: st0 = {0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x80 0x00 0x40}
+# CHECK-DAG: st1 = {0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x3f 0x00 0x00}
+# CHECK-DAG: st2 = {0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00}
+# CHECK-DAG: st3 = {0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x80}
+# CHECK-DAG: st4 = {0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x80 0xff 0x7f}
+# CHECK-DAG: st5 = {0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x80 0xff 0xff}
+# CHECK-DAG: st6 = {0x00 0x00 0x00 0x00 0x00 0x00 0x00 0xc0 0xff 0xff}
+# CHECK-DAG: st7 = {0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00}
+
+process continue
+# CHECK: Process {{[0-9]+}} exited with status = 0
Index: lldb/test/Shell/Register/Inputs/x86-fp-write.cpp
===================================================================
--- /dev/null
+++ lldb/test/Shell/Register/Inputs/x86-fp-write.cpp
@@ -0,0 +1,41 @@
+#include <cstdint>
+#include <cstdio>
+
+struct alignas(16) float80_raw {
+ uint8_t data[10];
+};
+
+int main() {
+ float80_raw st[8];
+ uint16_t env[14];
+
+ asm volatile(
+ "finit\n\t"
+ "int3\n\t"
+ "fstenv %1\n\t"
+ "fstpt 0x00(%0)\n\t"
+ "fstpt 0x10(%0)\n\t"
+ "fstpt 0x20(%0)\n\t"
+ "fstpt 0x30(%0)\n\t"
+ "fstpt 0x40(%0)\n\t"
+ "fstpt 0x50(%0)\n\t"
+ "fstpt 0x60(%0)\n\t"
+ "fstpt 0x70(%0)\n\t"
+ :
+ : "a"(st), "m"(env)
+ : "st"
+ );
+
+ printf("fctrl = 0x%04x\n", env[0]);
+ printf("fstat = 0x%04x\n", env[2]);
+ printf("ftag = 0x%04x\n", env[4]);
+
+ for (int i = 0; i < 8; ++i) {
+ printf("st%d = { ", i);
+ for (int j = 0; j < sizeof(st->data); ++j)
+ printf("0x%02x ", st[i].data[j]);
+ printf("}\n");
+ }
+
+ return 0;
+}
Index: lldb/test/Shell/Register/Inputs/x86-fp-read.cpp
===================================================================
--- /dev/null
+++ lldb/test/Shell/Register/Inputs/x86-fp-read.cpp
@@ -0,0 +1,43 @@
+#include <cstdint>
+
+struct alignas(16) float80_raw {
+ uint64_t mantissa;
+ uint16_t sign_exp;
+};
+
+int main() {
+ float80_raw st[] = {
+ {0x8000000000000000, 0x4000}, // +2.0
+ {0x3f00000000000000, 0x0000}, // 1.654785e-4932 (denormal)
+ {0x0000000000000000, 0x0000}, // +0
+ {0x0000000000000000, 0x8000}, // -0
+ {0x8000000000000000, 0x7fff}, // +inf
+ {0x8000000000000000, 0xffff}, // -inf
+ {0xc000000000000000, 0xffff}, // nan
+ // leave st7 empty to test tag word better
+ };
+
+ // unmask invalid op exception
+ uint16_t cw = 0x037e;
+
+ asm volatile(
+ "finit\n\t"
+ "fldcw %1\n\t"
+ // load on stack in reverse order to make the result easier to read
+ "fldt 0x60(%0)\n\t"
+ "fldt 0x50(%0)\n\t"
+ "fldt 0x40(%0)\n\t"
+ "fldt 0x30(%0)\n\t"
+ "fldt 0x20(%0)\n\t"
+ "fldt 0x10(%0)\n\t"
+ "fldt 0x00(%0)\n\t"
+ // this should trigger a stack fault
+ "fdiv %%st(0), %%st(7)\n\t"
+ "int3\n\t"
+ :
+ : "a"(st), "m"(cw)
+ : "st"
+ );
+
+ return 0;
+}
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits