Gabe Black has uploaded this change for review. ( https://gem5-review.googlesource.com/c/public/gem5/+/56672 )

Change subject: arch-x86: Make microcode ROM segments which accumulate.
......................................................................

arch-x86: Make microcode ROM segments which accumulate.

These segments can be compiled separately, and will automatically
accumulate in the ROM object at initialization time. Both local and
extern labels are adjusted for the position in the actual ROM.

Change-Id: I5f8fba1854b94187be5ab557a19a107aaa490bf5
---
M src/arch/x86/decoder.cc
M src/arch/x86/faults.cc
M src/arch/x86/microcode_rom.cc
M src/arch/x86/microcode_rom.hh
M src/arch/x86/ucasmlib/arch/x86/rom.py
M src/arch/x86/ucasmlib/arch/x86/symbols.py
6 files changed, 78 insertions(+), 25 deletions(-)



diff --git a/src/arch/x86/decoder.cc b/src/arch/x86/decoder.cc
index d1262f0..cc9373f 100644
--- a/src/arch/x86/decoder.cc
+++ b/src/arch/x86/decoder.cc
@@ -737,7 +737,8 @@
 StaticInstPtr
 Decoder::fetchRomMicroop(MicroPC micropc, StaticInstPtr curMacroop)
 {
-    return X86ISAInst::microcodeRom.fetchMicroop(micropc, curMacroop);
+    static const auto &rom = X86ISAInst::microcodeRom();
+    return rom.fetchMicroop(micropc, curMacroop);
 }

 } // namespace X86ISA
diff --git a/src/arch/x86/faults.cc b/src/arch/x86/faults.cc
index c25a0a4..1f1e414 100644
--- a/src/arch/x86/faults.cc
+++ b/src/arch/x86/faults.cc
@@ -71,16 +71,16 @@
     MicroPC entry;
     if (m5reg.mode == LongMode) {
         static MicroPC long_mode_interrupt =
-            X86ISAInst::microcodeRom.getLabel("longModeInterrupt");
+            X86ISAInst::microcodeRom().getLabel("longModeInterrupt");
         entry = long_mode_interrupt;
     } else {
         if (m5reg.submode == RealMode) {
             static MicroPC real_mode_interrupt =
-                X86ISAInst::microcodeRom.getLabel("realModeInterrupt");
+                X86ISAInst::microcodeRom().getLabel("realModeInterrupt");
             entry = real_mode_interrupt;
         } else {
             static MicroPC legacy_mode_interrupt =
-                X86ISAInst::microcodeRom.getLabel("legacyModeInterrupt");
+                X86ISAInst::microcodeRom().getLabel("legacyModeInterrupt");
             entry = legacy_mode_interrupt;
         }
     }
