Sandipan Das has uploaded this change for review. ( 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 <[email protected]>
---
M src/arch/power/process.cc
M src/arch/power/process.hh
2 files changed, 24 insertions(+), 20 deletions(-)



diff --git a/src/arch/power/process.cc b/src/arch/power/process.cc
index 26d28a8..c81d12e 100644
--- a/src/arch/power/process.cc
+++ b/src/arch/power/process.cc
@@ -76,13 +76,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<AuxVector<uint32_t>> auxv;
+    int intSize = sizeof(IntType);
+    ByteOrder byteOrder = objFile->getByteOrder();
+    std::vector<AuxVector<IntType>> auxv;

     std::string filename;
     if (argv.size() < 1)
@@ -101,7 +104,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
@@ -204,15 +207,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);
@@ -228,11 +231,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
@@ -251,7 +254,7 @@
     //Copy the aux stuff
     Addr auxv_array_end = auxv_array_base;
     for (const auto &aux: auxv) {
-        initVirtMem->write(auxv_array_end, aux, GuestByteOrder);
+        initVirtMem->write(auxv_array_end, aux, byteOrder);
         auxv_array_end += sizeof(aux);
     }
     //Write out the terminating zeroed auxilliary vector
@@ -260,9 +263,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 5e5a503..bd249a3 100644
--- a/src/arch/power/process.hh
+++ b/src/arch/power/process.hh
@@ -45,7 +45,8 @@
   public:
PowerProcess(const ProcessParams &params, ::Loader::ObjectFile *objFile);

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

 #endif // __POWER_PROCESS_HH__

--
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: 1
Gerrit-Owner: Sandipan Das <[email protected]>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

Reply via email to