From 9305bb6e83d57fde96c78e7b11d50914935f57d5 Mon Sep 17 00:00:00 2001 From: Gabe Black Date: Wed, 24 Apr 2019 20:11:23 -0700 Subject: [PATCH] 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/alpha/process.cc | 35 +++++++-------- src/arch/arm/process.cc | 70 ++++++++++++++--------------- src/arch/mips/process.cc | 45 +++++++++---------- src/arch/power/process.cc | 63 +++++++++++++------------- src/arch/riscv/process.cc | 60 ++++++++++++------------- src/arch/sparc/process.cc | 53 ++++++++++------------ src/arch/x86/process.cc | 78 +++++++++++++++----------------- src/sim/SConscript | 1 - src/sim/aux_vector.cc | 95 --------------------------------------- src/sim/aux_vector.hh | 26 +++++------ 10 files changed, 201 insertions(+), 325 deletions(-) delete mode 100644 src/sim/aux_vector.cc diff --git a/src/arch/alpha/process.cc b/src/arch/alpha/process.cc index 00468bbc3..a7822a367 100644 --- a/src/arch/alpha/process.cc +++ b/src/arch/alpha/process.cc @@ -82,8 +82,7 @@ AlphaProcess::argsInit(int intSize, int pageSize) objFile->loadSections(initVirtMem); - typedef AuxVector auxv_t; - std::vector auxv; + std::vector> auxv; ElfObject * elfObject = dynamic_cast(objFile); if (elfObject) @@ -96,20 +95,21 @@ AlphaProcess::argsInit(int intSize, int pageSize) // seem to be a problem. // check out _dl_aux_init() in glibc/elf/dl-support.c for details // --Lisa - auxv.push_back(auxv_t(M5_AT_PAGESZ, AlphaISA::PageBytes)); - auxv.push_back(auxv_t(M5_AT_CLKTCK, 100)); - auxv.push_back(auxv_t(M5_AT_PHDR, elfObject->programHeaderTable())); - DPRINTF(Loader, "auxv at PHDR %08p\n", elfObject->programHeaderTable()); - auxv.push_back(auxv_t(M5_AT_PHNUM, elfObject->programHeaderCount())); + auxv.emplace_back(M5_AT_PAGESZ, AlphaISA::PageBytes); + auxv.emplace_back(M5_AT_CLKTCK, 100); + auxv.emplace_back(M5_AT_PHDR, elfObject->programHeaderTable()); + DPRINTF(Loader, "auxv at PHDR %08p\n", + elfObject->programHeaderTable()); + auxv.emplace_back(M5_AT_PHNUM, elfObject->programHeaderCount()); // This is the base address of the ELF interpreter; it should be // zero for static executables or contain the base address for // dynamic executables. - auxv.push_back(auxv_t(M5_AT_BASE, getBias())); - auxv.push_back(auxv_t(M5_AT_ENTRY, objFile->entryPoint())); - auxv.push_back(auxv_t(M5_AT_UID, uid())); - auxv.push_back(auxv_t(M5_AT_EUID, euid())); - auxv.push_back(auxv_t(M5_AT_GID, gid())); - auxv.push_back(auxv_t(M5_AT_EGID, egid())); + auxv.emplace_back(M5_AT_BASE, getBias()); + auxv.emplace_back(M5_AT_ENTRY, objFile->entryPoint()); + auxv.emplace_back(M5_AT_UID, uid()); + auxv.emplace_back(M5_AT_EUID, euid()); + auxv.emplace_back(M5_AT_GID, gid()); + auxv.emplace_back(M5_AT_EGID, egid()); } @@ -168,11 +168,10 @@ AlphaProcess::argsInit(int intSize, int pageSize) 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, - (uint8_t*)&(auxv[x].getAuxType()), intSize); - initVirtMem.writeBlob(auxv_array_base + (x * 2 + 1) * intSize, - (uint8_t*)&(auxv[x].getAuxVal()), intSize); + Addr auxv_array_end = auxv_array_base; + for (const auto &aux: auxv) { + initVirtMem.write(auxv_array_end, aux, GuestByteOrder); + auxv_array_end += sizeof(aux); } ThreadContext *tc = system->getThreadContext(contextIds[0]); diff --git a/src/arch/arm/process.cc b/src/arch/arm/process.cc index ba9fbfaa3..baa861fc8 100644 --- a/src/arch/arm/process.cc +++ b/src/arch/arm/process.cc @@ -257,8 +257,7 @@ ArmProcess::argsInit(int pageSize, IntRegIndex spIndex) { int intSize = sizeof(IntType); - typedef AuxVector auxv_t; - std::vector auxv; + std::vector> auxv; string filename; if (argv.size() < 1) @@ -285,41 +284,41 @@ ArmProcess::argsInit(int pageSize, IntRegIndex spIndex) //Bits which describe the system hardware capabilities //XXX Figure out what these should be - auxv.push_back(auxv_t(M5_AT_HWCAP, features)); + auxv.emplace_back(M5_AT_HWCAP, features); //Frequency at which times() increments - auxv.push_back(auxv_t(M5_AT_CLKTCK, 0x64)); + auxv.emplace_back(M5_AT_CLKTCK, 0x64); //Whether to enable "secure mode" in the executable - auxv.push_back(auxv_t(M5_AT_SECURE, 0)); + auxv.emplace_back(M5_AT_SECURE, 0); // Pointer to 16 bytes of random data - auxv.push_back(auxv_t(M5_AT_RANDOM, 0)); + auxv.emplace_back(M5_AT_RANDOM, 0); //The filename of the program - auxv.push_back(auxv_t(M5_AT_EXECFN, 0)); + auxv.emplace_back(M5_AT_EXECFN, 0); //The string "v71" -- ARM v7 architecture - auxv.push_back(auxv_t(M5_AT_PLATFORM, 0)); + auxv.emplace_back(M5_AT_PLATFORM, 0); } //The system page size - auxv.push_back(auxv_t(M5_AT_PAGESZ, ArmISA::PageBytes)); - // For statically linked executables, this is the virtual address of the - // program header tables if they appear in the executable image - auxv.push_back(auxv_t(M5_AT_PHDR, elfObject->programHeaderTable())); + auxv.emplace_back(M5_AT_PAGESZ, ArmISA::PageBytes); + // For statically linked executables, this is the virtual address of + // the program header tables if they appear in the executable image + auxv.emplace_back(M5_AT_PHDR, elfObject->programHeaderTable()); // This is the size of a program header entry from the elf file. - auxv.push_back(auxv_t(M5_AT_PHENT, elfObject->programHeaderSize())); + auxv.emplace_back(M5_AT_PHENT, elfObject->programHeaderSize()); // This is the number of program headers from the original elf file. - auxv.push_back(auxv_t(M5_AT_PHNUM, elfObject->programHeaderCount())); + auxv.emplace_back(M5_AT_PHNUM, elfObject->programHeaderCount()); // This is the base address of the ELF interpreter; it should be // zero for static executables or contain the base address for // dynamic executables. - auxv.push_back(auxv_t(M5_AT_BASE, getBias())); + auxv.emplace_back(M5_AT_BASE, getBias()); //XXX Figure out what this should be. - auxv.push_back(auxv_t(M5_AT_FLAGS, 0)); + auxv.emplace_back(M5_AT_FLAGS, 0); //The entry point to the program - auxv.push_back(auxv_t(M5_AT_ENTRY, objFile->entryPoint())); + auxv.emplace_back(M5_AT_ENTRY, objFile->entryPoint()); //Different user and group IDs - auxv.push_back(auxv_t(M5_AT_UID, uid())); - auxv.push_back(auxv_t(M5_AT_EUID, euid())); - auxv.push_back(auxv_t(M5_AT_GID, gid())); - auxv.push_back(auxv_t(M5_AT_EGID, egid())); + auxv.emplace_back(M5_AT_UID, uid()); + auxv.emplace_back(M5_AT_EUID, euid()); + auxv.emplace_back(M5_AT_GID, gid()); + auxv.emplace_back(M5_AT_EGID, egid()); } //Figure out how big the initial stack nedes to be @@ -421,31 +420,28 @@ ArmProcess::argsInit(int pageSize, IntRegIndex spIndex) //Fix up the aux vectors which point to other data for (int i = auxv.size() - 1; i >= 0; i--) { - if (auxv[i].getHostAuxType() == M5_AT_PLATFORM) { - auxv[i].setAuxVal(platform_base); + if (auxv[i].type == M5_AT_PLATFORM) { + auxv[i].val = platform_base; initVirtMem.writeString(platform_base, platform.c_str()); - } else if (auxv[i].getHostAuxType() == M5_AT_EXECFN) { - auxv[i].setAuxVal(aux_data_base); + } else if (auxv[i].type == M5_AT_EXECFN) { + auxv[i].val = aux_data_base; initVirtMem.writeString(aux_data_base, filename.c_str()); - } else if (auxv[i].getHostAuxType() == M5_AT_RANDOM) { - auxv[i].setAuxVal(aux_random_base); + } else if (auxv[i].type == M5_AT_RANDOM) { + auxv[i].val = aux_random_base; // Just leave the value 0, we don't want randomness } } //Copy the aux stuff - for (int x = 0; x < auxv.size(); x++) { - initVirtMem.writeBlob(auxv_array_base + x * 2 * intSize, - (uint8_t*)&(auxv[x].getAuxType()), - intSize); - initVirtMem.writeBlob(auxv_array_base + (x * 2 + 1) * intSize, - (uint8_t*)&(auxv[x].getAuxVal()), - intSize); + Addr auxv_array_end = auxv_array_base; + for (const auto &aux: auxv) { + initVirtMem.write(auxv_array_end, aux, GuestByteOrder); + auxv_array_end += sizeof(aux); } //Write out the terminating zeroed auxillary vector - const IntType zero[2] = {0, 0}; - initVirtMem.writeBlob(auxv_array_base + 2 * intSize * auxv.size(), - (uint8_t*)zero, 2 * intSize); + const AuxVector zero(0, 0); + initVirtMem.write(auxv_array_end, zero); + auxv_array_end += sizeof(zero); copyStringArray(envp, envp_array_base, env_data_base, initVirtMem); copyStringArray(argv, argv_array_base, arg_data_base, initVirtMem); diff --git a/src/arch/mips/process.cc b/src/arch/mips/process.cc index 9b4b5bb3c..d8378725c 100644 --- a/src/arch/mips/process.cc +++ b/src/arch/mips/process.cc @@ -96,36 +96,36 @@ MipsProcess::argsInit(int pageSize) // load object file into target memory objFile->loadSections(initVirtMem); - typedef AuxVector auxv_t; - std::vector auxv; + std::vector> auxv; ElfObject * elfObject = dynamic_cast(objFile); if (elfObject) { // Set the system page size - auxv.push_back(auxv_t(M5_AT_PAGESZ, MipsISA::PageBytes)); + auxv.emplace_back(M5_AT_PAGESZ, MipsISA::PageBytes); // Set the frequency at which time() increments - auxv.push_back(auxv_t(M5_AT_CLKTCK, 100)); + auxv.emplace_back(M5_AT_CLKTCK, 100); // For statically linked executables, this is the virtual // address of the program header tables if they appear in the // executable image. - auxv.push_back(auxv_t(M5_AT_PHDR, elfObject->programHeaderTable())); - DPRINTF(Loader, "auxv at PHDR %08p\n", elfObject->programHeaderTable()); + auxv.emplace_back(M5_AT_PHDR, elfObject->programHeaderTable()); + DPRINTF(Loader, "auxv at PHDR %08p\n", + elfObject->programHeaderTable()); // This is the size of a program header entry from the elf file. - auxv.push_back(auxv_t(M5_AT_PHENT, elfObject->programHeaderSize())); + auxv.emplace_back(M5_AT_PHENT, elfObject->programHeaderSize()); // This is the number of program headers from the original elf file. - auxv.push_back(auxv_t(M5_AT_PHNUM, elfObject->programHeaderCount())); + auxv.emplace_back(M5_AT_PHNUM, elfObject->programHeaderCount()); // This is the base address of the ELF interpreter; it should be // zero for static executables or contain the base address for // dynamic executables. - auxv.push_back(auxv_t(M5_AT_BASE, getBias())); + auxv.emplace_back(M5_AT_BASE, getBias()); //The entry point to the program - auxv.push_back(auxv_t(M5_AT_ENTRY, objFile->entryPoint())); + auxv.emplace_back(M5_AT_ENTRY, objFile->entryPoint()); //Different user and group IDs - auxv.push_back(auxv_t(M5_AT_UID, uid())); - auxv.push_back(auxv_t(M5_AT_EUID, euid())); - auxv.push_back(auxv_t(M5_AT_GID, gid())); - auxv.push_back(auxv_t(M5_AT_EGID, egid())); + auxv.emplace_back(M5_AT_UID, uid()); + auxv.emplace_back(M5_AT_EUID, euid()); + auxv.emplace_back(M5_AT_GID, gid()); + auxv.emplace_back(M5_AT_EGID, egid()); } // Calculate how much space we need for arg & env & auxv arrays. @@ -177,19 +177,16 @@ MipsProcess::argsInit(int pageSize) copyStringArray(envp, envp_array_base, env_data_base, initVirtMem); // Copy the aux vector - for (typename vector::size_type x = 0; x < auxv.size(); x++) { - initVirtMem.writeBlob(auxv_array_base + x * 2 * intSize, - (uint8_t*)&(auxv[x].getAuxType()), intSize); - initVirtMem.writeBlob(auxv_array_base + (x * 2 + 1) * intSize, - (uint8_t*)&(auxv[x].getAuxVal()), intSize); + Addr auxv_array_end = auxv_array_base; + for (const auto &aux: auxv) { + initVirtMem.write(auxv_array_end, aux, GuestByteOrder); + auxv_array_end += sizeof(aux); } // Write out the terminating zeroed auxilliary vector - for (unsigned i = 0; i < 2; i++) { - const IntType zero = 0; - const Addr addr = auxv_array_base + 2 * intSize * (auxv.size() + i); - initVirtMem.writeBlob(addr, (uint8_t*)&zero, intSize); - } + const AuxVector zero(0, 0); + initVirtMem.write(auxv_array_end, zero); + auxv_array_end += sizeof(zero); ThreadContext *tc = system->getThreadContext(contextIds[0]); diff --git a/src/arch/power/process.cc b/src/arch/power/process.cc index ee72ba71a..1d082c77e 100644 --- a/src/arch/power/process.cc +++ b/src/arch/power/process.cc @@ -85,8 +85,7 @@ PowerProcess::initState() void PowerProcess::argsInit(int intSize, int pageSize) { - typedef AuxVector auxv_t; - std::vector auxv; + std::vector> auxv; string filename; if (argv.size() < 1) @@ -111,37 +110,37 @@ PowerProcess::argsInit(int intSize, int pageSize) //Bits which describe the system hardware capabilities //XXX Figure out what these should be - auxv.push_back(auxv_t(M5_AT_HWCAP, features)); + auxv.emplace_back(M5_AT_HWCAP, features); //The system page size - auxv.push_back(auxv_t(M5_AT_PAGESZ, PowerISA::PageBytes)); + auxv.emplace_back(M5_AT_PAGESZ, PowerISA::PageBytes); //Frequency at which times() increments - auxv.push_back(auxv_t(M5_AT_CLKTCK, 0x64)); - // For statically linked executables, this is the virtual address of the - // program header tables if they appear in the executable image - auxv.push_back(auxv_t(M5_AT_PHDR, elfObject->programHeaderTable())); + auxv.emplace_back(M5_AT_CLKTCK, 0x64); + // For statically linked executables, this is the virtual address of + // the program header tables if they appear in the executable image + auxv.emplace_back(M5_AT_PHDR, elfObject->programHeaderTable()); // This is the size of a program header entry from the elf file. - auxv.push_back(auxv_t(M5_AT_PHENT, elfObject->programHeaderSize())); + auxv.emplace_back(M5_AT_PHENT, elfObject->programHeaderSize()); // This is the number of program headers from the original elf file. - auxv.push_back(auxv_t(M5_AT_PHNUM, elfObject->programHeaderCount())); + auxv.emplace_back(M5_AT_PHNUM, elfObject->programHeaderCount()); // This is the base address of the ELF interpreter; it should be // zero for static executables or contain the base address for // dynamic executables. - auxv.push_back(auxv_t(M5_AT_BASE, getBias())); + auxv.emplace_back(M5_AT_BASE, getBias()); //XXX Figure out what this should be. - auxv.push_back(auxv_t(M5_AT_FLAGS, 0)); + auxv.emplace_back(M5_AT_FLAGS, 0); //The entry point to the program - auxv.push_back(auxv_t(M5_AT_ENTRY, objFile->entryPoint())); + auxv.emplace_back(M5_AT_ENTRY, objFile->entryPoint()); //Different user and group IDs - auxv.push_back(auxv_t(M5_AT_UID, uid())); - auxv.push_back(auxv_t(M5_AT_EUID, euid())); - auxv.push_back(auxv_t(M5_AT_GID, gid())); - auxv.push_back(auxv_t(M5_AT_EGID, egid())); + auxv.emplace_back(M5_AT_UID, uid()); + auxv.emplace_back(M5_AT_EUID, euid()); + auxv.emplace_back(M5_AT_GID, gid()); + auxv.emplace_back(M5_AT_EGID, egid()); //Whether to enable "secure mode" in the executable - auxv.push_back(auxv_t(M5_AT_SECURE, 0)); + auxv.emplace_back(M5_AT_SECURE, 0); //The filename of the program - auxv.push_back(auxv_t(M5_AT_EXECFN, 0)); + auxv.emplace_back(M5_AT_EXECFN, 0); //The string "v51" with unknown meaning - auxv.push_back(auxv_t(M5_AT_PLATFORM, 0)); + auxv.emplace_back(M5_AT_PLATFORM, 0); } //Figure out how big the initial stack nedes to be @@ -239,27 +238,25 @@ PowerProcess::argsInit(int intSize, int pageSize) //Fix up the aux vectors which point to other data for (int i = auxv.size() - 1; i >= 0; i--) { - if (auxv[i].getHostAuxType() == M5_AT_PLATFORM) { - auxv[i].setAuxVal(platform_base); + if (auxv[i].type == M5_AT_PLATFORM) { + auxv[i].val = platform_base; initVirtMem.writeString(platform_base, platform.c_str()); - } else if (auxv[i].getHostAuxType() == M5_AT_EXECFN) { - auxv[i].setAuxVal(aux_data_base); + } else if (auxv[i].type == M5_AT_EXECFN) { + auxv[i].val = aux_data_base; initVirtMem.writeString(aux_data_base, filename.c_str()); } } //Copy the aux stuff - for (int x = 0; x < auxv.size(); x++) - { - initVirtMem.writeBlob(auxv_array_base + x * 2 * intSize, - (uint8_t*)&(auxv[x].getAuxType()), intSize); - initVirtMem.writeBlob(auxv_array_base + (x * 2 + 1) * intSize, - (uint8_t*)&(auxv[x].getAuxVal()), intSize); + Addr auxv_array_end = auxv_array_base; + for (const auto &aux: auxv) { + initVirtMem.write(auxv_array_end, aux, GuestByteOrder); + auxv_array_end += sizeof(aux); } //Write out the terminating zeroed auxilliary vector - const uint64_t zero = 0; - initVirtMem.writeBlob(auxv_array_base + 2 * intSize * auxv.size(), - (uint8_t*)&zero, 2 * intSize); + const AuxVector zero(0, 0); + initVirtMem.write(auxv_array_end, zero); + auxv_array_end += sizeof(zero); copyStringArray(envp, envp_array_base, env_data_base, initVirtMem); copyStringArray(argv, argv_array_base, arg_data_base, initVirtMem); 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]); diff --git a/src/arch/sparc/process.cc b/src/arch/sparc/process.cc index 6659a04fa..3419e0970 100644 --- a/src/arch/sparc/process.cc +++ b/src/arch/sparc/process.cc @@ -192,9 +192,7 @@ SparcProcess::argsInit(int pageSize) { int intSize = sizeof(IntType); - typedef AuxVector auxv_t; - - std::vector auxv; + std::vector> auxv; string filename; if (argv.size() < 1) @@ -238,34 +236,34 @@ SparcProcess::argsInit(int pageSize) ElfObject * elfObject = dynamic_cast(objFile); if (elfObject) { // Bits which describe the system hardware capabilities - auxv.push_back(auxv_t(M5_AT_HWCAP, hwcap)); + auxv.emplace_back(M5_AT_HWCAP, hwcap); // The system page size - auxv.push_back(auxv_t(M5_AT_PAGESZ, SparcISA::PageBytes)); + auxv.emplace_back(M5_AT_PAGESZ, SparcISA::PageBytes); // Defined to be 100 in the kernel source. // Frequency at which times() increments - auxv.push_back(auxv_t(M5_AT_CLKTCK, 100)); - // For statically linked executables, this is the virtual address of the - // program header tables if they appear in the executable image - auxv.push_back(auxv_t(M5_AT_PHDR, elfObject->programHeaderTable())); + auxv.emplace_back(M5_AT_CLKTCK, 100); + // For statically linked executables, this is the virtual address of + // the program header tables if they appear in the executable image + auxv.emplace_back(M5_AT_PHDR, elfObject->programHeaderTable()); // This is the size of a program header entry from the elf file. - auxv.push_back(auxv_t(M5_AT_PHENT, elfObject->programHeaderSize())); + auxv.emplace_back(M5_AT_PHENT, elfObject->programHeaderSize()); // This is the number of program headers from the original elf file. - auxv.push_back(auxv_t(M5_AT_PHNUM, elfObject->programHeaderCount())); + auxv.emplace_back(M5_AT_PHNUM, elfObject->programHeaderCount()); // This is the base address of the ELF interpreter; it should be // zero for static executables or contain the base address for // dynamic executables. - auxv.push_back(auxv_t(M5_AT_BASE, getBias())); + auxv.emplace_back(M5_AT_BASE, getBias()); // This is hardwired to 0 in the elf loading code in the kernel - auxv.push_back(auxv_t(M5_AT_FLAGS, 0)); + auxv.emplace_back(M5_AT_FLAGS, 0); // The entry point to the program - auxv.push_back(auxv_t(M5_AT_ENTRY, objFile->entryPoint())); + auxv.emplace_back(M5_AT_ENTRY, objFile->entryPoint()); // Different user and group IDs - auxv.push_back(auxv_t(M5_AT_UID, uid())); - auxv.push_back(auxv_t(M5_AT_EUID, euid())); - auxv.push_back(auxv_t(M5_AT_GID, gid())); - auxv.push_back(auxv_t(M5_AT_EGID, egid())); + auxv.emplace_back(M5_AT_UID, uid()); + auxv.emplace_back(M5_AT_EUID, euid()); + auxv.emplace_back(M5_AT_GID, gid()); + auxv.emplace_back(M5_AT_EGID, egid()); // Whether to enable "secure mode" in the executable - auxv.push_back(auxv_t(M5_AT_SECURE, 0)); + auxv.emplace_back(M5_AT_SECURE, 0); } // Figure out how big the initial stack needs to be @@ -373,19 +371,16 @@ SparcProcess::argsInit(int pageSize) initVirtMem.writeString(file_name_base, filename.c_str()); // Copy the aux stuff - for (int x = 0; x < auxv.size(); x++) { - initVirtMem.writeBlob(auxv_array_base + x * 2 * intSize, - (uint8_t*)&(auxv[x].getAuxType()), intSize); - initVirtMem.writeBlob(auxv_array_base + (x * 2 + 1) * intSize, - (uint8_t*)&(auxv[x].getAuxVal()), intSize); + Addr auxv_array_end = auxv_array_base; + for (const auto &aux: auxv) { + initVirtMem.write(auxv_array_end, aux, GuestByteOrder); + auxv_array_end += sizeof(aux); } // Write out the terminating zeroed auxilliary vector - const IntType zero = 0; - initVirtMem.writeBlob(auxv_array_base + intSize * 2 * auxv.size(), - (uint8_t*)&zero, intSize); - initVirtMem.writeBlob(auxv_array_base + intSize * (2 * auxv.size() + 1), - (uint8_t*)&zero, intSize); + const AuxVector zero(0, 0); + initVirtMem.write(auxv_array_end, zero); + auxv_array_end += sizeof(zero); copyStringArray(envp, envp_array_base, env_data_base, initVirtMem); copyStringArray(argv, argv_array_base, arg_data_base, initVirtMem); diff --git a/src/arch/x86/process.cc b/src/arch/x86/process.cc index 9e34a7b5d..d01afbc25 100644 --- a/src/arch/x86/process.cc +++ b/src/arch/x86/process.cc @@ -762,8 +762,7 @@ X86Process::argsInit(int pageSize, { int intSize = sizeof(IntType); - typedef AuxVector auxv_t; - std::vector auxv = extraAuxvs; + std::vector> auxv = extraAuxvs; string filename; if (argv.size() < 1) @@ -859,40 +858,40 @@ X86Process::argsInit(int pageSize, // Bits which describe the system hardware capabilities // XXX Figure out what these should be - auxv.push_back(auxv_t(M5_AT_HWCAP, features)); + auxv.emplace_back(M5_AT_HWCAP, features); // The system page size - auxv.push_back(auxv_t(M5_AT_PAGESZ, X86ISA::PageBytes)); + auxv.emplace_back(M5_AT_PAGESZ, X86ISA::PageBytes); // Frequency at which times() increments // Defined to be 100 in the kernel source. - auxv.push_back(auxv_t(M5_AT_CLKTCK, 100)); + auxv.emplace_back(M5_AT_CLKTCK, 100); // This is the virtual address of the program header tables if they // appear in the executable image. - auxv.push_back(auxv_t(M5_AT_PHDR, elfObject->programHeaderTable())); + auxv.emplace_back(M5_AT_PHDR, elfObject->programHeaderTable()); // This is the size of a program header entry from the elf file. - auxv.push_back(auxv_t(M5_AT_PHENT, elfObject->programHeaderSize())); + auxv.emplace_back(M5_AT_PHENT, elfObject->programHeaderSize()); // This is the number of program headers from the original elf file. - auxv.push_back(auxv_t(M5_AT_PHNUM, elfObject->programHeaderCount())); + auxv.emplace_back(M5_AT_PHNUM, elfObject->programHeaderCount()); // This is the base address of the ELF interpreter; it should be // zero for static executables or contain the base address for // dynamic executables. - auxv.push_back(auxv_t(M5_AT_BASE, getBias())); + auxv.emplace_back(M5_AT_BASE, getBias()); // XXX Figure out what this should be. - auxv.push_back(auxv_t(M5_AT_FLAGS, 0)); + auxv.emplace_back(M5_AT_FLAGS, 0); // The entry point to the program - auxv.push_back(auxv_t(M5_AT_ENTRY, objFile->entryPoint())); + auxv.emplace_back(M5_AT_ENTRY, objFile->entryPoint()); // Different user and group IDs - auxv.push_back(auxv_t(M5_AT_UID, uid())); - auxv.push_back(auxv_t(M5_AT_EUID, euid())); - auxv.push_back(auxv_t(M5_AT_GID, gid())); - auxv.push_back(auxv_t(M5_AT_EGID, egid())); + auxv.emplace_back(M5_AT_UID, uid()); + auxv.emplace_back(M5_AT_EUID, euid()); + auxv.emplace_back(M5_AT_GID, gid()); + auxv.emplace_back(M5_AT_EGID, egid()); // Whether to enable "secure mode" in the executable - auxv.push_back(auxv_t(M5_AT_SECURE, 0)); + auxv.emplace_back(M5_AT_SECURE, 0); // The address of 16 "random" bytes. - auxv.push_back(auxv_t(M5_AT_RANDOM, 0)); + auxv.emplace_back(M5_AT_RANDOM, 0); // The name of the program - auxv.push_back(auxv_t(M5_AT_EXECFN, 0)); + auxv.emplace_back(M5_AT_EXECFN, 0); // The platform string - auxv.push_back(auxv_t(M5_AT_PLATFORM, 0)); + auxv.emplace_back(M5_AT_PLATFORM, 0); } // Figure out how big the initial stack needs to be @@ -1006,29 +1005,24 @@ X86Process::argsInit(int pageSize, initVirtMem.writeString(file_name_base, filename.c_str()); // Fix up the aux vectors which point to data - assert(auxv[auxv.size() - 3].getHostAuxType() == M5_AT_RANDOM); - auxv[auxv.size() - 3].setAuxVal(aux_data_base); - assert(auxv[auxv.size() - 2].getHostAuxType() == M5_AT_EXECFN); - auxv[auxv.size() - 2].setAuxVal(argv_array_base); - assert(auxv[auxv.size() - 1].getHostAuxType() == M5_AT_PLATFORM); - auxv[auxv.size() - 1].setAuxVal(aux_data_base + numRandomBytes); + assert(auxv[auxv.size() - 3].type == M5_AT_RANDOM); + auxv[auxv.size() - 3].val = aux_data_base; + assert(auxv[auxv.size() - 2].type == M5_AT_EXECFN); + auxv[auxv.size() - 2].val = argv_array_base; + assert(auxv[auxv.size() - 1].type == M5_AT_PLATFORM); + auxv[auxv.size() - 1].val = aux_data_base + numRandomBytes; // Copy the aux stuff - for (int x = 0; x < auxv.size(); x++) { - initVirtMem.writeBlob(auxv_array_base + x * 2 * intSize, - (uint8_t*)&(auxv[x].getAuxType()), - intSize); - initVirtMem.writeBlob(auxv_array_base + (x * 2 + 1) * intSize, - (uint8_t*)&(auxv[x].getAuxVal()), - intSize); + Addr auxv_array_end = auxv_array_base; + for (const auto &aux: auxv) { + initVirtMem.write(auxv_array_end, aux, GuestByteOrder); + auxv_array_end += sizeof(aux); } // Write out the terminating zeroed auxiliary vector - const uint64_t zero = 0; - initVirtMem.writeBlob(auxv_array_base + auxv.size() * 2 * intSize, - (uint8_t*)&zero, intSize); - initVirtMem.writeBlob(auxv_array_base + (auxv.size() * 2 + 1) * intSize, - (uint8_t*)&zero, intSize); + const AuxVector zero(0, 0); + initVirtMem.write(auxv_array_end, zero); + auxv_array_end += sizeof(zero); initVirtMem.writeString(aux_data_base, platform.c_str()); @@ -1053,8 +1047,7 @@ void X86_64Process::argsInit(int pageSize) { std::vector > extraAuxvs; - extraAuxvs.push_back(AuxVector(M5_AT_SYSINFO_EHDR, - vsyscallPage.base)); + extraAuxvs.emplace_back(M5_AT_SYSINFO_EHDR, vsyscallPage.base); X86Process::argsInit(pageSize, extraAuxvs); } @@ -1063,10 +1056,9 @@ I386Process::argsInit(int pageSize) { std::vector > extraAuxvs; //Tell the binary where the vsyscall part of the vsyscall page is. - extraAuxvs.push_back(AuxVector(M5_AT_SYSINFO, - vsyscallPage.base + vsyscallPage.vsyscallOffset)); - extraAuxvs.push_back(AuxVector(M5_AT_SYSINFO_EHDR, - vsyscallPage.base)); + extraAuxvs.emplace_back(M5_AT_SYSINFO, + vsyscallPage.base + vsyscallPage.vsyscallOffset); + extraAuxvs.emplace_back(M5_AT_SYSINFO_EHDR, vsyscallPage.base); X86Process::argsInit(pageSize, extraAuxvs); } diff --git a/src/sim/SConscript b/src/sim/SConscript index 8ab2c72f9..72b0f3df9 100644 --- a/src/sim/SConscript +++ b/src/sim/SConscript @@ -80,7 +80,6 @@ Source('mathexpr.cc') if env['TARGET_ISA'] != 'null': SimObject('InstTracer.py') SimObject('Process.py') - Source('aux_vector.cc') Source('faults.cc') Source('process.cc') Source('fd_array.cc') diff --git a/src/sim/aux_vector.cc b/src/sim/aux_vector.cc deleted file mode 100644 index 18834ac9b..000000000 --- a/src/sim/aux_vector.cc +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright (c) 2016 Advanced Micro Devices, Inc. - * All rights reserved. - * - * For use for simulation and test purposes only - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * Authors: Brandon Potter - */ - -#include "sim/aux_vector.hh" - -#include - -#include "config/the_isa.hh" - -#if THE_ISA == ALPHA_ISA -#include "arch/alpha/linux/process.hh" - -#elif THE_ISA == SPARC_ISA -#include "arch/sparc/linux/process.hh" -#include "arch/sparc/solaris/process.hh" - -#elif THE_ISA == MIPS_ISA -#include "arch/mips/linux/process.hh" - -#elif THE_ISA == ARM_ISA -#include "arch/arm/freebsd/process.hh" -#include "arch/arm/linux/process.hh" - -#elif THE_ISA == X86_ISA -#include "arch/x86/linux/process.hh" - -#elif THE_ISA == RISCV_ISA -#include "arch/riscv/linux/process.hh" - -#elif THE_ISA == POWER_ISA -#include "arch/power/linux/process.hh" - -#else -#error "THE_ISA not set" -#endif - -#include "arch/isa_traits.hh" -#include "sim/byteswap.hh" - -template -AuxVector::AuxVector(IntType type, IntType val) - : _auxType(TheISA::htog(type)), _auxVal(TheISA::htog(val)), - _auxHostType(type), _auxHostVal(val) -{ } - -template -inline void -AuxVector::setAuxType(IntType type) -{ - _auxType = TheISA::htog(type); - _auxHostType = type; -} - -template -inline void -AuxVector::setAuxVal(IntType val) -{ - _auxVal = TheISA::htog(val); - _auxHostVal = val; -} - -template class AuxVector; -template class AuxVector; diff --git a/src/sim/aux_vector.hh b/src/sim/aux_vector.hh index 1ca2d7862..00412fd82 100644 --- a/src/sim/aux_vector.hh +++ b/src/sim/aux_vector.hh @@ -41,23 +41,21 @@ class AuxVector { public: AuxVector() = default; - AuxVector(IntType type, IntType val); + AuxVector(IntType _type, IntType _val) : type(_type), val(_val) {} - IntType const& getAuxType() const { return _auxType; } - IntType const& getAuxVal() const { return _auxVal; } - IntType const& getHostAuxType() const { return _auxHostType; } - IntType const& getHostAuxVal() const { return _auxHostVal; } - - void setAuxType(IntType type); - void setAuxVal(IntType val); - - private: - IntType _auxType = 0; - IntType _auxVal = 0; - IntType _auxHostType = 0; - IntType _auxHostVal = 0; + IntType type = 0; + IntType val = 0; }; +template +inline AuxVector +swap_byte(AuxVector av) +{ + av.type = swap_byte(av.type); + av.val = swap_byte(av.val); + return av; +} + enum AuxiliaryVectorType { M5_AT_NULL = 0, // End of vector. M5_AT_IGNORE = 1, // Ignored. -- 2.30.2