From 9e3c8de30bafe33f35e4b9e82fb49418941f8cb7 Mon Sep 17 00:00:00 2001 From: Andreas Hansson Date: Fri, 24 Feb 2012 11:45:30 -0500 Subject: MEM: Make port proxies use references rather than pointers This patch is adding a clearer design intent to all objects that would not be complete without a port proxy by making the proxies members rathen than dynamically allocated. In essence, if NULL would not be a valid value for the proxy, then we avoid using a pointer to make this clear. The same approach is used for the methods using these proxies, such as loadSections, that now use references rather than pointers to better reflect the fact that NULL would not be an acceptable value (in fact the code would break and that is how this patch started out). Overall the concept of "using a reference to express unconditional composition where a NULL pointer is never valid" could be done on a much broader scale throughout the code base, but for now it is only done in the locations affected by the proxies. --- src/arch/alpha/freebsd/system.cc | 4 ++-- src/arch/alpha/linux/system.cc | 18 ++++++++---------- src/arch/alpha/linux/threadinfo.hh | 4 ++-- src/arch/alpha/process.cc | 6 +++--- src/arch/alpha/stacktrace.cc | 24 ++++++++++-------------- src/arch/alpha/system.cc | 14 +++++++------- src/arch/alpha/tru64/system.cc | 2 +- src/arch/alpha/utility.cc | 7 ++++--- src/arch/alpha/vtophys.cc | 8 ++++---- src/arch/alpha/vtophys.hh | 2 +- 10 files changed, 42 insertions(+), 47 deletions(-) (limited to 'src/arch/alpha') diff --git a/src/arch/alpha/freebsd/system.cc b/src/arch/alpha/freebsd/system.cc index 81aea8696..303d5f762 100644 --- a/src/arch/alpha/freebsd/system.cc +++ b/src/arch/alpha/freebsd/system.cc @@ -76,8 +76,8 @@ FreebsdAlphaSystem::doCalibrateClocks(ThreadContext *tc) ppc_vaddr = (Addr)tc->readIntReg(17); timer_vaddr = (Addr)tc->readIntReg(18); - virtProxy->write(ppc_vaddr, (uint32_t)SimClock::Frequency); - virtProxy->write(timer_vaddr, (uint32_t)TIMER_FREQUENCY); + virtProxy.write(ppc_vaddr, (uint32_t)SimClock::Frequency); + virtProxy.write(timer_vaddr, (uint32_t)TIMER_FREQUENCY); } void diff --git a/src/arch/alpha/linux/system.cc b/src/arch/alpha/linux/system.cc index 6f3cf6b32..e42553b63 100644 --- a/src/arch/alpha/linux/system.cc +++ b/src/arch/alpha/linux/system.cc @@ -88,9 +88,9 @@ LinuxAlphaSystem::initState() * Since we aren't using a bootloader, we have to copy the * kernel arguments directly into the kernel's memory. */ - virtProxy->writeBlob(CommandLine(), - (uint8_t*)params()->boot_osflags.c_str(), - params()->boot_osflags.length()+1); + virtProxy.writeBlob(CommandLine(), + (uint8_t*)params()->boot_osflags.c_str(), + params()->boot_osflags.length()+1); /** * find the address of the est_cycle_freq variable and insert it @@ -98,8 +98,8 @@ LinuxAlphaSystem::initState() * calculated it by using the PIT, RTC, etc. */ if (kernelSymtab->findAddress("est_cycle_freq", addr)) - virtProxy->write(addr, (uint64_t)(SimClock::Frequency / - params()->boot_cpu_frequency)); + virtProxy.write(addr, (uint64_t)(SimClock::Frequency / + params()->boot_cpu_frequency)); /** @@ -109,7 +109,7 @@ LinuxAlphaSystem::initState() * 255 ASNs. */ if (kernelSymtab->findAddress("dp264_mv", addr)) - virtProxy->write(addr + 0x18, LittleEndianGuest::htog((uint32_t)127)); + virtProxy.write(addr + 0x18, LittleEndianGuest::htog((uint32_t)127)); else panic("could not find dp264_mv\n"); @@ -176,10 +176,8 @@ LinuxAlphaSystem::setDelayLoop(ThreadContext *tc) if (kernelSymtab->findAddress("loops_per_jiffy", addr)) { Tick cpuFreq = tc->getCpuPtr()->frequency(); assert(intrFreq); - FSTranslatingPortProxy* vp; - - vp = tc->getVirtProxy(); - vp->writeHtoG(addr, (uint32_t)((cpuFreq / intrFreq) * 0.9988)); + FSTranslatingPortProxy &vp = tc->getVirtProxy(); + vp.writeHtoG(addr, (uint32_t)((cpuFreq / intrFreq) * 0.9988)); } } diff --git a/src/arch/alpha/linux/threadinfo.hh b/src/arch/alpha/linux/threadinfo.hh index 262da9007..94e362fe7 100644 --- a/src/arch/alpha/linux/threadinfo.hh +++ b/src/arch/alpha/linux/threadinfo.hh @@ -78,8 +78,8 @@ class ThreadInfo if (!addr) addr = tc->readMiscRegNoEffect(AlphaISA::IPR_PALtemp23); - PortProxy* p = tc->getPhysProxy(); - p->readBlob(addr, (uint8_t *)&sp, sizeof(Addr)); + PortProxy &p = tc->getPhysProxy(); + p.readBlob(addr, (uint8_t *)&sp, sizeof(Addr)); return sp & ~ULL(0x3fff); } diff --git a/src/arch/alpha/process.cc b/src/arch/alpha/process.cc index 4a3079264..07208fb29 100644 --- a/src/arch/alpha/process.cc +++ b/src/arch/alpha/process.cc @@ -144,16 +144,16 @@ AlphaLiveProcess::argsInit(int intSize, int pageSize) else panic("Unknown int size"); - initVirtMem->writeBlob(stack_min, (uint8_t*)&argc, intSize); + initVirtMem.writeBlob(stack_min, (uint8_t*)&argc, intSize); copyStringArray(argv, argv_array_base, arg_data_base, initVirtMem); copyStringArray(envp, envp_array_base, env_data_base, initVirtMem); //Copy the aux stuff for (vector::size_type x = 0; x < auxv.size(); x++) { - initVirtMem->writeBlob(auxv_array_base + x * 2 * intSize, + initVirtMem.writeBlob(auxv_array_base + x * 2 * intSize, (uint8_t*)&(auxv[x].a_type), intSize); - initVirtMem->writeBlob(auxv_array_base + (x * 2 + 1) * intSize, + initVirtMem.writeBlob(auxv_array_base + (x * 2 + 1) * intSize, (uint8_t*)&(auxv[x].a_val), intSize); } diff --git a/src/arch/alpha/stacktrace.cc b/src/arch/alpha/stacktrace.cc index e83827630..7c23489a3 100644 --- a/src/arch/alpha/stacktrace.cc +++ b/src/arch/alpha/stacktrace.cc @@ -48,28 +48,28 @@ ProcessInfo::ProcessInfo(ThreadContext *_tc) : tc(_tc) { Addr addr = 0; - FSTranslatingPortProxy* vp = tc->getVirtProxy(); + FSTranslatingPortProxy &vp = tc->getVirtProxy(); SymbolTable *symtab = tc->getSystemPtr()->kernelSymtab; if (!symtab->findAddress("thread_info_size", addr)) panic("thread info not compiled into kernel\n"); - thread_info_size = vp->readGtoH(addr); + thread_info_size = vp.readGtoH(addr); if (!symtab->findAddress("task_struct_size", addr)) panic("thread info not compiled into kernel\n"); - task_struct_size = vp->readGtoH(addr); + task_struct_size = vp.readGtoH(addr); if (!symtab->findAddress("thread_info_task", addr)) panic("thread info not compiled into kernel\n"); - task_off = vp->readGtoH(addr); + task_off = vp.readGtoH(addr); if (!symtab->findAddress("task_struct_pid", addr)) panic("thread info not compiled into kernel\n"); - pid_off = vp->readGtoH(addr); + pid_off = vp.readGtoH(addr); if (!symtab->findAddress("task_struct_comm", addr)) panic("thread info not compiled into kernel\n"); - name_off = vp->readGtoH(addr); + name_off = vp.readGtoH(addr); } Addr @@ -81,10 +81,8 @@ ProcessInfo::task(Addr ksp) const Addr tsk; - FSTranslatingPortProxy* vp; - - vp = tc->getVirtProxy(); - tsk = vp->readGtoH(base + task_off); + FSTranslatingPortProxy &vp = tc->getVirtProxy(); + tsk = vp.readGtoH(base + task_off); return tsk; } @@ -98,10 +96,8 @@ ProcessInfo::pid(Addr ksp) const uint16_t pd; - FSTranslatingPortProxy* vp; - - vp = tc->getVirtProxy(); - pd = vp->readGtoH(task + pid_off); + FSTranslatingPortProxy &vp = tc->getVirtProxy(); + pd = vp.readGtoH(task + pid_off); return pd; } diff --git a/src/arch/alpha/system.cc b/src/arch/alpha/system.cc index 656ab4d6f..8d6629169 100644 --- a/src/arch/alpha/system.cc +++ b/src/arch/alpha/system.cc @@ -119,8 +119,8 @@ AlphaSystem::initState() * others do.) */ if (consoleSymtab->findAddress("env_booted_osflags", addr)) { - virtProxy->writeBlob(addr, (uint8_t*)params()->boot_osflags.c_str(), - strlen(params()->boot_osflags.c_str())); + virtProxy.writeBlob(addr, (uint8_t*)params()->boot_osflags.c_str(), + strlen(params()->boot_osflags.c_str())); } /** @@ -130,9 +130,9 @@ AlphaSystem::initState() if (consoleSymtab->findAddress("m5_rpb", addr)) { uint64_t data; data = htog(params()->system_type); - virtProxy->write(addr+0x50, data); + virtProxy.write(addr+0x50, data); data = htog(params()->system_rev); - virtProxy->write(addr+0x58, data); + virtProxy.write(addr+0x58, data); } else panic("could not find hwrpb\n"); } @@ -178,8 +178,8 @@ AlphaSystem::fixFuncEventAddr(Addr addr) // lda gp,Y(gp): opcode 8, Ra = 29, rb = 29 const uint32_t gp_lda_pattern = (8 << 26) | (29 << 21) | (29 << 16); - uint32_t i1 = virtProxy->read(addr); - uint32_t i2 = virtProxy->read(addr + sizeof(MachInst)); + uint32_t i1 = virtProxy.read(addr); + uint32_t i2 = virtProxy.read(addr + sizeof(MachInst)); if ((i1 & inst_mask) == gp_ldah_pattern && (i2 & inst_mask) == gp_lda_pattern) { @@ -196,7 +196,7 @@ AlphaSystem::setAlphaAccess(Addr access) { Addr addr = 0; if (consoleSymtab->findAddress("m5AlphaAccess", addr)) { - virtProxy->write(addr, htog(Phys2K0Seg(access))); + virtProxy.write(addr, htog(Phys2K0Seg(access))); } else { panic("could not find m5AlphaAccess\n"); } diff --git a/src/arch/alpha/tru64/system.cc b/src/arch/alpha/tru64/system.cc index 13cc93247..cb4b8dd56 100644 --- a/src/arch/alpha/tru64/system.cc +++ b/src/arch/alpha/tru64/system.cc @@ -47,7 +47,7 @@ Tru64AlphaSystem::Tru64AlphaSystem(Tru64AlphaSystem::Params *p) { Addr addr = 0; if (kernelSymtab->findAddress("enable_async_printf", addr)) { - virtProxy->write(addr, (uint32_t)0); + virtProxy.write(addr, (uint32_t)0); } #ifdef DEBUG diff --git a/src/arch/alpha/utility.cc b/src/arch/alpha/utility.cc index 1bac650a0..32fc0b141 100644 --- a/src/arch/alpha/utility.cc +++ b/src/arch/alpha/utility.cc @@ -52,9 +52,10 @@ getArgument(ThreadContext *tc, int &number, uint16_t size, bool fp) return tc->readIntReg(16 + number); } else { Addr sp = tc->readIntReg(StackPointerReg); - FSTranslatingPortProxy* vp = tc->getVirtProxy(); - uint64_t arg = vp->read(sp + - (number-NumArgumentRegs) * sizeof(uint64_t)); + FSTranslatingPortProxy &vp = tc->getVirtProxy(); + uint64_t arg = vp.read(sp + + (number-NumArgumentRegs) * + sizeof(uint64_t)); return arg; } } diff --git a/src/arch/alpha/vtophys.cc b/src/arch/alpha/vtophys.cc index 453c48444..8ca23fce2 100644 --- a/src/arch/alpha/vtophys.cc +++ b/src/arch/alpha/vtophys.cc @@ -45,24 +45,24 @@ using namespace std; namespace AlphaISA { PageTableEntry -kernel_pte_lookup(PortProxy* mem, Addr ptbr, VAddr vaddr) +kernel_pte_lookup(PortProxy &mem, Addr ptbr, VAddr vaddr) { Addr level1_pte = ptbr + vaddr.level1(); - PageTableEntry level1 = mem->read(level1_pte); + PageTableEntry level1 = mem.read(level1_pte); if (!level1.valid()) { DPRINTF(VtoPhys, "level 1 PTE not valid, va = %#\n", vaddr); return 0; } Addr level2_pte = level1.paddr() + vaddr.level2(); - PageTableEntry level2 = mem->read(level2_pte); + PageTableEntry level2 = mem.read(level2_pte); if (!level2.valid()) { DPRINTF(VtoPhys, "level 2 PTE not valid, va = %#x\n", vaddr); return 0; } Addr level3_pte = level2.paddr() + vaddr.level3(); - PageTableEntry level3 = mem->read(level3_pte); + PageTableEntry level3 = mem.read(level3_pte); if (!level3.valid()) { DPRINTF(VtoPhys, "level 3 PTE not valid, va = %#x\n", vaddr); return 0; diff --git a/src/arch/alpha/vtophys.hh b/src/arch/alpha/vtophys.hh index 1695676cb..8613e8e77 100644 --- a/src/arch/alpha/vtophys.hh +++ b/src/arch/alpha/vtophys.hh @@ -41,7 +41,7 @@ class PortProxy; namespace AlphaISA { -PageTableEntry kernel_pte_lookup(PortProxy* mem, Addr ptbr, +PageTableEntry kernel_pte_lookup(PortProxy &mem, Addr ptbr, VAddr vaddr); Addr vtophys(Addr vaddr); -- cgit v1.2.3