qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio

target/sh4: Use env_cpu, env_archcpu

Cleanup in the boilerplate that each target must define.
Replace sh_env_get_cpu with env_archcpu. The combination
CPU(sh_env_get_cpu) should have used ENV_GET_CPU to begin;
use env_cpu now.

Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>

+16 -26
+1 -1
linux-user/sh4/cpu_loop.c
··· 23 23 24 24 void cpu_loop(CPUSH4State *env) 25 25 { 26 - CPUState *cs = CPU(sh_env_get_cpu(env)); 26 + CPUState *cs = env_cpu(env); 27 27 int trapnr, ret; 28 28 target_siginfo_t info; 29 29
-5
target/sh4/cpu.h
··· 207 207 CPUSH4State env; 208 208 }; 209 209 210 - static inline SuperHCPU *sh_env_get_cpu(CPUSH4State *env) 211 - { 212 - return container_of(env, SuperHCPU, env); 213 - } 214 - 215 210 #define ENV_OFFSET offsetof(SuperHCPU, env) 216 211 217 212 void superh_cpu_do_interrupt(CPUState *cpu);
+12 -14
target/sh4/helper.c
··· 216 216 217 217 static int itlb_replacement(CPUSH4State * env) 218 218 { 219 - SuperHCPU *cpu = sh_env_get_cpu(env); 220 - 221 219 if ((env->mmucr & 0xe0000000) == 0xe0000000) { 222 220 return 0; 223 221 } ··· 230 228 if ((env->mmucr & 0x2c000000) == 0x00000000) { 231 229 return 3; 232 230 } 233 - cpu_abort(CPU(cpu), "Unhandled itlb_replacement"); 231 + cpu_abort(env_cpu(env), "Unhandled itlb_replacement"); 234 232 } 235 233 236 234 /* Find the corresponding entry in the right TLB ··· 286 284 itlb = itlb_replacement(env); 287 285 ientry = &env->itlb[itlb]; 288 286 if (ientry->v) { 289 - tlb_flush_page(CPU(sh_env_get_cpu(env)), ientry->vpn << 10); 287 + tlb_flush_page(env_cpu(env), ientry->vpn << 10); 290 288 } 291 289 *ientry = env->utlb[utlb]; 292 290 update_itlb_use(env, itlb); ··· 448 446 449 447 void cpu_load_tlb(CPUSH4State * env) 450 448 { 451 - SuperHCPU *cpu = sh_env_get_cpu(env); 449 + CPUState *cs = env_cpu(env); 452 450 int n = cpu_mmucr_urc(env->mmucr); 453 451 tlb_t * entry = &env->utlb[n]; 454 452 455 453 if (entry->v) { 456 454 /* Overwriting valid entry in utlb. */ 457 455 target_ulong address = entry->vpn << 10; 458 - tlb_flush_page(CPU(cpu), address); 456 + tlb_flush_page(cs, address); 459 457 } 460 458 461 459 /* Take values into cpu status from registers. */ ··· 478 476 entry->size = 1024 * 1024; /* 1M */ 479 477 break; 480 478 default: 481 - cpu_abort(CPU(cpu), "Unhandled load_tlb"); 479 + cpu_abort(cs, "Unhandled load_tlb"); 482 480 break; 483 481 } 484 482 entry->sh = (uint8_t)cpu_ptel_sh(env->ptel); ··· 505 503 entry->v = 0; 506 504 } 507 505 508 - tlb_flush(CPU(sh_env_get_cpu(s))); 506 + tlb_flush(env_cpu(s)); 509 507 } 510 508 511 509 uint32_t cpu_sh4_read_mmaped_itlb_addr(CPUSH4State *s, ··· 531 529 if (entry->v) { 532 530 /* Overwriting valid entry in itlb. */ 533 531 target_ulong address = entry->vpn << 10; 534 - tlb_flush_page(CPU(sh_env_get_cpu(s)), address); 532 + tlb_flush_page(env_cpu(s), address); 535 533 } 536 534 entry->asid = asid; 537 535 entry->vpn = vpn; ··· 573 571 if (entry->v) { 574 572 /* Overwriting valid entry in utlb. */ 575 573 target_ulong address = entry->vpn << 10; 576 - tlb_flush_page(CPU(sh_env_get_cpu(s)), address); 574 + tlb_flush_page(env_cpu(s), address); 577 575 } 578 576 entry->ppn = (mem_value & 0x1ffffc00) >> 10; 579 577 entry->v = (mem_value & 0x00000100) >> 8; ··· 626 624 if (entry->vpn == vpn 627 625 && (!use_asid || entry->asid == asid || entry->sh)) { 628 626 if (utlb_match_entry) { 629 - CPUState *cs = CPU(sh_env_get_cpu(s)); 627 + CPUState *cs = env_cpu(s); 630 628 631 629 /* Multiple TLB Exception */ 632 630 cs->exception_index = 0x140; ··· 658 656 } 659 657 660 658 if (needs_tlb_flush) { 661 - tlb_flush_page(CPU(sh_env_get_cpu(s)), vpn << 10); 659 + tlb_flush_page(env_cpu(s), vpn << 10); 662 660 } 663 661 } else { 664 662 int index = (addr & 0x00003f00) >> 8; 665 663 tlb_t * entry = &s->utlb[index]; 666 664 if (entry->v) { 667 - CPUState *cs = CPU(sh_env_get_cpu(s)); 665 + CPUState *cs = env_cpu(s); 668 666 669 667 /* Overwriting valid entry in utlb. */ 670 668 target_ulong address = entry->vpn << 10; ··· 719 717 if (entry->v) { 720 718 /* Overwriting valid entry in utlb. */ 721 719 target_ulong address = entry->vpn << 10; 722 - tlb_flush_page(CPU(sh_env_get_cpu(s)), address); 720 + tlb_flush_page(env_cpu(s), address); 723 721 } 724 722 entry->ppn = (mem_value & 0x1ffffc00) >> 10; 725 723 entry->v = (mem_value & 0x00000100) >> 8;
+3 -6
target/sh4/op_helper.c
··· 46 46 void helper_ldtlb(CPUSH4State *env) 47 47 { 48 48 #ifdef CONFIG_USER_ONLY 49 - SuperHCPU *cpu = sh_env_get_cpu(env); 50 - 51 - /* XXXXX */ 52 - cpu_abort(CPU(cpu), "Unhandled ldtlb"); 49 + cpu_abort(env_cpu(env), "Unhandled ldtlb"); 53 50 #else 54 51 cpu_load_tlb(env); 55 52 #endif ··· 58 55 static inline void QEMU_NORETURN raise_exception(CPUSH4State *env, int index, 59 56 uintptr_t retaddr) 60 57 { 61 - CPUState *cs = CPU(sh_env_get_cpu(env)); 58 + CPUState *cs = env_cpu(env); 62 59 63 60 cs->exception_index = index; 64 61 cpu_loop_exit_restore(cs, retaddr); ··· 91 88 92 89 void helper_sleep(CPUSH4State *env) 93 90 { 94 - CPUState *cs = CPU(sh_env_get_cpu(env)); 91 + CPUState *cs = env_cpu(env); 95 92 96 93 cs->halted = 1; 97 94 env->in_sleep = 1;