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

Change subject: arch-x86: Pull segment descriptor reading into a macro.
......................................................................

arch-x86: Pull segment descriptor reading into a macro.

This common pattern was repeated many times.

Change-Id: I136a42ae37a6c12c75a3ca62aa628020ce0e53db
---
M src/arch/x86/microcode/SConscript
M src/arch/x86/microcode/general_purpose/control_transfer/interrupts_and_exceptions.ucode
M src/arch/x86/microcode/general_purpose/control_transfer/xreturn.ucode
M src/arch/x86/microcode/general_purpose/data_transfer/move.ucode
M src/arch/x86/microcode/general_purpose/data_transfer/stack_operations.ucode
M src/arch/x86/microcode/general_purpose/load_segment_registers.ucode
A src/arch/x86/microcode/macros/segmentation.ucode
M src/arch/x86/microcode/romutil.ucode
8 files changed, 86 insertions(+), 113 deletions(-)



diff --git a/src/arch/x86/microcode/SConscript b/src/arch/x86/microcode/SConscript
index af690f6..6e30737 100644
--- a/src/arch/x86/microcode/SConscript
+++ b/src/arch/x86/microcode/SConscript
@@ -26,9 +26,11 @@
 Import('*')

 arch_x86 = Dir('../')
+ucode_dir = Dir('.')
 class X86MicroCode(MicroCode):
     def __init__(self, source, *args, **kwargs):
         super().__init__(source, arch_x86.srcnode().abspath, 'x86',
+                asm_include_paths=[ucode_dir.srcnode().abspath],
                 *args, **kwargs)

 Export('X86MicroCode')
diff --git a/src/arch/x86/microcode/general_purpose/control_transfer/interrupts_and_exceptions.ucode b/src/arch/x86/microcode/general_purpose/control_transfer/interrupts_and_exceptions.ucode
index 4415ab0..f2b5a99 100644
--- a/src/arch/x86/microcode/general_purpose/control_transfer/interrupts_and_exceptions.ucode +++ b/src/arch/x86/microcode/general_purpose/control_transfer/interrupts_and_exceptions.ucode
@@ -33,6 +33,8 @@
 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

