]> git.proxmox.com Git - qemu.git/blob - target-xtensa/op_helper.c
Use uintptr_t for various op related functions
[qemu.git] / target-xtensa / op_helper.c
1 /*
2 * Copyright (c) 2011, Max Filippov, Open Source and Linux Lab.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the Open Source and Linux Lab nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28 #include "cpu.h"
29 #include "dyngen-exec.h"
30 #include "helper.h"
31 #include "host-utils.h"
32
33 static void do_unaligned_access(target_ulong addr, int is_write, int is_user,
34 uintptr_t retaddr);
35
36 #define ALIGNED_ONLY
37 #define MMUSUFFIX _mmu
38
39 #define SHIFT 0
40 #include "softmmu_template.h"
41
42 #define SHIFT 1
43 #include "softmmu_template.h"
44
45 #define SHIFT 2
46 #include "softmmu_template.h"
47
48 #define SHIFT 3
49 #include "softmmu_template.h"
50
51 static void do_restore_state(uintptr_t pc)
52 {
53 TranslationBlock *tb;
54
55 tb = tb_find_pc(pc);
56 if (tb) {
57 cpu_restore_state(tb, env, pc);
58 }
59 }
60
61 static void do_unaligned_access(target_ulong addr, int is_write, int is_user,
62 uintptr_t retaddr)
63 {
64 if (xtensa_option_enabled(env->config, XTENSA_OPTION_UNALIGNED_EXCEPTION) &&
65 !xtensa_option_enabled(env->config, XTENSA_OPTION_HW_ALIGNMENT)) {
66 do_restore_state(retaddr);
67 HELPER(exception_cause_vaddr)(
68 env->pc, LOAD_STORE_ALIGNMENT_CAUSE, addr);
69 }
70 }
71
72 void tlb_fill(CPUXtensaState *env1, target_ulong vaddr, int is_write, int mmu_idx,
73 uintptr_t retaddr)
74 {
75 CPUXtensaState *saved_env = env;
76
77 env = env1;
78 {
79 uint32_t paddr;
80 uint32_t page_size;
81 unsigned access;
82 int ret = xtensa_get_physical_addr(env, vaddr, is_write, mmu_idx,
83 &paddr, &page_size, &access);
84
85 qemu_log("%s(%08x, %d, %d) -> %08x, ret = %d\n", __func__,
86 vaddr, is_write, mmu_idx, paddr, ret);
87
88 if (ret == 0) {
89 tlb_set_page(env,
90 vaddr & TARGET_PAGE_MASK,
91 paddr & TARGET_PAGE_MASK,
92 access, mmu_idx, page_size);
93 } else {
94 do_restore_state(retaddr);
95 HELPER(exception_cause_vaddr)(env->pc, ret, vaddr);
96 }
97 }
98 env = saved_env;
99 }
100
101 void HELPER(exception)(uint32_t excp)
102 {
103 env->exception_index = excp;
104 cpu_loop_exit(env);
105 }
106
107 void HELPER(exception_cause)(uint32_t pc, uint32_t cause)
108 {
109 uint32_t vector;
110
111 env->pc = pc;
112 if (env->sregs[PS] & PS_EXCM) {
113 if (env->config->ndepc) {
114 env->sregs[DEPC] = pc;
115 } else {
116 env->sregs[EPC1] = pc;
117 }
118 vector = EXC_DOUBLE;
119 } else {
120 env->sregs[EPC1] = pc;
121 vector = (env->sregs[PS] & PS_UM) ? EXC_USER : EXC_KERNEL;
122 }
123
124 env->sregs[EXCCAUSE] = cause;
125 env->sregs[PS] |= PS_EXCM;
126
127 HELPER(exception)(vector);
128 }
129
130 void HELPER(exception_cause_vaddr)(uint32_t pc, uint32_t cause, uint32_t vaddr)
131 {
132 env->sregs[EXCVADDR] = vaddr;
133 HELPER(exception_cause)(pc, cause);
134 }
135
136 void debug_exception_env(CPUXtensaState *new_env, uint32_t cause)
137 {
138 if (xtensa_get_cintlevel(new_env) < new_env->config->debug_level) {
139 env = new_env;
140 HELPER(debug_exception)(env->pc, cause);
141 }
142 }
143
144 void HELPER(debug_exception)(uint32_t pc, uint32_t cause)
145 {
146 unsigned level = env->config->debug_level;
147
148 env->pc = pc;
149 env->sregs[DEBUGCAUSE] = cause;
150 env->sregs[EPC1 + level - 1] = pc;
151 env->sregs[EPS2 + level - 2] = env->sregs[PS];
152 env->sregs[PS] = (env->sregs[PS] & ~PS_INTLEVEL) | PS_EXCM |
153 (level << PS_INTLEVEL_SHIFT);
154 HELPER(exception)(EXC_DEBUG);
155 }
156
157 uint32_t HELPER(nsa)(uint32_t v)
158 {
159 if (v & 0x80000000) {
160 v = ~v;
161 }
162 return v ? clz32(v) - 1 : 31;
163 }
164
165 uint32_t HELPER(nsau)(uint32_t v)
166 {
167 return v ? clz32(v) : 32;
168 }
169
170 static void copy_window_from_phys(CPUXtensaState *env,
171 uint32_t window, uint32_t phys, uint32_t n)
172 {
173 assert(phys < env->config->nareg);
174 if (phys + n <= env->config->nareg) {
175 memcpy(env->regs + window, env->phys_regs + phys,
176 n * sizeof(uint32_t));
177 } else {
178 uint32_t n1 = env->config->nareg - phys;
179 memcpy(env->regs + window, env->phys_regs + phys,
180 n1 * sizeof(uint32_t));
181 memcpy(env->regs + window + n1, env->phys_regs,
182 (n - n1) * sizeof(uint32_t));
183 }
184 }
185
186 static void copy_phys_from_window(CPUXtensaState *env,
187 uint32_t phys, uint32_t window, uint32_t n)
188 {
189 assert(phys < env->config->nareg);
190 if (phys + n <= env->config->nareg) {
191 memcpy(env->phys_regs + phys, env->regs + window,
192 n * sizeof(uint32_t));
193 } else {
194 uint32_t n1 = env->config->nareg - phys;
195 memcpy(env->phys_regs + phys, env->regs + window,
196 n1 * sizeof(uint32_t));
197 memcpy(env->phys_regs, env->regs + window + n1,
198 (n - n1) * sizeof(uint32_t));
199 }
200 }
201
202
203 static inline unsigned windowbase_bound(unsigned a, const CPUXtensaState *env)
204 {
205 return a & (env->config->nareg / 4 - 1);
206 }
207
208 static inline unsigned windowstart_bit(unsigned a, const CPUXtensaState *env)
209 {
210 return 1 << windowbase_bound(a, env);
211 }
212
213 void xtensa_sync_window_from_phys(CPUXtensaState *env)
214 {
215 copy_window_from_phys(env, 0, env->sregs[WINDOW_BASE] * 4, 16);
216 }
217
218 void xtensa_sync_phys_from_window(CPUXtensaState *env)
219 {
220 copy_phys_from_window(env, env->sregs[WINDOW_BASE] * 4, 0, 16);
221 }
222
223 static void rotate_window_abs(uint32_t position)
224 {
225 xtensa_sync_phys_from_window(env);
226 env->sregs[WINDOW_BASE] = windowbase_bound(position, env);
227 xtensa_sync_window_from_phys(env);
228 }
229
230 static void rotate_window(uint32_t delta)
231 {
232 rotate_window_abs(env->sregs[WINDOW_BASE] + delta);
233 }
234
235 void HELPER(wsr_windowbase)(uint32_t v)
236 {
237 rotate_window_abs(v);
238 }
239
240 void HELPER(entry)(uint32_t pc, uint32_t s, uint32_t imm)
241 {
242 int callinc = (env->sregs[PS] & PS_CALLINC) >> PS_CALLINC_SHIFT;
243 if (s > 3 || ((env->sregs[PS] & (PS_WOE | PS_EXCM)) ^ PS_WOE) != 0) {
244 qemu_log("Illegal entry instruction(pc = %08x), PS = %08x\n",
245 pc, env->sregs[PS]);
246 HELPER(exception_cause)(pc, ILLEGAL_INSTRUCTION_CAUSE);
247 } else {
248 env->regs[(callinc << 2) | (s & 3)] = env->regs[s] - (imm << 3);
249 rotate_window(callinc);
250 env->sregs[WINDOW_START] |=
251 windowstart_bit(env->sregs[WINDOW_BASE], env);
252 }
253 }
254
255 void HELPER(window_check)(uint32_t pc, uint32_t w)
256 {
257 uint32_t windowbase = windowbase_bound(env->sregs[WINDOW_BASE], env);
258 uint32_t windowstart = env->sregs[WINDOW_START];
259 uint32_t m, n;
260
261 if ((env->sregs[PS] & (PS_WOE | PS_EXCM)) ^ PS_WOE) {
262 return;
263 }
264
265 for (n = 1; ; ++n) {
266 if (n > w) {
267 return;
268 }
269 if (windowstart & windowstart_bit(windowbase + n, env)) {
270 break;
271 }
272 }
273
274 m = windowbase_bound(windowbase + n, env);
275 rotate_window(n);
276 env->sregs[PS] = (env->sregs[PS] & ~PS_OWB) |
277 (windowbase << PS_OWB_SHIFT) | PS_EXCM;
278 env->sregs[EPC1] = env->pc = pc;
279
280 if (windowstart & windowstart_bit(m + 1, env)) {
281 HELPER(exception)(EXC_WINDOW_OVERFLOW4);
282 } else if (windowstart & windowstart_bit(m + 2, env)) {
283 HELPER(exception)(EXC_WINDOW_OVERFLOW8);
284 } else {
285 HELPER(exception)(EXC_WINDOW_OVERFLOW12);
286 }
287 }
288
289 uint32_t HELPER(retw)(uint32_t pc)
290 {
291 int n = (env->regs[0] >> 30) & 0x3;
292 int m = 0;
293 uint32_t windowbase = windowbase_bound(env->sregs[WINDOW_BASE], env);
294 uint32_t windowstart = env->sregs[WINDOW_START];
295 uint32_t ret_pc = 0;
296
297 if (windowstart & windowstart_bit(windowbase - 1, env)) {
298 m = 1;
299 } else if (windowstart & windowstart_bit(windowbase - 2, env)) {
300 m = 2;
301 } else if (windowstart & windowstart_bit(windowbase - 3, env)) {
302 m = 3;
303 }
304
305 if (n == 0 || (m != 0 && m != n) ||
306 ((env->sregs[PS] & (PS_WOE | PS_EXCM)) ^ PS_WOE) != 0) {
307 qemu_log("Illegal retw instruction(pc = %08x), "
308 "PS = %08x, m = %d, n = %d\n",
309 pc, env->sregs[PS], m, n);
310 HELPER(exception_cause)(pc, ILLEGAL_INSTRUCTION_CAUSE);
311 } else {
312 int owb = windowbase;
313
314 ret_pc = (pc & 0xc0000000) | (env->regs[0] & 0x3fffffff);
315
316 rotate_window(-n);
317 if (windowstart & windowstart_bit(env->sregs[WINDOW_BASE], env)) {
318 env->sregs[WINDOW_START] &= ~windowstart_bit(owb, env);
319 } else {
320 /* window underflow */
321 env->sregs[PS] = (env->sregs[PS] & ~PS_OWB) |
322 (windowbase << PS_OWB_SHIFT) | PS_EXCM;
323 env->sregs[EPC1] = env->pc = pc;
324
325 if (n == 1) {
326 HELPER(exception)(EXC_WINDOW_UNDERFLOW4);
327 } else if (n == 2) {
328 HELPER(exception)(EXC_WINDOW_UNDERFLOW8);
329 } else if (n == 3) {
330 HELPER(exception)(EXC_WINDOW_UNDERFLOW12);
331 }
332 }
333 }
334 return ret_pc;
335 }
336
337 void HELPER(rotw)(uint32_t imm4)
338 {
339 rotate_window(imm4);
340 }
341
342 void HELPER(restore_owb)(void)
343 {
344 rotate_window_abs((env->sregs[PS] & PS_OWB) >> PS_OWB_SHIFT);
345 }
346
347 void HELPER(movsp)(uint32_t pc)
348 {
349 if ((env->sregs[WINDOW_START] &
350 (windowstart_bit(env->sregs[WINDOW_BASE] - 3, env) |
351 windowstart_bit(env->sregs[WINDOW_BASE] - 2, env) |
352 windowstart_bit(env->sregs[WINDOW_BASE] - 1, env))) == 0) {
353 HELPER(exception_cause)(pc, ALLOCA_CAUSE);
354 }
355 }
356
357 void HELPER(wsr_lbeg)(uint32_t v)
358 {
359 if (env->sregs[LBEG] != v) {
360 tb_invalidate_phys_page_range(
361 env->sregs[LEND] - 1, env->sregs[LEND], 0);
362 env->sregs[LBEG] = v;
363 }
364 }
365
366 void HELPER(wsr_lend)(uint32_t v)
367 {
368 if (env->sregs[LEND] != v) {
369 tb_invalidate_phys_page_range(
370 env->sregs[LEND] - 1, env->sregs[LEND], 0);
371 env->sregs[LEND] = v;
372 tb_invalidate_phys_page_range(
373 env->sregs[LEND] - 1, env->sregs[LEND], 0);
374 }
375 }
376
377 void HELPER(dump_state)(void)
378 {
379 cpu_dump_state(env, stderr, fprintf, 0);
380 }
381
382 void HELPER(waiti)(uint32_t pc, uint32_t intlevel)
383 {
384 env->pc = pc;
385 env->sregs[PS] = (env->sregs[PS] & ~PS_INTLEVEL) |
386 (intlevel << PS_INTLEVEL_SHIFT);
387 check_interrupts(env);
388 if (env->pending_irq_level) {
389 cpu_loop_exit(env);
390 return;
391 }
392
393 env->halt_clock = qemu_get_clock_ns(vm_clock);
394 env->halted = 1;
395 if (xtensa_option_enabled(env->config, XTENSA_OPTION_TIMER_INTERRUPT)) {
396 xtensa_rearm_ccompare_timer(env);
397 }
398 HELPER(exception)(EXCP_HLT);
399 }
400
401 void HELPER(timer_irq)(uint32_t id, uint32_t active)
402 {
403 xtensa_timer_irq(env, id, active);
404 }
405
406 void HELPER(advance_ccount)(uint32_t d)
407 {
408 xtensa_advance_ccount(env, d);
409 }
410
411 void HELPER(check_interrupts)(CPUXtensaState *env)
412 {
413 check_interrupts(env);
414 }
415
416 void HELPER(wsr_rasid)(uint32_t v)
417 {
418 v = (v & 0xffffff00) | 0x1;
419 if (v != env->sregs[RASID]) {
420 env->sregs[RASID] = v;
421 tlb_flush(env, 1);
422 }
423 }
424
425 static uint32_t get_page_size(const CPUXtensaState *env, bool dtlb, uint32_t way)
426 {
427 uint32_t tlbcfg = env->sregs[dtlb ? DTLBCFG : ITLBCFG];
428
429 switch (way) {
430 case 4:
431 return (tlbcfg >> 16) & 0x3;
432
433 case 5:
434 return (tlbcfg >> 20) & 0x1;
435
436 case 6:
437 return (tlbcfg >> 24) & 0x1;
438
439 default:
440 return 0;
441 }
442 }
443
444 /*!
445 * Get bit mask for the virtual address bits translated by the TLB way
446 */
447 uint32_t xtensa_tlb_get_addr_mask(const CPUXtensaState *env, bool dtlb, uint32_t way)
448 {
449 if (xtensa_option_enabled(env->config, XTENSA_OPTION_MMU)) {
450 bool varway56 = dtlb ?
451 env->config->dtlb.varway56 :
452 env->config->itlb.varway56;
453
454 switch (way) {
455 case 4:
456 return 0xfff00000 << get_page_size(env, dtlb, way) * 2;
457
458 case 5:
459 if (varway56) {
460 return 0xf8000000 << get_page_size(env, dtlb, way);
461 } else {
462 return 0xf8000000;
463 }
464
465 case 6:
466 if (varway56) {
467 return 0xf0000000 << (1 - get_page_size(env, dtlb, way));
468 } else {
469 return 0xf0000000;
470 }
471
472 default:
473 return 0xfffff000;
474 }
475 } else {
476 return REGION_PAGE_MASK;
477 }
478 }
479
480 /*!
481 * Get bit mask for the 'VPN without index' field.
482 * See ISA, 4.6.5.6, data format for RxTLB0
483 */
484 static uint32_t get_vpn_mask(const CPUXtensaState *env, bool dtlb, uint32_t way)
485 {
486 if (way < 4) {
487 bool is32 = (dtlb ?
488 env->config->dtlb.nrefillentries :
489 env->config->itlb.nrefillentries) == 32;
490 return is32 ? 0xffff8000 : 0xffffc000;
491 } else if (way == 4) {
492 return xtensa_tlb_get_addr_mask(env, dtlb, way) << 2;
493 } else if (way <= 6) {
494 uint32_t mask = xtensa_tlb_get_addr_mask(env, dtlb, way);
495 bool varway56 = dtlb ?
496 env->config->dtlb.varway56 :
497 env->config->itlb.varway56;
498
499 if (varway56) {
500 return mask << (way == 5 ? 2 : 3);
501 } else {
502 return mask << 1;
503 }
504 } else {
505 return 0xfffff000;
506 }
507 }
508
509 /*!
510 * Split virtual address into VPN (with index) and entry index
511 * for the given TLB way
512 */
513 void split_tlb_entry_spec_way(const CPUXtensaState *env, uint32_t v, bool dtlb,
514 uint32_t *vpn, uint32_t wi, uint32_t *ei)
515 {
516 bool varway56 = dtlb ?
517 env->config->dtlb.varway56 :
518 env->config->itlb.varway56;
519
520 if (!dtlb) {
521 wi &= 7;
522 }
523
524 if (wi < 4) {
525 bool is32 = (dtlb ?
526 env->config->dtlb.nrefillentries :
527 env->config->itlb.nrefillentries) == 32;
528 *ei = (v >> 12) & (is32 ? 0x7 : 0x3);
529 } else {
530 switch (wi) {
531 case 4:
532 {
533 uint32_t eibase = 20 + get_page_size(env, dtlb, wi) * 2;
534 *ei = (v >> eibase) & 0x3;
535 }
536 break;
537
538 case 5:
539 if (varway56) {
540 uint32_t eibase = 27 + get_page_size(env, dtlb, wi);
541 *ei = (v >> eibase) & 0x3;
542 } else {
543 *ei = (v >> 27) & 0x1;
544 }
545 break;
546
547 case 6:
548 if (varway56) {
549 uint32_t eibase = 29 - get_page_size(env, dtlb, wi);
550 *ei = (v >> eibase) & 0x7;
551 } else {
552 *ei = (v >> 28) & 0x1;
553 }
554 break;
555
556 default:
557 *ei = 0;
558 break;
559 }
560 }
561 *vpn = v & xtensa_tlb_get_addr_mask(env, dtlb, wi);
562 }
563
564 /*!
565 * Split TLB address into TLB way, entry index and VPN (with index).
566 * See ISA, 4.6.5.5 - 4.6.5.8 for the TLB addressing format
567 */
568 static void split_tlb_entry_spec(uint32_t v, bool dtlb,
569 uint32_t *vpn, uint32_t *wi, uint32_t *ei)
570 {
571 if (xtensa_option_enabled(env->config, XTENSA_OPTION_MMU)) {
572 *wi = v & (dtlb ? 0xf : 0x7);
573 split_tlb_entry_spec_way(env, v, dtlb, vpn, *wi, ei);
574 } else {
575 *vpn = v & REGION_PAGE_MASK;
576 *wi = 0;
577 *ei = (v >> 29) & 0x7;
578 }
579 }
580
581 static xtensa_tlb_entry *get_tlb_entry(uint32_t v, bool dtlb, uint32_t *pwi)
582 {
583 uint32_t vpn;
584 uint32_t wi;
585 uint32_t ei;
586
587 split_tlb_entry_spec(v, dtlb, &vpn, &wi, &ei);
588 if (pwi) {
589 *pwi = wi;
590 }
591 return xtensa_tlb_get_entry(env, dtlb, wi, ei);
592 }
593
594 uint32_t HELPER(rtlb0)(uint32_t v, uint32_t dtlb)
595 {
596 if (xtensa_option_enabled(env->config, XTENSA_OPTION_MMU)) {
597 uint32_t wi;
598 const xtensa_tlb_entry *entry = get_tlb_entry(v, dtlb, &wi);
599 return (entry->vaddr & get_vpn_mask(env, dtlb, wi)) | entry->asid;
600 } else {
601 return v & REGION_PAGE_MASK;
602 }
603 }
604
605 uint32_t HELPER(rtlb1)(uint32_t v, uint32_t dtlb)
606 {
607 const xtensa_tlb_entry *entry = get_tlb_entry(v, dtlb, NULL);
608 return entry->paddr | entry->attr;
609 }
610
611 void HELPER(itlb)(uint32_t v, uint32_t dtlb)
612 {
613 if (xtensa_option_enabled(env->config, XTENSA_OPTION_MMU)) {
614 uint32_t wi;
615 xtensa_tlb_entry *entry = get_tlb_entry(v, dtlb, &wi);
616 if (entry->variable && entry->asid) {
617 tlb_flush_page(env, entry->vaddr);
618 entry->asid = 0;
619 }
620 }
621 }
622
623 uint32_t HELPER(ptlb)(uint32_t v, uint32_t dtlb)
624 {
625 if (xtensa_option_enabled(env->config, XTENSA_OPTION_MMU)) {
626 uint32_t wi;
627 uint32_t ei;
628 uint8_t ring;
629 int res = xtensa_tlb_lookup(env, v, dtlb, &wi, &ei, &ring);
630
631 switch (res) {
632 case 0:
633 if (ring >= xtensa_get_ring(env)) {
634 return (v & 0xfffff000) | wi | (dtlb ? 0x10 : 0x8);
635 }
636 break;
637
638 case INST_TLB_MULTI_HIT_CAUSE:
639 case LOAD_STORE_TLB_MULTI_HIT_CAUSE:
640 HELPER(exception_cause_vaddr)(env->pc, res, v);
641 break;
642 }
643 return 0;
644 } else {
645 return (v & REGION_PAGE_MASK) | 0x1;
646 }
647 }
648
649 void xtensa_tlb_set_entry(CPUXtensaState *env, bool dtlb,
650 unsigned wi, unsigned ei, uint32_t vpn, uint32_t pte)
651 {
652 xtensa_tlb_entry *entry = xtensa_tlb_get_entry(env, dtlb, wi, ei);
653
654 if (xtensa_option_enabled(env->config, XTENSA_OPTION_MMU)) {
655 if (entry->variable) {
656 if (entry->asid) {
657 tlb_flush_page(env, entry->vaddr);
658 }
659 entry->vaddr = vpn;
660 entry->paddr = pte & xtensa_tlb_get_addr_mask(env, dtlb, wi);
661 entry->asid = (env->sregs[RASID] >> ((pte >> 1) & 0x18)) & 0xff;
662 entry->attr = pte & 0xf;
663 } else {
664 qemu_log("%s %d, %d, %d trying to set immutable entry\n",
665 __func__, dtlb, wi, ei);
666 }
667 } else {
668 tlb_flush_page(env, entry->vaddr);
669 if (xtensa_option_enabled(env->config,
670 XTENSA_OPTION_REGION_TRANSLATION)) {
671 entry->paddr = pte & REGION_PAGE_MASK;
672 }
673 entry->attr = pte & 0xf;
674 }
675 }
676
677 void HELPER(wtlb)(uint32_t p, uint32_t v, uint32_t dtlb)
678 {
679 uint32_t vpn;
680 uint32_t wi;
681 uint32_t ei;
682 split_tlb_entry_spec(v, dtlb, &vpn, &wi, &ei);
683 xtensa_tlb_set_entry(env, dtlb, wi, ei, vpn, p);
684 }
685
686
687 void HELPER(wsr_ibreakenable)(uint32_t v)
688 {
689 uint32_t change = v ^ env->sregs[IBREAKENABLE];
690 unsigned i;
691
692 for (i = 0; i < env->config->nibreak; ++i) {
693 if (change & (1 << i)) {
694 tb_invalidate_phys_page_range(
695 env->sregs[IBREAKA + i], env->sregs[IBREAKA + i] + 1, 0);
696 }
697 }
698 env->sregs[IBREAKENABLE] = v & ((1 << env->config->nibreak) - 1);
699 }
700
701 void HELPER(wsr_ibreaka)(uint32_t i, uint32_t v)
702 {
703 if (env->sregs[IBREAKENABLE] & (1 << i) && env->sregs[IBREAKA + i] != v) {
704 tb_invalidate_phys_page_range(
705 env->sregs[IBREAKA + i], env->sregs[IBREAKA + i] + 1, 0);
706 tb_invalidate_phys_page_range(v, v + 1, 0);
707 }
708 env->sregs[IBREAKA + i] = v;
709 }
710
711 static void set_dbreak(unsigned i, uint32_t dbreaka, uint32_t dbreakc)
712 {
713 int flags = BP_CPU | BP_STOP_BEFORE_ACCESS;
714 uint32_t mask = dbreakc | ~DBREAKC_MASK;
715
716 if (env->cpu_watchpoint[i]) {
717 cpu_watchpoint_remove_by_ref(env, env->cpu_watchpoint[i]);
718 }
719 if (dbreakc & DBREAKC_SB) {
720 flags |= BP_MEM_WRITE;
721 }
722 if (dbreakc & DBREAKC_LB) {
723 flags |= BP_MEM_READ;
724 }
725 /* contiguous mask after inversion is one less than some power of 2 */
726 if ((~mask + 1) & ~mask) {
727 qemu_log("DBREAKC mask is not contiguous: 0x%08x\n", dbreakc);
728 /* cut mask after the first zero bit */
729 mask = 0xffffffff << (32 - clo32(mask));
730 }
731 if (cpu_watchpoint_insert(env, dbreaka & mask, ~mask + 1,
732 flags, &env->cpu_watchpoint[i])) {
733 env->cpu_watchpoint[i] = NULL;
734 qemu_log("Failed to set data breakpoint at 0x%08x/%d\n",
735 dbreaka & mask, ~mask + 1);
736 }
737 }
738
739 void HELPER(wsr_dbreaka)(uint32_t i, uint32_t v)
740 {
741 uint32_t dbreakc = env->sregs[DBREAKC + i];
742
743 if ((dbreakc & DBREAKC_SB_LB) &&
744 env->sregs[DBREAKA + i] != v) {
745 set_dbreak(i, v, dbreakc);
746 }
747 env->sregs[DBREAKA + i] = v;
748 }
749
750 void HELPER(wsr_dbreakc)(uint32_t i, uint32_t v)
751 {
752 if ((env->sregs[DBREAKC + i] ^ v) & (DBREAKC_SB_LB | DBREAKC_MASK)) {
753 if (v & DBREAKC_SB_LB) {
754 set_dbreak(i, env->sregs[DBREAKA + i], v);
755 } else {
756 if (env->cpu_watchpoint[i]) {
757 cpu_watchpoint_remove_by_ref(env, env->cpu_watchpoint[i]);
758 env->cpu_watchpoint[i] = NULL;
759 }
760 }
761 }
762 env->sregs[DBREAKC + i] = v;
763 }