kgdb_test.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. static char cmdline[256];
  17. static unsigned long 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. printk(KERN_ALERT "L1(before change) : data variable addr = 0x%p, data value is %d\n", &num1, num1);
  24. printk(KERN_ALERT "L1 : code function addr = 0x%p\n", kgdb_l1_test);
  25. num1 = num1 + 10 ;
  26. printk(KERN_ALERT "L1(after change) : data variable addr = 0x%p, data value is %d\n", &num1, num1);
  27. return ;
  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. printk(KERN_ALERT "L2(before change) : data variable addr = 0x%p, data value is %d\n", &num2, num2);
  36. printk(KERN_ALERT "L2 : code function addr = 0x%p\n", kgdb_l2_test);
  37. num2 = num2 + 20 ;
  38. printk(KERN_ALERT "L2(after change) : data variable addr = 0x%p, data value is %d\n", &num2, num2);
  39. return ;
  40. }
  41. #endif
  42. int kgdb_test(char *name, int len, int count, int z)
  43. {
  44. printk(KERN_DEBUG "kgdb name(%d): %s, %d, %d\n", len, name, count, z);
  45. count = z;
  46. return count;
  47. }
  48. static int test_proc_output(char *buf)
  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 int test_read_proc(char *page, char **start, off_t off,
  60. int count, int *eof, void *data)
  61. {
  62. int len;
  63. len = test_proc_output(page);
  64. if (len <= off+count)
  65. *eof = 1;
  66. *start = page + off;
  67. len -= off;
  68. if (len > count)
  69. len = count;
  70. if (len < 0)
  71. len = 0;
  72. return len;
  73. }
  74. static int test_write_proc(struct file *file, const char *buffer,
  75. unsigned long count, void *data)
  76. {
  77. if (count >= 256)
  78. len = 255;
  79. else
  80. len = count;
  81. memcpy(cmdline, buffer, count);
  82. cmdline[len] = 0;
  83. return len;
  84. }
  85. static int __init kgdbtest_init(void)
  86. {
  87. struct proc_dir_entry *entry;
  88. entry = create_proc_entry("kgdbtest", 0, NULL);
  89. if (entry == NULL)
  90. return -ENOMEM;
  91. entry->read_proc = test_read_proc;
  92. entry->write_proc = test_write_proc;
  93. entry->data = NULL;
  94. return 0;
  95. }
  96. static void __exit kgdbtest_exit(void)
  97. {
  98. remove_proc_entry("kgdbtest", NULL);
  99. }
  100. module_init(kgdbtest_init);
  101. module_exit(kgdbtest_exit);
  102. MODULE_LICENSE("GPL");