2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
6 * Copyright (C) 2008 David Daney
9 #include <linux/sched.h>
11 #include <asm/processor.h>
12 #include <asm/watch.h>
15 * Install the watch registers for the current thread. A maximum of
16 * four registers are installed although the machine may have more.
18 void mips_install_watch_registers(struct task_struct
*t
)
20 struct mips3264_watch_reg_state
*watches
= &t
->thread
.watch
.mips3264
;
21 switch (current_cpu_data
.watch_reg_use_cnt
) {
25 write_c0_watchlo3(watches
->watchlo
[3]);
26 /* Write 1 to the I, R, and W bits to clear them, and
27 1 to G so all ASIDs are trapped. */
28 write_c0_watchhi3(MIPS_WATCHHI_G
| MIPS_WATCHHI_IRW
|
31 write_c0_watchlo2(watches
->watchlo
[2]);
32 write_c0_watchhi2(MIPS_WATCHHI_G
| MIPS_WATCHHI_IRW
|
35 write_c0_watchlo1(watches
->watchlo
[1]);
36 write_c0_watchhi1(MIPS_WATCHHI_G
| MIPS_WATCHHI_IRW
|
39 write_c0_watchlo0(watches
->watchlo
[0]);
40 write_c0_watchhi0(MIPS_WATCHHI_G
| MIPS_WATCHHI_IRW
|
46 * Read back the watchhi registers so the user space debugger has
47 * access to the I, R, and W bits. A maximum of four registers are
48 * read although the machine may have more.
50 void mips_read_watch_registers(void)
52 struct mips3264_watch_reg_state
*watches
=
53 ¤t
->thread
.watch
.mips3264
;
54 switch (current_cpu_data
.watch_reg_use_cnt
) {
58 watches
->watchhi
[3] = (read_c0_watchhi3() &
59 (MIPS_WATCHHI_MASK
| MIPS_WATCHHI_IRW
));
61 watches
->watchhi
[2] = (read_c0_watchhi2() &
62 (MIPS_WATCHHI_MASK
| MIPS_WATCHHI_IRW
));
64 watches
->watchhi
[1] = (read_c0_watchhi1() &
65 (MIPS_WATCHHI_MASK
| MIPS_WATCHHI_IRW
));
67 watches
->watchhi
[0] = (read_c0_watchhi0() &
68 (MIPS_WATCHHI_MASK
| MIPS_WATCHHI_IRW
));
70 if (current_cpu_data
.watch_reg_use_cnt
== 1 &&
71 (watches
->watchhi
[0] & MIPS_WATCHHI_IRW
) == 0) {
72 /* Pathological case of release 1 architecture that
73 * doesn't set the condition bits. We assume that
74 * since we got here, the watch condition was met and
75 * signal that the conditions requested in watchlo
77 watches
->watchhi
[0] |= (watches
->watchlo
[0] & MIPS_WATCHHI_IRW
);
82 * Disable all watch registers. Although only four registers are
83 * installed, all are cleared to eliminate the possibility of endless
84 * looping in the watch handler.
86 void mips_clear_watch_registers(void)
88 switch (current_cpu_data
.watch_reg_count
) {
100 write_c0_watchlo3(0);
102 write_c0_watchlo2(0);
104 write_c0_watchlo1(0);
106 write_c0_watchlo0(0);
110 void mips_probe_watch_registers(struct cpuinfo_mips
*c
)
114 if ((c
->options
& MIPS_CPU_WATCH
) == 0)
117 * Check which of the I,R and W bits are supported, then
118 * disable the register.
120 write_c0_watchlo0(MIPS_WATCHLO_IRW
);
121 back_to_back_c0_hazard();
122 t
= read_c0_watchlo0();
123 write_c0_watchlo0(0);
124 c
->watch_reg_masks
[0] = t
& MIPS_WATCHLO_IRW
;
126 /* Write the mask bits and read them back to determine which
128 c
->watch_reg_count
= 1;
129 c
->watch_reg_use_cnt
= 1;
130 t
= read_c0_watchhi0();
131 write_c0_watchhi0(t
| MIPS_WATCHHI_MASK
);
132 back_to_back_c0_hazard();
133 t
= read_c0_watchhi0();
134 c
->watch_reg_masks
[0] |= (t
& MIPS_WATCHHI_MASK
);
135 if ((t
& MIPS_WATCHHI_M
) == 0)
138 write_c0_watchlo1(MIPS_WATCHLO_IRW
);
139 back_to_back_c0_hazard();
140 t
= read_c0_watchlo1();
141 write_c0_watchlo1(0);
142 c
->watch_reg_masks
[1] = t
& MIPS_WATCHLO_IRW
;
144 c
->watch_reg_count
= 2;
145 c
->watch_reg_use_cnt
= 2;
146 t
= read_c0_watchhi1();
147 write_c0_watchhi1(t
| MIPS_WATCHHI_MASK
);
148 back_to_back_c0_hazard();
149 t
= read_c0_watchhi1();
150 c
->watch_reg_masks
[1] |= (t
& MIPS_WATCHHI_MASK
);
151 if ((t
& MIPS_WATCHHI_M
) == 0)
154 write_c0_watchlo2(MIPS_WATCHLO_IRW
);
155 back_to_back_c0_hazard();
156 t
= read_c0_watchlo2();
157 write_c0_watchlo2(0);
158 c
->watch_reg_masks
[2] = t
& MIPS_WATCHLO_IRW
;
160 c
->watch_reg_count
= 3;
161 c
->watch_reg_use_cnt
= 3;
162 t
= read_c0_watchhi2();
163 write_c0_watchhi2(t
| MIPS_WATCHHI_MASK
);
164 back_to_back_c0_hazard();
165 t
= read_c0_watchhi2();
166 c
->watch_reg_masks
[2] |= (t
& MIPS_WATCHHI_MASK
);
167 if ((t
& MIPS_WATCHHI_M
) == 0)
170 write_c0_watchlo3(MIPS_WATCHLO_IRW
);
171 back_to_back_c0_hazard();
172 t
= read_c0_watchlo3();
173 write_c0_watchlo3(0);
174 c
->watch_reg_masks
[3] = t
& MIPS_WATCHLO_IRW
;
176 c
->watch_reg_count
= 4;
177 c
->watch_reg_use_cnt
= 4;
178 t
= read_c0_watchhi3();
179 write_c0_watchhi3(t
| MIPS_WATCHHI_MASK
);
180 back_to_back_c0_hazard();
181 t
= read_c0_watchhi3();
182 c
->watch_reg_masks
[3] |= (t
& MIPS_WATCHHI_MASK
);
183 if ((t
& MIPS_WATCHHI_M
) == 0)
186 /* We use at most 4, but probe and report up to 8. */
187 c
->watch_reg_count
= 5;
188 t
= read_c0_watchhi4();
189 if ((t
& MIPS_WATCHHI_M
) == 0)
192 c
->watch_reg_count
= 6;
193 t
= read_c0_watchhi5();
194 if ((t
& MIPS_WATCHHI_M
) == 0)
197 c
->watch_reg_count
= 7;
198 t
= read_c0_watchhi6();
199 if ((t
& MIPS_WATCHHI_M
) == 0)
202 c
->watch_reg_count
= 8;