summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndy Lutomirski <luto@amacapital.net>2014-05-05 17:59:02 -0700
committerAndy Lutomirski <luto@amacapital.net>2014-05-05 17:59:02 -0700
commit6ecbf653d60c8b0965fb4893784e76e166b7262d (patch)
treeac03e42e033ba677c59c4fe6f321ea71082080b8
parent72bd0ed03a01c4319b4152c825ff3c9a6cb6492d (diff)
downloadmisc-tests-6ecbf653d60c8b0965fb4893784e76e166b7262d.tar.gz
Add user_visible_state
-rw-r--r--.gitignore1
-rw-r--r--Makefile7
-rw-r--r--user_visible_state.c65
3 files changed, 71 insertions, 2 deletions
diff --git a/.gitignore b/.gitignore
index 9912d8c..2dde783 100644
--- a/.gitignore
+++ b/.gitignore
@@ -9,4 +9,5 @@ test_vsyscall_32
test_vsyscall_64
context_switch_latency
kernel_pf
+user_visible_state
*~
diff --git a/Makefile b/Makefile
index 0577441..bfda8fb 100644
--- a/Makefile
+++ b/Makefile
@@ -1,8 +1,11 @@
.PHONY: all clean
-all: timing_test_64 timing_test_32 evil-clock-test test_vsyscall_64 test_vsyscall_32 dump-vdso dump-vvar dump-vsyscall context_switch_latency kernel_pf
+all: timing_test_64 timing_test_32 evil-clock-test test_vsyscall_64 test_vsyscall_32 dump-vdso dump-vvar dump-vsyscall context_switch_latency kernel_pf user_visible_state
clean:
- rm -f timing_test_64 timing_test_32 evil-clock-test test_vsyscall_64 test_vsyscall_32 dump-vdso dump-vvar dump-vsyscall context_switch_latency kernel_pf
+ rm -f timing_test_64 timing_test_32 evil-clock-test test_vsyscall_64 test_vsyscall_32 dump-vdso dump-vvar dump-vsyscall context_switch_latency kernel_pf user_visible_state
+
+user_visible_state: user_visible_state.c
+ gcc -o $@ -O2 -std=gnu99 -Wall $(EXTRA_CFLAGS) -g $^ -lrt -ldl
kernel_pf: kernel_pf.c
gcc -o $@ -O2 -std=gnu99 -Wall $(EXTRA_CFLAGS) -g $^ -lrt -ldl
diff --git a/user_visible_state.c b/user_visible_state.c
new file mode 100644
index 0000000..58d1d88
--- /dev/null
+++ b/user_visible_state.c
@@ -0,0 +1,65 @@
+#include <stdio.h>
+#include <stdint.h>
+#include <xmmintrin.h>
+
+static void show_gdt_and_idt(void)
+{
+ struct {
+ unsigned short limit;
+ unsigned long base;
+ } __attribute__((packed)) val;
+
+ __asm__ ("sgdt %0" : "=m" (val));
+ printf("GDT: base = 0x%016lX limit = 0x%04hX\n", val.base, val.limit);
+
+ __asm__ ("sidt %0" : "=m" (val));
+ printf("IDT: base = 0x%016lX limit = 0x%04hX\n", val.base, val.limit);
+}
+
+static void show_ldt(void)
+{
+ unsigned short ldt;
+ asm ("sldt %0" : "=rm" (ldt));
+ printf("LDT: 0x%04hX\n", ldt);
+}
+
+static void show_tr(void)
+{
+ unsigned short tr;
+ asm ("str %0" : "=rm" (tr));
+ printf("TR: 0x%04X\n", tr);
+}
+
+static void show_msw(void)
+{
+ unsigned short msw;
+ asm ("smsww %0" : "=rm" (msw));
+ printf("MSW: 0x%04X\n", msw);
+}
+
+static void show_flags(void)
+{
+ unsigned long flags;
+ asm ("sub $128, %%sp\n\t"
+ "pushf\n\t"
+ "pop %0\n\t"
+ "add $128, %%sp" : "=r" (flags));
+ printf("FLAGS: 0x%016lX\n", flags);
+}
+
+static void show_rdtscp(void)
+{
+ unsigned int cpu;
+ __builtin_ia32_rdtscp(&cpu);
+ printf("RDTSCP: cpu %d\n", cpu);
+}
+
+int main()
+{
+ show_gdt_and_idt();
+ show_ldt();
+ show_tr();
+ show_msw();
+ show_flags();
+ show_rdtscp();
+}