From 9305bb6e83d57fde96c78e7b11d50914935f57d5 Mon Sep 17 00:00:00 2001 From: Gabe Black Date: Wed, 24 Apr 2019 20:11:23 -0700 Subject: arch, sim: Simplify the AuxVector type. The AuxVector type has a bunch of accessors which just give access to the underlying variables through references. We might as well just make those members accessible directly. Also, the AuxVector doesn't need to handle endianness flips itself. We can tell the byteswap mechanism how to flip an AuxVector, and let it handle that for us. This gets rid of the entire .cc file which was complicated by trying to both hide the ISA specific endianness translations, and instantiate templated functions in a .cc. Change-Id: I433cd61e73e0b067b6d628fba31be4a4ec1c4cf0 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/18373 Maintainer: Gabe Black Tested-by: kokoro Reviewed-by: Jason Lowe-Power Reviewed-by: Andreas Sandberg --- src/arch/riscv/process.cc | 60 +++++++++++++++++++++++------------------------ 1 file changed, 29 insertions(+), 31 deletions(-) (limited to 'src/arch/riscv') diff --git a/src/arch/riscv/process.cc b/src/arch/riscv/process.cc index 16d0dc7ff..ab8305257 100644 --- a/src/arch/riscv/process.cc +++ b/src/arch/riscv/process.cc @@ -139,17 +139,16 @@ RiscvProcess::argsInit(int pageSize) stack_top -= env.size() + 1; stack_top &= -addrSize; - typedef AuxVector auxv_t; - vector auxv; + vector> auxv; if (elfObject != nullptr) { - auxv.push_back(auxv_t(M5_AT_ENTRY, objFile->entryPoint())); - auxv.push_back(auxv_t(M5_AT_PHNUM, elfObject->programHeaderCount())); - auxv.push_back(auxv_t(M5_AT_PHENT, elfObject->programHeaderSize())); - auxv.push_back(auxv_t(M5_AT_PHDR, elfObject->programHeaderTable())); - auxv.push_back(auxv_t(M5_AT_PAGESZ, PageBytes)); - auxv.push_back(auxv_t(M5_AT_SECURE, 0)); - auxv.push_back(auxv_t(M5_AT_RANDOM, stack_top)); - auxv.push_back(auxv_t(M5_AT_NULL, 0)); + auxv.emplace_back(M5_AT_ENTRY, objFile->entryPoint()); + auxv.emplace_back(M5_AT_PHNUM, elfObject->programHeaderCount()); + auxv.emplace_back(M5_AT_PHENT, elfObject->programHeaderSize()); + auxv.emplace_back(M5_AT_PHDR, elfObject->programHeaderTable()); + auxv.emplace_back(M5_AT_PAGESZ, PageBytes); + auxv.emplace_back(M5_AT_SECURE, 0); + auxv.emplace_back(M5_AT_RANDOM, stack_top); + auxv.emplace_back(M5_AT_NULL, 0); } stack_top -= (1 + argv.size()) * addrSize + (1 + envp.size()) * addrSize + @@ -200,30 +199,30 @@ RiscvProcess::argsInit(int pageSize) ((1 + argv.size()) * addrSize + (1 + envp.size()) * addrSize + addrSize + 2 * sizeof(IntType) * auxv.size())); - memState->setStackMin(memState->getStackMin() & -2*addrSize); + memState->setStackMin(memState->getStackMin() & (-2 * addrSize)); Addr sp = memState->getStackMin(); const auto pushOntoStack = - [this, &sp](const uint8_t* data, const size_t size) { - initVirtMem.writeBlob(sp, data, size); - sp += size; + [this, &sp](IntType data) { + initVirtMem.write(sp, data, GuestByteOrder); + sp += sizeof(data); }; // Push argc and argv pointers onto stack - IntType argc = htog((IntType)argv.size()); - DPRINTF(Stack, "Wrote argc %d to address %p\n", - argv.size(), (void*)sp); - pushOntoStack((uint8_t*)&argc, sizeof(IntType)); + IntType argc = argv.size(); + DPRINTF(Stack, "Wrote argc %d to address %#x\n", argc, sp); + pushOntoStack(argc); + for (const Addr& argPointer: argPointers) { - DPRINTF(Stack, "Wrote argv pointer %p to address %p\n", - (void*)argPointer, (void*)sp); - pushOntoStack((uint8_t*)&argPointer, addrSize); + DPRINTF(Stack, "Wrote argv pointer %#x to address %#x\n", + argPointer, sp); + pushOntoStack(argPointer); } // Push env pointers onto stack for (const Addr& envPointer: envPointers) { - DPRINTF(Stack, "Wrote envp pointer %p to address %p\n", - (void*)envPointer, (void*)sp); - pushOntoStack((uint8_t*)&envPointer, addrSize); + DPRINTF(Stack, "Wrote envp pointer %#x to address %#x\n", + envPointer, sp); + pushOntoStack(envPointer); } // Push aux vector onto stack @@ -237,13 +236,12 @@ RiscvProcess::argsInit(int pageSize) {M5_AT_RANDOM, "M5_AT_RANDOM"}, {M5_AT_NULL, "M5_AT_NULL"} }; - for (const AuxVector& aux: auxv) { - DPRINTF(Stack, "Wrote aux key %s to address %p\n", - aux_keys[aux.getAuxType()], (void*)sp); - pushOntoStack((uint8_t*)&aux.getAuxType(), sizeof(IntType)); - DPRINTF(Stack, "Wrote aux value %x to address %p\n", - aux.getAuxVal(), (void*)sp); - pushOntoStack((uint8_t*)&aux.getAuxVal(), sizeof(IntType)); + for (const auto &aux: auxv) { + DPRINTF(Stack, "Wrote aux key %s to address %#x\n", + aux_keys[aux.type], sp); + pushOntoStack(aux.type); + DPRINTF(Stack, "Wrote aux value %x to address %#x\n", aux.val, sp); + pushOntoStack(aux.val); } ThreadContext *tc = system->getThreadContext(contextIds[0]); -- cgit v1.2.3