diff options
author | Jonathan Herman <hermanjl@cs.unc.edu> | 2013-01-22 10:38:37 -0500 |
---|---|---|
committer | Jonathan Herman <hermanjl@cs.unc.edu> | 2013-01-22 10:38:37 -0500 |
commit | fcc9d2e5a6c89d22b8b773a64fb4ad21ac318446 (patch) | |
tree | a57612d1888735a2ec7972891b68c1ac5ec8faea /arch/cris/arch-v32/mach-fs | |
parent | 8dea78da5cee153b8af9c07a2745f6c55057fe12 (diff) |
Diffstat (limited to 'arch/cris/arch-v32/mach-fs')
-rw-r--r-- | arch/cris/arch-v32/mach-fs/vcs_hook.c | 100 | ||||
-rw-r--r-- | arch/cris/arch-v32/mach-fs/vcs_hook.h | 42 |
2 files changed, 142 insertions, 0 deletions
diff --git a/arch/cris/arch-v32/mach-fs/vcs_hook.c b/arch/cris/arch-v32/mach-fs/vcs_hook.c new file mode 100644 index 00000000000..b11594ae0cb --- /dev/null +++ b/arch/cris/arch-v32/mach-fs/vcs_hook.c | |||
@@ -0,0 +1,100 @@ | |||
1 | /* | ||
2 | * Call simulator hook. This is the part running in the | ||
3 | * simulated program. | ||
4 | */ | ||
5 | |||
6 | #include "vcs_hook.h" | ||
7 | #include <stdarg.h> | ||
8 | #include <arch-v32/hwregs/reg_map.h> | ||
9 | #include <arch-v32/hwregs/intr_vect_defs.h> | ||
10 | |||
11 | #define HOOK_TRIG_ADDR 0xb7000000 /* hook cvlog model reg address */ | ||
12 | #define HOOK_MEM_BASE_ADDR 0xa0000000 /* csp4 (shared mem) base addr */ | ||
13 | |||
14 | #define HOOK_DATA(offset) ((unsigned *)HOOK_MEM_BASE_ADDR)[offset] | ||
15 | #define VHOOK_DATA(offset) ((volatile unsigned *)HOOK_MEM_BASE_ADDR)[offset] | ||
16 | #define HOOK_TRIG(funcid) \ | ||
17 | do { \ | ||
18 | *((unsigned *) HOOK_TRIG_ADDR) = funcid; \ | ||
19 | } while (0) | ||
20 | #define HOOK_DATA_BYTE(offset) ((unsigned char *)HOOK_MEM_BASE_ADDR)[offset] | ||
21 | |||
22 | int hook_call(unsigned id, unsigned pcnt, ...) | ||
23 | { | ||
24 | va_list ap; | ||
25 | unsigned i; | ||
26 | unsigned ret; | ||
27 | #ifdef USING_SOS | ||
28 | PREEMPT_OFF_SAVE(); | ||
29 | #endif | ||
30 | |||
31 | /* pass parameters */ | ||
32 | HOOK_DATA(0) = id; | ||
33 | |||
34 | /* Have to make hook_print_str a special case since we call with a | ||
35 | * parameter of byte type. Should perhaps be a separate | ||
36 | * hook_call. */ | ||
37 | |||
38 | if (id == hook_print_str) { | ||
39 | int i; | ||
40 | char *str; | ||
41 | |||
42 | HOOK_DATA(1) = pcnt; | ||
43 | |||
44 | va_start(ap, pcnt); | ||
45 | str = (char *)va_arg(ap, unsigned); | ||
46 | |||
47 | for (i = 0; i != pcnt; i++) | ||
48 | HOOK_DATA_BYTE(8 + i) = str[i]; | ||
49 | |||
50 | HOOK_DATA_BYTE(8 + i) = 0; /* null byte */ | ||
51 | } else { | ||
52 | va_start(ap, pcnt); | ||
53 | for (i = 1; i <= pcnt; i++) | ||
54 | HOOK_DATA(i) = va_arg(ap, unsigned); | ||
55 | va_end(ap); | ||
56 | } | ||
57 | |||
58 | /* read from mem to make sure data has propagated to memory before | ||
59 | * trigging */ | ||
60 | ret = *((volatile unsigned *)HOOK_MEM_BASE_ADDR); | ||
61 | |||
62 | /* trigger hook */ | ||
63 | HOOK_TRIG(id); | ||
64 | |||
65 | /* wait for call to finish */ | ||
66 | while (VHOOK_DATA(0) > 0) ; | ||
67 | |||
68 | /* extract return value */ | ||
69 | |||
70 | ret = VHOOK_DATA(1); | ||
71 | |||
72 | #ifdef USING_SOS | ||
73 | PREEMPT_RESTORE(); | ||
74 | #endif | ||
75 | return ret; | ||
76 | } | ||
77 | |||
78 | unsigned hook_buf(unsigned i) | ||
79 | { | ||
80 | return (HOOK_DATA(i)); | ||
81 | } | ||
82 | |||
83 | void print_str(const char *str) | ||
84 | { | ||
85 | int i; | ||
86 | /* find null at end of string */ | ||
87 | for (i = 1; str[i]; i++) ; | ||
88 | hook_call(hook_print_str, i, str); | ||
89 | } | ||
90 | |||
91 | void CPU_KICK_DOG(void) | ||
92 | { | ||
93 | (void)hook_call(hook_kick_dog, 0); | ||
94 | } | ||
95 | |||
96 | void CPU_WATCHDOG_TIMEOUT(unsigned t) | ||
97 | { | ||
98 | (void)hook_call(hook_dog_timeout, 1, t); | ||
99 | } | ||
100 | |||
diff --git a/arch/cris/arch-v32/mach-fs/vcs_hook.h b/arch/cris/arch-v32/mach-fs/vcs_hook.h new file mode 100644 index 00000000000..c000b9fece4 --- /dev/null +++ b/arch/cris/arch-v32/mach-fs/vcs_hook.h | |||
@@ -0,0 +1,42 @@ | |||
1 | /* | ||
2 | * Call simulator hook functions | ||
3 | */ | ||
4 | |||
5 | #ifndef HOOK_H | ||
6 | #define HOOK_H | ||
7 | |||
8 | int hook_call(unsigned id, unsigned pcnt, ...); | ||
9 | |||
10 | enum hook_ids { | ||
11 | hook_debug_on = 1, | ||
12 | hook_debug_off, | ||
13 | hook_stop_sim_ok, | ||
14 | hook_stop_sim_fail, | ||
15 | hook_alloc_shared, | ||
16 | hook_ptr_shared, | ||
17 | hook_free_shared, | ||
18 | hook_file2shared, | ||
19 | hook_cmp_shared, | ||
20 | hook_print_params, | ||
21 | hook_sim_time, | ||
22 | hook_stop_sim, | ||
23 | hook_kick_dog, | ||
24 | hook_dog_timeout, | ||
25 | hook_rand, | ||
26 | hook_srand, | ||
27 | hook_rand_range, | ||
28 | hook_print_str, | ||
29 | hook_print_hex, | ||
30 | hook_cmp_offset_shared, | ||
31 | hook_fill_random_shared, | ||
32 | hook_alloc_random_data, | ||
33 | hook_calloc_random_data, | ||
34 | hook_print_int, | ||
35 | hook_print_uint, | ||
36 | hook_fputc, | ||
37 | hook_init_fd, | ||
38 | hook_sbrk | ||
39 | |||
40 | }; | ||
41 | |||
42 | #endif | ||