diff --git a/src/arch/riscvcapstone/o3/dyn_inst.cc b/src/arch/riscvcapstone/o3/dyn_inst.cc index c4ad70826c..e0e23711b2 100644 --- a/src/arch/riscvcapstone/o3/dyn_inst.cc +++ b/src/arch/riscvcapstone/o3/dyn_inst.cc @@ -73,7 +73,7 @@ DynInst::DynInst(const Arrays &arrays, const StaticInstPtr &static_inst, #ifndef NDEBUG ++cpu->instcount; - if (cpu->instcount > 1500) { + if (0 && cpu->instcount > 1500) { #ifdef DEBUG cpu->dumpInsts(); dumpSNList(); diff --git a/src/arch/riscvcapstone/process.cc b/src/arch/riscvcapstone/process.cc index 9ef584007c..7dc118afdc 100644 --- a/src/arch/riscvcapstone/process.cc +++ b/src/arch/riscvcapstone/process.cc @@ -84,6 +84,16 @@ RiscvProcess64::RiscvProcess64(const ProcessParams ¶ms, const Addr mmap_end = 0x400000000ULL; memState = std::make_shared(this, brk_point, stack_base, max_stack_size, next_thread_stack_base, mmap_end); + + // objFile->printSections(); + + std::pair cap_relocs, cap_table; + cap_relocs = objFile->getSec("__cap_relocs"); + cap_table = objFile->getSec(".captable"); + + cap_relocs_base = cap_relocs.first; + cap_relocs_count = cap_relocs.second / 40; //sizeof(cap_reloc_struct) + cap_table_size = cap_table.second; } RiscvProcess32::RiscvProcess32(const ProcessParams ¶ms, @@ -105,8 +115,12 @@ RiscvProcess64::initState() Process::initState(); argsInit(PageBytes); - for (ContextID ctx: contextIds) + for (ContextID ctx: contextIds) { system->threads[ctx]->setMiscRegNoEffect(MISCREG_PRV, PRV_U); + system->threads[ctx]->setRegFlat(RegId(IntRegClass, 12), cap_relocs_base); + system->threads[ctx]->setRegFlat(RegId(IntRegClass, 13), cap_relocs_count); + system->threads[ctx]->setRegFlat(RegId(IntRegClass, 14), cap_table_size); + } } void diff --git a/src/arch/riscvcapstone/process.hh b/src/arch/riscvcapstone/process.hh index ca0a050349..53e6bd7cf4 100644 --- a/src/arch/riscvcapstone/process.hh +++ b/src/arch/riscvcapstone/process.hh @@ -66,6 +66,11 @@ class RiscvProcess64 : public RiscvProcess protected: void initState() override; + + private: + uint64_t cap_relocs_base; + uint64_t cap_relocs_count; + uint64_t cap_table_size; }; class RiscvProcess32 : public RiscvProcess diff --git a/src/base/loader/elf_object.cc b/src/base/loader/elf_object.cc index dc2abb8dfc..12fe9ff2e6 100644 --- a/src/base/loader/elf_object.cc +++ b/src/base/loader/elf_object.cc @@ -413,7 +413,9 @@ ElfObject::getSections() while (section) { GElf_Shdr shdr; gelf_getshdr(section, &shdr); - sectionNames.insert(elf_strptr(elf, ehdr.e_shstrndx, shdr.sh_name)); + std::string sName(elf_strptr(elf, ehdr.e_shstrndx, shdr.sh_name)); + sectionNames.insert(sName); + sectionMap[sName] = std::make_pair((uint64_t)shdr.sh_addr, (uint64_t)shdr.sh_size); section = elf_getscn(elf, ++sec_idx); } // while sections @@ -443,5 +445,18 @@ ElfObject::updateBias(Addr bias_addr) image.offset(bias_addr); } +void +ElfObject::printSections() +{ + if (!sectionNames.size()) + getSections(); + + // std::cout << sectionNames.size() << '\n'; + + for(auto &i : sectionMap) { + std::cout << i.first << ": " << i.second.first << ", " << i.second.second << "\n"; + } +} + } // namespace loader } // namespace gem5 diff --git a/src/base/loader/elf_object.hh b/src/base/loader/elf_object.hh index 6159b35a7b..d7b6f5876e 100644 --- a/src/base/loader/elf_object.hh +++ b/src/base/loader/elf_object.hh @@ -78,6 +78,7 @@ class ElfObject : public ObjectFile uint16_t _programHeaderSize = 0; uint16_t _programHeaderCount = 0; std::set sectionNames; + std::map> sectionMap; ElfObject *interpreter = nullptr; @@ -125,6 +126,15 @@ class ElfObject : public ObjectFile Addr programHeaderTable() {return _programHeaderTable;} uint16_t programHeaderSize() {return _programHeaderSize;} uint16_t programHeaderCount() {return _programHeaderCount;} + + void printSections() override; + + std::pair getSec(std::string sName) override + { + if (!sectionNames.size()) + getSections(); + return sectionMap[sName]; + } }; /** diff --git a/src/base/loader/object_file.hh b/src/base/loader/object_file.hh index 0415bec62e..847003593c 100644 --- a/src/base/loader/object_file.hh +++ b/src/base/loader/object_file.hh @@ -130,6 +130,10 @@ class ObjectFile : public ImageFile const SymbolTable &symtab() const { return _symtab; } + virtual void printSections() { std::cout << "In ObjectFile\n"; } + + virtual std::pair getSec(std::string sName) { return std::make_pair(0, 0); } + protected: Addr entry = 0; diff --git a/src/sim/process.cc b/src/sim/process.cc index ba14c0f33f..a348b450b0 100644 --- a/src/sim/process.cc +++ b/src/sim/process.cc @@ -159,12 +159,8 @@ Process::Process(const ProcessParams ¶ms, EmulationPageTable *pTable, image = objFile->buildImage(); - image.printSegments(); - if (loader::debugSymbolTable.empty()) loader::debugSymbolTable = objFile->symtab(); - - loader::debugSymbolTable.print(); } void