kgdb_test.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. * arch/blackfin/kernel/kgdb_test.c - Blackfin kgdb tests
  3. *
  4. * Copyright 2005-2008 Analog Devices Inc.
  5. *
  6. * Licensed under the GPL-2 or later.
  7. */
  8. #include <linux/module.h>
  9. #include <linux/kernel.h>
  10. #include <linux/init.h>
  11. #include <linux/proc_fs.h>
  12. #include <asm/current.h>
  13. #include <asm/uaccess.h>
  14. #include <asm/blackfin.h>
  15. /* Symbols are here for kgdb test to poke directly */
  16. static char cmdline[256];
  17. static size_t len;
  18. #ifndef CONFIG_SMP
  19. static int num1 __attribute__((l1_data));
  20. void kgdb_l1_test(void) __attribute__((l1_text));
  21. void kgdb_l1_test(void)
  22. {
  23. pr_alert("L1(before change) : data variable addr = 0x%p, data value is %d\n", &num1, num1);
  24. pr_alert("L1 : code function addr = 0x%p\n", kgdb_l1_test);
  25. num1 = num1 + 10;
  26. pr_alert("L1(after change) : data variable addr = 0x%p, data value is %d\n", &num1, num1);
  27. }
  28. #endif
  29. #if L2_LENGTH
  30. static int num2 __attribute__((l2));
  31. void kgdb_l2_test(void) __attribute__((l2));
  32. void kgdb_l2_test(void)
  33. {
  34. pr_alert("L2(before change) : data variable addr = 0x%p, data value is %d\n", &num2, num2);
  35. pr_alert("L2 : code function addr = 0x%p\n", kgdb_l2_test);
  36. num2 = num2 + 20;
  37. pr_alert("L2(after change) : data variable addr = 0x%p, data value is %d\n", &num2, num2);
  38. }
  39. #endif
  40. noinline int kgdb_test(char *name, int len, int count, int z)
  41. {
  42. pr_alert("kgdb name(%d): %s, %d, %d\n", len, name, count, z);
  43. count = z;
  44. return count;
  45. }
  46. static ssize_t
  47. kgdb_test_proc_read(struct file *file, char __user *buf,
  48. size_t count, loff_t *ppos)
  49. {
  50. kgdb_test("hello world!", 12, 0x55, 0x10);
  51. #ifndef CONFIG_SMP
  52. kgdb_l1_test();
  53. #endif
  54. #if L2_LENGTH
  55. kgdb_l2_test();
  56. #endif
  57. return 0;
  58. }
  59. static ssize_t
  60. kgdb_test_proc_write(struct file *file, const char __user *buffer,
  61. size_t count, loff_t *pos)
  62. {
  63. len = min_t(size_t, 255, count);
  64. memcpy(cmdline, buffer, count);
  65. cmdline[len] = 0;
  66. return len;
  67. }
  68. static const struct file_operations kgdb_test_proc_fops = {
  69. .owner = THIS_MODULE,
  70. .read = kgdb_test_proc_read,
  71. .write = kgdb_test_proc_write,
  72. .llseek = noop_llseek,
  73. };
  74. static int __init kgdbtest_init(void)
  75. {
  76. struct proc_dir_entry *entry;
  77. #if L2_LENGTH
  78. num2 = 0;
  79. #endif
  80. entry = proc_create("kgdbtest", 0, NULL, &kgdb_test_proc_fops);
  81. if (entry == NULL)
  82. return -ENOMEM;
  83. return 0;
  84. }
  85. static void __exit kgdbtest_exit(void)
  86. {
  87. remove_proc_entry("kgdbtest", NULL);
  88. }
  89. module_init(kgdbtest_init);
  90. module_exit(kgdbtest_exit);
  91. MODULE_LICENSE("GPL");