arch,base: Separate the idea of a memory image and object file.
A memory image can be described by an object file, but an object file is more than a memory image. Also, it makes sense to manipulate a memory image to, for instance, change how it's loaded into memory. That takes on larger implications (relocations, the entry point, symbols, etc.) when talking about the whole object file, and also modifies aspects which may not need to change. For instance if an image needs to be loaded into memory at addresses different from what's in the object file, but other things like symbols need to stay unmodified. Change-Id: Ia360405ffb2c1c48e0cc201ac0a0764357996a54 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/21466 Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Brandon Potter <Brandon.Potter@amd.com> Maintainer: Gabe Black <gabeblack@google.com>
This commit is contained in:
@@ -54,10 +54,10 @@ AlphaProcess::AlphaProcess(ProcessParams *params, ObjectFile *objFile)
|
||||
objFile)
|
||||
{
|
||||
fatal_if(params->useArchPT, "Arch page tables not implemented.");
|
||||
Addr brk_point = roundUp(objFile->maxSegmentAddr(), PageBytes);
|
||||
Addr brk_point = roundUp(image.maxAddr(), PageBytes);
|
||||
|
||||
// Set up stack. On Alpha, stack goes below the image.
|
||||
Addr stack_base = objFile->minSegmentAddr() - (409600 + 4096);
|
||||
Addr stack_base = image.minAddr() - (409600 + 4096);
|
||||
|
||||
// Set up region for mmaps.
|
||||
Addr mmap_end = 0x10000;
|
||||
@@ -74,13 +74,6 @@ AlphaProcess::AlphaProcess(ProcessParams *params, ObjectFile *objFile)
|
||||
void
|
||||
AlphaProcess::argsInit(int intSize, int pageSize)
|
||||
{
|
||||
// Patch the ld_bias for dynamic executables.
|
||||
updateBias();
|
||||
|
||||
objFile->loadSegments(initVirtMem);
|
||||
if (objFile->getInterpreter())
|
||||
objFile->getInterpreter()->loadSegments(initVirtMem);
|
||||
|
||||
std::vector<AuxVector<uint64_t>> auxv;
|
||||
|
||||
ElfObject * elfObject = dynamic_cast<ElfObject *>(objFile);
|
||||
|
||||
@@ -57,13 +57,11 @@ AlphaSystem::AlphaSystem(Params *p)
|
||||
*/
|
||||
// Load Console Code
|
||||
console = createObjectFile(params()->console);
|
||||
console->setLoadMask(loadAddrMask);
|
||||
if (console == NULL)
|
||||
fatal("Could not load console file %s", params()->console);
|
||||
|
||||
// Load pal file
|
||||
pal = createObjectFile(params()->pal);
|
||||
pal->setLoadMask(loadAddrMask);
|
||||
if (pal == NULL)
|
||||
fatal("Could not load PALcode file %s", params()->pal);
|
||||
|
||||
@@ -111,8 +109,8 @@ AlphaSystem::initState()
|
||||
System::initState();
|
||||
|
||||
// Load program sections into memory
|
||||
pal->loadSegments(physProxy);
|
||||
console->loadSegments(physProxy);
|
||||
pal->buildImage().mask(loadAddrMask).write(physProxy);
|
||||
console->buildImage().mask(loadAddrMask).write(physProxy);
|
||||
|
||||
/**
|
||||
* Copy the osflags (kernel arguments) into the consoles
|
||||
|
||||
@@ -132,8 +132,8 @@ FreebsdArmSystem::initState()
|
||||
if (ra)
|
||||
bootReleaseAddr = ra & ~ULL(0x7F);
|
||||
|
||||
dtb_file->setLoadOffset(params()->atags_addr + loadAddrOffset);
|
||||
dtb_file->loadSegments(physProxy);
|
||||
dtb_file->buildImage().
|
||||
offset(params()->atags_addr + loadAddrOffset).write(physProxy);
|
||||
delete dtb_file;
|
||||
|
||||
// Kernel boot requirements to set up r0, r1 and r2 in ARMv7
|
||||
|
||||
@@ -151,8 +151,8 @@ LinuxArmSystem::initState()
|
||||
"to DTB file: %s\n", params()->dtb_filename);
|
||||
}
|
||||
|
||||
dtb_file->setLoadOffset(params()->atags_addr + loadAddrOffset);
|
||||
dtb_file->loadSegments(physProxy);
|
||||
dtb_file->buildImage().
|
||||
offset(params()->atags_addr + loadAddrOffset).write(physProxy);
|
||||
delete dtb_file;
|
||||
} else {
|
||||
// Using ATAGS
|
||||
|
||||
@@ -75,7 +75,7 @@ ArmProcess32::ArmProcess32(ProcessParams *params, ObjectFile *objFile,
|
||||
ObjectFile::Arch _arch)
|
||||
: ArmProcess(params, objFile, _arch)
|
||||
{
|
||||
Addr brk_point = roundUp(objFile->maxSegmentAddr(), PageBytes);
|
||||
Addr brk_point = roundUp(image.maxAddr(), PageBytes);
|
||||
Addr stack_base = 0xbf000000L;
|
||||
Addr max_stack_size = 8 * 1024 * 1024;
|
||||
Addr next_thread_stack_base = stack_base - max_stack_size;
|
||||
@@ -89,7 +89,7 @@ ArmProcess64::ArmProcess64(ProcessParams *params, ObjectFile *objFile,
|
||||
ObjectFile::Arch _arch)
|
||||
: ArmProcess(params, objFile, _arch)
|
||||
{
|
||||
Addr brk_point = roundUp(objFile->maxSegmentAddr(), PageBytes);
|
||||
Addr brk_point = roundUp(image.maxAddr(), PageBytes);
|
||||
Addr stack_base = 0x7fffff0000L;
|
||||
Addr max_stack_size = 8 * 1024 * 1024;
|
||||
Addr next_thread_stack_base = stack_base - max_stack_size;
|
||||
@@ -266,14 +266,6 @@ ArmProcess::argsInit(int pageSize, IntRegIndex spIndex)
|
||||
//We want 16 byte alignment
|
||||
uint64_t align = 16;
|
||||
|
||||
// Patch the ld_bias for dynamic executables.
|
||||
updateBias();
|
||||
|
||||
// load object file into target memory
|
||||
objFile->loadSegments(initVirtMem);
|
||||
if (objFile->getInterpreter())
|
||||
objFile->getInterpreter()->loadSegments(initVirtMem);
|
||||
|
||||
//Setup the auxilliary vectors. These will already have endian conversion.
|
||||
//Auxilliary vectors are loaded only for elf formatted executables.
|
||||
ElfObject * elfObject = dynamic_cast<ElfObject *>(objFile);
|
||||
|
||||
@@ -143,7 +143,7 @@ ArmSystem::initState()
|
||||
|
||||
if (bootldr) {
|
||||
bool isGICv3System = dynamic_cast<Gicv3 *>(getGIC()) != nullptr;
|
||||
bootldr->loadSegments(physProxy);
|
||||
bootldr->buildImage().write(physProxy);
|
||||
|
||||
inform("Using bootloader at address %#x\n", bootldr->entryPoint());
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ MipsProcess::MipsProcess(ProcessParams *params, ObjectFile *objFile)
|
||||
Addr next_thread_stack_base = stack_base - max_stack_size;
|
||||
|
||||
// Set up break point (Top of Heap)
|
||||
Addr brk_point = objFile->maxSegmentAddr();
|
||||
Addr brk_point = image.maxAddr();
|
||||
brk_point = roundUp(brk_point, PageBytes);
|
||||
|
||||
// Set up region for mmaps. Start it 1GB above the top of the heap.
|
||||
@@ -89,14 +89,6 @@ MipsProcess::argsInit(int pageSize)
|
||||
{
|
||||
int intSize = sizeof(IntType);
|
||||
|
||||
// Patch the ld_bias for dynamic executables.
|
||||
updateBias();
|
||||
|
||||
// load object file into target memory
|
||||
objFile->loadSegments(initVirtMem);
|
||||
if (objFile->getInterpreter())
|
||||
objFile->getInterpreter()->loadSegments(initVirtMem);
|
||||
|
||||
std::vector<AuxVector<IntType>> auxv;
|
||||
|
||||
ElfObject * elfObject = dynamic_cast<ElfObject *>(objFile);
|
||||
|
||||
@@ -56,7 +56,7 @@ PowerProcess::PowerProcess(ProcessParams *params, ObjectFile *objFile)
|
||||
{
|
||||
fatal_if(params->useArchPT, "Arch page tables not implemented.");
|
||||
// Set up break point (Top of Heap)
|
||||
Addr brk_point = objFile->maxSegmentAddr();
|
||||
Addr brk_point = image.maxAddr();
|
||||
brk_point = roundUp(brk_point, PageBytes);
|
||||
|
||||
Addr stack_base = 0xbf000000L;
|
||||
@@ -95,13 +95,9 @@ PowerProcess::argsInit(int intSize, int pageSize)
|
||||
//We want 16 byte alignment
|
||||
uint64_t align = 16;
|
||||
|
||||
// Patch the ld_bias for dynamic executables.
|
||||
updateBias();
|
||||
|
||||
// load object file into target memory
|
||||
objFile->loadSegments(initVirtMem);
|
||||
if (objFile->getInterpreter())
|
||||
objFile->getInterpreter()->loadSegments(initVirtMem);
|
||||
image.write(initVirtMem);
|
||||
interpImage.write(initVirtMem);
|
||||
|
||||
//Setup the auxilliary vectors. These will already have endian conversion.
|
||||
//Auxilliary vectors are loaded only for elf formatted executables.
|
||||
|
||||
@@ -55,7 +55,7 @@ BareMetalRiscvSystem::initState()
|
||||
RiscvSystem::initState();
|
||||
|
||||
// load program sections into memory
|
||||
if (!bootloader->loadSegments(physProxy)) {
|
||||
if (!bootloader->buildImage().write(physProxy)) {
|
||||
warn("could not load sections to memory");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ RiscvProcess64::RiscvProcess64(ProcessParams *params, ObjectFile *objFile) :
|
||||
const Addr stack_base = 0x7FFFFFFFFFFFFFFFL;
|
||||
const Addr max_stack_size = 8 * 1024 * 1024;
|
||||
const Addr next_thread_stack_base = stack_base - max_stack_size;
|
||||
const Addr brk_point = roundUp(objFile->maxSegmentAddr(), PageBytes);
|
||||
const Addr brk_point = roundUp(image.maxAddr(), PageBytes);
|
||||
const Addr mmap_end = 0x4000000000000000L;
|
||||
memState = make_shared<MemState>(brk_point, stack_base, max_stack_size,
|
||||
next_thread_stack_base, mmap_end);
|
||||
@@ -87,7 +87,7 @@ RiscvProcess32::RiscvProcess32(ProcessParams *params, ObjectFile *objFile) :
|
||||
const Addr stack_base = 0x7FFFFFFF;
|
||||
const Addr max_stack_size = 8 * 1024 * 1024;
|
||||
const Addr next_thread_stack_base = stack_base - max_stack_size;
|
||||
const Addr brk_point = roundUp(objFile->maxSegmentAddr(), PageBytes);
|
||||
const Addr brk_point = roundUp(image.maxAddr(), PageBytes);
|
||||
const Addr mmap_end = 0x40000000L;
|
||||
memState = make_shared<MemState>(brk_point, stack_base, max_stack_size,
|
||||
next_thread_stack_base, mmap_end);
|
||||
@@ -123,10 +123,6 @@ RiscvProcess::argsInit(int pageSize)
|
||||
const int RandomBytes = 16;
|
||||
const int addrSize = sizeof(IntType);
|
||||
|
||||
updateBias();
|
||||
objFile->loadSegments(initVirtMem);
|
||||
if (objFile->getInterpreter())
|
||||
objFile->getInterpreter()->loadSegments(initVirtMem);
|
||||
ElfObject* elfObject = dynamic_cast<ElfObject*>(objFile);
|
||||
memState->setStackMin(memState->getStackBase());
|
||||
|
||||
|
||||
@@ -204,14 +204,6 @@ SparcProcess::argsInit(int pageSize)
|
||||
// maintain double word alignment of the stack pointer.
|
||||
uint64_t align = 16;
|
||||
|
||||
// Patch the ld_bias for dynamic executables.
|
||||
updateBias();
|
||||
|
||||
// load object file into target memory
|
||||
objFile->loadSegments(initVirtMem);
|
||||
if (objFile->getInterpreter())
|
||||
objFile->getInterpreter()->loadSegments(initVirtMem);
|
||||
|
||||
enum hardwareCaps
|
||||
{
|
||||
M5_HWCAP_SPARC_FLUSH = 1,
|
||||
|
||||
@@ -78,7 +78,7 @@ class Sparc32Process : public SparcProcess
|
||||
Sparc32Process(ProcessParams * params, ObjectFile *objFile)
|
||||
: SparcProcess(params, objFile, 0)
|
||||
{
|
||||
Addr brk_point = objFile->maxSegmentAddr();
|
||||
Addr brk_point = image.maxAddr();
|
||||
brk_point = roundUp(brk_point, SparcISA::PageBytes);
|
||||
|
||||
// Reserve 8M for main stack.
|
||||
@@ -122,7 +122,7 @@ class Sparc64Process : public SparcProcess
|
||||
Sparc64Process(ProcessParams * params, ObjectFile *objFile)
|
||||
: SparcProcess(params, objFile, 2047)
|
||||
{
|
||||
Addr brk_point = objFile->maxSegmentAddr();
|
||||
Addr brk_point = image.maxAddr();
|
||||
brk_point = roundUp(brk_point, SparcISA::PageBytes);
|
||||
|
||||
Addr max_stack_size = 8 * 1024 * 1024;
|
||||
|
||||
@@ -136,25 +136,15 @@ SparcSystem::initState()
|
||||
// Call the initialisation of the super class
|
||||
System::initState();
|
||||
|
||||
// Load reset binary into memory
|
||||
reset->setLoadOffset(params()->reset_addr);
|
||||
reset->loadSegments(physProxy);
|
||||
// Load the openboot binary
|
||||
openboot->setLoadOffset(params()->openboot_addr);
|
||||
openboot->loadSegments(physProxy);
|
||||
// Load the hypervisor binary
|
||||
hypervisor->setLoadOffset(params()->hypervisor_addr);
|
||||
hypervisor->loadSegments(physProxy);
|
||||
// Load the nvram image
|
||||
nvram->setLoadOffset(params()->nvram_addr);
|
||||
nvram->loadSegments(physProxy);
|
||||
// Load the hypervisor description image
|
||||
hypervisor_desc->setLoadOffset(params()->hypervisor_desc_addr);
|
||||
hypervisor_desc->loadSegments(physProxy);
|
||||
// Load the partition description image
|
||||
partition_desc->setLoadOffset(params()->partition_desc_addr);
|
||||
partition_desc->loadSegments(physProxy);
|
||||
|
||||
reset->buildImage().offset(params()->reset_addr).write(physProxy);
|
||||
openboot->buildImage().offset(params()->openboot_addr).write(physProxy);
|
||||
hypervisor->buildImage().
|
||||
offset(params()->hypervisor_addr).write(physProxy);
|
||||
nvram->buildImage().offset(params()->nvram_addr).write(physProxy);
|
||||
hypervisor_desc->buildImage().
|
||||
offset(params()->hypervisor_desc_addr).write(physProxy);
|
||||
partition_desc->buildImage().
|
||||
offset(params()->partition_desc_addr).write(physProxy);
|
||||
|
||||
// @todo any fixup code over writing data in binaries on setting break
|
||||
// events on functions should happen here.
|
||||
|
||||
@@ -136,7 +136,7 @@ X86_64Process::X86_64Process(ProcessParams *params, ObjectFile *objFile,
|
||||
vsyscallPage.vtimeOffset = 0x400;
|
||||
vsyscallPage.vgettimeofdayOffset = 0x0;
|
||||
|
||||
Addr brk_point = roundUp(objFile->maxSegmentAddr(), PageBytes);
|
||||
Addr brk_point = roundUp(image.maxAddr(), PageBytes);
|
||||
Addr stack_base = 0x7FFFFFFFF000ULL;
|
||||
Addr max_stack_size = 8 * 1024 * 1024;
|
||||
Addr next_thread_stack_base = stack_base - max_stack_size;
|
||||
@@ -175,7 +175,7 @@ I386Process::I386Process(ProcessParams *params, ObjectFile *objFile,
|
||||
vsyscallPage.vsyscallOffset = 0x400;
|
||||
vsyscallPage.vsysexitOffset = 0x410;
|
||||
|
||||
Addr brk_point = roundUp(objFile->maxSegmentAddr(), PageBytes);
|
||||
Addr brk_point = roundUp(image.maxAddr(), PageBytes);
|
||||
Addr stack_base = _gdtStart;
|
||||
Addr max_stack_size = 8 * 1024 * 1024;
|
||||
Addr next_thread_stack_base = stack_base - max_stack_size;
|
||||
@@ -770,14 +770,6 @@ X86Process::argsInit(int pageSize,
|
||||
// We want 16 byte alignment
|
||||
uint64_t align = 16;
|
||||
|
||||
// Patch the ld_bias for dynamic executables.
|
||||
updateBias();
|
||||
|
||||
// load object file into target memory
|
||||
objFile->loadSegments(initVirtMem);
|
||||
if (objFile->getInterpreter())
|
||||
objFile->getInterpreter()->loadSegments(initVirtMem);
|
||||
|
||||
enum X86CpuFeature {
|
||||
X86_OnboardFPU = 1 << 0,
|
||||
X86_VirtualModeExtensions = 1 << 1,
|
||||
|
||||
Reference in New Issue
Block a user