kgdb_test.c 2.4 KB

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