Alec Roelke has submitted this change and it was merged. ( https://gem5-review.googlesource.com/3401 )

Change subject: arch-riscv: Fix bad stack initialization
......................................................................

arch-riscv: Fix bad stack initialization

This patch fixes a problem with RISC-V initial stack setup in SE mode
where the AT_RANDOM aux vector value contains an address that is too
close to the top of the stack and doesn't fit the required 16 bytes. To
fix this, the program header table was added to the top of the stack
just like the RISC-V proxy kernel does.

Change-Id: I814562e060ff041cd0d7a7c54c3685645bd325a3
Reviewed-on: https://gem5-review.googlesource.com/3401
Reviewed-by: Jason Lowe-Power <[email protected]>
Reviewed-by: Brandon Potter <[email protected]>
Maintainer: Alec Roelke <[email protected]>
---
M src/arch/riscv/process.cc
1 file changed, 11 insertions(+), 0 deletions(-)

Approvals:
  Jason Lowe-Power: Looks good to me, but someone else must approve
  Brandon Potter: Looks good to me, approved
  Alec Roelke: Looks good to me, approved



diff --git a/src/arch/riscv/process.cc b/src/arch/riscv/process.cc
index 13038c1..eeea5ee 100644
--- a/src/arch/riscv/process.cc
+++ b/src/arch/riscv/process.cc
@@ -88,6 +88,7 @@

     // Determine stack size and populate auxv
     Addr stack_top = memState->getStackMin();
+    stack_top -= elfObject->programHeaderSize();
     for (const string& arg: argv)
         stack_top -= arg.size() + 1;
     for (const string& env: envp)
@@ -113,6 +114,16 @@
     allocateMem(roundDown(stack_top, pageSize),
             roundUp(memState->getStackSize(), pageSize));

+    // Copy program headers to stack
+    memState->setStackMin(memState->getStackMin() -
+            elfObject->programHeaderSize());
+    uint8_t* phdr = new uint8_t[elfObject->programHeaderSize()];
+    initVirtMem.readBlob(elfObject->programHeaderTable(), phdr,
+            elfObject->programHeaderSize());
+    initVirtMem.writeBlob(memState->getStackMin(), phdr,
+            elfObject->programHeaderSize());
+    delete phdr;
+
     // Copy argv to stack
     vector<Addr> argPointers;
     for (const string& arg: argv) {

--
To view, visit https://gem5-review.googlesource.com/3401
To unsubscribe, visit https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I814562e060ff041cd0d7a7c54c3685645bd325a3
Gerrit-Change-Number: 3401
Gerrit-PatchSet: 2
Gerrit-Owner: Alec Roelke <[email protected]>
Gerrit-Reviewer: Alec Roelke <[email protected]>
Gerrit-Reviewer: Brandon Potter <[email protected]>
Gerrit-Reviewer: Jason Lowe-Power <[email protected]>
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev

Reply via email to