Boris Shingarov has submitted this change. ( https://gem5-review.googlesource.com/c/public/gem5/+/40941 )

Change subject: arch-power: Refactor process initialization
......................................................................

arch-power: Refactor process initialization

This generalizes parts of the process initialization
routines in preparation for multi-mode support and
adds flexibility in terms of data types and byte order
used for setting up the environment corresponding to
the mode in use.

Change-Id: Ia9efb93d044682af8b0f0809bca64a17570bf197
Signed-off-by: Sandipan Das <sandi...@linux.ibm.com>
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/40941
Reviewed-by: Boris Shingarov <shinga...@labware.com>
Maintainer: Boris Shingarov <shinga...@labware.com>
Tested-by: kokoro <noreply+kok...@google.com>
---
M src/arch/power/process.cc
M src/arch/power/process.hh
2 files changed, 24 insertions(+), 20 deletions(-)

Approvals:
  Boris Shingarov: Looks good to me, approved; Looks good to me, approved
  kokoro: Regressions pass



diff --git a/src/arch/power/process.cc b/src/arch/power/process.cc
index a9a28b3..bc63146 100644
--- a/src/arch/power/process.cc
+++ b/src/arch/power/process.cc
@@ -81,13 +81,16 @@
 {
     Process::initState();

-    argsInit(sizeof(uint32_t), PageBytes);
+    argsInit<uint32_t>(PageBytes);
 }

+template <typename IntType>
 void
-PowerProcess::argsInit(int intSize, int pageSize)
+PowerProcess::argsInit(int pageSize)
 {
-    std::vector<gem5::auxv::AuxVector<uint32_t>> auxv;
+    int intSize = sizeof(IntType);
+    ByteOrder byteOrder = objFile->getByteOrder();
+    std::vector<gem5::auxv::AuxVector<IntType>> auxv;

     std::string filename;
     if (argv.size() < 1)
@@ -106,7 +109,7 @@
     //Auxilliary vectors are loaded only for elf formatted executables.
     auto *elfObject = dynamic_cast<loader::ElfObject *>(objFile);
     if (elfObject) {
-        uint32_t features = 0;
+        IntType features = 0;

         //Bits which describe the system hardware capabilities
         //XXX Figure out what these should be
@@ -209,15 +212,15 @@
roundUp(memState->getStackSize(), pageSize), "stack");

     // map out initial stack contents
-    uint32_t sentry_base = memState->getStackBase() - sentry_size;
-    uint32_t aux_data_base = sentry_base - aux_data_size;
-    uint32_t env_data_base = aux_data_base - env_data_size;
-    uint32_t arg_data_base = env_data_base - arg_data_size;
-    uint32_t platform_base = arg_data_base - platform_size;
- uint32_t auxv_array_base = platform_base - aux_array_size - aux_padding;
-    uint32_t envp_array_base = auxv_array_base - envp_array_size;
-    uint32_t argv_array_base = envp_array_base - argv_array_size;
-    uint32_t argc_base = argv_array_base - argc_size;
+    IntType sentry_base = memState->getStackBase() - sentry_size;
+    IntType aux_data_base = sentry_base - aux_data_size;
+    IntType env_data_base = aux_data_base - env_data_size;
+    IntType arg_data_base = env_data_base - arg_data_size;
+    IntType platform_base = arg_data_base - platform_size;
+    IntType auxv_array_base = platform_base - aux_array_size - aux_padding;
+    IntType envp_array_base = auxv_array_base - envp_array_size;
+    IntType argv_array_base = envp_array_base - argv_array_size;
+    IntType argc_base = argv_array_base - argc_size;

     DPRINTF(Stack, "The addresses of items on the initial stack:\n");
     DPRINTF(Stack, "0x%x - aux data\n", aux_data_base);
@@ -233,11 +236,11 @@
     // write contents to stack

     // figure out argc
-    uint32_t argc = argv.size();
-    uint32_t guestArgc = htobe(argc);
+    IntType argc = argv.size();
+    IntType guestArgc = htog(argc, byteOrder);

     //Write out the sentry void *
-    uint32_t sentry_NULL = 0;
+    IntType sentry_NULL = 0;
     initVirtMem->writeBlob(sentry_base, &sentry_NULL, sentry_size);

     //Fix up the aux vectors which point to other data
@@ -256,7 +259,7 @@
     //Copy the aux stuff
     Addr auxv_array_end = auxv_array_base;
     for (const auto &aux: auxv) {
-        initVirtMem->write(auxv_array_end, aux, ByteOrder::big);
+        initVirtMem->write(auxv_array_end, aux, byteOrder);
         auxv_array_end += sizeof(aux);
     }
     //Write out the terminating zeroed auxilliary vector
@@ -265,9 +268,9 @@
     auxv_array_end += sizeof(zero);

     copyStringArray(envp, envp_array_base, env_data_base,
-                    ByteOrder::big, *initVirtMem);
+                    byteOrder, *initVirtMem);
     copyStringArray(argv, argv_array_base, arg_data_base,
-                    ByteOrder::big, *initVirtMem);
+                    byteOrder, *initVirtMem);

     initVirtMem->writeBlob(argc_base, &guestArgc, intSize);

diff --git a/src/arch/power/process.hh b/src/arch/power/process.hh
index 210bce2..9f2ce4b 100644
--- a/src/arch/power/process.hh
+++ b/src/arch/power/process.hh
@@ -49,7 +49,8 @@
   public:
     PowerProcess(const ProcessParams &params, loader::ObjectFile *objFile);

-    void argsInit(int intSize, int pageSize);
+    template <typename IntType>
+    void argsInit(int pageSize);
 };

 } // namespace gem5

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/40941
To unsubscribe, or for help writing mail filters, visit https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: Ia9efb93d044682af8b0f0809bca64a17570bf197
Gerrit-Change-Number: 40941
Gerrit-PatchSet: 11
Gerrit-Owner: Sandipan Das <sandi...@linux.ibm.com>
Gerrit-Reviewer: Boris Shingarov <shinga...@labware.com>
Gerrit-Reviewer: kokoro <noreply+kok...@google.com>
Gerrit-MessageType: merged
_______________________________________________
gem5-dev mailing list -- gem5-dev@gem5.org
To unsubscribe send an email to gem5-dev-le...@gem5.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

Reply via email to