blob: 18ab004aea1c95ef2a427d3eddb3d0664b5e98cb [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>
Mike Frysinger459249a2009-01-07 23:14:39 +080016
17#include <asm/blackfin.h>
18
Mike Frysinger88f7c2f2009-12-07 10:20:20 +000019/* Symbols are here for kgdb test to poke directly */
Mike Frysinger459249a2009-01-07 23:14:39 +080020static 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{
Mike Frysinger88f7c2f2009-12-07 10:20:20 +000030 pr_alert("L1(before change) : data variable addr = 0x%p, data value is %d\n", &num1, num1);
31 pr_alert("L1 : code function addr = 0x%p\n", kgdb_l1_test);
32 num1 = num1 + 10;
33 pr_alert("L1(after change) : data variable addr = 0x%p, data value is %d\n", &num1, num1);
Mike Frysinger459249a2009-01-07 23:14:39 +080034}
Sonic Zhang0bf3d932009-03-05 16:44:53 +080035#endif
36
Mike Frysinger459249a2009-01-07 23:14:39 +080037#if L2_LENGTH
38
39static int num2 __attribute__((l2));
40void kgdb_l2_test(void) __attribute__((l2));
41
42void kgdb_l2_test(void)
43{
Mike Frysinger88f7c2f2009-12-07 10:20:20 +000044 pr_alert("L2(before change) : data variable addr = 0x%p, data value is %d\n", &num2, num2);
45 pr_alert("L2 : code function addr = 0x%p\n", kgdb_l2_test);
46 num2 = num2 + 20;
47 pr_alert("L2(after change) : data variable addr = 0x%p, data value is %d\n", &num2, num2);
Mike Frysinger459249a2009-01-07 23:14:39 +080048}
49
50#endif
51
Sonic Zhanga9930fd2011-08-12 17:57:57 +080052noinline int kgdb_test(char *name, int len, int count, int z)
Mike Frysinger459249a2009-01-07 23:14:39 +080053{
Mike Frysinger88f7c2f2009-12-07 10:20:20 +000054 pr_alert("kgdb name(%d): %s, %d, %d\n", len, name, count, z);
Mike Frysinger459249a2009-01-07 23:14:39 +080055 count = z;
56 return count;
57}
58
Mike Frysinger88f7c2f2009-12-07 10:20:20 +000059static ssize_t
60kgdb_test_proc_read(struct file *file, char __user *buf,
61 size_t count, loff_t *ppos)
Mike Frysinger459249a2009-01-07 23:14:39 +080062{
63 kgdb_test("hello world!", 12, 0x55, 0x10);
Sonic Zhang0bf3d932009-03-05 16:44:53 +080064#ifndef CONFIG_SMP
Mike Frysinger459249a2009-01-07 23:14:39 +080065 kgdb_l1_test();
Sonic Zhang0bf3d932009-03-05 16:44:53 +080066#endif
67#if L2_LENGTH
Mike Frysinger459249a2009-01-07 23:14:39 +080068 kgdb_l2_test();
Sonic Zhang0bf3d932009-03-05 16:44:53 +080069#endif
Mike Frysinger459249a2009-01-07 23:14:39 +080070
71 return 0;
72}
73
Mike Frysinger88f7c2f2009-12-07 10:20:20 +000074static ssize_t
75kgdb_test_proc_write(struct file *file, const char __user *buffer,
76 size_t count, loff_t *pos)
Mike Frysinger459249a2009-01-07 23:14:39 +080077{
Mike Frysinger88f7c2f2009-12-07 10:20:20 +000078 len = min_t(size_t, 255, count);
Mike Frysinger459249a2009-01-07 23:14:39 +080079 memcpy(cmdline, buffer, count);
80 cmdline[len] = 0;
81
82 return len;
83}
84
Alexey Dobriyan397b7612009-12-05 03:27:29 +030085static const struct file_operations kgdb_test_proc_fops = {
Mike Frysinger88f7c2f2009-12-07 10:20:20 +000086 .owner = THIS_MODULE,
87 .read = kgdb_test_proc_read,
88 .write = kgdb_test_proc_write,
Arnd Bergmann6038f372010-08-15 18:52:59 +020089 .llseek = noop_llseek,
Alexey Dobriyan397b7612009-12-05 03:27:29 +030090};
91
Mike Frysinger459249a2009-01-07 23:14:39 +080092static int __init kgdbtest_init(void)
93{
94 struct proc_dir_entry *entry;
95
Vivi Li9fc20522010-11-17 04:26:19 +000096#if L2_LENGTH
97 num2 = 0;
98#endif
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 Frysinger88f7c2f2009-12-07 10:20:20 +0000103
Mike Frysinger459249a2009-01-07 23:14:39 +0800104 return 0;
105}
106
107static void __exit kgdbtest_exit(void)
108{
109 remove_proc_entry("kgdbtest", NULL);
110}
111
112module_init(kgdbtest_init);
113module_exit(kgdbtest_exit);
114MODULE_LICENSE("GPL");