kgdb_test.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. static int num1 __attribute__((l1_data));
  19. void kgdb_l1_test(void) __attribute__((l1_text));
  20. void kgdb_l1_test(void)
  21. {
  22. printk(KERN_ALERT "L1(before change) : data variable addr = 0x%p, data value is %d\n", &num1, num1);
  23. printk(KERN_ALERT "L1 : code function addr = 0x%p\n", kgdb_l1_test);
  24. num1 = num1 + 10 ;
  25. printk(KERN_ALERT "L1(after change) : data variable addr = 0x%p, data value is %d\n", &num1, num1);
  26. return ;
  27. }
  28. #if L2_LENGTH
  29. static int num2 __attribute__((l2));
  30. void kgdb_l2_test(void) __attribute__((l2));
  31. void kgdb_l2_test(void)
  32. {
  33. printk(KERN_ALERT "L2(before change) : data variable addr = 0x%p, data value is %d\n", &num2, num2);
  34. printk(KERN_ALERT "L2 : code function addr = 0x%p\n", kgdb_l2_test);
  35. num2 = num2 + 20 ;
  36. printk(KERN_ALERT "L2(after change) : data variable addr = 0x%p, data value is %d\n", &num2, num2);
  37. return ;
  38. }
  39. #endif
  40. int kgdb_test(char *name, int len, int count, int z)
  41. {
  42. printk(KERN_DEBUG "kgdb name(%d): %s, %d, %d\n", len, name, count, z);
  43. count = z;
  44. return count;
  45. }
  46. static int test_proc_output(char *buf)
  47. {
  48. kgdb_test("hello world!", 12, 0x55, 0x10);
  49. kgdb_l1_test();
  50. #if L2_LENGTH
  51. kgdb_l2_test();
  52. #endif
  53. return 0;
  54. }
  55. static int test_read_proc(char *page, char **start, off_t off,
  56. int count, int *eof, void *data)
  57. {
  58. int len;
  59. len = test_proc_output(page);
  60. if (len <= off+count)
  61. *eof = 1;
  62. *start = page + off;
  63. len -= off;
  64. if (len > count)
  65. len = count;
  66. if (len < 0)
  67. len = 0;
  68. return len;
  69. }
  70. static int test_write_proc(struct file *file, const char *buffer,
  71. unsigned long count, void *data)
  72. {
  73. if (count >= 256)
  74. len = 255;
  75. else
  76. len = count;
  77. memcpy(cmdline, buffer, count);
  78. cmdline[len] = 0;
  79. return len;
  80. }
  81. static int __init kgdbtest_init(void)
  82. {
  83. struct proc_dir_entry *entry;
  84. entry = create_proc_entry("kgdbtest", 0, NULL);
  85. if (entry == NULL)
  86. return -ENOMEM;
  87. entry->read_proc = test_read_proc;
  88. entry->write_proc = test_write_proc;
  89. entry->data = NULL;
  90. return 0;
  91. }
  92. static void __exit kgdbtest_exit(void)
  93. {
  94. remove_proc_entry("kgdbtest", NULL);
  95. }
  96. module_init(kgdbtest_init);
  97. module_exit(kgdbtest_exit);
  98. MODULE_LICENSE("GPL");