blob: 6fc4e5f62261c8381e3f0d4c165e2e04a832ef2d [file] [log] [blame]
Mike Frysinger459249a2009-01-07 23:14:39 +08001/*
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
9#include <linux/module.h>
10#include <linux/kernel.h>
11#include <linux/init.h>
12#include <linux/proc_fs.h>
13
14#include <asm/current.h>
15#include <asm/uaccess.h>
16#include <asm/system.h>
17
18#include <asm/blackfin.h>
19
20static char cmdline[256];
Alexey Dobriyan397b7612009-12-05 03:27:29 +030021static size_t len;
Mike Frysinger459249a2009-01-07 23:14:39 +080022
Sonic Zhang0bf3d932009-03-05 16:44:53 +080023#ifndef CONFIG_SMP
Mike Frysinger459249a2009-01-07 23:14:39 +080024static int num1 __attribute__((l1_data));
25
26void kgdb_l1_test(void) __attribute__((l1_text));
27
28void kgdb_l1_test(void)
29{
30 printk(KERN_ALERT "L1(before change) : data variable addr = 0x%p, data value is %d\n", &num1, num1);
31 printk(KERN_ALERT "L1 : code function addr = 0x%p\n", kgdb_l1_test);
32 num1 = num1 + 10 ;
33 printk(KERN_ALERT "L1(after change) : data variable addr = 0x%p, data value is %d\n", &num1, num1);
34 return ;
35}
Sonic Zhang0bf3d932009-03-05 16:44:53 +080036#endif
37
Mike Frysinger459249a2009-01-07 23:14:39 +080038#if L2_LENGTH
39
40static int num2 __attribute__((l2));
41void kgdb_l2_test(void) __attribute__((l2));
42
43void kgdb_l2_test(void)
44{
45 printk(KERN_ALERT "L2(before change) : data variable addr = 0x%p, data value is %d\n", &num2, num2);
46 printk(KERN_ALERT "L2 : code function addr = 0x%p\n", kgdb_l2_test);
47 num2 = num2 + 20 ;
48 printk(KERN_ALERT "L2(after change) : data variable addr = 0x%p, data value is %d\n", &num2, num2);
49 return ;
50}
51
52#endif
53
54
55int kgdb_test(char *name, int len, int count, int z)
56{
Mingquan Pan4a3e53c2009-08-31 04:56:06 +000057 printk(KERN_ALERT "kgdb name(%d): %s, %d, %d\n", len, name, count, z);
Mike Frysinger459249a2009-01-07 23:14:39 +080058 count = z;
59 return count;
60}
61
Alexey Dobriyan397b7612009-12-05 03:27:29 +030062static ssize_t kgdb_test_proc_read(struct file *file, char __user *buf,
63 size_t count, loff_t *ppos)
Mike Frysinger459249a2009-01-07 23:14:39 +080064{
65 kgdb_test("hello world!", 12, 0x55, 0x10);
Sonic Zhang0bf3d932009-03-05 16:44:53 +080066#ifndef CONFIG_SMP
Mike Frysinger459249a2009-01-07 23:14:39 +080067 kgdb_l1_test();
Sonic Zhang0bf3d932009-03-05 16:44:53 +080068#endif
69#if L2_LENGTH
Mike Frysinger459249a2009-01-07 23:14:39 +080070 kgdb_l2_test();
Sonic Zhang0bf3d932009-03-05 16:44:53 +080071#endif
Mike Frysinger459249a2009-01-07 23:14:39 +080072
73 return 0;
74}
75
Alexey Dobriyan397b7612009-12-05 03:27:29 +030076static ssize_t kgdb_test_proc_write(struct file *file,
77 const char __user *buffer, size_t count, loff_t *pos)
Mike Frysinger459249a2009-01-07 23:14:39 +080078{
79 if (count >= 256)
80 len = 255;
81 else
82 len = count;
83
84 memcpy(cmdline, buffer, count);
85 cmdline[len] = 0;
86
87 return len;
88}
89
Alexey Dobriyan397b7612009-12-05 03:27:29 +030090static const struct file_operations kgdb_test_proc_fops = {
91 .owner = THIS_MODULE,
92 .read = kgdb_test_proc_read,
93 .write = kgdb_test_proc_write,
94};
95
Mike Frysinger459249a2009-01-07 23:14:39 +080096static int __init kgdbtest_init(void)
97{
98 struct proc_dir_entry *entry;
99
Alexey Dobriyan397b7612009-12-05 03:27:29 +0300100 entry = proc_create("kgdbtest", 0, NULL, &kgdb_test_proc_fops);
Mike Frysinger459249a2009-01-07 23:14:39 +0800101 if (entry == NULL)
102 return -ENOMEM;
Mike Frysinger459249a2009-01-07 23:14:39 +0800103 return 0;
104}
105
106static void __exit kgdbtest_exit(void)
107{
108 remove_proc_entry("kgdbtest", NULL);
109}
110
111module_init(kgdbtest_init);
112module_exit(kgdbtest_exit);
113MODULE_LICENSE("GPL");