summaryrefslogtreecommitdiff
path: root/src/base
diff options
context:
space:
mode:
Diffstat (limited to 'src/base')
-rw-r--r--src/base/loader/aout_object.cc21
-rw-r--r--src/base/loader/dtb_object.cc14
-rw-r--r--src/base/loader/ecoff_object.cc18
-rw-r--r--src/base/loader/elf_object.cc40
-rw-r--r--src/base/loader/elf_object.hh5
-rw-r--r--src/base/loader/hex_file.cc2
-rw-r--r--src/base/loader/hex_file.hh2
-rw-r--r--src/base/loader/object_file.cc23
-rw-r--r--src/base/loader/object_file.hh41
-rw-r--r--src/base/loader/raw_object.cc26
10 files changed, 90 insertions, 102 deletions
diff --git a/src/base/loader/aout_object.cc b/src/base/loader/aout_object.cc
index b731c9a83..e3f703e1d 100644
--- a/src/base/loader/aout_object.cc
+++ b/src/base/loader/aout_object.cc
@@ -46,9 +46,8 @@ AoutObject::tryFile(const string &fname, size_t len, uint8_t *data)
// right now this is only used for Alpha PAL code
return new AoutObject(fname, len, data,
ObjectFile::Alpha, ObjectFile::UnknownOpSys);
- }
- else {
- return NULL;
+ } else {
+ return nullptr;
}
}
@@ -62,21 +61,21 @@ AoutObject::AoutObject(const string &_filename,
entry = execHdr->entry;
- text.baseAddr = N_TXTADDR(*execHdr);
+ text.base = N_TXTADDR(*execHdr);
text.size = execHdr->tsize;
- text.fileImage = fileData + N_TXTOFF(*execHdr);
+ text.data = fileData + N_TXTOFF(*execHdr);
- data.baseAddr = N_DATADDR(*execHdr);
+ data.base = N_DATADDR(*execHdr);
data.size = execHdr->dsize;
- data.fileImage = fileData + N_DATOFF(*execHdr);
+ data.data = fileData + N_DATOFF(*execHdr);
- bss.baseAddr = N_BSSADDR(*execHdr);
+ bss.base = N_BSSADDR(*execHdr);
bss.size = execHdr->bsize;
- bss.fileImage = NULL;
+ bss.data = NULL;
DPRINTFR(Loader, "text: 0x%x %d\ndata: 0x%x %d\nbss: 0x%x %d\n",
- text.baseAddr, text.size, data.baseAddr, data.size,
- bss.baseAddr, bss.size);
+ text.base, text.size, data.base, data.size,
+ bss.base, bss.size);
}
diff --git a/src/base/loader/dtb_object.cc b/src/base/loader/dtb_object.cc
index fab6a762d..92e305ffa 100644
--- a/src/base/loader/dtb_object.cc
+++ b/src/base/loader/dtb_object.cc
@@ -55,17 +55,17 @@ DtbObject::DtbObject(const std::string &_filename, size_t _len, uint8_t *_data,
Arch _arch, OpSys _opSys)
: ObjectFile(_filename, _len, _data, _arch, _opSys)
{
- text.baseAddr = 0;
+ text.base = 0;
text.size = len;
- text.fileImage = fileData;
+ text.data = fileData;
- data.baseAddr = 0;
+ data.base = 0;
data.size = 0;
- data.fileImage = NULL;
+ data.data = nullptr;
- bss.baseAddr = 0;
+ bss.base = 0;
bss.size = 0;
- bss.fileImage = NULL;
+ bss.data = nullptr;
fileDataMmapped = true;
}
@@ -141,7 +141,7 @@ DtbObject::addBootCmdLine(const char* _args, size_t len)
}
text.size = newLen;
- text.fileImage = fdt_buf_w_space;
+ text.data = fdt_buf_w_space;
// clean up old buffer and set to new fdt blob
munmap(fileData, this->len);
diff --git a/src/base/loader/ecoff_object.cc b/src/base/loader/ecoff_object.cc
index caeab5f8f..76b91dd66 100644
--- a/src/base/loader/ecoff_object.cc
+++ b/src/base/loader/ecoff_object.cc
@@ -73,21 +73,21 @@ EcoffObject::EcoffObject(const string &_filename, size_t _len, uint8_t *_data,
entry = aoutHdr->entry;
- text.baseAddr = aoutHdr->text_start;
+ text.base = aoutHdr->text_start;
text.size = aoutHdr->tsize;
- text.fileImage = fileData + ECOFF_TXTOFF(execHdr);
+ text.data = fileData + ECOFF_TXTOFF(execHdr);
- data.baseAddr = aoutHdr->data_start;
+ data.base = aoutHdr->data_start;
data.size = aoutHdr->dsize;
- data.fileImage = fileData + ECOFF_DATOFF(execHdr);
+ data.data = fileData + ECOFF_DATOFF(execHdr);
- bss.baseAddr = aoutHdr->bss_start;
+ bss.base = aoutHdr->bss_start;
bss.size = aoutHdr->bsize;
- bss.fileImage = NULL;
+ bss.data = nullptr;
- DPRINTFR(Loader, "text: 0x%x %d\ndata: 0x%x %d\nbss: 0x%x %d\n",
- text.baseAddr, text.size, data.baseAddr, data.size,
- bss.baseAddr, bss.size);
+ DPRINTFR(Loader, "text: %#x %d\ndata: %#x %d\nbss: %#x %d\n",
+ text.base, text.size, data.base, data.size,
+ bss.base, bss.size);
}
bool
diff --git a/src/base/loader/elf_object.cc b/src/base/loader/elf_object.cc
index 2a8fb04ea..327919540 100644
--- a/src/base/loader/elf_object.cc
+++ b/src/base/loader/elf_object.cc
@@ -295,7 +295,7 @@ ElfObject::ElfObject(const std::string &_filename, size_t _len,
// initialize segment sizes to 0 in case they're not present
text.size = data.size = bss.size = 0;
- text.baseAddr = data.baseAddr = bss.baseAddr = 0;
+ text.base = data.base = bss.base = 0;
int sec_idx = 1;
@@ -352,9 +352,9 @@ ElfObject::ElfObject(const std::string &_filename, size_t _len,
if (phdr.p_paddr <= bss_sec_start &&
phdr.p_paddr + phdr.p_memsz > bss_sec_start &&
phdr.p_memsz - phdr.p_filesz > 0) {
- bss.baseAddr = phdr.p_paddr + phdr.p_filesz;
+ bss.base = phdr.p_paddr + phdr.p_filesz;
bss.size = phdr.p_memsz - phdr.p_filesz;
- bss.fileImage = NULL;
+ bss.data = nullptr;
}
// Check to see if this is the text or data segment
@@ -365,21 +365,21 @@ ElfObject::ElfObject(const std::string &_filename, size_t _len,
if (phdr.p_vaddr != 0)
relocate = false;
- text.baseAddr = phdr.p_paddr;
+ text.base = phdr.p_paddr;
text.size = phdr.p_filesz;
- text.fileImage = fileData + phdr.p_offset;
+ text.data = fileData + phdr.p_offset;
} else if (phdr.p_vaddr <= data_sec_start &&
phdr.p_vaddr + phdr.p_filesz > data_sec_start) {
- data.baseAddr = phdr.p_paddr;
+ data.base = phdr.p_paddr;
data.size = phdr.p_filesz;
- data.fileImage = fileData + phdr.p_offset;
+ data.data = fileData + phdr.p_offset;
} else {
// If it's none of the above but is loadable,
// load the filesize worth of data
Segment extra;
- extra.baseAddr = phdr.p_paddr;
+ extra.base = phdr.p_paddr;
extra.size = phdr.p_filesz;
- extra.fileImage = fileData + phdr.p_offset;
+ extra.data = fileData + phdr.p_offset;
extraSegments.push_back(extra);
}
}
@@ -389,9 +389,9 @@ ElfObject::ElfObject(const std::string &_filename, size_t _len,
"Empty .text segment in '%s'. ELF file corrupted?\n",
filename);
- DPRINTFR(Loader, "text: 0x%x %d\ndata: 0x%x %d\nbss: 0x%x %d\n",
- text.baseAddr, text.size, data.baseAddr, data.size,
- bss.baseAddr, bss.size);
+ DPRINTFR(Loader, "text: %#x %d\ndata: %#x %d\nbss: %#x %d\n",
+ text.base, text.size, data.base, data.size,
+ bss.base, bss.size);
elf_end(elf);
@@ -498,20 +498,20 @@ ElfObject::loadWeakSymbols(SymbolTable *symtab, Addr base, Addr offset,
}
bool
-ElfObject::loadSections(const PortProxy& mem_proxy, Addr addr_mask,
+ElfObject::loadSegments(const PortProxy& mem_proxy, Addr addr_mask,
Addr offset)
{
- if (!ObjectFile::loadSections(mem_proxy, addr_mask, offset))
+ if (!ObjectFile::loadSegments(mem_proxy, addr_mask, offset))
return false;
for (auto seg : extraSegments) {
- if (!loadSection(&seg, mem_proxy, addr_mask, offset)) {
+ if (!loadSegment(&seg, mem_proxy, addr_mask, offset)) {
return false;
}
}
if (interpreter)
- interpreter->loadSections(mem_proxy, addr_mask, offset);
+ interpreter->loadSegments(mem_proxy, addr_mask, offset);
return true;
}
@@ -570,9 +570,9 @@ ElfObject::updateBias(Addr bias_addr)
entry += bias_addr;
// Patch segments with the bias_addr.
- text.baseAddr += bias_addr;
- data.baseAddr += bias_addr;
- bss.baseAddr += bias_addr;
+ text.base += bias_addr;
+ data.base += bias_addr;
+ bss.base += bias_addr;
for (auto &segment : extraSegments)
- segment.baseAddr += bias_addr;
+ segment.base += bias_addr;
}
diff --git a/src/base/loader/elf_object.hh b/src/base/loader/elf_object.hh
index 9585684d4..244b9fc3f 100644
--- a/src/base/loader/elf_object.hh
+++ b/src/base/loader/elf_object.hh
@@ -51,9 +51,6 @@
class ElfObject : public ObjectFile
{
protected:
- // The global definition of a gem5 "Section" is closest to ELF's segments.
- typedef ObjectFile::Section Segment;
-
// These values are provided to a linux process by the kernel, so we
// need to keep them around.
Addr _programHeaderTable;
@@ -94,7 +91,7 @@ class ElfObject : public ObjectFile
public:
virtual ~ElfObject() {}
- bool loadSections(const PortProxy& mem_proxy, Addr addr_mask = maxAddr,
+ bool loadSegments(const PortProxy& mem_proxy, Addr addr_mask = maxAddr,
Addr offset = 0) override;
virtual bool loadAllSymbols(SymbolTable *symtab, Addr base = 0,
diff --git a/src/base/loader/hex_file.cc b/src/base/loader/hex_file.cc
index 32de90588..4c9ffa516 100644
--- a/src/base/loader/hex_file.cc
+++ b/src/base/loader/hex_file.cc
@@ -62,7 +62,7 @@ HexFile::~HexFile()
}
bool
-HexFile::loadSections(PortProxy& memProxy)
+HexFile::loadSegments(PortProxy& memProxy)
{
char Line[64];
Addr MemAddr;
diff --git a/src/base/loader/hex_file.hh b/src/base/loader/hex_file.hh
index fe34fddf0..befd7f320 100644
--- a/src/base/loader/hex_file.hh
+++ b/src/base/loader/hex_file.hh
@@ -52,7 +52,7 @@ class HexFile
virtual ~HexFile();
void close();
- bool loadSections(PortProxy& memProxy);
+ bool loadSegments(PortProxy& memProxy);
};
#endif // __BASE_LOADER_HEX_FILE_HH__
diff --git a/src/base/loader/object_file.cc b/src/base/loader/object_file.cc
index 0bb897cee..8a6b063de 100644
--- a/src/base/loader/object_file.cc
+++ b/src/base/loader/object_file.cc
@@ -73,17 +73,16 @@ ObjectFile::~ObjectFile()
bool
-ObjectFile::loadSection(Section *sec, const PortProxy& mem_proxy,
+ObjectFile::loadSegment(Segment *seg, const PortProxy& mem_proxy,
Addr addr_mask, Addr offset)
{
- if (sec->size != 0) {
- Addr addr = (sec->baseAddr & addr_mask) + offset;
- if (sec->fileImage) {
- mem_proxy.writeBlob(addr, sec->fileImage, sec->size);
- }
- else {
+ if (seg->size != 0) {
+ Addr addr = (seg->base & addr_mask) + offset;
+ if (seg->data) {
+ mem_proxy.writeBlob(addr, seg->data, seg->size);
+ } else {
// no image: must be bss
- mem_proxy.memsetBlob(addr, 0, sec->size);
+ mem_proxy.memsetBlob(addr, 0, seg->size);
}
}
return true;
@@ -91,12 +90,12 @@ ObjectFile::loadSection(Section *sec, const PortProxy& mem_proxy,
bool
-ObjectFile::loadSections(const PortProxy& mem_proxy, Addr addr_mask,
+ObjectFile::loadSegments(const PortProxy& mem_proxy, Addr addr_mask,
Addr offset)
{
- return (loadSection(&text, mem_proxy, addr_mask, offset)
- && loadSection(&data, mem_proxy, addr_mask, offset)
- && loadSection(&bss, mem_proxy, addr_mask, offset));
+ return (loadSegment(&text, mem_proxy, addr_mask, offset)
+ && loadSegment(&data, mem_proxy, addr_mask, offset)
+ && loadSegment(&bss, mem_proxy, addr_mask, offset));
}
namespace
diff --git a/src/base/loader/object_file.hh b/src/base/loader/object_file.hh
index 14dee3be0..db995f5d7 100644
--- a/src/base/loader/object_file.hh
+++ b/src/base/loader/object_file.hh
@@ -88,17 +88,17 @@ class ObjectFile
static const Addr maxAddr = std::numeric_limits<Addr>::max();
- virtual bool loadSections(const PortProxy& mem_proxy,
- Addr mask = maxAddr, Addr offset = 0);
+ virtual bool loadSegments(const PortProxy &mem_proxy,
+ Addr mask=maxAddr, Addr offset=0);
virtual bool loadAllSymbols(SymbolTable *symtab, Addr base = 0,
- Addr offset = 0, Addr mask = maxAddr) = 0;
+ Addr offset=0, Addr mask=maxAddr) = 0;
virtual bool loadGlobalSymbols(SymbolTable *symtab, Addr base = 0,
- Addr offset = 0, Addr mask = maxAddr) = 0;
- virtual bool loadLocalSymbols(SymbolTable *symtab, Addr base = 0,
- Addr offset = 0, Addr mask = maxAddr) = 0;
- virtual bool loadWeakSymbols(SymbolTable *symtab, Addr base = 0,
- Addr offset = 0, Addr mask = maxAddr)
+ Addr offset=0, Addr mask=maxAddr) = 0;
+ virtual bool loadLocalSymbols(SymbolTable *symtab, Addr base=0,
+ Addr offset=0, Addr mask=maxAddr) = 0;
+ virtual bool loadWeakSymbols(SymbolTable *symtab, Addr base=0,
+ Addr offset=0, Addr mask=maxAddr)
{ return false; }
virtual ObjectFile *getInterpreter() const { return nullptr; }
@@ -116,27 +116,28 @@ class ObjectFile
protected:
- struct Section {
- Addr baseAddr;
- uint8_t *fileImage;
+ struct Segment
+ {
+ Addr base;
+ uint8_t *data;
size_t size;
};
Addr entry;
- Section text;
- Section data;
- Section bss;
+ Segment text;
+ Segment data;
+ Segment bss;
- bool loadSection(Section *sec, const PortProxy& mem_proxy, Addr mask,
- Addr offset = 0);
+ bool loadSegment(Segment *seg, const PortProxy &mem_proxy, Addr mask,
+ Addr offset=0);
public:
Addr entryPoint() const { return entry; }
- Addr textBase() const { return text.baseAddr; }
- Addr dataBase() const { return data.baseAddr; }
- Addr bssBase() const { return bss.baseAddr; }
+ Addr textBase() const { return text.base; }
+ Addr dataBase() const { return data.base; }
+ Addr bssBase() const { return bss.base; }
size_t textSize() const { return text.size; }
size_t dataSize() const { return data.size; }
@@ -147,7 +148,7 @@ class ObjectFile
* blob that doesn't include an object header.
* @param a address to load the binary/text section at
*/
- void setTextBase(Addr a) { text.baseAddr = a; }
+ void setTextBase(Addr a) { text.base = a; }
/**
* Each instance of a Loader subclass will have a chance to try to load
diff --git a/src/base/loader/raw_object.cc b/src/base/loader/raw_object.cc
index 4a04f7dfc..9662d8613 100644
--- a/src/base/loader/raw_object.cc
+++ b/src/base/loader/raw_object.cc
@@ -45,21 +45,21 @@ RawObject::RawObject(const std::string &_filename, size_t _len,
uint8_t *_data, Arch _arch, OpSys _opSys)
: ObjectFile(_filename, _len, _data, _arch, _opSys)
{
- text.baseAddr = 0;
+ text.base = 0;
text.size = len;
- text.fileImage = fileData;
+ text.data = fileData;
- data.baseAddr = 0;
+ data.base = 0;
data.size = 0;
- data.fileImage = NULL;
+ data.data = nullptr;
- bss.baseAddr = 0;
+ bss.base = 0;
bss.size = 0;
- bss.fileImage = NULL;
+ bss.data = nullptr;
- DPRINTFR(Loader, "text: 0x%x %d\ndata: 0x%x %d\nbss: 0x%x %d\n",
- text.baseAddr, text.size, data.baseAddr, data.size,
- bss.baseAddr, bss.size);
+ DPRINTFR(Loader, "text: %#x %d\ndata: %#x %d\nbss: %#x %d\n",
+ text.base, text.size, data.base, data.size,
+ bss.base, bss.size);
}
bool
@@ -73,10 +73,6 @@ bool
RawObject::loadGlobalSymbols(SymbolTable *symtab, Addr base, Addr offset,
Addr addr_mask)
{
-/* int fnameStart = filename.rfind('/',filename.size()) + 1;
- int extStart = filename.rfind('.',filename.size());
- symtab->insert(text.baseAddr & addr_mask, filename.substr(fnameStart,
- extStart-fnameStart) + "_start");*/
return true;
}
@@ -84,9 +80,5 @@ bool
RawObject::loadLocalSymbols(SymbolTable *symtab, Addr base, Addr offset,
Addr addr_mask)
{
-/* int fnameStart = filename.rfind('/',filename.size()) + 1;
- int extStart = filename.rfind('.',filename.size());
- symtab->insert(text.baseAddr & addr_mask, filename.substr(fnameStart,
- extStart-fnameStart) + "_start");*/
return true;
}