Skip to content

Commit

Permalink
Retrieve and store info about captable and cap_relocs sections; disab…
Browse files Browse the repository at this point in the history
…le instcount check

Change-Id: I772f61952f24112dd8846c70bd1c0899d2d9105d
  • Loading branch information
hakase56557 committed Oct 4, 2023
1 parent 026fdd7 commit d7ce7c9
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/arch/riscvcapstone/o3/dyn_inst.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
16 changes: 15 additions & 1 deletion src/arch/riscvcapstone/process.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,16 @@ RiscvProcess64::RiscvProcess64(const ProcessParams &params,
const Addr mmap_end = 0x400000000ULL;
memState = std::make_shared<MemState>(this, brk_point, stack_base,
max_stack_size, next_thread_stack_base, mmap_end);

// objFile->printSections();

std::pair<uint64_t, uint64_t> 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 &params,
Expand All @@ -105,8 +115,12 @@ RiscvProcess64::initState()
Process::initState();

argsInit<uint64_t>(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
Expand Down
5 changes: 5 additions & 0 deletions src/arch/riscvcapstone/process.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 16 additions & 1 deletion src/base/loader/elf_object.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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, uint64_t>((uint64_t)shdr.sh_addr, (uint64_t)shdr.sh_size);
section = elf_getscn(elf, ++sec_idx);
} // while sections

Expand Down Expand Up @@ -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
10 changes: 10 additions & 0 deletions src/base/loader/elf_object.hh
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class ElfObject : public ObjectFile
uint16_t _programHeaderSize = 0;
uint16_t _programHeaderCount = 0;
std::set<std::string> sectionNames;
std::map<std::string, std::pair<uint64_t, uint64_t>> sectionMap;

ElfObject *interpreter = nullptr;

Expand Down Expand Up @@ -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<uint64_t, uint64_t> getSec(std::string sName) override
{
if (!sectionNames.size())
getSections();
return sectionMap[sName];
}
};

/**
Expand Down
4 changes: 4 additions & 0 deletions src/base/loader/object_file.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint64_t, uint64_t> getSec(std::string sName) { return std::make_pair<uint64_t, uint64_t>(0, 0); }

protected:
Addr entry = 0;

Expand Down
4 changes: 0 additions & 4 deletions src/sim/process.cc
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,8 @@ Process::Process(const ProcessParams &params, EmulationPageTable *pTable,

image = objFile->buildImage();

image.printSegments();

if (loader::debugSymbolTable.empty())
loader::debugSymbolTable = objFile->symtab();

loader::debugSymbolTable.print();
}

void
Expand Down

0 comments on commit d7ce7c9

Please sign in to comment.