@@ -89,11 +89,11 @@
     tc->setIntReg(INTREG_MICRO(7), pc.pc() - cs_base);
     if (errorCode != (uint64_t)(-1)) {
         if (m5reg.mode == LongMode) {
-            static MicroPC long_mode = X86ISAInst::microcodeRom.getLabel(
+            static MicroPC long_mode = X86ISAInst::microcodeRom().getLabel(
                     "longModeInterruptWithError");
             entry = long_mode;
         } else {
-            static MicroPC legacy_mode = X86ISAInst::microcodeRom.getLabel(
+ static MicroPC legacy_mode = X86ISAInst::microcodeRom().getLabel(
                     "legacyModeInterruptWithError");
             entry = legacy_mode;
         }
@@ -302,7 +302,7 @@
     // Update the handy M5 Reg.
     tc->setMiscReg(MISCREG_M5_REG, 0);
     static MicroPC init_int_halt =
-        X86ISAInst::microcodeRom.getLabel("initIntHalt");
+        X86ISAInst::microcodeRom().getLabel("initIntHalt");
     MicroPC entry = init_int_halt;
     pc.upc(romMicroPC(entry));
     pc.nupc(romMicroPC(entry) + 1);
diff --git a/src/arch/x86/microcode_rom.cc b/src/arch/x86/microcode_rom.cc
index e505e31..6a39aa8 100644
--- a/src/arch/x86/microcode_rom.cc
+++ b/src/arch/x86/microcode_rom.cc
@@ -30,6 +30,34 @@
 namespace gem5::X86ISAInst
 {

-MicrocodeRom microcodeRom;
+MicrocodeRom::Segment::Segment(const std::vector<GenFunc> &funcs,
+        const Labels &_labels, const Labels &_externs) :
+    genFuncs(funcs), labels(_labels), externs(_externs)
+{
+    microcodeRom().installSegment(*this);
+}
+
+void
+MicrocodeRom::installSegment(const Segment &segment)
+{
+    MicroPC base_offset = genFuncs.size();
+    genFuncs.insert(genFuncs.end(), segment.genFuncs.begin(),
+            segment.genFuncs.end());
+    for (auto & [label, micropc]: segment.labels) {
+        auto [it, success] = labels.insert({label, micropc + base_offset});
+        panic_if(!success, "Duplicate ROM label %s.", label);
+    }
+    for (auto & [label, micropc]: segment.externs) {
+ auto [it, success] = externs.insert({label, micropc + base_offset});
+        panic_if(!success, "Duplicate extern ROM label %s.", label);
+    }
+}
+
+MicrocodeRom &
+microcodeRom()
+{
+    static MicrocodeRom rom;
+    return rom;
+}

 } // namespace gem5::X86ISAInst
diff --git a/src/arch/x86/microcode_rom.hh b/src/arch/x86/microcode_rom.hh
index 10e3023..c802a0a 100644
--- a/src/arch/x86/microcode_rom.hh
+++ b/src/arch/x86/microcode_rom.hh
@@ -39,10 +39,7 @@
 #include "arch/x86/insts/macroop.hh"
 #include "cpu/static_inst.hh"

-namespace gem5
-{
-
-namespace X86ISAInst
+namespace gem5::X86ISAInst
 {

 class MicrocodeRom
@@ -53,23 +50,33 @@
             const Labels &labels, const X86ISA::ExtMachInst &machInst,
             const X86ISA::EmulEnv &env)>;

-  protected:
+    struct Segment
+    {
+        Segment(const std::vector<GenFunc> &funcs,
+                const Labels &_labels, const Labels &_externs);
+        std::vector<GenFunc> genFuncs;
+        Labels labels;
+        Labels externs;
+    };
+
+    friend struct Segment;
+
+  private:
+    void installSegment(const Segment &segment);
+
     std::vector<GenFunc> genFuncs;
     Labels labels;
     Labels externs;

   public:
-    //Constructor.
-    MicrocodeRom();
-
     MicroPC
-    getLabel(std::string label)
+    getLabel(std::string label) const
     {
         return externs.at(label);
     }

     StaticInstPtr
-    fetchMicroop(MicroPC micro_pc, StaticInstPtr macroop)
+    fetchMicroop(MicroPC micro_pc, StaticInstPtr macroop) const
     {
         micro_pc = normalMicroPC(micro_pc);
         if (micro_pc >= genFuncs.size())
@@ -90,9 +97,8 @@
     }
 };

-extern MicrocodeRom microcodeRom;
+MicrocodeRom &microcodeRom();

-} // namespace X86ISAInst
-} // namespace gem5
+} // namespace X86ISAInst::gem5

 #endif // __ARCH_X86_MICROCODE_ROM_HH__
diff --git a/src/arch/x86/ucasmlib/arch/x86/rom.py b/src/arch/x86/ucasmlib/arch/x86/rom.py
index c84fc39..66e3688 100644
--- a/src/arch/x86/ucasmlib/arch/x86/rom.py
+++ b/src/arch/x86/ucasmlib/arch/x86/rom.py
@@ -42,7 +42,12 @@
         externs = f'{{ {", ".join(extern_items)} }}'

         return f'''
-X86ISAInst::MicrocodeRom::MicrocodeRom() : genFuncs({allocator}),
-    labels({labels}), externs({externs})
-{{}}
+namespace
+{{
+X86ISAInst::MicrocodeRom::Segment segment = {{
+    {allocator},
+    {labels},
+    {externs}
+}};
+}} // anonymous namespace
 '''
diff --git a/src/arch/x86/ucasmlib/arch/x86/symbols.py b/src/arch/x86/ucasmlib/arch/x86/symbols.py
index 7367825..70bd1cc 100644
--- a/src/arch/x86/ucasmlib/arch/x86/symbols.py
+++ b/src/arch/x86/ucasmlib/arch/x86/symbols.py
@@ -179,7 +179,7 @@

 symbols["label"] = lambda label_str: f'label_{label_str}'
 symbols["rom_label"] = \
-    lambda label_str: f'microcodeRom.getLabel("{label_str}")'
+    lambda label_str: f'microcodeRom().getLabel("{label_str}")'

 def stack_index(index):
     return fpRegIdx(f'NUM_FLOATREGS + ((({index}) + 8) % 8)')

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/56672
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: I5f8fba1854b94187be5ab557a19a107aaa490bf5
Gerrit-Change-Number: 56672
Gerrit-PatchSet: 1
Gerrit-Owner: Gabe Black <gabe.bl...@gmail.com>
Gerrit-MessageType: newchange
_______________________________________________
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