<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<p><font size="2">Loop Mike.</font></p>
<p><font size="2">Hi Mike and Liming,<br>
</font></p>
<p><font size="2">Please refer to history emails. The
Self-Modifying-Code(SMC) method has security risks and no one
approve it. Ard and Pedro suggest using inline ASM in MdePkg.</font></p>
<p><font size="2">For this problem, it can only dealt with in the
preprocessing stage, because the CSR instructions can only
recognize immediate values, so macro can only be used to expand
and obtain the immediate values in the preprocessing stage.</font></p>
<p><font size="2">So, can I create a .h file and using inline ASM? I
think this file might be named Csr.h and located in
MdePkg/Include/Register/LoongArch64/. I have two plans if
possible:</font></p>
<p><b><font size="2">Plan A,<br>
</font></b></p>
<p><font size="2">All of CSR register numbers are defined in Csr.h
and include three CSR operations inline ASM, pseudocode:</font></p>
<p><font size="2">#if defined(__GNUC__)</font></p>
<p><font size="2">#define CsrRead(Sel)</font></p>
<p><font size="2">({</font></p>
<p><font size="2">XXXX<br>
</font></p>
<p><font size="2">)}</font></p>
<p><font size="2">...<br>
</font></p>
<p><font size="2">#endif<br>
</font></p>
<p><font size="2"><br>
</font></p>
<p><b><font size="2">Plan B,</font></b></p>
<p><font size="2">These three macros are defined in another file,
which may be named CsrOperationGcc.h, and include it in Csr.h,
pseudocode:</font></p>
<p><font size="2">#if defined(__GNUC__)</font></p>
<font size="2">#include "CsrPerationGcc.h"</font><br>
<p><font size="2">#endif</font></p>
<p><font size="2"></font></p>
<p><font size="2"><br>
</font></p>
<p><font size="2">Hope you can give your suggestions.<br>
</font></p>
<p><br>
</p>
<div class="moz-signature"
signature-switch-id="18b8a24a-8ce6-4aca-a108-921eeebcd5e9"><br>
<div
style="width:15%;height:1px;background-color:grey;transform:scaleY(0.3)"></div>
<div style="color:grey;font-size:11px">Thanks,<br>
Chao<br>
</div>
</div>
<div class="moz-cite-prefix">在 2023/8/16 05:26, Andrew Fish via
groups.io 写道:<br>
</div>
<blockquote type="cite"
cite="mid:0F79F614-3F6B-4262-93A6-26DF5FB8C11A@apple.com">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<br>
<div><br>
<blockquote type="cite">
<div>On Aug 15, 2023, at 11:48 AM, Ard Biesheuvel
<a class="moz-txt-link-rfc2396E" href="mailto:ardb@kernel.org"><ardb@kernel.org></a> wrote:</div>
<br class="Apple-interchange-newline">
<div>
<meta charset="UTF-8">
<span style="caret-color: rgb(0, 0, 0); font-family:
Helvetica; font-size: 12px; font-style: normal;
font-variant-caps: normal; font-weight: 400;
letter-spacing: normal; text-align: start; text-indent:
0px; text-transform: none; white-space: normal;
word-spacing: 0px; -webkit-text-stroke-width: 0px;
text-decoration: none; float: none; display: inline
!important;">On Tue, 15 Aug 2023 at 18:31, Andrew Fish via<span
class="Apple-converted-space"> </span></span><a
href="http://groups.io/" style="font-family: Helvetica;
font-size: 12px; font-style: normal; font-variant-caps:
normal; font-weight: 400; letter-spacing: normal; orphans:
auto; text-align: start; text-indent: 0px; text-transform:
none; white-space: normal; widows: auto; word-spacing:
0px; -webkit-text-stroke-width: 0px;"
moz-do-not-send="true">groups.io</a><br
style="caret-color: rgb(0, 0, 0); font-family: Helvetica;
font-size: 12px; font-style: normal; font-variant-caps:
normal; font-weight: 400; letter-spacing: normal;
text-align: start; text-indent: 0px; text-transform: none;
white-space: normal; word-spacing: 0px;
-webkit-text-stroke-width: 0px; text-decoration: none;">
<span style="caret-color: rgb(0, 0, 0); font-family:
Helvetica; font-size: 12px; font-style: normal;
font-variant-caps: normal; font-weight: 400;
letter-spacing: normal; text-align: start; text-indent:
0px; text-transform: none; white-space: normal;
word-spacing: 0px; -webkit-text-stroke-width: 0px;
text-decoration: none; float: none; display: inline
!important;"><</span><a
href="mailto:afish=apple.com@groups.io"
style="font-family: Helvetica; font-size: 12px;
font-style: normal; font-variant-caps: normal;
font-weight: 400; letter-spacing: normal; orphans: auto;
text-align: start; text-indent: 0px; text-transform: none;
white-space: normal; widows: auto; word-spacing: 0px;
-webkit-text-stroke-width: 0px;" moz-do-not-send="true"
class="moz-txt-link-freetext">afish=apple.com@groups.io</a><span
style="caret-color: rgb(0, 0, 0); font-family: Helvetica;
font-size: 12px; font-style: normal; font-variant-caps:
normal; font-weight: 400; letter-spacing: normal;
text-align: start; text-indent: 0px; text-transform: none;
white-space: normal; word-spacing: 0px;
-webkit-text-stroke-width: 0px; text-decoration: none;
float: none; display: inline !important;">> wrote:</span><br
style="caret-color: rgb(0, 0, 0); font-family: Helvetica;
font-size: 12px; font-style: normal; font-variant-caps:
normal; font-weight: 400; letter-spacing: normal;
text-align: start; text-indent: 0px; text-transform: none;
white-space: normal; word-spacing: 0px;
-webkit-text-stroke-width: 0px; text-decoration: none;">
<blockquote type="cite" style="font-family: Helvetica;
font-size: 12px; font-style: normal; font-variant-caps:
normal; font-weight: 400; letter-spacing: normal; orphans:
auto; text-align: start; text-indent: 0px; text-transform:
none; white-space: normal; widows: auto; word-spacing:
0px; -webkit-text-stroke-width: 0px; text-decoration:
none;"><br>
<br>
<br>
<blockquote type="cite">On Aug 15, 2023, at 8:39 AM, Pedro
Falcato <a class="moz-txt-link-rfc2396E" href="mailto:pedro.falcato@gmail.com"><pedro.falcato@gmail.com></a> wrote:<br>
<br>
On Tue, Aug 15, 2023 at 4:05 PM Andrew Fish via
groups.io<br>
<a class="moz-txt-link-rfc2396E" href="mailto:afish=apple.com@groups.io"><afish=apple.com@groups.io></a> wrote:<br>
<blockquote type="cite"><br>
Chao,<br>
<br>
From a quick google it looks like CSR* is used to
access banks of registers that relate to things like
performance counters and debug infrastructure and the
number of banks of these register sets is likely
implementation defined. Seems like we could introduce
some Fixed At Build PCD values that define the maximum
number of elements in a given bank.<br>
<br>
If we are forced to use assembler it might be possible
to write some macros that used the fixed at build
values to only generate functions for banks that are
needed for a given build. Then I think it becomes an
exercise in dead code stripping the assembler. Most
compilers generate assembler that contains functions
that can be stripped as long as those functions follow
certain rules.<br>
<br>
As a side note it would be good for us to have an
FAQ/Wiki entry for the dead code stripping rules for
the various flavors of assembler. I know the Apple
assembler has a unique take on this.<br>
</blockquote>
<br>
FWIW, I'm almost positive there's no DCE in GNU as (or
llvm-as as<br>
well). Unless you use something ffunction-sections<br>
-fdata-sections-like, but then you're relying on the
linker +<br>
gc-sections to take care of it, just like GCC/clang
would.<br>
<br>
</blockquote>
<br>
I guess I usually think of DCE as a linker job, since the
linker knows the functions that are NOT called. At least
from the Apple tools the DCE has the same rules if you are
using Link Time Optimization or not. It is basically a
flag in the object that tells the inker it is OK to follow
the DCE rules around labels and remove stuff.<br>
<br>
Worst case it seems like we could have macros that
generate assembly files based on build time constants so
we have one function per file. This might take a tweak to
the build system, but I’d rather do that than have library
functions that magically turn on Self Modifying Code.<br>
<br>
Regardless of the answer I think documenting the rules is
a useful exercises since needing to save size in firmware
images is not an uncommon task.<br>
<br>
</blockquote>
<br style="caret-color: rgb(0, 0, 0); font-family:
Helvetica; font-size: 12px; font-style: normal;
font-variant-caps: normal; font-weight: 400;
letter-spacing: normal; text-align: start; text-indent:
0px; text-transform: none; white-space: normal;
word-spacing: 0px; -webkit-text-stroke-width: 0px;
text-decoration: none;">
<span style="caret-color: rgb(0, 0, 0); font-family:
Helvetica; font-size: 12px; font-style: normal;
font-variant-caps: normal; font-weight: 400;
letter-spacing: normal; text-align: start; text-indent:
0px; text-transform: none; white-space: normal;
word-spacing: 0px; -webkit-text-stroke-width: 0px;
text-decoration: none; float: none; display: inline
!important;">There is already prior art in MdePkg where
code targeting both GCC and</span><br style="caret-color:
rgb(0, 0, 0); font-family: Helvetica; font-size: 12px;
font-style: normal; font-variant-caps: normal;
font-weight: 400; letter-spacing: normal; text-align:
start; text-indent: 0px; text-transform: none;
white-space: normal; word-spacing: 0px;
-webkit-text-stroke-width: 0px; text-decoration: none;">
<span style="caret-color: rgb(0, 0, 0); font-family:
Helvetica; font-size: 12px; font-style: normal;
font-variant-caps: normal; font-weight: 400;
letter-spacing: normal; text-align: start; text-indent:
0px; text-transform: none; white-space: normal;
word-spacing: 0px; -webkit-text-stroke-width: 0px;
text-decoration: none; float: none; display: inline
!important;">VS uses inline asm, so I don't see why we
would make our lives</span><br style="caret-color: rgb(0,
0, 0); font-family: Helvetica; font-size: 12px;
font-style: normal; font-variant-caps: normal;
font-weight: 400; letter-spacing: normal; text-align:
start; text-indent: 0px; text-transform: none;
white-space: normal; word-spacing: 0px;
-webkit-text-stroke-width: 0px; text-decoration: none;">
<span style="caret-color: rgb(0, 0, 0); font-family:
Helvetica; font-size: 12px; font-style: normal;
font-variant-caps: normal; font-weight: 400;
letter-spacing: normal; text-align: start; text-indent:
0px; text-transform: none; white-space: normal;
word-spacing: 0px; -webkit-text-stroke-width: 0px;
text-decoration: none; float: none; display: inline
!important;">difficult and deviate from that for
LoongArch.</span><br style="caret-color: rgb(0, 0, 0);
font-family: Helvetica; font-size: 12px; font-style:
normal; font-variant-caps: normal; font-weight: 400;
letter-spacing: normal; text-align: start; text-indent:
0px; text-transform: none; white-space: normal;
word-spacing: 0px; -webkit-text-stroke-width: 0px;
text-decoration: none;">
<br style="caret-color: rgb(0, 0, 0); font-family:
Helvetica; font-size: 12px; font-style: normal;
font-variant-caps: normal; font-weight: 400;
letter-spacing: normal; text-align: start; text-indent:
0px; text-transform: none; white-space: normal;
word-spacing: 0px; -webkit-text-stroke-width: 0px;
text-decoration: none;">
</div>
</blockquote>
<div><br>
</div>
<div>If you look at the BaseLib you can see an example of the
INF file[1] using C inline assembler for the GCC family[2] of
compilers and NASM for the MSFT [3] tools. Maybe you can plan
on using a similar pattern.</div>
<div><br>
</div>
<div>[1] <a
href="https://github.com/tianocore/edk2/blob/master/MdePkg/Library/BaseLib/BaseLib.inf#L321"
moz-do-not-send="true" class="moz-txt-link-freetext">https://github.com/tianocore/edk2/blob/master/MdePkg/Library/BaseLib/BaseLib.inf#L321</a></div>
<div>[2] <a
href="https://github.com/tianocore/edk2/blob/master/MdePkg/Library/BaseLib/X64/GccInline.c"
moz-do-not-send="true" class="moz-txt-link-freetext">https://github.com/tianocore/edk2/blob/master/MdePkg/Library/BaseLib/X64/GccInline.c</a></div>
<div>[3] <a
href="https://github.com/tianocore/edk2/blob/master/MdePkg/Library/BaseLib/X64/CpuPause.nasm"
moz-do-not-send="true" class="moz-txt-link-freetext">https://github.com/tianocore/edk2/blob/master/MdePkg/Library/BaseLib/X64/CpuPause.nasm</a></div>
<br>
</div>
<div>Thanks,</div>
<div><br>
</div>
<div>Andrew Fish</div>
<div><br>
<blockquote type="cite">
<div><br style="caret-color: rgb(0, 0, 0); font-family:
Helvetica; font-size: 12px; font-style: normal;
font-variant-caps: normal; font-weight: 400;
letter-spacing: normal; text-align: start; text-indent:
0px; text-transform: none; white-space: normal;
word-spacing: 0px; -webkit-text-stroke-width: 0px;
text-decoration: none;">
<span style="caret-color: rgb(0, 0, 0); font-family:
Helvetica; font-size: 12px; font-style: normal;
font-variant-caps: normal; font-weight: 400;
letter-spacing: normal; text-align: start; text-indent:
0px; text-transform: none; white-space: normal;
word-spacing: 0px; -webkit-text-stroke-width: 0px;
text-decoration: none; float: none; display: inline
!important;"></span></div>
</blockquote>
</div>
<br>
</blockquote>
</body>
</html>
<div width="1" style="color:white;clear:both">_._,_._,_</div>
<hr>
Groups.io Links:<p>
You receive all messages sent to this group.
<p>
<a target="_blank" href="https://edk2.groups.io/g/devel/message/107822">View/Reply Online (#107822)</a> |
|
<a target="_blank" href="https://groups.io/mt/100751724/1813853">Mute This Topic</a>
| <a href="https://edk2.groups.io/g/devel/post">New Topic</a>
<br>
<a href="https://edk2.groups.io/g/devel/editsub/1813853">Your Subscription</a> |
<a href="mailto:devel+owner@edk2.groups.io">Contact Group Owner</a> |
<a href="https://edk2.groups.io/g/devel/unsub">Unsubscribe</a>
[edk2-devel-archive@redhat.com]<br>
<div width="1" style="color:white;clear:both">_._,_._,_</div>