#include <linux/init.h>


SUBMITTED BY: Guest

DATE: Nov. 21, 2013, 3:24 a.m.

FORMAT: Text only

SIZE: 4.0 kB

HITS: 870

  1. #include <linux/init.h>
  2. #include <linux/module.h>
  3. #include <linux/kernel.h>
  4. MODULE_LICENSE("Dual BSD/GPL");
  5. unsigned long long my_rdmsr(unsigned long val) {
  6. unsigned long low = 0, high = 0;
  7. __asm__ volatile ("rdmsr" :
  8. "=a"(low), "=d"(high)
  9. : "c"(val));
  10. return ((unsigned long long)high << 32) + low;
  11. }
  12. void my_wrmsr(unsigned long val, unsigned long low, unsigned long high) {
  13. __asm__ volatile ("wrmsr"
  14. :
  15. : "a"(low), "d"(high), "c"(val));
  16. }
  17. static int my_init(void) {
  18. my_wrmsr(0x1d9, 0x3, 0x0);
  19. printk("<1> Attempt #1 %llx.n", my_rdmsr(0x1d9));
  20. wrmsr(0x1d9, 0x1, 0x0);
  21. int low;
  22. int high;
  23. rdmsr(0x1d9, low, high);
  24. printk("<1> Attempt #2 %x, %x.n", low, high);
  25. return 0;
  26. }
  27. static void my_exit(void) {
  28. printk("<1> unloadn");
  29. }
  30. module_init(my_init);
  31. module_exit(my_exit);
  32. obj-m := hello.o
  33. me@debian:~/code$ sudo make -C /usr/src/linux-headers-3.2.0-4-amd64/ M=`pwd` modules && sudo insmod hello.ko && sudo rmmod hello && sudo dmesg | tail
  34. make: Entering directory `/usr/src/linux-headers-3.2.0-4-amd64'
  35. Building modules, stage 2.
  36. MODPOST 1 modules
  37. make: Leaving directory `/usr/src/linux-headers-3.2.0-4-amd64'
  38. [ 2231.367819] unload
  39. [ 2248.363261] Attempt #1 0.
  40. [ 2248.363267] Attempt #2 0, 0.
  41. [ 2248.378066] unload
  42. [ 2288.395359] Attempt #1 0.
  43. [ 2288.395366] Attempt #2 0, 0.
  44. [ 2288.409889] unload
  45. [ 3021.984748] Attempt #1 0.
  46. [ 3021.984760] Attempt #2 0, 0.
  47. [ 3022.017626] unload

comments powered by Disqus