+include "macros/segmentation.ucode"
+
 def macroop IRET_REAL {
     .serialize_after

@@ -127,15 +129,9 @@
     #CS = READ_DESCRIPTOR (temp_CS, iret_chk)
     andi t0, t2, 0xFC, flags=(EZF,), dataSize=2
     br "processCSDescriptor", flags=(CEZF,)
-    andi t6, t2, 0xF8, dataSize=8
-    andi t0, t2, 0x4, flags=(EZF,), dataSize=2
-    br "globalCSDescriptor", flags=(CEZF,)
-    ld t8, tsl, [1, t0, t6], dataSize=8, addressSize=8, atCPL0=True
-    br "processCSDescriptor"
-globalCSDescriptor:
-    ld t8, tsg, [1, t0, t6], dataSize=8, addressSize=8, atCPL0=True
+    m_read_descriptor desc="t8", selector="t2"
 processCSDescriptor:
-    chks t0, t2, t6, NoCheck, dataSize=8
+    chks t0, t2, t8, NoCheck, dataSize=8


 ###
@@ -184,13 +180,7 @@
     #    SS = READ_DESCRIPTOR (temp_SS, ss_chk)
     andi t0, t9, 0xFC, flags=(EZF,), dataSize=2
     br "processSSDescriptor", flags=(CEZF,)
-    andi t7, t9, 0xF8, dataSize=8
-    andi t0, t9, 0x4, flags=(EZF,), dataSize=2
-    br "globalSSDescriptor", flags=(CEZF,)
-    ld t7, tsl, [1, t0, t7], dataSize=8, addressSize=8, atCPL0=True
-    br "processSSDescriptor"
-globalSSDescriptor:
-    ld t7, tsg, [1, t0, t7], dataSize=8, addressSize=8, atCPL0=True
+    m_read_descriptor desc="t7", selector="t9"
 processSSDescriptor:
     chks t0, t9, t7, NoCheck, dataSize=8

diff --git a/src/arch/x86/microcode/general_purpose/control_transfer/xreturn.ucode b/src/arch/x86/microcode/general_purpose/control_transfer/xreturn.ucode
index d670151..5c291f8 100644
--- a/src/arch/x86/microcode/general_purpose/control_transfer/xreturn.ucode
+++ b/src/arch/x86/microcode/general_purpose/control_transfer/xreturn.ucode
@@ -33,6 +33,8 @@
 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

+include "macros/segmentation.ucode"
+
 def macroop RET_NEAR
 {
     # Make the default data size of rets 64 bits in 64 bit mode
@@ -139,13 +141,7 @@
     # Do stuff if they're equal
     andi t0, t2, 0xFC, flags=(EZF,), dataSize=2
     br "processDescriptor", flags=(CEZF,)
-    andi t3, t2, 0xF8, dataSize=8
-    andi t0, t2, 0x4, flags=(EZF,), dataSize=2
-    br "globalDescriptor", flags=(CEZF,)
-    ld t3, tsl, [1, t0, t3], dataSize=8, addressSize=8
-    br "processDescriptor"
-globalDescriptor:
-    ld t3, tsg, [1, t0, t3], dataSize=8, addressSize=8
+    m_read_descriptor desc="t3", selector="t2"
 processDescriptor:
     chks t0, t2, t3, IretCheck, dataSize=8
     # There should be validity checks on the RIP checks here, but I'll do
diff --git a/src/arch/x86/microcode/general_purpose/data_transfer/move.ucode b/src/arch/x86/microcode/general_purpose/data_transfer/move.ucode
index dee2dfe..de4f060 100644
--- a/src/arch/x86/microcode/general_purpose/data_transfer/move.ucode
+++ b/src/arch/x86/microcode/general_purpose/data_transfer/move.ucode
@@ -33,6 +33,8 @@
 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

+include "macros/segmentation.ucode"
+
 #
 # Regular moves
 #
@@ -265,13 +267,7 @@
     .args 'S', 'R'
     andi t0, regm, 0xFC, flags=(EZF,), dataSize=2
     br "processDescriptor", flags=(CEZF,)
-    andi t2, regm, 0xF8, dataSize=8
-    andi t0, regm, 0x4, flags=(EZF,), dataSize=2
-    br "globalDescriptor", flags=(CEZF,)
-    ld t3, tsl, [1, t0, t2], dataSize=8, addressSize=8
-    br "processDescriptor"
-globalDescriptor:
-    ld t3, tsg, [1, t0, t2], dataSize=8, addressSize=8
+    m_read_descriptor desc="t3", selector="regm"
 processDescriptor:
     chks t0, regm, t3, NoCheck, dataSize=8
     wrdl sr, t3, regm
@@ -283,13 +279,7 @@
     ld t1, seg, sib, disp, dataSize=2
     andi t0, t1, 0xFC, flags=(EZF,), dataSize=2
     br "processDescriptor", flags=(CEZF,)
-    andi t2, t1, 0xF8, dataSize=8
-    andi t0, t1, 0x4, flags=(EZF,), dataSize=2
-    br "globalDescriptor", flags=(CEZF,)
-    ld t3, tsl, [1, t0, t2], dataSize=8, addressSize=8
-    br "processDescriptor"
-globalDescriptor:
-    ld t3, tsg, [1, t0, t2], dataSize=8, addressSize=8
+    m_read_descriptor desc="t3", selector="t1"
 processDescriptor:
     chks t0, t1, t3, NoCheck, dataSize=8
     wrdl sr, t3, t1
@@ -302,13 +292,7 @@
     ld t1, seg, riprel, disp, dataSize=2
     andi t0, t1, 0xFC, flags=(EZF,), dataSize=2
     br "processDescriptor", flags=(CEZF,)
-    andi t2, t1, 0xF8, dataSize=8
-    andi t0, t1, 0x4, flags=(EZF,), dataSize=2
-    br "globalDescriptor", flags=(CEZF,)
-    ld t3, tsl, [1, t0, t2], dataSize=8, addressSize=8
-    br "processDescriptor"
-globalDescriptor:
-    ld t3, tsg, [1, t0, t2], dataSize=8, addressSize=8
+    m_read_descriptor desc="t3", selector="t1"
 processDescriptor:
     chks t0, t1, t3, NoCheck, dataSize=8
     wrdl sr, t3, t1
@@ -319,13 +303,7 @@
     .args 'S', 'R'
     andi t0, regm, 0xFC, flags=(EZF,), dataSize=2
     br "processDescriptor", flags=(CEZF,)
-    andi t2, regm, 0xF8, dataSize=8
-    andi t0, regm, 0x4, flags=(EZF,), dataSize=2
-    br "globalDescriptor", flags=(CEZF,)
-    ld t3, tsl, [1, t0, t2], dataSize=8, addressSize=8
-    br "processDescriptor"
-globalDescriptor:
-    ld t3, tsg, [1, t0, t2], dataSize=8, addressSize=8
+    m_read_descriptor desc="t3", selector="regm"
 processDescriptor:
     chks t0, regm, t3, SSCheck, dataSize=8
     wrdl sr, t3, regm
@@ -337,13 +315,7 @@
     ld t1, seg, sib, disp, dataSize=2
     andi t0, t1, 0xFC, flags=(EZF,), dataSize=2
     br "processDescriptor", flags=(CEZF,)
-    andi t2, t1, 0xF8, dataSize=8
-    andi t0, t1, 0x4, flags=(EZF,), dataSize=2
-    br "globalDescriptor", flags=(CEZF,)
-    ld t3, tsl, [1, t0, t2], dataSize=8, addressSize=8
-    br "processDescriptor"
-globalDescriptor:
-    ld t3, tsg, [1, t0, t2], dataSize=8, addressSize=8
+    m_read_descriptor desc="t3", selector="t1"
 processDescriptor:
     chks t0, t1, t3, SSCheck, dataSize=8
     wrdl sr, t3, t1
@@ -356,13 +328,7 @@
     ld t1, seg, riprel, disp, dataSize=2
     andi t0, t1, 0xFC, flags=(EZF,), dataSize=2
     br "processDescriptor", flags=(CEZF,)
-    andi t2, t1, 0xF8, dataSize=8
-    andi t0, t1, 0x4, flags=(EZF,), dataSize=2
-    br "globalDescriptor", flags=(CEZF,)
-    ld t3, tsl, [1, t0, t2], dataSize=8, addressSize=8
-    br "processDescriptor"
-globalDescriptor:
-    ld t3, tsg, [1, t0, t2], dataSize=8, addressSize=8
+    m_read_descriptor desc="t3", selector="t1"
 processDescriptor:
     chks t0, t1, t3, SSCheck, dataSize=8
     wrdl sr, t3, t1
diff --git a/src/arch/x86/microcode/general_purpose/data_transfer/stack_operations.ucode b/src/arch/x86/microcode/general_purpose/data_transfer/stack_operations.ucode
index 01df801..643fb11 100644
--- a/src/arch/x86/microcode/general_purpose/data_transfer/stack_operations.ucode +++ b/src/arch/x86/microcode/general_purpose/data_transfer/stack_operations.ucode
@@ -33,6 +33,8 @@
 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

+include "macros/segmentation.ucode"
+
 def macroop POP {
     .args 'R'
     # Make the default data size of pops 64 bits in 64 bit mode
@@ -86,15 +88,7 @@
     andi t0, t1, 0xFC, flags=(EZF,), dataSize=2
     br "processDescriptor", flags=(CEZF,)

-    andi t2, t1, 0xF8, dataSize=8
-    andi t0, t1, 0x4, flags=(EZF,), dataSize=2
-    br "globalDescriptor"
-
-    ld t3, tsl, [1, t0, t2], dataSize=8, addressSize=8
-    br "processDescriptor"
-
-globalDescriptor:
-    ld t3, tsg, [1, t0, t2], dataSize=8, addressSize=8
+    m_read_descriptor desc="t3", selector="t1"

 processDescriptor:
     chks t0, t1, t3, NoCheck, dataSize=8
diff --git a/src/arch/x86/microcode/general_purpose/load_segment_registers.ucode b/src/arch/x86/microcode/general_purpose/load_segment_registers.ucode
index ce94052..f0231b2 100644
--- a/src/arch/x86/microcode/general_purpose/load_segment_registers.ucode
+++ b/src/arch/x86/microcode/general_purpose/load_segment_registers.ucode
@@ -33,6 +33,8 @@
 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

+include "macros/segmentation.ucode"
+
 def macro lxs_template addr_calc, seg {
     # Calculate the address of the pointer.
     {addr_calc}
@@ -46,20 +48,7 @@
     andi t0, t2, 0xFC, flags=(EZF,), dataSize=2
     br "processDescriptor", flags=(CEZF,)

-    # Extract the index.
-    andi t3, t2, 0xF8, dataSize=8
-
-    # Check if this is a local or global descriptor.
-    andi t0, t2, 0x4, flags=(EZF,), dataSize=2
-    br "globalDescriptor", flags=(CEZF,)
-
-    # It's local.
-    ld t4, tsl, [1, t0, t3], dataSize=8, addressSize=8
-    br "processDescriptor"
-
-    # It's global.
-globalDescriptor:
-    ld t4, tsg, [1, t0, t3], dataSize=8, addressSize=8
+    m_read_descriptor desc="t4", selector="t2"

     # Install the descriptor.
 processDescriptor:
diff --git a/src/arch/x86/microcode/macros/segmentation.ucode b/src/arch/x86/microcode/macros/segmentation.ucode
new file mode 100644
index 0000000..d8c1b81
--- /dev/null
+++ b/src/arch/x86/microcode/macros/segmentation.ucode
@@ -0,0 +1,46 @@
+# Copyright 2022 Google Inc.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met: redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer;
+# redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution;
+# neither the name of the copyright holders nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+def macro m_read_descriptor desc, selector, label_prefix=rnd_str()
+{
+    # Extract the index.
+    andi {desc}, {selector}, 0xF8, dataSize=8
+
+    # Determine if this descriptor is in the GDT or LDT.
+    andi t0, {selector}, 0x4, flags=(EZF,), dataSize=2
+
+    # It's in the GDT.
+    br "{label_prefix}_global_desc", flags=(CEZF,)
+
+    # Load it from the LDT.
+    ld {desc}, tsl, [1, t0, {desc}], dataSize=8, addressSize=8, atCPL0=True
+    br "{label_prefix}_process_desc"
+
+    # Load it from the GDT.
+{label_prefix}_global_desc:
+    ld {desc}, tsg, [1, t0, {desc}], dataSize=8, addressSize=8, atCPL0=True
+
+{label_prefix}_process_desc:
+};
diff --git a/src/arch/x86/microcode/romutil.ucode b/src/arch/x86/microcode/romutil.ucode
index c738f36..27b1d36 100644
--- a/src/arch/x86/microcode/romutil.ucode
+++ b/src/arch/x86/microcode/romutil.ucode
@@ -24,6 +24,8 @@
 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

+include "macros/segmentation.ucode"
+
 def macro long_int start_label, gate_check_type="IntGateCheck", \
         error_code_size=0, error_code_code=""
 {
@@ -49,14 +51,7 @@
     # descriptor.
     #
     srli t10, t4, 16, dataSize=8
-    andi t5, t10, 0xF8, dataSize=8
-    andi t0, t10, 0x4, flags=(EZF,), dataSize=2
-    br "{start_label}_globalDescriptor", flags=(CEZF,)
-    ld t3, tsl, [1, t0, t5], dataSize=8, addressSize=8, atCPL0=True
-    br "{start_label}_processDescriptor"
-{start_label}_globalDescriptor:
-    ld t3, tsg, [1, t0, t5], dataSize=8, addressSize=8, atCPL0=True
-{start_label}_processDescriptor:
+    m_read_descriptor desc="t3", selector="t10"
     chks t10, t10, t3, IntCSCheck, dataSize=8
     wrdl hs, t3, t10, dataSize=8
     wrsel hs, t10, dataSize=2
@@ -222,14 +217,7 @@
     # descriptor.
     #
     srli t10, t4, 16, dataSize=8
-    andi t5, t10, 0xF8, dataSize=8
-    andi t0, t10, 0x4, flags=(EZF,), dataSize=2
-    br "{start_label}_globalCS", flags=(CEZF,)
-    ld t3, tsl, [1, t0, t5], dataSize=8, addressSize=8, atCPL0=True
-    br "{start_label}_processCS"
-{start_label}_globalCS:
-    ld t3, tsg, [1, t0, t5], dataSize=8, addressSize=8, atCPL0=True
-{start_label}_processCS:
+    m_read_descriptor desc="t3", selector="t10"
     andi t13, t10, 0xff, dataSize=8
     chks t13, t13, t3, IntCSCheck, dataSize=8
     wrdl hs, t3, t13, dataSize=8
@@ -267,16 +255,7 @@
     # Check for a null selector.
     andi t0, t8, 0xFC, flags=(EZF,), dataSize=8
     fault "std::make_shared<GeneralProtection>(0)", flags=(CEZF,)
-    # Extract the index.
-    andi t11, t8, 0xF8, dataSize=8
-    # Check if this is a global or local descriptor.
-    andi t0, t8, 0x4, flags=(EZF,), dataSize=2
-    br "{start_label}_globalSS", flags=(CEZF,)
-    ld t12, tsl, [1, t0, t11], dataSize=8, addressSize=8, atCPL0=True
-    br "{start_label}_processSS"
-{start_label}_globalSS:
-    ld t12, tsg, [1, t0, t11], dataSize=8, addressSize=8, atCPL0=True
-{start_label}_processSS:
+    m_read_descriptor desc="t12", selector="t8"
     chks t0, t8, t12, SSCheck, dataSize=8
     wrdl hs, t12, t8, dataSize=8


--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/56903
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: I136a42ae37a6c12c75a3ca62aa628020ce0e53db
Gerrit-Change-Number: 56903
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